29#define ROUND(x) (floor(x+0.5))
30#define SINC(x) (sin(LAL_PI*x)/(LAL_PI*x))
36int main(
int argc,
char **argv )
45 fprintf( stderr,
"Starting Spectral Interpolation" );
48 struct timeval timePreTot, timeEndTot;
49 if ( inputParams.
Timing ) {
50 fprintf( stderr,
", outputting timing values.\n" );
51 gettimeofday( &timePreTot, NULL );
56 struct timeval timePreStart, timePreEnd;
57 struct timeval timePulStart, timePulEnd;
59 if ( inputParams.
Timing ) {
60 gettimeofday( &timePreStart, NULL );
64 if ( inputParams.
startF == 0. || inputParams.
endF == 0. ) {
65 fprintf( stderr,
"SFT start and end frequencies are required.\n" );
73 fprintf( stderr,
"Pulsar directory and parfile specified. Using specified parfile.\n" );
78 XLALPrintError(
"WARNING: Pulsar name and directory both set, specified pulsar name is useless.\n" );
99 EphemerisData *edat200 = NULL, *edat405 = NULL, *edat414 = NULL, *edat421 = NULL;
122 for ( h = 0; h < numfiles; h++ ) {
123 CHAR *psrname = NULL;
128 fprintf( stderr,
"Warning... could not read in \"%s\". Skipping this pulsars.", parfiles->
data[h] );
134 fprintf( stderr,
"Warning... no frequency given in \"%s\". Skipping this pulsars.", parfiles->
data[h] );
142 fprintf( stderr,
"Warning... the GW frequency (%lf Hz) given in \"%s\" lies outside of SFT boundaries (%f to %f Hz).\n",
f0 * inputParams.
freqfactor, parfiles->
data[h], inputParams.
startF, inputParams.
endF );
148 fprintf( stderr,
"Warning... no source right ascension specified in \"%s!\". Skipping this pulsar.", parfiles->
data[h] );
153 fprintf( stderr,
"Warning... no source declination specified in \"%s!\". Skipping this pulsar.", parfiles->
data[h] );
162 if ( numpulsars > 0 ) {
185 if ( (
int )
sizeof( outputFilename ) <= snprintf( outputFilename,
FILENAME_MAXLEN,
"%s/SplInter_%s_%s", inputParams.
outputdir, psrname,
193 if ( (
fp = fopen( outputFilename,
"w" ) ) == NULL ) {
194 fprintf( stderr,
"Error... can't open output file %s!\n", outputFilename );
223 REAL8 startF = NAN, endF = NAN;
224 if ( inputParams.
Timing ) {
225 gettimeofday( &timePulStart, NULL );
230 if ( inputParams.
Timing ) {
231 gettimeofday( &timePulEnd, NULL );
236 fprintf( stderr,
"Number of valid Pulsars with frequencies within the SFT boundaries: %d\n", numpulsars );
240 if ( (
int )
sizeof( outputFilename ) <= snprintf( earthfile200,
FILENAME_MAXLEN,
"%s/earth00-40-DE200.dat.gz", inputParams.
ephemdir ) ) {
243 if ( (
int )
sizeof( outputFilename ) <= snprintf( sunfile200,
FILENAME_MAXLEN,
"%s/sun00-40-DE200.dat.gz", inputParams.
ephemdir ) ) {
246 if ( (
int )
sizeof( outputFilename ) <= snprintf( earthfile405,
FILENAME_MAXLEN,
"%s/earth00-40-DE405.dat.gz", inputParams.
ephemdir ) ) {
249 if ( (
int )
sizeof( outputFilename ) <= snprintf( sunfile405,
FILENAME_MAXLEN,
"%s/sun00-40-DE405.dat.gz", inputParams.
ephemdir ) ) {
252 if ( (
int )
sizeof( outputFilename ) <= snprintf( earthfile414,
FILENAME_MAXLEN,
"%s/earth00-19-DE414.dat.gz", inputParams.
ephemdir ) ) {
255 if ( (
int )
sizeof( outputFilename ) <= snprintf( sunfile414,
FILENAME_MAXLEN,
"%s/sun00-19-DE414.dat.gz", inputParams.
ephemdir ) ) {
258 if ( (
int )
sizeof( outputFilename ) <= snprintf( earthfile421,
FILENAME_MAXLEN,
"%s/earth00-40-DE421.dat.gz", inputParams.
ephemdir ) ) {
261 if ( (
int )
sizeof( outputFilename ) <= snprintf( sunfile421,
FILENAME_MAXLEN,
"%s/sun00-40-DE421.dat.gz", inputParams.
ephemdir ) ) {
271 if ( (
int )
sizeof( outputFilename ) <= snprintf( timefileTDB,
FILENAME_MAXLEN,
"%s/tdb_2000-2040.dat.gz", inputParams.
ephemdir ) ) {
274 if ( (
int )
sizeof( outputFilename ) <= snprintf( timefileTE405,
FILENAME_MAXLEN,
"%s/te405_2000-2040.dat.gz", inputParams.
ephemdir ) ) {
285 if ( edat200 == NULL || edat405 == NULL || edat414 == NULL || edat421 == NULL ) {
286 XLALPrintError(
"Error, could not read sun and earth ephemeris files - check that the ephemeris directory is correct" );
295 if ( tdatTDB == NULL || tdatTE405 == NULL ) {
296 XLALPrintError(
"Error, could not read time correction ephemeris file - check that the ephemeris directory is correct" );
303 REAL8 segmentsStart = 0., segmentsEnd = 0;
306 segmentsEnd = inputParams.
endTime;
309 if ( segmentsEnd - segmentsStart < inputParams.
minSegLength ) {
310 XLALPrintError(
"Applicable length of segment list, %.0f to %.0f is less than specified minimum duration of data, %.0f\n", segmentsStart, segmentsEnd, inputParams.
minSegLength );
318 if ( seglist->
length == 0 ) {
319 fprintf( stderr,
"No segments found in segment file.\n" );
324 if ( inputParams.
Timing ) {
325 gettimeofday( &timePreEnd, NULL );
328 UINT4 TotalNSFTs = 0;
329 REAL8 TotalInterTime = 0., TotalCatalogTime = 0., TotalLoadTime = 0.;
335 if ( sftlalcache == NULL ) {
336 XLALPrintError(
"Error... there's a problem loading the SFT LALCache file" );
341 XLALPrintError(
"Error... must specify either --sft-cache, --sft-lalcache, or --sft-loc" );
345 FILE *fpout[numpulsars];
351 while ( segcount < seglist->length ) {
353 REAL8 startt = 0., endt = 0.;
354 REAL8 baryAlpha[numpulsars], baryDelta[numpulsars], barydInv[numpulsars];
361 if ( startt > segmentsEnd || endt < segmentsStart ) {
366 if ( startt < segmentsStart ) {
367 startt = segmentsStart;
369 if ( endt > segmentsEnd ) {
386 fprintf( stderr,
"Segment %.0lf-%.0lf", startt, endt );
388 for ( h = 0; h < numpulsars; h++ ) {
405 struct timeval timeCatalogStart, timeCatalogEnd, timeLoadStart, timeLoadEnd, timeInterpolateStart, timeInterpolateEnd;
406 REAL8 tInterpolate = 0., tLoad = 0., tCatalog = 0.;
420 if ( inputParams.
Timing ) {
421 gettimeofday( &timeCatalogStart, NULL );
425 if ( sftlalcache == NULL ) {
446 struct stat fileStat;
447 if (
stat( cacheFileCheck, &fileStat ) < 0 ) {
449 fprintf( stderr,
" SFT cache file %s does not exist.\n", cacheFileCheck );
453 if ( fileStat.st_size == 0 ) {
455 fprintf( stderr,
" SFT cache file %s is empty.\n", cacheFileCheck );
462 CHAR *cacheFile = NULL;
466 if ( sievesfts->
length == 0 ) {
468 fprintf( stderr,
" no SFTs for this period.\n" );
475 for ( h = 0; h < sievesfts->
length; h++ ) {
479 if ( strncmp( sftptr,
"file://localhost/", strlen(
"file://localhost/" ) ) == 0 ) {
480 sftptr += strlen(
"file://localhost/" ) - 1;
483 if ( h < sievesfts->length - 1 ) {
494 if ( inputParams.
Timing ) {
495 gettimeofday( &timeCatalogEnd, NULL );
496 tCatalog = (
REAL8 )timeCatalogEnd.tv_usec * 1.e-6 + (
REAL8 )timeCatalogEnd.tv_sec - (
REAL8 )timeCatalogStart.tv_usec * 1.e-6 - (
REAL8 )timeCatalogStart.tv_sec;
497 TotalCatalogTime += tCatalog;
507 if ( catalog->
length == 0 ) {
515 TotalNSFTs += ( catalog->
length );
527 if ( inputParams.
Timing ) {
528 gettimeofday( &timeLoadStart, NULL );
538 REAL8 tAv = 0., fAp = 0., dtpow = 1.;
546 for ( h = 0; h < freqs->
length; h++ ) {
547 fAp += ( freqs->
data[h] * dtpow ) / gsl_sf_fact( h );
558 if ( inputParams.
Timing ) {
559 gettimeofday( &timeLoadEnd, NULL );
560 tLoad = (
REAL8 )timeLoadEnd.tv_usec * 1.e-6 + (
REAL8 )timeLoadEnd.tv_sec - (
REAL8 )timeLoadStart.tv_usec * 1.e-6 - (
REAL8 )timeLoadStart.tv_sec;
564 if ( SFTdat == NULL ) {
570 if ( inputParams.
Timing ) {
571 gettimeofday( &timeInterpolateStart, NULL );
575 for ( h = 0; h < numpulsars; h++ ) {
577 if ( ( fpout[h] = fopen( outputfilenames->
data[h],
"a" ) ) == NULL ) {
578 fprintf( stderr,
"Error... can't open output file %s!\n", outputfilenames->
data[h] );
583 if ( setvbuf( fpout[h], NULL, _IOFBF, 0x10000 ) ) {
584 fprintf( stderr,
"Warning: Unable to set output file buffer!" );
589 for ( sftnum = 0; sftnum < ( SFTdat->
length ); sftnum++ ) {
597 for ( h = 0; h < numpulsars; h++ ) {
599 REAL8 InterpolatedImagValue = 0., InterpolatedRealValue = 0.,
600 UnnormalisedInterpolatedImagValue = 0., UnnormalisedInterpolatedRealValue = 0.,
601 AbsSquaredWeightSum = 0;
604 REAL8 phaseShift = 0., fnew = 0., f1new = 0., sqrtf1new = 0.;
632 baryInput.
delta = baryDelta[h];
633 baryInput.
alpha = baryAlpha[h];
634 baryInput.
dInv = barydInv[h];
636 baryInputE.
delta = baryDelta[h];
637 baryInputE.
alpha = baryAlpha[h];
638 baryInputE.
dInv = barydInv[h];
640 baryInputS.
delta = baryDelta[h];
641 baryInputS.
alpha = baryAlpha[h];
642 baryInputS.
dInv = barydInv[h];
700 REAL8 totaltDot = 0., totaltDotstart = 0., totaltDotend = 0.;
701 REAL8 totaldeltaT = 0., totaldeltaTstart = 0., totaldeltaTend = 0.;
710 BinaryPulsarInput binInputS, binInputM, binInputE, binInputSP, binInputSM, binInputEP, binInputEM;
711 BinaryPulsarOutput binOutputS, binOutputM, binOutputE, binOutputSP, binOutputSM, binOutputEP, binOutputEM;
714 binInputS.
tb = timestamp + emitS.
deltaT;
715 binInputE.
tb = timestamp + 1. / deltaf + emitE.
deltaT;
716 binInputM.
tb = timestamp + 1. / ( 2.*deltaf ) + emit.
deltaT;
719 binInputSM.
tb = timestamp + emitS.
deltaT - 1;
720 binInputSP.
tb = timestamp + emitS.
deltaT + 1;
721 binInputEM.
tb = timestamp + 1. / deltaf + emitE.
deltaT - 1;
722 binInputEP.
tb = timestamp + 1. / deltaf + emitE.
deltaT + 1;
724 binInputS.
earth = earthS;
725 binInputE.
earth = earthE;
726 binInputM.
earth = earth;
728 binInputSP.
earth = earthS;
729 binInputEP.
earth = earthE;
730 binInputSM.
earth = earthS;
731 binInputEM.
earth = earthE;
749 totaltDotend = emitE.
tDot + ( binOutputEP.
deltaT - binOutputEM.
deltaT ) / 2;
750 totaltDotstart = emitS.
tDot + ( binOutputSP.
deltaT - binOutputSM.
deltaT ) / 2;
753 totaldeltaT = emit.
deltaT;
754 totaldeltaTend = emitE.
deltaT;
755 totaldeltaTstart = emitS.
deltaT;
757 totaltDot = emit.
tDot;
758 totaltDotend = emitE.
tDot;
759 totaltDotstart = emitS.
tDot;
764 tdt = timestamp - pepoch + 1. / ( 2.*deltaf ) + totaldeltaT;
765 tdtS = timestamp - pepoch + totaldeltaTstart;
766 tdtE = timestamp - pepoch + 1. / ( 2.*deltaf ) + totaldeltaTend;
770 fnew = 0., phaseShift = 0.;
771 REAL8 fstart = 0., fend = 0.;
772 REAL8 dtpow = 1., dtspow = 1., dtepow = 1.;
776 fnew += ( freqs->
data[
k] * dtpow ) / gsl_sf_fact(
k );
780 fstart += ( freqs->
data[
k] * dtspow ) / gsl_sf_fact(
k );
784 fend += ( freqs->
data[
k] * dtepow ) / gsl_sf_fact(
k );
788 phaseShift += ( freqs->
data[
k] * dtpow ) / gsl_sf_fact(
k + 1 );
790 fnew *= ( inputParams.
freqfactor * totaltDot );
791 fstart *= ( inputParams.
freqfactor * totaltDotstart );
792 fend *= ( inputParams.
freqfactor * totaltDotend );
795 if ( ( fnew < inputParams.
startF ) || ( fnew > inputParams.
endF ) ) {
796 fprintf( stderr,
"Pulsar %s has frequency %.4f outside of the frequency range %f-%f at time %.0f\n",
802 f1new = ( fend - fstart ) * deltaf;
804 sqrtf1new = sqrt( fabs( f1new ) );
805 REAL8 signf1new = f1new / fabs( f1new );
807 UINT4 dataLength = 0, dpNum = 0;
811 - ( fnew - inputParams.
bandwidth / 2. - SFTdat->
data->
f0 ) / deltaf ) );
814 if ( dataLength < 1 ) {
820 REAL8Vector *dataFreqs = NULL, *ReDp = NULL, *ImDp = NULL, *ReMu = NULL, *ImMu = NULL, *MuMu = NULL;
834 REAL8 ReStdDev = 0., ImStdDev = 0., StdDev = 0., ReStdDevSum = 0., ImStdDevSum = 0.;
839 datapoint <=
ROUND( ( fnew + inputParams.
bandwidth / 2. - SFTdat->
data->
f0 ) / deltaf ); datapoint++ ) {
842 ReDp->data[dpNum] = creal( SFTdat->
data[sftnum].
data->
data[datapoint] );
844 ImDp->data[dpNum] = cimag( SFTdat->
data[sftnum].
data->
data[datapoint] );
846 dataFreqs->
data[dpNum] = SFTdat->
data->
f0 + datapoint * deltaf;
848 ReStdDevSum += ( ReDp->data[dpNum] ) * ( ReDp->data[dpNum] );
850 ImStdDevSum += ( ImDp->data[dpNum] ) * ( ImDp->data[dpNum] );
856 ReStdDev = sqrt( ReStdDevSum / ( dataLength - 1 ) );
857 ImStdDev = sqrt( ImStdDevSum / ( dataLength - 1 ) );
859 StdDev = sqrt( ReStdDev * ReStdDev + ImStdDev * ImStdDev ) / 2;
863 for ( dpNum = 0; dpNum < dataFreqs->
length; dpNum++ ) {
864 if ( ( ( fabs( ReDp->data[dpNum] ) < 2 * inputParams.
stddevthresh * StdDev &&
865 fabs( ImDp->data[dpNum] ) < 2 * inputParams.
stddevthresh * StdDev ) ||
867 ( fabs( dataFreqs->
data[dpNum] - fnew ) < 5 * deltaf ) ) {
868 dpUsed->
data[dpNum] = 1;
871 dpUsed->
data[dpNum] = 0;
879 if ( fabs( f1new ) / ( deltaf * deltaf ) > 0.1 ) {
880 for ( dpNum = 0; dpNum < dataLength; dpNum++ ) {
882 if ( dpUsed->
data[dpNum] == 1 ) {
883 REAL8 FresPlusC = 0., FresMinC = 0., FresPlusS = 0., FresMinS = 0., delPhase = 0.;
885 delPhase = phaseShift -
LAL_PI * ( fnew - dataFreqs->
data[dpNum] ) * ( fnew - dataFreqs->
data[dpNum] ) / f1new
886 -
LAL_PI * ( dataFreqs->
data[dpNum] ) / deltaf;
892 ReMu->data[dpNum] = 1 / (
LAL_SQRT2 * sqrtf1new ) * ( cos( delPhase ) * ( FresPlusC - FresMinC )
893 - signf1new * sin( delPhase ) * ( FresPlusS - FresMinS ) );
895 ImMu->data[dpNum] = 1 / (
LAL_SQRT2 * sqrtf1new ) * ( sin( delPhase ) * ( FresPlusC - FresMinC )
896 + signf1new * cos( delPhase ) * ( FresPlusS - FresMinS ) );
898 MuMu->data[dpNum] = 1 / ( 2 * fabs( f1new ) ) * ( ( FresPlusC - FresMinC ) * ( FresPlusC - FresMinC )
899 + ( FresPlusS - FresMinS ) * ( FresPlusS - FresMinS ) );
911 if ( fmod( ( fnew - SFTdat->
data->
f0 ), deltaf ) < ( 0.01 * deltaf ) ||
912 fmod( ( fnew - SFTdat->
data->
f0 ), deltaf ) > ( 0.99 * deltaf ) ) {
913 for ( dpNum = 0; dpNum < dataLength; dpNum++ ) {
916 ReMu->data[dpNum] = cos( phaseShift -
LAL_PI * dataFreqs->
data[dpNum] / deltaf ) / deltaf;
917 ImMu->data[dpNum] = sin( phaseShift -
LAL_PI * dataFreqs->
data[dpNum] / deltaf ) / deltaf;
918 MuMu->data[dpNum] = 1 / ( deltaf * deltaf );
921 ReMu->data[dpNum] = 0;
922 ImMu->data[dpNum] = 0;
923 MuMu->data[dpNum] = 0;
931 for ( dpNum = 0; dpNum < dataLength; dpNum++ ) {
933 if ( dpUsed->
data[dpNum] == 1 ) {
935 ReMu->data[dpNum] = 1 / ( deltaf ) *
SINC( ( dataFreqs->
data[dpNum] - fnew ) / deltaf )
936 * cos( phaseShift -
LAL_PI * dataFreqs->
data[dpNum] / deltaf );
938 ImMu->data[dpNum] = 1 / ( deltaf ) *
SINC( ( dataFreqs->
data[dpNum] - fnew ) / deltaf )
939 * sin( phaseShift -
LAL_PI * dataFreqs->
data[dpNum] / deltaf );
941 MuMu->data[dpNum] = 1. / ( deltaf * deltaf ) *
SINC( ( dataFreqs->
data[dpNum] - fnew ) / deltaf )
942 *
SINC( ( dataFreqs->
data[dpNum] - fnew ) / deltaf );
956 REAL8Vector *ReResiduals = NULL, *ImResiduals = NULL, *ReHf = NULL, *ImHf = NULL;
967 REAL8 ResStdDev = 0.;
970 UINT4 numReduced = 1;
974 while ( numReduced ) {
975 UINT4 dpCountStart = 0, dpCountEnd = 0;
977 for ( dpNum = 0; dpNum < dataLength; dpNum++ ) {
978 dpCountStart += dpUsed->
data[dpNum];
982 for ( dpNum = 0; dpNum < dataLength; dpNum++ ) {
984 if ( dpUsed->
data[dpNum] == 1 ) {
986 REAL8 ReVal = 0., ImVal = 0;
988 ReVal = ReDp->data[dpNum] * ReMu->data[dpNum] + ImDp->data[dpNum] * ImMu->data[dpNum];
989 ImVal = ImDp->data[dpNum] * ReMu->data[dpNum] - ReDp->data[dpNum] * ImMu->data[dpNum];
990 AbsSquaredWeightSum += MuMu->data[dpNum];
992 UnnormalisedInterpolatedRealValue += ReVal;
993 UnnormalisedInterpolatedImagValue += ImVal;
1000 InterpolatedRealValue = UnnormalisedInterpolatedRealValue / AbsSquaredWeightSum;
1001 InterpolatedImagValue = UnnormalisedInterpolatedImagValue / AbsSquaredWeightSum;
1004 REAL8 ResReStdDev = 0., ResImStdDev = 0., ResReStdDevSum = 0., ResImStdDevSum = 0.;
1007 for ( dpNum = 0; dpNum < dataLength; dpNum++ ) {
1009 if ( dpUsed->
data[dpNum] == 1 ) {
1012 ReHf->data[dpNum] = InterpolatedRealValue * ReMu->data[dpNum] - InterpolatedImagValue * ImMu->data[dpNum];
1013 ImHf->data[dpNum] = InterpolatedImagValue * ReMu->data[dpNum] + InterpolatedRealValue * ImMu->data[dpNum];
1016 ReResiduals->
data[dpNum] = ReDp->data[dpNum] - ReHf->data[dpNum];
1017 ImResiduals->data[dpNum] = ImDp->data[dpNum] - ImHf->data[dpNum];
1019 ResReStdDevSum += ReResiduals->
data[dpNum] * ReResiduals->
data[dpNum];
1020 ResImStdDevSum += ImResiduals->data[dpNum] * ImResiduals->data[dpNum];
1027 ResReStdDev = sqrt( ResReStdDevSum / ( dpCountStart - 1 ) );
1028 ResImStdDev = sqrt( ResImStdDevSum / ( dpCountStart - 1 ) );
1031 ResStdDev = sqrt( ResReStdDev * ResReStdDev + ResImStdDev * ResImStdDev ) / 2;
1034 for ( dpNum = 0; dpNum < dataFreqs->
length; dpNum++ ) {
1036 if ( dpUsed->
data[dpNum] == 1 ) {
1038 if ( ( fabs( ReResiduals->
data[dpNum] ) < inputParams.
stddevthresh * ( ResStdDev ) &&
1039 fabs( ImResiduals->data[dpNum] ) < inputParams.
stddevthresh * ( ResStdDev ) ) ||
1041 ( fabs( dataFreqs->
data[dpNum] - fnew ) < 2 * deltaf ) ) {
1042 dpUsed->
data[dpNum] = 1;
1044 dpUsed->
data[dpNum] = 0;
1051 for ( dpNum = 0; dpNum < dataLength; dpNum++ ) {
1052 dpCountEnd += dpUsed->
data[dpNum];
1056 if ( dpCountStart == dpCountEnd ) {
1076 fprintf( fpout[h],
"%.0f\t%.6e\t%.6e\t%.6e\n", timestamp + 1. / ( 2.*deltaf ), InterpolatedRealValue
1077 , InterpolatedImagValue, ResStdDev * deltaf *
LAL_SQRT2 );
1082 if ( inputParams.
Timing ) {
1083 gettimeofday( &timeInterpolateEnd, NULL );
1084 tInterpolate = (
REAL8 )timeInterpolateEnd.tv_usec * 1.e-6 + (
REAL8 )timeInterpolateEnd.tv_sec - (
REAL8 )timeInterpolateStart.tv_usec * 1.e-6 - (
REAL8 )timeInterpolateStart.tv_sec;
1089 if ( inputParams.
Timing ) {
1090 fprintf( stderr,
" done. Number of SFTs = %d. Obtaining Catalog took %.5fs, SFT Load took %.5fs, Interpolation took %.5fs.\n",
1091 (
INT4 )( SFTdat->
length ), tCatalog, tLoad, tInterpolate );
1092 TotalInterTime += tInterpolate;
1093 TotalLoadTime += tLoad;
1095 fprintf( stderr,
" done.\n" );
1099 for ( h = 0; h < numpulsars; h++ ) {
1109 if ( sftlalcache != NULL ) {
1113 REAL8 tPre = 0., tPul = 0.;
1114 if ( inputParams.
Timing ) {
1115 tPre = (
REAL8 )timePreEnd.tv_usec * 1.e-6 + (
REAL8 )timePreEnd.tv_sec - (
REAL8 )timePreStart.tv_usec * 1.e-6 - (
REAL8 )timePreStart.tv_sec;
1116 tPul = (
REAL8 )timePulEnd.tv_usec * 1.e-6 + (
REAL8 )timePulEnd.tv_sec - (
REAL8 )timePulStart.tv_usec * 1.e-6 - (
REAL8 )timePulStart.tv_sec;
1119 fprintf( stderr,
"Spectral Interpolation Complete.\n" );
1122 if ( inputParams.
Timing ) {
1123 fprintf( stderr,
":\nPre-Interpolation things took %.5fs, of which source parameter load time was %.5fs\nTotal Number of SFTs = %d\nTotal catalog time %.5fs\nTotal SFT Load time %.5fs\nTotal Interpolation time %.5fs.\n", tPre, tPul, TotalNSFTs, TotalCatalogTime, TotalLoadTime, TotalInterTime );
1127 fprintf( stderr,
"\nPerforming Outlier Removal routine with noise threshold of %.5f", inputParams.
stddevthresh );
1128 struct timeval timeORStart, timeOREnd;
1129 if ( inputParams.
Timing ) {
1130 gettimeofday( &timeORStart, NULL );
1133 for ( h = 0; h < numpulsars; h++ ) {
1134 FILE *BkFile = NULL;
1135 BkFile = fopen( outputfilenames->
data[h],
"r" );
1136 if ( BkFile == NULL ) {
1144 REAL8Vector *ReData = NULL, *ImData = NULL, *NData = NULL;
1154 while ( !feof( BkFile ) &&
k < TotalNSFTs ) {
1155 offset = ftell( BkFile );
1157 if (
fscanf( BkFile,
"%s", jnkstr ) == EOF ) {
1162 fseek( BkFile, offset, SEEK_SET );
1165 &ImData->data[
k], &NData->data[
k] ) == EOF ) {
1173 FILE *BkFileOut = NULL;
1174 BkFileOut = fopen( outputfilenames->
data[h],
"w" );
1177 REAL8 meanNoiseEst = 0, meanAbsValue = 0.;
1181 if ( setvbuf( BkFileOut, NULL, _IOFBF, 0x10000 ) ) {
1182 fprintf( stderr,
"Warning: Unable to set output file buffer!" );
1185 for (
p = 0;
p < NData->length;
p++ ) {
1186 meanAbsValue += sqrt( ReData->
data[
p] * ReData->
data[
p] + ImData->data[
p] * ImData->data[
p] ) / NData->length;
1187 meanNoiseEst += NData->data[
p] / NData->length;
1192 for (
p = 0;
p < startlen;
p++ ) {
1194 fabs( ImData->data[
p] ) < meanAbsValue * inputParams.
stddevthresh &&
1195 NData->data[
p] < meanNoiseEst * inputParams.
stddevthresh ) {
1197 ImData->data[
j] = ImData->data[
p];
1198 NData->data[
j] = NData->data[
p];
1203 if (
j != startlen ) {
1210 for (
p = 0;
p < NData->length;
p++ ) {
1211 meanNoiseEst += NData->data[
p] / NData->length;
1212 meanAbsValue += sqrt( ReData->
data[
p] * ReData->
data[
p] + ImData->data[
p] * ImData->data[
p] ) / NData->length;
1216 for (
p = 0;
p < ReData->
length;
p++ ) {
1218 fabs( ImData->data[
p] ) < meanAbsValue * inputParams.
stddevthresh &&
1219 NData->data[
p] < meanNoiseEst * inputParams.
stddevthresh ) {
1221 ImData->data[
j] = ImData->data[
p];
1222 NData->data[
j] = NData->data[
p];
1239 for (
p = 0;
p < ReData->
length;
p++ ) {
1241 fprintf( BkFileOut,
"%d\t%.6e\t%.6e\t%.6e\n", timeStamp->
data[
p], ReData->
data[
p]
1242 , ImData->data[
p], NData->data[
p] );
1245 fclose( BkFileOut );
1254 fprintf( stderr,
" done.\n" );
1255 if ( inputParams.
Timing ) {
1256 gettimeofday( &timeOREnd, NULL );
1258 if ( inputParams.
Timing ) {
1259 REAL8 tOR = (
REAL8 )timeOREnd.tv_usec * 1.e-6 + (
REAL8 )timeOREnd.tv_sec - (
REAL8 )timeORStart.tv_usec * 1.e-6 - (
REAL8 )timeORStart.tv_sec;
1260 fprintf( stderr,
"Outlier Removal took %.5fs", tOR );
1264 if ( inputParams.
gzip ) {
1266 for ( h = 0; h < numpulsars; h++ ) {
1268 XLALPrintError(
"Error... problem gzipping the output file.\n" );
1273 for ( h = 0; h < numpulsars; h++ ) {
1281 if ( inputParams.
Timing ) {
1282 gettimeofday( &timeEndTot, NULL );
1283 REAL8 tTot = (
REAL8 )timeEndTot.tv_usec * 1
e-6 + (
REAL8 )timeEndTot.tv_sec - (
REAL8 )timePreTot.tv_usec * 1
e-6 - (
REAL8 )timePreTot.tv_sec;
1284 fprintf( stderr,
"Total time taken: %.5fs\n", tTot );
1293 struct option long_options[] = {
1321 char args[] =
"hi:F:C:L:d:P:N:o:e:l:S:E:m:b:M:Z:s:f:T:ntgBG";
1330 inputParams->
endF = 0.;
1331 inputParams->
startF = 0.;
1336 inputParams->
endTime = INFINITY;
1337 inputParams->
Timing = 0.;
1342 inputParams->
gzip = 0;
1346 int option_index = 0;
1349 c = getopt_long( argc, argv,
args, long_options, &option_index );
1359 snprintf( inputParams->
ifo,
sizeof( inputParams->
ifo ),
"%s", optarg );
1371 inputParams->
startF = atof( optarg );
1374 inputParams->
endF = atof( optarg );
1391 snprintf( inputParams->
PSRname,
sizeof( inputParams->
PSRname ),
"%s",
1411 snprintf( inputParams->
segfile,
sizeof( inputParams->
segfile ),
"%s",
1419 inputParams->
bandwidth = atof( optarg );
1422 inputParams->
startTime = atof( optarg );
1425 inputParams->
endTime = atof( optarg );
1440 inputParams->
gzip = 1;
1443 fprintf( stderr,
"unknown error while parsing options\n" );
1446 fprintf( stderr,
"unknown error while parsing options\n" );
1458 REAL8 a, absx, fact, sign, sum, sumc, sums, term, test;
1478 sum += sign * term /
n;
1488 if ( term < test ) {
1501 b = 1.0 - I *
LAL_PI * absx * absx;
1509 d = 1. / (
a *
d + b );
1513 if ( fabs( creal( del ) - 1.0 ) + fabs( cimag( del ) ) <
XLAL_FRESNEL_EPS ) {
1521 h = ( absx - I * absx ) * h;
1522 cs = ( 0.5 + I * 0.5 ) * ( 1. - h * ( cos(
LAL_PI_2 * absx * absx ) + I * sin(
LAL_PI_2 * absx * absx ) ) );
1530 C = memcpy(
C, &FC,
sizeof(
REAL8 ) );
1531 S = memcpy( S, &
FS,
sizeof(
REAL8 ) );
void XLALBinaryPulsarDeltaTNew(BinaryPulsarOutput *output, BinaryPulsarInput *input, PulsarParameters *params)
function to calculate the binary system delay using new parameter structure
#define required_argument
const REAL8Vector * PulsarGetREAL8VectorParam(const PulsarParameters *pars, const CHAR *name)
Return a REAL8Vector parameter.
REAL8 PulsarGetREAL8ParamOrZero(const PulsarParameters *pars, const CHAR *name)
Return a REAL8 parameter if it exists, otherwise return zero.
int PulsarCheckParam(const PulsarParameters *pars, const CHAR *name)
Check for the existence of the parameter name in the PulsarParameters structure.
PulsarParameters * XLALReadTEMPOParFile(const CHAR *pulsarAndPath)
Read in the parameters from a TEMPO(2) parameter file into a PulsarParameters structure.
void PulsarClearParams(PulsarParameters *pars)
Free all the parameters from a PulsarParameters structure.
void PulsarAddParam(PulsarParameters *pars, const CHAR *name, void *value, PulsarParamType type)
Add a parameter and value to the PulsarParameters structure.
REAL8 PulsarGetREAL8Param(const PulsarParameters *pars, const CHAR *name)
Return a REAL8 parameter.
const CHAR * PulsarGetStringParam(const PulsarParameters *pars, const CHAR *name)
Return a string parameter.
REAL8 PulsarGetREAL8VectorParamIndividual(const PulsarParameters *pars, const CHAR *name)
Return an individual REAL8 value from a REAL8Vector parameter.
static SFTConstraints empty_SFTConstraints
int main(int argc, char **argv)
static LIGOTimeGPS empty_LIGOTimeGPS
void get_input_args(InputParams *inputParams, int argc, char *argv[])
INT4 XLALFresnel(REAL8 *C, REAL8 *S, REAL8 x)
#define XLAL_FRESNEL_XMIN
#define XLAL_FRESNEL_MAXIT
#define XLAL_FRESNEL_FPMIN
int XLALGzipTextFile(const char *path)
TimeCorrectionData * XLALInitTimeCorrections(const CHAR *timeCorrectionFile)
An XLAL interface for reading a time correction file containing a table of values for converting betw...
EphemerisData * XLALInitBarycenter(const CHAR *earthEphemerisFile, const CHAR *sunEphemerisFile)
XLAL interface to reading ephemeris files 'earth' and 'sun', and return ephemeris-data in old backwar...
int XLALBarycenter(EmissionTime *emit, const BarycenterInput *baryinput, const EarthState *earth)
Transforms from detector arrival time in GPS (as specified in the LIGOTimeGPS structure) to pulse em...
int XLALBarycenterEarthNew(EarthState *earth, const LIGOTimeGPS *tGPS, const EphemerisData *edat, const TimeCorrectionData *tdat, TimeCorrectionType ttype)
Computes the position and orientation of the Earth, at some arrival time, but unlike XLALBarycenterEa...
TimeCorrectionType
Enumerated type denoting the time system type to be produced in the solar system barycentring routine...
@ TIMECORRECTION_ORIGINAL
void XLALDestroyCache(LALCache *cache)
int XLALCacheUniq(LALCache *cache)
LALCache * XLALCacheImport(const char *fname)
LALCache * XLALCacheDuplicate(const LALCache *cache)
int XLALCacheSieve(LALCache *cache, INT4 t0, INT4 t1, const char *srcregex, const char *dscregex, const char *urlregex)
void * XLALMalloc(size_t n)
void * XLALRealloc(void *p, size_t n)
char char * XLALStringDuplicate(const char *s)
int char * XLALStringAppend(char *s, const char *append)
const LALDetector * XLALGetSiteInfo(const CHAR *name)
Find the site geometry-information 'LALDetector' for given a detector name (or prefix).
void XLALDestroySFTVector(SFTVector *vect)
XLAL interface to destroy an SFTVector.
void XLALDestroySFTCatalog(SFTCatalog *catalog)
Free an 'SFT-catalogue'.
LALSegList * XLALReadSegmentsFromFile(const char *fname)
Function to read a segment list from given filename, returns a sorted LALSegList.
LALStringVector * XLALFindFiles(const CHAR *globstring)
Returns a list of filenames matching the input argument, which may be one of the following:
SFTVector * XLALLoadSFTs(const SFTCatalog *catalog, REAL8 fMin, REAL8 fMax)
Load the given frequency-band [fMin, fMax) (half-open) from the SFT-files listed in the SFT-'catalogu...
SFTCatalog * XLALSFTdataFind(const CHAR *file_pattern, const SFTConstraints *constraints)
Find the list of SFTs matching the file_pattern and satisfying the given constraints,...
int XLALSegListFree(LALSegList *seglist)
void XLALDestroyStringVector(LALStringVector *vect)
LALStringVector * XLALAppendString2Vector(LALStringVector *vect, const CHAR *string)
REAL8Vector * XLALResizeREAL8Vector(REAL8Vector *vector, UINT4 length)
void XLALDestroyUINT4Vector(UINT4Vector *vector)
INT4Vector * XLALResizeINT4Vector(INT4Vector *vector, UINT4 length)
INT4Vector * XLALCreateINT4Vector(UINT4 length)
void XLALDestroyINT4Vector(INT4Vector *vector)
REAL8Vector * XLALCreateREAL8Vector(UINT4 length)
void XLALDestroyREAL8Vector(REAL8Vector *vector)
UINT4Vector * XLALCreateUINT4Vector(UINT4 length)
#define XLAL_CHECK(assertion,...)
int XLALPrintError(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
LIGOTimeGPS * XLALGPSSetREAL8(LIGOTimeGPS *epoch, REAL8 t)
REAL8 XLALGPSGetREAL8(const LIGOTimeGPS *epoch)
p
RUN ANALYSIS SCRIPT ###.
structure containing the output parameters for the binary delay function
REAL8 deltaT
deltaT to add to TDB in order to account for binary
A vector of COMPLEX8FrequencySeries.
COMPLEX8FrequencySeries * data
Pointer to the data array.
UINT4 length
Number of elements in array.
Basic output structure of LALBarycenterEarth.c.
Basic output structure produced by LALBarycenter.c.
REAL8 deltaT
(TDB) - (GPS)
REAL8 tDot
d(emission time in TDB)/d(arrival time in GPS)
This structure contains all information about the center-of-mass positions of the Earth and Sun,...
The PulsarParameters structure to contain a set of pulsar parameters.
An "SFT-catalogue": a vector of SFTdescriptors, as returned by XLALSFTdataFind()
SFTDescriptor * data
array of data-entries describing matched SFTs
UINT4 length
number of SFTs in catalog
'Constraints' for SFT-matching: which detector, within which time-stretch and which timestamps exactl...
CHAR * detector
2-char channel-prefix describing the detector (eg 'H1', 'H2', 'L1', 'G1' etc)
LIGOTimeGPS * maxStartTime
only include SFTs whose epoch is < maxStartTime
LIGOTimeGPS * minStartTime
only include SFTs whose epoch is >= minStartTime
SFTtype header
SFT-header info.
UINT4 numBins
number of frequency-bins in this SFT
This structure will contain a vector of time corrections used during conversion from TT to TDB/TCB/Te...