c---------------------------------------------------------------- c This provides a safe version of getcwd, c that works with a variety of compilers. c c Note: len, len_trim, trim are standard on f90, but not c on older compilers. c c Authored by Aidan P. Thompson 8/31/01 c character*(*) function getpath() implicit none integer istatus,getcwd,ind0,ind1 c c This routine uses getcwd, which is not a fortran standard c It assumes the returned value of path is in one of two forms. c c a) path followed by all blanks c c b) path followed by a char(0) and then garbage, possibly blanks. c c To avoid overflow, we need len(getpath) >= length of path + 1 c do ind0 = 1,len(getpath) getpath(ind0:ind0) = char(0) end do istatus = getcwd(getpath) ind1=max(index(getpath,char(0)),index(getpath,' ')) do ind0 = ind1,len(getpath) getpath(ind0:ind0) = ' ' end do return end c---------------------------------------------------------------- c This demonstrates how to use getpath c to open a file using enfs: or else standard I/O c Authored by Aidan P. Thompson 8/31/01 c c You can compile it for CPlant machines c and run it using yod -sz 1, c or you can compile it for serial machines c (to test portability of getpath). c program enfs_test implicit none integer maxpathlen parameter (maxpathlen = 129) character dumpfile*32 character mypath*maxpathlen character getpath*maxpathlen logical Lenfs write(6,*) 'Do you want to use enfs:? (T/F)' read(5,*) Lenfs dumpfile = 'ldump_file' mypath = getpath() if (len_trim(mypath).eq.0) then write(6,*) 'getcwd failed' stop elseif(len_trim(mypath).eq.len(mypath)) then write(6,*) 'path too long' stop else if (Lenfs) then if (mypath(1:9).eq.'/enfs/tmp') then open (11,file='enfs:'//trim(mypath)//'/'//dumpfile, $ status='unknown') write(11,*) 'Hello enfs world' else write(6,*) 'enfs: only works on enfs filesystem' stop endif else open (11,file=trim(mypath)//'/'//dumpfile, $ status='unknown') write(11,*) 'Hello no-enfs world' endif endif stop end