Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
8 Views

How to open binary file with BIG ENDIAN

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.

0 Kudos
10 Replies
Highlighted
8 Views

Yes, CONVERT='BIG_ENDIAN'

Yes, CONVERT='BIG_ENDIAN' should work. It will byte-swap the record lengths.

Retired 12/31/2016
0 Kudos
Highlighted
Beginner
8 Views

program p1

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?

0 Kudos
Highlighted
8 Views

You want form='unformatted'

You want form='unformatted' and "read(10)", not "read (10,*)". List-directed is not unformatted.

Retired 12/31/2016
0 Kudos
Highlighted
Beginner
8 Views

Works fine but I got now some

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?

0 Kudos
Highlighted
8 Views

read (10) A,B,C,D,E,J

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.

Retired 12/31/2016
0 Kudos
Highlighted
Beginner
8 Views

program p1

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***
 

0 Kudos
Highlighted
Black Belt
8 Views

Please attach the file rec.in

Please attach the file rec.in, rather than providing fragments of hex-dumps of the file.

0 Kudos
Highlighted
Beginner
8 Views

Fazer download folder.tar.bz2

0 Kudos
Highlighted
8 Views

Take off "access="stream". It

Take off "access="stream". It isn't a stream file.

Retired 12/31/2016
0 Kudos
Highlighted
Beginner
8 Views

Thanks Steve,works perfect!

Thanks Steve,works perfect!

0 Kudos