Menu

appending variables after ncdiff left them behind

Developers
2016-11-17
2016-11-18
  • Christine Smit

    Christine Smit - 2016-11-17

    I have two files with variables:

    file1.nc: data_variable, file_1_variable
    file2.nc: data_variable, file_2_variable

    if I run

    ncdiff -o out.nc file1.nc file2.nc

    The output file only has the 'data_variable' variable. The file_1_variable and file_2_variable variables are gone. I can't figure out any command line options for ncdiff to just copy those variables over. So, I thought I'd try appending them back in. This first command works:

    ncks -O -v data_variable,file_1_variable file1.nc out.nc

    And I get the file_1_variable in out.nc. Yay! The problem comes when I try to add file_2_variable in. If I run

    ncks -O data_variable,file_1_variable,file_2_variable file2.nc out.nc

    I get an error because ncks is trying to find file_1_variable in file2.nc. But if I run

    ncks -O data_variable,file_2_variable file2.nc out.nc

    Then ncks removes file_1_variable from out.nc.

    So, what do I do?

     
  • Charlie Zender

    Charlie Zender - 2016-11-17

    Hi Christine,
    First, I think the answer to your question is Yes, and that you just need to use -A instead of -O when appending to the output file.

    Second, ncbo traditionally copied unmodified any variables that were only in file1. Then I thought we changed it to also copy unmodified any variables only in file2. Pedro, if you're reading this, is that what we tried to do or do I misremember? We may need to revisit this behavior.
    cz

     
  • Christine Smit

    Christine Smit - 2016-11-18

    Thank you! That solved the problem. I vaguely remembered there was a -A append option, but when I looked in the documentation, I somehow managed to miss it.

     

Log in to post a comment.