The tasks which a data extraction routine must accomplish were discussed in Sec. 2. A sample routine that completes these tasks is the wrtraw routine which follows:
C.....Subroutine to write raw output files. 1 subroutine wrtraw(nframe,istart,iend,ihop,jstart,jend,jhop, 2 & base,field,ilead,xmax) 3 implicit real (a-h,o-z) 4 real field(ilead,*) 5 character filnam*1024, base*(*), frmt*30 6 C..... 7 C Local variables: 8 C frmt = internal file used to construct output file name 9 C ilen = number of non-blank characters in the base name 10 C idum,jdum = dummy loop counters 11 C ipnt = record pointer for output file 12 C ndigit = number of digits in current frame number 13 C Input variables: 14 C field,ilead = two dimensional array with leading dimension ilead 15 C base = base name of output files 16 C nframe = frame number (assumed set by calling program) 17 C istart,jstart = starting column and row for output 18 C iend,jend = ending column and row for output 19 C ihop,jhop = column and row strides 20 C Output variable: 21 C xmax = largest absolute value of output 22 C..... 23 C.....Determine the location of last character in the base name. 24 ilen = index(base,' ') - 1 25 C.....Calculate the number of digits in the current frame number. 26 ndigit = log10(real(nframe)+0.01) + 1 27 C.....Construct the proper format for the desired output file name. 28 write(frmt,'(a2,i4,a5,i9,a1)')'(a',ilen,',a1,i',ndigit,')' 29 C.....Put this together to obtain the proper output file name. 30 write(filnam,frmt)base,'.',nframe 31 C.....Open the output file and write header info. 32 open(68,file=filnam,status='new',form='unformatted', 33 & access='direct',recl=4,err=2000) 34 write(68,rec=1)real((iend-istart)/ihop + 1) 35 write(68,rec=2)real((jend-jstart)/jhop + 1) 36 C..... 37 C Loop through writing of data. The first entry is for the upper 38 C left corner, the next is for the next column over, etc. 39 C..... 40 ipnt=2 41 do 20 jdum=jend,jstart,-jhop 42 do 10 idum=istart,iend,ihop 43 ipnt=ipnt + 1 44 if(abs(field(idum,jdum)).gt.xmax)xmax=abs(field(idum,jdum)) 45 write(68,rec=ipnt)field(idum,jdum) 46 10 continue 47 20 continue 48 close(68) 49 return 50 2000 write(6,*)'Error opening output file in wrtraw.' 51 stop 52 end 53
First, wrtraw opens an output file whose name is the base name base with the frame number nframe appended. We do not want to unreasonably restrict the length of the base name and hence assume it can have an arbitrary length (in practice, the code requires the length to be slightly less that 1024 characters). This fact necessitates the use of code which is somewhat obscure (ref. lines 25-31) to construct the output file name. The key is to understand the use of Fortran internal files and to recognize the role the internal file frmt plays in the construction of a format statement. Despite this bit of arcane code, the rest should be fairly self-explanatory.
Note that the output file is opened as an unformatted file in order to store values in binary form. Although binary storage is not essential, it can greatly reduce the size of the output file. The record length here is set to four which typically means four bytes, i.e., the usual number of bytes in a single precision floating point number. Unfortunately, some compilers interpret the record length differently. For example, the Digital Equipment Corporation Fortran compiler assumes the record length specifies the number of four-byte blocks. Hence, for these compilers the appropriate record length would be one. Machines, such as Crays, that use 64 bit words may require modification of this code. As a last resort, ASCII storage can be used, but this greatly increases the space needed to store results and would require the modification of the rw2pnm routine to permit the reading of ASCII input. (Since one typically deals with ASCII data, these simple changes are not presented here.)