nco/nco_dmn_utl.h File Reference

#include <stdio.h>
#include <string.h>
#include <netcdf.h>
#include "nco_netcdf.h"
#include "nco.h"
#include "nco_mmr.h"

Include dependency graph for nco_dmn_utl.h:

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

Go to the source code of this file.

Functions

void nco_dmn_dfn (const char *const fl_nm, const int nc_id, dmn_sct **const dmn, const int nbr_dmn)
dmn_sctnco_dmn_dpl (const dmn_sct *const dmn)
dmn_sctnco_dmn_fll (const int nc_id, const int dmn_id, const char *const dmn_nm)
dmn_sctnco_dmn_free (dmn_sct *dmn)
void nco_dmn_lmt_mrg (dmn_sct **const dmn, const int nbr_dmn, CST_X_PTR_CST_PTR_CST_Y(lmt_sct, lmt), const int lmt_nbr)
dmn_sct ** nco_dmn_lst_free (dmn_sct **dmn_lst, const int dmn_nbr)
nm_id_sctnco_dmn_lst_mk (const int nc_id, CST_X_PTR_CST_PTR_CST_Y(char, dmn_lst_in), const int nbr_dmn)
nm_id_sctnco_dmn_lst_ass_var (const int nc_id, const nm_id_sct *const var, const int nbr_var, int *const nbr_dmn)
void nco_dmn_xrf (dmn_sct *const dmn_1, dmn_sct *const dmn_2)


Function Documentation

void nco_dmn_dfn const char *const   fl_nm,
const int  nc_id,
dmn_sct **const   dmn,
const int  nbr_dmn
 

Definition at line 13 of file nco_dmn_utl.c.

References var_sct_tag::cnt, var_sct_tag::nc_id, NC_NOERR, NC_UNLIMITED, nco_def_dim(), nco_inq_dimid_flg(), var_sct_tag::nm, and prg_nm_get().

Referenced by main(), ncap_mk_cst(), and ncap_var_init().

00017 {
00018   /* Purpose: Define dimensions in output file */
00019 
00020   int idx;
00021   int rcd=NC_NOERR; /* [rcd] Return code */
00022 
00023   for(idx=0;idx<nbr_dmn;idx++){
00024 
00025     /* Has dimension already been defined? */
00026     rcd=nco_inq_dimid_flg(nc_id,dmn[idx]->nm,&dmn[idx]->id);
00027 
00028     /* If dimension has not been defined yet, define it */
00029     if(rcd != NC_NOERR){
00030       if(dmn[idx]->is_rec_dmn){
00031         (void)nco_def_dim(nc_id,dmn[idx]->nm,NC_UNLIMITED,&(dmn[idx]->id));
00032       }else{
00033         (void)nco_def_dim(nc_id,dmn[idx]->nm,dmn[idx]->cnt,&(dmn[idx]->id));
00034       } /* end else */
00035     }else{
00036       (void)fprintf(stderr,"%s: WARNING dimension \"%s\" is already defined in %s\n",prg_nm_get(),dmn[idx]->nm,fl_nm);
00037     } /* end if */
00038   } /* end loop over idx */
00039   
00040 } /* end nco_dmn_dfn() */

dmn_sct* nco_dmn_dpl const dmn_sct *const   dmn  ) 
 

Definition at line 44 of file nco_dmn_utl.c.

References nco_malloc().

Referenced by main(), ncap_mk_cst(), and ncap_var_init().

00045 {
00046   /* Purpose: nco_malloc() and return duplicate of input dmn_sct */
00047   const void *dmn_vp=dmn;
00048 
00049   dmn_sct *dmn_cpy;
00050 
00051   dmn_cpy=(dmn_sct *)nco_malloc(sizeof(dmn_sct));
00052 
00053   /* Shallow copy structure */
00054   (void)memcpy((void *)dmn_cpy,dmn_vp,sizeof(dmn_sct));
00055 
00056   /* Make sure dmn_free() frees names when dimension is destructed */
00057   if(dmn->nm != NULL) dmn_cpy->nm=(char *)strdup(dmn->nm);
00058 
00059   return dmn_cpy;
00060 } /* end nco_dmn_dpl() */

dmn_sct* nco_dmn_fll const int  nc_id,
const int  dmn_id,
const char *const   dmn_nm
 

Definition at line 64 of file nco_dmn_utl.c.

References dmn_sct_tag::cid, dmn_sct_tag::cnt, var_sct_tag::dmn_id, dmn_sct_tag::end, False, dmn_sct_tag::id, dmn_sct_tag::is_crd_dmn, dmn_sct_tag::is_rec_dmn, var_sct_tag::nc_id, dmn_sct_tag::nc_id, NC_NOERR, nco_inq(), nco_inq_dimlen(), nco_inq_varid_flg(), nco_inq_vartype(), nco_malloc(), dmn_sct_tag::nm, dmn_sct_tag::srd, dmn_sct_tag::srt, dmn_sct_tag::sz, True, dmn_sct_tag::type, dmn_sct_tag::val, ptr_unn::vp, and dmn_sct_tag::xrf.

Referenced by main().

00067 {
00068   /* Purpose: nco_malloc() and return a completed dmn_sct */
00069 
00070   dmn_sct *dmn;
00071   
00072   int rcd=NC_NOERR; /* [rcd] Return code */
00073   int rec_dmn_id;
00074   
00075   dmn=(dmn_sct *)nco_malloc(sizeof(dmn_sct));
00076   
00077   dmn->nm=(char *)strdup(dmn_nm);
00078   dmn->id=dmn_id;
00079   dmn->nc_id=nc_id;
00080   dmn->xrf=NULL;
00081   dmn->val.vp=NULL;
00082 
00083   dmn->is_crd_dmn=False;
00084   (void)nco_inq_dimlen(dmn->nc_id,dmn_id,&dmn->sz);
00085   
00086   /* Get record dimension ID */
00087   (void)nco_inq(dmn->nc_id,(int *)NULL,(int *)NULL,(int *)NULL,&rec_dmn_id);
00088   if(dmn->id == rec_dmn_id){
00089     dmn->is_rec_dmn=True;
00090   }else{
00091     dmn->is_rec_dmn=False;
00092   } /* end if */
00093    
00094   rcd=nco_inq_varid_flg(dmn->nc_id,dmn_nm,&dmn->cid);
00095   if(rcd == NC_NOERR){
00096     dmn->is_crd_dmn=True;
00097     /* What type is coordinate? */
00098     (void)nco_inq_vartype(dmn->nc_id,dmn->cid,&dmn->type);
00099   } /* end if */
00100   
00101   dmn->cnt=dmn->sz;
00102   dmn->srt=0L;
00103   dmn->end=dmn->sz-1L;
00104   dmn->srd=1L;
00105   
00106   return dmn;
00107 } /* end nco_dmn_fll() */

dmn_sct* nco_dmn_free dmn_sct dmn  ) 
 

Definition at line 111 of file nco_dmn_utl.c.

References nco_free(), and dmn_sct_tag::nm.

Referenced by nco_dmn_lst_free().

00112 {
00113   /* Threads: Routine is thread safe and calls no unsafe routines */
00114   /* Purpose: Free all memory associated with a dynamically allocated dimension structure */
00115   dmn->nm=(char *)nco_free(dmn->nm);
00116   /* Free structure pointer last */
00117   dmn=(dmn_sct *)nco_free(dmn);
00118 
00119   return NULL;
00120 } /* end nco_dmn_free() */

void nco_dmn_lmt_mrg dmn_sct **const   dmn,
const int  nbr_dmn,
CST_X_PTR_CST_PTR_CST_Y(lmt_sct, lmt)  ,
const int  lmt_nbr
 

Definition at line 124 of file nco_dmn_utl.c.

References dmn_sct_tag::cnt, dmn_sct_tag::end, var_sct_tag::nm, dmn_sct_tag::srd, and dmn_sct_tag::srt.

Referenced by main().

00128 {
00129   /* Purpose: Merge limit structure information into dimension structures */
00130 
00131   int idx;
00132   int lmt_idx;
00133 
00134   for(idx=0;idx<nbr_dmn;idx++){
00135     /* Does this dimension have user-specified limits? */
00136     for(lmt_idx=0;lmt_idx<lmt_nbr;lmt_idx++){
00137       /* 20050707: Match on name not ID so nco_dmn_lmt_mrg() works with single
00138          limit list applied to any input file */
00139       if(!strcmp(lmt[lmt_idx]->nm,dmn[idx]->nm)){
00140         dmn[idx]->cnt=lmt[lmt_idx]->cnt;
00141         dmn[idx]->srt=lmt[lmt_idx]->srt;
00142         dmn[idx]->end=lmt[lmt_idx]->end;
00143         dmn[idx]->srd=lmt[lmt_idx]->srd;
00144         break;
00145       } /* end if */
00146     } /* end loop over lmt_idx */
00147   } /* end loop over dmn */
00148 } /* end nco_dmn_lmt_mrg() */

nm_id_sct* nco_dmn_lst_ass_var const int  nc_id,
const nm_id_sct *const   var,
const int  nbr_var,
int *const   nbr_dmn
 

Definition at line 152 of file nco_dmn_utl.c.

References var_sct_tag::dmn_id, False, nm_id_sct::id, var_sct_tag::nc_id, NC_MAX_DIMS, NC_MAX_NAME, nco_inq(), nco_inq_dimname(), nco_inq_var(), nco_malloc(), nco_realloc(), nm_id_sct::nm, and True.

Referenced by main().

00156 {
00157   /* Purpose: Create list of all dimensions associated with input variable list */
00158 
00159   bool dmn_has_been_placed_on_list;
00160 
00161   char dmn_nm[NC_MAX_NAME];
00162 
00163   int dmn_id[NC_MAX_DIMS];
00164   int idx_dmn_in;
00165   int idx_var;
00166   int idx_var_dmn;
00167   int idx_dmn_lst;
00168   int nbr_dmn_in;
00169   int nbr_var_dmn;
00170   
00171   nm_id_sct *dmn;
00172 
00173   *nbr_dmn=0;
00174 
00175   /* Get number of dimensions */
00176   (void)nco_inq(nc_id,&nbr_dmn_in,(int *)NULL,(int *)NULL,(int *)NULL);
00177 
00178   /* Number of input dimensions is upper bound on number of output dimensions */
00179   dmn=(nm_id_sct *)nco_malloc(nbr_dmn_in*sizeof(nm_id_sct));
00180   
00181   /* ...For each dimension in file... */
00182   for(idx_dmn_in=0;idx_dmn_in<nbr_dmn_in;idx_dmn_in++){
00183     /* ...begin search for dimension in dimension list by... */
00184     dmn_has_been_placed_on_list=False;
00185     /* ...looking through the set of output variables... */
00186     for(idx_var=0;idx_var<nbr_var;idx_var++){
00187       /* ...and searching each dimension of each output variable... */
00188       (void)nco_inq_var(nc_id,var[idx_var].id,(char *)NULL,(nc_type *)NULL,&nbr_var_dmn,dmn_id,(int *)NULL);
00189       for(idx_var_dmn=0;idx_var_dmn<nbr_var_dmn;idx_var_dmn++){
00190         /* ...until output variable is found which contains input dimension... */
00191         if(idx_dmn_in == dmn_id[idx_var_dmn]){
00192           /* ...then search each member of output dimension list... */
00193           for(idx_dmn_lst=0;idx_dmn_lst<*nbr_dmn;idx_dmn_lst++){
00194             /* ...until input dimension is found... */
00195             if(idx_dmn_in == dmn[idx_dmn_lst].id) break; /* ...then search no further... */
00196           } /* end loop over idx_dmn_lst */
00197           /* ...and if dimension was not found on output dimension list... */
00198           if(idx_dmn_lst == *nbr_dmn){
00199             /* ...then add dimension to output dimension list... */
00200             (void)nco_inq_dimname(nc_id,idx_dmn_in,dmn_nm);
00201             dmn[*nbr_dmn].id=idx_dmn_in;
00202             dmn[*nbr_dmn].nm=(char *)strdup(dmn_nm);
00203             (*nbr_dmn)++;
00204           } /* end if dimension was not found in current output dimension list */
00205           /* ...call off the dogs for this input dimension... */
00206           dmn_has_been_placed_on_list=True;
00207         } /* end if input dimension belongs to this output variable */
00208         if(dmn_has_been_placed_on_list) break; /* break out of idx_var_dmn to idx_var */
00209       } /* end loop over idx_var_dmn */
00210       if(dmn_has_been_placed_on_list) break; /* break out of idx_var to idx_dmn_in */
00211     } /* end loop over idx_var */
00212   } /* end loop over idx_dmn_in */
00213   
00214   /* We now have final list of dimensions to extract. Phew. */
00215   
00216   /* Free unused space in output dimension list */
00217   dmn=(nm_id_sct *)nco_realloc((void *)dmn,*nbr_dmn*sizeof(nm_id_sct));
00218   
00219   return dmn;
00220 } /* end nco_dmn_lst_ass_var() */

dmn_sct** nco_dmn_lst_free dmn_sct **  dmn_lst,
const int  dmn_nbr
 

Definition at line 224 of file nco_dmn_utl.c.

00226 {
00227   /* Threads: Routine is thread safe and calls no unsafe routines */
00228   /* Purpose: Free all memory associated with dynamically allocated dimension structure list */
00229   int idx;
00230 
00231   for(idx=0;idx<dmn_nbr;idx++){
00232     dmn_lst[idx]=nco_dmn_free(dmn_lst[idx]);
00233   } /* end loop over idx */
00234 
00235   /* Free structure pointer last */
00236   dmn_lst=(dmn_sct **)nco_free(dmn_lst);
00237 
00238   return dmn_lst;
00239 } /* end nco_dmn_lst_free() */

nm_id_sct* nco_dmn_lst_mk const int  nc_id,
CST_X_PTR_CST_PTR_CST_Y(char, dmn_lst_in)  ,
const int  nbr_dmn
 

Definition at line 243 of file nco_dmn_utl.c.

References var_sct_tag::nc_id, nco_inq_dimid(), nco_malloc(), var_sct_tag::nm, and nm_id_sct::nm.

Referenced by main().

00246 {
00247   /* Purpose: Create list of dimension name-ID structures from list of dimension name strings */
00248   int idx;
00249 
00250   nm_id_sct *dmn_lst;
00251   
00252   dmn_lst=(nm_id_sct *)nco_malloc(nbr_dmn*sizeof(nm_id_sct));
00253   for(idx=0;idx<nbr_dmn;idx++){
00254     /* Copy name and then get requested dimension ID from input file */
00255     dmn_lst[idx].nm=(char *)strdup(dmn_lst_in[idx]);
00256     (void)nco_inq_dimid(nc_id,dmn_lst[idx].nm,&dmn_lst[idx].id);
00257   } /* end loop over idx */
00258   
00259   return dmn_lst;
00260 } /* end nco_dmn_lst_mk() */

void nco_dmn_xrf dmn_sct *const   dmn_1,
dmn_sct *const   dmn_2
 

Definition at line 264 of file nco_dmn_utl.c.

References dmn_sct_tag::xrf.

Referenced by main(), ncap_mk_cst(), and ncap_var_init().

00266 {
00267   /* Purpose: Make xrf elements of dimension structures point to eachother */
00268   dmn_1->xrf=dmn_2;
00269   dmn_2->xrf=dmn_1;
00270 } /* end nco_dmn_xrf() */


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