/*@@ @file Write3D.c @date Fri May 21 1999 @author Thomas Radke, Gerd Lanfermann @desc Output and trigger routines for 3D output into HDF5 files. Added general hyperslab extraction @enddesc @history @hauthor Thomas Radke @hdate May 21 1999 @hdesc Just copied from thorn FlexIO. @hendhistory @@*/ #include "cctk.h" #include "cctk_Parameters.h" #include "StoreNamedData.h" #include "CactusPUGH/PUGH/src/include/pugh.h" #include "CactusBase/IOUtil/src/ioGH.h" #include "ioHDF5GH.h" #include #include #include /* local function prototypes */ void IOHDF5i_DumpParameters (cGH *GH, hid_t group); void IOHDF5i_DumpGHExtensions (cGH *GH, hid_t group); char *IOHDF5_Get_filename_ND (cGH *GH, int index, ioHDF5Geo_t *slab_geo, const char *name, int *isNewFile); /*@@ @routine Write3D @author Paul Walker @date Feb 1997 @calledby IOHDF5_Output3DVarAs, IOHDF5_TriggerOutput3D @var GH @vdesc Pointer to CCTK GH @vtype cGH @vio in @vcomment @endvar @var index @vdesc index of variable to output @vtype int @vio in @vcomment @endvar @var alias @vdesc alias name of variable to output @vtype const char * @vio in @vcomment @endvar @@*/ int IOHDF5_Write3D (cGH *GH, int index, const char *alias) { DECLARE_CCTK_PARAMETERS int timelevel; ioGH *ioUtilGH; ioHDF5GH *h5GH; hid_t fid, plist; int isNewFile; char *filename; int ierr=0; ioHDF5Geo_t geo; int SDIM; /* Get the handle for IO extensions */ ioUtilGH = (ioGH *) GH->extensions [CCTK_GHExtensionHandle ("IO")]; h5GH = (ioHDF5GH *) GH->extensions [CCTK_GHExtensionHandle ("IOHDF5")]; /* The dimension of the slab - HARDCODED */ SDIM = 3; /* Get the slab geometry for 2D slabs */ geo = h5GH->out_geo[index][SDIM]; /* Set geo.sdim to announce 3d output */ geo.sdim = SDIM; /* get the dimension of the variable */ geo.vdim = CCTK_GroupDimFromVarI(index); /* check if variable has storage assigned */ if (! CCTK_QueryGroupStorageI (GH, CCTK_GroupIndexFromVarI (index))) { char *fullname = CCTK_FullName (index); CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "No IOHDF5 3D output for '%s' (no storage)", fullname); free (fullname); return(-1); } if (verbose) CCTK_VInfo (CCTK_THORNSTRING, "HDF5 %dD-output of variable '%s', " "downsampling parameters (%d, %d, %d)", SDIM, alias, geo.downs[0], geo.downs [1], geo.downs[2]); /* get the filename for output */ if (!(filename = IOHDF5_Get_filename_ND (GH, index, &geo, alias, &isNewFile))) { char *fullname = CCTK_FullName (index); CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "Unable to construct file name for '%s'", fullname); free(fullname); return(-1); } /* open the output file on IO procs or - in case of parallel HDF5 - on all procs */ #ifdef HAVE_PARALLEL if (CCTK_MyProc (GH) != ioUtilGH->ioproc && ! ioUtilGH->unchunked) #else if (CCTK_MyProc (GH) != ioUtilGH->ioproc) #endif { fid = -1; } else { if (verbose) CCTK_VInfo (CCTK_THORNSTRING, "%s HDF5 output file '%s'", isNewFile ? "Opening" : "Appending", filename); CACTUS_IOHDF5_ERROR (plist = H5Pcreate (H5P_FILE_ACCESS)); #ifdef CCTK_MPI #ifdef HAVE_PARALLEL if (ioUtilGH->unchunked) CACTUS_IOHDF5_ERROR (H5Pset_mpi (plist, PUGH_pGH (GH)->PUGH_COMM_WORLD, MPI_INFO_NULL)); #endif #endif if (isNewFile) CACTUS_IOHDF5_ERROR (fid = H5Fcreate (filename, H5F_ACC_TRUNC, H5P_DEFAULT, plist)); else CACTUS_IOHDF5_ERROR (fid = H5Fopen (filename, H5F_ACC_RDWR, plist)); H5Pclose (plist); } /* get the current timelevel */ timelevel = 0; /* output global attributes */ if (isNewFile && fid >= 0) { hid_t group; /* all GH extension variables and parameter stuff which is not specific to any dataset goes into dedicated groups */ if (out3D_parameters) { CACTUS_IOHDF5_ERROR (group = H5Gcreate (fid, GLOBAL_PARAMETERS_GROUP, 0)); IOHDF5i_DumpParameters (GH, group); CACTUS_IOHDF5_ERROR (H5Gclose (group)); } if (verbose) CCTK_INFO ("Dumping GH extensions ..."); CACTUS_IOHDF5_ERROR (group = H5Gcreate (fid, GHEXTENSIONS_GROUP, 0)); IOHDF5i_DumpGHExtensions (GH, group); CACTUS_IOHDF5_ERROR (H5Gclose (group)); } /* output the data */ ierr = IOHDF5_DumpVar (GH, index, timelevel, &geo, fid); /* close the file */ if (fid >= 0) { if (verbose) CCTK_INFO ("Closing HDF5 output file from this iteration"); CACTUS_IOHDF5_ERROR (H5Fclose (fid)); } /* free the filename if it was not registered for re-opening in IOHDF5_net3D_filename () */ if (out3D_septimefiles) free (filename); return(ierr); }