Ejemplo n.º 1
0
//Main program
int main(int argc, char *argv[])
{
   
  INT4 ii, jj;               //counter variables
   
   //Turn off gsl error handler
   gsl_set_error_handler_off();
   
   //Initiate command line interpreter and config file loader
   struct gengetopt_args_info args_info;
   struct cmdline_parser_params *configparams;
   configparams = cmdline_parser_params_create();  //initialize parameters structure
   configparams->check_required = 0;  //don't check for required values at the step
   if ( cmdline_parser_ext(argc, argv, &args_info, configparams) ) {
       fprintf(stderr, "%s: cmdline_parser_ext() failed.\n", __func__);
       XLAL_ERROR(XLAL_FAILURE);
   }
   configparams->initialize = 0;  //don't reinitialize the parameters structure
   if ( args_info.config_given && cmdline_parser_config_file(args_info.config_arg, &args_info, configparams) ) {
      fprintf(stderr, "%s: cmdline_parser_config_file() failed.\n", __func__);
      XLAL_ERROR(XLAL_FAILURE);
   }
   //Check required
   if ( cmdline_parser_required(&args_info, argv[0]) ) {
      fprintf(stderr, "%s: cmdline_parser_required() failed.\n", __func__);
      XLAL_ERROR(XLAL_FAILURE);
   }
   
   //Set lalDebugLevel to user input or 0 if no input
   
   //Allocate input parameters structure memory
   inputParamsStruct *inputParams = new_inputParams(args_info.IFO_given);
   if (inputParams==NULL) {
      fprintf(stderr, "%s: new_inputParams() failed.\n", __func__);
      XLAL_ERROR(XLAL_EFUNC);
   }
   
   //Read TwoSpect input parameters
   if ( (readTwoSpectInputParams(inputParams, args_info)) != 0 ) {
      fprintf(stderr, "%s: readTwoSpectInputParams() failed.\n", __func__);
      XLAL_ERROR(XLAL_EFUNC);
   }
   
   //Initialize ephemeris data structure
   EphemerisData *edat = XLALInitBarycenter(earth_ephemeris, sun_ephemeris);
   if (edat==NULL) {
      fprintf(stderr, "%s: XLALInitBarycenter() failed.\n", __func__);
      XLAL_ERROR(XLAL_EFUNC);
   }
   
   //Maximum detector velocity in units of c from start of observation time - Tcoh to end of observation + Tcoh
   REAL4 detectorVmax = CompDetectorVmax(inputParams->searchstarttime-inputParams->Tcoh, inputParams->Tcoh, inputParams->SFToverlap, inputParams->Tobs+2.0*inputParams->Tcoh, inputParams->det[0], edat);
   if (xlalErrno!=0) {
      fprintf(stderr, "%s: CompDetectorVmax() failed.\n", __func__);
      XLAL_ERROR(XLAL_EFUNC);
   }
   
   //Assume maximum bin shift possible
   inputParams->maxbinshift = (INT4)round(detectorVmax * (inputParams->fmin+0.5*inputParams->fspan) * inputParams->Tcoh)+1;

   //Read in the T-F data from SFTs
   fprintf(stderr, "Loading in SFTs... ");
   REAL8 tfnormalization = 2.0/inputParams->Tcoh/(args_info.avesqrtSh_arg*args_info.avesqrtSh_arg);
   REAL4Vector *tfdata = readInSFTs(inputParams, &(tfnormalization));
   if (tfdata==NULL) {
      fprintf(stderr, "\n%s: readInSFTs() failed.\n", __func__);
      XLAL_ERROR(XLAL_EFUNC);
   }
   fprintf(stderr, "done\n");
   
   //Removing bad SFTs using K-S test and Kuiper's test
   if (inputParams->markBadSFTs!=0 && inputParams->signalOnly==0) {
      fprintf(stderr, "Marking and removing bad SFTs... ");
      INT4 numffts = (INT4)floor(inputParams->Tobs/(inputParams->Tcoh-inputParams->SFToverlap)-1);    //Number of FFTs
      INT4 numfbins = (INT4)(round(inputParams->fspan*inputParams->Tcoh+2.0*inputParams->dfmax*inputParams->Tcoh)+12+1)+2*inputParams->maxbinshift+inputParams->blksize-1;     //Number of frequency bins
      REAL4Vector *tempvect = XLALCreateREAL4Vector(numfbins);
      if (tempvect==NULL) {
         fprintf(stderr, "%s: XLALCreateREAL4Vector(%d) failed.\n", __func__, numfbins);
         XLAL_ERROR(XLAL_EFUNC);
      }
      REAL8 ksthreshold = 1.358/(sqrt(numfbins)+0.12+0.11/sqrt(numfbins));
      REAL8 kuiperthreshold = 1.747/(sqrt(numfbins)+0.155+0.24/sqrt(numfbins));
      //fprintf(stderr, "%f %f\n", ksthreshold, kuiperthreshold);
      INT4 badsfts = 0, badsfts0 = 0, kuiperoverlap1 = 0, kuiperoverlap2 = 0, totalsfts = 0;
      FILE *OUTPUT = fopen("./output/kskoutput.dat","a");
      for (ii=0; ii<numffts; ii++) {
         if (tfdata->data[ii*numfbins]!=0.0) {
            totalsfts++;
            memcpy(tempvect->data, &(tfdata->data[ii*numfbins]), sizeof(REAL4)*tempvect->length);
            qsort(tempvect->data, tempvect->length, sizeof(REAL4), qsort_REAL4_compar);
            REAL4 vector_median = 0.0;
            if (tempvect->length % 2 != 1) vector_median = 0.5*(tempvect->data[(INT4)(0.5*tempvect->length)-1] + tempvect->data[(INT4)(0.5*tempvect->length)]);
            else vector_median = tempvect->data[(INT4)(0.5*tempvect->length)];
            REAL4 vector_mean = (REAL4)(vector_median/LAL_LN2);

            REAL8 ksvalue = 0.0, testval1, testval2, testval;
            REAL8 oneoverlength = 1.0/tempvect->length;
            for (jj=0; jj<(INT4)tempvect->length; jj++) {
               testval1 = fabs((1.0+jj)*oneoverlength - gsl_cdf_exponential_P(tempvect->data[jj], vector_mean));
               testval2 = fabs(jj*oneoverlength - gsl_cdf_exponential_P(tempvect->data[jj], vector_mean));
               testval = fmax(testval1, testval2);
               if (testval>ksvalue) ksvalue = testval;
            }

            REAL8 loval = 0.0, hival = 0.0;
            for (jj=0; jj<(INT4)tempvect->length; jj++) {
              testval1 = (1.0+jj)*oneoverlength - gsl_cdf_exponential_P(tempvect->data[jj], vector_mean);
              testval2 = jj*oneoverlength - gsl_cdf_exponential_P(tempvect->data[jj], vector_mean);
              if (hival<testval1) hival = testval1;
              if (loval<testval2) loval = testval2;
            }
            REAL8 kuiperval1 = hival + loval;

            loval = -1.0, hival = -1.0;
            for (jj=0; jj<(INT4)tempvect->length; jj++) {
              testval1 = (1.0+jj)*oneoverlength - gsl_cdf_exponential_P(tempvect->data[jj], vector_mean);
              testval2 = jj*oneoverlength - gsl_cdf_exponential_P(tempvect->data[jj], vector_mean);
              if (hival<testval1) hival = testval1;
              if (hival<testval2) hival = testval2;
              if (loval<-testval1) loval = -testval1;
              if (loval<-testval2) loval = -testval2;
            }
            REAL8 kuiperval = hival + loval;

            //fprintf(OUTPUT, "%g %g %g\n", ksvalue, kuiperval1, kuiperval);

            if (ksvalue>ksthreshold || kuiperval1>kuiperthreshold) badsfts0++;
            if (ksvalue>ksthreshold || kuiperval>kuiperthreshold) badsfts++;
            if (kuiperval1>kuiperthreshold && kuiperval>kuiperthreshold) kuiperoverlap1++;
            if (kuiperval1>kuiperthreshold || kuiperval>kuiperthreshold) kuiperoverlap2++;

         }
      }
      fprintf(OUTPUT, "%f %d %d %d %d\n", inputParams->fmin, badsfts0, badsfts, kuiperoverlap1, kuiperoverlap2);
      fclose(OUTPUT);
      fprintf(stderr, "Fraction excluded in K-S and Kuiper's tests = %f\n", (REAL4)badsfts/(REAL4)totalsfts);
      XLALDestroyREAL4Vector(tempvect);
   }

   XLALDestroyREAL4Vector(tfdata);
   XLALDestroyEphemerisData(edat);
   cmdline_parser_free(&args_info);
   free_inputParams(inputParams);

   return 0;

}
Ejemplo n.º 2
0
int main(int argc, char *argv[]) {
	struct client_context cc;
	struct fbr_mutex mutex;
	ev_timer stop_timer;
	struct cmdline_parser_params *params;
	struct me_cli_config config;

	signal(SIGPIPE, SIG_IGN);
	signal(SIGSEGV, sigsegv_handler);

	srand((unsigned int) time(NULL));
	memset(&cc, 0x00, sizeof(cc));

	params = cmdline_parser_params_create();

	params->initialize = 1;
	params->print_errors = 1;
	params->check_required = 0;

	if (0 == access("strings-client.conf", R_OK)) {
		if(0 != cmdline_parser_config_file("strings-client.conf",
					&cc.args_info, params))
			exit(EXIT_FAILURE + 1);
		params->initialize = 0;
	}
	params->check_required = 1;
	if(0 != cmdline_parser_ext(argc, argv, &cc.args_info, params))
		exit(EXIT_FAILURE + 1);

	if (cc.args_info.value_size_arg < 50)
		errx(EXIT_FAILURE, "minimum value size is 50 bytes");
	if (cc.args_info.value_size_arg > 1350)
		errx(EXIT_FAILURE, "maximum value size is 1350 bytes");

	cmdline_parser_dump(stdout, &cc.args_info);
	wait_for_debugger = cc.args_info.wait_for_debugger_flag;
	cc.loop = EV_DEFAULT;
	fbr_init(&cc.fbr, cc.loop);
	setup_logging(&cc);

	ev_timer_init(&stop_timer, run_timeout_cb,
			cc.args_info.run_time_arg, 0.0);
	stop_timer.data = &cc;
	ev_timer_start(cc.loop, &stop_timer);
	cc.concurrency = cc.args_info.concurrency_arg;
	cc.last_value_id = 0;
	cc.stats.received = 0;
	cc.stats.timeouts = 0;
	cc.stats.duplicates = 0;
	cc.stats.extra_values = 0;
	cc.stats.other = 0;
	cc.last_iid = 0;
	cc.conn_initialized = 0;
	fbr_mutex_init(&cc.fbr, &mutex);
	fbr_cond_init(&cc.fbr, &cc.timeouts_cond);
	fbr_cond_init(&cc.fbr, &cc.conn_init_cond);
	cc.mutex = &mutex;

	config.fctx = &cc.fbr;
	config.loop = cc.loop;
	config.peers = cc.args_info.mersenne_ip_arg;
	config.peers_size = cc.args_info.mersenne_ip_given;
	config.port = cc.args_info.port_arg;
	config.starting_iid = 0;
	config.foreign_func = foreign_cb;
	config.foreign_func_arg = &cc;
	config.service_id = cc.args_info.service_id_arg;
	cc.conn = me_cli_open(&config);

	cc.main = fbr_create(&cc.fbr, "main", fiber_main, NULL, 0);
	fbr_transfer(&cc.fbr, cc.main);

	ev_loop(cc.loop, 0);

	me_cli_close(cc.conn);
	fbr_destroy(&cc.fbr);
	free(params);

	return 0;
}