subroutine fopen(iun,fnam,ostat) c c - opens file with name=fnam as unit = iun c - ostat can be 'OLD','NEW' of 'UNKNOWN' (default) c - format fill be FORMATTED unless iun is input as < 0 c - if open fails it will assume the name begins with a env. variable c and it will try to interpret the variable. eg. if you have defined c setenv data3 /home/pagoo3/data and you input 'data3/file.dat' c for fnam, then the open will first fail, then fixfnam will c replace fnam with '/home/pagoo3/data/file.dat' c The maximum number of characters in the full file name must be c less than 80. c - if ostat='NEW' and the open fails because fnam exists, then c fnam will be renamed fnam% and fnam will opened as 'NEW' c character fnam*(*),ostat*(*) character*100 newnam,savnam character*11 frmt frmt='FORMATTED' newnam=fnam if(ostat.eq.' ') ostat='UNKNOWN' if(iun.lt.0) then iun=iabs(iun) frmt='UNFORMATTED' endif open(iun,file=newnam,form=frmt,status=ostat,err=10) return 10 call fixfnam(newnam) open(iun,file=newnam,form=frmt,status=ostat,err=20,iostat=ios) return 20 if(ios.eq.117.or.ios.eq.1017) then ieeer=ieee_flags('clear','exception','all',out) savnam=newnam nl=notbnk(savnam,80)+1 savnam(nl:nl)='%' ii=rename(newnam,savnam) open(iun,file=newnam,form=frmt,status=ostat) ieeer=ieee_flags('clear','exception','all',out) else write(6,31) ios,newnam 31 format(' error ',i4,' opening, ', a) stop endif end subroutine fopen_dir(iun,fnam,ostat,ircl) c c - similar to fopen, but for direct access files c - does not have the rename on fail to open 'NEW' feature c character fnam*(*),ostat*(*) character*80 newnam character*11 frmt frmt='FORMATTED' newnam=fnam if(ostat.eq.' ') ostat='UNKNOWN' if(iun.lt.0) then iun=iabs(iun) frmt='UNFORMATTED' endif open(iun,file=newnam,access='direct',form=frmt, 1 status=ostat,recl=ircl,err=10) return 10 call fixfnam(newnam) open(iun,file=newnam,access='direct',form=frmt, 1 status=ostat,recl=ircl) return end