ncrename renames both dimension and coordinate variable in one go

Help
Mark S.
2013-12-17
2013-12-17
  • Mark S.

    Mark S. - 2013-12-17

    Already mailed Charlie about this matter instead of dropping it here. I have the impression it might have to do with bug 44. It is a NetCDF4 file, and using NetCDF 4.2.1.1 and NCO 4.3.6

    I have a strange problem with ncrename. If I change a coordinate variable the dimension is also being renamed, and, likewise, if I change the dimension name, also the coordinate variable will be renamed. This is not the way it should be.

    An example file: http://www.knmi.nl/~savenije/test.nc

    And I do something like: ncrename -v lon,something test.nc OR
    ncrename -d lon,something test.nc

    If I first nccopy to classic the problem is not there. Maybe one could check?

    Regards, Mark

     
  • Christopher Lynnes

    Yes, I also noticed this also for netCDF-4 files with nco version 4.3.1 and 4.2.1.

    To elaborate on the problem, if you try to add both -d and -v options for the dimension variable, it fails (with an "HDF error") because it cannot find the variable by that name (having already been renamed as part of the dimension renaming).

    My workaround was the same, to convert to netCDF3.

     
  • Christopher Lynnes

    But would be nice to fix...

     
    Last edit: Christopher Lynnes 2013-12-17
  • Charlie Zender

    Charlie Zender - 2013-12-17

    Hi Mark and Chris,

    So I took another look and identified the problem.
    It has to do with the netCDF4/HDF5 library, not NCO.
    I can reproduce your problem only if I build NCO with netCDF 4.3.0
    or (presumably since yours is 4.2.1.1) earlier.
    netCDF 4.3.1-rc5 (and possibly earlier rc's) fixes this problem.
    One can demonstrate the behavior with these commands:

    ncks -O -h -m -M -4 -v lat_T42 ~/nco/data/in.nc ~/foo.nc
    ncks --cdl -m ~/foo.nc
    ncrename -O -v lat_T42,lat ~/foo.nc ~/foo2.nc
    ncks --cdl -m ~/foo2.nc
    ncrename -O -d lat_T42,lat ~/foo.nc ~/foo2.nc
    ncks --cdl -m ~/foo2.nc
    ncrename -O -d lat_T42,lat -v lat_T42,lat ~/foo.nc ~/foo2.nc
    ncks --cdl -m ~/foo2.nc

    Final note: the last ncrename triggers a longstanding bug that will
    fail on any netCDF version prior to 4.3.1-rc5. This is "Known Problem
    A" detailed in NCO ANNOUNCE. The HDF Group recently fixed this
    and this fix is in -rc5. Merry Christmas :)

    I was unaware that netCDF 4.3.0 and earlier renamed both the dimension
    and the variable on netCDF4 files (when only one rename is
    specified/intended). This would have been in the ANNOUNCE had I
    realize it. Anyway, also fixed in -rc5. I'll add some documentation
    about this to the manual for "legacy" users (i.e., everyone). To be
    clear, building NCO from the current netCDF snapshot fixes this
    problem, so upgrading is one option for you...

    Best,
    cz

     
  • Mark S.

    Mark S. - 2013-12-17

    Thanks Charlie for sorting that out. Much appreciated!

    Mark

     

Log in to post a comment.