#include <stdio.h>#include <stdlib.h>#include <string.h>#include <netcdf.h>#include "nco_netcdf.h"#include "nco.h"#include "nco_ctl.h"#include "nco_lst_utl.h"#include "nco_mmr.h"#include "nco_var_utl.h"Include dependency graph for nco_var_lst.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.
Functions | |
| nm_id_sct * | nco_var_lst_mk (const int nc_id, const int nbr_var, char *const *const var_lst_in, const nco_bool EXTRACT_ALL_COORDINATES, int *const nbr_xtr) |
| nm_id_sct * | nco_var_lst_mk_old (const int nc_id, const int nbr_var, CST_X_PTR_CST_PTR_CST_Y(char, var_lst_in), const nco_bool EXTRACT_ALL_COORDINATES, int *const nbr_xtr) |
| int | nco_var_meta_search (int nbr_var, nm_id_sct *in_lst, char *rexp, bool *in_bool) |
| nm_id_sct * | nco_var_lst_xcl (const int nc_id, const int nbr_var, nm_id_sct *xtr_lst, int *const nbr_xtr) |
| nm_id_sct * | nco_var_lst_add_crd (const int nc_id, const int nbr_dim, nm_id_sct *xtr_lst, int *const nbr_xtr) |
| void | var_lst_convert (const int nc_id, nm_id_sct *xtr_lst, const int nbr_xtr, dmn_sct *const *const dim, const int nbr_dmn_xtr, var_sct ***const var_ptr, var_sct ***const var_out_ptr) |
| void | nco_var_lst_dvd (var_sct *const *const var, var_sct *const *const var_out, const int nbr_var, const nco_bool CNV_CCM_CCSM_CF, const int nco_pck_map, const int nco_pck_plc, CST_X_PTR_CST_PTR_CST_Y(dmn_sct, dmn_xcl), const int nbr_dmn_xcl, var_sct ***const var_fix_ptr, var_sct ***const var_fix_out_ptr, int *const nbr_var_fix, var_sct ***const var_prc_ptr, var_sct ***const var_prc_out_ptr, int *const nbr_var_prc) |
| int | nco_var_lst_mrg (var_sct ***var_1_ptr, var_sct ***var_2_ptr, int *const var_nbr_1, int *const var_nbr_2) |
|
||||||||||||||||||||
|
Definition at line 290 of file nco_var_lst.c. References NC_MAX_NAME, NC_NOERR, nco_inq_dimname(), nco_inq_varid_flg(), nco_malloc(), and nco_realloc(). Referenced by main(). 00294 { 00295 /* Purpose: Add all coordinates to extraction list 00296 Find all coordinates (dimensions which are also variables) and 00297 add them to the list if they are not already there. */ 00298 00299 char crd_nm[NC_MAX_NAME]; 00300 00301 int crd_id; 00302 int idx; 00303 int rcd=NC_NOERR; /* [rcd] Return code */ 00304 00305 for(idx=0;idx<nbr_dim;idx++){ 00306 (void)nco_inq_dimname(nc_id,idx,crd_nm); 00307 00308 /* Does variable of same name exist in input file? */ 00309 rcd=nco_inq_varid_flg(nc_id,crd_nm,&crd_id); 00310 if(rcd == NC_NOERR){ 00311 /* Dimension is coordinate. Is it already on list? */ 00312 int lst_idx; 00313 00314 for(lst_idx=0;lst_idx<*nbr_xtr;lst_idx++){ 00315 if(crd_id == xtr_lst[lst_idx].id) break; 00316 } /* end loop over lst_idx */ 00317 if(lst_idx == *nbr_xtr){ 00318 /* Coordinate is not already on the list, put it there */ 00319 if(*nbr_xtr == 0) xtr_lst=(nm_id_sct *)nco_malloc((*nbr_xtr+1)*sizeof(nm_id_sct)); else xtr_lst=(nm_id_sct *)nco_realloc((void *)xtr_lst,(*nbr_xtr+1)*sizeof(nm_id_sct)); 00320 /* According to man page for realloc(), this should work even when xtr_lst == NULL */ 00321 /* xtr_lst=(nm_id_sct *)nco_realloc((void *)xtr_lst,(*nbr_xtr+1)*sizeof(nm_id_sct));*/ 00322 xtr_lst[*nbr_xtr].nm=(char *)strdup(crd_nm); 00323 xtr_lst[*nbr_xtr].id=crd_id; 00324 (*nbr_xtr)++; 00325 } /* end if */ 00326 } /* end if */ 00327 } /* end loop over idx */ 00328 00329 return xtr_lst; 00330 } /* end nco_var_lst_add_crd() */
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Definition at line 368 of file nco_var_lst.c. References var_sct_tag::dim, EXIT_FAILURE, False, dmn_sct_tag::id, var_sct_tag::is_crd_var, var_sct_tag::is_fix_var, var_sct_tag::is_rec_var, var_sct_tag::nbr_dim, NC_BYTE, NC_CHAR, NC_MAX_VARS, NC_NAT, ncap, ncatted, ncbo, ncea, ncecat, ncflint, ncks, nco_dfl_case_prg_id_err(), nco_exit(), nco_malloc(), nco_pck_plc_all_new_att, nco_pck_plc_all_xst_att, nco_pck_plc_nil, nco_pck_plc_typ_get(), nco_pck_plc_upk, nco_pck_plc_xst_new_att, nco_realloc(), nco_typ_sng(), ncpdq, ncra, ncrcat, ncwa, var_sct_tag::nm, NULL_CEWI, var_sct_tag::pck_ram, prg_get(), prg_nm_get(), True, type, var_sct_tag::type, and var_type. Referenced by main(). 00382 { 00383 /* Purpose: Divide two input lists into output lists based on program type */ 00384 00385 char *var_nm=NULL_CEWI; 00386 00387 int idx; 00388 int prg; /* Program key */ 00389 00390 enum op_typ{ 00391 fix, /* 0 [enm] Fix variable (operator alters neither data nor metadata) */ 00392 prc /* 1 [enm] Process variable (operator may alter data or metadata) */ 00393 }; /* end op_typ */ 00394 00395 int idx_dmn; 00396 int idx_xcl; 00397 int var_op_typ[NC_MAX_VARS]; 00398 00399 nc_type var_type=NC_NAT; /* NC_NAT present in netcdf.h version netCDF 3.5+ */ 00400 00401 var_sct **var_fix; 00402 var_sct **var_fix_out; 00403 var_sct **var_prc; 00404 var_sct **var_prc_out; 00405 00406 prg=prg_get(); /* Program key */ 00407 00408 /* Allocate space for too many structures first then realloc() appropriately 00409 It is calling function's responsibility to free() this memory */ 00410 var_fix=(var_sct **)nco_malloc(NC_MAX_VARS*sizeof(var_sct *)); 00411 var_fix_out=(var_sct **)nco_malloc(NC_MAX_VARS*sizeof(var_sct *)); 00412 var_prc=(var_sct **)nco_malloc(NC_MAX_VARS*sizeof(var_sct *)); 00413 var_prc_out=(var_sct **)nco_malloc(NC_MAX_VARS*sizeof(var_sct *)); 00414 00415 /* Find operation type for each variable: for now this is either fix or prc */ 00416 for(idx=0;idx<nbr_var;idx++){ 00417 00418 /* Initialize operation type to processed. Change to fixed where warranted later. */ 00419 var_op_typ[idx]=prc; 00420 var_nm=var[idx]->nm; 00421 var_type=var[idx]->type; 00422 00423 /* Override operation type based depending on both variable type and program */ 00424 switch(prg){ 00425 case ncap: 00426 var_op_typ[idx]=fix; 00427 break; 00428 case ncatted: 00429 /* Do nothing */ 00430 break; 00431 case ncbo: 00432 if((var[idx]->is_crd_var) || (var_type == NC_CHAR) || (var_type == NC_BYTE)) var_op_typ[idx]=fix; 00433 break; 00434 case ncea: 00435 if((var[idx]->is_crd_var) || (var_type == NC_CHAR) || (var_type == NC_BYTE)) var_op_typ[idx]=fix; 00436 break; 00437 case ncecat: 00438 if(var[idx]->is_crd_var) var_op_typ[idx]=fix; 00439 break; 00440 case ncflint: 00441 if((var_type == NC_CHAR) || (var_type == NC_BYTE) || (var[idx]->is_crd_var && !var[idx]->is_rec_var)) var_op_typ[idx]=fix; 00442 break; 00443 case ncks: 00444 /* Do nothing */ 00445 break; 00446 case ncra: 00447 if(!var[idx]->is_rec_var) var_op_typ[idx]=fix; 00448 break; 00449 case ncrcat: 00450 if(!var[idx]->is_rec_var) var_op_typ[idx]=fix; 00451 break; 00452 case ncpdq: 00453 case ncwa: 00454 if(nco_pck_plc != nco_pck_plc_nil){ 00455 /* Packing operation requested 00456 Variables are processed for packing/unpacking operator unless ... */ 00457 if( 00458 /* ...unpacking requested for unpacked variable... */ 00459 (nco_pck_plc == nco_pck_plc_upk && !var[idx]->pck_ram) || 00460 /* ...or packing unpacked requested and variable is already packed... */ 00461 (nco_pck_plc == nco_pck_plc_all_xst_att && var[idx]->pck_ram) || 00462 /* ...or re-packing packed requested and variable is unpacked... */ 00463 (nco_pck_plc == nco_pck_plc_xst_new_att && !var[idx]->pck_ram) || 00464 /* ...or... */ 00465 ( 00466 /* ...any type of packing requested... */ 00467 (nco_pck_plc == nco_pck_plc_all_new_att || 00468 nco_pck_plc == nco_pck_plc_all_xst_att || 00469 nco_pck_plc == nco_pck_plc_xst_new_att) && 00470 /* ...yet map does not allow (re-)packing... */ 00471 !nco_pck_plc_typ_get(nco_pck_map,var[idx]->typ_upk,(nc_type *)NULL) 00472 ) 00473 ) 00474 var_op_typ[idx]=fix; 00475 }else{ /* endif packing operation requested */ 00476 /* Process every variable containing an altered (averaged, re-ordered, reversed) dimension */ 00477 for(idx_dmn=0;idx_dmn<var[idx]->nbr_dim;idx_dmn++){ 00478 for(idx_xcl=0;idx_xcl<nbr_dmn_xcl;idx_xcl++){ 00479 if(var[idx]->dim[idx_dmn]->id == dmn_xcl[idx_xcl]->id) break; 00480 } /* end loop over idx_xcl */ 00481 if(idx_xcl != nbr_dmn_xcl){ 00482 var_op_typ[idx]=prc; 00483 break; 00484 } /* end if */ 00485 } /* end loop over idx_dmn */ 00486 /* Fix variables with no altered (averaged, re-ordered, reversed) dimensions */ 00487 if(idx_dmn == var[idx]->nbr_dim) var_op_typ[idx]=fix; 00488 } /* endif averaging or re-ordering */ 00489 break; 00490 default: nco_dfl_case_prg_id_err(); break; 00491 } /* end switch */ 00492 00493 if(CNV_CCM_CCSM_CF){ 00494 if(!strcmp(var_nm,"ntrm") || !strcmp(var_nm,"ntrn") || !strcmp(var_nm,"ntrk") || !strcmp(var_nm,"ndbase") || !strcmp(var_nm,"nsbase") || !strcmp(var_nm,"nbdate") || !strcmp(var_nm,"nbsec") || !strcmp(var_nm,"mdt") || !strcmp(var_nm,"mhisf")) var_op_typ[idx]=fix; 00495 /* NB: all !strcmp()'s except "msk_" which uses strstr() */ 00496 if(prg == ncbo && (!strcmp(var_nm,"hyam") || !strcmp(var_nm,"hybm") || !strcmp(var_nm,"hyai") || !strcmp(var_nm,"hybi") || !strcmp(var_nm,"gw") || !strcmp(var_nm,"lon_bnds") || !strcmp(var_nm,"lat_bnds") || !strcmp(var_nm,"area") || !strcmp(var_nm,"ORO") || !strcmp(var_nm,"date") || !strcmp(var_nm,"datesec") || (strstr(var_nm,"msk_") == var_nm))) var_op_typ[idx]=fix; 00497 } /* end if CNV_CCM_CCSM_CF */ 00498 00499 } /* end loop over var */ 00500 00501 /* Assign list pointers based on operation type for each variable */ 00502 *nbr_var_prc=*nbr_var_fix=0; 00503 for(idx=0;idx<nbr_var;idx++){ 00504 if(var_op_typ[idx] == fix){ 00505 var[idx]->is_fix_var=var_out[idx]->is_fix_var=True; 00506 var_fix[*nbr_var_fix]=var[idx]; 00507 var_fix_out[*nbr_var_fix]=var_out[idx]; 00508 ++*nbr_var_fix; 00509 }else{ 00510 var[idx]->is_fix_var=var_out[idx]->is_fix_var=False; 00511 var_prc[*nbr_var_prc]=var[idx]; 00512 var_prc_out[*nbr_var_prc]=var_out[idx]; 00513 ++*nbr_var_prc; 00514 if(((var[idx]->type == NC_CHAR) || (var[idx]->type == NC_BYTE)) && ((prg != ncecat) && (prg != ncpdq) && (prg != ncrcat))){ 00515 (void)fprintf(stderr,"%s: WARNING Variable %s is of type %s, for which processing (i.e., averaging, differencing) is ill-defined\n",prg_nm_get(),var[idx]->nm,nco_typ_sng(var[idx]->type)); 00516 } /* end if */ 00517 } /* end else */ 00518 } /* end loop over var */ 00519 00520 /* Sanity check */ 00521 if(*nbr_var_prc+*nbr_var_fix != nbr_var){ 00522 (void)fprintf(stdout,"%s: ERROR nbr_var_prc+nbr_var_fix != nbr_var\n",prg_nm_get()); 00523 nco_exit(EXIT_FAILURE); 00524 } /* end if */ 00525 00526 /* fxm: Remove ncap exception when finished with ncap list processing */ 00527 /* fxm: ncpdq processes all variables when pakcing requested */ 00528 if(*nbr_var_prc == 0 && prg != ncap && prg != ncpdq){ 00529 (void)fprintf(stdout,"%s: ERROR no variables fit criteria for processing\n",prg_nm_get()); 00530 switch(prg_get()){ 00531 case ncap: 00532 (void)fprintf(stdout,"%s: HINT Extraction list must contain at least one derived field\n",prg_nm_get()); 00533 case ncatted: 00534 /* Do nothing */ 00535 break; 00536 case ncbo: 00537 (void)fprintf(stdout,"%s: HINT Extraction list must contain a non-coordinate variable that is not NC_CHAR or NC_BYTE in order to perform a binary operation (e.g., subtraction)\n",prg_nm_get()); 00538 break; 00539 case ncea: 00540 (void)fprintf(stdout,"%s: HINT Extraction list must contain a non-coordinate variable that is not NC_CHAR or NC_BYTE\n",prg_nm_get()); 00541 break; 00542 case ncecat: 00543 (void)fprintf(stdout,"%s: HINT Extraction list must contain a non-coordinate variable\n",prg_nm_get()); 00544 break; 00545 case ncflint: 00546 (void)fprintf(stdout,"%s: HINT Extraction list must contain a variable that is not NC_CHAR or NC_BYTE\n",prg_nm_get()); 00547 break; 00548 case ncks: 00549 /* Do nothing */ 00550 break; 00551 case ncpdq: 00552 (void)fprintf(stdout,"%s: HINT Extraction list must contain a variable that shares at least one dimension with the re-order list\n",prg_nm_get()); 00553 break; 00554 case ncra: 00555 (void)fprintf(stdout,"%s: HINT Extraction list must contain a record variable that is not NC_CHAR or NC_BYTE\n",prg_nm_get()); 00556 break; 00557 case ncrcat: 00558 (void)fprintf(stdout,"%s: HINT Extraction list must contain a record variable which to concatenate\n",prg_nm_get()); 00559 break; 00560 case ncwa: 00561 (void)fprintf(stdout,"%s: HINT Extraction list must contain a variable that contains an averaging dimension\n",prg_nm_get()); 00562 break; 00563 default: nco_dfl_case_prg_id_err(); break; 00564 } /* end switch */ 00565 nco_exit(EXIT_FAILURE); 00566 } /* end if */ 00567 00568 /* Free unused space and save pointers in output variables */ 00569 *var_fix_ptr=(var_sct **)nco_realloc(var_fix,*nbr_var_fix*sizeof(var_sct *)); 00570 *var_fix_out_ptr=(var_sct **)nco_realloc(var_fix_out,*nbr_var_fix*sizeof(var_sct *)); 00571 *var_prc_ptr=(var_sct **)nco_realloc(var_prc,*nbr_var_prc*sizeof(var_sct *)); 00572 *var_prc_out_ptr=(var_sct **)nco_realloc(var_prc_out,*nbr_var_prc*sizeof(var_sct *)); 00573 00574 } /* end nco_var_lst_dvd */
|
|
||||||||||||||||||||||||
|
Definition at line 13 of file nco_var_lst.c. References EXIT_FAILURE, nm_id_sct::id, NC_MAX_NAME, nco_calloc(), nco_exit(), nco_free(), nco_inq_varname(), nco_malloc(), nco_realloc(), nco_var_meta_search(), nm_id_sct::nm, prg_nm_get(), and True. Referenced by main(). 00018 { 00019 /* Purpose: Create variable extraction list with or without regular expressions */ 00020 00021 int idx; 00022 int jdx; 00023 int nbr_tmp; 00024 #ifdef NCO_HAVE_REGEX_FUNCTIONALITY 00025 int rx_mch_nbr; 00026 #endif /* NCO_HAVE_REGEX_FUNCTIONALITY */ 00027 00028 char *var_sng; 00029 00030 nm_id_sct *xtr_lst=NULL; /* xtr_lst may be alloc()'d from NULL with -c option */ 00031 nm_id_sct *in_lst=NULL; 00032 bool *in_bool=NULL; 00033 00034 /* Create list of all variables in input file */ 00035 char var_nm[NC_MAX_NAME]; 00036 00037 in_lst=(nm_id_sct *)nco_malloc(nbr_var*sizeof(nm_id_sct)); 00038 for(idx=0;idx<nbr_var;idx++){ 00039 /* Get name of each variable */ 00040 (void)nco_inq_varname(nc_id,idx,var_nm); 00041 in_lst[idx].nm=(char *)strdup(var_nm); 00042 in_lst[idx].id=idx; 00043 } /* end loop over idx */ 00044 00045 /* Return all variables if .. */ 00046 if(*nbr_xtr == 0 && !EXTRACT_ALL_COORDINATES){ 00047 *nbr_xtr=nbr_var; 00048 return in_lst; 00049 } /* end if */ 00050 00051 /* Initialize and allocacte bool array to all False */ 00052 in_bool=(bool *)nco_calloc((size_t)nbr_var,sizeof(bool)); 00053 00054 /* Loop through var_lst_in */ 00055 for(idx=0;idx<*nbr_xtr;idx++){ 00056 var_sng=var_lst_in[idx]; 00057 00058 /* Convert pounds (#s) back to commas */ 00059 while(*var_sng){ 00060 if(*var_sng == '#') *var_sng=','; 00061 var_sng++; 00062 } /* end while */ 00063 var_sng=var_lst_in[idx]; 00064 00065 /* If var_sng is regular expression... */ 00066 if(strpbrk(var_sng,".*^$\\[]()<>+?|{}")){ 00067 /* ...and regular expression library is present */ 00068 #ifdef NCO_HAVE_REGEX_FUNCTIONALITY 00069 rx_mch_nbr=nco_var_meta_search(nbr_var,in_lst,var_sng,in_bool); 00070 if(rx_mch_nbr == 0) (void)fprintf(stdout,"%s: WARNING: Regular expression \"%s\" does not match any variables\nHINT: http://nco.sf.net/nco.html#rx",prg_nm_get(),var_sng); 00071 continue; 00072 #else 00073 (void)fprintf(stdout,"%s: ERROR: Sorry, wildcarding (extended regular expression matches to variables) is unavailable, so unable to compile regular expression \"%s\".\nHINT: Make sure libregex.a is on path and re-build NCO.\n",prg_nm_get(),var_sng); 00074 nco_exit(EXIT_FAILURE); 00075 #endif /* NCO_HAVE_REGEX_FUNCTIONALITY */ 00076 } /* end if regular expression */ 00077 00078 /* Normal variable so search through var array */ 00079 for(jdx=0;jdx<nbr_var;jdx++) 00080 if(!strcmp(var_sng,in_lst[jdx].nm)) break; 00081 /* No matches found so die gently */ 00082 if(jdx == nbr_var){ 00083 (void)fprintf(stdout,"%s: ERROR nco_var_lst_mk() reports user-specified variable \"%s\" is not in input file\n",prg_nm_get(),var_sng); 00084 nco_exit(EXIT_FAILURE); 00085 }else{ 00086 in_bool[jdx]=True; 00087 } /* end else */ 00088 } /* end loop over var_lst_in */ 00089 00090 /* Create final list of vars using var list and bool array */ 00091 00092 /* malloc() xtr_lst to maximium size(nbr_var) */ 00093 xtr_lst=(nm_id_sct *)nco_malloc(nbr_var*sizeof(nm_id_sct)); 00094 nbr_tmp=0; /* nbr_tmp is incremented */ 00095 for(idx=0;idx<nbr_var;idx++){ 00096 /* Copy var to output array */ 00097 if(in_bool[idx]){ 00098 xtr_lst[nbr_tmp].nm=(char *)strdup(in_lst[idx].nm); 00099 xtr_lst[nbr_tmp].id=in_lst[idx].id; 00100 nbr_tmp++; 00101 } /* end if */ 00102 (void)nco_free(in_lst[idx].nm); 00103 } /* end loop over var */ 00104 00105 /* realloc() list to actual size */ 00106 xtr_lst=(nm_id_sct *)nco_realloc(xtr_lst,nbr_tmp*sizeof(nm_id_sct)); 00107 00108 (void)nco_free(in_lst); 00109 (void)nco_free(in_bool); 00110 00111 *nbr_xtr=nbr_tmp; 00112 return xtr_lst; 00113 } /* end nco_var_lst_mk() */
|
|
||||||||||||||||||||||||
|
Definition at line 117 of file nco_var_lst.c. References EXIT_FAILURE, False, nm_id_sct::id, NC_MAX_NAME, NC_NOERR, nco_exit(), nco_inq_varid_flg(), nco_inq_varname(), nco_malloc(), nm_id_sct::nm, prg_nm_get(), and True. 00122 { 00123 /* Purpose: Create variable extraction list 00124 NB: Routine is deprecated in favor of nco_var_lst_mk() */ 00125 00126 bool err_flg=False; 00127 int rcd=NC_NOERR; /* [rcd] Return code */ 00128 int idx; 00129 00130 nm_id_sct *xtr_lst=NULL; /* xtr_lst may be alloc()'d from NULL with -c option */ 00131 00132 if(*nbr_xtr > 0){ 00133 /* If user named variables with -v option then check validity of user's list and find IDs */ 00134 xtr_lst=(nm_id_sct *)nco_malloc(*nbr_xtr*sizeof(nm_id_sct)); 00135 00136 for(idx=0;idx<*nbr_xtr;idx++){ 00137 xtr_lst[idx].nm=(char *)strdup(var_lst_in[idx]); 00138 rcd=nco_inq_varid_flg(nc_id,xtr_lst[idx].nm,&xtr_lst[idx].id); 00139 if(rcd != NC_NOERR){ 00140 (void)fprintf(stdout,"%s: ERROR nco_var_lst_mk() reports user-specified variable \"%s\" is not in input file\n",prg_nm_get(),xtr_lst[idx].nm); 00141 err_flg=True; 00142 } /* endif */ 00143 } /* end loop over idx */ 00144 00145 if(err_flg) nco_exit(EXIT_FAILURE); 00146 }else if(!EXTRACT_ALL_COORDINATES){ 00147 /* If the user did not specify variables with the -v option, 00148 and the user did not request automatic processing of all coords, 00149 then extract all variables in file. In this case 00150 we can assume variable IDs range from 0..nbr_var-1. */ 00151 char var_nm[NC_MAX_NAME]; 00152 00153 *nbr_xtr=nbr_var; 00154 xtr_lst=(nm_id_sct *)nco_malloc(*nbr_xtr*sizeof(nm_id_sct)); 00155 for(idx=0;idx<nbr_var;idx++){ 00156 /* Get name of each variable. */ 00157 (void)nco_inq_varname(nc_id,idx,var_nm); 00158 xtr_lst[idx].nm=(char *)strdup(var_nm); 00159 xtr_lst[idx].id=idx; 00160 } /* end loop over idx */ 00161 } /* end else */ 00162 00163 return xtr_lst; 00164 } /* end nco_var_lst_mk_old() */
|
|
||||||||||||||||||||
|
Definition at line 578 of file nco_var_lst.c. References EXIT_FAILURE, NC_MAX_VARS, nco_exit(), nco_free(), nco_malloc(), nco_realloc(), and prg_nm_get(). Referenced by main(). 00582 { 00583 /* Purpose: Merge two variable lists into same order 00584 NB: Routine design is open-ended with maximum flexibility 00585 Initial functionality will simply sort list two into list one order and 00586 destroy original (un-merged) list two on output 00587 Refinements could include changing number of variables in each list 00588 This would allow symmetric list merges */ 00589 00590 const char fnc_nm[]="nco_var_lst_mrg()"; /* [sng] Function name */ 00591 00592 int idx_1; 00593 int idx_2; 00594 int rcd=0; /* [rcd] Return code */ 00595 00596 var_sct **var_1; 00597 var_sct **var_2; 00598 var_sct **var_out; 00599 00600 var_1=*var_1_ptr; 00601 var_2=*var_2_ptr; 00602 00603 var_out=(var_sct **)nco_malloc(NC_MAX_VARS*sizeof(var_sct *)); 00604 00605 /* ...For each variable in first list... */ 00606 for(idx_1=0;idx_1<*var_nbr_1;idx_1++){ 00607 /* ...search through second list... */ 00608 for(idx_2=0;idx_2<*var_nbr_2;idx_2++){ 00609 /* ...until variable with same name is found... */ 00610 if(!strcmp(var_1[idx_1]->nm,var_2[idx_2]->nm)) break; /* ...then search no further... */ 00611 } /* end loop over idx_2 */ 00612 /* ...and if variable was not found in second list... */ 00613 if(idx_2 == *var_nbr_2){ 00614 (void)fprintf(stderr,"%s: ERROR %s variable \"%s\" is in list one and not in list two\n",prg_nm_get(),fnc_nm,var_1[idx_1]->nm); 00615 nco_exit(EXIT_FAILURE); 00616 } /* end if variable was not found in second list */ 00617 /* ...otherwise assign variable to correct slot in output list */ 00618 var_out[idx_1]=var_2[idx_2]; 00619 } /* end loop over idx_1 */ 00620 00621 /* Free un-merged list before overwriting with merged list */ 00622 var_2=(var_sct **)nco_free(var_2); 00623 *var_2_ptr=(var_sct **)nco_realloc(var_out,*var_nbr_2*sizeof(var_sct *)); 00624 00625 return rcd; 00626 } /* end nco_var_lst_mrg() */
|
|
||||||||||||||||||||
|
Definition at line 241 of file nco_var_lst.c. References NC_MAX_NAME, nco_free(), nco_inq_varname(), nco_malloc(), and nco_realloc(). Referenced by main(). 00245 { 00246 /* Purpose: Convert exclusion list to extraction list 00247 User wants to extract all variables except those currently in list 00248 Since it is hard to edit existing list, copy existing extraction list into 00249 exclusion list, then construct new extraction list from scratch. */ 00250 00251 char var_nm[NC_MAX_NAME]; 00252 00253 int idx; 00254 int lst_idx; 00255 int nbr_xcl; 00256 00257 nm_id_sct *xcl_lst; 00258 00259 /* Turn the extract list into the exclude list and reallocate the extract list */ 00260 nbr_xcl=*nbr_xtr; 00261 *nbr_xtr=0; 00262 xcl_lst=(nm_id_sct *)nco_malloc(nbr_xcl*sizeof(nm_id_sct)); 00263 (void)memcpy((void *)xcl_lst,(void *)xtr_lst,nbr_xcl*sizeof(nm_id_sct)); 00264 xtr_lst=(nm_id_sct *)nco_realloc((void *)xtr_lst,(nbr_var-nbr_xcl)*sizeof(nm_id_sct)); 00265 00266 for(idx=0;idx<nbr_var;idx++){ 00267 /* Get name and ID of variable */ 00268 (void)nco_inq_varname(nc_id,idx,var_nm); 00269 for(lst_idx=0;lst_idx<nbr_xcl;lst_idx++){ 00270 if(idx == xcl_lst[lst_idx].id) break; 00271 } /* end loop over lst_idx */ 00272 /* If variable is not in exclusion list then add it to new list */ 00273 if(lst_idx == nbr_xcl){ 00274 xtr_lst[*nbr_xtr].nm=(char *)strdup(var_nm); 00275 xtr_lst[*nbr_xtr].id=idx; 00276 ++*nbr_xtr; 00277 } /* end if */ 00278 } /* end loop over idx */ 00279 00280 /* Free memory for names in exclude list before losing pointers to names */ 00281 /* NB: cannot free memory if list points to names in argv[] */ 00282 /* for(idx=0;idx<nbr_xcl;idx++) xcl_lst[idx].nm=(char *)nco_free(xcl_lst[idx].nm);*/ 00283 xcl_lst=(nm_id_sct *)nco_free(xcl_lst); 00284 00285 return xtr_lst; 00286 } /* end nco_var_lst_xcl() */
|
|
||||||||||||||||||||
|
Referenced by nco_var_lst_mk(). |
|
||||||||||||||||||||||||||||||||
|
Definition at line 334 of file nco_var_lst.c. References nco_malloc(), nco_var_dpl(), nco_var_fll(), nco_xrf_dmn(), and nco_xrf_var(). 00341 { 00342 /* Purpose: Make var_sct list from nm_id list 00343 The var_sct lst is duplicated to be used for output list */ 00344 00345 int idx; 00346 00347 var_sct **var; 00348 var_sct **var_out; 00349 00350 var=(var_sct **)nco_malloc(nbr_xtr*sizeof(var_sct *)); 00351 var_out=(var_sct **)nco_malloc(nbr_xtr*sizeof(var_sct *)); 00352 00353 /* Fill in variable structure list for all extracted variables */ 00354 for(idx=0;idx<nbr_xtr;idx++){ 00355 var[idx]=nco_var_fll(nc_id,xtr_lst[idx].id,xtr_lst[idx].nm,dim,nbr_dmn_xtr); 00356 var_out[idx]=nco_var_dpl(var[idx]); 00357 (void)nco_xrf_var(var[idx],var_out[idx]); 00358 (void)nco_xrf_dmn(var_out[idx]); 00359 } /* end loop over idx */ 00360 00361 *var_ptr=var; 00362 *var_out_ptr=var_out; 00363 00364 } /* end var_lst_convert() */
|
1.4.4