aboutsummaryrefslogtreecommitdiff
path: root/src/Startup.c
diff options
context:
space:
mode:
authortradke <tradke@0888f3d4-9f52-45d2-93bc-d00801ff5e46>2000-06-20 08:52:29 +0000
committertradke <tradke@0888f3d4-9f52-45d2-93bc-d00801ff5e46>2000-06-20 08:52:29 +0000
commitc0d7c72fb498b9a8c6cf062a31dbbbae75fec444 (patch)
treede61d233631023cc6672f1fbae39786fb461bef1 /src/Startup.c
parent0a5cd6924df319727ac5c7304e611010490a2d3a (diff)
This commit was generated by cvs2svn to compensate for changes in r2, which
included commits to RCS files with non-trunk default branches. git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGHIO/IOStreamedHDF5/trunk@3 0888f3d4-9f52-45d2-93bc-d00801ff5e46
Diffstat (limited to 'src/Startup.c')
-rw-r--r--src/Startup.c208
1 files changed, 208 insertions, 0 deletions
diff --git a/src/Startup.c b/src/Startup.c
new file mode 100644
index 0000000..bfae509
--- /dev/null
+++ b/src/Startup.c
@@ -0,0 +1,208 @@
+ /*@@
+ @file Startup.c
+ @date Fri May 21 1999
+ @author Thomas Radke
+ @desc
+ Startup routines for StreamedHDF5.
+ @enddesc
+ @history
+ @hauthor Thomas Radke @hdate May 21 1999
+ @hdesc Just copied from thorn FlexIO.
+ @endhistory
+ @@*/
+
+#include <stdio.h>
+
+#include "cctk.h"
+#include "cctk_Parameters.h"
+#include "CactusBase/IOUtil/src/ioGH.h"
+#include "Development/Socket/src/SocketUtils.h"
+#include "StreamedHDF5GH.h"
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+
+/* prototypes of functions to be registered */
+int StreamedHDF5_OutputGH(cGH *GH);
+int StreamedHDF5_TriggerOutput(cGH *GH, int);
+int StreamedHDF5_TimeFor(cGH *GH, int);
+int StreamedHDF5_OutputVarAs(cGH *GH, const char *var, const char *alias);
+
+/* local function prototypes */
+static void *StreamedHDF5_SetupGH (tFleshConfig *config, int convergence_level, cGH *GH);
+static int StreamedHDF5_InitGH (cGH *GH);
+
+
+ /*@@
+ @routine StreamedHDF5_Startup
+ @date Fri May 21 1999
+ @author Thomas Radke
+ @desc
+ The startup registration routine for StreamedHDF5.
+ Registers the GH extensions needed for StreamedHDF5 and
+ the registerable routines used for each method of StreamedHDF5.
+ StreamedHDF5 does not overload any functions.
+ @enddesc
+ @calls
+ @calledby CCTK scheduler at STARTUP
+ @history
+
+ @endhistory
+@@*/
+void StreamedHDF5_Startup (void)
+{
+ int IO_GHExtension;
+
+
+ if (CCTK_GHExtensionHandle ("IO") < 0)
+ {
+ CCTK_WARN (1, "Thorn IOUtil was not activated. "
+ "No StreamedHDF5 IO methods will be enabled.");
+ return;
+ }
+
+ /* this check can go as soon as the Stream VFD
+ comes with the default HDF5 installation */
+#ifndef H5FDstream_H
+ CCTK_WARN (1, "The Stream VFD is not included in the configured HDF5 "
+ "installation. No HDF5 stream output will be available !");
+#else
+ IO_GHExtension = CCTK_RegisterGHExtension ("StreamedHDF5");
+ CCTK_RegisterGHExtensionSetupGH (IO_GHExtension, StreamedHDF5_SetupGH);
+ CCTK_RegisterGHExtensionInitGH (IO_GHExtension, StreamedHDF5_InitGH);
+#endif
+}
+
+
+ /*@@
+ @routine StreamedHDF5_Terminate
+ @date Mon Jun 19 2000
+ @author Thomas Radke
+ @desc
+ StreamedHDF5's termination routine
+ Closes the socket if it was opened before.
+ @enddesc
+ @calls
+ @calledby CCTK scheduler at TERMINATE
+ @history
+
+ @endhistory
+@@*/
+void StreamedHDF5_Terminate (cGH *GH)
+{
+ int handle;
+ StreamedHDF5GH *myGH;
+
+
+ handle = CCTK_GHExtensionHandle ("StreamedHDF5");
+ myGH = handle >= 0 ? (StreamedHDF5GH *) GH->extensions [handle] : NULL;
+ if (myGH)
+ {
+ if (myGH->socket >= 0)
+ {
+ close (myGH->socket);
+ }
+ }
+}
+
+
+/*************************** local routines *********************************/
+static void *StreamedHDF5_SetupGH (tFleshConfig *config, int convergence_level, cGH *GH)
+{
+ DECLARE_CCTK_PARAMETERS
+ int IOMethod;
+ int numvars, socket;
+ StreamedHDF5GH *newGH;
+
+
+ if (CCTK_MyProc (GH) == 0)
+ {
+ socket = Socket_TCPOpenServerSock (port);
+ if (socket < 0)
+ {
+ CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Couldn't open TCP server socket on port %d. No HDF5 stream "
+ "output available !", port);
+ return (NULL);
+ }
+
+ if (Socket_SetNonBlocking (socket) < 0)
+ {
+ CCTK_WARN (1, "Couldn't set socket into non-blocking mode. No HDF5 "
+ "stream output available !");
+ close (socket);
+ return (NULL);
+ }
+ }
+ else
+ {
+ socket = -1;
+ }
+
+ /* Register StreamedHDF5 routines as output methods */
+ IOMethod = CCTK_RegisterIOMethod ("StreamedHDF5");
+ CCTK_RegisterIOMethodOutputGH (IOMethod, StreamedHDF5_OutputGH);
+ CCTK_RegisterIOMethodOutputVarAs (IOMethod, StreamedHDF5_OutputVarAs);
+ CCTK_RegisterIOMethodTimeToOutput (IOMethod, StreamedHDF5_TimeFor);
+ CCTK_RegisterIOMethodTriggerOutput (IOMethod, StreamedHDF5_TriggerOutput);
+
+ numvars = CCTK_NumVars ();
+
+ newGH = (StreamedHDF5GH *) malloc (sizeof (StreamedHDF5GH));
+ newGH->do_output = (char *) malloc (numvars * sizeof (char));
+ newGH->out_last = (int *) malloc (numvars * sizeof (int));
+ newGH->socket = socket;
+
+ /* save the original error printing routine and its argument */
+ CACTUS_IOHDF5_ERROR (H5Eget_auto (&newGH->printErrorFn,
+ &newGH->printErrorFnArg));
+
+ /* predefine dataspaces for writing scalar and array attributes */
+ /* the dimension of the array dataspace is set when used */
+ CACTUS_IOHDF5_ERROR (newGH->scalarDataspace = H5Screate (H5S_SCALAR));
+ CACTUS_IOHDF5_ERROR (newGH->arrayDataspace = H5Screate (H5S_SIMPLE));
+
+ /* predefine a IOHDF5_COMPLEX datatype */
+ CACTUS_IOHDF5_ERROR (newGH->IOHDF5_COMPLEX =
+ H5Tcreate (H5T_COMPOUND, sizeof (CCTK_COMPLEX)));
+ CACTUS_IOHDF5_ERROR (H5Tinsert (newGH->IOHDF5_COMPLEX, "real",
+ offsetof (CCTK_COMPLEX, Re), IOHDF5_REAL));
+ CACTUS_IOHDF5_ERROR (H5Tinsert (newGH->IOHDF5_COMPLEX, "imag",
+ offsetof (CCTK_COMPLEX, Im), IOHDF5_REAL));
+
+ /* predefine a C string datatype */
+ CACTUS_IOHDF5_ERROR (newGH->IOHDF5_STRING = H5Tcopy (H5T_C_S1));
+
+ return (newGH);
+}
+
+
+static int StreamedHDF5_InitGH (cGH *GH)
+{
+ DECLARE_CCTK_PARAMETERS
+ int i, handle;
+ StreamedHDF5GH *myGH;
+
+
+ handle = CCTK_GHExtensionHandle ("StreamedHDF5");
+ myGH = handle >= 0 ? (StreamedHDF5GH *) GH->extensions [handle] : NULL;
+ if (handle < 0 || myGH == NULL)
+ {
+ return (-1);
+ }
+
+ /* How often to output */
+ myGH->out_every = out_every > 0 ? out_every : -1;
+ if (outHDF5_every > 0)
+ myGH->out_every = outHDF5_every;
+ ParseVarsForOutput (out_vars, myGH->do_output);
+
+ for (i = 0; i < CCTK_NumVars (); i++)
+ myGH->out_last [i] = -1;
+
+ return (0);
+}
+
+