aboutsummaryrefslogtreecommitdiff
path: root/src/Ell_DBstructure.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/Ell_DBstructure.c')
-rw-r--r--src/Ell_DBstructure.c117
1 files changed, 117 insertions, 0 deletions
diff --git a/src/Ell_DBstructure.c b/src/Ell_DBstructure.c
new file mode 100644
index 0000000..572bf61
--- /dev/null
+++ b/src/Ell_DBstructure.c
@@ -0,0 +1,117 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "cctk.h"
+#include "cctk_parameters.h"
+#include "cctk_WarnLevel.h"
+#include "cctk_FortranString.h"
+
+#include "StoreNamedData.h"
+
+#include "Ell_DBstructure.h"
+
+static pNamedData *EllInfoDB;
+
+struct t_ellthingy
+{
+ int type;
+ int been_set;
+ union
+ {
+ CCTK_REAL r;
+ CCTK_INT i;
+ char *s;
+ } vals;
+};
+
+int Ell_CreateKey(int vartype, const char *keychain) {
+
+ struct t_ellthingy* new;
+ int retval;
+
+ if ((struct t_ellthingy*)GetNamedData(EllInfoDB, keychain)) {
+ retval = ELLCREATE_TWICE;
+ } else {
+
+ new = (struct t_ellthingy*)malloc(sizeof(struct t_ellthingy));
+
+ new->type = vartype;
+ new->been_set = 0;
+ new->vals.r = 0.0;
+ new->vals.i = 0;
+ new->vals.s = NULL;
+
+ printf("Ell_Base: Creating key >%s< (type %d) \n",keychain,new->type);
+ retval = StoreNamedData(&EllInfoDB, keychain, new);
+ if (retval!=0) retval = ELLCREATE_FAILED;
+ }
+
+ return(retval);
+}
+
+
+
+int Ell_GetRealKey(CCTK_REAL *value, const char *keychain) {
+
+ struct t_ellthingy *getme=NULL;
+ int retval;
+
+ getme = (struct t_ellthingy*)GetNamedData(EllInfoDB, keychain);
+
+ if (!(getme)) {
+ printf("Ell_GetRealKey: Cannot get structure with key >%s< \n",keychain);
+ printf("Ell_GetRealKey: Create first!\n");
+ retval = ELLGETREAL_NKEY;
+ }
+ else if (getme->type!=CCTK_VARIABLE_REAL) {
+ printf("You are not getting a CCTK_REAL value off this key: >%s< type: %d\n",
+ keychain,getme->type);
+ retval = ELLGETREAL_NREAL;
+ }
+ else {
+ *value=getme->vals.r;
+ retval=0;
+ }
+ return(retval);
+}
+
+void FMODIFIER FORTRAN_NAME(Ell_GetRealKey)
+ (int *ierr, CCTK_REAL *value, ONE_FORTSTRING_ARG) {
+ ONE_FORTSTRING_CREATE(key)
+ *ierr = Ell_GetRealKey(value, key);
+ free(key);
+}
+
+
+int Ell_SetRealKey(CCTK_REAL value, const char *keychain) {
+ int retval;
+
+ struct t_ellthingy *setme;
+
+ setme = GetNamedData(EllInfoDB, keychain);
+ if (!(setme)) {
+ retval = ELLSETREAL_FAILED;
+ }
+ else {
+ setme->type = CCTK_VARIABLE_REAL;
+ setme->vals.r = value;
+ setme->been_set = 1;
+ retval=0;
+ }
+ return(retval);
+}
+
+void FMODIFIER FORTRAN_NAME(Ell_SetRealKey)
+ (int *ierr, CCTK_REAL *value, ONE_FORTSTRING_ARG) {
+
+ ONE_FORTSTRING_CREATE(key)
+ *ierr = Ell_SetRealKey(*value, key);
+ free(key);
+
+}
+
+
+
+