nco/nco_att_utl.h File Reference

#include <stdio.h>
#include <string.h>
#include <time.h>
#include <netcdf.h>
#include "nco_netcdf.h"
#include "nco.h"
#include "nco_cnf_typ.h"
#include "nco_ctl.h"
#include "nco_lst_utl.h"
#include "nco_mmr.h"
#include "nco_mss_val.h"
#include "nco_sng_utl.h"

Include dependency graph for nco_att_utl.h:

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

Go to the source code of this file.

Functions

void nco_aed_prc (const int nc_id, const int var_id, const aed_sct aed)
void nco_att_cpy (const int in_id, const int out_id, const int var_in_id, const int var_out_id, const bool PCK_ATT_CPY)
void nco_fl_lst_att_cat (const int out_id, CST_X_PTR_CST_PTR_CST_Y(char, fl_lst_in), const int fl_nbr)
void nco_hst_att_cat (const int out_id, const char *const hst_sng)
void nco_mpi_att_cat (const int out_id, const int mpi_nbr)
aed_sctnco_prs_aed_lst (const int nbr_aed, X_CST_PTR_CST_PTR_Y(char, aed_arg))
int nco_prs_att (rnm_sct *const rnm_att, char *const var_nm)
rnm_sctnco_prs_rnm_lst (const int nbr_rnm, char *const *const rnm_arg)
void nco_thr_att_cat (const int out_id, const int thr_nbr)


Function Documentation

void nco_aed_prc const int  nc_id,
const int  var_id,
const aed_sct  aed
 

Definition at line 13 of file nco_att_utl.c.

References aed_append, aed_create, aed_delete, aed_modify, aed_overwrite, ptr_unn::bp, cast_nctype_void(), cast_void_nctype(), var_sct_tag::cnt, ptr_unn::cp, var_sct_tag::dmn_id, ptr_unn::dp, EXIT_FAILURE, False, ptr_unn::fp, var_sct_tag::has_mss_val, var_sct_tag::id, long_CEWI, ptr_unn::lp, var_sct_tag::mss_val, var_sct_tag::nbr_att, var_sct_tag::nbr_dim, NC_BYTE, NC_CHAR, NC_DOUBLE, NC_FLOAT, NC_GLOBAL, var_sct_tag::nc_id, NC_INT, NC_MAX_NAME, NC_NOERR, NC_SHORT, nco_del_att(), nco_dfl_case_nc_type_err(), nco_enddef(), nco_exit(), nco_free(), nco_get_att(), nco_get_var1(), nco_get_vara(), nco_inq(), nco_inq_att_flg(), nco_inq_attname(), nco_inq_dimlen(), nco_inq_var(), nco_inq_vardimid(), nco_malloc(), nco_malloc_flg(), nco_mss_val_get(), nco_put_att(), nco_put_var1(), nco_put_vara(), nco_redef(), nco_typ_lng(), nco_typ_sng(), nco_val_cnf_typ(), NULL_CEWI, prg_nm_get(), ptr_unn::sp, var_sct_tag::srt, var_sct_tag::sz, var_sct_tag::type, var_sct_tag::val, and ptr_unn::vp.

Referenced by main(), nco_att_cpy(), nco_fl_lst_att_cat(), nco_mpi_att_cat(), and nco_thr_att_cat().

00016 {
00017   /* Purpose: Process single attribute edit for single variable */
00018   
00019   /* If var_id == NC_GLOBAL ( = -1) then global attribute will be edited */
00020   
00021   char att_nm[NC_MAX_NAME];
00022   char var_nm[NC_MAX_NAME];
00023   
00024   /* fxm: netCDF 2 specifies att_sz should be type int, netCDF 3 uses size_t */
00025   int nbr_att; /* [nbr] Number of attributes */
00026   int rcd=NC_NOERR; /* [rcd] Return code */
00027   long att_sz;
00028   
00029   nc_type att_typ;
00030   
00031   void *att_val_new=NULL;
00032   
00033   if(var_id == NC_GLOBAL){
00034     /* Get number of global attributes in file */
00035     (void)nco_inq(nc_id,(int *)NULL,(int *)NULL,&nbr_att,(int *)NULL);
00036     (void)strcpy(var_nm,"Global");
00037   }else{
00038     /* Get name and number of attributes for variable */
00039     (void)nco_inq_var(nc_id,var_id,var_nm,(nc_type *)NULL,(int *)NULL,(int *)NULL,&nbr_att);
00040   } /* end else */
00041 
00042   /* Query attribute metadata when attribute name was specified */
00043   if(aed.att_nm) rcd=nco_inq_att_flg(nc_id,var_id,aed.att_nm,&att_typ,&att_sz);
00044 
00045   /* Before changing metadata, change missing values to new missing value if warranted 
00046      This capability is add-on feature not implemented too cleanly or efficiently
00047      If every variable has "missing_value" attribute and "missing_value" is changed
00048      globally, then algorithm goes into and out of define mode for each variable,
00049      rather than collecting all information in first pass and replacing all data in second pass.
00050      This is because ncatted was originally designed to change only metadata and so was
00051      architected differently from other NCO operators. */
00052   if(
00053      aed.att_nm /* Linux strcmp() dumps core if attribute name is blank */
00054      && strcmp(aed.att_nm,"missing_value") == 0 /* Current attribute is "missing_value" */
00055      && var_id != NC_GLOBAL /* Current attribute is not global */
00056      && (aed.mode == aed_modify || aed.mode == aed_overwrite)  /* Modifying or overwriting existing value */
00057      && rcd == NC_NOERR /* Only when existing missing_value attribute is modified */
00058      && att_sz == 1L /* Old missing_value attribute must be of size 1 */
00059      && aed.sz == 1L /* New missing_value attribute must be of size 1 */
00060      ){
00061 
00062     int *dmn_id;
00063     long *dmn_sz;
00064     long *dmn_srt;
00065     long idx;
00066     long var_sz=long_CEWI;
00067     ptr_unn mss_val_crr;
00068     ptr_unn mss_val_new;
00069     ptr_unn var_val;
00070     var_sct *var=NULL_CEWI;
00071 
00072     (void)fprintf(stdout,"%s: WARNING Replacing missing value data in variable %s\n",prg_nm_get(),var_nm);
00073 
00074     /* Take file out of define mode */
00075     (void)nco_enddef(nc_id);
00076   
00077     /* Initialize (partially) variable structure */
00078     var=(var_sct *)nco_malloc(sizeof(var_sct));
00079     var->nc_id=nc_id;
00080     var->id=var_id;
00081     var->sz=1L;
00082 
00083     /* Get type of variable and number of dimensions */
00084     (void)nco_inq_var(nc_id,var_id,(char *)NULL,&var->type,&var->nbr_dim,(int *)NULL,(int *)NULL);
00085     dmn_id=(int *)nco_malloc(var->nbr_dim*sizeof(int));
00086     dmn_sz=(long *)nco_malloc(var->nbr_dim*sizeof(long));
00087     dmn_srt=(long *)nco_malloc(var->nbr_dim*sizeof(long));
00088     (void)nco_inq_vardimid(nc_id,var_id,dmn_id);
00089 
00090     /* Get dimension sizes and construct variable size */
00091     for(idx=0;idx<var->nbr_dim;idx++){
00092       (void)nco_inq_dimlen(nc_id,dmn_id[idx],dmn_sz+idx);
00093       var->sz*=dmn_sz[idx];
00094       dmn_srt[idx]=0L;
00095     } /* end loop over dim */
00096     var->dmn_id=dmn_id;
00097     var->cnt=dmn_sz;
00098     var->srt=dmn_srt;
00099       
00100     /* Place nco_var_get() code inline since var struct is not truly complete */
00101     if((var->val.vp=(void *)nco_malloc_flg(var->sz*nco_typ_lng(var->type))) == NULL){
00102       (void)fprintf(stdout,"%s: ERROR Unable to malloc() %ld*%lu bytes in nco_aed_prc()\n",prg_nm_get(),var->sz,(unsigned long)nco_typ_lng(var->type));
00103       nco_exit(EXIT_FAILURE); 
00104     } /* end if */
00105     if(var->sz > 1L){
00106       (void)nco_get_vara(nc_id,var_id,var->srt,var->cnt,var->val.vp,var->type);
00107     }else{
00108       (void)nco_get_var1(nc_id,var_id,var->srt,var->val.vp,var->type);
00109     } /* end else */
00110     
00111     /* Get current missing value attribute */
00112     var->mss_val.vp=NULL;
00113     var->has_mss_val=nco_mss_val_get(nc_id,var);
00114 
00115     /* Sanity check */
00116     if(var->has_mss_val == False){
00117       (void)fprintf(stdout,"%s: ERROR \"missing_value\" attribute does not exist in nco_aed_prc()\n",prg_nm_get());
00118       nco_exit(EXIT_FAILURE);
00119     } /* end if */
00120 
00121     /* Shortcuts to avoid indirection */
00122     var_val=var->val;
00123     var_sz=var->sz;
00124 
00125     /* Get new and old missing values in same type as variable */
00126     mss_val_crr.vp=(void *)nco_malloc(att_sz*nco_typ_lng(var->type));
00127     mss_val_new.vp=(void *)nco_malloc(aed.sz*nco_typ_lng(var->type));
00128 
00129     (void)nco_val_cnf_typ(var->type,var->mss_val,var->type,mss_val_crr); 
00130     (void)nco_val_cnf_typ(aed.type,aed.val,var->type,mss_val_new);
00131 
00132     /* Typecast pointer to values before access */
00133     (void)cast_void_nctype(var->type,&var_val);
00134     (void)cast_void_nctype(var->type,&mss_val_crr);
00135     (void)cast_void_nctype(var->type,&mss_val_new);
00136   
00137     switch(var->type){
00138     case NC_FLOAT: for(idx=0L;idx<var_sz;idx++) {if(var_val.fp[idx] == *mss_val_crr.fp) var_val.fp[idx]=*mss_val_new.fp;} break;
00139     case NC_DOUBLE: for(idx=0L;idx<var_sz;idx++) {if(var_val.dp[idx] == *mss_val_crr.dp) var_val.dp[idx]=*mss_val_new.dp;} break;
00140     case NC_INT: for(idx=0L;idx<var_sz;idx++) {if(var_val.lp[idx] == *mss_val_crr.lp) var_val.lp[idx]=*mss_val_new.lp;} break;
00141     case NC_SHORT: for(idx=0L;idx<var_sz;idx++) {if(var_val.sp[idx] == *mss_val_crr.sp) var_val.sp[idx]=*mss_val_new.sp;} break;
00142     case NC_CHAR: for(idx=0L;idx<var_sz;idx++) {if(var_val.cp[idx] == *mss_val_crr.cp) var_val.cp[idx]=*mss_val_new.cp;} break;
00143     case NC_BYTE: for(idx=0L;idx<var_sz;idx++) {if(var_val.bp[idx] == *mss_val_crr.bp) var_val.bp[idx]=*mss_val_new.bp;} break;
00144     default: nco_dfl_case_nc_type_err(); break;
00145     } /* end switch */
00146 
00147     /* Un-typecast the pointer to values after access */
00148     (void)cast_nctype_void(var->type,&var_val);
00149     (void)cast_nctype_void(var->type,&mss_val_crr);
00150     (void)cast_nctype_void(var->type,&mss_val_new);
00151 
00152     /* Write to disk */
00153     if(var->nbr_dim == 0){
00154       (void)nco_put_var1(nc_id,var_id,var->srt,var->val.vp,var->type);
00155     }else{ /* end if variable is a scalar */
00156       (void)nco_put_vara(nc_id,var_id,var->srt,var->cnt,var->val.vp,var->type);
00157     } /* end else */
00158 
00159     /* Free memory */
00160     mss_val_crr.vp=nco_free(mss_val_crr.vp);
00161     mss_val_new.vp=nco_free(mss_val_new.vp);
00162     var->mss_val.vp=nco_free(var->mss_val.vp);
00163     var->val.vp=nco_free(var->val.vp);
00164     var->dmn_id=(int *)nco_free(var->dmn_id);
00165     var->srt=(long *)nco_free(var->srt);
00166     var->cnt=(long *)nco_free(var->cnt);
00167     /* 20050704 try and use nco_free() to avoid valgrind error message */
00168     var=(var_sct *)nco_free(var);
00169 
00170     /* Put file back in define mode */
00171     (void)nco_redef(nc_id);
00172   } /* end if replacing missing value data */
00173 
00174   /* Change metadata (as written, this must be done after missing_value data is replaced) */
00175   switch(aed.mode){
00176   case aed_append:      
00177     if(rcd == NC_NOERR){
00178       /* Append to existing attribute value */
00179       if(aed.type != att_typ){
00180         (void)fprintf(stdout,"%s: ERROR %s attribute %s is of type %s not %s, unable to append\n",prg_nm_get(),var_nm,aed.att_nm,nco_typ_sng(att_typ),nco_typ_sng(aed.type));
00181         nco_exit(EXIT_FAILURE);
00182       } /* end if */
00183       att_val_new=(void *)nco_malloc((att_sz+aed.sz)*nco_typ_lng(aed.type));
00184       (void)nco_get_att(nc_id,var_id,aed.att_nm,(void *)att_val_new,aed.type);
00185       /* NB: Following assumes sizeof(char) = 1 byte */
00186       (void)memcpy((void *)((char *)att_val_new+att_sz*nco_typ_lng(aed.type)),
00187                    (void *)aed.val.vp,
00188                    aed.sz*nco_typ_lng(aed.type));
00189       (void)nco_put_att(nc_id,var_id,aed.att_nm,aed.type,att_sz+aed.sz,att_val_new);
00190       att_val_new=nco_free(att_val_new);
00191     }else{
00192       /* Create new attribute */
00193       (void)nco_put_att(nc_id,var_id,aed.att_nm,aed.type,aed.sz,aed.val.vp);
00194     } /* end else */
00195     break;
00196   case aed_create:      
00197     if(rcd != NC_NOERR) (void)nco_put_att(nc_id,var_id,aed.att_nm,aed.type,aed.sz,aed.val.vp);  
00198     break;
00199   case aed_delete:      
00200     /* Delete specified attribute if attribute name was specified... */
00201     if(aed.att_nm){
00202       /* ...and if attribute is known to exist from previous inquire call... */
00203       if(rcd == NC_NOERR) (void)nco_del_att(nc_id,var_id,aed.att_nm);
00204     }else{
00205       /* ...else delete all attributes for this variable... */
00206       while(nbr_att){
00207         (void)nco_inq_attname(nc_id,var_id,nbr_att-1,att_nm);
00208         (void)nco_del_att(nc_id,var_id,att_nm);
00209         nbr_att--;
00210       } /* end while */
00211     } /* end else */
00212     break;
00213   case aed_modify:      
00214     if(rcd == NC_NOERR) (void)nco_put_att(nc_id,var_id,aed.att_nm,aed.type,aed.sz,aed.val.vp);
00215     break;
00216   case aed_overwrite:   
00217     (void)nco_put_att(nc_id,var_id,aed.att_nm,aed.type,aed.sz,aed.val.vp);  
00218     break;
00219   default: 
00220     break;
00221   } /* end switch */
00222   
00223 } /* end nco_aed_prc() */

void nco_att_cpy const int  in_id,
const int  out_id,
const int  var_in_id,
const int  var_out_id,
const bool  PCK_ATT_CPY
 

Definition at line 227 of file nco_att_utl.c.

References aed_overwrite, aed_sct::att_nm, EXIT_FAILURE, aed_sct::id, aed_sct::mode, var_sct_tag::nbr_att, NC_GLOBAL, NC_MAX_NAME, NC_NOERR, nco_aed_prc(), nco_copy_att(), nco_exit(), nco_free(), nco_get_att(), nco_inq_att(), nco_inq_att_flg(), nco_inq_attname(), nco_inq_natts(), nco_inq_varname(), nco_inq_varnatts(), nco_inq_vartype(), nco_malloc(), nco_typ_lng(), nco_val_cnf_typ(), prg_nm_get(), aed_sct::sz, aed_sct::type, aed_sct::val, aed_sct::var_nm, and ptr_unn::vp.

Referenced by main(), and nco_var_dfn().

00232 {
00233   /* Purpose: Copy attributes from input netCDF file to output netCDF file
00234      If var_in_id == NC_GLOBAL, then copy global attributes
00235      Otherwise copy only indicated variable's attributes
00236      If PCK_ATT_CPY is false, then copy all attributes except "scale_factor", "add_offset" */
00237 
00238   char att_nm[NC_MAX_NAME];
00239   char var_nm[NC_MAX_NAME];
00240 
00241   int idx;
00242   int nbr_att;
00243   int rcd; /* [enm] Return code */
00244 
00245   if(var_in_id == NC_GLOBAL){
00246     (void)nco_inq_natts(in_id,&nbr_att);
00247   }else{
00248     (void)nco_inq_varnatts(in_id,var_in_id,&nbr_att);
00249   } /* end else */
00250   
00251   /* Jump back to here if current attribute is treated specially */
00252   for(idx=0;idx<nbr_att;idx++){
00253     (void)nco_inq_attname(in_id,var_in_id,idx,att_nm);
00254     rcd=nco_inq_att_flg(out_id,var_out_id,att_nm,(nc_type *)NULL,(long *)NULL);
00255       
00256     /* If instructed not to copy packing attributes... */
00257     if(!PCK_ATT_CPY)
00258       /* ...verify attributed is "scale_factor" or "add_offset" ... */
00259       if(!strcmp(att_nm,"scale_factor") || !strcmp(att_nm,"add_offset"))
00260         /* ...then skip remainder of loop, thereby skipping attribute copy... */
00261         continue;
00262     
00263     /* Will copy overwrite an existing attribute? */
00264     if(rcd == NC_NOERR){
00265       if(var_out_id == NC_GLOBAL){
00266         (void)fprintf(stderr,"%s: WARNING Overwriting global attribute %s\n",prg_nm_get(),att_nm);
00267       }else{
00268         (void)nco_inq_varname(out_id,var_out_id,var_nm);
00269         (void)fprintf(stderr,"%s: WARNING Overwriting attribute %s for output variable %s\n",prg_nm_get(),att_nm,var_nm);
00270       } /* end else */
00271     } /* end if */
00272 
00273     if(PCK_ATT_CPY || strcmp(att_nm,"missing_value")){
00274       /* Copy all attributes except missing_value with fast library routine */
00275       (void)nco_copy_att(in_id,var_in_id,att_nm,out_id,var_out_id);
00276     }else{
00277       /* Convert "missing_value" attribute to unpacked type then copy 
00278          This imposes NCO convention that missing_value is same type as variable,
00279          whether variable is packed or not */
00280       aed_sct aed;
00281       
00282       long att_sz;
00283       size_t att_lng_in;
00284       
00285       nc_type att_typ_in;
00286       nc_type att_typ_out;
00287       
00288       ptr_unn mss_tmp;
00289       
00290       (void)nco_inq_att(in_id,var_in_id,att_nm,&att_typ_in,&att_sz);
00291       
00292       if(att_sz != 1L){
00293         (void)fprintf(stderr,"%s: ERROR input \"%s\" attribute has %li elements, but nco_att_cpy() only works for size of 1\n",prg_nm_get(),att_nm,att_sz);
00294         nco_exit(EXIT_FAILURE); 
00295       } /* end if */
00296       
00297       /* Convert "missing_value" to unpacked type before copying */
00298       aed.att_nm=att_nm; /* Name of attribute */
00299       if(var_out_id == NC_GLOBAL){
00300         aed.var_nm=NULL;
00301       }else{
00302         (void)nco_inq_varname(out_id,var_out_id,var_nm);
00303         aed.var_nm=var_nm; /* Name of variable, or NULL for global attribute */
00304       } /* end if */
00305       aed.id=out_id; /* Variable ID or NC_GLOBAL ( = -1) for global attribute */
00306       aed.sz=att_sz; /* Number of elements in attribute */
00307       (void)nco_inq_vartype(out_id,var_out_id,&att_typ_out);
00308       aed.type=att_typ_out; /* Type of attribute */
00309       aed.val.vp=(void *)nco_malloc(nco_typ_lng(aed.type)); /* Pointer to attribute value */
00310       att_lng_in=att_sz*nco_typ_lng(att_typ_in);
00311       mss_tmp.vp=(void *)nco_malloc(att_lng_in);
00312       (void)nco_get_att(in_id,var_in_id,att_nm,mss_tmp.vp,att_typ_in);
00313       (void)nco_val_cnf_typ(att_typ_in,mss_tmp,att_typ_out,aed.val);
00314       aed.mode=aed_overwrite; /* Action to perform with attribute */
00315       (void)nco_aed_prc(out_id,var_out_id,aed); 
00316       /* Release temporary memory */
00317       aed.val.vp=nco_free(aed.val.vp);
00318       mss_tmp.vp=nco_free(mss_tmp.vp);
00319     } /* PCK_ATT_CPY */
00320 
00321   } /* end loop over attributes */
00322 } /* end nco_att_cpy() */

void nco_fl_lst_att_cat const int  out_id,
CST_X_PTR_CST_PTR_CST_Y(char, fl_lst_in)  ,
const int  fl_nbr
 

Definition at line 326 of file nco_att_utl.c.

References aed_overwrite, aed_sct::att_nm, ptr_unn::cp, aed_sct::id, ptr_unn::lp, aed_sct::mode, NC_CHAR, NC_GLOBAL, NC_INT, nco_aed_prc(), nco_free(), nco_malloc(), aed_sct::sz, aed_sct::type, aed_sct::val, and aed_sct::var_nm.

Referenced by main().

00329 {
00330   /* Purpose: Write input file list to global metadata */
00331   aed_sct fl_in_lst_aed;
00332   aed_sct fl_in_nbr_aed;
00333   char att_nm_lst[]="nco_input_file_list";
00334   char att_nm_nbr[]="nco_input_file_number";
00335   char spc_sng[]=" "; /* [sng] Intervening space */
00336   char *fl_in_lst_sng;
00337   nco_int fl_nbr_lng; /* [nbr] Number of files in input file list */
00338   int fl_idx;
00339   size_t fl_in_lst_sng_lng; /* [nbr] Filename list string length */
00340   ptr_unn att_val;
00341   
00342   /* Unfold file list into single string */
00343   fl_in_lst_sng_lng=0L; /* [nbr] Filename list string length */
00344   for(fl_idx=0;fl_idx<fl_nbr;fl_idx++){
00345     fl_in_lst_sng_lng+=strlen(fl_lst_in[fl_idx]);
00346   } /* end loop over fl */
00347   /* Make room for intervening spaces and for terminating NUL character */
00348   fl_in_lst_sng=(char *)nco_malloc((fl_in_lst_sng_lng+(fl_nbr-1L)+1L)*sizeof(char));
00349   fl_in_lst_sng[0]='\0';
00350   for(fl_idx=0;fl_idx<fl_nbr;fl_idx++){
00351     fl_in_lst_sng=strcat(fl_in_lst_sng,fl_lst_in[fl_idx]);
00352     if(fl_idx != fl_nbr-1) fl_in_lst_sng=strcat(fl_in_lst_sng,spc_sng);
00353   } /* end loop over fl */
00354   
00355   /* Copy fl_nbr so can take address without endangering number */
00356   fl_nbr_lng=fl_nbr;
00357   /* Insert number of files into value */
00358   att_val.lp=&fl_nbr_lng;
00359   /* Initialize nco_input_file_number attribute edit structure */
00360   fl_in_nbr_aed.att_nm=att_nm_nbr;
00361   fl_in_nbr_aed.var_nm=NULL;
00362   fl_in_nbr_aed.id=NC_GLOBAL;
00363   fl_in_nbr_aed.sz=1L;
00364   fl_in_nbr_aed.type=NC_INT;
00365   /* Insert value into attribute structure */
00366   fl_in_nbr_aed.val=att_val;
00367   fl_in_nbr_aed.mode=aed_overwrite;
00368   /* Write nco_input_file_number attribute to disk */
00369   (void)nco_aed_prc(out_id,NC_GLOBAL,fl_in_nbr_aed);
00370 
00371   /* Insert file list into value */
00372   att_val.cp=(nco_char *)fl_in_lst_sng;
00373   /* Initialize nco_input_file_list attribute edit structure */
00374   fl_in_lst_aed.att_nm=att_nm_lst;
00375   fl_in_lst_aed.var_nm=NULL;
00376   fl_in_lst_aed.id=NC_GLOBAL;
00377   fl_in_lst_aed.sz=(long)strlen(fl_in_lst_sng)+1L;
00378   fl_in_lst_aed.type=NC_CHAR;
00379   /* Insert value into attribute structure */
00380   fl_in_lst_aed.val=att_val;
00381   fl_in_lst_aed.mode=aed_overwrite;
00382   /* Write nco_input_file_list attribute to disk */
00383   (void)nco_aed_prc(out_id,NC_GLOBAL,fl_in_lst_aed);
00384   
00385   /* Free string holding file list attribute */
00386   fl_in_lst_sng=(char *)nco_free(fl_in_lst_sng);
00387 } /* end nco_fl_lst_att_cat() */

void nco_hst_att_cat const int  out_id,
const char *const   hst_sng
 

Definition at line 391 of file nco_att_utl.c.

References NC_CHAR, NC_GLOBAL, NC_MAX_NAME, nco_free(), nco_get_att(), nco_inq(), nco_inq_att(), nco_inq_attname(), nco_malloc(), nco_put_att(), nco_typ_sng(), prg_nm_get(), and TIME_STAMP_SNG_LNG.

Referenced by main(), and nco_arm_time_install().

00393 {
00394   /* Purpose: Add command line and date stamp to existing history attribute, if any,
00395      and write them to specified output file */
00396   
00397   /* Length of string + NUL required to hold output of ctime() */
00398 #define TIME_STAMP_SNG_LNG 25 
00399   
00400   char att_nm[NC_MAX_NAME];
00401   char *ctime_sng;
00402   char *history_crr=NULL;
00403   char *history_new;
00404   char time_stamp_sng[TIME_STAMP_SNG_LNG];
00405   
00406   const char sng_history[]="history"; /* [sng] Possible name of history attribute */
00407   
00408   int idx;
00409   int glb_att_nbr;
00410 
00411   long att_sz=0;
00412 
00413   nc_type att_typ;
00414   
00415   time_t time_crr_time_t;
00416 
00417   /* Create timestamp string */
00418   time_crr_time_t=time((time_t *)NULL);
00419   ctime_sng=ctime(&time_crr_time_t);
00420   /* NUL-terminate time_stamp_sng */
00421   time_stamp_sng[TIME_STAMP_SNG_LNG-1]='\0';
00422   /* Get rid of carriage return in ctime_sng */
00423   (void)strncpy(time_stamp_sng,ctime_sng,TIME_STAMP_SNG_LNG-1);
00424 
00425   /* Get number of global attributes in file */
00426   (void)nco_inq(out_id,(int *)NULL,(int *)NULL,&glb_att_nbr,(int *)NULL);
00427 
00428   for(idx=0;idx<glb_att_nbr;idx++){
00429     (void)nco_inq_attname(out_id,NC_GLOBAL,idx,att_nm);
00430     if(!strcasecmp(att_nm,sng_history)) break;
00431   } /* end loop over att */
00432 
00433   /* Fill in history string */
00434   if(idx == glb_att_nbr){
00435     /* Global attribute "[hH]istory" does not yet exist */
00436 
00437     /* Add 3 for formatting characters */
00438     history_new=(char *)nco_malloc((strlen(hst_sng)+strlen(time_stamp_sng)+3)*sizeof(char));
00439     (void)sprintf(history_new,"%s: %s",time_stamp_sng,hst_sng);
00440     /* Set attribute name to default */
00441     (void)strcpy(att_nm,sng_history);
00442 
00443   }else{ 
00444     /* Global attribute "[hH]istory" currently exists */
00445   
00446     /* NB: ncattinq(), unlike strlen(), counts terminating NUL for stored NC_CHAR arrays */
00447     (void)nco_inq_att(out_id,NC_GLOBAL,att_nm,&att_typ,&att_sz);
00448     if(att_typ != NC_CHAR){
00449       (void)fprintf(stderr,"%s: WARNING the \"%s\" global attribute is type %s, not %s. Therefore current command line will not be appended to %s in output file.\n",prg_nm_get(),att_nm,nco_typ_sng(att_typ),nco_typ_sng(NC_CHAR),att_nm);
00450       return;
00451     } /* end if */
00452 
00453     /* Allocate and NUL-terminate space for current history attribute
00454        If history attribute is of size zero then ensure strlen(history_crr) = 0 */
00455     history_crr=(char *)nco_malloc((att_sz+1)*sizeof(char));
00456     history_crr[att_sz]='\0';
00457     if(att_sz > 0) (void)nco_get_att(out_id,NC_GLOBAL,att_nm,(void *)history_crr,NC_CHAR);
00458 
00459     /* Add 4 for formatting characters */
00460     history_new=(char *)nco_malloc((strlen(history_crr)+strlen(hst_sng)+strlen(time_stamp_sng)+4)*sizeof(char));
00461     (void)sprintf(history_new,"%s: %s\n%s",time_stamp_sng,hst_sng,history_crr);
00462   } /* endif history global attribute currently exists */
00463 
00464   (void)nco_put_att(out_id,NC_GLOBAL,att_nm,NC_CHAR,(long)(strlen(history_new)+1UL),(void *)history_new);
00465 
00466   history_crr=(char *)nco_free(history_crr);
00467   history_new=(char *)nco_free(history_new);
00468 
00469   return; /* 20050109: fxm added return to void function to squelch erroneous gcc-3.4.2 warning */ 
00470 } /* end nco_hst_att_cat() */

void nco_mpi_att_cat const int  out_id,
const int  mpi_nbr
 

Definition at line 813 of file nco_att_utl.c.

References aed_overwrite, aed_sct::att_nm, aed_sct::id, ptr_unn::lp, aed_sct::mode, NC_GLOBAL, NC_INT, nco_aed_prc(), aed_sct::sz, aed_sct::type, aed_sct::val, and aed_sct::var_nm.

Referenced by main().

00815 {
00816   /* Purpose: Write number of tasks information to global metadata */
00817   aed_sct mpi_nbr_aed;
00818   char att_nm_nbr[]="nco_mpi_task_number";
00819   nco_int mpi_nbr_lng; /* [nbr] MPI tasks number copy */
00820   ptr_unn att_val;
00821   
00822   /* Copy mpi_nbr so can take address without endangering number */
00823   mpi_nbr_lng=mpi_nbr;
00824   /* Insert tasks number into value */
00825   att_val.lp=&mpi_nbr_lng;
00826   /* Initialize nco_mpi_task_number attribute edit structure */
00827   mpi_nbr_aed.att_nm=att_nm_nbr;
00828   mpi_nbr_aed.var_nm=NULL;
00829   mpi_nbr_aed.id=NC_GLOBAL;
00830   mpi_nbr_aed.sz=1L;
00831   mpi_nbr_aed.type=NC_INT;
00832   /* Insert value into attribute structure */
00833   mpi_nbr_aed.val=att_val;
00834   mpi_nbr_aed.mode=aed_overwrite;
00835   /* Write nco_mpi_tasks_number attribute to disk */
00836   (void)nco_aed_prc(out_id,NC_GLOBAL,mpi_nbr_aed);
00837 
00838 } /* end nco_mpi_att_cat() */

aed_sct* nco_prs_aed_lst const int  nbr_aed,
X_CST_PTR_CST_PTR_Y(char, aed_arg) 
 

Definition at line 474 of file nco_att_utl.c.

References aed_append, aed_create, aed_delete, aed_modify, aed_overwrite, aed_sct::att_nm, ptr_unn::bp, cast_nctype_void(), ptr_unn::cp, dbg_lvl_get(), ptr_unn::dp, EXIT_FAILURE, False, ptr_unn::fp, aed_sct::id, ptr_unn::lp, lst_prs_2D(), aed_sct::mode, NC_BYTE, NC_CHAR, NC_DOUBLE, NC_FLOAT, NC_INT, NC_SHORT, nco_dfl_case_nc_type_err(), nco_exit(), nco_free(), nco_malloc(), nco_sng_lst_free(), nco_typ_lng(), nco_typ_sng(), NULL_CEWI, prg_nm_get(), sng_ascii_trn(), sng_lst_cat(), ptr_unn::sp, var_sct_tag::sz, aed_sct::sz, type, aed_sct::type, var_sct_tag::val, aed_sct::val, aed_sct::var_nm, and ptr_unn::vp.

Referenced by main().

00476 {
00477   /* Purpose: Parse name, type, size, and value elements of comma-separated list of attribute edit information
00478      Routine merely evaluates syntax of input expressions
00479      Routine does not validate attributes or variables against those present in input netCDF file */
00480 
00481   /* Options are:
00482      -a att_nm,var_nm,mode,att_typ,att_val (modifies attribute att_nm for the single variable var_nm)
00483 
00484      -a att_nm,,mode,att_typ,att_val (modifies attribute att_nm for every variable in file)
00485      If option -a is given with var_nm = NULL, then var_nm is expanded into every variable name in file
00486      Thus attribute editing operation is performed on every variable in file.
00487 
00488      mode,att_nm,att_typ,att_val (modifies global attribute att_nm for file)
00489      This option may be combined with modes -a, -c, -d, or -o to specify 
00490      appending to, changing, deleting, or overwriting, any existing global attribute named att_nm
00491 
00492      One mode must be set for each edited attribute: append (a), create (c), delete (d), modify (m), or overwrite (o).
00493      -a: Attribute append mode
00494      Append value att_val to current var_nm attribute att_nm value att_val, if any. 
00495      If var_nm does not have an attribute att_nm, there is not effect.
00496 
00497      -c: Attribute create mode
00498      Create variable var_nm attribute att_nm with att_val if att_nm does not yet exist. 
00499      If var_nm already has an attribute att_nm, there is not effect.
00500 
00501      -d: Attribute delete mode
00502      Delete current var_nm attribute att_nm.
00503      If var_nm does not have an attribute att_nm, there is not effect.
00504 
00505      -m: Attribute modify mode
00506      Change value of current var_nm attribute att_nm to value att_val.
00507      If var_nm does not have an attribute att_nm, there is not effect.
00508 
00509      -o: Attribute overwrite mode
00510      Write attribute att_nm with value att_val to variable var_nm, overwriting existing attribute att_nm, if any.
00511      This is default mode.
00512    */
00513 
00514   char **arg_lst;
00515 
00516   const char * const dlm_sng=",";
00517 
00518   const long idx_att_val_arg=4L; /* Number of required delimiters preceding attribute values in -a argument list */
00519 
00520   aed_sct *aed_lst;
00521 
00522   int idx;
00523   int arg_nbr;
00524 
00525   aed_lst=(aed_sct *)nco_malloc(nbr_aed*sizeof(aed_sct));
00526 
00527   for(idx=0;idx<nbr_aed;idx++){
00528 
00529     /* Process attribute edit specifications as normal text list */
00530     arg_lst=lst_prs_2D(aed_arg[idx],dlm_sng,&arg_nbr);
00531 
00532     /* Check syntax */
00533     if(
00534        arg_nbr < 5 || /* Need more info */
00535        /* arg_lst[0] == NULL || */ /* att_nm not specified */
00536        arg_lst[2] == NULL || /* mode not specified */
00537        (*(arg_lst[2]) != 'd' && (arg_lst[3] == NULL || (arg_lst[idx_att_val_arg] == NULL && *(arg_lst[3]) != 'c'))) || /* att_typ and att_val must be specified when mode is not delete, except that att_val = "" is valid for character type */
00538        False){
00539       (void)fprintf(stdout,"%s: ERROR in attribute edit specification %s\n",prg_nm_get(),aed_arg[idx]);
00540       nco_exit(EXIT_FAILURE);
00541     } /* end if */
00542 
00543     /* Initialize structure */
00544     /* aed strings not explicitly set by user remain NULL,
00545        i.e., specifying default setting appears as if nothing was set.
00546        Hopefully, in routines that follow, the branch followed by an aed for which
00547        all default settings were specified (e.g.,"-a foo,,,,") will yield same result
00548        as branch for which all defaults were set. */
00549     aed_lst[idx].att_nm=NULL;
00550     aed_lst[idx].var_nm=NULL;
00551     aed_lst[idx].val.vp=NULL;
00552     aed_lst[idx].type=NC_CHAR;
00553     aed_lst[idx].mode=aed_overwrite;
00554     aed_lst[idx].sz=-1L;
00555     aed_lst[idx].id=-1;
00556 
00557     /* Fill in structure */
00558     if(arg_lst[0] != NULL) aed_lst[idx].att_nm=strdup(arg_lst[0]);
00559     if(arg_lst[1] != NULL) aed_lst[idx].var_nm=strdup(arg_lst[1]);
00560 
00561     /* fxm: Change these switches to string comparisons someday */
00562     /* Set mode of current aed structure */
00563     /* Convert single letter code to mode enum */
00564     /*    if(!strcmp("append",arg_lst[2])){aed_lst[idx].mode=aed_append;
00565     }else if(!strcmp("create",arg_lst[2])){aed_lst[idx].mode=aed_create;
00566     }else if(!strcmp("delete",arg_lst[2])){aed_lst[idx].mode=aed_delete;
00567     }else if(!strcmp("modify",arg_lst[2])){aed_lst[idx].mode=aed_modify;
00568     }else if(!strcmp("overwrite",arg_lst[2])){aed_lst[idx].mode=aed_overwrite;} */
00569     switch(*(arg_lst[2])){
00570     case 'a': aed_lst[idx].mode=aed_append; break;
00571     case 'c': aed_lst[idx].mode=aed_create; break;
00572     case 'd': aed_lst[idx].mode=aed_delete; break;
00573     case 'm': aed_lst[idx].mode=aed_modify; break;
00574     case 'o': aed_lst[idx].mode=aed_overwrite; break;
00575     default: 
00576       (void)fprintf(stderr,"%s: ERROR `%s' is not a supported mode\n",prg_nm_get(),arg_lst[2]);
00577       (void)fprintf(stderr,"%s: HINT: Valid modes are `a' = append, `c' = create,`d' = delete, `m' = modify, and `o' = overwrite",prg_nm_get());
00578       nco_exit(EXIT_FAILURE);
00579       break;
00580     } /* end switch */
00581 
00582     /* Attribute type and value do not matter if we are deleting it */
00583     if(aed_lst[idx].mode != aed_delete){
00584 
00585       /* Set type of current aed structure */
00586       /* Convert single letter code to type enum */
00587       switch(*(arg_lst[3])){
00588       case 'f': aed_lst[idx].type=NC_FLOAT; break;
00589       case 'd': aed_lst[idx].type=NC_DOUBLE; break;
00590       case 'l': 
00591       case 'i': aed_lst[idx].type=NC_INT; break;
00592       case 's': aed_lst[idx].type=NC_SHORT; break;
00593       case 'c': aed_lst[idx].type=NC_CHAR; break;
00594       case 'b': aed_lst[idx].type=NC_BYTE; break;
00595       default: 
00596         (void)fprintf(stderr,"%s: ERROR `%s' is not a supported netCDF data type\n",prg_nm_get(),arg_lst[3]);
00597         (void)fprintf(stderr,"%s: HINT: Valid data types are `c' = char, `f' = float, `d' = double,`s' = short, `l' = long, `b' = byte",prg_nm_get());
00598         nco_exit(EXIT_FAILURE);
00599         break;
00600       } /* end switch */
00601       
00602       /* Re-assemble string list values which inadvertently contain delimiters */
00603       if(aed_lst[idx].type == NC_CHAR && arg_nbr > idx_att_val_arg+1){
00604         /* Number of elements which must be concatenated into single string value */
00605         long lmn_nbr;
00606         lmn_nbr=arg_nbr-idx_att_val_arg; 
00607         if(dbg_lvl_get() >= 2) (void)fprintf(stdout,"%s: WARNING NC_CHAR (string) attribute is embedded with %li literal element delimiters (\"%s\"), re-assembling...\n",prg_nm_get(),lmn_nbr-1L,dlm_sng);
00608         /* Rewrite list, splicing in original delimiter string */
00609         /* fxm: TODO nco527 this is probably where ncatted memory is lost */
00610         arg_lst[idx_att_val_arg]=sng_lst_cat(arg_lst+idx_att_val_arg,lmn_nbr,dlm_sng);
00611         /* Keep bookkeeping straight, just in case */
00612         arg_nbr=idx_att_val_arg+1L;
00613         lmn_nbr=1L;
00614       } /* endif arg_nbr > idx_att_val_arg+1 */
00615       
00616       /* Replace any C language '\X' escape codes with ASCII bytes */
00617       if(aed_lst[idx].type == NC_CHAR) (void)sng_ascii_trn(arg_lst[idx_att_val_arg]);
00618 
00619       /* Set size of current aed structure */
00620       if(aed_lst[idx].type == NC_CHAR){
00621         /* Include NUL-terminator in string length */
00622         aed_lst[idx].sz=(arg_lst[idx_att_val_arg] == NULL) ? 0L : strlen(arg_lst[idx_att_val_arg])+1L;
00623       }else{
00624         /* Number of elements of numeric types is determined by number of delimiters */
00625         aed_lst[idx].sz=arg_nbr-idx_att_val_arg;
00626       } /* end else */
00627       
00628       /* Set value of current aed structure */
00629       if(aed_lst[idx].type == NC_CHAR){
00630         aed_lst[idx].val.cp=(nco_char *)strdup(arg_lst[idx_att_val_arg]);
00631       }else{
00632         double *val_arg_dbl=NULL_CEWI;
00633         
00634         long lmn;
00635         
00636         val_arg_dbl=(double *)nco_malloc(aed_lst[idx].sz*sizeof(double));
00637         aed_lst[idx].val.vp=(void *)nco_malloc(aed_lst[idx].sz*nco_typ_lng(aed_lst[idx].type));
00638         
00639         for(lmn=0L;lmn<aed_lst[idx].sz;lmn++) val_arg_dbl[lmn]=strtod(arg_lst[idx_att_val_arg+lmn],(char **)NULL);
00640         
00641         /* Copy and typecast entire array of values, using implicit coercion rules of C */
00642         /* 20011001: Use explicit coercion rules to quiet C++ compiler warnings */
00643         switch(aed_lst[idx].type){
00644         case NC_FLOAT: for(lmn=0L;lmn<aed_lst[idx].sz;lmn++) {aed_lst[idx].val.fp[lmn]=(float)val_arg_dbl[lmn];} break; 
00645         case NC_DOUBLE: for(lmn=0L;lmn<aed_lst[idx].sz;lmn++) {aed_lst[idx].val.dp[lmn]=(double)val_arg_dbl[lmn];} break; 
00646         case NC_INT: for(lmn=0L;lmn<aed_lst[idx].sz;lmn++) {aed_lst[idx].val.lp[lmn]=(nco_int)val_arg_dbl[lmn];} break; 
00647         case NC_SHORT: for(lmn=0L;lmn<aed_lst[idx].sz;lmn++) {aed_lst[idx].val.sp[lmn]=(short)val_arg_dbl[lmn];} break; 
00648         case NC_CHAR: for(lmn=0L;lmn<aed_lst[idx].sz;lmn++) {aed_lst[idx].val.cp[lmn]=(nco_char)val_arg_dbl[lmn];} break; 
00649         case NC_BYTE: for(lmn=0L;lmn<aed_lst[idx].sz;lmn++) {aed_lst[idx].val.bp[lmn]=(nco_byte)val_arg_dbl[lmn];} break; 
00650         default: nco_dfl_case_nc_type_err(); break;
00651         } /* end switch */
00652         
00653         /* Free array used to hold double values */
00654         val_arg_dbl=(double *)nco_free(val_arg_dbl);
00655       } /* end else */
00656       /* Un-typecast pointer to values after access */
00657       (void)cast_nctype_void(aed_lst[idx].type,&aed_lst[idx].val);
00658       
00659     } /* end if mode is not delete */
00660 
00661     arg_lst=nco_sng_lst_free(arg_lst,arg_nbr);
00662 
00663   } /* end loop over aed */
00664   
00665   if(dbg_lvl_get() == 5){
00666     for(idx=0;idx<nbr_aed;idx++){
00667       (void)fprintf(stderr,"aed_lst[%d].att_nm = %s\n",idx,aed_lst[idx].att_nm);
00668       (void)fprintf(stderr,"aed_lst[%d].var_nm = %s\n",idx,aed_lst[idx].var_nm == NULL ? "NULL" : aed_lst[idx].var_nm);
00669       (void)fprintf(stderr,"aed_lst[%d].id = %i\n",idx,aed_lst[idx].id);
00670       (void)fprintf(stderr,"aed_lst[%d].sz = %li\n",idx,aed_lst[idx].sz);
00671       (void)fprintf(stderr,"aed_lst[%d].type = %s\n",idx,nco_typ_sng(aed_lst[idx].type));
00672       /*      (void)fprintf(stderr,"aed_lst[%d].val = %s\n",idx,aed_lst[idx].val);*/
00673       (void)fprintf(stderr,"aed_lst[%d].mode = %i\n",idx,aed_lst[idx].mode);
00674     } /* end loop over idx */
00675   } /* end debug */
00676   
00677   return aed_lst;
00678   
00679 } /* end nco_prs_aed_lst() */

int nco_prs_att rnm_sct *const   rnm_att,
char *const   var_nm
 

Definition at line 683 of file nco_att_utl.c.

References EXIT_FAILURE, NC_MAX_NAME, nco_exit(), rnm_sct::new_nm, rnm_sct::old_nm, and prg_nm_get().

Referenced by main().

00683                                                           :]Attribute name on input, Attribute name on output */
00684  char * const var_nm) /* O [sng] Variable name, if any */
00685 {
00686   /* Purpose: Check if attribute name space contains variable name before attribute name of form var_nm:att_nm
00687      Attribute name is then extracted from from old_nm and new_nm as necessary */
00688   
00689   char *dlm_ptr; /* Ampersand pointer */
00690 
00691   size_t att_nm_lng;
00692   size_t var_nm_lng;
00693 
00694   dlm_ptr=strchr(rnm_att->old_nm,'@');  
00695   if(dlm_ptr == NULL) return 0;
00696   
00697   att_nm_lng=strlen(rnm_att->old_nm);
00698   
00699   /* Return if ampersand appears to be part of attribute name */
00700   if(att_nm_lng < 3 || dlm_ptr == rnm_att->old_nm || dlm_ptr == rnm_att->old_nm+att_nm_lng-1) return 0;
00701 
00702   /* NUL-terminate variable name */
00703   *dlm_ptr='\0';
00704   var_nm_lng=strlen(rnm_att->old_nm);
00705   if(var_nm_lng > NC_MAX_NAME){
00706     (void)fprintf(stdout,"%s: ERROR Derived variable name \"%s\" too long\n",prg_nm_get(),rnm_att->old_nm);
00707     nco_exit(EXIT_FAILURE);
00708   } /* end if */ 
00709 
00710   /* Copy variable name only */
00711   strcpy(var_nm,rnm_att->old_nm);
00712   /* Set to attribute name alone */
00713   rnm_att->old_nm=dlm_ptr+1; 
00714     
00715   dlm_ptr=strchr(rnm_att->new_nm,'@');  
00716   if(dlm_ptr){
00717     att_nm_lng=strlen(rnm_att->new_nm);
00718     if((dlm_ptr-rnm_att->new_nm) < (long)att_nm_lng) rnm_att->new_nm=dlm_ptr+1; else return 0;
00719   } /* endif */
00720   return 1;
00721 } /* end nco_prs_att() */

rnm_sct* nco_prs_rnm_lst const int  nbr_rnm,
char *const *const   rnm_arg
 

Definition at line 725 of file nco_att_utl.c.

References dbg_lvl_get(), EXIT_FAILURE, nco_exit(), nco_malloc(), nco_usg_prn(), rnm_sct::new_nm, and rnm_sct::old_nm.

Referenced by main().

00727 {
00728   /* Purpose: Set old_nm, new_nm elements of rename structure
00729      Routine merely fills rename structure and does not attempt to validate 
00730      presence of variables in input netCDF file. */
00731 
00732   rnm_sct *rnm_lst;
00733 
00734   int idx;
00735 
00736   ptrdiff_t lng_arg_1;
00737   ptrdiff_t lng_arg_2;
00738 
00739   rnm_lst=(rnm_sct *)nco_malloc((size_t)nbr_rnm*sizeof(rnm_sct));
00740 
00741   for(idx=0;idx<nbr_rnm;idx++){
00742     char *comma_1_cp;
00743 
00744     /* Find positions of commas and number of characters between (non-inclusive) them */
00745     comma_1_cp=strchr(rnm_arg[idx],',');
00746     
00747     /* Before doing any pointer arithmetic, make sure pointers are valid */
00748     if(comma_1_cp == NULL){
00749       (void)nco_usg_prn();
00750       nco_exit(EXIT_FAILURE);
00751     } /* end if */
00752     
00753     lng_arg_1=comma_1_cp-rnm_arg[idx]; 
00754     lng_arg_2=rnm_arg[idx]+strlen(rnm_arg[idx])-comma_1_cp-1; 
00755     
00756     /* Exit if length of either argument is zero */
00757     if(lng_arg_1 <= 0 || lng_arg_2 <= 0){
00758       (void)nco_usg_prn();
00759       nco_exit(EXIT_FAILURE);
00760     } /* end if */
00761     
00762     /* Assign pointers to member of rnm_lst */
00763     rnm_lst[idx].old_nm=rnm_arg[idx];
00764     rnm_lst[idx].new_nm=comma_1_cp+1;
00765 
00766     /* NUL-terminate arguments */
00767     rnm_lst[idx].old_nm[lng_arg_1]='\0';
00768     rnm_lst[idx].new_nm[lng_arg_2]='\0';
00769     
00770   } /* end loop over rnm_lst */
00771 
00772   if(dbg_lvl_get() == 5){
00773     for(idx=0;idx<nbr_rnm;idx++){
00774       (void)fprintf(stderr,"%s\n",rnm_lst[idx].old_nm);
00775       (void)fprintf(stderr,"%s\n",rnm_lst[idx].new_nm);
00776     } /* end loop over idx */
00777   } /* end debug */
00778 
00779   return rnm_lst;
00780 } /* end nco_prs_rnm_lst() */

void nco_thr_att_cat const int  out_id,
const int  thr_nbr
 

Definition at line 784 of file nco_att_utl.c.

References aed_overwrite, aed_sct::att_nm, aed_sct::id, ptr_unn::lp, aed_sct::mode, NC_GLOBAL, NC_INT, nco_aed_prc(), aed_sct::sz, aed_sct::type, aed_sct::val, and aed_sct::var_nm.

Referenced by main().

00786 {
00787   /* Purpose: Write thread information to global metadata */
00788   aed_sct thr_nbr_aed;
00789   char att_nm_nbr[]="nco_openmp_thread_number";
00790   nco_int thr_nbr_lng; /* [nbr] Thread number copy */
00791   ptr_unn att_val;
00792   
00793   /* Copy thr_nbr so can take address without endangering number */
00794   thr_nbr_lng=thr_nbr;
00795   /* Insert thread number into value */
00796   att_val.lp=&thr_nbr_lng;
00797   /* Initialize nco_openmp_thread_number attribute edit structure */
00798   thr_nbr_aed.att_nm=att_nm_nbr;
00799   thr_nbr_aed.var_nm=NULL;
00800   thr_nbr_aed.id=NC_GLOBAL;
00801   thr_nbr_aed.sz=1L;
00802   thr_nbr_aed.type=NC_INT;
00803   /* Insert value into attribute structure */
00804   thr_nbr_aed.val=att_val;
00805   thr_nbr_aed.mode=aed_overwrite;
00806   /* Write nco_openmp_thread_number attribute to disk */
00807   (void)nco_aed_prc(out_id,NC_GLOBAL,thr_nbr_aed);
00808 
00809 } /* end nco_thr_att_cat() */


Generated on Thu Mar 16 18:15:11 2006 for nco by  doxygen 1.4.4