55#include <lal/LALFrStream.h>
56#include <lal/LALFrameIO.h>
57#include <lal/LALCache.h>
58#include <lal/TimeSeries.h>
59#include <lal/LALStdlib.h>
60#include <lal/AVFactories.h>
61#include <lal/UserInput.h>
62#include <lal/GeneratePulsarSignal.h>
63#include <lal/LALInitBarycenter.h>
64#include <lal/LALDatatypes.h>
65#include <lal/DetectorSite.h>
67#include <lal/SkyCoordinates.h>
68#include <lal/RngMedBias.h>
69#include <lal/LALRunningMedian.h>
70#include <lal/BinaryPulsarTiming.h>
71#include <lal/LogPrintf.h>
72#include <lal/LALString.h>
73#include <lal/LALPulsarVCSInfo.h>
75#define STRINGLENGTH 256
102int main(
int argc,
char **argv )
118 result =
time( NULL );
119 struct tm *btm = localtime( &result );
126 strncpy( logfiledir, ( strrchr( uvar->gwfdir,
'/' ) + 1 ), 5 );
127 logfiledir[5] =
'\0';
129 sprintf( log_file,
"%s/%s/injections-%s.log", uvar->outputdir, uvar->logDir, logfiledir );
133 if ( ( logfile = fopen( log_file,
"a" ) ) == NULL ) {
134 fprintf( stderr,
"Error opening .log file! \n" );
137 fprintf( logfile,
"\nsw_inj_frames.c version number: %s\nCurrent time: %s \n",
version, asctime( btm ) );
138 fprintf( logfile,
"User inputs:\n Sample rate: %f\n Pulsar file directory: %s\n Raw frame file directory: %s\n Output directory: %s\n \n Name of directory for log (w/in output dir): %s\n IFO: %s\n", uvar->srate, uvar->inputdir, uvar->gwfdir, uvar->outputdir, uvar->logDir, uvar->IFO );
143 struct dirent **parnamelist;
144 struct dirent **gwfnamelist;
156 XLALPrintError(
"%s: Failed to get site-info for detector '%s'\n", fn, uvar->IFO );
171 sprintf( in_chan,
"%s:LDAS-STRAIN", uvar->IFO );
175 sprintf( out_chan,
"%s:CWINJ_TOT", uvar->IFO );
179 sprintf( inj_chan,
"%s:CWINJ_SIG", uvar->IFO );
182 if ( ( logfile = fopen( log_file,
"a" ) ) == NULL ) {
183 fprintf( stderr,
"Error opening .log file! \n" );
186 fprintf( logfile,
"Channels:\n Reading from raw: %s\n Injection+noise: %s\n Pure injection: %s\n", in_chan, out_chan, inj_chan );
199 sprintf( gwf_dir,
"%s/.", uvar->gwfdir );
208 int n = scandir( uvar->inputdir, &parnamelist, 0, alphasort );
210 XLALPrintError(
"%s: scandir() failed for directory '%s'\n", fn, uvar->inputdir );
221 free( parnamelist[0] );
222 free( parnamelist[1] );
224 for ( h = 2; h < numParFiles; h++ ) {
225 if ( strstr( parnamelist[h]->d_name,
".par" ) == NULL ) {
227 free( parnamelist[h] );
232 if ( ( logfile = fopen( log_file,
"a" ) ) == NULL ) {
233 fprintf( stderr,
"Error opening .log file! \n" );
236 sprintf( parname,
"%s/%s", uvar->inputdir, parnamelist[h]->d_name );
239 if ( !
stat( parname, &b ) ) {
240 strftime(
t, 100,
"%d/%m/%Y %H:%M:%S", localtime( &b.st_mtime ) );
241 fprintf( logfile,
"%s/%s Last Modified: %s\n", uvar->inputdir, parnamelist[h]->d_name,
t );
249 if ( ( inject = fopen( parname,
"r" ) ) == NULL ) {
250 fprintf( stderr,
"Error opening file: %s\n", parname );
261 free( parnamelist[h] );
269 if ( (
m = scandir( uvar->gwfdir, &gwfnamelist, 0, alphasort ) ) == -1 ) {
270 XLALPrintError(
"%s: scandir('%s',...) failed.\n", fn, uvar->gwfdir );
274 free( gwfnamelist[0] );
275 free( gwfnamelist[1] );
279 if ( strstr( gwfnamelist[
k]->d_name,
".gwf" ) == NULL ) {
281 free( gwfnamelist[
k] );
287 if ( ( gwffile =
XLALFrStreamOpen( uvar->gwfdir, gwfnamelist[
k]->d_name ) ) == NULL ) {
292 char framefilename[256];
293 sprintf( framefilename,
"%s/%s/failed_frames.txt", uvar->outputdir, uvar->logDir );
294 if ( ( frames = fopen( framefilename,
"a" ) ) == NULL ) {
295 fprintf( stderr,
"Error opening file %s! \n", framefilename );
298 fprintf( frames,
"%s\n", gwfnamelist[
k]->d_name );
305 if ( ( logfile = fopen( log_file,
"a" ) ) == NULL ) {
306 fprintf( stderr,
"Error opening .log file! \n" );
309 fprintf( logfile,
"Read file %s/%s\n", uvar->gwfdir, gwfnamelist[
k]->d_name );
319 strncpy( strepoch, strchr( gwfnamelist[
k]->d_name,
'9' ), 9 );
321 epoch.gpsSeconds = atoi( strepoch );
322 epoch.gpsNanoSeconds = 0;
326 strncpy( strdur, ( strrchr( gwfnamelist[
k]->d_name,
'-' ) + 1 ), 3 );
329 ndata = atoi( strdur );
332 if ( ( logfile = fopen( log_file,
"a" ) ) == NULL ) {
333 fprintf( stderr,
"Error opening .log file! \n" );
336 fprintf( logfile,
"Using epoch: %i and duration: %i\n",
epoch.gpsSeconds, ndata );
349 char framefilename[256];
350 sprintf( framefilename,
"%s/%s/failed_frames.txt", uvar->outputdir, uvar->logDir );
351 if ( ( frames = fopen( framefilename,
"a" ) ) == NULL ) {
352 fprintf( stderr,
"Error opening file %s! \n", framefilename );
355 fprintf( frames,
"%s\n", gwfnamelist[
k]->d_name );
371 if ( ( logfile = fopen( log_file,
"a" ) ) == NULL ) {
372 fprintf( stderr,
"Error opening .log file! \n" );
375 fprintf( logfile,
"Writing to %s/%s\n", uvar->outputdir, out_file );
396 snprintf( fffile,
STRINGLENGTH,
"%s/%s", uvar->outputdir, out_file );
398 if ( ( filetest = fopen( fffile,
"w+" ) ) == NULL ) {
412 for ( counter = 0; counter < total_inject->
data->
length; counter++ ) {
413 total_inject->
data->
data[counter] = 0;
417 n = scandir( uvar->inputdir, &parnamelist, 0, alphasort );
419 XLALPrintError(
"%s: scandir() failed for directory '%s'\n", fn, uvar->inputdir );
425 for ( h = 0; h < numParFiles; h++ ) {
426 if ( strstr( parnamelist[h]->d_name,
".par" ) == NULL ) {
429 free( parnamelist[h] );
460 REAL8 ra = 0., dec = 0.;
483 for (
UINT4 kk = 0; kk < 3; kk++ ) {
486 params.pulsar.spindown->data[kk] = 2.*fs->
data[kk + 1];
488 params.pulsar.spindown->data[kk] = 0.;
499 params.pulsar.aPlus = 0.5 *
h0 * ( 1. + cosiota * cosiota );
500 params.pulsar.aCross =
h0 * cosiota;
513 w = atan2( eps1, eps2 );
514 e = sqrt( eps1 * eps1 + eps2 * eps2 );
522 REAL8 fe, uasc, Dt, T0val = 0.;
523 fe = sqrt( ( 1.0 -
params.orbit.ecc ) / ( 1.0 +
params.orbit.ecc ) );
524 uasc = 2.0 * atan( fe * tan(
params.orbit.argp / 2.0 ) );
546 if (
status.statusCode ) {
547 if ( ( logfile = fopen( log_file,
"a" ) ) == NULL ) {
548 fprintf( stderr,
"Error opening .log file! \n" );
551 fprintf( logfile,
"LAL Routine failed at pulsar %s\n", pulin );
555 fprintf( stderr,
"LAL Routine failed\n" );
569 free( parnamelist[h] );
616 free( gwfnamelist[
k] );
619 if ( ( logfile = fopen( log_file,
"a" ) ) == NULL ) {
620 fprintf( stderr,
"Error opening .log file! \n" );
623 fprintf( logfile,
"%s created successfully!\n", out_file );
697static int charcmp(
const void *c1,
const void *c2 )
699 char a = *(
const char * )
c1;
700 char b = *(
const char * )
c2;
701 return (
a > b ) - (
a < b );
717 for ( cs = chname; *cs; cs += 2 ) {
724 if ( strlen( cs ) <= 2 || !isupper( cs[0] ) || !isdigit( cs[1] ) ) {
734 detflgs |= 1 << 2 *
d;
735 strncat(
site, cs, 1 );
742 for ( cs =
s =
site; *
s; ++cs )
751 if ( !isalnum( *
s ) ) {
#define __func__
log an I/O error, i.e.
const LALVCSInfoList lalPulsarVCSInfoList
NULL-terminated list of VCS and build information for LALPulsar and its dependencies
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 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.
const LALDetector lalCachedDetectors[LAL_NUM_DETECTORS]
void LALGeneratePulsarSignal(LALStatus *status, REAL4TimeSeries **signalvec, const PulsarSignalParams *params)
EphemerisData * XLALInitBarycenter(const CHAR *earthEphemerisFile, const CHAR *sunEphemerisFile)
XLAL interface to reading ephemeris files 'earth' and 'sun', and return ephemeris-data in old backwar...
void XLALDestroyEphemerisData(EphemerisData *edat)
Destructor for EphemerisData struct, NULL robust.
#define XLAL_LAST_ELEM(x)
#define XLAL_INIT_DECL(var,...)
int XLALFrStreamClose(LALFrStream *stream)
LALFrStream * XLALFrStreamOpen(const char *dirname, const char *pattern)
int XLALFrStreamGetREAL8TimeSeries(REAL8TimeSeries *series, LALFrStream *stream)
LALFrameUFrameH LALFrameH
int XLALFrameWrite(LALFrameH *frame, const char *fname)
LALFrameH * XLALFrameNew(const LIGOTimeGPS *epoch, double duration, const char *project, int run, int frnum, INT8 detectorFlags)
void XLALFrameFree(LALFrameH *frame)
int XLALFrameAddREAL8TimeSeriesProcData(LALFrameH *frame, const REAL8TimeSeries *series)
char char * XLALStringDuplicate(const char *s)
void LogPrintf(LogLevel_t, const char *format,...) _LAL_GCC_PRINTF_FORMAT_(2
const LALDetector * XLALGetSiteInfo(const CHAR *name)
Find the site geometry-information 'LALDetector' for given a detector name (or prefix).
COORDINATESYSTEM_EQUATORIAL
void XLALDestroyREAL8TimeSeries(REAL8TimeSeries *series)
void XLALDestroyREAL4TimeSeries(REAL4TimeSeries *series)
REAL8TimeSeries * XLALCreateREAL8TimeSeries(const CHAR *name, const LIGOTimeGPS *epoch, REAL8 f0, REAL8 deltaT, const LALUnit *sampleUnits, size_t length)
const LALUnit lalSecondUnit
REAL8Vector * XLALCreateREAL8Vector(UINT4 length)
void XLALDestroyREAL8Vector(REAL8Vector *vector)
#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)
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.
Input parameters to GeneratePulsarSignal(), defining the source and the time-series.
int XLALFrameFileName(char *fname, size_t size, const char *chname, const LIGOTimeGPS *epoch, double duration)
int main(int argc, char **argv)
int InitUserVars(UserInput_t *uvar, int argc, char **argv)
Function to register and read all user input.
static int charcmp(const void *c1, const void *c2)