/***************************************************************** * * Name of source file: j_src_spectra/lc_main.c * Version of source file: 5.1.0 * Parent component: None * Programmer: Stefan Larsson * Affiliation: Stockholm Observatory * Contact address: Stockholm Observatory * SCFAB, SE-106 91 Stockholm, Sweden * Phone: +46 8-5537 8543 FAX: +46 8-5537 8510 * stefan@astro.su.se * Purpose: Extract source light curve for individual * sources in one science window of event data. * Date: 2005/06/02 * This program is used for both spectra and * light curves. * The implementation here is to produce * only spectra but by changing the * presently hardcoded parameters doLC * and doSpec it is possible to compute * either lightcurves or spectra. * * The update history below, v0.01-2.9.0 * refer to the j_src-spectra version of * this program. Later updates are done in * parallell. * Update history: * 2000/05/11 0.01 SL Adaption of test code jextr5.c * 2000/09/11 1.0 CAO First delivered version of this executable * 2000/09/22 1.1 CAO No change from first version * 2000/11/23 2.0 SL/PK Actually writes spectra. * 2001/04/06 2.1 SL Updated parameter interface * 2001/06/19 2.2 SL Error in mask geomery definition corrected. * Added calculation of statistical errors. * 2001/09/13 2.3 SL Bug fix (error in -BSP). * Times are now converted to IJD. * The use of GTI, timeStart, timeStop and * timeStep implemented. * Big arrays now use dynamical memmory * allocation. * 2001/11/08 2.4 SL Using new templates for -ARF, -SPE, -BSP. * based on ARF II and PHA II and more XSPEC * friendly. * 2002/01/15 2.5 SL Updates: * - Grey Filter correction is now applied. * - Collimator vignetting, detector QEFF and * area is now included in the ARF. * - All -ARF columns are now filled with * relevant data. * 2002/05/09 2.6 SL Updates: Following SPRs resolved * SPR-0780, SPR-01199,SPR-01203 * 2002/06/13 2.7 SL Updates: Following SPRs resolved * - SCREW-506 resolved (chatty -> chatter) * - Unused variables removed (SPR-1283) * "if( =" cases -> "if( ==" SPR-1283 * - RESPFILE keyword is now written. * j_src_grey_correction deleted. (Not used * any more). * 2002/06/27 2.7.1 SL Updates: Resolved * SPR-1585 Incorrect parameter information * in j_src_spectra.par * 2002/09/05 2.8.0 SL Updates: Resolved * SPR-1717, 1838, 1860 * 2002/09/22 2.9.0 SL Updates: Resolved SCREW 747 * * 2002/10/21 3.0.0 SL Modified to produce src light curves. * 2002/11/21 3.1.0 SL Updates: Resolved * SPR 2150: Added option (parameter useRaDec) * to use sky coordinates (RA,DEC) * instead of instrument coordinates. * SPR 2055: If GTI table is available but * with zero time intervals, conclude * that there are no good intervals * and exit with warning. * rowSelect: New parameter to select events * according to STATUS value. * radiusLimit: New parameter to set outer * detector radius for selected * data. * 2002/12/05 3.1.1 SL Updates: * - Corrected bug in source coordinates for * JemX-2 (180 degree rotation). * - Corrected inconsistent number of time * bins which lead to occasional core dump. * - Added diagnosticModes * 3 Source position scan * 4 Randomization of event positions. * 2003/01/09 3.2.0 SL Updates: * - Source sky coordinates (REC,DEC) are * Now written to light curve data structures. * - Period folding implemented. * 2003/01/09 3.3.0 SL Updates: * Overlaping energy ranges allowed (SPR 2748) * 2003/06/18 3.4.0 SL - SCREW (00920, Add source position to * source spectra and lightcurves) fixed in * previous delivery. * (j_src_lc/spectra) * - SPR-02937 (Data gaps wrongly handled) fixed. * (j_src_lc) * - SPR-01123 (Assignment operator) fixed. * (j_src_spectra) * 2003/10/04 3.5.0 SL * 2003/10/20 3.5.1 SL - SPR-3260: Bug in detector area calculation * fixed. * * 2004/01/28 3.5.2 SL - SPR-3390/3391: Uninitialized memory read. * Fixed. * - precisionLevel = 20 now make an energy * dependent correction for leakage from * illuminated to non-illuminated areas. * - Mask support structure is included * in vignetting calculation. * Routines by Niels Lund adapted * (See note by CK above). * BUT NOT USED DUE TO DIFFERENCIES * BETWEEN LINUX AND SUN TEST!! * - Size (but not structure) of the * Crab is now taken into account * in PIF calculation if identified by * source_id. * * 2004/05/10 4.0.0 SL New delivery. * - PIF calculation is now moved into function * j_src_pif_create20. This will later be part * of Jem-X shared functions. * - Bug fixes: 1) Interpolation error * (openArea etc.) corrected. * 2) Minor error in equations * solving for source fluxes * corrected. * - Solution of source fluxes moved to * function j_src_solve_rate * - Number of PIF energies increased (to 10) to * eliminate spectral bumps, in particular around * 10 keV. * - precisionLevel = 0 removed * - Added precisionLevel = 25 with 18 PIF energies * instead of default 10. * - Mapping of an evendistribution in PIF * calculation onto detector pixels was * increased from 7x7 to 13x13 pixels. * - Introduced a proper maximum for the photon * detection depth in the detector. * - Illuminated and non-illuminated areas are * defined by PIF cut values. This was changed * from a fix PIF value to a PIF value for which * the illuminated area contains 75% of the flux * This is numerically more stable. * * - Solved SPR03372: keyword EXPOSURE now set in * JMXi-SRCL-ARF. (Does not affect j_src_lc). * * 2004/06/07 4.0.1 SL Bug fix. * - Sign of Source direction in calculation * of PSF for the PIF. * - In the PIF calculation, the effect of * detector penetration depth was taken into * account bothe in the PSF and in collimator * vignetting. The latter is now removed. * * 2004/06/07 4.1.0 SL Formal delivery (renamed v4.0.1) * - Solving SPR-3644: Looking for -FULL-* * instead of -FULL-COR and REST-COR. * - Solving SPR-3668: Bug in PIF calc. * (See v4.0.1). * * 2004/10/31 4.1.1 SL Detector status map definitions are now * taken from jemx.h instead of being * hard coded in j_src_pif_create20. * * 2004/12/01 4.1.2 SL No change in this file. * In j_src_lc.c: ONTIME and DEADC keywords * are now set. * * 2005/03/31 5.0.0 SL Solved SPR-04019: * An error occured * when writing source Ra&Dec to * time resolved spectra. * storePIF option added. * * 2005/06/02 5.0.1 SL Solved SPR-04203: * Some variables are now static * solves a problem for older Linux systems. * * 2005/06/19 5.0.2 SL Solved SPR-04232: * overrideCollTilt<0 is now handled * correctly. * Solved SPR-04235: * When no LC time bin is found. Now exit * with warning and not with error. * * 2005/10/13 5.1.0 SL Solved SPR-04252: FPE * * Type of element: Executable top level function * Part of package: j_src_lc-5.0.1.tar.gz * Name: j_src_lc_main * Children: j_src_params * j_src_work * Returns: Zero - executable completed with no errors * Negative values - incomplete execution due to * error condition * Error codes: See j_src_lc.txt ******************************************************************************/ #include int main (int argc, char *argv[]) { int status = ISDC_OK; int closeStatus = ISDC_OK; int mode = 0; /* Running mode of this executable */ int evtType = 0; /* Data types to use */ int bgrMethod = 0; /* Background subtraction method */ int vignCorr = 0; /* Vignetting correction */ int fluxScaling = 1; /* Flux scaling (1=open area, 2=detector) */ int useRaDec = 0; /* Src coord: RA,DEC or instr. */ int skipNearDeadAnode = 0; /* Ignore pixels near dead anodes */ int skipHotSpot = 0; /* Ignore pixels in hotspot area */ int precisionLevel = 0; /* Speed/precision level */ int diagnosticMode = 0; /* Diagnostic Mode (0=Normal, 1=Diagnostic) */ double diagnosticParam = 0.0; /* Diagnostic parameter */ double overrideCollTilt = -1.0; /* Collimator tilt parameter */ int tAccuracy = 0; /* Time Corr. accuracy (0=Low, 1=High) */ int nPhaseBins = -1; /* Number of phase bins */ int doSpec = 0; /* Switch to compute spectra */ int doPif = 0; /* Switch to store PIF values */ int chatty = 1; /* Level of debugging/monitoring output */ char responseFile[DAL_FILE_NAME_STRING]; /* Resonse file string */ char instrStr[5]; /* String for instrument number */ char gtiNames[DAL_FILE_NAME_STRING]; char instModDOL[DAL_FILE_NAME_STRING]; char rowSelect[DAL_FILE_NAME_STRING]; double *phaseBins=NULL; double timeStart=0.0; /* Start time in IJD */ double timeStop=0.0; /* Stop time in IJD */ double timeStep=0.0; /* Integration time */ double radiusLimit=0.0; dal_element *inSWGptr=NULL; /* Pointer to SWG group */ dal_element *instrGrpPtr=NULL;/* Pointer to Instrument Model Group */ dal_element *responsePtr=NULL;/* Pointer to response Group */ dal_element *bkgSpecCatPtr=NULL;/* Pointer to Instr. Bkg spectra catalog */ dal_element *dbgSpecCatPtr=NULL;/* Pointer to Diffuse Bkg spectra catalog */ /* LC parameters */ int nChanBins = 0; /* Number of channel bins */ int chanLow[J_NUM_SCI_BINS]; /* Lower channel boundary */ int chanHigh[J_NUM_SCI_BINS]; /* Upper channel boundary */ int doLC = 1; /* Switch to compute lc */ do { /* Use a once-only do/while loop to force program termination whenever status returned is not ISDC_OK */ /* * Initialisation */ mode = CommonInit(COMPONENT_NAME, COMPONENT_VERSION,argc,argv); if (mode != ISDC_SINGLE_MODE) { RILlogMessage(NULL, Error_2, "Not started in ISDC_SINGLE_MODE, mode = %d", mode); status = J_SRC_NOT_IN_SMODE; continue; } /* * Get the parameters, get instrument data, and prepare access to * data structures (open the connections) */ status = j_src_params(&inSWGptr, &instrGrpPtr, &responsePtr, &bkgSpecCatPtr, &dbgSpecCatPtr, responseFile, rowSelect, instrStr, gtiNames, instModDOL, &timeStep, &timeStart, &timeStop, &evtType, &precisionLevel, &diagnosticMode, &diagnosticParam, &overrideCollTilt, &tAccuracy, &nPhaseBins, &phaseBins, &bgrMethod, &vignCorr, &useRaDec, &nChanBins, chanLow, chanHigh, &radiusLimit,&fluxScaling, doLC, doSpec, &doPif, &skipNearDeadAnode,&skipHotSpot, &chatty, status); if (status != ISDC_OK) { if (J_SRC_NO_INPUT_DATA == status) { RILlogMessage(NULL, Log_2, "No imaging data to process in this SWG, " "so do nothing"); status = ISDC_OK; continue; } else { RILlogMessage(NULL, Error_2, "Problem getting input parameters etc., status = %d\n", status); continue; } } if (evtType == 1) { RILlogMessage(NULL, Warning_2, " Source extraction aborted. No FULL data available."); continue; } /*************** NB - Attention ! ! ! ! ! Adhoc change ***************/ diagnosticMode = 1; /* Go ahead and do the work, */ status = j_src_work(inSWGptr, instrGrpPtr, responsePtr, bkgSpecCatPtr, dbgSpecCatPtr, responseFile, instrStr, gtiNames, instModDOL, timeStep, timeStart, timeStop, evtType, precisionLevel, diagnosticMode, diagnosticParam, overrideCollTilt, tAccuracy, nPhaseBins, phaseBins, bgrMethod, vignCorr, useRaDec, rowSelect, nChanBins,chanLow,chanHigh, radiusLimit,fluxScaling, doLC, doSpec, doPif, skipNearDeadAnode,skipHotSpot, chatty, status); if (status == J_SRC_NO_GTI) { status = ISDC_OK; continue; } if (status == J_SRC_NO_SOURCES) { if (J_CHATTY_NORMAL<=chatty) { RILlogMessage(NULL,Log_1, "No source list to work with found => exit"); } status = ISDC_OK; continue; } if (status != ISDC_OK) { RILlogMessage(NULL, Error_2, "Problem in the work function, status = %d\n", status); continue; } } while (0); RILlogMessage(NULL, Log_2,"Work completed: status is %d", status); closeStatus = CommonCloseSWG(inSWGptr, ISDC_OK); if( closeStatus != ISDC_OK ){ RILlogMessage(NULL, Warning_2, "Failed to close the SWG: %d continuing with commonExit", closeStatus); } if( status != ISDC_OK ) { RILlogMessage(NULL, Error_2, "Terminating with error status = %d", status); } RILlogMessage(NULL, Log_2, " This is executable %s, version %s", COMPONENT_NAME, COMPONENT_VERSION); CommonExit(status); return status; }