C+ C NAME: C SetLog2Dir C PURPOSE: C Set logical to directory containing files matching specified wildcard C CALLING SEQUENCE: subroutine SetLog2Dir(iPrompt,cLog,cWild,cFound) C INPUTS: C iPrompt integer 1 = prompt for directory until C requested files are located C 2 = do not prompt C -2 = do not prompt, do not delete logical C cLog*(*) character name of logical C cWild*(*) character file name wildcard C (NO directory specification permitted) C OUTPUTS: C cFound*(*) character first file name matching wildcard C = ' ' if no file is found C If necessary the logical is entered into the PROCESS table C CALLS: C AskChar,iSearch,iGetLogical,iSetLogical,iDeleteLogical,Say,iSetFileSpec C INCLUDE: include 'filparts.h' include 'dirspec.h' C PROCEDURE: C > If iPrompt=1 then the logical is defined upon return and C cFound contains the first file name matching the wildcard (if necessary C after prompting for a directory). C > If iPrompt=2 then two things can happen on return C - The logical is still defined and a matching file is located. C cFound contains the first matching file name upon return C - The logical is not defined, and cFound = ' ', because C 1. the logical was not defined in the first place C 2. no matching file name was found C 3. matching files were also found in the current directory C > If iPrompt=-2 then three things can happen on return C - The logical is not defined, and cFound = ' ', because C 1. the logical was not defined in the first place C - The logical is still defined and a matching file is located. C cFound contains the first matching file name upon return C - The logical is still defined, but cFound = ' ', because C 2. no matching file name was found C 3. matching files were also found in the current directory C > If a matching file name is returned in cFound, then also iSetFileSpec C has been called to fill the parse structure. C C The following steps are taken to set the logical and test the wildcard: C >1 Translate the logical cLog C >2 If the logical is not defined, go to step 6 C >3 If the logical is defined then test the wildcard. C >4 If a match is found, RETURN, UNLESS the current directory is different C from the logical directory, and also contains matching files C >5 Undefine the logical (happens if the logical directory does not C contain matching files or the ambiguity with the current directory C arises (see previous step). C >6 RETURN if iPrompt=0 (cFound=' ', logical does not exist (anymore)) C >7 Test the wildcard in the default directory. If a match is found C offer it as the default choice for the directory prompt C >8 Prompt for directory until a match for the wildcard if found C >9 Set the logical to the selected directory C MODIFICATION HISTORY: C SEP-1992, Paul Hick (UCSD/CASS; pphick@ucsd.edu) C- integer iPrompt character cLog*(*) character cWild*(*) character cFound*(*) character cDat*120 character cDef*120 character cDefFound*120 character cMessage*120 character cSay*10 /'SetLog2Dir'/ iDat = iGetLogical(cLog,cDat) ! Translate logical cLog iDef = iGetDefaultDir(cDef) ! Current working directory cDef(iDef+1:) = cWild ! Check current directory if (iSearch(1,cDef,cDefFound) .ne. 1) cDefFound = ' ' cDef(iDef+1:) = ' ' if (iDat .eq. 0) then ! Logical not defined cFound = ' ' else ! Logical is defined if (cDat .eq. cDef) then ! Logical points to current dir cFound = cDefFound else ! Logical dir is not current dir cDat(iDat+1:) = cWild ! Check for wild card files if (iSearch(1,cDat,cFound) .ne. 1) cFound = ' ' cDat(iDat+1:) = ' ' end if !------- ! Return if matching files found in the logical dir (cFound .ne. ' ') and ! - the logical dir is also the current dir (cDat .eq. cDef) ! - or the current dir does not contain any matches (cDefFound .eq. ' ') if (cFound .ne. ' ' .and. (cDat .eq. cDef .or. cDefFound .eq. ' ')) then cMessage = cWild call Say(cSay,'I',cLog,cDat(:iDat)//' contains files matching '//cMessage) I = iSetFileSpec(cFound) ! Fills parse structure return end if !-------- ! Two possibilities remain at this point: ! - the logical dir does not contain matches (cFound .eq. ' ') ! - the logical dir contains matches (cFound .ne. ' '), ! but the current dir (not the same dir as the logical) does too. ! In this case, print message if (cFound .ne. ' ' .and. cDefFound .ne. ' ') then! Implies cDat .ne. cDef cMessage = cWild call Say(cSay,'I',cLog,cDat(:iDat)//' and default directory '//cDef & //'#both contain files matching '//cMessage(:itrim(cMessage))//': logical has been undefined') end if cFound = ' ' ! Make sure to clear cFound if (iPrompt .gt. 0) then ! Override deletion of logical I = iDeleteLogical(cLog) iDat = 0 end if end if ! Logical not defined if (iDat .eq. 0) then cMessage = cLog call Say(cSay,'W','NoTrans','no translation for logical name '//cMessage) end if !------- ! iPrompt = 2: logical does not exist, and cFound = ' ' ! iPrompt = -2: logical still exists, if it existed already; ! cFound = ' ', UNLESS both logical dir and current dir contain matches if (abs(iPrompt) .eq. 2) then ! No prompting; note that cFound = ' ' I = iSetFileSpec(cFound) ! Safety belt: clear parse structure return end if !------- ! At this point iPrompt=1 (prompting is required) and ! - either, the logical is not defined yet ! - or, the logical dir does not contain any matches ! - or, the logical dir and the current dir both contain matching files if (cDefFound .ne. ' ') then cMessage = cWild call Say(cSay,'I',cDef,' contains files matching '//cMessage) cDat = cDef else cDat = ' ' end if !------- ! Prompt for cLog directory. If the default directory contains the ! requested files, present it as the default choice. cMessage = 'Set '//cLog(:itrim(cLog))//' directory (0=Exit)$dir' !write (*,*) ' ' iDat = itrim(cDat) I = 0 do while (I .ne. 1) cDat(iDat+1:) = ' ' !I = iSwitchGraphicsOff() call AskChar(cMessage,cDat) if (cDat .eq. '0') call Say(cSay,'I','StopPlay','Exit') if (bOS__NotCaseSensitive) call uppercase(cDat) iDat = itrim(cDat) cDat(iDat+1:) = cWild I = iSearch(1,cDat,cFound) end do I = iSetFileSpec(cFound) I = iGetFileSpec(0,FIL__DIRECTORY,cDat) cMessage = cWild call Say(cSay,'I',cLog,cDat(:I)//' contains files matching '//cMessage) I = iSetLogical(cLog,cDat,'PROCESS') return end