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;
90 sync_netcdf4_file(NC_FILE_INFO_T *h5)
92 NC_HDF5_FILE_INFO_T *hdf5_info;
95 assert(h5 && h5->format_file_info);
96 LOG((3,
"%s", __func__));
100 if (h5->flags & NC_INDEF)
106 h5->flags ^= NC_INDEF;
109 h5->redef = NC_FALSE;
121 nc_bool_t bad_coord_order = NC_FALSE;
124 if ((retval = nc4_rec_write_groups_types(h5->root_grp)))
130 if ((retval = nc4_detect_preserve_dimids(h5->root_grp, &bad_coord_order)))
134 if ((retval = nc4_rec_write_metadata(h5->root_grp, bad_coord_order)))
138 if((retval = NC4_write_ncproperties(h5)))
143 hdf5_info = (NC_HDF5_FILE_INFO_T *)h5->format_file_info;
144 if (H5Fflush(hdf5_info->hdfid, H5F_SCOPE_GLOBAL) < 0)
166 nc4_close_netcdf4_file(NC_FILE_INFO_T *h5,
int abort,
NC_memio *memio)
168 NC_HDF5_FILE_INFO_T *hdf5_info;
171 assert(h5 && h5->root_grp && h5->format_file_info);
172 LOG((3,
"%s: h5->path %s abort %d", __func__, h5->controller->path, abort));
175 hdf5_info = (NC_HDF5_FILE_INFO_T *)h5->format_file_info;
179 if ((retval = nc4_rec_grp_del(h5->root_grp)))
183 nclistfree(h5->alldims);
184 nclistfree(h5->allgroups);
185 nclistfree(h5->alltypes);
192 if (h5->comm != MPI_COMM_NULL)
193 MPI_Comm_free(&h5->comm);
194 if (h5->info != MPI_INFO_NULL)
195 MPI_Info_free(&h5->info);
202 NC4_free_provenance(h5->provenance);
203 h5->provenance = NULL;
207 if (hdf5_info->hdfid > 0 && H5Fclose(hdf5_info->hdfid) < 0)
215 if(h5->mem.inmemory) {
217 (void)NC4_extract_file_image(h5);
218 if(!abort && memio != NULL) {
219 *memio = h5->mem.memio;
220 h5->mem.memio.memory = NULL;
223 if(h5->mem.memio.memory != NULL) {
227 free(h5->mem.memio.memory);
229 h5->mem.memio.memory = NULL;
230 h5->mem.memio.size = 0;
231 NC4_image_finalize(h5->mem.udata);
235 if (h5->format_file_info)
236 free(h5->format_file_info);
259 nc4_close_hdf5_file(NC_FILE_INFO_T *h5,
int abort,
NC_memio *memio)
263 assert(h5 && h5->root_grp && h5->format_file_info);
264 LOG((3,
"%s: h5->path %s abort %d", __func__, h5->controller->path, abort));
267 if (h5->flags & NC_INDEF)
268 h5->flags ^= NC_INDEF;
272 if (!h5->no_write && !abort)
273 if ((retval = sync_netcdf4_file(h5)))
277 if ((retval = nc4_rec_grp_HDF5_del(h5->root_grp)))
282 if ((retval = nc4_close_netcdf4_file(h5, abort, memio)))
297 dumpopenobjects(NC_FILE_INFO_T* h5)
299 NC_HDF5_FILE_INFO_T *hdf5_info;
302 assert(h5 && h5->format_file_info);
303 hdf5_info = (NC_HDF5_FILE_INFO_T *)h5->format_file_info;
305 if(hdf5_info->hdfid <= 0)
308 nobjs = H5Fget_obj_count(hdf5_info->hdfid, H5F_OBJ_ALL);
313 }
else if(nobjs > 0) {
320 snprintf(msg,
sizeof(msg),
"There are %d HDF5 objects open!", nobjs);
327 fprintf(stdout,
"%s\n",msg);
330 reportopenobjects(logit,hdf5_info->hdfid);
352 NC4_set_fill(
int ncid,
int fillmode,
int *old_modep)
354 NC_FILE_INFO_T *nc4_info;
357 LOG((2,
"%s: ncid 0x%x fillmode %d", __func__, ncid, fillmode));
360 if ((retval = nc4_find_grp_h5(ncid, NULL, &nc4_info)))
365 if (nc4_info->no_write)
374 *old_modep = nc4_info->fill_mode;
376 nc4_info->fill_mode = fillmode;
393 NC_FILE_INFO_T *nc4_info;
396 LOG((1,
"%s: ncid 0x%x", __func__, ncid));
399 if ((retval = nc4_find_grp_h5(ncid, NULL, &nc4_info)))
404 if (nc4_info->flags & NC_INDEF)
408 if (nc4_info->no_write)
412 nc4_info->flags |= NC_INDEF;
416 nc4_info->redef = NC_TRUE;
435 NC4__enddef(
int ncid,
size_t h_minfree,
size_t v_align,
436 size_t v_minfree,
size_t r_align)
438 return NC4_enddef(ncid);
455 NC_FILE_INFO_T *nc4_info;
461 LOG((1,
"%s: ncid 0x%x", __func__, ncid));
464 if ((retval = nc4_find_nc_grp_h5(ncid, NULL, &grp, &nc4_info)))
468 for (i = 0; i < ncindexsize(grp->vars); i++)
470 var = (NC_VAR_INFO_T *)ncindexith(grp->vars, i);
472 var->written_to = NC_TRUE;
475 return nc4_enddef_netcdf4_file(nc4_info);
492 NC_FILE_INFO_T *nc4_info;
495 LOG((2,
"%s: ncid 0x%x", __func__, ncid));
497 if ((retval = nc4_find_grp_h5(ncid, NULL, &nc4_info)))
502 if (nc4_info->flags & NC_INDEF)
506 if ((retval = NC4_enddef(ncid)))
510 return sync_netcdf4_file(nc4_info);
530 NC_FILE_INFO_T *nc4_info;
535 LOG((2,
"%s: ncid 0x%x", __func__, ncid));
538 if ((retval = nc4_find_nc_grp_h5(ncid, &nc, NULL, &nc4_info)))
543 if (nc4_info->flags & NC_INDEF && !nc4_info->redef)
551 if ((retval = nc4_close_hdf5_file(nc4_info, 1, NULL)))
556 if (
remove(path) < 0)
572 NC4_close(
int ncid,
void* params)
581 LOG((1,
"%s: ncid 0x%x", __func__, ncid));
584 if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
587 assert(nc && h5 && grp);
595 if(inmemory && params != NULL) {
600 if ((retval = nc4_close_hdf5_file(grp->nc4_info, 0, memio)))
624 NC4_inq(
int ncid,
int *ndimsp,
int *nvarsp,
int *nattsp,
int *unlimdimidp)
632 LOG((2,
"%s: ncid 0x%x", __func__, ncid));
635 if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
638 assert(h5 && grp && nc);
644 *ndimsp = ncindexcount(grp->dim);
648 *nvarsp = ncindexcount(grp->vars);
653 if (grp->atts_not_read)
654 if ((retval = nc4_read_atts(grp, NULL)))
657 *nattsp = ncindexcount(grp->att);
669 for(i=0;i<ncindexsize(grp->dim);i++) {
670 NC_DIM_INFO_T* d = (NC_DIM_INFO_T*)ncindexith(grp->dim,i);
671 if(d == NULL)
continue;
673 *unlimdimidp = d->hdr.id;
692 nc4_enddef_netcdf4_file(NC_FILE_INFO_T *h5)
695 LOG((3,
"%s", __func__));
698 if (!(h5->flags & NC_INDEF))
702 h5->flags ^= NC_INDEF;
705 h5->redef = NC_FALSE;
707 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.