1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
/* This is part of the netCDF package. Copyright 2005 University
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>
#include <string.h>
#ifndef LOGGING
#define LOGGING
#endif
#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)
{
int stat;
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);
stat = nc_rename_grp(grpid,newname);
check(stat);
stat = nc_close(ncid);
check(stat);
exit(0);
}
|