LALApps 10.1.1.1-bf6a62b
AddFrame.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2010 Florent Robinet
3* robinet@lal.in2p3.fr
4*/
5
6#include <stdio.h>
7#include <stdlib.h>
8
9#include <lal/LALFrameIO.h>
10#include <lal/LALCache.h>
11#include <lal/LALFrStream.h>
12#include <lal/LALConstants.h>
13#include <lal/Date.h>
14#include <lal/Units.h>
15#include <lal/TimeSeries.h>
16
17int Min(int a, int b);
18/***************************************************************************/
19
20int main(int argc,char *argv[])
21{
22 LALFrameH *frame; /* output frame */
23 char filename[256]; /* output file name */
24
25 REAL8TimeSeries *ht_1; /* H1 strain data */
26 REAL8TimeSeries *ht_2; /* H2 strain data */
27 REAL8TimeSeries *ht_m; /* H- strain data */
28
29 char cache_name_1[256]; /* H1 frame cache name */
30 char cache_name_2[256]; /* H2 frame cache name */
31 LALCache *cache_1; /* H1 frame cache */
32 LALCache *cache_2; /* H2 frame cache */
33 LALFrStream *stream_1; /* H1 stream */
34 LALFrStream *stream_2; /* H2 stream */
35
36 int i, p, gps_start_i, gps_end_i, start, end;
37 LIGOTimeGPS gps_start, gps_end;
38
39 cache_name_1[0]='\0';
40 cache_name_2[0]='\0';
41 filename[0]='\0';
42 ht_1=NULL;
43 ht_2=NULL;
44
45 /* read arguments */
46 if(argc!=4){
47 printf("%s(): usage: lalapps_StringAddFrame [gps_start] [gps_end] [outdir]\n",__func__);
48 printf(" There should be the H1 and H2 cache files ready in [outdir] named H1.cache and H2.cache\n");
49 return 1;
50 }
51 gps_start_i=atoi(argv[1]);
52 gps_end_i=atoi(argv[2]);
53 sprintf(cache_name_1,"%s/H1.cache", argv[3]);
54 sprintf(cache_name_2,"%s/H2.cache", argv[3]);
55
56 /* create Frame cache, open frame stream and delete frame cache */
57 cache_1 = XLALCacheImport(cache_name_1);
58 if(!cache_1){
59 printf("%s(): no cache named %s\n",__func__,cache_name_1);
60 return 2;
61 }
62 stream_1 = XLALFrStreamCacheOpen(cache_1);
63 XLALDestroyCache(cache_1);
64 if(!stream_1){
65 printf("%s(): no stream for H1\n",__func__);
66 return 2;
67 }
68 if(!stream_1) XLAL_ERROR(XLAL_EFUNC);
69
70 cache_2 = XLALCacheImport(cache_name_2);
71 if(!cache_2){
72 printf("%s(): no cache named %s\n",__func__,cache_name_2);
73 return 3;
74 }
75 stream_2 = XLALFrStreamCacheOpen(cache_2);
76 XLALDestroyCache(cache_2);
77 if(!stream_2){
78 printf("%s(): no stream for H2\n",__func__);
79 return 3;
80 }
81
82 /* turn on checking for missing data */
85
86 /* divide the time period into 128s segments */
87 for(i=gps_start_i; i<gps_end_i; i+=128){
88
89 start=i;
90 end=Min(i+128,gps_end_i);
91 printf("Building frame %d-%d...\n",start,end);
92
93 /* define time segment */
94 gps_start.gpsSeconds = start;
95 gps_start.gpsNanoSeconds = 0;
96 gps_end.gpsSeconds = end;
97 gps_end.gpsNanoSeconds = 0;
98
99 /* read H1 and H2 data */
100 ht_1 = XLALFrStreamReadREAL8TimeSeries(stream_1, "H1:LSC-STRAIN", &gps_start, XLALGPSDiff(&gps_end, &gps_start), 0);
101 if(!ht_1) {
102 XLALFrStreamClose(stream_1);
103 printf("%s(): cannot read data for H1:LSC-STRAIN\n",__func__);
104 }
105 ht_2 = XLALFrStreamReadREAL8TimeSeries(stream_2, "H2:LSC-STRAIN", &gps_start, XLALGPSDiff(&gps_end, &gps_start), 0);
106 if(!ht_2) {
107 XLALFrStreamClose(stream_2);
108 printf("%s(): cannot read data for H2:LSC-STRAIN\n",__func__);
109 }
110
111 /* units */
114
115 /* create H- time series */
116 ht_m = XLALCreateREAL8TimeSeries("H2:LSC-STRAIN_HNULL", &gps_start, ht_1->f0, ht_1->deltaT, &ht_1->sampleUnits, ht_1->data->length);
117
118 /* fill H- data vector */
119 for ( p = 0 ; p < (int)ht_1->data->length; p++ )
120 ht_m->data->data[p]=ht_1->data->data[p]-ht_2->data->data[p];
121
122 /* save time series into a frame */
123 frame = XLALFrameNew(&gps_start, XLALGPSDiff(&gps_end, &gps_start), "LIGO", 0, 1,LAL_LHO_4K_DETECTOR_BIT);
124 /*XLALFrameAddREAL8TimeSeriesProcData( frame, ht_1 );*/
125 /*XLALFrameAddREAL8TimeSeriesProcData( frame, ht_2 );*/
127 sprintf(filename,"%s/H-H1H2_COHERENT-%d-%d.gwf", argv[3],start,end-start);
128 XLALFrameWrite(frame, filename);
129
130 /* cleaning */
134 XLALFrameFree(frame);
135 }
136
137 /* close streams */
138 XLALFrStreamClose(stream_1);
139 XLALFrStreamClose(stream_2);
140
141 return 0;
142}
143
144/***************************************************************************/
145
146int Min(int a, int b){
147 if(a>b) return b;
148 else return a;
149}
int main(int argc, char *argv[])
Definition: AddFrame.c:20
int Min(int a, int b)
Definition: AddFrame.c:146
void XLALDestroyCache(LALCache *cache)
LALCache * XLALCacheImport(const char *fname)
#define LAL_LHO_4K_DETECTOR_BIT
int XLALFrStreamClose(LALFrStream *stream)
LALFrStream * XLALFrStreamCacheOpen(LALCache *cache)
int XLALFrStreamSetMode(LALFrStream *stream, int mode)
LAL_FR_STREAM_VERBOSE_MODE
REAL8TimeSeries * XLALFrStreamReadREAL8TimeSeries(LALFrStream *stream, const char *chname, const LIGOTimeGPS *start, REAL8 duration, size_t lengthlimit)
LALFrameUFrameH LALFrameH
int XLALFrameWrite(LALFrameH *frame, const char *fname)
LALFrameH * XLALFrameNew(const LIGOTimeGPS *epoch, double duration, const char *project, int run, int frnum, INT8 detectorFlags)
void XLALFrameFree(LALFrameH *frame)
int XLALFrameAddREAL8TimeSeriesProcData(LALFrameH *frame, const REAL8TimeSeries *series)
static const INT4 a
void XLALDestroyREAL8TimeSeries(REAL8TimeSeries *series)
REAL8TimeSeries * XLALCreateREAL8TimeSeries(const CHAR *name, const LIGOTimeGPS *epoch, REAL8 f0, REAL8 deltaT, const LALUnit *sampleUnits, size_t length)
const LALUnit lalStrainUnit
#define XLAL_ERROR(...)
XLAL_EFUNC
REAL8 XLALGPSDiff(const LIGOTimeGPS *t1, const LIGOTimeGPS *t0)
int i
Definition: inspinj.c:596
int
start
INT4 gpsNanoSeconds
REAL8Sequence * data
LALUnit sampleUnits
REAL8 * data