aboutsummaryrefslogtreecommitdiff
path: root/src/Ell_DBstructure.c
blob: 572bf61ee43a02351515d41439f07e373ba9a1c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
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);

}