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"};
61 LOG((2,
"nc_inq_typeids: ncid 0x%x", ncid));
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;
103 LOG((2,
"nc_inq_atomic_type: typeid %d", typeid1));
105 if (typeid1 >= NUM_ATOMIC_TYPES)
110 *size = nc4_atomic_size[typeid1];
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++) {
137 if(sizep) *sizep = nc4_atomic_size[i];
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)
174 *size = nc4_atomic_size[typeid1];
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)
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));
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)
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;
299 size_t *offsetp,
nc_type *field_typeidp,
int *ndimsp,
303 NC_TYPE_INFO_T *type;
304 NC_FIELD_INFO_T *field;
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];
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));
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;
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));
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);
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));
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);
554 NC_GRP_INFO_T *grptwo;
556 NC_TYPE_INFO_T *type = NULL;
561 for (i = 0; i < NUM_ATOMIC_TYPES; i++)
577 if (name[0] !=
'/' && strstr(name,
"/"))
581 if (!(norm_name = (
char*)malloc(strlen(name) + 1)))
588 for (grptwo = grp; grptwo; grptwo = grptwo->parent) {
589 type = (NC_TYPE_INFO_T*)ncindexlookup(grptwo->type,norm_name);
593 *typeidp = type->hdr.id;
603 *typeidp = type->hdr.id;
631 LOG((4,
"%s xtype: %d", __func__, xtype));
671 NC_TYPE_INFO_T *type;
679 *type_class = type->nc_type_class;