* Thu Dec 16 13:55:33 EST 1993 /faraday/h1/ksg/src/test getunit.f C Thu Jun 13 11:08:23 EDT 1991 /faraday/h1/vgr/src/pls getunit * Thu Apr 25 09:35:36 EDT 1991 /leverrier/h1/ksg/src/test getunit.f c Thu Oct 20 13:20:37 EDT 1988 c 8mm tape added c Fri April 23, 1993 8mm treated as a 1/2 tape added subroutine getunit(namex,iunit,ju,il,ir,iff,stream,indpip,lltape) character*8 namex character*4 name integer iunit, iff, ju, il, ir include "vgrcom.i" c include "../include/vgrcom.i" ccc integer MAXUN parameter ( MAXUN=99 ) integer*4 stream(MAXUN), indpip(MAXUN+1) character*8 arn(MAXUN) integer i, n, j, ia(MAXUN), nf(MAXUN), iu integer ib( MAXUN) integer ltape(MAXUN),lltape character*128 filenamea(MAXUN), filenamet c data n /0/ integer istab( MAXUN) ccc gsgjr 13-08-09 shortened lin to stay in 72 col data nf /MAXUN*0/ data ia /MAXUN*0/ data ib /MAXUN*0/ data arn /MAXUN*' '/ c receives the name fo the file in name c and iunit = 1 for formated files and iunit = -1 for unformatted c opens file when necessary c returning fortran unit number in iunit (stores in ia) c (negative for unformatted c returns unit number in ju, stores in ib c ir ( nf) number of file in current dataset, if negative a tape. c il (j) index in array c iff = 1 normal, iff = 2 extend dataset with next file. c stream is pointer to pipe if formed c indpip is index to location of '|' in file name (note off set for c index) c 0 => no pipe, 1 => output pipe, >1 => input pipe c ltape = 1 for 1/2" tape, 2 for 8mm tape, 3 for 8mm treated same as 1/2" tape c on 1/2" tape logical records == physical records c on 8mm record count is is added at begining and end as it is on disk c environmental variable will be suffixed with a .l for 8mm to be treated as 1/2" ( fore literal) c if iunit is not specified set it to n+1 c write(6,2110) iunit 2110 format(' JWB I am in getunit ', I5) c write(6,2120) namex 2120 format(' namex ', A8) if (iunit .eq. 0) iunit=n+1 name = namex(1:4) j = 0 do 100 i=1,n j = i if ( name .eq. arn(i)) go to 1000 write(6,2121) i,name,arn(i) 2121 format(' in getunit do loop ',I5,2A20) 100 continue if (j .ge. MAXUN ) then write (0,*) 'too many bat files opened' write (0,*) 'too many bat files opened' call exit(10) end if j = j+1 arn(j) = name n = j c is this a fortran unit ?, if so find out which one. do 200 i=1,36 iu = i if ( name .eq. unitn(i)) go to 210 200 continue iu = 0 210 continue call getenv( name, filename) filenamea(j) = filename c check for vbs type files lfn = lnblnk( filename ) i = index( filename, '.L') if ( i .eq. lfn - 1 ) then c set flag for vbs record call batvbsi( j, 1) c and remove '.L' from file name filename(i:i+1) = ' ' lfn = lnblnk( filename ) end if c check for literal flag, only implimented for 8mm tapes i = index( filename, ".l") if ( ( i .eq. lfn - 1 ) .and. ( filename(1:5) .eq. "/dev/")) | then literal = 1 c and remove '.l' from file name filename(i:i+1) = ' ' lfn = lnblnk( filename ) else literal = 0 end if if ( filename .eq. 'stdin') then ia(j) = 5 ib(j) = 0 ltape(j) = 0 indpip(j+1) = -1 else if ( filename .eq. 'stdout') then ia(j) = 6 ib(j) = 1 ltape(j) = 0 indpip(j+1) = -2 else indpip(j+1) = index( filename, '|') end if if ( indpip(j+1) .eq. 0) then if ( iu .eq. 0) then iu = iunit/iabs(iunit) ia(j) = iu*(j + 100) c open file write(6,2341) name, ia(j), ib(j) 2341 format(' inition called from getunit',a8,' name is blank ',2i10 ) call inition (1, name, ia(j), ib(j)) else write(6,2342) ia(j), ib(j) 2342 format(' initio called from getunit',2i10 ) ia(j) = iu call initio( 1, ia(j), ib(j)) end if if ( filename(1:5) .eq. "/dev/") then if ((filename(6:8) .eq. "rmt") .or. | (filename(6:9) .eq. "nrmt")) then ltape(j) = 1 else if ((filename(6:8) .eq. "rst") .or. | (filename(6:8) .eq. "rsx") .or. | (filename(6:9) .eq. "nrsx") .or. | (filename(6:9) .eq. "nrst")) then if ( literal .eq. 1 ) then ltape(j) = 3 else ltape(j) = 2 end if end if else ltape(j) = 0 end if else if ( indpip(j+1) .gt. 1) then filenamet = filename 400 filenamet( indpip(j+1):indpip(j+1)) = ' ' indpipj = index( filenamet, "|") if (indpipj .gt. 0) then indpip(j+1) = indpipj go to 400 end if filename( indpip(j+1):indpip(j+1)) = ' ' call popenr( filename, j) else if ( indpip(j+1) .eq. 1) then filename( indpip(j+1):indpip(j+1)) = ' ' call popenw( filename, j) else if ( indpip(j+1) .eq. -1) then call popenrs( filename, j) else if ( indpip(j+1) .eq. -2) then call popenws( filename, j) end if end if 1000 continue c c If iunit is negative then remove name from arn list c if (iunit .lt. 0) then arn(j)=" " endif if (iff .eq. 1) then else if ( iff .eq. 2) then c indpip(j+1) = index( filename, '|') if ( indpip(j+1) .eq. 0 ) then c append next file to dataset nf(j) = nf(j) + 1 c send file number in ib c receive file discriptor in ib C ib(j) = nf(j) c unload tape call tbatoff( ib(j)) call initioex( 1, ia(j), ib(j)) if ( filename(1:5) .eq. "/dev/") then if ((filename(6:8) .eq. "rmt") .or. | (filename(6:9) .eq. "nrmt")) then ltape(j) = 1 else if ((filename(6:8) .eq. "rst") .or. | (filename(6:9) .eq. "nrst")) then ltape(j) = 2 else ltape(j) = 0 end if c loop till tape is loaded ccc gsgjr 113_08_09 istab declared integer array to satisfy fstat definition 1005 i = fstat( ia(j), istab) if ( i .eq. 0 ) go to 1010 i = 2 call sleep ( i) go to 1005 1010 continue else end if else c for the present we do not extend piped files ib(j) = -5 end if else return end if iunit = ia(j) ju = ib(j) il = j ir = nf(j) + 1 lltape = ltape(j) return end