aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortradke <tradke@0337457d-221f-4ee6-a5f0-14255d5370d8>2004-05-09 14:51:19 +0000
committertradke <tradke@0337457d-221f-4ee6-a5f0-14255d5370d8>2004-05-09 14:51:19 +0000
commit93b29a5e7ea6c7b97746202c24daa475f32923c3 (patch)
tree6f9e6e5d12e80d0405616f34590921884d2c41ee
parent32d2d2fe0a90e255f268251b22b919d1fafd7554 (diff)
Added aliased function Coord_GetDefaultSystem() which returns the
default coordinate system registered for a given grid dimension. git-svn-id: http://svn.cactuscode.org/arrangements/CactusBase/CoordBase/trunk@15 0337457d-221f-4ee6-a5f0-14255d5370d8
-rw-r--r--doc/documentation.tex41
-rw-r--r--interface.ccl11
-rw-r--r--src/CoordBase.c152
-rw-r--r--src/CoordBase.h30
4 files changed, 139 insertions, 95 deletions
diff --git a/doc/documentation.tex b/doc/documentation.tex
index ab06462..ce6749a 100644
--- a/doc/documentation.tex
+++ b/doc/documentation.tex
@@ -233,9 +233,9 @@ section \ref{CactusBase_CoordBase_APIs}).
\label{CactusBase_CoordBase_APIs}
\begin{verbatim}
-int systemhandle = Coord_SystemRegister(const cGH *GH,
- int dim,
- const char *systemname)
+CCTK_INT systemhandle = Coord_SystemRegister(CCTK_POINTER_TO_CONST GH,
+ CCTK_INT dim,
+ CCTK_STRING systemname)
\end{verbatim}
registers a coordinate system, along with its
dimension, with the CoordBase thorn. This will create a coordinate
@@ -251,8 +251,8 @@ COORDERROR\_SYSTEMEXISTS & coordinate system of this name already exists\\
table handles on a GH extension, under the name ``CoordBase''.
\begin{verbatim}
-int systemhandle = Coord_SystemHandle(const cGH *GH,
- const char *systemname)
+CCTK_INT systemhandle = Coord_SystemHandle(CCTK_POINTER_TO_CONST GH,
+ CCTK_STRING systemname)
\end{verbatim}
returns the handle for a given coordinate system, or
negative on error:\beforetable
@@ -262,10 +262,10 @@ negative on error:\beforetable
\end{tabular}
\begin{verbatim}
-int coordhandle = Coord_CoordRegister(const cGH *GH,
- int systemhandle,
- int direction,
- const char *coordname)
+CCTK_INT coordhandle = Coord_CoordRegister(CCTK_POINTER_TO_CONST GH,
+ CCTK_INT systemhandle,
+ CCTK_INT direction,
+ CCTK_STRING coordname)
\end{verbatim}
registers a coordinate within a coordinate system, in the specified
`direction'. (Direction in this context means the index in the
@@ -283,9 +283,9 @@ COORDERROR\_DUPLICATENAME & coordinate of this name already exists in this
\end{tabular}
\begin{verbatim}
-int coordhandle = Coord_CoordHandle(const cGH *GH,
- const char *coordname,
- const char *systemname)
+CCTK_INT coordhandle = Coord_CoordHandle(CCTK_POINTER_TO_CONST GH,
+ CCTK_STRING coordname,
+ CCTK_STRING systemname)
\end{verbatim}
returns the coordinate handle for a given coordinatate in a coordinate system,
or negative on error:\beforetable
@@ -313,8 +313,8 @@ COORDERROR\_NOCOORDSYS & no coordinate system is associated with the
\end{tabular}
\begin{verbatim}
-int systemhandle = Coord_SetDefaultSystem(const cGH *GH,
- const char *systemname)
+CCTK_INT systemhandle = Coord_SetDefaultSystem(CCTK_POINTER_TO_CONST GH,
+ CCTK_STRING systemname)
\end{verbatim}
sets this coordinate system to be the default for grid variables of
the same dimension. It returns the handle of the system, or negative
@@ -330,6 +330,19 @@ COORDERROR\_DEFAULTEXISTS & grid variables of this dimension already have a \\
default system will apply for each grid variable of that dimension,
unless it is overridden.
+\begin{verbatim}
+CCTK_INT systemhandle = Coord_GetDefaultSystem(CCTK_POINTER_TO_CONST GH,
+ CCTK_INT dim)
+\end{verbatim}
+gets the default coordinate system for grid variables of dimension {\tt dim}
+(ranging from 1 to the maximum number of dimensions registered).
+It returns the handle of the system, or negative for errors:\beforetable
+\begin{tabular}{ll}
+COORDERROR\_INVALIDDIM & given dimension is invalid\\
+COORDERROR\_NOSYSTEM & given dimension does not have a default coordinate
+ system associated
+\end{tabular}
+
\section{Coordinate Schema}
\label{CactusBase_CoordBase_coordinate_schema}
diff --git a/interface.ccl b/interface.ccl
index f213cc8..b85937f 100644
--- a/interface.ccl
+++ b/interface.ccl
@@ -1,7 +1,7 @@
# Interface definition for thorn CoordBase
# $Header$
-implements: CoordBase
+implements: CoordBase
# Old header file - should use aliased functions
@@ -18,7 +18,7 @@ PROVIDES FUNCTION Coord_SystemRegister \
LANGUAGE C
CCTK_INT FUNCTION Coord_SystemHandle \
- (CCTK_POINTER_TO_CONST IN GH, \
+ (CCTK_POINTER_TO_CONST IN GH, \
CCTK_STRING IN systemname)
PROVIDES FUNCTION Coord_SystemHandle \
WITH CoordBase_SystemHandle \
@@ -55,6 +55,13 @@ PROVIDES FUNCTION Coord_SetDefaultSystem \
WITH CoordBase_SetDefaultSystem \
LANGUAGE C
+CCTK_INT FUNCTION Coord_GetDefaultSystem \
+ (CCTK_POINTER_TO_CONST IN GH, \
+ CCTK_INT IN systemdim)
+PROVIDES FUNCTION Coord_GetDefaultSystem \
+ WITH CoordBase_GetDefaultSystem \
+ LANGUAGE C
+
# The location of the boundary points
diff --git a/src/CoordBase.c b/src/CoordBase.c
index 403ba56..9f38148 100644
--- a/src/CoordBase.c
+++ b/src/CoordBase.c
@@ -56,19 +56,16 @@ static int longest_systemname=0;
@vdesc cctkGH *
@vtype CCTK_POINTER_TO_CONST
@vio in
- @vcomment
@endvar
@var dim
@vdesc coordinate system dimension
@vtype CCTK_INT
@vio in
- @vcomment
@endvar
@var systemname
@vdesc coordinate system name
@vtype CCTK_STRING
@vio in
- @vcomment
@endvar
@returntype int
@@ -82,11 +79,10 @@ static int longest_systemname=0;
@@*/
CCTK_INT CoordBase_SystemRegister(CCTK_POINTER_TO_CONST GH, CCTK_INT dim,
- CCTK_STRING systemname)
+ CCTK_STRING systemname)
{
- int retval;
- int *systemhandle_ptr;
- int systemname_length;
+ int len, retval;
+ int *ptr;
const coordbaseGH *GHex;
uHash *hash;
@@ -109,12 +105,12 @@ CCTK_INT CoordBase_SystemRegister(CCTK_POINTER_TO_CONST GH, CCTK_INT dim,
hash = GHex->coordsystems;
/* Has a coordinate system of this name already been registered? */
- systemname_length = strlen(systemname);
- if (systemname_length>longest_systemname)
+ len = strlen(systemname);
+ if (len>longest_systemname)
{
- longest_systemname = systemname_length+1;
+ longest_systemname = len+1;
}
- if (Util_HashData(hash, systemname_length, systemname, 0))
+ if (Util_HashData(hash, len, systemname, 0))
{
CCTK_VWarn(1,__LINE__,__FILE__,CCTK_THORNSTRING,
"Coordinate system %s already registered",systemname);
@@ -124,36 +120,25 @@ CCTK_INT CoordBase_SystemRegister(CCTK_POINTER_TO_CONST GH, CCTK_INT dim,
if (retval == 0)
{
-
/* Now make a table for this system */
- systemhandle_ptr = (int *) malloc(sizeof(int));
- *systemhandle_ptr = Util_TableCreate(UTIL_TABLE_FLAGS_CASE_INSENSITIVE);
- if (*systemhandle_ptr < 0)
+ ptr = malloc(sizeof(int));
+ retval = *ptr = Util_TableCreate(UTIL_TABLE_FLAGS_CASE_INSENSITIVE);
+ if (retval < 0)
{
CCTK_WARN(0,"Could not create table");
retval = COORDERROR_TABLEERROR;
}
- else
- {
- retval = *systemhandle_ptr;
- }
- /* Add coordinate system name */
- if (Util_TableSetString(*systemhandle_ptr, systemname, "NAME") < 0)
+ /* Add coordinate system information */
+ if (Util_TableSetString(*ptr, systemname, "NAME") < 0 ||
+ Util_TableSetInt(*ptr, dim, "DIMENSION") < 0)
{
- CCTK_WARN(0, "Internal error when writing coordinate system name to table");
+ CCTK_WARN(0, "Internal error when adding key/value table entries");
retval = COORDERROR_TABLEERROR;
}
- /* Add dimension information */
- if (Util_TableSetInt(*systemhandle_ptr, dim, "DIMENSION") < 0)
- {
- CCTK_WARN(0, "Internal error when writing coordinate system dimension to table");
- retval = COORDERROR_TABLEERROR;
- }
-
- /* Register it with the Coordinate GH Extension */
- if (Util_HashAdd(hash, systemname_length, systemname, 0, systemhandle_ptr) < 0)
+ /* Register the system with the Coordinate GH Extension */
+ if (Util_HashAdd(hash, len, systemname, 0, ptr) < 0)
{
CCTK_WARN(0, "Internal error when storing coordinate system handle");
retval = COORDERROR_TABLEERROR;
@@ -177,13 +162,11 @@ CCTK_INT CoordBase_SystemRegister(CCTK_POINTER_TO_CONST GH, CCTK_INT dim,
@vdesc cctkGH *
@vtype CCTK_POINTER_TO_CONST
@vio in
- @vcomment
@endvar
@var systemname
@vdesc coordinate system name
@vtype CCTK_STRING
@vio in
- @vcomment
@endvar
@returntype int
@@ -233,13 +216,11 @@ CCTK_INT CoordBase_SystemHandle(CCTK_POINTER_TO_CONST GH, CCTK_STRING systemname
@vdesc cctkGH *
@vtype CCTK_POINTER_TO_CONST
@vio in
- @vcomment
@endvar
@var systemhandle
@vdesc coordinate system handle
@vtype CCTK_INT
@vio in
- @vcomment
@endvar
@var direction
@vdesc index within coodinate basis
@@ -251,7 +232,6 @@ CCTK_INT CoordBase_SystemHandle(CCTK_POINTER_TO_CONST GH, CCTK_STRING systemname
@vdesc coordinate system name
@vtype CCTK_STRING
@vio in
- @vcomment
@endvar
@returntype int
@@ -268,9 +248,9 @@ CCTK_INT CoordBase_SystemHandle(CCTK_POINTER_TO_CONST GH, CCTK_STRING systemname
@@*/
CCTK_INT CoordBase_CoordRegister(CCTK_POINTER_TO_CONST GH,
- CCTK_INT systemhandle,
- CCTK_INT direction,
- CCTK_STRING coordname)
+ CCTK_INT systemhandle,
+ CCTK_INT direction,
+ CCTK_STRING coordname)
{
int coordinate_handle;
CCTK_INT system_dimension;
@@ -278,10 +258,9 @@ CCTK_INT CoordBase_CoordRegister(CCTK_POINTER_TO_CONST GH,
CCTK_INT i;
char *coordname_buffer;
- /* Initialize variables */
+ (void) (&GH + 0);
+
coordinate_handle = 0;
- GH = GH;
- /*(void *) ((const cGH *)GH + 0);*/
/* Check input arguments */
/* Get coordinate system dimension, and check for valid systemhandle */
@@ -323,7 +302,7 @@ CCTK_INT CoordBase_CoordRegister(CCTK_POINTER_TO_CONST GH,
if (coordinate_tables[direction-1]>=0)
{
CCTK_VWarn(1,__LINE__,__FILE__,CCTK_THORNSTRING, "Coordinate already "
- "registered for 'direction' %d", direction);
+ "registered for direction %d", direction);
coordinate_handle = COORDERROR_COORDINATEEXISTS;
}
@@ -341,7 +320,7 @@ CCTK_INT CoordBase_CoordRegister(CCTK_POINTER_TO_CONST GH,
}
else if (Util_StrCmpi(coordname_buffer, coordname)==0)
{
- CCTK_VWarn(1,__LINE__,__FILE__,CCTK_THORNSTRING, "Coordinate named %s "
+ CCTK_VWarn(1,__LINE__,__FILE__,CCTK_THORNSTRING, "Coordinate '%s' "
"is already registered for this system", coordname_buffer);
coordinate_handle = COORDERROR_DUPLICATENAME;
break;
@@ -404,19 +383,16 @@ CCTK_INT CoordBase_CoordRegister(CCTK_POINTER_TO_CONST GH,
@vdesc cctkGH *
@vtype CCTK_POINTER_TO_CONST
@vio in
- @vcomment
@endvar
@var coordname
@vdesc coordinate name
@vtype CCTK_STRING
@vio in
- @vcomment
@endvar
@var systemname
@vdesc coordinate system name
@vtype CCTK_STRING
@vio in
- @vcomment
@endvar
@returntype int
@@ -430,8 +406,8 @@ CCTK_INT CoordBase_CoordRegister(CCTK_POINTER_TO_CONST GH,
@@*/
CCTK_INT CoordBase_CoordHandle(CCTK_POINTER_TO_CONST GH,
- CCTK_STRING coordname,
- CCTK_STRING systemname)
+ CCTK_STRING coordname,
+ CCTK_STRING systemname)
{
int coord_handle;
int *system_handle_ptr;
@@ -447,12 +423,13 @@ CCTK_INT CoordBase_CoordHandle(CCTK_POINTER_TO_CONST GH,
GHex = CCTK_GHExtension(GH,"CoordBase");
hash = GHex->coordsystems;
+ coord_handle = COORDERROR_NOSYSTEM;
+
/* Get system table handle */
system_handle_ptr = Util_HashData(hash, strlen(systemname), systemname, 0);
if (!system_handle_ptr)
{
CCTK_WARN(1, "No such coordinate system registered");
- coord_handle = COORDERROR_NOSYSTEM;
}
else
{
@@ -519,13 +496,11 @@ CCTK_INT CoordBase_CoordHandle(CCTK_POINTER_TO_CONST GH,
@vdesc cctkGH *
@vtype CCTK_POINTER_TO_CONST
@vio in
- @vcomment
@endvar
@var groupname
@vdesc variable group name
@vtype CCTK_STRING
@vio in
- @vcomment
@endvar
@returntype int
@@ -538,7 +513,7 @@ CCTK_INT CoordBase_CoordHandle(CCTK_POINTER_TO_CONST GH,
@@*/
CCTK_INT CoordBase_GroupSystem(CCTK_POINTER_TO_CONST GH,
- CCTK_STRING groupname)
+ CCTK_STRING groupname)
{
int system_handle;
int group_tags_table;
@@ -553,7 +528,7 @@ CCTK_INT CoordBase_GroupSystem(CCTK_POINTER_TO_CONST GH,
group_tags_table = CCTK_GroupTagsTable(groupname);
if (group_tags_table < 0)
{
- CCTK_VWarn(1,__LINE__,__FILE__,CCTK_THORNSTRING, "Invalid group name %s",
+ CCTK_VWarn(1,__LINE__,__FILE__,CCTK_THORNSTRING, "Invalid group name '%s'",
groupname);
system_handle = COORDERROR_INVALIDGROUPNAME;
}
@@ -568,8 +543,8 @@ CCTK_INT CoordBase_GroupSystem(CCTK_POINTER_TO_CONST GH,
if (system_handle < 0)
{
CCTK_VWarn(1,__LINE__,__FILE__,CCTK_THORNSTRING, "Coordinate system "
- "%s associated with group %s does not exist", system_name,
- groupname);
+ "'%s' associated with group '%s' does not exist",
+ system_name, groupname);
system_handle = COORDERROR_INVALIDNAME;
}
}
@@ -580,13 +555,12 @@ CCTK_INT CoordBase_GroupSystem(CCTK_POINTER_TO_CONST GH,
if (system_handle == -9999 && CCTK_GroupTypeI(gindex) == CCTK_GF)
{
GHex = CCTK_GHExtension(GH,"CoordBase");
- assert(GHex && GHex->default_coord_systems);
gdim = CCTK_GroupDimI(gindex);
- assert(gdim>0);
- if ((system_handle = GHex->default_coord_systems[gdim-1]) < 0)
+ system_handle = GHex->default_coord_systems[gdim-1];
+ if (system_handle < 0)
{
CCTK_VWarn(1,__LINE__,__FILE__,CCTK_THORNSTRING, "No coordinate "
- "system is associated with group %s", groupname);
+ "system is associated with group '%s'", groupname);
system_handle = COORDERROR_NOCOORDSYS;
}
}
@@ -611,13 +585,11 @@ CCTK_INT CoordBase_GroupSystem(CCTK_POINTER_TO_CONST GH,
@vdesc cctkGH *
@vtype CCTK_POINTER_TO_CONST
@vio in
- @vcomment
@endvar
@var systemname
@vdesc coordinate system name
@vtype CCTK_STRING
@vio in
- @vcomment
@endvar
@returntype int
@@ -632,7 +604,7 @@ CCTK_INT CoordBase_GroupSystem(CCTK_POINTER_TO_CONST GH,
@@*/
CCTK_INT CoordBase_SetDefaultSystem(CCTK_POINTER_TO_CONST GH,
- CCTK_STRING systemname)
+ CCTK_STRING systemname)
{
int system_handle;
CCTK_INT system_dimension;
@@ -650,7 +622,7 @@ CCTK_INT CoordBase_SetDefaultSystem(CCTK_POINTER_TO_CONST GH,
if (system_handle<0)
{
CCTK_VWarn(1,__LINE__,__FILE__,CCTK_THORNSTRING, "Invalid system name "
- "%s", systemname);
+ "'%s'", systemname);
retval = COORDERROR_INVALIDNAME;
}
else
@@ -658,7 +630,7 @@ CCTK_INT CoordBase_SetDefaultSystem(CCTK_POINTER_TO_CONST GH,
/* Get system dimension */
if (Util_TableGetInt(system_handle, &system_dimension, "DIMENSION") < 0)
{
- CCTK_VWarn(1,__LINE__,__FILE__,CCTK_THORNSTRING, "System %s does not "
+ CCTK_VWarn(1,__LINE__,__FILE__,CCTK_THORNSTRING, "System '%s' does not "
"have a registered dimension", systemname);
retval = COORDERROR_NODIMENSION;
}
@@ -669,7 +641,7 @@ CCTK_INT CoordBase_SetDefaultSystem(CCTK_POINTER_TO_CONST GH,
{
CCTK_VWarn(1,__LINE__,__FILE__,CCTK_THORNSTRING, "Default coordinate "
"system for %d dimensional grid variables is already set. "
- "Overwriting to %s.", system_dimension, systemname);
+ "Overwriting to '%s'.", system_dimension, systemname);
retval = COORDERROR_DEFAULTEXISTS;
}
else
@@ -689,3 +661,51 @@ CCTK_INT CoordBase_SetDefaultSystem(CCTK_POINTER_TO_CONST GH,
return retval;
}
+
+ /*@@
+ @routine CoordBase_GetDefaultSystem
+ @date 9 May 2004
+ @author Thomas Radke
+ @desc
+ Get the default coordinate system for grid variables
+ of a given dimension
+ @enddesc
+
+ @var GH
+ @vdesc cctkGH *
+ @vtype CCTK_POINTER_TO_CONST
+ @vio in
+ @endvar
+ @var systemdim
+ @vdesc dimension of coordinate system to query
+ @vtype CCTK_INT
+ @vio in
+ @vcomment ranges from 1 to the maximum number of dimensions
+ @endvar
+
+ @returntype int
+ @returndesc
+ coordinate system handle, or
+ COORDERROR_INVALIDDIM given dimension is invalid
+ COORDERROR_NOSYSTEM given dimension does not have a default coordinate
+ system associated
+ @endreturndesc
+@@*/
+
+CCTK_INT CoordBase_GetDefaultSystem(CCTK_POINTER_TO_CONST GH,
+ CCTK_INT systemdim)
+{
+ CCTK_INT retval;
+ const coordbaseGH *myGH;
+
+
+ myGH = CCTK_GHExtension(GH,"CoordBase");
+
+ retval = COORDERROR_INVALIDDIM;
+ if (systemdim >= 1 && systemdim <= CCTK_MaxDim())
+ {
+ retval = myGH->default_coord_systems[systemdim-1];
+ }
+
+ return (retval);
+}
diff --git a/src/CoordBase.h b/src/CoordBase.h
index b67b07c..364d5ac 100644
--- a/src/CoordBase.h
+++ b/src/CoordBase.h
@@ -1,10 +1,10 @@
/*@@
- @header CoordBase.h
- @date Wed June 26 2002
- @author Gabrielle Allen
- @desc
- Headers and defines for coordinate base thorn
- @enddesc
+ @header CoordBase.h
+ @date Wed June 26 2002
+ @author Gabrielle Allen
+ @desc
+ Defines and prototypes for the coordinate base thorn
+ @enddesc
@version $Header$
@@*/
@@ -13,8 +13,8 @@
#ifndef COORD_IN_COORDBASE
-/* Since some people may still be including this header file
- * rather than using the function aliasing, we need to
+/* Since some people may still be including this header file
+ * rather than using the function aliasing, we need to
* allow them access to the internal functions.
*/
@@ -24,11 +24,12 @@
#define Coord_CoordHandle CoordBase_CoordHandle
#define Coord_GroupSystem CoordBase_GroupSystem
#define Coord_SetDefaultSystem CoordBase_SetDefaultSystem
+#define Coord_GetDefaultSystem CoordBase_GetDefaultSystem
#endif /* COORD_IN_COORDBASE */
-#ifdef __cplusplus
-extern "C"
+#ifdef __cplusplus
+extern "C"
{
#endif
@@ -54,10 +55,13 @@ CCTK_INT CoordBase_GroupSystem(CCTK_POINTER_TO_CONST GH,
CCTK_INT CoordBase_SetDefaultSystem(CCTK_POINTER_TO_CONST GH,
CCTK_STRING systemname);
-#ifdef __cplusplus
+CCTK_INT CoordBase_GetDefaultSystem(CCTK_POINTER_TO_CONST GH,
+ CCTK_INT systemdim);
+
+#ifdef __cplusplus
}
#endif
-
+
#define COORDERROR_SYSTEMEXISTS -1
#define COORDERROR_INVALIDDIM -2
#define COORDERROR_INVALIDNAME -3
@@ -72,4 +76,4 @@ CCTK_INT CoordBase_SetDefaultSystem(CCTK_POINTER_TO_CONST GH,
#define COORDERROR_NODIMENSION -12
#define COORDERROR_DEFAULTEXISTS -13
-#endif
+#endif /* _COORDBASE_H_ */