[ncl-talk] question about fbindirread reading byte for multiple variables in one file?

Dennis Shea shea at ucar.edu
Mon Sep 29 07:09:51 MDT 2014


The 3B40*RT* (*R*eal *T*ime) product is a big-endian binary file containing
variables of mixed types: type character, type short and type byte. NCL can
be used to read the data but it is a bit cumbersome because NCL's binary
read functions only read one variable type. They lack the necessay
'granularity' to partition the different variable types. The approach is to
read the *entire file as a single type* and extract the appropriate
information. The same record must be read for *each* type specification.
Hence, the user must keep track of the byte counts.

Examples for 3B42RT and 3B40RT are at the bottom of:
      http://www.ncl.ucar.edu/Applications/HiResPrc.shtml

The trmm_3B42RT_1 and 3B40RT_1 examples read & plot the data. The nc file
contains unpacked data.

The trmm_3B42RT_2 and 3B40RT_2 examples are a 'translation' of the
big-endian binary to netCDF. The variable types are maintained.
This is **MUCH** better than binary!!

Good luck
 <http://www.ncl.ucar.edu/Applications/Scripts/trmm_3B40RT_2.ncl>

On Fri, Sep 26, 2014 at 3:36 AM, dyjbean at gmail.com <dyjbean at gmail.com>
wrote:

>   i have one trmm data file, whose file has seven blocks(2880-byte header
> and six variables with the same dimension 1440*720),as follows:
>
> block byte_count integer_byte
> 1 2880 2
> 2 2073600 2
> 3 2073600 1
> 4 1036800 1
> 5 1036800 1
> 6 1036800 1
> 7 1036800 1
> +++++++++++++++++++++++++++++++++++++++
> i have a test using ncl prompt,as follows:
>
> ncl 0> nlat=720
> ncl 1> nlon=1440
> ncl 2> filn="3B40RT.2001012212.7R2.bin"
> ncl 3> ncha=2880
> ncl 4> dims=(/nlon,nlat/)
> ncl 5> nbyt=nlon*nlat
> ncl 6> setfileoption("bin","ReadByteOrder","BigEndian")
> ncl 7> ff=fbindirread(filn,0,-1,"byte")
> ncl 8> printVarSummary(ff)
>
> Variable: ff
> Type: byte
> Total Size: 8297280 bytes
> 8297280 values
> Number of Dimensions: 1
> Dimensions and sizes: [8297280]
> Coordinates:
>
> +++++++++++++++++++++++++++++++++++++
> there is 8297280 bytes in file.
>
>
>
>
> but when i want to extract the six variable with ncl script,the below is
> my ncl code:
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
>
> begin
> nlat=720
> nlon=1440
> filn="3B40RT.2001012212.7R2.bin"
> ncha=2880
> dims=(/nlon,nlat/)
> nbyt=nlon*nlat
> setfileoption("bin","ReadByteOrder","BigEndian")
> ff=fbindirread(filn,0,-1,"byte")
> ffhead=ff(0:ncha-1)
>
> pr=new(dims,"float")
> pr at _FillValue=-31999
>
> pe=new(dims,"float")
> pe at _FillValue=-31999
>
> tp=new(dims,"float")
> tp at _FillValue=-31999
>
> ap=new(dims,"float")
> ap at _FillValue=-31999
>
> rp=new(dims,"float")
> rp at _FillValue=-31999
>
> sr=new(dims,"float")
> sr at _FillValue=-31999
>
>
> pr=byte2flt(onedtond(ff(ncha:ncha+nbyt*2-1),dims))
> pe=byte2flt(onedtond(ff(ncha+nbyt*2:ncha+nbyt*4-1),dims))
> tp=byte2flt(onedtond(ff(ncha+nbyt*4:ncha+nbyt*5-1),dims))
> ap=byte2flt(onedtond(ff(ncha+nbyt*5:ncha+nbyt*6-1),dims))
> rp=byte2flt(onedtond(ff(ncha+nbyt*6:ncha+nbyt*7-1),dims))
> sr=byte2flt(onedtond(ff(ncha+nbyt*7:ncha+nbyt*8-1),dims))
>
> end
>
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> there come to two warnings:
> warning:onedtond : output dimension sizes have fewer elements than input,
> some data not copied
> warning:onedtond : output dimension sizes have fewer elements than input,
> some data not copied
>
> *what i'm confused is the "rec_num" set in function fbindirread, is it a
> byte position or integer position?*
>
> ------------------------------
>  dyjbean at gmail.com
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20140929/3c35a280/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bg.jpg
Type: image/jpeg
Size: 46225 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20140929/3c35a280/attachment.jpg 


More information about the ncl-talk mailing list