Blame view

src/DECODERS/nc2nc/nc2nc.c 1.19 KB
bd9dfce2   Benjamin Renard   Add CALLEXT and D...
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <netcdf.h>


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);
}