*i Thu Dec 16 15:00:12 EST 1993 /faraday/h1/ksg/src/test initio.f C#include c set up a common with largest and smallest valuse of numbers subroutine initio(n,ia,ib) integer n, ia(n), ib(n) c open n fortran files ia(i), i=1,n c the unit file descriptors will be returned in ib c if n > 1000 continue dataset with new file c JWB make all the file numbers positive do 3412 i = 1,n 3412 if (ia(i) < 0 ) ia(i) =-ia(i) ns = -1 nn = 1 c write (iout,"('calling initiox 1 ')") do 100 i=1,n call initiox( nn, ia(i), ib(i), ns) 100 continue return end C subroutine initio0(n,ia,ib) integer n, ia(n), ib(n) c same as init except will not stop if file is alredy open ns = -2 nn = 1 write (iout,"('calling initiox 2 ')") do 100 i=1,n call initiox( nn, ia(i), ib(i), ns) 100 continue return end C subroutine initioco(n,ia,ib) integer n, ia(n), ib(n) c same as init except will close the file if it is alredy open ns = -3 nn = 1 write (iout,"('calling initiox 3 ')") do 100 i=1,n call initiox( nn, ia(i), ib(i), ns) 100 continue return end C subroutine initiowr(n,ia,ib) integer n, ia(n), ib(n) c direct init printer output to fortran io unit n ns = -4 write (iout,"('calling initiox 4 ')") call initiox( n, ia, ib, ns) return end C subroutine inition (n,name,ia,ib) common /initcom/ junit, filen character*4 filen integer junit(36) character*8 name(n) integer ia(n), ib(n), i c opens n i/o files set by environmental variables name c ia return fortran unit numbers c ib returns unit unit numbers nn = 1 ns = -5 write (iout,"('calling initiox 5 ')") do 100 i=1,n filen = name(i) call initiox( nn, ia(i), ib(i), ns) 100 continue return end C subroutine initioex( n, ia, ib) c extends a i/o file by closing old extension and opening new one integer n, ia(n), ib(n), nn, ns ns = -6 nn = 1 write (iout,"('calling initiox 6 ')") do 100 i=1,n call initiox( nn, ia(i), ib(i), ns) 100 continue return end C subroutine initiocl( n, ia, ib) integer n, ia(n), ib(n), nn, ns ns = -7 nn = 1 write (iout,"('calling initiox 7 ')") do 100 i=1,n call initiox( nn, ia(i), ib(i), ns) 100 continue return end C subroutine initiot(n,ia,ib,filena) character*8 filena include "vgrcom.i" integer n, ia(n), ib(n) c open n fortran files ia(i), i=1,n, with unique names c the unit file descriptors will be returned in ib c if n > 1000 continue dataset with new file ns = -8 nn = 1 write (iout,"('calling initiox 8 ')") do 100 i=1,n filename(1:8) = filena(1:8) call initiox( nn, ia(i), ib(i), ns) 100 continue return end C subroutine initiox(n,iai,ibi,ns) common /initcom/ junit, filen include "vgrcom.i" character*4 filen integer junit(36) integer n, iai, ibi real*8 dflmax, dflmin real flmax, flmin ccc gsgjr 13_08_09 removed ',' ccc integer, inmax integer inmax integer in, iout logical linit character*12 form(2) character*12 unitne character*2 chnum(99) integer num(36), numi integer get_fd logical ls integer ipreset equivalence (ipreset,preset) data form /'formatted','UNformated'/ data linit /.false./ data iout /0/ data chnum | /'1 ','2 ','3 ','4 ','5 ','6 ','7 ','8 ','9 ','10' | ,'11','12','13','14','15','16','17','18','19','20' | ,'21','22','23','24','25','26','27','28','29','30' | ,'31','32','33','34','35','36','37','38','39','40' | ,'41','42','43','44','45','46','47','48','49','50' | ,'51','52','53','54','55','56','57','58','59','60' | ,'61','62','63','64','65','66','67','68','69','70' | ,'71','72','73','74','75','76','77','78','79','80' | ,'81','82','83','84','85','86','87','88','89','90' | ,'91','92','93','94','95','96','97','98','99'/ ccc gsgjr 13 11 21 data statment to avoid lack of dflmax() in GCC real*8 dmaxdbM, dmindbM real*4 amaxfM, aminfM integer*4 imaxinS, imininS integer*2 i2maY, i2miO ccccc data dmakdbl /1.79769d+308/, dmindbl /2.22507d-308/ ccccc data amaxfM /3.40282e+38/, aminfl /1.17549e-38/ ccccc data i2maY /32767/, i2min /-32768/ ccccc data imaxinS /2147483647/, iminint /-2147483648/ cccccccc dmaxdbM = dflmax() cccccccc dmindbl = dflmin() cccccccc amaxfM = flmax() cccccccc aminfl = flmin() cccccccc imaxinS = inmax() cccccccc iminint = -imaxinS data num /36*0/ c write (iout,"('just starting in initiox ')") c write (iout, 2190) n,ns,iai,ibi 2190 format(4I10) if (linit) go to 100 linit = .true. dmaxdbM = 1.79769d+308 dmindbM = 2.22507d-308 amaxfM = 3.40282e+38 aminfM = 1.17549e-38 i2maY = 32767 i2miO = -32768 imaxinS = 2147483647 imininS = -2147483647 ccccc dsqmax = dsqrt(dmaxdbM) fsqmax = sqrt(amaxfM) c preset is NaN ipreset = -1 C preset needs to be a number so test can be done on it preset = fsqmax 100 continue c if ( ns .eq. -4) then iout = n return end if ls = ns .eq. -1 .or. ns .eq. -8 c extend dataset if (ns .eq. -6) go to 2000 c close dataset if (ns .eq. -7) go to 1500 iunit = iabs(iai) if (iunit .lt. 100) then c open numbered unit if ( lopen(iunit)) then if (ls) then go to 1005 else if (ns .eq. -2) go to 1020 close(iunit,err=200) 200 continue end if end if lopen(iunit) = .true. lform(iunit) = iai .eq. iunit c lform(iunit) = .t. implies formatted file c iai positive implies formatted file in = 2 if (lform(iunit)) in = 1 filen = unitn(iunit) else c open named unit in=+1 formatted, in=-1 unformatted in = (iai+iabs(iai))/(2*iabs(iai)) + 1 end if if ( ns .eq. -8 ) then call gettemp( filename ) else call getenv( filen, filename) end if lfn = lnblnk( filename ) i = index( filename, ".L") if ( i .eq. lfn - 1 ) then filename( i:i+1) = ' ' lfn = lnblnk( filename ) end if i = index( filename, ".l") if ( ( i .eq. lfn - 1 ) .and. ( filename(1:5) .eq. "/dev/")) | then filename( i:i+1) = ' ' lfn = lnblnk( filename ) end if indpip = index( filename, '|') 210 if (indpip .eq. 0) then if (filename .eq. 'stdin') then lopen(iunit) = .true. ibi = 0 if ( ns .gt. -4) junit( iunit) = ibi iunit = 5 iai = iunit else if (filename .eq. 'stdout') then lopen(iunit) = .true. ibi = 1 if ( ns .gt. -4) junit( iunit) = ibi iunit = 6 iai = iunit else if (in .eq. 1 ) then open( iunit,file=filename,form=form(1),iostat=iostat) else open( iunit,file=filename,form=form(2),iostat=iostat) end if else if (indpip .ge. 1) then filename( indpip:indpip) = ' ' C pipe will be opened by getunit called from bat return end if if (iostat .eq. 0) go to 1010 if (filename(1:8) .eq. "/dev/rmt") then close( iunit) write ( iout,*) " waiting for tape drive ",filename call sleep (10) go to 210 end if c JWB write (iout,"('am I there? ')") write (iout,"('1 error trying to open unit',i4,', on file ',a48,' | , iostat = ',i5)") | iai, filename,iostat call exit ( 1) 1005 continue write (iout,'(" file number ",i4," already open")' ) iai call exit ( 1) 1010 continue ibi = -3 ccc gsgjr 13_11_17 keeping statements to col 1-72 write (iout,"('file',2x,a4,', number',i4,' opened on file ',a80, | ' form ' ,a12,', iostat =',i3)") | filen, iunit, filename,form(in),iostat ibi = -2 ibi = get_fd( iunit) if ( ns .gt. -4) junit( iunit) = ibi if (ibi .ne. -1) go to 1020 ccc gsgjr 13_08_09 to keep line in 72 col ccc write (iout,"(' file number',i3,' could not get file descriptor')") iai write(iout,"('file number',i3, | ' could not get file descriptor')") iai call exit ( 1) 1020 continue return 1500 continue c close file iunit = iabs(iai) close( iunit, err=1550) 1550 continue lopen( iunit) = .false. return c c to continue a file after an end of data. i.e. 2*eof 2000 continue iunit = iabs(iai) c we continue only one file at a time for now if (iunit .lt. 100) then c numbered file filen = unitn(iunit) num(iunit) = num(iunit) + 1 numi = num(iunit) c lform(iunit) = .t. implies formatted file c iai positive implies formatted file in = 2 if (lform(iunit)) in = 1 if (lopen(iunit)) then close( iunit, err= 2100) else ibi = -2 return end if else c named file numi = ibi in = (iai+iabs(iai))/(2*iabs(iai)) + 1 close( iunit, err= 2100) end if c open named unit unitne = filen // "f" // chnum(numi) call getenv( unitne, filename) if ( filename .eq. "") then ibi = -1 return end if 220 if (in .eq. 1 ) then open( iunit,file=filename,form=form(1),iostat=iostat) else open( iunit,file=filename,form=form(2),iostat=iostat) end if ibi = get_fd( iunit) if (iostat .eq. 0) go to 2110 if (filename(1:8) .eq. "/dev/rmt") then close ( iunit) write ( iout,*) " waiting for tape drive ",filename call sleep (10) go to 220 end if 2100 continue if ((iunit .le. 36) .and. (iunit .gt. 0)) then write (iout, | "(' file number ', i3,' has error on continueing image num',i3)") | iai,num(iunit) else write (iout, | "(' file number ', i3,' has error on continueing iunit num',i3)") | iai,iunit end if ibi = -3 return 2110 continue write (iout,"(' file number',i3,', extent num',i3, | ', on file ',a40,' iostat =',i3)") iunit,numi,filename, iostat return end C subroutine initiotst( n, ia, ib) integer i, n, ia(n), ib(n) include "vgrcom.i" common /initcom/ junit, filen character*4 filen integer junit(36) do 100 i=1,n if ( lopen( ia(i)) ) then ib(i) = junit(ia(i)) else ib(i) = -1 end if 100 continue return end c to force loading of block data subroutine oidummyioio call iodummyio end