summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgoodale <goodale@17b73243-c579-4c4c-a9d2-2d5706c11dac>1999-01-21 11:11:35 +0000
committergoodale <goodale@17b73243-c579-4c4c-a9d2-2d5706c11dac>1999-01-21 11:11:35 +0000
commit85477596402e451bbd9b484cf82b2d42636f0128 (patch)
treeaaa384d51120ebd22c335900dea1dd0975a92be1
parent1fb86a584a8f490faece6d9ffa9d09bbb0995b38 (diff)
Added functions to set tha values of ints, doubles, keywords, strings, etc
as required by the bindings. Tom git-svn-id: http://svn.cactuscode.org/flesh/trunk@98 17b73243-c579-4c4c-a9d2-2d5706c11dac
-rw-r--r--src/include/Misc.h9
-rw-r--r--src/util/Misc.c250
2 files changed, 259 insertions, 0 deletions
diff --git a/src/include/Misc.h b/src/include/Misc.h
index 55cae343..b4643235 100644
--- a/src/include/Misc.h
+++ b/src/include/Misc.h
@@ -26,6 +26,15 @@ int CCTK_DoubleInRange(double inval, const char *range);
int CCTK_IntInRangeList(int inval, int n_elements, ...);
int CCTK_DoubleInRangeList(double inval, int n_elements, ...);
+int CCTK_SetDoubleInRangeList(double *data, const char *value,
+ int n_elements, ...);
+int CCTK_SetIntInRangeList(int *data, const char *value,
+ int n_elements, ...);
+int CCTK_SetKeywordInRangeList(char **data, const char *value,
+ int n_elements, ...);
+int CCTK_SetString(char **data, const char *value);
+int CCTK_SetLogical(int *data, const char *value);
+
#ifdef _cplusplus
}
#endif
diff --git a/src/util/Misc.c b/src/util/Misc.c
index bca572ea..4aca8fb0 100644
--- a/src/util/Misc.c
+++ b/src/util/Misc.c
@@ -292,3 +292,253 @@ int CCTK_DoubleInRangeList(double inval, int n_elements, ...)
}
+
+ /*@@
+ @routine CCTK_SetDoubleInRangeList
+ @date Thu Jan 21 09:41:21 1999
+ @author Tom Goodale
+ @desc
+ Sets the value of a double if the desired value is in one of
+ the specified ranges.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+int CCTK_SetDoubleInRangeList(double *data, const char *value,
+ int n_elements, ...)
+{
+ int retval;
+ char temp[1001];
+ int p;
+ int arg;
+ va_list ap;
+
+ char *element;
+
+ double inval;
+
+ retval = 1;
+
+ /* Convert the value string to a double.
+ * Allow various formats.
+ */
+ strncpy(temp, value, 1000);
+
+ for (p=0;p<strlen(temp);p++)
+ {
+ if (temp[p] == 'E' ||
+ temp[p] == 'd' ||
+ temp[p] == 'D')
+ {
+ temp[p] = 'e';
+ break;
+ }
+ }
+
+ inval = atof(temp);
+
+ /* Walk through the element list. */
+ va_start(ap, n_elements);
+
+ for(arg = 0; arg < n_elements; arg++)
+ {
+ element = va_arg(ap, char *);
+
+ if(CCTK_DoubleInRange(inval, element))
+ {
+ retval = 0;
+ *data = inval;
+ break;
+ }
+ }
+
+ va_end(ap);
+
+ return retval;
+}
+
+ /*@@
+ @routine CCTK_SetIntInRangeList
+ @date Thu Jan 21 10:27:26 1999
+ @author Tom Goodale
+ @desc
+ Sets the value of a integer if the desired value is in one of
+ the specified ranges.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+int CCTK_SetIntInRangeList(int *data, const char *value,
+ int n_elements, ...)
+{
+ int retval;
+ int arg;
+ va_list ap;
+
+ char *element;
+
+ int inval;
+
+ retval = 1;
+
+ /* Convert the value string to an int.*/
+
+ inval = atoi(value);
+
+ /* Walk through the element list. */
+ va_start(ap, n_elements);
+
+ for(arg = 0; arg < n_elements; arg++)
+ {
+ element = va_arg(ap, char *);
+
+ if(CCTK_IntInRange(inval, element))
+ {
+ retval = 0;
+ *data = inval;
+ break;
+ }
+ }
+
+ va_end(ap);
+
+ return retval;
+}
+
+ /*@@
+ @routine CCTK_SetKeywordInRangeList
+ @date Thu Jan 21 10:28:00 1999
+ @author Tom Goodale
+ @desc
+ Sets the value of a keyword if the desired value is in one of
+ the specified ranges.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+int CCTK_SetKeywordInRangeList(char **data, const char *value,
+ int n_elements, ...)
+{
+ int retval;
+ int arg;
+ va_list ap;
+
+ char *element;
+
+ int inval;
+
+ retval = 1;
+
+ /* Walk through the element list. */
+ va_start(ap, n_elements);
+
+ for(arg = 0; arg < n_elements; arg++)
+ {
+ element = va_arg(ap, char *);
+
+ if(CCTK_Equals(value, element))
+ {
+ if(*data) free(*data);
+ *data = (char *)malloc((strlen(value)+1)*sizeof(char));
+ if(*data)
+ {
+ strcpy(*data, value);
+ retval = 0;
+ }
+ else
+ {
+ retval =-1;
+ }
+ break;
+ }
+ }
+
+ va_end(ap);
+
+ return retval;
+}
+
+
+ /*@@
+ @routine CCTK_SetString
+ @date Thu Jan 21 10:28:27 1999
+ @author Tom Goodale
+ @desc
+ Sets the value of a string
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+int CCTK_SetString(char **data, const char *value)
+{
+ int retval;
+
+ retval = 1;
+
+ if(*data) free(*data);
+ *data = (char *)malloc((strlen(value)+1)*sizeof(char));
+ if(*data)
+ {
+ strcpy(*data, value);
+ retval = 0;
+ }
+ else
+ {
+ retval = -1;
+ }
+
+ return retval;
+}
+
+ /*@@
+ @routine CCTK_SetLogical
+ @date Thu Jan 21 10:35:11 1999
+ @author Tom Goodale
+ @desc
+ Sets the value of a logical to true or false according to
+ the value of the value string.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+int CCTK_SetLogical(int *data, const char *value)
+{
+ int retval = 1;
+
+ if(CCTK_InList(value, 5, "true", "t", "yes", "y", "1"))
+ {
+ *data = 1;
+ retval = 0;
+ }
+ else if(CCTK_InList(value, 5, "false", "f", "no", "n", "0"))
+ {
+ *data = 0;
+ retval = 0;
+ }
+ else
+ {
+ retval = -1;
+ }
+
+ return retval;
+}