NASA Logo
Ocean Color Science Software

ocssw V2022
find_variable.c
Go to the documentation of this file.
1 #include "find_variable.h"
2 #include "stdio.h"
3 #define MAXNUMNCGRP 100
4 int32_t find_nc_variable_parent_grp_c_interface_id_ncid(const char* var_name, int32_t ncid,
5  int32_t* netcdf_c_var_id, int32_t* netcdf_c_grp_id) {
6  int32_t numgrps;
7  int32_t ncids[MAXNUMNCGRP];
8  int32_t status = nc_inq_varid(ncid, var_name, netcdf_c_var_id);
9  if (status == NC_NOERR) {
10  *netcdf_c_grp_id = ncid;
11  return status;
12  }
13 
14  status = nc_inq_grps(ncid, &numgrps, ncids);
15  if (status != NC_NOERR)
16  return status;
17  else {
18  for (int32_t i = 0; i < numgrps; i++) {
19  status = find_nc_variable_parent_grp_c_interface_id_ncid(var_name, ncids[i], netcdf_c_var_id,
20  netcdf_c_grp_id);
21  if (status == NC_NOERR)
22  return status;
23  }
24  }
25  return NC_ENOTVAR;
26 };
27 
28 
29 int32_t find_nc_variable_possible_names(const char * possible_names[], int32_t number_of_names, int32_t ncid,
30  int32_t* netcdf_c_var_id, int32_t* netcdf_c_grp_id, int32_t * file_index_name )
31 {
32  int32_t status = 0;
33  if(number_of_names <=0)
34  return NC2_ERR;
35  for(int32_t i = 0; i < number_of_names; i ++)
36  {
37  status = find_nc_variable_parent_grp_c_interface_id_ncid(possible_names[i],ncid,netcdf_c_var_id,netcdf_c_grp_id);
38  if (status == NC_NOERR)
39  {
40  *file_index_name = i;
41  return status;
42  }
43  }
44  return NC2_ERR;
45 }
int status
Definition: l1_czcs_hdf.c:32
int32_t find_nc_variable_parent_grp_c_interface_id_ncid(const char *var_name, int32_t ncid, int32_t *netcdf_c_var_id, int32_t *netcdf_c_grp_id)
Recursively searches for a netcdf variable within an NC file or group. Search is recursive ( DFS tree...
Definition: find_variable.c:4
int32_t find_nc_variable_possible_names(const char *possible_names[], int32_t number_of_names, int32_t ncid, int32_t *netcdf_c_var_id, int32_t *netcdf_c_grp_id, int32_t *file_index_name)
Definition: find_variable.c:29
#define MAXNUMNCGRP
Definition: find_variable.c:3
int i
Definition: decode_rs.h:71