SUBROUTINE SORTFILE(itype,ifile,icounts) C SORTFILE ALLOCATES SPACE FOR SORTING PROCEDURE, THEN C SORTS A FILE BY RECORD NUMBER, REWRITES THE FILE C WITH THE SORTED VALUES AND REWINDS IT TO THE BEGINNING. c*********************************************************** c c Passed Variables: c c itype - structure indicator c 0 - one real value c 1 - two integer values c 2 - one integer one real value c 3 - one integer value c 4 - three integer values c ifile - file identification number c icounts - number of structures to free space for c*********************************************************** c*********************************************************** c c Array: c iallset - set to one if a structure has already had c space allocated c c*********************************************************** character*8 firsttime dimension iallset(4) save iallset save firsttime if ( firsttime .ne. 'sortfile' ) then call arrayinit(iallset,1,4) firsttime='sortfile' endif if ( icounts.le.0 ) return c*********************************************************** c c Rewind file c c Allocate space for sorting file c c allocator: c itype - structure indicator c c 0 - one real value c 1 - two integer values c 2 - one integer one real value c 3 - one integer value c 4 - three integer values c icounts - number of structures to free space for c c Sort file by record number c c jsort: c ifile - file identification number c c Free up allocated space c c freeup: c itype - structure indicator (see above) c c Rewind file c c************************************************************ call filerewind(ifile) itype0=itype if ( itype .eq. 5 ) itype0=1 if ( iallset(itype0) .eq. 0 ) then call allocator(itype0,icounts+1) iallset(itype0)= icounts+1 elseif ( iallset(itype0) .lt. icounts+1 ) then call reallocator(itype0,icounts+1) iallset(itype0)= icounts+1 endif if ( itype.eq. 3 ) then call jsort(ifile) elseif ( itype.eq. 1 ) then call djsort(ifile) elseif ( itype.eq. 4 ) then call threejsort(ifile) elseif ( itype .eq. 5 ) then call newcmask(icounts,ifile+1,ifile) endif c call freeup(itype) call filerewind(ifile) return end