integer function BListAll(ID, cWild, BListFnc, NCoff, VarBeg,VarEnd, & nFileMax, cFile,TFile,XCFileBeg,XCFileEnd,WFile,Nr,R0,Scale) include 'dirspec.h' include 'filparts.h' integer BListFnc external BListFnc integer ID character cWild*(*) real VarBeg real VarEnd integer nFileMax character cFile (*)*(*) real TFile (*) real XCFileBeg(*) real XCFileEnd(*) real WFile (*) integer Nr (*) real R0 real Scale character cSay*8 /'BListAll'/ character cSearch*(FIL__LENGTH) character cFound *(FIL__LENGTH) parameter (nTmpMax=1000) ! Scratch array size integer iTmp(nTmpMax) real rTmp(nTmpMax) character cTmp(nTmpMax)*(FIL__LENGTH) character cXCvarFormat*9 character cID(0:1)*11 /'overlap','bracket'/ call Say(cSay,'I',cID(ID),'['//cXCvarFormat(NCoff,VarBeg)//','//cXCvarFormat(NCoff,VarEnd)//']') iBelow = 0 ! ID=1 only: Earliest time >= VarEnd iAbove = 0 ! ID=1 only: Latest time <= VarBeg !------- ! Process the wild card for file search call FileSelection(cWild,cSearch) !------- ! Search for all files matching the wildcard. iBad = -1 nF = 0 I = 1 do while (iSearch(I,cSearch,cFound) .eq. 1) !----- ! Determine time and start/end Carrington variable, and version number. ! (this information could be derived from the file name, ! or might have determined by reading the file. if (BListFnc(cFound,NCoff,TFound,XCFoundBeg,XCFoundEnd,NrFound,R0,Scale) .eq. 1) then !------- ! Compare times. If TFound is already on the list TFile then it could ! be a more recent version. I = 1 !do while (I .le. nF .and. TFound .ne. TFile(I)) ! DOESN'T WORK do while (I .le. nF .and. XCFoundBeg .ne. XCFileBeg(I)) I = I+1 end do !------ ! Check whether the file needs to be stored. Note that the condition ! I = iBad is used to reject the file. if (I .le. nF) then ! File already on list, check version number !------- ! Only more recent versions (with higher version number) are accepted if (NrFound .le. Nr(I)) I = iBad else if (ID .eq. 0) then ! File not on list yet: I = nF+1 !------ ! Check whether [XCFoundBeg,XCFoundEnd] overlaps with [XCBeg,XCEnd] ! If not then reject the file if (VarBeg .gt. XCFoundEnd .or. VarEnd .le. XCFoundBeg) I = iBad else if (ID .eq. 1) then ! File not on list yet: I = nF+1 !------ ! Only the latest time before VarBeg and the earliest time later than ! VarEnd are needed. if (TFound .le. VarBeg) then if (iBelow .eq. 0) then ! First time <= VarBeg iBelow = I ! Remember where time is stored else if (TFound .gt. TFile(iBelow)) then I = iBelow ! TFound closer to VarBeg: overwrite iBelow else ! TFound not closer: reject I = iBad end if else if (TFound .ge. VarEnd) then if (iAbove .eq. 0) then ! First time >= VarEnd iAbove = I ! Remember where time is stored else if (TFound .lt. TFile(iAbove)) then I = iAbove ! TFound closer to VarEnd: overwrite iAbove else ! TFound not closer: reject I = iBad end if endif end if !------- ! A new map is added at position I if there is still room ! We can't terminate the outer 'while' loop when the arrays are full, ! because more recent versions for some of the synoptic maps may show up ! We may be overwriting previous entries in the list, when a more recent ! version is found, or (ID=1 only) when the iBelow or iAbove entries are updated. if (I .ne. iBad) then if (I .gt. nFileMax) call SayTooSmall(cSay,'E','nFileMax',nFileMax) cFile (I) = cFound TFile (I) = TFound XCFileBeg(I) = XCFoundBeg XCFileEnd(I) = XCFoundEnd WFile (I) = 1.0 Nr (I) = NrFound if (I .gt. nF) nF = I ! Update map counter only when adding to list end if end if I = 0 ! Continues iSearch with same wildcard end do if (nF .eq. 0) then ! No files read R0 = BadR4() Scale = BadR4() else if (nF .gt. nTmpMax) call SayTooSmall(cSay,'E','nTmpMax',nTmpMax) !------- ! Sort the files into chronological order call IndexR4(1,nF,1,nF,TFile,iTmp) ! Get index array for TFile do I=1,nF ! Sort cFile cTmp(I) = cFile(iTmp(I)) end do do I=1,nF cFile(I) = cTmp(I) end do do I=1,nF ! Sort TFile rTmp(I) = TFile(iTmp(I)) end do call ArrR4Copy(nF,rTmp,TFile) do I=1,nF ! Sort XCFileBeg rTmp(I) = XCFileBeg(iTmp(I)) end do call ArrR4Copy(nF,rTmp,XCFileBeg) do I=1,nF ! Sort XCFileEnd rTmp(I) = XCFileEnd(iTmp(I)) end do call ArrR4Copy(nF,rTmp,XCFileEnd) do I=1,nF ! Sort WFile rTmp(I) = WFile(iTmp(I)) end do call ArrR4Copy(nF,rTmp,WFile) end if BListAll = nF return end