Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALPulsar 7.1.1.1-8a6b96f
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
GeneralMeshTest.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 Jolien Creighton, Ian Jones, Benjamin Owen
3*
4* This program is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License as published by
6* the Free Software Foundation; either version 2 of the License, or
7* (at your option) any later version.
8*
9* This program is distributed in the hope that it will be useful,
10* but WITHOUT ANY WARRANTY; without even the implied warranty of
11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12* GNU General Public License for more details.
13*
14* You should have received a copy of the GNU General Public License
15* along with with program; see the file COPYING. If not, write to the
16* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17* MA 02110-1301 USA
18*/
19
20/**
21 * \author Jones, D. I., Owen, B. J.
22 * \file
23 * \ingroup PtoleMetric_h
24 * \brief Tests and showcases the combination of a LAL metric function (of the
25 * user's specification) and \ref TwoDMesh_h modules by producing a
26 * template mesh.
27 *
28 * ### Program <tt>GeneralMeshTest.c</tt> ###
29 *
30 *
31 * ### Usage ###
32 *
33 * \code
34 * GeneralMeshTest
35 * \endcode
36 *
37 * ### Description ###
38 *
39 * The <b>-b</b> option sets the beginning GPS time of integration to
40 * the option argument. (Default is \f$ 731265908 \f$ seconds, chosen to lie
41 * within the S2 run).
42 *
43 * The <b>-c</b> option determins the center of the patch. This option
44 * is hardcoded to use equatorial coordinates and the argument should be
45 * given in hh:mm:ss:dd:mm:ss format. (Default is the center of the
46 * globular cluster 47 Tuc).
47 *
48 * The <b>-f</b> option sets the maximum frequency of integration (in Hz) to the
49 * option argument. (The default value is 1000.)
50 *
51 * The <b>-l</b> option determines, for a rectangular search region, the
52 * limits in right ascension and declination of the grid. The argument should
53 * be given in degrees as RA(min):RA(max):dec(min):dec(max). (The default is
54 * the octant of the sky defined by \f$ 0 < \textrm{RA} < 90 \f$ and \f$ 0< \textrm{dec} <
55 * 85 \f$ ; this avoids the coordinate singularity at the poles.) This option
56 * automatically overrides whatever is specified by the <b>-r</b> option.
57 *
58 * The <b>-m</b> option sets the maximum mismatch of the mesh to the option
59 * argument. (Default is 0.02.)
60 *
61 * The texttt{-p} option causes the coordinates of the nodes to be written to
62 * a file <tt>mesh.dat</tt>, for the benifit of users who don't have
63 * \c xmgrace installed. The format is one node per line, (RA, DEC),
64 * with the angles in degrees.
65 *
66 * The <b>-r</b> option sets the radius (in arcminutes) of the circular
67 * sky patch. If you specify radius zero you will get a search over a
68 * rectangular region whose limits in RA and dec are specified by the
69 * <b>-l</b> option. (The default value is the radius of the globular
70 * cluster 47 Tuc).
71 *
72 * The <b>-t</b> option sets the duration of integration in seconds. (The
73 * default is \f$ 39600 \f$ seconds \f$ = 11 \f$ hours, which is chosen because it is of
74 * the right size for S2 analyses).
75 *
76 * ### Algorithm ###
77 *
78 *
79 * ### Uses ###
80 *
81 * \code
82 * lalDebugLevel LALDCreateVector()
83 * LALCheckMemoryLeaks() LALDDestroyVector()
84 * LALProjectMetric() XLALGetEarthTimes()
85 * LALPtoleMetric() XLALInitBarycenter()
86 * LALCreateTwoDMesh() LALDestroyTwoDMesh()
87 * \endcode
88 *
89 * ### Notes ###
90 *
91 * For most regions of parameter space the three metric codes seem to
92 * agree well. However, for short (less than one day) runs, they are all
93 * capable of returning (unphysical) negative determinant metrics for
94 * points very close to the equator.
95 *
96 */
97
98
99/** \name Error Codes */ /** @{ */
100#define GENERALMESHTESTC_EMEM 1
101#define GENERALMESHTESTC_ERNG 2
102#define GENERALMESHTESTC_EFIO 3
103#define GENERALMESHTESTC_EOPT 4
104#define GENERALMESHTESTC_EMET 5
105
106#define GENERALMESHTESTC_MSGEMEM "memory (de)allocation error"
107#define GENERALMESHTESTC_MSGERNG "value out of range"
108#define GENERALMESHTESTC_MSGEFIO "file I/O error"
109#define GENERALMESHTESTC_MSGEOPT "unknown command-line option"
110#define GENERALMESHTESTC_MSGEMET "determinant of projected metric negative"
111/** @} */
112
113#include <config.h>
114
115#include <math.h>
116#include <stdio.h>
117#include <lal/AVFactories.h>
118#include <lal/LALgetopt.h>
119#include <lal/PtoleMetric.h>
120#include <lal/TwoDMesh.h>
121#include <lal/LALInitBarycenter.h>
122
123
124/** \cond DONT_DOXYGEN */
125
126#define MIN_DURATION (86400./LAL_TWOPI) /* one radian of rotation */
127#define MAX_DURATION (3.16e7) /* one year; arbitrary */
128#define MIN_FREQ 1e2 /* more or less arbitrary */
129#define MAX_FREQ 1e4 /* more or less arbitrary */
130#define MAX_NODES 1e6 /* keep idiot users safe */
131
132/* IAN: Clumsy way of specifying rectangular search region if */
133/* the r=0 option is invoked. */
134REAL4 ra_min;
135REAL4 ra_max;
136REAL4 dec_min;
137REAL4 dec_max;
138
139void getRange( LALStatus *, REAL4 [2], REAL4, void * );
140void getMetric( LALStatus *, REAL4 [3], REAL4 [2], void * );
141
142/* BEN: This is a cheat. Should make a search area structure. */
143static SkyPosition center; /* center of search */
144REAL4 radius; /* radius of search, in arcminutes */
145
146int main( int argc, char **argv )
147{
148 static LALStatus stat; /* status structure */
149 INT2 opt; /* command-line option character */
150 BOOLEAN nonGrace; /* whether or not to write to data file */
151 TwoDMeshNode *firstNode; /* head of linked list of nodes in mesh */
152 static TwoDMeshParamStruc mesh; /* mesh parameters */
153 static PtoleMetricIn search; /* more mesh parameters */
154 REAL4 mismatch; /* mismatch threshold of mesh */
155 int begin; /* start time of integration (seconds) */
156 REAL4 duration; /* duration of integration (seconds) */
157 REAL4 fMax; /* maximum frequency of search */
158 FILE *fp; /* where to write a plot */
159 float a, b, c, d, e, f; /* To specify center of search region */
160 BOOLEAN rectangular; /* is the search region rectangular? */
161
162 /* Set default values. */
163 nonGrace = 0;
164 begin = 731265908;
165 duration = 1e5;
166 fMax = 1e3;
167 mismatch = .02;
168 /* This is (roughly) the center of globular cluster 47 Tuc. */
170 center.longitude = ( 24.1 / 60 ) * LAL_PI_180;
171 center.latitude = -( 72 + 5. / 60 ) * LAL_PI_180;
172 radius = 24.0 / 60 * LAL_PI_180;
173 ra_min = 0.0;
174 ra_max = LAL_PI_2;
175 dec_min = 0.0;
176 dec_max = LAL_PI_2;
177 rectangular = 0;
178
179 /* Parse and sanity-check the command-line options. */
180 while ( ( opt = LALgetopt( argc, argv, "a:b:c:d:ef:l:m:pr:t:x" ) ) != -1 ) {
181 switch ( opt ) {
182 case '?':
184 case 'b':
185 begin = atoi( LALoptarg );
186 break;
187 case 'c':
188 if ( sscanf( LALoptarg, "%f:%f:%f:%f:%f:%f", &a, &b, &c, &d, &e, &f ) != 6 ) {
189 fprintf( stderr, "coordinates should be hh:mm:ss:dd:mm:ss\n" );
191 }
192 center.longitude = ( 15 * a + b / 4 + c / 240 ) * LAL_PI_180;
193 center.latitude = ( d + e / 60 + f / 3600 ) * LAL_PI_180;
194 break;
195 case 'f':
196 fMax = atof( LALoptarg );
197 break;
198 case 'l':
199 if ( sscanf( LALoptarg, "%f:%f:%f:%f",
200 &ra_min, &ra_max, &dec_min, &dec_max ) != 4 ) {
201 fprintf( stderr, "coordinates should be ra_min, ra_max, dec_min, dec_max, all in degrees\n" );
203 }
204 ra_min *= LAL_PI_180;
205 ra_max *= LAL_PI_180;
206 dec_min *= LAL_PI_180;
207 dec_max *= LAL_PI_180;
208 rectangular = 1;
209 radius = 0;
210 break;
211 case 'm':
212 mismatch = atof( LALoptarg );
213 break;
214 case 'p':
215 nonGrace = 1;
216 break;
217 case 'r':
218 if ( rectangular == 1 ) {
219 break;
220 }
221 radius = LAL_PI_180 / 60 * atof( LALoptarg );
222 if ( radius < 0 ) {
223 fprintf( stderr, "%s line %d: %s\n", __FILE__, __LINE__,
226 }
227 break;
228 case 't':
229 duration = atof( LALoptarg );
230 if ( duration < MIN_DURATION || duration > MAX_DURATION ) {
231 fprintf( stderr, "%s line %d: %s\n", __FILE__, __LINE__,
234 }
235 break;
236 } /* switch( opt ) */
237 } /* while( LALgetopt... ) */
238
239
240 /* Set the mesh input parameters. */
241 mesh.mThresh = mismatch;
242 mesh.nIn = MAX_NODES;
243 mesh.getRange = getRange;
244 mesh.getMetric = getMetric;
245 mesh.metricParams = ( void * ) &search;
246 if ( radius == 0 ) {
247 mesh.domain[0] = dec_min;
248 mesh.domain[1] = dec_max;
249 /* I don't understand this line*/
250 mesh.rangeParams = ( void * ) &search;
251 } else {
252 mesh.domain[0] = center.latitude - radius;
253 mesh.domain[1] = center.latitude + radius;
254 mesh.rangeParams = NULL;
255 }
256
257
258 /* Set detector location */
260
261 /* Ptolemetric constants */
263 search.spindown = NULL;
264 search.epoch.gpsSeconds = begin;
265 search.epoch.gpsNanoSeconds = 0;
266 search.duration = duration;
267 search.maxFreq = fMax;
268
269 /* Create mesh */
270 firstNode = NULL;
271 LALCreateTwoDMesh( &stat, &firstNode, &mesh );
272 if ( stat.statusCode ) {
273 return stat.statusCode;
274 }
275 printf( "created %d nodes\n", mesh.nOut );
276 if ( mesh.nOut == MAX_NODES ) {
277 printf( "This overflowed your limit. Try a smaller search.\n" );
278 }
279
280
281 /* Write what we've got to file mesh.dat, if required */
282 if ( nonGrace ) {
283 TwoDMeshNode *node;
284 fp = fopen( "mesh.dat", "w" );
285 if ( !fp ) {
287 }
288
289 for ( node = firstNode; node; node = node->next )
290 fprintf( fp, "%e %e\n",
291 ( double )( ( node->y ) * 180 / LAL_PI ), ( double )( ( node->x ) * 180 / LAL_PI ) );
292 fclose( fp );
293 }
294
295 /* Clean up and leave. */
296 LALDestroyTwoDMesh( &stat, &firstNode, &mesh.nOut );
297 printf( "destroyed %d nodes\n", mesh.nOut );
298 if ( stat.statusCode ) {
300 }
301
303 return 0;
304} /* main() */
305
306
307/* This is the parameter range function as required by TwoDMesh. */
308
309void getRange( LALStatus *stat, REAL4 y[2], REAL4 x, void *unused )
310{
311 /* Set up shop. */
312 INITSTATUS( stat );
314
315 /* Search a circle. BEN: The 1.001 is a kludge. */
316 y[0] = center.longitude - sqrt( pow( radius * 1.001, 2 )
317 - pow( x - center.latitude, 2 ) );
318 y[1] = center.longitude + sqrt( pow( radius * 1.001, 2 )
319 - pow( x - center.latitude, 2 ) );
320
321 if ( unused ) {
322 y[0] = ra_min;
323 y[1] = ra_max;
324 }
325
326 /*
327 printf("x = %le, y[0] = %le, y[1] = %le\n", (double)x, (double)y[0],
328 (double)y[1]);
329 */
330
331 /* Clean up and leave. */
333 RETURN( stat );
334} /* getRange() */
335
336
337/* This is the wrapped metric function as required by TwoDMesh. */
338
340 REAL4 g[3],
341 REAL4 x[2],
342 void *params )
343{
344
345 REAL8Vector *metric = NULL; /* for output of metric */
346 PtoleMetricIn *Ppatch = NULL; /* pointer for PtoleMetric params */
347 REAL8 determinant; /* Determinant of projected metric */
348
349
350 Ppatch = params;
351
352 /* Set up shop. */
353 INITSTATUS( stat );
355 TRY( LALDCreateVector( stat->statusPtr, &metric, 6 ), stat );
356
357 /* Translate input. */
358 Ppatch->position.longitude = x[1];
359 Ppatch->position.latitude = x[0];
360
361 /* Call the real metric function. */
362 LALPtoleMetric( stat->statusPtr, metric, Ppatch );
363
364 BEGINFAIL( stat )
365 TRY( LALDDestroyVector( stat->statusPtr, &metric ), stat );
366 ENDFAIL( stat );
367 LALProjectMetric( stat->statusPtr, metric, 0 );
368 BEGINFAIL( stat )
369 TRY( LALDDestroyVector( stat->statusPtr, &metric ), stat );
370 ENDFAIL( stat );
371
372 determinant = metric->data[5] * metric->data[2] - pow( metric->data[4], 2.0 );
373 if ( determinant < 0.0 ) {
374 printf( "%s line %d: %s\n", __FILE__, __LINE__,
376 return;
377 }
378
379
380
381 /* Translate output. */
382 g[1] = metric->data[2];
383 g[0] = metric->data[5];
384 g[2] = metric->data[4];
385
386
387 /* Clean up and leave. */
388 TRY( LALDDestroyVector( stat->statusPtr, &metric ), stat );
390 RETURN( stat );
391
392
393} /* getMetric() */
394
395/** \endcond */
LALDetectorIndexGEO600DIFF
void getMetric(LALStatus *, meshREAL g[3], meshREAL skypos[2], void *params)
Definition: DopplerScan.c:414
void getRange(LALStatus *, meshREAL y[2], meshREAL x, void *params)
#define GENERALMESHTESTC_EOPT
#define GENERALMESHTESTC_MSGERNG
#define GENERALMESHTESTC_MSGEMET
#define GENERALMESHTESTC_ERNG
#define GENERALMESHTESTC_EMEM
#define GENERALMESHTESTC_EFIO
void LALCheckMemoryLeaks(void)
#define c
#define ENDFAIL(statusptr)
#define TRY(func, statusptr)
#define ATTATCHSTATUSPTR(statusptr)
#define DETATCHSTATUSPTR(statusptr)
#define INITSTATUS(statusptr)
#define RETURN(statusptr)
#define BEGINFAIL(statusptr)
int LALgetopt(int argc, char *const *argv, const char *optstring)
#define fprintf
double e
int main(int argc, char **argv)
const LALDetector lalCachedDetectors[LAL_NUM_DETECTORS]
#define LAL_PI_2
#define LAL_PI_180
unsigned char BOOLEAN
double REAL8
int16_t INT2
float REAL4
void LALPtoleMetric(LALStatus *status, REAL8Vector *metric, PtoleMetricIn *input)
Computes metric components for a pulsar search in the `‘Ptolemaic’' approximation; both the Earth's s...
Definition: PtoleMetric.c:91
void LALProjectMetric(LALStatus *stat, REAL8Vector *metric, BOOLEAN errors)
Project out the zeroth dimension of a metric.
Definition: PtoleMetric.c:732
static const INT4 a
COORDINATESYSTEM_EQUATORIAL
void LALCreateTwoDMesh(LALStatus *stat, TwoDMeshNode **mesh, TwoDMeshParamStruc *params)
Definition: TwoDMesh.c:106
void LALDestroyTwoDMesh(LALStatus *stat, TwoDMeshNode **mesh, UINT4 *nFree)
Definition: TwoDMesh.c:159
void LALDCreateVector(LALStatus *, REAL8Vector **, UINT4)
void LALDDestroyVector(LALStatus *, REAL8Vector **)
list y
INT4 gpsNanoSeconds
This structure will likely be changed to match up better with those under StackMetric....
Definition: PtoleMetric.h:110
SkyPosition position
The equatorial coordinates at which the metric components are evaluated.
Definition: PtoleMetric.h:111
REAL4Vector * spindown
The (dimensionless) spindown parameters for which the metric components are evaluated.
Definition: PtoleMetric.h:112
REAL4 maxFreq
The maximum frequency to be searched, in Hz.
Definition: PtoleMetric.h:115
const LALDetector * site
The detector site, used only for its latitude and longitude.
Definition: PtoleMetric.h:116
REAL4 duration
Duration of integration, in seconds.
Definition: PtoleMetric.h:114
LIGOTimeGPS epoch
When the coherent integration begins.
Definition: PtoleMetric.h:113
REAL8 longitude
REAL8 latitude
CoordinateSystem system
This structure represents a single node in a linked list of mesh points, specified in the coordinate ...
Definition: TwoDMesh.h:124
struct tagTwoDMeshNode * next
The next mesh point in the linked list; NULL if this is the tail.
Definition: TwoDMesh.h:128
REAL4 y
The coordinates of the mesh point.
Definition: TwoDMesh.h:125
This structure stores the parameters required by the two-dimensional mesh placement functions.
Definition: TwoDMesh.h:142
void(* getMetric)(LALStatus *, REAL4[3], REAL4[2], void *)
A function that returns in its second argument the components , , and (in that order) of the metri...
Definition: TwoDMesh.h:150
UINT4 nIn
The maximum number of mesh points allowed, after which the placement routine will quit.
Definition: TwoDMesh.h:170
void * metricParams
The parameters to be passed as the fourth argument of *getMetric(), above.
Definition: TwoDMesh.h:155
REAL4 mThresh
The maximum mismatch desired between any point in the region and the nearest mesh point; note that t...
Definition: TwoDMesh.h:156
void(* getRange)(LALStatus *, REAL4[2], REAL4, void *)
A function that returns in its second argument the range spanned by the parameter region for a speci...
Definition: TwoDMesh.h:144
UINT4 nOut
The number of mesh points added by the placement routine; if an error occurs, this will store the num...
Definition: TwoDMesh.h:171
REAL4 domain[2]
The domain spanned by the desired parameter region.
Definition: TwoDMesh.h:143
void * rangeParams
The parameters to be passed as the fourth argument of *getRange(), above.
Definition: TwoDMesh.h:149