14#include "nc4internal.h"
15#include "nc4dispatch.h"
32NC4_inq_typeids(
int ncid,
int *ntypes,
int *typeids)
40 LOG((2,
"nc_inq_typeids: ncid 0x%x", ncid));
43 if ((retval = nc4_find_grp_h5(ncid, &grp, &h5)))
49 for(
size_t i=0;i<ncindexsize(grp->type);i++)
51 if((type = (NC_TYPE_INFO_T*)ncindexith(grp->type,i)) == NULL)
continue;
53 typeids[num] = type->hdr.id;
80NC4_inq_type(
int ncid,
nc_type typeid1,
char *name,
size_t *size)
87 LOG((2,
"nc_inq_type: ncid 0x%x typeid %d", ncid, typeid1));
90 if (typeid1 < NUM_ATOMIC_TYPES)
92 if((retval=NC4_inq_atomic_type(typeid1, name, size)))
return retval;
97 if ((retval = nc4_find_nc4_grp(ncid, &grp)))
101 if (!(type = nclistget(grp->nc4_info->alltypes, (
size_t)typeid1)))
105 strcpy(name, type->hdr.name);
109 if (type->nc_type_class ==
NC_VLEN)
135NC4_inq_user_type(
int ncid,
nc_type typeid1,
char *name,
size_t *size,
136 nc_type *base_nc_typep,
size_t *nfieldsp,
int *classp)
139 NC_TYPE_INFO_T *type;
142 LOG((2,
"nc_inq_user_type: ncid 0x%x typeid %d", ncid, typeid1));
145 if ((retval = nc4_find_nc4_grp(ncid, &grp)))
149 if (!(type = nclistget(grp->nc4_info->alltypes, (
size_t)typeid1)))
156 *nfieldsp = nclistlength(type->u.c.field);
157 else if (type->nc_type_class ==
NC_ENUM)
158 *nfieldsp = nclistlength(type->u.e.enum_member);
166 if (type->nc_type_class ==
NC_VLEN)
168 else if (type->nc_type_class ==
NC_STRING) {
169 if((retval=NC4_inq_type(ncid,typeid1,NULL,size)))
return retval;
174 strcpy(name, type->hdr.name);
180 if (type->nc_type_class ==
NC_ENUM)
181 *base_nc_typep = type->u.e.base_nc_typeid;
182 else if (type->nc_type_class ==
NC_VLEN)
183 *base_nc_typep = type->u.v.base_nc_typeid;
191 *classp = type->nc_type_class;
214NC4_inq_compound_field(
int ncid,
nc_type typeid1,
int fieldid,
char *name,
215 size_t *offsetp,
nc_type *field_typeidp,
int *ndimsp,
219 NC_TYPE_INFO_T *type;
220 NC_FIELD_INFO_T *field;
224 if ((retval = nc4_find_nc4_grp(ncid, &grp)))
228 if (!(type = nclistget(grp->nc4_info->alltypes, (
size_t)typeid1)))
232 if (!(field = nclistget(type->u.c.field, (
size_t)fieldid)))
236 strcpy(name, field->hdr.name);
238 *offsetp = field->offset;
240 *field_typeidp = field->nc_typeid;
242 *ndimsp = field->ndims;
244 for (d = 0; d < field->ndims; d++)
245 dim_sizesp[d] = field->dim_size[d];
265NC4_inq_compound_fieldindex(
int ncid,
nc_type typeid1,
const char *name,
int *fieldidp)
268 NC_TYPE_INFO_T *type;
269 NC_FIELD_INFO_T *field;
274 LOG((2,
"nc_inq_compound_fieldindex: ncid 0x%x typeid %d name %s",
275 ncid, typeid1, name));
278 if ((retval = nc4_find_grp_h5(ncid, NULL, &h5)))
282 if ((retval = nc4_find_type(h5, typeid1, &type)))
290 if ((retval = nc4_normalize_name(name, norm_name)))
294 for (i = 0; i < nclistlength(type->u.c.field); i++)
296 field = nclistget(type->u.c.field, i);
298 if (!strcmp(field->hdr.name, norm_name))
307 *fieldidp = field->hdr.id;
328NC4_inq_enum_ident(
int ncid,
nc_type xtype,
long long value,
char *identifier)
331 NC_TYPE_INFO_T *type;
332 NC_ENUM_MEMBER_INFO_T *enum_member;
338 LOG((3,
"nc_inq_enum_ident: xtype %d value %d\n", xtype, value));
341 if ((retval = nc4_find_nc4_grp(ncid, &grp)))
345 if (!(type = nclistget(grp->nc4_info->alltypes, (
size_t)xtype)))
349 if (type->nc_type_class !=
NC_ENUM)
353 for (found = 0, i = 0; i < nclistlength(type->u.e.enum_member); i++)
355 enum_member = nclistget(type->u.e.enum_member, i);
357 switch (type->u.e.base_nc_typeid)
360 ll_val = *(
char *)enum_member->value;
363 ll_val = *(
unsigned char *)enum_member->value;
366 ll_val = *(
short *)enum_member->value;
369 ll_val = *(
unsigned short *)enum_member->value;
372 ll_val = *(
int *)enum_member->value;
375 ll_val = *(
unsigned int *)enum_member->value;
379 ll_val = *(
long long *)enum_member->value;
384 LOG((4,
"ll_val=%d", ll_val));
388 strcpy(identifier, enum_member->name);
397 strcpy(identifier, NC_UNDEFINED_ENUM_IDENT);
422NC4_inq_enum_member(
int ncid,
nc_type typeid1,
int idx,
char *identifier,
426 NC_TYPE_INFO_T *type;
427 NC_ENUM_MEMBER_INFO_T *enum_member;
430 LOG((2,
"nc_inq_enum_member: ncid 0x%x typeid %d", ncid, typeid1));
433 if ((retval = nc4_find_nc4_grp(ncid, &grp)))
437 if (!(type = nclistget(grp->nc4_info->alltypes, (
size_t)typeid1)))
441 if (type->nc_type_class !=
NC_ENUM)
445 if (!(enum_member = nclistget(type->u.e.enum_member, (
size_t)idx)))
450 strcpy(identifier, enum_member->name);
452 memcpy(value, enum_member->value, type->size);
472NC4_inq_typeid(
int ncid,
const char *name,
nc_type *typeidp)
475 NC_GRP_INFO_T *grptwo;
477 NC_TYPE_INFO_T *type = NULL;
478 char *norm_name = NULL;
482 for (i = 0; i < NUM_ATOMIC_TYPES; i++)
483 if (!strcmp(name, nc4_atomic_name[i]))
491 if ((retval = nc4_find_grp_h5(ncid, &grp, &h5)))
498 if (name[0] !=
'/' && strstr(name,
"/"))
502 if (!(norm_name = (
char*)malloc(strlen(name) + 1)))
504 if ((retval = nc4_normalize_name(name, norm_name)))
510 int rootncid = (grp->nc4_info->root_grp->hdr.id | grp->nc4_info->controller->ext_ncid);
512 char* lastname = strrchr(norm_name,
'/');
513 if(lastname == norm_name)
516 if((retval = NC4_inq_grp_full_ncid(rootncid,norm_name,&parent)))
519 if((retval=nc4_find_nc4_grp(parent,&grp)))
522 type = (NC_TYPE_INFO_T*)ncindexlookup(grp->type,lastname);
529 for (grptwo = grp; grptwo; grptwo = grptwo->parent) {
530 type = (NC_TYPE_INFO_T*)ncindexlookup(grptwo->type,norm_name);
534 *typeidp = type->hdr.id;
542 if ((type = nc4_rec_find_named_type(grp->nc4_info->root_grp, norm_name)))
544 *typeidp = type->hdr.id;
568nc4_get_typeclass(
const NC_FILE_INFO_T *h5,
nc_type xtype,
int *type_class)
572 LOG((4,
"%s xtype: %d", __func__, xtype));
612 NC_TYPE_INFO_T *type;
615 if ((retval = nc4_find_type(h5, xtype, &type)))
620 *type_class = type->nc_type_class;
639NC4_inq_type_fixed_size(
int ncid,
nc_type xtype,
int* fixedsizep)
643 NC_FILE_INFO_T* h5 = NULL;
644 NC_TYPE_INFO_T* typ = NULL;
646 if(xtype <
NC_STRING) {f = 1;
goto done;}
647 if(xtype ==
NC_STRING) {f = 0;
goto done;}
651 if ((stat = nc4_find_grp_h5(ncid, NULL, &h5)))
653 if((stat = nc4_find_type(h5,xtype,&typ)))
goto done;
657 if(fixedsizep) *fixedsizep = f;
675 NC_FILE_INFO_T* file = NULL;
676 NC_TYPE_INFO_T* utype = NULL;
678 if(subtype ==
NC_STRING) {parenttype->varsized = 1;
goto done;}
680 file = parenttype->container->nc4_info;
681 if((stat = nc4_find_type(file,subtype,&utype)))
goto done;
682 switch (utype->nc_type_class) {
684 case NC_VLEN: parenttype->varsized = 1;
break;
685 case NC_COMPOUND:
if(utype->varsized) parenttype->varsized = 1;
break;
702 if(typ->hdr.id ==
NC_STRING) {typ->varsized = 1;
goto done;}
703 switch (typ->nc_type_class) {
705 case NC_VLEN: typ->varsized = 1;
break;
720 NC_TYPE_INFO_T* vtype = NULL;
723 vtype = var->type_info;
726 return vtype->varsized;
int NC4_var_varsized(NC_VAR_INFO_T *var)
Test if a variable's type is fixed sized or not.
int NC4_recheck_varsize(NC_TYPE_INFO_T *parenttype, nc_type subtype)
For types with one or more subtypes (e.g.
int NC4_set_varsize(NC_TYPE_INFO_T *typ)
When creating a type, mark it as variable-sized if known for sure.
#define NC_EBADTYPE
Not a netcdf data type.
#define NC_EBADFIELD
Bad field ID.
#define NC_UINT
unsigned 4-byte int
#define NC_INT
signed 4 byte integer
#define NC_BYTE
signed 1 byte integer
#define NC_VLEN
vlen (variable-length) types
#define NC_NAT
Not A Type.
#define NC_DOUBLE
double precision floating point number
#define NC_UBYTE
unsigned 1 byte int
#define NC_FLOAT
single precision floating point number
#define NC_ENOMEM
Memory allocation (malloc) failure.
#define EXTERNL
Needed for DLL build.
#define NC_COMPOUND
compound types
#define NC_SHORT
signed 2 byte integer
#define NC_ENUM
enum types
#define NC_INT64
signed 8-byte int
#define NC_UINT64
unsigned 8-byte int
#define NC_EINVAL
Invalid Argument.
#define NC_MAX_NAME
Maximum for classic library.
#define NC_NOERR
No Error.
#define NC_USHORT
unsigned 2-byte int
#define NC_OPAQUE
opaque types
#define NC_CHAR
ISO/ASCII character.
int nc_type
The nc_type type is just an int.
This is the type of arrays of vlens.