C+ C NAME: C iOSGetForeign C CATEGORY: C Machine-dependent functions: Linux, Unix C PURPOSE: C Get command line arguments as single string C CALLING SEQUENCE: function iOSGetForeign(L,cStr) C INPUTS: C (none) C OUTPUTS: C cStr character*(*) command line string C L integer useful length of cStr (=itrim(cStr)) C iOSGetForeign integer 0: no command line string (--> L=0) C 1: command line string present (L > 0) C CALLS: C itrim C PROCEDURE: C NARGC returns the number of command line arguments. C These are picked up with GETARG and strung together in cStr C MODIFICATION HISTORY: C SEP-1999, Paul Hick (UCSD/CASS; pphick@ucsd.edu); Added documentation C- integer L character cStr*(*) N = IARGC() L = 0 cStr = ' ' do I=1,N if (L .ne. 0) L = L+1 call GETARG(I,cStr(L+1:)) L = itrim(cStr) end do iOSGetForeign = min(L,1) return end C+ C NAME: C iOSSpawnCmd C PURPOSE: C Execute a single shell command C CATEGORY: C Machine-dependent functions: Linux, Unix C CALLING SEQUENCE: function iOSSpawnCmd(Cmd,iNoWait) C INPUTS: C Cmd character*(*) shell command C iNoWait integer (not used; kept for compatibility with VMS) C OUTPUTS: C iOSSpawnCmd integer 0: error executing command C 1: command executed succesully C CALLS: C itrim C PROCEDURE: C The error status is determined from the return value of the SYSTEM call. C Under NT the command string should include the prefix 'cmd /c'. C MODIFICATION HISTORY: C SEP-1999, Paul Hick (UCSD/CASS; pphick@ucsd.edu); Added documentation C- character Cmd*(*) integer iNoWait integer SYSTEM iOSSpawnCmd = itrim(Cmd) if (iOSSpawnCmd .gt. 0) then if (SYSTEM(Cmd) .eq. 0) then iOSSpawnCmd = 1 else iOSSpawnCmd = 0 end if end if return end C+ C NAME: C OSExitCmd C PURPOSE: C Terminate program execution. Set an exit code for external use C Current status: disfunctional C CATEGORY: C Machine-dependent functions: Linux, Unix C CALLING SEQUENCE: subroutine OSExitCmd(Cmd,iCode) C INPUTS: C Cmd character*(*) shell command passed to SYSTEM C iCode integer error code passed to EXIT function C OUTPUTS: C (none) C INCLUDE: include 'filparts.h' include 'dirspec.h' C CALLS: C bGetLun, iFilePath, itrim C PROCEDURE: C > The shell command string is written into a file OSExitCmd.tmp in the C $temp directory (if it is not an empty string). In principle the calling C shell could take some action by reading the file. C > The main purpose of this subroutine is to set an exit code to be checked C by a script or command procedure. This is done using the EXIT function. C MODIFICATION HISTORY: C SEP-1999, Paul Hick (UCSD/CASS; pphick@ucsd.edu); Added documentation C- character Cmd*(*) integer iCode character cFile*(FIL__LENGTH) logical bGetLun iCmd = itrim(Cmd) if (iCmd .gt. 0) then if (bGetLun(iU,cTemp)) then ! Get logical unit number I = iFilePath(cTemp,0,' ','OSExitCmd.tmp',cFile) open (iU, file=cFile, status='UNKNOWN') write (iU,'(A)') Cmd(:iCmd) iU = iFreeLun(iU) ! Close file end if end if c I = mod(iCode,2) I = iCode call exit(I) return end C+ C NAME: C iOSGetDirectory C PURPOSE: C Get a fully-qualified directory name, incl. drive and directory C CATEGORY: C Machine-dependent functions: Linux, Unix C CALLING SEQUENCE: function iOSGetDirectory(cDir) C INPUTS: C cDir character*(*) (incomplete) directory name C OUTPUTS: C cDir character*(*) complete directory name, C incl. trailing backslash C iOSGetDirectory integer 0: if GETCWD failed C 1: if GETCWD succesful C CALLS: C itrim C INCLUDE: include 'dirspec.h' C RESTRICTIONS: C Do NOT call this function directly. Instead use iSearch. C PROCEDURE: C Input is passed to GETCWD. Then a trailing (back)slash is C appended if necessary. C MODIFICATION HISTORY: C SEP-1999, Paul Hick (UCSD/CASS; pphick@ucsd.edu); Added documentation C- character cDir*(*) integer GETCWD if (GETCWD(cDir) .eq. 0) then I = itrim(cDir) if (cDir(I:I) .ne. cTrail) cDir(I+1:) = cTrail ! Return with trailing backslash iOSGetDirectory = 1 else iOSGetDirectory = 0 end if return end C+ C NAME: C iOSCheckDirectory C PURPOSE: C Check whether a directory exists C CATEGORY: C Machine-dependent functions: Linux, Unix C CALLING SEQUENCE: function iOSCheckDirectory(cDir) C INPUTS: C cDir character*(*) (incomplete) directory name C OUTPUTS: C cDir character*(*) if the directory exists, a (back)slash is added C if it is not there already; if it does not exist C the input value is returned unmodified C iOSCheckDirectory C integer 0: directory does not exist C 1: directory exists C INCLUDE: include 'filparts.h' include 'dirspec.h' C RESTRICTIONS: C Do NOT call this function directly. Instead use iSearch. C PROCEDURE: C Existence of the directory is tested by changing directory C using CHDIR and checking its exit status. The current directory C is saved using GETCWD and is restored before returning. C There is an alternative way to check wheter a directory exists: C iDir = itrim(cDir) C bStatus = bOSFind(1,cDir(:iDir-1),1,cNamTmp) C This involves spawning a subprocess. C MODIFICATION HISTORY: C SEP-1999, Paul Hick (UCSD/CASS; pphick@ucsd.edu); Added documentation C- character cDir*(*) character cOld*(FIL__LENGTH) integer CHDIR integer GETCWD iOSCheckDirectory = 0 if (GETCWD(cOld) .eq. 0) then if (CHDIR(cDir) .eq. 0) then I = itrim(cDir) if (cDir(I:I) .ne. cTrail) cDir(I+1:) = cTrail iOSCheckDirectory = 1 end if ! Return with trailing backslash if (CHDIR(cOld) .ne. 0) iOSCheckDirectory = 0 end if return end C+ C NAME: C iOSSetDirectory C PURPOSE: C Change to a new working directory C CATEGORY: C Machine-dependent functions: Linux, Unix C CALLING SEQUENCE: function iOSSetDirectory(cDir) C INPUTS: C cDir character*(*) (incomplete) directory name C OUTPUTS: C iOSSetDirectory C integer 0: change of directory failed C 1: change of directory successful C RESTRICTIONS: C Do NOT call this function directly. Use iSetDefaultDir.. C PROCEDURE: C Input is passed unmodified to CHDIR. Return status is C determined from CHDIR exit status. C MODIFICATION HISTORY: C SEP-1999, Paul Hick (UCSD/CASS; pphick@ucsd.edu); Added documentation C- character cDir*(*) integer CHDIR if (CHDIR(cDir) .eq. 0) then iOSSetDirectory = 1 else iOSSetDirectory = 0 end if return end C+ C NAME: C iOSDeleteFile C PURPOSE: C Delete a file C CATEGORY: C Machine-dependent functions: Linux, Unix C CALLING SEQUENCE: function iOSDeleteFile(cFile) C INPUTS: C cFile character*(*) file to be deleted C OUTPUTS: C iOSDeleteFile integer 0: delete failed C 1: delete successful C PROCEDURE: C Input is passed unmodified to UNLINK. Return status is determined C from UNLINK exit status. C MODIFICATION HISTORY: C SEP-1999, Paul Hick (UCSD/CASS); Added documentation C SEP-2001, Paul Hick (UCSD/CASS; pphick@ucsd.edu) C Changed call to UNLINK from subroutine call to function call. C The Absoft f. Linux compiler insists on function call; g77 C accepts both. C- character cFile*(*) integer UNLINK if (UNLINK(cFile) .eq. 0) then iOSDeleteFile = 1 else iOSDeleteFile = 0 end if return end C+ C NAME: C iOSRenameFile C PURPOSE: C Rename a file C CATEGORY: C Machine-dependent functions: Linux, Unix C CALLING SEQUENCE: function iOSRenameFile(cFile1,cFile2) C INPUTS: C cFile1 character*(*) file to be renamed C cFile2 character*(*) new file name C OUTPUTS: C iOSRenameFile integer 0: rename failed C 1: rename successful C PROCEDURE: C Input is passed unmodified to RENAME. Return status is determined C from RENAME exit status. C MODIFICATION HISTORY: C SEP-1999, Paul Hick (UCSD/CASS); Added documentation C SEP-2001, Paul Hick (UCSD/CASS; pphick@ucsd.edu) C Changed call to RENAME from subroutine call to function call. C The Absoft f. Linux compiler insists on a function call; g77 C accepts both. C- character cFile1*(*) character cFile2*(*) integer RENAME if (RENAME(cFile1,cFile2) .eq. 0) then iOSRenameFile = 1 else iOSRenameFile = 0 end if return end C+ C NAME: C iOSCopyFile C PURPOSE: C Copies a file C CATEGORY: C Machine-dependent functions: Linux, Unix C CALLING SEQUENCE: function iOSCopyFile(cFile1,cFile2) C INPUTS: C cFile1 character*(*) file to be copied C cFile2 character*(*) new file name C OUTPUTS: C iOSCopyFile integer 0: copy failed C 1: copy successful C CALLS: C itrim, Str2Str, iSearch C INCLUDE: include 'filparts.h' include 'dirspec.h' C PROCEDURE: C Roundabout way of copying a file by passing a C a cp command to the SYSTEM procedure. C MODIFICATION HISTORY: C SEP-1999, Paul Hick (UCSD/CASS; pphick@ucsd.edu); Added documentation C- character cFile1*(*) character cFile2*(*) character cStr1*(FIL__LENGTH) character cStr2*(FIL__LENGTH) integer SYSTEM integer Str2Str iOSCopyFile = 0 if (iSearch(1,cFile2,cStr1) .eq. 1) return if (cOpSys .eq. OS__DOS) then cStr2 = 'cmd /c copy' else cStr2 = 'cp' end if I = itrim(cStr2)+1 I = I+Str2Str(cFile1,cStr2(I+1:)) I = I+1 I = I+Str2Str(cFile2,cStr2(I+1:)) I = SYSTEM(cStr2) if (iSearch(1,cFile2,cStr1) .ne. 1) return iOSCopyFile = 1 return end C+ C NAME: C iOSProtect C PURPOSE: C Modify protection of a file C CATEGORY: C Machine-dependent functions: Linux, Unix C CALLING SEQUENCE: function iOSProtect(cFile,iProt,iCode) C INPUTS: C cFile character*(*) file to be protected C iProt integer not used C iCode integer not used C OUTPUTS: C iOSProtect integer always 1 C PROCEDURE: C NOT IMPLEMENTED C MODIFICATION HISTORY: C SEP-1999, Paul Hick (UCSD/CASS; pphick@ucsd.edu); Added documentation C- character cFile*(*) integer*2 iProt integer iCode iOSProtect = 1 return end