/*@@ @file Write.c @date Fri May 21 1999 @author Thomas Radke @desc Output and trigger routines for FiberBundle output into HDF5 files @enddesc @history @hauthor Thomas Radke @hdate May 21 1999 @hdesc Just copied from thorn FlexIO. @hendhistory @@*/ #include #include #include "cctk.h" #include "cctk_Parameters.h" #include "StoreNamedData.h" #include "CactusBase/IOUtil/src/ioGH.h" #include "StreamedHDF5GH.h" /* local function prototypes */ void StreamedHDF5i_DumpParameters (cGH *GH, hid_t group); void StreamedHDF5i_DumpGHExtensions (cGH *GH, hid_t group); /*@@ @routine Write @author Paul Walker @date Feb 1997 @calledby StreamedHDF5_OutputVarAs, StreamedHDF5_TriggerOutput @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 @@*/ void StreamedHDF5_Write (cGH *GH, int index, const char *alias) { DECLARE_CCTK_PARAMETERS int vtype; int timelevel; StreamedHDF5GH *myGH; hid_t fid, plist; #if 0 hid_t group; #endif /* first, check if variable has storage assigned */ if (! CCTK_QueryGroupStorageI (GH, CCTK_GroupIndexFromVarI (index))) { char *fullname = CCTK_FullName (index); CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, "No StreamedHDF5 output for '%s' (no storage)", fullname); free (fullname); return; } /* check if variable is of type GF or ARRAY */ vtype = CCTK_GroupTypeFromVarI (index); if (vtype != CCTK_GF && vtype != CCTK_ARRAY) { char *fullname = CCTK_FullName (index); CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, "No StreamedHDF5 output for '%s' (not an array type)", fullname); free (fullname); return; } /* Get the handles for IO and StreamedHDF5 extensions */ myGH = (StreamedHDF5GH *) GH->extensions [CCTK_GHExtensionHandle ("StreamedHDF5")]; fid = -1; if (CCTK_MyProc (GH) == 0) { /* filename is not used if we pass a socket descriptor but it must not be NULL or an empty string */ static const char *filename = "bla"; if (verbose) CCTK_VInfo (CCTK_THORNSTRING, "Opening HDF5 output file on port %d", port); /* set VFD to stream and open the file */ CACTUS_IOHDF5_ERROR (plist = H5Pcreate (H5P_FILE_ACCESS)); CACTUS_IOHDF5_ERROR (H5Pset_fapl_stream (plist, 0, myGH->socket)); CACTUS_IOHDF5_ERROR (fid = H5Fcreate (filename, H5F_ACC_TRUNC, H5P_DEFAULT, plist)); CACTUS_IOHDF5_ERROR (H5Pclose (plist)); #if 0 /* output global attributes */ if (verbose) CCTK_INFO ("Dumping GH extensions ..."); CACTUS_IOHDF5_ERROR (group = H5Gcreate (fid, GHEXTENSIONS_GROUP, 0)); StreamedHDF5i_DumpGHExtensions (GH, group); CACTUS_IOHDF5_ERROR (H5Gclose (group)); #endif } /* get the current timelevel */ timelevel = CCTK_NumTimeLevelsFromVarI (index) - 1; if (timelevel > 0) timelevel--; /* output the data */ StreamedHDF5_DumpVar (GH, index, timelevel, fid); /* close the file */ if (fid >= 0) { if (verbose) CCTK_INFO ("Closing HDF5 output file from this iteration"); CACTUS_IOHDF5_ERROR (H5Fclose (fid)); } }