burstdso.c

Go to the documentation of this file.
00001 /*
00002 *  Copyright (C) 2007 Julien Sylvestre
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 <stdlib.h>
00021 #include <stdio.h>
00022 #include <string.h>
00023 
00024 #include <sys/types.h>
00025 #include <sys/stat.h>
00026 #include <unistd.h>
00027 
00028 #include "datacondAPI/DatacondCaller.h"
00029 
00030 #include <burstdso.h>
00031 
00032 #include <lalapps/lalapps.h>
00033 
00034 
00035 int main(int argc, char *argv[]) {
00036 
00037   char nocondor = 0;
00038 
00039   char *fQuery; /* frame data */
00040 
00041   char *algorithms; /* algorithms */
00042 
00043   char *filterParams; /* params */
00044 
00045   char *rFiles = NULL; /* response files */
00046 
00047   float f0=0.0, f1=1.0; /* portion of the job to do */
00048 
00049   int Nsymbols = 0;
00050   static datacond_symbol_type *symbols = NULL; /* datacond symbols */
00051 
00052   BurstSearchParams bparams; /* burst search parameters */
00053 
00054   char *times, *algo, *params, *fraction, *resp, *dataserver;
00055 
00056   /* Which error handler to use */
00057   lal_errhandler = LAL_ERR_EXIT;
00058   set_debug_level( "227" ); /* no memory debugging */
00059 
00060   /* look at command line arguments */
00061   if(argc<5) {
00062     fprintf(stderr,"burstdso [-nocondor] dataserver framesQuery algorithms filterParams [responseFiles] [fraction]\n");
00063     fprintf(stderr,"frameQuery, algorithms, filterParams and responseFiles can be files or strings\n");
00064     fprintf(stderr,"Pass an empty string (\"\") for responseFiles to use fraction without responseFiles\n");
00065     fprintf(stderr,"fraction: f0-f1\n");
00066     return 1;
00067   }
00068 
00069   if(strstr(argv[1],"nocondor")) {
00070     argc -= 1;
00071     argv++;
00072     nocondor=1;
00073   }
00074 
00075   dataserver = argv[1];
00076   fQuery = argv[2];
00077   algo = argv[3];
00078   params = argv[4];
00079 
00080 
00081 
00082 
00083   /*****************************************/
00084   /* parse parameters */
00085   /* If the parameter is a string, it is stored directly. 
00086      If, however, the parameter is a file, the the content
00087      of the file is stored in the appropriate variable. */
00088   /*****************************************/
00089   {
00090     /* frame query */
00091     struct stat buf;
00092 
00093     if(stat(fQuery,&buf)) {
00094       times = (char *)calloc(1 + strlen(fQuery), sizeof(char));
00095       strcpy(times, fQuery);
00096     } else {
00097       /* fQuery is a filename */
00098       FILE *in;
00099       char *p;
00100 
00101       if((in = fopen(fQuery,"r"))==NULL) {
00102         fprintf(stderr,"Can't open %s\n",fQuery);
00103         return 1;
00104       }
00105 
00106       p = times = (char *)calloc(1 + buf.st_size, sizeof(char));
00107 
00108       while((p=fgets(p,buf.st_size,in))) {
00109         p += strlen(p);
00110       }
00111 
00112       fclose(in);
00113     }
00114   }
00115 
00116 
00117   {
00118     /* algorithms */
00119     struct stat buf;
00120 
00121     if(stat(algo,&buf)) {
00122       algorithms = (char *)calloc(1 + strlen(algo), sizeof(char));
00123       strcpy(algorithms, algo);
00124     } else {
00125       /* algo is a filename */
00126       FILE *in;
00127       char *p;
00128 
00129       if((in = fopen(algo,"r"))==NULL) {
00130         fprintf(stderr,"Can't open %s\n",algo);
00131         return 1;
00132       }
00133 
00134       p = algorithms = (char *)calloc(1 + buf.st_size, sizeof(char));
00135 
00136       while((p=fgets(p,buf.st_size,in))) {
00137         p += strlen(p);
00138       }
00139 
00140       fclose(in);
00141     }
00142   }
00143 
00144   {
00145     /* filterParams */
00146     struct stat buf;
00147 
00148     if(stat(params,&buf)) {
00149       filterParams = (char *)calloc(1 + strlen(params), sizeof(char));
00150       strcpy(filterParams, params);
00151     } else {
00152       /* params is a filename */
00153       FILE *in;
00154       char *p;
00155 
00156       if((in = fopen(params,"r"))==NULL) {
00157         fprintf(stderr,"Can't open %s\n",params);
00158         return 1;
00159       }
00160 
00161       p = filterParams = (char *)calloc(1 + buf.st_size, sizeof(char));
00162 
00163       while((p=fgets(p,buf.st_size,in))) {
00164         p += strlen(p);
00165       }
00166 
00167       fclose(in);
00168     }
00169   }
00170 
00171   if(argc>5)
00172   {
00173     /* response Files */
00174     struct stat buf;
00175 
00176     resp = argv[5];
00177 
00178     if(stat(resp,&buf)) {
00179       if(strlen(resp)>0) {
00180         rFiles = (char *)calloc(1 + strlen(resp), sizeof(char));
00181         strcpy(rFiles, resp);
00182       }
00183     } else {
00184       /* resp is a filename */
00185       FILE *in;
00186       char *p;
00187 
00188       if((in = fopen(resp,"r"))==NULL) {
00189         fprintf(stderr,"Can't open %s\n",resp);
00190         return 1;
00191       }
00192 
00193       p = rFiles = (char *)calloc(1 + buf.st_size, sizeof(char));
00194 
00195       while((p=fgets(p,buf.st_size,in))) {
00196         p += strlen(p);
00197       }
00198 
00199       fclose(in);
00200     }
00201   }
00202 
00203   if(argc>6) {
00204     fraction = argv[6];
00205     sscanf(fraction,"%g-%g",&f0,&f1);
00206   }
00207 
00208 
00209 #ifdef DEBUGBURST
00210   fprintf(stderr,"%s\n%s\n%s\n%s\n%g\n%g\n",fQuery,algorithms,filterParams,rFiles,f0,f1);
00211 #endif
00212 
00213   /*****************************************/
00214   /* prepare output symbols */
00215   /* For each output statement in the algorithms, we
00216      have to allocate an entry in the symbols table
00217      for the stand-alone datacondAPI, so that the data
00218      can be sent back to the analysis code. In the 
00219      output statement, the comment field must comtain
00220      the datatype of the output data in square brackets,
00221      for instance:
00222      output(cavfaccplx,_,_,H2:CAL-CAV_FAC,H2 cavity factor [COMPLEX8TimeSeries]);
00223      Note that this is not necessary if the output type
00224      is a single precision time series. */
00225   /*****************************************/
00226   if(OutputSymbols(algorithms, &Nsymbols, &symbols)) {
00227     fprintf(stderr,"ERROR: OutputSymbols\n");
00228     return 1;
00229   }
00230 
00231   /*****************************************/
00232   /* acquire data */
00233   /*****************************************/
00234   /* loop over lines in fQuery, get data, add to datacond callchain */
00235   /* Format is:
00236      frame_type Site [file] GPS_Start-GPS_End channel alias
00237      file is optional, and is a frame file that overrides LSCdataFind
00238      channel can be adc(H2:LSC-AS_Q), proc(H2:CAL-OLOOP_FAC), or proc(H2:CAL-RESPONSE!0!7000.0001!), for instance; same format as LDAS
00239      alias is a name to represent the data in the datacondAPI
00240   */
00241 
00242   if(nocondor) {
00243 
00244     if(getFrameData(times, dataserver, &Nsymbols, &symbols)) {
00245       fprintf(stderr,"ERROR: can't get frame data\n");
00246       return 1;
00247     }
00248 
00249   } else {
00250     
00251     if(getFrameData(times, dataserver, &Nsymbols, &symbols)) {
00252       fprintf(stderr,"ERROR: can't get frame data\n");
00253       return 1;
00254     }
00255 
00256   }
00257 
00258   /*****************************************/
00259   /* get non-frame data */
00260   /*****************************************/
00261   /* loop over lines in rFiles, add to datacond callchain & algorithm */
00262   /* format is:
00263      file push/pass datacond_symbol
00264      pass option not supported yet
00265      file can be a URL */
00266 
00267   if(rFiles) {
00268     if(getNonFrameData(rFiles, &algorithms, &Nsymbols, &symbols)) {
00269       fprintf(stderr,"ERROR: can't get non-frame data\n");
00270       return 1;
00271     }
00272   }
00273 
00274   /*****************************************/
00275   /* condition data (datacondAPI) */
00276   /*****************************************/
00277   if(ConditionData(Nsymbols, symbols, algorithms)) {
00278     fprintf(stderr,"ERROR: dataconditioning failed\n");
00279     return 1;
00280   }
00281 
00282   /*****************************************/
00283   /* prepare search */
00284   /*****************************************/
00285   /* setup parameters */
00286   if(InitSearch(filterParams, &bparams)) {
00287     fprintf( stderr, "ERROR: InitSearch\n");
00288     return 1;
00289   }
00290   
00291   /* run calibration, etc. */
00292   if(ReConditionData(Nsymbols, symbols, algorithms, &bparams)) {
00293     fprintf(stderr,"ERROR: dataconditioning failed, level 2\n");
00294     return 1;
00295   }
00296 
00297   /*****************************************/
00298   /* run search */
00299   /*****************************************/
00300   if(RunSearch(&bparams, f0, f1)) {
00301     fprintf( stderr, "ERROR: RunSearch\n");
00302     return 1;
00303   }
00304 
00305   /*****************************************/
00306   /* clean up */
00307   /*****************************************/
00308   free(times);
00309   free(algorithms);
00310   free(filterParams);
00311 
00312   if(rFiles) free(rFiles);
00313 
00314   symbolsfree(symbols);
00315 
00316   bparamsfree(&bparams);
00317 
00318   return 0;
00319 }

Generated on Tue Sep 2 02:40:52 2008 for LAL by  doxygen 1.5.2