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.c255
1 files changed, 177 insertions, 78 deletions
diff --git a/src/Ell_DBstructure.c b/src/Ell_DBstructure.c
index 0dd2e94..f3592ca 100644
--- a/src/Ell_DBstructure.c
+++ b/src/Ell_DBstructure.c
@@ -1,3 +1,12 @@
+/*@@
+ @file Ell_DBstructure.c
+ @date
+ @author Gerd Lanfermann
+ @desc
+ Database for elliptic parameters
+ @enddesc
+ @version $Id$
+ @@*/
#include <stdio.h>
#include <stdlib.h>
@@ -16,7 +25,29 @@ static const char *rcsid = "$Header$";
CCTK_FILEVERSION(CactusElliptic_EllBase_Ell_DBstructure_c)
-static pNamedData *EllInfoDB;
+/********************************************************************
+ ******************** External Routines ************************
+ ********************************************************************/
+void CCTK_FCALL CCTK_FNAME(Ell_IsKey)
+ (int *ierr, ONE_FORTSTRING_ARG);
+void CCTK_FCALL CCTK_FNAME(Ell_DeleteKey)
+ (int *ierr, ONE_FORTSTRING_ARG);
+void CCTK_FCALL CCTK_FNAME(Ell_SetRealKey)
+ (int *ierr, CCTK_REAL *value, ONE_FORTSTRING_ARG);
+void CCTK_FCALL CCTK_FNAME(Ell_SetIntKey)
+ (int *ierr, CCTK_INT *value, ONE_FORTSTRING_ARG);
+void CCTK_FCALL CCTK_FNAME(Ell_SetStrKey)
+ (int *ierr, TWO_FORTSTRINGS_ARGS);
+void CCTK_FCALL CCTK_FNAME(Ell_GetRealKey)
+ (int *ierr, CCTK_REAL *value, ONE_FORTSTRING_ARG);
+void CCTK_FCALL CCTK_FNAME(Ell_GetIntKey)
+ (int *ierr, CCTK_INT *value, ONE_FORTSTRING_ARG);
+void CCTK_FCALL CCTK_FNAME(Ell_GetStrKey)
+ (int *nchar, char **cstring,ONE_FORTSTRING_ARG);
+
+/********************************************************************
+ ******************** Internal Typedefs ************************
+ ********************************************************************/
struct t_ellthingy
{
@@ -30,16 +61,30 @@ struct t_ellthingy
} vals;
};
-int Ell_CreateKey(int vartype, const char *keychain) {
+/********************************************************************
+ ******************** Static Variables *************************
+ ********************************************************************/
+
+static pNamedData *EllInfoDB;
+
+/********************************************************************
+ ******************** Internal Routines ************************
+ ********************************************************************/
+
+int Ell_CreateKey(int vartype, const char *keychain)
+{
DECLARE_CCTK_PARAMETERS
struct t_ellthingy* new;
int retval;
- if ((struct t_ellthingy*)GetNamedData(EllInfoDB, keychain)) {
+ if ((struct t_ellthingy*)GetNamedData(EllInfoDB, keychain))
+ {
retval = ELLCREATE_TWICE;
- } else {
+ }
+ else
+ {
new = (struct t_ellthingy*)malloc(sizeof(struct t_ellthingy));
@@ -86,68 +131,86 @@ int Ell_CreateKey(int vartype, const char *keychain) {
}
-int Ell_IsKey(const char *keychain) {
+int Ell_IsKey(const char *keychain)
+{
int retval=ELL_ISNOKEY;
- if ((struct t_ellthingy*)GetNamedData(EllInfoDB, keychain)) {
+ if ((struct t_ellthingy*)GetNamedData(EllInfoDB, keychain))
+ {
retval = 0;
- } else
+ }
+ else
+ {
retval = ELL_ISNOKEY;
+ }
return(retval);
}
-void CCTK_FCALL CCTK_FNAME(Ell_IsKey)(int *ierr, ONE_FORTSTRING_ARG) {
+void CCTK_FCALL CCTK_FNAME(Ell_IsKey)(int *ierr, ONE_FORTSTRING_ARG)
+{
ONE_FORTSTRING_CREATE(key)
*ierr = Ell_IsKey(key);
free(key);
}
-int Ell_UnsetKey(const char *keychain) {
+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");
+ if (!(getme))
+ {
+ CCTK_VWarn(4,__LINE__,__FILE__,CCTK_THORNSTRING,
+ "Ell_GetRealKey: Cannot get structure with key %s",keychain);
retval = ELLGET_NOKEY;
- } else {
+ }
+ else
+ {
getme->been_set = ELL_NO;
retval = 0;
}
return(retval);
}
-int Ell_DeleteKey(const char *keychain) {
+int Ell_DeleteKey(const char *keychain)
+{
int retval;
- printf("NO IMPLEMENTED YET!");
+ /* avoid compiler warnings */
+ keychain = keychain;
+ CCTK_INFO("Ell_DeleteKey: Routine not implemented yet!");
retval = 1;
return(retval);
}
-void CCTK_FCALL CCTK_FNAME(Ell_DeleteKey)(int *ierr, ONE_FORTSTRING_ARG){
+void CCTK_FCALL CCTK_FNAME(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 Ell_SetRealKey(CCTK_REAL value, const char *keychain)
+{
int retval;
struct t_ellthingy *setme;
setme = GetNamedData(EllInfoDB, keychain);
- if (!(setme)) {
+ if (!(setme))
+ {
retval = ELLSET_FAILED;
- } else if (setme->type!=CCTK_VARIABLE_REAL) {
+ }
+ 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);
+ CCTK_VWarn(4,__LINE__,__FILE__,CCTK_THORNSTRING,
+ "Ell_SetRealKey: Key %s not of type CCTK_REAL (type %d)",
+ keychain,setme->type);
}
- else {
+ else
+ {
setme->type = CCTK_VARIABLE_REAL;
setme->vals.r = value;
setme->been_set = ELL_YES;
@@ -158,21 +221,25 @@ int Ell_SetRealKey(CCTK_REAL value, const char *keychain) {
}
void CCTK_FCALL CCTK_FNAME(Ell_SetRealKey)
- (int *ierr, CCTK_REAL *value, ONE_FORTSTRING_ARG) {
+ (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 Ell_SetIntKey(CCTK_INT value, const char *keychain)
+{
int retval;
struct t_ellthingy *setme;
setme = GetNamedData(EllInfoDB, keychain);
- if (!(setme)) {
+ if (!(setme))
+ {
retval = ELLSET_FAILED;
}
- else if (setme->type!=CCTK_VARIABLE_INT) {
+ 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);
@@ -187,35 +254,45 @@ int Ell_SetIntKey(CCTK_INT value, const char *keychain) {
}
void CCTK_FCALL CCTK_FNAME(Ell_SetIntKey)
- (int *ierr, CCTK_INT *value, ONE_FORTSTRING_ARG) {
+ (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 Ell_SetStrKey(char *value, const char *keychain)
+{
int retval;
struct t_ellthingy *setme;
setme = GetNamedData(EllInfoDB, keychain);
- if (!(setme)) {
+ if (!(setme))
+ {
retval = ELLSET_FAILED;
- } else if (setme->type!=CCTK_VARIABLE_STRING) {
+ }
+ 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);
+ CCTK_VWarn(4,__LINE__,__FILE__,CCTK_THORNSTRING,
+ "Ell_SetStrKey: Key %s not of type STRING (type %d)",
+ keychain,setme->type);
}
- else {
+ else
+ {
setme->type = CCTK_VARIABLE_STRING;
- setme->vals.s = strdup(value);
+ setme->vals.s = strdup(value);
setme->been_set = ELL_YES;
- retval=0;
+ retval = 0;
}
+
return(retval);
+
}
-void CCTK_FCALL CCTK_FNAME(Ell_SetStringKey)
- (int *ierr, TWO_FORTSTRINGS_ARGS) {
+void CCTK_FCALL CCTK_FNAME(Ell_SetStrKey)
+ (int *ierr, TWO_FORTSTRINGS_ARGS)
+{
TWO_FORTSTRINGS_CREATE(value,key)
*ierr = Ell_SetStrKey(value, key);
free(value);
@@ -223,35 +300,37 @@ void CCTK_FCALL CCTK_FNAME(Ell_SetStringKey)
}
-
-
-
-
-/*** GET OPERATIONS ***/
-
-
-int Ell_GetRealKey(CCTK_REAL *value, const char *keychain) {
+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");
+ if (!(getme))
+ {
+ CCTK_VWarn(4,__LINE__,__FILE__,CCTK_THORNSTRING,
+ "Ell_GetRealKey: Cannot get structure for key %s",keychain);
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);
+ else if (getme->type!=CCTK_VARIABLE_REAL)
+ {
+ CCTK_VWarn(4,__LINE__,__FILE__,CCTK_THORNSTRING,
+ "Ell_GetRealKey: Not getting a CCTK_REAL value off 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);
+ else if (getme->been_set==ELL_NO)
+ {
+ CCTK_VWarn(4,__LINE__,__FILE__,CCTK_THORNSTRING,
+ "Ell_GetRealKey: Key %s has not been set to any value",
+ keychain);
retval = ELLGET_NOTSET;
}
- else {
+ else
+ {
*value=getme->vals.r;
retval=0;
}
@@ -259,33 +338,44 @@ int Ell_GetRealKey(CCTK_REAL *value, const char *keychain) {
}
void CCTK_FCALL CCTK_FNAME(Ell_GetRealKey)
- (int *ierr, CCTK_REAL *value, ONE_FORTSTRING_ARG) {
+ (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) {
+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)) {
+ 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);
+ else if (getme->type!=CCTK_VARIABLE_INT)
+ {
+ CCTK_VWarn(4,__LINE__,__FILE__,CCTK_THORNSTRING,
+ "Ell_GetIntKey: Not getting a CCTK_INT value from key %s "
+ "(type %d)",
+ 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);
+ else if (getme->been_set==ELL_NO)
+ {
+ CCTK_VWarn(4,__LINE__,__FILE__,CCTK_THORNSTRING,
+ "Ell_GetIntKey: Key %s has not been set to any value (type %d)",
+ keychain,getme->type);
retval = ELLGET_NOTSET;
- } else {
+ }
+ else
+ {
*value=getme->vals.i;
retval=0;
}
@@ -294,13 +384,15 @@ int Ell_GetIntKey(CCTK_INT *value,const char *keychain) {
}
void CCTK_FCALL CCTK_FNAME(Ell_GetIntKey)
- (int *ierr, CCTK_INT *value, ONE_FORTSTRING_ARG) {
+ (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) {
+int Ell_GetStrKey(char **value, const char *keychain)
+{
struct t_ellthingy *getme=NULL;
int retval;
@@ -309,20 +401,27 @@ int Ell_GetStrKey(char **value, const char *keychain) {
getme = (struct t_ellthingy*)GetNamedData(EllInfoDB, keychain);
- if (!(getme)) {
- printf("Ell_GetStrKey: Cannot get structure with key >%s< \n",keychain);
- printf("Ell_GetStrKey: Create first!\n");
+ if (!(getme))
+ {
+ CCTK_VWarn(4,__LINE__,__FILE__,CCTK_THORNSTRING,
+ "Ell_GetStrKey: Cannot get structure with key %s",keychain);
retval = ELLGET_NOKEY;
}
- else if (getme->type!=CCTK_VARIABLE_STRING) {
- printf("You are not getting a CCTK_STRING value off this key: >%s< type: %d\n",
- keychain,getme->type);
+ else if (getme->type!=CCTK_VARIABLE_STRING)
+ {
+ CCTK_VWarn(4,__LINE__,__FILE__,CCTK_THORNSTRING,
+ "Ell_GetStrKey: Not getting a CCTK_STRING from this key %s "
+ "type: %d", keychain,getme->type);
retval = ELLGET_BADTYPE;
}
- else if (getme->been_set==ELL_NO) {
- printf("Key has not been set\n");
+ else if (getme->been_set==ELL_NO)
+ {
+ CCTK_VWarn(4,__LINE__,__FILE__,CCTK_THORNSTRING,
+ "Ell_GetStrKey: Key %s has not been set", keychain);
retval = ELLGET_NOTSET;
- } else {
+ }
+ else
+ {
*value=strdup(getme->vals.s);
retval=0;
}
@@ -347,12 +446,12 @@ void CCTK_FCALL CCTK_FNAME(Ell_GetStrKey)
*nchar = -1;
}
- for (i=0;i<strlen(*cstring);i++)
+ for (i=0;i<(int)strlen(*cstring);i++)
{
fptr[i] = (*cstring)[i];
}
- for (i=strlen(*cstring);i<cctk_strlen1;i++)
+ for (i=(int)strlen(*cstring);i<(int)cctk_strlen1;i++)
{
fptr[i] = ' ';
}