Re: How to read this kind of binary file

From: Dave Allured - NOAA Affiliate <dave.allured_at_nyahnyahspammersnyahnyah>
Date: Fri Jan 25 2013 - 13:29:26 MST

NCL does not have normal support to read mixed data types within the
same binary record. (This needs to be stated explicitly in the binary
read function docs.)

If it is possible to change your data files to write the integers and
floats into different records, this would probably be the most robust

However, if it is really necessary, I think you can read mixed data
types with multiple read operations on the same record. Something
like this:

   ints = fbinrecread (fili, 0, 3, "integer")
   floats = fbinrecread (fili, 0, 3, "float")

   a = ints(0)
   b = floats(1)
   c = floats(2)

Please give this a try and let us know if it works.

Note: This is not a completely safe method because it depends on
assumptions about the low-level data formats. In this example, the
storage size for integers and floats must be the same number of bytes,
or the method will fail. For example, if "a" was type double (64
bits) instead of integer, the memory offsets for b and c would change,
and you would get the wrong values unless you depended on more
assumptions and compensated for the different storage sizes. HTH.


On Thu, Jan 24, 2013 at 4:18 PM, GCCA <> wrote:
> Dear all,
> I would like to use ncl read a binary file. It is written with Fortran.
> It has three variables: a, b, and c.
> integer a
> real b, c
> open (11, file="example01", form= "unformatted")
> write(11) a, b, c
> There is only one recorder in this binary.
> Could anybody tell me how to use fbinrecread or fbinread to this binary file?
> Thanks in andvance!
> Guangshan
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
Received on Fri Jan 25 13:29:36 2013

This archive was generated by hypermail 2.1.8 : Tue Jan 29 2013 - 22:44:26 MST