#include #include #include #include main(int argc, char **argv) { int ncID; char varname[NC_MAX_NAME]; int i, ii, j, status, nvars; char SpecialSymbol[9] = {' ', '#', '%', '@', '+', '.', '>', '<', '-'}; /* open nc file to write */ if((status = nc_open(argv[1],NC_WRITE|NC_SHARE,&ncID)) != NC_NOERR) { fprintf(stderr,"Can not open file %s to write\n",argv[1]); exit(0); } /* get info on number of variables */ status = nc_inq_nvars(ncID, &nvars); for (j = 0; j < nvars; j++) { /* get the name of variable by its ID */ status = nc_inq_varname(ncID, j, varname); /* Replace special symbols with underscore(s) */ for (ii = 0; ii < 9; ii++) for (i = 0; i < strlen(varname); i++) { if (varname[i] == SpecialSymbol[ii]) varname[i] = '_'; } /* Rename the variable */ status = nc_rename_var(ncID, j, varname); nc_sync(ncID); } status = nc_close(ncID); }