character*4 eol integer*4 iol logical*1 nin(4) character buf*20, infile*50, outfile*50 equivalence (iol,eol) C ---------- note that SGI fortran works in 4-byte-words (isgi=4) C in which case this code will not work in the header length C is not a multiple of four bytes. C for these cases, use the C-code provided. C C most other fortrans can access single bytes (isgi=1) C and don't have this limitation C C Note that this code uses the shortest possible block size C and direct file access to make it compatible with the widest C possible range of files and compilers. This also makes it C very slow. Increasing the block size, or using 'flat' access C whenever possible will speed it, in many cases substantially. C ---------------------------------------------------------------------- * isgi=4 ! use this value for SGI fortran isgi=1 ! use for almost any other fortran iol=10*(1+256**3) ! define end-of-line character write(*,*) 'input file?' read(*,'(a50)') infile write(*,*) 'output file?' read(*,'(a50)') outfile open(1,file=infile,access='direct', recl=20/isgi) read(1,rec=1) buf i1=index(buf,'=') !check for = in HEADERLENGTH i2=index(buf,eol(4:4)) !check for end of line after length * write(*,*) 'i1=',i1,' i2=',i2,' buf=',buf(i1+1:i2-1) read(buf(i1+1:i2-1),'(i5)') lhead irec0=lhead/isgi ! note that this may fail if isgi=4 write(*,*) 'header length is =',lhead, irec0 if(mod(lhead,isgi).ne.0) stop 'header not multiple of word length' close(1) open(1,file=infile,access='direct', status='old',recl=1) open(2,file=outfile,access='direct', recl=1) if (isgi.eq.1) then do i=1,irec0 read (1,rec=i) nin(1) write(2,rec=i) nin(1) enddo i=irec0+1 read (1,rec=i,iostat=iend) nin(1) do while(iend.eq.0) do k=1,3 read (1,rec=i+k,iostat=iend) nin(k+1) if (iend.ne.0) then close(1) close(2) stop 'last word was incomplete' endif enddo do k=1,4 write(2,rec=i+4-k) nin(k) enddo i=i+4 read (1,rec=i,iostat=iend) nin(1) enddo else do i=1,irec0 read (1,rec=i) nin write(2,rec=i) nin enddo i=irec0+1 read (1,rec=i,iostat=iend) nin do while(iend.eq.0) write(2,rec=i) (nin(k),k=4,1,-1) i=i+1 read (1,rec=i,iostat=iend) nin enddo endif close(1) close(2) end