summaryrefslogtreecommitdiff
path: root/src/main/Coord.c
diff options
context:
space:
mode:
authorallen <allen@17b73243-c579-4c4c-a9d2-2d5706c11dac>1999-04-22 14:29:12 +0000
committerallen <allen@17b73243-c579-4c4c-a9d2-2d5706c11dac>1999-04-22 14:29:12 +0000
commit5283679ca4e3b9ecadcc87cd84144d05881a17c0 (patch)
tree9df78ec7066bf3a159c147ab89fa3b115e596486 /src/main/Coord.c
parent0b227c37425c33f1d87e8414a19ed2f12600ffd9 (diff)
Coordinate registration. Now a GF which represents a coordinate
is registered with a name and a direction. This is so that we can for example register the grid function "grid::x" to be called "x" and then IO uses the grid function called "x" for an x-coordinate for output. git-svn-id: http://svn.cactuscode.org/flesh/trunk@491 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'src/main/Coord.c')
-rw-r--r--src/main/Coord.c207
1 files changed, 144 insertions, 63 deletions
diff --git a/src/main/Coord.c b/src/main/Coord.c
index b39927c0..7f8bce22 100644
--- a/src/main/Coord.c
+++ b/src/main/Coord.c
@@ -7,68 +7,156 @@
@enddesc
@@*/
-#define DEBUG_COORDS
+/*#define DEBUG_COORD*/
#include <stdio.h>
#include "cctk.h"
-#include "StoreNamedData.h"
+#include "StoreHandledData.h"
#include "WarnLevel.h"
-#include "Coords.h"
+#include "Coord.h"
+#include "ErrorCodes.h"
-static pNamedData *coordinates = NULL;
+static cHandledData *coordinates = NULL;
+static int num_coords = 0;
/*@@
@routine RegisterCoord_ByIndex
@date 11-12th April 1999
@author Gabrielle Allen
@desc
- Register a GF as a coordinate with a name and
- an (optional) direction.
+ Register a GF as a coordinate with a name, and index
+ and a direction
@enddesc
+ @calls CCTK_GetHandle, CCTK_NewHandle, CCTK_Warn
+
+ @var name
+ @vdesc Name coordinate is registered as
+ @vtype const char *
+ @vio in
+ @vcomment The name must not be the same as the variable name
+ @endvar
+
+ @var index
+ @vdesc The index of the variable providing the coordinate
+ @vtype int
+ @vio in
+ @vcomment
+ @endvar
+
+ @var dir
+ @vdesc An index giving the coordinate direction
+ @vtype int
+ @vio in
+ @vcomment This should be an optional argument
+ @endvar
+
+ @returntype int
+ @returndesc
+ -1 = Duplicate coordinate name, all duplicates
+ will be ignored
+ ERROR_MEMORY = Failure with malloc
+ >= 0 Handle returned by coordinate registration
+ @endreturndesc
+
@@*/
int CCTK_RegisterCoord_ByIndex(const char *name, int index, int dir)
{
- int retval = 0;
- int *store_data;
- store_data = (int *)malloc(2*sizeof(int));
- store_data[0] = index;
- store_data[1] = dir;
+ int handle;
+ struct Coordprops *new_coord;
+ char *coordname;
- if (StoreNamedData(&coordinates,
- name,
- &store_data))
- {
- char *message;
- message = (char *)malloc( (100+sizeof(name))*sizeof(char) );
- sprintf(message,"Memory failure while registering coordinate %s\n",
- name);
- CCTK_Warn(0,message);
- if (message) free(message);
- retval = -1;
- }
+ /* Check that the method hasn't already been registered */
+ handle = CCTK_GetHandle(coordinates, name, NULL);
-#ifdef DEBUG_COORDS
- printf(" In RegisterCoord\n ----------------\n");
- printf(" Registering index %d as %s in dir %d\n",
- store_data[0],name,store_data[1]);
+ if(handle < 0)
+ {
+ /* New extension. */
+ new_coord = (struct Coordprops *)malloc(sizeof(struct Coordprops));
+
+ if(new_coord)
+ {
+ /* Get a handle for it. */
+ handle = CCTK_NewHandle(&coordinates, name, new_coord);
+
+ /* Initialise the coordinate properties structure */
+ new_coord->name = (char *)name;
+ new_coord->index = index;
+ new_coord->direction = dir;
+
+ /* Remember how many methods there are */
+ num_coords++;
+
+#ifdef DEBUG_COORD
+ printf(" In CCTK_RegisterCoord_ByIndex\n");
+ printf(" -----------------------------\n");
+ printf(" handle %d, name %s,\n",handle,name);
+ printf(" index %d, direction %d\n",index,dir);
#endif
- return retval;
+ }
+ else
+ {
+ /* Memory failure. */
+ handle = ERROR_MEMORY;
+ }
+ }
+ else
+ {
+ /* Method already exists. */
+ char *msg;
+ msg = (char *)malloc(200*sizeof(char)+sizeof(name));
+ sprintf(msg,"Coordinate with name -%s- already registered",name);
+ CCTK_Warn(1,"CCTK",msg);
+ if (msg) free(msg);
+ handle = -1;
+ }
+
+ return handle;
}
-
/*@@
@routine RegisterCoord
@date 11-12th April 1999
@author Gabrielle Allen
@desc
Register a GF as a coordinate with a name and
- an (optional) direction.
+ a direction.
@enddesc
+ @calls CCTK_RegisterCoord_ByIndex, CCTK_GetVarIndex
+
+ @var name
+ @vdesc Name coordinate is registered as
+ @vtype const char *
+ @vio in
+ @vcomment The name must not be the same as the variable name
+ @endvar
+
+ @var gfname
+ @vdesc The name of the variable providing the coordinate
+ @vtype const char *
+ @vio in
+ @vcomment
+ @endvar
+
+ @var dir
+ @vdesc An index giving the coordinate direction
+ @vtype int
+ @vio in
+ @vcomment This should be an optional argument
+ @endvar
+
+ @returntype int
+ @returndesc
+ -1 = Duplicate coordinate name, all duplicates
+ will be ignored
+ ERROR_MEMORY = Failure with malloc
+ >= 0 Handle returned by coordinate registration
+ @endreturndesc
+
@@*/
int CCTK_RegisterCoord(const char *coordname,
@@ -78,22 +166,17 @@ int CCTK_RegisterCoord(const char *coordname,
int retval;
int index;
+
index = CCTK_GetVarIndex(gfname);
- if (index < 0)
- {
- char *msg;
- msg = (char *)malloc( (100+strlen(gfname)) );
- sprintf(msg,"Error from CCTK_GetVarNum for -%s- in CCTK_RegisterCoord",
- gfname);
- CCTK_Warn(1,msg);
- if (msg) free(msg);
-
- retval = -2; /* Error from CCTK_GetVarNum */
+ if (index >= 0)
+ {
+ retval = CCTK_RegisterCoord_ByIndex(coordname,index,dir);
}
else
{
- retval = CCTK_RegisterCoord_ByIndex(coordname,index,dir);
+ /* FIXME Should this register this error or a failed to register coord error */
+ retval = ERROR_INDEXNOTINRANGE;
}
return retval;
@@ -101,31 +184,29 @@ int CCTK_RegisterCoord(const char *coordname,
}
-
int CCTK_GetCoordIndex(const char *name)
{
- void *data;
- int index;
- int retval;
-
- index = GetNamedData(coordinates,name);
- /* if (!data)
+ int handle;
+ struct Coordprops *coord;
+
+ for (handle = 0;;handle++)
{
- printf("No data found\n");
+ coord = (struct Coordprops *)CCTK_GetHandledData(coordinates, handle);
+ if (coord)
+ {
+ if (CCTK_Equals(name,(const char *)coord->name))
+ return coord->index;
+ }
+ else
+ {
+ char *msg;
+ msg = (char *)malloc( 100*sizeof(char)+sizeof(name) );
+ sprintf(msg,"Could not find registered coordinate %s",name);
+ CCTK_Warn(2,"CCTK",msg);
+ if (msg) free(msg);
+ return ERROR_COORDNOTFOUND;
+ }
+
}
- index = (int *)data;
- if (index)
- retval = index;
- */
- printf("Pointer is %x %d\n",index,index);
- printf("Index is %d\n",retval);
-
- return index;
-
}
-
-
-
-
-