C+ C NAME: C ForeignArg C PURPOSE: C Get input from DCL command line invoking main program executable C CATEGORY: C Command line processing C CALLING SEQUENCE: subroutine ForeignArg(cSep,iVar,cVar,cArg) C INPUTS: C cSep character*1 Separator character used to delimit individual C arguments on command line C iVar integer maximum # of (cSep-separated) entries read C from command line into cVar C OUTPUTS: C iVar integer actual number of entries read into cVar C (after argument switches have been removed for C ForeignArg and ForeignArgs) C cVar character(iVar)*(*) C values of valid entries C cArg character*(*) values of argument switches (single string) C SEE ALSO: C ForeignInput, ForeignArgs C CALLS: C iOSGetForeign, uppercase, LocFirstLen, cInt2Str, itrim, cSay C INCLUDE: include 'dirspec.h' C RESTRICTIONS: C >>> The separator character cSep must be only one character long. C At most 500 characters are read from the DCL command line. C C > The function iOSGetForeign is a system dependent function. C Currently versions are available for VMS, NT and Unix/Linux. C > Only the first iVar elements of cVar and the first iArg elements of C cArg contain valid entries. C > No warning is given if # arguments on the command line exceed the C input values of iVar or iArg, or if they do not fit into the cArg C string (they will simply be ignored). C PROCEDURE: C > iOSGetForeign is used to read the argument list into the character*200 C string. The string is interpreted using the cSep character as delimiter. C > A switch begins at the character '/' and ends at the next cSep, blank or C '/'. All switches are concatenated and returned in cArg in the form C '/switch1/switch2/switch3'. Only non-zero length switches are stored. C > Non-switches are stored in the cVar array. C MODIFICATION HISTORY: C MAR-1995, Paul Hick (UCSD/CASS) C JUN-2006, Paul Hick (UCSD/CASS; pphick@ucsd.edu) C Added check for cSwitch followed by numeric char to escape C minus signs on Linux. C- character cSep integer iVar character cVar(iVar)*(*) character cArg*(*) character cStr*500 character cBlank /' '/ character cSay*10 /'ForeignArg'/ character cInt2Str*14 logical bArg logical bMessage nArg = len(cArg) bMessage = cVar(1) .ne. 'quiet' do I=1,iVar ! Clear output variables cVar(I) = ' ' end do cArg = ' ' I = iOSGetForeign(L,cStr) ! Get foreign input in cVar if (I*L .eq. 0) then iVar = 0 return end if if (bOS__NotCaseSensitive) call uppercase(cStr(:L)) bArg = .FALSE. ! bArg set .TRUE. if slash is found iArg = 0 ! Effective length of cArg string I = 0 ! Effective # cVar strings IP0 = 1 ! cStr has been processed upto IP0-1 do while (IP0 .le. L) IP1 = IP0-1+min(LocFirstLen(cSep ,cStr(IP0:L)), & LocFirstLen(cBlank ,cStr(IP0:L)), & LocFirstLen(cSwitch,cStr(IP0:L))) IP2 = IP1+1 !------- ! Check for cSwitch//cSwitch. ! This is used to indicate a single cSwitch character that should NOT be interpreted as a cSwitch. ! In addition, check for a cSwitch followed by a numeric char (probably a minus sign that ! should not be interpreted as a cSwitch. do while (IP1 .lt. L .and. (cStr(IP1:IP2) .eq. cSwitch//cSwitch .or. index('1234567890',cStr(IP2:IP2)) .ne. 0)) if (cStr(IP1:IP2) .eq. cSwitch//cSwitch) then cStr(IP2:) = cStr(IP2+1:) ! Remove the 2nd cSwitch L = L-1 ! Adjust cStr length end if IP1 = IP2 ! Position after 1st cSwitch IP1 = IP1-1+min(LocFirstLen(cSep ,cStr(IP1:L)), & LocFirstLen(cBlank ,cStr(IP1:L)), & LocFirstLen(cSwitch,cStr(IP1:L))) IP2 = IP1+1 end do ! Always IP1 >= IP0 if (IP1 .eq. IP0) then ! No chars preceding separator, blank or slash bArg = cStr(IP0:IP1) .eq. cSwitch ! Start of switch found else ! Non-zero length switch or cVar value if (bArg) then if (iArg .lt. nArg) then cArg(iArg+1:nArg) = cStr(IP0-1:IP1-1) ! Include slash preceding switch iArg = min(nArg,iArg+IP1-IP0+1) end if bArg = .FALSE. else if (I .lt. iVar) then I = I+1 cVar(I) = cStr(IP0:IP1-1) end if end if if (cStr(IP1:IP1) .eq. cSwitch) IP1 = IP1-1 end if IP0 = IP1+1 ! Position following last separator, blank or slash end do iVar = I if (bMessage .and. (iVar .ne. 0 .or. itrim(cArg) .ne. 0)) then call Say(cSay,'I','=','========') do I=1,iVar call Say(cSay,'I','Arg '//cInt2Str(I),cVar(I)(:itrim(cVar(I)))) end do if (itrim(cArg) .ne. 0) call Say(cSay,'I','key',cArg) call Say(cSay,'I','=','========') end if return end