Unidata - To provide the data services, tools, and cyberinfrastructure leadership that advance Earth system science, enhance educational opportunities, and broaden participation. Unidata
         
  advanced  
 

Re: [netcdfgroup] Appending new data to a variable

Hi,

C. S. Natarajan wrote:
>        I am trying to concatenate reasonably large netcdf files to make a
> large file. I.e I am trying to combine 64 256 MB files to create a 16GB
> file. I'm new to the file format and 'am not entirely sure whats the best
> way to go about this! Each file contains a 3-D matrix of of size
> 2048*2048*32 of type short.

Here are several possibilities:

 - Get and install the NCO (netCDF Operators) package from
   http://nco.sourceforge.net/ and use the ncecat or ncrcat utility to
   combine the input files into one output file from the command line.

 - Get and install the NCL (NCAR Command Language) package from
   http://www.ncl.ucar.edu/ and use a small NCL script to accomplish
   the concatenation.  Examples of how to do this with NCO and NCL are
   discussed in the Follow-Ups to this mailing list posting:
   
http://www.unidata.ucar.edu/mailing_lists/archives/netcdfgroup/2009/msg00194.html

 - Get and install the CDO (Climate Data Operators) package from
   http://www.mpimet.mpg.de/fileadmin/software/cdo/ and use its merge
   operators, if they're suitable for what you need.

 - Write a program using the nc_put_vara_short() interface to append
   each variable to the desired variable, with start and count arguments.

> Naively I tried just creating a new file with the size of the new dataset
> 2048*2048*2048 and tried adding data to it. However everytime I add data
> using nc_put_var_short, only the latest addition remains! for example
> ......
>    if ((retval = nc_put_var_int(ncid, varid, &data_out[0][0][0])))
>       ERR(retval);
> 
>    if ((retval = nc_put_var_int(ncid, varid, &data_out2[0][0][0])))
>       ERR(retval);
> 
>    if ((retval = nc_close(ncid)))
>       ERR(retval);
> ....
> only retains data from out2!   Is there anyway to keep appending 3-D
> matrices at the end of the current variable?

Yes, by incrementing one of the indices in the start array before each
write, so that each slab gets written to the desired section of the
output variable.

--Russ


 
 
  Contact Us     Site Map     Search     Terms and Conditions     Privacy Policy     Participation Policy
 
National Science Foundation (NSF) UCAR Community Programs   Unidata is a member of the UCAR Community Programs, is managed by the University Corporation for Atmospheric Research, and is sponsored by the National Science Foundation.
P.O. Box 3000     Boulder, CO 80307-3000 USA     Tel: 303-497-8643     Fax: 303-497-8690