Commit 48dc4935 authored by David Keitel's avatar David Keitel

refactor write_transientCandidateAll_to_fp()

 -new function write_transientFstatMap_to_fp()
  with more atomic inputs, useful for SWIG usage
 -write_transientCandidateAll_to_fp() now just a wrapper
 -closes #5616
Original: c8e513ffab5b95db4ce01e27fc77ee42fd8d94be
parent e8c2fb11
......@@ -1013,55 +1013,103 @@ write_transientCandidate_to_fp ( FILE *fp, const transientCandidate_t *thisCand,
/**
* Write full set of t0 and tau grid points for given transient CW candidate into output file.
* Write full set of t0 and tau grid points (assumed at fixed Doppler parameters) into output file.
*
* NOTE: if input thisCand == NULL, we write a header comment-line explaining the fields
* NOTE: if input FstatMap == NULL, we write a header comment-line explaining the fields
*
* if doppler = NULL, we skip those columns
*
*/
int
write_transientCandidateAll_to_fp ( FILE *fp, const transientCandidate_t *thisCand )
int write_transientFstatMap_to_fp ( FILE *fp, const transientFstatMap_t *FstatMap, const transientWindowRange_t *windowRange, const PulsarDopplerParams *doppler )
{
/* sanity checks */
if ( !fp ) {
XLALPrintError ( "%s: invalid NULL filepointer input.\n", __func__ );
XLAL_ERROR ( XLAL_EINVAL );
}
if ( thisCand == NULL ) /* write header-line comment */
if ( !FstatMap ) /* write header-line comment */
{
fprintf (fp, "%%%% Freq[Hz] Alpha[rad] Delta[rad] fkdot[1] fkdot[2] fkdot[3] t0[s] tau[s] twoF\n");
if ( !doppler )
{
fprintf (fp, "%%%% t0[s] tau[s] twoF\n");
}
else
{
fprintf (fp, "%%%% Freq[Hz] Alpha[rad] Delta[rad] fkdot[1] fkdot[2] fkdot[3] t0[s] tau[s] twoF\n");
}
}
else
{
if ( !thisCand->FstatMap ) {
XLALPrintError ("%s: incomplete: transientCand->FstatMap == NULL!\n", __func__ );
if ( !windowRange ) {
XLALPrintError ( "%s: invalid NULL windowRange input.\n", __func__ );
XLAL_ERROR ( XLAL_EINVAL );
}
UINT4 t0 = thisCand->windowRange.t0;
UINT4 t0 = windowRange->t0;
UINT4 N_t0Range = (UINT4) floor ( windowRange->t0Band / windowRange->dt0 ) + 1;
UINT4 N_tauRange = (UINT4) floor ( windowRange->tauBand / windowRange->dtau ) + 1;
UINT4 N_t0Range = (UINT4) floor ( thisCand->windowRange.t0Band / thisCand->windowRange.dt0 ) + 1;
UINT4 N_tauRange = (UINT4) floor ( thisCand->windowRange.tauBand / thisCand->windowRange.dtau ) + 1;
LogPrintf ( LOG_DETAIL, "N_t0Range=%d, N_tauRange=%d\n", N_t0Range, N_tauRange);
/* ----- OUTER loop over start-times [t0,t0+t0Band] ---------- */
for ( UINT4 m = 0; m < N_t0Range; m ++ ) /* m enumerates 'binned' t0 start-time indices */
{
UINT4 this_t0 = t0 + m * thisCand->windowRange.dt0;
UINT4 this_t0 = t0 + m * windowRange->dt0;
/* ----- INNER loop over timescale-parameter tau ---------- */
for ( UINT4 n = 0; n < N_tauRange; n ++ )
{
UINT4 this_tau = thisCand->windowRange.tau + n * thisCand->windowRange.dtau;
fprintf (fp, " %- 18.16f %- 19.16f %- 19.16f %- 9.6g %- 9.5g %- 9.5g %10d %10d %- 11.8g\n",
thisCand->doppler.fkdot[0], thisCand->doppler.Alpha, thisCand->doppler.Delta,
thisCand->doppler.fkdot[1], thisCand->doppler.fkdot[2], thisCand->doppler.fkdot[3],
this_t0, this_tau, 2.0 * gsl_matrix_get ( thisCand->FstatMap->F_mn, m, n )
);
UINT4 this_tau = windowRange->tau + n * windowRange->dtau;
if ( !doppler )
{
fprintf (fp, " %10d %10d %- 11.8g\n",
this_t0, this_tau, 2.0 * gsl_matrix_get ( FstatMap->F_mn, m, n )
);
}
else
{
fprintf (fp, " %- 18.16f %- 19.16f %- 19.16f %- 9.6g %- 9.5g %- 9.5g %10d %10d %- 11.8g\n",
doppler->fkdot[0], doppler->Alpha, doppler->Delta,
doppler->fkdot[1], doppler->fkdot[2], doppler->fkdot[3],
this_t0, this_tau, 2.0 * gsl_matrix_get ( FstatMap->F_mn, m, n )
);
}
}
}
}
return XLAL_SUCCESS;
} /* write_transientFstatMap_to_fp() */
/**
* Write full set of t0 and tau grid points for given transient CW candidate into output file.
*
* NOTE: if input thisCand == NULL, we write a header comment-line explaining the fields
*
*/
int
write_transientCandidateAll_to_fp ( FILE *fp, const transientCandidate_t *thisCand )
{
/* sanity checks */
if ( !fp ) {
XLALPrintError ( "%s: invalid NULL filepointer input.\n", __func__ );
XLAL_ERROR ( XLAL_EINVAL );
}
if ( thisCand == NULL ) {
/* still pass a pointer empty doppler struct,
* so that the output file header will have all column names
*/
PulsarDopplerParams XLAL_INIT_DECL(emptyDoppler);
XLAL_CHECK( write_transientFstatMap_to_fp ( fp, NULL, NULL, &emptyDoppler ) == XLAL_SUCCESS, XLAL_EFUNC, "Failed to write transient-FstatMap file header." );
}
else {
XLAL_CHECK( write_transientFstatMap_to_fp ( fp, thisCand->FstatMap, &thisCand->windowRange, &thisCand->doppler ) == XLAL_SUCCESS, XLAL_EFUNC, "Failed to write transient-FstatMap file body." );
}
return XLAL_SUCCESS;
} /* write_transientCandidateAll_to_fp() */
......
......@@ -109,6 +109,8 @@ int XLALApplyTransientWindow2NoiseWeights ( MultiNoiseWeights *multiNoiseWeights
int write_transientCandidate_to_fp ( FILE *fp, const transientCandidate_t *thisTransCand, const char timeUnit );
int write_transientFstatMap_to_fp ( FILE *fp, const transientFstatMap_t *FstatMap, const transientWindowRange_t *windowRange, const PulsarDopplerParams *doppler );
int write_transientCandidateAll_to_fp ( FILE *fp, const transientCandidate_t *thisTransCand );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment