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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problems with reading binary file

Status
Not open for further replies.

milenko76

Technical User
Mar 26, 2010
100
PT
I have this file,which is input for the program I am using.SO when I do od -h output I get:
milenko@hp6830s:~/Desktop/prog/fast/2d_example$ od -h fd01.picks
0000000 0000 1800 4040 0000 0000 0000 003f 0000
0000020 0000 0000 cc3c cdcc ffff ffff 0000 1800
0000040 0000 1800 803f 0000 0000 0000 233c 0ad7
0000060 e23e 0610 cc3c cdcc 0000 0100 0000 1800
0000100 0000 1800 0040 0000 0000 0000 233c 0ad7
0000120 6b3e 6112 cc3c cdcc 0000 0100 0000 1800
0000140 0000 1800 6040 0000 0000 0000 233c 0ad7
0000160 2f3e 1393 cc3c cdcc 0000 0100 0000 1800
How to interperet? What is the record length? Is it int*2 or what?I am using Intel 11.1 Linux Compiler.
 
It can be anything you want it to be. Have you been given a spec for the data?
 
No,actually I have made also similar input file from ASCII,but that one could not be read properly.
 
You could try it as 16 or 32 bit integers or 16 or 32 bit floats. For 16 bit integers, set the record length to 2, for 32 bit, set it to 4.
 
ASCII:
1.000 1.000 .020 .000 .000 -1
.000 1.000 .020 5.215 .050 1
0.250 1.000 .020 5.208 .050 1
0.500 1.000 .020 5.173 .050 1
0.750 1.000 .020 5.308 .050 1
1.000 1.000 .020 5.215 .050 1
These are just first six lines.Code:
character*72 ifname,ofname
c
write(*, fmt="(/'Enter input file name')")
read(5,85) ifname
85 format(a72)
write(*, fmt="(/'Enter output file name')")
read(5,85) ofname
open(unit=11, file=ifname, status='old')
open(unit=12, file=ofname, form='unformatted')
n=0
100 read(11,5, end=999) x,y,z,t,u,i
5 format(5f10.3,i3)
write(12) x,y,z,t,u,i
n=n+1
go to 100
999 write(6,1) n
1 format(/'number of lines in file: ',i10/)
stop
end
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top