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
PtoleMeshTest.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 Jolien Creighton, Ian Jones, Benjamin Owen, Reinhard Prix
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 Owen, B. J., Jones, D. I.
22 * \file
23 * \ingroup PtoleMetric_h
24 * \brief Tests and showcases the combination of \ref PtoleMetric_h and \ref TwoDMesh_h modules.
25 *
26 * ### Program PtoleMeshTest ###
27 *
28 *
29 * ### Usage ###
30 *
31 * \code
32 * PtoleMeshTest
33 * \endcode
34 *
35 * ### Description ###
36 *
37 * The <tt>-b</tt> option sets the beginning time of integration to the option
38 * argument. (Default is \f$ 0 \f$ seconds)
39 *
40 * The <tt>-c</tt> option determins the center of the patch. (Default is the
41 * center of the globular cluster 47 Tuc.) This option is hardcoded to use
42 * equatorial coordinates and the argument should be given in hh:mm:ss:dd:mm:ss
43 * format.
44 *
45 * The <tt>-e</tt> option sets \c lalDebugLevel to the option argument.
46 * (Default is 1.)
47 *
48 * The <tt>-f</tt> option sets the maximum frequency of integration (in Hz) to the
49 * option argument. (The default value is 1000.)
50 *
51 * The <tt>-i</tt> option does not function at this time.
52 *
53 * The <tt>-m</tt> option sets the maximum mismatch of the mesh to the option
54 * argument. (Default is 0.02.)
55 *
56 * The <tt>-n</tt> option sets the maximum number of nodes in the mesh to the
57 * option argument. (Default is \f$ 10^6 \f$ .)
58 *
59 * The texttt{-p} option causes the coordinates of the nodes to be written to
60 * a file <tt>mesh.dat</tt>, for the benifit of users who don't have
61 * \c xmgrace installed. The format is one node per line, (RA, DEC),
62 * with the angles in degrees.
63 *
64 * The <tt>-r</tt> option sets the radius (in arcminutes) of the circular
65 * sky patch. (The default value is set for the globular cluster 47 Tuc.)
66 * At the moment there is no option for another patch shape, but if you
67 * specify radius zero you will get a search over a rectangular region
68 * whose limits in RA and dec are specified in the code.
69 *
70 * The <tt>-t</tt> option sets the duration of integration, in seconds. (The
71 * default is \f$ 10^5 \f$ seconds, which is of order one day but is not an integer
72 * multiple of anything astronomically important.)
73 *
74 * ### Algorithm ###
75 *
76 *
77 * ### Uses ###
78 *
79 * \code
80 * lalDebugLevel
81 * LALCheckMemoryLeaks()
82 * LALProjectMetric()
83 * LALPtoleMetric()
84 * \endcode
85 *
86 * ### Notes ###
87 *
88 */
89
90/** \name Error Codes */ /** @{ */
91#define PTOLEMESHTESTC_EMEM 1
92#define PTOLEMESHTESTC_ERNG 2
93#define PTOLEMESHTESTC_EFIO 3
94#define PTOLEMESHTESTC_EOPT 4
95
96#define PTOLEMESHTESTC_MSGEMEM "memory (de)allocation error"
97#define PTOLEMESHTESTC_MSGERNG "value out of range"
98#define PTOLEMESHTESTC_MSGEFIO "file I/O error"
99#define PTOLEMESHTESTC_MSGEOPT "unknown command-line option"
100/** @} */
101
102#include <config.h>
103
104#include <math.h>
105#include <stdio.h>
106#include <lal/AVFactories.h>
107#include <lal/LALgetopt.h>
108#include <lal/PtoleMetric.h>
109#include <lal/TwoDMesh.h>
110
111/** \cond DONT_DOXYGEN */
112
113/* BEN: These aren't used right now, but should be. */
114#define MIN_DURATION (86400./LAL_TWOPI) /* one radian of rotation */
115#define MAX_DURATION (86400.*5) /* not much orbital motion */
116#define MIN_FREQ 1e2 /* more or less arbitrary */
117#define MAX_FREQ 1e4 /* more or less arbitrary */
118
119/* IAN: Clumsy way of specifying rectangular search region if */
120/* the r=0 option is invoked. */
121
122#define RA_min 0.0
123#define RA_max LAL_PI_2/2.0
124#define dec_min LAL_PI_2/2.0
125#define dec_max LAL_PI_2
126
127
128
129
130void getRange( LALStatus *, REAL4 [2], REAL4, void * );
131void getMetric( LALStatus *, REAL4 [3], REAL4 [2], void * );
132
133/* BEN: This is a cheat. Should make a search area structure. */
134static SkyPosition center; /* center of search */
135REAL4 radius; /* radius of search, in arcminutes */
136
137int main( int argc, char **argv )
138{
139 static LALStatus stat; /* status structure */
140 INT2 opt; /* command-line option character */
141 BOOLEAN nonGrace; /* whether or not to write to data file */
142 TwoDMeshNode *firstNode; /* head of linked list of nodes in mesh */
143 static TwoDMeshParamStruc mesh; /* mesh parameters */
144 static PtoleMetricIn search; /* more mesh parameters */
145 REAL4 mismatch; /* mismatch threshold of mesh */
146 UINT4 maxNodes; /* maximum nodes in mesh */
147 REAL4 begin; /* start time of integration (seconds) */
148 REAL4 duration; /* duration of integration (seconds) */
149 REAL4 fMax; /* maximum frequency of search */
150 FILE *fp; /* where to write a plot */
151
152
153
154 /* Set default values. */
155 nonGrace = 0;
156 begin = 0.0;
157 duration = 1e5;
158 fMax = 1e3;
159 mismatch = .02;
160 maxNodes = 1e6;
161 /* This is (roughly) the center of globular cluster 47 Tuc. */
163 center.longitude = ( 24.1 / 60 ) * LAL_PI_180;
164 center.latitude = -( 72 + 5. / 60 ) * LAL_PI_180;
165 radius = 24.0 / 60 * LAL_PI_180;
166
167 /* Parse and sanity-check the command-line options. */
168 while ( ( opt = LALgetopt( argc, argv, "b:c:e:f:im:n:pr:t:x" ) ) != -1 ) {
169 switch ( opt ) {
170 float a, b, c, d, e, f;
171 case '?':
172 return PTOLEMESHTESTC_EOPT;
173 case 'b':
174 begin = atof( LALoptarg );
175 break;
176 case 'c':
177 if ( sscanf( LALoptarg, "%f:%f:%f:%f:%f:%f", &a, &b, &c, &d, &e, &f ) != 6 ) {
178 fprintf( stderr, "coordinates should be hh:mm:ss:dd:mm:ss\n" );
179 return PTOLEMESHTESTC_EOPT;
180 }
181 center.longitude = ( 15 * a + b / 4 + c / 240 ) * LAL_PI_180;
182 center.latitude = ( d + e / 60 + f / 3600 ) * LAL_PI_180;
183 break;
184 case 'e':
185 break;
186 case 'f':
187 fMax = atof( LALoptarg );
188 break;
189 case 'i':
190 break;
191 case 'm':
192 mismatch = atof( LALoptarg );
193 break;
194 case 'n':
195 maxNodes = atoi( LALoptarg );
196 break;
197 case 'p':
198 nonGrace = 1;
199 break;
200 case 'r':
201 radius = LAL_PI_180 / 60 * atof( LALoptarg );
202 if ( radius < 0 ) {
203 fprintf( stderr, "%s line %d: %s\n", __FILE__, __LINE__,
205 return PTOLEMESHTESTC_ERNG;
206 }
207 break;
208 case 't':
209 duration = atof( LALoptarg );
210 if ( duration < MIN_DURATION || duration > MAX_DURATION ) {
211 fprintf( stderr, "%s line %d: %s\n", __FILE__, __LINE__,
213 return PTOLEMESHTESTC_ERNG;
214 }
215 break;
216 } /* switch( opt ) */
217 } /* while( LALgetopt... ) */
218
219 /* Create the mesh. */
220 mesh.mThresh = mismatch;
221 mesh.nIn = maxNodes;
222 mesh.getRange = getRange;
223 mesh.getMetric = getMetric;
224 mesh.metricParams = ( void * ) &search;
225 if ( radius == 0 ) {
226 mesh.domain[0] = dec_min;
227 mesh.domain[1] = dec_max;
228 mesh.rangeParams = ( void * ) &search;
229 } else {
230 mesh.domain[0] = center.latitude - radius;
231 mesh.domain[1] = center.latitude + radius;
232 mesh.rangeParams = NULL;
233
234 }
236 search.spindown = NULL;
237 search.epoch.gpsSeconds = begin;
238 search.epoch.gpsNanoSeconds = 0;
239 search.duration = duration;
240 search.maxFreq = fMax;
241 /* BEN: make this flexible later */
243 firstNode = NULL;
244 LALCreateTwoDMesh( &stat, &firstNode, &mesh );
245 if ( stat.statusCode ) {
246 return stat.statusCode;
247 }
248 printf( "created %d nodes\n", mesh.nOut );
249
250 /* Write what we've got to file mesh.dat */
251 if ( nonGrace ) {
252 TwoDMeshNode *node;
253 fp = fopen( "mesh.dat", "w" );
254 if ( !fp ) {
255 return PTOLEMESHTESTC_EFIO;
256 }
257
258 for ( node = firstNode; node; node = node->next ) {
259 fprintf( fp, "%e %e\n", node->y, node->x );
260 }
261 fclose( fp );
262 }
263
264 /* Clean up and leave. */
265 LALDestroyTwoDMesh( &stat, &firstNode, &mesh.nOut );
266 printf( "destroyed %d nodes\n", mesh.nOut );
267 if ( stat.statusCode ) {
268 return PTOLEMESHTESTC_EMEM;
269 }
271 return 0;
272} /* main() */
273
274
275/* This is the parameter range function as required by TwoDMesh. */
276
277void getRange( LALStatus *stat, REAL4 y[2], REAL4 x, void *unused )
278{
279 /* Set up shop. */
280 INITSTATUS( stat );
282
283 /* Search a circle. BEN: The 1.001 is a kludge. */
284 y[0] = center.longitude - sqrt( pow( radius * 1.001, 2 )
285 - pow( x - center.latitude, 2 ) );
286 y[1] = center.longitude + sqrt( pow( radius * 1.001, 2 )
287 - pow( x - center.latitude, 2 ) );
288
289 if ( unused ) {
290 y[0] = RA_min;
291 y[1] = RA_max;
292 }
293
294 /* Clean up and leave. */
296 RETURN( stat );
297} /* getRange() */
298
299
300/* This is the wrapped metric function as required by TwoDMesh. */
301
303 REAL4 g[3],
304 REAL4 x[2],
305 void *params )
306{
307 PtoleMetricIn *patch = params; /* avoid pesky gcc warnings */
308 REAL8Vector *metric = NULL; /* for output of metric */
309
310 /* Set up shop. */
311 INITSTATUS( stat );
313 TRY( LALDCreateVector( stat->statusPtr, &metric, 6 ), stat );
314
315 /* Translate input. */
316 patch->position.longitude = x[1];
317 patch->position.latitude = x[0];
318
319
320 /* Call the real metric function. */
321 LALPtoleMetric( stat->statusPtr, metric, patch );
322 BEGINFAIL( stat )
323 TRY( LALDDestroyVector( stat->statusPtr, &metric ), stat );
324 ENDFAIL( stat );
325 LALProjectMetric( stat->statusPtr, metric, 0 );
326 BEGINFAIL( stat )
327 TRY( LALDDestroyVector( stat->statusPtr, &metric ), stat );
328 ENDFAIL( stat );
329
330 /* Translate output. */
331 g[1] = metric->data[2];
332 g[0] = metric->data[5];
333 g[2] = metric->data[4];
334
335 /* Clean up and leave. */
336 TRY( LALDDestroyVector( stat->statusPtr, &metric ), stat );
338 RETURN( stat );
339} /* getMetric() */
340
341/** \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)
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 PTOLEMESHTESTC_ERNG
Definition: PtoleMeshTest.c:92
#define PTOLEMESHTESTC_EOPT
Definition: PtoleMeshTest.c:94
#define PTOLEMESHTESTC_MSGERNG
Definition: PtoleMeshTest.c:97
#define PTOLEMESHTESTC_EFIO
Definition: PtoleMeshTest.c:93
#define PTOLEMESHTESTC_EMEM
Definition: PtoleMeshTest.c:91
#define fprintf
double e
int main(int argc, char **argv)
const LALDetector lalCachedDetectors[LAL_NUM_DETECTORS]
#define LAL_PI_180
unsigned char BOOLEAN
int16_t INT2
uint32_t UINT4
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