14 #include "nc4internal.h"
15 #include "nc4dispatch.h"
18 EXTERNL int NCD4_get_substrate(
int ncid);
23 #define NC_CHAR_LEN sizeof(char)
24 #define NC_STRING_LEN sizeof(char *)
26 #define NC_SHORT_LEN 2
28 #define NC_FLOAT_LEN 4
29 #define NC_DOUBLE_LEN 8
30 #define NC_INT64_LEN 8
33 const char* nc4_atomic_name[NUM_ATOMIC_TYPES] = {
"none",
"byte",
"char",
34 "short",
"int",
"float",
37 "int64",
"uint64",
"string"};
38 static const int nc4_atomic_size[NUM_ATOMIC_TYPES] = {0, NC_BYTE_LEN, NC_CHAR_LEN, NC_SHORT_LEN,
39 NC_INT_LEN, NC_FLOAT_LEN, NC_DOUBLE_LEN,
40 NC_BYTE_LEN, NC_SHORT_LEN, NC_INT_LEN, NC_INT64_LEN,
41 NC_INT64_LEN, NC_STRING_LEN};
57 NC4_inq_typeids(
int ncid,
int *ntypes,
int *typeids)
65 LOG((2,
"nc_inq_typeids: ncid 0x%x", ncid));
68 if ((retval = nc4_find_grp_h5(ncid, &grp, &h5)))
75 for(i=0;i<ncindexsize(grp->type);i++)
77 if((type = (NC_TYPE_INFO_T*)ncindexith(grp->type,i)) == NULL)
continue;
79 typeids[num] = type->hdr.id;
105 NC4_inq_atomic_type(
nc_type typeid1,
char *name,
size_t *size)
107 LOG((2,
"nc_inq_atomic_type: typeid %d", typeid1));
109 if (typeid1 >= NUM_ATOMIC_TYPES)
112 strcpy(name, nc4_atomic_name[typeid1]);
114 *size = nc4_atomic_size[typeid1];
130 NC4_lookup_atomic_type(
const char *name,
nc_type* idp,
size_t *sizep)
134 LOG((2,
"nc_lookup_atomic_type: name %s ", name));
136 if (name == NULL || strlen(name) == 0)
138 for(i=0;i<NUM_ATOMIC_TYPES;i++) {
139 if(strcasecmp(name,nc4_atomic_name[i])==0) {
141 if(sizep) *sizep = nc4_atomic_size[i];
163 NC4_inq_type(
int ncid,
nc_type typeid1,
char *name,
size_t *size)
166 NC_TYPE_INFO_T *type;
170 LOG((2,
"nc_inq_type: ncid 0x%x typeid %d", ncid, typeid1));
173 if (typeid1 < NUM_ATOMIC_TYPES)
176 strcpy(name, nc4_atomic_name[typeid1]);
178 *size = nc4_atomic_size[typeid1];
183 if ((retval = nc4_find_nc4_grp(ncid, &grp)))
187 if (!(type = nclistget(grp->nc4_info->alltypes, typeid1)))
191 strcpy(name, type->hdr.name);
195 if (type->nc_type_class ==
NC_VLEN)
197 else if (type->nc_type_class ==
NC_STRING)
198 *size = NC_STRING_LEN;
223 NC4_inq_user_type(
int ncid,
nc_type typeid1,
char *name,
size_t *size,
224 nc_type *base_nc_typep,
size_t *nfieldsp,
int *classp)
227 NC_TYPE_INFO_T *type;
230 LOG((2,
"nc_inq_user_type: ncid 0x%x typeid %d", ncid, typeid1));
233 if ((retval = nc4_find_nc4_grp(ncid, &grp)))
237 if (!(type = nclistget(grp->nc4_info->alltypes, typeid1)))
244 *nfieldsp = nclistlength(type->u.c.field);
245 else if (type->nc_type_class ==
NC_ENUM)
246 *nfieldsp = nclistlength(type->u.e.enum_member);
254 if (type->nc_type_class ==
NC_VLEN)
256 else if (type->nc_type_class ==
NC_STRING)
257 *size = NC_STRING_LEN;
262 strcpy(name, type->hdr.name);
268 if (type->nc_type_class ==
NC_ENUM)
269 *base_nc_typep = type->u.e.base_nc_typeid;
270 else if (type->nc_type_class ==
NC_VLEN)
271 *base_nc_typep = type->u.v.base_nc_typeid;
279 *classp = type->nc_type_class;
302 NC4_inq_compound_field(
int ncid,
nc_type typeid1,
int fieldid,
char *name,
303 size_t *offsetp,
nc_type *field_typeidp,
int *ndimsp,
307 NC_TYPE_INFO_T *type;
308 NC_FIELD_INFO_T *field;
312 if ((retval = nc4_find_nc4_grp(ncid, &grp)))
316 if (!(type = nclistget(grp->nc4_info->alltypes, typeid1)))
320 if (!(field = nclistget(type->u.c.field,fieldid)))
324 strcpy(name, field->hdr.name);
326 *offsetp = field->offset;
328 *field_typeidp = field->nc_typeid;
330 *ndimsp = field->ndims;
332 for (d = 0; d < field->ndims; d++)
333 dim_sizesp[d] = field->dim_size[d];
353 NC4_inq_compound_fieldindex(
int ncid,
nc_type typeid1,
const char *name,
int *fieldidp)
356 NC_TYPE_INFO_T *type;
357 NC_FIELD_INFO_T *field;
362 LOG((2,
"nc_inq_compound_fieldindex: ncid 0x%x typeid %d name %s",
363 ncid, typeid1, name));
366 if ((retval = nc4_find_grp_h5(ncid, NULL, &h5)))
370 if ((retval = nc4_find_type(h5, typeid1, &type)))
378 if ((retval = nc4_normalize_name(name, norm_name)))
382 for (i = 0; i < nclistlength(type->u.c.field); i++)
384 field = nclistget(type->u.c.field, i);
386 if (!strcmp(field->hdr.name, norm_name))
395 *fieldidp = field->hdr.id;
416 NC4_inq_enum_ident(
int ncid,
nc_type xtype,
long long value,
char *identifier)
419 NC_TYPE_INFO_T *type;
420 NC_ENUM_MEMBER_INFO_T *enum_member;
426 LOG((3,
"nc_inq_enum_ident: xtype %d value %d\n", xtype, value));
429 if ((retval = nc4_find_nc4_grp(ncid, &grp)))
433 if (!(type = nclistget(grp->nc4_info->alltypes, xtype)))
437 if (type->nc_type_class !=
NC_ENUM)
441 for (found = 0, i = 0; i < nclistlength(type->u.e.enum_member); i++)
443 enum_member = nclistget(type->u.e.enum_member, i);
445 switch (type->u.e.base_nc_typeid)
448 ll_val = *(
char *)enum_member->value;
451 ll_val = *(
unsigned char *)enum_member->value;
454 ll_val = *(
short *)enum_member->value;
457 ll_val = *(
unsigned short *)enum_member->value;
460 ll_val = *(
int *)enum_member->value;
463 ll_val = *(
unsigned int *)enum_member->value;
467 ll_val = *(
long long *)enum_member->value;
472 LOG((4,
"ll_val=%d", ll_val));
476 strcpy(identifier, enum_member->name);
485 strcpy(identifier, NC_UNDEFINED_ENUM_IDENT);
510 NC4_inq_enum_member(
int ncid,
nc_type typeid1,
int idx,
char *identifier,
514 NC_TYPE_INFO_T *type;
515 NC_ENUM_MEMBER_INFO_T *enum_member;
518 LOG((2,
"nc_inq_enum_member: ncid 0x%x typeid %d", ncid, typeid1));
521 if ((retval = nc4_find_nc4_grp(ncid, &grp)))
525 if (!(type = nclistget(grp->nc4_info->alltypes, typeid1)))
529 if (type->nc_type_class !=
NC_ENUM)
533 if (!(enum_member = nclistget(type->u.e.enum_member, idx)))
538 strcpy(identifier, enum_member->name);
540 memcpy(value, enum_member->value, type->size);
560 NC4_inq_typeid(
int ncid,
const char *name,
nc_type *typeidp)
563 NC_GRP_INFO_T *grptwo;
565 NC_TYPE_INFO_T *type = NULL;
566 char *norm_name = NULL;
570 for (i = 0; i < NUM_ATOMIC_TYPES; i++)
571 if (!strcmp(name, nc4_atomic_name[i]))
579 if ((retval = nc4_find_grp_h5(ncid, &grp, &h5)))
586 if (name[0] !=
'/' && strstr(name,
"/"))
590 if (!(norm_name = (
char*)malloc(strlen(name) + 1)))
592 if ((retval = nc4_normalize_name(name, norm_name)))
598 int rootncid = (grp->nc4_info->root_grp->hdr.id | grp->nc4_info->controller->ext_ncid);
600 char* lastname = strrchr(norm_name,
'/');
601 if(lastname == norm_name)
604 if((retval = NC4_inq_grp_full_ncid(rootncid,norm_name,&parent)))
607 if((retval=nc4_find_nc4_grp(parent,&grp)))
610 type = (NC_TYPE_INFO_T*)ncindexlookup(grp->type,lastname);
617 for (grptwo = grp; grptwo; grptwo = grptwo->parent) {
618 type = (NC_TYPE_INFO_T*)ncindexlookup(grptwo->type,norm_name);
622 *typeidp = type->hdr.id;
630 if ((type = nc4_rec_find_named_type(grp->nc4_info->root_grp, norm_name)))
632 *typeidp = type->hdr.id;
656 nc4_get_typeclass(
const NC_FILE_INFO_T *h5,
nc_type xtype,
int *type_class)
660 LOG((4,
"%s xtype: %d", __func__, xtype));
700 NC_TYPE_INFO_T *type;
703 if ((retval = nc4_find_type(h5, xtype, &type)))
708 *type_class = type->nc_type_class;
727 NC4_inq_type_fixed_size(
int ncid,
nc_type xtype,
int* fixedsizep)
733 if(xtype <
NC_STRING) {f = 1;
goto done;}
734 if(xtype ==
NC_STRING) {f = 0;
goto done;}
738 if((stat =
nc_inq_user_type(ncid,xtype,NULL,NULL,NULL,NULL,&xclass)))
goto done;
743 NC_FILE_INFO_T* h5 = NULL;
744 NC_TYPE_INFO_T* typ = NULL;
748 if ((stat = NC_check_id(ncid, &nc)))
goto done;
749 xformat = nc->dispatch->model;
751 ncid = NCD4_get_substrate(ncid);
754 if ((stat = nc4_find_grp_h5(ncid, NULL, &h5)))
756 if((stat = nc4_find_type(h5,xtype,&typ)))
goto done;
757 f = !typ->u.c.varsized;
763 if(fixedsizep) *fixedsizep = f;
EXTERNL int nc_inq_user_type(int ncid, nc_type xtype, char *name, size_t *size, nc_type *base_nc_typep, size_t *nfieldsp, int *classp)
Learn about a user defined type.
#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_FORMATX_DAP4
Extended format specifier returned by nc_inq_format_extended() Added in version 4....
#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.