X
328 Rate this article:
No rating

[INTERNAL] How to change variable names and data in a NetCDF file: Xconv, NCO and ncrename

Anonym

If you have an NCDF file that contains vairables and data, a question that might arises is: how to change the names of the variables inside the NetCDF file. 

What follow are three programs that allows you to do that.

 

Discussion

Xconv

One of the easiest way to change the name of the variable is to use a command line program called Xconv (Jeff Cole from the University of Reading). The program can be downloaded in the link below:

Xconv (Download): 

http://badc.nerc.ac.uk/help/software/xconv/

Xconv Documentation: 

http://www.met.reading.ac.uk/~jeff/xconv/

Basically you have to type:

xconv -i file.nc

and then when the window opens just click on the variable you want to change the name, click on the "Names" button on the top right, change the name of the variable, click on "Apply", then on the top left in the "Output name file" write the name of the new NetCDF file, select all the fields you wish that file to have and then click on "Convert". It should be pretty straightforward. 

With Xconv you can also transform or interpolate the data to another grid, change any of the attributes of the variables, make quick plots of the fields to see how they look like or just look at the data (using the "View Data" and "Plot Data" buttons, respectively) among other things. Xconv was developed by Jeff Cole from the University of Reading.


NCO

The same variable changes in a NetCDF file can also be done using the NCO, i.e. NetCDF operators. It is available for download in the link below:

NCO: http://nco.sourceforge.net/

You have several operators that are used to do different things with NetCDF files. Say e.g. that you have 3 files (file1.nc, file2.nc, file3.nc) with several fields and you want to create a file that is the average of those three. All you have to do is type:

ncea file1.nc file2.nc file3.nc fileavg.nc

and a new file with the name fileavg.nc will be created that is the average of the three input files (ncea stands for NetCDF Ensemble Average). 

 

ncrename

To rename a variable you use "ncrename" - you just have to do "ncrename -v old_variable_name, new_variable_name file.nc" to change the name of the of the variable in file.nc (you can find more information in the link below):

NCRename:  http://linux.die.net/man/1/ncrename

To edit the data of a NetCDF file you can do it on IDL. 

The NetCDF Operators may be useful in the long run as they allow you to easily manipulate NetCDF files but it is always good to have Xconv around just to make sure that everything is fine with your file.