Re: I write a binary data into a netcdf data .But , the nc can't be opened in Grads.

From: Adam Phillips <asphilli_at_nyahnyahspammersnyahnyah>
Date: Tue, 06 Jun 2006 10:00:33 -0600

Hi Li,

As you can see from the results of a ncdump on your netCDF file, there
are no attributes associated with time,lev,lat, or lon...

You need to add the following lines in your ncl code to write the
attributes for each variable to the netCDF file:
filevarattdef(fout,"time",time)
filevarattdef(fout,"lev",lev)
filevarattdef(fout,"lon",lat)
filevarattdef(fout,"lon",lon)

I see the example on the NCL Applications page makes this same mistake,
and I will fix that now.
(http://www.ncl.ucar.edu/Applications/method_2.shtml)

Also, this is very minor, but the (/ /) are not needed for the following
lines except where you have more than one string element. So this:

filevardef (fout,"time",typeof(time),"time")
filevardef (fout,(/"lev"/),(/typeof(lev)/),(/"lev"/))
filevardef (fout,(/"lat"/),(/typeof(lat)/),(/"lat"/))
filevardef (fout,(/"lon"/),(/typeof(lon)/),(/"lon"/))
filevardef (fout,(/"uwnd"/),(/"float"/),(/"time","lev","lat","lon"/))

should look like this:

filevardef (fout,"time",typeof(time),"time")
filevardef (fout,"lev",typeof(lev),"lev")
filevardef (fout,"lat",typeof(lat),"lat")
filevardef (fout,"lon",typeof(lon),"lon")
filevardef(fout,"uwnd","float",(/"time","lev","lat","lon"/))

Good luck,
Adam

lxf wrote:
> Hi,
>
> I read a binary data "u.nc" and wrote it into a netcdf data "uuu.nc" in an efficient way . But ,The "uuu.nc" can't be opened in Grads:
> "-> sdfopen uuu.lxf.nc
> Scanning self-describing file: uuu.nc
> SDF file has no discernable X coordinate."
>
> I just can't find out the reason.
> Any suggestion are much appreciated!
>
> =============================================================
> The following is result of "% ncl -x uuu.ncl > info.txt "
> -------------------------------------------------------------
> "info.txt" :
>
> Copyright (C) 1995-2006 - All Rights Reserved
> University Corporation for Atmospheric Research
> NCAR Command Language Version 4.2.0.a033
> The use of this software is governed by a License Agreement.
> See http://www.ncl.ucar.edu/ for more details.
> + begin
> + dir="./"
> + in=systemfunc("ls "+dir+"u.grd")
> + u = fbindirread(in,0,(/244,12,73,144/),"float")
> +
> + ;=============================
> + ; create coordinate variables
> + ;============================
> + lon=fspan(0,357.5,144)
> + lon!0 = "lon"
> + lon_at_long_name = "longitude"
> + lon_at_units = "degrees_east"
> + lon&lon = lon
> +
> + lat=fspan(-90,90,73)
> + lat!0 = "lat"
> + lat_at_long_name = "latitude"
> + lat_at_units = "degrees_north"
> + lat&lat = lat
> +
> + lev=(/89,726,1408,2945,4136,5505,7121,9102,10308,11752,13577,16088/)
> + lev!0 = "lev"
> + lev_at_long_name = "level"
> + lev_at_units = "m"
> + lev&lev = lev
> +
> + time=ispan(17552832,17554290,6)*1d0
> + time!0 = "time"
> + time_at_long_name = "time"
> + time_at_units = "hours since 1-1-1 00:00:0.0"
> + time&time = time
> +
> + u!0 = "time"
> + u!1 = "lev"
> + u!2 = "lat"
> + u!3 = "lon"
> +
> + u&time = time
> + u&lev = lev
> + u&lat = lat
> + u&lon = lon
> +
> + ;=============================
> + system("rm -f uuu.lxf.nc")
> + fout=addfile("uuu.lxf.nc","c")
> + setfileoption(fout,"DefineMode",True)
> +
> + ;creat global attributes
> + fileAtt = True
> + fileAtt_at_creation_date = systemfunc("date")
> + fileAtt_at_title = "efficient write netcdf data "
> + fileattdef(fout,fileAtt)
> +
> + ;predefine coordinate variables
> + dimNames = (/"time","lev","lat","lon"/)
> + dimSizes = (/-1,12,73,144/)
> + dimUnlim = (/True,False,False,False/)
> + filedimdef(fout,dimNames,dimSizes,dimUnlim)
> +
> + ;predefine variable names,type,and dimensions
> + filevardef (fout,"time",typeof(time),"time")
> + filevardef (fout,(/"lev"/),(/typeof(lev)/),(/"lev"/))
> + filevardef (fout,(/"lat"/),(/typeof(lat)/),(/"lat"/))
> + filevardef (fout,(/"lon"/),(/typeof(lon)/),(/"lon"/))
> + filevardef (fout,(/"uwnd"/),(/"float"/),(/"time","lev","lat","lon"/))
> +
> + ;create var attributes for each variable
> + u_at_long_name = "4xDaily u-wind"
> + u_at_units = "m/s"
> + u_at_missing_value = 32766
> + u@_FillValue = u_at_missing_value
> + filevarattdef(fout,"uwnd",u)
> +
> + printVarSummary(u)
> +
> + ;output data values only
> + fout->time = (/time/)
> + fout->lev = (/lev/)
> + fout->lat = (/lat/)
> + fout->lon = (/lon/)
> + fout->uwnd = (/u/)
> +
> + system("ncl_filedump uuu.nc")
> + end
> Copyright (C) 1995-2006 - All Rights Reserved
> University Corporation for Atmospheric Research
> NCAR Command Language Version 4.2.0.a033
> The use of this software is governed by a License Agreement.
> See http://www.ncl.ucar.edu/ for more details.
> Variable: f (file variable)
>
> filename: uuu.lxf
> path: uuu.lxf.nc
> file global attributes:
> title : efficient write netcdf data
> creation_date : Tue Jun 6 22:33:42 CST 2006
> dimensions:
> time = 244 // unlimited
> lev = 12
> lat = 73
> lon = 144
> variables:
> double time ( time )
>
> integer lev ( lev )
>
> float lat ( lat )
>
> float lon ( lon )
>
> float uwnd ( time, lev, lat, lon )
> _FillValue : 32766
> missing_value : 32766
> units : m/s
> long_name : 4xDaily u-wind
>
>
> Copyright (C) 1995-2006 - All Rights Reserved
> University Corporation for Atmospheric Research
> NCAR Command Language Version 4.2.0.a033
> The use of this software is governed by a License Agreement.
> See http://www.ncl.ucar.edu/ for more details.
>
> Variable: u
> Type: float
> Total Size: 123116544 bytes
> 30779136 values
> Number of Dimensions: 4
> Dimensions and sizes: [time | 244] x [lev | 12] x [lat | 73] x [lon | 144]
> Coordinates:
> time: [17552832..17554290]
> lev: [89..16088]
> lat: [-90..90]
> lon: [ 0..357.5]
> Number Of Attributes: 4
> _FillValue : 32766
> missing_value : 32766
> units : m/s
> long_name : 4xDaily u-wind
>
> =================================================================
> Yours,
> Li
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk_at_ucar.edu
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

-- 
--------------------------------------------------------------
Adam Phillips			             asphilli_at_ucar.edu
National Center for Atmospheric Research   tel: (303) 497-1726
ESSL/CGD/CAS                               fax: (303) 497-1333
P.O. Box 3000				
Boulder, CO 80307-3000	  http://www.cgd.ucar.edu/cas/asphilli
_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Jun 06 2006 - 10:00:33 MDT

This archive was generated by hypermail 2.2.0 : Tue Jun 06 2006 - 14:11:24 MDT