#include <math.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/stat.h>#include <time.h>#include <unistd.h>#include "nco_getopt.h"#include <netcdf.h>#include "nco_netcdf.h"#include "libnco.h"Include dependency graph for ncrename.c:

Go to the source code of this file.
Defines | |
| #define | MAIN_PROGRAM_FILE |
Functions | |
| int | main (int argc, char **argv) |
|
|
Definition at line 62 of file ncrename.c. |
|
||||||||||||
|
Definition at line 66 of file ncrename.c. References copyright_prn(), EXIT_FAILURE, EXIT_SUCCESS, False, getopt_long, int_CEWI, option::name, NC_MAX_ATTRS, NC_MAX_DIMS, NC_MAX_NAME, NC_MAX_VARS, NC_NOERR, NC_WRITE, nco__enddef(), nco_bool, nco_close(), nco_cmd_ln_sng(), nco_enddef(), nco_exit(), nco_exit_gracefully(), nco_fl_cp(), nco_fl_lst_mk(), nco_fl_mk_lcl(), nco_fl_nm_prs(), nco_fl_rm(), nco_free(), nco_hst_att_cat(), nco_inq(), nco_inq_attid(), nco_inq_attid_flg(), nco_inq_dimid(), nco_inq_dimid_flg(), nco_inq_varid(), nco_inq_varid_flg(), nco_inq_varname(), nco_lbr_vrs_prn(), nco_open(), nco_openmp_ini(), nco_prs_att(), nco_prs_rnm_lst(), nco_redef(), nco_rename_att(), nco_rename_dim(), nco_rename_var(), nco_sng_lst_free(), nco_thr_att_cat(), nco_usg_prn(), no_argument, NULL_CEWI, rnm_sct::old_nm, omp_in_parallel(), optarg, optind, prg_nm_get(), prg_prs(), required_argument, and True. 00067 { 00068 nco_bool FILE_RETRIEVED_FROM_REMOTE_LOCATION; 00069 nco_bool FL_LST_IN_FROM_STDIN=False; /* [flg] fl_lst_in comes from stdin */ 00070 nco_bool FORCE_APPEND=False; /* Option A */ 00071 nco_bool FORCE_OVERWRITE=False; /* Option O */ 00072 nco_bool HISTORY_APPEND=True; /* Option h */ 00073 nco_bool OUTPUT_TO_NEW_NETCDF_FILE=False; 00074 nco_bool REMOVE_REMOTE_FILES_AFTER_PROCESSING=True; /* Option R */ 00075 00076 char **fl_lst_abb=NULL; /* Option a */ 00077 char **fl_lst_in; 00078 char *att_rnm_arg[NC_MAX_ATTRS]; 00079 char *cmd_ln; 00080 char *dmn_rnm_arg[NC_MAX_DIMS]; 00081 char *fl_in=NULL; 00082 char *fl_out=NULL; /* Option o */ 00083 char *fl_pth=NULL; /* Option p */ 00084 char *fl_pth_lcl=NULL; /* Option l */ 00085 char *opt_crr=NULL; /* [sng] String representation of current long-option name */ 00086 char *time_bfr_srt; 00087 char *var_rnm_arg[NC_MAX_VARS]; 00088 00089 const char * const CVS_Id="$Id: ncrename.c,v 1.90 2006/02/26 07:41:55 zender Exp $"; 00090 const char * const CVS_Revision="$Revision: 1.90 $"; 00091 const char * const opt_sht_lst="a:D:d:hl:Oo:p:rv:-:"; 00092 00093 extern char *optarg; 00094 extern int optind; 00095 00096 int abb_arg_nbr=0; 00097 int fl_nbr=0; 00098 int idx; 00099 int nbr_att_rnm=0; /* Option a. NB: nbr_att_rnm gets incremented */ 00100 int nbr_dmn_rnm=0; /* Option d. NB: nbr_dmn_rnm gets incremented */ 00101 int nbr_var_rnm=0; /* Option v. NB: nbr_var_rnm gets incremented */ 00102 int nc_id; 00103 int opt; 00104 int rcd=NC_NOERR; /* [rcd] Return code */ 00105 int thr_nbr=int_CEWI; /* [nbr] Thread number Option t */ 00106 00107 rnm_sct *var_rnm_lst=NULL_CEWI; 00108 rnm_sct *dmn_rnm_lst=NULL_CEWI; 00109 rnm_sct *att_rnm_lst=NULL_CEWI; 00110 00111 size_t hdr_pad=0UL; /* [B] Pad at end of header section */ 00112 00113 time_t time_crr_time_t; 00114 00115 static struct option opt_lng[] = 00116 { /* Structure ordered by short option key if possible */ 00117 /* Long options with no argument, no short option counterpart */ 00118 /* Long options with argument, no short option counterpart */ 00119 {"hdr_pad",required_argument,0,0}, 00120 {"header_pad",required_argument,0,0}, 00121 /* Long options with short counterparts */ 00122 {"attribute",required_argument,0,'a'}, 00123 {"debug",required_argument,0,'D'}, 00124 {"dbg_lvl",required_argument,0,'D'}, 00125 {"dimension",required_argument,0,'d'}, 00126 {"dmn",required_argument,0,'d'}, 00127 {"history",no_argument,0,'h'}, 00128 {"hst",no_argument,0,'h'}, 00129 {"local",required_argument,0,'l'}, 00130 {"lcl",required_argument,0,'l'}, 00131 {"overwrite",no_argument,0,'O'}, 00132 {"ovr",no_argument,0,'O'}, 00133 {"output",required_argument,0,'o'}, 00134 {"fl_out",required_argument,0,'o'}, 00135 {"path",required_argument,0,'p'}, 00136 {"revision",no_argument,0,'r'}, 00137 {"variable",required_argument,0,'v'}, 00138 {"version",no_argument,0,'r'}, 00139 {"vrs",no_argument,0,'r'}, 00140 {"help",no_argument,0,'?'}, 00141 {0,0,0,0} 00142 }; 00143 int opt_idx=0; /* Index of current long option into opt_lng array */ 00144 00145 /* Start clock and save command line */ 00146 cmd_ln=nco_cmd_ln_sng(argc,argv); 00147 time_crr_time_t=time((time_t *)NULL); 00148 time_bfr_srt=ctime(&time_crr_time_t); time_bfr_srt=time_bfr_srt; /* Avoid compiler warning until variable is used for something */ 00149 00150 /* Get program name and set program enum (e.g., prg=ncra) */ 00151 prg_nm=prg_prs(argv[0],&prg); 00152 00153 /* Parse command line arguments */ 00154 while(1){ 00155 /* getopt_long_only() allows one dash to prefix long options */ 00156 opt=getopt_long(argc,argv,opt_sht_lst,opt_lng,&opt_idx); 00157 /* NB: access to opt_crr is only valid when long_opt is detected */ 00158 if(opt == EOF) break; /* Parse positional arguments once getopt_long() returns EOF */ 00159 opt_crr=(char *)strdup(opt_lng[opt_idx].name); 00160 00161 /* Process long options without short option counterparts */ 00162 if(opt == 0){ 00163 if(!strcmp(opt_crr,"hdr_pad") || !strcmp(opt_crr,"header_pad")) hdr_pad=strtoul(optarg,(char **)NULL,10); 00164 } /* opt != 0 */ 00165 /* Process short options */ 00166 switch(opt){ 00167 case 0: /* Long options have already been processed, return */ 00168 break; 00169 case 'A': /* Toggle FORCE_APPEND */ 00170 FORCE_APPEND=!FORCE_APPEND; 00171 break; 00172 case 'a': /* Copy argument for later processing */ 00173 att_rnm_arg[nbr_att_rnm]=(char *)strdup(optarg); 00174 nbr_att_rnm++; 00175 break; 00176 case 'D': /* Debugging level. Default is 0. */ 00177 dbg_lvl=(unsigned short)strtol(optarg,(char **)NULL,10); 00178 break; 00179 case 'd': /* Copy argument for later processing */ 00180 dmn_rnm_arg[nbr_dmn_rnm]=(char *)strdup(optarg); 00181 nbr_dmn_rnm++; 00182 break; 00183 case 'h': /* Toggle appending to history global attribute */ 00184 HISTORY_APPEND=!HISTORY_APPEND; 00185 break; 00186 case 'l': /* Local path prefix for files retrieved from remote file system */ 00187 fl_pth_lcl=(char *)strdup(optarg); 00188 break; 00189 case 'O': /* Toggle FORCE_OVERWRITE */ 00190 FORCE_OVERWRITE=!FORCE_OVERWRITE; 00191 break; 00192 case 'o': /* Name of output file */ 00193 fl_out=(char *)strdup(optarg); 00194 break; 00195 case 'p': /* Common file path */ 00196 fl_pth=(char *)strdup(optarg); 00197 break; 00198 case 'R': /* Toggle removal of remotely-retrieved-files. Default is True. */ 00199 REMOVE_REMOTE_FILES_AFTER_PROCESSING=!REMOVE_REMOTE_FILES_AFTER_PROCESSING; 00200 break; 00201 case 'r': /* Print CVS program information and copyright notice */ 00202 (void)copyright_prn(CVS_Id,CVS_Revision); 00203 (void)nco_lbr_vrs_prn(); 00204 nco_exit(EXIT_SUCCESS); 00205 break; 00206 case 'v': /* Copy argument for later processing */ 00207 var_rnm_arg[nbr_var_rnm]=(char *)strdup(optarg); 00208 nbr_var_rnm++; 00209 break; 00210 case '?': /* Print proper usage */ 00211 (void)nco_usg_prn(); 00212 nco_exit(EXIT_SUCCESS); 00213 break; 00214 case '-': /* Long options are not allowed */ 00215 (void)fprintf(stderr,"%s: ERROR Long options are not available in this build. Use single letter options instead.\n",prg_nm_get()); 00216 nco_exit(EXIT_FAILURE); 00217 break; 00218 default: /* Print proper usage */ 00219 (void)nco_usg_prn(); 00220 nco_exit(EXIT_FAILURE); 00221 } /* end switch */ 00222 if(opt_crr != NULL) opt_crr=(char *)nco_free(opt_crr); 00223 } /* end while loop */ 00224 00225 /* Process positional arguments and fill in filenames */ 00226 fl_lst_in=nco_fl_lst_mk(argv,argc,optind,&fl_nbr,&fl_out,&FL_LST_IN_FROM_STDIN); 00227 if(fl_out != NULL) OUTPUT_TO_NEW_NETCDF_FILE=True; else fl_out=(char *)strdup(fl_lst_in[0]); 00228 00229 if(nbr_var_rnm == 0 && nbr_att_rnm == 0 && nbr_dmn_rnm == 0){ 00230 (void)fprintf(stdout,"%s: ERROR must specify something to rename\n",prg_nm); 00231 nco_usg_prn(); 00232 nco_exit(EXIT_FAILURE); 00233 } /* end if */ 00234 00235 /* Make uniform list of user-specified rename structures */ 00236 if(nbr_var_rnm > 0) var_rnm_lst=nco_prs_rnm_lst(nbr_var_rnm,var_rnm_arg); 00237 if(nbr_dmn_rnm > 0) dmn_rnm_lst=nco_prs_rnm_lst(nbr_dmn_rnm,dmn_rnm_arg); 00238 if(nbr_att_rnm > 0) att_rnm_lst=nco_prs_rnm_lst(nbr_att_rnm,att_rnm_arg); 00239 00240 /* We have final list of variables, dimensions, and attributes to rename */ 00241 00242 /* Parse filename */ 00243 fl_in=nco_fl_nm_prs(fl_in,0,&fl_nbr,fl_lst_in,abb_arg_nbr,fl_lst_abb,fl_pth); 00244 /* Make sure file is on local system and is readable or die trying */ 00245 fl_in=nco_fl_mk_lcl(fl_in,fl_pth_lcl,&FILE_RETRIEVED_FROM_REMOTE_LOCATION); 00246 00247 if(OUTPUT_TO_NEW_NETCDF_FILE){ 00248 00249 if(!FORCE_OVERWRITE){ 00250 int rcd_lcl; 00251 00252 struct stat stat_sct; 00253 00254 rcd_lcl=stat(fl_out,&stat_sct); 00255 00256 /* If file already exists, then query user whether to overwrite */ 00257 if(rcd_lcl != -1){ 00258 char usr_reply='z'; 00259 short nbr_itr=0; 00260 00261 while(usr_reply != 'n' && usr_reply != 'y'){ 00262 nbr_itr++; 00263 if(nbr_itr > 10){ 00264 (void)fprintf(stdout,"\n%s: ERROR %hd failed attempts to obtain valid interactive input. Assuming non-interactive shell and exiting.\n",prg_nm_get(),nbr_itr-1); 00265 nco_exit(EXIT_FAILURE); 00266 } /* end if */ 00267 (void)fprintf(stdout,"ncrename: overwrite %s (y/n)? ",fl_out); 00268 (void)fflush(stdout); 00269 usr_reply=(char)fgetc(stdin); 00270 /* Allow one carriage return per response free of charge */ 00271 if(usr_reply == '\n') usr_reply=(char)fgetc(stdin); 00272 (void)fflush(stdin); 00273 } /* end while */ 00274 00275 if(usr_reply == 'n'){ 00276 nco_exit(EXIT_SUCCESS); 00277 } /* end if */ 00278 } /* end if rcd_lcl != -1 */ 00279 } /* end if FORCE_OVERWRITE */ 00280 00281 /* Copy input file to output file and then search through output, 00282 changing names on the fly. This avoids possible XDR translation 00283 performance penalty of copying each variable with netCDF. */ 00284 (void)nco_fl_cp(fl_in,fl_out); 00285 00286 } /* end if OUTPUT_TO_NEW_NETCDF_FILE */ 00287 00288 /* Open file enabled for writing. Place file in define mode for renaming. */ 00289 rcd=nco_open(fl_out,NC_WRITE,&nc_id); 00290 (void)nco_redef(nc_id); 00291 00292 /* Without further ado, change names */ 00293 for(idx=0;idx<nbr_var_rnm;idx++){ 00294 if(var_rnm_lst[idx].old_nm[0] == '.'){ 00295 rcd=nco_inq_varid_flg(nc_id,var_rnm_lst[idx].old_nm+1,&var_rnm_lst[idx].id); 00296 if(rcd == NC_NOERR){ 00297 (void)nco_rename_var(nc_id,var_rnm_lst[idx].id,var_rnm_lst[idx].new_nm); 00298 if(dbg_lvl > 0) (void)fprintf(stderr,"Renamed variable \'%s\' to \'%s\'\n",var_rnm_lst[idx].old_nm+1,var_rnm_lst[idx].new_nm); 00299 }else{ 00300 (void)fprintf(stderr,"%s: WARNING Variable \"%s\" not present in %s, skipping it.\n",prg_nm,var_rnm_lst[idx].old_nm+1,fl_in); 00301 } /* end if */ 00302 }else{ /* Variable name does not contain '.' so variable presence is required */ 00303 rcd=nco_inq_varid(nc_id,var_rnm_lst[idx].old_nm,&var_rnm_lst[idx].id); 00304 (void)nco_rename_var(nc_id,var_rnm_lst[idx].id,var_rnm_lst[idx].new_nm); 00305 if(dbg_lvl > 0) (void)fprintf(stderr,"Renamed variable \'%s\' to \'%s\'\n",var_rnm_lst[idx].old_nm,var_rnm_lst[idx].new_nm); 00306 } /* end else */ 00307 } /* end loop over idx */ 00308 00309 for(idx=0;idx<nbr_dmn_rnm;idx++){ 00310 if(dmn_rnm_lst[idx].old_nm[0] == '.'){ 00311 00312 rcd=nco_inq_dimid_flg(nc_id,dmn_rnm_lst[idx].old_nm+1,&dmn_rnm_lst[idx].id); 00313 if(rcd == NC_NOERR){ 00314 (void)nco_rename_dim(nc_id,dmn_rnm_lst[idx].id,dmn_rnm_lst[idx].new_nm); 00315 if(dbg_lvl > 0) (void)fprintf(stderr,"Renamed dimension \'%s\' to \'%s\'\n",dmn_rnm_lst[idx].old_nm+1,dmn_rnm_lst[idx].new_nm); 00316 }else{ 00317 (void)fprintf(stderr,"%s: WARNING Dimension \'%s\' not present in %s, skipping it.\n",prg_nm,dmn_rnm_lst[idx].old_nm+1,fl_in); 00318 } /* end if */ 00319 00320 }else{ 00321 rcd=nco_inq_dimid(nc_id,dmn_rnm_lst[idx].old_nm,&dmn_rnm_lst[idx].id); 00322 (void)nco_rename_dim(nc_id,dmn_rnm_lst[idx].id,dmn_rnm_lst[idx].new_nm); 00323 if(dbg_lvl > 0) (void)fprintf(stderr,"Renamed dimension \'%s\' to \'%s\'\n",dmn_rnm_lst[idx].old_nm,dmn_rnm_lst[idx].new_nm); 00324 } /* end else */ 00325 } /* end loop over idx */ 00326 00327 if(nbr_att_rnm > 0){ 00328 int nbr_var_fl; 00329 00330 /* Get number of variables in file */ 00331 (void)nco_inq(nc_id,(int *)NULL,&nbr_var_fl,(int *)NULL,(int *)NULL); 00332 00333 for(idx=0;idx<nbr_att_rnm;idx++){ 00334 int var_id; 00335 int nbr_rnm=0; 00336 00337 /* Rename attribute of single variable... */ 00338 if(strchr(att_rnm_lst[idx].old_nm,'@')){ 00339 /* Get variable name from old name */ 00340 char var_nm[NC_MAX_NAME]; 00341 if(nco_prs_att((att_rnm_lst+idx),var_nm)){ 00342 /* Get var_id of variable */ 00343 if(var_nm[0] == '.'){ 00344 rcd=nco_inq_varid_flg(nc_id,var_nm+1,&var_id); 00345 if(rcd != NC_NOERR){ 00346 (void)fprintf(stderr,"%s: WARNING Variable \'%s\' not present in %s, skipping it.\n",prg_nm,var_nm+1,fl_in); 00347 continue; 00348 } /* end if */ 00349 }else{ /* Variable name does not contain '.' so variable presence is required */ 00350 rcd=nco_inq_varid(nc_id,var_nm,&var_id); 00351 } /* end if */ 00352 if(rcd == NC_NOERR){ 00353 if(att_rnm_lst[idx].old_nm[0] == '.'){ 00354 /* Preceding '.' means attribute may not be present */ 00355 rcd=nco_inq_attid_flg(nc_id,var_id,att_rnm_lst[idx].old_nm+1,&att_rnm_lst[idx].id); 00356 if(rcd == NC_NOERR){ 00357 (void)nco_rename_att(nc_id,var_id,att_rnm_lst[idx].old_nm+1,att_rnm_lst[idx].new_nm); 00358 nbr_rnm++; 00359 if(dbg_lvl > 0) (void)fprintf(stderr,"Renamed attribute \'%s\' to \'%s\' for variable \'%s\'\n",att_rnm_lst[idx].old_nm+1,att_rnm_lst[idx].new_nm,(var_nm[0] == '.' ? var_nm+1 : var_nm)); 00360 }else{ 00361 (void)fprintf(stderr,"%s: WARNING Attribute \'%s\' not present in variable \'%s\'\n",prg_nm,att_rnm_lst[idx].old_nm+1,(var_nm[0] == '.' ? var_nm+1 : var_nm)); 00362 } /* endelse */ 00363 }else{ 00364 rcd=nco_inq_attid(nc_id,var_id,att_rnm_lst[idx].old_nm,&att_rnm_lst[idx].id); 00365 if(rcd == NC_NOERR){ 00366 (void)nco_rename_att(nc_id,var_id,att_rnm_lst[idx].old_nm,att_rnm_lst[idx].new_nm); 00367 nbr_rnm++; 00368 if(dbg_lvl > 0) (void)fprintf(stderr,"Renamed attribute \'%s\' to \'%s\' for variable \'%s\'\n",att_rnm_lst[idx].old_nm,att_rnm_lst[idx].new_nm,(var_nm[0] == '.' ? var_nm+1 : var_nm)); 00369 } /* endif attribute is present */ 00370 } /* endelse attribute must be present */ 00371 }else{ 00372 (void)fprintf(stderr,"%s: WARNING variable \'%s\' not present in %s\n",prg_nm,var_nm,fl_in); 00373 } /* endelse variable is present */ 00374 } /* end if renaming single variable */ 00375 }else{ /* ...or rename attribute for all variables... */ 00376 for(var_id=-1;var_id<nbr_var_fl;var_id++){ /* Start loop at -1 for global attributes */ 00377 if(att_rnm_lst[idx].old_nm[0] == '.'){ 00378 /* Rename attribute if variable contains attribute else do nothing */ 00379 rcd=nco_inq_attid_flg(nc_id,var_id,att_rnm_lst[idx].old_nm+1,&att_rnm_lst[idx].id); 00380 if(rcd == NC_NOERR){ 00381 (void)nco_rename_att(nc_id,var_id,att_rnm_lst[idx].old_nm+1,att_rnm_lst[idx].new_nm); 00382 nbr_rnm++; 00383 /* Inform user which variable had attribute renamed */ 00384 if(var_id > -1){ 00385 char var_nm[NC_MAX_NAME]; 00386 00387 (void)nco_inq_varname(nc_id,var_id,var_nm); 00388 if(dbg_lvl > 0) (void)fprintf(stderr,"Renamed attribute \'%s\' to \'%s\' for variable \'%s\'\n",att_rnm_lst[idx].old_nm+1,att_rnm_lst[idx].new_nm,var_nm); 00389 }else{ 00390 if(dbg_lvl > 0) (void)fprintf(stderr,"Renamed global attribute \'%s\' to \'%s\'\n",att_rnm_lst[idx].old_nm+1,att_rnm_lst[idx].new_nm); 00391 } /* end else */ 00392 } /* end if */ 00393 00394 }else{ 00395 /* Rename attribute or die trying */ 00396 rcd=nco_inq_attid_flg(nc_id,var_id,att_rnm_lst[idx].old_nm,&att_rnm_lst[idx].id); 00397 if(rcd == NC_NOERR){ 00398 (void)nco_rename_att(nc_id,var_id,att_rnm_lst[idx].old_nm,att_rnm_lst[idx].new_nm); 00399 nbr_rnm++; 00400 /* Inform user which variable had attribute renamed */ 00401 if(var_id > -1){ 00402 char var_nm[NC_MAX_NAME]; 00403 00404 (void)nco_inq_varname(nc_id,var_id,var_nm); 00405 if(dbg_lvl > 0) (void)fprintf(stderr,"Renamed attribute \'%s\' to \'%s\' for variable \'%s\'\n",att_rnm_lst[idx].old_nm,att_rnm_lst[idx].new_nm,var_nm); 00406 }else{ 00407 if(dbg_lvl > 0) (void)fprintf(stderr,"Renamed global attribute \'%s\' to \'%s\'\n",att_rnm_lst[idx].old_nm,att_rnm_lst[idx].new_nm); 00408 } /* end else */ 00409 } /* end if */ 00410 } /* end else */ 00411 } /* end loop over var_id */ 00412 } /* end if renaming attribute for all variables */ 00413 /* See to it that any mandatory renaming was performed, else abort */ 00414 if(nbr_rnm == 0){ 00415 if(att_rnm_lst[idx].old_nm[0] == '.'){ 00416 (void)fprintf(stderr,"%s: WARNING Attribute \'%s\' not renamed because not found in searched variable(s)\n",prg_nm,att_rnm_lst[idx].old_nm+1); 00417 }else{ 00418 (void)fprintf(stdout,"%s: ERROR Attribute \'%s\' not present in %s, aborting.\n",prg_nm,att_rnm_lst[idx].old_nm,fl_in); 00419 nco_exit(EXIT_FAILURE); 00420 } /* end else */ 00421 } /* end if */ 00422 00423 } /* end loop over attributes to rename */ 00424 00425 } /* end if renaming attributes */ 00426 00427 /* Catenate timestamped command line to "history" global attribute */ 00428 if(HISTORY_APPEND) (void)nco_hst_att_cat(nc_id,cmd_ln); 00429 00430 /* Initialize thread information */ 00431 thr_nbr=nco_openmp_ini(thr_nbr); 00432 if(thr_nbr > 0 && HISTORY_APPEND) (void)nco_thr_att_cat(nc_id,thr_nbr); 00433 00434 #ifdef _OPENMP 00435 /* fxm: hack to get libxlsmp library linked in */ 00436 (void)omp_in_parallel(); 00437 #endif /* !_OPENMP */ 00438 00439 /* Take output file out of define mode */ 00440 if(hdr_pad == 0UL){ 00441 (void)nco_enddef(nc_id); 00442 }else{ 00443 (void)nco__enddef(nc_id,hdr_pad); 00444 if(dbg_lvl > 1) (void)fprintf(stderr,"%s: INFO Padding header with %lu extra bytes \n",prg_nm_get(),(unsigned long)hdr_pad); 00445 } /* hdr_pad */ 00446 00447 /* Close the open netCDF file */ 00448 nco_close(nc_id); 00449 00450 /* Remove local copy of file */ 00451 if(FILE_RETRIEVED_FROM_REMOTE_LOCATION && REMOVE_REMOTE_FILES_AFTER_PROCESSING) (void)nco_fl_rm(fl_in); 00452 00453 /* ncrename-unique memory */ 00454 for(idx=0;idx<nbr_att_rnm;idx++) att_rnm_arg[idx]=(char *)nco_free(att_rnm_arg[idx]); 00455 for(idx=0;idx<nbr_dmn_rnm;idx++) dmn_rnm_arg[idx]=(char *)nco_free(dmn_rnm_arg[idx]); 00456 for(idx=0;idx<nbr_var_rnm;idx++) var_rnm_arg[idx]=(char *)nco_free(var_rnm_arg[idx]); 00457 if(nbr_att_rnm > 0) att_rnm_lst=(rnm_sct *)nco_free(att_rnm_lst); 00458 if(nbr_dmn_rnm > 0) dmn_rnm_lst=(rnm_sct *)nco_free(dmn_rnm_lst); 00459 if(nbr_var_rnm > 0) var_rnm_lst=(rnm_sct *)nco_free(var_rnm_lst); 00460 00461 /* NCO-generic clean-up */ 00462 /* Free individual strings/arrays */ 00463 if(cmd_ln != NULL) cmd_ln=(char *)nco_free(cmd_ln); 00464 if(fl_in != NULL) fl_in=(char *)nco_free(fl_in); 00465 if(fl_out != NULL) fl_out=(char *)nco_free(fl_out); 00466 if(fl_pth != NULL) fl_pth=(char *)nco_free(fl_pth); 00467 if(fl_pth_lcl != NULL) fl_pth_lcl=(char *)nco_free(fl_pth_lcl); 00468 /* Free lists of strings */ 00469 if(fl_lst_in != NULL && fl_lst_abb == NULL) fl_lst_in=nco_sng_lst_free(fl_lst_in,fl_nbr); 00470 if(fl_lst_in != NULL && fl_lst_abb != NULL) fl_lst_in=nco_sng_lst_free(fl_lst_in,1); 00471 if(fl_lst_abb != NULL) fl_lst_abb=nco_sng_lst_free(fl_lst_abb,abb_arg_nbr); 00472 00473 nco_exit_gracefully(); 00474 return EXIT_SUCCESS; 00475 } /* end main() */
|
1.4.4