/*@@ @file OutputInfo.c @date June 31 1999 @author Gabrielle Allen @desc Functions to deal with Info output of Variables @enddesc @@*/ /*#define IO_DEBUG*/ #include #include #include #include #include "cctk.h" #include "cctk_Parameters.h" #include "CactusBase/IOUtil/src/ioGH.h" #include "iobasicGH.h" /* extern prototypes */ int IOBasic_WriteInfo (cGH *GH, CCTK_REAL *val,int index, const char *operator, const char *alias); /* the number at which to switch from decimal to exp notation */ #define DECIMAL_PRECISION 1.0e-8 #define DECIMAL_TOOBIG 1.0e+8 #define USE_DECIMAL_NOTATION(x) ((fabs (x) > DECIMAL_PRECISION) || ((x) == 0.0) || (fabs(x) < DECIMAL_TOOBIG)) /* static variables */ static int print_header = 0; static int outInfo_vars_lastset = 0; /*@@ @routine IOBasic_OutputInfoGH @date June 31 1999 @author Gabrielle Allen @desc Loops over all variables and prints output if requested method @enddesc @history @endhistory @var GH @vdesc Pointer to CCTK GH @vtype cGH @vio in @vcomment @endvar @@*/ int IOBasic_OutputInfoGH (cGH *GH) { DECLARE_CCTK_PARAMETERS int i; int ierr1=-1; int ierr2=-1; const char *name; iobasicGH *myGH; const cParamData *paramdata; CCTK_REAL val; /* Get the GH extensions for IOBasic */ myGH = (iobasicGH *) GH->extensions [CCTK_GHExtensionHandle ("IOBasic")]; /* How often to output */ myGH->outInfo_every = out_every > 0 ? out_every : -1; if (outInfo_every > 0) { myGH->outInfo_every = outInfo_every; } /* Return if no output is required */ if (myGH->outInfo_every < 1 || GH->cctk_iteration % myGH->outInfo_every != 0) { return (0); } /* Check the 'outInfo_vars' parameter */ paramdata = CCTK_ParameterData ("outInfo_vars", CCTK_THORNSTRING); if (! paramdata) { CCTK_WARN (1, "Couldn't get info on parameter 'outInfo_vars'"); return (0); } /* re-parse the 'outInfo_vars' parameter if it was changed and also print a header */ if (paramdata->n_set != outInfo_vars_lastset) { int do_outInfo; IOUtil_ParseVarsForOutput (outInfo_vars, myGH->do_outInfo); /* Save the last setting of 'outInfo_vars' parameter */ outInfo_vars_lastset = paramdata->n_set; do_outInfo = 0; for (i = 0; i < CCTK_NumVars (); i++) do_outInfo |= myGH->do_outInfo [i]; /* suppress any output if there are no variables to output */ if (! do_outInfo) return (0); print_header = 1; } if (print_header) { char l1[1024],l2[1024],l3[1024]; print_header = 0; sprintf (l1," it | |"); sprintf (l2," | t |"); sprintf (l3,"----------------"); for (i = 0; i < CCTK_NumVars (); i++) { char ll[80]; if(myGH->do_outInfo [i]) { sprintf (ll," "); ll[25-strlen(CCTK_VarName(i))] = '\0'; sprintf (l1,"%s %s%s |",l1,CCTK_VarName(i),ll); sprintf (l2,"%s Min Max |",l2); sprintf (l3,"%s----------------------------",l3); } } printf ("%s\n%s\n%s\n%s\n",l3,l1,l2,l3); fflush(stdout); } /* Print the iteration/timestep information for all variables */ if (USE_DECIMAL_NOTATION (GH->cctk_time)) { printf("%4d |%9.3f|",GH->cctk_iteration,GH->cctk_time); } else { printf("%4d |%7.3e|",GH->cctk_iteration,GH->cctk_time); } /* Loop over all variables */ for (i = 0; i < CCTK_NumVars (); i++) { /* Check this Variable should be output */ if (! myGH->do_outInfo [i]) { continue; } /* Check variable not already output this iteration */ if (myGH->outInfo_last [i] != GH->cctk_iteration) { /* Get the variable name for this index (for filename) */ name = CCTK_VarName(i); #ifdef IO_DEBUG printf("\nIn IO OutputInfoGH\n----------------\n"); printf(" Index = %d\n",i); printf(" Variable = -%s-\n",name); printf(" Last output iteration was = %d\n",myGH->outInfo_last[i]); #endif /* Make the IO call */ ierr1 = IOBasic_WriteInfo (GH, &val, i, "minimum", name); myGH->infovals[i][0] = val; ierr2 = IOBasic_WriteInfo (GH, &val, i, "maximum", name); myGH->infovals[i][1] = val; /* Register GF as having info output this iteration */ myGH->outInfo_last [i] = GH->cctk_iteration; } if (ierr1 == 0) { /* finally print out the stuff */ if (USE_DECIMAL_NOTATION (myGH->infovals [i][0])) { printf ("%12.8f |", myGH->infovals [i][0]); } else { printf ("%10.6e |", myGH->infovals [i][0]); } } else { printf(" ----------- |"); } if (ierr2 == 0) { if (USE_DECIMAL_NOTATION (myGH->infovals [i][1])) { printf ("%12.8f |", myGH->infovals [i][1]); } else { printf ("%10.6e |", myGH->infovals [i][1]); } } else { printf(" ----------- |"); } } /* end of loop over all variables */ /* Add the new line */ printf ("\n"); fflush(stdout); return (0); } /*@@ @routine IOBasic_TimeForInfo @date June 31 1999 @author Gabrielle Allen @desc Decides if it is time to output a variable using info output method @enddesc @calls CCTK_GHExtensionHandle CCTK_GroupTypeFromVarI CCTK_WARN CCTK_QueryGroupStorageI CCTK_GroupFromVar @calledby @history @endhistory @var GH @vdesc Pointer to CCTK GH @vtype cGH @vio in @vcomment @endvar @var var @vdesc index of variable @vtype int @vio in @vcomment @endvar @@*/ int IOBasic_TimeForInfo (cGH *GH, int var) { int return_type; iobasicGH *myGH; const cParamData *paramdata; DECLARE_CCTK_PARAMETERS /* Default is do not do output */ return_type = 0; /* Get the GH extensions for IOBasic */ myGH = (iobasicGH *) GH->extensions [CCTK_GHExtensionHandle ("IOBasic")]; /* How often to output */ myGH->outInfo_every = out_every > 0 ? out_every : -1; if (outInfo_every > 0) myGH->outInfo_every = outInfo_every; /* return if no output requested */ if (myGH->outInfo_every <= 0) return (0); /* Check the 'outInfo_vars' parameter */ paramdata = CCTK_ParameterData ("outInfo_vars", CCTK_THORNSTRING); if (! paramdata) { CCTK_WARN (1, "Couldn't get info on parameter 'outInfo_vars'"); return (0); } /* re-parse the 'outInfo_vars' parameter if it was changed and also print a header */ if (paramdata->n_set != outInfo_vars_lastset) { IOUtil_ParseVarsForOutput (outInfo_vars, myGH->do_outInfo); /* Save the last setting of 'outInfo_vars' parameter */ outInfo_vars_lastset = paramdata->n_set; print_header = 1; } /* Check this GF should be output */ if (myGH->do_outInfo [var] && (GH->cctk_iteration % myGH->outInfo_every == 0)) { /* Check GF not already output this iteration */ if (myGH->outInfo_last [var] == GH->cctk_iteration) CCTK_WARN (2, "Already done info output in IO"); else return_type = 1; } return return_type; } /*@@ @routine IOBasic_TriggerOutputInfo @date June 31 1999 @author Gabrielle Allen @desc Triggers the output of a variable using IOBasic's info output method @enddesc @history @endhistory @var GH @vdesc Pointer to CCTK GH @vtype cGH @vio in @vcomment @endvar @var variable @vdesc index of variable @vtype int @vio in @vcomment @endvar @@*/ int IOBasic_TriggerOutputInfo (cGH *GH, int variable) { const char *var; iobasicGH *myGH; int ierr1,ierr2; CCTK_REAL val; /* Get the GH extension for IOBasic */ myGH = (iobasicGH *) GH->extensions [CCTK_GHExtensionHandle ("IOBasic")]; var = CCTK_VarName (variable); /* Do the Info output */ #ifdef IO_DEBUG printf("\nIn IO TriggerOutputInfo\n---------------------\n"); printf(" Index = %d\n",variable); printf(" Variable = -%s-\n",var); #endif ierr1=IOBasic_WriteInfo (GH, &val, variable, "minimum",var); myGH->infovals[variable][0] = val; ierr2=IOBasic_WriteInfo (GH, &val, variable, "maximum",var); myGH->infovals[variable][1] = val; /* Register GF as having Info output this iteration */ myGH->outInfo_last [variable] = GH->cctk_iteration; return 0; }