c FINGERSHO.FOR - This is here due to an optimization bug in VAX Fortran V5.1

c------------------------------------------------------------------
	Subroutine Show_Info (HeaderWritten, Finger_Out_Routine,
	1                     TestOutput)

c  This routine sorts the user info array, and outputs it.

	Include		'GETJPIDEF'
	Include		'FingerFlg'
	Include		'Fingerdef.inc'

	External	Finger_Out_Routine

	Integer		PID_array, STS_array, State_array,
	1		PgCnt_array, FP_array

	Character	Prcnam_array*15, Username_array*12,
	1		Terminal_array*8

	Dimension	PID_array(200), STS_array(200),
	1		State_array(200), PgCnt_array(200),
	2		Prcnam_array(200), Username_array(200),
	3		Terminal_array(200), FP_array(200)

	Common	/Info/	PID_array, STS_array, State_array,
	1		PgCnt_array, Prcnam_array, Username_array,
	2		Terminal_array, Last_Number, FP_array

	Character*20	Get_Image, Image_Name
	Character*11	Login_Time
	Character*10	CPU_Time
	Character*20	Get_LastName, LastName, LN_array, SortType
	Character*32	WhoAmI
	Logical		HeaderWritten, Swapped
	Integer		TestOutput,	FlagProcess
	Integer		Index, Index_array, Temp, SortField, l_WhoAmI
	Dimension	Index_array(200), LN_array(200)
	Common /Sorter/	SortType, SortField, WhoAmI, l_WhoAmI

c  Sorting is done by a bubble sort (yeah, I know .... yech! ... but it
c  was easy!).  To have reasonable performance, an array of indecies
c  is initialized in sequence, and then the indecies are swapped around
c  as the sort proceeds.  Then, that array is used to select the user
c  info in the sorted order.

c  Initialize the index array, and get the sort information too.
c  [rph] this whole if-then-else used to be INSIDE the DoWhile. I
c  hoisted it to prevent situations in which if you were sorting on
c  field 5 you'd end up with 5*Last_number extra compares.

	Index = 1
	If (SortField .eq. 0) then
	  DoWhile(Index .le. Last_Number)
	    Index_array(Index) = Index
	    LN_array(Index) = ' '			!20 spaces
	    LN_array(Index) = Get_LastName(Username_array(Index))
	    Index = Index + 1
	  EndDo
	Else If (SortField .eq. 1) then
	  DoWhile(Index .le. Last_Number)
	    Index_array(Index) = Index
	    LN_array(Index) = ' '			!20 spaces
	    LN_array(Index) = Username_array(Index)
	    Index = Index + 1
	  EndDo
	Else If (SortField .eq. 2) then
	  DoWhile(Index .le. Last_Number)
	    Index_array(Index) = Index
	    LN_array(Index) = ' '			!20 spaces
	    LN_array(Index) = Prcnam_array(Index)
	    Index = Index + 1
	  EndDo
	Else If (SortField .eq. 3) then
	  DoWhile(Index .le. Last_Number)
	    Index_array(Index) = Index
	    LN_array(Index) = ' '			!20 spaces
	    Write(LN_array(Index), 1001) PID_array(Index)
	    Index = Index + 1
	  EndDo
	Else If (SortField .eq. 4) then
	  DoWhile(Index .le. Last_Number)
	    Index_array(Index) = Index
	    LN_array(Index) = ' '			!20 spaces
	    LN_array(Index) = Terminal_array(Index)
	    Index = Index + 1
	  EndDo
	Else If (SortField .ge. 5) then
	  DoWhile(Index .le. Last_Number)
	    Index_array(Index) = Index
	    LN_array(Index) = ' '			!20 spaces
	    Image_Name = Get_Image(PID_array(Index),LOGINTIM,CPUTIM)
	    If (SortField .eq. 5) Then
	      Call Sys$AscTim(,Login_Time,LOGINTIM,%val(1))
	      LN_array(Index) = Login_Time(1:5)
	    Else If (SortField .eq. 6) Then
	      LN_array(Index) = Image_Name
	    Else If (SortField .eq. 7) Then
	      Write(CPU_Time, 1002) CPUTIM
	      LN_array(Index) = CPU_Time
	    EndIf
	    Index = Index + 1
	  EndDo
	EndIf
	Swapped = .true.

c  Sort by the extracted data.

	DoWhile ( Swapped )
	    Index = 1
	    Swapped = .false.
	    DoWhile (Index .lt. Last_Number)
	        If ( LGT ( LN_array(Index_array(Index  )),
	1                  LN_array(Index_array(Index+1)) ) ) then
	            Temp = Index_array(Index)
	            Index_array(Index) = Index_array(Index + 1)
	            Index_array(Index + 1) = Temp
	            Swapped = .true.
	        EndIf
	        Index = Index + 1
	    EndDo
	EndDo

c  Send the sorted data to the output.

	Index = 1
	DoWhile (Index .le. Last_Number)
	    Call User_Info(PID_array(Index_array(Index)),
	1                  STS_array(Index_array(Index)),
	2                  Prcnam_array(Index_array(Index)),
	3                  Username_array(Index_array(Index)),
	4                  Terminal_array(Index_array(Index)),
	5                  State_array(Index_array(Index)),
	6                  PgCnt_array(Index_array(Index)),
	7                  HeaderWritten,
	8                  TestOutput,
	9                  FP_array(Index_array(Index)),
	9                  Finger_Out_Routine)
	    Index = Index + 1
	EndDo


	Return

1001	Format(Z8)
1002	Format(Z10)
	End

