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

Andrew Friedman andfried at berkeley.edu
Mon Mar 24 03:42:06 EDT 2014


Hi Pankaj,

I’ve been using NCO to address similar issues as you are having, after writing with sdfwrite.

You can use NCO to rename your z-dimension and flip the vertical levels.

ncrename -v lev,z_t -d lev,z_t outfile.nc
ncpdq -O --rdr=-z_t outfile.nc outfile.nc

Also, I don’t know what errors you are getting, but you could have a problem with data type of your dimensions.
Though you are setting floating point output for the variables, it won’t output your dimensions as floating point. You can change the format of the output variables using 

ncap2 -O -s ''z_t = z_t.float()'' outfile.nc outfile.nc

NCO can be found here: http://nco.sourceforge.net/

Best,
Andrew

On Mar 24, 2014, at 11:14 AM, pankaj kumar <pankajqumar at yahoo.com> 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'
>        'set sdfwrite -flt montly_temp.nc'
> 
>        'set sdfattr time String long_name time'
>        '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'
> 
>        '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'
>   
>        'set sdfattr TEMP String long_name Potential Temperature'
>        'set sdfattr TEMP String units degC'
>        'set undef 'undef_value
>  
>        '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'
>           
>        '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




More information about the gradsusr mailing list