How to create attribute of file?
Added by Liubov Tupikina over 11 years ago
Hi to all people!
I'm working with netcdf file and I need to create new attributes for one of my variables: "var1".
So that I have:
float var1(time, lat, lon) ;
var1:table = 255 ;
var1:grid_type = "gaussian" ;
I want to CREATE (not to change) variable attribute "long_name", so that I will have smth like this but for variable "var1":
float temp2(time, lat, lon) ;
temp2:long_name = "2m temperature" ;
temp2:units = "K" ;
temp2:code = 167 ;
temp2:table = 128 ;
temp2:grid_type = "gaussian" ;
Replies (3)
RE: How to create attribute of file? - Added by Ralf Mueller over 11 years ago
there is an attribute editor available in the nco package : http://nco.sourceforge.net/nco.html#ncatted-netCDF-Attribute-Editor
RE: How to create attribute of file? - Added by Ralf Mueller over 11 years ago
example: Lets use this files
netcdf zOld { dimensions: x = 8 ; y = 8 ; variables: double x(x) ; x:long_name = "x" ; x:actual_range = 0., 7. ; double y(y) ; y:long_name = "y" ; y:actual_range = 0., 7. ; float z(y, x) ; z:long_name = "z" ; z:_FillValue = NaNf ; z:actual_range = 719.896667480469, 1005.97003173828 ;
With the following call, you can add a new attribute the variable 'z'
ncatted -a newAtt,z,a,c,'newAttValue' zOld.nc -o zNew.nc
Now lets hava a look into zNew.nc
netcdf zNew { dimensions: x = 8 ; y = 8 ; variables: double x(x) ; x:long_name = "x" ; x:actual_range = 0., 7. ; double y(y) ; y:long_name = "y" ; y:actual_range = 0., 7. ; float z(y, x) ; z:long_name = "z" ; z:_FillValue = NaNf ; z:actual_range = 719.896667480469, 1005.97003173828 ; z:newAtt = "newAttValue" ;
If you leaf out the '-o' options, the changed will be applied to zOld.nc. Attributes can have different types like float or integers:
ncatted -a newFloatAtt,z,a,f,0.815 zOld.nc ncatted -a newIntAtt,z,a,i,34 zOld.nc
leads to
netcdf zOld { dimensions: x = 8 ; y = 8 ; variables: double x(x) ; x:long_name = "x" ; x:actual_range = 0., 7. ; double y(y) ; y:long_name = "y" ; y:actual_range = 0., 7. ; float z(y, x) ; z:long_name = "z" ; z:_FillValue = NaNf ; z:actual_range = 719.896667480469, 1005.97003173828 ; z:newFloatAtt = 0.815f ; z:newIntAtt = 34 ;
RE: How to create attribute of file? - Added by Neil Brink over 11 years ago
Thanks for your reply. I think this is easy as compared to another solution I had considered. I think I will go with this only.
http://www.karinherzog.com/de