Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALSimulation 6.2.0.1-3a66518
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
unicorn.c
Go to the documentation of this file.
1#include <math.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5
6#include <gsl/gsl_rng.h>
7
8#include <lal/LALStdlib.h>
9#include <lal/LALgetopt.h>
10#include <lal/LALConstants.h>
11#include <lal/LALDetectors.h>
12#include <lal/LALSimulation.h>
13#include <lal/TimeSeries.h>
14#include <lal/Date.h>
15#include <lal/Audio.h>
16#include <lal/LALSimBurst.h>
17
18/* global variables for parameters (with default values) */
21double hrss = 1.0;
22double f_min;
23double f_max;
24double deltaT = 1.0/16384.0;
25double V = 1.0;
26char output[FILENAME_MAX];
27
28int usage(const char *program);
29int parseargs(int argc, char **argv);
30int fprintgps(FILE *fp, const LIGOTimeGPS *t);
31
32#define CAT(a,b) a ## b
33#define FLT(i) CAT(i,.)
34#define HMS2RAD(h,m,s) (LAL_PI * ((h) + ((m) + (s) / 60.) / 60.) / 12.0)
35#define DMS2RAD(d,m,s) ((signbit(FLT(d)) ? -LAL_PI : LAL_PI) * (abs(d) + ((m) + (s) / 60.) / 60.) / 180.0)
36
37int main(int argc, char *argv[])
38{
39 /*
40 * RA and DEC are centered on Mon R2 IRS 3
41 * See: J. Giannakopoulou et al. 1997 ApJ 487 346 doi:10.1086/304574
42 */
43 double ra = HMS2RAD( 6, 7, 47.8);
44 double dec = DMS2RAD(-6, 22, 55);
45 double psi = 0.0;
46 REAL8TimeSeries *h, *hplus, *hcross;
47 gsl_rng *rng;
48 FILE *fp = stdout;
49
50 /* XLALSetErrorHandler(XLALBacktraceErrorHandler); */
52
53 parseargs(argc, argv);
54
55 gsl_rng_env_setup();
56 rng = gsl_rng_alloc(gsl_rng_default);
57
58 XLALSimUnicorn(&hplus, &hcross, f_min, f_max, V, hrss, deltaT, rng);
59 XLALGPSAddGPS(&hplus->epoch, &epoch);
60 XLALGPSAddGPS(&hcross->epoch, &epoch);
61
62 h = XLALSimDetectorStrainREAL8TimeSeries(hplus, hcross, ra, dec, psi, &detector);
63
64 if (*output)
65 fp = fopen(output, "w");
66
67 /* determine type of output from filename */
68 if (*output && 0 == strcmp(strrchr(output, '.'), ".wav"))
70 else if (*output && 0 == strcmp(strrchr(output, '.'), ".au"))
72 else { /* ascii file */
73 size_t j;
74 fprintf(fp, "# time (s)\t%s:STRAIN (strain)\n", detector.frDetector.prefix);
75 for (j = 0; j < h->data->length; ++j) {
76 LIGOTimeGPS t = h->epoch;
77 XLALGPSAdd(&t, j * h->deltaT);
78 fprintgps(fp, &t);
79 fprintf(fp, "\t%.18e\n", h->data->data[j]);
80 }
81 }
82
83 if (*output)
84 fclose(fp);
85
89 gsl_rng_free(rng);
91
92 return 0;
93}
94
95int parseargs(int argc, char **argv)
96{
97 struct LALoption long_options[] = {
98 { "help", no_argument, 0, 'h' },
99 { "detector-site", required_argument, 0, 'd' },
100 { "min-frequency", required_argument, 0, 'f' },
101 { "max-frequency", required_argument, 0, 'F' },
102 { "hrss", required_argument, 0, 'H' },
103 { "output-file", required_argument, 0, 'o' },
104 { "sample-rate", required_argument, 0, 's' },
105 { "gps-start-time", required_argument, 0, 't' },
106 { "time-freq-volume", required_argument, 0, 'V' },
107 { 0, 0, 0, 0 }
108 };
109 char args[] = "hd:f:F:H:o:s:t:V:";
110 while (1) {
111 int option_index = 0;
112 int c;
113
114 c = LALgetopt_long_only(argc, argv, args, long_options, &option_index);
115 if (c == -1) /* end of options */
116 break;
117
118 switch (c) {
119 case 0: /* if option set a flag, nothing else to do */
120 if (long_options[option_index].flag)
121 break;
122 else {
123 fprintf(stderr, "error parsing option %s with argument %s\n", long_options[option_index].name, LALoptarg);
124 exit(1);
125 }
126 case 'h': /* help */
127 usage(argv[0]);
128 exit(0);
129 case 'd': /* detector-site */
130 switch (*LALoptarg) {
131 case 'G':
133 break;
134 case 'H':
136 break;
137 case 'L':
139 break;
140 case 'V':
142 break;
143 default:
144 fprintf(stderr, "unrecognized detector site %s - must be 'G', 'H', 'L' or 'V'\n", LALoptarg);
145 exit(1);
146 }
147 break;
148 case 'f': /* min-frequency */
149 f_min = atof(LALoptarg);
150 break;
151 case 'F': /* max-frequency */
152 f_max = atof(LALoptarg);
153 break;
154 case 'H': /* hrss */
155 hrss = atof(LALoptarg);
156 break;
157 case 'o': /* output-file */
158 strncpy(output, LALoptarg, sizeof(output) - 1);
159 break;
160 case 's': /* sample-rate */
161 deltaT = 1.0 / atof(LALoptarg);
162 break;
163 case 't': /* gps-start-time */
165 break;
166 case 'V': /* time-freq-volume */
167 V = atof(LALoptarg);
168 break;
169 case '?':
170 default:
171 fprintf(stderr, "unknown error while parsing options\n");
172 exit(1);
173 }
174 }
175
176 if (LALoptind < argc) {
177 fprintf(stderr, "extraneous command line arguments:\n");
178 while (LALoptind < argc)
179 fprintf(stderr, "%s\n", argv[LALoptind++]);
180 exit(1);
181 }
182
183 if (V < LAL_2_PI) {
184 fprintf(stderr, "error: time-frequency volume must be at least 2/pi\n");
185 usage(argv[0]);
186 exit(1);
187 }
188
189 if (strlen(detector.frDetector.prefix) == 0) {
190 fprintf(stderr, "error: must specify a detector site\n");
191 usage(argv[0]);
192 exit(1);
193 }
194
195 if (f_max == 0.0) /* default value: Nyquist */
196 f_max = 0.5 / deltaT;
197 else if (f_max < f_min) {
198 fprintf(stderr, "error: the maximum frequency must be greater than the minimum frequency\n");
199 usage(argv[0]);
200 exit(1);
201 }
202 else if (f_max > 0.5 / deltaT) {
203 fprintf(stderr, "error: the maximum frequency must be less than the Nyquist frequency\n");
204 usage(argv[0]);
205 exit(1);
206 }
207
208 return 0;
209}
210
211int usage( const char *program )
212{
213 fprintf(stderr, "usage: %s [options]\n", program);
214 fprintf(stderr, "options:\n" );
215 fprintf(stderr, "\t-h, --help \tprint this message and exit\n");
216 fprintf(stderr, "\t-d detectorSite\t(required) detector site (G|H|L|V)\n");
217 fprintf(stderr, "\t-f minFrequency\t(default=0) minimum frequency (Hz)\n");
218 fprintf(stderr, "\t-F maxFrequency\t(default=Nyquist) maximum frequency (Hz)\n");
219 fprintf(stderr, "\t-H hrss \t(default=1) root-sum-squared strain hrss (s)\n");
220 fprintf(stderr, "\t-o outfile \t(default=stdout) output filename\n");
221 fprintf(stderr, "\t-s sampleRate \t(default=16384) sample rate (Hz)\n");
222 fprintf(stderr, "\t-t GPSStartTime\t(default=0) start time relative to GPS epoch (s)\n");
223 fprintf(stderr, "\t-V TimeFreqVol \t(default=1) pixel time-frequency volume\n");
224 fprintf(stderr, "environment:\n" );
225 fprintf(stderr, "\tGSL_RNG_SEED \trandom number generator seed\n");
226 fprintf(stderr, "\tGSL_RNG_TYPE \trandom number generator type\n");
227 return 0;
228}
229
230int fprintgps(FILE *fp, const LIGOTimeGPS *t)
231{
232 char *s = XLALGPSToStr(NULL, t);
233 int result = fprintf(fp, "%s", s);
234 free(s);
235 return result;
236}
void LALCheckMemoryLeaks(void)
#define c
const char * name
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
#define fprintf
int s
Definition: bh_qnmode.c:137
int XLALAudioAURecordREAL8TimeSeries(FILE *fp, REAL8TimeSeries *series)
int XLALAudioWAVRecordREAL8TimeSeries(FILE *fp, REAL8TimeSeries *series)
const LALDetector lalCachedDetectors[LAL_NUM_DETECTORS]
char * XLALGPSToStr(char *s, const LIGOTimeGPS *t)
#define LAL_2_PI
LAL_LLO_4K_DETECTOR
LAL_VIRGO_DETECTOR
LAL_GEO_600_DETECTOR
LAL_LHO_4K_DETECTOR
int XLALSimUnicorn(REAL8TimeSeries **hplus, REAL8TimeSeries **hcross, double f_min, double f_max, double V, double hrss, double deltaT, gsl_rng *rng)
Generates a time-frequency unicorn signal.
REAL8TimeSeries * XLALSimDetectorStrainREAL8TimeSeries(const REAL8TimeSeries *hplus, const REAL8TimeSeries *hcross, REAL8 right_ascension, REAL8 declination, REAL8 psi, const LALDetector *detector)
Transforms the waveform polarizations into a detector strain.
void XLALDestroyREAL8TimeSeries(REAL8TimeSeries *series)
void XLALAbortErrorHandler(const char *func, const char *file, int line, int errnum)
XLALErrorHandlerType * XLALSetErrorHandler(XLALErrorHandlerType *newHandler)
LIGOTimeGPS * XLALGPSSetREAL8(LIGOTimeGPS *epoch, REAL8 t)
LIGOTimeGPS * XLALGPSAdd(LIGOTimeGPS *epoch, REAL8 dt)
LIGOTimeGPS * XLALGPSAddGPS(LIGOTimeGPS *epoch, const LIGOTimeGPS *dt)
char * program
Definition: inject.c:87
LALFrDetector frDetector
CHAR prefix[3]
int * flag
REAL8Sequence * data
LIGOTimeGPS epoch
REAL8 * data
FILE * fp
int main(int argc, char *argv[])
Definition: unicorn.c:37
LIGOTimeGPS epoch
Definition: unicorn.c:20
double V
Definition: unicorn.c:25
int fprintgps(FILE *fp, const LIGOTimeGPS *t)
Definition: unicorn.c:230
double hrss
Definition: unicorn.c:21
int usage(const char *program)
Definition: unicorn.c:211
int parseargs(int argc, char **argv)
Definition: unicorn.c:95
char output[FILENAME_MAX]
Definition: unicorn.c:26
double f_min
Definition: unicorn.c:22
double deltaT
Definition: unicorn.c:24
LALDetector detector
Definition: unicorn.c:19
#define HMS2RAD(h, m, s)
Definition: unicorn.c:34
#define DMS2RAD(d, m, s)
Definition: unicorn.c:35
double f_max
Definition: unicorn.c:23