14#include "nc4internal.h"
15#include "nc4dispatch.h"
18EXTERNL int NCD4_get_substrate(
int ncid);
23#define NC_CHAR_LEN sizeof(char)
24#define NC_STRING_LEN sizeof(char *)
29#define NC_DOUBLE_LEN 8
33const char* nc4_atomic_name[NUM_ATOMIC_TYPES] = {
"none",
"byte",
"char",
34 "short",
"int",
"float",
37 "int64",
"uint64",
"string"};
38static 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};
57NC4_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;
105NC4_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];
130NC4_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];
163NC4_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;
223NC4_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;
302NC4_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];
353NC4_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;
415NC4_inq_enum_ident(
int ncid,
nc_type xtype,
long long value,
char *identifier)
418 NC_TYPE_INFO_T *type;
419 NC_ENUM_MEMBER_INFO_T *enum_member;
425 LOG((3,
"nc_inq_enum_ident: xtype %d value %d\n", xtype, value));
428 if ((retval = nc4_find_nc4_grp(ncid, &grp)))
432 if (!(type = nclistget(grp->nc4_info->alltypes, xtype)))
436 if (type->nc_type_class !=
NC_ENUM)
440 for (found = 0, i = 0; i < nclistlength(type->u.e.enum_member); i++)
442 enum_member = nclistget(type->u.e.enum_member, i);
444 switch (type->u.e.base_nc_typeid)
447 ll_val = *(
char *)enum_member->value;
450 ll_val = *(
unsigned char *)enum_member->value;
453 ll_val = *(
short *)enum_member->value;
456 ll_val = *(
unsigned short *)enum_member->value;
459 ll_val = *(
int *)enum_member->value;
462 ll_val = *(
unsigned int *)enum_member->value;
466 ll_val = *(
long long *)enum_member->value;
471 LOG((4,
"ll_val=%d", ll_val));
475 strcpy(identifier, enum_member->name);
505NC4_inq_enum_member(
int ncid,
nc_type typeid1,
int idx,
char *identifier,
509 NC_TYPE_INFO_T *type;
510 NC_ENUM_MEMBER_INFO_T *enum_member;
513 LOG((2,
"nc_inq_enum_member: ncid 0x%x typeid %d", ncid, typeid1));
516 if ((retval = nc4_find_nc4_grp(ncid, &grp)))
520 if (!(type = nclistget(grp->nc4_info->alltypes, typeid1)))
524 if (type->nc_type_class !=
NC_ENUM)
528 if (!(enum_member = nclistget(type->u.e.enum_member, idx)))
533 strcpy(identifier, enum_member->name);
535 memcpy(value, enum_member->value, type->size);
555NC4_inq_typeid(
int ncid,
const char *name,
nc_type *typeidp)
558 NC_GRP_INFO_T *grptwo;
560 NC_TYPE_INFO_T *type = NULL;
561 char *norm_name = NULL;
565 for (i = 0; i < NUM_ATOMIC_TYPES; i++)
566 if (!strcmp(name, nc4_atomic_name[i]))
574 if ((retval = nc4_find_grp_h5(ncid, &grp, &h5)))
581 if (name[0] !=
'/' && strstr(name,
"/"))
585 if (!(norm_name = (
char*)malloc(strlen(name) + 1)))
587 if ((retval = nc4_normalize_name(name, norm_name)))
593 int rootncid = (grp->nc4_info->root_grp->hdr.id | grp->nc4_info->controller->ext_ncid);
595 char* lastname = strrchr(norm_name,
'/');
596 if(lastname == norm_name)
599 if((retval = NC4_inq_grp_full_ncid(rootncid,norm_name,&parent)))
602 if((retval=nc4_find_nc4_grp(parent,&grp)))
605 type = (NC_TYPE_INFO_T*)ncindexlookup(grp->type,lastname);
612 for (grptwo = grp; grptwo; grptwo = grptwo->parent) {
613 type = (NC_TYPE_INFO_T*)ncindexlookup(grptwo->type,norm_name);
617 *typeidp = type->hdr.id;
625 if ((type = nc4_rec_find_named_type(grp->nc4_info->root_grp, norm_name)))
627 *typeidp = type->hdr.id;
651nc4_get_typeclass(
const NC_FILE_INFO_T *h5,
nc_type xtype,
int *type_class)
655 LOG((4,
"%s xtype: %d", __func__, xtype));
695 NC_TYPE_INFO_T *type;
698 if ((retval = nc4_find_type(h5, xtype, &type)))
703 *type_class = type->nc_type_class;
722NC4_inq_type_fixed_size(
int ncid,
nc_type xtype,
int* fixedsizep)
728 if(xtype <
NC_STRING) {f = 1;
goto done;}
729 if(xtype ==
NC_STRING) {f = 0;
goto done;}
733 if((stat =
nc_inq_user_type(ncid,xtype,NULL,NULL,NULL,NULL,&xclass)))
goto done;
738 NC_FILE_INFO_T* h5 = NULL;
739 NC_TYPE_INFO_T* typ = NULL;
743 if ((stat = NC_check_id(ncid, &nc)))
goto done;
744 xformat = nc->dispatch->model;
746 ncid = NCD4_get_substrate(ncid);
749 if ((stat = nc4_find_grp_h5(ncid, NULL, &h5)))
751 if((stat = nc4_find_type(h5,xtype,&typ)))
goto done;
752 f = !typ->u.c.varsized;
758 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.