Re: to read binary file of ecmwf forecast data

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Thu Oct 03 2013 - 08:21:10 MDT

Really, it is your responsibility to find the structure
of the binary file. One reason why file formats like netCDF,
GRIB and HDF exist is to get around the issues presented
by binary files.

[1] Was the file written as a 'flat' binary file using fortran's
     *direct* or *sequential* methods?

     Was it written via a (say) C block I/O function write?

[2] Are there multiple records on the file?

[3] Does the file contain a sequence of header and data records?

[4] Do the records contain variables of mixed types?

===
http://www.ncl.ucar.edu/Document/Functions/
Go to the 'File input/output' and click.
You can see assorted functions.

Read the documentation for the functions used below.
====
You can try

     setfileoption("bin","ReadByteOrder","BigEndian")
     nrecBig = fbinnumrec("ec_file")
     print(nrecBig)

     setfileoption("bin","ReadByteOrder","LittleEndian")
     nrecLit = fbinnumrec("ec_file")
     print(nrecLit)

If nrecBig or nrecLit look reasonable then it is like
a fortran sequential file and you can use fbinrecread
to read the file.

     setfileoption("bin","ReadByteOrder","BigEndian")
     cBig = cbinread("ec_file",-1,"float")
     print("cBig: min="+min(cBig)+" max="+max(cBig))

     setfileoption("bin","ReadByteOrder","LittleEndian")
     cLit = cbinread("ec_file",-1,"float")
     print("cLit: min="+min(cLit)+" max="+max(cLit))

On 10/3/13 2:27 AM, 宋靜 wrote:
> hello,
>
> i got one binary file for ECMWF forecast data, but have no idea of its
> structure.
>
> i tried the code:
>
> setfileoption("bin","ReadByteOrder","BigEndian")
> f = cbinread("ec_file",-1,"float")
> printVarSummary(f)
> asciiwrite ("ec.txt", f)
>
> and it shows the first several lines in file ec.txt like:
>
> 53833.26
> -nan
> 0
> 2.150461e-40
> 2.942727e-44
> 2.35802e-38
> 4.591789e-40
> 3.325774e-34
> 9.860761e-32
> 2.350989e-38
> 1.025519e-28
> 9.184811e-41
> 1.5186e-36
> 6.439222e-10
> 6.613232e-39
> 1.421491e-40
> 0
> 9.629649e-35
> -nan
>
> ...
>
> i want to get the variable info in the binary file, so what can i do?
>
> many thanks to reply.
>
>
>
> _______________________________________________
> 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 Thu Oct 3 08:21:25 2013

This archive was generated by hypermail 2.1.8 : Fri Oct 04 2013 - 16:45:17 MDT