build_zm_frames.c

Go to the documentation of this file.
00001 /*
00002 *  Copyright (C) 2007 Patrick Brady, Saikat Ray-Majumder
00003 *
00004 *  This program is free software; you can redistribute it and/or modify
00005 *  it under the terms of the GNU General Public License as published by
00006 *  the Free Software Foundation; either version 2 of the License, or
00007 *  (at your option) any later version.
00008 *
00009 *  This program is distributed in the hope that it will be useful,
00010 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 *  GNU General Public License for more details.
00013 *
00014 *  You should have received a copy of the GNU General Public License
00015 *  along with with program; see the file COPYING. If not, write to the
00016 *  Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00017 *  MA  02111-1307  USA
00018 */
00019 
00020 #include<stdio.h>
00021 #include<math.h>
00022 #include<stdarg.h> 
00023 #include <FrameL.h>
00024 
00025 #include <lalapps.h>
00026 #include <series.h>
00027 #include <processtable.h>
00028 #include <lalappsfrutils.h>
00029 
00030 #include <lal/LALStdlib.h>
00031 #include <lal/LALError.h>
00032 #include <lal/Calibration.h>
00033 #include <lal/AVFactories.h>
00034 #include <lal/LALDatatypes.h>
00035 #include <lal/LALConstants.h>
00036 #include <lal/RealFFT.h>
00037 #include <lal/Interpolate.h>
00038 
00039 RCSID( "$Id: build_zm_frames.c,v 1.7 2007/06/08 15:30:04 bema Exp $" );
00040 
00041 #define PLAYC_ENORM  0
00042 #define PLAYC_ESUB   1
00043 #define PLAYC_EARG   2
00044 #define PLAYC_EVAL   3
00045 #define PLAYC_EFILE  4
00046 #define PLAYC_EINPUT 5
00047 #define PLAYC_EMEM   6
00048 
00049 #define PLAYC_MSGENORM  "Normal exit"
00050 #define PLAYC_MSGESUB   "Subroutine failed"
00051 #define PLAYC_MSGEARG   "Error parsing arguments"
00052 #define PLAYC_MSGEVAL   "Input argument out of valid range"
00053 #define PLAYC_MSGEFILE  "Could not open file"
00054 #define PLAYC_MSGEINPUT "Error reading file"
00055 #define PLAYC_MSGEMEM   "Out of memory"
00056 
00057 /* Usage format string. */       
00058 #define USAGE "Usage: %s --infileindex waveform id --channel channel suffix " \
00059         "--nfiles #files --frame-length framelength(sec:Must be power of 2) " \
00060         "[--verbose] [--printrawdata] [--printinterpolateddata] [--help]\n"
00061 
00062 #define MAX_LENGTH 81920
00063 #define TRUE  1
00064 #define FALSE 0
00065 
00066 
00067 static float **matrix(long nrow, long ncol)
00068 /* allocate a float matrix with subscript range m[nrl..nrh][ncl..nch] */
00069 {
00070   long i;
00071   float **m;
00072   
00073   /* allocate pointers to rows */
00074   m=(float **) malloc((size_t)((nrow)*sizeof(float*)));
00075   if (!m) exit(1);
00076   
00077   /* allocate rows and set pointers to them */
00078   m[0]=(float *) malloc((size_t)((nrow*ncol)*sizeof(float)));
00079   if (!m[0]) exit(2);
00080   
00081   for(i=1;i<nrow;i++) m[i]=m[i-1]+ncol;
00082   
00083   /* return pointer to array of pointers to rows */
00084   return m;
00085 }
00086 
00087 static void free_matrix(float **m)
00088 {
00089   free(m[0]);
00090   free(m);
00091 }
00092 
00093 /* byte swap because the data was written on a machine which is big-endian */
00094 static void swap4(int n, char *b1) {
00095   char *b2,*b3,*b4;
00096   char temp;
00097   int i; 
00098 
00099   for (i=0;i<n;i++) {
00100     b2=b1+1;
00101     b3=b2+1;
00102     b4=b3+1; 
00103     
00104     temp=*b1;
00105     *b1=*b4;
00106     *b4=temp;
00107     temp=*b2;
00108     *b2=*b3;
00109     *b3=temp;
00110     b1+=4;
00111   }
00112   return;
00113 }
00114 
00115 /* function to read in ZM waveforms */
00116 static int readZM(const char* fname,  float **time,  float **amplitude, float **ampcross)
00117 {
00118   long n;
00119   int i;
00120   FILE *fp=NULL;     
00121 
00122 
00123   fp = fopen(fname,"r+b");
00124 
00125   if(!fp){
00126     fprintf(stderr,"File %s doesn't exit\n",fname);
00127     exit(6);
00128   }
00129 
00130   fread(&i, sizeof(long), 1, fp);
00131   fread(&n, sizeof(long), 1, fp);
00132   fread(&i, sizeof(long), 1, fp);
00133   fread(&i, sizeof(long), 1, fp);
00134   swap4(1,(char *)&n);
00135 
00136 
00137   (*time) = (float *)malloc( n*sizeof(float));
00138   fread(*time, sizeof(float), n, fp);
00139   swap4(n,(char *)(*time));
00140 
00141   (*amplitude) = (float *)malloc( n*sizeof(float));
00142   fread(*amplitude, sizeof(float), n, fp);
00143   swap4(n,(char *)(*amplitude));     
00144 
00145   (*ampcross) = (float *)malloc( n*sizeof(float));
00146   memset( *ampcross, 0, n*sizeof(float) );
00147 
00148   fclose(fp);
00149 
00150   return n;
00151 } 
00152 
00153 /* function to read in Ott et al waveforms */
00154 static int readOtt(const char* fname,  float **time,  float **amplitude, float **ampcross)
00155 {
00156   int i;
00157   FILE *fp;     
00158   CHAR line[1024];
00159   int nlines=0;
00160   float tmp,tmpt,tmph;
00161   float *itime, *iamp;
00162 
00163   fp = fopen(fname,"r");
00164 
00165   if(!fp){
00166     fprintf(stderr,"File %s doesn't exit\n",fname);
00167     exit(6);
00168   }
00169 
00170   /* read data into arrays */
00171   nlines=0;
00172   while (1) {
00173     if (fgets(line,sizeof(line),fp)==NULL) {
00174       break;
00175     }
00176     if (line[0] != '#'){
00177       sscanf(line,"%e %e %e\n",&tmpt,&tmp,&tmph);
00178       nlines++;
00179     }
00180   }
00181   fclose(fp);
00182 
00183   itime = (*time) = (float *)malloc( nlines*sizeof(float));
00184   iamp  = (*amplitude) = (float *)malloc( nlines*sizeof(float));
00185 
00186   (*ampcross) = (float *)malloc( nlines*sizeof(float));
00187   memset( *ampcross, 0, nlines*sizeof(float) );
00188 
00189   fp = fopen(fname,"r");
00190   /* read data into arrays */
00191   i=0;
00192   while (1) {
00193     if (fgets(line,sizeof(line),fp)==NULL) {
00194       break;
00195     }
00196     if (line[0] != '#'){
00197       sscanf(line,"%e %e %e\n",&itime[i],&tmp,&iamp[i]);
00198       i++;
00199     }
00200   }
00201   fclose(fp);
00202 
00203   return nlines;
00204 }
00205 
00206 static int readWarren(const char* fname,  float **time,  float **amplitude, float **ampcross)
00207 {
00208   int i;
00209   FILE *fp;     
00210   CHAR line[1024];
00211   int nlines=0;
00212   float tmp,tmpt,tmph;
00213   float *itime, *iamp, *iampcross;
00214 
00215   fp = fopen(fname,"r");
00216 
00217   if(!fp){
00218     fprintf(stderr,"File %s doesn't exist\n",fname);
00219     exit(6);
00220   }
00221 
00222   /* read data into arrays */
00223   nlines=0;
00224   while (1) {
00225     if (fgets(line,sizeof(line),fp)==NULL) {
00226       break;
00227     }
00228     if (line[0] != '#'){
00229       sscanf(line,"%e %e %e\n",&tmpt,&tmp,&tmph);
00230       nlines++;
00231     }
00232   }
00233   fclose(fp);
00234   
00235   itime = (*time) = (float *)malloc( nlines*sizeof(float));
00236   iamp  = (*amplitude) = (float *)malloc( nlines*sizeof(float));
00237   iampcross  = (*ampcross) = (float *)malloc( nlines*sizeof(float));
00238 
00239   fp = fopen(fname,"r");
00240   /* read data into arrays */
00241   i=0;
00242   while (1) {
00243     if (fgets(line,sizeof(line),fp)==NULL) {
00244       break;
00245     }
00246     if (line[0] != '#'){
00247       sscanf(line,"%e %e %e\n",&itime[i],&iamp[i],&iampcross[i]);
00248       i++;
00249     }
00250   }
00251   fclose(fp);
00252 
00253   return nlines;
00254 } 
00255 
00256 static void build_interpolate ( float **h, float **t, float **h_intpolat, float **t_intpolat, float dt, int l, int *N, int nfiles ){
00257 
00258   static LALStatus stat;
00259 
00260   float      t_target[5];
00261   float      h_target[5];
00262   float      target;
00263   SInterpolatePar intpar   ={5,t_target,h_target};
00264   SInterpolateOut intout;
00265 
00266   INT4 i,j,k,m;
00267 
00268   for(i=0;i<nfiles;i++){
00269     for(j=0;j<l;j++){
00270       t_intpolat[i][j] = j*dt;
00271       h_intpolat[i][j] = 0;
00272     }
00273   }
00274 
00275   for(i=0;i<nfiles;i++){
00276     for(j=0;t_intpolat[i][j]<t[i][N[i]-1];j++){
00277       for(k=0;t[i][k]<=t_intpolat[i][j];k++){
00278       }
00279 
00280       for(m=0;m<5;m++){
00281         t_target[m]=0;
00282         h_target[m]=0;
00283       }
00284 
00285       if(k>=2 && k<=(N[i]-3)){
00286         for(m=0;m<5;m++){
00287           t_target[m]=t[i][k-2+m];
00288           h_target[m]=h[i][k-2+m];
00289         }
00290       }
00291       else if(k==1){
00292         for(m=0;m<5;m++){
00293           t_target[m]=t[i][k-1+m];
00294           h_target[m]=h[i][k-1+m];
00295         }
00296       }
00297       else if(k==0){
00298         for(m=0;m<5;m++){
00299           t_target[m]=t[i][k+m];
00300           h_target[m]=h[i][k+m];
00301         }
00302       }
00303       else if(k==(N[i]-2)){
00304         for(m=0;m<5;m++){
00305           t_target[m]=t[i][k-3+m];
00306           h_target[m]=h[i][k-3+m];
00307         }
00308       }
00309       else if(k==(N[i]-1)){
00310         for(m=0;m<5;m++){
00311           t_target[m]=t[i][k-4+m];
00312           h_target[m]=h[i][k-4+m];
00313         }
00314       }
00315 
00316       target = t_intpolat[i][j];
00317 
00318       LAL_CALL( LALSPolynomialInterpolation( &stat, &intout, target, &intpar ), 
00319           &stat);
00320       h_intpolat[i][j]=intout.y;
00321     }
00322   }
00323 }
00324  
00325 static void find_tpeak( float **hplus_intpolat, float **hcross_intpolat, float dt, INT4 nfiles, INT4 l, int *tpeak){
00326 
00327   int i,j;
00328 
00329   float Fplus, Fcross;
00330   float **hsquare, **t;
00331   float htmp;
00332   int ttmp;
00333 
00334   t = matrix(nfiles,l);
00335   hsquare = matrix(nfiles,l);
00336 
00337   Fplus = 1.0;
00338   Fcross = 0.0;
00339 
00340   for(i=0; i<nfiles;i++){
00341     for(j=0;j<l;j++){
00342       t[i][j] = j*dt;
00343       hsquare[i][j] = Fplus*hplus_intpolat[i][j]*Fplus*hplus_intpolat[i][j] + Fcross*hcross_intpolat[i][j]*Fcross*hcross_intpolat[i][j];
00344     }
00345   }
00346 
00347   for(i=0;i<nfiles;i++){
00348     htmp = hsquare[i][0];
00349     ttmp = 0;
00350     for(j=1;j<l;j++){
00351       if(hsquare[i][j] > htmp){
00352         htmp = hsquare[i][j];  
00353         ttmp = j;
00354       }  
00355     }
00356     tpeak[i] = ttmp;
00357   }
00358 
00359   free_matrix(hsquare);
00360 }
00361 
00362 struct options_t {
00363         CHAR *infileindex;
00364         CHAR *channel;
00365         INT4 nfiles;
00366 
00367         int verbose;
00368         int printrawdata;
00369         int printinterpolateddata;
00370 
00371         INT4 samplerate;
00372         REAL4 lframe ;
00373         INT4 useZMWaveforms;
00374         INT4 useOttWaveforms;
00375         INT4 useWarrenWaveforms;
00376         INT4 useKuduWaveforms;
00377 };
00378 
00379 static void set_option_defaults(struct options_t *options)
00380 {
00381         options->infileindex = NULL;
00382         options->channel = NULL;
00383         options->nfiles = 0;
00384 
00385         options->verbose = FALSE;
00386         options->printrawdata = FALSE;
00387         options->printinterpolateddata = FALSE;
00388 
00389         options->samplerate = 0;
00390         options->lframe = 0;
00391         options->useZMWaveforms = 0;
00392         options->useOttWaveforms = 0;
00393         options->useWarrenWaveforms = 0;
00394         options->useKuduWaveforms = 0;
00395 }
00396 
00397 
00398 static void parse_command_line(int argc, char **argv, struct options_t *options)
00399 {
00400         struct option long_options[] = {
00401                 /* these options set a flag */
00402                 {"verbose",                no_argument,        &options->verbose, TRUE},
00403                 {"printrawdata",           no_argument,        &options->printrawdata, TRUE},
00404                 {"printinterpolateddata",  no_argument,        &options->printinterpolateddata, TRUE},
00405                 /* parameters which determine the output xml file */
00406                 {"infileindex",     required_argument,  NULL,  'a'},
00407                 {"channel",         required_argument,  NULL,  'b'},
00408                 {"nfiles",          required_argument,  NULL,  'c'},
00409                 {"sample-rate",     required_argument,  NULL,  'd'},
00410                 {"frame-length",    required_argument,  NULL,  'e'},
00411                 {"help",            no_argument,        NULL,  'o'}, 
00412                 {NULL, 0, NULL, 0}
00413         };
00414         int c;
00415         int option_index;
00416 
00417         do {
00418                 switch(c = getopt_long(argc, argv, "a:b:c:d:e:", long_options, &option_index)) {
00419                         case -1:
00420                         case 0:
00421                         break;
00422 
00423                         case 'a':
00424                         options->infileindex = optarg;
00425                         if ( ! strcmp("zm", optarg))
00426                           options->useZMWaveforms = 1;
00427                         if ( ! strcmp("ott", optarg))
00428                           options->useOttWaveforms = 1;
00429                         if ( ! strcmp("warren", optarg))
00430                           options->useWarrenWaveforms = 1;
00431                         break;
00432 
00433                         case 'b':
00434                         /*
00435                          * output cache file name
00436                          */
00437                         options->channel = optarg;
00438                         break;  
00439 
00440                         case 'c':
00441                         /*
00442                          * output cache file name
00443                          */
00444                         options->nfiles = atoi(optarg);
00445                         break;
00446 
00447                         case 'd':
00448                         /*
00449                          * output cache file name
00450                          */
00451                         options->samplerate = atoi(optarg);
00452                         break;          
00453 
00454                         case 'e':
00455                         /*
00456                          * output cache file name
00457                          */
00458                         options->lframe = atoi(optarg);
00459                         break;
00460 
00461                         case ':':
00462                         case '?':
00463                         case 'o':
00464                         default:
00465                         /*
00466                          * print usage
00467                          */
00468                         LALPrintError(USAGE, *argv);
00469                         exit(1);
00470                 }
00471         } while(c != -1);
00472 
00473         if(optind < argc) {
00474                 fprintf(stderr, "extraneous command line arguments:\n");
00475                 while(optind < argc)
00476                         fprintf(stderr, "%s\n", argv[optind++]);
00477                 exit(2);
00478         }
00479 
00480         if(!options->infileindex) {
00481                 LALPrintError( "Input file naming index must be specified\n" );
00482                 exit(3);
00483         }
00484 
00485         if(!options->lframe) {
00486                 LALPrintError( "Frame length in seconds must be specified\n" );
00487                 exit(4);
00488         }
00489 
00490         if(!(options->useZMWaveforms || options->useOttWaveforms || options->useWarrenWaveforms)) {
00491                 LALPrintError( "Invalid input for --infileindex; Must be one of zm/ott/warren\n" );
00492                 exit(5);
00493         }
00494 }
00495 
00496 
00497 /*void swap4(int n,char *here);
00498   int readZM(const char* fname,  float **time,  float **amplitude); 
00499   int readOtt(const char* fname,  float **time,  float **amplitude);*/ 
00500   int snprintf(char *str,size_t size,const char *format, ...);
00501 
00502 int main(int argc, char **argv)
00503 {
00504   static LALStatus stat;                                                      
00505 
00506   struct options_t options;       /* command line */
00507 
00508   INT4 nfiles = 0;                /* no. of input files */
00509   REAL4 dt = 1.0/16384.0;         /* default sample rate */
00510 
00511   CHAR filename[30], outputfile[30];
00512 
00513   FILE *fp;
00514 
00515   int i,j,l,tshift,N[2048];
00516   int lframe ;
00517   float n[2048];
00518   float x; 
00519   int *tpeakindex;
00520   int tpeakmax;
00521 
00522   float *time, *ampplus, *ampcross;
00523    
00524   float **hplus, **hcross, **t;
00525   float **hplus_intpolat, **hcross_intpolat, **t_intpolat;
00526   float **hplus_pad, **hcross_pad, **t_pad;
00527 
00528   /* frame output data */
00529   struct FrFile *frOutFile  = NULL;
00530   struct FrameH *outFrame   = NULL;
00531 
00532   /* raw input data storage */
00533   REAL4TimeSeries               zmseries;
00534 
00535   /*******************************************************************
00536    * PARSE ARGUMENTS (arg stores the current position)               *
00537    *******************************************************************/
00538   set_option_defaults(&options);
00539   parse_command_line(argc, argv, &options);
00540 
00541   /* set some of the variables */
00542   nfiles = options.nfiles;               /* no. of input files */
00543   if ( options.samplerate )
00544     dt = 1.0/options.samplerate;         /* required sample  rate */
00545   lframe = (int)(options.lframe*options.samplerate);  /* no.of points in the frame */
00546 
00547   /* allocate some memory */
00548   t = matrix(nfiles,MAX_LENGTH);
00549   memset( t[0], 0, nfiles*MAX_LENGTH*sizeof(float) );
00550   hplus = matrix(nfiles,MAX_LENGTH);
00551   memset( hplus[0], 0, nfiles*MAX_LENGTH*sizeof(float) );
00552   hcross = matrix(nfiles,MAX_LENGTH);
00553   memset( hcross[0], 0, nfiles*MAX_LENGTH*sizeof(float) );
00554 
00555   /******************************************************************
00556    * Read in the waveforms
00557    ******************************************************************/
00558   N[0]=0;
00559   for(i=0;i<nfiles;i++){
00560     /* read in Zm waveforms */
00561     if ( options.useZMWaveforms ){
00562       if (options.verbose)
00563         fprintf(stdout,"Reading in file %s-%d.bin\n", options.infileindex, i);
00564       snprintf(filename,30,"%s-%d.bin", options.infileindex, i);
00565       N[i] = readZM(filename,&time,&ampplus,&ampcross);
00566 
00567       if (options.printrawdata){
00568         /* print out in same format as Ott et al */
00569         snprintf(filename,30,"%s-%d.trh", options.infileindex, i);
00570         /* write out the ZM waveforms */
00571         fp = fopen(filename,"w");
00572         for(j=0;j<N[i];j++){  
00573           fprintf(fp, "%e\t%e\t%e\n", *(time+j), *(ampplus+j), 1e-20*(*(ampplus+j)));
00574         }
00575         fclose(fp);
00576       }    
00577     } 
00578     /* read in Ott waveforms */
00579     else if (options.useOttWaveforms ){
00580       if (options.verbose)
00581         fprintf(stdout,"Reading in file %s-%d.bin\n", options.infileindex, i);
00582       snprintf(filename,30,"%s-%d.bin", options.infileindex, i);
00583       N[i] = readOtt(filename,&time,&ampplus,&ampcross);
00584     }
00585     /*read in Warren waveforms*/
00586     else if (options.useWarrenWaveforms){
00587       if (options.verbose)
00588         fprintf(stdout,"Reading in file %s-%d.dat\n", options.infileindex, i);
00589       snprintf(filename,30,"%s-%d.bin", options.infileindex, i);
00590       snprintf(filename,30,"%s-%d.dat", options.infileindex, i);
00591       N[i] = readWarren(filename,&time,&ampplus,&ampcross);
00592 
00593       if (options.printrawdata){
00594         snprintf(filename,30,"%s-%d-raw.dat", options.infileindex, i);
00595         /* write out the Warren waveforms */
00596         fp = fopen(filename,"w");
00597         for(j=0;j<N[i];j++){  
00598           fprintf(fp, "%e %e %e\n", *(time+j), *(ampplus+j), *(ampcross+j));
00599         }
00600         fclose(fp);
00601       }
00602     }
00603 
00604     if (options.verbose)
00605       fprintf(stdout,"Read %d lines from file %s-%d\n", N[i],options.infileindex, i);
00606 
00607     /* store the raw time and amplitudes in t & h */
00608     for(j=0;j<N[i];j++){   
00609       t[i][j] = *(time+j);
00610       hplus[i][j] = *(ampplus+j);
00611       hcross[i][j] = *(ampcross+j);
00612     }
00613 
00614     free(time);
00615     free(ampplus);
00616     free(ampcross);
00617   }
00618 
00619   /*calculate h+ from A
00620   for(i=0;i<nfiles;i++){
00621     for(j=0;j<N[i];j++){
00622       look into pg.2 of documentation:here angle=90 & R=1cm.
00623       h[i][j] *= (0.273);             
00624     }
00625   }
00626   */
00627 
00628   /*********************************************************************************
00629    * Find l: the required array size to store the waveforms and interpolate to fit l
00630    ********************************************************************************/
00631 
00632   for(i=0;i<nfiles;i++){
00633     n[i] = (t[i][N[i]-1]-t[i][0])/dt;
00634   }
00635 
00636   x=n[0];
00637   for(i=1;i<nfiles;i++){
00638     if(n[i]>x)
00639       x = n[i];
00640   }
00641 
00642   for(i=0;pow(2,i)<x;++i){
00643   }
00644   l=pow(2,i);                          /* l is the required arraysize */
00645 
00646   if ( options.verbose )
00647     fprintf(stdout,"Number of points = %d\n",l);
00648 
00649   /******************************interpolate**************************/
00650 
00651   /* allocate some memory */
00652   t_intpolat = matrix(nfiles,l);
00653   memset( t_intpolat[0], 0, nfiles*l*sizeof(float) );
00654   hplus_intpolat = matrix(nfiles,l);
00655   memset( hplus_intpolat[0], 0, nfiles*l*sizeof(float) );
00656   hcross_intpolat = matrix(nfiles,l);
00657   memset( hcross_intpolat[0], 0, nfiles*l*sizeof(float) );
00658 
00659   build_interpolate(hplus, t, hplus_intpolat, t_intpolat, dt, l, N, nfiles);
00660   build_interpolate(hcross, t, hcross_intpolat, t_intpolat, dt, l, N, nfiles);
00661   
00662   if ( options.printinterpolateddata ){
00663     /* print out the interpolated data */
00664     for(i=0;i<nfiles;i++){
00665       snprintf(filename,30,"%s-%d-interpolated.dat", options.infileindex, i);
00666       /* write out the ZM waveforms */
00667       fp = fopen(filename,"w");
00668       for(j=0;j<l;j++){  
00669         fprintf(fp, "%e\t%e\t%e\n", t_intpolat[i][j], hplus_intpolat[i][j], hcross_intpolat[i][j]);
00670       }
00671       fclose(fp);
00672     }
00673   }
00674 
00675   tpeakindex = malloc( nfiles*sizeof(float));
00676   find_tpeak(hplus_intpolat, hcross_intpolat, dt, nfiles, l, tpeakindex);
00677 
00678   tpeakmax = tpeakindex[0];
00679   for(i=1;i<nfiles;i++){
00680     if (tpeakindex[i] > tpeakmax)
00681       tpeakmax = tpeakindex[i];
00682   }
00683 
00684   free_matrix(t);
00685   free_matrix(hplus);
00686   free_matrix(hcross);
00687   /*********************************************************************** 
00688    * Now adjust the time series so that the peak is at the center of the 
00689    * frame(whose length is specified by the user)
00690    **********************************************************************/
00691 
00692   if(lframe<2*tpeakmax){
00693     fprintf(stderr,"Error: Have to increase the frame length. Make it greater than %e secs\n",2*tpeakmax*dt);
00694     exit(8);
00695   }
00696 
00697   t_pad = matrix(nfiles,lframe);
00698   hplus_pad = matrix(nfiles,lframe);
00699   hcross_pad = matrix(nfiles,lframe);
00700 
00701   tshift = 0;
00702   for ( i=0; i<nfiles; i++){
00703     for (j=0; j<lframe; j++){
00704       t_pad[i][j] = j*dt;
00705       hplus_pad[i][j] = 0;
00706       hcross_pad[i][j] = 0;
00707     }
00708     tshift = lframe/2 - tpeakindex[i];    
00709     for (j = 0; j < l; j++){
00710       hplus_pad[i][j+tshift] = hplus_intpolat[i][j];
00711       hcross_pad[i][j+tshift] = hcross_intpolat[i][j];
00712     }
00713   }
00714 
00715   free_matrix(t_intpolat);
00716   free_matrix(hplus_intpolat);
00717   free_matrix(hcross_intpolat);
00718 
00719   if ( options.printinterpolateddata ){
00720     /* print out the interpolated data */
00721     for(i=0;i<nfiles;i++){
00722       snprintf(filename,30,"%s-%d-padded.dat", options.infileindex, i);
00723       /* write out the waveforms */
00724       fp = fopen(filename,"w");
00725       for(j=0;j<lframe;j++){  
00726         fprintf(fp, "%e\t%e\t%e\n", t_pad[i][j], hplus_pad[i][j], hcross_pad[i][j]);
00727       }
00728       fclose(fp);
00729     }
00730   }
00731 
00732   /* create the required vector to store the waveform */
00733   LALSCreateVector( &stat, &(zmseries.data), lframe );
00734   zmseries.deltaT = dt;
00735   if ( options.verbose)
00736     printf("deltaT = %e\n",zmseries.deltaT);
00737   zmseries.epoch.gpsSeconds = 0;
00738   zmseries.epoch.gpsNanoSeconds = 0;
00739   snprintf( zmseries.name, LALNameLength * sizeof(CHAR), "SIM" );
00740 
00741   /*************************************************************
00742    * Build the frames from the interpolated and padded waveforms
00743    ************************************************************/
00744   for(i=0;i<nfiles;i++){
00745     snprintf(outputfile,30,"plus_%s_%0d",options.infileindex,i);
00746 
00747     memset( zmseries.data->data, 0, zmseries.data->length*sizeof(REAL4) );
00748     for(j=0;j<lframe;j++){
00749       zmseries.data->data[j]=hplus_pad[i][j];
00750     }
00751 
00752     outFrame = fr_add_proc_REAL4TimeSeries( outFrame, 
00753         &zmseries, "strain", outputfile );
00754   }
00755 
00756   for(i=0;i<nfiles;i++){
00757     snprintf(outputfile,30,"cross_%s_%0d",options.infileindex,i);
00758 
00759     memset( zmseries.data->data, 0, zmseries.data->length*sizeof(REAL4) );
00760     for(j=0;j<lframe;j++){
00761       zmseries.data->data[j]=hcross_pad[i][j];
00762     }
00763 
00764     outFrame = fr_add_proc_REAL4TimeSeries( outFrame, 
00765         &zmseries, "strain", outputfile );
00766   }
00767 
00768   free_matrix(t_pad);
00769   free_matrix(hplus_pad);
00770   free_matrix(hcross_pad);
00771 
00772   /****************************************************************
00773    * Write out the frame file containing all the different channels
00774    ****************************************************************/
00775   snprintf(filename,30,"HL-SIM_%s-%d-%d.gwf",options.infileindex,zmseries.epoch.gpsSeconds,(int)(zmseries.data->length*zmseries.deltaT));
00776   frOutFile = FrFileONew( filename, 0 );
00777   FrameWrite( outFrame, frOutFile );
00778   FrFileOEnd( frOutFile );
00779 
00780   LALCheckMemoryLeaks();
00781   return 0;
00782 }
00783 
00784 
00785 
00786 
00787 
00788 
00789 
00790 
00791 
00792 

Generated on Mon Sep 8 03:06:27 2008 for LAL by  doxygen 1.5.2