Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALApps 10.1.0.1-b246709
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
stochasticbank.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2011 Drew Keppel, Duncan Brown
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 *
22 * File Name: stochasticbank.c
23 *
24 * Author: Keppel, D.
25 *
26 *
27 *-----------------------------------------------------------------------
28 */
29
30#include <config.h>
31#include <stdio.h>
32#include <stdlib.h>
33#include <string.h>
34#include <sys/types.h>
35#include <sys/stat.h>
36#include <fcntl.h>
37#include <regex.h>
38#include <time.h>
39#include <math.h>
40
41#include <series.h>
42
43#include <lal/LALConfig.h>
44#include <lal/LALgetopt.h>
45#include <lal/LALStdio.h>
46#include <lal/LALStdlib.h>
47#include <lal/LALError.h>
48#include <lal/LALDatatypes.h>
49#include <lal/AVFactories.h>
50#include <lal/LIGOLwXML.h>
51#include <lal/LIGOLwXMLRead.h>
52#include <lal/LIGOMetadataTables.h>
53#include <lal/LIGOMetadataUtils.h>
54#include <lal/GenerateInspiral.h>
55#include <lal/TimeFreqFFT.h>
56#include <lal/Interpolate.h>
57#include <lal/TimeSeries.h>
58#include <lal/VectorOps.h>
59#include <lal/Units.h>
60#include <lal/Date.h>
61#include <lal/LALInspiral.h>
62#include <lal/LALInspiralBank.h>
63#include "inspiral.h"
64#include <LALAppsVCSInfo.h>
65
66#define CVS_ID_STRING "$Id$"
67#define CVS_NAME_STRING "$Name$"
68#define CVS_REVISION "$Revision$"
69#define CVS_SOURCE "$Source$"
70#define CVS_DATE "$Date$"
71#define PROGRAM_NAME "tmpltbank"
72
73int arg_parse_check( int argc, char *argv[], ProcessParamsTable *procparams );
76REAL4FrequencySeries *readPSD(const char *fname, REAL4 fNyq, REAL4 df, UINT4 N, REAL4 fLow, REAL4 fHigh);
77
78typedef struct
79tagTemplateWaveformPairs
80{
83 struct tagTemplateWaveformPairs *next;
84}
86
87/*
88 *
89 * variables that control program behaviour
90 *
91 */
92
93/* debugging */
94extern int vrbflg; /* verbocity of lal function */
95
96/* template bank generation parameters */
97LIGOTimeGPS gpsStartTime = { 0, 0 }; /* input data GPS start time */
98LIGOTimeGPS gpsEndTime = { 0, 0 }; /* input data GPS end time */
99REAL4 minMass = -1; /* minimum component mass */
100REAL4 maxMass = -1; /* maximum component mass */
101REAL4 minMTotal = -1; /* minimum total mass */
102REAL4 maxMTotal = -1; /* maximum total mass */
103REAL4 minMChirp = -1; /* minimum chirp mass */
104REAL4 maxMChirp = -1; /* maximum chirp mass */
105REAL4 fLo = -1; /* low frequency cutoff */
106REAL4 fHi = -1; /* high frequency cutoff */
107INT4 facTries = -1; /* ratio of numTries/numTmplts */
108REAL4 minMatch = -1; /* minimal match of tmplt bank */
109enum { unset, urandom, user } randSeedType = unset; /* sim seed type */
110INT4 randomSeed = 0; /* value of sim rand seed */
112
113/* input/output parameters */
114CHAR *userTag = NULL;
117
119{
120 INT4 exponent = 0;
121 REAL4 mantissa;
122
123 mantissa = frexp(x, &exponent);
124
125 if (mantissa < 0)
126 return NAN;
127 else if (mantissa == 0.5)
128 return ldexp((REAL4) 1., exponent - 1);
129 else
130 return ldexp((REAL4) 1., exponent);
131}
132
133
135{
136 REAL4 qmax1,qmax2,tmp1,tmp2;
137
138 tmp1 = pow(mchirp / m, 5.);
139 tmp2 = tmp1 * (-9. + pow(3., .5) * pow(27. + 4.*tmp1, .5) ) / 18.;
140 tmp2 = pow(tmp2, 1./3.);
141 qmax1 = tmp2 + tmp1 / 3. / tmp2;
142
143 tmp1 = -M;
144 tmp2 = pow(mchirp, 5./3.) * pow(M, 1./3.);
145 qmax2 = -tmp1 + sqrt(tmp1*tmp1 - 4.*tmp2);
146 qmax2 /= 2. * m;
147
148 return qmax1 < qmax2 ? qmax1 : qmax2;
149}
150
151
153{
154 FILE *fp;
155 UINT4 i, j;
156 REAL4 f0, f1;
157 REAL8 junk;
158 char line[1000];
161
162 fp = fopen(fname, "r");
163 i = 0;
164 while (fgets(line, sizeof line, fp))
165 {
166 if (*line == '#')
167 continue;
168 else if (i == 0)
169 sscanf(line, "%e\t%le", &f0, &junk);
170 else if (i == 1)
171 sscanf(line, "%e\t%le", &f1, &junk);
172 i++;
173 }
174 fclose(fp);
175
177 fp = fopen(fname, "r");
178 i = 0;
179 while (fgets(line, sizeof line, fp))
180 {
181 if (*line == '#')
182 continue;
183 sscanf(line, "%le\t%le", &junk, &(psd1->data->data[i]));
184 i++;
185 }
186 fclose(fp);
187
188
189 REAL8 Fs[psd1->data->length];
190 for (i = 0; i < psd1->data->length; i++)
191 {
192 Fs[i] = (REAL8) (i * (REAL4) psd1->deltaF + (REAL4) psd1->f0);
193 }
194
196
197 for (i = 0; i < N / 2 + 1; i++)
198 {
199 REAL8 tmpS, dS;
200 REAL8 tmpf = (REAL8) fNyq - df*i;
201
202 if ( tmpf < fLow || tmpf > fHigh )
203 {
204 psd->data->data[i] = 0.;
205 if (i > 0)
206 psd->data->data[N - i] = 0.;
207 continue;
208 }
209
210 for (j=2; j < 10; j++)
211 {
212 dS = XLALREAL8PolynomialInterpolation(&tmpS, tmpf, psd1->data->data, Fs, 10);
213 if ( (tmpS == 0. && dS < 1e-5) || (fabs(dS / tmpS) < 1e-5) )
214 break;
215 }
216
217 psd->data->data[i] = tmpS;
218 if (i > 0)
219 psd->data->data[N - i] = tmpS;
220 }
222
223 return psd;
224}
225
226
227int main ( int argc, char *argv[] )
228{
229 /* lal function variables */
231
232 /* templates */
233 RandomParams *randParams = NULL;
234 InspiralTemplate newTmplt;
235 SnglInspiralTable *thisTmplt = NULL;
236
237 /* output data */
238 SnglInspiralTable *templateBank = NULL;
239 ProcessTable *proctable;
240 ProcessParamsTable *procparams;
241 LIGOLwXMLStream *results;
242
243 /* waveform storage */
244
245 REAL4TimeSeries *realWaveform = NULL; /* storing real waveform */
246 REAL4TimeSeries *imagWaveform = NULL; /* storing imag waveform */
247 REAL4TimeSeries *overlap = NULL; /* storing abs(complex overlap) */
248 COMPLEX8TimeSeries *waveform = NULL; /* storing complex waveform */
249 COMPLEX8TimeSeries *overlapc = NULL; /* storing complex overlap */
250
251 COMPLEX8FrequencySeries *waveformf1 = NULL; /* storing FFT of complex waveform 1 */
252 COMPLEX8FrequencySeries *waveformf2 = NULL; /* storing FFT of complex waveform 2 */
253 COMPLEX8FrequencySeries *overlapf = NULL; /* storing FFT of complex overlap */
254
255 REAL4FrequencySeries *psd = NULL; /* storing inverse psd */
256
257 TemplateWaveformPairs *headWvTmpltPr = NULL;
258 TemplateWaveformPairs *thisWvTmpltPr = NULL;
259 TemplateWaveformPairs *tmpWvTmpltPr = NULL;
260
261 /* counters and other variables */
262 UINT4 i, N, trynum, lastTmplt, numTmplts;
263 INT4 fs;
264 CHAR fname[256];
265 REAL4 dt, df, norm, match;
266 COMPLEX8FFTPlan *fwdp = NULL;
267 COMPLEX8FFTPlan *revp = NULL;
268
269 /*
270 *
271 * initialization
272 *
273 */
274
275
276 /* set up inital debugging values */
279
280 /* create the process and process params tables */
281 proctable = (ProcessTable *) calloc( 1, sizeof(ProcessTable) );
282 XLALGPSTimeNow(&(proctable->start_time));
285 procparams = (ProcessParamsTable *) calloc( 1, sizeof(ProcessParamsTable) );
286
287 /* call the argument parse and check function */
288 arg_parse_check( argc, argv, procparams );
289
290 /* can use LALMalloc() / LALCalloc() from here */
291
292
293 /*
294 *
295 * create the radom number seed
296 *
297 */
298
299
300 if ( randSeedType == urandom )
301 {
302 FILE *fpRand = NULL;
303 INT4 randByte;
304
305 if ( vrbflg )
306 fprintf( stdout, "obtaining random seed from /dev/urandom: " );
307
308 randomSeed = 0;
309 fpRand = fopen( "/dev/urandom", "r" );
310 if ( fpRand )
311 {
312 for ( randByte = 0; randByte < 4 ; ++randByte )
313 {
314 INT4 tmpSeed = (INT4) fgetc( fpRand );
315 randomSeed += tmpSeed << ( randByte * 8 );
316 }
317 fclose( fpRand );
318 }
319 else
320 {
321 perror( "error obtaining random seed from /dev/urandom" );
322 exit( 1 );
323 }
324 }
325 else if ( randSeedType == user )
326 {
327 if ( vrbflg )
328 fprintf( stdout, "using user specified random seed: " );
329 }
330
331 if ( vrbflg ) fprintf( stdout, "%d\n", randomSeed );
332
333 /* create the tmplt bank random parameter structure */
335 &status );
336
337 // compute length of longest waveform
338 memset( &newTmplt, 0, sizeof(InspiralTemplate) );
339 newTmplt.massChoice = m1Andm2;
340 newTmplt.order = LAL_PNORDER_TWO;
341 newTmplt.fLower = fLo;
342 newTmplt.fCutoff = fHi;
343 newTmplt.mass1 = minMChirp / pow(.25, .6) / 2;
344 newTmplt.mass2 = newTmplt.mass1;
345
347
348 fs = 2 * ceil_pow_2(fHi * 1.1);
349 dt = 1. / fs;
350 N = fs * 2 * ceil_pow_2(newTmplt.t0 * 1.1 + 32.);
351 df = (REAL4) fs / N;
352
353 memset( &newTmplt, 0, sizeof(InspiralTemplate) );
354 newTmplt.massChoice = m1Andm2;
355 newTmplt.approximant = TaylorT1;
358 newTmplt.fLower = fLo;
359 newTmplt.fCutoff = fHi;
360 newTmplt.tSampling = fs;
361 newTmplt.signalAmplitude = 1.;
362
365
366 psd = readPSD(psdFileName, fs/2, df, N, fLo, fHi);
367
368 realWaveform = XLALCreateREAL4TimeSeries("", &tc, 0.0, dt, &lalDimensionlessUnit, N);
369 imagWaveform = XLALCreateREAL4TimeSeries("", &tc, 0.0, dt, &lalDimensionlessUnit, N);
371 overlapc = XLALCreateCOMPLEX8TimeSeries("", &tc, 0.0, dt, &lalDimensionlessUnit, N);
373
374 waveformf1 = XLALCreateCOMPLEX8FrequencySeries("", &tc, 0.0, df, &lalSecondUnit, N);
375 overlapf = XLALCreateCOMPLEX8FrequencySeries("", &tc, 0.0, df, &lalSecondUnit, N);
376
377 /*
378 *
379 * create a stochastic template bank
380 *
381 */
382
383
384 trynum = 0;
385 numTmplts = 0;
386 lastTmplt = 0;
387 while ( trynum <= facTries * numTmplts )
388 {
389 fprintf(stderr, "\r%i %i %i", trynum, numTmplts, lastTmplt);
390
391 REAL4 randfloat,mchirp,q,m1,m2,M,eta;
392 REAL4 qmax;
393
394 trynum++;
395 lastTmplt++;
396
397 /* generate random parameters for the injection */
398 randfloat = XLALUniformDeviate( randParams );
399 if ( XLAL_IS_REAL4_FAIL_NAN( randfloat ) )
400 {
401 exit( 1 );
402 }
403
404 mchirp = (maxMChirp - minMChirp) * randfloat;
405 mchirp += minMChirp;
406
407 qmax = max_mass_ratio(mchirp, minMass, maxMTotal);
408
409 m2 = 0;
410 m1 = 0;
411 while (m2 < minMass)
412 {
413 /* generate random parameters for the injection */
414 randfloat = XLALUniformDeviate( randParams );
415 if ( XLAL_IS_REAL4_FAIL_NAN( randfloat ) )
416 {
417 exit( 1 );
418 }
419
420 q = (qmax - 1.) * randfloat;
421 q += 1.;
422
423 eta = q;
424 eta /= 1.+q;
425 eta /= 1.+q;
426
427 M = mchirp / pow(eta, 0.6);
428 m2 = M / (q + 1.);
429 m1 = M - m2;
430 }
431
432 newTmplt.mass1 = m1;
433 newTmplt.mass2 = m2;
434
435
437
438
439 /* --- now we can call the injection function --- */
440 memset(realWaveform->data->data, 0., realWaveform->data->length*sizeof(REAL4));
441 memset(imagWaveform->data->data, 0., imagWaveform->data->length*sizeof(REAL4));
442 memset(waveform->data->data, 0., waveform->data->length*sizeof(COMPLEX8));
443
444 LAL_CALL(LALInspiralWaveTemplates(&status, realWaveform->data, imagWaveform->data, &newTmplt), &status);
445
446 for (i=0; i< realWaveform->data->length; i++)
447 {
448 waveform->data->data[i] = crectf( realWaveform->data->data[i], imagWaveform->data->data[i] );
449 }
450
451 // FFT complex waveform
452
453 XLALCOMPLEX8TimeFreqFFT(waveformf1, waveform, fwdp);
454
455 // whiten waveform
456
458
459 // normalize waveform
460
461 XLALCCVectorMultiplyConjugate(overlapf->data, waveformf1->data, waveformf1->data);
462 XLALCOMPLEX8FreqTimeFFT(overlapc, overlapf, revp);
463 XLALCOMPLEX8VectorAbs(overlap->data, overlapc->data);
464 norm = 0.;
465 for (i = 0; i < overlap->data->length; i++)
466 {
467 if (overlap->data->data[i] > norm)
468 norm = overlap->data->data[i];
469 }
470 norm = sqrt(norm);
471
472 for (i = 0; i < waveformf1->data->length; i++)
473 {
474 waveformf1->data->data[i] /= norm;
475 }
476
477 // compute overlap with previous tmplts
478
479 tmpWvTmpltPr = headWvTmpltPr;
480 match = 0.;
481 while (tmpWvTmpltPr)
482 {
483 waveformf2 = tmpWvTmpltPr->waveformf;
484 XLALCCVectorMultiplyConjugate(overlapf->data, waveformf1->data, waveformf2->data);
485 XLALCOMPLEX8FreqTimeFFT(overlapc, overlapf, revp);
486 XLALCOMPLEX8VectorAbs(overlap->data, overlapc->data);
487 match = 0.;
488 for (i = 0; i < overlap->data->length; i++)
489 {
490 if (overlap->data->data[i] > match)
491 match = overlap->data->data[i];
492 }
493
494 if (match > minMatch)
495 break;
496 tmpWvTmpltPr = tmpWvTmpltPr->next;
497 }
498
499 if (match > minMatch)
500 continue;
501
502 // save waveform in tmplt list
503
504 if ( ! templateBank )
505 {
506 thisTmplt = templateBank =
508 }
509 else
510 {
511 thisTmplt = thisTmplt->next =
513 }
514
515 thisTmplt->mass1 = newTmplt.mass1;
516 thisTmplt->mass2 = newTmplt.mass2;
517 thisTmplt->mchirp = newTmplt.chirpMass;
518 thisTmplt->eta = newTmplt.eta;
519 thisTmplt->tau0 = newTmplt.t0;
520 thisTmplt->tau2 = newTmplt.t2;
521 thisTmplt->tau3 = newTmplt.t3;
522 thisTmplt->tau4 = newTmplt.t4;
523 thisTmplt->tau5 = newTmplt.t5;
524 thisTmplt->ttotal = newTmplt.tC;
525 thisTmplt->psi0 = newTmplt.psi0;
526 thisTmplt->psi3 = newTmplt.psi3;
527 thisTmplt->f_final = newTmplt.fFinal;
528 thisTmplt->eta = newTmplt.eta;
529 thisTmplt->beta = newTmplt.beta;
530 snprintf( thisTmplt->ifo, LIGOMETA_IFO_MAX, "P1" );
531 snprintf( thisTmplt->search, LIGOMETA_SEARCH_MAX, "stochasticbank" );
532 snprintf( thisTmplt->channel, LIGOMETA_CHANNEL_MAX, "SIM-BANK" );
533
534 if (thisWvTmpltPr == NULL)
535 thisWvTmpltPr = (TemplateWaveformPairs *) LALCalloc(1, sizeof(TemplateWaveformPairs));
536 else
537 {
538 thisWvTmpltPr->next = (TemplateWaveformPairs *) LALCalloc(1, sizeof(TemplateWaveformPairs));
539 thisWvTmpltPr = thisWvTmpltPr->next;
540 }
541 thisWvTmpltPr->sngl_inspiral = thisTmplt;
542 thisWvTmpltPr->waveformf = waveformf1;
543 if (headWvTmpltPr == NULL)
544 headWvTmpltPr = thisWvTmpltPr;
545
546 waveformf1 = XLALCreateCOMPLEX8FrequencySeries("", &tc, 0.0, df, &lalSecondUnit, N);
547
548 numTmplts++;
549 lastTmplt = 0;
550 }
551 fprintf(stderr, "\r%i %i %i\n", trynum, numTmplts, lastTmplt);
552
553 /*
554 *
555 * write the output data
556 *
557 */
558
559 /* open the output xml file */
560 if ( userTag && !outCompress )
561 {
562 snprintf( fname, sizeof(fname), "P1-TMPLTBANK_%s-%d-%d.xml",
565 }
566 else if ( userTag && outCompress )
567 {
568 snprintf( fname, sizeof(fname), "P1-TMPLTBANK_%s-%d-%d.xml.gz",
571 }
572 else if ( !userTag && outCompress )
573 {
574 snprintf( fname, sizeof(fname), "P1-TMPLTBANK-%d-%d.xml.gz",
577 }
578 else
579 {
580 snprintf( fname, sizeof(fname), "P1-TMPLTBANK-%d-%d.xml",
583 }
584 results = XLALOpenLIGOLwXMLFile( fname );
585
586 /* write the process table */
587 snprintf( proctable->ifos, LIGOMETA_IFO_MAX, "P1" );
588 XLALGPSTimeNow(&(proctable->end_time));
589 XLALWriteLIGOLwXMLProcessTable( results, proctable );
590 free( proctable );
591
592 /* erase the first empty process params entry */
593 {
594 ProcessParamsTable *emptyPPtable = procparams;
595 procparams = procparams->next;
596 free( emptyPPtable );
597 }
598
599 /* write the process params table */
600 XLALWriteLIGOLwXMLProcessParamsTable( results, procparams );
601 XLALDestroyProcessParamsTable( procparams );
602
603 /* write the template bank to the file */
604 if ( templateBank )
605 XLALWriteLIGOLwXMLSnglInspiralTable( results, templateBank );
606
607 while ( templateBank )
608 {
609 thisTmplt = templateBank;
610 templateBank = templateBank->next;
611 LALFree( thisTmplt );
612 }
613
614 /* close the output xml file */
615 XLALCloseLIGOLwXMLFile( results );
616
617 /* free the rest of the memory, check for memory leaks and exit */
618
620
621 while (headWvTmpltPr)
622 {
623 thisWvTmpltPr = headWvTmpltPr;
624 headWvTmpltPr = headWvTmpltPr->next;
626 LALFree(thisWvTmpltPr);
627 }
628
631 XLALDestroyREAL4TimeSeries(realWaveform);
632 XLALDestroyREAL4TimeSeries(imagWaveform);
640 exit( 0 );
641}
642
643
644/* ------------------------------------------------------------------------- */
645
646#define ADD_PROCESS_PARAM( pptype, format, ppvalue ) \
647this_proc_param = this_proc_param->next = (ProcessParamsTable *) \
648 calloc( 1, sizeof(ProcessParamsTable) ); \
649 snprintf( this_proc_param->program, LIGOMETA_PROGRAM_MAX, "%s", \
650 PROGRAM_NAME ); \
651 snprintf( this_proc_param->param, LIGOMETA_PARAM_MAX, "--%s", \
652 long_options[option_index].name ); \
653 snprintf( this_proc_param->type, LIGOMETA_TYPE_MAX, "%s", pptype ); \
654 snprintf( this_proc_param->value, LIGOMETA_VALUE_MAX, format, ppvalue );
655
656#define USAGE \
657" --help display this message\n"\
658" --version print version information and exit\n"\
659" --user-tag STRING set the process_params usertag to STRING\n"\
660"\n"\
661" --gps-start-time SEC GPS second of data start time\n"\
662" --gps-end-time SEC GPS second of data end time\n"\
663" --low-frequency-cutoff F Compute tau parameters from F Hz\n"\
664" --minimum-mass MASS set minimum component mass of bank to MASS\n"\
665" --maximum-mass MASS set maximum component mass of bank to MASS\n"\
666" --tries-factor N test a factor N more points than templates retained\n"\
667" --random-seed SEED set random number seed for injections to SEED\n"\
668 " (urandom|integer)\n"\
669" --write-compress write a compressed xml file\n"\
670 "\n"
671
672int arg_parse_check( int argc, char *argv[], ProcessParamsTable *procparams )
673{
674 /* LALgetopt arguments */
675 struct LALoption long_options[] =
676 {
677 /* these options set a flag */
678 {"verbose", no_argument, &vrbflg, 1 },
679 {"write-compress", no_argument, &outCompress, 1 },
680 {"help", no_argument, 0, 'h'},
681 {"gps-start-time", required_argument, 0, 's'},
682 {"gps-end-time", required_argument, 0, 'e'},
683 {"low-frequency-cutoff", required_argument, 0, 'f'},
684 {"high-frequency-cutoff", required_argument, 0, 'F'},
685 {"minimum-mass", required_argument, 0, 'a'},
686 {"maximum-mass", required_argument, 0, 'A'},
687 {"minimum-mtotal", required_argument, 0, 'b'},
688 {"maximum-mtotal", required_argument, 0, 'B'},
689 {"minimum-mchirp", required_argument, 0, 'c'},
690 {"maximum-mchirp", required_argument, 0, 'C'},
691 {"tries-factor", required_argument, 0, 'N'},
692 {"minimal-match", required_argument, 0, 'm'},
693 {"psd-file", required_argument, 0, 'P'},
694 {"random-seed", required_argument, 0, 'S'},
695 {"user-tag", required_argument, 0, 'Z'},
696 {"userTag", required_argument, 0, 'Z'},
697 {0, 0, 0, 0}
698 };
699 int c;
700 ProcessParamsTable *this_proc_param = procparams;
701
702
703 /*
704 *
705 * parse command line arguments
706 *
707 */
708
709
710 while ( 1 )
711 {
712 /* LALgetopt_long stores long option here */
713 int option_index = 0;
714 size_t LALoptarg_len;
715
716 c = LALgetopt_long_only( argc, argv, "ha:b:c:e:m:s:A:B:C:N:P:S:Z:",
717 long_options, &option_index );
718
719 /* detect the end of the options */
720 if ( c == - 1 )
721 {
722 break;
723 }
724
725 switch ( c )
726 {
727 case 0:
728 /* if this option set a flag, do nothing else now */
729 if ( long_options[option_index].flag != 0 )
730 {
731 break;
732 }
733 else
734 {
735 fprintf( stderr, "error parsing option %s with argument %s\n",
736 long_options[option_index].name, LALoptarg );
737 exit( 1 );
738 }
739 break;
740
741 case 'h':
742 fprintf( stdout, USAGE );
743 exit( 0 );
744 break;
745
746 case 'Z':
747 /* create storage for the usertag */
748 LALoptarg_len = strlen( LALoptarg ) + 1;
749 userTag = (CHAR *) calloc( LALoptarg_len, sizeof(CHAR) );
750 memcpy( userTag, LALoptarg, LALoptarg_len );
751
752 this_proc_param = this_proc_param->next = (ProcessParamsTable *)
753 calloc( 1, sizeof(ProcessParamsTable) );
754 snprintf( this_proc_param->program, LIGOMETA_PROGRAM_MAX, "%s",
755 PROGRAM_NAME );
756 snprintf( this_proc_param->param, LIGOMETA_PARAM_MAX, "--userTag" );
757 snprintf( this_proc_param->type, LIGOMETA_TYPE_MAX, "string" );
758 snprintf( this_proc_param->value, LIGOMETA_VALUE_MAX, "%s",
759 LALoptarg );
760 break;
761
762 case 'P':
763 /* create storage for the psd file name */
764 LALoptarg_len = strlen( LALoptarg ) + 1;
765 psdFileName = (CHAR *) calloc( LALoptarg_len, sizeof(CHAR) );
766 memcpy( psdFileName, LALoptarg, LALoptarg_len );
767 ADD_PROCESS_PARAM( "string", "%s", psdFileName );
768 break;
769
770 case 'a':
771 minMass = (REAL4) atof( LALoptarg );
772 if ( minMass <= 0 )
773 {
774 fprintf( stdout, "invalid argument to --%s:\n"
775 "miniumum component mass must be > 0: "
776 "(%f solar masses specified)\n",
777 long_options[option_index].name, minMass );
778 exit( 1 );
779 }
780 ADD_PROCESS_PARAM( "float", "%e", minMass );
781 break;
782
783 case 'A':
784 maxMass = (REAL4) atof( LALoptarg );
785 if ( maxMass <= 0 )
786 {
787 fprintf( stdout, "invalid argument to --%s:\n"
788 "maxiumum component mass must be > 0: "
789 "(%f solar masses specified)\n",
790 long_options[option_index].name, maxMass );
791 exit( 1 );
792 }
793 ADD_PROCESS_PARAM( "float", "%e", maxMass );
794 break;
795
796 case 'b':
797 minMTotal = (REAL4) atof( LALoptarg );
798 if ( minMTotal <= 0 )
799 {
800 fprintf( stdout, "invalid argument to --%s:\n"
801 "miniumum total mass must be > 0: "
802 "(%f solar masses specified)\n",
803 long_options[option_index].name, minMTotal );
804 exit( 1 );
805 }
806 ADD_PROCESS_PARAM( "float", "%e", minMTotal );
807 break;
808
809 case 'B':
810 maxMTotal = (REAL4) atof( LALoptarg );
811 if ( maxMTotal <= 0 )
812 {
813 fprintf( stdout, "invalid argument to --%s:\n"
814 "maxiumum total mass must be > 0: "
815 "(%f solar masses specified)\n",
816 long_options[option_index].name, maxMTotal );
817 exit( 1 );
818 }
819 ADD_PROCESS_PARAM( "float", "%e", maxMTotal );
820 break;
821
822 case 'c':
823 minMChirp = (REAL4) atof( LALoptarg );
824 if ( minMChirp <= 0 )
825 {
826 fprintf( stdout, "invalid argument to --%s:\n"
827 "miniumum chirp mass must be > 0: "
828 "(%f solar masses specified)\n",
829 long_options[option_index].name, minMChirp );
830 exit( 1 );
831 }
832 ADD_PROCESS_PARAM( "float", "%e", minMChirp );
833 break;
834
835 case 'C':
836 maxMChirp = (REAL4) atof( LALoptarg );
837 if ( maxMChirp <= 0 )
838 {
839 fprintf( stdout, "invalid argument to --%s:\n"
840 "maxiumum chirp mass must be > 0: "
841 "(%f solar masses specified)\n",
842 long_options[option_index].name, maxMChirp );
843 exit( 1 );
844 }
845 ADD_PROCESS_PARAM( "float", "%e", maxMChirp );
846 break;
847
848 case 'f':
849 fLo = (REAL4) atof( LALoptarg );
850 if ( fLo <= 0 )
851 {
852 fprintf( stdout, "invalid argument to --%s:\n"
853 "lower frequency cutoff must be > 0: "
854 "(%f Hz specified)\n",
855 long_options[option_index].name, fLo );
856 exit( 1 );
857 }
858 ADD_PROCESS_PARAM( "float", "%e", fLo );
859 break;
860
861 case 'F':
862 fHi = (REAL4) atof( LALoptarg );
863 if ( fHi <= 0 )
864 {
865 fprintf( stdout, "invalid argument to --%s:\n"
866 "upper frequency cutoff must be > 0: "
867 "(%f Hz specified)\n",
868 long_options[option_index].name, fHi );
869 exit( 1 );
870 }
871 ADD_PROCESS_PARAM( "float", "%e", fHi );
872 break;
873
874 case 'J':
875 if ( ! strcmp( "urandom", LALoptarg ) )
876 {
878 ADD_PROCESS_PARAM( "string", "%s", LALoptarg );
879 }
880 else
881 {
883 randomSeed = (INT4) atoi( LALoptarg );
884 ADD_PROCESS_PARAM( "int", "%d", randomSeed );
885 }
886 break;
887
888 case 'N':
889 facTries = (INT4) atoi( LALoptarg );
890 if ( facTries < 1 )
891 {
892 fprintf( stderr, "invalid argument to --%s:\n"
893 "ratio of test points to templates"
894 "must be greater than 1: (%d specified)\n",
895 long_options[option_index].name, facTries );
896 exit( 1 );
897 }
898 ADD_PROCESS_PARAM( "int", "%d", facTries );
899 break;
900
901 case 'm':
902 minMatch = (REAL4) atof( LALoptarg );
903 if ( minMatch < 0 || minMatch >= 1 )
904 {
905 fprintf( stderr, "invalid argument to --%s:\n"
906 "minimal match of the template bank"
907 "must be in [0,1): (%f specified)\n",
908 long_options[option_index].name, minMatch );
909 exit( 1 );
910 }
911 ADD_PROCESS_PARAM( "float", "%f", minMatch );
912 break;
913
914 case 's':
915 {
916 long int gstartt = atol( LALoptarg );
917 if ( gstartt < 441417609 )
918 {
919 fprintf( stderr, "invalid argument to --%s:\n"
920 "GPS start time is prior to "
921 "Jan 01, 1994 00:00:00 UTC:\n"
922 "(%ld specified)\n",
923 long_options[option_index].name, gstartt );
924 exit( 1 );
925 }
926 if ( gstartt > 999999999 )
927 {
928 fprintf( stderr, "invalid argument to --%s:\n"
929 "GPS start time is after "
930 "Sep 14, 2011 01:46:26 UTC:\n"
931 "(%ld specified)\n",
932 long_options[option_index].name, gstartt );
933 exit( 1 );
934 }
935 gpsStartTime.gpsSeconds = (INT4) gstartt;
937 ADD_PROCESS_PARAM( "int", "%ld", gstartt );
938 }
939 break;
940
941 case 'e':
942 {
943 long int gendt = atol( LALoptarg );
944 if ( gendt > 999999999 )
945 {
946 fprintf( stderr, "invalid argument to --%s:\n"
947 "GPS end time is after "
948 "Sep 14, 2011 01:46:26 UTC:\n"
949 "(%ld specified)\n",
950 long_options[option_index].name, gendt );
951 exit( 1 );
952 }
953 else if ( gendt < 441417609 )
954 {
955 fprintf( stderr, "invalid argument to --%s:\n"
956 "GPS end time is prior to "
957 "Jan 01, 1994 00:00:00 UTC:\n"
958 "(%ld specified)\n",
959 long_options[option_index].name, gendt );
960 exit( 1 );
961 }
962 gpsEndTime.gpsSeconds = (INT4) gendt;
964 ADD_PROCESS_PARAM( "int", "%ld", gendt );
965 }
966 break;
967
968 case '?':
969 fprintf( stderr, USAGE );
970 exit( 1 );
971 break;
972
973 default:
974 fprintf( stderr, "unknown error while parsing options\n" );
975 fprintf( stderr, USAGE );
976 exit( 1 );
977 }
978 }
979
980 if ( LALoptind < argc )
981 {
982 fprintf( stderr, "extraneous command line arguments:\n" );
983 while ( LALoptind < argc )
984 {
985 fprintf ( stderr, "%s\n", argv[LALoptind++] );
986 }
987 exit( 1 );
988 }
989
990 /*
991 *
992 * check validity of arguments
993 *
994 */
995
996
997 if ( minMass < 0 )
998 {
999 fprintf( stderr, "--minimum-mass must be specified\n" );
1000 exit( 1 );
1001 }
1002 if ( maxMass < 0 )
1003 {
1004 fprintf( stderr, "--maximum-mass must be specified\n" );
1005 exit( 1 );
1006 }
1007
1008 if ( minMTotal < 0 )
1009 {
1010 fprintf( stderr, "--minimum-mtotal must be specified\n" );
1011 exit( 1 );
1012 }
1013 if ( maxMTotal < 0 )
1014 {
1015 fprintf( stderr, "--maximum-mtotal must be specified\n" );
1016 exit( 1 );
1017 }
1018
1019 if ( minMChirp < 0 )
1020 {
1021 fprintf( stderr, "--minimum-mchirp must be specified\n" );
1022 exit( 1 );
1023 }
1024 if ( maxMChirp < 0 )
1025 {
1026 fprintf( stderr, "--maximum-mchirp must be specified\n" );
1027 exit( 1 );
1028 }
1029
1030 if ( fLo < 0 )
1031 {
1032 fprintf( stderr, "--low-frequency-cutoff must be specified\n" );
1033 exit( 1 );
1034 }
1035 if ( fHi < 0 )
1036 {
1037 fprintf( stderr, "--high-frequency-cutoff must be specified\n" );
1038 exit( 1 );
1039 }
1040
1041 /* check that the bank parameters have been specified */
1042 if ( facTries < 0 )
1043 {
1044 fprintf( stderr, "--tries-factor must be specified\n" );
1045 exit( 1 );
1046 }
1047
1048 return 0;
1049}
1050
1051#undef ADD_PROCESS_PARAM
const LALVCSInfo lalAppsVCSIdentInfo
Identable VCS and build information for LALApps.
lal_errhandler_t lal_errhandler
int LAL_ERR_EXIT(LALStatus *stat, const char *func, const char *file, const int line, volatile const char *id)
#define LAL_CALL(function, statusptr)
int j
void LALInspiralWaveTemplates(LALStatus *status, REAL4Vector *filter1, REAL4Vector *filter2, InspiralTemplate *params)
void LALInspiralParameterCalc(LALStatus *status, InspiralTemplate *params)
void LALCheckMemoryLeaks(void)
#define LALCalloc(m, n)
#define LALFree(p)
int LALgetopt_long_only(int argc, char *const *argv, const char *options, const struct LALoption *long_options, int *opt_index)
int LALoptind
char * LALoptarg
#define no_argument
#define required_argument
int XLALCloseLIGOLwXMLFile(LIGOLwXMLStream *xml)
LIGOLwXMLStream * XLALOpenLIGOLwXMLFile(const char *path)
int XLALWriteLIGOLwXMLProcessTable(LIGOLwXMLStream *, const ProcessTable *)
int XLALWriteLIGOLwXMLProcessParamsTable(LIGOLwXMLStream *, const ProcessParamsTable *)
int XLALWriteLIGOLwXMLSnglInspiralTable(LIGOLwXMLStream *xml, const SnglInspiralTable *sngl_inspiral)
#define LIGOMETA_SEARCH_MAX
#define LIGOMETA_TYPE_MAX
#define LIGOMETA_CHANNEL_MAX
#define LIGOMETA_PROGRAM_MAX
#define LIGOMETA_VALUE_MAX
#define LIGOMETA_PARAM_MAX
#define LIGOMETA_IFO_MAX
void XLALDestroyProcessParamsTable(ProcessParamsTable *)
int XLALPopulateProcessTable(ProcessTable *ptable, const char *program_name, const char *cvs_revision, const char *cvs_source, const char *cvs_date, long process_id)
REAL8 tmp1
#define fprintf
double e
COMPLEX8FFTPlan * XLALCreateReverseCOMPLEX8FFTPlan(UINT4 size, int measurelvl)
COMPLEX8FFTPlan * XLALCreateForwardCOMPLEX8FFTPlan(UINT4 size, int measurelvl)
void XLALDestroyCOMPLEX8FFTPlan(COMPLEX8FFTPlan *plan)
LIGOTimeGPS * XLALGPSTimeNow(LIGOTimeGPS *gpstime)
REAL8FrequencySeries * XLALCreateREAL8FrequencySeries(const CHAR *name, const LIGOTimeGPS *epoch, REAL8 f0, REAL8 deltaF, const LALUnit *sampleUnits, size_t length)
void XLALDestroyCOMPLEX8FrequencySeries(COMPLEX8FrequencySeries *series)
REAL4FrequencySeries * XLALCreateREAL4FrequencySeries(const CHAR *name, const LIGOTimeGPS *epoch, REAL8 f0, REAL8 deltaF, const LALUnit *sampleUnits, size_t length)
COMPLEX8FrequencySeries * XLALCreateCOMPLEX8FrequencySeries(const CHAR *name, const LIGOTimeGPS *epoch, REAL8 f0, REAL8 deltaF, const LALUnit *sampleUnits, size_t length)
void XLALDestroyREAL4FrequencySeries(REAL4FrequencySeries *series)
void XLALDestroyREAL8FrequencySeries(REAL8FrequencySeries *series)
REAL8 XLALREAL8PolynomialInterpolation(REAL8 *yout, REAL8 xtarget, REAL8 *y, REAL8 *x, UINT4 n)
#define LIGOTIMEGPSZERO
double REAL8
#define XLAL_INIT_DECL(var,...)
#define crectf(re, im)
char CHAR
uint32_t UINT4
float complex COMPLEX8
int32_t INT4
float REAL4
m1Andm2
TaylorT1
LAL_PNORDER_TWO
LAL_PNORDER_THREE_POINT_FIVE
LAL_PNORDER_NEWTONIAN
static const INT4 m
static const INT4 q
void LALCreateRandomParams(LALStatus *status, RandomParams **params, INT4 seed)
REAL4 XLALUniformDeviate(RandomParams *params)
void LALDestroyRandomParams(LALStatus *status, RandomParams **params)
COMPLEX8FrequencySeries * XLALWhitenCOMPLEX8FrequencySeries(COMPLEX8FrequencySeries *fseries, const REAL4FrequencySeries *psd)
int XLALCOMPLEX8FreqTimeFFT(COMPLEX8TimeSeries *tser, const COMPLEX8FrequencySeries *freq, const COMPLEX8FFTPlan *plan)
int XLALCOMPLEX8TimeFreqFFT(COMPLEX8FrequencySeries *freq, const COMPLEX8TimeSeries *tser, const COMPLEX8FFTPlan *plan)
REAL4TimeSeries * XLALCreateREAL4TimeSeries(const CHAR *name, const LIGOTimeGPS *epoch, REAL8 f0, REAL8 deltaT, const LALUnit *sampleUnits, size_t length)
COMPLEX8TimeSeries * XLALCreateCOMPLEX8TimeSeries(const CHAR *name, const LIGOTimeGPS *epoch, REAL8 f0, REAL8 deltaT, const LALUnit *sampleUnits, size_t length)
void XLALDestroyCOMPLEX8TimeSeries(COMPLEX8TimeSeries *series)
void XLALDestroyREAL4TimeSeries(REAL4TimeSeries *series)
const LALUnit lalSecondUnit
const LALUnit lalDimensionlessUnit
COMPLEX8Vector * XLALCCVectorMultiplyConjugate(COMPLEX8Vector *out, const COMPLEX8Vector *in1, const COMPLEX8Vector *in2)
int XLALCOMPLEX8VectorAbs(REAL4Vector *out, const COMPLEX8Vector *in)
void XLALAbortErrorHandler(const char *func, const char *file, int line, int errnum)
XLALErrorHandlerType * XLALSetErrorHandler(XLALErrorHandlerType *newHandler)
#define XLAL_IS_REAL4_FAIL_NAN(val)
REAL8 norm
Definition: inspinj.c:572
char name[LIGOMETA_SOURCE_MAX]
Definition: inspinj.c:561
static LALStatus status
Definition: inspinj.c:552
int i
Definition: inspinj.c:596
M
eta
m2
m1
waveform
c
psd
fHigh
string line
f0
f1
int N
float atol
REAL4 fLow
Definition: randombank.c:83
INT4 numTmplts
Definition: randombank.c:84
RandomParams * randParams
Definition: spininj.c:212
CHAR fname[256]
Definition: spininj.c:211
int main(int argc, char *argv[])
REAL4 fHi
#define PROGRAM_NAME
REAL4 minMatch
REAL4 fLo
#define USAGE
REAL4 ceil_pow_2(REAL4 x)
REAL4 maxMChirp
INT4 outCompress
@ user
@ urandom
@ unset
#define ADD_PROCESS_PARAM(pptype, format, ppvalue)
REAL4 minMass
INT4 facTries
LIGOTimeGPS gpsStartTime
CHAR * psdFileName
REAL4 maxMTotal
int vrbflg
defined in lal/lib/std/LALError.c
LIGOTimeGPS tc
enum @6 randSeedType
REAL4 minMChirp
REAL4 maxMass
REAL4 minMTotal
INT4 randomSeed
REAL4FrequencySeries * readPSD(const char *fname, REAL4 fNyq, REAL4 df, UINT4 N, REAL4 fLow, REAL4 fHigh)
LIGOTimeGPS gpsEndTime
CHAR * userTag
REAL4 max_mass_ratio(REAL4 mchirp, REAL4 m, REAL4 M)
int arg_parse_check(int argc, char *argv[], ProcessParamsTable *procparams)
COMPLEX8Sequence * data
COMPLEX8Sequence * data
COMPLEX8 * data
Approximant approximant
LALPNOrder ampOrder
LALPNOrder order
InputMasses massChoice
const char *const vcsDate
const char *const vcsStatus
const char *const vcsId
int * flag
INT4 gpsNanoSeconds
CHAR type[LIGOMETA_TYPE_MAX]
CHAR param[LIGOMETA_PARAM_MAX]
CHAR value[LIGOMETA_VALUE_MAX]
struct tagProcessParamsTable * next
CHAR program[LIGOMETA_PROGRAM_MAX]
LIGOTimeGPS start_time
CHAR ifos[LIGOMETA_IFOS_MAX]
LIGOTimeGPS end_time
REAL4Sequence * data
REAL4 * data
REAL8Sequence * data
REAL8 * data
CHAR ifo[LIGOMETA_IFO_MAX]
struct tagSnglInspiralTable * next
CHAR channel[LIGOMETA_CHANNEL_MAX]
CHAR search[LIGOMETA_SEARCH_MAX]
struct tagTemplateWaveformPairs * next
SnglInspiralTable * sngl_inspiral
COMPLEX8FrequencySeries * waveformf
FILE * fp
double df