Re: how can i read the head information from a binary data fileset

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Sat Mar 03 2012 - 08:52:33 MST

You do not state if the binary was created via fortran, C, or some
other language/tool. Was it created on a big-endian (eg, IBM/AIX,
SunOS,...) or little endian (most linux OS) system.

If (say) fortran, the generating program might be

    character*16 stnname
    integer year, month, day, hour
    real lon, lat

    integer nx, ny, nz
    real x(nx,ny,nz)

    write(...) stnname, year, month, day, hour, lon, lat

    write(...) x

NCL is not 'good' (elegant) at reading mixed type binary records.
It lacks the granularity to parse the record(s). Multiple
reads of the same record are necessary

; read header: note 16 characters = 32 bytes => 8 integer/float values

   char = fbinrecread("/data/file/...", 0, -1, "character")
   stnam = tostring(char(0:15))

   date = fbinrecread("/data/file/...", 0, -1, "integer")
   year = date(8) ; skip 32 bytes
   month = date(9)
   day = date(10)
   hour = date(11)

   lonlat = fbinrecread("/data/file/...", 0, -1, "float")
   lon = lonlat(12)
   lat = lonlat(13)

http://www.ncl.ucar.edu/Document/Functions/Built-in/fbinrecread.shtml

--
Also, if the data were created on a machine with a different endian than
the one you are using to read the data, you must inform NCL of that via
    setfileoption("bin","ReadByteOrder","LittleEndian")  ; or "BigEndian"
http://www.ncl.ucar.edu/Document/Functions/Built-in/setfileoption.shtml
On 3/3/12 1:53 AM, Jie Tang wrote:
> hi,ncl users.
>   I have a binary format data file. And the first record of this file is
> the head information that described its data format.
> And the head line included several variables in different format with
> "string" "float " and "integer".
>   For example this head line is :
>   STNNAME    2012  3  3  1  120.1 30.2
>    How could I read these head line into my ncl script.
> like that :
> recinfo=cbinread(fili,162,c("string","integer","integer","integer","real"."real"))
> of course ,the aforementioned command line does not works.Can anyone
> help me ?
> --
> TANG Jie
>
>
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Sat Mar 3 08:52:43 2012

This archive was generated by hypermail 2.1.8 : Mon Mar 05 2012 - 14:12:07 MST