14 #include "nc4internal.h"
15 #include "nc4dispatch.h"
19 #define NC_CHAR_LEN sizeof(char)
20 #define NC_STRING_LEN sizeof(char *)
22 #define NC_SHORT_LEN 2
24 #define NC_FLOAT_LEN 4
25 #define NC_DOUBLE_LEN 8
26 #define NC_INT64_LEN 8
29 const char* nc4_atomic_name[NUM_ATOMIC_TYPES] = {"none", "byte", "char",
30 "short",
"int",
"float",
33 "int64",
"uint64",
"string"};
34 static const int nc4_atomic_size[NUM_ATOMIC_TYPES] = {0, NC_BYTE_LEN, NC_CHAR_LEN, NC_SHORT_LEN,
35 NC_INT_LEN, NC_FLOAT_LEN, NC_DOUBLE_LEN,
36 NC_BYTE_LEN, NC_SHORT_LEN, NC_INT_LEN, NC_INT64_LEN,
37 NC_INT64_LEN, NC_STRING_LEN};
53 NC4_inq_typeids(
int ncid,
int *ntypes,
int *typeids)
61 LOG((2,
"nc_inq_typeids: ncid 0x%x", ncid));
64 if ((retval = nc4_find_grp_h5(ncid, &grp, &h5)))
71 for(i=0;i<ncindexsize(grp->type);i++)
73 if((type = (NC_TYPE_INFO_T*)ncindexith(grp->type,i)) == NULL)
continue;
75 typeids[num] = type->hdr.id;
101 NC4_inq_atomic_type(
nc_type typeid1,
char *name,
size_t *size)
103 LOG((2,
"nc_inq_atomic_type: typeid %d", typeid1));
105 if (typeid1 >= NUM_ATOMIC_TYPES)
108 strcpy(name, nc4_atomic_name[typeid1]);
110 *size = nc4_atomic_size[typeid1];
126 NC4_lookup_atomic_type(
const char *name,
nc_type* idp,
size_t *sizep)
130 LOG((2,
"nc_lookup_atomic_type: name %s ", name));
132 if (name == NULL || strlen(name) == 0)
134 for(i=0;i<NUM_ATOMIC_TYPES;i++) {
135 if(strcasecmp(name,nc4_atomic_name[i])==0) {
137 if(sizep) *sizep = nc4_atomic_size[i];
159 NC4_inq_type(
int ncid,
nc_type typeid1,
char *name,
size_t *size)
162 NC_TYPE_INFO_T *type;
166 LOG((2,
"nc_inq_type: ncid 0x%x typeid %d", ncid, typeid1));
169 if (typeid1 < NUM_ATOMIC_TYPES)
172 strcpy(name, nc4_atomic_name[typeid1]);
174 *size = nc4_atomic_size[typeid1];
179 if ((retval = nc4_find_nc4_grp(ncid, &grp)))
183 if (!(type = nclistget(grp->nc4_info->alltypes, typeid1)))
187 strcpy(name, type->hdr.name);
191 if (type->nc_type_class ==
NC_VLEN)
193 else if (type->nc_type_class ==
NC_STRING)
194 *size = NC_STRING_LEN;
219 NC4_inq_user_type(
int ncid,
nc_type typeid1,
char *name,
size_t *size,
220 nc_type *base_nc_typep,
size_t *nfieldsp,
int *classp)
223 NC_TYPE_INFO_T *type;
226 LOG((2,
"nc_inq_user_type: ncid 0x%x typeid %d", ncid, typeid1));
229 if ((retval = nc4_find_nc4_grp(ncid, &grp)))
233 if (!(type = nclistget(grp->nc4_info->alltypes, typeid1)))
240 *nfieldsp = nclistlength(type->u.c.field);
241 else if (type->nc_type_class ==
NC_ENUM)
242 *nfieldsp = nclistlength(type->u.e.enum_member);
250 if (type->nc_type_class ==
NC_VLEN)
252 else if (type->nc_type_class ==
NC_STRING)
253 *size = NC_STRING_LEN;
258 strcpy(name, type->hdr.name);
264 if (type->nc_type_class ==
NC_ENUM)
265 *base_nc_typep = type->u.e.base_nc_typeid;
266 else if (type->nc_type_class ==
NC_VLEN)
267 *base_nc_typep = type->u.v.base_nc_typeid;
275 *classp = type->nc_type_class;
298 NC4_inq_compound_field(
int ncid,
nc_type typeid1,
int fieldid,
char *name,
299 size_t *offsetp,
nc_type *field_typeidp,
int *ndimsp,
303 NC_TYPE_INFO_T *type;
304 NC_FIELD_INFO_T *field;
308 if ((retval = nc4_find_nc4_grp(ncid, &grp)))
312 if (!(type = nclistget(grp->nc4_info->alltypes, typeid1)))
316 if (!(field = nclistget(type->u.c.field,fieldid)))
320 strcpy(name, field->hdr.name);
322 *offsetp = field->offset;
324 *field_typeidp = field->nc_typeid;
326 *ndimsp = field->ndims;
328 for (d = 0; d < field->ndims; d++)
329 dim_sizesp[d] = field->dim_size[d];
349 NC4_inq_compound_fieldindex(
int ncid,
nc_type typeid1,
const char *name,
int *fieldidp)
352 NC_TYPE_INFO_T *type;
353 NC_FIELD_INFO_T *field;
358 LOG((2,
"nc_inq_compound_fieldindex: ncid 0x%x typeid %d name %s",
359 ncid, typeid1, name));
362 if ((retval = nc4_find_grp_h5(ncid, NULL, &h5)))
366 if ((retval = nc4_find_type(h5, typeid1, &type)))
374 if ((retval = nc4_normalize_name(name, norm_name)))
378 for (i = 0; i < nclistlength(type->u.c.field); i++)
380 field = nclistget(type->u.c.field, i);
382 if (!strcmp(field->hdr.name, norm_name))
391 *fieldidp = field->hdr.id;
411 NC4_inq_enum_ident(
int ncid,
nc_type xtype,
long long value,
char *identifier)
414 NC_TYPE_INFO_T *type;
415 NC_ENUM_MEMBER_INFO_T *enum_member;
421 LOG((3,
"nc_inq_enum_ident: xtype %d value %d\n", xtype, value));
424 if ((retval = nc4_find_nc4_grp(ncid, &grp)))
428 if (!(type = nclistget(grp->nc4_info->alltypes, xtype)))
432 if (type->nc_type_class !=
NC_ENUM)
436 for (found = 0, i = 0; i < nclistlength(type->u.e.enum_member); i++)
438 enum_member = nclistget(type->u.e.enum_member, i);
440 switch (type->u.e.base_nc_typeid)
443 ll_val = *(
char *)enum_member->value;
446 ll_val = *(
unsigned char *)enum_member->value;
449 ll_val = *(
short *)enum_member->value;
452 ll_val = *(
unsigned short *)enum_member->value;
455 ll_val = *(
int *)enum_member->value;
458 ll_val = *(
unsigned int *)enum_member->value;
462 ll_val = *(
long long *)enum_member->value;
467 LOG((4,
"ll_val=%d", ll_val));
471 strcpy(identifier, enum_member->name);
501 NC4_inq_enum_member(
int ncid,
nc_type typeid1,
int idx,
char *identifier,
505 NC_TYPE_INFO_T *type;
506 NC_ENUM_MEMBER_INFO_T *enum_member;
509 LOG((2,
"nc_inq_enum_member: ncid 0x%x typeid %d", ncid, typeid1));
512 if ((retval = nc4_find_nc4_grp(ncid, &grp)))
516 if (!(type = nclistget(grp->nc4_info->alltypes, typeid1)))
520 if (type->nc_type_class !=
NC_ENUM)
524 if (!(enum_member = nclistget(type->u.e.enum_member, idx)))
529 strcpy(identifier, enum_member->name);
531 memcpy(value, enum_member->value, type->size);
551 NC4_inq_typeid(
int ncid,
const char *name,
nc_type *typeidp)
554 NC_GRP_INFO_T *grptwo;
556 NC_TYPE_INFO_T *type = NULL;
557 char *norm_name = NULL;
561 for (i = 0; i < NUM_ATOMIC_TYPES; i++)
562 if (!strcmp(name, nc4_atomic_name[i]))
570 if ((retval = nc4_find_grp_h5(ncid, &grp, &h5)))
577 if (name[0] !=
'/' && strstr(name,
"/"))
581 if (!(norm_name = (
char*)malloc(strlen(name) + 1)))
583 if ((retval = nc4_normalize_name(name, norm_name)))
589 int rootncid = (grp->nc4_info->root_grp->hdr.id | grp->nc4_info->controller->ext_ncid);
591 char* lastname = strrchr(norm_name,
'/');
592 if(lastname == norm_name)
595 if((retval = NC4_inq_grp_full_ncid(rootncid,norm_name,&parent)))
598 if((retval=nc4_find_nc4_grp(parent,&grp)))
601 type = (NC_TYPE_INFO_T*)ncindexlookup(grp->type,lastname);
608 for (grptwo = grp; grptwo; grptwo = grptwo->parent) {
609 type = (NC_TYPE_INFO_T*)ncindexlookup(grptwo->type,norm_name);
613 *typeidp = type->hdr.id;
621 if ((type = nc4_rec_find_named_type(grp->nc4_info->root_grp, norm_name)))
623 *typeidp = type->hdr.id;
647 nc4_get_typeclass(
const NC_FILE_INFO_T *h5,
nc_type xtype,
int *type_class)
651 LOG((4,
"%s xtype: %d", __func__, xtype));
691 NC_TYPE_INFO_T *type;
694 if ((retval = nc4_find_type(h5, xtype, &type)))
699 *type_class = type->nc_type_class;