Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

error renaming a variable in a group #1672

Open
jswhit opened this issue Mar 13, 2020 · 6 comments
Open

error renaming a variable in a group #1672

jswhit opened this issue Mar 13, 2020 · 6 comments

Comments

@jswhit
Copy link

jswhit commented Mar 13, 2020

Reported in Unidata/netcdf4-python#999. Here's a simple C program that triggers the HDF Error. The rename only fails if the file is closed and then re-opened.

#include <netcdf.h>
#include <stdio.h>
#include <stdlib.h>
#define FILE_NAME "rename_test.nc"
#define DIM1_NAME "lon"
#define GRP1_NAME "grp"
#define VAR1_NAME "lon"
#define VAR2_NAME "longitude"
#define ERR(e) {printf("Error: %s\n", nc_strerror(e)); exit(2);}
int
main()
{
    int ncid, dimid, varid, ierr, grpid;
    /* Create a file with a variable in a group. */
    if ((ierr=nc_create(FILE_NAME, NC_NETCDF4, &ncid))) ERR(ierr);
    if ((ierr=nc_def_dim(ncid, DIM1_NAME, 1, &dimid))) ERR(ierr);
    if ((ierr=nc_def_grp(ncid, GRP1_NAME, &grpid))) ERR(ierr);
    if ((ierr=nc_def_var(grpid, VAR1_NAME, NC_FLOAT, 1, &dimid, &varid))) ERR(ierr);
    if ((ierr=nc_close(ncid))) ERR(ierr);
    /* Open the file and rename the variable. */
    if ((ierr=nc_open(FILE_NAME, NC_WRITE, &ncid))) ERR(ierr);
    if ((ierr=nc_inq_grp_ncid(ncid, GRP1_NAME, &grpid))) ERR(ierr);
    if ((ierr=nc_inq_varid(grpid, VAR1_NAME, &varid))) ERR(ierr);
    if ((ierr=nc_rename_var(grpid, varid, VAR2_NAME))) ERR(ierr);
    if ((ierr=nc_close(ncid))) ERR(ierr);
}
@edwardhartnett
Copy link
Contributor

Well if you would just name the variable correctly in the first place, there would be no need for a rename! ;-)

However, I would have thought this simple example would have worked. Sigh.

It might be time for a total re-write of the renaming code, as outlined at the end of the long discussion on #597.

@nvishnoiMW
Copy link

We observed the same issue in Netcdf version 4.8.1. Is there a targeted release to fix this issue?

Thanks,
Nalini

@krisfed
Copy link

krisfed commented Feb 24, 2022

I know it doesn't look like a particularly common issue... But would be nice to know if a fix is potentially planned for 4.8.2 or if it is on a back-burner for now.

@edwardhartnett
Copy link
Contributor

It is definitely back-burner, because this requires a lot of work to fix.

But if you try renaming in different orders, some will work, and some won't.

@krisfed
Copy link

krisfed commented Feb 28, 2022

Makes sense, thanks for the update!

@krisfed
Copy link

krisfed commented Aug 25, 2022

Hi, just wanted to check if there are any new updates, or if this is still on a back-burner for now.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants