22 #include <lal/LALStdio.h>
23 #include <lal/LALStdlib.h>
24 #include <lal/LALConstants.h>
25 #include <lal/AVFactories.h>
26 #include <lal/Random.h>
28 #include <lal/SkyCoordinates.h>
105 #define GEOCENTRICGEODETICTESTC_ENORM 0
106 #define GEOCENTRICGEODETICTESTC_ESUB 1
107 #define GEOCENTRICGEODETICTESTC_EARG 2
108 #define GEOCENTRICGEODETICTESTC_EMEM 3
109 #define GEOCENTRICGEODETICTESTC_ETEST 4
113 #define GEOCENTRICGEODETICTESTC_MSGENORM "Normal exit"
114 #define GEOCENTRICGEODETICTESTC_MSGESUB "Subroutine failed"
115 #define GEOCENTRICGEODETICTESTC_MSGEARG "Error parsing arguments"
116 #define GEOCENTRICGEODETICTESTC_MSGEMEM "Out of memory"
117 #define GEOCENTRICGEODETICTESTC_MSGETEST "Test case failed"
123 #define USAGE "Usage: %s [-x xmin xmax nx] [-y ymin ymax ny]\n" \
124 "\t[-z zmin zmax nz] [-o outfle] [-d debuglevel]\n"
127 #define ERROR( code, msg, statement ) \
129 if ( lalDebugLevel & LALERROR ) \
131 LALPrintError( "Error[0] %d: program %s, file %s, line %d, %s\n" \
132 " %s %s\n", (code), *argv, __FILE__, \
133 __LINE__, "$Id$", statement ? \
134 statement : "", (msg) ); \
138 #define INFO( statement ) \
140 if ( lalDebugLevel & LALINFO ) \
142 LALPrintError( "Info[0]: program %s, file %s, line %d, %s\n" \
143 " %s\n", *argv, __FILE__, __LINE__, \
144 "$Id$", (statement) ); \
148 #define WARNING( statement ) \
150 if ( lalDebugLevel & LALWARNING ) \
152 LALPrintError( "Warning[0]: program %s, file %s, line %d, %s\n" \
153 " %s\n", *argv, __FILE__, __LINE__, \
154 "$Id$", (statement) ); \
158 #define SUB( func, statusptr ) \
160 if ( (func), (statusptr)->statusCode ) \
162 ERROR( GEOCENTRICGEODETICTESTC_ESUB, \
163 GEOCENTRICGEODETICTESTC_MSGESUB, \
164 "Function call \"" #func "\" failed:" ); \
165 return GEOCENTRICGEODETICTESTC_ESUB; \
170 main(
int argc,
char **argv )
175 REAL8 x_1 = 0.0, x_2 = 0.0, dx;
176 REAL8 y_1 = 0.0, y_2 = 0.0, dy;
177 REAL8 z_1 = 0.0, z_2 = 0.0, dz;
178 INT4 nx = 1, ny = 1, nz = 1;
181 REAL8 ddr, ddmax = 0.0;
191 while ( arg < argc ) {
194 if ( !strcmp( argv[arg],
"-x" ) ) {
195 if ( argc > arg + 3 ) {
198 x_1 = atof( argv[arg++] );
199 x_2 = atof( argv[arg++] );
200 nx = atoi( argv[arg++] );
203 GEOCENTRICGEODETICTESTC_MSGEARG, 0 );
207 }
else if ( !strcmp( argv[arg],
"-y" ) ) {
208 if ( argc > arg + 3 ) {
211 y_1 = atof( argv[arg++] );
212 y_2 = atof( argv[arg++] );
213 ny = atoi( argv[arg++] );
216 GEOCENTRICGEODETICTESTC_MSGEARG, 0 );
220 }
else if ( !strcmp( argv[arg],
"-z" ) ) {
221 if ( argc > arg + 3 ) {
224 z_1 = atof( argv[arg++] );
225 z_2 = atof( argv[arg++] );
226 nz = atoi( argv[arg++] );
229 GEOCENTRICGEODETICTESTC_MSGEARG, 0 );
236 else if ( !strcmp( argv[arg],
"-v" ) ) {
237 if ( argc > arg + 1 ) {
239 verbosity = atoi( argv[arg++] );
242 GEOCENTRICGEODETICTESTC_MSGEARG, 0 );
249 else if ( !strcmp( argv[arg],
"-d" ) ) {
250 if ( argc > arg + 1 ) {
254 GEOCENTRICGEODETICTESTC_MSGEARG, 0 );
261 else if ( argv[arg][0] ==
'-' ) {
263 GEOCENTRICGEODETICTESTC_MSGEARG, 0 );
275 REAL4 lon, coslat, sinlat, rad;
280 coslat = sqrt( 1.0 - sinlat*sinlat );
282 x_1 = x_2 = rad*coslat*cos( lon );
283 y_1 = y_2 = rad*coslat*sin( lon );
284 z_1 = z_2 = rad*sinlat;
291 dx = ( x_2 - x_1 )/( nx - 1.0 );
293 dy = ( y_2 - y_1 )/( ny - 1.0 );
295 dz = ( z_2 - z_1 )/( nz - 1.0 );
302 for ( i = 0; i < nx; i++ ) {
304 for ( j = 0; j < ny; j++ ) {
306 for ( k = 0; k < nz; k++ ) {
320 ddr = sqrt( ddx*ddx + ddy*ddy + ddz*ddz );
323 if ( verbosity == 1 )
324 fprintf( stdout,
"%+23.16e\n", ddr );
325 else if ( verbosity == 2 )
327 else if ( verbosity == 3 )
328 fprintf( stdout,
"%+23.16e %+23.16e %+23.16e %+23.16e\n",
330 else if ( verbosity == 4 )
331 fprintf( stdout,
"%+23.16e %+23.16e %+23.16e"
332 " %+23.16e %+23.16e %+23.16e %+23.16e\n",
x,
y, z,
340 fprintf( stdout,
"Maximum error: %.16em\n", ddmax );
341 if ( !xyz && ddmax > 1.0e-6 ) {
343 GEOCENTRICGEODETICTESTC_MSGETEST, 0 );
347 INFO( GEOCENTRICGEODETICTESTC_MSGENORM );
#define GEOCENTRICGEODETICTESTC_ENORM
Normal exit.
#define GEOCENTRICGEODETICTESTC_EARG
Error parsing arguments.
#define GEOCENTRICGEODETICTESTC_ETEST
Test case failed.
void LALCheckMemoryLeaks(void)
#define SUB(func, statusptr)
#define ERROR(code, msg, statement)
int main(int argc, char *argv[])
#define LAL_180_PI
pi/180 is the number of radians in one degree
#define LAL_REARTH_SI
Earth equatorial radius, m.
#define LAL_TWOPI
2*pi is circumference of a circle divided by its radius
unsigned char BOOLEAN
Boolean logical type, see Headers LAL(Atomic)Datatypes.h for more details.
double REAL8
Double precision real floating-point number (8 bytes).
int32_t INT4
Four-byte signed integer.
float REAL4
Single precision real floating-point number (4 bytes).
int LALPrintError(const char *fmt,...)
RandomParams * XLALCreateRandomParams(INT4 seed)
REAL4 XLALUniformDeviate(RandomParams *params)
void XLALDestroyRandomParams(RandomParams *params)
void LALGeocentricToGeodetic(LALStatus *, EarthPosition *location)
void LALGeodeticToGeocentric(LALStatus *, EarthPosition *location)
This structure stores the location of a point on (or near) the surface of the Earth in both geodetic ...
REAL8 elevation
The vertical distance of the point above the reference ellipsoid, in metres.
REAL8 z
The Earth-fixed geocentric Cartesian coordinates of the point, in metres.
SkyPosition geodetic
The geographic coordinates of the upward vertical direction from the point; that is,...
LAL status structure, see The LALStatus structure for more details.
This structure contains the parameters necessary for generating the current sequence of random number...
REAL8 longitude
The longitudinal coordinate (in radians), as defined above.
REAL8 latitude
The latitudinal coordinate (in radians), as defined above.