Help Files: Fortran77: Sorting Files





     HELP                      Sep. 15, 1984            F77/SORT_FILES



                           Sorting Data in Files

     Sorting of files can be done with the UNIX sort utility, for  ex-
     ample:

             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  de-
     fault  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

     To specify keys by character positions within a  record,  specify
     the  number  of  fields to skip and then the number of additional
     characters to skip.  For example, 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:

             sort +0.19 -0.29 unsrt > srt

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

             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 ...


Comments to decf@euler.berkeley.edu
© 1998 UC Regents