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;
260 if (h5->comm != MPI_COMM_NULL)
261 MPI_Comm_free(&h5->comm);
262 if (h5->info != MPI_INFO_NULL)
263 MPI_Info_free(&h5->info);
269 NC4_clear_provenance(&h5->provenance);
273 if (hdf5_info->hdfid > 0 && H5Fclose(hdf5_info->hdfid) < 0)
281 if (h5->mem.inmemory)
284 (void)NC4_extract_file_image(h5);
285 if (!abort && memio != NULL)
287 *memio = h5->mem.memio;
288 h5->mem.memio.memory = NULL;
291 if (h5->mem.memio.memory != NULL)
296 free(h5->mem.memio.memory);
298 h5->mem.memio.memory = NULL;
299 h5->mem.memio.size = 0;
300 NC4_image_finalize(h5->mem.udata);
304 if (h5->format_file_info)
305 free(h5->format_file_info);
308 if ((retval = nc4_nc4f_list_del(h5)))
328 nc4_close_hdf5_file(NC_FILE_INFO_T *h5,
int abort,
NC_memio *memio)
332 assert(h5 && h5->root_grp && h5->format_file_info);
333 LOG((3,
"%s: h5->path %s abort %d", __func__, h5->controller->path, abort));
336 if (h5->flags & NC_INDEF)
337 h5->flags ^= NC_INDEF;
341 if (!h5->no_write && !abort)
342 if ((retval = sync_netcdf4_file(h5)))
346 if ((retval = nc4_rec_grp_HDF5_del(h5->root_grp)))
351 if ((retval = nc4_close_netcdf4_file(h5, abort, memio)))
366 dumpopenobjects(NC_FILE_INFO_T* h5)
368 NC_HDF5_FILE_INFO_T *hdf5_info;
371 assert(h5 && h5->format_file_info);
372 hdf5_info = (NC_HDF5_FILE_INFO_T *)h5->format_file_info;
374 if(hdf5_info->hdfid <= 0)
377 nobjs = H5Fget_obj_count(hdf5_info->hdfid, H5F_OBJ_ALL);
382 }
else if(nobjs > 0) {
389 snprintf(msg,
sizeof(msg),
"There are %d HDF5 objects open!", nobjs);
396 fprintf(stdout,
"%s\n",msg);
399 reportopenobjects(logit,hdf5_info->hdfid);
421 NC4_set_fill(
int ncid,
int fillmode,
int *old_modep)
423 NC_FILE_INFO_T *nc4_info;
426 LOG((2,
"%s: ncid 0x%x fillmode %d", __func__, ncid, fillmode));
429 if ((retval = nc4_find_grp_h5(ncid, NULL, &nc4_info)))
434 if (nc4_info->no_write)
443 *old_modep = nc4_info->fill_mode;
445 nc4_info->fill_mode = fillmode;
462 NC_FILE_INFO_T *nc4_info;
465 LOG((1,
"%s: ncid 0x%x", __func__, ncid));
468 if ((retval = nc4_find_grp_h5(ncid, NULL, &nc4_info)))
473 if (nc4_info->flags & NC_INDEF)
477 if (nc4_info->no_write)
481 nc4_info->flags |= NC_INDEF;
485 nc4_info->redef = NC_TRUE;
504 NC4__enddef(
int ncid,
size_t h_minfree,
size_t v_align,
505 size_t v_minfree,
size_t r_align)
507 return NC4_enddef(ncid);
524 NC_FILE_INFO_T *nc4_info;
530 LOG((1,
"%s: ncid 0x%x", __func__, ncid));
533 if ((retval = nc4_find_grp_h5(ncid, &grp, &nc4_info)))
537 for (i = 0; i < ncindexsize(grp->vars); i++)
539 var = (NC_VAR_INFO_T *)ncindexith(grp->vars, i);
541 var->written_to = NC_TRUE;
544 return nc4_enddef_netcdf4_file(nc4_info);
561 NC_FILE_INFO_T *nc4_info;
564 LOG((2,
"%s: ncid 0x%x", __func__, ncid));
566 if ((retval = nc4_find_grp_h5(ncid, NULL, &nc4_info)))
571 if (nc4_info->flags & NC_INDEF)
575 if ((retval = NC4_enddef(ncid)))
579 return sync_netcdf4_file(nc4_info);
599 NC_FILE_INFO_T *nc4_info;
604 LOG((2,
"%s: ncid 0x%x", __func__, ncid));
607 if ((retval = nc4_find_nc_grp_h5(ncid, &nc, NULL, &nc4_info)))
612 if (nc4_info->flags & NC_INDEF && !nc4_info->redef)
620 if ((retval = nc4_close_hdf5_file(nc4_info, 1, NULL)))
625 if (
remove(path) < 0)
641 NC4_close(
int ncid,
void* params)
649 LOG((1,
"%s: ncid 0x%x", __func__, ncid));
652 if ((retval = nc4_find_grp_h5(ncid, &grp, &h5)))
663 if(inmemory && params != NULL) {
668 if ((retval = nc4_close_hdf5_file(grp->nc4_info, 0, memio)))
692 NC4_inq(
int ncid,
int *ndimsp,
int *nvarsp,
int *nattsp,
int *unlimdimidp)
700 LOG((2,
"%s: ncid 0x%x", __func__, ncid));
703 if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
706 assert(h5 && grp && nc);
712 *ndimsp = ncindexcount(grp->dim);
716 *nvarsp = ncindexcount(grp->vars);
722 if ((retval = nc4_read_atts(grp, NULL)))
725 *nattsp = ncindexcount(grp->att);
737 for(i=0;i<ncindexsize(grp->dim);i++) {
738 NC_DIM_INFO_T* d = (NC_DIM_INFO_T*)ncindexith(grp->dim,i);
739 if(d == NULL)
continue;
741 *unlimdimidp = d->hdr.id;
760 nc4_enddef_netcdf4_file(NC_FILE_INFO_T *h5)
763 LOG((3,
"%s", __func__));
766 if (!(h5->flags & NC_INDEF))
770 h5->flags ^= NC_INDEF;
773 h5->redef = NC_FALSE;
775 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.