[gradsusr] command sdfattr not working to change header of netcdf file

Jennifer Adams jma at cola.iges.org
Tue Mar 25 15:24:59 EDT 2014


As a general rule, GrADS does not support a lot of features in the sdfwrite interface because there is no good reason to duplicate code that works very nicely in the NetCDF Operators. So, you can create some basic netcdf files with sdfwrite, and then you can tweak them further with NCO if necessary. 

Please see additional comments inline...

On Mar 23, 2014, at 11:14 PM, pankaj kumar wrote:

> Dear Sir/Ma'am,
> 
> I want to write the header of a netcdf file generated using sdfwrite as follows:
> 
> netcdf monthly_SST {
> dimensions:
>     time = 12 ;
>     z_t = 15 ;
>     nlon = 360 ;
>     nlat = 180 ;
> variables:
>     double time(time) ;
>         time:long_name = "time" ;
>         time:units = "days since 0000-01-01 00:00:00" ;
>         time:bounds = "time_bound" ;
>         time:calendar = "noleap" ;
>     float z_t(z_t) ;
>         z_t:long_name = "depth from surface to midpoint of layer" ;
>         z_t:units = "centimeters" ;
>         z_t:positive = "down" ;
>         z_t:valid_min = 500.f ;
>         z_t:valid_max = 14500.f ;
>     float TEMP(time, z_t, nlat, nlon) ;
>         TEMP:_FillValue = 9.96921e+36f ;
>         TEMP:long_name = "Potential Temperature" ;
>         TEMP:units = "degC" ;
>     float TLAT(nlat) ;
>         TLAT:long_name = "array of t-grid latitudes" ;
>         TLAT:units = "degrees_north" ;
>     float TLONG(nlon) ;
>         TLONG:long_name = "array of t-grid longitudes" ;
>         TLONG:units = "degrees_east" 
> 
> however, the auto-written header of the file generated by grads command is very different which has many missing information also. I tried to change the header using 
> set sdfattr
> but I have not got any success in changing anything. My grads script is as given below:
> 
>        'set yflip on'
This command is for graphics, not for data output. It will not reverse the underlying order of the Y axis. You can try bringing your original data in upside down, but your success will depend a bit on the original format.


>        'set sdfwrite -flt montly_temp.nc'
The -flt option affects data variables, but not coordinates, which are always written out as doubles.  
 
> 
>        'set sdfattr time String long_name time'
This attribute is set by default.

>        'set sdfattr time String units days since 0000-01-01 00:00:00'
>        'set sdfattr time String bounds time_bound'
>        'set sdfattr time String calendar noleap'

You cannot override the units or the calendar attributes of the time axis. This guarantees that they will be correct. The 'bounds' attribute will be written out, but what does it mean? 

> 
>        'set sdfattr z_t String long_name depth from surface to midpoint of layer'
>        'set sdfattr z_t String units centimeters'
>        'set sdfattr z_t Sting positive down'
>        'set sdfattr z_t float valid_min 500.f'
>        'set sdfattr z_t float valid_max 14500.f'

The Z axis is not named z_t, it is 'lev'. Setting the attribute 'positive' to 'down'  will not alter the order of the Z axis values. Andrew's comment shows you how to rename and flip the Z axis with NCO. 

>   
>        'set sdfattr TEMP String long_name Potential Temperature'
>        'set sdfattr TEMP String units degC'

Variables in GrADS are lower case. This won't get written because the varname won't match the defined variable. 

>        'set undef 'undef_value

GrADS will automaticlly set the _FillValue attribute with the default undef value. Use 'set undef' if you want it to be something other than -9.99e8.

>  
>        'set sdfattr TLAT String long_name array of t-grid latitudes'
>        'set sdfattr TLAT String units degrees_north'
> 
>        'set sdfattr TLONG String long_name array of t-grid longitudes'
>        'set sdfattr TLONG String units degrees_east'

These will be ignored because they are upper case and also because the longitude and latitudes grids are named 'lon' and 'lat'. The default values for the units are 'degrees_east' and 'degrees_north'  and for the long_name are "Longitdue" and "Latitude". 
>           
>        'q sdfwrite'
>        'sdfwrite TEMP'
>        'c sdfwrite'
> 
> Since I am writing ocean data, I want to set top layer (500 cm) as first level but the bottom layer (14500 cm) is by default set as first level. I tried to invert levels using 'set yflip on' before sdfwrite command but it is not working. Please see how this can be achieved.
> 
> Thank you.
> With Regards
> Pankaj Sinha 
> Hokkaido University
> _______________________________________________
> gradsusr mailing list
> gradsusr at gradsusr.org
> http://gradsusr.org/mailman/listinfo/gradsusr

--
Jennifer M. Adams
Center for Ocean-Land-Atmosphere Studies (COLA)
111 Research Hall, Mail Stop 2B3
George Mason University
4400 University Drive
Fairfax, VA 22030 





-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20140325/700c4417/attachment-0001.html 


More information about the gradsusr mailing list