C+ C NAME: C SortIPS C PURPOSE: C Sort the original Nagoya and Ooty IPS files into chronological order C CALLING SEQUENCE: program SortIPS C INPUTS: C Name of unsorted input file (by user prompt) C OUTPUTS: C The sorted data are written to a file NAGOYA.%% and Ooty,%%, C where %% stands for the year, e.g. 90 for 1990 data. C INCLUDE: include 'openfile.h' include 'filparts.h' C CALLS: C IndexR4, bOpenFile, itrim C PROCEDURE: C > All records are read into a big string array STRINGS. C A TIMES array (doy of year) is extracted from the STRINGS array. C This TIMES array is sorted to obtain an index array. The year,month C day and UT are used to calculate TIMES. The index array is then used C to write the STRINGS array into the new file in sorted order. C > C MODIFICATION HISTORY: C JUN-1994, Paul Hick (UCSD) C- parameter (nREC = 10000) character cStr*140 character cStrs(nREC)*140 character cFmt1*40 /'(A9,3I2,F6.2)'/ character cFmt2*40 /'(2X,3I2,2X,2I2,F8.3)'/ character cSrce*9 character cDum*30 character cFile*80 character cMon*3 character cStrType(2)*7 /'nagoya.','ooty.'/ character cStrHead(2)*11 /'SOURCE','Date Time'/ character cSay*7 /'SortIPS'/ real TIMES(nREC) integer INDAR(nREC) logical bOpen logical bOpenFile integer Str2Str bOpen = bOpenFile(OPN__READONLY+OPN__TEXT+OPN__STOP,iU,cFile,iRecl) call AskWhat('Nagoya, Ooty',iTyp) cStr = cStrHead(iTyp) iStr = itrim(cStr) if (iTyp .eq. 1) then ! Find the first data record read (iU,'(A)',iostat=iErr) cDum do while (cDum(:6) .ne. cStr(:iStr)) if (iErr .ne. 0) call Say(cSay,'F','No','header record starting with '//cStr(:iStr)//' found') read (iU,'(A)',iostat=iErr) cDum end do else read (iU,'(A)',iostat=iErr) cDum I = index(cDum,cStr(:iStr)) do while (I .eq. 0) if (iErr .ne. 0) call Say(cSay,'F','No','header record starting with '//cStr(:iStr)//' found') read (iU,'(A)',iostat=iErr) cDum I = index(cDum,cStr(:iStr)) end do end if iRec = 0 read (iU,'(A)',iostat=iErr) cStr call Say(cSay,'I','First record',cStr) do while (iErr .eq. 0) ! Read all records iRec = iRec+1 if (iTyp .eq. 1) then !------- ! Recl=73: Years 1990-1993 ! Recl=68: Years 1994-1996 ! Recl=66: Years 1997-1998 ! Nagoya files for years 1990-1993 have a column THR in columns ! 27-31. These columns are omitted. Nagoya files for years ! 1990-1996 contain a 'source index' instead of a g-value. ! The source index is replaced by 0 in format F8.5 (used for ! g-value starting in 1997). lStr = itrim(cStr) if (ichar(cStr(lStr:lStr)) .eq. 13) lStr = lStr-1 if (lStr .eq. 73 .or. lStr .eq. 68) cStr(lStr-10+1:) = ' 0.00000'//cStr(lStr-10+1:) ! 90-96: Omit source index if (lStr .eq. 73) cStr = cStr(:26)//cStr(32:) ! 90-93: Omit THR end if if (iRec .gt. nREC) then iErr = 1 else cStrs(iRec) = cStr read (iU,'(A)',iostat=iErr) cStr end if end do call Say(cSay,'I','Last record',cStr) iU = iFreeLun(iU) I = Int2Str(iRec,cDum)+1 I = I+Str2Str('records read',cDum(I+1:)) call Say(cSay,'I',cFile,cDum) if (iRec .gt. nREC) call Say(cSay,'E','NREC','parameter too small') if (iTyp .eq. 1) then ! Nagoya read (cStrs(1),cFmt1) cSrce,iY,iM,iD,UT else ! Ooty read (cStrs(1),cFmt2) iY,iM,iD,iH,iMI,UT end if do I=1,iRec if (iTyp .eq. 1) then ! Nagoya read (cStrs(I),cFmt1) cSrce,iY,iM,iD,UT else ! Ooty read (cStrs(I),cFmt2) iY,iM,iD,iH,iMI,UT end if iY = 1900+iY if (iY .lt. 1970) iY = iY+100 if (I .eq. 1) iY0 = iY if (iY .ne. iY0) call Say(cSay,'E','INVYR','file contains data for more than one year') cMon = ' ' call DATE_DOY(0,iY,cMon,iM,iD,iDoy) TIMES(I) = iDoy+UT/24. end do call IndexR4(1,iRec,1,nREC,TIMES,INDAR) ! Sorting data I = iGetFileSpec(0,FIL__DIRECTORY,cFile) ! Write into same directory as input file I = I+Str2Str(cStrType(iTyp),cFile(I+1:)) ! 'Nagoya' or 'Ooty' I = I+Int2Str(iY0,cFile(I+1:)) ! 4-digit year as extension iRecl = (itrim(cStrs(1))+4)/4*4 bOpen = bOpenFile(OPN__NEW+OPN__TEXT+OPN__TRYINPUT+OPN__STOP,iU,cFile,iRecl) call Say(cSay,'I',cFile,'... writing sorted data') do I=1,iRec write (iU,'(A)') cStrs(INDAR(I))(:itrim(cStrs(INDAR(I)))) end do iU = iFreeLun(iU) do I=1,iRec if (INDAR(I) .ne. I) call Say(cSay,'S','Stop','Original file was NOT sorted') end do call Say(cSay,'S','Stop','Original file was already sorted') end