21 #include "netcdf_meta.h"
22 #include "nc4internal.h"
24 #include "ncdispatch.h"
39 static const NC_reservedatt NC_reserved[] = {
40 {NC_ATT_CLASS, READONLYFLAG|HIDDENATTRFLAG},
41 {NC_ATT_DIMENSION_LIST, READONLYFLAG|HIDDENATTRFLAG},
42 {NC_ATT_NAME, READONLYFLAG|HIDDENATTRFLAG},
43 {NC_ATT_REFERENCE_LIST, READONLYFLAG|HIDDENATTRFLAG},
44 {NC_XARRAY_DIMS, READONLYFLAG|NAMEONLYFLAG|HIDDENATTRFLAG},
45 {NC_ATT_CODECS, VARFLAG|READONLYFLAG|NAMEONLYFLAG},
46 {NC_ATT_FORMAT, READONLYFLAG},
47 {ISNETCDF4ATT, READONLYFLAG|NAMEONLYFLAG},
48 {NCPROPS,READONLYFLAG|NAMEONLYFLAG|HIDDENATTRFLAG},
49 {NC_NCZARR_ATTR_UC, READONLYFLAG|HIDDENATTRFLAG},
50 {NC_ATT_COORDINATES, READONLYFLAG|HIDDENATTRFLAG},
51 {NC_ATT_DIMID_NAME, READONLYFLAG|HIDDENATTRFLAG},
52 {SUPERBLOCKATT, READONLYFLAG|NAMEONLYFLAG},
53 {NC_ATT_NC3_STRICT_NAME, READONLYFLAG},
54 {NC_ATT_NC3_STRICT_NAME, READONLYFLAG},
55 {NC_NCZARR_ATTR, READONLYFLAG|HIDDENATTRFLAG},
57 #define NRESERVED (sizeof(NC_reserved) / sizeof(NC_reservedatt))
59 static int NC4_move_in_NCList(NC* nc,
int new_id);
65 int nc_log_level = NC_TURN_OFF_LOGGING;
68 FILE *LOG_FILE = NULL;
85 nc_log(
int severity,
const char *fmt, ...)
93 if (severity > nc_log_level)
105 if ((mpierr = MPI_Initialized(&mpi_initialized)))
118 fprintf(f,
"ERROR: ");
119 for (t = 0; t < severity; t++)
124 vfprintf(f, fmt, argp);
146 nc4_check_name(
const char *name,
char *norm_name)
160 if ((retval = NC_check_name(name)))
164 if ((retval = nc_utf8_normalize((
const unsigned char *)name,
165 (
unsigned char **)&temp)))
176 strcpy(norm_name, temp);
203 nc4_file_list_add(
int ncid,
const char *path,
int mode,
void **dispatchdata)
209 if ((ret = NC_check_id(ncid, &nc)))
214 if ((ret = nc4_nc4f_list_add(nc, path, mode)))
220 *dispatchdata = nc->dispatchdata;
239 nc4_file_change_ncid(
int ncid,
unsigned short new_ncid_index)
244 LOG((2,
"%s: ncid %d new_ncid_index %d", __func__, ncid, new_ncid_index));
247 if ((ret = NC_check_id(ncid, &nc)))
252 LOG((3,
"moving nc->ext_ncid %d nc->ext_ncid >> ID_SHIFT %d",
253 nc->ext_ncid, nc->ext_ncid >> ID_SHIFT));
254 if (NC4_move_in_NCList(nc, new_ncid_index))
256 LOG((3,
"moved to new_ncid_index %d new nc->ext_ncid %d", new_ncid_index,
282 nc4_file_list_get(
int ncid,
char **path,
int *mode,
void **dispatchdata)
288 if ((ret = NC_check_id(ncid, &nc)))
301 *dispatchdata = nc->dispatchdata;
321 nc4_nc4f_list_add(NC *nc,
const char *path,
int mode)
326 assert(nc && !NC4_DATA(nc) && path);
330 if (!(h5 = calloc(1,
sizeof(NC_FILE_INFO_T))))
332 nc->dispatchdata = h5;
335 h5->hdr.sort = NCFIL;
336 h5->hdr.name = strdup(path);
337 h5->hdr.id = nc->ext_ncid;
340 h5->cmode = mode | NC_INDEF;
344 h5->next_typeid = NC_FIRSTUSERTYPEID;
347 h5->alldims = nclistnew();
348 h5->alltypes = nclistnew();
349 h5->allgroups = nclistnew();
354 if ((retval = nc4_grp_list_add(h5, NULL, NC_GROUP_NAME, &h5->root_grp)))
373 nc4_find_nc4_grp(
int ncid, NC_GRP_INFO_T **grp)
375 return nc4_find_nc_grp_h5(ncid, NULL, grp, NULL);
394 nc4_find_grp_h5(
int ncid, NC_GRP_INFO_T **grp, NC_FILE_INFO_T **h5)
396 return nc4_find_nc_grp_h5(ncid, NULL, grp, h5);
414 nc4_find_nc_grp_h5(
int ncid, NC **nc, NC_GRP_INFO_T **grp, NC_FILE_INFO_T **h5)
416 NC_GRP_INFO_T *my_grp = NULL;
417 NC_FILE_INFO_T *my_h5 = NULL;
423 if ((retval = NC_check_id(ncid, &my_nc)))
425 my_h5 = my_nc->dispatchdata;
426 assert(my_h5 && my_h5->root_grp);
429 index = (ncid & GRP_ID_MASK);
430 if (!(my_grp = nclistget(my_h5->allgroups,index)))
460 nc4_find_grp_h5_var(
int ncid,
int varid, NC_FILE_INFO_T **h5, NC_GRP_INFO_T **grp,
463 NC_FILE_INFO_T *my_h5;
464 NC_GRP_INFO_T *my_grp;
465 NC_VAR_INFO_T *my_var;
469 if ((retval = nc4_find_grp_h5(ncid, &my_grp, &my_h5)))
471 assert(my_grp && my_h5);
474 if (!(my_var = (NC_VAR_INFO_T *)ncindexith(my_grp->vars, varid)))
476 assert(my_var && my_var->hdr.id == varid);
503 nc4_find_dim(NC_GRP_INFO_T *grp,
int dimid, NC_DIM_INFO_T **dim,
504 NC_GRP_INFO_T **dim_grp)
506 assert(grp && grp->nc4_info && dim);
507 LOG((4,
"%s: dimid %d", __func__, dimid));
510 if (!((*dim) = nclistget(grp->nc4_info->alldims, dimid)))
515 *dim_grp = (*dim)->container;
531 nc4_find_var(NC_GRP_INFO_T *grp,
const char *name, NC_VAR_INFO_T **var)
533 assert(grp && var && name);
536 *var = (NC_VAR_INFO_T*)ncindexlookup(grp->vars,name);
550 nc4_rec_find_named_type(NC_GRP_INFO_T *start_grp,
char *name)
553 NC_TYPE_INFO_T *type, *res;
559 type = (NC_TYPE_INFO_T*)ncindexlookup(start_grp->type,name);
564 for(i=0;i<ncindexsize(start_grp->children);i++) {
565 g = (NC_GRP_INFO_T*)ncindexith(start_grp->children,i);
566 if(g == NULL)
continue;
567 if ((res = nc4_rec_find_named_type(g, name)))
586 nc4_find_type(
const NC_FILE_INFO_T *h5,
nc_type typeid, NC_TYPE_INFO_T **type)
590 if (
typeid < 0 || !type)
600 if (!(*type = nclistget(h5->alltypes,
typeid)))
622 nc4_find_grp_att(NC_GRP_INFO_T *grp,
int varid,
const char *name,
int attnum,
626 NC_ATT_INFO_T *my_att;
627 NCindex *attlist = NULL;
629 assert(grp && grp->hdr.name && att);
631 LOG((4,
"%s: grp->name %s varid %d attnum %d", __func__, grp->hdr.name,
641 var = (NC_VAR_INFO_T*)ncindexith(grp->vars,varid);
651 my_att = (NC_ATT_INFO_T *)ncindexlookup(attlist, name);
653 my_att = (NC_ATT_INFO_T *)ncindexith(attlist, attnum);
679 nc4_find_nc_att(
int ncid,
int varid,
const char *name,
int attnum,
685 LOG((4,
"nc4_find_nc_att: ncid 0x%x varid %d name %s attnum %d",
686 ncid, varid, name, attnum));
689 if ((retval = nc4_find_grp_h5(ncid, &grp, NULL)))
693 return nc4_find_grp_att(grp, varid, name, attnum, att);
705 obj_track(NC_FILE_INFO_T* file, NC_OBJ* obj)
710 case NCDIM: list = file->alldims;
break;
711 case NCTYP: list = file->alltypes;
break;
712 case NCGRP: list = file->allgroups;
break;
717 nclistset(list,obj->id,obj);
735 nc4_var_list_add2(NC_GRP_INFO_T *grp,
const char *name, NC_VAR_INFO_T **var)
737 NC_VAR_INFO_T *new_var = NULL;
738 NCglobalstate* gs = NC_getglobalstate();
741 if (!(new_var = calloc(1,
sizeof(NC_VAR_INFO_T))))
743 new_var->hdr.sort = NCVAR;
744 new_var->container = grp;
747 new_var->chunkcache.size = gs->chunkcache.size;
748 new_var->chunkcache.nelems = gs->chunkcache.nelems;
749 new_var->chunkcache.preemption = gs->chunkcache.preemption;
752 new_var->hdr.id = ncindexsize(grp->vars);
753 if (!(new_var->hdr.name = strdup(name))) {
760 new_var->att = ncindexnew(0);
763 ncindexadd(grp->vars, (NC_OBJ *)new_var);
785 nc4_var_set_ndims(NC_VAR_INFO_T *var,
int ndims)
795 if (!(var->dim = calloc(ndims,
sizeof(NC_DIM_INFO_T *))))
797 if (!(var->dimids = calloc(ndims,
sizeof(
int))))
802 memset(var->dimids, -1, ndims *
sizeof(
int));
823 nc4_var_list_add(NC_GRP_INFO_T* grp,
const char* name,
int ndims,
828 if ((retval = nc4_var_list_add2(grp, name, var)))
830 if ((retval = nc4_var_set_ndims(*var, ndims)))
850 nc4_dim_list_add(NC_GRP_INFO_T *grp,
const char *name,
size_t len,
851 int assignedid, NC_DIM_INFO_T **dim)
853 NC_DIM_INFO_T *new_dim = NULL;
858 if (!(new_dim = calloc(1,
sizeof(NC_DIM_INFO_T))))
861 new_dim->hdr.sort = NCDIM;
865 new_dim->hdr.id = assignedid;
867 new_dim->hdr.id = grp->nc4_info->next_dimid++;
870 if (!(new_dim->hdr.name = strdup(name))) {
880 new_dim->unlimited = NC_TRUE;
883 new_dim->container = grp;
886 ncindexadd(grp->dim, (NC_OBJ *)new_dim);
887 obj_track(grp->nc4_info, (NC_OBJ *)new_dim);
909 nc4_att_list_add(NCindex *list,
const char *name, NC_ATT_INFO_T **att)
911 NC_ATT_INFO_T *new_att = NULL;
913 LOG((3,
"%s: name %s ", __func__, name));
915 if (!(new_att = calloc(1,
sizeof(NC_ATT_INFO_T))))
917 new_att->hdr.sort = NCATT;
920 new_att->hdr.id = ncindexsize(list);
921 if (!(new_att->hdr.name = strdup(name))) {
928 ncindexadd(list, (NC_OBJ *)new_att);
952 nc4_grp_list_add(NC_FILE_INFO_T *h5, NC_GRP_INFO_T *parent,
char *name,
955 NC_GRP_INFO_T *new_grp;
959 LOG((3,
"%s: name %s ", __func__, name));
962 if (!(new_grp = calloc(1,
sizeof(NC_GRP_INFO_T))))
966 new_grp->hdr.sort = NCGRP;
967 new_grp->nc4_info = h5;
968 new_grp->parent = parent;
971 new_grp->hdr.id = h5->next_nc_grpid++;
972 assert(parent || !new_grp->hdr.id);
975 if (!(new_grp->hdr.name = strdup(name)))
982 new_grp->children = ncindexnew(0);
983 new_grp->dim = ncindexnew(0);
984 new_grp->att = ncindexnew(0);
985 new_grp->type = ncindexnew(0);
986 new_grp->vars = ncindexnew(0);
990 ncindexadd(parent->children, (NC_OBJ *)new_grp);
991 obj_track(h5, (NC_OBJ *)new_grp);
1014 nc4_check_dup_name(NC_GRP_INFO_T *grp,
char *name)
1016 NC_TYPE_INFO_T *type;
1021 type = (NC_TYPE_INFO_T*)ncindexlookup(grp->type,name);
1026 g = (NC_GRP_INFO_T*)ncindexlookup(grp->children,name);
1031 var = (NC_VAR_INFO_T*)ncindexlookup(grp->vars,name);
1052 nc4_type_new(
size_t size,
const char *name,
int assignedid,
1053 NC_TYPE_INFO_T **type)
1055 NC_TYPE_INFO_T *new_type;
1057 LOG((4,
"%s: size %d name %s assignedid %d", __func__, size, name, assignedid));
1063 if (!(new_type = calloc(1,
sizeof(NC_TYPE_INFO_T))))
1065 new_type->hdr.sort = NCTYP;
1066 new_type->hdr.id = assignedid;
1069 new_type->size = size;
1070 if (!(new_type->hdr.name = strdup(name))) {
1095 nc4_type_list_add(NC_GRP_INFO_T *grp,
size_t size,
const char *name,
1096 NC_TYPE_INFO_T **type)
1098 NC_TYPE_INFO_T *new_type;
1102 assert(grp && name && type);
1103 LOG((4,
"%s: size %d name %s", __func__, size, name));
1106 if ((retval = nc4_type_new(size, name, grp->nc4_info->next_typeid,
1109 grp->nc4_info->next_typeid++;
1115 ncindexadd(grp->type, (NC_OBJ *)new_type);
1116 obj_track(grp->nc4_info,(NC_OBJ*)new_type);
1138 nc4_field_list_add(NC_TYPE_INFO_T *parent,
const char *name,
1139 size_t offset,
nc_type xtype,
int ndims,
1140 const int *dim_sizesp)
1142 NC_FIELD_INFO_T *field;
1149 if (!(field = calloc(1,
sizeof(NC_FIELD_INFO_T))))
1151 field->hdr.sort = NCFLD;
1154 if (!(field->hdr.name = strdup(name)))
1159 field->nc_typeid = xtype;
1160 field->offset = offset;
1161 field->ndims = ndims;
1165 if (!(field->dim_size = malloc(ndims *
sizeof(
int))))
1167 free(field->hdr.name);
1171 for (i = 0; i < ndims; i++)
1172 field->dim_size[i] = dim_sizesp[i];
1176 field->hdr.id = nclistlength(parent->u.c.field);
1177 nclistpush(parent->u.c.field,field);
1195 nc4_enum_member_add(NC_TYPE_INFO_T *parent,
size_t size,
1196 const char *name,
const void *value)
1198 NC_ENUM_MEMBER_INFO_T *member;
1201 assert(name && size > 0 && value);
1202 LOG((4,
"%s: size %d name %s", __func__, size, name));
1205 if (!(member = calloc(1,
sizeof(NC_ENUM_MEMBER_INFO_T))))
1207 if (!(member->value = malloc(size))) {
1211 if (!(member->name = strdup(name))) {
1212 free(member->value);
1218 memcpy(member->value, value, size);
1221 nclistpush(parent->u.e.enum_member,member);
1235 field_free(NC_FIELD_INFO_T *field)
1238 if (field->hdr.name)
1239 free(field->hdr.name);
1240 if (field->dim_size)
1241 free(field->dim_size);
1257 nc4_type_free(NC_TYPE_INFO_T *type)
1261 assert(type && type->rc && type->hdr.name);
1269 LOG((4,
"%s: deleting type %s", __func__, type->hdr.name));
1272 free(type->hdr.name);
1275 switch (type->nc_type_class)
1279 NC_FIELD_INFO_T *field;
1283 for(i=0;i<nclistlength(type->u.c.field);i++) {
1284 field = nclistget(type->u.c.field,i);
1287 nclistfree(type->u.c.field);
1293 NC_ENUM_MEMBER_INFO_T *enum_member;
1296 for(i=0;i<nclistlength(type->u.e.enum_member);i++) {
1297 enum_member = nclistget(type->u.e.enum_member,i);
1298 free(enum_member->value);
1299 free(enum_member->name);
1302 nclistfree(type->u.e.enum_member);
1326 nc4_att_free(NC_ATT_INFO_T *att)
1331 LOG((3,
"%s: name %s ", __func__, att->hdr.name));
1335 free(att->hdr.name);
1353 for (i = 0; i < att->len; i++)
1355 free(att->stdata[i]);
1363 for (i = 0; i < att->len; i++)
1370 NC_FILE_INFO_T* h5 = NULL;
1373 parent = att->container;
1374 if(parent->sort == NCVAR) parent = (NC_OBJ*)(((NC_VAR_INFO_T*)parent)->container);
1375 assert(parent->sort == NCGRP);
1376 h5 = ((NC_GRP_INFO_T*)parent)->nc4_info;
1378 if((stat =
nc_reclaim_data(h5->controller->ext_ncid,att->nc_typeid,att->data,att->len)))
goto done;
1399 var_free(NC_VAR_INFO_T *var)
1405 LOG((4,
"%s: deleting var %s", __func__, var->hdr.name));
1408 for (i = 0; i < ncindexsize(var->att); i++)
1409 if ((retval = nc4_att_free((NC_ATT_INFO_T *)ncindexith(var->att, i))))
1411 ncindexfree(var->att);
1414 if (var->chunksizes)
1415 free(var->chunksizes);
1418 free(var->alt_name);
1427 if (var->fill_value) {
1428 int ncid = var->container->nc4_info->controller->ext_ncid;
1429 int tid = var->type_info->hdr.id;
1430 if((retval = nc_reclaim_data_all(ncid, tid, var->fill_value, 1)))
return retval;
1431 var->fill_value = NULL;
1436 if ((retval = nc4_type_free(var->type_info)))
1441 free(var->hdr.name);
1459 nc4_var_list_del(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var)
1466 i = ncindexfind(grp->vars, (NC_OBJ *)var);
1468 ncindexidel(grp->vars, i);
1470 return var_free(var);
1482 dim_free(NC_DIM_INFO_T *dim)
1485 LOG((4,
"%s: deleting dim %s", __func__, dim->hdr.name));
1489 free(dim->hdr.name);
1505 nc4_dim_list_del(NC_GRP_INFO_T *grp, NC_DIM_INFO_T *dim)
1509 int pos = ncindexfind(grp->dim, (NC_OBJ *)dim);
1511 ncindexidel(grp->dim, pos);
1514 return dim_free(dim);
1527 nc4_rec_grp_del(NC_GRP_INFO_T *grp)
1533 LOG((3,
"%s: grp->name %s", __func__, grp->hdr.name));
1537 for (i = 0; i < ncindexsize(grp->children); i++)
1538 if ((retval = nc4_rec_grp_del((NC_GRP_INFO_T *)ncindexith(grp->children,
1541 ncindexfree(grp->children);
1544 for (i = 0; i < ncindexsize(grp->att); i++)
1545 if ((retval = nc4_att_free((NC_ATT_INFO_T *)ncindexith(grp->att, i))))
1547 ncindexfree(grp->att);
1550 for (i = 0; i < ncindexsize(grp->vars); i++) {
1551 NC_VAR_INFO_T* v = (NC_VAR_INFO_T *)ncindexith(grp->vars, i);
1552 if ((retval = var_free(v)))
1555 ncindexfree(grp->vars);
1558 for (i = 0; i < ncindexsize(grp->dim); i++)
1559 if ((retval = dim_free((NC_DIM_INFO_T *)ncindexith(grp->dim, i))))
1561 ncindexfree(grp->dim);
1564 for (i = 0; i < ncindexsize(grp->type); i++)
1565 if ((retval = nc4_type_free((NC_TYPE_INFO_T *)ncindexith(grp->type, i))))
1567 ncindexfree(grp->type);
1570 free(grp->hdr.name);
1588 nc4_rec_grp_del_att_data(NC_GRP_INFO_T *grp)
1594 LOG((3,
"%s: grp->name %s", __func__, grp->hdr.name));
1598 for (i = 0; i < ncindexsize(grp->children); i++)
1599 if ((retval = nc4_rec_grp_del_att_data((NC_GRP_INFO_T *)ncindexith(grp->children, i))))
1603 for (i = 0; i < ncindexsize(grp->att); i++) {
1604 NC_ATT_INFO_T * att = (NC_ATT_INFO_T*)ncindexith(grp->att, i);
1605 if((retval = nc_reclaim_data_all(grp->nc4_info->controller->ext_ncid,att->nc_typeid,att->data,att->len)))
1613 for (i = 0; i < ncindexsize(grp->vars); i++) {
1615 NC_VAR_INFO_T* v = (NC_VAR_INFO_T *)ncindexith(grp->vars, i);
1616 for(j=0;j<ncindexsize(v->att);j++) {
1617 NC_ATT_INFO_T* att = (NC_ATT_INFO_T*)ncindexith(v->att, j);
1618 if((retval = nc_reclaim_data_all(grp->nc4_info->controller->ext_ncid,att->nc_typeid,att->data,att->len)))
1640 nc4_att_list_del(NCindex *list, NC_ATT_INFO_T *att)
1642 assert(att && list);
1643 ncindexidel(list, ((NC_OBJ *)att)->
id);
1644 return nc4_att_free(att);
1661 nc4_file_list_del(
int ncid)
1667 if ((retval = nc4_find_grp_h5(ncid, NULL, &h5)))
1672 if ((retval = nc4_nc4f_list_del(h5)))
1688 nc4_nc4f_list_del(NC_FILE_INFO_T *h5)
1700 if ((retval = nc4_rec_grp_del_att_data(h5->root_grp)))
1705 if ((retval = nc4_rec_grp_del(h5->root_grp)))
1709 nclistfree(h5->alldims);
1710 nclistfree(h5->allgroups);
1711 nclistfree(h5->alltypes);
1714 nullfree(h5->hdr.name);
1734 nc4_normalize_name(
const char *name,
char *norm_name)
1737 int stat = nc_utf8_normalize((
const unsigned char *)name,(
unsigned char **)&temp_name);
1745 strcpy(norm_name, temp_name);
1750 #ifdef ENABLE_SET_LOG_LEVEL
1759 nc4_init_logging(
void)
1764 #if NC_HAS_PARALLEL4
1765 if (!LOG_FILE && nc_log_level >= 0)
1770 int mpi_initialized;
1773 if ((mpierr = MPI_Initialized(&mpi_initialized)))
1775 if (mpi_initialized)
1777 if ((mpierr = MPI_Comm_rank(MPI_COMM_WORLD, &my_rank)))
1782 sprintf(log_filename,
"nc4_log_%d.log", my_rank);
1785 if (!(LOG_FILE = fopen(log_filename,
"w")))
1801 nc4_finalize_logging(
void)
1804 #if NC_HAS_PARALLEL4
1828 nc_set_log_level(
int new_level)
1832 nc_log_level = new_level;
1834 #if NC_HAS_PARALLEL4
1843 nc4_finalize_logging();
1846 LOG((1,
"log_level changed to %d", nc_log_level));
1854 #define MAX_NESTS 10
1865 rec_print_metadata(NC_GRP_INFO_T *grp,
int tab_count)
1870 NC_TYPE_INFO_T *type;
1871 NC_FIELD_INFO_T *field;
1872 char tabs[MAX_NESTS+1] =
"";
1873 char temp_string[10];
1874 int t, retval, d, i;
1877 for (t = 0; t < tab_count && t < MAX_NESTS; t++)
1881 LOG((2,
"%s GROUP - %s nc_grpid: %d nvars: %d natts: %d",
1882 tabs, grp->hdr.name, grp->hdr.id, ncindexsize(grp->vars), ncindexsize(grp->att)));
1884 for (i = 0; i < ncindexsize(grp->att); i++)
1886 att = (NC_ATT_INFO_T *)ncindexith(grp->att, i);
1888 LOG((2,
"%s GROUP ATTRIBUTE - attnum: %d name: %s type: %d len: %d",
1889 tabs, att->hdr.id, att->hdr.name, att->nc_typeid, att->len));
1892 for (i = 0; i < ncindexsize(grp->dim); i++)
1894 dim = (NC_DIM_INFO_T *)ncindexith(grp->dim, i);
1896 LOG((2,
"%s DIMENSION - dimid: %d name: %s len: %d unlimited: %d",
1897 tabs, dim->hdr.id, dim->hdr.name, dim->len, dim->unlimited));
1900 for (i = 0; i < ncindexsize(grp->vars); i++)
1904 char *dims_string = NULL;
1906 var = (NC_VAR_INFO_T*)ncindexith(grp->vars,i);
1910 if (!(dims_string = malloc(
sizeof(
char) * var->ndims * 4)))
1912 strcpy(dims_string,
"");
1913 for (d = 0; d < var->ndims; d++)
1915 sprintf(temp_string,
" %d", var->dimids[d]);
1916 strcat(dims_string, temp_string);
1919 if (!var->meta_read)
1920 strcat(storage_str,
"unknown");
1922 strcat(storage_str,
"contiguous");
1924 strcat(storage_str,
"compact");
1926 strcat(storage_str,
"chunked");
1928 strcat(storage_str,
"virtual");
1930 strcat(storage_str,
"unknown");
1931 LOG((2,
"%s VARIABLE - varid: %d name: %s ndims: %d "
1932 "dimids:%s storage: %s", tabs, var->hdr.id, var->hdr.name,
1934 (dims_string ? dims_string :
" -"), storage_str));
1935 for (j = 0; j < ncindexsize(var->att); j++)
1937 att = (NC_ATT_INFO_T *)ncindexith(var->att, j);
1939 LOG((2,
"%s VAR ATTRIBUTE - attnum: %d name: %s type: %d len: %d",
1940 tabs, att->hdr.id, att->hdr.name, att->nc_typeid, att->len));
1946 for (i = 0; i < ncindexsize(grp->type); i++)
1948 type = (NC_TYPE_INFO_T*)ncindexith(grp->type, i);
1950 LOG((2,
"%s TYPE - nc_typeid: %d size: %d committed: %d name: %s",
1951 tabs, type->hdr.id, type->size, (
int)type->committed, type->hdr.name));
1956 LOG((3,
"compound type"));
1957 for (j = 0; j < nclistlength(type->u.c.field); j++)
1959 field = (NC_FIELD_INFO_T *)nclistget(type->u.c.field, j);
1960 LOG((4,
"field %s offset %d nctype %d ndims %d", field->hdr.name,
1961 field->offset, field->nc_typeid, field->ndims));
1964 else if (type->nc_type_class ==
NC_VLEN)
1966 LOG((3,
"VLEN type"));
1967 LOG((4,
"base_nc_type: %d", type->u.v.base_nc_typeid));
1969 else if (type->nc_type_class ==
NC_OPAQUE)
1970 LOG((3,
"Opaque type"));
1971 else if (type->nc_type_class ==
NC_ENUM)
1973 LOG((3,
"Enum type"));
1974 LOG((4,
"base_nc_type: %d", type->u.e.base_nc_typeid));
1978 LOG((0,
"Unknown class: %d", type->nc_type_class));
1984 for (i = 0; i < ncindexsize(grp->children); i++)
1985 if ((retval = rec_print_metadata((NC_GRP_INFO_T *)ncindexith(grp->children, i),
2003 log_metadata_nc(NC_FILE_INFO_T *h5)
2005 LOG((2,
"*** NetCDF-4 Internal Metadata: int_ncid 0x%x ext_ncid 0x%x",
2006 h5->root_grp->nc4_info->controller->int_ncid,
2007 h5->root_grp->nc4_info->controller->ext_ncid));
2010 LOG((2,
"This is a netCDF-3 file."));
2013 LOG((2,
"FILE - path: %s cmode: 0x%x parallel: %d redef: %d "
2014 "fill_mode: %d no_write: %d next_nc_grpid: %d", h5->root_grp->nc4_info->controller->path,
2015 h5->cmode, (
int)h5->parallel, (
int)h5->redef, h5->fill_mode, (
int)h5->no_write,
2016 h5->next_nc_grpid));
2017 if(nc_log_level >= 2)
2018 return rec_print_metadata(h5->root_grp, 0);
2036 NC4_show_metadata(
int ncid)
2041 int old_log_level = nc_log_level;
2044 if ((retval = nc4_find_grp_h5(ncid, NULL, &h5)))
2049 retval = log_metadata_nc(h5);
2050 nc_log_level = old_log_level;
2062 const NC_reservedatt*
2063 NC_findreserved(
const char* name)
2071 int m = (L + R) / 2;
2072 const NC_reservedatt* p = &NC_reserved[m];
2073 int cmp = strcmp(p->name,name);
2074 if(cmp == 0)
return p;
2084 NC4_move_in_NCList(NC* nc,
int new_id)
2086 int stat = move_in_NCList(nc,new_id);
2089 if(nc->dispatchdata)
2090 ((NC_OBJ*)nc->dispatchdata)->id = nc->ext_ncid;
2098 static NCglobalstate* nc_globalstate = NULL;
2104 const char* tmp = NULL;
2106 if(nc_globalstate == NULL) {
2107 nc_globalstate = calloc(1,
sizeof(NCglobalstate));
2110 if((nc_globalstate->rcinfo = calloc(1,
sizeof(
struct NCRCinfo)))==NULL)
2112 if((nc_globalstate->rcinfo->entries = nclistnew())==NULL)
2114 if((nc_globalstate->rcinfo->s3profiles = nclistnew())==NULL)
2118 if(getenv(NCRCENVIGNORE) != NULL)
2119 nc_globalstate->rcinfo->ignore = 1;
2120 tmp = getenv(NCRCENVRC);
2121 if(tmp != NULL && strlen(tmp) > 0)
2122 nc_globalstate->rcinfo->rcfile = strdup(tmp);
2124 nc_globalstate->chunkcache.size = CHUNK_CACHE_SIZE;
2125 nc_globalstate->chunkcache.nelems = CHUNK_CACHE_NELEMS;
2126 nc_globalstate->chunkcache.preemption = CHUNK_CACHE_PREEMPTION;
2134 NC_getglobalstate(
void)
2136 if(nc_globalstate == NULL)
2138 return nc_globalstate;
2142 NC_freeglobalstate(
void)
2144 if(nc_globalstate != NULL) {
2145 nullfree(nc_globalstate->tempdir);
2146 nullfree(nc_globalstate->home);
2147 nullfree(nc_globalstate->cwd);
2148 NC_rcclear(nc_globalstate->rcinfo);
2149 free(nc_globalstate->rcinfo);
2150 free(nc_globalstate);
2151 nc_globalstate = NULL;
2206 NCglobalstate* gs = NC_getglobalstate();
2207 gs->alignment.threshold = threshold;
2208 gs->alignment.alignment = alignment;
2209 gs->alignment.defined = 1;
2233 NCglobalstate* gs = NC_getglobalstate();
2234 if(thresholdp) *thresholdp = gs->alignment.threshold;
2235 if(alignmentp) *alignmentp = gs->alignment.alignment;
int nc_get_alignment(int *thresholdp, int *alignmentp)
Provide get function to retrieve global data alignment information.
int nc_set_alignment(int threshold, int alignment)
Provide a function to store global data alignment information.
EXTERNL int nc_free_vlen(nc_vlen_t *vl)
Free memory in a VLEN object.
static int NC_createglobalstate(void)
Main header file for the C API.
#define NC_UNLIMITED
Size argument to nc_def_dim() for an unlimited dimension.
#define NC_EBADTYPE
Not a netcdf data type.
#define NC_VIRTUAL
In HDF5 files you can set storage for each variable to be either contiguous or chunked,...
#define NC_VLEN
vlen (variable-length) types
#define NC_ENAMEINUSE
String match to name in use.
#define NC_ENOMEM
Memory allocation (malloc) failure.
#define NC_COMPOUND
compound types
#define NC_EINTERNAL
NetCDF Library Internal Error.
#define NC_CHUNKED
In HDF5 files you can set storage for each variable to be either contiguous or chunked,...
#define NC_ENUM
enum types
#define NC_CONTIGUOUS
In HDF5 files you can set storage for each variable to be either contiguous or chunked,...
#define NC_GLOBAL
Attribute id to put/get a global attribute.
#define NC_EMAXNAME
NC_MAX_NAME exceeded.
#define NC_ENOTATT
Attribute not found.
EXTERNL int nc_reclaim_data(int ncid, nc_type xtypeid, void *memory, size_t count)
Reclaim a vector of instances of arbitrary type.
#define NC_COMPACT
In HDF5 files you can set storage for each variable to be either contiguous or chunked,...
#define NC_ENOTVAR
Variable not found.
#define NC_EINVAL
Invalid Argument.
#define NC_MAX_NAME
Maximum for classic library.
#define NC_NOERR
No Error.
#define NC_EMPI
MPI operation failed.
#define NC_OPAQUE
opaque types
#define NC_EIO
Generic IO error.
#define NC_EBADID
Not a netcdf id.
#define NC_EBADTYPID
Bad type ID.
#define NC_EBADDIM
Invalid dimension id or name.
int nc_type
The nc_type type is just an int.