C+ C NAME: C libarg C PURPOSE: C Extract command line switches from foreign input strings C CALLING SEQUENCE: program libarg C INPUTS: C Foreign input from command line C If not foreign input is provided the symbol array P1,..,P8 is processed C OUTPUTS: C To local symbols P1,..,P8 and ARG, or to local symbols specified C as command line arguments C CALLS: C ForeignInput, itrim, iGetSymbol,iSetSymbol,Say C RESTRICTIONS: C > The individual entries in the foreign input should not exceed 20 chars C PROCEDURE: C On VMS: C $ $EXE:LIBARG SYMBOL1 SYMBOL2 ..... C > After the switches have been removed, the remaining strings are put C sequentially into P1,..,P8 until no strings remain. Trailing values C in the P'I symbol array that do not receive any string are explicitly C set to the zero-length string. C > A switch is identified by looking for the character '/' C > Switches are extracted and stored in the symbol ARG C > The '/' is part of the switch C MODIFICATION HISTORY: C JUN-1994, Paul Hick (UCSD) C- parameter (nVar = 8) ! Array for foreign input character cName (nVar)*50 character cValue(nVar)*50 parameter (nArg = 100) character cArg*(nArg) character cc*8 logical bShift !------- Get symbol names on command line iVar = nVar call ForeignInput(' ',iVar,cName) bShift = iVar .eq. 0 if (iVar .eq. 0) then ! No symbols provided as foreign input: iVar = 8 ! .. check P1,...,P8 cc = '12345678' do I=1,iVar cName(I) = 'P'//cc(I:I) J = iGetSymbol(cName(I),cValue(I)) end do else ! Check symbols provided as foreign input do I=1,iVar J = iGetSymbol(cName(I),cValue(I)) end do end if !------- ! The first iVar entries of the cName array contain the names of (local) symbols iArg = 0 do I=1,iVar ! Loop over all symbols iSlash1 = index(cValue(I),'/') ! Position of slash do while (iSlash1 .ne. 0) ! While slash present L = itrim(cValue(I)) ! Find position of 2nd slash iSlash2 = iSlash1+index(cValue(I)(iSlash1+1:),'/') ! If no 2nd slash, set to end of string if (iSlash2 .eq. iSlash1) iSlash2 = L+1 if (iSlash2-iSlash1 .gt. 1) then! Length of switch (includes leading slash) if (iArg+iSlash2-iSlash1 .gt. nArg) call Say('LIBARG','E','nArg','parameter too small') cArg(iArg+1:) = cValue(I)(iSlash1:iSlash2-1) ! Extract switch iArg = iArg+iSlash2-iSlash1 ! Accumulated length of switches end if ! Remove switch from input string if (iSlash1 .eq. 1) then ! 1st char is slash if (iSlash2 .eq. L+1) then ! Whole string part of switch: nothing left cValue(I) = ' ' else ! Extract remaining part of input string cValue(I) = cValue(I)(iSlash2:) end if else ! 1st char is not a slash if (iSlash2 .eq. L+1) then !cValue(I) = cValue(I)(:iSlash1-1) cValue(I)(iSlash1:) = ' ' else !cValue(I) = cValue(I)(:iSlash1-1)//cValue(I)(iSlash2:) cValue(I)(iSlash1:) = cValue(I)(iSlash2:) end if end if iSlash1 = index(cValue(I),'/') ! Find next slash end do end do iP = 0 do I=1,iVar ! Set local symbols if (.not. bShift .or. itrim(cValue(I)) .ne. 0) then iP = iP+1 call iSetSymbol(cName(iP),cValue(I),1) end if end do cc = ' ' do I=iP+1,iVar ! Remaining symbols set to zero-length string call iSetSymbol(cName(I),cc,1) end do call iSetSymbol('ARG',cArg,1) end