ncdf4a13/libsrc4/nc4internal.c File Reference

#include <nc4internal.h>
#include "netcdf.h"

Include dependency graph for nc4internal.c:

Go to the source code of this file.

Functions

int file_list_add_netcdf4 (NC_FILE_INFO_T *nc, const char *path, int mode)
NC_FILE_INFO_Tfind_nc_file (int ncid)
NC_GRP_INFO_Tfind_nc_grp (int ncid)
int find_nc4_file (int ncid, NC_FILE_INFO_T **nc)
int find_grp_h5 (int ncid, NC_GRP_INFO_T **grp, NC_HDF5_FILE_INFO_T **h5)
int find_nc4_grp (int ncid, NC_GRP_INFO_T **grp)
int find_nc_grp_h5 (int ncid, NC_FILE_INFO_T **nc, NC_GRP_INFO_T **grp, NC_HDF5_FILE_INFO_T **h5)
NC_GRP_INFO_Trec_find_grp (NC_GRP_INFO_T *start_grp, int target_nc_grpid)
int find_grp_var (int ncid, int varid, NC_GRP_INFO_T **grp, NC_HDF5_FILE_INFO_T **h5, NC_VAR_INFO_T **var)
int find_grp_var_nc (NC_FILE_INFO_T *nc, int ncid, int varid, NC_GRP_INFO_T **grp, NC_VAR_INFO_T **var)
int find_var (NC_GRP_INFO_T *grp, int varid, NC_VAR_INFO_T **var)
int find_dim (NC_GRP_INFO_T *grp, int dimid, NC_DIM_INFO_T **dim)
NC_TYPE_INFO_Trec_find_hdf_type (NC_GRP_INFO_T *start_grp, hid_t target_hdf_typeid)
NC_TYPE_INFO_Trec_find_nc_type (NC_GRP_INFO_T *start_grp, hid_t target_nc_typeid)
int find_type (NC_HDF5_FILE_INFO_T *h5, int typeid, NC_TYPE_INFO_T **type)
int find_dim_len (NC_GRP_INFO_T *grp, int dimid, size_t **len)
int nc4_find_grp_att (NC_GRP_INFO_T *grp, int varid, const char *name, int attnum, NC_ATT_INFO_T **att)
int find_nc_att (int ncid, int varid, const char *name, int attnum, NC_ATT_INFO_T **att)
int data_type_convert (nc_type *mem_type, nc_type file_type, void **orig_data, size_t len, void **data, int *mem_allocated)
int file_list_add (int new_id)
int nc4_var_list_add (NC_VAR_INFO_T **list, NC_VAR_INFO_T **var)
int dim_list_add (NC_DIM_INFO_T **list)
int att_list_add (NC_ATT_INFO_T **list)
int nc4_grp_list_add (NC_GRP_INFO_T **list, int new_nc_grpid, NC_GRP_INFO_T *parent_grp, NC_FILE_INFO_T *nc, char *name, NC_GRP_INFO_T **grp)
int nc4_type_list_add (NC_TYPE_INFO_T **list, int typeid, size_t size, const char *name, nc_type class, nc_type base_nc_type)
int field_list_add (NC_FIELD_INFO_T **list, int fieldid, char *name, size_t offset, hid_t field_hdf_typeid, nc_type xtype, int ndims, int *dim_sizesp)
int nc4_enum_member_add (NC_ENUM_MEMBER_INFO_T **list, size_t size, const char *name, const void *value)
void var_list_del (NC_VAR_INFO_T **list, NC_VAR_INFO_T *var)
int type_list_del (NC_TYPE_INFO_T **list, NC_TYPE_INFO_T *type)
void field_list_del (NC_FIELD_INFO_T **list, NC_FIELD_INFO_T *field)
int rec_grp_del (NC_GRP_INFO_T **list, NC_GRP_INFO_T *grp)
void dim_list_del (NC_DIM_INFO_T **list, NC_DIM_INFO_T *dim)
void att_list_del (NC_ATT_INFO_T **list, NC_ATT_INFO_T *att)
void file_list_del (NC_FILE_INFO_T *nc)
void grp_list_del (NC_GRP_INFO_T **list, NC_GRP_INFO_T *grp)

Variables

NC_FILE_INFO_Tnc_file = NULL


Function Documentation

int att_list_add NC_ATT_INFO_T **  list  ) 
 

Definition at line 869 of file nc4internal.c.

References nc_calloc, NC_ENOMEM, NC_NOERR, NC_ATT_INFO::next, and NC_ATT_INFO::prev.

Referenced by main(), nc4_put_att(), read_grp_atts(), and read_var().

00870 {
00871    NC_ATT_INFO_T *att, *a1;
00872    if (!(att = nc_calloc(1, sizeof(NC_ATT_INFO_T))))
00873       return NC_ENOMEM;
00874    if (*list)
00875    {
00876       for (a1 = *list; a1; a1 = a1->next)
00877          if (!a1->next)
00878             break;
00879       a1->next = att;
00880       att->prev = a1;
00881    }
00882    else
00883    {
00884       *list = att;
00885    }
00886 
00887    return NC_NOERR;
00888 }

void att_list_del NC_ATT_INFO_T **  list,
NC_ATT_INFO_T att
 

Definition at line 1270 of file nc4internal.c.

References NC_ATT_INFO::class, NC_ATT_INFO::data, len, nc_free, NC_VLEN, NC_ATT_INFO::next, NC_ATT_INFO::prev, and NC_ATT_INFO::stdata.

Referenced by main(), nc_del_att(), rec_grp_del(), and var_list_del().

01271 {
01272    int i;
01273 
01274    /* Take this att out of the list. */
01275    if(*list == att)
01276       *list = att->next;
01277    else
01278       att->prev->next = att->next;
01279 
01280    if(att->next)
01281       att->next->prev = att->prev;
01282 
01283    /* Nc_Free memory that was nc_malloced to hold data for this
01284     * attribute. VLEN data must be treated differently - we must nc_free
01285     * all the p members of the hvl_t structs that make up the
01286     * array. */
01287    if (att->data)
01288    {
01289       if (att->class == NC_VLEN)
01290          for (i = 0; i < att->len; i++)
01291          {
01292             nc_free(((hvl_t *)att->data)[i].p);
01293             /*nc_free(((hvl_t)data1[i]).p);*/
01294          }
01295       else
01296          nc_free(att->data);
01297    }
01298 
01299    /* If this is a string array attribute, delete all members of the
01300     * string array, then delete the array of pointers to strings. (The
01301     * array was filled with pointers by HDF5 when the att was read,
01302     * and memory for each string was allocated by HDF5. That's why I
01303     * use free and not nc_free, because the netCDF library didn't
01304     * allocate the memory that is being freed.) */
01305    if (att->stdata)
01306    {
01307       for (i = 0; i < att->len; i++)
01308          free(att->stdata[i]);
01309       nc_free(att->stdata);
01310    }
01311 
01312    nc_free(att);
01313 }

int data_type_convert nc_type mem_type,
nc_type  file_type,
void **  orig_data,
size_t  len,
void **  data,
int *  mem_allocated
 

Definition at line 562 of file nc4internal.c.

References LOG, NC_BYTE, NC_DOUBLE, NC_ENOMEM, NC_FLOAT, NC_INT, NC_LONG, nc_malloc, NC_NOERR, and NC_SHORT.

00565 {
00566    short *shortp;
00567    size_t i;
00568    int *intp;
00569    float *floatp;
00570    double *doublep;
00571    signed char *bytep;
00572    double *double_data = NULL;
00573    long *long_data = NULL;
00574 
00575    /* If we're converting from any int type to float... */
00576    if ((*mem_type == NC_SHORT ||
00577         *mem_type == NC_INT ||
00578         *mem_type == NC_BYTE) && 
00579        (file_type == NC_FLOAT ||
00580         file_type == NC_DOUBLE))
00581    {
00582       /* Convert the data to a double instead... */
00583       LOG((4, "converting data to double"));
00584       if (!(double_data = nc_malloc(len * sizeof(double))))
00585          return NC_ENOMEM;
00586       switch (*mem_type)
00587       {
00588       case NC_BYTE:
00589          for (bytep=(signed char *)(*orig_data), i=0; i<len; i++, bytep++)
00590             double_data[i] = (double)*bytep;
00591          break;
00592       case NC_SHORT:
00593          for (shortp=(short *)(*orig_data), i=0; i<len; i++, shortp++)
00594             double_data[i] = (double)*shortp;
00595          break;
00596       case NC_INT:
00597          for (intp=(int *)(*orig_data), i=0; i<len; i++, intp++)
00598             double_data[i] = (double)*intp;
00599          break;
00600       default:
00601          break;
00602       }
00603       *mem_type = NC_DOUBLE;
00604       *data = double_data;
00605       (*mem_allocated)++;
00606    }
00607    /* If we're converting from a float type to long. */
00608    else if ((*mem_type == NC_FLOAT ||
00609              *mem_type == NC_DOUBLE) &&
00610             (file_type == NC_BYTE || 
00611              file_type == NC_SHORT ||
00612              file_type == NC_INT))
00613    {
00614       /* Convert there data to a long instead... */
00615       LOG((4, "converting data to long"));
00616       if (!(long_data = nc_malloc(len * sizeof(long))))
00617          return NC_ENOMEM;
00618       switch (*mem_type)
00619       {
00620       case NC_FLOAT:
00621          for (floatp=(float *)(*orig_data), i=0; i<len; i++, floatp++)
00622             long_data[i] = (long)*floatp;
00623          break;
00624       case NC_DOUBLE:
00625          for (doublep=(double *)(*orig_data), i=0; i<len; i++, doublep++)
00626             long_data[i] = (long)*doublep;
00627          break;
00628       default:
00629          break;
00630       }
00631       *mem_type = NC_LONG;
00632       *data = long_data;
00633       (*mem_allocated)++;
00634    }
00635    /* Else we aren't converting the data after all. */
00636    else
00637    {
00638       LOG((4, "not converting data at all!"));
00639       *data = (void *)(*orig_data);
00640    }
00641    return NC_NOERR;
00642 }

int dim_list_add NC_DIM_INFO_T **  list  ) 
 

Definition at line 855 of file nc4internal.c.

References nc_calloc, NC_ENOMEM, NC_NOERR, and NC_DIM_INFO::next.

Referenced by nc_def_dim(), and read_scale().

00856 {
00857    NC_DIM_INFO_T *dim;
00858    if (!(dim = nc_calloc(1, sizeof(NC_DIM_INFO_T))))
00859       return NC_ENOMEM;
00860    if(*list)
00861       (*list)->prev = dim;
00862    dim->next = *list;
00863    *list = dim;
00864    return NC_NOERR;
00865 }

void dim_list_del NC_DIM_INFO_T **  list,
NC_DIM_INFO_T dim
 

Definition at line 1252 of file nc4internal.c.

References nc_free, NC_DIM_INFO::next, and NC_DIM_INFO::prev.

Referenced by rec_grp_del().

01253 {
01254    /* Take this dimension out of the list. */
01255    if(*list == dim)
01256       *list = dim->next;
01257    else
01258       dim->prev->next = dim->next;
01259 
01260    if(dim->next)
01261       dim->next->prev = dim->prev;
01262 
01263    nc_free(dim);
01264 }

int field_list_add NC_FIELD_INFO_T **  list,
int  fieldid,
char *  name,
size_t  offset,
hid_t  field_hdf_typeid,
nc_type  xtype,
int  ndims,
int *  dim_sizesp
 

Definition at line 966 of file nc4internal.c.

References NC_FIELD_INFO::dim_size, NC_FIELD_INFO::fieldid, NC_FIELD_INFO::hdf_typeid, LOG, NC_FIELD_INFO::name, nc_calloc, NC_check_name(), NC_EINVAL, NC_ENOMEM, NC_NOERR, NC_FIELD_INFO::nctype, NC_FIELD_INFO::ndims, NC_FIELD_INFO::next, NC_FIELD_INFO::offset, and NC_FIELD_INFO::prev.

Referenced by nc_insert_array_compound(), and read_type().

00969 {
00970    NC_FIELD_INFO_T *field, *f;
00971    int i, retval;
00972 
00973    if (!name)
00974       return NC_EINVAL;
00975 
00976    LOG((4, "field_list_add: fieldid %d name %s", fieldid, name));
00977 
00978    /* Check name. */
00979    if ((retval = NC_check_name(name)))
00980       return retval;
00981 
00982    /* Allocate storage for this field information. */
00983    if (!(field = nc_calloc(1, sizeof(NC_FIELD_INFO_T))))
00984       return NC_ENOMEM;
00985 
00986    /* Add this field to list. */
00987    if (*list)
00988    {
00989       for (f = *list; f; f = f->next)
00990          if (!f->next)
00991             break;
00992       f->next = field;
00993       field->prev = f;
00994    }
00995    else
00996    {
00997       *list = field;
00998    }
00999 
01000    /* Store the information about this field. */
01001    field->fieldid = fieldid;
01002    strcpy(field->name, name);
01003    field->hdf_typeid = field_hdf_typeid;
01004    field->nctype = xtype;
01005    field->offset = offset;
01006    field->ndims = ndims;
01007    for (i = 0; i < ndims; i++)
01008       field->dim_size[i] = dim_sizesp[i];
01009 
01010    return NC_NOERR;
01011 }

void field_list_del NC_FIELD_INFO_T **  list,
NC_FIELD_INFO_T field
 

Definition at line 1144 of file nc4internal.c.

References nc_free, NC_FIELD_INFO::next, and NC_FIELD_INFO::prev.

Referenced by type_list_del().

01145 {
01146 
01147    /* Take this field out of the list. */
01148    if(*list == field)
01149       *list = field->next;
01150    else
01151       field->prev->next = field->next;
01152 
01153    if(field->next)
01154       field->next->prev = field->prev;
01155 
01156    /* Nc_Free the memory. */
01157    nc_free(field);
01158 }

int file_list_add int  new_id  ) 
 

Definition at line 812 of file nc4internal.c.

References NC_FILE_INFO::ext_ncid, nc_calloc, NC_ENOMEM, NC_NOERR, NC_FILE_INFO::next, and NC_FILE_INFO::prev.

Referenced by main(), nc_create_file(), and nc_open_file().

00813 {
00814    NC_FILE_INFO_T *nc;
00815    if (!(nc = nc_calloc(1, sizeof(NC_FILE_INFO_T))))
00816       return NC_ENOMEM;
00817    if(nc_file != NULL)
00818       nc_file->prev = nc;
00819    nc->next = nc_file;
00820    nc->ext_ncid = new_id;
00821    nc_file = nc;
00822    return NC_NOERR;
00823 }

int file_list_add_netcdf4 NC_FILE_INFO_T nc,
const char *  path,
int  mode
 

Definition at line 43 of file nc4internal.c.

References NC_HDF5_FILE_INFO_T::cmode, nc4_grp_list_add(), NC_FILE_INFO::nc4_info, nc_calloc, NC_COMPOUND, NC_ENOMEM, NC_GROUP_NAME, NC_HDF5_FILE_INFO_T::next_nc_grpid, NC_HDF5_FILE_INFO_T::next_typeid, NC_HDF5_FILE_INFO_T::path, and NC_HDF5_FILE_INFO_T::root_grp.

Referenced by main(), nc4_create_file(), and nc4_open_file().

00044 {
00045    NC_HDF5_FILE_INFO_T *h5;
00046    NC_GRP_INFO_T *grp;
00047 
00048    assert(nc && !nc->nc4_info && path);
00049 
00050    /* The NC_FILE_INFO_T was allocated and inited by
00051       ncfunc.c before this function is called. We need to nc_malloc and
00052       initialize the substructure NC_HDF_FILE_INFO_T. */
00053    if (!(nc->nc4_info = nc_calloc(1, sizeof(NC_HDF5_FILE_INFO_T))))
00054       return NC_ENOMEM;
00055    h5 = nc->nc4_info;
00056 
00057    /* Hang on to the filename for nc_abort. */
00058    strcpy(h5->path, path);
00059 
00060    /* Hang on to cmode. */
00061    h5->cmode = mode;
00062 
00063    /* The next_typeid needs to be set beyond the end of our atomic
00064     * types. */
00065    h5->next_typeid = NC_COMPOUND + 1;
00066 
00067    /* There's always at least one open group - the root
00068     * group. Allocate space for one group's worth of information. Set
00069     * it's hdf id, name, and a pointer to it's file structure. */
00070    return nc4_grp_list_add(&(h5->root_grp), h5->next_nc_grpid++, 
00071                            NULL, nc, NC_GROUP_NAME, &grp);
00072 }

void file_list_del NC_FILE_INFO_T nc  ) 
 

Definition at line 1318 of file nc4internal.c.

References nc_free, NC_FILE_INFO::next, and NC_FILE_INFO::prev.

Referenced by main(), nc_abort(), nc_close(), nc_create_file(), and nc_open_file().

01319 {
01320    if(nc_file == nc)
01321       nc_file = nc->next;
01322    else
01323       nc->prev->next = nc->next;
01324 
01325    if(nc->next)
01326       nc->next->prev = nc->prev;
01327 
01328    nc_free(nc);
01329 }

int find_dim NC_GRP_INFO_T grp,
int  dimid,
NC_DIM_INFO_T **  dim
 

Definition at line 317 of file nc4internal.c.

References NC_GRP_INFO::dim, NC_EBADDIM, NC_NOERR, NC_DIM_INFO::next, and NC_GRP_INFO::parent.

Referenced by nc_def_var_full(), nc_inq_dim(), and pg_vara().

00318 {
00319    NC_GRP_INFO_T *g;
00320    int finished = 0; 
00321    
00322    assert(grp && dim);
00323 
00324    /* Find the dim info. */
00325    for (g = grp; g && !finished; g = g->parent)
00326       for ((*dim) = g->dim; (*dim); (*dim) = (*dim)->next)
00327          if ((*dim)->dimid == dimid)
00328          {
00329             finished++;
00330             break;
00331          }
00332 
00333    /* If we didn't find it, return an error. */
00334    if (!(*dim))
00335      return NC_EBADDIM;
00336 
00337    return NC_NOERR;
00338 }

int find_dim_len NC_GRP_INFO_T grp,
int  dimid,
size_t **  len
 

Definition at line 417 of file nc4internal.c.

References NC_GRP_INFO::children, find_dim_len(), find_var_shape_grp(), LOG, NC_GRP_INFO::name, NC_MAX_DIMS, NC_NOERR, ndims, NC_GRP_INFO::next, NC_VAR_INFO::next, NC_GRP_INFO::var, and NC_VAR_INFO::varid.

Referenced by find_dim_len(), and nc_inq_dim().

00418 {
00419    NC_GRP_INFO_T *g;
00420    NC_VAR_INFO_T *var;
00421    int d, ndims, dimids[NC_MAX_DIMS];
00422    size_t dimlen[NC_MAX_DIMS];
00423    int retval; 
00424    
00425    assert(grp && len);
00426    LOG((3, "find_dim_len: grp->name %s dimid %d", grp->name, dimid));
00427 
00428    /* If there are any groups, call this function recursively on
00429     * them. */
00430    for (g = grp->children; g; g = g->next)
00431       if ((retval = find_dim_len(g, dimid, len)))
00432          return retval;
00433 
00434    /* For all variables in this group, find the ones that use this
00435     * dimension, and remember the max length. */
00436    for (var = grp->var; var; var = var->next)
00437    {
00438       /* Find dimensions of this var. */
00439       if ((retval = find_var_shape_grp(grp, var->varid, &ndims, 
00440                                        dimids, dimlen)))
00441          return retval;
00442 
00443       /* Check for any dimension that matches dimid. If found, check
00444        * if it's length is longer than *lenp. */
00445       for (d = 0; d < ndims; d++)
00446       {
00447          if (dimids[d] == dimid)
00448          {
00449             /* Remember the max length in *lenp. */
00450             **len = dimlen[d] > **len ? dimlen[d] : **len;
00451             break;
00452          }
00453       }
00454    }
00455 
00456    return NC_NOERR;
00457 }

int find_grp_h5 int  ncid,
NC_GRP_INFO_T **  grp,
NC_HDF5_FILE_INFO_T **  h5
 

Definition at line 129 of file nc4internal.c.

References NC_FILE_INFO::ext_ncid, FILE_ID_MASK, GRP_ID_MASK, NC_FILE_INFO::nc4_info, NC_EBADGRPID, NC_EBADID, NC_NOERR, NC_FILE_INFO::next, rec_find_grp(), and NC_HDF5_FILE_INFO_T::root_grp.

Referenced by find_grp_var(), find_nc_att(), nc_def_grp(), nc_def_var_full(), nc_inq_dimids(), nc_inq_grpname(), nc_inq_grps(), nc_inq_ncid(), nc_inq_typeids(), nc_inq_unlimdims(), nc_inq_varids(), and nc_var_par_access().

00130 {
00131    NC_FILE_INFO_T *f;
00132 
00133    for (f = nc_file; f; f = f->next)
00134    {
00135       /* Find the file from the file id part of ncid. */
00136       if (f->ext_ncid == (ncid & FILE_ID_MASK))
00137       {
00138          if (f->nc4_info)
00139          {
00140             assert(f->nc4_info->root_grp);
00141 
00142             /* If we can't find it, the grp id part of ncid is bad. */
00143             if (!(*grp = rec_find_grp(f->nc4_info->root_grp, (ncid & GRP_ID_MASK))))
00144                return NC_EBADGRPID;
00145 
00146             *h5 = (*grp)->file->nc4_info;
00147             assert(*h5);
00148          }
00149          else
00150          {
00151             *h5 = NULL;
00152             *grp = NULL;
00153          }
00154          return NC_NOERR;
00155       }
00156    }
00157 
00158    return NC_EBADID;
00159 }

int find_grp_var int  ncid,
int  varid,
NC_GRP_INFO_T **  grp,
NC_HDF5_FILE_INFO_T **  h5,
NC_VAR_INFO_T **  var
 

Definition at line 256 of file nc4internal.c.

References find_grp_h5(), NC_EBADID, NC_ENOTVAR, and NC_NOERR.

00258 {
00259    int retval; 
00260 
00261    assert(grp && h5 && var);
00262 
00263    if ((retval = find_grp_h5(ncid, grp, h5)))
00264       return NC_EBADID;
00265 
00266    /* Find the var info. The number of elements we'll eveutually
00267       read/write is the product of the count for each dimension. */
00268    for ((*var)=(*grp)->var; (*var); (*var)=(*var)->next)
00269      if ((*var)->varid == varid)
00270        break;
00271    if (!(*var))
00272      return NC_ENOTVAR;
00273 
00274    return NC_NOERR;
00275 }

int find_grp_var_nc NC_FILE_INFO_T nc,
int  ncid,
int  varid,
NC_GRP_INFO_T **  grp,
NC_VAR_INFO_T **  var
 

Definition at line 280 of file nc4internal.c.

References GRP_ID_MASK, NC_FILE_INFO::nc4_info, NC_ENOTVAR, NC_NOERR, rec_find_grp(), and NC_HDF5_FILE_INFO_T::root_grp.

Referenced by pg_var(), pg_var1(), pg_vara(), and pg_varm().

00282 {
00283    assert(grp && var && nc && nc->nc4_info && nc->nc4_info->root_grp);
00284    *grp = rec_find_grp(nc->nc4_info->root_grp, (ncid & GRP_ID_MASK));
00285 
00286    /* Find the var info. The number of elements we'll eveutually
00287       read/write is the product of the count for each dimension. */
00288    for ((*var)=(*grp)->var; (*var); (*var)=(*var)->next)
00289      if ((*var)->varid == varid)
00290        break;
00291    if (!(*var))
00292      return NC_ENOTVAR;
00293 
00294    return NC_NOERR;
00295 }

int find_nc4_file int  ncid,
NC_FILE_INFO_T **  nc
 

Definition at line 109 of file nc4internal.c.

References find_nc_file(), NC_CLASSIC_MODEL, NC_EBADID, NC_ENOTNC4, NC_ESTRICTNC3, and NC_NOERR.

Referenced by nc_inq_compound_fieldindex().

00110 {
00111    
00112    /* Find file metadata. */
00113    if (!((*nc) = find_nc_file(ncid)))
00114       return NC_EBADID;
00115 
00116    /* Check for netcdf-3 files or netcdf-3 rules. */
00117    if (!(*nc)->nc4_info)
00118       return NC_ENOTNC4;
00119    if ((*nc)->nc4_info->cmode & NC_CLASSIC_MODEL)
00120       return NC_ESTRICTNC3;
00121 
00122    return NC_NOERR;
00123 }

int find_nc4_grp int  ncid,
NC_GRP_INFO_T **  grp
 

Definition at line 165 of file nc4internal.c.

References NC_HDF5_FILE_INFO_T::cmode, NC_FILE_INFO::ext_ncid, FILE_ID_MASK, GRP_ID_MASK, NC_FILE_INFO::nc4_info, NC_CLASSIC_MODEL, NC_EBADGRPID, NC_EBADID, NC_ENOTNC4, NC_ESTRICTNC3, NC_NOERR, NC_FILE_INFO::next, rec_find_grp(), and NC_HDF5_FILE_INFO_T::root_grp.

Referenced by add_user_type(), nc_inq_compound_field(), nc_inq_enum_member(), nc_inq_type(), nc_inq_user_type(), nc_insert_array_compound(), and nc_insert_enum().

00166 {
00167    NC_FILE_INFO_T *f;
00168 
00169    for (f = nc_file; f; f = f->next)
00170    {
00171       /* Find the file from the file id part of ncid. */
00172       if (f->ext_ncid == (ncid & FILE_ID_MASK))
00173       {
00174          /* No netcdf-3 files allowed! */
00175          if (!f->nc4_info)
00176             return NC_ENOTNC4;
00177 
00178          assert(f->nc4_info->root_grp);
00179 
00180          /* This function demands netcdf-4 files without strict nc3
00181           * rules.*/
00182          if (f->nc4_info->cmode & NC_CLASSIC_MODEL)
00183             return NC_ESTRICTNC3;
00184          
00185          /* If we can't find it, the grp id part of ncid is bad. */
00186          if (!(*grp = rec_find_grp(f->nc4_info->root_grp, (ncid & GRP_ID_MASK))))
00187             return NC_EBADGRPID;
00188 
00189          return NC_NOERR;
00190       }
00191    }
00192 
00193    return NC_EBADID;
00194 }

int find_nc_att int  ncid,
int  varid,
const char *  name,
int  attnum,
NC_ATT_INFO_T **  att
 

Definition at line 502 of file nc4internal.c.

References NC_GRP_INFO::att, NC_VAR_INFO::att, find_grp_h5(), LOG, NC_ENOTATT, NC_ENOTVAR, NC_GLOBAL, NC_NOERR, NC_VAR_INFO::next, NC_ATT_INFO::next, NC_GRP_INFO::var, and NC_VAR_INFO::varid.

Referenced by nc_inq_attname().

00504 {
00505    NC_GRP_INFO_T *grp;
00506    NC_HDF5_FILE_INFO_T *h5;
00507    NC_VAR_INFO_T *var;
00508    NC_ATT_INFO_T *attlist = NULL;
00509    int retval;
00510 
00511    LOG((4, "find_nc_att: ncid 0x%x varid %d name %s attnum %d", 
00512         ncid, varid, name, attnum));
00513 
00514    /* Find info for this file and group, and set pointer to each. */
00515    if ((retval = find_grp_h5(ncid, &grp, &h5)))
00516       return retval;
00517    assert(grp && h5);
00518 
00519    /* Get either the global or a variable attribute list. */
00520    if (varid == NC_GLOBAL)
00521       attlist = grp->att;
00522    else
00523    {
00524       for(var = grp->var; var; var = var->next)
00525       {
00526          if (var->varid == varid)
00527          {
00528             attlist = var->att;
00529             break;
00530          }
00531       }
00532       if (!var)
00533          return NC_ENOTVAR;
00534    }
00535 
00536    /* Now find the attribute by name or number. If a name is provided, ignore the attnum. */
00537    for (*att = attlist; *att; *att = (*att)->next)
00538       if ((name && !strcmp((*att)->name, name)) ||
00539           (!name && (*att)->attnum == attnum))
00540          return NC_NOERR;
00541 
00542    /* If we get here, we couldn't find the attribute. */
00543    return NC_ENOTATT;
00544 }

NC_FILE_INFO_T* find_nc_file int  ncid  ) 
 

Definition at line 77 of file nc4internal.c.

References NC_FILE_INFO::ext_ncid, FILE_ID_MASK, and NC_FILE_INFO::next.

Referenced by find_nc4_file(), main(), nc4_get_att_tc(), nc4_get_var1_tc(), nc4_get_var_tc(), nc4_get_vara_tc(), nc4_get_varm_tc(), nc4_get_vars_tc(), nc4_put_att_tc(), nc4_put_var1_tc(), nc4_put_var_tc(), nc4_put_vara_tc(), nc4_put_varm_tc(), nc4_put_vars_tc(), nc__enddef(), nc_abort(), nc_def_var(), nc_enddef(), nc_inq_att(), nc_inq_attid(), nc_inq_attname(), nc_inq_base_pe(), nc_inq_format(), nc_inq_varnatts(), nc_redef(), nc_set_base_pe(), nc_set_fill(), and nc_sync().

00078 {
00079    NC_FILE_INFO_T *f;
00080    for (f=nc_file; f; f = f->next)
00081       if ((f->ext_ncid & FILE_ID_MASK) == (ncid & FILE_ID_MASK))
00082          return f;
00083 
00084    return NULL;
00085 }

NC_GRP_INFO_T* find_nc_grp int  ncid  ) 
 

Definition at line 90 of file nc4internal.c.

References NC_FILE_INFO::ext_ncid, FILE_ID_MASK, GRP_ID_MASK, NC_FILE_INFO::nc4_info, NC_FILE_INFO::next, rec_find_grp(), and NC_HDF5_FILE_INFO_T::root_grp.

Referenced by open_var().

00091 {
00092    NC_FILE_INFO_T *f;
00093 
00094    for (f = nc_file; f; f = f->next)
00095    {
00096       if (f->ext_ncid == (ncid & FILE_ID_MASK))
00097       {
00098          assert(f->nc4_info && f->nc4_info->root_grp);
00099          return rec_find_grp(f->nc4_info->root_grp, (ncid & GRP_ID_MASK));
00100       }
00101    }
00102 
00103    return NULL;
00104 }

int find_nc_grp_h5 int  ncid,
NC_FILE_INFO_T **  nc,
NC_GRP_INFO_T **  grp,
NC_HDF5_FILE_INFO_T **  h5
 

Definition at line 197 of file nc4internal.c.

References NC_FILE_INFO::ext_ncid, FILE_ID_MASK, GRP_ID_MASK, NC_FILE_INFO::nc4_info, NC_EBADGRPID, NC_EBADID, NC_NOERR, NC_FILE_INFO::next, rec_find_grp(), and NC_HDF5_FILE_INFO_T::root_grp.

Referenced by nc_close(), nc_def_dim(), nc_del_att(), nc_inq(), nc_inq_dim(), nc_inq_dimid(), nc_inq_unlimdim(), nc_inq_var(), nc_inq_varid(), nc_rename_att(), nc_rename_dim(), and nc_rename_var().

00199 {
00200    NC_FILE_INFO_T *f;
00201 
00202    for (f = nc_file; f; f = f->next)
00203    {
00204       /* Find the file from the file id part of ncid. */
00205       if (f->ext_ncid == (ncid & FILE_ID_MASK))
00206       {
00207          *nc = f;
00208          if (f->nc4_info)
00209          {
00210             assert(f->nc4_info->root_grp);
00211 
00212             /* If we can't find it, the grp id part of ncid is bad. */
00213             if (!(*grp = rec_find_grp(f->nc4_info->root_grp, (ncid & GRP_ID_MASK))))
00214                return NC_EBADGRPID;
00215 
00216             *h5 = (*grp)->file->nc4_info;
00217             assert(*h5);
00218          }
00219          else
00220          {
00221             *h5 = NULL;
00222             *grp = NULL;
00223          }
00224          return NC_NOERR;
00225       }
00226    }
00227 
00228    return NC_EBADID;
00229 }

int find_type NC_HDF5_FILE_INFO_T h5,
int  typeid,
NC_TYPE_INFO_T **  type
 

Definition at line 395 of file nc4internal.c.

References NC_EBADTYPID, NC_EINVAL, NC_NOERR, NC_STRING, rec_find_nc_type(), and NC_HDF5_FILE_INFO_T::root_grp.

Referenced by get_hdf_typeid(), nc4_get_att(), nc4_get_typelen_mem(), nc4_put_att(), nc_inq_compound_fieldindex(), nc_insert_array_compound(), nc_insert_enum(), read_grp_atts(), and read_type().

00396 {
00397    if (typeid < 0 || !type)
00398       return NC_EINVAL;
00399    *type = NULL;
00400 
00401    /* Atomic types don't have associated NC_TYPE_INFO_T struct, just
00402     * return NOERR. */
00403    if (typeid <= NC_STRING)
00404       return NC_NOERR;
00405 
00406    /* Find the type. */
00407    if(!(*type = rec_find_nc_type(h5->root_grp, typeid)))
00408       return NC_EBADTYPID;
00409 
00410    return NC_NOERR;
00411 }

int find_var NC_GRP_INFO_T grp,
int  varid,
NC_VAR_INFO_T **  var
 

Definition at line 301 of file nc4internal.c.

References NC_ENOTVAR, NC_NOERR, NC_VAR_INFO::next, and NC_GRP_INFO::var.

00302 {
00303    assert(grp && var);
00304 
00305    /* Find the var info. */
00306    for ((*var) = grp->var; (*var); (*var) = (*var)->next)
00307      if ((*var)->varid == varid)
00308        break;
00309    if (!(*var))
00310      return NC_ENOTVAR;
00311 
00312    return NC_NOERR;
00313 }

void grp_list_del NC_GRP_INFO_T **  list,
NC_GRP_INFO_T grp
 

Definition at line 1334 of file nc4internal.c.

References nc_free, NC_GRP_INFO::next, and NC_GRP_INFO::prev.

Referenced by rec_grp_del().

01335 {
01336    if(*list == grp)
01337       *list = grp->next;
01338    else
01339       grp->prev->next = grp->next;
01340 
01341    if(grp->next)
01342       grp->next->prev = grp->prev;
01343 
01344    nc_free(grp);
01345 }

int nc4_enum_member_add NC_ENUM_MEMBER_INFO_T **  list,
size_t  size,
const char *  name,
const void *  value
 

Definition at line 1015 of file nc4internal.c.

References LOG, NC_ENUM_MEMBER_INFO::name, nc_calloc, NC_check_name(), NC_ENOMEM, NC_NOERR, NC_ENUM_MEMBER_INFO::next, NC_ENUM_MEMBER_INFO::prev, and NC_ENUM_MEMBER_INFO::value.

Referenced by nc_insert_enum(), and read_type().

01017 {
01018    NC_ENUM_MEMBER_INFO_T *member, *m;
01019    int retval;
01020 
01021    assert(name && size > 0 && value);
01022    LOG((4, "nc4_enum_member_add: name %s", name));
01023 
01024    /* Check name. */
01025    if ((retval = NC_check_name(name)))
01026       return retval;
01027 
01028    /* Allocate storage for this field information. */
01029    if (!(member = nc_calloc(1, sizeof(NC_ENUM_MEMBER_INFO_T))) ||
01030        !(member->value = nc_calloc(1, size)))
01031       return NC_ENOMEM;
01032 
01033    /* Add this field to list. */
01034    if (*list)
01035    {
01036       for (m = *list; m; m = m->next)
01037          if (!m->next)
01038             break;
01039       m->next = member;
01040       member->prev = m;
01041    }
01042    else
01043    {
01044       *list = member;
01045    }
01046 
01047    /* Store the information about this member. */
01048    strcpy(member->name, name);
01049    memcpy(member->value, value, size);
01050 
01051    return NC_NOERR;
01052 }

int nc4_find_grp_att NC_GRP_INFO_T grp,
int  varid,
const char *  name,
int  attnum,
NC_ATT_INFO_T **  att
 

Definition at line 461 of file nc4internal.c.

References NC_GRP_INFO::att, NC_VAR_INFO::att, LOG, NC_GRP_INFO::name, NC_ENOTATT, NC_ENOTVAR, NC_GLOBAL, NC_NOERR, NC_VAR_INFO::next, NC_ATT_INFO::next, NC_GRP_INFO::var, and NC_VAR_INFO::varid.

Referenced by nc4_get_att().

00463 {
00464    NC_VAR_INFO_T *var;
00465    NC_ATT_INFO_T *attlist = NULL;
00466 
00467    assert(grp && grp->name);
00468    LOG((4, "nc4_find_grp_att: grp->name %s varid %d name %s attnum %d", 
00469         grp->name, varid, name, attnum));
00470 
00471    /* Get either the global or a variable attribute list. */
00472    if (varid == NC_GLOBAL)
00473       attlist = grp->att;
00474    else
00475    {
00476       for(var = grp->var; var; var = var->next)
00477       {
00478          if (var->varid == varid)
00479          {
00480             attlist = var->att;
00481             break;
00482          }
00483       }
00484       if (!var)
00485          return NC_ENOTVAR;
00486    }
00487 
00488    /* Now find the attribute by name or number. If a name is provided,
00489     * ignore the attnum. */
00490    for (*att = attlist; *att; *att = (*att)->next)
00491       if ((name && !strcmp((*att)->name, name)) ||
00492           (!name && (*att)->attnum == attnum))
00493          return NC_NOERR;
00494 
00495    /* If we get here, we couldn't find the attribute. */
00496    return NC_ENOTATT;
00497 }

int nc4_grp_list_add NC_GRP_INFO_T **  list,
int  new_nc_grpid,
NC_GRP_INFO_T parent_grp,
NC_FILE_INFO_T nc,
char *  name,
NC_GRP_INFO_T **  grp
 

Definition at line 893 of file nc4internal.c.

References LOG, nc_calloc, NC_ENOMEM, NC_GRP_INFO::nc_grpid, NC_NOERR, NC_GRP_INFO::next, and NC_GRP_INFO::prev.

Referenced by file_list_add_netcdf4(), main(), nc_def_grp(), and rec_read_metadata().

00896 {
00897    NC_GRP_INFO_T *g;
00898 
00899    LOG((3, "grp_list_add: new_nc_grpid %d name %s ", 
00900         new_nc_grpid, name));
00901 
00902    /* Get the memory to store this groups info. */
00903    if (!(*grp = nc_calloc(1, sizeof(NC_GRP_INFO_T))))
00904       return NC_ENOMEM;
00905 
00906    /* If the list is not NULL, add this group to it. Otherwise, this
00907     * group structure becomes the list. */
00908    if (*list)
00909    {
00910       /* Move to end of the list. */
00911       for (g = *list; g; g = g->next)
00912          if (!g->next)
00913             break;
00914       g->next = *grp; /* Add grp to end of list. */
00915       (*grp)->prev = g;
00916    }
00917    else
00918    {
00919       *list = *grp;
00920    }
00921 
00922    /* Fill in this group's information. */
00923    (*grp)->nc_grpid = new_nc_grpid;
00924    (*grp)->parent = parent_grp;
00925    strcpy((*grp)->name, name);
00926    (*grp)->file = nc;
00927 
00928    return NC_NOERR;
00929 }

int nc4_type_list_add NC_TYPE_INFO_T **  list,
int  typeid,
size_t  size,
const char *  name,
nc_type  class,
nc_type  base_nc_type
 

Definition at line 933 of file nc4internal.c.

References NC_TYPE_INFO::base_nc_type, NC_TYPE_INFO::class, NC_TYPE_INFO::name, nc_calloc, NC_ENOMEM, NC_NOERR, NC_TYPE_INFO::nc_typeid, NC_TYPE_INFO::next, NC_TYPE_INFO::prev, NC_TYPE_INFO::size, and type.

Referenced by add_user_type(), and read_type().

00935 {
00936    NC_TYPE_INFO_T *type, *t;
00937 
00938    if (!(type = nc_calloc(1, sizeof(NC_TYPE_INFO_T))))
00939       return NC_ENOMEM;
00940 
00941    if (*list)
00942    {
00943       for (t = *list; t; t = t->next)
00944          if (!t->next)
00945             break;
00946       t->next = type;
00947       type->prev = t;
00948    }
00949    else
00950    {
00951       *list = type;
00952    }
00953 
00954    /* Remembe info about this new type. */
00955    type->class = class;
00956    type->nc_typeid = typeid;
00957    strcpy(type->name, name);
00958    type->size = size;
00959    type->base_nc_type = base_nc_type;
00960 
00961    return NC_NOERR;
00962 }

int nc4_var_list_add NC_VAR_INFO_T **  list,
NC_VAR_INFO_T **  var
 

Definition at line 828 of file nc4internal.c.

References nc_calloc, NC_ENOMEM, NC_NOERR, NC_VAR_INFO::next, and NC_VAR_INFO::prev.

Referenced by nc_def_var_full(), and read_var().

00829 {
00830    NC_VAR_INFO_T *v;
00831 
00832    /* Allocate storage for new variable. */
00833    if (!(*var = nc_calloc(1, sizeof(NC_VAR_INFO_T))))
00834       return NC_ENOMEM;
00835 
00836    /* Go to the end of the list and set the last one to point at our
00837     * new var, or, if the list is empty, our new var becomes the
00838     * list. */
00839    if(*list)
00840    {
00841       for (v = *list; v; v = v->next)
00842          if (!v->next)
00843             break;
00844       v->next = *var;
00845       (*var)->prev = v;
00846    }      
00847    else
00848       *list = *var;
00849 
00850    return NC_NOERR;
00851 }

NC_GRP_INFO_T* rec_find_grp NC_GRP_INFO_T start_grp,
int  target_nc_grpid
 

Definition at line 233 of file nc4internal.c.

References NC_GRP_INFO::children, NC_GRP_INFO::nc_grpid, NC_GRP_INFO::next, and rec_find_grp().

Referenced by find_grp_h5(), find_grp_var_nc(), find_nc4_grp(), find_nc_grp(), find_nc_grp_h5(), main(), nc4_get_att(), nc4_put_att(), and rec_find_grp().

00234 {
00235    NC_GRP_INFO_T *g, *res;
00236 
00237    assert(start_grp);
00238    
00239    /* Is this the group we are searching for? */
00240    if (start_grp->nc_grpid == target_nc_grpid)
00241       return start_grp;
00242 
00243    /* Shake down the kids. */
00244    if (start_grp->children)
00245       for (g = start_grp->children; g; g = g->next)
00246          if ((res = rec_find_grp(g, target_nc_grpid)))
00247             return res;
00248 
00249    /* Can't find if. Fate, why do you mock me? */
00250    return NULL;
00251 }

NC_TYPE_INFO_T* rec_find_hdf_type NC_GRP_INFO_T start_grp,
hid_t  target_hdf_typeid
 

Definition at line 342 of file nc4internal.c.

References NC_GRP_INFO::children, equal(), NC_TYPE_INFO::hdf_typeid, NC_TYPE_INFO::next, NC_GRP_INFO::next, rec_find_hdf_type(), type, and NC_GRP_INFO::type.

Referenced by get_netcdf_type(), and rec_find_hdf_type().

00343 {
00344    NC_GRP_INFO_T *g;
00345    NC_TYPE_INFO_T *type, *res;
00346    htri_t equal;
00347 
00348    assert(start_grp);
00349    
00350    /* Does this group have the type we are searching for? */
00351    for (type = start_grp->type; type; type = type->next)
00352    {
00353       if ((equal = H5Tequal(type->hdf_typeid, target_hdf_typeid)) < 0)
00354          return NULL;
00355       if (equal)
00356          return type;
00357    }
00358 
00359    /* Shake down the kids. */
00360    if (start_grp->children)
00361       for (g = start_grp->children; g; g = g->next)
00362          if ((res = rec_find_hdf_type(g, target_hdf_typeid)))
00363             return res;
00364 
00365    /* Can't find if. Fate, why do you mock me? */
00366    return NULL;
00367 }

NC_TYPE_INFO_T* rec_find_nc_type NC_GRP_INFO_T start_grp,
hid_t  target_nc_typeid
 

Definition at line 371 of file nc4internal.c.

References NC_GRP_INFO::children, NC_TYPE_INFO::nc_typeid, NC_TYPE_INFO::next, NC_GRP_INFO::next, rec_find_nc_type(), type, and NC_GRP_INFO::type.

Referenced by find_type(), nc_inq_compound_field(), nc_inq_enum_member(), nc_inq_type(), nc_inq_user_type(), and rec_find_nc_type().

00372 {
00373    NC_GRP_INFO_T *g;
00374    NC_TYPE_INFO_T *type, *res;
00375 
00376    assert(start_grp);
00377    
00378    /* Does this group have the type we are searching for? */
00379    for (type = start_grp->type; type; type = type->next)
00380       if (type->nc_typeid == target_nc_typeid)
00381          return type;
00382 
00383    /* Shake down the kids. */
00384    if (start_grp->children)
00385       for (g = start_grp->children; g; g = g->next)
00386          if ((res = rec_find_nc_type(g, target_nc_typeid)))
00387             return res;
00388 
00389    /* Can't find if. Fate, why do you mock me? */
00390    return NULL;
00391 }

int rec_grp_del NC_GRP_INFO_T **  list,
NC_GRP_INFO_T grp
 

Definition at line 1162 of file nc4internal.c.

References NC_GRP_INFO::att, att_list_del(), NC_GRP_INFO::children, NC_GRP_INFO::dim, dim_list_del(), NC_VAR_INFO::dimscale, grp_list_del(), NC_VAR_INFO::hdf_datasetid, NC_DIM_INFO::hdf_dimscaleid, NC_GRP_INFO::hdf_grpid, LOG, NC_GRP_INFO::name, NC_ATT_INFO::name, NC_VAR_INFO::name, NC_DIM_INFO::name, NC_TYPE_INFO::name, NC_EHDFERR, NC_NOERR, NC_GRP_INFO::next, NC_ATT_INFO::next, NC_VAR_INFO::next, NC_DIM_INFO::next, NC_TYPE_INFO::next, rec_grp_del(), type, NC_GRP_INFO::type, type_list_del(), NC_GRP_INFO::var, and var_list_del().

Referenced by close_netcdf4_file(), main(), and rec_grp_del().

01163 {
01164    NC_GRP_INFO_T *g, *c;
01165    NC_VAR_INFO_T *v, *var;
01166    NC_ATT_INFO_T *a, *att;
01167    NC_DIM_INFO_T *d, *dim;
01168    NC_TYPE_INFO_T *type, *t;
01169    int retval;
01170 
01171    assert(grp);
01172    LOG((3, "rec_grp_del: grp->name %s", grp->name));
01173 
01174    /* Recursively call this function for each child, if any, stopping
01175     * if there is an error. */
01176    g = grp->children;
01177    while(g)
01178    {
01179       c = g->next;
01180       if ((retval = rec_grp_del(&(grp->children), g)))
01181          return retval;
01182       g = c;
01183    }
01184 
01185    /* Delete all the list contents for vars, dims, and atts, in each
01186     * group. */
01187    att = grp->att;
01188    while (att)
01189    {
01190       LOG((4, "rec_grp_del: deleting att %s", att->name));      
01191       a = att->next;
01192       att_list_del(&grp->att, att);
01193       att = a;
01194    }
01195 
01196    /* Delete all vars. */
01197    var = grp->var;
01198    while (var)
01199    {
01200       LOG((4, "rec_grp_del: deleting var %s", var->name));      
01201       /* Close HDF5 dataset associated with this var, unless it's a
01202        * scale. */
01203       if (var->hdf_datasetid && !var->dimscale && 
01204           H5Dclose(var->hdf_datasetid) < 0)
01205          return NC_EHDFERR;
01206       v = var->next;
01207       var_list_del(&grp->var, var);
01208       var = v;
01209    }
01210 
01211    
01212    /* Delete all dims. */
01213    dim = grp->dim;
01214    while (dim)
01215    {
01216       LOG((4, "rec_grp_del: deleting dim %s", dim->name));      
01217       /* Close HDF5 dataset associated with this dim. */
01218       if (dim->hdf_dimscaleid && H5Dclose(dim->hdf_dimscaleid) < 0)
01219          return NC_EHDFERR;
01220       d = dim->next;
01221       dim_list_del(&grp->dim, dim);
01222       dim = d;
01223    }
01224 
01225    /* Delete all types. */
01226    type = grp->type; 
01227    while (type)
01228    {
01229       LOG((4, "rec_grp_del: deleting type %s", type->name));      
01230       t = type->next;
01231       if ((retval = type_list_del(&grp->type, type)))
01232          return retval;
01233       type = t;
01234    }
01235 
01236    /* Tell HDF5 we're closing this group. (The only reason I check
01237     * hdf_grpid here is so that I can tests list code without really
01238     * have a HDF file open.) */ 
01239    LOG((4, "rec_grp_del: closing group %s", grp->name));         
01240    if (grp->hdf_grpid && H5Gclose(grp->hdf_grpid) < 0) 
01241       return NC_EHDFERR;
01242 
01243    /* Finally, redirect pointers around this entry in the list, and
01244     * nc_free it's memory. */
01245    grp_list_del(list, grp);
01246 
01247    return NC_NOERR;
01248 }

int type_list_del NC_TYPE_INFO_T **  list,
NC_TYPE_INFO_T type
 

Definition at line 1096 of file nc4internal.c.

References NC_TYPE_INFO::enum_member, NC_TYPE_INFO::field, field_list_del(), NC_TYPE_INFO::hdf_typeid, NC_EHDFERR, nc_free, NC_NOERR, NC_FIELD_INFO::next, NC_ENUM_MEMBER_INFO::next, NC_TYPE_INFO::next, NC_TYPE_INFO::prev, and NC_ENUM_MEMBER_INFO::value.

Referenced by rec_grp_del().

01097 {
01098    NC_FIELD_INFO_T *field, *f;
01099    NC_ENUM_MEMBER_INFO_T *enum_member, *em;
01100 
01101    /* Close any open user-defined HDF5 typieds. */
01102    if (type->hdf_typeid)
01103    {
01104       if (H5Tclose(type->hdf_typeid) < 0)
01105          return NC_EHDFERR;
01106    }
01107 
01108    /* Delete all the fields in this type (there will be some if its a
01109     * compound). */
01110    field = type->field;
01111    while (field)
01112    {
01113       f = field->next;
01114       field_list_del(&type->field, field);
01115       field = f;
01116    }
01117 
01118    /* Delete all the enum_members, if any. */
01119    enum_member = type->enum_member;
01120    while (enum_member)
01121    {
01122       em = enum_member->next;
01123       nc_free(enum_member->value);
01124       enum_member = em;
01125    }
01126 
01127    /* Take this type out of the list. */
01128    if(*list == type)
01129       *list = type->next;
01130    else
01131       type->prev->next = type->next;
01132 
01133    if(type->next)
01134       type->next->prev = type->prev;
01135 
01136    /* Nc_Free the memory. */
01137    nc_free(type);
01138    
01139    return NC_NOERR;
01140 }

void var_list_del NC_VAR_INFO_T **  list,
NC_VAR_INFO_T var
 

Definition at line 1056 of file nc4internal.c.

References NC_VAR_INFO::att, att_list_del(), NC_VAR_INFO::dimscale_attached, NC_VAR_INFO::dimscale_hdf5_objids, NC_VAR_INFO::fill_value, nc_free, NC_ATT_INFO::next, NC_VAR_INFO::next, and NC_VAR_INFO::prev.

Referenced by rec_grp_del().

01057 {
01058    NC_ATT_INFO_T *a, *att;
01059 
01060    /* First delete all the attributes attached to this var. */
01061    att = (*list)->att;
01062    while (att)
01063    {
01064       a = att->next;
01065       att_list_del(&var->att, att);
01066       att = a;
01067    }
01068 
01069    /* Remove the var from the linked list. */
01070    if(*list == var)
01071       *list = var->next;
01072    else
01073       var->prev->next = var->next;
01074 
01075    if(var->next)
01076       var->next->prev = var->prev;
01077    
01078    /* Delete any HDF5 dimscale objid information. */
01079    if (var->dimscale_hdf5_objids)
01080       nc_free(var->dimscale_hdf5_objids);
01081 
01082    /* Delete information about the attachment status of dimscales. */
01083    if (var->dimscale_attached)
01084       nc_free(var->dimscale_attached);
01085 
01086    /* Delete any fill value allocation. */
01087    if (var->fill_value)
01088       nc_free(var->fill_value);
01089    
01090    /* Delete the var. */
01091    nc_free(var);
01092 }


Variable Documentation

NC_FILE_INFO_T* nc_file = NULL
 

Definition at line 23 of file nc4internal.c.


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