aboutsummaryrefslogtreecommitdiff
path: root/src/ParseVars.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ParseVars.c')
-rw-r--r--src/ParseVars.c204
1 files changed, 204 insertions, 0 deletions
diff --git a/src/ParseVars.c b/src/ParseVars.c
new file mode 100644
index 0000000..f441234
--- /dev/null
+++ b/src/ParseVars.c
@@ -0,0 +1,204 @@
+ /*@@
+ @file GHExtension.c
+ @date Tue 9th Feb 1999
+ @author Gabrielle Allen
+ @desc
+ IOUtil GH extension stuff.
+ @enddesc
+ @history
+ @endhistory
+ @@*/
+
+/*#define DEBUG_IO*/
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "cctk.h"
+#include "util_String.h"
+#include "cctk_Parameters.h"
+
+#include "StreamedHDF5GH.h"
+
+
+static char *rcsid = "$Header$";
+
+
+/* ===============================================================
+ utility routines used by other IO thorns
+ ===============================================================*/
+
+ /*@@
+ @routine IOUtil_ParseVarsForOutput
+ @date Sat March 6 1999
+ @author Gabrielle Allen
+ @desc
+ Sets each flag in the do_output[] do_output to true
+ if var[i] could be found in the list of variable names.
+ var_list my also contain group names of variables as well as the
+ special keyword "all" which indicates that output is requested
+ on all variables.
+ @enddesc
+ @history
+ @endhistory
+ @var var_list
+ @vdesc list of variables and/or group names
+ @vtype const char *
+ @vio in
+ @endvar
+ @var do_output
+ @vdesc do_output of flags indicating output was requested for var[i]
+ @vtype char []
+ @vio out
+ @endvar
+@@*/
+
+void ParseVarsForOutput (StreamedHDF5GH *h5GH, const char *var_list)
+{
+ char *outname=NULL;
+ char *before=NULL;
+ char *after=NULL;
+ char *splitstring;
+ int first,groupnum,i,last,index,varnum;
+ StreamGeo_t geo_tmp;
+ int ierr=0;
+
+ /* First initialise every variable to no output */
+ for (i=0; i<CCTK_NumVars(); i++)
+ {
+ h5GH->do_output[i] = 0;
+ }
+
+ /* Initialize geometry structure with default */
+ SetDefaultGeo(&geo_tmp);
+
+ splitstring = (char *) var_list;
+
+ /* split string at blanks */
+ while(Util_SplitString(&before,&after,splitstring," ")==0) {
+
+#ifdef DEBUG_IO
+ printf(" String is -%s-\n",splitstring);
+ printf(" Split is -%s- and -%s-\n",before,after);
+#endif
+
+ if (CCTK_Equals(before," ")) continue;
+
+ if (strlen(before) > 0)
+ {
+ /* Extract geometry information */
+ ierr=GeometryParser(before, &outname, &geo_tmp);
+ if (ierr<0) printf("GeometryParser failed: >%s<\n",before);
+
+ /* Look for any special tokens */
+ if (CCTK_Equals(outname,"all"))
+ {
+ int ilab;
+ for (ilab=0;ilab<CCTK_NumVars();ilab++) {
+ h5GH->geo_output[ilab]= geo_tmp;
+ h5GH->do_output[ilab] = 1;
+ }
+ }
+ else
+ {
+ /* See if this name is implementation::variable */
+ varnum = CCTK_VarIndex(outname);
+ if ( varnum < 0 )
+ {
+ /* See if this name is implementation::group */
+ groupnum = CCTK_GroupIndex(outname);
+ if (groupnum < 0)
+ {
+ char *msg;
+ msg = (char *)malloc((100+strlen(outname))*sizeof(char));
+ sprintf(msg,"Ignoring <%s> in IO string (invalid token)",outname);
+ CCTK_WARN(2,msg);
+ free(msg);
+ }
+ else
+ {
+ /* We have a group so now need all the variables in the group */
+ first = CCTK_FirstVarIndexI(groupnum);
+ last = first+CCTK_NumVarsInGroupI(groupnum)-1;
+ for (index=first;index<=last;index++) {
+ h5GH->geo_output[index]=geo_tmp;
+ h5GH->do_output[index] =1;
+ }
+ }
+ }
+ else
+ {
+ h5GH->geo_output[varnum]= geo_tmp;
+ h5GH->do_output[varnum] = 1;
+ }
+ }
+ }
+ if(before)
+ {
+ free(before);
+ before = NULL;
+ }
+ if(outname)
+ {
+ free(outname);
+ outname = NULL;
+ }
+ if(splitstring != var_list)
+ {
+ free(splitstring);
+ }
+
+ splitstring = after;
+
+ }
+
+ if (strlen(splitstring)>0) {
+
+ /* Extract geometry information */
+ ierr=GeometryParser(splitstring, &outname, &geo_tmp);
+ if (ierr<0) printf("GeometryParser failed: >%s<\n",before);
+
+ /* Special cases */
+ if (CCTK_Equals(splitstring,"all")) {
+ int ilab;
+ for (ilab=0;ilab<CCTK_NumVars();ilab++) {
+ h5GH->geo_output[ilab]=geo_tmp;
+ h5GH->do_output [ilab]=1;
+ }
+ } else {
+
+ varnum = CCTK_VarIndex(splitstring);
+ if (varnum < 0) {
+ groupnum = CCTK_GroupIndex(splitstring);
+ if (groupnum < 0) {
+ char *msg;
+ msg = (char *)malloc((100+strlen(splitstring))*sizeof(char));
+ sprintf(msg,"Ignoring %s in IO string (invalid token)",splitstring);
+ CCTK_WARN(2,msg);
+ free(msg);
+ } else {
+ /* We have a group so now need all the variables in the group */
+ first = CCTK_FirstVarIndexI(groupnum);
+ last = first+CCTK_NumVarsInGroupI(groupnum)-1;
+ for (index=first;index<=last;index++) {
+ h5GH->geo_output[index]=geo_tmp;
+ h5GH->do_output[index] =1;
+ }
+ }
+ }
+ else {
+ h5GH->geo_output[varnum]=geo_tmp;
+ h5GH->do_output[varnum] =1;
+ }
+ }
+ }
+
+ if (before) free(before);
+ if (after) free(after);
+ if(splitstring != var_list)
+ {
+ free(splitstring);
+ }
+
+}