15 #include "hdf5internal.h"
18 extern int NC4_extract_file_image(NC_FILE_INFO_T* h5);
20 static void dumpopenobjects(NC_FILE_INFO_T* h5);
33 static const NC_reservedatt NC_reserved[NRESERVED] = {
34 {NC_ATT_CLASS, READONLYFLAG|DIMSCALEFLAG},
35 {NC_ATT_DIMENSION_LIST, READONLYFLAG|DIMSCALEFLAG},
36 {NC_ATT_NAME, READONLYFLAG|DIMSCALEFLAG},
37 {NC_ATT_REFERENCE_LIST, READONLYFLAG|DIMSCALEFLAG},
38 {NC_ATT_FORMAT, READONLYFLAG},
39 {ISNETCDF4ATT, READONLYFLAG|NAMEONLYFLAG},
40 {NCPROPS, READONLYFLAG|NAMEONLYFLAG|MATERIALIZEDFLAG},
41 {NC_ATT_COORDINATES, READONLYFLAG|DIMSCALEFLAG|MATERIALIZEDFLAG},
42 {NC_DIMID_ATT_NAME, READONLYFLAG|DIMSCALEFLAG|MATERIALIZEDFLAG},
43 {SUPERBLOCKATT, READONLYFLAG|NAMEONLYFLAG},
44 {NC3_STRICT_ATT_NAME, READONLYFLAG|MATERIALIZEDFLAG},
48 static int NC4_enddef(
int ncid);
49 static void dumpopenobjects(NC_FILE_INFO_T* h5);
59 NC_findreserved(
const char* name)
67 const NC_reservedatt* p = &NC_reserved[m];
68 int cmp = strcmp(p->name,name);
69 if(cmp == 0)
return p;
95 detect_preserve_dimids(NC_GRP_INFO_T *grp, nc_bool_t *bad_coord_orderp)
98 NC_GRP_INFO_T *child_grp;
104 for (i=0; i < ncindexsize(grp->vars); i++)
106 var = (NC_VAR_INFO_T*)ncindexith(grp->vars,i);
107 if (var == NULL)
continue;
109 if (var->dimscale && var->ndims)
115 if (var->dimids[0] < last_dimid)
117 LOG((5,
"%s: %s is out of order coord var", __func__, var->hdr.name));
118 *bad_coord_orderp = NC_TRUE;
121 last_dimid = var->dimids[0];
128 LOG((5,
"%s: %s is multidimensional coord var", __func__, var->hdr.name));
129 *bad_coord_orderp = NC_TRUE;
136 if (var->is_new_var || var->became_coord_var)
138 LOG((5,
"%s: coord var defined after enddef/redef", __func__));
139 *bad_coord_orderp = NC_TRUE;
146 for (i = 0; i < ncindexsize(grp->children); i++)
148 if (!(child_grp = (NC_GRP_INFO_T *)ncindexith(grp->children, i)))
150 if ((retval = detect_preserve_dimids(child_grp, bad_coord_orderp)))
168 sync_netcdf4_file(NC_FILE_INFO_T *h5)
170 NC_HDF5_FILE_INFO_T *hdf5_info;
173 assert(h5 && h5->format_file_info);
174 LOG((3,
"%s", __func__));
178 if (h5->flags & NC_INDEF)
184 h5->flags ^= NC_INDEF;
187 h5->redef = NC_FALSE;
199 nc_bool_t bad_coord_order = NC_FALSE;
202 if ((retval = nc4_rec_write_groups_types(h5->root_grp)))
208 if ((retval = detect_preserve_dimids(h5->root_grp, &bad_coord_order)))
212 if ((retval = nc4_rec_write_metadata(h5->root_grp, bad_coord_order)))
216 if((retval = NC4_write_ncproperties(h5)))
221 hdf5_info = (NC_HDF5_FILE_INFO_T *)h5->format_file_info;
222 if (H5Fflush(hdf5_info->hdfid, H5F_SCOPE_GLOBAL) < 0)
244 nc4_close_netcdf4_file(NC_FILE_INFO_T *h5,
int abort,
NC_memio *memio)
246 NC_HDF5_FILE_INFO_T *hdf5_info;
249 assert(h5 && h5->root_grp && h5->format_file_info);
250 LOG((3,
"%s: h5->path %s abort %d", __func__, h5->controller->path, abort));
253 hdf5_info = (NC_HDF5_FILE_INFO_T *)h5->format_file_info;
257 if ((retval = nc4_rec_grp_del(h5->root_grp)))
261 nclistfree(h5->alldims);
262 nclistfree(h5->allgroups);
263 nclistfree(h5->alltypes);
270 if (h5->comm != MPI_COMM_NULL)
271 MPI_Comm_free(&h5->comm);
272 if (h5->info != MPI_INFO_NULL)
273 MPI_Info_free(&h5->info);
280 NC4_free_provenance(h5->provenance);
281 h5->provenance = NULL;
285 if (hdf5_info->hdfid > 0 && H5Fclose(hdf5_info->hdfid) < 0)
293 if(h5->mem.inmemory) {
295 (void)NC4_extract_file_image(h5);
296 if(!abort && memio != NULL) {
297 *memio = h5->mem.memio;
298 h5->mem.memio.memory = NULL;
301 if(h5->mem.memio.memory != NULL) {
305 free(h5->mem.memio.memory);
307 h5->mem.memio.memory = NULL;
308 h5->mem.memio.size = 0;
309 NC4_image_finalize(h5->mem.udata);
313 if (h5->format_file_info)
314 free(h5->format_file_info);
337 nc4_close_hdf5_file(NC_FILE_INFO_T *h5,
int abort,
NC_memio *memio)
341 assert(h5 && h5->root_grp && h5->format_file_info);
342 LOG((3,
"%s: h5->path %s abort %d", __func__, h5->controller->path, abort));
345 if (h5->flags & NC_INDEF)
346 h5->flags ^= NC_INDEF;
350 if (!h5->no_write && !abort)
351 if ((retval = sync_netcdf4_file(h5)))
355 if ((retval = nc4_rec_grp_HDF5_del(h5->root_grp)))
360 if ((retval = nc4_close_netcdf4_file(h5, abort, memio)))
375 dumpopenobjects(NC_FILE_INFO_T* h5)
377 NC_HDF5_FILE_INFO_T *hdf5_info;
380 assert(h5 && h5->format_file_info);
381 hdf5_info = (NC_HDF5_FILE_INFO_T *)h5->format_file_info;
383 if(hdf5_info->hdfid <= 0)
386 nobjs = H5Fget_obj_count(hdf5_info->hdfid, H5F_OBJ_ALL);
391 }
else if(nobjs > 0) {
398 snprintf(msg,
sizeof(msg),
"There are %d HDF5 objects open!", nobjs);
405 fprintf(stdout,
"%s\n",msg);
408 reportopenobjects(logit,hdf5_info->hdfid);
430 NC4_set_fill(
int ncid,
int fillmode,
int *old_modep)
432 NC_FILE_INFO_T *nc4_info;
435 LOG((2,
"%s: ncid 0x%x fillmode %d", __func__, ncid, fillmode));
438 if ((retval = nc4_find_grp_h5(ncid, NULL, &nc4_info)))
443 if (nc4_info->no_write)
452 *old_modep = nc4_info->fill_mode;
454 nc4_info->fill_mode = fillmode;
471 NC_FILE_INFO_T *nc4_info;
474 LOG((1,
"%s: ncid 0x%x", __func__, ncid));
477 if ((retval = nc4_find_grp_h5(ncid, NULL, &nc4_info)))
482 if (nc4_info->flags & NC_INDEF)
486 if (nc4_info->no_write)
490 nc4_info->flags |= NC_INDEF;
494 nc4_info->redef = NC_TRUE;
513 NC4__enddef(
int ncid,
size_t h_minfree,
size_t v_align,
514 size_t v_minfree,
size_t r_align)
516 return NC4_enddef(ncid);
533 NC_FILE_INFO_T *nc4_info;
539 LOG((1,
"%s: ncid 0x%x", __func__, ncid));
542 if ((retval = nc4_find_grp_h5(ncid, &grp, &nc4_info)))
546 for (i = 0; i < ncindexsize(grp->vars); i++)
548 var = (NC_VAR_INFO_T *)ncindexith(grp->vars, i);
550 var->written_to = NC_TRUE;
553 return nc4_enddef_netcdf4_file(nc4_info);
570 NC_FILE_INFO_T *nc4_info;
573 LOG((2,
"%s: ncid 0x%x", __func__, ncid));
575 if ((retval = nc4_find_grp_h5(ncid, NULL, &nc4_info)))
580 if (nc4_info->flags & NC_INDEF)
584 if ((retval = NC4_enddef(ncid)))
588 return sync_netcdf4_file(nc4_info);
608 NC_FILE_INFO_T *nc4_info;
613 LOG((2,
"%s: ncid 0x%x", __func__, ncid));
616 if ((retval = nc4_find_nc_grp_h5(ncid, &nc, NULL, &nc4_info)))
621 if (nc4_info->flags & NC_INDEF && !nc4_info->redef)
629 if ((retval = nc4_close_hdf5_file(nc4_info, 1, NULL)))
634 if (
remove(path) < 0)
650 NC4_close(
int ncid,
void* params)
658 LOG((1,
"%s: ncid 0x%x", __func__, ncid));
661 if ((retval = nc4_find_grp_h5(ncid, &grp, &h5)))
672 if(inmemory && params != NULL) {
677 if ((retval = nc4_close_hdf5_file(grp->nc4_info, 0, memio)))
701 NC4_inq(
int ncid,
int *ndimsp,
int *nvarsp,
int *nattsp,
int *unlimdimidp)
709 LOG((2,
"%s: ncid 0x%x", __func__, ncid));
712 if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
715 assert(h5 && grp && nc);
721 *ndimsp = ncindexcount(grp->dim);
725 *nvarsp = ncindexcount(grp->vars);
731 if ((retval = nc4_read_atts(grp, NULL)))
734 *nattsp = ncindexcount(grp->att);
746 for(i=0;i<ncindexsize(grp->dim);i++) {
747 NC_DIM_INFO_T* d = (NC_DIM_INFO_T*)ncindexith(grp->dim,i);
748 if(d == NULL)
continue;
750 *unlimdimidp = d->hdr.id;
769 nc4_enddef_netcdf4_file(NC_FILE_INFO_T *h5)
772 LOG((3,
"%s", __func__));
775 if (!(h5->flags & NC_INDEF))
779 h5->flags ^= NC_INDEF;
782 h5->redef = NC_FALSE;
784 return sync_netcdf4_file(h5);
#define NC_CLASSIC_MODEL
Enforce classic model on netCDF-4.
#define NC_INMEMORY
Read from memory.
#define NC_EHDFERR
Error at HDF5 layer.
#define NC_ENOTINDEFINE
Operation not allowed in data mode.
#define NC_EINDEFINE
Operation not allowed in define mode.
#define NC_EINVAL
Invalid Argument.
#define NC_EBADGRPID
Bad group ID.
#define NC_NOFILL
Argument to nc_set_fill() to turn off filling of data.
#define NC_MAX_NAME
Maximum for classic library.
#define NC_ECANTREMOVE
Can't remove file.
#define NC_EPERM
Write to read only.
#define NC_NOERR
No Error.
#define NC_FILL
Argument to nc_set_fill() to clear NC_NOFILL.