NetCDF  4.6.3
 All Data Structures Files Functions Variables Typedefs Macros Modules Pages
nc4dim.c
Go to the documentation of this file.
1 /* Copyright 2003-2018, University Corporation for Atmospheric
2  * Research. See the COPYRIGHT file for copying and redistribution
3  * conditions. */
15 #include "nc4internal.h"
16 #include "nc4dispatch.h"
17 
32 int
33 NC4_inq_unlimdim(int ncid, int *unlimdimidp)
34 {
35  NC_GRP_INFO_T *grp, *g;
36  NC_FILE_INFO_T *h5;
37  NC_DIM_INFO_T *dim;
38  int found = 0;
39  int retval;
40  int i;
41 
42  LOG((2, "%s: called", __func__));
43 
44  if ((retval = nc4_find_grp_h5(ncid, &grp, &h5)))
45  return retval;
46  assert(h5 && grp);
47 
48  if (unlimdimidp)
49  {
50  /* According to netcdf-3 manual, return -1 if there is no unlimited
51  dimension. */
52  *unlimdimidp = -1;
53  for (g = grp; g && !found; g = g->parent)
54  {
55  for(i=0;i<ncindexsize(grp->dim);i++)
56  {
57  dim = (NC_DIM_INFO_T*)ncindexith(grp->dim,i);
58  if(dim == NULL) continue;
59  if (dim->unlimited)
60  {
61  *unlimdimidp = dim->hdr.id;
62  found++;
63  break;
64  }
65  }
66  }
67  }
68 
69  return NC_NOERR;
70 }
71 
85 int
86 NC4_inq_dimid(int ncid, const char *name, int *idp)
87 {
88  NC *nc;
89  NC_GRP_INFO_T *grp, *g;
90  NC_FILE_INFO_T *h5;
91  NC_DIM_INFO_T *dim;
92  char norm_name[NC_MAX_NAME + 1];
93  int retval;
94  int found;
95 
96  LOG((2, "%s: ncid 0x%x name %s", __func__, ncid, name));
97 
98  /* Check input. */
99  if (!name)
100  return NC_EINVAL;
101 
102  /* Find metadata for this file. */
103  if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
104  return retval;
105  assert(h5 && nc && grp);
106 
107  /* Normalize name. */
108  if ((retval = nc4_normalize_name(name, norm_name)))
109  return retval;
110 
111  /* check for a name match in this group and its parents */
112  found = 0;
113  for (g = grp; g ; g = g->parent) {
114  dim = (NC_DIM_INFO_T*)ncindexlookup(g->dim,norm_name);
115  if(dim != NULL) {found = 1; break;}
116  }
117  if(!found)
118  return NC_EBADDIM;
119  assert(dim != NULL);
120  if (idp)
121  *idp = dim->hdr.id;
122  return NC_NOERR;
123 }
124 
140 int
141 NC4_inq_unlimdims(int ncid, int *nunlimdimsp, int *unlimdimidsp)
142 {
143  NC_DIM_INFO_T *dim;
144  NC_GRP_INFO_T *grp;
145  NC *nc;
146  NC_FILE_INFO_T *h5;
147  int num_unlim = 0;
148  int retval;
149  int i;
150 
151  LOG((2, "%s: ncid 0x%x", __func__, ncid));
152 
153  /* Find info for this file and group, and set pointer to each. */
154  if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
155  return retval;
156  assert(h5 && nc && grp);
157 
158  /* Get our dim info. */
159  assert(h5);
160  {
161  for(i=0;i<ncindexsize(grp->dim);i++)
162  {
163  dim = (NC_DIM_INFO_T*)ncindexith(grp->dim,i);
164  if(dim == NULL) continue;
165  if (dim->unlimited)
166  {
167  if (unlimdimidsp)
168  unlimdimidsp[num_unlim] = dim->hdr.id;
169  num_unlim++;
170  }
171  }
172  }
173 
174  /* Give the number if the user wants it. */
175  if (nunlimdimsp)
176  *nunlimdimsp = num_unlim;
177 
178  return NC_NOERR;
179 }
#define NC_EBADDIM
Invalid dimension id or name.
Definition: netcdf.h:366
#define NC_EINVAL
Invalid Argument.
Definition: netcdf.h:333
#define NC_MAX_NAME
Maximum for classic library.
Definition: netcdf.h:273
#define NC_NOERR
No Error.
Definition: netcdf.h:323

Return to the Main Unidata NetCDF page.
Generated on Sat Apr 6 2019 08:19:00 for NetCDF. NetCDF is a Unidata library.