#include #include #include #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) { DECLARE_CCTK_PARAMETERS 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; if (StoreNamedData(&EllInfoDB, keychain, new)!=0) { if (!CCTK_Equals(elliptic_verbose,"no")) { char *msg; char *name=CCTK_VarTypeName(vartype); msg = (char *)malloc( (200 + strlen(keychain) + strlen(name) )*sizeof(char) ); sprintf(msg,"Failed to create %s (%s)",keychain,name); CCTK_INFO(msg); free(msg); } retval = ELLCREATE_FAILED; } else { if (!CCTK_Equals(elliptic_verbose,"no")) { char *msg; char *name=CCTK_VarTypeName(vartype); msg = (char *)malloc( (200 + strlen(keychain) + strlen(name) )*sizeof(char) ); sprintf(msg,"Created %s (%s)",keychain,name); CCTK_INFO(msg); free(msg); } retval = 0; } } return(retval); USE_CCTK_PARAMETERS } int Ell_IsKey(const char *keychain) { int retval=ELL_ISNOKEY; if ((struct t_ellthingy*)GetNamedData(EllInfoDB, keychain)) { retval = 0; } else retval = ELL_ISNOKEY; return(retval); } 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; } return(retval); } int Ell_DeleteKey(const char *keychain) { int retval; printf("NO IMPLEMENTED YET!"); retval = 1; return(retval); } 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 if (setme->type!=CCTK_VARIABLE_REAL) { retval = ELLSET_BADTYPE; printf("Ell_SetRealKey: The key you try to set is not of type CCTK_REAL: >%s< (type %d)\n", keychain,setme->type); } else { setme->type = CCTK_VARIABLE_REAL; 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 if (setme->type!=CCTK_VARIABLE_INT) { retval = ELLSET_BADTYPE; printf("Ell_SetIntKey: The key you try to set is not of type CCTK_INT: >%s< (type %d)\n", keychain,setme->type); } 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_INT *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 if (setme->type!=CCTK_VARIABLE_STRING) { retval = ELLSET_BADTYPE; printf("Ell_SetStrKey: The key you try to set is not of type STRING: >%s< (type %d)\n", keychain,setme->type); } 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) { 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("Ell_GetRealKey: You are not getting a CCTK_REAL value off this key: >%s< type: %d (need %d)\n", keychain,getme->type,CCTK_VARIABLE_REAL); retval = ELLGET_BADTYPE; } else if (getme->been_set==ELL_NO) { printf("Ell_GetRealKey: This key has not been set to any value: >%s< \n",keychain); retval = ELLGET_NOTSET; } else { *value=getme->vals.r; retval=0; } printf("GetReal: %f %f\n",*value,getme->vals.r); 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_GetIntKey(CCTK_INT *value,const char *keychain) { struct t_ellthingy *getme=NULL; int retval; getme = (struct t_ellthingy*)GetNamedData(EllInfoDB, keychain); if (!(getme)) { printf("Ell_GetIntKey: Cannot get structure with key >%s< \n",keychain); printf("Ell_GetIntKey: Create first!\n"); retval = ELLGET_NOKEY; } else if (getme->type!=CCTK_VARIABLE_INT) { printf("Ell_GetIntKey: You are not getting a CCTK_INT value off this key: >%s< type: %d\n", keychain,getme->type); retval = ELLGET_BADTYPE; } else if (getme->been_set==ELL_NO) { printf("Ell_GetIntKey: Key has not been set to any value: >%s< type %d\n",keychain,getme->type); retval = ELLGET_NOTSET; } else { *value=getme->vals.i; retval=0; } return(retval); } void FMODIFIER FORTRAN_NAME(Ell_GetIntKey) (int *ierr, CCTK_INT *value, ONE_FORTSTRING_ARG) { ONE_FORTSTRING_CREATE(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_STRING) { 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\n"); retval = ELLGET_NOTSET; } else { *value=getme->vals.r; retval=0; } return(retval); } void FMODIFIER FORTRAN_NAME(Ell_GetStrKey) (int *nchar, char **cstring,ONE_FORTSTRING_ARG) { int i; ONE_FORTSTRING_CREATE(fstring) ONE_FORTSTRING_PTR(fptr) if (strlen(*cstring) > cctk_strlen1) { char *message; message = (char *)malloc( (200+strlen(*cstring))*sizeof(char) ); sprintf(message,"Cannot output %s to char* of length %d\n", *cstring,cctk_strlen1); CCTK_Warn (1,__LINE__,__FILE__,"Cactus",message); free(message); *nchar = -1; } for (i=0;i