diff options
Diffstat (limited to 'src/Startup.c')
-rw-r--r-- | src/Startup.c | 176 |
1 files changed, 145 insertions, 31 deletions
diff --git a/src/Startup.c b/src/Startup.c index 6927697..eee9631 100644 --- a/src/Startup.c +++ b/src/Startup.c @@ -1,58 +1,172 @@ -#include <stdio.h> + /*@@ + @file Startup.c + @date Thu 18 April 2002 + @author Thomas Radke + @desc + Startup routines for IOJpeg. + @enddesc + @version $Id$ + @@*/ -#include "cctk.h" -#include "cctk_Parameters.h" -#include "IOJpeg.h" +#include <stdlib.h> +#include <string.h> -static const char *rcsid = "$Header$"; +#include "cctk.h" +#include "cctk_IOMethods.h" +#include "cctk_Parameters.h" +#include "CactusBase/IOUtil/src/ioutil_Utils.h" +#include "ioJpegGH.h" +/* the rcs ID and its dummy function to use it */ +static const char *rcsid = "$Id$"; CCTK_FILEVERSION(CactusIO_IOJpeg_Startup_c) -void *IOJpeg_SetupGH (tFleshConfig *config, int convergence_level, cGH *GH); -int IOJpeg_InitGH (cGH *GH); - +/******************************************************************** + ******************** External Routines ************************ + ********************************************************************/ void IOJpeg_Startup (void); + +/******************************************************************** + ******************** Internal Routines ************************ + ********************************************************************/ +static void *IOJpeg_SetupGH (tFleshConfig *config, int conv_level, cGH *GH); + + + /*@@ + @routine IOJpeg_Startup + @date Thu 18 April 2002 + @author Thomas Radke + @desc + The startup registration routine for IOJpeg. + Registers the GH extensions needed for IOJpeg + along with its setup routine. + @enddesc + @calls CCTK_RegisterGHExtension + CCTK_RegisterGHExtensionSetupGH +@@*/ void IOJpeg_Startup (void) { + CCTK_RegisterGHExtensionSetupGH (CCTK_RegisterGHExtension ("IOJpeg"), + IOJpeg_SetupGH); +} + + +/******************************************************************** + ******************** Internal Routines ************************ + ********************************************************************/ + /*@@ + @routine IOJpeg_SetupGH + @date Thu 18 April 2002 + @author Thomas Radke + @desc + Allocates and sets up IOJpeg's GH extension structure + @enddesc + + @calls CCTK_RegisterIOMethod + CCTK_RegisterIOMethodOutputGH + CCTK_RegisterIOMethodOutputVarAs + CCTK_RegisterIOMethodTimeToOutput + CCTK_RegisterIOMethodTriggerOutput + + @var config + @vdesc the CCTK configuration as provided by the flesh + @vtype tFleshConfig * + @vio unused + @endvar + @var conv_level + @vdesc the convergence level + @vtype int + @vio unused + @endvar + @var GH + @vdesc Pointer to CCTK grid hierarchy + @vtype cGH * + @vio in + @endvar + + @returntype void * + @returndesc + pointer to the allocated GH extension structure + @endreturndesc +@@*/ +static void *IOJpeg_SetupGH (tFleshConfig *config, int conv_level, cGH *GH) +{ + int i, numvars; + ioJpegGH *myGH; DECLARE_CCTK_PARAMETERS - int IO_GHExtension; - int IOMethod; - if (CCTK_GHExtensionHandle ("IO") < 0) + /* suppress compiler warnings about unused variables */ + (void) (config + 0); + (void) (conv_level + 0); + (void) (GH + 0); + + /* allocate the GH extension and its components */ + myGH = (ioJpegGH *) malloc (sizeof (ioJpegGH)); + if (! myGH) + { + CCTK_WARN (0, "IOJpeg_SetupGH: Unable to allocate memory for GH"); + } + + /* register the IOJpeg routines as output methods */ + i = CCTK_RegisterIOMethod ("IOJpeg"); + CCTK_RegisterIOMethodOutputGH (i, IOJpeg_OutputGH); + CCTK_RegisterIOMethodOutputVarAs (i, IOJpeg_OutputVarAs); + CCTK_RegisterIOMethodTimeToOutput (i, IOJpeg_TimeFor); + CCTK_RegisterIOMethodTriggerOutput (i, IOJpeg_TriggerOutput); + + if (! CCTK_Equals (newverbose, "none")) { - CCTK_WARN (1, "IOJpeg: Thorn IOUtil was not activated. " - "No IOJpeg IO methods will be enabled."); - return; + CCTK_INFO ("I/O Method 'IOJpeg' registered"); + CCTK_INFO ("IOJpeg: Output of 2D jpeg images of grid functions/arrays"); } - if (CCTK_MaxDim() < 3) + numvars = CCTK_NumVars (); + myGH->out_every = (int *) malloc (numvars * sizeof (int)); + myGH->out_last = (int *) malloc (numvars * sizeof (int)); + + for (i = 0; i < numvars; i++) { - CCTK_WARN (1, "IOJpeg: IOJpeg can only currently handle 3D GVs. " - "No IOJpeg IO methods will be enabled."); - return; + myGH->out_last[i] = -1; } - IO_GHExtension = CCTK_RegisterGHExtension ("IOJpeg"); - CCTK_RegisterGHExtensionSetupGH (IO_GHExtension, IOJpeg_SetupGH); - CCTK_RegisterGHExtensionInitGH (IO_GHExtension, IOJpeg_InitGH); + myGH->out_vars = strdup (""); + myGH->out_every_default = 0; - /* Register the 2D IOJpeg routines as output methods */ + /* Check whether "out2D_dir" was set. + If so take this dir otherwise default to "IO::outdir" */ + if (CCTK_ParameterQueryTimesSet ("out2D_dir", CCTK_THORNSTRING) <= 0) + { + out2D_dir = outdir; + } - IOMethod = CCTK_RegisterIOMethod ("IOJpeg_2D"); - CCTK_RegisterIOMethodOutputGH (IOMethod, IOJpeg_Output2DGH); - CCTK_RegisterIOMethodOutputVarAs (IOMethod, IOJpeg_Output2DVarAs); - CCTK_RegisterIOMethodTimeToOutput (IOMethod, IOJpeg_TimeFor2D); - CCTK_RegisterIOMethodTriggerOutput (IOMethod, IOJpeg_TriggerOutput2D); + /* omit the directory if it's the current working dir */ + if (strcmp (out2D_dir, ".") == 0) + { + myGH->outdir = strdup (""); + } + else + { + myGH->outdir = (char *) malloc (strlen (out2D_dir) + 2); + sprintf (myGH->outdir, "%s/", out2D_dir); + } - if (CCTK_Equals (newverbose, "standard") || - CCTK_Equals( newverbose, "full")) + /* create the output dir */ + i = IOUtil_CreateDirectory (GH, myGH->outdir, 0, 0); + if (i < 0) + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "IOJpeg_SetupGH: problem creating IOJpeg output directory '%s'", + myGH->outdir); + } + else if (i >= 0 && CCTK_Equals (newverbose, "full")) { - CCTK_INFO ("I/O Method 'IOJpeg_2D' registered"); - CCTK_INFO ("IOJpeg_2D: Output of 2D slices in 3D in Jpeg format"); + CCTK_VInfo (CCTK_THORNSTRING, "IOJpeg: Output to directory '%s'", + myGH->outdir); } + return (myGH); } |