OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
nccmp_user_type.c
Go to the documentation of this file.
1 /*
2  * nccmp_user_type.c
3  *
4  * Created on: Sep 26, 2016
5  * Author: rhealy
6  */
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <netcdf.h>
10 #include "nccmp_user_type.h"
11 //#define NCCMP_MAX_COMPOUND_FIELD_DIMS 4
12 //#define NCCMP_MAX_COMPOUND_FIELDS 20
13 // see https://www.unidata.ucar.edu/software/netcdf/netcdf-4/newdocs/netcdf-c/nc_005finq_005fcompound.html
14 
16  int status;
17  int i, typeid, *typeids = NULL, field_i;
18  nccmp_user_type_t *comp_node;
19 
20  status = nc_inq_typeids(group_id, nuser_types, NULL);
21  if (status != NC_NOERR) {
22  fprintf(stderr, "Netcdf error status = %d\n", status);
23  exit(status);
24  }
25 
26  if (*nuser_types < 1) {
27  *nuser_types = 0;
28  return (NULL);
29  }
30 
31  typeids = (int *) calloc(*nuser_types, sizeof (int));
32  if (!typeids) {
33  fprintf(stderr, "Error allocating typeids\n ");
34  exit(1);
35  }
36 
37  comp_node = (nccmp_user_type_t *) malloc((*nuser_types) * sizeof (nccmp_user_type_t));
38  status = nc_inq_typeids(group_id, NULL, typeids);
39  if (status != NC_NOERR) {
40  fprintf(stderr, "Netcdf error status = %d\n", status);
41  exit(status);
42  }
43 
44  //results = nccmp_darray_create(*nuser_types);
45  //using nc_inq_user_type for possible future implementation of other user types - rjh
46  for (i = 0; i < *nuser_types; ++i) {
47  typeid = typeids[i];
48  comp_node[i].type_id = typeid;
49  comp_node[i].group_id = group_id;
50  status = nc_inq_user_type(group_id,
51  typeid,
52  comp_node[i].name,
53  & comp_node[i].size,
54  & comp_node[i].base_type,
55  & comp_node[i].num_fields,
56  & comp_node[i].user_class);
57  if (status != NC_NOERR) {
58  fprintf(stderr, "Netcdf error status = %d\n", status);
59  exit(status);
60  }
61  if (comp_node[i].user_class != NC_COMPOUND) {
62  fprintf(stderr, "Can only handle compound types at the moment\n ");
63  exit(1);
64  }
65 
66  if (comp_node[i].num_fields) {
67  comp_node[i].root_size = comp_node[i].size; /* This node is a compound root. */
68  comp_node[i].fields = (nccmp_user_type_t *) malloc(comp_node[i].num_fields * sizeof (nccmp_user_type_t));
69 
70  for (field_i = 0; field_i < comp_node[i].num_fields; ++field_i) {
71  comp_node[i].fields[field_i].group_id = group_id;
72  comp_node[i].fields[field_i].field_index = field_i;
73 
74  status = nc_inq_compound_field(group_id,
75  typeid,
76  field_i,
77  comp_node[i].fields[field_i].name,
78  & comp_node[i].fields[field_i].offset,
79  & comp_node[i].fields[field_i].type_id,
80  & comp_node[i].fields[field_i].num_dims,
81  comp_node[i].fields[field_i].dim_sizes);
82  if (status != NC_NOERR) {
83  fprintf(stderr, "Netcdf error status = %d\n", status);
84  exit(status);
85  }
86 
87  }
88  }
89  }
90 
91  free(typeids);
92 
93  return comp_node;
94 }
int status
Definition: l1_czcs_hdf.c:32
#define NULL
Definition: decode_rs.h:63
int nuser_types
Definition: nccmp.h:66
struct nccmp_user_type_t * fields
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude resolving resolving GSFcd00179 Corrected handling of fill values for[Sensor|Solar][Zenith|Azimuth] resolving MODxl01751 Changed to validate LUT version against a value retrieved from the resolving MODxl02056 Changed to calculate Solar Diffuser angles without adjustment for estimated post launch changes in the MODIS orientation relative to incidentally resolving defects MODxl01766 Also resolves MODxl01947 Changed to ignore fill values in SCI_ABNORM and SCI_STATE fields
Definition: HISTORY.txt:400
l2prod offset
nccmp_user_type_t * nccmp_load_group_usertype_array(int group_id, int *nuser_types)
int i
Definition: decode_rs.h:71