How to assign time attribution to binary data

From: Li Tao (taoli AT hawaii.edu)
Date: Wed Jan 19 2005 - 12:26:58 MST


Dear Dennis Shea and all:

It works very well after I use fortran program to convert data format from
byte to float.

I still have one question to need help. I don't know how to assign time
attribution to the binary data.
I can get the time from the file name. The following is an example you give
to me.

       fil = "/disk/ide41/yzhang/AMSR_E/amsre_20040601v4_d3d"
       filc = stringtochar ( fil )
       year = stringtointeger( chartostring( filc(32:35) )
       month= stringtointeger( chartostring( filc(36:37) )
       day = stringtointeger( chartostring( filc(38:39) )

     sst!0="time"
    sst&time=?????

Thanks and regrards!

Li Tao

IPRC/SOEST
University of Hawaii, POST Bldg. 412G
1680 East West Road
Honolulu, Hawaii 96822

e-mail: taoli@hawaii.edu
phone: (808) 956-2453
fax: (808) 956-9425

----- Original Message -----
From: "Dennis Shea" <shea@ucar.edu>
To: "Li Tao" <taoli@hawaii.edu>
Cc: <ncl-talk@ucar.edu>
Sent: Monday, January 17, 2005 7:57 PM
Subject: Re: how to read from many binary files:

>
> > I am a new user of NCL.
>
> Welcome ...
>
> > I try to read many x-y dimension binary files named with date,
> > then write them into nc format, I have three questions.
>
> > First question, I try read one file, and write out one vairable.
> > I use Grads to visialize the plot , the error message is following:
>
> > Scanning self-describing file: rain.nc
> > SDF file has no discernable X coordinate.
>
> [1]
> This is a Grads error. Perhaps there is an error in the ddf file.
> A description that might help is:
> http://www.cgd.ucar.edu/~asphilli/ddfhelp.html
>
> [2] Are you sure your data is of type "byte" ?
> That is unusual for binary data. Usually, it is
> of type float or double or integer. Data packed
> in "byte" usually have a 'scale_factor' and/or
> 'add_offset' to get it into float or double.
>
> > The following is my ncl file:
>
> [3] **Untested** modifications of your code. I speculate
> the "byte" should be "float"
>
> [4] fout = addfile ("./rain.nc","c")
> ^ not "w"
> _______________________________________________
> 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"
>
> procedure createNcVariable (x:numeric, longName:string, units:string \
> ,lat[*]:numeric, lon[*]:numeric)
> ; procedure to add meta data
> begin
> xmsg = -9999.0
>
> x!0 ="lat"
> x!1 ="lon"
> x&lat = lat ; assign coordinate values and units
> x&lon = lon
> x@long_name = longName
> x@units = units
> x@_FillValue = xmsg
> x@missing_value = xmsg
> ; set values to _FillValue
> x1d = ndtooned( x )
> imsg = ind( x1d.ge.251 .and. x1d.le.255)
> x1d(imsg) = xmsg
> x = onedtond ( x1d, dimsizes(x) )
> end
>
> begin
> nlat = 720
> mlon = 1440
> file_in = "/disk/ide41/yzhang/AMSR_E/amsre_20040601v4_d3d"
> SST = fbindirread (file_in,0, (/nlat,mlon/),"byte")
> ????
> WSPD = fbindirread (file_in,1, (/nlat,mlon/),"byte")
> VAPOR = fbindirread (file_in,2, (/nlat,mlon/),"byte")
> CLOUD = fbindirread (file_in,3, (/nlat,mlon/),"byte")
> RAIN = fbindirread (file_in,4, (/nlat,mlon/),"byte")
>
> ;==========================================
> ; Create lon and lat coordinates variables; contributed.ncl
> ;==========================================
> lat = latGlobeFo (nlat, "lat", "latitude", "degrees_north")
> lon = lonGlobeFo (mlon, "lon", "longitude", "degrees_east")
> ; lat = fspan (-89.875,89.875,nlat)
> ; lon = fspan (0.125,359.875,mlon)
> printVarSummary (lat)
> printVarSummary (lon)
>
> ;creat output variables with proper dimensions
> createNcVariable (SST , "sea surface temperature*0.15-3.0" \
> , "deg C", lat, lon)
> createNcVariable (WSPD , "wind speed", "???", lat, lon)
> createNcVariable (VAPOR, "atmospheric water vapor*0.3" \
> , "mm", lat, lon)
> createNcVariable (CLOUD, "cloud liquid water*0.01" \
> , "mm", lat, lon)
> createNcVariable (RAIN , "rain rate*0.01", "mm/hr", lat, lon)
>
> printVarSummary (SST)
>
> ;=======================
> ; draw variable
> ;=======================
> wks=gsn_open_wks("x11","example")
> gsn_define_colormap (wks, "gui_default")
> res = True
> res@gsnMaximize = True ; only affect ps or pdf (otherwise,
ignored)
> res@cnFillOn = True ; turn on color
> res@gsnSpreadColors = True ; use entire color map
> plot=gsn_csm_contour_map_ce(wks,SST,res)
>
> fout = addfile ("./rain.nc","c")
> fout@source_file = file_in
> fout@creation_date = systemfunc("date")
> fout ->SST = SST
> end
>
> ____________________________________________________
>
> > second question, I try to read many binary files which named with
> > date such as amsre_20040601v4_d3d, how can I do?
>
> ; read the names of multiple files
> file_in = systemfunc (" ls/disk/ide41/yzhang/AMSR_E/amsre_*_d3d")
> print(file_in)
> nfils = dimsizes(file_in) ; number of files
>
> You can loop over files
>
> do nf=0,nfils-1
> :
> end do
>
> FYI: consider
>
> fil = "/disk/ide41/yzhang/AMSR_E/amsre_20040601v4_d3d"
> filc = stringtochar ( fil )
> year = stringtointeger( chartostring( filc(32:35) )
> month= stringtointeger( chartostring( filc(36:37) )
> day = stringtointeger( chartostring( filc(38:39) )
>
> > Third question, the value of missing data is from 251 to 255,
> > I try to change 255 to -9999.9 and change 251, 252, 253, 254
> > as missing data with same value, May I use ncl to do this?
>
> yes, of course. see createNcVariable
>
>
> Could anyone help me?
>
>
> Thanks and regards!
>
>
> Li Tao
>
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk@ucar.edu
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>

_______________________________________________
ncl-talk mailing list
ncl-talk@ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk



This archive was generated by hypermail 2b29 : Thu Jan 20 2005 - 22:10:20 MST