diff options
Diffstat (limited to 'src/IsoSurfacerInit.c')
-rw-r--r-- | src/IsoSurfacerInit.c | 494 |
1 files changed, 494 insertions, 0 deletions
diff --git a/src/IsoSurfacerInit.c b/src/IsoSurfacerInit.c new file mode 100644 index 0000000..5948426 --- /dev/null +++ b/src/IsoSurfacerInit.c @@ -0,0 +1,494 @@ +#ifndef TCP /* JMS addition */ +#define TCP +#endif + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#ifndef _WIN32 +#include <time.h> +#include <unistd.h> +#endif + +#include <ctype.h> + +#include <cctk.h> +#include <cctk_Parameters.h> + +//#include <cctk_DefineThorn.h> + +//#ifdef CACTUSNET_HTTP +//#include "CactusNet/http/src/http_GHExtensions.hpp" +//#endif + +#include "http_GHExtensions.hpp" + + +#include "IsoSurfacerGH.h" +#include "IsoSurfacerInit.h" + + +/* Some function forward declarations */ +CCTK_INT4 ParseIsoString(char *s, param_map&parms); +CCTK_INT4 NumberOfItems(char *s, char *d); +char *GetSubString(char *s, char *d, CCTK_INT4 n); + +isotimes_st isotimes; +isotimes_st cdtimes; + +CCTK_INT4 RunIsoSurfacer; + + +#ifdef CACTUSNET_HTTP +CactusCommands::Client * IsosurfaceHttpClientCreator(CactusCommands::Reply*msgbuf, CactusCommands::CommandList&cmds ); +#endif + +/***************************************************************/ +void *IsoSurfacer_SetupGH (tFleshConfig *config, + int convergence_level, + cGH *GH){ + isosurfacerGH *myGH=(isosurfacerGH*)malloc(sizeof(isosurfacerGH)); + return myGH; +} + +int IsoSurfacer_InitGH (cGH *GH){ + DECLARE_CCTK_PARAMETERS + int n; + isosurfacerGH *myGH; + myGH = (isosurfacerGH *) GH->extensions [CCTK_GHExtensionHandle ("IsoSurfacer")]; + + printf("IsoInit\n"); + /* initialize values */ + myGH->funcName=0; + myGH->formats=0; + myGH->outfreq=1; + myGH->firstIteration=1; + myGH->resolution=1; + myGH->uniq_verts=1; + myGH->RunIsoSurfacer = 0; + + /* OK, this is ridiculous. + Separate out the isostring components into + separate things and end this craziness */ + if( (n = ParseIsoString(isosurfacer, myGH->isoparms)) == 0) + return 0; + + RunIsoSurfacer = 1; + /* + doIso = 0; + + for (i=0; i<CCTK_NumVars (); i++) { + char *fullname = CCTK_FullName (i); + + for(j=0; j<n; j++) + if(CCTK_Equals (fullname, allparms[j].funcName) ) { + doIso = 1; + myGH->do_iso [i] = 1; + myGH->isoparms [i] = allparms[j]; + if((allparms[j]).formats&SOCK){ + printf("usesockets**********\n"); + } + break; + } + free (fullname); + } +*/ + + if (CCTK_MyProc (GH) == 0){ + char *cmd = (char *) malloc (strlen (outdir) + 80); + + sprintf (cmd, "mkdir -p %s", outdir); + if (system (cmd) < 0) + CCTK_WARN (1, "Problem creating IsoSurfacer output directory"); + free (cmd); + } + memset(&isotimes, 0, sizeof(isotimes)); + memset(&cdtimes, 0, sizeof(cdtimes)); + return true; +} + +/************************************************************/ + +void IsoSurfaceEnd(cGH *GH) +{ + + + if( RunIsoSurfacer == 0 ) + return; + +#if 0 + isosurfacerGH *myGH; + + myGH = (isosurfacerGH *) GH->extensions [CCTK_GHExtensionHandle ("IsoSurfacer")]; + + /* Close Data Connections (If open) */ + if(myGH->datasocket) { + CCTK_INT4 i=0; + SendData(myGH->datasocket,"done",1,INT32,&i); + delete static_cast<DataSender*>(myGH->datasocket); + } + if(myGH->commandsocket) + delete static_cast<CommandReceiver*>(myGH->commandsocket); + +#endif // EXTERNAL_REMOTEIO + + printf("IsoSurfacer timing \n"); + printf("\n Total number of calls to the IsoSurfacer: %d\n", isotimes.ncalls); + printf(" Time spent in IsoSurfacer:\n"); + printf(" Total real time : %.4f s\n", + isotimes.realtime_total * 1.0 / CLK_TCK); +#ifndef _WIN32 + printf(" Total user time : %.4f s\n", + isotimes.tms_total.tms_utime * 1.0 / CLK_TCK); + printf(" Total system time : %.4f s\n", + isotimes.tms_total.tms_stime * 1.0 / CLK_TCK); + printf(" Average real time per call : %.4f s\n", + isotimes.realtime_total * 1.0 / CLK_TCK / isotimes.ncalls); + printf(" Average user time per call : %.4f s\n", + isotimes.tms_total.tms_utime * 1.0 / CLK_TCK / isotimes.ncalls); + printf(" Average system time per call : %.4f s\n", + isotimes.tms_total.tms_stime * 1.0 / CLK_TCK / isotimes.ncalls); +#endif + printf("\n Total number of calls to CollectData: %d\n", cdtimes.ncalls); + printf(" Time spent in CollectData:\n"); + printf(" Total real time : %.4f s\n", + cdtimes.realtime_total * 1.0 / CLK_TCK); +#ifndef _WIN32 + printf(" Total user time : %.4f s\n", + cdtimes.tms_total.tms_utime * 1.0 / CLK_TCK); + printf(" Total system time : %.4f s\n", + cdtimes.tms_total.tms_stime * 1.0 / CLK_TCK); +#endif + printf(" Average real time per call : %.4f s\n", + cdtimes.realtime_total * 1.0 / CLK_TCK / cdtimes.ncalls); +#ifndef _WIN32 + printf(" Average user time per call : %.4f s\n", + cdtimes.tms_total.tms_utime * 1.0 / CLK_TCK / cdtimes.ncalls); + printf(" Average system time per call : %.4f s\n", + cdtimes.tms_total.tms_stime * 1.0 / CLK_TCK / cdtimes.ncalls); + printf("--------------------------------------------------\n"); +#endif +} + +int IsoSurfacer_rfrTraverseGH (cGH *GH, int rfrpoint) +{ + return 0; +} + +/*****************************************************************************/ + +CCTK_INT4 ParseIsoString(char *s, param_map&allparms) +{ + CCTK_INT4 i, j; + CCTK_INT4 n, m; + CCTK_INT4 nlevels, nformats; + char *sub0, *sub1, *sub2; + + + + /* First see how many functions we have */ + /* by simply counting the number of {} pairs */ + n = NumberOfItems(s, "{}"); + + if(n == 0) + { + printf("Isosurfacer: empty parameter string '%s'\n", s); + return 0; + } + + /* Allocate that many isoparms structs */ +// *allparms = NEW(n, isoparms_st); + + /* Now fill in each isoparms struct with the info for each function */ + for(i=0; i<n; i++) + { + sub0 = GetSubString(s, "{}", i); + + /* Check that we have the right number of () pairs */ + m = NumberOfItems(sub0, "()"); + + if(m != 4) + { + printf("Isosurfacer: improperly formed parameter string '%s'\n", s); + printf(" there should be exactly 4 () pairs\n"); + free(sub0); + return 0; + } + + /*- 1 -----------------------------------------------------------------*/ + /* The first () pair contains the function name */ + char*gridfunc = GetSubString(sub0, "()", 0); + + isoparms_st*gridparams = new isoparms_st(); + + allparms[gridfunc] = gridparams ; + + gridparams->funcName = gridfunc; + + + /*- 2 -----------------------------------------------------------------*/ + /* The second () pair contains the list of isosurface levels */ + sub1 = GetSubString(sub0, "()", 1); + + /* First see how many there are by counting the number of commas + 1 */ + nlevels = NumberOfItems(sub1, ","); + + /* and get the values */ + for(j=0; j<nlevels; j++) + { + sub2 = GetSubString(sub1, ",", j); + gridparams->isolevels.push_back( Isolevel() ); + + gridparams->isolevels.back().value = atof(sub2); + + gridparams->isolevels.back().Ncolorinfo = 0; + + char*N = strchr(sub2, ':'); + if (N) + { + N++; + int Nvalues = NumberOfItems(N, "/"); + if (Nvalues > 7 ) + Nvalues = 7; + + for(int k=0; k<Nvalues; k++) + { + char*sub3 = GetSubString(N, "/", k); + char*number = sub3; + while(*number && !isdigit(*number)) number++; + gridparams->isolevels.back().colorinfo[k] = atof(number); + free(sub3); + } + + gridparams->isolevels.back().Ncolorinfo = Nvalues; + } + + free(sub2); + } + + free(sub1); + + + /*- 3 -----------------------------------------------------------------*/ + /* The third () pair contains the list of output formats */ + sub1 = GetSubString(sub0, "()", 2); + + /* See how many there are by counting the number of commas + 1 */ + nformats = NumberOfItems(sub1, ","); + + /* and get the values */ + gridparams->formats = 0; + for(j=0; j<nformats; j++) + { + sub2 = GetSubString(sub1, ",", j); + if( !strcmp(sub2, "BIN") ) + gridparams->formats |= BIN; + else if (!strcmp(sub2, "VRML")) + gridparams->formats |= VRML; + else if (!strcmp(sub2, "ASCII")) + gridparams->formats |= ASCII; + else if (!strcmp(sub2, "UCD")){ +#ifdef VERBOSE + printf("UCD found in formats string\n"); +#endif + gridparams->formats |= UCD; + } + else if (!strcmp(sub2,"SOCK")){ /* JMS addition */ +#ifdef VERBOSE + printf("SOCK found in formats string for %d\n",i); +#endif + gridparams->formats |= SOCK; + } + else if (!strcmp(sub2,"ISOHDF5")){ /* TR addition */ +#ifdef VERBOSE + printf("HDF5 found in formats string for %d\n",i); +#endif + gridparams->formats |= ISOHDF5; + } + else if(!strcmp(sub2,"NONE")){ +#ifdef VERBOSE + printf("NONE string found in formats string\n"); +#endif + gridparams->formats |= NONE; + } + else + { + printf("Isosurfacer: invalid output format '%s'\n", sub2); + printf(" supported formats are: BIN, VRML, ASCII, UCD, SOCK\n"); + free(sub2); + free(sub1); + free(sub0); + return 0; + } + free(sub2); + } + + free(sub1); + + + /*- 4 -----------------------------------------------------------------*/ + /* The fourth () pair contains the other various parameters */ + sub1 = GetSubString(sub0, "()", 3); + + /* Check that the amount of them is correct (=4) */ + if( NumberOfItems(sub1, ",") != 4) + { + printf("Isosurfacer: improperly formed parameter string '%s'\n", s); + printf(" there should be exactly 4 parameters in the last () pair\n"); + free(sub1); + free(sub0); + return 0; + } + + /* The first one is the frequency of output */ + sub2 = GetSubString(sub1, ",", 0); + gridparams->outfreq = (CCTK_INT4)atoi(sub2); + free(sub2); + + /* Then the first iteration */ + sub2 = GetSubString(sub1, ",", 1); + gridparams->firstIteration = (CCTK_INT4)atoi(sub2); + free(sub2); + + /* Then the resolution */ + sub2 = GetSubString(sub1, ",", 2); + gridparams->resolution = (CCTK_INT4)atoi(sub2); + free(sub2); + + /* And finally the "uniq_vertices" flag */ + sub2 = GetSubString(sub1, ",", 3); + gridparams->uniq_verts = (CCTK_INT4)atoi(sub2); + free(sub2); + + free(sub1); + + free(sub0); + } + + return n; +} + +/*****************************************************************************/ + +CCTK_INT4 +NumberOfItems(char *s, char *d) +{ + int ld, i; + int result; + char *p; + + result = 0; + ld = strlen(d); + + switch(ld) + { + case 1: + p = s; + while( *p != '\0' ) + { + if( *p++ == d[0] ) + result++; + } + if( p != s ) + result++; + return result; + + case 2: + p = s; + i = 0; + while( *p != '\0' ) + { + if ( *p++ == d[i] ) + { + result++; + i = (i==0)?1:0; + } + } + if( (result % 2) != 0 ) + return 0; + else + return result/2; + + default: + return 0; + } +} + +/*****************************************************************************/ + +char * +GetSubString(char *s, char *d, CCTK_INT4 n) +{ + int ld, count, i; + char *result; + char *p, *q = NULL; + + result = NULL; + ld = strlen(d); + + p = s; + count = 0; + switch(ld) + { + case 1: + q = p; + while( *p != '\0' ) + { + if( *p++ == d[0] ) + { + if(count == n) + break; + else + { + count++; + q = p; + } + } + } + if(*p == '\0') + p++; + break; + + case 2: + i = 0; + while( *p != '\0' ) + { + if ( *p++ == d[i] ) + { + if(i==0) + { + q = p; + } + else + { + if(count == n) + break; + else + count++; + } + i = (i==0)?1:0; + } + } + break; + + default: + return NULL; + } + + if(count == n) + { + while( *q == ' ' ) + q++; + p-=2; + while( *p == ' ' ) + p--; + p++; + result = NEW((p-q+1), char); + strncpy(result, q, p-q); + result[p-q] = '\0'; + } + return result; +} + +/**********************************************************/ |