/* *************************************************************************** * * Name of source file: c_newlc/WriteLC.c * Version of source file: 1.0 * Purpose: Write light curve component in j_ima_iros * Date: 2015/03/30 * Programmer: Niels Lund * Derived from component: Stefan Larsson's j_src_lc.c ******************************************************************************/ /* ======================================================= * Write everything irequired to the output data structure(s). * A single function is used for both normal and folded * lightcurves - nPhaseBins is used as flag to distinguish * the two cases. * ======================================================= */ /* if we have folded lightcurves we must make sure to write * only nPhaseBin entries */ /* **************************************************************************** */ #include #define J_SRC_ACCURACY 1e-6 int j_iir_Write_LC( dal_element *theSWG, Auxdata auxdata, struct instr_data *jmx_id, struct log_con *logger, swg_pointing *point, struct backpro *backproj, struct shadowgrams *sh, goodsrc *GOODSRC, timeslices *Tslices, b_list *B_list, long nPhaseBins, int chatter, int status) { int i, j, k, ALLsrc, m0, m1, m2, ntime, i5; char sourceName[32], gnuname[128], textline[256], nameLC[14]; float xmm, ymm; FILE* gnufil; Instrument jemxInstr; char *srcID[MAX_STR_LEN]; float srcRA[SCW_SRCMAX]; float srcDec[SCW_SRCMAX]; long nSources; long nOutLCBins; int nChanBins; double timeStep; double timeStart; double tElapse; double onTime; double meanDead; float srcOffAxisAngle[N_SRCMAX]; dal_element *dalPtr=NULL; /* generic DAL pointer */ dal_dataType dType=DAL_DT_UNKNOWN; /* needed for DAL calls */ char nameEbds[14]; /* name of energy boundaries table */ char typeName[FLEN_CARD]; /* FULL or REST */ char appFlag[2] = "F"; double *rateBuff=NULL; /* local buffer for rate per energy */ double *errBuff=NULL; /* local buffer for error per energy */ double *bRateBuff=NULL; /* local buffer for bRate per energy */ double *bErrBuff=NULL; /* local buffer for bError per energy */ double *timeLC=NULL; /* local buffer for for mid-Times */ double *timeDel=NULL; /* local buffer for for delta-Times */ double *fracExp=NULL; /* local buffer for fractional exposure */ double timeErr=1.0/8192.0; /* JEM-X time uncertainty */ double timeErrRel=0.0; /* JEM-X time relative uncertainty */ double rate=0.0; /* Keep rate value during calc */ double bRate=0.0; /* Keep bRate value during calc */ double srcRate=0.0; /* Net source rate */ double bkgRate=0.0; /* Background rate */ double time=0.0; /* Live time for a bin */ double sumtime=0.0; /* Sum of time for bins */ double sumRate=0.0; /* Sum of net rate for all timebins */ double sumBRate=0.0; /* Sum of bkg. rates for all time bins*/ double sumNRate=0.0; /* Sum of nRate for all timebins */ double rateVariance=0.0; /* Variance of illum. rate */ double bRateVariance=0.0; /* Variance of shadow. rate */ double sumSrcVariance=0.0; /* Sum of source error variances */ double sumBkgVariance=0.0; /* Sum of backgr. error variances */ double avgRate=0.0; double avgRateErr=0.0; double srcVariance = 0.0; double bkgVariance = 0.0; float eMin[J_NUM_SCI_BINS]; /* buffer for lower energy bounds */ float eMax[J_NUM_SCI_BINS]; /* buffer for upper energy bounds */ float deltaT=0.0; /* TIMEDEL */ float detSig = 0.0; /* Detection significance */ long numRead=0; /* counter of read values */ int iSource=0; /* loop over sources */ long nRate=0; /* Number of events (illum. area) */ int iChan=0; /* loop over channels */ int midChan[J_NUM_SCI_BINS]; /* Mid point of LC band/channel */ int giveEbounds=0; /* boolean: do we have energy bounds? */ static int func_local = -1, local_calling_num=0; clock_t calling_TT, TT_now; /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "j_iir_Write_LC"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->logstat = logprint(logger, logger->tmptxt, 6); logger->func_used_num = 199; } } logger->func_calls[func_local]++; logger->TT = TT_now = clock(); calling_TT = logger->TT; local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; /* function entry timing end */ if (logger->trace) traces(func_local, 0, logger); /* * exit function immediately if callingStatus is not OK on entry */ if (status != ISDC_OK) goto exitnow; if (logger->trace) traces(func_local, 5, logger); i5 = logger->i5; nChanBins = sh->numShds - backproj->ee_basic; nSources = logger->N_SRC3; jemxInstr = jmx_id->jmx_unit;; nOutLCBins = logger->NumTimeBins; if (0 < nPhaseBins) { nOutLCBins = nPhaseBins; } if (logger->trace) traces(func_local, nOutLCBins+nPhaseBins*10000, logger); /* Allocate local buffers */ status = DALallocateDataBuffer( (void **)&rateBuff, nOutLCBins * sizeof(double), status ); if (logger->trace) traces(func_local, 1000000+status, logger); status = DALallocateDataBuffer( (void **)&errBuff, nOutLCBins * sizeof(double), status ); if (logger->trace) traces(func_local, 2000000+status, logger); status = DALallocateDataBuffer( (void **)&bRateBuff, nOutLCBins * sizeof(double), status ); if (logger->trace) traces(func_local, 3000000+status, logger); status = DALallocateDataBuffer( (void **)&bErrBuff, nOutLCBins * sizeof(double), status ); if (logger->trace) traces(func_local, 4000000+status, logger); status = DALallocateDataBuffer( (void **)&timeLC, nOutLCBins * sizeof(double), status ); if (logger->trace) traces(func_local, 5000000+status, logger); status = DALallocateDataBuffer( (void **)&fracExp, nOutLCBins * sizeof(double), status ); if (logger->trace) traces(func_local, 6000000+status, logger); status = DALallocateDataBuffer( (void **)&timeDel, nPhaseBins * sizeof(double), status ); if (logger->trace) traces(func_local, 7000000+status, logger); if (ISDC_OK!=status) { RILlogMessage(NULL,Error_2, "(Write_LC) Error allocating buffers!"); goto exitnow; } if (logger->trace) traces(func_local, 10, logger); for (ntime=0; ntimeNumTimeBins; ntime++) { *(timeLC + ntime) = (Tslices[ntime].Tstart + Tslices[ntime].Tstop) / 2.0; if (Tslices[ntime].dontUse) *(fracExp + ntime) = 0.0; else *(fracExp + ntime) = Tslices[ntime].final_expo; } deltaT = timeStep = Tslices[1].Tstop - Tslices[1].Tstart; for (ntime=0; ntimepival[iChan][0] + sh->pival[iChan][1]) / 2; } if (1 == jmx_id->jmx_unit) strcpy(nameLC,"JMX1-SRC.-"); if (2 == jmx_id->jmx_unit) strcpy(nameLC,"JMX2-SRC.-"); /* distinguish between folded lightcurve and normal one */ if (nPhaseBins > 0) { strcat(nameLC, "FLC"); /* FLC */ } else { strcat(nameLC, "LCR"); /* LCR */ } if (logger->trace) traces(func_local, 15, logger); /* * Now to the actual output data */ dalPtr=NULL; if (logger->trace) traces(func_local, 10000+100*nSources+nChanBins, logger); for (iSource=0; iSourceallsrc_lc[iSource]; if (logger->trace) traces(func_local, 10000+100*iSource, logger); for (iChan=backproj->ee_basic; iChanee_basic; iChan++) { /* loop over E-bands. Ends in 599 */ if (logger->trace) traces(func_local, 10000+100*iSource+iChan, logger); if (iChan < backproj->ee_basic) continue; if (logger->trace) traces(func_local, 20000+100*iSource+iChan, logger); /* Create new child of detector lightcurve Index */ status = DAL3GENindexCreateMember(theSWG, nameLC, NULL, &dalPtr, status); if (ISDC_OK!=status) { RILlogMessage(NULL, Error_1, "(Write_LC) Can not correctly create output LC number %d!, status: %d", iChan+1-backproj->ee_basic, status); goto exitnow; } if (logger->trace) traces(func_local,20, logger); /* get the light curve data from gnu-files output by j_ima_iros 'work' 201504xx */ ALLsrc = logger->allsrc_lc[iSource]; txtConvert(GOODSRC[ALLsrc].name, sourceName, logger); srcRA[iSource] = GOODSRC[ALLsrc].RA; srcDec[iSource] = GOODSRC[ALLsrc].dec; /* For all energy bands, but only for first source: Read also the global light curve */ if (iSource > 0) goto skipGlobal; if (logger->trace) traces(func_local,30, logger); sprintf(gnuname, "J%1d_lc_%04d%04d%04d_Global_E%02d.gnu", jmx_id->jmx_unit+1, backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv, iChan); sprintf(logger->tmptxt, "DALNAVN: E: %2d, J%1d_lc_%04d%04d%04d_Global_E%02d.gnu", iChan, jmx_id->jmx_unit+1, backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv, iChan); logger->logstat = logprint(logger, logger->tmptxt, 0); if ((gnufil = fopen(gnuname, "rt")) == NULL) { sprintf(logger->tmptxt,"Dalnavn error: Could not open %s for reading", gnuname); logger->logstat = logprint(logger, logger->tmptxt, 0); } else fclose(gnufil); m0 = m1 = m2 = 0.0; if ((gnufil = fopen(gnuname, "rt")) != NULL) { sprintf(logger->tmptxt,"Successfully opened %s for reading", gnuname); logger->logstat = logprint(logger, logger->tmptxt, i5); if (logger->trace) traces(func_local,40, logger); for (ntime=0; ntimeNumTimeBins; ntime++) { if (Tslices[ntime].dontUse) continue; fgets(textline, 200, gnufil); if (feof(gnufil)) goto udone0; sscanf(textline, "%d %f", &j, &(Tslices[ntime].wflux[0])); m0 += 1.0; m1 += Tslices[ntime].wflux[0]; m2 += Tslices[ntime].wflux[0] * Tslices[ntime].wflux[0]; k = strlen(textline); textline[k-1] = 0; } udone0: fclose(gnufil); gnufil = NULL; } else { sprintf(logger->tmptxt,"Could not open %s for reading, inserting dummy data", gnuname); logger->logstat = logprint(logger, logger->tmptxt, i5); if (logger->trace) traces(func_local,45, logger); for (ntime=0; ntimeNumTimeBins; ntime++) { Tslices[ntime].wflux[0] = 0.0; } } /* transfer light curve to bRateBuff */ if (logger->trace) traces(func_local,50, logger); for (ntime=0; ntimeNumTimeBins; ntime++) { if ((m2 == 0.0) || (Tslices[ntime].dontUse)) { Tslices[ntime].wflux[ 0] = 0.0; Tslices[ntime].wflux[88] = 1.0; } else { Tslices[ntime].wflux[88] = avgRateErr; } bRateBuff[ntime] = Tslices[ntime].wflux[0]; bErrBuff[ntime] = Tslices[ntime].wflux[88]; } if (logger->trace) traces(func_local,60, logger); skipGlobal: /* get the light curve data from gnu-files output by j_ima_iros 'work' 201504xx */ ALLsrc = logger->allsrc_lc[iSource]; txtConvert(GOODSRC[ALLsrc].name, sourceName, logger); srcRA[iSource] = GOODSRC[ALLsrc].RA; srcDec[iSource] = GOODSRC[ALLsrc].dec; sprintf(gnuname, "J%1d_lc_%04d%04d%04d_%s_E%02d.gnu", jmx_id->jmx_unit+1, backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv, sourceName, iChan); sprintf(logger->tmptxt, "DALNAVN: ALLsrc %2d, E: %2d, %20s J%1d_lc_%04d%04d%04d_%s_E%02d.gnu", ALLsrc, iChan, GOODSRC[ALLsrc].name, jmx_id->jmx_unit+1, backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv, sourceName, iChan ); logger->logstat = logprint(logger, logger->tmptxt, 0); if (logger->trace) traces(func_local, 130, logger); m0 = m1 = m2 = 0.0; if ((gnufil = fopen(gnuname, "rt")) != NULL) { sprintf(logger->tmptxt,"Successfully opened %s for reading", gnuname); logger->logstat = logprint(logger, logger->tmptxt, i5); if (logger->trace) traces(func_local, 140, logger); for (ntime=0; ntimeNumTimeBins; ntime++) { if (Tslices[ntime].dontUse) continue; fgets(textline, 200, gnufil); if (feof(gnufil)) goto udoneA; sscanf(textline, "%d %f", &j, &(Tslices[ntime].wflux[1])); m0 += 1.0; m1 += Tslices[ntime].wflux[1]; m2 += Tslices[ntime].wflux[1] * Tslices[ntime].wflux[1]; k = strlen(textline); textline[k-1] = 0; } udoneA: fclose(gnufil); gnufil = NULL; } else { sprintf(logger->tmptxt,"Dalnavn error: Could not open %s for reading", gnuname); logger->logstat = logprint(logger, logger->tmptxt, 0); sprintf(logger->tmptxt,"Could not open %s for reading, inserting dummy data", gnuname); logger->logstat = logprint(logger, logger->tmptxt, i5); if (logger->trace) traces(func_local, 135, logger); for (ntime=0; ntimeNumTimeBins; ntime++) { Tslices[ntime].wflux[1] = 0.0; } } if (logger->trace) traces(func_local, 145, logger); /* calculate flux mean and standard devation */ if (m2 > 0.0) { avgRate = m1 / m0; avgRateErr = sqrt(m2 / m0 - avgRate * avgRate); } else { avgRate = 0.0; avgRateErr = 1.0; } /* transfer light curve to rateBuff */ for (ntime=0; ntimeNumTimeBins; ntime++) { if ((m2 == 0.0) || (Tslices[ntime].dontUse)) { Tslices[ntime].wflux[ 1] = 0.0; Tslices[ntime].wflux[89] = 1.0; } else { Tslices[ntime].wflux[89] = avgRateErr; } rateBuff[ntime] = Tslices[ntime].wflux[1]; errBuff[ntime] = Tslices[ntime].wflux[89]; } if (logger->trace) traces(func_local, 150, logger); /* end of reading of this light curve 201504xx */ /* Write the source IDs. */ status = DALattributePut(dalPtr, "SOURCEID", DAL_CHAR, (void*)&srcID[iSource], NULL, NULL, status); if (ISDC_OK!=status) { RILlogMessage(NULL,Error_1, "(Write_LC) Error writing SOURCEID keyword!"); goto exitnow; } if (logger->trace) traces(func_local, 160, logger); /* Write angle offset from the center of the field of view. */ i = getxy( srcRA[iSource], srcDec[iSource], jmx_id->jmx_unit, &xmm, &ymm, jmx_id, point, logger); if (i > 0) { srcOffAxisAngle[iSource] = sqrt(xmm*xmm + ymm*ymm) / jmx_id->mask_height * 180.0 / 3.14159; } else srcOffAxisAngle[iSource] = 0.0; if (logger->trace) traces(func_local, 170, logger); status = DALattributePut(dalPtr, "OFFANGLE", DAL_FLOAT, (void*)&srcOffAxisAngle[iSource], NULL, NULL, status); if (ISDC_OK!=status) { RILlogMessage(NULL,Error_1, "(Write_LC) Error writing OFFANGLE keyword!"); goto exitnow; } /* Write the source coordinates. */ status = DALattributePut(dalPtr, "RA_OBJ", DAL_FLOAT, (void*)&srcRA[iSource], NULL, NULL, status); if (ISDC_OK!=status) { RILlogMessage(NULL, Error_1, "(Write_LC) Error writing RA_OBJ keyword!"); goto exitnow; } /* Write the source coordinates. */ status = DALattributePut(dalPtr, "DEC_OBJ", DAL_FLOAT, (void*)&srcDec[iSource], NULL, NULL, status); if (ISDC_OK!=status) { RILlogMessage(NULL,Error_1, "(Write_LC) Error writing DEC_OBJ keyword!"); goto exitnow; } if (logger->trace) traces(func_local, 180, logger); /* Add sufficient rows */ status = DALtableAddRows(dalPtr, 0, nOutLCBins, status); if (ISDC_OK!=status) { RILlogMessage(NULL,Error_1, "(Write_LC) Can not add %ld rows to table!", nOutLCBins); goto exitnow; } if (logger->trace) traces(func_local, 190, logger); /* Write column TIME for normal lightcurves or PHASE and PHASEDEL for folded lightcurves */ if (0 == nPhaseBins) { status = DALtablePutCol(dalPtr, "TIME", 0, DAL_DOUBLE, nOutLCBins, (void*)timeLC, status); if (ISDC_OK!=status) { RILlogMessage(NULL, Error_1, "(Write_LC) Can not write column TIME!"); goto exitnow; } if (logger->trace) traces(func_local, 290, logger); /* Write TIMEDEL. */ status = DALattributePut(dalPtr, "TIMEDEL", DAL_FLOAT, (void*)&deltaT, NULL, NULL, status); if (ISDC_OK!=status) { RILlogMessage(NULL, Error_1, "(Write_LC) Error writing TIMEDEL keyword!"); goto exitnow; } status = DALtablePutCol(dalPtr, "FRACEXP", 0, DAL_DOUBLE, nOutLCBins, (void*)fracExp, status); if (ISDC_OK!=status) { RILlogMessage(NULL, Error_1, "(Write_LC) Can not write column FRACEXP!"); goto exitnow; } } else { status = DALtablePutCol(dalPtr, "PHASE", 0, DAL_DOUBLE, nOutLCBins, (void*)timeLC, status); if (ISDC_OK!=status) { RILlogMessage(NULL, Error_1, "(Write_LC) Can not write column TIME!"); goto exitnow; } status = DALtablePutCol(dalPtr,"PHASEDEL", 0, DAL_DOUBLE, nOutLCBins, (void*)timeDel, status); if (ISDC_OK!=status) { RILlogMessage(NULL, Error_1, "(Write_LC) Can not write column PHASEDEL!"); goto exitnow; } } if (logger->trace) traces(func_local, 210, logger); /* Write columns RATE and ERROR regardless of LC type */ status = DALtablePutCol(dalPtr,"RATE", 0, DAL_DOUBLE,nOutLCBins, (void*)rateBuff,status); if (ISDC_OK!=status) { RILlogMessage(NULL, Error_1, "(Write_LC) Can not write column RATE!"); goto exitnow; } status = DALtablePutCol(dalPtr,"ERROR", 0, DAL_DOUBLE,nOutLCBins, (void*)errBuff,status); if (ISDC_OK!=status) { RILlogMessage(NULL, Error_1, "(Write_LC) Can not write column ERROR!"); goto exitnow; } if (logger->trace) traces(func_local, 220, logger); /* Write columns BRATE and BERROR regardless of LC type */ status = DALtablePutCol(dalPtr,"BRATE", 0, DAL_DOUBLE,nOutLCBins, (void*)bRateBuff,status); if (ISDC_OK!=status) { RILlogMessage(NULL, Error_1, "(Write_LC) Can not write column BRATE!"); goto exitnow; } status = DALtablePutCol(dalPtr,"BERROR", 0, DAL_DOUBLE,nOutLCBins, (void*)bErrBuff,status); if (ISDC_OK!=status) { RILlogMessage(NULL, Error_1, "(Write_LC) Can not write column BERROR!"); goto exitnow; } if (logger->trace) traces(func_local, 230, logger); /* Set keywords for channel and energy boundaries */ status = DALattributePut(dalPtr,"CHANMIN", DAL_INT, (void*)&(sh->pival[iChan][0]), NULL, NULL, status); status = DALattributePut(dalPtr,"CHANMAX", DAL_INT, (void*)&(sh->pival[iChan][1]), NULL, NULL, status); if (logger->trace) traces(func_local, 240, logger); if (giveEbounds) { status = DALattributePut(dalPtr,"E_MIN", DAL_FLOAT, (void*)&(jmx_id->escale[sh->pival[iChan][0]]), NULL, NULL, status); status = DALattributePut(dalPtr,"E_MAX", DAL_FLOAT, (void*)&(jmx_id->escale[sh->pival[iChan][1]]), NULL, NULL, status); if (ISDC_OK!=status) { RILlogMessage(NULL, Error_1, "(Write_LC) Error writing channel/energy keywords!"); goto exitnow; } } if (logger->trace) traces(func_local, 250, logger); if(avgRate > 0.0 && avgRateErr > 0.0){ detSig = avgRate/avgRateErr; }else { detSig = 0.0; } status = DALattributePut(dalPtr, "DETSIG", DAL_FLOAT, (void*)&detSig, NULL, NULL, status); tElapse = Tslices[logger->NumTimeBins - 1].Tstop - Tslices[0].Tstart; /* set further keywords: elapsed time and on time */ status = DALattributePut(dalPtr, "TELAPSE", DAL_DOUBLE, (void*)&tElapse, NULL, NULL, status); if (ISDC_OK!=status) { RILlogMessage(NULL,Error_1, "(Write_LC) Error writing TELAPSE keyword!"); goto exitnow; } onTime = sh->accumT; status = DALattributePut(dalPtr,"ONTIME",DAL_DOUBLE, (void*)&onTime, NULL, NULL, status); if (ISDC_OK!=status) { RILlogMessage(NULL,Error_1, "(Write_LC) Error writing ONTIME keyword!"); goto exitnow; } if (tElapse > 0.0) meanDead = onTime / tElapse; else meanDead = 0.0; /* mean dead time correction factor */ status = DALattributePut(dalPtr,"DEADC",DAL_DOUBLE, (void*)&meanDead, NULL, NULL, status); if (ISDC_OK!=status) { RILlogMessage(NULL,Error_1, "(Write_LC) Error writing DEADC keyword!"); goto exitnow; } /* average countrate and error */ status = DALattributePut(dalPtr,"SRCCNT",DAL_DOUBLE, (void*)(&avgRate), NULL, NULL, status); if (ISDC_OK!=status) { RILlogMessage(NULL,Error_1, "(Write_LC) Error writing SRCCNT keyword!"); goto exitnow; } status = DALattributePut(dalPtr,"SRCCNTE",DAL_DOUBLE, (void*)(&avgRateErr), NULL, NULL, status); if (ISDC_OK!=status) { RILlogMessage(NULL,Error_1, "(Write_LC) Error writing SRCCNTE keyword!"); goto exitnow; } if (logger->trace) traces(func_local, 260, logger); /* for folded lightcurves record also period and phase zero */ if (0 < nPhaseBins) { if (logger->trace) traces(func_local, 270, logger); status = DALattributePut(dalPtr,"PERIOD", DAL_DOUBLE, (void*)&timeStep, NULL, NULL, status); if (ISDC_OK!=status) { RILlogMessage(NULL,Error_1, "(Write_LC) Error writing PERIOD keyword!"); goto exitnow; } status = DALattributePut(dalPtr,"PHASZERO", DAL_DOUBLE, (void*)&timeStart, NULL, NULL, status); if (ISDC_OK!=status) { RILlogMessage(NULL,Error_1, "(Write_LC) Error writing PHASZERO keyword!"); goto exitnow; } } if (logger->trace) traces(func_local, 280, logger); /* data type used */ strcpy(typeName,"FULL"); status = DALattributePut(dalPtr, "DATAMODE", DAL_CHAR, (void*)&typeName, NULL, NULL, status); if (ISDC_OK!=status) { RILlogMessage(NULL, Error_1, "(Write_LC) Error writing DATAMODE keyword!"); goto exitnow; } timeErrRel = timeErr / deltaT; /* The relative uncertainty is not really known */ status = DALattributePut(dalPtr, "TIERRELA",DAL_DOUBLE, (void*)&timeErrRel, NULL, NULL, status); if (ISDC_OK!=status) { RILlogMessage(NULL,Error_1, "(Write_LC) Error writing TIERRELA keyword!"); goto exitnow; } /* JEM-X events have an uncertainty of 1/8192 sec */ status = DALattributePut(dalPtr, "TIERABSO",DAL_DOUBLE, (void*)&timeErr, NULL, NULL, status); if (ISDC_OK!=status) { RILlogMessage(NULL,Error_1, "(Write_LC) Error writing TIERABSO keyword!"); goto exitnow; } if (logger->trace) traces(func_local, 290, logger); /* Copy standard keywords from SWG */ status = DAL3GENattributeCopy(theSWG,dalPtr, "REVOL,SWID,SW_TYPE,SWBOUND, OBTSTART,OBTEND,TSTART,TSTOP",status); if (ISDC_OK!=status) { RILlogMessage(NULL,Warning_2, "(Write_LC) Problems copying standard keywords from the SWG! status=%d",status); RILlogMessage(NULL,Log_2, "(Write_LC) Resetting status to ISDC_OK."); status = ISDC_OK; } if(chatter > J_CHATTY_VERBOSE){ status = CommonStampObject(dalPtr,"Wrote lightcurve data",status); } if (status != ISDC_OK) { RILlogMessage(NULL,Error_2, "Problem stamping lightcurve! status=%d", status); } status = DAL3GENindexUpdate(dalPtr,theSWG,status); if (status != ISDC_OK) { RILlogMessage(NULL,Error_2, "Error updating lightcurve index! status=%d", status); } if (logger->trace) traces(func_local, 300, logger); } /* end of loop over energy channels */ } /* end of loop over sources */ if (rateBuff != NULL) { DALfreeDataBuffer(rateBuff, ISDC_OK); } if (errBuff != NULL) { DALfreeDataBuffer(errBuff, ISDC_OK); } if (bRateBuff != NULL) { DALfreeDataBuffer(bRateBuff, ISDC_OK); } if (bErrBuff != NULL) { DALfreeDataBuffer(bErrBuff, ISDC_OK); } if (timeLC != NULL) { DALfreeDataBuffer(timeLC, ISDC_OK); } if (fracExp != NULL) { DALfreeDataBuffer(fracExp, ISDC_OK); } if (timeDel != NULL) { DALfreeDataBuffer(timeDel, ISDC_OK); } if (logger->trace) traces(func_local, 310, logger); slut: ; if (logger->trace) traces(func_local, 99, logger); /* function exit timing start */ TT_now = clock(); logger->func_times[func_local] += difftime(TT_now, logger->TT); logger->TT = TT_now; logger->func_calling_num = local_calling_num; /* function exit timing end */ return( status ); exitnow: /* exitnow */ if (logger->trace) traces(func_local, 1000000-status, logger); goto slut; }