- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have one binary file(Sun Sparc) and now I want to convert it to ascii.Part of hex dump
0000000 0000 1800 0000 0000 0000 0000 0000 0000
0000010 0000 0000 0000 0000 ffff ffff 0000 1800
0000020 0000 1800 003f 0000 0000 0000 233c 0ad7
0000030 0000 0000 233c 0ad7 0000 0100 0000 1800
0000040 0000 1800 803f 0000 0000 0000 233c 0ad7
0000050 0000 0000 233c 0ad7 0000 0100 0000 1800
0000060 0000 1800 c03f 0000 0000 0000 233c 0ad7
0000070 0000 0000 233c 0ad7 0000 0100 0000 1800
0000080 0000 1800 0040 0000 0000 0000 233c 0ad7
0000090 0000 0000 233c 0ad7 0000 0100 0000 1800
00000a0 0000 1800 2040 0000 0000 0000 233c 0ad7
00000b0 0000 0000 233c 0ad7 0000 0100 0000 1800
00000c0 0000 1800 4040 0000 0000 0000 233c 0ad7
00000d0 0000 0000 233c 0ad7 0000 0100 0000 1800
00000e0 0000 1800 6040 0000 0000 0000 233c 0ad7
00000f0 0000 0000 233c 0ad7 0000 0100 0000 1800
0000100 0000 1800 8040 0000 0000 0000 233c 0ad7
0000110 0000 0000 233c 0ad7 0000 0100 0000 1800
0000120 0000 1800 9040 0000 0000 0000 233c 0ad7
0000130 0000 0000 233c 0ad7 0000 0100 0000 1800
0000140 0000 1800 a040 0000 0000 0000 233c 0ad7
0000150 0000 0000 233c 0ad7 0000 0100 0000 1800
0000160 0000 1800 b040 0000 0000 0000 233c 0ad7
0000170 0000 0000 233c 0ad7 0000 0100 0000 1800
0000180 0000 1800 c040 0000 0000 0000 233c 0ad7
0000190 0000 0000 233c 0ad7 0000 0100 0000 1800
00001a0 0000 1800 d040 0000 0000 0000 233c 0ad7
00001b0 0000 0000 233c 0ad7 0000 0100 0000 1800
00001c0 0000 1800 e040 0000 0000 0000 233c 0ad7
00001d0 0000 0000 233c 0ad7 0000 0100 0000 1800
00001e0 0000 1800 f040 0000 0000 0000 233c 0ad7
00001f0 0000 0000 233c 0ad7 0000 0100 0000 1800
0000200
How should I read this file?
open(10,file='rec.in',status='old',form='unformatted',CONVERT='BIG_ENDIAN')
I am confused because of this header and trailer issues.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, CONVERT='BIG_ENDIAN' should work. It will byte-swap the record lengths.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
program p1
implicit none
real,dimension(2400) :: v
integer ::irec
inquire (iolength = irec) v(1)
write(*,*)irec
open(10,file='rec.in',status='old',form='formatted',CONVERT='BIG_ENDIAN')
read(10,*)v
end
My code,but I got
1
forrtl: severe (59): list-directed I/O syntax error, unit 10, file /home/milenko/Downloads/fast/2d_example_linux/rec.in
Why?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You want form='unformatted' and "read(10)", not "read (10,*)". List-directed is not unformatted.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Works fine but I got now some absurd values in my txt putput file.
If I suppose that each record contains 5 reals and one integer how should my read statement look like?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
read (10) A,B,C,D,E,J
Assuming A,B,C,D and E are declared REAL and J is declared INTEGER. Or if A is an array of 5 reals:
read (10) A,J
Maybe you want an END= or an IOSTAT= in there somewhere - I don't know what you're looking for.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
program p1
implicit none
real:: x,y,z,t,u
integer :: i,n
open(10,file='rec.in',status='old',form='unformatted', access='stream', convert='BIG_ENDIAN')
open(20,file='rec.txt',status='unknown')
100 read(10, end=999) x,y,z,t,u,i
write(20,5) x,y,z,t,u,i
5 format(5f10.3,i3)
n=n+1
go to 100
999 write(6,200) n
200 format(/'number of lines in file: ',i10/)
end
Then part of the output
cat rec.txt
0.000 0.000 0.000 0.000 0.000 0
NaN 0.000 0.000 0.500 0.000***
0.000 0.010 0.000 0.000 0.000***
0.000 0.010 0.000 0.010 0.000 24
0.000 1.500 0.000 0.010 0.000***
0.000 0.000 0.000 2.000 0.000***
0.000 0.010 0.000 0.000 0.000***
0.000 0.010 0.000 0.010 0.000 24
0.000 3.000 0.000 0.010 0.000***
0.000 0.000 0.000 3.500 0.000***
0.000 0.010 0.000 0.000 0.000***
0.000 0.010 0.000 0.010 0.000 24
0.000 4.500 0.000 0.010 0.000***
0.000 0.000 0.000 5.000 0.000***
0.000 0.010 0.000 0.000 0.000***
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Please attach the file rec.in, rather than providing fragments of hex-dumps of the file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Take off "access="stream". It isn't a stream file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Steve,works perfect!
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page