//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; }
//Main program int main(int argc, char *argv[]) { FILE *OUTPUT; LALDetector det; LALStatus XLAL_INIT_DECL(status); UserVariables_t XLAL_INIT_DECL(uvar); XLAL_CHECK ( InitUserVars(&uvar, argc, argv) == XLAL_SUCCESS, XLAL_EFUNC ); XLAL_CHECK( (OUTPUT = fopen(uvar.outfilename,"w")) != NULL, XLAL_EIO, "Output file %s could not be opened\n", uvar.outfilename ); //Interferometer if (strcmp("L1", uvar.IFO)==0) { fprintf(stderr,"IFO = %s\n", uvar.IFO); det = lalCachedDetectors[LAL_LLO_4K_DETECTOR]; //L1 } else if (strcmp("H1", uvar.IFO)==0) { fprintf(stderr,"IFO = %s\n", uvar.IFO); det = lalCachedDetectors[LAL_LHO_4K_DETECTOR]; //H1 } else if (strcmp("V1", uvar.IFO)==0) { fprintf(stderr,"IFO = %s\n", uvar.IFO); det = lalCachedDetectors[LAL_VIRGO_DETECTOR]; //V1 } else { XLAL_ERROR( XLAL_EINVAL, "Not using valid interferometer! Expected 'H1', 'L1', or 'V1' not %s.\n", uvar.IFO); } //Parameters for the sky-grid fprintf(stderr, "Sky region = %s\n", uvar.skyRegion); DopplerSkyScanInit XLAL_INIT_DECL(scanInit); DopplerSkyScanState XLAL_INIT_DECL(scan); PulsarDopplerParams dopplerpos; scanInit.gridType = GRID_ISOTROPIC; //Default value for an approximate-isotropic grid scanInit.skyRegionString = uvar.skyRegion; //"allsky" = Default value for all-sky search scanInit.numSkyPartitions = 1; //Default value so sky is not broken into chunks scanInit.Freq = uvar.fmin+0.5*uvar.fspan; //Mid-point of the frequency band //Initialize ephemeris data structure EphemerisData *edat = NULL; XLAL_CHECK( (edat = XLALInitBarycenter(uvar.ephemEarth, uvar.ephemSun)) != NULL, XLAL_EFUNC ); //v1: Maximum orbital earth speed in units of c from start of S6 TwoSpect data for 104 weeks total time //else: maximum detector velocity around the time of observation REAL4 detectorVmax = 0.0; if (uvar.v1) detectorVmax = CompDetectorVmax(931081500.0+uvar.SFToverlap, uvar.Tsft, uvar.SFToverlap, 62899200.0-uvar.SFToverlap, det, edat); else detectorVmax = CompDetectorVmax(uvar.t0-uvar.Tsft, uvar.Tsft, uvar.SFToverlap, uvar.Tobs+2.0*uvar.Tsft, det, edat); XLAL_CHECK( xlalErrno == 0, XLAL_EFUNC, "CompDetectorVmax() failed\n" ); //Initialize the sky-grid scanInit.dAlpha = 0.5/((uvar.fmin+0.5*uvar.fspan) * uvar.Tsft * detectorVmax); scanInit.dDelta = scanInit.dAlpha; InitDopplerSkyScan(&status, &scan, &scanInit); XLAL_CHECK( status.statusCode == 0, XLAL_EFUNC ); //Start at first location XLAL_CHECK( XLALNextDopplerSkyPos(&dopplerpos, &scan) == XLAL_SUCCESS, XLAL_EFUNC ); //loop through and output to the specified file while (scan.state != STATE_FINISHED) { fprintf(OUTPUT, "%.6f %.6f\n", dopplerpos.Alpha, dopplerpos.Delta); //Iterate to next sky location XLAL_CHECK( XLALNextDopplerSkyPos(&dopplerpos, &scan) == XLAL_SUCCESS, XLAL_EFUNC ); } //Destroy XLALDestroyUserVars(); XLALDestroyEphemerisData(edat); fclose(OUTPUT); return 0; }