From 84caf40279e3658c39488680ca0a9f297e0ee467 Mon Sep 17 00:00:00 2001 From: lanfer Date: Fri, 29 Oct 1999 08:40:46 +0000 Subject: more routines for elliptic database (not added to make yet) examples in maximal.F and SOR's Startup git-svn-id: http://svn.cactuscode.org/arrangements/CactusElliptic/EllBase/trunk@17 57bc7290-fb3d-4efd-a9b1-28e84cce6043 --- src/Ell_DBstructure.c | 200 +++++++++++++++++++++++++++++++++++++++++++++----- src/Ell_DBstructure.h | 42 ++++++++++- 2 files changed, 222 insertions(+), 20 deletions(-) diff --git a/src/Ell_DBstructure.c b/src/Ell_DBstructure.c index 572bf61..39d2485 100644 --- a/src/Ell_DBstructure.c +++ b/src/Ell_DBstructure.c @@ -43,7 +43,6 @@ int Ell_CreateKey(int vartype, const char *keychain) { 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; } @@ -51,6 +50,131 @@ int Ell_CreateKey(int vartype, const char *keychain) { return(retval); } +int Ell_IsKey(const char *keychain) { + int retval; + if ((struct t_ellthingy*)GetNamedData(EllInfoDB, keychain)) { + retval = 0; + } + retval = ELL_ISNOKEY; +} + +void FMODIFIER FORTRAN_NAME(Ell_IsKey)(int *ierr, ONE_FORTSTRING_ARG) { + ONE_FORTSTRING_CREATE(key) + *ierr = Ell_IsKey(key); + free(key); +} + +int Ell_UnsetKey(const char *keychain) { + + struct t_ellthingy* getme; + 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 = ELLGET_NOKEY; + } else { + getme->been_set = ELL_NO; + retval = 0; + } +} + +int Ell_DeleteKey(const char *keychain) { + int retval; + printf("NO IMPLEMENTED YET!"); + retval = 1; +} + +void FMODIFIER FORTRAN_NAME(Ell_DeleteKey)(int *ierr, ONE_FORTSTRING_ARG){ + ONE_FORTSTRING_CREATE(key); + *ierr = Ell_DeleteKey(key); + free(key); +} + + +/*** SET OPERATIONS ***/ + +int Ell_SetRealKey(CCTK_REAL value, const char *keychain) { + int retval; + struct t_ellthingy *setme; + + setme = GetNamedData(EllInfoDB, keychain); + if (!(setme)) { + retval = ELLSET_FAILED; + } + else { + setme->type = CCTK_VARIABLE_INT; + setme->vals.r = value; + setme->been_set = ELL_YES; + 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); +} + +int Ell_SetIntKey(CCTK_INT value, const char *keychain) { + int retval; + struct t_ellthingy *setme; + + setme = GetNamedData(EllInfoDB, keychain); + if (!(setme)) { + retval = ELLSET_FAILED; + } + else { + setme->type = CCTK_VARIABLE_INT; + setme->vals.i = value; + setme->been_set = ELL_YES; + retval=0; + } + return(retval); +} + +void FMODIFIER FORTRAN_NAME(Ell_SetIntKey) + (int *ierr, CCTK_REAL *value, ONE_FORTSTRING_ARG) { + ONE_FORTSTRING_CREATE(key) + *ierr = Ell_SetIntKey(*value, key); + free(key); +} + +int Ell_SetStrKey(char *value, const char *keychain) { + int retval; + struct t_ellthingy *setme; + + setme = GetNamedData(EllInfoDB, keychain); + if (!(setme)) { + retval = ELLSET_FAILED; + } + else { + setme->type = CCTK_VARIABLE_STRING; + setme->vals.s = value; + setme->been_set = ELL_YES; + retval=0; + } + return(retval); +} + +void FMODIFIER FORTRAN_NAME(Ell_SetStringKey) + (int *ierr, TWO_FORTSTRINGS_ARGS) { + TWO_FORTSTRINGS_CREATE(value,key) + *ierr = Ell_SetStrKey(value, key); + free(value); + free(key); +} + + + + + + +/*** GET OPERATIONS ***/ int Ell_GetRealKey(CCTK_REAL *value, const char *keychain) { @@ -63,12 +187,12 @@ int Ell_GetRealKey(CCTK_REAL *value, const char *keychain) { if (!(getme)) { printf("Ell_GetRealKey: Cannot get structure with key >%s< \n",keychain); printf("Ell_GetRealKey: Create first!\n"); - retval = ELLGETREAL_NKEY; + retval = ELLGET_NOKEY; } 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; + retval = ELLGET_BADTYPE; } else { *value=getme->vals.r; @@ -84,33 +208,75 @@ void FMODIFIER FORTRAN_NAME(Ell_GetRealKey) free(key); } +int Ell_GetIntKey(CCTK_INT *value,const char *keychain) { -int Ell_SetRealKey(CCTK_REAL value, const char *keychain) { + struct t_ellthingy *getme=NULL; int retval; - struct t_ellthingy *setme; + getme = (struct t_ellthingy*)GetNamedData(EllInfoDB, keychain); - setme = GetNamedData(EllInfoDB, keychain); - if (!(setme)) { - retval = ELLSETREAL_FAILED; + if (!(getme)) { + printf("Ell_GetRealKey: Cannot get structure with key >%s< \n",keychain); + printf("Ell_GetRealKey: Create first!\n"); + retval = ELLGET_NOKEY; } - else { - setme->type = CCTK_VARIABLE_REAL; - setme->vals.r = value; - setme->been_set = 1; + 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 = ELLGET_BADTYPE; + } + else if (getme->been_set==ELL_NO) { + printf("Key has not been set"); + retval = ELLGET_NOTSET; + } else { + *value=getme->vals.r; retval=0; } return(retval); } -void FMODIFIER FORTRAN_NAME(Ell_SetRealKey) - (int *ierr, CCTK_REAL *value, ONE_FORTSTRING_ARG) { - +void FMODIFIER FORTRAN_NAME(Ell_GetIntKey) + (int *ierr, CCTK_INT *value, ONE_FORTSTRING_ARG) { ONE_FORTSTRING_CREATE(key) - *ierr = Ell_SetRealKey(*value, key); + *ierr = Ell_GetIntKey(value, key); free(key); +} + +int Ell_GetStrKey(char *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 = ELLGET_NOKEY; + } + 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 = ELLGET_BADTYPE; + } + else if (getme->been_set==ELL_NO) { + printf("Key has not been set"); + retval = ELLGET_NOTSET; + } else { + *value=getme->vals.r; + retval=0; + } + return(retval); +} + +void FMODIFIER FORTRAN_NAME(Ell_GetStrKey) + (int *ierr, TWO_FORTSTRINGS_ARGS) { + TWO_FORTSTRINGS_CREATE(value,key) + *ierr = Ell_GetStrKey(value, key); + free(key); + free(value); +} -} diff --git a/src/Ell_DBstructure.h b/src/Ell_DBstructure.h index 673c4b5..670649e 100644 --- a/src/Ell_DBstructure.h +++ b/src/Ell_DBstructure.h @@ -2,12 +2,48 @@ #define _ELLBASE_H_ + +#define ELL_NO 0 +#define ELL_YES 1 +#define ELL_ISNOKEY -1 + #define ELLCREATE_FAILED -1 #define ELLCREATE_TWICE -2 + +#define ELLGET_NOKEY -1 +#define ELLGET_BADTYPE -2 +#define ELLGET_NOTSET -3 + +#define ELLSET_FAILED -1 + + + +#ifdef CCODE + +#ifdef __cplusplus +extern "C" { +#endif + +int Ell_CreateKey(int vartype, const char *keychain); +int Ell_IsKey(const char *keychain); +int Ell_UnsetKey(const char *keychain); +int Ell_DeleteKey(const char *keychain); + +int Ell_SetRealKey(CCTK_REAL value, const char *keychain); +int Ell_SetIntKey(CCTK_INT value, const char *keychain); +int Ell_SetStrKey(char *value, const char *keychain); + +int Ell_GetRealKey(CCTK_REAL *value, const char *keychain); +int Ell_GetIntKey(CCTK_INT *value,const char *keychain); +int Ell_GetStrKey(char *value, const char *keychain); + + +#ifdef __cplusplus +} +#endif + +#endif -#define ELLGETREAL_NKEY -1 -#define ELLGETREAL_NREAL -2 -#define ELLSETREAL_FAILED -1 #endif -- cgit v1.2.3