Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Read Binary Header

vgtoro
Beginner
708 Views
Dear all

I am reading a binary file that have a header. I need extract the this header a information for process the data.

My piece of code is:

byte head(512)
real*4 dopdata(512)
integer*4 a
character cfile*11,chdata(512)

cfile='20050460000' ! binary file

open(10,file=cfile,form='binary',status='old')
read(10,end=999) head(1:512)

DO I=1,512
chdata(I:I) = CHAR(head(I))
END DO

READ(UNIT=chdata(2), FMT='(I4)') a
write(6,*) a

The fist part of header is:
2048 SAMPLES 15-FEB-05 00:00 LOC Cangrejo FMSPEC FREQUENZ 16.300MHZ YEAR
2005 RANGE: 1.5000 KM,TRUENORTH:210 GRAD,RATE:0.260000S,NRRANGES: 80

I need (for example) extract the number 2048, but when I "write(6,*) a" the result is only "2". Anybody have a idea why this happend?

I appreciate a lot your help.

Regards




0 Kudos
4 Replies
Aubrey_W_
New Contributor I
708 Views
Hello,

I'm moving this to the Intel Fortran Compiler forum, since the question is not related to the Intel Manycore Testing Lab. You are more likely to get an answer there.

Regards,

==
Aubrey W.
Intel Software Network Support
0 Kudos
mecej4
Honored Contributor III
708 Views
You probably meant to declare

chdata*512

instead of

chdata(512)

and to change the read statement to

READ(UNIT=CHDATA(2:5),FMT='(I4)')A

With your declaration, the length of each element of the array chdata is one character, so the READ statement processes just one character, which is why you got 2 instead of the expected 2048.
0 Kudos
vgtoro
Beginner
708 Views
Thanks a lot !!!!

Actually had an error in the statement of my variable (chdata). On the other hand solves the problem by reading the header "word for word" and assigning the appropriate variable:

7994 real*8 mdoppler(40,50,512)
7995 real*4 dopdata(512),freq,rnge,rate,lat,lon,dgt
7996 *
7997 integer nyear, nmonth,nday,nhour,nmin,samples,tnorth,nrrange
7998 integer ntl,nftl,nx,ny,res
7999 *
8000 character cfile11*20,chdata(128)*4
8001 character station*9,cfreq*6,crnge*6,crate*8
8002 character claenge*9,cwbreite*8,clat*9,clon*10,cdgt*9
8003 character t1*11,t2*5,t3*21,t4*26,t5*14,t6*11,t7*12,t8*16,t9*10
8004 character t10*10,t11*7,t12*5,t13*5,t14*6,t15*7
8005 character*4 csamples
8006 character*3 cmonth,ca3,cnftl,ctnorth
8007 character*2 cday,cyear,chour,cmin,cnrrange,cntl,cnx,cny
8008 character*1 ca,cb,cc,cd,ce,cf,cg,ch,ci
8009 *----------------------------------------------------------------------
8010 open(10,file=cfile11,form='binary',status='old')
8011 read(10,end=999) csamples,t1
8012 * write(6,*) csamples
8013 read(10,end=999) cday,cg,cmonth,ca,cyear
8014 * write(6,*) cday,cmonth,cyear
8015 read(10,end=999) cb,chour,cc,cmin,t2,station
8016 * write(6,*) chour,cmin,station ....

Thanks again
0 Kudos
Steven_L_Intel1
Employee
708 Views
Consider using the F2003 standard ACCESS='STREAM' in place of FORM='BINARY'. You can probably just change the OPEN and leave the rest of the code as-is.
0 Kudos
Reply