ncrename renames both dimension and coordinate variable in one go

Mark S.
  • 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 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:

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

    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 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/ ~/
    ncks --cdl -m ~/
    ncrename -O -v lat_T42,lat ~/ ~/
    ncks --cdl -m ~/
    ncrename -O -d lat_T42,lat ~/ ~/
    ncks --cdl -m ~/
    ncrename -O -d lat_T42,lat -v lat_T42,lat ~/ ~/
    ncks --cdl -m ~/

    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...


  • Mark S.

    Mark S. - 2013-12-17

    Thanks Charlie for sorting that out. Much appreciated!



Log in to post a comment.