aboutsummaryrefslogtreecommitdiff
path: root/src/CoordinateStuff.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/CoordinateStuff.c')
-rw-r--r--src/CoordinateStuff.c152
1 files changed, 87 insertions, 65 deletions
diff --git a/src/CoordinateStuff.c b/src/CoordinateStuff.c
index e9a2b9e..025fc01 100644
--- a/src/CoordinateStuff.c
+++ b/src/CoordinateStuff.c
@@ -1,3 +1,13 @@
+ /*@@
+ @file CoordinateStuff.c
+ @date
+ @author Cactus Maintainers
+ @desc
+ Extra functions for coordinate information
+ @enddesc
+ @version $Header$
+ @@*/
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -9,12 +19,36 @@ static const char *rcsid = "$Header$";
CCTK_FILEVERSION(CactusWave_WaveBinarySource_CoordinateStuff_c)
-int IndexFloorC(cGH *GH, CCTK_REAL coord_value, int d);
+/********************************************************************
+ ********************* Local Data Types ***********************
+ ********************************************************************/
+
+
+/********************************************************************
+ ********************* Local Routine Prototypes *********************
+ ********************************************************************/
+
+
+/********************************************************************
+ ********************* Local Data *****************************
+ ********************************************************************/
+
+
+/********************************************************************
+ ***************** External Routines Prototype ********************
+ ********************************************************************/
+
int IndexCeilC(cGH *GH, CCTK_REAL coord_value, int d);
+int IndexFloorC(cGH *GH, CCTK_REAL coord_value, int d);
+
+
+/********************************************************************
+ ********************** External Routines ************************
+ ********************************************************************/
/*@@
- @routine IndexFloor
+ @routine IndexFloorC
@date Fri Jan 7 10:34:29 2000
@author Gerd Lanfermann
@desc
@@ -24,6 +58,8 @@ int IndexCeilC(cGH *GH, CCTK_REAL coord_value, int d);
Other return values:
-1 : gridindex not on this gridpatch
+ -2 : illegal dimension
+ -3 : coordinate value outside grid
@enddesc
@calls
@calledby
@@ -35,51 +71,43 @@ int IndexCeilC(cGH *GH, CCTK_REAL coord_value, int d);
int IndexFloorC(cGH *GH, CCTK_REAL coord_value, int d)
{
- int index_low,idummy;
+ int index_low;
CCTK_REAL cmin,cmax;
- if (d==0)
- {
- CCTK_CoordRange(GH,&cmin,&cmax, 1, "x", "cart3d");
- }
- else if (d==1)
- {
- CCTK_CoordRange(GH,&cmin,&cmax, 2, "y", "cart3d");
- }
- else if (d==2)
+ if (d>=0 || d<3)
{
- CCTK_CoordRange(GH,&cmin,&cmax, 3, "z", "cart3d");
+ CCTK_CoordRange(GH,&cmin,&cmax, d+1, NULL, "cart3d");
+
+ if ((coord_value<cmin)||(coord_value>cmax))
+ {
+ CCTK_VWarn(2,__LINE__,__FILE__,CCTK_THORNSTRING,
+ "IndexFloor: coordinate value outside grid [%f,%f]: %f \n",
+ cmin, cmax, coord_value);
+ index_low = -3;
+ }
+ else
+ {
+ index_low = floor((coord_value-cmin)/ GH->cctk_delta_space[d])
+ - GH->cctk_lbnd[d];
+
+ if (index_low<0 || index_low>=GH->cctk_lsh[d])
+ {
+ index_low = -1;
+ }
+ }
}
else
{
- CCTK_WARN(0,"IndexFloor: dimension is not valid. Fortran:1..3 C:0..2");
+ CCTK_WARN(1,"IndexFloorC: dimension is not valid");
+ index_low = -2;
}
- if ((coord_value<cmin)||(coord_value>cmax))
- {
- CCTK_VWarn(2,__LINE__,__FILE__,CCTK_THORNSTRING,
- "IndexFloor: coordinate value outside grid [%f,%f]: %f \n",
- cmin, cmax, coord_value);
- return(-3);
- }
-
- idummy = floor((coord_value-cmin)/ GH->cctk_delta_space[d]);
- index_low = idummy-GH->cctk_lbnd[d];
-
- if (index_low<0)
- {
- index_low = -1;
- }
- if (index_low>=GH->cctk_lsh[d])
- {
- index_low = -1;
- }
return(index_low);
}
/*@@
- @routine IndexCeil
+ @routine IndexCeilC
@date Fri Jan 7 10:34:29 2000
@author Gerd Lanfermann
@desc
@@ -88,6 +116,8 @@ int IndexFloorC(cGH *GH, CCTK_REAL coord_value, int d)
including ghostzones.
Other return values:
-1 : grid index not on this gridpatch
+ -2 : illegal dimension
+ -3 : coordinate value outside grid
@enddesc
@calls
@calledby
@@ -100,44 +130,36 @@ int IndexFloorC(cGH *GH, CCTK_REAL coord_value, int d)
int IndexCeilC(cGH *GH, CCTK_REAL coord_value, int d)
{
- int index_up,idummy;
+ int index_up;
CCTK_REAL cmin,cmax;
- if (d==0)
- {
- CCTK_CoordRange(GH,&cmin,&cmax, -1, "x", "cart3d");
- }
- else if (d==1)
+ if (d>=0 || d<3)
{
- CCTK_CoordRange(GH,&cmin,&cmax, -1, "y", "cart3d");
- }
- else if (d==2)
- {
- CCTK_CoordRange(GH,&cmin,&cmax, -1, "z", "cart3d");
+ CCTK_CoordRange(GH,&cmin,&cmax, d+1, NULL, "cart3d");
+
+ if ((coord_value<cmin)||(coord_value>cmax))
+ {
+ CCTK_VWarn(2,__LINE__,__FILE__,CCTK_THORNSTRING,
+ "IndexCeil: coordinate value outside grid [%f,%f]: %f \n",
+ cmin, cmax, coord_value);
+ index_up = -3;
+ }
+ else
+ {
+ index_up = ceil((coord_value-cmin)/ GH->cctk_delta_space[d])
+ -GH->cctk_lbnd[d];
+
+ if (index_up<0 || index_up>=GH->cctk_lsh[d])
+ {
+ index_up = -1;
+ }
+ }
}
else
{
- CCTK_WARN(0,"IndexCeilC: dimension is not valid. Fortran:1..3 C:0..2");
+ CCTK_WARN(1,"IndexCeilC: dimension is not valid");
+ index_up = -2;
}
- if ((coord_value<cmin)||(coord_value>cmax))
- {
- CCTK_VWarn(2,__LINE__,__FILE__,CCTK_THORNSTRING,
- "IndexCeil: coordinate value outside grid [%f,%f]: %f \n",
- cmin,cmax, coord_value);
- return(-3);
- }
-
- idummy = ceil((coord_value-cmin)/ GH->cctk_delta_space[d]);
- index_up = idummy-GH->cctk_lbnd[d];
-
- if (index_up<0)
- {
- index_up = -1;
- }
- if (index_up>=GH->cctk_lsh[d])
- {
- index_up = -1;
- }
return(index_up);
}