2018-12-07 06:27:32 +08:00
|
|
|
/* This is part of the netCDF package. Copyright 2018 University
|
2013-07-21 09:08:39 +08:00
|
|
|
Corporation for Atmospheric Research/Unidata See COPYRIGHT file for
|
|
|
|
conditions of use. See www.unidata.ucar.edu for more info.
|
|
|
|
|
|
|
|
Utility to rename a group
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2013-12-01 13:20:28 +08:00
|
|
|
#include <string.h>
|
2013-07-21 09:08:39 +08:00
|
|
|
|
2014-08-19 04:24:16 +08:00
|
|
|
#ifndef LOGGING
|
2013-07-21 09:08:39 +08:00
|
|
|
#define LOGGING
|
2014-08-19 04:24:16 +08:00
|
|
|
#endif
|
2013-07-21 09:08:39 +08:00
|
|
|
#include "netcdf.h"
|
|
|
|
|
|
|
|
#undef RENAME_DEBUG
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage(const char* msg)
|
|
|
|
{
|
|
|
|
if(msg != NULL)
|
|
|
|
fprintf(stderr,"%s\n",msg);
|
|
|
|
fprintf(stderr,"usage: renamegroup <filename> <old group path name> <new name>\n");
|
|
|
|
fflush(stderr);
|
|
|
|
exit(0); /* do not cause error */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
check(int status)
|
|
|
|
{
|
|
|
|
if(status == 0) return;
|
|
|
|
fprintf(stderr,"%d: %s\n",status,nc_strerror(status));
|
|
|
|
fflush(stderr);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2017-10-25 02:18:20 +08:00
|
|
|
int stat;
|
2013-07-21 09:08:39 +08:00
|
|
|
int ncid, grpid;
|
|
|
|
char* filename;
|
|
|
|
char* oldname;
|
|
|
|
char* newname;
|
|
|
|
|
|
|
|
switch (argc) {
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
usage("No arguments");
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
usage("Too few arguments");
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
default:
|
|
|
|
filename = argv[1];
|
|
|
|
oldname = argv[2];
|
|
|
|
newname = argv[3];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(strlen(filename) == 0)
|
|
|
|
usage("bad filename argument");
|
|
|
|
if(strlen(oldname) == 0)
|
|
|
|
usage("bad old name argument");
|
|
|
|
if(strlen(newname) == 0)
|
|
|
|
usage("bad new name argument");
|
|
|
|
|
|
|
|
stat = nc_open(filename,NC_WRITE,&ncid);
|
|
|
|
check(stat);
|
|
|
|
|
|
|
|
#ifdef RENAME_DEBUG
|
|
|
|
stat = nc_set_log_level(0);
|
|
|
|
check(stat);
|
|
|
|
nc_log_hdf5();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
stat = nc_inq_grp_full_ncid(ncid,oldname,&grpid);
|
|
|
|
check(stat);
|
|
|
|
|
2013-07-23 01:27:43 +08:00
|
|
|
stat = nc_rename_grp(grpid,newname);
|
2013-07-21 09:08:39 +08:00
|
|
|
check(stat);
|
|
|
|
|
|
|
|
stat = nc_close(ncid);
|
|
|
|
check(stat);
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|