Project

General

Profile

how can I rename many variables and their dimensions within one file?

Added by Erik Noble almost 12 years ago

Hi. I am trying to Rename Variables and dimensions in one file.
I see the command chname, and I see that it works if I type:

$ cdo chname,u_gr_p,U temp_j.nc temp_j2.nc
cdo chname: Processed 3666690 values from 6 variables over 1 timestep. ( 0.07s )
$

But How would do this for many variables and dimensions in one file?

Basically I want to do the exact same thing that NCO's ncrename command can do ( the name of the one file I'm changing is temp_$i)

ncrename -h -v u_gr_p,U -v v_gr_p,V -v T_p,T -v rh_p,RH -v precip_c,RAINC -v precip_g,RAINNC -d pressure,lev -v pressure,lev -d latitude,lat -v latitude,lat -d longitude,lon -v longitude,lon temp_$i

Thank you


Replies (5)

RE: how can I rename many variables and their dimensions within one file? - Added by Erik Noble almost 12 years ago

Ok, I figured out how to change the names of multiple variables by just adding their names after the chname command, like so:

cdo chname,u_gr_p,U,v_gr_p,V,T_p,T,rh_p,RH,precip_c,RAINC,precip_g,RAINNC,latitude,lat,longitude,lon,pressure,lev temp_j1.nc temp_j2.nc

But, I am still puzzled about changing the dimension-names, though. I simply want to change latitude to lat, longitude to lon, and pressure to lev.
Even though I asked for this in the command above, the result didn't have this (see below).
How do I change this?
Thank you.
-Erik

$ ncdump -h temp_j2.nc
netcdf temp_j2 {
dimensions:
longitude = 393 ;
latitude = 311 ;
pressure = 7 ;
time = UNLIMITED ; // (1 currently)
variables:
float longitude(longitude) ;
longitude:standard_name = "longitude" ;
longitude:long_name = "x-coordinate in Cartesian system" ;
longitude:units = "m" ;
longitude:axis = "X" ;
float latitude(latitude) ;
latitude:standard_name = "latitude" ;
latitude:long_name = "y-coordinate in Cartesian system" ;
latitude:units = "m" ;
latitude:axis = "Y" ;
float pressure(pressure) ;
pressure:standard_name = "air_pressure" ;
pressure:long_name = "Pressure Levels" ;
pressure:units = "hPa" ;
pressure:positive = "down" ;
pressure:axis = "Z" ;
double time(time) ;
time:standard_name = "time" ;
time:units = "hours since 2006-09-02 00:00:00" ;
time:calendar = "standard" ;
float RAINNC ;
RAINNC:standard_name = "large_scale_precipitation_amount" ;
RAINNC:long_name = "Accumulated Total Grid Scale Precipitation" ;
RAINNC:units = "mm" ;
float RAINC ;
...
...
[snip]

RE: how can I rename many variables and their dimensions within one file? - Added by Jaison-Thomas Ambadan almost 12 years ago

Hi,

In your file "longitude","latitude" ...,"time" etc are NetCDF co-ordinate variables associated with a grid type. I don't think you can change the names of co-ordinate variables with CDO "chname" command - as far as I know it is only for physical "variables". If you want to change the names of "longitude" to "lon" etc I guess you have to change the "attributes" associated with NetCDF co-ordinate variables. I'm not sure CDO can change that. You can use a simple NCL/MATLAB or FORTRAN/C program for that.

Cheers,
J.

RE: how can I rename many variables and their dimensions within one file? - Added by Jaison-Thomas Ambadan almost 12 years ago

I forgot: since I'm not an expert on the subject, may be Uwe Schulzweida or Ralf Mueller can help with this :)

Cheers,
J.

RE: how can I rename many variables and their dimensions within one file? - Added by Ralf Mueller almost 12 years ago

CDO is designed to handle data variables. Plain dimensions are some kind of meta information of data variables and hence handled automatically. CDO is not meant to be a complete replacement of nco tools. For renaming, this link might be helpful.

RE: how can I rename many variables and their dimensions within one file? - Added by Erik Noble almost 12 years ago

Thank you Jaison and Ralf.

I am familiar with using the the ncrename nco tool to change both variables and attributes; I just wanted to know if CDO could help me rename attributes.

    (1-5/5)