Hi Ufuk
If the data are written via the (default) fortran sequential binary write eg
integer ii(45)
real ff(19)
write(iunit) ii,ff
then the fortran sequential write *silently* inserts
a 4-byte record delimeter before and after each record written
4-byte ... 45 integers ... 19 reals ... 4-byte
When you used the following
rec1=fbinrecread("./aenwha.1.1.96.73.pit9410.ext.pp", 0, 45,"integer")
this is reading a *partial* record.
then,
the following is actually reading the *2nd* record on the file ...
not the first.
rec2=fbinrecread("./aenwha.1.1.96.73.pit9410.ext.pp", 1, 19, "float")
Likeley, this is also a partial record too.
=====
To read a fortran sequential record, you must read the *entire*
record. Since NCL's fbinrecread only allows one type to be read
at a time, you must read the first record [record 0] twice.
Once for the integers and once for the floats.
=============
Your 2nd approach
rec1=fbinrecread("./aenwha.1.1.96.73.pit9410.ext.pp", 0, 45, "integer")
This is again reading a *partial* record ... Use
rec1=fbinrecread(fname, 0, 64, "integer") ; ignore 46-64
>
> lblrec = rec1(14) ; length of data record in words
> lbrow = rec1(17) ; number of rows in field (latitude)
> lbnpt = rec1(18) ; number of grid points in each row (longitude)
> lbfc = rec1(22) ; field code
> lbvc = rec1(25) ; vertical coordinate type
rec2 = fbinrecread(fname, 0, 64, "float") ; ignore 1-45
This is reading a complete record, that is why bval and aval are read
correctly
>
> bval = rec2(45) ; b-value of vertical coordinate (if lbvc == 9)
> aval = rec2(46) ; a-value of vertical coordinate (if lbvc == 9)
Let me know how this goes.
Hope all is well
D
Ufuk Utku Turuncoglu wrote:
> Hi All,
>
> I try to read a binary file (Hadley Center, HadCM3 output in PP format).
> The file simple contains header information in each slice of the
> variable. The header file contains 1-45 integer values and 46-64 float
> values (total 64 value). The actual field data comes after these header
> values. Please see the following link Appendix 5 for more information.
>
> http://precis.metoffice.com/docs/tech_man.pdf
>
> My problem is i could not read header data correctly when i use the
> following code,
>
> rec1 = fbinrecread("./aenwha.1.1.96.73.pit9410.ext.pp", 0, 45,
> "integer")
>
> lblrec = rec1(14) ; length of data record in words
> lbrow = rec1(17) ; number of rows in field (latitude)
> lbnpt = rec1(18) ; number of grid points in each row (longitude)
> lbfc = rec1(22) ; field code
> lbvc = rec1(25) ; vertical coordinate type
>
> rec2 = fbinrecread("./aenwha.1.1.96.73.pit9410.ext.pp", 1, 19, "float")
>
> bval = rec2(0) ; b-value of vertical coordinate (if lbvc == 9)
> aval = rec2(1) ; a-value of vertical coordinate (if lbvc == 9)
>
> but if i use following one,
>
> rec1 = fbinrecread("./aenwha.1.1.96.73.pit9410.ext.pp", 0, 45,
> "integer")
>
> lblrec = rec1(14) ; length of data record in words
> lbrow = rec1(17) ; number of rows in field (latitude)
> lbnpt = rec1(18) ; number of grid points in each row (longitude)
> lbfc = rec1(22) ; field code
> lbvc = rec1(25) ; vertical coordinate type
>
> rec2 = fbinrecread("./aenwha.1.1.96.73.pit9410.ext.pp", 0, 64, "float")
>
> bval = rec2(45) ; b-value of vertical coordinate (if lbvc == 9)
> aval = rec2(46) ; a-value of vertical coordinate (if lbvc == 9)
>
> i can read the correct value of bval and aval values. Why does the first
> version read wrong data? How can i read defined subset of header file in
> each fbinrecread call? I will use this script to read ak and bk values
> of the each hybrid sigma layers but i this case it is not working.
> Please let me know, if you need any further information.
>
> Thanks,
>
> --ufuk
>
>
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Jan 15 09:06:16 2010
This archive was generated by hypermail 2.1.8 : Fri Jan 15 2010 - 13:51:45 MST