mirror of
https://github.com/Unidata/netcdf-c.git
synced 2024-11-21 03:13:42 +08:00
Many changes to address NCF-177 (renaming dimensions and variables). Also
many cleanups to fix compiler warnings, streamline iteration over objects in HDF5 file when opening the file, and generally straightening out the code to be cleaner and simpler. Tested on Mac OS/X with gcc 4.8 and OpenMPI (which uses clang).
This commit is contained in:
parent
857080f1e1
commit
e1fc13b215
@ -20,11 +20,6 @@
|
||||
#define DIMSCALE_LABEL "dimscale_label"
|
||||
#define STR_LEN 255
|
||||
|
||||
/* typedef struct { */
|
||||
/* unsigned long fileno; /\*file number *\/ */
|
||||
/* haddr_t objno; /\*object number *\/ */
|
||||
/* } HDF5_OBJID_T; */
|
||||
|
||||
herr_t alien_visitor(hid_t did, unsigned dim, hid_t dsid,
|
||||
void *visitor_data)
|
||||
{
|
||||
@ -37,34 +32,21 @@ herr_t alien_visitor(hid_t did, unsigned dim, hid_t dsid,
|
||||
if (H5Iget_name(did, name1, STR_LEN) < 0) ERR;
|
||||
if (strcmp(&name1[1], VAR1_NAME)) ERR;
|
||||
|
||||
/*printf("visiting did 0x%x dim %d dsid 0x%x name of did %s \n",
|
||||
did, dim, dsid, name1);*/
|
||||
|
||||
/* Get more info on the dimscale object.*/
|
||||
if (H5Gget_objinfo(dsid, ".", 1, &statbuf) < 0) ERR;
|
||||
objid->fileno[0] = statbuf.fileno[0];
|
||||
objid->objno[0] = statbuf.objno[0];
|
||||
objid->fileno[1] = statbuf.fileno[1];
|
||||
objid->objno[1] = statbuf.objno[1];
|
||||
/*printf("for dsid: statbuf.fileno = %d statbuf.objno = %d\n",
|
||||
statbuf.fileno, statbuf.objno);*/
|
||||
|
||||
if (H5Gget_objinfo(did, ".", 1, &statbuf) < 0) ERR;
|
||||
/*printf("for did: statbuf.fileno = %d statbuf.objno = %d\n",
|
||||
statbuf.fileno, statbuf.objno);*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
herr_t alien_visitor2(hid_t did, unsigned dim, hid_t dsid, void *visitor_data)
|
||||
{
|
||||
char name1[STR_LEN];
|
||||
H5G_stat_t statbuf;
|
||||
HDF5_OBJID_T *objid = visitor_data;
|
||||
|
||||
if (H5Iget_name(did, name1, STR_LEN) < 0) ERR;
|
||||
/*printf("visiting did 0x%x dim %d dsid 0x%x name of did %s \n",
|
||||
did, dim, dsid, name1); */
|
||||
|
||||
/* Get obj id of the dimscale object. THis will be used later to
|
||||
* match dimensions to dimscales. */
|
||||
if (H5Gget_objinfo(dsid, ".", 1, &statbuf) < 0) ERR;
|
||||
@ -145,9 +127,6 @@ main()
|
||||
if ((obj_class = H5Gget_objtype_by_idx(fileid, i)) < 0) ERR;
|
||||
if (H5Gget_objname_by_idx(fileid, i, obj_name, STR_LEN) < 0) ERR;
|
||||
|
||||
/*printf("\nEncountered: HDF5 object obj_class %d obj_name %s\n",
|
||||
obj_class, obj_name);*/
|
||||
|
||||
/* Deal with object based on its obj_class. */
|
||||
switch(obj_class)
|
||||
{
|
||||
@ -179,9 +158,6 @@ main()
|
||||
dimscale_obj.objno[0] = statbuf.objno[0];
|
||||
dimscale_obj.fileno[1] = statbuf.fileno[1];
|
||||
dimscale_obj.objno[1] = statbuf.objno[1];
|
||||
/*printf("statbuf.fileno = %d statbuf.objno = %d\n",
|
||||
statbuf.fileno, statbuf.objno);*/
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -193,8 +169,6 @@ main()
|
||||
/* Go through all dimscales for this var and learn about them. */
|
||||
if (H5DSiterate_scales(datasetid, 0, NULL, alien_visitor,
|
||||
&vars_dimscale_obj) < 0) ERR;
|
||||
/*printf("vars_dimscale_obj.fileno = %d vars_dimscale_obj.objno = %d\n",
|
||||
vars_dimscale_obj.fileno, vars_dimscale_obj.objno);*/
|
||||
if (vars_dimscale_obj.fileno[0] != dimscale_obj.fileno[0] ||
|
||||
vars_dimscale_obj.objno[0] != dimscale_obj.objno[0] ||
|
||||
vars_dimscale_obj.fileno[1] != dimscale_obj.fileno[1] ||
|
||||
@ -202,8 +176,6 @@ main()
|
||||
|
||||
/* There's also a label for dimension 0. */
|
||||
if (H5DSget_label(datasetid, 0, label, STR_LEN) < 0) ERR;
|
||||
|
||||
/*printf("found non-scale dataset %s, label %s\n", obj_name, label);*/
|
||||
}
|
||||
if (H5Dclose(datasetid) < 0) ERR;
|
||||
break;
|
||||
@ -304,9 +276,6 @@ main()
|
||||
if ((obj_class = H5Gget_objtype_by_idx(fileid, i)) < 0) ERR;
|
||||
if (H5Gget_objname_by_idx(fileid, i, obj_name, STR_LEN) < 0) ERR;
|
||||
|
||||
/* printf("\nEncountered: HDF5 object obj_class %d obj_name %s\n", */
|
||||
/* obj_class, obj_name); */
|
||||
|
||||
/* Deal with object based on its obj_class. */
|
||||
switch(obj_class)
|
||||
{
|
||||
@ -333,9 +302,6 @@ main()
|
||||
dimscale_obj[dimscale_cnt].objno[0] = statbuf.objno[0];
|
||||
dimscale_obj[dimscale_cnt].fileno[1] = statbuf.fileno[1];
|
||||
dimscale_obj[dimscale_cnt].objno[1] = statbuf.objno[1];
|
||||
/* printf("dimscale_obj[%d].fileno = %d dimscale_obj[%d].objno = %d\n", */
|
||||
/* dimscale_cnt, dimscale_obj[dimscale_cnt].fileno, dimscale_cnt, */
|
||||
/* dimscale_obj[dimscale_cnt].objno); */
|
||||
dimscale_cnt++;
|
||||
}
|
||||
else
|
||||
@ -791,9 +757,6 @@ main()
|
||||
if ((obj_class = H5Gget_objtype_by_idx(fileid, i)) < 0) ERR;
|
||||
if (H5Gget_objname_by_idx(fileid, i, obj_name, STR_LEN) < 0) ERR;
|
||||
|
||||
/* printf("\nEncountered: HDF5 object obj_class %d obj_name %s\n", */
|
||||
/* obj_class, obj_name); */
|
||||
|
||||
/* Deal with object based on its obj_class. */
|
||||
switch(obj_class)
|
||||
{
|
||||
@ -819,9 +782,6 @@ main()
|
||||
dimscale_obj[dimscale_cnt].objno[0] = statbuf.objno[0];
|
||||
dimscale_obj[dimscale_cnt].fileno[1] = statbuf.fileno[1];
|
||||
dimscale_obj[dimscale_cnt].objno[1] = statbuf.objno[1];
|
||||
/* printf("dimscale_obj[%d].fileno = %d dimscale_obj[%d].objno = %d\n", */
|
||||
/* dimscale_cnt, dimscale_obj[dimscale_cnt].fileno, dimscale_cnt, */
|
||||
/* dimscale_obj[dimscale_cnt].objno); */
|
||||
dimscale_cnt++;
|
||||
}
|
||||
else
|
||||
@ -982,9 +942,6 @@ main()
|
||||
if ((obj_class = H5Gget_objtype_by_idx(fileid, i)) < 0) ERR;
|
||||
if (H5Gget_objname_by_idx(fileid, i, obj_name, STR_LEN) < 0) ERR;
|
||||
|
||||
/* printf("\nEncountered: HDF5 object obj_class %d obj_name %s\n", */
|
||||
/* obj_class, obj_name); */
|
||||
|
||||
/* Deal with object based on its obj_class. */
|
||||
switch(obj_class)
|
||||
{
|
||||
@ -1010,9 +967,6 @@ main()
|
||||
dimscale_obj[dimscale_cnt].objno[0] = statbuf.objno[0];
|
||||
dimscale_obj[dimscale_cnt].fileno[1] = statbuf.fileno[1];
|
||||
dimscale_obj[dimscale_cnt].objno[1] = statbuf.objno[1];
|
||||
/* printf("dimscale_obj[%d].fileno = %d dimscale_obj[%d].objno = %d\n", */
|
||||
/* dimscale_cnt, dimscale_obj[dimscale_cnt].fileno, dimscale_cnt, */
|
||||
/* dimscale_obj[dimscale_cnt].objno); */
|
||||
dimscale_cnt++;
|
||||
}
|
||||
else
|
||||
|
@ -23,11 +23,6 @@
|
||||
#define DIMSCALE_LABEL "dimscale_label"
|
||||
#define STR_LEN 255
|
||||
|
||||
/* typedef struct { */
|
||||
/* unsigned long fileno; /\*file number *\/ */
|
||||
/* haddr_t objno; /\*object number *\/ */
|
||||
/* } HDF5_OBJID_T; */
|
||||
|
||||
herr_t alien_visitor(hid_t did, unsigned dim, hid_t dsid,
|
||||
void *visitor_data)
|
||||
{
|
||||
@ -40,34 +35,21 @@ herr_t alien_visitor(hid_t did, unsigned dim, hid_t dsid,
|
||||
if (H5Iget_name(did, name1, STR_LEN) < 0) ERR;
|
||||
if (strcmp(&name1[1], VAR1_NAME)) ERR;
|
||||
|
||||
/*printf("visiting did 0x%x dim %d dsid 0x%x name of did %s \n",
|
||||
did, dim, dsid, name1);*/
|
||||
|
||||
/* Get more info on the dimscale object.*/
|
||||
if (H5Gget_objinfo(dsid, ".", 1, &statbuf) < 0) ERR;
|
||||
objid->fileno[0] = statbuf.fileno[0];
|
||||
objid->objno[0] = statbuf.objno[0];
|
||||
objid->fileno[1] = statbuf.fileno[1];
|
||||
objid->objno[1] = statbuf.objno[1];
|
||||
/*printf("for dsid: statbuf.fileno = %d statbuf.objno = %d\n",
|
||||
statbuf.fileno, statbuf.objno);*/
|
||||
|
||||
if (H5Gget_objinfo(did, ".", 1, &statbuf) < 0) ERR;
|
||||
/*printf("for did: statbuf.fileno = %d statbuf.objno = %d\n",
|
||||
statbuf.fileno, statbuf.objno);*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
herr_t alien_visitor2(hid_t did, unsigned dim, hid_t dsid, void *visitor_data)
|
||||
{
|
||||
char name1[STR_LEN];
|
||||
H5G_stat_t statbuf;
|
||||
HDF5_OBJID_T *objid = visitor_data;
|
||||
|
||||
if (H5Iget_name(did, name1, STR_LEN) < 0) ERR;
|
||||
/*printf("visiting did 0x%x dim %d dsid 0x%x name of did %s \n",
|
||||
did, dim, dsid, name1); */
|
||||
|
||||
/* Get obj id of the dimscale object. THis will be used later to
|
||||
* match dimensions to dimscales. */
|
||||
if (H5Gget_objinfo(dsid, ".", 1, &statbuf) < 0) ERR;
|
||||
@ -144,9 +126,6 @@ main()
|
||||
if ((obj_class = H5Gget_objtype_by_idx(fileid, i)) < 0) ERR;
|
||||
if (H5Gget_objname_by_idx(fileid, i, obj_name, STR_LEN) < 0) ERR;
|
||||
|
||||
/*printf("\nEncountered: HDF5 object obj_class %d obj_name %s\n",
|
||||
obj_class, obj_name);*/
|
||||
|
||||
/* Deal with object based on its obj_class. */
|
||||
switch(obj_class)
|
||||
{
|
||||
@ -178,9 +157,6 @@ main()
|
||||
dimscale_obj.objno[0] = statbuf.objno[0];
|
||||
dimscale_obj.fileno[1] = statbuf.fileno[1];
|
||||
dimscale_obj.objno[1] = statbuf.objno[1];
|
||||
/*printf("statbuf.fileno = %d statbuf.objno = %d\n",
|
||||
statbuf.fileno, statbuf.objno);*/
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -192,8 +168,6 @@ main()
|
||||
/* Go through all dimscales for this var and learn about them. */
|
||||
if (H5DSiterate_scales(datasetid, 0, NULL, alien_visitor,
|
||||
&vars_dimscale_obj) < 0) ERR;
|
||||
/*printf("vars_dimscale_obj.fileno = %d vars_dimscale_obj.objno = %d\n",
|
||||
vars_dimscale_obj.fileno, vars_dimscale_obj.objno);*/
|
||||
if (vars_dimscale_obj.fileno[0] != dimscale_obj.fileno[0] ||
|
||||
vars_dimscale_obj.objno[0] != dimscale_obj.objno[0] ||
|
||||
vars_dimscale_obj.fileno[1] != dimscale_obj.fileno[1] ||
|
||||
@ -201,8 +175,6 @@ main()
|
||||
|
||||
/* There's also a label for dimension 0. */
|
||||
if (H5DSget_label(datasetid, 0, label, STR_LEN) < 0) ERR;
|
||||
|
||||
/*printf("found non-scale dataset %s, label %s\n", obj_name, label);*/
|
||||
}
|
||||
if (H5Dclose(datasetid) < 0) ERR;
|
||||
break;
|
||||
|
@ -27,75 +27,25 @@
|
||||
#define NC_EHDFERR 255
|
||||
#define DIM_WITHOUT_VARIABLE "This is a netCDF dimension but not a netCDF variable."
|
||||
|
||||
/* typedef struct { */
|
||||
/* unsigned long fileno; /\*file number *\/ */
|
||||
/* haddr_t objno; /\*object number *\/ */
|
||||
/* } HDF5_OBJID_T; */
|
||||
|
||||
struct nc_hdf5_link_info
|
||||
{
|
||||
char name[STR_LEN];
|
||||
H5I_type_t obj_type;
|
||||
};
|
||||
|
||||
#if 0
|
||||
static herr_t
|
||||
visit_link(hid_t g_id, const char *name, const H5L_info_t *info,
|
||||
void *op_data)
|
||||
{
|
||||
/* A positive return value causes the visit iterator to immediately
|
||||
* return that positive value, indicating short-circuit
|
||||
* success. The iterator can be restarted at the next group
|
||||
* member. */
|
||||
int ret = 1;
|
||||
hid_t id;
|
||||
|
||||
strncpy(((struct nc_hdf5_link_info *)op_data)->name, name, NC_MAX_NAME);
|
||||
|
||||
/* Open this critter. */
|
||||
if ((id = H5Oopen_by_addr(g_id, info->u.address)) < 0)
|
||||
return NC_EHDFERR;
|
||||
|
||||
/* Is this critter a group, type, data, attribute, or what? */
|
||||
if ((((struct nc_hdf5_link_info *)op_data)->obj_type = H5Iget_type(id)) < 0)
|
||||
ret = NC_EHDFERR;
|
||||
|
||||
/* Close the critter to release resouces. */
|
||||
if (H5Oclose(id) < 0)
|
||||
return NC_EHDFERR;
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
herr_t alien_visitor(hid_t did, unsigned dim, hid_t dsid,
|
||||
void *visitor_data)
|
||||
{
|
||||
#if 0
|
||||
char name1[STR_LEN];
|
||||
#endif
|
||||
H5G_stat_t statbuf;
|
||||
HDF5_OBJID_T *objid = visitor_data;
|
||||
|
||||
/* This should get "/var1", the name of the dataset that the scale
|
||||
* is attached to. */
|
||||
/*if (H5Iget_name(did, name1, STR_LEN) < 0) ERR;*/
|
||||
|
||||
/* printf("visiting did 0x%x dim %d dsid 0x%x name of did %s \n",
|
||||
did, dim, dsid, name1);*/
|
||||
|
||||
/* Get more info on the dimscale object.*/
|
||||
if (H5Gget_objinfo(dsid, ".", 1, &statbuf) < 0) ERR;
|
||||
objid->fileno[0] = statbuf.fileno[0];
|
||||
objid->objno[0] = statbuf.objno[0];
|
||||
objid->fileno[1] = statbuf.fileno[1];
|
||||
objid->objno[1] = statbuf.objno[1];
|
||||
/* printf("for dsid: statbuf.fileno = %d statbuf.objno = %d\n",
|
||||
statbuf.fileno, statbuf.objno);*/
|
||||
|
||||
if (H5Gget_objinfo(did, ".", 1, &statbuf) < 0) ERR;
|
||||
/* printf("for did: statbuf.fileno = %d statbuf.objno = %d\n",
|
||||
statbuf.fileno, statbuf.objno);*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -105,9 +55,6 @@ main()
|
||||
printf("\n*** Checking HDF5 dimscales detach.\n");
|
||||
printf("*** Creating a file with two vars with one dimension scale...");
|
||||
{
|
||||
#if 0
|
||||
hid_t cparmsid;
|
||||
#endif
|
||||
hid_t fileid, grpid, spaceid, var1_id, var2_id, dimscaleid;
|
||||
hid_t fcpl_id, fapl_id, create_propid, access_propid;
|
||||
hsize_t dims[NDIMS] = {DIM_LEN};
|
||||
@ -186,107 +133,6 @@ main()
|
||||
if (H5Dclose(dimscaleid) < 0) ERR;
|
||||
if (H5Gclose(grpid) < 0) ERR;
|
||||
if (H5Fclose(fileid) < 0) ERR;
|
||||
|
||||
/* /\* Now read the file and check it. *\/ */
|
||||
/* { */
|
||||
/* hid_t fileid, spaceid = 0, datasetid = 0; */
|
||||
/* hsize_t num_obj, i; */
|
||||
/* int obj_class; */
|
||||
/* char obj_name[STR_LEN + 1]; */
|
||||
/* char dimscale_name[STR_LEN+1]; */
|
||||
/* htri_t is_scale; */
|
||||
/* char label[STR_LEN+1]; */
|
||||
/* int num_scales; */
|
||||
/* hsize_t dims[1], maxdims[1]; */
|
||||
/* H5G_stat_t statbuf; */
|
||||
/* HDF5_OBJID_T dimscale_obj, vars_dimscale_obj; */
|
||||
/* struct nc_hdf5_link_info link_info; */
|
||||
/* hsize_t idx = 0; */
|
||||
|
||||
/* /\* Open the file. *\/ */
|
||||
/* if ((fileid = H5Fopen(FILE_NAME, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) ERR; */
|
||||
/* if ((grpid = H5Gopen2(fileid, "/", H5P_DEFAULT)) < 0) ERR; */
|
||||
|
||||
/* /\* Loop through objects in the root group. *\/ */
|
||||
/* if (H5Gget_num_objs(fileid, &num_obj) < 0) ERR; */
|
||||
/* for (i = 0; i < num_obj; i++) */
|
||||
/* { */
|
||||
|
||||
/* if (H5Literate(grpid, H5_INDEX_CRT_ORDER, H5_ITER_INC, */
|
||||
/* &idx, visit_link, (void *)&link_info) < 0) ERR; */
|
||||
|
||||
/* printf("Encountered: HDF5 object link_info.name %s\n", link_info.name); */
|
||||
|
||||
/* /\* Deal with object based on its obj_class. *\/ */
|
||||
/* switch(link_info.obj_type) */
|
||||
/* { */
|
||||
/* case H5I_GROUP: */
|
||||
/* break; */
|
||||
/* case H5I_DATASET: */
|
||||
/* /\* Open the dataset. *\/ */
|
||||
/* if ((datasetid = H5Dopen1(fileid, link_info.name)) < 0) ERR; */
|
||||
|
||||
/* if ((spaceid = H5Dget_space(datasetid)) < 0) ERR; */
|
||||
/* if (H5Sget_simple_extent_dims(spaceid, dims, maxdims) < 0) ERR; */
|
||||
/* if (maxdims[0] != DIM_LEN) ERR; */
|
||||
/* if (H5Sclose(spaceid) < 0) ERR; */
|
||||
|
||||
/* /\* Is this a dimscale? *\/ */
|
||||
/* if ((is_scale = H5DSis_scale(datasetid)) < 0) ERR; */
|
||||
/* if (is_scale && strcmp(link_info.name, DIMSCALE_NAME)) ERR; */
|
||||
/* if (is_scale) */
|
||||
/* { */
|
||||
/* /\* A dimscale comes with a NAME attribute, in */
|
||||
/* * addition to its real name. *\/ */
|
||||
/* if (H5DSget_scale_name(datasetid, dimscale_name, STR_LEN) < 0) ERR; */
|
||||
/* if (strcmp(dimscale_name, dimscale_wo_var)) ERR; */
|
||||
|
||||
/* /\* fileno and objno uniquely identify an object and a */
|
||||
/* * HDF5 file. *\/ */
|
||||
/* if (H5Gget_objinfo(datasetid, ".", 1, &statbuf) < 0) ERR; */
|
||||
/* dimscale_obj.fileno[0] = statbuf.fileno[0]; */
|
||||
/* dimscale_obj.objno[0] = statbuf.objno[0]; */
|
||||
/* dimscale_obj.fileno[1] = statbuf.fileno[1]; */
|
||||
/* dimscale_obj.objno[1] = statbuf.objno[1]; */
|
||||
/* /\*printf("scale statbuf.fileno = %d statbuf.objno = %d\n", */
|
||||
/* statbuf.fileno, statbuf.objno);*\/ */
|
||||
|
||||
/* } */
|
||||
/* else */
|
||||
/* { */
|
||||
/* /\* Here's how to get the number of scales attached */
|
||||
/* * to the dataset's dimension 0. *\/ */
|
||||
/* if ((num_scales = H5DSget_num_scales(datasetid, 0)) < 0) ERR; */
|
||||
/* if (num_scales != 1) ERR; */
|
||||
|
||||
/* /\* Go through all dimscales for this var and learn about them. *\/ */
|
||||
/* if (H5DSiterate_scales(datasetid, 0, NULL, alien_visitor, */
|
||||
/* &vars_dimscale_obj) < 0) ERR; */
|
||||
/* /\*printf("vars_dimscale_obj.fileno = %d vars_dimscale_obj.objno = %d\n", */
|
||||
/* vars_dimscale_obj.fileno, vars_dimscale_obj.objno);*\/ */
|
||||
/* /\* if (vars_dimscale_obj.fileno[0] != dimscale_obj.fileno[0] || *\/ */
|
||||
/* /\* vars_dimscale_obj.objno[0] != dimscale_obj.objno[0] || *\/ */
|
||||
/* /\* vars_dimscale_obj.fileno[1] != dimscale_obj.fileno[1] || *\/ */
|
||||
/* /\* vars_dimscale_obj.objno[1] != dimscale_obj.objno[1]) ERR; *\/ */
|
||||
|
||||
/* /\* There's also a label for dimension 0. *\/ */
|
||||
/* if (H5DSget_label(datasetid, 0, label, STR_LEN) < 0) ERR; */
|
||||
|
||||
/* /\*printf("found non-scale dataset %s, label %s\n", link_info.name, label);*\/ */
|
||||
/* } */
|
||||
/* if (H5Dclose(datasetid) < 0) ERR; */
|
||||
/* break; */
|
||||
/* case H5I_DATATYPE: */
|
||||
/* break; */
|
||||
/* default: */
|
||||
/* printf("Unknown object!"); */
|
||||
/* ERR; */
|
||||
/* } */
|
||||
/* } */
|
||||
|
||||
/* /\* Close up the shop. *\/ */
|
||||
/* if (H5Fclose(fileid) < 0) ERR; */
|
||||
/* }*/
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
FINAL_RESULTS;
|
||||
|
@ -108,11 +108,9 @@ typedef struct NC_DIM_INFO
|
||||
struct NC_DIM_INFO *next;
|
||||
struct NC_DIM_INFO *prev;
|
||||
hid_t hdf_dimscaleid;
|
||||
char *old_name; /* only used to rename dim */
|
||||
int dirty;
|
||||
unsigned char coord_var_in_grp;
|
||||
HDF5_OBJID_T hdf5_objid;
|
||||
struct NC_VAR_INFO *coord_var; /* The coord var, if it exists. */
|
||||
int too_long; /* True if len it too big to fit in local size_t. */
|
||||
int too_long; /* True if len is too big to fit in local size_t. */
|
||||
} NC_DIM_INFO_T;
|
||||
|
||||
typedef struct NC_ATT_INFO
|
||||
@ -234,7 +232,6 @@ typedef struct NC_GRP_INFO
|
||||
int natts;
|
||||
struct NC_HDF5_FILE_INFO *nc4_info;
|
||||
char *name;
|
||||
char *old_name; /* need when renaming group */
|
||||
hid_t hdf_grpid;
|
||||
NC_TYPE_INFO_T *type;
|
||||
} NC_GRP_INFO_T;
|
||||
@ -292,6 +289,7 @@ int nc4_convert_type(const void *src, void *dest,
|
||||
int dest_long);
|
||||
|
||||
/* These functions do HDF5 things. */
|
||||
int rec_detach_scales(NC_GRP_INFO_T *grp, int dimid, hid_t dimscaleid);
|
||||
int nc4_open_var_grp2(NC_GRP_INFO_T *grp, int varid, hid_t *dataset);
|
||||
int pg_var(NC_PG_T pg, NC *nc, int ncid, int varid, nc_type xtype, int is_long, void *ip);
|
||||
int nc4_pg_var1(NC_PG_T pg, NC *nc, int ncid, int varid, const size_t *indexp,
|
||||
@ -306,7 +304,7 @@ int nc4_pg_varm(NC_PG_T pg, NC *nc, int ncid, int varid, const size_t *startp,
|
||||
int nc4_rec_match_dimscales(NC_GRP_INFO_T *grp);
|
||||
int nc4_rec_detect_need_to_preserve_dimids(NC_GRP_INFO_T *grp, int *bad_coord_orderp);
|
||||
int nc4_rec_write_metadata(NC_GRP_INFO_T *grp, int bad_coord_order);
|
||||
int nc4_rec_write_types(NC_GRP_INFO_T *grp);
|
||||
int nc4_rec_write_groups_types(NC_GRP_INFO_T *grp);
|
||||
int nc4_enddef_netcdf4_file(NC_HDF5_FILE_INFO_T *h5);
|
||||
int nc4_reopen_dataset(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var);
|
||||
int nc4_adjust_var_cache(NC_GRP_INFO_T *grp, NC_VAR_INFO_T * var);
|
||||
@ -321,6 +319,7 @@ NC_GRP_INFO_T *nc4_find_nc_grp(int ncid);
|
||||
NC_GRP_INFO_T *nc4_rec_find_grp(NC_GRP_INFO_T *start_grp, int target_nc_grpid);
|
||||
NC *nc4_find_nc_file(int ncid, NC_HDF5_FILE_INFO_T**);
|
||||
int nc4_find_dim(NC_GRP_INFO_T *grp, int dimid, NC_DIM_INFO_T **dim, NC_GRP_INFO_T **dim_grp);
|
||||
int nc4_find_var(NC_GRP_INFO_T *grp, const char *name, NC_VAR_INFO_T **var);
|
||||
int nc4_find_dim_len(NC_GRP_INFO_T *grp, int dimid, size_t **len);
|
||||
int nc4_find_type(NC_HDF5_FILE_INFO_T *h5, int typeid1, NC_TYPE_INFO_T **type);
|
||||
NC_TYPE_INFO_T *nc4_rec_find_nc_type(NC_GRP_INFO_T *start_grp, hid_t target_nc_typeid);
|
||||
@ -357,6 +356,10 @@ int nc4_rec_grp_del(NC_GRP_INFO_T **list, NC_GRP_INFO_T *grp);
|
||||
int nc4_enum_member_add(NC_ENUM_MEMBER_INFO_T **list, size_t size,
|
||||
const char *name, const void *value);
|
||||
|
||||
/* Break & reform coordinate variables */
|
||||
int nc4_break_coord_var(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *coord_var, NC_DIM_INFO_T *dim);
|
||||
int nc4_reform_coord_var(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *coord_var, NC_DIM_INFO_T *dim);
|
||||
|
||||
int NC_check_name(const char *name);
|
||||
|
||||
/* Check and normalize names. */
|
||||
|
@ -31,7 +31,7 @@ NC4_inq_unlimdim(int ncid, int *unlimdimidp)
|
||||
int found = 0;
|
||||
int retval;
|
||||
|
||||
LOG((2, "called nc_inq_unlimdim"));
|
||||
LOG((2, "%s: called", __func__));
|
||||
|
||||
if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
|
||||
return retval;
|
||||
@ -74,7 +74,7 @@ NC4_def_dim(int ncid, const char *name, size_t len, int *idp)
|
||||
char norm_name[NC_MAX_NAME + 1];
|
||||
int retval = NC_NOERR;
|
||||
|
||||
LOG((2, "nc_def_dim: ncid 0x%x name %s len %d", ncid, name,
|
||||
LOG((2, "%s: ncid 0x%x name %s len %d", __func__, ncid, name,
|
||||
(int)len));
|
||||
|
||||
/* Find our global metadata structure. */
|
||||
@ -137,7 +137,6 @@ NC4_def_dim(int ncid, const char *name, size_t len, int *idp)
|
||||
return NC_ENOMEM;
|
||||
strcpy(grp->dim->name, norm_name);
|
||||
grp->dim->len = len;
|
||||
grp->dim->dirty++;
|
||||
if (len == NC_UNLIMITED)
|
||||
grp->dim->unlimited++;
|
||||
|
||||
@ -160,7 +159,7 @@ NC4_inq_dimid(int ncid, const char *name, int *idp)
|
||||
int finished = 0;
|
||||
int retval;
|
||||
|
||||
LOG((2, "nc_inq_dimid: ncid 0x%x name %s", ncid, name));
|
||||
LOG((2, "%s: ncid 0x%x name %s", __func__, ncid, name));
|
||||
|
||||
/* Find metadata for this file. */
|
||||
if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
|
||||
@ -204,7 +203,7 @@ NC4_inq_dim(int ncid, int dimid, char *name, size_t *lenp)
|
||||
NC_DIM_INFO_T *dim;
|
||||
int ret = NC_NOERR;
|
||||
|
||||
LOG((2, "nc_inq_dim: ncid 0x%x dimid %d", ncid, dimid));
|
||||
LOG((2, "%s: ncid 0x%x dimid %d", __func__, ncid, dimid));
|
||||
|
||||
/* Find our global metadata structure. */
|
||||
if ((ret = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
|
||||
@ -277,7 +276,7 @@ NC4_rename_dim(int ncid, int dimid, const char *name)
|
||||
if (!name)
|
||||
return NC_EINVAL;
|
||||
|
||||
LOG((2, "nc_rename_dim: ncid 0x%x dimid %d name %s", ncid,
|
||||
LOG((2, "%s: ncid 0x%x dimid %d name %s", __func__, ncid,
|
||||
dimid, name));
|
||||
|
||||
/* Find info for this file and group, and set pointer to each. */
|
||||
@ -313,33 +312,21 @@ NC4_rename_dim(int ncid, int dimid, const char *name)
|
||||
if (!dim)
|
||||
return NC_EBADDIM;
|
||||
|
||||
/* If not in define mode, switch to it, unless the new name is
|
||||
* shorter. (This is in accordance with the v3 interface.) */
|
||||
/* if (!(h5->flags & NC_INDEF) && strlen(name) > strlen(dim->name)) */
|
||||
/* { */
|
||||
/* if (h5->cmode & NC_CLASSIC_MODEL) */
|
||||
/* return NC_ENOTINDEFINE; */
|
||||
/* if ((retval = NC4_redef(ncid))) */
|
||||
/* return retval; */
|
||||
/* } */
|
||||
|
||||
/* Save the old name, we'll need it to rename this object when we
|
||||
* sync to HDF5 file. But if there already is an old_name saved,
|
||||
* just stick with what we've got, since the user might be renaming
|
||||
* the crap out of this thing, without ever syncing with the
|
||||
* file. When the sync does take place, we only need the original
|
||||
* name of the dim, not any of the intermediate ones. If the user
|
||||
* could just make up his mind, we could all get on to writing some
|
||||
* data... */
|
||||
if (!dim->old_name)
|
||||
/* Check for renaming dimension w/o variable */
|
||||
if (dim->hdf_dimscaleid)
|
||||
{
|
||||
dim->old_name = dim->name;
|
||||
dim->name = NULL;
|
||||
}
|
||||
/* Sanity check */
|
||||
assert(!dim->coord_var);
|
||||
|
||||
/* Check if this is a coordinate variable, and if so, mark it dirty */
|
||||
if (dim->coord_var)
|
||||
dim->coord_var->dirty++;
|
||||
/* Close the HDF5 dataset */
|
||||
if (H5Dclose(dim->hdf_dimscaleid) < 0)
|
||||
return NC_EHDFERR;
|
||||
dim->hdf_dimscaleid = 0;
|
||||
|
||||
/* Now delete the dataset (it will be recreated later, if necessary) */
|
||||
if (H5Gunlink(grp->hdf_grpid, dim->name) < 0)
|
||||
return NC_EDIMMETA;
|
||||
}
|
||||
|
||||
/* Give the dimension its new name in metadata. UTF8 normalization
|
||||
* has been done. */
|
||||
@ -349,6 +336,37 @@ NC4_rename_dim(int ncid, int dimid, const char *name)
|
||||
return NC_ENOMEM;
|
||||
strcpy(dim->name, norm_name);
|
||||
|
||||
/* Check if dimension was a coordinate variable, but names are different now */
|
||||
if (dim->coord_var && strcmp(dim->name, dim->coord_var->name))
|
||||
{
|
||||
/* Break up the coordinate variable */
|
||||
if ((retval = nc4_break_coord_var(grp, dim->coord_var, dim)))
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* Check if dimension should become a coordinate variable */
|
||||
if (!dim->coord_var)
|
||||
{
|
||||
NC_VAR_INFO_T *var;
|
||||
|
||||
/* Attempt to find a variable with the same name as the dimension in
|
||||
* the current group. */
|
||||
if ((retval = nc4_find_var(grp, dim->name, &var)))
|
||||
return retval;
|
||||
|
||||
/* Check if we found a variable and the variable has the dimension in
|
||||
* index 0. */
|
||||
if (var && var->dim[0] == dim)
|
||||
{
|
||||
/* Sanity check */
|
||||
assert(var->dimids[0] == dim->dimid);
|
||||
|
||||
/* Reform the coordinate variable */
|
||||
if ((retval = nc4_reform_coord_var(grp, var, dim)))
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
|
||||
return NC_NOERR;
|
||||
}
|
||||
|
||||
@ -366,7 +384,7 @@ NC4_inq_unlimdims(int ncid, int *nunlimdimsp, int *unlimdimidsp)
|
||||
int num_unlim = 0;
|
||||
int retval;
|
||||
|
||||
LOG((2, "nc_inq_unlimdims: ncid 0x%x", ncid));
|
||||
LOG((2, "%s: ncid 0x%x", __func__, ncid));
|
||||
|
||||
/* Find info for this file and group, and set pointer to each. */
|
||||
if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -23,7 +23,7 @@ NC4_def_grp(int parent_ncid, const char *name, int *new_ncid)
|
||||
char norm_name[NC_MAX_NAME + 1];
|
||||
int retval;
|
||||
|
||||
LOG((2, "nc_def_grp: parent_ncid 0x%x name %s", parent_ncid, name));
|
||||
LOG((2, "%s: parent_ncid 0x%x name %s", __func__, parent_ncid, name));
|
||||
|
||||
/* Find info for this file and group, and set pointer to each. */
|
||||
if ((retval = nc4_find_grp_h5(parent_ncid, &grp, &h5)))
|
||||
@ -98,19 +98,25 @@ NC4_rename_grp(int grpid, const char *name)
|
||||
if ((retval = NC4_redef(grpid)))
|
||||
return retval;
|
||||
|
||||
/* Save the old name, we'll need it to rename this object when we
|
||||
* sync to HDF5 file. But if there already is an old_name saved,
|
||||
* just stick with what we've got, since the user might be renaming
|
||||
* the crap out of this thing, without ever syncing with the
|
||||
* file. When the sync does take place, we only need the original
|
||||
* name of the grp, not any of the intermediate ones. If the user
|
||||
* could just make up his mind, we could all get on to writing some
|
||||
* data... */
|
||||
if (!grp->old_name)
|
||||
/* Rename the group, if it exists in the file */
|
||||
if (grp->hdf_grpid)
|
||||
{
|
||||
if (!(grp->old_name = malloc((strlen(grp->name) + 1) * sizeof(char))))
|
||||
return NC_ENOMEM;
|
||||
strcpy(grp->old_name, grp->name);
|
||||
/* Close the group */
|
||||
if (H5Gclose(grp->hdf_grpid) < 0)
|
||||
return NC_EHDFERR;
|
||||
grp->hdf_grpid = 0;
|
||||
|
||||
/* Attempt to rename & re-open the group, if the parent group is open */
|
||||
if (grp->parent->hdf_grpid)
|
||||
{
|
||||
/* Rename the group */
|
||||
if (H5Gmove(grp->parent->hdf_grpid, grp->name, name) < 0)
|
||||
return NC_EHDFERR;
|
||||
|
||||
/* Reopen the group, with the new name */
|
||||
if ((grp->hdf_grpid = H5Gopen2(grp->parent->hdf_grpid, name, H5P_DEFAULT)) < 0)
|
||||
return NC_EHDFERR;
|
||||
}
|
||||
}
|
||||
|
||||
/* Give the group its new name in metadata. UTF8 normalization
|
||||
|
532
libsrc4/nc4hdf.c
532
libsrc4/nc4hdf.c
File diff suppressed because it is too large
Load Diff
@ -16,6 +16,7 @@ conditions.
|
||||
#include "nc4internal.h"
|
||||
#include "nc.h" /* from libsrc */
|
||||
#include "ncdispatch.h" /* from libdispatch */
|
||||
#include "H5DSpublic.h"
|
||||
#include <utf8proc.h>
|
||||
|
||||
#if 0 /*def USE_PNETCDF*/
|
||||
@ -125,7 +126,7 @@ find_var_dim_max_length(NC_GRP_INFO_T *grp, int varid, int dimid, size_t *maxlen
|
||||
if ((dataset_ndims = H5Sget_simple_extent_dims(spaceid,
|
||||
h5dimlen, h5dimlenmax)) < 0)
|
||||
BAIL(NC_EHDFERR);
|
||||
LOG((5, "find_var_shape_nc: varid %d len %d max: %d",
|
||||
LOG((5, "find_var_dim_max_length: varid %d len %d max: %d",
|
||||
varid, (int)h5dimlen[0], (int)h5dimlenmax[0]));
|
||||
for (d=0; d<dataset_ndims; d++) {
|
||||
if (var->dimids[d] == dimid) {
|
||||
@ -176,30 +177,10 @@ nc4_nc4f_list_add(NC *nc, const char *path, int mode)
|
||||
return nc4_grp_list_add(&(h5->root_grp), h5->next_nc_grpid++,
|
||||
NULL, nc, NC_GROUP_NAME, &grp);
|
||||
}
|
||||
/* /\* Given an ncid, find the relevant group and return a pointer to */
|
||||
/* * it. *\/ */
|
||||
/* NC_GRP_INFO_T * */
|
||||
/* find_nc_grp(int ncid) */
|
||||
/* { */
|
||||
/* NC *f; */
|
||||
|
||||
/* for (f = nc_file; f; f = f->next) */
|
||||
/* { */
|
||||
/* if (f->ext_ncid == (ncid & FILE_ID_MASK)) */
|
||||
/* { */
|
||||
/* assert(f->nc4_info && f->nc4_info->root_grp); */
|
||||
/* return nc4_rec_find_grp(f->nc4_info->root_grp, (ncid & GRP_ID_MASK)); */
|
||||
/* } */
|
||||
/* } */
|
||||
|
||||
/* return NULL; */
|
||||
/* } */
|
||||
|
||||
/* Given an ncid, find the relevant group and return a pointer to it,
|
||||
* return an error of this is not a netcdf-4 file (or if strict nc3 is
|
||||
* turned on for this file.) */
|
||||
|
||||
|
||||
int
|
||||
nc4_find_nc4_grp(int ncid, NC_GRP_INFO_T **grp)
|
||||
{
|
||||
@ -365,6 +346,20 @@ nc4_find_dim(NC_GRP_INFO_T *grp, int dimid, NC_DIM_INFO_T **dim,
|
||||
return NC_NOERR;
|
||||
}
|
||||
|
||||
/* Find a var (by name) in a grp. */
|
||||
int
|
||||
nc4_find_var(NC_GRP_INFO_T *grp, const char *name, NC_VAR_INFO_T **var)
|
||||
{
|
||||
assert(grp && var && name);
|
||||
|
||||
/* Find the var info. */
|
||||
for ((*var) = grp->var; (*var); (*var) = (*var)->next)
|
||||
if (0 == strcmp(name, (*var)->name))
|
||||
break;
|
||||
|
||||
return NC_NOERR;
|
||||
}
|
||||
|
||||
/* Recursively hunt for a HDF type id. */
|
||||
NC_TYPE_INFO_T *
|
||||
nc4_rec_find_hdf_type(NC_GRP_INFO_T *start_grp, hid_t target_hdf_typeid)
|
||||
@ -703,8 +698,7 @@ nc4_grp_list_add(NC_GRP_INFO_T **list, int new_nc_grpid,
|
||||
{
|
||||
NC_GRP_INFO_T *g;
|
||||
|
||||
LOG((3, "grp_list_add: new_nc_grpid %d name %s ",
|
||||
new_nc_grpid, name));
|
||||
LOG((3, "%s: new_nc_grpid %d name %s ", __func__, new_nc_grpid, name));
|
||||
|
||||
/* Get the memory to store this groups info. */
|
||||
if (!(*grp = calloc(1, sizeof(NC_GRP_INFO_T))))
|
||||
@ -1089,8 +1083,6 @@ nc4_dim_list_del(NC_DIM_INFO_T **list, NC_DIM_INFO_T *dim)
|
||||
/* Free memory allocated for names. */
|
||||
if (dim->name)
|
||||
free(dim->name);
|
||||
if (dim->old_name)
|
||||
free(dim->old_name);
|
||||
|
||||
free(dim);
|
||||
return NC_NOERR;
|
||||
@ -1125,7 +1117,7 @@ nc4_rec_grp_del(NC_GRP_INFO_T **list, NC_GRP_INFO_T *grp)
|
||||
int retval;
|
||||
|
||||
assert(grp);
|
||||
LOG((3, "nc4_rec_grp_del: grp->name %s", grp->name));
|
||||
LOG((3, "%s: grp->name %s", __func__, grp->name));
|
||||
|
||||
/* Recursively call this function for each child, if any, stopping
|
||||
* if there is an error. */
|
||||
@ -1143,7 +1135,7 @@ nc4_rec_grp_del(NC_GRP_INFO_T **list, NC_GRP_INFO_T *grp)
|
||||
att = grp->att;
|
||||
while (att)
|
||||
{
|
||||
LOG((4, "nc4_rec_grp_del: deleting att %s", att->name));
|
||||
LOG((4, "%s: deleting att %s", __func__, att->name));
|
||||
a = att->next;
|
||||
if ((retval = nc4_att_list_del(&grp->att, att)))
|
||||
return retval;
|
||||
@ -1154,11 +1146,10 @@ nc4_rec_grp_del(NC_GRP_INFO_T **list, NC_GRP_INFO_T *grp)
|
||||
var = grp->var;
|
||||
while (var)
|
||||
{
|
||||
LOG((4, "nc4_rec_grp_del: deleting var %s", var->name));
|
||||
LOG((4, "%s: deleting var %s", __func__, var->name));
|
||||
/* Close HDF5 dataset associated with this var, unless it's a
|
||||
* scale. */
|
||||
if (var->hdf_datasetid && !var->dimscale &&
|
||||
H5Dclose(var->hdf_datasetid) < 0)
|
||||
if (var->hdf_datasetid && H5Dclose(var->hdf_datasetid) < 0)
|
||||
return NC_EHDFERR;
|
||||
v = var->next;
|
||||
if ((retval = nc4_var_list_del(&grp->var, var)))
|
||||
@ -1170,7 +1161,7 @@ nc4_rec_grp_del(NC_GRP_INFO_T **list, NC_GRP_INFO_T *grp)
|
||||
dim = grp->dim;
|
||||
while (dim)
|
||||
{
|
||||
LOG((4, "nc4_rec_grp_del: deleting dim %s", dim->name));
|
||||
LOG((4, "%s: deleting dim %s", __func__, dim->name));
|
||||
/* Close HDF5 dataset associated with this dim. */
|
||||
if (dim->hdf_dimscaleid && H5Dclose(dim->hdf_dimscaleid) < 0)
|
||||
return NC_EHDFERR;
|
||||
@ -1184,7 +1175,7 @@ nc4_rec_grp_del(NC_GRP_INFO_T **list, NC_GRP_INFO_T *grp)
|
||||
type = grp->type;
|
||||
while (type)
|
||||
{
|
||||
LOG((4, "nc4_rec_grp_del: deleting type %s", type->name));
|
||||
LOG((4, "%s: deleting type %s", __func__, type->name));
|
||||
t = type->next;
|
||||
if ((retval = type_list_del(&grp->type, type)))
|
||||
return retval;
|
||||
@ -1192,7 +1183,7 @@ nc4_rec_grp_del(NC_GRP_INFO_T **list, NC_GRP_INFO_T *grp)
|
||||
}
|
||||
|
||||
/* Tell HDF5 we're closing this group. */
|
||||
LOG((4, "nc4_rec_grp_del: closing group %s", grp->name));
|
||||
LOG((4, "%s: closing group %s", __func__, grp->name));
|
||||
if (grp->hdf_grpid && H5Gclose(grp->hdf_grpid) < 0)
|
||||
return NC_EHDFERR;
|
||||
|
||||
@ -1262,6 +1253,113 @@ nc4_att_list_del(NC_ATT_INFO_T **list, NC_ATT_INFO_T *att)
|
||||
return NC_NOERR;
|
||||
}
|
||||
|
||||
/* Break a coordinate variable to separate the dimension and the variable */
|
||||
int
|
||||
nc4_break_coord_var(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *coord_var, NC_DIM_INFO_T *dim)
|
||||
{
|
||||
int retval = NC_NOERR;
|
||||
|
||||
/* Sanity checks */
|
||||
assert(dim->coord_var == coord_var);
|
||||
assert(coord_var->dim[0] == dim);
|
||||
assert(coord_var->dimids[0] == dim->dimid);
|
||||
assert(0 == dim->hdf_dimscaleid);
|
||||
|
||||
/* If we're replacing an existing dimscale dataset, go to
|
||||
* every var in the file and detach this dimension scale. */
|
||||
if ((retval = rec_detach_scales(grp->nc4_info->root_grp,
|
||||
dim->dimid, coord_var->hdf_datasetid)))
|
||||
return retval;
|
||||
|
||||
/* Allow attached dimscales to be tracked on the [former] coordinate variable */
|
||||
if (coord_var->ndims)
|
||||
{
|
||||
/* Coordinate variables shouldn't have dimscales attached */
|
||||
assert(NULL == coord_var->dimscale_attached);
|
||||
|
||||
/* Allocate space for tracking them */
|
||||
if (NULL == (coord_var->dimscale_attached = calloc(coord_var->ndims, sizeof(int))))
|
||||
return NC_ENOMEM;
|
||||
}
|
||||
|
||||
/* Detach dimension from variable */
|
||||
coord_var->dimscale = 0;
|
||||
coord_var->dirty++;
|
||||
dim->coord_var = NULL;
|
||||
|
||||
return NC_NOERR;
|
||||
}
|
||||
|
||||
/* Reform a coordinate variable from a dimension and a variable */
|
||||
int
|
||||
nc4_reform_coord_var(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var, NC_DIM_INFO_T *dim)
|
||||
{
|
||||
int retval = NC_NOERR;
|
||||
|
||||
/* Attach variable to dimension */
|
||||
var->dimscale++;
|
||||
var->dirty++;
|
||||
dim->coord_var = var;
|
||||
|
||||
/* Detach dimscales from the [new] coordinate variable */
|
||||
if(var->dimscale_attached)
|
||||
{
|
||||
int dims_detached = 0;
|
||||
int finished = 0;
|
||||
int d;
|
||||
|
||||
/* Loop over all dimensions for variable */
|
||||
for (d = 0; d < var->ndims && !finished; d++)
|
||||
/* Is there a dimscale attached to this axis? */
|
||||
if(var->dimscale_attached[d])
|
||||
{
|
||||
NC_GRP_INFO_T *g;
|
||||
|
||||
for (g = grp; g && !finished; g = g->parent)
|
||||
{
|
||||
NC_DIM_INFO_T *dim1;
|
||||
|
||||
for (dim1 = g->dim; dim1 && !finished; dim1 = dim1->next)
|
||||
if (var->dimids[d] == dim1->dimid)
|
||||
{
|
||||
hid_t dim_datasetid; /* Dataset ID for dimension */
|
||||
|
||||
/* Find dataset ID for dimension */
|
||||
if (dim1->coord_var)
|
||||
dim_datasetid = dim1->coord_var->hdf_datasetid;
|
||||
else
|
||||
dim_datasetid = dim1->hdf_dimscaleid;
|
||||
assert(dim_datasetid > 0);
|
||||
if (H5DSdetach_scale(var->hdf_datasetid, dim_datasetid, d) < 0)
|
||||
BAIL(NC_EHDFERR);
|
||||
var->dimscale_attached[d] = 0;
|
||||
if (dims_detached++ == var->ndims)
|
||||
finished++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Release & reset the array tracking attached dimscales */
|
||||
free(var->dimscale_attached);
|
||||
var->dimscale_attached = NULL;
|
||||
}
|
||||
|
||||
/* Use variable's dataset ID for the dimscale ID */
|
||||
if (dim->hdf_dimscaleid)
|
||||
{
|
||||
if (H5Dclose(dim->hdf_dimscaleid) < 0)
|
||||
BAIL(NC_EHDFERR);
|
||||
dim->hdf_dimscaleid = 0;
|
||||
|
||||
/* Now delete the dimscale's dataset (it will be recreated later, if necessary) */
|
||||
if (H5Gunlink(grp->hdf_grpid, dim->name) < 0)
|
||||
return NC_EDIMMETA;
|
||||
}
|
||||
|
||||
exit:
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* Normalize a UTF8 name. Put the result in norm_name, which can be
|
||||
* NC_MAX_NAME + 1 in size. This function makes sure the free() gets
|
||||
* called on the return from utf8proc_NFC, and also ensures that the
|
||||
|
107
libsrc4/nc4var.c
107
libsrc4/nc4var.c
@ -66,9 +66,6 @@ nc4_reopen_dataset(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var)
|
||||
#ifdef EXTRA_TESTS
|
||||
num_plists--;
|
||||
#endif
|
||||
|
||||
if (var->dimscale)
|
||||
var->dim[0]->hdf_dimscaleid = var->hdf_datasetid;
|
||||
}
|
||||
|
||||
return NC_NOERR;
|
||||
@ -293,8 +290,8 @@ nc4_find_default_chunksizes2(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var)
|
||||
if (suggested_size > var->dim[d]->len)
|
||||
suggested_size = var->dim[d]->len;
|
||||
var->chunksizes[d] = suggested_size ? suggested_size : 1;
|
||||
LOG((4, "nc_def_var_nc4: name %s dim %d DEFAULT_CHUNK_SIZE %d num_values %f type_size %d "
|
||||
"chunksize %ld", var->name, d, DEFAULT_CHUNK_SIZE, num_values, type_size, var->chunksizes[d]));
|
||||
LOG((4, "%s: name %s dim %d DEFAULT_CHUNK_SIZE %d num_values %f type_size %d "
|
||||
"chunksize %ld", __func__, var->name, d, DEFAULT_CHUNK_SIZE, num_values, type_size, var->chunksizes[d]));
|
||||
}
|
||||
|
||||
/* Find total chunk size. */
|
||||
@ -348,9 +345,7 @@ nc_def_var_nc4(int ncid, const char *name, nc_type xtype,
|
||||
NC_HDF5_FILE_INFO_T *h5;
|
||||
NC_TYPE_INFO_T *type_info;
|
||||
char norm_name[NC_MAX_NAME + 1];
|
||||
int num_unlim = 0;
|
||||
int d;
|
||||
size_t num_values = 1;
|
||||
int retval;
|
||||
|
||||
/* Find info for this file and group, and set pointer to each. */
|
||||
@ -406,14 +401,10 @@ nc_def_var_nc4(int ncid, const char *name, nc_type xtype,
|
||||
{
|
||||
if ((retval = nc4_find_dim(grp, dimidsp[d], &dim, NULL)))
|
||||
return retval;
|
||||
if (dim->unlimited)
|
||||
num_unlim++;
|
||||
else
|
||||
num_values *= dim->len;
|
||||
}
|
||||
|
||||
/* These degrubbing messages sure are handy! */
|
||||
LOG((3, "nc_def_var_nc4: name %s type %d ndims %d", norm_name, xtype, ndims));
|
||||
LOG((3, "%s: name %s type %d ndims %d", __func__, norm_name, xtype, ndims));
|
||||
#ifdef LOGGING
|
||||
{
|
||||
int dd;
|
||||
@ -455,8 +446,6 @@ nc_def_var_nc4(int ncid, const char *name, nc_type xtype,
|
||||
&var->type_info->size)))
|
||||
return retval;
|
||||
}
|
||||
if (!num_unlim)
|
||||
var->contiguous = 1;
|
||||
|
||||
/* Allocate space for dimension information. */
|
||||
if (ndims)
|
||||
@ -467,21 +456,49 @@ nc_def_var_nc4(int ncid, const char *name, nc_type xtype,
|
||||
return NC_ENOMEM;
|
||||
}
|
||||
|
||||
/* Assign dimensions to the variable */
|
||||
/* At the same time, check to see if this is a coordinate
|
||||
* variable. If so, it will have the same name as one of its
|
||||
* dimensions. If it is a coordinate var, is it a coordinate var in
|
||||
* the same group as the dim? */
|
||||
/* Also, check whether we should use contiguous or chunked storage */
|
||||
var->contiguous = 1;
|
||||
for (d = 0; d < ndims; d++)
|
||||
{
|
||||
NC_GRP_INFO_T *dim_grp;
|
||||
|
||||
/* Look up each dimension */
|
||||
if ((retval = nc4_find_dim(grp, dimidsp[d], &dim, &dim_grp)))
|
||||
return retval;
|
||||
if (strcmp(dim->name, norm_name) == 0 && dim_grp == grp && d == 0)
|
||||
|
||||
/* Check for dim index 0 having the same name, in the same group */
|
||||
if (d == 0 && dim_grp == grp && strcmp(dim->name, norm_name) == 0)
|
||||
{
|
||||
var->dimscale++;
|
||||
dim->coord_var = var;
|
||||
dim->coord_var_in_grp++;
|
||||
|
||||
/* Use variable's dataset ID for the dimscale ID */
|
||||
if (dim->hdf_dimscaleid)
|
||||
{
|
||||
/* Detach dimscale from any variables using it */
|
||||
if ((retval = rec_detach_scales(grp, dimidsp[d], dim->hdf_dimscaleid)) < 0)
|
||||
return retval;
|
||||
|
||||
if (H5Dclose(dim->hdf_dimscaleid) < 0)
|
||||
return NC_EHDFERR;
|
||||
dim->hdf_dimscaleid = 0;
|
||||
|
||||
/* Now delete the dataset (it will be recreated later, if necessary) */
|
||||
if (H5Gunlink(grp->hdf_grpid, dim->name) < 0)
|
||||
return NC_EDIMMETA;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check for unlimited dimension and turn off contiguous storage */
|
||||
if (dim->unlimited)
|
||||
var->contiguous = 0;
|
||||
|
||||
/* Track dimensions for variable */
|
||||
var->dimids[d] = dimidsp[d];
|
||||
var->dim[d] = dim;
|
||||
}
|
||||
@ -547,8 +564,8 @@ NC4_def_var(int ncid, const char *name, nc_type xtype, int ndims,
|
||||
NC *nc;
|
||||
NC_HDF5_FILE_INFO_T *h5;
|
||||
|
||||
LOG((2, "nc_def_var: ncid 0x%x name %s xtype %d ndims %d",
|
||||
ncid, name, xtype, ndims));
|
||||
LOG((2, "%s: ncid 0x%x name %s xtype %d ndims %d",
|
||||
__func__, ncid, name, xtype, ndims));
|
||||
|
||||
/* If there are dimensions, I need their ids. */
|
||||
if (ndims && !dimidsp)
|
||||
@ -596,7 +613,7 @@ NC4_inq_var_all(int ncid, int varid, char *name, nc_type *xtypep,
|
||||
int d;
|
||||
int retval;
|
||||
|
||||
LOG((2, "nc_inq_var_all: ncid 0x%x varid %d", ncid, varid));
|
||||
LOG((2, "%s: ncid 0x%x varid %d", __func__, ncid, varid));
|
||||
|
||||
/* Find info for this file and group, and set pointer to each. */
|
||||
if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
|
||||
@ -726,7 +743,7 @@ nc_def_var_extra(int ncid, int varid, int *shuffle, int *deflate,
|
||||
int d;
|
||||
int retval;
|
||||
|
||||
LOG((2, "nc_def_var_extra: ncid 0x%x varid %d", ncid, varid));
|
||||
LOG((2, "%s: ncid 0x%x varid %d", __func__, ncid, varid));
|
||||
|
||||
/* Find info for this file and group, and set pointer to each. */
|
||||
if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
|
||||
@ -786,7 +803,7 @@ nc_def_var_extra(int ncid, int varid, int *shuffle, int *deflate,
|
||||
var->deflate = *deflate;
|
||||
if (*deflate)
|
||||
var->deflate_level = *deflate_level;
|
||||
LOG((3, "nc_def_var_extra: *deflate_level %d", *deflate_level));
|
||||
LOG((3, "%s: *deflate_level %d", __func__, *deflate_level));
|
||||
}
|
||||
|
||||
/* Szip in use? */
|
||||
@ -1070,7 +1087,7 @@ NC4_inq_varid(int ncid, const char *name, int *varidp)
|
||||
if (!varidp)
|
||||
return NC_NOERR;
|
||||
|
||||
LOG((2, "nc_inq_varid: ncid 0x%x name %s", ncid, name));
|
||||
LOG((2, "%s: ncid 0x%x name %s", __func__, ncid, name));
|
||||
|
||||
/* Find info for this file and group, and set pointer to each. */
|
||||
if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, NULL)))
|
||||
@ -1114,8 +1131,8 @@ NC4_rename_var(int ncid, int varid, const char *name)
|
||||
NC_VAR_INFO_T *var;
|
||||
int retval = NC_NOERR;
|
||||
|
||||
LOG((2, "nc_rename_var: ncid 0x%x varid %d name %s",
|
||||
ncid, varid, name));
|
||||
LOG((2, "%s: ncid 0x%x varid %d name %s",
|
||||
__func__, ncid, varid, name));
|
||||
|
||||
/* Find info for this file and group, and set pointer to each. */
|
||||
if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
|
||||
@ -1174,6 +1191,38 @@ NC4_rename_var(int ncid, int varid, const char *name)
|
||||
return NC_ENOMEM;
|
||||
strcpy(var->name, name);
|
||||
|
||||
/* Check if this was a coordinate variable previously, but names are different now */
|
||||
if (var->dimscale && strcmp(var->name, var->dim[0]->name))
|
||||
{
|
||||
/* Break up the coordinate variable */
|
||||
if ((retval = nc4_break_coord_var(grp, var, var->dim[0])))
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* Check if this should become a coordinate variable */
|
||||
if (!var->dimscale)
|
||||
{
|
||||
/* Only variables with >0 dimensions can become coordinate variables */
|
||||
if (var->ndims)
|
||||
{
|
||||
NC_GRP_INFO_T *dim_grp;
|
||||
NC_DIM_INFO_T *dim;
|
||||
|
||||
/* Check to see if this is became a coordinate variable. If so, it
|
||||
* will have the same name as dimension index 0. If it is a
|
||||
* coordinate var, is it a coordinate var in the same group as the dim?
|
||||
*/
|
||||
if ((retval = nc4_find_dim(grp, var->dimids[0], &dim, &dim_grp)))
|
||||
return retval;
|
||||
if (strcmp(dim->name, name) == 0 && dim_grp == grp)
|
||||
{
|
||||
/* Reform the coordinate variable */
|
||||
if ((retval = nc4_reform_coord_var(grp, var, dim)))
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exit:
|
||||
return retval;
|
||||
}
|
||||
@ -1191,7 +1240,7 @@ NC4_var_par_access(int ncid, int varid, int par_access)
|
||||
NC_VAR_INFO_T *var;
|
||||
int retval;
|
||||
|
||||
LOG((1, "nc_var_par_access: ncid 0x%x varid %d par_access %d", ncid,
|
||||
LOG((1, "%s: ncid 0x%x varid %d par_access %d", __func__, ncid,
|
||||
varid, par_access));
|
||||
|
||||
if (par_access != NC_INDEPENDENT && par_access != NC_COLLECTIVE)
|
||||
@ -1245,8 +1294,8 @@ nc4_put_vara_tc(int ncid, int varid, nc_type mem_type, int mem_type_is_long,
|
||||
NC_HDF5_FILE_INFO_T *h5;
|
||||
#endif
|
||||
|
||||
LOG((2, "nc4_put_vara_tc: ncid 0x%x varid %d mem_type %d mem_type_is_long %d",
|
||||
ncid, varid, mem_type, mem_type_is_long));
|
||||
LOG((2, "%s: ncid 0x%x varid %d mem_type %d mem_type_is_long %d",
|
||||
__func__, ncid, varid, mem_type, mem_type_is_long));
|
||||
|
||||
if (!(nc = nc4_find_nc_file(ncid,NULL)))
|
||||
return NC_EBADID;
|
||||
@ -1375,8 +1424,8 @@ nc4_get_vara_tc(int ncid, int varid, nc_type mem_type, int mem_type_is_long,
|
||||
NC *nc;
|
||||
NC_HDF5_FILE_INFO_T* h5;
|
||||
|
||||
LOG((2, "nc4_get_vara_tc: ncid 0x%x varid %d mem_type %d mem_type_is_long %d",
|
||||
ncid, varid, mem_type, mem_type_is_long));
|
||||
LOG((2, "%s: ncid 0x%x varid %d mem_type %d mem_type_is_long %d",
|
||||
__func__, ncid, varid, mem_type, mem_type_is_long));
|
||||
|
||||
if (!(nc = nc4_find_nc_file(ncid,&h5)))
|
||||
return NC_EBADID;
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define LOGGING
|
||||
#include "netcdf.h"
|
||||
|
@ -15,7 +15,6 @@
|
||||
#define LEVEL_NAME "level"
|
||||
#define TIME_NAME "time"
|
||||
#define DIM5_NAME "twilight_zone"
|
||||
#define DIM_NAME "dim"
|
||||
#define LAT_LEN 1
|
||||
#define LON_LEN 2
|
||||
#define LEVEL_LEN 3
|
||||
@ -171,6 +170,153 @@ main(int argc, char **argv)
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** Testing renaming dimensions and vars...");
|
||||
{
|
||||
#define FILE_NAME1 "foo1.nc"
|
||||
#define FILE_NAME2 "foo2.nc"
|
||||
#define FILE_NAME3 "foo3.nc"
|
||||
#define FILE_NAME4 "foo4.nc"
|
||||
#define DIM_NAME "lat_T42"
|
||||
#define VAR_NAME DIM_NAME
|
||||
#define DIM_NAME2 "lat"
|
||||
#define VAR_NAME2 DIM_NAME2
|
||||
#define RANK_lat_T42 1
|
||||
int ncid, varid, dimid;
|
||||
int lat_T42_dim;
|
||||
size_t lat_T42_len = 3;
|
||||
int lat_T42_id;
|
||||
int lat_T42_dims[RANK_lat_T42];
|
||||
char name[NC_MAX_NAME + 1];
|
||||
|
||||
/* =========== */
|
||||
/* Sub-test #1 */
|
||||
/* =========== */
|
||||
/* create file with dimension and associated coordinate variable */
|
||||
if (nc_create(FILE_NAME1, NC_CLOBBER|NC_NETCDF4|NC_CLASSIC_MODEL, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, DIM_NAME, lat_T42_len, &lat_T42_dim)) ERR;
|
||||
lat_T42_dims[0] = lat_T42_dim;
|
||||
if (nc_def_var(ncid, VAR_NAME, NC_INT, RANK_lat_T42, lat_T42_dims, &lat_T42_id)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
|
||||
/* reopen file, rename coordinate dimension and then associated variable */
|
||||
if (nc_open(FILE_NAME1, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_inq_dimid(ncid, DIM_NAME, &dimid)) ERR;
|
||||
if (nc_inq_varid(ncid, VAR_NAME, &varid)) ERR;
|
||||
if (nc_rename_dim(ncid, dimid, DIM_NAME2)) ERR;
|
||||
if (nc_rename_var(ncid, varid, VAR_NAME2)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
|
||||
/* reopen file, check coordinate dimension and associated variable names */
|
||||
/* Should be just like they created the file with DIM_NAME2 & VAR_NAME2 to
|
||||
* begin with.
|
||||
*/
|
||||
if (nc_open(FILE_NAME1, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_inq_dimid(ncid, DIM_NAME2, &dimid)) ERR;
|
||||
if (nc_inq_varid(ncid, VAR_NAME2, &varid)) ERR;
|
||||
if (nc_inq_dimname(ncid, dimid, name)) ERR;
|
||||
if (strcmp(name, DIM_NAME2)) ERR;
|
||||
if (nc_inq_varname(ncid, varid, name)) ERR;
|
||||
if (strcmp(name, VAR_NAME2)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
|
||||
/* =========== */
|
||||
/* Sub-test #2 */
|
||||
/* =========== */
|
||||
/* create file with dimension and associated coordinate variable */
|
||||
if (nc_create(FILE_NAME1, NC_CLOBBER|NC_NETCDF4|NC_CLASSIC_MODEL, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, DIM_NAME, lat_T42_len, &lat_T42_dim)) ERR;
|
||||
lat_T42_dims[0] = lat_T42_dim;
|
||||
if (nc_def_var(ncid, VAR_NAME, NC_INT, RANK_lat_T42, lat_T42_dims, &lat_T42_id)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
|
||||
/* reopen file, just rename coordinate dimension */
|
||||
if (nc_open(FILE_NAME1, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_inq_dimid(ncid, DIM_NAME, &dimid)) ERR;
|
||||
if (nc_rename_dim(ncid, dimid, DIM_NAME2)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
|
||||
/* reopen file, check coordinate dimension and associated variable names */
|
||||
/* Should be just like the file was created with DIM_NAME2 to begin with */
|
||||
if (nc_open(FILE_NAME1, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_inq_dimid(ncid, DIM_NAME2, &dimid)) ERR;
|
||||
if (nc_inq_varid(ncid, VAR_NAME, &varid)) ERR;
|
||||
if (nc_inq_dimname(ncid, dimid, name)) ERR;
|
||||
if (strcmp(name, DIM_NAME2)) ERR;
|
||||
if (nc_inq_varname(ncid, varid, name)) ERR;
|
||||
if (strcmp(name, VAR_NAME)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
|
||||
/* =========== */
|
||||
/* Sub-test #3 */
|
||||
/* =========== */
|
||||
/* create file with dimension and associated coordinate variable */
|
||||
if (nc_create(FILE_NAME1, NC_CLOBBER|NC_NETCDF4|NC_CLASSIC_MODEL, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, DIM_NAME, lat_T42_len, &lat_T42_dim)) ERR;
|
||||
lat_T42_dims[0] = lat_T42_dim;
|
||||
if (nc_def_var(ncid, VAR_NAME, NC_INT, RANK_lat_T42, lat_T42_dims, &lat_T42_id)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
|
||||
/* reopen file, just rename variable */
|
||||
if (nc_open(FILE_NAME1, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_inq_varid(ncid, VAR_NAME, &varid)) ERR;
|
||||
if (nc_rename_var(ncid, varid, VAR_NAME2)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
|
||||
/* reopen file, check coordinate dimension and associated variable names */
|
||||
/* Should be just like the file was created with VAR_NAME2 to begin with */
|
||||
if (nc_open(FILE_NAME1, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_inq_dimid(ncid, DIM_NAME, &dimid)) ERR;
|
||||
if (nc_inq_varid(ncid, VAR_NAME2, &varid)) ERR;
|
||||
if (nc_inq_dimname(ncid, dimid, name)) ERR;
|
||||
if (strcmp(name, DIM_NAME)) ERR;
|
||||
if (nc_inq_varname(ncid, varid, name)) ERR;
|
||||
if (strcmp(name, VAR_NAME2)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
|
||||
/* =========== */
|
||||
/* Sub-test #4 */
|
||||
/* =========== */
|
||||
/* create file with dimension and associated coordinate variable */
|
||||
if (nc_create(FILE_NAME1, NC_CLOBBER|NC_NETCDF4|NC_CLASSIC_MODEL, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, DIM_NAME, lat_T42_len, &lat_T42_dim)) ERR;
|
||||
lat_T42_dims[0] = lat_T42_dim;
|
||||
if (nc_def_var(ncid, VAR_NAME, NC_INT, RANK_lat_T42, lat_T42_dims, &lat_T42_id)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
|
||||
/* reopen file, rename associated variable and then coordinate dimension */
|
||||
if (nc_open(FILE_NAME1, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_inq_dimid(ncid, DIM_NAME, &dimid)) ERR;
|
||||
if (nc_inq_varid(ncid, VAR_NAME, &varid)) ERR;
|
||||
if (nc_rename_var(ncid, varid, VAR_NAME2)) ERR;
|
||||
if (nc_rename_dim(ncid, dimid, DIM_NAME2)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
|
||||
/* reopen file, check coordinate dimension and associated variable names */
|
||||
/* Should be just like they created the file with DIM_NAME2 & VAR_NAME2 to
|
||||
* begin with.
|
||||
*/
|
||||
if (nc_open(FILE_NAME1, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_inq_dimid(ncid, DIM_NAME2, &dimid)) ERR;
|
||||
if (nc_inq_varid(ncid, VAR_NAME2, &varid)) ERR;
|
||||
if (nc_inq_dimname(ncid, dimid, name)) ERR;
|
||||
if (strcmp(name, DIM_NAME2)) ERR;
|
||||
if (nc_inq_varname(ncid, varid, name)) ERR;
|
||||
if (strcmp(name, VAR_NAME2)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** Testing file with just one unlimited dimension...");
|
||||
{
|
||||
|
@ -68,9 +68,6 @@ main(int argc, char **argv)
|
||||
* Christian! Next time I'm in Rostock I'll come by and buy you
|
||||
* a beer. ;-) */
|
||||
#define TL 15
|
||||
#define SHUFFLE 0
|
||||
#define DEFLATE 1
|
||||
#define DEFLATE_LEVEL 5
|
||||
int ncid;
|
||||
int time_dim;
|
||||
int tl_dim;
|
||||
@ -137,9 +134,6 @@ main(int argc, char **argv)
|
||||
* Christian! Next time I'm in Rostock I'll come by and buy you
|
||||
* a beer. ;-) */
|
||||
#define TL 15
|
||||
#define SHUFFLE 0
|
||||
#define DEFLATE 1
|
||||
#define DEFLATE_LEVEL 5
|
||||
#define NDIMS2 2
|
||||
#define NUM_TIMES 16
|
||||
int ncid;
|
||||
@ -247,7 +241,6 @@ main(int argc, char **argv)
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** Checking multiple unlimited dimensions...");
|
||||
{
|
||||
#define MAX(x,y) ((x)>(y)?(x):(y))
|
||||
#define NDIMS 2
|
||||
#define MAX_VALUES 3
|
||||
|
||||
|
@ -53,6 +53,7 @@ int test_pio(int);
|
||||
int test_pio_attr(int);
|
||||
int test_pio_big(int);
|
||||
int test_pio_hyper(int);
|
||||
int test_pio_extend(int);
|
||||
|
||||
char* getenv_all(MPI_Comm comm, int root, const char* name);
|
||||
int facc_type;
|
||||
|
@ -17,6 +17,7 @@ void
|
||||
define_netcdf(void)
|
||||
{
|
||||
char filename[2048+1];
|
||||
const char *fname;
|
||||
|
||||
/* Rule for specifying the dataset name:
|
||||
1. use -o name
|
||||
@ -28,37 +29,43 @@ define_netcdf(void)
|
||||
*/
|
||||
if(netcdf_name) { /* -o flag name */
|
||||
strcpy(filename,netcdf_name);
|
||||
fname = filename;
|
||||
} else { /* construct a usable output file name */
|
||||
if (cdlname != NULL && strcmp(cdlname,"-") != 0) {/* cmd line name */
|
||||
char* p;
|
||||
|
||||
strncpy(filename,cdlname,2048);
|
||||
/* remove any suffix and prefix*/
|
||||
p = strrchr(filename,'.');
|
||||
if(p != NULL) {*p= '\0';}
|
||||
p = strrchr(filename,'/');
|
||||
if(p != NULL) {strncpy(filename,p+1,2048);}
|
||||
if(p != NULL)
|
||||
fname = p + 1;
|
||||
else
|
||||
fname = filename;
|
||||
} else {/* construct name from dataset name */
|
||||
strncpy(filename,datasetname,2048); /* Reserve space for extension, terminating '\0' */
|
||||
fname = filename;
|
||||
}
|
||||
/* Append the proper extension */
|
||||
strcat(filename,binary_ext);
|
||||
strcat(fname,binary_ext);
|
||||
}
|
||||
|
||||
/* Execute exactly one of these */
|
||||
#ifdef ENABLE_C
|
||||
if (l_flag == L_C) gen_ncc(filename); else /* create C code to create netcdf */
|
||||
if (l_flag == L_C) gen_ncc(fname); else /* create C code to create netcdf */
|
||||
#endif
|
||||
#ifdef ENABLE_F77
|
||||
if (l_flag == L_F77) gen_ncf77(filename); else /* create Fortran code */
|
||||
if (l_flag == L_F77) gen_ncf77(fname); else /* create Fortran code */
|
||||
#endif
|
||||
#ifdef ENABLE_JAVA
|
||||
if(l_flag == L_JAVA) {
|
||||
gen_ncjava(filename);
|
||||
gen_ncjava(fname);
|
||||
} else
|
||||
#endif
|
||||
/* Binary is the default */
|
||||
#ifdef ENABLE_BINARY
|
||||
gen_netcdf(filename); /* create netcdf */
|
||||
gen_netcdf(fname); /* create netcdf */
|
||||
#else
|
||||
derror("No language specified");
|
||||
#endif
|
||||
|
@ -9,6 +9,7 @@
|
||||
#define MAX_NC_ATTSIZE 20000 /* max size of attribute (for ncgen) */
|
||||
#define MAXTRST 5000 /* max size of string value (for ncgen) */
|
||||
|
||||
#include "config.h"
|
||||
#include "generic.h"
|
||||
|
||||
extern int ncid; /* handle for netCDF */
|
||||
|
Loading…
Reference in New Issue
Block a user