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_provenance(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);
279 NC4_clear_provenance(&h5->provenance);
283 if (hdf5_info->hdfid > 0 && H5Fclose(hdf5_info->hdfid) < 0)
291 if(h5->mem.inmemory) {
293 (void)NC4_extract_file_image(h5);
294 if(!abort && memio != NULL) {
295 *memio = h5->mem.memio;
296 h5->mem.memio.memory = NULL;
299 if(h5->mem.memio.memory != NULL) {
303 free(h5->mem.memio.memory);
305 h5->mem.memio.memory = NULL;
306 h5->mem.memio.size = 0;
307 NC4_image_finalize(h5->mem.udata);
311 if (h5->format_file_info)
312 free(h5->format_file_info);
335 nc4_close_hdf5_file(NC_FILE_INFO_T *h5,
int abort,
NC_memio *memio)
339 assert(h5 && h5->root_grp && h5->format_file_info);
340 LOG((3,
"%s: h5->path %s abort %d", __func__, h5->controller->path, abort));
343 if (h5->flags & NC_INDEF)
344 h5->flags ^= NC_INDEF;
348 if (!h5->no_write && !abort)
349 if ((retval = sync_netcdf4_file(h5)))
353 if ((retval = nc4_rec_grp_HDF5_del(h5->root_grp)))
358 if ((retval = nc4_close_netcdf4_file(h5, abort, memio)))
373 dumpopenobjects(NC_FILE_INFO_T* h5)
375 NC_HDF5_FILE_INFO_T *hdf5_info;
378 assert(h5 && h5->format_file_info);
379 hdf5_info = (NC_HDF5_FILE_INFO_T *)h5->format_file_info;
381 if(hdf5_info->hdfid <= 0)
384 nobjs = H5Fget_obj_count(hdf5_info->hdfid, H5F_OBJ_ALL);
389 }
else if(nobjs > 0) {
396 snprintf(msg,
sizeof(msg),
"There are %d HDF5 objects open!", nobjs);
403 fprintf(stdout,
"%s\n",msg);
406 reportopenobjects(logit,hdf5_info->hdfid);
428 NC4_set_fill(
int ncid,
int fillmode,
int *old_modep)
430 NC_FILE_INFO_T *nc4_info;
433 LOG((2,
"%s: ncid 0x%x fillmode %d", __func__, ncid, fillmode));
436 if ((retval = nc4_find_grp_h5(ncid, NULL, &nc4_info)))
441 if (nc4_info->no_write)
450 *old_modep = nc4_info->fill_mode;
452 nc4_info->fill_mode = fillmode;
469 NC_FILE_INFO_T *nc4_info;
472 LOG((1,
"%s: ncid 0x%x", __func__, ncid));
475 if ((retval = nc4_find_grp_h5(ncid, NULL, &nc4_info)))
480 if (nc4_info->flags & NC_INDEF)
484 if (nc4_info->no_write)
488 nc4_info->flags |= NC_INDEF;
492 nc4_info->redef = NC_TRUE;
511 NC4__enddef(
int ncid,
size_t h_minfree,
size_t v_align,
512 size_t v_minfree,
size_t r_align)
514 return NC4_enddef(ncid);
531 NC_FILE_INFO_T *nc4_info;
537 LOG((1,
"%s: ncid 0x%x", __func__, ncid));
540 if ((retval = nc4_find_grp_h5(ncid, &grp, &nc4_info)))
544 for (i = 0; i < ncindexsize(grp->vars); i++)
546 var = (NC_VAR_INFO_T *)ncindexith(grp->vars, i);
548 var->written_to = NC_TRUE;
551 return nc4_enddef_netcdf4_file(nc4_info);
568 NC_FILE_INFO_T *nc4_info;
571 LOG((2,
"%s: ncid 0x%x", __func__, ncid));
573 if ((retval = nc4_find_grp_h5(ncid, NULL, &nc4_info)))
578 if (nc4_info->flags & NC_INDEF)
582 if ((retval = NC4_enddef(ncid)))
586 return sync_netcdf4_file(nc4_info);
606 NC_FILE_INFO_T *nc4_info;
611 LOG((2,
"%s: ncid 0x%x", __func__, ncid));
614 if ((retval = nc4_find_nc_grp_h5(ncid, &nc, NULL, &nc4_info)))
619 if (nc4_info->flags & NC_INDEF && !nc4_info->redef)
627 if ((retval = nc4_close_hdf5_file(nc4_info, 1, NULL)))
632 if (
remove(path) < 0)
648 NC4_close(
int ncid,
void* params)
656 LOG((1,
"%s: ncid 0x%x", __func__, ncid));
659 if ((retval = nc4_find_grp_h5(ncid, &grp, &h5)))
670 if(inmemory && params != NULL) {
675 if ((retval = nc4_close_hdf5_file(grp->nc4_info, 0, memio)))
699 NC4_inq(
int ncid,
int *ndimsp,
int *nvarsp,
int *nattsp,
int *unlimdimidp)
707 LOG((2,
"%s: ncid 0x%x", __func__, ncid));
710 if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
713 assert(h5 && grp && nc);
719 *ndimsp = ncindexcount(grp->dim);
723 *nvarsp = ncindexcount(grp->vars);
729 if ((retval = nc4_read_atts(grp, NULL)))
732 *nattsp = ncindexcount(grp->att);
744 for(i=0;i<ncindexsize(grp->dim);i++) {
745 NC_DIM_INFO_T* d = (NC_DIM_INFO_T*)ncindexith(grp->dim,i);
746 if(d == NULL)
continue;
748 *unlimdimidp = d->hdr.id;
767 nc4_enddef_netcdf4_file(NC_FILE_INFO_T *h5)
770 LOG((3,
"%s", __func__));
773 if (!(h5->flags & NC_INDEF))
777 h5->flags ^= NC_INDEF;
780 h5->redef = NC_FALSE;
782 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.