MISR Toolkit  1.5.1
MtkNCVarId.c
Go to the documentation of this file.
1 /*===========================================================================
2 = =
3 = MtkNCVarId =
4 = =
5 =============================================================================
6 
7  Copyright 2017, California Institute of Technology.
8  ALL RIGHTS RESERVED.
9  U.S. Government Sponsorship acknowledged.
10 
11 ============================================================================*/
12 
13 #define _GNU_SOURCE
14 
15 #include "MisrUtil.h"
16 #include <netcdf.h> // Definition of nc_inq_varid
17 #include <string.h> // Definition of strcspn
18 #include <stdlib.h> // Definition of calloc
19 #include <stdio.h>
20 
21 MTKt_status MtkNCVarId(int Ncid, const char *Name, MTKt_ncvarid *Var)
22 {
23  MTKt_status status_code; /* Return status code for error macros */
24  const char *p = Name;
25  size_t len;
26  Var->gid = Ncid;
27 
28  while (strlen(p) != (len = strcspn(p, "/"))) {
29 
30  char *group_name = calloc(len+1, sizeof(char));
31  strncpy(group_name, p, len);
32 
33  int nc_status = nc_inq_grp_ncid(Var->gid, group_name, &(Var->gid));
34  free(group_name);
36 
37  p += len + 1;
38  }
39 
40  int nc_status = nc_inq_varid(Var->gid, p, &(Var->varid));
42 
43  return MTK_SUCCESS;
44  ERROR_HANDLE:
45  return status_code;
46 }
HDFFCLIBAPI intf * len
#define MTK_ERR_CODE_JUMP(code)
Definition: MisrError.h:175
#define NC_NOERR
Definition: netcdf.h:313
MTKt_status MtkNCVarId(int Ncid, const char *Name, MTKt_ncvarid *Var)
Definition: MtkNCVarId.c:21
EXTERNL int nc_inq_varid(int ncid, const char *name, int *varidp)
MTKt_status
Definition: MisrError.h:11
EXTERNL int nc_inq_grp_ncid(int ncid, const char *grp_name, int *grp_ncid)

MISR Toolkit - Copyright © 2005 - 2020 Jet Propulsion Laboratory
Generated on Fri Jun 19 2020 22:49:51