Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Write line delimiter question

Status
Not open for further replies.

Holywhippet

Programmer
Jul 10, 2005
2
AU
I'm trying to help someone else at work by writing a program for them. They use a Fortran program to analyse certain datasets. They need the data in a certain format though. The data being processed are raster images. The format the data needs to be in starts with 7 numbers, these are the X min and max, the Y max and min, the width of each cell, the height of each cell and the number value for "no data" cells. After this, the actual data is written. It as stored in a series of rows. The data file is all in binary format rather than ASCII format.

If you don't follow, don't worry. The point is, the code writes each line of data with the following commands:

do i=1,m
write (30) (a(i,j),j=1,n)
enddo

where n is the width of the array and m is the height. This writes a series of numbers into the file, in this case they are 4 byte real numbers. However, each row of numbers has a 4 byte delimiter at the start and end of each line. The delimiter isn't a constant though. It is the same throughout each output file, but if I give it different input data the delimiter is different. I assume it has some relationship to the data being outputted like the number of columns but the exact line escapes me.

I am using the Force 2.0.7 compiler for this. To help me, I've been given a program that converts and equivalent file in ASCII format into the binary format. The ASCII format version has the first 7 numbers comma delimited then each row of numbers comma delimited and written on a different line. The full source code for this program is as follows:

c program erm_read.for
c Written by Zhiqun Shi, 23rd July 1994
c Revised 2nd August 1994, 31st August 1994, 2nd September
c The function of this program is to read a head of ermapper data file,
c then to determine the coordinate origin of the set of data, spacing
c interval and cell numbers of easting and northing.


character infile*40,outfile*40
Real a(3000000)

print *,' Input file name of grid data ='
read (5,100) infile
print *,' Input the output file name of grid data ='
read (5,100) outfile
100 format(a40)
open(unit=20,file=infile,status='old',form='formatted')
open(unit=30,file=outfile,status='new',form='unformatted')
print *,'Start Reading'
read(20,*) xmin,xmax,ymin,ymax,dx,dy,spec
m=nint((ymax-ymin)/dy)
n=nint((xmax-xmin)/dx)
print *,' xmin=',xmin
print *,' xmax=',xmax
print *,' ymin=',ymin
print *,' ymax=',ymax
print *,' dx=',dx
print *,' dy=',dy
print *,' spec=',spec
print *,' The total number of rows, m=',m
print *,' The total number of columns, n=',n



write (30) xmin,xmax,ymin,ymax,dx,dy,spec
Call data_input(a,m,n)
print *, 'Finish output data'
Stop
End

subroutine data_input(a,m,n)
real a(m,n)
do i=1,m
read (20,*) (a(i,j),j=1,n)
enddo
rewind 20
close (unit=20)

do i=1,m
write (30) (a(i,j),j=1,n)
enddo
rewind 30

close (unit=30)
return
end
 
Don't worry. I got it. It's the number of bytes each line uses.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top