[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 20050302: How to extract one variable from the whole Netcdf file

>To: address@hidden
>From: Ming Yang <address@hidden>
>Subject: How to extract one variable from the whole Netcdf file 
>Organization: UNC
>Keywords: 200503021900.j22J0xv2002105 netCDF

Hi Ming,

>    I am a new user of netcdf data. I have a big nc file which contains
> tens of variables. What I want to do now is to extract one of the
> variables from the whole nc file and generate a new nc file containing
> this varaible only. Do you know what is the most efficient way to do this?

One way is to install the NCO package, freely available from:


and use the "ncks" program that is part of that package.  For example,
if you just want to extract the variable "foo" (along with all its
attributes and whatever dimensions are used by foo) from the netCDF
file "file.nc", you would just invoke:

  ncks -v foo file.nc foo.nc

and it would extract and write the requested output file.

Another freely available package that does it is CDO from 


in which you can use the program "selvar" (select variable) invoked

  selvar foo file.nc foo.nc

If you know Python, Ruby, or Perl, you could use the netCDF interface
for one of those scripting languages to develop a fairly small script
that would do what you want.  Or there's always writing a program in
C, Fortran, Java, or C++, using the appropriate netCDF interface.



Russ Rew                                         UCAR Unidata Program
address@hidden          http://www.unidata.ucar.edu/staff/russ

NOTE: All email exchanges with Unidata User Support are recorded in the Unidata inquiry tracking system and then made publicly available through the web. If you do not want to have your interactions made available in this way, you must let us know in each email you send to us.