Thardy
Technical User
- Oct 29, 2011
- 13
Dear members,
I wrote a program to read a binary file I received.
1) The structure of the biary file is as follows:
1st line : P(1),P(2),P(3),....,P(N) ; where,P(1)>P(2)....
2nd line : X,Y,A(P(2)),..,A(P(N)),W(P(2)),..,W(P(N)),T(P(2)), ..,T(P(N)),ST,GA1,GA2,GB1,GB2,GB3
3nd line : X,Y,A(P(2)),..,A(P(N)),W(P(2)),..,W(P(N)),T(P(2)), ..,T(P(N)),ST,GA1,GA2,GB1,GB2,GB3
4nd line : X,Y,A(P(2)),..,A(P(N)),W(P(2)),..,W(P(N)),T(P(2)), ..,T(P(N)),ST,GA1,GA2,GB1,GB2,GB3
2)The program I wrote is as follows:
implicit none
integer, parameter:: k_layer = 6
integer::X,Y,j,j_lay
real :: P(1:k_layer), T(1:k_layer)
real :: A(1:k_layer), W(1:k_layer)
real :: ST
character :: f_i*150, f_o*150
integer,parameter :: i_pix=10000
integer :: itr
real :: GA(2)
real :: GB(3)
integer, parameter :: k_rec = 2*2
& + k_layer*4
& + k_layer*4
& + k_layer*4
& + 4
& + 4*5
integer, parameter :: k_dammy = k_rec - k_layer*4
character(k_dammy) :: cdammy
f_i='binaryfilepixels'
f_o='textfilepixels'
open (11, file = f_i, status = 'old', access = 'direct',
& recl = k_rec,form='unformatted',convert='big_endian')
read (11 , rec=1)(P(j_lay),j_lay=1, k_layer)
write(*,'(6F7.2)')(P(j_lay), j_lay=1, k_layer)
read(11, rec = i_pix + 1)
& X, Y,
& ( A(j_lay), j_lay =1, k_layer),
& ( W(j_lay), j_lay =1, k_layer),
& ( T(j_lay), j_lay =1, k_layer),
& ST,
& (GA(itr),itr=1,2),
& (GB(itr),itr=1,3)
open (12, file = f_o, status = 'new', access = 'direct',
& recl = k_rec,form='formatted')
write(12, 1000)
& (P(j_lay), j_lay=1, k_layer),
& X, Y,
& ( A(j_lay), j_lay =1, k_layer),
& ( W(j_lay), j_lay =1, k_layer),
& ( T(j_lay), j_lay =1, k_layer),
& ST,
& (GA(itr),itr=1, 2),
& (GB(itr),itr=1, 2)
999 format (2I5, 18F7.2, 6F7.2)
1000 format (2I5, 18F7.2, 6F7.2)
close (11)
close (12)
stop
End
3) The gfortran compiling works ok but at the execution part there is an error in the reading of the binary file. Could somebody help to correct what is wrong?
Thanks in advance
Thardy
I wrote a program to read a binary file I received.
1) The structure of the biary file is as follows:
1st line : P(1),P(2),P(3),....,P(N) ; where,P(1)>P(2)....
2nd line : X,Y,A(P(2)),..,A(P(N)),W(P(2)),..,W(P(N)),T(P(2)), ..,T(P(N)),ST,GA1,GA2,GB1,GB2,GB3
3nd line : X,Y,A(P(2)),..,A(P(N)),W(P(2)),..,W(P(N)),T(P(2)), ..,T(P(N)),ST,GA1,GA2,GB1,GB2,GB3
4nd line : X,Y,A(P(2)),..,A(P(N)),W(P(2)),..,W(P(N)),T(P(2)), ..,T(P(N)),ST,GA1,GA2,GB1,GB2,GB3
2)The program I wrote is as follows:
implicit none
integer, parameter:: k_layer = 6
integer::X,Y,j,j_lay
real :: P(1:k_layer), T(1:k_layer)
real :: A(1:k_layer), W(1:k_layer)
real :: ST
character :: f_i*150, f_o*150
integer,parameter :: i_pix=10000
integer :: itr
real :: GA(2)
real :: GB(3)
integer, parameter :: k_rec = 2*2
& + k_layer*4
& + k_layer*4
& + k_layer*4
& + 4
& + 4*5
integer, parameter :: k_dammy = k_rec - k_layer*4
character(k_dammy) :: cdammy
f_i='binaryfilepixels'
f_o='textfilepixels'
open (11, file = f_i, status = 'old', access = 'direct',
& recl = k_rec,form='unformatted',convert='big_endian')
read (11 , rec=1)(P(j_lay),j_lay=1, k_layer)
write(*,'(6F7.2)')(P(j_lay), j_lay=1, k_layer)
read(11, rec = i_pix + 1)
& X, Y,
& ( A(j_lay), j_lay =1, k_layer),
& ( W(j_lay), j_lay =1, k_layer),
& ( T(j_lay), j_lay =1, k_layer),
& ST,
& (GA(itr),itr=1,2),
& (GB(itr),itr=1,3)
open (12, file = f_o, status = 'new', access = 'direct',
& recl = k_rec,form='formatted')
write(12, 1000)
& (P(j_lay), j_lay=1, k_layer),
& X, Y,
& ( A(j_lay), j_lay =1, k_layer),
& ( W(j_lay), j_lay =1, k_layer),
& ( T(j_lay), j_lay =1, k_layer),
& ST,
& (GA(itr),itr=1, 2),
& (GB(itr),itr=1, 2)
999 format (2I5, 18F7.2, 6F7.2)
1000 format (2I5, 18F7.2, 6F7.2)
close (11)
close (12)
stop
End
3) The gfortran compiling works ok but at the execution part there is an error in the reading of the binary file. Could somebody help to correct what is wrong?
Thanks in advance
Thardy