0

How can add variable name and units to NetCDF attribute in NCO.

dimensions:
lat = UNLIMITED ; // (34 currently)
lon = 42 ;
time = 360 ;

float precip(lat,lon,time) ;
  precip:_FillValue = 1.e+20f ;
  precip:missing_value = 1.e+20f ;
  precip:cell_methods = "time: sum" ;

C:\nco>ncatted -a units,'precip',c,c,'mm day-1' nclimgrid_lowres_prcp_ncpdq5.nc ncatted: overwrite nclimgrid_lowres_prcp_ncpdq5.nc (y/n)? y The system cannot find the path specified. ncatted: ERROR File contains no variables or groups that match name 'precip' so attribute units cannot be changed

ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86

2 Answers2

1

Your command looks correct. Too bad it does not work :) Add -O to automatically overwrite the output file. Single quotes only needed around the whitespace. I have no Windows machine to test on, but try this and post any error messages:

ncatted -O -a units,precip,c,c,'mm day-1' nclimgrid_lowres_prcp_ncpdq5.nc

If that does not work try this

ncatted -O -a units,precip,c,c,'mm day-1' nclimgrid_lowres_prcp_ncpdq5.nc out.nc
Charlie Zender
  • 5,929
  • 14
  • 19
  • ncatted -O -a name,precip,c,c,precip nclimgrid_lowres_prcp4.nc nclimgrid_lowres_prcp5.nc ncatted -O -a unite,precip,c,c,millimeter nclimgrid_lowres_prcp5.nc nclimgrid_lowres_prcp6.nc – mjh1366 Jan 22 '23 at 05:39
0

To offer an alternative using cdo you can also set any attribute for variables in the following way

cdo setattribute,var@attr="stuff" in.nc out.nc

for example:

cdo -setattribute,precip@long_name="Precipitation" -setattribute,precip@units="mm day-1" in.nc out.nc 
ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86