.TI F77/SORT_FILES "Sep. 4, 1985"
Sorting Data in Files

Sorting of files can be done with the UNIX sort utility, for example:

	sort unsrt > srt

sorts the data in file 'unsrt' and writes the sorted records onto file
\&'srt'.  The records are sorted in ascending order using the entire
record as a sort key.

It is also possible to sort specifying keys by fields.  The default is
that fields are nonblank nonempty strings separated by blanks.  For
example, to sort on the second field separated by blanks (fields separated
by single blanks):

	sort +1 -2 unsrt > srt

You can also specify sorting by specific columns, e.g.:

	sort -tx +0.19 -0.29 unsrt > srt

sorts using columns 20-29 as a sort key.  0.19 means to skip 0 fields and
then skip 19 characters; thus it points at character 20; 0.29 similarly
points to character 30.  +0.19 -0.29 means that the sort key starts in
column 20 and ends before column 30; i.e. the sort key is columns
20-29.  The '-tx' forces sort to consider the first column of the
first field to be in column one, otherwise it considers it to be the
first nonblank column.

Sorts can be done from within an f77 program by using the
subroutine system() which causes a UNIX command to be executed.
For example:

.nf
	open(8,file='unsrt')
	 ... code writing data creating unsorted file ...
	close(8)
	call system('sort +0.19 -0.29 unsrt > srt ')
	open(8,file='srt')
	 ... code reading sorted data ...
.fi
