Menu

Merging netcdf files

Help
Ed_M
2014-12-17
2014-12-17
  • Ed_M

    Ed_M - 2014-12-17

    Hi

    I have 3 netcdf files (see below) with different variables (i.e.: var1, var2, var3) that I would like to merge into a single file containing each of these, but I'm a bit uncertain on how to do it. I tried the following, but I wasn't able to make it work. Any thoughts on how I could make this work?


    What I tried:
    a. First, rename the "z" variable in the input files
    ncrename -h -v z,var1 file1.nc
    ncrename -h -v z,var2 file2.nc
    ncrename -h -v z,var3 file3.nc

    b. Then, merge the files together into a single one
    ncecat file1.nc file2.nc file3.nc out.nc
    ERROR: nco_inq_varid() reports requested variable "var1" is not in input file
    nco_err_exit(): ERROR Short NCO-generated message (usually name of function that triggered error): nco_inq_varid()
    nco_err_exit(): ERROR Error code is -49. Translation into English with nc_strerror(-49) is "NetCDF: Variable not found"
    nco_err_exit(): ERROR NCO will now exit with system call exit(EXIT_FAILURE)


    netcdf file1 {
    dimensions:
    x = 720 ;
    y = 360 ;
    variables:
    double x(x) ;
    x:long_name = "user_x_unit" ;
    x:actual_range = 0., 359.5 ;
    double y(y) ;
    y:long_name = "user_y_unit" ;
    y:actual_range = -90., 89.5 ;
    float z(y, x) ;
    z:long_name = "user_z_unit" ;
    z:_FillValue = NaNf ;
    z:actual_range = 0.200000002980232, 28.1700000762939 ;


    netcdf file2 {
    dimensions:
    x = 720 ;
    y = 360 ;
    variables:
    double x(x) ;
    x:long_name = "user_x_unit" ;
    x:actual_range = 0., 359.5 ;
    double y(y) ;
    y:long_name = "user_y_unit" ;
    y:actual_range = -90., 89.5 ;
    float z(y, x) ;
    z:long_name = "user_z_unit" ;
    z:_FillValue = NaNf ;
    z:actual_range = -24.0076866149902, 23.0212440490723 ;


    netcdf file3 {
    dimensions:
    x = 720 ;
    y = 360 ;
    variables:
    double x(x) ;
    x:long_name = "user_x_unit" ;
    x:actual_range = 0., 359.5 ;
    double y(y) ;
    y:long_name = "user_y_unit" ;
    y:actual_range = -90., 89.5 ;
    float z(y, x) ;
    z:long_name = "user_z_unit" ;
    z:_FillValue = NaNf ;
    z:actual_range = -20.9784336090088, 25.5077877044678 ;

     
  • Charlie Zender

    Charlie Zender - 2014-12-17

    Hi Ed,
    This prcoess is called "appending" in NCO-speak:
    ncks -A file1.nc file2.nc
    ncks -A file2.nc file3.nc
    No renaming should be necessary.
    http://nco.sf.net/nco.html#append
    cz

     
  • Ed_M

    Ed_M - 2014-12-17

    Thanks Charlie for the clarification & info... it worked perfectly

     

Log in to post a comment.