/***************************************************************** * Name of source file: j_ima_iros_params.c * Version of source file: 3.2.7 * Parent component: None * Programmer: Niels Lund & Niels J. Westergaard * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325705 FAX: +45 35362475 * nl@dnsc.dk, njw@dnsc.dk * Purpose: Get the parameters and open files for the * j_ima_iros executable * Origin date: 041122 * Update history: 1.0.0 041130 First version * 1.0.4 050126 Test version for undue crash * 1.1.0 050131 Now reading FITS sky/backproj files * 1.1.1 050211 Keywords adapted to needs of j_ima_mosaic * 1.1.2 050303 Extra keyw:RLIMIDX, new cleaning * 1.1.3 050307 New DMAP: 51 radii * 1.1.4 050407 New clean, etc. * 1.1.4 050407 New clean, etc. * 1.1.5 050415 New clean again, updated flux determination * 1.1.6 050418 Now uses JMXi-DBKG-MOD as default for empty field shds * 1.2.0 050425 Deals with SPR 4102,4108 and reduces RAM requirement * 1.3.0 050503 Deals with SPR 4120 and copes with up to 6 shadowgrams * 1.3.1 050517 Deals with SPR 4143 and initializes ima_sigma properly * 1.3.2 050519 Closes SPR 4157 - bad size of three arrays * 1.3.3 050602 Changes some arrays to static (SPR 4202) * 1.4.0 050620 Include user defined sources (SCREW 1740) * 1.5.1 051129 Separating functions to jmx_lib_pif * 1.5.2 051202 Separating functions to jmx_lib_pif (2) * 1.5.3 051202 Give offX, x2x values in mm in IMOD-GRP * 1.5.4 060104 Bug in sh_depth corrected, detectmap now in mm * 1.5.5 060106 Introduced one more digit in logfile for src position * 1.5.6 060228 Removed parameter detMapFile and some obsolete variables * 1.5.7 060606 Shifted detCondMap to struct jmx_id and status_map * 1.5.8 060807 SPR 04551 Bad assignment of RLIMIDX corrected * 1.5.9 060807 SPR 04533 Resetting status variable has been removed * 1.5.10 060807 SPR 04523 Declaring testsum as float iso. int * 1.5.11 060807 SPR 04458 A warning log line has been added * 1.5.12 060907 SPR 04301 A relative VIGNDOL path is given * 1.6.0 060911 SCREW 1918 Image correction map and parameters introduced * 1.6.1 060912 SPR 4441 Shadowgrams with too few counts are excluded * 1.6.2 060915 SCREW 1842 A significance map can now be obtained * 1.6.3 060915 An exposure (vignetting) map is now a product * 1.6.4 060928 Included test for zero divisor in peaktransfer.c * 1.6.5 061002 New defaults for par. skyImagesOut * 1.7.0 061110 Produces images with few or zero events (SPR 4594) * 1.7.1 061114 SPR 4603 Image unit (BUNIT) is now cts/dm2/s * 1.8.0 061213 SPR 4640 Error in findpeak has been corrected * 1.8.1 070123 SPR 4590 int changed to long for 64 bit code * 2.1.0 070809 SCREWs 2021-2023 * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.2.0 071205 Flux determination has been improved * 2.2.1 071205 SPR 4742: Division by zero eliminated * 2.2.2 080111 Makes trigger rates from JEM-X HK available * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 3.2.7 100224 SPR 4915: Fixing logics for sparse shadowgrams * Type of element: Function * Part of package: j_ima_iros * Name: j_ima_iros_params * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ #include int j_ima_iros_params( dal_element **theSWG, Instrument *jemxNum, char *instMod, /* DOL of Instrument Model data */ char *bkgShdDOL, /* DOL of empty field shadowgrams */ struct log_con *logger, struct backpro *backproj, struct backpro_lists *bp, struct shadowgrams *sh, int *useDeadAnodes, /* same as 'dead_ano' in orig. version */ int *yes2all, /* same as 'yes2all' in orig. version */ int *chatter, int status ) { /* Ordinary variables */ FILE *trace = NULL; char *inGroup = "inSWG"; /* input to CommonPreparePARsStrings */ char *inDOLs = ""; char *outGroup = "outSWG"; /* input to CommonPreparePARsStrings */ char *outDOLs = "skyRes,listRes"; char strjemxNum[5]; int clobber = 0; /* Boolean - clean output index table ? */ int intJemxNum = 0; /* int; for PIL value retrieval */ int itmp = 0; double dtmp = 0.0; 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_ima_iros_params"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; 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); /* Immediate return if called while executable is in error condition */ if( status != ISDC_OK ) return( status ); /* Get the parameters */ status = PILGetString("instMod", instMod); status = PILGetInt("chatter", chatter); logger->chatter = *chatter; status = PILGetInt("jemxNum", &intJemxNum); status = PILGetInt("skyImageDim", &itmp); backproj->FOV_ff = itmp; status = PILGetInt("detAccLimit", &itmp); sh->detAccLimit = (unsigned short) itmp; status = PILGetString("bkgShdDOL", bkgShdDOL ); status = PILGetString("dolBPL", logger->dolBPL ); status = PILGetBool("makeNewBPL", &itmp); backproj->makeNewBPL = itmp; status = PILGetString("newBackProjFile", backproj->newBackProjFile ); status = PILGetBool("useDeadAnodes", &itmp); *useDeadAnodes = itmp; /* transferred directly as a separate argument */ status = PILGetInt("maxNumSources", &itmp); backproj->iterations = itmp; status = PILGetReal("edgeEnhanceFactor", &dtmp); logger->edge = dtmp; status = PILGetReal("loopLimitPeak", &dtmp); logger->limit_f = dtmp; status = PILGetReal("detSigSingle", &dtmp); logger->qual_limit = dtmp; status = PILGetBool("yes2all", &itmp); *yes2all = itmp; /* transferred directly as a separate argument */ status = PILGetInt("pixelFold", &itmp); logger->pix_fold_ctrl = itmp; status = PILGetString("pixelFoldFile", logger->pixfold_file ); /* * status = PILGetInt("anodePhase", &itmp); * logger->pix_select[0] = itmp; * * status = PILGetInt("rearPhase", &itmp); * logger->pix_select[1] = itmp; * * status = PILGetBool("doPhaseScan", &itmp); * logger->pix_select[2] = itmp; */ status = PILGetReal("pix3fact", &dtmp); logger->pixfact = dtmp; status = PILGetInt("cleanStep", &itmp); backproj->cleanstep = itmp; status = PILGetReal("skyRadiusFactor", &dtmp); logger->sky_rad_lim = dtmp; status = PILGetReal("radiusLimit0", &dtmp); logger->drl_par[0] = dtmp; status = PILGetReal("radiusLimit1", &dtmp); logger->drl_par[1] = dtmp; status = PILGetReal("radiusLimit2", &dtmp); logger->drl_par[2] = dtmp; status = PILGetReal("radiusLimit3", &dtmp); logger->drl_par[3] = dtmp; status = PILGetReal("interactionDepth", &dtmp); backproj->indep = dtmp; bp->parameters[10] = dtmp; status = PILGetReal("hotPixelLimit", &dtmp); logger->hotpix_lim = dtmp; status = PILGetInt("shdOutCtrl", &itmp); logger->shdg_out_ctrl = itmp; if (logger->trace) traces(func_local, 4300+logger->shdg_out_ctrl, logger); status = PILGetString("skyImagesOut", logger->skyImagesOut); bp->skipNeighborCor = strstr( logger->skyImagesOut, "NONCOR" ) == NULL ? 0 : 1; /* * if skyImagesOut contains the string 'NONCOR' then the neighbor correction * should NOT be carried out i.e. skipped so skipNeighborCor should be 1 (one) */ status = PILGetBool("detImagesOut", &itmp ); logger->detImagesOut = itmp; status = PILGetBool("userImagesOut", &itmp ); logger->userImagesOut = itmp; status = PILGetBool("onlyDoShd", &itmp); logger->test = itmp; status = PILGetInt("eeSelect0", &itmp); logger->ee_select[0] = itmp; status = PILGetInt("eeSelect1", &itmp); logger->ee_select[1] = itmp; status = PILGetInt("eeSelect2", &itmp); logger->ee_select[2] = itmp; status = PILGetInt("eeSelect3", &itmp); logger->ee_select[3] = itmp; status = PILGetBool("useHexpos", &itmp); logger->useHexpos = itmp; RILlogMessage( NULL, Log_0,"##9875## just before logger->trace == 0 : value = %lu", logger->trace ); if (logger->trace == 0) { status = PILGetBool("useTrace", &itmp); logger->trace = itmp; RILlogMessage( NULL, Log_0,"##9875## just after logger->trace == 0 : value = %lu", logger->trace ); if( itmp ) { trace = fopen("imatrace.txt", "w"); fprintf(trace, " main %d\n", 0); fclose(trace); } } status = PILGetString("tracestring", logger->tracestring ); RILlogMessage( NULL, Log_0,"##9876## tracestring: %s", logger->tracestring ); status = PILGetInt("signifLim", &itmp); backproj->signiflim = itmp; status = PILGetInt("illumNorm", &itmp); backproj->illumin_norm_yes = itmp; status = PILGetReal("collHreduc", &dtmp); bp->coll_h_reduc = dtmp; if( status != ISDC_OK ) return( status ); if( intJemxNum == 1 ) { *jemxNum = JMX1; strcpy( strjemxNum, "JMX1" ); } else { *jemxNum = JMX2; strcpy( strjemxNum, "JMX2" ); } status = CommonPreparePARsStrings( inGroup, /* Input */ inDOLs, outGroup, /* Output */ outDOLs, 1, /* make unique */ theSWG, /* unified group */ &clobber, /* clobber ? */ status); /* current status */ if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##32## CommonPreparePARsStrings returned: %d", status); /* return( status); */ } RILlogMessage(NULL,Log_0,"##33## drl_par3 = %f", logger->drl_par[3]); 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 ); } /***************************************************************** * Name of source file: j_ima_iros_prepare.c * Version of source file: 4.0.6 * Parent component: None * Programmer: Niels Lund & Niels J. Westergaard * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325705 FAX: +45 35362475 * njw@dnsc.dk * Purpose: Get the parameters and open files for the * j_ima_iros executable * Local version 1.1 050208 Removed many old statements * Origin date: 041122 * Update history: 1.0.0 041130 First version * 1.0.4 050126 Test version for undue crash * 1.1.0 050131 Now reading FITS sky/backproj files * 1.1.1 050211 Keywords adapted to needs of j_ima_mosaic * 1.1.2 050303 Extra keyw:RLIMIDX, new cleaning * 1.1.3 050307 New DMAP: 51 radii * 1.1.4 050407 New clean, etc. * 1.1.4 050407 New clean, etc. * 1.1.5 050415 New clean again, updated flux determination * 1.1.6 050418 Now uses JMXi-DBKG-MOD as default for empty field shds * 1.2.0 050425 Deals with SPR 4102,4108 and reduces RAM requirement * 1.3.0 050503 Deals with SPR 4120 and copes with up to 6 shadowgrams * 1.3.1 050517 Deals with SPR 4143 and initializes ima_sigma properly * 1.3.2 050519 Closes SPR 4157 - bad size of three arrays * 1.3.3 050602 Changes some arrays to static (SPR 4202) * 1.4.0 050620 Include user defined sources (SCREW 1740) * 1.4.1 051125 Transfer x_rms, y_rms and abs_len from jmx_id to backproj * 1.5.1 051129 Separating functions to jmx_lib_pif * 1.5.2 051202 Separating functions to jmx_lib_pif (2) * 1.5.3 051202 Give offX, x2x values in mm in IMOD-GRP * 1.5.4 060104 Bug in sh_depth corrected, detectmap now in mm * 1.5.5 060106 Introduced one more digit in logfile for src position * 1.5.6 060228 Removed parameter detMapFile and some obsolete variables * 1.5.7 060606 Shifted detCondMap to struct jmx_id and status_map * 1.5.8 060807 SPR 04551 Bad assignment of RLIMIDX corrected * 1.5.9 060807 SPR 04533 Resetting status variable has been removed * 1.5.10 060807 SPR 04523 Declaring testsum as float iso. int * 1.5.11 060807 SPR 04458 A warning log line has been added * 1.5.12 060907 SPR 04301 A relative VIGNDOL path is given * 1.6.0 060911 SCREW 1918 Image correction map and parameters introduced * 1.6.1 060912 SPR 4441 Shadowgrams with too few counts are excluded * 1.6.2 060915 SCREW 1842 A significance map can now be obtained * 1.6.3 060915 An exposure (vignetting) map is now a product * 1.6.4 060928 Included test for zero divisor in peaktransfer.c * 1.6.5 061002 New defaults for par. skyImagesOut * 1.7.0 061110 Produces images with few or zero events (SPR 4594) * 1.7.1 061114 SPR 4603 Image unit (BUNIT) is now cts/dm2/s * 1.8.0 061213 SPR 4640 Error in findpeak has been corrected * 1.8.1 070123 SPR 4590 int changed to long for 64 bit code * 2.1.0 070730 Active use of input source catalog * 2.1.0 070809 SCREWs 2021-2023 * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.2.0 071205 Flux determination has been improved * 2.2.1 071205 SPR 4742: Division by zero eliminated * 2.2.2 080111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 4.0.6 120628 SPR ?: Reduced memory allocation demands * Type of element: Function * Part of package: j_ima_iros * Name: j_ima_iros_prepare *********************************************************************** */ int j_ima_iros_prepare( dal_element *theSWG, Instrument jemxNum, char *instMod, char *resultxt, char *bkgShdDOL, Events **bufevents, long *numEvents, Auxdata *auxdata, struct instr_data *jmx_id, struct log_con *logger, struct backpro *backproj, struct shadowgrams *sh, struct backpro_lists *bp, userbin *USERBIN, struct scwlist *SCWnow, swg_pointing *point, int dead_ano, int chatter, int status) { /* static char full_ref_name[200]; */ char swid[50]; char stmp[10]; char srclcatName[DS_NAME_SIZE]; char **gtiNames = NULL; /* ***** The gtiNames ought to be a parameter as it is in j_ima_shadowgram * To be implemented [2010-03-17/NJW] and not continue this sloppy way */ char rowSelect[30]; int itmp = 0, num_flag3 = 0; int *catFlag = NULL; int *CLASS_OBJcat = NULL; int nGTI = 0; int numNames = 1; /* For GTI retrieval */ int *dump_ptr; float *fdump; double *ddump; Events *Yevent; int i = 0; int j = 0; int k = 0; int m = 0; int preset_src2 = 0; int jemx = 0; int tAccuracy = 1; int skipNearDeadAnode = 0; int skipHotSpot = 0; long loop = 0; long ltmp = 0; long numRows = 0; long numRead = 0; float p_RA = 0.0; float p_dec = 0.0; float p_posang = 0.0; float e_mean = 0.0; float c_sum = 0.0; float ima_sigma_table[4]; /* table for sigma of peak in an image as function of energy. Introduced 2005-05-17 [NJW] and must later be defined in e.g. IMOD */ float *RA_OBJcat = NULL; float *DEC_OBJcat = NULL; float *ERR_OBJcat = NULL; float adist = 0.0; /* used to receive output from arcdist function */ float xxx[16]={0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0}; double timeStart = -1.; double timeStop = -1.; double radiusLimit = 125.; double *gtiStartIJD = NULL; double *gtiEndIJD = NULL; OBTime *gtiStartOBT = NULL; OBTime *gtiEndOBT = NULL; dal_element *ptrImod = NULL; dal_element *srclcatPtr = NULL; dal_dataType DALtype; /* JEMXirosImodData irosData; */ /* struct that holds specific IROS data */ 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_ima_iros_prepare"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } 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); if( status != ISDC_OK ) goto exittrace; /* * The initialization of sh->eval is now done in j_iir_get_shds */ strcpy( rowSelect, "STATUS <= 2048" ); /* * Get the revolution number and SWID * Unpack to PID and PIDV */ status = DALattributeGetInt( theSWG, "REVOL", <mp, NULL, NULL, status); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##121## keyword REVOL, status = %d", status); goto exittrace; } SCWnow->orbit = (short) ltmp; status = DALattributeGetChar( theSWG, "SWID", swid, NULL, NULL, status); strncpy( stmp, swid+4, 4 ); *(stmp+4) = '\0'; sscanf( stmp, "%d", &itmp ); SCWnow->pid = (short) itmp; strncpy( stmp, swid+8, 4 ); *(stmp+4) = '\0'; sscanf( stmp, "%d", &itmp ); SCWnow->pidv = (short) itmp; if( chatter > J_CHATTY_NORMAL ) { RILlogMessage( NULL, Log_0,"##122## SWID: %s, rev: %4d, pid: %4d, pidv: %4d", swid, (int)(SCWnow->orbit), (int)(SCWnow->pid), (int)(SCWnow->pidv) ); } /* * Transfer info to backproj struct */ backproj->aux_orbit = SCWnow->orbit; backproj->aux_pid = SCWnow->pid; backproj->aux_pidv = SCWnow->pidv; logger->medium_limit = 10.0; /* source strength class threshold */ logger->high_limit = 10.0; /* source strength class threshold */ for (i=0; itot_cnt_norm[i] = 10000.0; /* position determination uncertainty at the boundaries*/ /* * definitions from before 2005-04-19 [NJW]: * jmx_id->x_rms[0] = 2.0; jmx_id->x_rms[1] = 1.5; jmx_id->x_rms[2] = 1.4; * jmx_id->x_rms[3] = 1.3; jmx_id->x_rms[4] = 1.2; jmx_id->y_rms[0] = 2.0; * jmx_id->y_rms[1] = 1.5; jmx_id->y_rms[2] = 1.4; jmx_id->y_rms[3] = 1.3; * jmx_id->y_rms[4] = 1.2; jmx_id->abs_len[0] = 0.1; jmx_id->abs_len[1] = 2.0; * jmx_id->abs_len[2] = 4.3; jmx_id->abs_len[3] = 20.0; jmx_id->abs_len[4] = 80.0; * * these values are defined for all shadowgrams in function j_fitprep */ sprintf(logger->tmptxt, "##123## 0 Control data file: %s ", resultxt); /* logger->logstat = logprint(logger, logger->tmptxt, 4); */ if( chatter > J_CHATTY_NORMAL ) RILlogMessage(NULL,Log_0,"##124## j_ima_iros_prepare"); if( chatter > J_CHATTY_NORMAL ) RILlogMessage(NULL,Log_0,"##125## j_ima_iros_prepare"); logger->fits_shft = 0; /* optional X-shift of fits shadowgrams (cbj requires a shift value of 10) */ logger->test = 0; if( chatter > J_CHATTY_NORMAL ) RILlogMessage(NULL,Log_0,"##126## j_ima_iros_prepare"); /* * * Get the instrument and mask average temperatures * */ status = j_lpf_get_sc_hk( theSWG, jmx_id, chatter, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_0, "##3## %d: After get_sc_hk", status ); goto exittrace; /* On error: jump to end */ } /* * * Get the trigger rates from JEM-X HK data * */ status = j_lpf_get_jemx_hk( theSWG, jemxNum, jmx_id, chatter, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_0, "##3## %d: After get_jemx_hk", status ); goto exittrace; /* On error: jump to end */ } /* * * Open the IMOD Group * */ if( chatter > J_CHATTY_NORMAL ) RILlogMessage(NULL,Log_0,"##127## j_ima_iros_prepare"); if( chatter > J_CHATTY_NORMAL ) { RILlogMessage( NULL, Log_0,"##128## The -IMOD-GRP to open: %s", instMod); } status = DALobjectOpen(instMod, &ptrImod, status); if( status != ISDC_OK ) goto exittrace; /* On error: jump to end */ if( chatter > J_CHATTY_NORMAL ) { RILlogMessage( NULL, Log_0,"##129## The INST MOD group has now been opened"); } /* * * Get the detector map and fill the * struct instr_data jmx_id->status_map (unsigned short) * */ status = JEMXLIBgetStatusMap( ptrImod, jemxNum, jmx_id, logger, /* log control parameters */ chatter, status); if( chatter > J_CHATTY_NORMAL ) { RILlogMessage( NULL, Log_0, "##130## status = %d", status); } if( status != ISDC_OK ) goto exittrace; /* * * Get the mask array and fill the struct instr_data jmx_id->njwmask * */ status = JEMXLIBgetMask( ptrImod, jemxNum, jmx_id, logger, /* log control parameters */ chatter, status); if( chatter > J_CHATTY_NORMAL ) RILlogMessage( NULL, Log_0, "##131## status = %d", status); if( status != ISDC_OK ) goto exittrace; /* * * Get the SPAG correction table into struct instr_data jmx_id->spagf * */ /* debugging */ jmx_id->checkpoint = 123; status = j_lpf_get_spag_mod( jemxNum, ptrImod, jmx_id, chatter, status); if( chatter > J_CHATTY_NORMAL ) { RILlogMessage( NULL, Log_0, "##131a## status = %d", status); } if( status != ISDC_OK ) goto exittrace; if( chatter > J_CHATTY_NORMAL ) { RILlogMessage( NULL, Log_0,"##131b## checkpoint = %d", jmx_id->checkpoint ); for( j = 8; j < J_NUM_Y_PIXELS; j += 16 ) { k = 0; for( i = 16; i < J_NUM_X_PIXELS; i += 32 ) { xxx[k] = jmx_id->spagf[i][j]; k++; k %= 16; } RILlogMessage(NULL,Log_0,"##1## %5.2f%5.2f%5.2f%5.2f%5.2f%5.2f%5.2f%5.2f", xxx[0],xxx[1],xxx[2],xxx[3],xxx[4],xxx[5],xxx[6],xxx[7]); } } /* * Prior to the existence of jmx_lib_pif the call of JEMXLIBgetIrosImodData * was placed here [NJW/2005-11-30] */ if ((backproj->FOV_ff > FOV_f) || (backproj->FOV_ff < 1)) { sprintf(logger->error_text, "##132## Illegal value (%d) of FOV_ff, legal values are 1 and 2 only!", backproj->FOV_ff); logger->logstat = logprint(logger, logger->error_text, 7); status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_FOV_F_ERR; goto exittrace; } if( chatter > J_CHATTY_NORMAL ) RILlogMessage( NULL, Log_0,"##131b## status = %d", status ); /* * * Copy information from the JEMXLIB struct irosData to jmx_id (struct instr_data) * * After 2005-11-30 the values are written directly into jmx_id in function * JEMXLIBgetIrosImodData that is called from alignment_init * * New development 2007-06-27/NJW * alignment_init and JEMXLIBgetIrosImodData have been replaced by a call of * JEMXLIBgetInstrData, that has been suitably updated. * */ /* * jmx_id->coll_pitch = irosData.colpitch; * jmx_id->coll_h = irosData.collh; * jmx_id->coll_w = irosData.collw; * jmx_id->coll_r = irosData.collr; * jmx_id->xshi = irosData.xshift; * jmx_id->yshi = irosData.yshift; * jmx_id->c_tiltx = irosData.ctiltx; * jmx_id->c_tilty = irosData.ctilty; * jmx_id->struc_h2 = irosData.struch2; * jmx_id->struc_h1 = irosData.struch1; * jmx_id->coll_wb = irosData.collwb; * jmx_id->coll_curv = irosData.collcurv; * jmx_id->mask_r = irosData.maskr; * jmx_id->mask_height= irosData.masksep; * jmx_id->hexa_dim = irosData.hexadim; * jmx_id->alfa = irosData.alpha; * jmx_id->beta = irosData.beta; * jmx_id->gammav = irosData.gamma; * jmx_id->phase2 = irosData.phase2; * backproj->x2xpix = irosData.x2x; * backproj->y2ypix = irosData.y2y; * backproj->offXpix = irosData.offx; * backproj->offYpix = irosData.offy; * jmx_id->scaleX = irosData.scalex; * jmx_id->scaleY = irosData.scaley; * jmx_id->offQrad = irosData.offq; * jmx_id->offRrad = irosData.offr; * jmx_id->mm2rad = 1.0 / jmx_id->mask_height; */ if( chatter > J_CHATTY_NORMAL ) RILlogMessage( NULL, Log_0,"##131c## status = %d", status ); backproj->FOV_radius = 128 * backproj->FOV_ff - 1; backproj->sky_xdim = backproj->sky_ydim = 2 * backproj->FOV_radius + 1; backproj->skydim = backproj->sky_xdim * backproj->sky_ydim; backproj->backmodels = BACKMODELS; if( chatter > J_CHATTY_NORMAL ) RILlogMessage( NULL, Log_0,"##131d## status = %d", status ); /* * The call from before 2007-06-27: * * status = alignment_init( * ptrImod, * jemxNum, * logger, * jmx_id, * chatter, * status); * */ status = JEMXLIBgetInstrData( instMod, ptrImod, jemxNum, jmx_id, logger, chatter, status); if( chatter > J_CHATTY_NORMAL ) RILlogMessage( NULL, Log_0,"##131e## status = %d", status ); if (status != ISDC_OK ) { sprintf(logger->tmptxt, "##133## Bad or missing alignment.dat, exiting!"); logger->logstat = logprint(logger, logger->tmptxt, 7); goto exittrace; } /* * Reading the EEFF, CFTM, and CURT information from IMOD * */ status = j_lpf_get_EEFF_CFTM_CURT( jemxNum, ptrImod, jmx_id, chatter, status); if( chatter > J_CHATTY_NORMAL ) RILlogMessage( NULL, Log_0,"##131f## status = %d", status ); if (status != ISDC_OK ) { sprintf(logger->tmptxt, "##134## Bad or missing alignment.dat, exiting!"); logger->logstat = logprint(logger, logger->tmptxt, 7); goto exittrace; } /* Verify time_slope_data */ sprintf(logger->tmptxt, "##1341## Time slope origin: %4.0f, slopes: ", jmx_id->eeff_time_origin); for (i=0; itmptxt2, " %5.3f", jmx_id->eeff_time_slope[i]); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } logger->logstat = logprint(logger, logger->tmptxt, logger->i5); /* * The following statements have been transferred from alignment_init.c * and changed to accomodate the shift from getting values in [mm] in stead * of [pixels] */ backproj->pix2mm = (jmx_id->coll_r + jmx_id->mask_r) / backproj->FOV_radius; backproj->pix2rad = backproj->pix2mm / jmx_id->mask_height; if( chatter > J_CHATTY_NORMAL ) RILlogMessage( NULL, Log_0,"##131f## status = %d", status ); /* * The following four statements are only put here for the * benefit of 'snapshot3'. The thus defined variables are * not used anywhere else. [2005-12-02/NJW] */ jmx_id->offXpix = jmx_id->offXmm / backproj->pix2mm; jmx_id->offYpix = jmx_id->offYmm / backproj->pix2mm; jmx_id->x2xpix = jmx_id->x2xmm / backproj->pix2mm; jmx_id->y2ypix = jmx_id->y2ymm / backproj->pix2mm; if ( chatter > J_CHATTY_VERY_VERBOSE ) { status = snapshot3( "##134##", jmx_id, chatter, status ); } sprintf(logger->tmptxt, "##135## dead_ano: %d, iterations: %d, edge: %f, limit_f:" " %lf, qual_limit: %lf, shdg_out_ctrl: %d", dead_ano, backproj->iterations, logger->edge, logger->limit_f, logger->qual_limit, logger->shdg_out_ctrl); logger->logstat = logprint(logger, logger->tmptxt, 4); /* table for sigma of peak in an image as function of energy. * Introduced 2005-05-17 [NJW] and must * later be defined in e.g. IMOD */ ima_sigma_table[0] = 3.0; ima_sigma_table[1] = 2.0; ima_sigma_table[2] = 1.8; ima_sigma_table[3] = 2.0; jemx = (jemxNum == JMX1) ? 0 : 1 ; jmx_id->jmx_unit = jemx; if (logger->shdg_out_ctrl > 0) logger->shdg_out_ctrl = 1; status = j_iir_get_shds( theSWG, jemxNum, sh, USERBIN, logger, chatter, status ); if (status != ISDC_OK) { RILlogMessage( NULL, Error_0,"##136## After attempt to get" " shds, status = %d", status); status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_SHDREADERR; goto exittrace; } backproj->ee_basic = 3; backproj->ee_max = sh->numShds; if (sh->numShds < 3) backproj->ee_basic = sh->numShds; logger->ee_search = backproj->ee_basic; for (i=0; inumShds; i++) { c_sum = 0.0; for (j=0; jf_shadgram[i][j]; sprintf(logger->tmptxt, "Shadowgram %3d contains %f counts\n", i, c_sum); logger->logstat = logprint(logger, logger->tmptxt, logger->i5); } if (sh->numShds > EE256) { sprintf(logger->tmptxt, "##137## No of energy bands requested (%2d)" " exceeds array dimensions (%3d), exiting!", sh->numShds, EE256); logger->logstat = logprint(logger, logger->tmptxt, 7); status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_EBAND_ERR; goto exittrace; } if( chatter > J_CHATTY_NORMAL ) { RILlogMessage( NULL, Log_0, "##138## %d shadowgrams", sh->numShds ); } /* * Define the detector radius limits from the input parameter values * based on the mean energies */ for( i = 0; i < sh->numShds; i++ ) { e_mean = 0.5*( sh->eval[i][0] + sh->eval[i][1] ); itmp = 0; if( e_mean > E_DRL1 ) itmp++; if( e_mean > E_DRL2 ) itmp++; if( e_mean > E_DRL3 ) itmp++; logger->det_rad_lim[i] = (int) (logger->drl_par[itmp] + 0.5); /* * if( (float) logger->det_rad_lim[i] > USERBIN[i].radlimit - 1.0) { * logger->det_rad_lim[i] = (int) (USERBIN[i].radlimit - 1.0); * RILlogMessage( NULL, Warning_0, * "##9151## Data radius limit #%d reduced to %d mm from %d mm. (shd radius limit - 1)", * i, logger->det_rad_lim[i], (int) (logger->drl_par[itmp] + 0.5)); * } */ backproj->ima_sigma[i] = ima_sigma_table[itmp]; if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##139## itmp = %d drl_par = %f", itmp, logger->drl_par[itmp]); RILlogMessage( NULL, Log_0, "##140## E%d (%4.1f keV) has det_rad_lim = %d mm", i, e_mean, logger->det_rad_lim[i] ); RILlogMessage( NULL, Log_0, "##141## itmp = %d ima_sigma_table = %f", itmp, ima_sigma_table[itmp]); RILlogMessage( NULL, Log_0, "##142## E%d (%4.1f keV) has ima_sigma = %f", i, e_mean, backproj->ima_sigma[i] ); } } /* * Get the 'empty field' shadowgrams with extra information */ status = j_iir_get_bkgshds( jemxNum, /* JMX1 or JMX2 */ ptrImod, /* Pointer to IMOD group */ bkgShdDOL, /* DOL of bkg shadowgrams (overrides IMOD) */ backproj, /* struct with backprojection info */ sh, /* struct with shadowgram info */ logger, /* log control parameters */ chatter, /* Level of debugging output */ status); /* Status flag */ /* * Make initialization for the backprojection process: */ if( chatter > J_CHATTY_VERY_VERBOSE ) { status = snapshot1( "##143##", backproj, sh, chatter, status ); } status = backsky_init(jemx, dead_ano, logger, backproj, jmx_id, sh, bp, USERBIN, SCWnow, chatter, status ); if( chatter > J_CHATTY_VERY_VERBOSE ) { status = snapshot1( "##144##", backproj, sh, chatter, status ); } if (status != ISDC_OK) { sprintf(logger->tmptxt, "##145## ref_file_name: %s, jemx: %1d, orbit: %3d", logger->ref_file_name, jemx+1, backproj->aux_orbit); /* sprintf(logger->tmptxt, "##145## ref_file_name: %s, full_ref_name: %s, jemx: %1d, orbit: %3d", logger->ref_file_name, full_ref_name, jemx+1, backproj->aux_orbit); */ logger->logstat = logprint(logger, logger->tmptxt, 7); sprintf(logger->tmptxt, "##146## Bad status on return from backsky_init"); logger->logstat = logprint(logger, logger->error_text, 7); goto exittrace; } /* sh->accumT = sh->shdgr_aux[27]; Old definition */ /* sh->shdgr_aux[4] = Orbit_number * 65536 + Pointing ID */ sh->aux_pidv = backproj->aux_pidv; status = j_iir_get_radec_init( theSWG, /* pointer to SWG */ jemxNum, /* JEMX identifier */ point, /* struct with pointing parameters */ &p_RA, &p_dec, &p_posang, logger, jmx_id, chatter, /* Level of debugging output */ status); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_0, "##147## %d: After j_iir_get_radec_init", status ); goto exittrace; } if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##148## RAdec: %f %f", p_RA, p_dec); RILlogMessage( NULL, Log_0, "##149## posang: %f", p_posang); } if( chatter > J_CHATTY_VERY_VERBOSE ) { status = snapshot1( "##150##", backproj, sh, chatter, status ); } SCWnow->orbit = backproj->aux_orbit; SCWnow->pid = backproj->aux_pid; SCWnow->pidv = sh->aux_pidv; SCWnow->jemx = jmx_id->jmx_unit; SCWnow->startT = sh->shdgr_aux[23]; SCWnow->endT = sh->shdgr_aux[24]; /* SCWnow->eff_obs_time = sh->shdgr_aux[27]; */ /* ------------------------------------------------------------ * Section for reading the flux correction coefficients from * JMXi-CFEX/CFEY-MOD * * Introduced 2008-07-07/NJW * -----------------------------------------------------------*/ status = j_lpf_get_XYvsE( jemxNum, ptrImod, jmx_id, chatter, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_0, "##147## %d: After j_lpf_get_XYvsE", status ); goto exittrace; } /* ------------------------------------------------------------ * Section for reading the image correction coefficients from * JMXi-CIEX/CIEY-MOD * * Introduced 2008-08-13/NJW * -----------------------------------------------------------*/ status = j_iir_get_XYvsEima( jemxNum, ptrImod, backproj, chatter, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_0, "##147## %d: After j_iir_get_XYvsEima", status ); goto exittrace; } /* ------------------------------------------------------------ * Section for reading the sigma(PSF) table from * JMXi-PSFS-MOD * * Introduced 2009-01-21/NJW * -----------------------------------------------------------*/ status = j_iir_get_psfsigma( jemxNum, ptrImod, backproj, sh, logger, chatter, status); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_0, "##148## %d: After j_iir_get_psfsigma", status ); goto exittrace; } /* ----------------------------------------------------------------- * * Read all flagged sources from JMXi-SRCL-CAT * and add to the array GOODSRC * * ----------------------------------------------------------------- */ if( jemxNum == JMX1 ) { strcpy( srclcatName, "JMX1-SRCL-CAT" ); } else { strcpy( srclcatName, "JMX2-SRCL-CAT" ); } backproj->preset_src = 0; /* Initialization */ preset_src2 = MAX_NUM_PRESET_SRCS - 1; /* initialize 'backward' pointer */ status = DALobjectFindElement( theSWG, srclcatName, &srclcatPtr, status); if( status == ISDC_OK ) { /* * Get number of rows in the catalog */ status = DALtableGetNumRows( srclcatPtr, &numRows, status ); if( status != ISDC_OK ) return( status ); if( numRows > 0 ) { /* * Allocate memory for reading the tables */ status = DALallocateDataBuffer((void**)&catFlag, numRows*sizeof(int), status); status = DALallocateDataBuffer((void**)&CLASS_OBJcat, numRows*sizeof(int), status); status = DALallocateDataBuffer((void**)&RA_OBJcat, numRows*sizeof(float), status); status = DALallocateDataBuffer((void**)&DEC_OBJcat, numRows*sizeof(float), status); status = DALallocateDataBuffer((void**)&ERR_OBJcat, numRows*sizeof(float), status); if ( status != ISDC_OK ) return( status ); /* * Read the columns */ DALtype = DAL_FLOAT; status = DALtableGetCol( srclcatPtr, "RA_OBJ", 0, &DALtype, &numRead, (void*)RA_OBJcat, status); status = DALtableGetCol( srclcatPtr, "DEC_OBJ", 0, &DALtype, &numRead, (void*)DEC_OBJcat, status); status = DALtableGetCol( srclcatPtr, "ERR_RAD", 0, &DALtype, &numRead, (void*)ERR_OBJcat, status); DALtype = DAL_INT; status = DALtableGetCol( srclcatPtr, "FLAG", 0, &DALtype, &numRead, (void*)catFlag, status); status = DALtableGetCol( srclcatPtr, "CLASS", 0, &DALtype, &numRead, (void*)CLASS_OBJcat, status); if ( status != ISDC_OK ) return( status ); /* * Select all sources within J_IIR_CATSRCLIM degrees from the pointing. * Avoid sources flagged with a '9' (user specified avoidance). * A maximum of number of MAX_NUM_PRESET_SRCS will be extracted. * Preference will be given to sources flagged with '1' and '3' */ for ( loop = 0; loop < numRows; loop++ ) { if (catFlag[loop] == 9) continue; /* Avoid this source */ if (backproj->preset_src >= MAX_NUM_PRESET_SRCS) continue; /* No more storage space */ /* * Do the test for off-axis angle in a reponse to SPR-04451 [2006-09-07/NJW] */ status = j_iir_arcdist(RA_OBJcat[loop], DEC_OBJcat[loop], p_RA, p_dec, &adist, status); if ((catFlag[loop] == 1) || (catFlag[loop] == 3)) { if ( adist < J_IIR_CATSRCRLIM ) { /* Extract this one */ if ((num_flag3 >= 3) && (catFlag[loop] == 3)) goto skip_flag3; /* don't accept more than 3 flag-3 sources */ if (catFlag[loop] == 3) num_flag3++; backproj->preset_src_RA[backproj->preset_src] = RA_OBJcat[loop]; backproj->preset_src_dec[backproj->preset_src] = DEC_OBJcat[loop]; backproj->preset_src_flag[backproj->preset_src] = catFlag[loop]; backproj->preset_src_id[backproj->preset_src] = loop + 1; backproj->preset_src++; /* remove low priority sources if necessary */ if (preset_src2 <= backproj->preset_src) preset_src2 = backproj->preset_src+1; sprintf(logger->tmptxt, "A %3d class: %5d, Err_Rad: %7.5f, RA/dec: %8.4f %8.4f, flag: %2d, src_id: %3d", (int)(loop), CLASS_OBJcat[loop], ERR_OBJcat[loop], RA_OBJcat[loop], DEC_OBJcat[loop], catFlag[loop], backproj->preset_src_id[backproj->preset_src-1]); logger->logstat = logprint(logger, logger->tmptxt, 0); skip_flag3: ; } } else { /* Extract other sources if there is room (avoid extended sources, classes 3000 and 5000, and planetary or unidentified objects and sources with 'ERR_RAD' > 0.001 deg (3.6")) */ if ((adist < J_IIR_CATSRCRLIM) && (ERR_OBJcat[loop] <= 0.001) && (CLASS_OBJcat[loop] < 8000) && ((int)(CLASS_OBJcat[loop] / 1000) != 3) && ((int)(CLASS_OBJcat[loop] / 1000) != 5)) { if (preset_src2 > backproj->preset_src) { backproj->preset_src_RA[preset_src2] = RA_OBJcat[loop]; backproj->preset_src_dec[preset_src2] = DEC_OBJcat[loop]; backproj->preset_src_flag[preset_src2] = 0; backproj->preset_src_id[preset_src2] = loop + 1; preset_src2--; if ((MAX_NUM_PRESET_SRCS - 1 - preset_src2) < 20) { sprintf(logger->tmptxt, "B %3d class: %5d, Err_Rad: %7.5f, RA/dec: %8.4f %8.4f, flag: %2d, src_id: %3d", (int)(loop), CLASS_OBJcat[loop], ERR_OBJcat[loop], RA_OBJcat[loop], DEC_OBJcat[loop], catFlag[loop], backproj->preset_src_id[preset_src2+1]); logger->logstat = logprint(logger, logger->tmptxt, 0); } } } } } } /* * Move the low priority sources up adjacent to the hig priority ones */ sprintf(logger->tmptxt, "prepare: input catalog entries: %3d, priority presets: %3d, inside FOV: num: %3d, ptr: %3d", (int)(numRows), backproj->preset_src, MAX_NUM_PRESET_SRCS - preset_src2 - 1, preset_src2); logger->logstat = logprint(logger, logger->tmptxt, 0); if ((preset_src2 < (MAX_NUM_PRESET_SRCS-1)) && (preset_src2 > (backproj->preset_src+1))) { k = preset_src2 - backproj->preset_src + 1; m = MAX_NUM_PRESET_SRCS - preset_src2 - 1; for ( loop = 0; loop < m; loop++ ) { backproj->preset_src_RA[backproj->preset_src] = backproj->preset_src_RA[backproj->preset_src + k]; backproj->preset_src_dec[backproj->preset_src] = backproj->preset_src_dec[backproj->preset_src + k]; backproj->preset_src_flag[backproj->preset_src] = 0; backproj->preset_src_id[backproj->preset_src] = backproj->preset_src_id[backproj->preset_src + k]; backproj->preset_src++; } } sprintf(logger->tmptxt, "prepare: after selection: j_ima_iros catalog entries: %3d", backproj->preset_src); logger->logstat = logprint(logger, logger->tmptxt, 0); } else { RILlogMessage( NULL, Warning_0, "##151## %d: Problem reading catalog; skip those sources", status ); status = ISDC_OK; } /*-------------------------------------------------------- * * Fill the auxiliary data struct (Auxdata) * [2010-03-03/NJW] * *--------------------------------------------------------*/ gtiNames = (char**) malloc( sizeof(char*) ); gtiNames[0] = (char*) malloc( 20*sizeof(char) ); strcpy( gtiNames[0], "MERGED" ); /* The sloppy way, see declarations */ status = j_read_GTI( theSWG, jemxNum, gtiNames, numNames, &nGTI, >iStartOBT, >iEndOBT, >iStartIJD, >iEndIJD, logger, chatter, status); if( J_IIR_NO_GTI == status) { RILlogMessage( NULL, Warning_2, "##123## No Good Time in selected GTI tables => exiting!"); return status; } /* TEST TEST */ if( nGTI > 0 ) { for( i = 0; i < nGTI; i++ ) { RILlogMessage( NULL, Log_0,"##4300## gtiStartIJD = %13.8f, OBT = %20llu", gtiStartIJD[i], gtiStartOBT[i]); RILlogMessage( NULL, Log_0,"##4300## gtiEndIJD = %13.8f, OBT = %20llu", gtiEndIJD[i], gtiEndOBT[i]); } } else { RILlogMessage( NULL, Log_0,"##4300## No GTIs found"); } auxdata->n_GTI = nGTI; auxdata->GTI_OBTstart = gtiStartOBT; auxdata->GTI_OBTstop = gtiEndOBT; auxdata->GTI_IJDstart = gtiStartIJD; auxdata->GTI_IJDstop = gtiEndIJD; if( auxdata->n_GTI > 0 ) { for( i = 0; i < auxdata->n_GTI; i++ ) { RILlogMessage( NULL, Log_0,"##4300## GTI_IJDstart = %13.8f, OBT = %20llu", auxdata->GTI_IJDstart[i], auxdata->GTI_OBTstart[i]); RILlogMessage( NULL, Log_0,"##4300## GTI_IJDstop = %13.8f, OBT = %20llu", auxdata->GTI_IJDstop[i], auxdata->GTI_OBTstop[i]); } } /* END TEST TEST */ status = j_iir_get_gain( theSWG, jemxNum, auxdata, logger, chatter, status); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_0,"##6661## %d: After j_iir_get_gain", status); goto exittrace; } /* TEST TEST */ if( auxdata->n_gains > 0 ) { for( i = 0; i < auxdata->n_gains; i++ ) { RILlogMessage( NULL, Log_0,"##4301## IJD = %13.8f, gain = %7.3f", auxdata->scpTimes[i], auxdata->scpGain[i]); } } else { RILlogMessage( NULL, Log_0,"##4301## No gain values found"); } /* END TEST TEST */ status = j_iir_get_greyfilter( theSWG, jemxNum, auxdata, logger, chatter, status); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_0,"##6662## %d: After j_iir_get_greyfilter", status); goto exittrace; } /* TEST TEST */ if( auxdata->n_greyValues > 0 ) { for( i = 0; i < auxdata->n_greyValues; i++ ) { RILlogMessage( NULL, Log_0,"##4302## IJD = %13.8f, grey = %3i", auxdata->greyTimes[i], auxdata->greyValues[i]); } } else { RILlogMessage( NULL, Log_0,"##4302## No grey values found"); } /* END TEST TEST */ status = j_iir_get_dead_time( theSWG, jemxNum, auxdata, logger, chatter, status); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_0,"##6663## %d: After j_iir_get_dead_time", status); goto exittrace; } /* TEST TEST */ if( auxdata->n_deadTimes > 0 ) { m = (auxdata->n_deadTimes - 1)/30 + 1; for( i = 0; i < auxdata->n_deadTimes; i += m ) { RILlogMessage( NULL, Log_0,"##4303## IJD = %13.8f, deadTime = %7.4f" ", rateCor = %7.4f, deadEff = %7.4f", auxdata->deadIJD[i], auxdata->deadTime[i], auxdata->rateCor[i], auxdata->deadEff[i]); } } else { RILlogMessage( NULL, Log_0,"##4303## No deadtime values found"); } /* END TEST TEST */ /*-------------------------------------------------------- * * Read events and build event list (struct Events) * *--------------------------------------------------------*/ status = j_iir_get_events( theSWG, /* Pointer to input SWG */ jemxNum, /* JEMX unit number */ bufevents, /* Pointer to struct with event information */ numEvents, /* Number of events */ SCWnow, /* Various ScW information */ auxdata, /* such as gain, GTI, and grey filter */ logger, tAccuracy, /* Time Corr. Accuracy */ rowSelect, /* CFITSIO selection string */ chatter, /* Level of debugging output */ status); /* Status flag */ if( status != ISDC_OK ) { RILlogMessage( NULL, Error_0,"##6663## %d: After j_iir_get_events", status); goto exittrace; } sprintf(logger->tmptxt, "# timeStart: %12.7f, timeStop: %12.7f, number of events in buffer: %9d, status: %d", SCWnow->gtiStartIJD, SCWnow->gtiStopIJD, (int)(*numEvents), status); logger->logstat = logprint(logger, logger->tmptxt, 0); exittrace: /* exittrace: */ /* if (logger->trace) traces(func_local, (int)(SCWnow), logger); */ 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 ); } /* ************************************************************* */ /* ************************************************************* */ /***************************************************************** * Name of source file: j_ima_iros_work.c * Version of source file: 4.0.12 * Parent component: None * Programmer: Niels Lund & Niels J. Westergaard * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325705 FAX: +45 35362475 * njw@dnsc.dk * Purpose: Initiate the backprojection and source * finding processes * Origin date: 041122 * Update history: 1.0.0 041130 First version * 1.0.4 050126 Test version for undue crash * 1.1.0 050131 Now reading FITS sky/backproj files * 1.1.1 050211 Keywords adapted to needs of j_ima_mosaic * 1.1.2 050303 Extra keyw:RLIMIDX, new cleaning * 1.1.3 050307 New DMAP: 51 radii * 1.1.4 050317 Align with PC-version as of 20050317 (NL) * 1.1.4 050328 'illum' cast to 'int' in 'if'-statement * 1.1.4 050407 New clean, etc. * 1.1.4 050407 New clean, etc. * 1.1.5 050415 New clean again, updated flux determination * 1.1.6 050418 Now uses JMXi-DBKG-MOD as default for empty field shds * 1.2.0 050425 Deals with SPR 4102,4108 and reduces RAM requirement * 1.3.0 050503 Deals with SPR 4120 and copes with up to 6 shadowgrams * 1.3.1 050517 Deals with SPR 4143 and initializes ima_sigma properly * 1.3.2 050519 Closes SPR 4157 - bad size of three arrays * 1.3.3 050602 Changes some arrays to static (SPR 4202) * 1.4.0 050620 Include user defined sources (SCREW 1740) * 1.4.1 051125 Transfer x_rms, y_rms and abs_len from jmx_id to backproj * 1.5.1 051129 Separating functions to jmx_lib_pif * 1.5.2 051202 Separating functions to jmx_lib_pif (2) * 1.5.3 051202 Give offX, x2x values in mm in IMOD-GRP * 1.5.4 060104 Bug in sh_depth corrected, detectmap now in mm * 1.5.5 060106 Introduced one more digit in logfile for src position * 1.5.6 060228 Removed parameter detMapFile and some obsolete variables * 1.5.7 060606 Shifted detCondMap to struct jmx_id and status_map * 1.5.8 060807 SPR 04551 Bad assignment of RLIMIDX corrected * 1.5.9 060807 SPR 04533 Resetting status variable has been removed * 1.5.10 060807 SPR 04523 Declaring testsum as float iso. int * 1.5.11 060807 SPR 04458 A warning log line has been added * 1.5.12 060907 SPR 04301 A relative VIGNDOL path is given * 1.6.0 060911 SCREW 1918 Image correction map and parameters introduced * 1.6.1 060912 SPR 4441 Shadowgrams with too few counts are excluded * 1.6.2 060915 SCREW 1842 A significance map can now be obtained * 1.6.3 060915 An exposure (vignetting) map is now a product * 1.6.4 060928 Included test for zero divisor in peaktransfer.c * 1.6.5 061002 New defaults for par. skyImagesOut * 1.7.0 061110 Produces images with few or zero events (SPR 4594) * 1.7.1 061114 SPR 4603 Image unit (BUNIT) is now cts/dm2/s * 1.8.0 061213 SPR 4640 Error in findpeak has been corrected * 1.8.1 070123 SPR 4590 int changed to long for 64 bit code * 1.8.2 070306 modified for new irosloop2 logic. * 2.1.0 070730 Active use of input source catalog * 2.1.0 070809 SCREWs 2021-2023 * only three fixed energy bands analyzed with IROS logic. * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.2.2 080111 Makes HK values available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.X 090320 Modified 'peaktransfer' and error estimation * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.2 090519 SPR 4866+4869 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 4.0.2 120321 SPR ?: Bug reported by JC, LP fixed * 4.0.6 120628 SPR ?: Reduced memory allocation demands * 4.0.7 120710 SPR ?: Flux error estimates as in version 3.2.7 * 4.0.9 120820 SPR ?: Improve FITS header content * 4.0.10 120830 SPR ?: Initialize variables as suggested by valgrind * 4.0.12 120919 SPR ?: Introduce corrections by LP and Co. * Type of element: Function * Part of package: j_ima_iros * Name: j_ima_iros_work * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ /* QQQQQQ */ int j_ima_iros_work( dal_element *theSWG, /* pointer to the SWG */ Auxdata auxdata, /* such as gain, GTI, and greyfilter */ struct instr_data *jmx_id, struct log_con *logger, swg_pointing *point, Events *bufevents, struct backpro *backproj, struct shadowgrams *sh, struct backpro_lists *bp, struct scwlist *SCWnow, goodsrc *GOODSRC, userbin *USERBIN, timeslices *Tslices, /* Shd_adhoc shd_adhoc, */ int chatter, int status ) { Instrument jemxNum; char ID_string[13]; char f_exttext[2][J_IIR_TEXTSIZE]; char elmntName[DS_NAME_SIZE]; int eeb, eeuser, eelim, kMAX, i5 = 0; int jb, ix, oldaccessum, newaccessum, jemx, addnew; int ch1, ch2, ch3, ch4, ch5, ch6, ch7; int chx1[256][4], chx2[256][4]; int preset_temp = 0, n_additional, xsrc; int sky_index, ghoststep[2], srclist_index; static float xx[SCW_SRCMAX], yy[SCW_SRCMAX]; static float goodbet[SCW_SRCMAX]; static float backcnt[EE256+1][SCW_SRCMAX]; static float shadow[detdim]; static float peakval[2*EE256][SCW_SRCMAX]; static float shadow_r[detdim], shdg_fits[detdim]; static float s_reject[EE256]; static float s_accept[EE256]; static float take_away_var[SCW_SRCMAX]; static int src_id[SCW_SRCMAX]; static short used_ee[EE256][N_SRCMAX], used2[N_SRCMAX], preset[SCW_SRCMAX]; static short AA[256]; static double solut_e[EE256][SCW_SRCMAX]; static double solut[SCW_SRCMAX]; static double orig_solut[4][4], orig_rms[4]; static float maps[300 * sizeof(MAPS_SRC) / sizeof (float)]; MAPS_SRC *maps_src = NULL; double sh_rms[EE256+1][4]; double amx[6], sky_rms, val; double timestep; int map_n, xvalstart, yvalstart, n; int ylow, yhigh, ShNNN; int edgepix[9], edgepi2[9], edgepi3[9]; float fitrms, factor, pkval, ShSUM; float diff_x, diff_y, x, y, r; float cmx, cmy, avr, aveffi, avillu; float funval, transmis, Emin, Emax; float sumX, sumY, sumgood; float s_dec, s_RA; float avX0, avY0, xmm, ymm; float peakcount[2]; float fk, sum_str, tot_area, sn_best, sn_temp; float temptot, tempgood; float sn_new, normfact, xx_dif, yy_dif; float s_sum, c_sum; float hot_reject; float testsum = 0.0; float eff_imag_min=1000.0, eff_imag_max=-1000.0; float mean_bkg[2] = {0.0, 0.0}; float e_minim, e_maxim, meanE, shsum; float abs_len, escape, remaining; float rawcount, Apix, Anoise = 0.5; /* float pifnum, pifmax, pifmean, pifmin, pifval, pifzero; */ float edgeXmm[9], edgeYmm[9]; float X_rms[256], Y_rms[256]; float RMS_correction, rms_factor, x_rms, y_rms; int i, j, k, kkkk, num_flag1_srcs, num_flag3_srcs; int chk_no, skysize; int pixels, j_src, psrc, pd ; int bitpix, dim1, dim2; int isrc, jsrc, n_src1, n_src2; int starTm=0, starTh=0, stopTh=0, stopTm=0; int n_common, n_common2; int iee, vigncorr = 1; /* default: vignetting correction will be applied ! */ int n_sources, n_sources_ini, fitcycles; int e1, e2, ksrc; int n_src; int ij, ij_out; int baseErr; int e1_stop, e2_stop, ic_stop, jc_stop; int PIlop; int ntime; double quality, diff, sum; double sh_rms2; double startT=0, stopT=0, xrms, yrms; double sumtot, cdelt, rad_ang; double divisor = 0.0, exposure = 0.0; double nn_f_min, nn_f_max, varim_min, varim_max; static struct fit_struc FS1, FS2; struct fit_struc *f_struc1 = {&FS1}; struct fit_struc *f_struc2 = {&FS2}; static struct candsrc CANDSRC[N_SRCMAX]; /* structure containing information about source candidates found */ int pif_status; FILE *par_chk; char calibname[100]; maps_src = (MAPS_SRC*)maps; 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_ima_iros_work"); 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 */ logger->shdg_out_ctrl = 1; /* 111111 */ /* QQQQQQ */ if (logger->trace) traces(func_local, 0, logger); i5 = logger->i5; /* NL 20120122 */ status = ISDC_OK; logger->new_detmap = 1; for (i=0; isrc_illum_cnts[i][j] = 0.0; for (i=0; iorig_data_peak[j][i] = 0.0; for (i=0; i<3*SCW_SRCMAX; i++) backproj->blindspots[i] = 0; /* *************************************************************************** */ /* */ /* */ /* Special case for off-axis transient search */ /* */ /* */ /* *************************************************************************** */ if (logger->useHexpos == 100) { edgeXmm[0] = edgeYmm[0] = edgeYmm[1] = edgeYmm[5] = edgeXmm[3] = edgeXmm[7] = 0.0; edgeXmm[1] = 237.0; edgeYmm[7] = 233.0; edgeXmm[5] = -240.0; edgeYmm[3] = -238.0; edgeXmm[2] = edgeXmm[8] = 225.0 / sqrt(2.0); edgeXmm[6] = -223.0 / sqrt(2.0); edgeYmm[6] = 223.0 /sqrt(2.0); edgeYmm[8] = 215.0 / sqrt(2.0); edgeYmm[2] = edgeYmm[4] = edgeXmm[4] = -225.0 / sqrt(2.0); for (j=0; j<9; j++) { status = detectmap2(edgeXmm[j], edgeYmm[j], &(backproj->edgemap[j][0]), 0, jmx_id->jmx_unit, jmx_id, logger); edgepix[j] = edgepi2[j] = edgepi3[j] = 0; for (i=0; iedgemap[j][i] > 0) edgepix[j]++; if (backproj->edgemap[j][i] > 1) edgepi2[j]++; if ((backproj->edgemap[j][i] > 1) && (sh->soft_shdgr[0][i] > 0.0)) edgepi3[j]++; } sprintf(logger->tmptxt, "EDGE pixel count for (x,y): %6.1f %6.1f, pixelcount: %6d %6d %6d", edgeXmm[j], edgeYmm[j], edgepix[j], edgepi2[j], edgepi3[j]); logger->logstat = logprint(logger, logger->tmptxt, i5); } } /* *************************************************************************** */ /* */ /* */ /* BEGIN BLOCK PROCESSING ONE SCIENCE WINDOW */ /* */ /* */ /* */ /* *************************************************************************** */ backproj->map_cnt = 0; for (i=0; is_detect[i] = 0; for (i=0; i<256; i++) AA[i] = 1; for (i=0; imap_cnt = 0; for (PIlop=0; PIlop<256; PIlop++) { X_rms[PIlop] = jmx_id->cposres[PIlop] / 2.36; Y_rms[PIlop] = jmx_id->bposres[PIlop] / 2.36; RMS_correction = 0.5; /* QQQQQ originally: 0.5; Niels Lund 20080421 */ if (jmx_id->jmx_unit == 0) { if (jmx_id->escale[PIlop] < 11.0) rms_factor = 1.0 + RMS_correction; if ((jmx_id->escale[PIlop] >= 11.0) && (jmx_id->escale[PIlop] < 35.0)) rms_factor = 1.0 + RMS_correction * (35.0 - jmx_id->escale[PIlop]) / 24.0; if (jmx_id->escale[PIlop] >= 35.0) rms_factor = 1.0; X_rms[PIlop] /= rms_factor; Y_rms[PIlop] /= rms_factor; } /* printf("%3d, E: %5.2f, rmsX/Y: %6.2f %6.2f, att_len: %6.2f\n", PIlop, jmx_id->escale[PIlop], X_rms[PIlop], Y_rms[PIlop], jmx_id->attlen_xe[PIlop]); */ } for (i=0; inumBkgShds; i++) { meanE = 0.0; k = 0; for (j=0; j<256; j++) { if ((jmx_id->escale[j] >= sh->bkg_eval[i][0]) && (jmx_id->escale[j] <= sh->bkg_eval[i][1])) { k++; meanE += jmx_id->escale[j]; } } sh->E_mean_bkg[i] = meanE / (float)(k); /* printf("Mean E backgr: bkg_shd: %1d, E_mean_bkg: %f\n", i, sh->E_mean_bkg[i]); */ } /* if (jmx_id->jmx_unit == 0) fine_anoder(AA); */ /* get NJW selected anodes into AA */ ch1 = ch2 = ch3 = ch4 = ch5 = ch6 = ch7 = 0; yhigh = 0; ylow = 256; for (i=0; istatus_map[i] > 0) { ch1++; if ((i%256) > yhigh) yhigh = i % 256; if ((i%256) < ylow ) ylow = i % 256; if ((jmx_id->status_map[i] <= sh->detAccLimit) && (jmx_id->status_map[i] != 32)) ch2++; } if (sh->soft_shdgr[0][i] > 0.0) ch3++; if (sh->soft_shdgr[1][i] > 0.0) ch4++; if (sh->soft_shdgr[2][i] > 0.0) ch5++; if (sh->soft_shdgr[3][i] > 0.0) ch6++; /* prepare common select map to be used for all energy bands */ ix = i / 256; sh->common_select_map[i] = 0; if ((jmx_id->status_map[i] > 0) && (AA[ix] == 1) && (jmx_id->status_map[i] <= sh->detAccLimit) && (jmx_id->status_map[i] != 32)) { if ((sh->soft_shdgr[0][i] > 0.0) && (sh->soft_shdgr[1][i] > 0.0) && (sh->soft_shdgr[2][i] > 0.0) && (sh->soft_shdgr[3][i] > 0.0)) sh->common_select_map[i] = 1; } if (sh->common_select_map[i] > 0) ch7++; } /* printf("status map counters: %d %d %d %d %d %d %d, numBkgShds: %d\n", ch1, ch2, ch3, ch4, ch5, ch6, ch7, sh->numBkgShds); */ for (j=0; jempty[j][i] = 0.0; /* ************************************************************************* */ /* * * */ /* * QQQQQQ * */ /* * Make loop over search energy bins and generate corresponding * */ /* * background shadowgrams * */ /* * * */ /* * * */ /* ************************************************************************* */ for (eeuser=0; eeuseree_basic; eeuser++) { status = j_fitprep(eeuser, theSWG, jmx_id, logger, backproj, sh, bp, SCWnow, USERBIN, chatter, status); if (logger->trace) traces(func_local, 55, logger); if (status < 0) goto exittrace; } /* prepare header data for fits files */ sprintf(ID_string, "%04d%04d%04d", backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv); sprintf(logger->ref_file_name, "Not used"); if (jmx_id->jmx_unit == 0) { sprintf(f_struc1->instru, "JMX1"); jemxNum = JMX1; strcpy(elmntName, "JMX1-EVTS-SHD"); jemx = 0; } else { sprintf(f_struc1->instru, "JMX2"); jemxNum = JMX2; strcpy(elmntName, "JMX2-EVTS-SHD"); jemx = 1; } f_struc1->naxis1 = J_IIR_DIM_STDSHDG; f_struc1->naxis2 = J_IIR_DIM_STDSHDG; f_struc1->bitpix = -32; f_struc1->jemx = jmx_id->jmx_unit; f_struc1->orbit = backproj->aux_orbit; f_struc1->pid = backproj->aux_pid; f_struc1->pidv = sh->aux_pidv; f_struc1->ctrl = 0; dim1 = dim2 = backproj->FOV_radius * 2 + 1; /* midisky image dimensions */ bitpix = -32; /* use float representation in FITS file */ if (jmx_id->jmx_unit == 0) sprintf(f_struc2->instru, "JMX1"); else sprintf(f_struc2->instru, "JMX2"); f_struc2->naxis1 = dim1; f_struc2->naxis2 = dim2; f_struc2->bitpix = -32; f_struc2->jemx = jmx_id->jmx_unit; f_struc2->orbit = backproj->aux_orbit; f_struc2->pid = backproj->aux_pid; f_struc2->pidv = sh->aux_pidv; f_struc2->crval1 = SCWnow->jmxRA; f_struc2->crval2 = SCWnow->jmxdec; f_struc2->rot_ang = SCWnow->roll_angle + jmx_id->phase2; f_struc2->crpix1 = (double)(backproj->FOV_radius+1); f_struc2->crpix2 = (double)(backproj->FOV_radius+1); f_struc2->exposure = sh->accumT; f_struc2->varia_id = 100; f_struc2->ctrl = 1; strcpy(f_struc2->bkg_model, logger->ref_file_name); for (i=0; itmptxt, "##8777## In work: preset_src: %d\n", backproj->preset_src); logger->logstat = logprint(logger, logger->tmptxt, i5); j = backproj->preset_src + SCW_SRCMAX; for (i=0; ipointing_RA = point->j_RA / GTORAD; SCWnow->pointing_dec = point->j_dec / GTORAD; SCWnow->roll_angle = point->j_posangle / GTORAD; SCWnow->jmxRA = point->jmxRA; SCWnow->jmxdec = point->jmxdec; num_flag1_srcs = 0; num_flag3_srcs = 0; n = backproj->preset_src; /* Eliminate offending user specified sources */ if (backproj->preset_src > 0) { for (i=0; ipreset_src; i++) { next_try: /* next_try */ status = getxy(backproj->preset_src_RA[i], backproj->preset_src_dec[i], jmx_id->jmx_unit, &xmm, &ymm, jmx_id, point, logger); if (status < 0) { /* remove offending source (outside FOV) */ for (j=i; j<(backproj->preset_src-1); j++) { backproj->preset_src_RA[j] = backproj->preset_src_RA[j+1]; backproj->preset_src_dec[j] = backproj->preset_src_dec[j+1]; backproj->preset_src_flag[j] = backproj->preset_src_flag[j+1]; } backproj->preset_src--; sprintf(logger->tmptxt, "Source removed: RA/dec: %f %f, flag: %d\n", backproj->preset_src_RA[i], backproj->preset_src_dec[i], backproj->preset_src_flag[i]); logger->logstat = logprint(logger, logger->tmptxt, i5); status = 0; if (backproj->preset_src > i) goto next_try; } else { backproj->preset_src_xx[i] = xmm / backproj->pix2mm + backproj->FOV_radius; backproj->preset_src_yy[i] = ymm / backproj->pix2mm + backproj->FOV_radius; if (backproj->preset_src_flag[i] == 3) num_flag3_srcs++; if (backproj->preset_src_flag[i] == 1) num_flag1_srcs++; sprintf(logger->tmptxt, "Catalog src in FOV, X/Y: %f %f, flag: %d\n", backproj->preset_src_xx[i]-backproj->FOV_radius, backproj->preset_src_yy[i]-backproj->FOV_radius, backproj->preset_src_flag[i]); logger->logstat = logprint(logger, logger->tmptxt, 0); } } } sprintf(logger->tmptxt, "Original number of catalog sources: %3d, inside FOV: %d, flag-1/3 sources: %2d %2d", n, backproj->preset_src, num_flag1_srcs, num_flag3_srcs); logger->logstat = logprint(logger, logger->tmptxt, i5); if (num_flag3_srcs > SCW_SRCMAX-backproj->backmodels) num_flag3_srcs = SCW_SRCMAX-backproj->backmodels; sprintf(logger->tmptxt, "Total number of accepted catalog sources: %3d, flag-1/3 preset src: %2d %2d", backproj->preset_src, num_flag1_srcs, num_flag3_srcs); logger->logstat = logprint(logger, logger->tmptxt, i5); /* ************************************************************************* */ /* * * */ /* * QQQQQQ * */ /* * check for preset source type-3 and introduce these in source list * */ /* * * */ /* * * */ /* ************************************************************************* */ n_sources = backproj->backmodels; for (i=0; isky_ydim - 294; ghoststep[1] = -318 * backproj->sky_ydim + 37; } else { ghoststep[0] = -126 * backproj->sky_ydim + 294; ghoststep[1] = 318 * backproj->sky_ydim - 37; } for (i=0; ipreset_src; i++) { if (backproj->preset_src_flag[i] != 3) continue; /* introduce preset sources type-3 into list */ xx[n_sources] = backproj->preset_src_xx[i]; yy[n_sources] = backproj->preset_src_yy[i]; preset[n_sources] = 3; sprintf(logger->tmptxt, "##261x## work2: preset src3: %2d, xx/yy: %6.2f %6.2f", backproj->blindnum_preset, xx[n_sources], yy[n_sources]); logger->logstat = logprint(logger, logger->tmptxt, 0); /* make irosloop 'blind' to the preset sources */ sky_index = (int)(yy[n_sources] + 0.5) + (int)(xx[n_sources] + 0.5) * backproj->sky_ydim;; backproj->blindspots[backproj->blindnum_preset] = sky_index; n_sources++; if (n_sources >= SCW_SRCMAX) n_sources = SCW_SRCMAX - 1; else { backproj->blindnum_preset++; /* check for potential ghosts, eliminate these as well. Note: one more instance! NL 2009-12-03 */ if (((sky_index + ghoststep[0]) > 0) && ((sky_index + ghoststep[0]) < backproj->skydim)) { backproj->blindspots[backproj->blindnum_preset] = sky_index + ghoststep[0]; backproj->blindnum_preset++; } if (((sky_index + ghoststep[1]) > 0) && ((sky_index + ghoststep[1]) < backproj->skydim)) { backproj->blindspots[backproj->blindnum_preset] = sky_index + ghoststep[1]; backproj->blindnum_preset++; } } } /* ************************************************************************* */ /* ************************************************************************* */ /* * * */ /* * * */ /* * Here starts the source finding loop over the basic energy bands * */ /* * (ends approximately in line 930) * */ /* * * */ /* * * */ /* ************************************************************************* */ /* ************************************************************************* */ /* 222222 */ /* QQQQQQ */ n_sources_ini = n_sources; for (eeb=0; eebee_basic; eeb++) { /* eeb = 0 to 2 indicates the energy band */ n_sources = n_sources_ini; if (logger->trace) traces(func_local, 90000+eeb, logger); SCWnow->cand_lst_start[eeb] = logger->N_SRC; /* save start index value of source candidate list */ for (i=0; iskydim; i++) { /* backproj->fitsimage[eeb][0][i] = USERBIN[eeb].variance[i]; */ backproj->illumx[i] = USERBIN[eeb].illumnew[i]; backproj->access[i] = 0; if (backproj->illumx[i] >= (int)(backproj->signiflim)) backproj->access[i] = 1; } for (i=0; ieffic[i] = USERBIN[eeb].effic_shdg[i]; if ((sh->common_select_map[i] > 0) && (USERBIN[eeb].effic_shdg[i] > 0.0)) backproj->soft_gr[i] = USERBIN[eeb].soft_gr[i]; else backproj->soft_gr[i] = -1.0; /* this pixel should not be used */ } /* fits output for Niels Landvad. Start */ status = fits_test_output("shadow_", USERBIN[eeb].shadow, 256, logger, chatter, status); status = fits_test_output("soft_gr_", USERBIN[eeb].soft_gr, 256, logger, chatter, status); status = fits_test_output("effic_shdg_", USERBIN[eeb].effic_shdg, 256, logger, chatter, status); status = fits_test_output("f_shadgram_", USERBIN[eeb].f_shadgram, 256, logger, chatter, status); /* fits output for Niels Landvad. End */ /* * if( chatter > J_CHATTY_MAXIMAL ) { * RILlogMessage( NULL, Log_0, "##34## Dump of backproj->soft_gr"); * status = fits_test_output( "soft_gr_", backproj->soft_gr, 256, logger, chatter, status ); * if( status != ISDC_OK ) goto exittrace; * } */ /* transfer the raw shadowgram to be analyzed into "shadow_r[]" */ s_sum = s_accept[eeb] = s_reject[eeb] = 0.0; pixels = 0; backproj->act_pix[eeb] = 0.0; for (i=0; isoft_gr[i] > 0.0) { shadow_r[i] = USERBIN[eeb].f_shadgram[i]; shadow[i] = USERBIN[eeb].shadow[i]; s_accept[eeb] += USERBIN[eeb].f_shadgram[i]; s_sum += shadow_r[i]; backproj->act_pix[eeb] += 1.0; pixels++; } else { shadow_r[i] = 0.0; s_reject[eeb] += USERBIN[eeb].f_shadgram[i]; } } hot_reject = 0.0; /* hot_reject = hotpix_chk(shadow_r, eeb, backproj, logger); */ s_accept[eeb] -= hot_reject; s_sum -= hot_reject; s_reject[eeb] += hot_reject; sprintf(logger->tmptxt, "##35## Accepted/rejected shadowgram counts: E%2d: %8.1f %8.1f, hot_rejects: %6.1f", eeb, s_accept[eeb], s_reject[eeb], hot_reject); logger->logstat = logprint(logger, logger->tmptxt, 2); sh_rms[eeb][0] = rmscalc(shadow_r, backproj->soft_gr, logger); if( pixels == 0.0 ) { RILlogMessage( NULL, Warning_1,"##36## Attempt to divide with zero! reset to 1"); pixels = 1.0; } SCWnow->mean_pix[eeb] = s_accept[eeb] / (float)(pixels); if (logger->shdg_out_ctrl == 1) { /* output status map as FITS */ for(i=0; i<256-logger->fits_shft; i++){ for (j=0; j<256; j++) { ij = i + j*256; shdg_fits[ij] = (float)(jmx_id->status_map[ij]); } } strcpy(f_exttext[0], "status map"); strcpy(f_exttext[1], "condition map shadowgram"); status = shdg_to_fits(theSWG, eeuser, shdg_fits, jemxNum, elmntName, f_exttext, f_struc1, logger, eeb, sh, chatter, status ); if (status != ISDC_OK) goto exittrace; /* output raw input shadowgram as FITS */ strcpy(f_exttext[0], "RAWSHDIN_T"); strcpy(f_exttext[1], "Raw input shadowgram - transposed"); status = shdg_to_fits(theSWG, eeuser, shadow_r, jemxNum, elmntName, f_exttext, f_struc1, logger, eeb, sh, chatter, status ); if (status != ISDC_OK) goto exittrace; /* output pixelfolded shadowgram as FITS */ strcpy(f_exttext[0], "PIXFOLD_SHDGR"); strcpy(f_exttext[1], "Pixelfold shadowgram"); status = shdg_to_fits(theSWG, eeuser, shadow, jemxNum, elmntName, f_exttext, f_struc1, logger, eeb, sh, chatter, status ); if (status != ISDC_OK) goto exittrace; } if (USERBIN[eeb].totcnt <= 1.0) { sh_rms[eeb][1] = 0.0; SCWnow->cand_lst_no[eeb] = 0; continue; } sh_rms[eeb][1] = rmscalc(shadow, backproj->soft_gr, logger); fk = 0.0; j = 0; for (i=0; isoft_gr[i] > 0.0) fk += shadow[i]; if (shadow[i] > 0.0) j++; backproj->shadw[i] = shadow[i]; } sprintf(logger->tmptxt, "##40## JEM-X%1d. Cnts/rms before imageprep: %8.1f/%8.2lf, after: %8.1f/%8.2lf, check: %6.0f, E%02d, nonzero: %5d", jmx_id->jmx_unit+1, s_sum, sh_rms[eeb][0], USERBIN[eeb].totcnt, sh_rms[eeb][1], fk, eeb, j); logger->logstat = logprint(logger, logger->tmptxt, 2); jmx_id->absolen = USERBIN[eeb].abs_len; /* calculate the position scatter around the X-ray absorbtion point at this energy */ jmx_id->scatt_len = sh_xy(USERBIN[eeb].x_rms, USERBIN[eeb].y_rms, logger, jmx_id); if ((logger->develop & 1) == 1) { if (eeb == 0) par_chk = fopen("work_par_chk.txt", "wt"); else par_chk = fopen("work_par_chk.txt", "at"); saveparams(par_chk, eeb, jmx_id, backproj, bp, logger); fclose(par_chk); } /* **************************************************************************************** */ /* */ /* The "irosloop2" goes through the full "Iterative Removal Of Sources" sequence */ /* for one energy value (eeb) until the loop terminates due to limited significance or */ /* too many iteration loops */ /* */ /* **************************************************************************************** */ sprintf(logger->tmptxt, "##41## calling irosloop"); logger->logstat = logprint(logger, logger->tmptxt, 2); backproj->stopcode[eeb] = 0; preset_temp = backproj->preset_src; if (logger->trace) traces(func_local, 91000+eeb, logger); if (logger->dontUseShdg[eeb] > 0) { n_sources = backproj->backmodels; } else { status = irosloop2(jmx_id->jmx_unit, eeb, xx, yy, src_id, solut, &fitrms, &sh_rms2, &fitcycles, &n_sources, goodbet, preset, jmx_id, logger, backproj, bp, sh, maps_src, chatter, status); } if (logger->trace) traces(func_local, 92000+eeb, logger); backproj->preset_src = preset_temp; if ( status != ISDC_OK ) { logger->logstat = logprint(logger, logger->error_text, 7); status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_IROSLOOPERR; goto exittrace; } if (logger->trace) traces(func_local, 93000+eeb, logger); sprintf(logger->tmptxt, "##42## returning from irosloop, ee: %1d, n_sources: %4d, stopcode: %1x", eeb, n_sources, backproj->stopcode[eeb]); logger->logstat = logprint(logger, logger->tmptxt, 2); /* status = fits_test_output( "work2_usbfi_", USERBIN[eeb].fst_imag, 511, logger, chatter, status ); * the content USERBIN[eeb].fst_image and of backproj->fitsimage[eeb][2] is unchanged here */ if( chatter > J_CHATTY_VERBOSE ) { testsum = 0.0; for( i = 0; i < backproj->skydim; i++ ) testsum += backproj->fitsimage[eeb][0][i]; RILlogMessage( NULL, Log_0,"##43## SUM fitsimage[eeb][0] = %f", testsum); testsum = 0.0; for( i = 0; i < backproj->skydim; i++ ) testsum += backproj->fitsimage[eeb][1][i]; RILlogMessage( NULL, Log_0,"##44## SUM fitsimage[eeb][1] = %f", testsum); testsum = 0.0; for( i = 0; i < backproj->skydim; i++ ) testsum += backproj->fitsimage[eeb][2][i]; RILlogMessage( NULL, Log_0,"##45## SUM fitsimage[eeb][2] = %f", testsum); testsum = 0.0; for( i = 0; i < backproj->skydim; i++ ) if (backproj->access[i] > 0) testsum += backproj->fitsimage[eeb][0][i]; RILlogMessage( NULL, Log_0,"##47## SUM fitsimage[eeb][0] = %f", testsum); testsum = 0.0; for( i = 0; i < backproj->skydim; i++ ) if (backproj->access[i] > 0) testsum += backproj->fitsimage[eeb][1][i]; RILlogMessage( NULL, Log_0,"##48## SUM fitsimage[eeb][1] = %f", testsum); testsum = 0.0; for( i = 0; i < backproj->skydim; i++ ) if (backproj->access[i] > 0) testsum += backproj->fitsimage[eeb][2][i]; RILlogMessage( NULL, Log_0,"##49## SUM fitsimage[eeb][2] = %f", testsum); } if (logger->test == 99) {n_sources = 1000; continue;} /* test witout requiring backpro8_d */ SCWnow->cand_lst_no[eeb] = n_sources - backproj->backmodels; SCWnow->fitcycles[eeb] = fitcycles; for (isrc=backproj->backmodels; isrcN_SRC].scw_ID = logger->N_SCW; CANDSRC[logger->N_SRC].ee = eeb; CANDSRC[logger->N_SRC].xx = xx[isrc]; CANDSRC[logger->N_SRC].yy = yy[isrc]; CANDSRC[logger->N_SRC].preset = preset[isrc]; CANDSRC[logger->N_SRC].src_id = src_id[isrc]; CANDSRC[logger->N_SRC].src_strength = goodbet[isrc]; sprintf(logger->tmptxt, "CANDSRC[%4d]: ee: %1d, X/Y: %f %f, preset: %3d, src_id: %3d", logger->N_SRC, CANDSRC[logger->N_SRC].ee, CANDSRC[logger->N_SRC].xx, CANDSRC[logger->N_SRC].yy, CANDSRC[logger->N_SRC].preset, CANDSRC[logger->N_SRC].src_id); logger->logstat = logprint(logger, logger->tmptxt, i5); if (logger->tot_cnt_norm[eeb] == 0.0 ) { RILlogMessage( NULL, Warning_1,"##51## Attempt to divide with zero! reset to 1"); logger->tot_cnt_norm[eeb] = 1.0; } normfact = USERBIN[eeb].totcnt / logger->tot_cnt_norm[eeb]; logger->N_SRC++; if (logger->N_SRC > N_SRCMAX) { sprintf(logger->tmptxt, "##52## Too many source candidates: %5d", logger->N_SRC); logger->logstat = logprint(logger, logger->tmptxt, 7); status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_TOOMANYCAND; if (logger->trace) traces(func_local, 94000+eeb, logger); goto exittrace; } } SCWnow->backgr_str[eeb][0] = goodbet[0]; SCWnow->backgr_str[eeb][1] = goodbet[1]; SCWnow->backgr_area[eeb] = backproj->act_pix[eeb] / 100.0; SCWnow->fitrms[eeb] = fitrms; sh_rms[eeb][2] = sh_rms2; if (n_sources == 1000) continue; /* special signal for irosloop return */ /* ******************************************************** */ /* */ /* Analysis of this energy band completed. Store results */ /* for later comparison with the other energy bands. */ /* */ /* ******************************************************** */ sprintf(logger->tmptxt, " "); /* print newline */ logger->logstat = logprint(logger, logger->tmptxt, i5); sprintf(logger->tmptxt, "##53## JMX%1d E: %02d, t: %6.0f s, Const. fitpwr, %8.1lf, Backgr. fitpwr, %8.1lf", jmx_id->jmx_unit+1, eeb, sh->accumT, SCWnow->backgr_str[eeb][0], SCWnow->backgr_str[eeb][1]); logger->logstat = logprint(logger, logger->tmptxt, i5); for (isrc=backproj->backmodels; isrccand_lst_start[eeb] + isrc - backproj->backmodels; if(backproj->norm_d[isrc][eeb] == 0.0 ) { RILlogMessage( NULL, Warning_1,"##54## Attempt to divide with zero! reset to 1"); backproj->norm_d[isrc][eeb] = 1.0; } CANDSRC[n_src].src_pixel_area = 0.01 / backproj->norm_d[isrc][eeb]; if (logger->pointdata > 0) { /* get the background area corresponding to each source */ status = FUN(isrc, 0, eeb, xx, yy, jmx_id->jmx_unit, 0, &funval, jmx_id, logger, backproj, chatter, status); if (status != ISDC_OK) { logger->logstat = logprint(logger, logger->error_text, 7); status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_FUNERR; if (logger->trace) traces(func_local, 95000+eeb, logger); goto exittrace; } backcnt[eeb][isrc] = 2.0 * funval; /* determine RA and dec of the source candidates found at this energy */ xmm = (xx[isrc] - backproj->FOV_radius) * backproj->pix2mm; ymm = (yy[isrc] - backproj->FOV_radius) * backproj->pix2mm; getRAdec(xmm, ymm, jmx_id->jmx_unit, &s_RA, &s_dec, point, logger, jmx_id); CANDSRC[n_src].RA = s_RA; CANDSRC[n_src].dec = s_dec; CANDSRC[n_src].src_backgr_area = backcnt[eeb][isrc]; sprintf(logger->tmptxt, "##55## src: %1d, fitpwr: %8.1lf, XY: %+6.1f %+6.1f E: %2d RA/dec: %+7.3f %+7.3f, bkg_area: %6.1f, src_id: %3d", isrc, CANDSRC[n_src].src_strength, CANDSRC[n_src].xx, CANDSRC[n_src].yy, CANDSRC[n_src].ee, CANDSRC[n_src].RA, CANDSRC[n_src].dec, backcnt[eeb][isrc], CANDSRC[n_src].src_id); logger->logstat = logprint(logger, logger->tmptxt, i5); } else { sprintf(logger->tmptxt, "##56## src: %1d, fitpwr: %8.1lf, XY: %+6.1f %+6.1f E: %2d", isrc, CANDSRC[n_src].src_strength, CANDSRC[n_src].xx, CANDSRC[n_src].yy, CANDSRC[n_src].ee); logger->logstat = logprint(logger, logger->tmptxt, i5); } } if (logger->trace) traces(func_local, 96000+eeb, logger); } /* *************************************************************************** */ /* *************************************************************************** */ /* * * */ /* * END OF BLOCK PROCESSING 3 BASIC ENERGY BANDS FROM ONE SCIENCE WINDOW * */ /* * (Begins approximately in line 500) * */ /* * * */ /* *************************************************************************** */ /* *************************************************************************** */ /* 333333 */ /* QQQQQQ */ if (n_sources == 1000) { /* special signal for irosloop return */ status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_SPECIAL; goto exittrace; } /* software development test prints (ends approx line 960) */ for (eeb=0; eebee_basic; eeb++) { if (USERBIN[eeb].totcnt <= 1.0) { n_sources = backproj->backmodels; sh_rms[eeb][1] = 0.0; continue; } sprintf(logger->tmptxt, "##57## ngrp[%1d]: best srcnum: %2d, best fitcycles: %2d, best rms: %6.3f", eeb, SCWnow->cand_lst_no[eeb], SCWnow->fitcycles[eeb], SCWnow->fitrms[eeb]); logger->logstat = logprint(logger, logger->tmptxt, i5); sprintf(logger->tmptxt, "##58## Best fit coefficients : "); for (j=0; jcand_lst_no[eeb] + backproj->backmodels; j++) { n_src = SCWnow->cand_lst_start[eeb] + j - backproj->backmodels; if (j < backproj->backmodels) sprintf(logger->tmptxt2, " %7.1f", SCWnow->backgr_str[eeb][j]); else sprintf(logger->tmptxt2, " %7.1f", CANDSRC[n_src].src_strength); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } logger->logstat = logprint(logger, logger->tmptxt, i5); sprintf(logger->tmptxt, "##59## Corresp. eff. areas (cm2): "); for (j=0; jcand_lst_no[eeb] + backproj->backmodels; j++) { n_src = SCWnow->cand_lst_start[eeb] + j - backproj->backmodels; if (j < backproj->backmodels) sprintf(logger->tmptxt2, " %7.1f", SCWnow->backgr_area[eeb]); else sprintf(logger->tmptxt2, " %7.1f", CANDSRC[n_src].src_pixel_area); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } logger->logstat = logprint(logger, logger->tmptxt, i5); sprintf(logger->tmptxt, "##60## Integration time: %8.1lf (s), Absorbtion length: %5.2lf (mm)", sh->accumT, backproj->abs_len[eeb]); logger->logstat = logprint(logger, logger->tmptxt, i5); } startT = (sh->shdgr_aux[23] - (int)(sh->shdgr_aux[23])) * 24.0; starTh = startT; starTm = (startT - starTh) * 60; stopT = (sh->shdgr_aux[24] - (int)(sh->shdgr_aux[24])) * 24.0; stopTh = stopT; stopTm = (stopT - stopTh) * 60; for (i=0; iee_basic; e1++) used_ee[e1][i] = 0; used2[i] = 0; } sprintf(logger->tmptxt, "##61## Number of sources per E-band:"); for (eeb=0; eebee_basic; eeb++) { if (USERBIN[eeb].totcnt <= 1.0) continue; sprintf(logger->tmptxt2, " %2d", SCWnow->cand_lst_no[eeb]); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } logger->logstat = logprint(logger, logger->tmptxt, i5); e1_stop = e2_stop = ic_stop = jc_stop = 0; /* *************************************************************************** */ /* *************************************************************************** */ /* * * */ /* * * */ /* * START OF BLOCK IDENTIFYING COMMON SOURCES BETWEEN BASIC ENERGY BANDS * */ /* * (Ends approximately in line 1270) * */ /* * * */ /* * * */ /* *************************************************************************** */ /* *************************************************************************** */ /* 444444 */ /* QQQQQQ */ /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ kkkk = 0; logger->N_SRC2 = 0; initGOOD(GOODSRC, logger, status); for (e1=0; e1ee_basic; e1++) { if (SCWnow->cand_lst_no[e1] == 0) continue; for (isrc=0; isrccand_lst_no[e1]; isrc++) { n_src1 = SCWnow->cand_lst_start[e1] + isrc; if (CANDSRC[n_src1].src_id > 0) backproj->s_detect[CANDSRC[n_src1].src_id] |= (1<<((2-e1)*4)) * (1+isrc); } } /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* e1-loop isrc-loop */ for (e1=0; e1ee_basic-1; e1++) { e1_stop = 1; if (SCWnow->cand_lst_no[e1] == 0) continue; e1_stop = 9; for (isrc=0; isrccand_lst_no[e1]; isrc++) { ic_stop = 1; if (used_ee[e1][isrc] > 0) continue; ic_stop = 2; n_src1 = SCWnow->cand_lst_start[e1] + isrc; if (SCWnow->backgr_area[e1] > 0.0) { divisor = sqrt((double)(USERBIN[e1].totcnt * CANDSRC[n_src1].src_pixel_area / SCWnow->backgr_area[e1])); if (divisor > 0.0) quality = (double)(CANDSRC[n_src1].src_strength) / divisor; else { quality = 0.0; sprintf(logger->tmptxt, "Normalization problems: ee: %2d, src#: %2d, Pixel area: %f, Total counts: %8.1f", e1, n_src1, CANDSRC[n_src1].src_pixel_area, USERBIN[e1].totcnt); logger->logstat = logprint(logger, logger->tmptxt, i5); RILlogMessage(NULL,Warning_1, "##63## divisor: ee: %2d, src#: %2d, totalcnt: %8.1f, pix_area: %f", e1, n_src1, USERBIN[e1].totcnt, CANDSRC[n_src1].src_pixel_area); } } else { quality = 0.0; sprintf(logger->tmptxt, "Normalization problems: SCWnow->backgr_area: %f", SCWnow->backgr_area[e1]); logger->logstat = logprint(logger, logger->tmptxt, 2); RILlogMessage(NULL,Warning_1,"##62## divisor: %f", SCWnow->backgr_area[e1]); } ic_stop = 9; sumX = CANDSRC[n_src1].xx * CANDSRC[n_src1].src_strength; sumY = CANDSRC[n_src1].yy * CANDSRC[n_src1].src_strength; sum_str = CANDSRC[n_src1].src_strength; sumgood = sum_str; tot_area = CANDSRC[n_src1].src_backgr_area; sumtot = tot_area; if( tot_area == 0.0 ) { sprintf(logger->tmptxt, "Normalization problems: CANDSRC->src_backgr_area: %f", tot_area); logger->logstat = logprint(logger, logger->tmptxt, 2); RILlogMessage( NULL, Warning_1,"##64## Attempt to divide with zero! reset to 1"); tot_area = 1.0; sumtot = 1.0; } sn_best = sumgood / sqrt(sumtot); CANDSRC[n_src1].best_sn = sn_best; GOODSRC[logger->N_SRC2].sn[e1] = sn_best; for (e2=e1+1; e2ee_basic; e2++) { e2_stop = 1; if (SCWnow->cand_lst_no[e2] == 0) continue; e2_stop = 9; /* e1-loop isrc-loop e2-loop jsrc-loop */ for (jsrc=0; jsrccand_lst_no[e2]; jsrc++) { jc_stop = 1; if (used_ee[e2][jsrc] > 0) continue; n_src2 = SCWnow->cand_lst_start[e2] + jsrc; divisor = SCWnow->backgr_area[e2]; if( divisor < 1.e-7 ) { sprintf(logger->tmptxt, "Normalization problems (e2): SCWnow->backgr_area: %f", divisor); logger->logstat = logprint(logger, logger->tmptxt, 2); RILlogMessage(NULL,Warning_1,"##65## background area < 1.e-7; STOP !"); status = -35; goto exittrace; } jc_stop = 2; if ((double)(CANDSRC[n_src2].src_strength) < sqrt((double)(USERBIN[e2].totcnt * CANDSRC[n_src2].src_pixel_area / divisor)) && (CANDSRC[n_src1].preset == 0)) { sprintf(logger->tmptxt, "##971## e2: %1d, jsrc: %1d, src.no: %2d, source strength: %f", e2, jsrc, n_src2, CANDSRC[n_src2].src_strength); logger->logstat = logprint(logger, logger->tmptxt, 2); sprintf(logger->tmptxt, "##1971## e2: %1d, jsrc: %1d, Quality problems: Pixel area: %f, Total count: %8.1f, backgr.area: %f", e2, jsrc, CANDSRC[n_src2].src_pixel_area, USERBIN[e2].totcnt , SCWnow->backgr_area[e2]); logger->logstat = logprint(logger, logger->tmptxt, 2); continue; } jc_stop = 9; xx_dif = CANDSRC[n_src1].xx - CANDSRC[n_src2].xx; yy_dif = CANDSRC[n_src1].yy - CANDSRC[n_src2].yy; /* e1-loop isrc-loop e2-loop jsrc-loop sqrt(dx2+dy2) < 1.5 */ if (sqrt((double)(xx_dif * xx_dif + yy_dif * yy_dif)) < 1.5) { tempgood = sum_str + CANDSRC[n_src2].src_strength; temptot = tot_area + CANDSRC[n_src2].src_backgr_area; if( temptot == 0.0 ) { sprintf(logger->tmptxt, "Normalization problems: total backgr area: %f", temptot); logger->logstat = logprint(logger, logger->tmptxt, 2); RILlogMessage( NULL, Warning_1,"##66## Attempt to divide with zero! reset to 1"); temptot = 1.0; } sn_temp = tempgood / sqrt((double)(temptot)); if( CANDSRC[n_src2].src_backgr_area <= 0.0 ) { sprintf(logger->tmptxt, "Normalization problems: CANDSRC->src_backgr_area: %f", CANDSRC[n_src2].src_backgr_area); logger->logstat = logprint(logger, logger->tmptxt, 2); RILlogMessage( NULL, Warning_1,"##67## Attempt to divide with zero! reset to 1"); CANDSRC[n_src2].src_backgr_area = 1.0; } sn_new = CANDSRC[n_src2].src_strength / sqrt((double)(CANDSRC[n_src2].src_backgr_area)); if ((sn_temp >= sn_best) && (sn_temp >= sn_new )) { sn_best = sn_temp; sum_str = tempgood; tot_area = temptot; } if ((sn_new >= sn_best) && (sn_new >= sn_temp)) { sn_best = sn_new; sum_str = CANDSRC[n_src2].src_strength; tot_area = USERBIN[e2].totcnt; } sumgood += CANDSRC[n_src2].src_strength; sumX += CANDSRC[n_src2].xx * CANDSRC[n_src2].src_strength; sumY += CANDSRC[n_src2].yy * CANDSRC[n_src2].src_strength; if( sumgood == 0.0 ) { sprintf(logger->tmptxt, "Normalization problems: sumgood: %f", sumgood); logger->logstat = logprint(logger, logger->tmptxt, 2); RILlogMessage( NULL, Warning_1,"##68## Attempt to divide with zero! reset to 1"); sumgood = 1.0; } avX0 = sumX / sumgood; avY0 = sumY / sumgood; logger->tmptxt[0] = 0; if (logger->pointdata > 0) { /* e1-loop isrc-loop e2-loop jsrc-loop sqrt(dx2+dy2) < 1.5 pointing data available */ xmm = (avX0 - backproj->FOV_radius) * backproj->pix2mm; ymm = (avY0 - backproj->FOV_radius) * backproj->pix2mm; getRAdec(xmm, ymm, jmx_id->jmx_unit, &s_RA, &s_dec, point, logger, jmx_id); sprintf(logger->tmptxt, "##69##"); sprintf(logger->tmptxt2, " RA/dec: %+7.3f %+7.3f E%1d fit: %7.1lf, E%1d fit: %7.1lf ", s_RA, s_dec, CANDSRC[n_src1].ee, CANDSRC[n_src1].src_strength, CANDSRC[n_src2].ee, CANDSRC[n_src2].src_strength); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } else { sprintf(logger->tmptxt2, "##70## XY: %+7.1f %+7.1f strengths: %7.1lf %7.1lf ", avX0-(float)(backproj->FOV_radius), avY0-(float)(backproj->FOV_radius), CANDSRC[n_src1].src_strength, CANDSRC[n_src2].src_strength); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } if ((starTh + starTm + stopTh + stopTm) == 0) { sprintf(logger->tmptxt2, " "); } else { sprintf(logger->tmptxt2, "time: %2d:%2d to %2d:%2d", starTh, starTm, stopTh, stopTm); } if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); logger->logstat = logprint(logger, logger->tmptxt, 2); CANDSRC[n_src1].best_sn = sn_best; used_ee[e2][jsrc] = 1; used2[isrc] = 1; backproj->com_RA[kkkk] = s_RA; backproj->com_dec[kkkk] = s_dec; GOODSRC[logger->N_SRC2].xx = avX0; GOODSRC[logger->N_SRC2].yy = avY0; GOODSRC[logger->N_SRC2].RA = s_RA; GOODSRC[logger->N_SRC2].dec = s_dec; GOODSRC[logger->N_SRC2].preset |= CANDSRC[n_src1].preset; /* GOODSRC[logger->N_SRC2].src_id = CANDSRC[n_src1].src_id; src_id for verified sources should be identified on the basis of the average coordinates avX0, avY0 */ GOODSRC[logger->N_SRC2].srcnum = CANDSRC[n_src1].srcnum; GOODSRC[logger->N_SRC2].scw_ID = CANDSRC[n_src1].scw_ID; GOODSRC[logger->N_SRC2].sn[e2] = sn_best; GOODSRC[logger->N_SRC2].detects |= (1<<((2-e1)*4)) * (1+isrc); GOODSRC[logger->N_SRC2].detects |= (1<<((2-e2)*4)) * (1+jsrc); GOODSRC[logger->N_SRC2].preset |= (4<N_SRC2].preset |= (4<N_SRC2].preset |= 32; sprintf(logger->tmptxt, "##71## Energy scales: %d %d, kkkk: %2d, scw_ID: %3d, N_SRC: %4d, N_SRC2: %3d, XY0: %6.1f %6.1f, XY1: %6.1f %6.1f ", CANDSRC[n_src1].ee, CANDSRC[n_src2].ee, kkkk, GOODSRC[logger->N_SRC2].scw_ID, logger->N_SRC, logger->N_SRC2, CANDSRC[n_src1].xx, CANDSRC[n_src1].yy, CANDSRC[n_src2].xx, CANDSRC[n_src2].yy); logger->logstat = logprint(logger, logger->tmptxt, i5); jc_stop = 9; /* e1-loop isrc-loop e2-loop jsrc-loop sqrt(dx2+dy2) < 1.5 */ } jc_stop = 4; } e2_stop = 9; } if (used2[isrc] > 0) { used_ee[e1][isrc] = 1; logger->N_SRC2++; initGOOD(GOODSRC, logger, status); if (logger->trace) traces(func_local, 10000+logger->N_SRC2, logger); kkkk++; if (kkkk > SCW_SRCMAX) {kkkk = SCW_SRCMAX; goto sourcefull;} } used2[isrc] = 0; } e1_stop = 9; } /* *************************************************************************** */ /* *************************************************************************** */ /* * * */ /* * * */ /* * END OF BLOCK IDENTIFYING COMMON SOURCES BETWEEN BASIC ENERGY BANDS * */ /* * (Begins approximately in line 920) * */ /* * * */ /* * * */ /* *************************************************************************** */ /* *************************************************************************** */ sourcefull: /* sourcefull */ sprintf(logger->tmptxt, "##961## end of e1 loop: %2d, no of common sources found: %2d, stopcodes: %1d %1d", e1, logger->N_SRC2, e1_stop, e2_stop); logger->logstat = logprint(logger, logger->tmptxt, i5); n_common = kkkk; /* 555555 */ /* QQQQQQ */ /* *************************************************************************** */ /* *************************************************************************** */ /* * * */ /* * * */ /* * START OF BLOCK IDENTIFYING STRONG SOURCES IN SINGLE ENERGY BANDS * */ /* * (Ends approximately in line 1390) * */ /* * * */ /* * * */ /* *************************************************************************** */ /* *************************************************************************** */ for (e1=0; e1ee_basic; e1++) { if (SCWnow->cand_lst_no[e1] > 0) { for (isrc=0; isrccand_lst_no[e1]; isrc++) { if (used_ee[e1][isrc] > 0) continue; n_src1 = SCWnow->cand_lst_start[e1] + isrc; if(USERBIN[e1].totcnt <= 0.0 ) { RILlogMessage( NULL, Warning_1,"##72## Attempt to divide with zero totcnt!to 1"); USERBIN[e1].totcnt = 1.0; } quality = (double)(CANDSRC[n_src1].src_strength) / sqrt((double)(USERBIN[e1].totcnt)); sprintf(logger->tmptxt, "##73## Single band source: E%1d, quality: %5.1lf, limit: %5.1f", e1, quality, logger->qual_limit); if (quality >= logger->qual_limit) sprintf(logger->tmptxt2, " Accepted"); else sprintf(logger->tmptxt2, " NOT accepted"); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); logger->logstat = logprint(logger, logger->tmptxt, 2); if (quality > logger->qual_limit) { sprintf(logger->tmptxt, "##74## Single band strong source: quality: %5.1lf ", quality); if (logger->pointdata > 0) { xmm = (CANDSRC[n_src1].xx - backproj->FOV_radius) * backproj->pix2mm; ymm = (CANDSRC[n_src1].yy - backproj->FOV_radius) * backproj->pix2mm; getRAdec(xmm, ymm, jmx_id->jmx_unit, &s_RA, &s_dec, point, logger, jmx_id); sprintf(logger->tmptxt2, "##75## RA/dec: %+7.3f %+7.3f ee: %1d fit: %7.1lf ", s_RA, s_dec, e1, CANDSRC[n_src1].src_strength); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); backproj->com_RA[kkkk] = s_RA; backproj->com_dec[kkkk] = s_dec; } else { sprintf(logger->tmptxt2, " XY: %+7.1f %+7.1f strengths: %7.1lf ", CANDSRC[n_src1].xx - (float)(backproj->FOV_radius), CANDSRC[n_src1].yy - (float)(backproj->FOV_radius), CANDSRC[n_src1].src_strength); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); backproj->com_RA[kkkk] = 0.0; backproj->com_dec[kkkk] = 0.0; } sprintf(logger->tmptxt2, "CR2"); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); logger->logstat = logprint(logger, logger->tmptxt, 2); sumgood = CANDSRC[n_src1].src_strength; sumtot = CANDSRC[n_src1].src_backgr_area; if( sumtot == 0.0 ) { RILlogMessage( NULL, Warning_1,"##76## Attempt to divide with zero! reset to 1"); sumtot = 1.0; } sn_best = sumgood / sqrt(sumtot); CANDSRC[n_src1].best_sn = sn_best; GOODSRC[logger->N_SRC2].sn[e1] = sn_best; GOODSRC[logger->N_SRC2].xx = CANDSRC[n_src1].xx; GOODSRC[logger->N_SRC2].yy = CANDSRC[n_src1].yy; GOODSRC[logger->N_SRC2].RA = CANDSRC[n_src1].RA; GOODSRC[logger->N_SRC2].dec = CANDSRC[n_src1].dec; GOODSRC[logger->N_SRC2].scw_ID = CANDSRC[n_src1].scw_ID; GOODSRC[logger->N_SRC2].preset |= CANDSRC[n_src1].preset; /* GOODSRC[logger->N_SRC2].src_id = CANDSRC[n_src1].src_id; * src_id for verified sources should be identified on the basis * of the average coordinates avX0, avY0 */ GOODSRC[logger->N_SRC2].detects |= (1<<((2-e1)*4)) * (1+isrc); GOODSRC[logger->N_SRC2].preset |= (4<tmptxt, "##59a# Energy scale: %d scw_ID: %3d, N_SRC: %4d, N_SRC2: %3d, XY0: %6.1f %6.1f ", e1, GOODSRC[logger->N_SRC2].scw_ID, n_src1, logger->N_SRC2, CANDSRC[n_src1].xx, CANDSRC[n_src1].yy); logger->logstat = logprint(logger, logger->tmptxt, 2); kkkk++; if (kkkk > SCW_SRCMAX) {kkkk = SCW_SRCMAX; goto sourcefull2;} logger->N_SRC2++; initGOOD(GOODSRC, logger, status); if (logger->trace) traces(func_local, 20000+logger->N_SRC2, logger); } } } } /* ************************************************************************* */ /* *************************************************************************** */ /* * * */ /* * * */ /* * END OF BLOCK IDENTIFYING STRONG SOURCES IN SINGLE ENERGY BANDS * */ /* * (Begins approximately in line 1280) * */ /* * * */ /* * * */ /* *************************************************************************** */ /* *************************************************************************** */ /* 666666 */ /* QQQQQQ */ sourcefull2: /* sourcefull2 */ n_common2 = kkkk; /* *********************************************************************************** */ /* *********************************************************************************** */ /* * * */ /* * * */ /* * Identify catalog sources among the sources found by ima_iros * */ /* * (for such sources use the coordinates from the catalog for the flux fitting) * */ /* * (ends approx in line 1500) * */ /* * * */ /* *********************************************************************************** */ /* *********************************************************************************** */ sprintf(logger->tmptxt, "Number of catalog sources: %3d, number of found sources: %3d", backproj->preset_src, n_common2); logger->logstat = logprint(logger, logger->tmptxt, 3); if (backproj->preset_src > 0) { for (j=0; jpreset_src; j++) { for (i=0; iN_SRC2; i++) { diff_x = backproj->preset_src_xx[j] - GOODSRC[i].xx; diff_y = backproj->preset_src_yy[j] - GOODSRC[i].yy; diff = diff_x * diff_x + diff_y *diff_y; diff = sqrt(diff); if (diff < 1.5) { GOODSRC[i].catxx = backproj->preset_src_xx[j]; GOODSRC[i].catyy = backproj->preset_src_yy[j]; GOODSRC[i].catRA = backproj->preset_src_RA[j]; GOODSRC[i].catdec = backproj->preset_src_dec[j]; GOODSRC[i].src_id = backproj->preset_src_id[j]; if ((GOODSRC[i].preset & 3) == 3) { GOODSRC[i].diff_x = 0.0; GOODSRC[i].diff_y = 0.0; GOODSRC[i].preset |= 64; } else { GOODSRC[i].diff_x = diff_x; GOODSRC[i].diff_y = diff_y; GOODSRC[i].preset |= 64 + 1024 + backproj->preset_src_flag[j]; backproj->preset_src_flag[j] = 2; /* indicate that this source in the basic set uses catalog coordinates */ } goto next_preset_src; } else { if ((GOODSRC[i].preset & 3) != 3) GOODSRC[i].preset |= 1024; } } next_preset_src: ; /* next_preset_src */ } } if (n_common2 > n_common) { sprintf(logger->tmptxt, "##77## Analysis using %d common and %d strong source(s) between %d energy bands", n_common, n_common2-n_common, backproj->ee_basic); } else { RILlogMessage(NULL,Log_0,"##78## n_common2 = %d", n_common2 ); sprintf(logger->tmptxt, "##79## Analysis using %d common source(s) between %d energy bands", n_common, backproj->ee_basic); } logger->logstat = logprint(logger, logger->tmptxt, 2); if (logger->trace) traces(func_local, 33, logger); ksrc = backproj->backmodels + n_common2; for (n_src=0; n_srcbackmodels+n_src] = GOODSRC[n_src].catxx; yy[backproj->backmodels+n_src] = GOODSRC[n_src].catyy; } else { xx[backproj->backmodels+n_src] = GOODSRC[n_src].xx; yy[backproj->backmodels+n_src] = GOODSRC[n_src].yy; } sprintf(logger->tmptxt, "source %1d: X: %6.2f, Y: %6.2f", n_src, xx[backproj->backmodels+n_src], yy[backproj->backmodels+n_src]); logger->logstat = logprint(logger, logger->tmptxt, i5); } if (n_common2 == 0) { sprintf(logger->tmptxt, "##80## No common sources in the four energy bands"); logger->logstat = logprint(logger, logger->tmptxt, 2); } if( sh->accumT == 0.0 ) { RILlogMessage( NULL, Warning_1, "##81## Attempt to divide with accumT: (%f)! reset to 1", sh->accumT); sh->accumT = 1.0; } /* ***************************************************************************** */ /* ***************************************************************************** */ /* * * */ /* * * */ /* * FITTING LOOP FOR BASIC SOURCE SET OVER SEARCH ENERGY INTERVALS * */ /* * (Ends approximately in line 1650) * */ /* * * */ /* * * */ /* ***************************************************************************** */ /* ***************************************************************************** */ /* 777777 */ /* QQQQQQ */ for (i=0; isrclist[i] = -1; for (i=0; isrclist[i] = i; ShNNN = 0; for (i=0; isoft_gr[i] > 0.0) ShNNN++; for (eeuser=0; eeuseree_basic; eeuser++) { backproj->additional = -1; if (eeuser == 0) logger->new_detmap = 1; else logger->new_detmap = 0; if (logger->trace) traces(func_local, (int)(6200000+eeuser), logger); status = final_fit( eeuser, n_common2, solut_e, jmx_id, logger, backproj, sh, SCWnow, GOODSRC, USERBIN, chatter, status); if (logger->trace) traces(func_local, 180, logger); kMAX = backproj->backmodels + n_common2; if (kMAX > BASIC_SRCMAX) kMAX = BASIC_SRCMAX; for (jsrc=0; jsrctmptxt2, "Src %1d E %1d FITmap * 10**4", jsrc, eeuser); strcpy(f_exttext[1], logger->tmptxt2); ShSUM = 0.0; for(i=0; i<256; i++){ for (j=0; j<256; j++) { ij = i + j*256; if (backproj->soft_gr[ij] <= 0.0) shdg_fits[ij] = NAN; else { shdg_fits[ij] = logger->fit_funcs[jsrc][ij] * solut_e[eeuser][jsrc]; ShSUM += shdg_fits[ij]; } } } if (logger->trace) traces(func_local, 181+jsrc, logger); sprintf(logger->tmptxt, "EE: %2d, fit_function%1d: sum: %7.1f, solut_e: %7.1f, used_pixels: %5d", eeuser, jsrc, ShSUM/solut_e[eeuser][jsrc], solut_e[eeuser][jsrc], ShNNN); logger->logstat = logprint(logger, logger->tmptxt, i5); status = shdg_to_fits(theSWG, eeuser, shdg_fits, jemxNum, elmntName, f_exttext, f_struc1, logger, eeuser, sh, chatter, status ); if (status != ISDC_OK) {status= -70; goto exittrace; } } /* output data shadowgram as FITS */ strcpy(f_exttext[0], "INPUT SHDGRM "); sprintf(logger->tmptxt2, "InputShdg. E %2d", eeuser); strcpy(f_exttext[1], logger->tmptxt2); ShSUM = 0.0; for(i=0; i<256; i++){ for (j=0; j<256; j++) { ij = i + j*256; if (backproj->soft_gr[ij] <= 0.0) shdg_fits[ij] = NAN; else { shdg_fits[ij] = logger->fit_funcs[BASIC_SRCMAX+0][ij]; ShSUM += shdg_fits[ij]; } } } if (logger->trace) traces(func_local, 190, logger); sprintf(logger->tmptxt, "EE: %2d, input shadgrm: sum: %7.1f, used_pixels: %5d", eeuser, ShSUM, ShNNN); logger->logstat = logprint(logger, logger->tmptxt, i5); status = shdg_to_fits(theSWG, eeuser, shdg_fits, jemxNum, elmntName, f_exttext, f_struc1, logger, eeuser, sh, chatter, status ); if (status != ISDC_OK) {status= -71; goto exittrace; } /* output residual shadowgram as FITS */ strcpy(f_exttext[0], "RESIDUAL SHDGRM "); sprintf(logger->tmptxt2, "Residual E %2d", eeuser); strcpy(f_exttext[1], logger->tmptxt2); ShSUM = 0.0; for(i=0; i<256; i++){ for (j=0; j<256; j++) { ij = i + j*256; if (backproj->soft_gr[ij] <= 0.0) shdg_fits[ij] = NAN; else { shdg_fits[ij] = logger->fit_funcs[BASIC_SRCMAX+1][ij]; ShSUM += shdg_fits[ij]; } } } if (logger->trace) traces(func_local, 191, logger); sprintf(logger->tmptxt, "EE: %2d, resid shadgrm: sum: %7.1f, used_pixels: %5d", eeuser, ShSUM, ShNNN); logger->logstat = logprint(logger, logger->tmptxt, i5); status = shdg_to_fits(theSWG, eeuser, shdg_fits, jemxNum, elmntName, f_exttext, f_struc1, logger, eeuser, sh, chatter, status ); if (status != ISDC_OK) {status= -72; goto exittrace; } /* output efficiency shadowgram as FITS */ strcpy(f_exttext[0], "EFFICIENCY SHDGRM "); sprintf(logger->tmptxt2, "Efficiency E %2d", eeuser); strcpy(f_exttext[1], logger->tmptxt2); ShSUM = 0.0; for(i=0; i<256; i++){ for (j=0; j<256; j++) { ij = i + j*256; if (backproj->soft_gr[ij] <= 0.0) shdg_fits[ij] = NAN; else { shdg_fits[ij] = logger->fit_funcs[BASIC_SRCMAX+2][ij]; ShSUM += shdg_fits[ij]; } } } if (logger->trace) traces(func_local, 192, logger); /* sprintf(logger->tmptxt, "EE: %2d, effic shadgrm: sum: %7.1f, used_pixels: %5d", eeuser, ShSUM, ShNNN); logger->logstat = logprint(logger, logger->tmptxt, i5); */ status = shdg_to_fits(theSWG, eeuser, shdg_fits, jemxNum, elmntName, f_exttext, f_struc1, logger, eeuser, sh, chatter, status ); if (status != ISDC_OK) {status= -72; goto exittrace; } for (jsrc=0; jsrcbackmodels+n_common2; jsrc++) { sprintf(logger->tmptxt, "##3217a## E: %2d, solut_e: %lf ", eeuser, solut_e[eeuser][jsrc]); logger->logstat = logprint(logger, logger->tmptxt, i5); } sh_rms[eeuser][3] = rmscalc(sh->resid, USERBIN[eeuser].soft_gr, logger); if (logger->shdg_out_ctrl == 1) { /* output residual shadowgram as FITS */ strcpy(f_exttext[0], "RESIDUAL_SHDGR"); strcpy(f_exttext[1], "Residual shadowgram"); status = shdg_to_fits(theSWG, eeuser, sh->resid, jemxNum, elmntName, f_exttext, f_struc1, logger, eeb, sh, chatter, status ); if (status != ISDC_OK) goto exittrace; } /* ************************************************************** */ /* */ /* Use final residual shadowgram to form sky image */ /* */ /* ************************************************************** */ /* QQQQQQ */ /* 757575 */ status = final_sky( eeuser, n_common2, peakval, theSWG, jmx_id, logger, backproj, sh, bp, SCWnow, GOODSRC, USERBIN, chatter, status ); status = fluxerror( eeuser, n_common2, peakval, logger, backproj, sh, GOODSRC, status ); /* ************************************************************** */ /* */ /* Special section for pif_map output (only basic source set) */ /* */ /* ************************************************************** */ kMAX = ksrc; if (kMAX > BASIC_SRCMAX) kMAX = BASIC_SRCMAX; /* * for (jsrc=backproj->backmodels; jsrcshdg_out_ctrl == 2) { * * strcpy(f_exttext[0], "SOURCE_PIF_MAP"); * sprintf(logger->tmptxt2, "Src %1d E %1d PIFmap", jsrc, eeuser); * strcpy(f_exttext[1], logger->tmptxt2); * * for(i=0; i<256; i++){ * for (j=0; j<256; j++) { * ij = i + j*256; * if (USERBIN[eeuser].pif_maps[jsrc][ij] < 0.0) shdg_fits[ij] = NAN; * else shdg_fits[ij] = USERBIN[eeuser].pif_maps[jsrc][ij]; * } * } * * status = shdg_to_fits(theSWG, eeuser, shdg_fits, jemxNum, elmntName, f_exttext, * f_struc1, logger, eeb, sh, chatter, status ); * * strcpy(f_exttext[0], "SOURCE_PIFEFF_MAP"); * * for(i=0; i<256; i++){ * for (j=0; j<256; j++) { * ij = i + j*256; * if (USERBIN[eeuser].pifeff_maps[jsrc][ij] < 0.0) shdg_fits[ij] = NAN; * else shdg_fits[ij] = USERBIN[eeuser].pifeff_maps[jsrc][ij]; * } * } * * status = shdg_to_fits(theSWG, eeuser, shdg_fits, jemxNum, elmntName, f_exttext, * f_struc1, logger, eeb, sh, chatter, status ); * if (status != ISDC_OK) goto exittrace; * } * } */ } /* *************************************************************************** */ /* *************************************************************************** */ /* * * */ /* * * */ /* * END OF BLOCK PROCESSING BASIC SOURCE SET FOR SEARCH ENERGY BANDS * */ /* * (begins approximately in line 1550) * */ /* * * */ /* * * */ /* *************************************************************************** */ /* *************************************************************************** */ /* 888888 */ /* QQQQQQ */ /* *************************************************************************** */ /* *************************************************************************** */ /* * * */ /* * * */ /* * FITTING LOOP OVER USER ENERGY INTERVALS * */ /* * first perform source fits over basic source set * */ /* * next perform new fit including one extra preset source in addition * */ /* * to the basic set for every step of the loop * */ /* * (ends approximately in line 1700) * */ /* * * */ /* * * */ /* *************************************************************************** */ /* *************************************************************************** */ /* LOOP OVER ENERGIES */ for (eeuser=backproj->ee_basic; eeusernumShds; eeuser++) { status = j_fitprep(eeuser, theSWG, jmx_id, logger, backproj, sh, bp, SCWnow, USERBIN, chatter, status); if (logger->trace) traces(func_local, 45, logger); if (logger->trace) traces(func_local, 45000+eeuser, logger); if (logger->trace) traces(func_local, 45200+sh->numShds, logger); backproj->additional = -1; status = final_fit( eeuser, n_common2, solut_e, jmx_id, logger, backproj, sh, SCWnow, GOODSRC, USERBIN, chatter, status); for (jsrc=0; jsrcbackmodels+n_common2; jsrc++) { if (logger->trace) traces(func_local, 95000+n_common2*100+jsrc, logger); sprintf(logger->tmptxt, "##3217b## E: %2d, solut_e: %f\n", eeuser, solut_e[eeuser][jsrc]); logger->logstat = logprint(logger, logger->tmptxt, i5); } /* ************************************************************** */ /* */ /* LOOP OVER ADDITIONAL SOURCES */ /* */ /* ************************************************************** */ if (backproj->preset_src > 0) { for (psrc=0; psrcpreset_src; psrc++) { if (backproj->preset_src_flag[psrc] != 1) continue; /* this source should not be testet in this loop */ if (backproj->preset_src_N_SRC2[psrc] < 0) { addnew = 1; logger->new_detmap = 1; backproj->preset_src_N_SRC2[psrc] = logger->N_SRC2; sprintf(logger->tmptxt, "##4545## n_common2: %1d, psrc: %2d, X/Y: %7.2f %7.2f, backproN_SRC2: %2d, loggerN_SRC2: %2d", n_common2, psrc, backproj->preset_src_xx[psrc], backproj->preset_src_yy[psrc], backproj->preset_src_N_SRC2[psrc], logger->N_SRC2); logger->logstat = logprint(logger, logger->tmptxt, i5); GOODSRC[backproj->preset_src_N_SRC2[psrc]].xx = backproj->preset_src_xx[psrc]; GOODSRC[backproj->preset_src_N_SRC2[psrc]].yy = backproj->preset_src_yy[psrc]; GOODSRC[backproj->preset_src_N_SRC2[psrc]].RA = backproj->preset_src_RA[psrc]; GOODSRC[backproj->preset_src_N_SRC2[psrc]].dec = backproj->preset_src_dec[psrc]; GOODSRC[backproj->preset_src_N_SRC2[psrc]].catxx = backproj->preset_src_xx[psrc]; GOODSRC[backproj->preset_src_N_SRC2[psrc]].catyy = backproj->preset_src_yy[psrc]; GOODSRC[backproj->preset_src_N_SRC2[psrc]].catRA = backproj->preset_src_RA[psrc]; GOODSRC[backproj->preset_src_N_SRC2[psrc]].catdec = backproj->preset_src_dec[psrc]; GOODSRC[backproj->preset_src_N_SRC2[psrc]].src_id = backproj->preset_src_id[psrc]; GOODSRC[backproj->preset_src_N_SRC2[psrc]].preset |= 1; } else { addnew = 0; logger->new_detmap = 0; } backproj->srclist[n_common2] = backproj->preset_src_N_SRC2[psrc]; backproj->additional = backproj->preset_src_N_SRC2[psrc]; if (logger->trace) traces(func_local, 46, logger); if (logger->trace) traces(func_local, 46000+backproj->additional, logger); if (logger->trace) traces(func_local, 460000+status, logger); if (logger->trace) traces(func_local, 470000+eeuser, logger); status = final_fit( eeuser, n_common2, solut_e, jmx_id, logger, backproj, sh, SCWnow, GOODSRC, USERBIN, chatter, status); if (logger->trace) traces(func_local, 470000+status, logger); if (logger->trace) { for (xsrc=0; xsrcaccumT * GOODSRC[backproj->preset_src_N_SRC2[psrc]].src_pixel_area[eeuser]; GOODSRC[backproj->preset_src_N_SRC2[psrc]].flux[eeuser] = solut_e[eeuser][backproj->backmodels+logger->N_SRC2] * 100.0 / exposure; */ if (addnew) { logger->N_SRC2++; initGOOD(GOODSRC, logger, status); addnew = 0; } for (jsrc=0; jsrcbackmodels+logger->N_SRC2; jsrc++) { sprintf(logger->tmptxt, "##3217b## E: %2d, solut_e: %f\n", eeuser, solut_e[eeuser][jsrc]); logger->logstat = logprint(logger, logger->tmptxt, i5); } } /* end of loop over preset sources */ /* *************************************************************************** */ /* *************************************************************************** */ /* * * */ /* * * */ /* * End of source fits including one extra preset source * */ /* * in addition to the basic set for every step of the loop * */ /* * (begins approximately in line 1650) * */ /* * * */ /* * * */ /* *************************************************************************** */ /* *************************************************************************** */ } /* end of 'preset_src' if-statement */ /* ************************************************************** */ /* */ /* Backproject final residual shadowgram to form sky image */ /* */ /* ************************************************************** */ backproj->additional = -1; status = final_sky( eeuser, logger->N_SRC2, peakval, theSWG, jmx_id, logger, backproj, sh, bp, SCWnow, GOODSRC, USERBIN, chatter, status ); status = fluxerror( eeuser, logger->N_SRC2, peakval, logger, backproj, sh, GOODSRC, status ); } /* end of ee loop */ /* QQQQQQ */ /* 999999 */ /* *************************************************************************** */ /* *************************************************************************** */ /* * * */ /* * * */ /* * Start of light curve section. Perform source fits for every time bin * */ /* * Ends approximately in line 1850) * */ /* * * */ /* * * */ /* *************************************************************************** */ /* *************************************************************************** */ if (logger->trace) traces(func_local, 50, logger); /* goto notimesteps; */ /* *************************************************************************** */ /* TESTING j_iir_fill_adhoc_shd */ /* *************************************************************************** */ goto notimesteps; /* !!!!!!!!!!!!!!! */ /* 0.5*(auxdata.GTI_IJDstart[0]+auxdata.GTI_IJDstop[0])-25.*J_IIR_IJDSECOND, */ /* 0.5*(auxdata.GTI_IJDstart[0]+auxdata.GTI_IJDstop[0])+25.*J_IIR_IJDSECOND, */ /* status = j_iir_fill_adhoc_shd( auxdata.GTI_IJDstart[0], auxdata.GTI_IJDstop[0], 46, 82, bufevents, SCWnow->numEvents, auxdata, shd_adhoc, logger, chatter, status); status = j_iir_fill_adhoc_shd( auxdata.GTI_IJDstart[0], auxdata.GTI_IJDstop[0], 83, 128, bufevents, SCWnow->numEvents, auxdata, shd_adhoc, logger, chatter, status); status = j_iir_fill_adhoc_shd( auxdata.GTI_IJDstart[0], auxdata.GTI_IJDstop[0], 129, 159, bufevents, SCWnow->numEvents, auxdata, shd_adhoc, logger, chatter, status); status = j_iir_fill_adhoc_shd( auxdata.GTI_IJDstart[0], auxdata.GTI_IJDstop[0], 160, 223, bufevents, SCWnow->numEvents, auxdata, shd_adhoc, logger, chatter, status); */ if(SCWnow->numEvents == 0) goto notimesteps; sprintf(logger->tmptxt, "Event times: %f %f %f %f", bufevents[0].ijd, bufevents[1].ijd, bufevents[SCWnow->numEvents-2].ijd, bufevents[SCWnow->numEvents-1].ijd); logger->logstat = logprint(logger, logger->tmptxt, i5); SCWnow->NumTimeBins = 8; timestep = (bufevents[SCWnow->numEvents-1].ijd - bufevents[0].ijd) / SCWnow->NumTimeBins; sprintf(logger->tmptxt, "subshadowgram time intervals:"); logger->logstat = logprint(logger, logger->tmptxt, i5); for (ntime=0; ntimeNumTimeBins; ntime++) { status = initTslice(Tslices[ntime], logger, status); Tslices[ntime].Tstart = bufevents[0].ijd + ntime * timestep; Tslices[ntime].Tstop = Tslices[ntime].Tstart + timestep; sprintf(logger->tmptxt, " %3d Start: %12.6f, Stop: %12.6f, duration: %6.1f s", ntime, Tslices[ntime].Tstart, Tslices[ntime].Tstop, (Tslices[ntime].Tstop - Tslices[ntime].Tstart) * 86400.0); logger->logstat = logprint(logger, logger->tmptxt, i5); /* --- next line is part of unfinished development 2010-03-02/NJW */ /* status = TsliceAnalysis(bufevents, SCWnow, Tslices, logger, status); */ } if (logger->trace) traces(func_local, 60, logger); notimesteps: ; /* ******************************************************************* */ /* Final summary printout */ /* ******************************************************************* */ /* QQQQQQ */ sprintf(calibname, "c%1d_%04d%04d%04d.bin", jmx_id->jmx_unit+1, backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv); sprintf(logger->tmptxt, "Call summary_p in mixwork "); logger->logstat = logprint(logger, logger->tmptxt, 0); /* QQQQQQ */ for (jsrc=0; jsrcdevelop & 1) == 1) { calibout(jsrc, n_common2, backproj->ee_basic, vigncorr, GOODSRC[jsrc].diff_x, GOODSRC[jsrc].diff_y, solut_e[0][jsrc], solut_e[1][jsrc], solut_e[2][jsrc], backproj->resid_data_peak[0][jsrc], backproj->resid_data_peak[1][jsrc], backproj->resid_data_peak[2][jsrc], calibname, theSWG, point, jmx_id, logger, backproj, SCWnow, sh, GOODSRC, chatter, status); } } n_additional = 0; summary_p(n_common2, n_additional, solut_e, jmx_id, backproj, sh, SCWnow, GOODSRC, logger, chatter, status ); status = ISDC_OK; slut: ; if (logger->trace) traces(func_local, 100000+logger->N_SRC2, logger); 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 */ /* Argument changed from ISDC_OK to 'status' with version 3.0.1 */ return( status ); exittrace: /* exittrace */ if (logger->trace) traces(func_local, 1000-status, logger); goto slut; } /***************************************************************** * Name of source file: final_fit.c * Version of source file: 4.0.6 * Parent component: None * Programmer: Niels Lund * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325716 FAX: +45 35362475 * nl@dnsc.dk * Purpose: perform final flux fitting for given source set and energy * Origin date: 20091211 * Update history: 1.0.0 20091211 First version * 4.0.2 120321 SPR ?: Bug reported by JC, LP fixed * 4.0.4 120430 SPR ?: Still better flux error estimation * 4.0.5 120607 SPR ?: Still better flux error estimation * 4.0.6 120628 SPR ?: Reduced memory allocation demands * Type of element: Function * Part of package: j_ima_iros * Name: final_fit * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ /* QQQQQQ */ int final_fit( int eeuser, int n_common2, double solut_e[EE256][SCW_SRCMAX], struct instr_data *jmx_id, struct log_con *logger, struct backpro *backproj, struct shadowgrams *sh, struct scwlist *SCWnow, goodsrc *GOODSRC, userbin *USERBIN, int chatter, int status) { int ee3, i5 = 0, logi5; int i, j, k, chk_no, q; int isrc, jsrc, n_src, jb, pd; int ksrc, o_src_user, o_src_good; int baseErr; static float xx[SCW_SRCMAX], yy[SCW_SRCMAX]; static float shadow[detdim]; float pifmax; float e_minim, e_maxim, shsum; float funval, transmis, Emin, Emax; float xmm, ymm; float Apix, Anoise = 0.5, rawcount; /* NL 20120601 Ad-hoc parameter required to establish sensible flux error estimates for the Crab */ float fluxerr_norm[2] = {8000.0, 9000.0}; static double solut[SCW_SRCMAX]; static double orig_solut[4][4], orig_rms[4]; double finalvar[EE256], sh_rms[EE256+1][4]; double xrms, yrms, sum; double exposure = 0.0; 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], "final_fit"); 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 */ i5 = logger->i5; /* NL 20120122 */ if (logger->trace) traces(func_local, 0, logger); if (logger->trace) traces(func_local, 7000+eeuser, logger); if (logger->trace) traces(func_local, 8000+n_common2, logger); for (i=0; ibackmodels+n_src] = GOODSRC[n_src].catxx; yy[backproj->backmodels+n_src] = GOODSRC[n_src].catyy; } else { xx[backproj->backmodels+n_src] = GOODSRC[n_src].xx; yy[backproj->backmodels+n_src] = GOODSRC[n_src].yy; } sprintf(logger->tmptxt, "##7657## source %1d: X: %6.2f, Y: %6.2f", n_src, xx[backproj->backmodels+n_src], yy[backproj->backmodels+n_src]); logger->logstat = logprint(logger, logger->tmptxt, i5); } ksrc = backproj->backmodels + n_common2; if (logger->trace) traces(func_local, 90000+backproj->additional, logger); if (backproj->additional >= 0) { ksrc++; xx[backproj->backmodels+n_common2] = GOODSRC[backproj->additional].catxx; yy[backproj->backmodels+n_common2] = GOODSRC[backproj->additional].catyy; sprintf(logger->tmptxt, "##7657## source %1d: X: %6.2f, Y: %6.2f", n_common2, xx[backproj->backmodels+n_common2], yy[backproj->backmodels+n_common2]); logger->logstat = logprint(logger, logger->tmptxt, i5); if (logger->trace) traces(func_local, 20, logger); } if (logger->trace) traces(func_local, 10, logger); if (logger->trace) traces(func_local, 9000+ksrc, logger); ee3 = eeuser; if (ee3 > backproj->ee_basic ) ee3 = backproj->ee_basic; /* ***************************************************************************** */ /* * * */ /* * PREPARE FITTING LOOP FOR INPUT SOURCE SET * */ /* * * */ /* ***************************************************************************** */ for (i=0; iskydim; i++) { backproj->illumx[i] = USERBIN[eeuser].illumnew[i]; backproj->access[i] = 0; if (backproj->illumx[i] >= (int)(backproj->signiflim)) backproj->access[i] = 1; } shsum = sum = 0.0; for (i=0; ishadw[i] = USERBIN[eeuser].f_shadgram[i]; backproj->effic[i] = USERBIN[eeuser].effic_shdg[i]; if (backproj->effic[i] > 0.0) { backproj->soft_gr[i] = backproj->empty[ee3][i] = USERBIN[eeuser].soft_gr[i]; sum += backproj->soft_gr[i]; } else backproj->soft_gr[i] = backproj->empty[ee3][i] = -1.0; } for (i=0; iempty_norm[i] = backproj->empty[ee3][i] / sum; for (i=0; iskydim; i++) { backproj->fitsimage[ee3][0][i] = USERBIN[eeuser].variance[i]; backproj->fitsimage[ee3][2][i] = USERBIN[eeuser].fst_imag[i]; if (backproj->fitsimage[ee3][0][i] > 1.0) backproj->fitsimage[ee3][5][i] = 1.0 / sqrt((double)(backproj->fitsimage[ee3][0][i])); else backproj->fitsimage[ee3][5][i] = 1.0; } backproj->act_pix[eeuser] = USERBIN[eeuser].act_pix; xrms = USERBIN[eeuser].x_rms; yrms = USERBIN[eeuser].y_rms; jmx_id->absolen = USERBIN[eeuser].abs_len; jmx_id->scatt_len = sh_xy(xrms, yrms, logger, jmx_id); /* calculate read-out scatter around X-ray absorbtion point at this energy */ sprintf(logger->tmptxt, "eeuser: %1d, ee3: %1d, x/y_rms: %f %f, shadow_sum: %f, absolen: %f, scatt_len: %d\n", eeuser, ee3, xrms, yrms, shsum, jmx_id->absolen, (int)(jmx_id->scatt_len)); logger->logstat = logprint(logger, logger->tmptxt, i5); sh->totcnt[eeuser] = shsum; /* This statement renormalizes totcnt so the values printed for the different fit components are consistent */ status = ISDC_OK; status = FUN(-1, 1, ee3, xx, yy, jmx_id->jmx_unit, 0, &funval, jmx_id, logger, backproj, chatter, status); /* reset fitting functions */ if( status != ISDC_OK ) { sprintf(logger->tmptxt, "xReturn from FUN(-1, ..), status: %d", status); logger->logstat = logprint(logger, logger->tmptxt, i5); logger->logstat = logprint(logger, logger->error_text, 7); status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_FUNERR; goto exittrace; } chk_no = 1; logger -> fun_last = 1; sprintf(logger->tmptxt, "Calling 'shadowfit' from 'final_fit', ksrc: %2d", ksrc); logger->logstat = logprint(logger, logger->tmptxt, i5); if (logger->trace) traces(func_local, 19000+eeuser, logger); if (logger->trace) traces(func_local, 29000+ee3, logger); if (logger->trace) traces(func_local, 10020+backproj->additional, logger); status = shadowfit(shadow, jmx_id->jmx_unit, ee3, ksrc, xx, yy, solut, chk_no, &finalvar[eeuser], jmx_id, logger, backproj, sh, chatter, status); logger -> fun_last = 0; if (logger->trace) traces(func_local, 10030+backproj->additional, logger); if (status != ISDC_OK) { if (logger->trace) traces(func_local, 77000+status, logger); sprintf(logger->tmptxt, "xReturn from shadowfit, status: %d", status); logger->logstat = logprint(logger, logger->tmptxt, i5); RILlogMessage( NULL, Log_3, "##83## Exit shadowfit with status = %d", status); /* * When shadowfit returns one of 8 status-values the source * is dismissed */ baseErr = J_ERROR_CODE_START + J_IMA_IROS_ERR; if ( status == baseErr+J_IIR_FUNERR1 || status == baseErr+J_IIR_FUNERR2 || status == baseErr+J_IIR_FUNERR3 || status == baseErr+J_IIR_FUNERR4 || status == baseErr+J_IIR_FUNERR5 || status == baseErr+J_IIR_FUNERR6 || status == baseErr+J_IIR_FUNERR7 || status == baseErr+J_IIR_FUNERR8 || status == baseErr+J_IIR_SNGLMTX ) { status = ISDC_OK; } if (backproj->additional < 0) n_common2 = 0; else { status = -47; } if (logger->trace) traces(func_local, 79000-status, logger); goto exittrace; /* NL 20120214. goto statement moved here from just after large 'if' */ } sprintf(logger->tmptxt, "xReturn from 'shadowfit' in 'final_fit', status: %d, additional: %3d, ee3: %2d, eeuser: %3d", status, backproj->additional, ee3, eeuser); if (logger->trace) traces(func_local, 76001-status, logger); for (q=0; qtmptxt2, " %8.1f", solut[q]); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } logger->logstat = logprint(logger, logger->tmptxt, i5); if (logger->trace) traces(func_local, 76002-status, logger); for (i=0; iresid[i]; if ((n_common2 == 0) && (backproj->additional < 0)) { solut_e[eeuser][0] = backproj->solut0_0[ee3]; solut_e[eeuser][1] = backproj->solut0_1[ee3]; status = ISDC_OK; goto exittrace; } /* New section to save fitting functions for each source and each energy range */ if (logger->trace) traces(func_local, 10040+backproj->additional, logger); for (jsrc=0; jsrctrace) traces(func_local, 2000+jsrc, logger); o_src_user = jsrc; o_src_good = jsrc - backproj->backmodels; if (logger->trace) traces(func_local, 2100+o_src_user, logger); if (logger->trace) traces(func_local, 2200+n_common2, logger); if ((backproj->additional >= 0) && (jsrc == (backproj->backmodels+n_common2))) { o_src_good = backproj->additional; o_src_user = backproj->additional + backproj->backmodels; } if (logger->trace) traces(func_local, 2400+backproj->additional, logger); if (logger->trace) traces(func_local, 2400+o_src_good, logger); if (logger->trace) traces(func_local, 2500+o_src_user, logger); o_src_user = o_src_good + backproj->backmodels; if (logger->trace) traces(func_local, 2000+o_src_user, logger); pifmax = 0.0; for (i=0; ipif_maps[jsrc][i]; USERBIN[eeuser].pifeff_maps[o_src_user][i] = backproj->pifeff_maps[jsrc][i]; } if (jsrc < 2) continue; /* skip background components */ if (backproj->pif_maps[jsrc][i] > pifmax) pifmax = backproj->pif_maps[jsrc][i]; } USERBIN[eeuser].pifnorm[o_src_user] = pifmax; } /* End of new section to save fitting functions for each source and each energy range */ if (logger->trace) traces(func_local, 10040+backproj->additional, logger); if (backproj->additional < 0) { SCWnow->resid_variance[ee3 ] = finalvar[eeuser]; SCWnow->take_away_resid_var[ee3 ][0] = backproj->errsolut[0]; SCWnow->take_away_resid_var[ee3 ][1] = backproj->errsolut[1]; } SCWnow->backgr_area[ee3 ] = 0.01 * backproj->act_pix[eeuser]; if (ee3 < 3) { orig_solut[ee3][0] = solut[0]; orig_solut[ee3][1] = solut[1]; if (ksrc > 2) orig_solut[ee3][2] = solut[2]; else orig_solut[ee3][2] = 1.0; orig_rms[ee3] = finalvar[eeuser]; } if (logger->trace) traces(func_local, 10050+backproj->additional, logger); /* NL 20120601 Save fitted flux and flux error for two background components */ GOODSRC[SCW_SRCMAX-2].src_strength[eeuser] = solut[0]; GOODSRC[SCW_SRCMAX-2].errsolut[eeuser] = backproj->errsolut[0]; GOODSRC[SCW_SRCMAX-1].src_strength[eeuser] = solut[1]; GOODSRC[SCW_SRCMAX-1].errsolut[eeuser] = backproj->errsolut[1]; for (jsrc=backproj->backmodels; jsrcadditional >= 0) && (jsrc == (backproj->backmodels+n_common2))) o_src_user = backproj->additional + backproj->backmodels; o_src_good = o_src_user - backproj->backmodels; GOODSRC[o_src_good].src_strength[eeuser] = solut[jsrc]; GOODSRC[o_src_good].take_away_resid_var[eeuser] = backproj->errsolut[jsrc]; if (backproj->additional < 0) { /* NL 20120601 Ad-hoc parameter required to establish sensible flux error estimates for the Crab */ GOODSRC[o_src_good].errsolut[eeuser] = backproj->errsolut[jsrc] * sh->totcnt[eeuser] / fluxerr_norm[jmx_id->jmx_unit]; } if ((backproj->additional >= 0) && (jsrc == (backproj->backmodels+n_common2))) { GOODSRC[o_src_good].errsolut[eeuser] = backproj->errsolut[jsrc] * sh->totcnt[eeuser] / fluxerr_norm[jmx_id->jmx_unit]; } if (backproj->norm_d[jsrc][ee3] > 0.0) { Emin = sh->eval[eeuser][0]; Emax = sh->eval[eeuser][1]; xmm = (xx[jsrc] - backproj->FOV_radius) * backproj->pix2mm; ymm = (yy[jsrc] - backproj->FOV_radius) * backproj->pix2mm; transmis = 1.0; if ((logger->develop & 4096) == 0) { status = off_axis_transmission( xmm, ymm, Emin, Emax, &transmis, jmx_id, logger); if (status < 0) { sprintf(logger->tmptxt, "AAA status: %3d on return from off_axis transmission\n", status); logger->logstat = logprint(logger, logger->tmptxt, i5); transmis = 1.0; } } GOODSRC[o_src_good].src_pixel_area[eeuser] = 0.01 * transmis * backproj->src_effic[jsrc] / backproj->norm_d[jsrc][ee3]; GOODSRC[o_src_good].transmis[eeuser] = transmis; exposure = sh->accumT * GOODSRC[o_src_good].src_pixel_area[eeuser]; GOODSRC[o_src_good].errsolut[eeuser] *= 100.0 / exposure; sprintf(logger->tmptxt, "fnl_fit:Bee: %2d, jsrc: %2d, o_src_good: %2d, src_pixel_area: %5.2f, src_str: %6.1f, effic/norm_d/transm: %5.3f %8.6f %5.3f", eeuser, jsrc, o_src_good, GOODSRC[o_src_good].src_pixel_area[eeuser], GOODSRC[o_src_good].src_strength[eeuser], backproj->src_effic[jsrc], backproj->norm_d[jsrc][ee3], transmis); logger->logstat = logprint(logger, logger->tmptxt, i5); GOODSRC[o_src_good].src_effic[eeuser] = backproj->src_effic[jsrc]; } else { GOODSRC[o_src_good].src_pixel_area[eeuser] = 0.0; } if (backproj->norm_db[jsrc][ee3] > 0.0) { GOODSRC[o_src_good].src_backgr_area[eeuser] = 0.01 / backproj->norm_db[jsrc][ee3]; } else { GOODSRC[o_src_good].src_backgr_area[eeuser] = 0.0; } } for (jsrc=0; jsrctmptxt, "##3217## E: %2d, jsrc: %2d, solut_e: %f\n", eeuser, jsrc, solut_e[eeuser][jsrc]); logger->logstat = logprint(logger, logger->tmptxt, i5); } /* ++++++++++++++++++++++++++++++++++++++++++++++++ */ sprintf(logger->tmptxt, "##105## E%02d residual variance: %6.3lf, mean: %4.2lf take-away variances: ", ee3, SCWnow->resid_variance[ee3 ], SCWnow->mean_pix[ee3 ]); for (jsrc =0; jsrc backmodels+n_common2; jsrc ++) { if (jsrc < backproj->backmodels) { sprintf(logger->tmptxt2, " %6.3f", SCWnow->take_away_resid_var[ee3 ][jsrc ]); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } else { n_src = jsrc - backproj->backmodels; sprintf(logger->tmptxt2, " %6.3f", GOODSRC[n_src].take_away_resid_var[eeuser]); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } } if (n_common2 > 0) logger->logstat = logprint(logger, logger->tmptxt, i5); if ((SCWnow->backgr_area[ee3 ] > 0.0) && (sh->totcnt[eeuser] > 0.0)) { sprintf(logger->tmptxt, "##8835## eeuser: %2d, ee3: %d, totcnt: %8.1f backgr.area: %10.4e, finalvar: %e\n", eeuser, ee3, sh->totcnt[eeuser], SCWnow->backgr_area[ee3], finalvar[eeuser]); logger->logstat = logprint(logger, logger->tmptxt, i5); finalvar[eeuser] *= SCWnow->backgr_area[ee3] * 100.0 / sh->totcnt[eeuser]; /* form reduced variance */ } jb = backproj->backmodels; for (jsrc=jb; jsrcadditional >= 0) && (jsrc == (backproj->backmodels+n_common2))) o_src_user = backproj->additional + backproj->backmodels; o_src_good = o_src_user - backproj->backmodels; exposure = sh->accumT * GOODSRC[o_src_good].src_pixel_area[eeuser]; sprintf(logger->tmptxt, "flux calculation: o_src_good: %3d, ksrc: %2d, eeuser: %2d, solut_e: %f, accumT: %7.1f, exposure: %7.1f", o_src_good, ksrc, eeuser, solut_e[eeuser][jsrc], sh->accumT, exposure); logger->logstat = logprint(logger, logger->tmptxt, i5); pd = 0; if (exposure > 0.0) { if (backproj->additional < 0) { GOODSRC[o_src_good].flux[eeuser] = (float)(solut_e[eeuser][jsrc] * 100.0 / exposure ); sprintf(logger->tmptxt, "flux calculationA: jsrc: %2d, o_src_good: %3d, eeuser: %2d, flux: %f", jsrc, o_src_good, eeuser, GOODSRC[o_src_good].flux[eeuser]); logger->logstat = logprint(logger, logger->tmptxt, i5); } if ((backproj->additional >= 0) && (jsrc == (jb + n_common2))) { GOODSRC[o_src_good].flux[eeuser] = (float)(solut_e[eeuser][jsrc] * 100.0 / exposure ); sprintf(logger->tmptxt, "fluxCalcB: o_src_good (hex): %3x, ee%1d, cnts: %5.0f, flux: %7.4f, solut_e: %7.2f", o_src_good, eeuser, USERBIN[eeuser].totcnt, GOODSRC[o_src_good].flux[eeuser], solut_e[eeuser][jsrc]); logger->logstat = logprint(logger, logger->tmptxt, i5); } } else { status = -10; goto exittrace; } } /* 757575 */ slut: if (logger->trace) traces(func_local, 99, logger); sprintf(logger->tmptxt, "normal return from 'final_fit', status: %d, additional: %3d, ee3: %2d %2d", status, backproj->additional, ee3, eeuser); logger->logstat = logprint(logger, logger->tmptxt, i5); /* 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 ); exittrace: ; /* exittrace */ if (logger->trace) traces(func_local, 1000-status, logger); sprintf(logger->tmptxt, "exittrace return from 'final_fit', status: %d, additional: %3d, ee: %2d %2d:", status, backproj->additional, ee3, eeuser); logger->logstat = logprint(logger, logger->tmptxt, i5); goto slut; } /***************************************************************** * Name of source file: final_sky.c * Version of source file: 4.0.8 * Parent component: None * Programmer: Niels Lund * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325716 FAX: +45 35362475 * nl@dnsc.dk * Purpose: generate final sky_image for output, calculate ima flux errors * Origin date: 20091212 * Update history: 1.0.0 20091212 First version * 4.0.2 120321 SPR ?: Bug reported by JC, LP fixed * 4.0.3 120423 SPR ?: Better flux error, 100 flag sources allowed * 4.0.3 120423 SPR ?: Better flux error, 100 flag sources allowed * 4.0.8 120813 SPR ?: Fixes bug in significance image * Type of element: Function * Part of package: j_ima_iros * Name: final_sky * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ /* QQQQQQ */ int final_sky( int eeuser, int n_common2, float peakval[2*EE256][SCW_SRCMAX], dal_element *theSWG, /* pointer to the SWG */ struct instr_data *jmx_id, struct log_con *logger, struct backpro *backproj, struct shadowgrams *sh, struct backpro_lists *bp, struct scwlist *SCWnow, goodsrc *GOODSRC, userbin *USERBIN, int chatter, int status ) { char pchar; char *NoPifPtr, charO={'O'}, charo={'o'}; int i, j, k, ee3, i5 = 0, ix, iy, ixy, jj; int jemx, dim1, dim2, bitpix, ipeak; int map_n, xvalstart, yvalstart, n; int skysize, NoPifFlag = 0; int j_src; int isrc; int vigncorr = 1; /* default: vignetting correction will be applied ! */ int n_src; int baseErr; static float xx[SCW_SRCMAX], yy[SCW_SRCMAX]; static float imgpeak[EEMAX][SKYDIM]; static float weight_shdg[detdim]; static float weight_sky[SKYDIM]; static float nnF[SKYDIM]; float detsig[2], factor, pkval, testima[SKYDIM]; float n_factor, nn_factor, peakcount[2]; float aveffi, avillu, fff; float testsum = 0.0, peakmax; float eff_imag_min=1000.0, eff_imag_max=-1000.0; float e_minim, e_maxim; float mean_bkg[2] = {0.0, 0.0}; double amx[6], sky_rms, val; double cdelt, rad_ang; double nn_f_min, nn_f_max, varim_min, varim_max; static struct fit_struc FS2; struct fit_struc *f_struc2 = {&FS2}; 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], "final_sky"); 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); i5 = logger->i5; /* NL 20120122 */ n_factor = 100.0 / sh->accumT; dim1 = dim2 = backproj->FOV_radius * 2 + 1; /* midisky image dimensions */ bitpix = -32; /* use float representation in FITS file */ if (jmx_id->jmx_unit == 0) sprintf(f_struc2->instru, "JMX1"); else sprintf(f_struc2->instru, "JMX2"); f_struc2->naxis1 = dim1; f_struc2->naxis2 = dim2; f_struc2->bitpix = -32; f_struc2->jemx = jmx_id->jmx_unit; f_struc2->orbit = backproj->aux_orbit; f_struc2->pid = backproj->aux_pid; f_struc2->pidv = sh->aux_pidv; f_struc2->crval1 = SCWnow->jmxRA; f_struc2->crval2 = SCWnow->jmxdec; f_struc2->rot_ang = SCWnow->roll_angle + jmx_id->phase2; f_struc2->crpix1 = (double)(backproj->FOV_radius+1); f_struc2->crpix2 = (double)(backproj->FOV_radius+1); f_struc2->exposure = sh->accumT; f_struc2->varia_id = 100; f_struc2->ctrl = 1; strcpy(f_struc2->bkg_model, logger->ref_file_name); ee3 = eeuser; if (ee3 > backproj->ee_basic ) ee3 = backproj->ee_basic; /* ******************************************************************** */ /* */ /* Backproject final residual shadowgram to form final sky image */ /* and raw shadowgram to form weighted variance image */ /* and first residual shadowgram to form weighted first image */ /* */ /* ******************************************************************** */ for (i=0; iskyim_r[i] = 0.0; for (i=0; isoft_gr[i] > 0.0) weight_shdg[i] = sh->backcmp[i] * sh->backcmp[i] / (sh->backall[i] * sh->backall[i]); else weight_shdg[i] = 0.0; } NoPifPtr = strstr( logger->skyImagesOut, "NOPIF" ); if ((strstr( logger->skyImagesOut, "PIF" ) != NULL) && (NoPifPtr == NULL)) { status = backpro8_W(sh->resid, USERBIN[eeuser].effic_shdg, weight_shdg, USERBIN[eeuser].shadow, logger->resid1, backproj->skyim_r, weight_sky, backproj->fitsimage[ee3][0], backproj->fitsimage[ee3][1], logger, backproj, bp); } else { status = backpro8_d(sh->resid, backproj->skyim_r, logger, backproj, bp); } if (n_common2 == 0) { sprintf(logger->tmptxt, "##80## No common sources in the search energy bands"); logger->logstat = logprint(logger, logger->tmptxt, i5); goto write_skyimages; } for (n_src=0; n_srcbackmodels+n_src] = GOODSRC[n_src].catxx; yy[backproj->backmodels+n_src] = GOODSRC[n_src].catyy; } else { xx[backproj->backmodels+n_src] = GOODSRC[n_src].xx; yy[backproj->backmodels+n_src] = GOODSRC[n_src].yy; } sprintf(logger->tmptxt, "source %1d: X: %6.2f, Y: %6.2f", n_src, xx[backproj->backmodels+n_src], yy[backproj->backmodels+n_src]); logger->logstat = logprint(logger, logger->tmptxt, i5); } if (status != ISDC_OK) { sprintf(logger->tmptxt, "##89## backpro8_W error, status = %d", status); logger->logstat = logprint(logger, logger->tmptxt, i5); RILlogMessage( NULL, Error_0, "##89## backpro8_W error, status = %d", status); logger->logstat = logprint(logger, logger->error_text, 7); status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_BACKPRODERR; goto exittrace; } status = clean2(backproj->skyim_r, xx, yy, n_common2, backproj->backmodels, imgpeak[ee3], ee3, logger, backproj, chatter, status ); /* save flat fielded residual map */ for (i=0; iskydim; i++) { backproj->fitsimage[ee3][3][i] = imgpeak[ee3][i]; /* copy updated residual image to fitsimage 3 and 4 */ backproj->fitsimage[ee3][4][i] = imgpeak[ee3][i]; } if ((strstr( logger->skyImagesOut, "PIF" ) != NULL) && (NoPifPtr == NULL)) { /* clean weight-backprojected first residual image using information about found sources */ status = clean2(backproj->fitsimage[ee3][1], xx, yy, n_common2, backproj->backmodels, imgpeak[ee3], ee3, logger, backproj, chatter, status ); /* save flat fielded, weighted first image */ for (i=0; iskydim; i++) backproj->fitsimage[ee3][2][i] = imgpeak[ee3][i]; } for (isrc=0; isrcpeak_last = 1; peakval[eeuser][isrc] = peaktransfer(xx[backproj->backmodels+isrc], yy[backproj->backmodels+isrc], backproj->fitsimage[ee3][2], imgpeak[ee3], peakcount, mean_bkg, ee3, detsig, backproj, logger); logger->peak_last = 0; GOODSRC[isrc].mean_bkg[eeuser] = mean_bkg[0]; peakval[eeuser+256][isrc] = peakcount[1]; /* GOODSRC[isrc].sn[eeuser] = detsig[0]; diabled 20120604 Niels Lund */ GOODSRC[isrc].peakval[eeuser] = peakval[eeuser][isrc]; /* **************************Copied from *work.c 20090331 ************************** * logger->peak_last = 0; * pkval = peaktransfer(xx[ksrc], yy[ksrc], backproj->fitsimage[ee3][2], imgpeak[ee3], * peakcount, mean_bkg, ee3, detsig, backproj, logger); * logger->peak_last = 0; * * rawcount = peakcount[1]; * Apix = GOODSRC[logger->N_SRC2].src_pixel_area[eeuser]; * GOODSRC[logger->N_SRC2].flux_err[eeuser] = sqrt(rawcount) + (Anoise / Apix) * fabs(peakcount[0]); * GOODSRC[logger->N_SRC2].flux_err[eeuser] *= 100 / exposure; **************************Copied from *work.c 20090331 ************************** */ GOODSRC[isrc].fit_peakval[eeuser] = peakcount[1]; GOODSRC[isrc].fit_backval[eeuser] = peakcount[0]; if (detsig[0] > 0.0) GOODSRC[isrc].flux_err[eeuser] = 1.0 / detsig[0]; else GOODSRC[isrc].flux_err[eeuser] = 99.99; if ((GOODSRC[isrc].preset & 3) == 3) { if (detsig[0] < 4.0) { if (ee3 == 0) GOODSRC[isrc].preset &= 0xFB; if (ee3 == 1) GOODSRC[isrc].preset &= 0xF7; if (ee3 == 2) GOODSRC[isrc].preset &= 0xEF; } } sprintf(logger->tmptxt, "##90## E%02d: source: %2d, peakval1: %8.1f, detsig: %5.1f, mean_backgr: %6.1f", eeuser, isrc, peakval[eeuser][isrc], GOODSRC[isrc].sn[eeuser], GOODSRC[isrc].mean_bkg[eeuser]); logger->logstat = logprint(logger, logger->tmptxt, i5); } /* recover peaks of strong sources from 'imgpeak' image */ for (isrc=0; isrcpeak_last = 0; peaktransfer(xx[backproj->backmodels+isrc], yy[backproj->backmodels+isrc], imgpeak[ee3], backproj->fitsimage[ee3][4], peakcount, mean_bkg, ee3, detsig, backproj, logger); logger->peak_last = 0; GOODSRC[isrc].sn2[eeuser] = detsig[0]; } /* redo cleaning of raw image, now using the information about strong sources */ status = clean2(backproj->fitsimage[ee3][1], xx, yy, n_common2, backproj->backmodels, imgpeak[ee3], ee3, logger, backproj, chatter, status ); for (i=0; iskydim; i++) backproj->fitsimage[ee3][1][i] = imgpeak[ee3][i]; for (map_n=0; map_nbackmodels + map_n]); yvalstart = (int)(yy[backproj->backmodels + map_n]); amx[0] = -xvalstart * backproj->sky_ydim - yvalstart; /* fix position for findpeak */ findpeak(backproj->fitsimage[ee3][2], &sky_rms, amx, ee3, logger, backproj); /* excess source counts in amx[3] */ backproj->orig_data_peak[ee3][map_n] = amx[3]; amx[0] = -xvalstart * backproj->sky_ydim - yvalstart; /* fix position for findpeak */ findpeak(backproj->fitsimage[ee3][3], &sky_rms, amx, ee3, logger, backproj); /* excess source counts in amx[3] */ backproj->resid_data_peak[ee3][map_n] = amx[3]; } /* after final fit output final, source cleaned map */ write_skyimages: /* write_skyimages */ eff_imag_max = -1000.0; eff_imag_min = +1000.0; nn_f_min = 1.0e20; nn_f_max = -1.0e20; varim_min = 1.0e20; varim_max = -1.0e20; avillu = aveffi = 0.0; if ( strstr( logger->skyImagesOut, "NOVIGN" ) == NULL ) { /* convert image units to counts/s/cm2 */ peakmax = 0.0; ipeak = 0; for (i=0; iskydim; i++) { if (backproj->illumx[i] > backproj->signiflim) { if (eff_imag_min > weight_sky[i]) eff_imag_min = weight_sky[i]; if (eff_imag_max < weight_sky[i]) eff_imag_max = weight_sky[i]; if ((strstr( logger->skyImagesOut, "PIF" ) != NULL) && (NoPifPtr == NULL)) { if (weight_sky[i] > 0.05) nn_factor = n_factor * 100.0 / (weight_sky[i] * USERBIN[eeuser].transcor[i]); else nn_factor = 0.0; } else { if (USERBIN[eeuser].eff_imag[i] > 0.05) nn_factor = n_factor * 100.0 / USERBIN[eeuser].eff_imag[i]; else nn_factor = 0.0; } nnF[i] = nn_factor; if (backproj->illumx[i] > 0) aveffi += weight_sky[i]; if (backproj->soft_gr[i] > 0.0) avillu += (float)(backproj->illumx[i]); backproj->fitsimage[ee3][1][i] = USERBIN[eeuser].raw_imag[i] * nn_factor; /* raw image */ backproj->fitsimage[ee3][2][i] *= nn_factor; /* raw, rectified image */ backproj->fitsimage[ee3][3][i] *= nn_factor; /* residual image */ backproj->fitsimage[ee3][4][i] *= nn_factor; /* residual image + found sources */ backproj->skyim_r[i] *= nn_factor; /* residual image before cleaning */ if (nn_factor > nn_f_max) nn_f_max = nn_factor; if (nn_factor < nn_f_min) nn_f_min = nn_factor; if (backproj->fitsimage[ee3][0][i] > varim_max) varim_max = backproj->fitsimage[ee3][0][i]; if (backproj->fitsimage[ee3][0][i] < varim_min) varim_min = backproj->fitsimage[ee3][0][i]; if (backproj->fitsimage[ee3][0][i] > 1.0e10) backproj->fitsimage[ee3][0][i] = 1.0e6; backproj->fitsimage[ee3][0][i] *= nn_factor * nn_factor; /* variance image */ testima[i] = backproj->fitsimage[ee3][3][i] / nn_factor; if (backproj->fitsimage[ee3][0][i] > 0.0) { if ((backproj->fitsimage[ee3][4][i] / sqrt(backproj->fitsimage[ee3][0][i])) > peakmax) {ipeak = i; peakmax = backproj->fitsimage[ee3][4][i] / sqrt(backproj->fitsimage[ee3][0][i]);} } } else { backproj->fitsimage[ee3][0][i] = 0.0; backproj->fitsimage[ee3][1][i] = 0.0; backproj->fitsimage[ee3][2][i] = 0.0; backproj->fitsimage[ee3][3][i] = 0.0; backproj->fitsimage[ee3][4][i] = 0.0; testima[i] = imgpeak[ee3][i] = 0.0; } } /* end of i-loop */ if (eeuser == backproj->ee_basic) { for (j=0; j<5; j++) { sprintf(logger->tmptxt, "##BB %6d image%1d%1d: ", ipeak, ee3, j); for (i = ipeak - 5; i < ipeak + 5; i++) { sprintf(logger->tmptxt2, "%+e ", backproj->fitsimage[ee3][j][i]); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } logger->logstat = logprint(logger, logger->tmptxt, 0); } sprintf(logger->tmptxt, "##BB %6d imgpeak: ", ipeak); for (i = ipeak - 5; i < ipeak + 5; i++) { sprintf(logger->tmptxt2, "%+e ", imgpeak[ee3][i]); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } logger->logstat = logprint(logger, logger->tmptxt, 0); sprintf(logger->tmptxt, "##BB %6d nn_fact: ", ipeak); for (i = ipeak - 5; i < ipeak + 5; i++) { sprintf(logger->tmptxt2, "%+e ", nnF[i]); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } sprintf(logger->tmptxt2, "\n##BB"); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); logger->logstat = logprint(logger, logger->tmptxt, 0); } vigncorr = 1; } else vigncorr = 0; sprintf(logger->tmptxt, "##8834## eeuser: %2d, n_factor: %10.4e, eff_imag_min: %10.4e, eeff_imag_max: %10.4e\n", eeuser, n_factor, eff_imag_min, eff_imag_max); logger->logstat = logprint(logger, logger->tmptxt, i5); sprintf(logger->tmptxt, "##8834## eeuser: %2d, nn_f_min: %e, nn_f_max: %e, varim_min: %e, varim_max: %e\n", eeuser, nn_f_min, nn_f_max, varim_min, varim_max); logger->logstat = logprint(logger, logger->tmptxt, i5); skysize = f_struc2->naxis1 * f_struc2->naxis2; if ( chatter > J_CHATTY_NORMAL ) { sprintf(logger->tmptxt, "##91## E%02d: ee_basic: %2d, skysize: %d\n", ee3, backproj->ee_basic, skysize); logger->logstat = logprint(logger, logger->tmptxt, i5); } if (avillu != 0.0) { sprintf(logger->tmptxt, "Skyimages output: ee: %3d, aveffi: %f, avillum: %f, mean effi: %f\n", eeuser, aveffi, avillu, aveffi / avillu); logger->logstat = logprint(logger, logger->tmptxt, i5); } if( chatter > J_CHATTY_VERBOSE ) { testsum = 0.0; for( i = 0; i < backproj->skydim; i++ ) testsum += backproj->fitsimage[ee3][0][i]; RILlogMessage( NULL, Log_0,"##92## SUM fitsimage[ee3][0] = %f", testsum); testsum = 0.0; for( i = 0; i < backproj->skydim; i++ ) testsum += backproj->fitsimage[ee3][1][i]; RILlogMessage( NULL, Log_0,"##93## SUM fitsimage[ee3][1] = %f", testsum); testsum = 0.0; for( i = 0; i < backproj->skydim; i++ ) testsum += backproj->fitsimage[ee3][2][i]; RILlogMessage( NULL, Log_0,"##94## SUM fitsimage[ee3][2] = %f", testsum); testsum = 0.0; } cdelt = (jmx_id->mask_r + jmx_id->coll_r) / (backproj->FOV_radius * jmx_id->mask_height * GTORAD); /* QQQQ NL 20081211 Compensation for penetration effect on focal length */ cdelt /= 0.994 + 0.006 * USERBIN[eeuser].i_depth / 27.5; /* NL 20081211 Compensation for penetration effect on focal length */ rad_ang = SCWnow->roll_angle * GTORAD + J_COR_PI / 2.0 + jmx_id->phase2; f_struc2->cd1_1 = cdelt * cos(rad_ang); f_struc2->cd1_2 = cdelt * sin(rad_ang); f_struc2->cd2_1 = cdelt * sin(rad_ang); f_struc2->cd2_2 = -cdelt * cos(rad_ang); e_minim = f_struc2->emin = sh->eval[eeuser][0]; e_maxim = f_struc2->emax = sh->eval[eeuser][1]; f_struc2->psfsigma = backproj->psfsigma[eeuser]; /* PSFSIGMA in degrees */ /* +++++++++++++++++++++++++++++++++++++++++++++++++ */ /* output the sky image as FITS */ /* for (i=0; ifitsimage[ee3][1][i] = USERBIN[eeuser].raw_imag[i]; */ logger->skipNeighborCor = bp->skipNeighborCor; if ((logger->detImagesOut > 0) && (eeuser < backproj->ee_basic) && ( strstr( logger->skyImagesOut, "NONE" ) == NULL) ) { if (logger->trace) traces(func_local, 70, logger); skyout( theSWG, jmx_id, logger, backproj, sh, f_struc2, imgpeak[ee3], e_minim, e_maxim, ee3, eeuser, vigncorr, chatter, status); } if ((logger->userImagesOut > 0) && (eeuser >= backproj->ee_basic) && ( strstr( logger->skyImagesOut, "NONE" ) == NULL) ) { if (logger->trace) traces(func_local, 80, logger); skyout( theSWG, jmx_id, logger, backproj, sh, f_struc2, imgpeak[ee3], e_minim, e_maxim, ee3, eeuser, vigncorr, chatter, status); } 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 ); exittrace: /* exittrace */ if (logger->trace) traces(func_local, 1000-status, logger); goto slut; } /***************************************************************** * Name of source file: irosloop2.c * Version of source file: 4.0.12 * Parent component: None * Programmer: Niels Lund * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325716 FAX: +45 35362475 * nl@spacecenter.dk * Purpose: Perform the IROS loop in j_ima_iros * Origin date: 041122 * Update history: 1.0.0 041130 First version * 1.0.4 050126 Test version for undue crash * 1.1.0 050131 Now reading FITS sky/backproj files * 1.1.1 050211 Keywords adapted to needs of j_ima_mosaic * 1.1.2 050303 Extra keyw:RLIMIDX, new cleaning * 1.1.3 050307 New DMAP: 51 radii * 1.1.4 050407 New clean, etc. * 1.1.5 050415 New clean again, updated flux determination * 1.1.6 050418 Now uses JMXi-DBKG-MOD as default for empty field shds * 1.2.0 050425 Deals with SPR 4102,4108 and reduces RAM requirement * 1.3.0 050503 Deals with SPR 4120 and copes with up to 6 shadowgrams * 1.3.1 050517 Deals with SPR 4143 and initializes ima_sigma properly * 1.3.2 050519 Closes SPR 4157 - bad size of three arrays * 1.3.3 050602 Changes some arrays to static (SPR 4202) * 1.4.0 050609 Introduction of pre-selected sources, correction of blindspot error * 1.4.0 050620 Include user defined sources (SCREW 1740) * 1.5.1 051129 Separating functions to jmx_lib_pif * 1.5.2 051202 Separating functions to jmx_lib_pif (2) * 1.5.3 051202 Give offX, x2x values in mm in IMOD-GRP * 1.5.4 060104 Bug in sh_depth corrected, detectmap now in mm * 1.5.5 060106 Introduced one more digit in logfile for src position * 1.5.6 060228 Removed parameter detMapFile and some obsolete variables * 1.5.7 060606 Shifted detCondMap to struct jmx_id and status_map * 1.5.8 060807 SPR 04551 Bad assignment of RLIMIDX corrected * 1.5.9 060807 SPR 04533 Resetting status variable has been removed * 1.5.10 060807 SPR 04523 Declaring testsum as float iso. int * 1.5.11 060807 SPR 04458 A warning log line has been added * 1.5.12 060907 SPR 04301 A relative VIGNDOL path is given * 1.6.0 060911 SCREW 1918 Image correction map and parameters introduced * 1.6.1 060912 SPR 4441 Shadowgrams with too few counts are excluded * 1.6.2 060915 SCREW 1842 A significance map can now be obtained * 1.6.3 060915 An exposure (vignetting) map is now a product * 1.6.4 060928 Included test for zero divisor in peaktransfer.c * 1.6.5 061002 New defaults for par. skyImagesOut * 1.7.0 061110 Produces images with few or zero events (SPR 4594) * 1.7.1 061114 SPR 4603 Image unit (BUNIT) is now cts/dm2/s * 1.8.0 061213 SPR 4640 Error in findpeak has been corrected * 1.8.1 070123 SPR 4590 int changed to long for 64 bit code * 2.0.0 070302 Simplified peak optimization involving 'radcor' routine * 2.1.0 070730 Active use of input source catalog * and feedback from sky_image analysis * 2.1.0 070809 SCREWs 2021-2023 * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 4.0.10 120830 SPR ?: Initialize variables as suggested by valgrind * 4.0.12 120919 SPR ?: Introduce corrections by LP and Co. * Type of element: Function * Part of package: j_ima_iros * Name: irosloop2 * Required components: DAL, PIL, RIL, DAL3GEN Flow of program: Fit shadowgram with background components, generate residual shadowgram A: Backproject residual shadowgram to form sky image Blank out regions in the sky image around all sources found so far. Find highest peak in sky image Stop if peak too small. Create source illumination function corresponding to peak position Fit shadowgram with background components plus all sources found so far NEW for 2.0.0 !! Check position of peak corresponding to last found source NEW for 2.0.0 !! Update coordinates of last source Create source illumination function corresp. to updated peak position Fit shadowgram with backgr. components plus all sources found so far, generate residual shadowgram. Stop if last source power too small Go back to A (search for more sources) *****************************************************************/ int irosloop2( int jemx, int ee, float xx_iir[SCW_SRCMAX], float yy_iir[SCW_SRCMAX], int src_id[SCW_SRCMAX], double solut[SCW_SRCMAX], float *goodrms, double *sh_rms2, int *fitcycles, int *goodnsrc, float goodbet_g[SCW_SRCMAX], short preset[SCW_SRCMAX], struct instr_data *jmx_id, struct log_con *logger, struct backpro *backproj, struct backpro_lists *bp, struct shadowgrams *sh, MAPS_SRC *maps_src, int chatter, int status) { int i5 = 0; int i, j, m, tours, nsrc, ngrp, fitcnt = 0; int mini_rms, mini_const, sxy=0, sxy_list[SCW_SRCMAX]; int sxy2; int xvalstart, yvalstart, sky_index; int ghoststep[2]; int baseErr = J_ERROR_CODE_START + J_IMA_IROS_ERR; static float skyim[SKYDIM]; float valmin_rms, valmin_const, xnow, ynow, shadow_counts, funval; float x_in, y_in, x_out, y_out, abs_len, xchk, ychk; float fitval; float current_skyim[SKYDIM]; float testsum = 0.0; /* SPR 4523 2006-08-07/NJW */ float xx[SCW_SRCMAX]; float yy[SCW_SRCMAX]; float diff; double amx[6], rms, sky_rms, amx2[6]; static int func_local = -1, local_calling_num=0; clock_t clock(void), calling_TT, TT_now; if( status != ISDC_OK ) return( status ); /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "irosloop2"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ /* QQQQQQ */ if (logger->trace) traces(func_local, 0, logger); i5 = logger->i5; /* NL 20120122 */ backproj->blindnum = backproj->blindnum_preset; tours = 0; backproj->stopcode[ee] = 0; nsrc = *goodnsrc; ngrp = nsrc - 1; if (jemx == 0) { ghoststep[0] = 126 * backproj->sky_ydim - 294; ghoststep[1] = -318 * backproj->sky_ydim + 37; } else { ghoststep[0] = -126 * backproj->sky_ydim + 294; ghoststep[1] = 318 * backproj->sky_ydim - 37; } sprintf(logger->tmptxt, "##257## irosloop2: Calling fun initially"); logger->logstat = logprint(logger, logger->tmptxt, i5); status = FUN(-1, 1, ee, xx, yy, jemx, 0, &funval, jmx_id, logger, backproj, chatter, status); /* reset fitting functions */ if (status != ISDC_OK ) goto nextee; sprintf(logger->tmptxt, "##258## Returning from fun, blindnum preset: %3d", backproj->blindnum_preset); logger->logstat = logprint(logger, logger->tmptxt, i5); shadow_counts = 0; for (i=0; isoft_gr[i] > 0.0) shadow_counts += backproj->shadw[i]; /* introduce coordinates for preset-sources type-3 into local list */ for (i=0; iblindnum_preset == 0) { for (i=0; iskydim; i++) current_skyim[i] = backproj->fitsimage[ee][2][i]; goto igen; } /* ************************************************************************** */ /* */ /* Fit shadowgram with background components and preset sources */ /* */ /* ************************************************************************** */ /* QQQQQQ */ /* shadowfit returns a solution to the fit process in "solut" and a residual shadowgram in "sh->resid" */ sprintf(logger->tmptxt, "##263## Calling shadowfit (1), nsrc: %3d", nsrc); logger->logstat = logprint(logger, logger->tmptxt, i5); status = shadowfit(backproj->shadw, jemx, ee, nsrc, xx, yy, solut, 0, &rms, jmx_id, logger, backproj, sh, chatter, status); *goodrms = rms; backproj->solut0_0[ee] = solut[0]; backproj->solut0_1[ee] = solut[1]; for (m=backproj->backmodels; mtmptxt, "##264## Negative status on return" " from shadowfit (1), status: %d", status); logger->logstat = logprint(logger, logger->tmptxt, i5); if (logger->trace) traces(func_local, 7701, logger); goto nextee; } if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##265## Other error: status = %d", status); if (logger->trace) traces(func_local, 7702, logger); goto nextee; } if (logger->test == 99) goto nextee; sprintf(logger->tmptxt, "##266## Returning from shadowfit"); logger->logstat = logprint(logger, logger->tmptxt, i5); fitcnt = 1; *fitcycles = fitcnt; if (rms < 0.0) { status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_BADDATA; goto nextee; /* bad data */ } sprintf(logger->tmptxt, "##999c## E%1d. In irosloop2: calling rmscalc with 'sh_resid' after shadowfit", ee); logger->logstat = logprint(logger, logger->tmptxt, i5); *sh_rms2 = rmscalc(sh->resid, backproj->soft_gr, logger); sprintf(logger->tmptxt, "##267## Returning from rmscalc"); logger->logstat = logprint(logger, logger->tmptxt, i5); mini_rms = mini_const = 0; valmin_const = fabs(solut[0]); valmin_rms = rms; sprintf(logger->tmptxt, "##266a# E%1d backgr.fitpwr: %6.2f %6.2f, rms: %6.2f", ee, solut[0], solut[1], rms); logger->logstat = logprint(logger, logger->tmptxt, i5); /* ******************************************************** */ /* */ /* Backproject residual shadowgram to form sky image */ /* */ /* ******************************************************** */ /* QQQQQQ */ sprintf(logger->tmptxt, "##268## Calling backpro8_d 2"); logger->logstat = logprint(logger, logger->tmptxt, i5); for (i=0; iskyim_r[i] = 0.0; status = backpro8_d(sh->resid, backproj->skyim_r, logger, backproj, bp); if (status != ISDC_OK) { RILlogMessage( NULL, Error_1, "##269## after backpro8_d: %d", status); status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_BACKPRODERR; goto nextee; } sprintf(logger->tmptxt, "##270## Returning from backpro8_d 2"); logger->logstat = logprint(logger, logger->tmptxt, i5); /* * if( chatter > J_CHATTY_MAXIMAL ) { * status = fits_test_output( "backpro8_1_", backproj->skyim_r, 511, logger, chatter, status ); * RILlogMessage( NULL, Log_0, "##271## Dump of 'backproj->skyim_r'"); * } */ testsum = 0.0; for (i=0; iskydim; i++) { backproj->fitsimage[ee][1][i] = backproj->skyim_r[i]; testsum += backproj->skyim_r[i]; } for (i=0; iresid1[i] = sh->resid[i]; /* logger->resid1[detdim] contains the residual shadowgram after removal of background components */ sprintf(logger->tmptxt, "##272## Calling clean, testsum = %f", testsum); logger->logstat = logprint(logger, logger->tmptxt, 0); status = clean(backproj->skyim_r, skyim, ee, logger, backproj, chatter, status ); /* remove large scale structures in skyimage */ if( status != ISDC_OK ) { RILlogMessage( NULL, Warning_0, "##273## clean returned: %d, status reset!", status); status = ISDC_OK; } testsum = 0.0; for (i=0; iskydim; i++) { testsum += skyim[i]; } sprintf(logger->tmptxt, "##274a## Returning from clean, cnts out = %f", testsum); logger->logstat = logprint(logger, logger->tmptxt, 0); /* after first fit output background cleaned map */ for( i=0; i < backproj->skydim; i++) { backproj->fitsimage[ee][2][i] = skyim[i]; backproj->fitsimage[ee][3][i] = skyim[i]; backproj->fitsimage[ee][4][i] = skyim[i]; current_skyim[i] = skyim[i]; } /* backproj->fitsimage[ee][2] contains the first cleaned backprojected sky_image */ /* ******************************************************** */ /* ******************************************************** */ /* * * */ /* * Iterative source removal loop starts here * */ /* * * */ /* ******************************************************** */ /* ******************************************************** */ /* QQQQQQ */ igen: /* igen */ nsrc++; tours++; if (nsrc > SCW_SRCMAX) { sprintf(logger->tmptxt, "##275## stop for nsrc > %2d", SCW_SRCMAX); logger->logstat = logprint(logger, logger->tmptxt, i5); nsrc--; backproj->stopcode[ee] = 1; goto nextee; /* next energy range */ } /* Remove regions around sources already found */ if (backproj->blindnum > 0) blankout(backproj->blindnum, backproj->blindspots, current_skyim, backproj, logger); /* ******************************************************** */ /* */ /* Find dominant source in sky image */ /* */ /* ******************************************************** */ amx[0] = 1.0; /* current_skyim contains the current cleaned backprojected sky_image */ sxy = findpeak(current_skyim, &sky_rms, amx, ee, logger, backproj); /* source position X is in amx[1], Y in amx[2] and excess source counts in amx[3] */ if (sxy < 0) { backproj->stopcode[ee] = 7; sprintf(logger->tmptxt, "##276## stop for findpeak bad residual map, sxy: %d ", sxy); logger->logstat = logprint(logger, logger->tmptxt, i5); ngrp--; nsrc--; /* disregard last found source */ goto nextee; } sprintf(logger->tmptxt, " ##914## After findpeak1 call: ee: %1d, nsrc: %2d, amx[0/1/2/3]: %8.0f %8.4f %8.4f %8.4f, sxy: %8d", ee, nsrc, amx[0], amx[1]-backproj->FOV_radius, amx[2]-backproj->FOV_radius, amx[3], sxy); if (nsrc >= 3) logger->logstat = logprint(logger, logger->tmptxt, i5); xvalstart = (int)(amx[1]) - 5; yvalstart = (int)(amx[2]) - 5; for (j=0; j<12; j++) { /* collect data from 12x12 field around source */ for (i=0; i<12; i++) { sky_index = (xvalstart+i) * backproj->sky_ydim + yvalstart + j; if ((sky_index >= 0) && (sky_index < backproj->skydim)) fitval = current_skyim[sky_index]; else fitval = -1000.0; maps_src[backproj->map_cnt].map[i][j] = fitval; } } maps_src[backproj->map_cnt].x_findpeak = amx[1]; maps_src[backproj->map_cnt].y_findpeak = amx[2]; maps_src[backproj->map_cnt].peak_count = amx[3]; maps_src[backproj->map_cnt].ee = ee; maps_src[backproj->map_cnt].step = 0; maps_src[backproj->map_cnt].x_map = 0.0; maps_src[backproj->map_cnt].y_map = 0.0; backproj->map_cnt++; if (backproj->map_cnt > 299) backproj->map_cnt = 299; /* ************************************************************ */ /* */ /* Correct the peak position according to abs_len and offset */ /* */ /* ************************************************************ */ /* QQQQQQ */ x_in = amx[1]; y_in = amx[2]; abs_len = jmx_id->absolen; radcor(x_in, y_in, abs_len, jemx, &x_out, &y_out, jmx_id, backproj, logger); amx[1] = x_out; amx[2] = y_out; for (j=0; j<12; j++) { /* 12x12 field around source */ for (i=0; i<12; i++) { maps_src[backproj->map_cnt].map[i][j] = maps_src[backproj->map_cnt - 1].map[i][j]; } } maps_src[backproj->map_cnt].x_findpeak = amx[1]; maps_src[backproj->map_cnt].y_findpeak = amx[2]; maps_src[backproj->map_cnt].peak_count = 0.0; maps_src[backproj->map_cnt].ee = ee; maps_src[backproj->map_cnt].step = 1; maps_src[backproj->map_cnt].x_map = 0.0; maps_src[backproj->map_cnt].y_map = 0.0; backproj->map_cnt++; if (backproj->map_cnt > 299) backproj->map_cnt = 299; /* sprintf(logger->tmptxt, " ##914## After radcor1 call: ee: %1d, nsrc: %2d, amx[0/1/2/3]: %8.0f %8.4f %8.4f %8.4f, sxy: %8d", ee, nsrc, amx[0], amx[1]-backproj->FOV_radius, amx[2]-backproj->FOV_radius, amx[3], sxy); if (nsrc >= 3) logger->logstat = logprint(logger, logger->tmptxt, 0); else logger->logstat = logprint(logger, logger->tmptxt, i5); */ if ((nsrc-backproj->backmodels) >= backproj->iterations) { backproj->stopcode[ee] = 2; sprintf(logger->tmptxt, "##277## stop for backproj->iterations"); logger->logstat = logprint(logger, logger->tmptxt, i5); ngrp--; nsrc--; /* disregard last found source */ if (backproj->map_cnt > 0) backproj->map_cnt--; goto nextee; } if (tours >= 20) { sprintf(logger->tmptxt, "##278## stop for more than 20 fit cycles"); logger->logstat = logprint(logger, logger->tmptxt, i5); backproj->stopcode[ee] = 3; ngrp--; nsrc--; /* disregard last found source */ if (backproj->map_cnt > 0) backproj->map_cnt--; goto nextee; } if (amx[0] < (3.0 * sky_rms)) { sprintf(logger->tmptxt, "##279## stop for peak significance"); logger->logstat = logprint(logger, logger->tmptxt, i5); backproj->stopcode[ee] = 4; ngrp--; nsrc--; /* disregard last found source */ if (backproj->map_cnt > 0) backproj->map_cnt--; goto nextee; /* check significance of new peak */ } xnow = amx[1]; ynow = amx[2]; for (j=0; j<12; j++) { /* 12x12 field around source */ for (i=0; i<12; i++) { maps_src[backproj->map_cnt].map[i][j] = maps_src[backproj->map_cnt - 1].map[i][j]; } } maps_src[backproj->map_cnt].x_findpeak = xnow; maps_src[backproj->map_cnt].y_findpeak = ynow; maps_src[backproj->map_cnt].peak_count = 0.0; maps_src[backproj->map_cnt].ee = ee; maps_src[backproj->map_cnt].step = 2; maps_src[backproj->map_cnt].x_map = 0.0; maps_src[backproj->map_cnt].y_map = 0.0; backproj->map_cnt++; if (backproj->map_cnt > 299) backproj->map_cnt = 299; ngrp = nsrc - 1; xx_iir[ngrp] = xx[ngrp] = xnow; yy_iir[ngrp] = yy[ngrp] = ynow; sxy_list[ngrp] = sxy; sprintf(logger->tmptxt, "##280## Dominant source position: sxy: %6d, delta xy: %+4d %+4d, ngrp: %2d", sxy, (int)(sxy/backproj->sky_ydim - backproj->FOV_radius), (int)((sxy%backproj->sky_ydim) - backproj->FOV_radius), ngrp); logger->logstat = logprint(logger, logger->tmptxt, 4); /* ******************************************************** */ /* */ /* Fit shadowgram with background and source components */ /* Generate residual shadowgram for next findpeak operation */ /* */ /* ******************************************************** */ /* QQQQQQ */ sprintf(logger->tmptxt, "Calling shadowfit (2), n_src: %1d, ngrp: %d", nsrc, ngrp); logger->logstat = logprint(logger, logger->tmptxt, i5); status = shadowfit(backproj->shadw, jemx, ee, nsrc, xx, yy, solut, 0, &rms, jmx_id, logger, backproj, sh, chatter, status ); /* *************************************************************************** */ /* */ /* When shadowfit returns one of 9 status-values the source is dismissed */ /* */ /* *************************************************************************** */ if ( status == baseErr+J_IIR_FUNERR1 || status == baseErr+J_IIR_FUNERR2 || status == baseErr+J_IIR_FUNERR3 || status == baseErr+J_IIR_FUNERR4 || status == baseErr+J_IIR_FUNERR5 || status == baseErr+J_IIR_FUNERR6 || status == baseErr+J_IIR_FUNERR7 || status == baseErr+J_IIR_FUNERR8 || status == baseErr+J_IIR_IMFITERR2 || status == baseErr+J_IIR_IMFITERR3 || status == baseErr+J_IIR_IMFITERR4 || status == baseErr+J_IIR_IMFITERR5 || status == baseErr+J_IIR_IMFITERR6 || status == baseErr+J_IIR_IMFITERR7 || status == baseErr+J_IIR_SNGLMTX ) { sprintf(logger->tmptxt, "##281## Returning from shadowfit (2), status: %d", status); logger->logstat = logprint(logger, logger->tmptxt, 2); logger->logstat = logprint(logger, logger->tmptxt, 0); backproj->stopcode[ee] = 14; ngrp--; nsrc--; if (backproj->map_cnt > 0) backproj->map_cnt--; if (logger->trace) traces(func_local, 7703, logger); status = ISDC_OK; goto nextee; } if( status != ISDC_OK ) { backproj->stopcode[ee] = 15; RILlogMessage( NULL, Error_1, "##282## Other error: status = %d", status); sprintf(logger->tmptxt, "##282## Returning from shadowfit (2), error status = %d", status); logger->logstat = logprint(logger, logger->tmptxt, 2); ngrp--; /* inserted 070422, niels lund */ nsrc--; if (backproj->map_cnt > 0) backproj->map_cnt--; if (logger->trace) traces(func_local, 7704, logger); goto nextee; } fitcnt++; sprintf(logger->tmptxt, "##283## peak power: %8.3f, counts: %10.1f", solut[ngrp], shadow_counts); logger->logstat = logprint(logger, logger->tmptxt, 4); if (rms < 0.0) { backproj->stopcode[ee] = 5; sprintf(logger->tmptxt, "##284## stop for negative rms"); logger->logstat = logprint(logger, logger->tmptxt, i5); ngrp--; nsrc--; if (backproj->map_cnt > 0) backproj->map_cnt--; goto nextee; } /* **************************************************************************** */ /* backproj->current_src_map[] contains the illumination_map for the current source */ for (i=0; iskyim_r[i] = 0.0; status = backpro8_d(backproj->current_src_map, backproj->skyim_r, logger, backproj, bp); /* backproj->skyim_r[SKYDIM] contains the raw backprojected sky_image for the current source */ if (status != ISDC_OK) { RILlogMessage( NULL, Error_1, "##801## after backpro8_d: %d", status); status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_BACKPRODERR; goto nextee; } if (logger->chatter == 1) { sprintf(logger->tmptxt, "##802## Returning from backpro8_d 3"); logger->logstat = logprint(logger, logger->tmptxt, i5); } logger->median = 0; /* backproj->skyim_r[SKYDIM] contains the raw backprojected sky_image for the current source */ for (i=0; iskydim; i++) { if (jirisnan(backproj->skyim_r[i])) { sprintf(logger->tmptxt, "NAN value in backproj->skyim_r, index: %d", i); logger->logstat = logprint(logger, logger->tmptxt, i5); status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_BACKPRODERR; goto nextee; } } clean(backproj->skyim_r, skyim, ee, logger, backproj, chatter, status); /* remove large scale structures in skyimage */ for (i=0; iskydim; i++) { if (jirisnan(skyim[i])) { sprintf(logger->tmptxt, "NAN value in skyim, index: %d", i); logger->logstat = logprint(logger, logger->tmptxt, i5); status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_BACKPRODERR; goto nextee; } } /* skyim contains the cleaned backprojected sky_image for the current source */ if (logger->chatter == 1) { sprintf(logger->tmptxt, "##803## Returning from clean"); logger->logstat = logprint(logger, logger->tmptxt, i5); } /* ************************************************************ */ /* */ /* this call to findpeak just calculates the centroid */ /* for the last source peak subtracted during shadowfit */ /* */ /* ************************************************************ */ /* QQQQQQ */ amx2[0] = -sxy; /* keep the initial source position fixed at original position */ /* sprintf(logger->tmptxt, " ##914## Prior to findpeak call: ee: %1d, nsrc: %2d, amx2[0/1/2]: %8.0f %8.4f %8.4f", ee, nsrc, amx2[0], amx2[1]-backproj->FOV_radius, amx2[2]-backproj->FOV_radius, amx2[3]); if (nsrc >= 3) logger->logstat = logprint(logger, logger->tmptxt, 0); else logger->logstat = logprint(logger, logger->tmptxt, i5); */ /* skyim contains the sky_image contribution from the current source */ sxy2 = findpeak(skyim, &sky_rms, amx2, ee, logger, backproj); /* source position X is in amx2[1], Y in amx2[2] and excess source counts in amx2[3] */ sprintf(logger->tmptxt, " ##914## After findpeak call: ee: %1d, nsrc: %2d, amx2[0/1/2/3]: %8.0f %8.4f %8.4f %8.4f, sxy2: %8d", ee, nsrc, amx2[0], amx2[1]-backproj->FOV_radius, amx2[2]-backproj->FOV_radius, amx2[3], sxy2); if (nsrc >= 3) logger->logstat = logprint(logger, logger->tmptxt, 0); else logger->logstat = logprint(logger, logger->tmptxt, i5); if (sxy2 < 0) { if (logger->chatter == 1) { sprintf(logger->tmptxt, " ##805## stop for bad peak map "); logger->logstat = logprint(logger, logger->tmptxt, i5); } backproj->stopcode[ee] = 6; ngrp--; nsrc--; /* disregard last found source */ if (backproj->map_cnt > 0) backproj->map_cnt--; goto nextee; } for (j=0; j<12; j++) { /* collect data from 12x12 field around source */ for (i=0; i<12; i++) { sky_index = (xvalstart+i) * backproj->sky_ydim + yvalstart + j; if ((sky_index >= 0) && (sky_index < backproj->skydim)) fitval = skyim[sky_index]; else fitval = -1000.0; maps_src[backproj->map_cnt].map[i][j] = fitval; } } maps_src[backproj->map_cnt].x_findpeak = amx2[1]; maps_src[backproj->map_cnt].y_findpeak = amx2[2]; maps_src[backproj->map_cnt].ee = ee; maps_src[backproj->map_cnt].step = 3; maps_src[backproj->map_cnt].x_map = 0.0; maps_src[backproj->map_cnt].y_map = 0.0; backproj->map_cnt++; if (backproj->map_cnt > 299) backproj->map_cnt = 299; /* ******************************************************************** */ /* */ /* Correct the updated peak position according to abs_len and offset */ /* */ /* ******************************************************************** */ /* QQQQQQ */ x_in = amx2[1]; y_in = amx2[2]; abs_len = jmx_id->absolen; radcor(x_in, y_in, abs_len, jemx, &x_out, &y_out, jmx_id, backproj, logger); amx2[1] = x_out; amx2[2] = y_out; for (j=0; j<12; j++) { /* 12x12 field around source */ for (i=0; i<12; i++) { maps_src[backproj->map_cnt].map[i][j] = maps_src[backproj->map_cnt - 1].map[i][j]; } } maps_src[backproj->map_cnt].x_findpeak = amx2[1]; maps_src[backproj->map_cnt].y_findpeak = amx2[2]; maps_src[backproj->map_cnt].peak_count = 0.0; maps_src[backproj->map_cnt].ee = ee; maps_src[backproj->map_cnt].step = 4; maps_src[backproj->map_cnt].x_map = 0.0; maps_src[backproj->map_cnt].y_map = 0.0; backproj->map_cnt++; if (backproj->map_cnt > 299) backproj->map_cnt = 299; /* sprintf(logger->tmptxt, " ##914## After radcor call: ee: %1d, nsrc: %2d, amx2[0/1/2/3]: %8.0f %8.4f %8.4f %8.4f, sxy2: %8d", ee, nsrc, amx2[0], amx2[1]-backproj->FOV_radius, amx2[2]-backproj->FOV_radius, amx2[3], sxy2); if (nsrc >= 3) logger->logstat = logprint(logger, logger->tmptxt, 0); else logger->logstat = logprint(logger, logger->tmptxt, i5); */ if (sxy2 < 0) { if (logger->chatter == 1) { sprintf(logger->tmptxt, " ##807## stop for bad residual map "); logger->logstat = logprint(logger, logger->tmptxt, i5); } backproj->stopcode[ee] = 8; ngrp--; nsrc--; /* disregard last found source */ if (backproj->map_cnt > 0) backproj->map_cnt--; goto nextee; } if ((abs(amx[1] - amx2[1]) > 3.0) || (abs(amx[2] - amx2[2]) > 3.0)) { if (logger->chatter == 1) { sprintf(logger->tmptxt, " ##808## stop for large amx difference "); logger->logstat = logprint(logger, logger->tmptxt, i5); } backproj->stopcode[ee] = 13; ngrp--; nsrc--; /* disregard last found source */ if (backproj->map_cnt > 0) backproj->map_cnt--; goto nextee; } xchk = xx[ngrp] + amx[1] - amx2[1]; ychk = yy[ngrp] + amx[2] - amx2[2]; abs_len = jmx_id->absolen; status = radcor(xchk, ychk, abs_len, jemx, &x_out, &y_out, jmx_id, backproj, logger); if (status < 0) { if (logger->chatter == 1) { sprintf(logger->tmptxt, " ##809## stop for illegal coord. extrapolation "); logger->logstat = logprint(logger, logger->tmptxt, i5); } backproj->stopcode[ee] = 11; ngrp--; nsrc--; /* disregard last found source */ if (backproj->map_cnt > 0) backproj->map_cnt--; status = ISDC_OK; goto nextee; } sky_index = (int)(xchk) * backproj->sky_ydim + (int)(ychk); if ((int)(backproj->illumx[sky_index]) > backproj->signiflim) { xx_iir[ngrp] = xx[ngrp] = xchk; /* (xchk,ychk) are legal, use them as updated (xx,yy) */ yy_iir[ngrp] = yy[ngrp] = ychk; } for (j=0; j<12; j++) { /* 12x12 field around source */ for (i=0; i<12; i++) { maps_src[backproj->map_cnt].map[i][j] = maps_src[backproj->map_cnt - 1].map[i][j]; } } maps_src[backproj->map_cnt].x_findpeak = xchk; maps_src[backproj->map_cnt].y_findpeak = ychk; maps_src[backproj->map_cnt].peak_count = 0.0; maps_src[backproj->map_cnt].ee = ee; maps_src[backproj->map_cnt].step = 5; maps_src[backproj->map_cnt].x_map = 0.0; maps_src[backproj->map_cnt].y_map = 0.0; backproj->map_cnt++; if (backproj->map_cnt > 299) backproj->map_cnt = 299; fitcnt++; /* ++++++++++++++++++++++++++++++++++++++++++++++++++ begin of new src identification */ /* ************************************************************************* */ /* ************************************************************************* */ /* * * */ /* * * */ /* * Identify the last source found with a catalog source if possible * */ /* * (for identified sources use the coordinates from the catalog) * */ /* * * */ /* * * */ /* ************************************************************************* */ /* ************************************************************************* */ if ((solut[ngrp] > (2.0 * logger->limit_f * shadow_counts)) && (backproj->preset_src > 0)) { for (j=0; jpreset_src; j++) { if (backproj->preset_src_flag[j] == 3) continue; diff = ((backproj->preset_src_xx[j] - xx[ngrp]) * (backproj->preset_src_xx[j] - xx[ngrp])) + ((backproj->preset_src_yy[j] - yy[ngrp]) * (backproj->preset_src_yy[j] - yy[ngrp])); diff = sqrt(diff); if (diff < 1.5) { xx[ngrp] = backproj->preset_src_xx[j]; /* apply diff correction in order to avoid impact on shadowfit */ yy[ngrp] = backproj->preset_src_yy[j]; src_id[ngrp] = backproj->preset_src_id[j]; sprintf(logger->tmptxt, "irosloop identification: source[%2d]: ee: %1d, src_id: %3d\n", ngrp, ee, src_id[ngrp]); logger->logstat = logprint(logger, logger->tmptxt, i5); goto found_catalog_src; } } } src_id[ngrp] = 0; found_catalog_src: ; /* found_catalog_src */ /* ++++++++++++++++++++++++++++++++++++++++++++++++++++ end of new src identification */ /* sprintf(logger->tmptxt, " ##914## Updated xx and yy for nsrc: %2d: ngrp: %2d, amx0/1/2: %8.3f %8.3f %8.3f, xx/yy: %8.3f %8.3f", nsrc, ngrp, amx[0], amx[1]-backproj->FOV_radius, amx[2]-backproj->FOV_radius, xx[ngrp]-backproj->FOV_radius, yy[ngrp]-backproj->FOV_radius); if (nsrc >= 3) logger->logstat = logprint(logger, logger->tmptxt, 0); else logger->logstat = logprint(logger, logger->tmptxt, i5); */ /* if (logger->chatter == 1) { */ sprintf(logger->tmptxt, "Calling shadowfit (3), n_src: %1d, ngrp: %d", nsrc, ngrp); logger->logstat = logprint(logger, logger->tmptxt, i5); /* } */ status = shadowfit(backproj->shadw, jemx, ee, nsrc, xx, yy, solut, 0, &rms, jmx_id, logger, backproj, sh, chatter, status); /* sh->resid[detdim] contains the residual shadowgram */ /* if (status < 0) { */ if( status != ISDC_OK ) { sprintf(logger->tmptxt, "Negative status after shadowfit (3) with %2d components: %3d", nsrc, status); logger->logstat = logprint(logger, logger->tmptxt, i5); backproj->stopcode[ee] = 9; ngrp--; nsrc--; /* disregard last found source */ if (backproj->map_cnt > 0) backproj->map_cnt--; if (logger->trace) traces(func_local, 7705, logger); status = ISDC_OK; goto nextee; } if (rms < 0.0) { /* sprintf(logger->tmptxt, " ##809## stop for negative rms"); logger->logstat = logprint(logger, logger->tmptxt, i5); */ backproj->stopcode[ee] = 10; ngrp--; nsrc--; if (backproj->map_cnt > 0) backproj->map_cnt--; goto nextee; } if ((mini_rms == 0) || (mini_const == 0)) { for (m=0; m<=ngrp; m++) goodbet_g[m] = solut[m]; *goodnsrc = nsrc; *goodrms = rms; *fitcycles = fitcnt; } else { sprintf(logger->tmptxt, " ##813## stop beyond best fit"); logger->logstat = logprint(logger, logger->tmptxt, i5); ngrp--; nsrc--; if (backproj->map_cnt > 0) backproj->map_cnt--; backproj->stopcode[ee] = 11; goto nextee; } if (solut[ngrp] < logger->limit_f * (0.95 * shadow_counts + 0.05 * backproj->src_illum_cnts[nsrc][ee])) { /* if (solut[ngrp] < logger->limit_f * shadow_counts) { */ sprintf(logger->tmptxt, "\n ##817## stop for peak power: solut[ngrp]: %8.3lf, counts: %10.1f", solut[ngrp], shadow_counts); logger->logstat = logprint(logger, logger->tmptxt, i5); backproj->stopcode[ee] = 12; ngrp--; nsrc--; if (backproj->map_cnt > 0) backproj->map_cnt--; goto nextee; } /* **************************************************************************** */ /* ******************************************************** */ /* */ /* Backproject residual shadowgram to form sky image */ /* */ /* ******************************************************** */ /* QQQQQQ */ sprintf(logger->tmptxt, "##289## Calling backpro8_d 3"); logger->logstat = logprint(logger, logger->tmptxt, i5); for (i=0; iskyim_r[i] = 0.0; status = backpro8_d(sh->resid, backproj->skyim_r, logger, backproj, bp); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_0, "##290## After backpro8_d, status = %d", status); status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_BACKPRODERR; goto nextee; } sprintf(logger->tmptxt, "##291## Returning from backpro8_d 3"); logger->logstat = logprint(logger, logger->tmptxt, i5); status = clean(backproj->skyim_r, skyim, ee, logger, backproj, chatter, status ); /* remove large scale structures in skyimage */ if( status != ISDC_OK ) { RILlogMessage( NULL, Warning_0, "##292## clean returned: %d, status reset!", status); status = ISDC_OK; } for (j=0; j<12; j++) { /* collect data from 12x12 field around source */ for (i=0; i<12; i++) { sky_index = (xvalstart+i) * backproj->sky_ydim + yvalstart + j; if ((sky_index >= 0) && (sky_index < backproj->skydim)) fitval = skyim[sky_index]; else fitval = -1000.0; maps_src[backproj->map_cnt].map[i][j] = fitval; } } maps_src[backproj->map_cnt].x_findpeak = xx[ngrp]; maps_src[backproj->map_cnt].y_findpeak = yy[ngrp]; maps_src[backproj->map_cnt].peak_count = 0.0; maps_src[backproj->map_cnt].ee = ee; maps_src[backproj->map_cnt].step = 6; maps_src[backproj->map_cnt].x_map = 0.0; maps_src[backproj->map_cnt].y_map = 0.0; if (src_id[ngrp] > 0) { maps_src[backproj->map_cnt].x_map = xx[ngrp]; maps_src[backproj->map_cnt].y_map = yy[ngrp]; maps_src[backproj->map_cnt-1].x_map = xx[ngrp]; maps_src[backproj->map_cnt-1].y_map = yy[ngrp]; maps_src[backproj->map_cnt-2].x_map = xx[ngrp]; maps_src[backproj->map_cnt-2].y_map = yy[ngrp]; maps_src[backproj->map_cnt-3].x_map = xx[ngrp]; maps_src[backproj->map_cnt-3].y_map = yy[ngrp]; maps_src[backproj->map_cnt-4].x_map = xx[ngrp]; maps_src[backproj->map_cnt-4].y_map = yy[ngrp]; maps_src[backproj->map_cnt-5].x_map = xx[ngrp]; maps_src[backproj->map_cnt-5].y_map = yy[ngrp]; maps_src[backproj->map_cnt-6].x_map = xx[ngrp]; maps_src[backproj->map_cnt-6].y_map = yy[ngrp]; } backproj->map_cnt++; if (backproj->map_cnt > 299) backproj->map_cnt = 299; /* ******************************************************** */ /* */ /* Use new residual image as input for next iteration */ /* */ /* ******************************************************** */ for( i=0; iskydim; i++) current_skyim[i] = skyim[i]; /* ******************************************************** */ /* */ /* Repeat source finding and elimination from shadowgram */ /* */ /* ******************************************************** */ /* QQQQQQ */ backproj->blindspots[backproj->blindnum] = sxy; backproj->blindnum++; /* check for potential ghosts, eliminate these as well. Note: one more instance! NL 2009-12-03 */ if (((sxy + ghoststep[0]) > 0) && ((sxy + ghoststep[0]) < backproj->skydim)) { backproj->blindspots[backproj->blindnum] = sxy + ghoststep[0]; backproj->blindnum++; } if (((sxy + ghoststep[1]) > 0) && ((sxy + ghoststep[1]) < backproj->skydim)) { backproj->blindspots[backproj->blindnum] = sxy + ghoststep[1]; backproj->blindnum++; } goto igen; nextee: /* nextee */ if (logger->trace) traces(func_local, 1000+ee, logger); if (logger->trace) traces(func_local, 2000+backproj->stopcode[ee], logger); *goodnsrc = nsrc; 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 */ if (status != ISDC_OK) RILlogMessage( NULL, Error_0, "##293## Imagefit return, nsrc" "= %d, goodnsrc: %d, goodrms: " "%f", nsrc, *goodnsrc, *goodrms); return( status ); } /* ***************************************************** */ /***************************************************************** * Name of source file: imageprep.c * Version of source file: 4.0.12 * Parent component: None * Programmer: Niels Lund * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325716 FAX: +45 35362475 * nl@spacecenter.dk * Purpose: Perform the first image generation for user defined energy bins * Origin date: 070629 * Update history: 1.0.0 070629 First version * 2.1.0 070809 SCREWs 2021-2023 * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 4.0.12 120919 SPR ?: Introduce corrections by LP and Co. * Type of element: Function * Part of package: j_ima_iros * Name: imageprep * Calls: * Returns: * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ int imageprep( int jemx, int ee3, float xx[SCW_SRCMAX], float yy[SCW_SRCMAX], double solut[SCW_SRCMAX], float *goodrms, double *sh_rms2, int *fitcycles, int *goodnsrc, struct instr_data *jmx_id, struct log_con *logger, struct backpro *backproj, struct backpro_lists *bp, struct shadowgrams *sh, int chatter, int status) { char dumptxt[30]; int i, nsrc = 0, fitcnt, i5; static int icall=0; int baseErr = J_ERROR_CODE_START + J_IMA_IROS_ERR; static float skyim[SKYDIM], shadow[detdim]; float valmin_rms, valmin_const, shadow_counts, pixfold_counts, funval; float testsum = 0.0; /* SPR 4523 2006-08-07/NJW */ double rms; static int func_local = -1, local_calling_num=0; clock_t clock(void), calling_TT, TT_now; if( status != ISDC_OK ) return( status ); /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "imageprep"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ i5 = logger->i5; /* NL 20120122 */ /* printf("At entry to 'imageprep': Address of 'status' (stack pointer): %d\n", (int)(&status)); */ if (logger->trace) traces(func_local, 0, logger); sprintf(logger->tmptxt, "##9257## Calling fun initially"); logger->logstat = logprint(logger, logger->tmptxt, 5); status = FUN(-1, 1, ee3, xx, yy, jemx, 0, &funval, jmx_id, logger, backproj, chatter, status); /* reset fitting functions */ if (status != ISDC_OK ) goto nextee; sprintf(logger->tmptxt, "##9258## Returning from fun"); logger->logstat = logprint(logger, logger->tmptxt, 5); shadow_counts = 0.0; for (i=0; isoft_gr[i] > 0.0) shadow_counts += backproj->shadw[i]; else backproj->effic[i] = 0.0; } /* pixelfold generates a shadowgram "shadow" which is corrected for detector nonlinearities */ if (logger->pix_fold_ctrl == 0) { /* no pixelfold */ for (i=0; ishadw[i]; } if (logger->pix_fold_ctrl > 0) status = pixelfold(backproj->shadw, ee3, shadow, sh->totcnt, logger, backproj, jmx_id); for (i=0; ishadw[i] = shadow[i]; pixfold_counts = 0.0; for (i=0; isoft_gr[i] > 0.0) pixfold_counts += backproj->shadw[i]; } /* ***************************************************************** */ /* */ /* Backproject raw shadowgram to form variance image */ /* */ /* ***************************************************************** */ sprintf(logger->tmptxt, "##9259## Calling backpro8_2 1, shadow_counts: %6.1f, pixfold_counts: %6.1f", shadow_counts, pixfold_counts); logger->logstat = logprint(logger, logger->tmptxt, i5); status = backpro8_2(backproj->shadw, backproj->effic, backproj->fitsimage[ee3][0], backproj->skyeff, logger, backproj, bp); if (status != ISDC_OK) { RILlogMessage( NULL, Error_1, "##9260## after backpro8_2: %d", status); status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_BACKPRODERR; goto nextee; } sprintf(logger->tmptxt, "##9261## Returning from backpro8_2 - yes!"); logger->logstat = logprint(logger, logger->tmptxt, 5); /* * if( chatter > J_CHATTY_MAXIMAL ) { * status = fits_test_output( "backpro8_1_", backproj->fitsimage[ee3][0], 511, logger, chatter, status ); * RILlogMessage( NULL, Log_0, "##9262## Dump of 'variance image'"); * } */ for( i=0; i < backproj->skydim; i++) { if (backproj->fitsimage[ee3][0][i] > 1.0) backproj->fitsimage[ee3][5][i] = 1.0 / sqrt((double)(backproj->fitsimage[ee3][0][i])); else backproj->fitsimage[ee3][5][i] = 1.0; } nsrc = backproj->backmodels; /* ************************************************************ */ /* */ /* Fit shadowgram with background components only */ /* */ /* ************************************************************ */ /* imagefit returns a solution to the fit process in "solut" and a residual shadowgram in "sh->resid" */ sprintf(logger->tmptxt, "##9263## Calling imagefit (A1)"); logger->logstat = logprint(logger, logger->tmptxt, 5); testsum = 0.0; for( i=0; i < detdim; i++) testsum += backproj->shadw[i]; sprintf(logger->tmptxt, "##9372## Before imagefit, shadw testsum = %f", testsum); logger->logstat = logprint(logger, logger->tmptxt, i5); status = shadowfit(backproj->shadw, jemx, ee3, nsrc, xx, yy, solut, 0, &rms, jmx_id, logger, backproj, sh, chatter, status); *goodrms = rms; backproj->solut0_0[ee3] = solut[0]; backproj->solut0_1[ee3] = solut[1]; /* * baseErr+J_IIR_FUNERR1 .. FUNERR8 are legal */ if( status == baseErr+J_IIR_FUNERR1 || status == baseErr+J_IIR_FUNERR2 || status == baseErr+J_IIR_FUNERR3 || status == baseErr+J_IIR_FUNERR4 || status == baseErr+J_IIR_FUNERR5 || status == baseErr+J_IIR_FUNERR6 || status == baseErr+J_IIR_FUNERR7 || status == baseErr+J_IIR_FUNERR8 || status == baseErr+J_IIR_IMFITERR2 || status == baseErr+J_IIR_IMFITERR3 || status == baseErr+J_IIR_IMFITERR4 || status == baseErr+J_IIR_IMFITERR5 || status == baseErr+J_IIR_IMFITERR6 || status == baseErr+J_IIR_IMFITERR7 || status == baseErr+J_IIR_SNGLMTX ) { status = ISDC_OK; sprintf(logger->tmptxt, "##9264## Negative status on return" " from imagefit (2), status: %d", status); logger->logstat = logprint(logger, logger->tmptxt, 5); if (logger->trace) traces(func_local, 7701, logger); goto nextee; } if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##9265## Other error: status = %d", status); if (logger->trace) traces(func_local, 7702, logger); goto nextee; } sprintf(logger->tmptxt, "##9266## Returning from imagefit"); logger->logstat = logprint(logger, logger->tmptxt, 5); fitcnt = 1; *fitcycles = fitcnt; if (rms < 0.0) { status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_BADDATA; goto nextee; /* bad data */ } sprintf(logger->tmptxt, "##999c## E%1d. In imageprep: calling rmscalc with 'sh->resid' after shadowfit", ee3); logger->logstat = logprint(logger, logger->tmptxt, i5); *sh_rms2 = rmscalc(sh->resid, backproj->soft_gr, logger); sprintf(logger->tmptxt, "##9267## Returning from rmscalc"); logger->logstat = logprint(logger, logger->tmptxt, 5); valmin_const = fabs(solut[0]); valmin_rms = rms; sprintf(logger->tmptxt, "##9266a# E%1d backgr.fitpwr: %6.2f %6.2f, rms: %6.2f", ee3, solut[0], solut[1], rms); logger->logstat = logprint(logger, logger->tmptxt, i5); /* ******************************************************** */ /* */ /* Backproject residual shadowgram to form sky image */ /* */ /* ******************************************************** */ sprintf(logger->tmptxt, "##9268## Calling backpro8_d 2"); logger->logstat = logprint(logger, logger->tmptxt, 5); testsum = 0.0; for( i=0; i < detdim; i++) testsum += sh->resid[i]; sprintf(logger->tmptxt, "##9372## Before backpro8_d, resid testsum = %f", testsum); logger->logstat = logprint(logger, logger->tmptxt, i5); status = backpro8_d(sh->resid, backproj->skyim_r, logger, backproj, bp); if (status != ISDC_OK) { RILlogMessage( NULL, Error_1, "##9269## after backpro8_d: %d", status); status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_BACKPRODERR; goto nextee; } sprintf(logger->tmptxt, "##9270## Returning from backpro8_d 2"); logger->logstat = logprint(logger, logger->tmptxt, 5); testsum = 0.0; for (i=0; iskydim; i++) { backproj->fitsimage[ee3][1][i] = backproj->skyim_r[i]; testsum += backproj->skyim_r[i]; } sprintf(logger->tmptxt, "##9272## Calling clean0, skyim_r testsum = %f", testsum); logger->logstat = logprint(logger, logger->tmptxt, i5); for (i=0; iresid1[i] = sh->resid[i]; /* logger->resid1[detdim] contains the residual shadowgram after removal of background components */ /* status = fits_test_output( "raw_skyim_", backproj->skyim_r, 511, logger, chatter, status ); */ for (i=0; iskydim; i++) { backproj->access[i] = 0; if (backproj->illumx[i] >= (int)(backproj->signiflim)) backproj->access[i] = 1; } testsum = 0.0; for( i=0; i < backproj->skydim; i++) testsum += backproj->skyim_r[i]; sprintf(logger->tmptxt, "##9372## Before clean0, skyim_r testsum = %f", testsum); logger->logstat = logprint(logger, logger->tmptxt, i5); status = clean0(backproj->skyim_r, skyim, ee3, logger, backproj, chatter, status ); /* remove large scale structures in skyimage */ if( status != ISDC_OK ) { RILlogMessage( NULL, Warning_0, "##9273## clean0 returned: %d, status reset!", status); sprintf(logger->tmptxt, "##9273## clean0 returned: %d, status reset!", status); logger->logstat = logprint(logger, logger->tmptxt, i5); status = ISDC_OK; } /* status = fits_test_output( "clean_skyim_", skyim, 511, logger, chatter, status ); */ sprintf(logger->tmptxt, "##9474## Returning from clean0"); logger->logstat = logprint(logger, logger->tmptxt, 5); /* after first fit output background cleaned map */ testsum = 0.0; for( i=0; i < backproj->skydim; i++) { backproj->fitsimage[ee3][2][i] = skyim[i]; backproj->fitsimage[ee3][3][i] = skyim[i]; backproj->fitsimage[ee3][4][i] = skyim[i]; testsum += backproj->fitsimage[ee3][2][i]; } /* backproj->fitsimage[ee3][2][SKYDIM] contains the first cleaned backprojected sky_image */ sprintf(logger->tmptxt, "##9572## After clean0, ee3: %1d, fitsimage[3][2] testsum = %f", ee3, testsum); logger->logstat = logprint(logger, logger->tmptxt, i5); /* ******************************************************** */ nextee: /* nextee */ *goodnsrc = nsrc; 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 */ if (status != ISDC_OK) RILlogMessage( NULL, Error_0, "##293## Imagefit return, nsrc" "= %d, goodnsrc: %d, goodrms: " "%f", nsrc, *goodnsrc, *goodrms); return( status ); } /***************************************************************** * Name of source file: backpro8_2.c * Version of source file: 3.2.7 * Programmer: Niels Lund & Niels J. Westergaard * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325705 FAX: +45 35362475 * njw@space.dtu.dk * Purpose: Initiate the backprojection and source * finding processes * Origin date: 041122 * Update history: 1.0.0 041130 First version * 1.6.3 060915 An exposure (vignetting) map is now a product * 1.6.4 060928 Included test for zero divisor in peaktransfer.c * 1.6.5 061002 New defaults for par. skyImagesOut * 1.7.0 061110 Produces images with few or zero events (SPR 4594) * 1.7.1 061114 SPR 4603 Image unit (BUNIT) is now cts/dm2/s * 2.1.0 070809 SCREWS 2021-2023 * 2.1.0 070809 SCREWs 2021-2023 * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.1.6 071125 Modified to backproject efficiency shadowgram in parallel with counts shadowgram * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 3.2.7 100224 SPR 4915: Fixing logics for sparse shadowgrams * Type of element: Function * Part of package: j_ima_iros * Name: backpro8_2 * Returns: * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ int backpro8_2(float shdgr[detdim],float eff[detdim], float sky[SKYDIM], double sky_eff[SKYDIM], struct log_con *logger, struct backpro *backproj, struct backpro_lists *bp) /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* */ /* subroutine to backproject a JEM-X shadowgram as provided in shdgr[detdim] */ /* */ /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ { int det_index, length=0, sky_index, i; int list_index; int numlists, looplim, ix, M, mod, mm, pixlen, iii, status; unsigned char *b_bot; float shdgr_val, shdgr_sum, shdgr_abs, eff_val, fx, fy, FOV2; 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], "backpro8_2"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ if (logger->trace) traces(func_local, 1, logger); for (i=0; iskydim; i++) sky[i] = 0.0; for (i=0; isoft_gr[i] <= 0.0) shdgr[i] = 0.0; FOV2 = (float)(backproj->FOV_radius * backproj->FOV_radius) * logger->sky_rad_lim * logger->sky_rad_lim; shdgr_sum = shdgr_abs = 0.0; for (i=0; itmptxt, "##218## Shadowgram sum: %8.3e, abs. sum: %8.1f", shdgr_sum, shdgr_abs); logger->logstat = logprint(logger, logger->tmptxt, 5); iii = 0; M = detdim * 256; /* loop limit */ mod = detdim - 1; /* modulo parameter */ for (mm=256; mmd_allow_l' */ iii++; shdgr_val = shdgr[det_index]; eff_val = eff[det_index]; if (eff_val <= 0) continue; /* == changed to <= ! 25042008 Niels Lund */ eff_val += 12500.0; /* add dummy value to allow backprojection of 'illumination' together with efficiency */ pixlen = (int)bp->d_allow_l[det_index]; if (pixlen == 0) continue; if (pixlen == 1) { sky_index = bp->o_allow_p[bp->o_allow_subl[det_index]]; sky[sky_index] += shdgr_val; continue; } looplim = det_index; if (det_index < detdim-257) { numlists = bp->o_allow_subl[(det_index+256)%mod] - bp->o_allow_subl[det_index]; } else { numlists = 0; } b_bot = bp->d_allow + bp->o_allow_st[det_index]; for (list_index=0; list_indexo_allow_p[bp->o_allow_subl[det_index] + list_index]; length = bp->o_allow_len[bp->o_allow_subl[det_index] + list_index]; while (length > 100) { length -= 100; sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); } switch (length) { case 100: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 99: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 98: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 97: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 96: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 95: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 94: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 93: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 92: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 91: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 90: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 89: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 88: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 87: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 86: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 85: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 84: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 83: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 82: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 81: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 80: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 79: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 78: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 77: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 76: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 75: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 74: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 73: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 72: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 71: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 70: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 69: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 68: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 67: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 66: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 65: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 64: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 63: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 62: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 61: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 60: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 59: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 58: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 57: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 56: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 55: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 54: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 53: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 52: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 51: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 50: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 49: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 48: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 47: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 46: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 45: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 44: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 43: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 42: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 41: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 40: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 39: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 38: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 37: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 36: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 35: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 34: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 33: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 32: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 31: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 30: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 29: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 28: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 27: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 26: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 25: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 24: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 23: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 22: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 21: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 20: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 19: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 18: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 17: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 16: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 15: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 14: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 13: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 12: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 11: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 10: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 9: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 8: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 7: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 6: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 5: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 4: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 3: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 2: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 1: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; sky_index += (int)(*b_bot++); case 0: sky[sky_index] += shdgr_val; sky_eff[sky_index] += eff_val; break; default: sprintf(logger->tmptxt, "backpro8_2: switch default take for det_index: %6d length: %5d, sky_index: %7d", det_index, length, sky_index); logger->logstat = logprint(logger, logger->tmptxt, 7); status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_BACKPRO_BAD_DEFAULT; goto exittrace; break; } } } /* remove dummy points outside the edges of the sky image */ for (sky_index=0; sky_indexskydim; sky_index++) { ix = sky_index / backproj->sky_ydim; backproj->illumx[sky_index] = (int)(sky_eff[sky_index] / 12500.0); /* new illumination image */ sky_eff[sky_index] = sky_eff[sky_index] - (float)(backproj->illumx[sky_index]) * 12500.0; /* new effective illumination image */ if ((bp->ixy_lim[ix][0] >= sky_index) || (bp->ixy_lim[ix][1] <= sky_index)) { sky[sky_index] = 0.0; sky_eff[sky_index] = 0.0001; backproj->illumx[sky_index] = 0; } if (sky_eff[sky_index] <= 0.0) sky_eff[sky_index] = 0.0001; backproj->access[sky_index] = 0; if (backproj->illumx[sky_index] >= backproj->signiflim) backproj->access[sky_index] = 1; fx = (float)(sky_index / backproj->sky_ydim) - (float)(backproj->FOV_radius); fy = (float)(sky_index % backproj->sky_ydim) - (float)(backproj->FOV_radius); if ((fx*fx + fy*fy) > FOV2) { backproj->access[sky_index] = 0; backproj->illumx[sky_index] = 0; } } status = 0; exittrace: 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); } /* ************************************************************************** */ /***************************************************************** * Name of source file: backpro8_W.c * Version of source file: 1.0 * Programmer: Niels Lund * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325716 FAX: +45 35362475 * nl@space.dtu.dk * Purpose: Backproject shadowgram and weight function½ * * Origin date: 20110509 * Update history: 1.0 20110509 First version * Type of element: Function * Part of package: j_ima_iros * Name: backpro8_W * Returns: * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ int backpro8_W( float shdgr[detdim], float eff[detdim], float weight[detdim], float SHraw[detdim], float SH1st[detdim], float sky[SKYDIM], float sky_eff[SKYDIM], float svar[SKYDIM], float sky1[SKYDIM], struct log_con *logger, struct backpro *backproj, struct backpro_lists *bp) /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* */ /* subroutine to backproject a JEM-X shadowgram as provided in shdgr[detdim] */ /* */ /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ { int det_index, length=0, SX, i; int list_index; int numlists, looplim, ix, M, mod, mm, pixlen, iii, status; unsigned char *b_bot; float shdgr_val, shdgr_sum, shdgr_abs, eff_val, fx, fy, FOV2; float s1_val, sv_val; 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], "backpro8_W"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ if (logger->trace) traces(func_local, 1, logger); for (i=0; iskydim; i++) sky[i] = sky1[i] = svar[i] = sky_eff[i] = 0.0; /* Corrected 28/12 2011. Niels Lund */ for (i=0; isoft_gr[i] <= 0.0) shdgr[i] = 0.0; FOV2 = (float)(backproj->FOV_radius * backproj->FOV_radius) * logger->sky_rad_lim * logger->sky_rad_lim; shdgr_sum = shdgr_abs = 0.0; for (i=0; itmptxt, "##218## Shadowgram sum: %8.3e, abs. sum: %8.1f", shdgr_sum, shdgr_abs); logger->logstat = logprint(logger, logger->tmptxt, 5); iii = 0; M = detdim * 256; /* loop limit */ mod = detdim - 1; /* modulo parameter */ for (mm=256; mmd_allow_l' */ iii++; shdgr_val = shdgr[det_index] * weight[det_index]; s1_val = SH1st[det_index] * weight[det_index]; sv_val = SHraw[det_index] * weight[det_index] * weight[det_index]; eff_val = eff[det_index] * weight[det_index]; if (eff_val <= 0) continue; /* == changed to <= ! 25042008 Niels Lund */ pixlen = (int)bp->d_allow_l[det_index]; if (pixlen == 0) continue; if (pixlen == 1) { SX = bp->o_allow_p[bp->o_allow_subl[det_index]]; sky[SX] += shdgr_val; sky1[SX] += s1_val; /* Corrected 28/12 2011. Niels Lund */ svar[SX] += sv_val; /* Corrected 28/12 2011. Niels Lund */ sky_eff[SX] += eff_val; continue; } looplim = det_index; if (det_index < detdim-257) { numlists = bp->o_allow_subl[(det_index+256)%mod] - bp->o_allow_subl[det_index]; } else { numlists = 0; } b_bot = bp->d_allow + bp->o_allow_st[det_index]; for (list_index=0; list_indexo_allow_p[bp->o_allow_subl[det_index] + list_index]; length = bp->o_allow_len[bp->o_allow_subl[det_index] + list_index]; while (length > 100) { length -= 100; sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); } switch (length) { case 100: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 99: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 98: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 97: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 96: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 95: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 94: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 93: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 92: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 91: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 90: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 89: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 88: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 87: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 86: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 85: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 84: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 83: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 82: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 81: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 80: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 79: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 78: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 77: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 76: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 75: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 74: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 73: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 72: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 71: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 70: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 69: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 68: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 67: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 66: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 65: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 64: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 63: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 62: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 61: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 60: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 59: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 58: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 57: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 56: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 55: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 54: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 53: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 52: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 51: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 50: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 49: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 48: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 47: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 46: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 45: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 44: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 43: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 42: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 41: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 40: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 39: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 38: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 37: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 36: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 35: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 34: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 33: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 32: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 31: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 30: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 29: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 28: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 27: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 26: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 25: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 24: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 23: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 22: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 21: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 20: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 19: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 18: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 17: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 16: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 15: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 14: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 13: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 12: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 11: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 10: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 9: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 8: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 7: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 6: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 5: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 4: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 3: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 2: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 1: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; SX += (int)(*b_bot++); case 0: sky[SX] += shdgr_val; sky1[SX] += s1_val; svar[SX] += sv_val; sky_eff[SX] += eff_val; break; default: sprintf(logger->tmptxt, "backpro8_W: switch default take for det_index: %6d length: %5d, SX: %7d", det_index, length, SX); logger->logstat = logprint(logger, logger->tmptxt, 7); status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_BACKPRO_BAD_DEFAULT; goto exittrace; break; } } } /* remove dummy points outside the edges of the sky image */ for (SX=0; SXskydim; SX++) { ix = SX / backproj->sky_ydim; if ((bp->ixy_lim[ix][0] >= SX) || (bp->ixy_lim[ix][1] <= SX)) { sky[SX] = svar[SX] = sky1[SX] = 0.0; /* Corrected 28/12 2011. Niels Lund */ sky_eff[SX] = 0.0001; } if (sky_eff[SX] <= 0.0) sky_eff[SX] = 0.0001; fx = (float)(SX / backproj->sky_ydim) - (float)(backproj->FOV_radius); fy = (float)(SX % backproj->sky_ydim) - (float)(backproj->FOV_radius); if ((fx*fx + fy*fy) > FOV2) { backproj->illumx[SX] = 0; } } status = 0; exittrace: 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); } /* ************************************************************************** */ /***************************************************************** * Name of source file: j_iir_get_shds.c * Version of source file: 3.2.6 * Parent component: j_ima_iros * Programmer: Niels J. Westergaard & Niels Lund * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325700 FAX: +45 35362475 * njw@spacecenter.dk, nl@spacecenter.dk * Purpose: Read the shadowgrams from a science window * Origin date: 041217 * Update history: 1.0.0 041217 First version * 1.0.4 050126 Test version for undue crash * 1.1.0 050131 Now reading FITS sky/backproj files * 1.1.1 050211 Keywords adapted to needs of j_ima_mosaic * 1.1.2 050303 Extra keyw:RLIMIDX, new cleaning * 1.1.3 050307 New DMAP: 51 radii * 1.1.4 050407 New clean, etc. * 1.1.4 050407 New clean, etc. * 1.1.5 050415 New clean again, updated flux determination * 1.1.6 050418 Now uses JMXi-DBKG-MOD as default for empty field shds * 1.2.0 050425 Deals with SPR 4102,4108 and reduces RAM requirement * 1.3.0 050503 Deals with SPR 4120 and copes with up to 6 shadowgrams * 1.3.1 050517 Deals with SPR 4143 and initializes ima_sigma properly * 1.3.2 050519 Closes SPR 4157 - bad size of three arrays * 1.3.3 050602 Changes some arrays to static (SPR 4202) * 1.4.0 050620 Include user defined sources (SCREW 1740) * 1.5.1 051129 Separating functions to jmx_lib_pif * 1.5.2 051202 Separating functions to jmx_lib_pif (2) * 1.5.3 051202 Give offX, x2x values in mm in IMOD-GRP * 1.5.4 060104 Bug in sh_depth corrected, detectmap now in mm * 1.5.5 060106 Introduced one more digit in logfile for src position * 1.5.6 060228 Removed parameter detMapFile and some obsolete variables * 1.5.7 060606 Shifted detCondMap to struct jmx_id and status_map * 1.5.8 060807 SPR 04551 Bad assignment of RLIMIDX corrected * 1.5.9 060807 SPR 04533 Resetting status variable has been removed * 1.5.10 060807 SPR 04523 Declaring testsum as float iso. int * 1.5.11 060807 SPR 04458 A warning log line has been added * 1.5.12 060907 SPR 04301 A relative VIGNDOL path is given * 1.6.0 060911 SCREW 1918 Image correction map and parameters introduced * 1.6.1 060912 SPR 4441 Shadowgrams with too few counts are excluded * 1.6.2 060915 SCREW 1842 A significance map can now be obtained * 1.6.3 060915 An exposure (vignetting) map is now a product * 1.6.4 060928 Included test for zero divisor in peaktransfer.c * 1.6.5 061002 New defaults for par. skyImagesOut * 1.7.0 061110 Produces images with few or zero events (SPR 4594) * 1.7.1 061114 SPR 4603 Image unit (BUNIT) is now cts/dm2/s * 1.8.0 061213 SPR 4640 Error in findpeak has been corrected * 1.8.1 070123 SPR 4590 int changed to long for 64 bit code * 2.1.0 070809 SCREWs 2021-2023 * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * Type of element: Executable * Part of package: j_ima_iros * Name: j_iir_get_shds * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ int j_iir_get_shds( dal_element *theSWG, /* Pointer to input SWG */ Instrument jemxNum, /* Number of JEMX unit */ struct shadowgrams *sh, /* All shadowgram information */ userbin *USERBIN, /* shadowgram structure */ struct log_con *logger, /* log control parameters */ int chatter, /* Level of debugging output */ int status) /* Status flag */ { /* Ordinary variables */ char evtsshdName[DS_NAME_SIZE]; /* to hold "JMXi-EVTS-SHD" */ char shadidxName[DS_NAME_SIZE]; /* to hold "JMXi-EVTS-SHD-IDX" */ char strSelection[100]; /* row selection string */ char strLong[20]; /* temporary string */ char strjemxNum[5]; char shdType[J_IIR_MAX_NUM_MEM]; int i = 0; /* short loop variables */ int numAxes = 0; int numMembersShad = 0; int iShad = 0; int nRaw = 0; /* number of raw shadowgrams */ int NumFound = 0; int shdIdenShad[J_IIR_MAX_NUM_MEM]; long loop = 0; long startValues[2]={0,0}; long endValues[2]={0,0}; long numValues = 0; long axes[DAL_MAX_ARRAY_DIMENSION]; long ltmp = 0; float numberOfCounts = 0.0; float maxShadowgram = 0.0; float minShadowgram = 0.0; double exposure = 1.0; double dtmp = 0.0; /* DAL, RIL, PIL, COMMON declarations */ dal_element *shgramPtr = NULL; /* Shadowgram Pointer */ dal_element *ptrIdxTabShg = NULL; /* Shadowgram Index Table Pointer */ dal_dataType DALtype; /* End of DAL etc. declarations */ static int func_local = -1, local_calling_num=0; clock_t calling_TT, TT_now; /* Immediate return if called while executable is in error condition */ if( status != ISDC_OK ) return(status); /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "j_iir_get_shds"); if (logger->func_used_num > J_IIR_MAX_NUM_FUNCS) { sprintf(logger->tmptxt, "func_used_num > %d", J_IIR_MAX_NUM_FUNCS); logger->logstat = logprint(logger, logger->tmptxt, 6); logger->func_used_num = J_IIR_MAX_NUM_FUNCS; } } 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); /* * * Define certain names * */ if( jemxNum == JMX1 ) { strcpy( strjemxNum, "JMX1" ); } else { strcpy( strjemxNum, "JMX2" ); } strcpy( evtsshdName, strjemxNum ); strcpy( shadidxName, strjemxNum ); strcat( evtsshdName, J_EVTSSHD_DS ); strcat( shadidxName, J_EVTSSHD_DS ); strcat( shadidxName, "-IDX" ); /* * Initialize number of obtained shadowgrams */ sh->numShds = 0; /* * * Get pointer to shadowgram index table * */ status = DALobjectFindElement( theSWG, shadidxName, &ptrIdxTabShg, status); if( status != ISDC_OK ) goto exittrace; if( chatter > J_CHATTY_VERY_VERBOSE ) { RILlogMessage(NULL, Log_0, "##152## Got pointer to shadowgram index table"); } /* * * Get number of shadowgrams in input index (EVTS-SHD-IDX) table * */ status = DAL3GENindexGetNumMembers( theSWG, evtsshdName, &numMembersShad, status); if( status != ISDC_OK ) goto exittrace; if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage(NULL, Log_0, "##153## numMembersShad = %d", numMembersShad); } /* * If there are no shadowgrams then no action is required */ if( numMembersShad == 0 ) { if( chatter > J_CHATTY_QUIET ) RILlogMessage(NULL, Log_0, "##154## No shadowgrams in EVTS-SHD-IDX"); goto exittrace; } /* * * Get shadowgram identifiers and types * */ if( chatter > J_CHATTY_VERY_VERBOSE ) { RILlogMessage(NULL, Log_0, "##155## Going to get shg index row identifiers"); } DALtype = DAL_INT; status = DALtableGetCol(ptrIdxTabShg, "SHDIDEN", 0, &DALtype, &numValues, shdIdenShad, status); if( status != ISDC_OK ) goto exittrace; DALtype = DAL_BYTE; status = DALtableGetCol(ptrIdxTabShg, "SHDTYPE", 0, &DALtype, &numValues, shdType, status); if( status != ISDC_OK ) goto exittrace; /* * Check for consistency */ if( (int) numValues != numMembersShad ) { status = J_ERROR_CODE_START + J_IMA_IROS_ERR + J_IIR_MEMB_WRONG_NUM; goto exittrace; } /* * Get the number of raw shadowgrams */ nRaw = 0; for( i = 0; i < numMembersShad; i++ ) { if( shdType[i] == J_IIR_RAW_SHD ) nRaw++; } if( nRaw == 0 ) { if( chatter > J_CHATTY_QUIET ) RILlogMessage(NULL, Log_0, "##156## No valid shadowgrams found in EVTS-SHD-IDX"); goto exittrace; } /* * * LOOP over all shadowgrams * */ for( iShad = 0; iShad < numMembersShad; iShad++) { /* If shadowgram type is not raw - then skip */ if( shdType[iShad] != J_IIR_RAW_SHD ) continue; /* * Compose selection string */ status = initUSER(sh->numShds, USERBIN, logger, status); strcpy(strSelection, "(SHDIDEN==" ); sprintf( strLong,"%d)", shdIdenShad[iShad] ); strcat(strSelection, strLong ); if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage(NULL, Log_0, "##157## Selection string: %s", strSelection); } if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage(NULL, Log_0, "##158## Find Member with DS Name: %s", evtsshdName); } status = DAL3GENindexFindMember( theSWG, evtsshdName, strSelection, &NumFound, &shgramPtr, status); if( status != ISDC_OK ) goto exittrace; if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage(NULL, Log_0, "##159## %d members found", NumFound); } if( NumFound != 1 ) { status = J_ERROR_CODE_START + J_IMA_IROS_ERR + J_IIR_SHDIDEN_ERROR; goto exittrace; } /* save pointer to use for copying of keywords in outfit_isdc */ sh->ptr[sh->numShds] = shgramPtr; /* Get array with shadowgram 1) get the structure */ status = DALarrayGetStruct( shgramPtr, &DALtype, &numAxes, axes, status); if( status != ISDC_OK ) goto exittrace; if( chatter > J_CHATTY_NORMAL ) { RILlogMessage(NULL, Log_0, "##160## shdg numAxes = %d", numAxes); RILlogMessage(NULL, Log_0, "##161## shdg axes[0] = %ld", axes[0]); RILlogMessage(NULL, Log_0, "##162## shdg axes[1] = %ld", axes[1]); } /* Get array with shadowgram 2) use info to read array */ startValues[0] = 1; startValues[1] = 1; endValues[0] = J_IIR_DIM_STDSHDG; endValues[1] = J_IIR_DIM_STDSHDG; if( chatter > J_CHATTY_NORMAL ) { RILlogMessage( NULL, Log_0, "##163## Going to get image section"); } DALtype = DAL_DT_UNKNOWN; status = DALarrayGetSection( shgramPtr, numAxes, startValues, /* endValues, &DALtype, &numValues, USERBIN[sh->numShds].f_shadgram, status); */ endValues, &DALtype, &numValues, sh->f_shadgram[sh->numShds], status); if( status != ISDC_OK ) goto exittrace; status = DALattributeGetReal( shgramPtr, "E_MIN", &sh->eval[sh->numShds][0], NULL, NULL, status); status = DALattributeGetReal( shgramPtr, "E_MAX", &sh->eval[sh->numShds][1], NULL, NULL, status); status = DALattributeGetReal( shgramPtr, "EXPOSURE", &exposure, NULL, NULL, status); if( (float)(exposure) == 0.0) { RILlogMessage( NULL, Log_0, "##165## exposure = %f, set to 1.0 s", (float)(exposure)); exposure = 1.0; } sh->accumT = (float) exposure; status = DALattributeGetReal( shgramPtr, "AVG_GAIN", &dtmp, NULL, NULL, status); sh->avg_gain = (float)(dtmp); /* USERBIN[sh->numShds].avg_gain = (float) dtmp; * if (USERBIN[sh->numShds].avg_gain < 5.0) { * sprintf(logger->tmptxt, "##5768## USERBIN[%2d].avg_gain: %f, not accetable!", * sh->numShds, USERBIN[sh->numShds].avg_gain); * logger->logstat = logprint(logger, logger->tmptxt, 0); * status = -1; * } * status = DALattributeGetReal( shgramPtr, "EEFF_COR", * &dtmp, NULL, NULL, status); * USERBIN[sh->numShds].eeff_cor = (float) dtmp; * status = DALattributeGetReal( shgramPtr, "RADLIMIT", * &dtmp, NULL, NULL, status); * USERBIN[sh->numShds].radlimit = (float) dtmp; */ status = DALattributeGetInt( shgramPtr, "CHANMIN", <mp, NULL, NULL, status); sh->pival[sh->numShds][0] = (int) ltmp; status = DALattributeGetInt( shgramPtr, "CHANMAX", <mp, NULL, NULL, status); sh->pival[sh->numShds][1] = (int) ltmp; if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##164## status = %d", status ); goto exittrace; } maxShadowgram = sh->f_shadgram[sh->numShds][0]; minShadowgram = sh->f_shadgram[sh->numShds][0]; numberOfCounts = 0.0; for( loop = 0L; loop < J_IIR_SIZE_STDSHDG; loop++ ) { if( sh->f_shadgram[sh->numShds][loop] > maxShadowgram ) { maxShadowgram = sh->f_shadgram[sh->numShds][loop]; } if( sh->f_shadgram[sh->numShds][loop] < minShadowgram ) { minShadowgram = sh->f_shadgram[sh->numShds][loop]; } numberOfCounts += sh->f_shadgram[sh->numShds][loop]; } if( chatter > J_CHATTY_NORMAL ) { RILlogMessage( NULL, Log_0, "##166## min/max in shadowgram: %f/%f", minShadowgram, maxShadowgram); } if( chatter > J_CHATTY_NORMAL ) { RILlogMessage( NULL, Log_0, "##167## No of cts in shdg : %f", numberOfCounts); } if( numberOfCounts < J_IIR_MINNUMCTSSHD ) { /* * SPR-04441 fix: Don't include shadowgrams with too few counts * [2006-09-12/NJW] */ RILlogMessage( NULL, Warning_0,"##168## Too few counts in shadowgram - skip"); } else { /* * Transpose the shadowgram to match the original * and expected orientation */ transpose_f( sh->f_shadgram[sh->numShds], J_IIR_DIM_STDSHDG ); if (logger->trace) traces(func_local, 1000+sh->numShds, logger); sh->numShds++; } } /* Terminate loop over input shadowgrams */ exittrace: 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 ); } /***************************************************************** * Name of source file: j_iir_bin_search.c * Version of source file: 0.3.0 * Parent component: j_ima_iros * Programmer: Niels J. Westergaard * Affiliation: National Space Institute/DTU * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325705 FAX: +45 35362475 * njw@space.dtu.dk * Purpose: Binary search in 1D array * Origin date: 060626 * Update history: 1.1.6 060626 * 0.3.0 060830 Electronic efficiency included * Type of element: Function *****************************************************************/ int j_iir_bin_search( long n, /* Number of elements in array */ double *xv, /* Array with x values */ double x, /* x value for which function value is wanted */ long *index, /* Result of interpolation */ int status) /* Fault condition flag */ { long i, i1, i2; static long i_previous = 0; if( status != ISDC_OK ) return(status); /* * First test previous value */ if( i_previous+1 < n ) { *index = i_previous; if( x >= xv[i_previous] && x < xv[i_previous+1] ) return status; } /* * If x value is outside range given by 'xv' then the * either 0 or n-1 is returned */ *index = 0; if( x <= xv[0] ) return( status ); *index = n-1; if( x >= xv[n-1] ) return( status ); /* Inside the range a binary search is used */ i1 = 0L; i2 = n - 1; do { i = (i1 + i2 ) / 2; if( x >= xv[i] ) { i1 = i; } else { i2 = i; } } while( i2 - i1 > 1 ); *index = i_previous = i1; return( status ); } /***************************************************************** /***************************************************************** * Name of source file: getNumShds.c * Version of source file: 3.2.7 * Parent component: j_ima_iros * Programmer: Niels J. Westergaard & Niels Lund * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325700 FAX: +45 35362475 * njw@spacecenter.dk, nl@spacecenter.dk * Purpose: Read the shadowgrams from a science window * Origin date: 070627 * Update history: 2.0.0 070627 First version * 2.1.0 070809 SCREWs 2021-2023 * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 3.2.7 100224 SPR 4915: Fixing logics for sparse shadowgrams * Type of element: Executable * Part of package: j_ima_iros * Name: getNumShds.c * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ int getNumShds( dal_element *theSWG, /* Pointer to input SWG */ Instrument jemxNum, /* Number of JEMX unit */ struct shadowgrams *sh, /* All shadowgram information */ struct log_con *logger, /* log control parameters */ int chatter, /* Level of debugging output */ int status) /* Status flag */ { /* Ordinary variables */ char evtsshdName[DS_NAME_SIZE]; /* to hold "JMXi-EVTS-SHD" */ char shadidxName[DS_NAME_SIZE]; /* to hold "JMXi-EVTS-SHD-IDX" */ /* char strSelection[100]; */ /* row selection string */ /* char strLong[20]; */ /* temporary string */ char strjemxNum[5]; int numMembersShad = 0; /* DAL, RIL, PIL, COMMON declarations */ dal_element *ptrIdxTabShg = NULL; /* Shadowgram Index Table Pointer */ /* End of DAL etc. declarations */ static int func_local = -1, local_calling_num=0; clock_t calling_TT, TT_now; /* Immediate return if called while executable is in error condition */ if( status != ISDC_OK ) return(status); /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "getNumShds"); if (logger->func_used_num > J_IIR_MAX_NUM_FUNCS) { sprintf(logger->tmptxt, "func_used_num > %d", J_IIR_MAX_NUM_FUNCS); logger->logstat = logprint(logger, logger->tmptxt, 6); logger->func_used_num = J_IIR_MAX_NUM_FUNCS; } } 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); /* * * Define certain names * */ if( jemxNum == JMX1 ) { strcpy( strjemxNum, "JMX1" ); } else { strcpy( strjemxNum, "JMX2" ); } strcpy( evtsshdName, strjemxNum ); strcpy( shadidxName, strjemxNum ); strcat( evtsshdName, J_EVTSSHD_DS ); strcat( shadidxName, J_EVTSSHD_DS ); strcat( shadidxName, "-IDX" ); /* * * Get pointer to shadowgram index table * */ status = DALobjectFindElement( theSWG, shadidxName, &ptrIdxTabShg, status); if( status != ISDC_OK ) goto exittrace; if( chatter > J_CHATTY_VERY_VERBOSE ) { RILlogMessage(NULL, Log_0, "##152## Got pointer to shadowgram index table"); } /* * * Get number of shadowgrams in input index (EVTS-SHD-IDX) table * */ status = DAL3GENindexGetNumMembers( theSWG, evtsshdName, &numMembersShad, status); if( status != ISDC_OK ) goto exittrace; if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage(NULL, Log_0, "##153## numMembersShad = %d", numMembersShad); } /* * Initialize number of obtained shadowgrams */ sh->numShds = numMembersShad; /* printf("getNumShds: %d, sh->numShds: %d\n", numMembersShad, sh->numShds); */ exittrace: if (logger->trace) traces(func_local, 1000+numMembersShad, logger); 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((int)(numMembersShad)); } /************************************************************************** * * Name of source file: j_iir_get_events. c * Name of Function: j_iir_get_events * Version of source file: 4.0.12 * Parent component: j_ima_iros * Programmer: Niels J. Westergaard * Affiliation: National Space Institute/DTU * Contact address: DTU Space * Dep. of Astrophysics * Juliane Maries Vej 30 * DK 2100 Copenhagen O * njw@space.dtu.dk * Date: 2009-08-27 * Purpose: Get the events and related information from * the ScW * Update history: * 0.3.0 090827 First version * 3.2.7 100308 Expects Auxdata information * 4.0.12 120919 SPR ?: Introduce corrections by LP and Co. * *****************************************************************************/ int j_iir_get_events( dal_element *theSWG, /* Pointer to input SWG */ Instrument jemxNum, /* JEMX unit number */ Events **bufevents, /* Pointer to struct with event information */ long *numEvents, /* Number of events */ struct scwlist *SCWnow, /* Various ScW information */ Auxdata *auxdata, /* such as gain, GTI, and grey filter */ struct log_con *logger, int tAccuracy, /* Time Corr. Accuracy */ char *rowSelect, /* CFITSIO selection string */ int chatter, /* Level of debugging output */ int status) /* Status flag */ { unsigned char *byteBuffer=NULL; char rowFilter[DAL_BIG_STRING]; unsigned short *ushortBuffer = NULL; short *rawx = NULL; short *rawy = NULL; int itmp = 0; long i = 0; long m = 0; long bufferSize = 0; long nOBTs = 0; long nBytes = 0; long nEvents = 0; /* Number of FULL + REST events selected */ long nFullEvents = 0; /* Number of FULL events selected */ long nRestEvents = 0; /* Number of REST events selected */ long indexd = 0; /* Used in binary search for deadTime */ long indexg = 0; /* Used in binary search for grey filter */ long indexgn = 0; /* Used in binary search for gain */ float greyCorr = 0.0; float deadCorr = 0.0; double *timeIJD = NULL; double time_val = 0.0; Events *all_events = NULL; Events *full_events = NULL; dal_dataType dataType; OBTime *obtBuffer = NULL; OBTime *fullEventOBT = NULL; OBTime *allEventOBT = NULL; TCOR_flag Accuracy; static int func_local = -1, local_calling_num=0; clock_t calling_TT, TT_now; /* * Immediate return if called while executable is in error condition */ if( status != ISDC_OK ) return status ; /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "j_iir_get_events"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; if (logger->trace) traces(func_local, 0, logger); logger->func_calling_num = func_local; logger->func_times[local_calling_num] += TT_now - calling_TT; /* function entry timing end */ /* * Setting the Accuracy variable for later use */ if(tAccuracy == 0) { Accuracy = TCOR_ACCURATE; } else if(tAccuracy == 1) { Accuracy = TCOR_INACCURATE; } else if(tAccuracy == 3) { Accuracy = TCOR_ANY; } else{ status = J_IIR_INVALID_PAR; RILlogMessage(NULL, Error_2, "##93## Invalid time corr accuracy value = %d ", tAccuracy ); return status ; } /****************READING FULL EVENT DATA*************************************/ /* * Compose selection string */ if(strlen(rowSelect)>0) { strcpy(rowFilter , rowSelect); } else { /* * strcpy(rowFilter, "(STATUS==0)" ); */ strcpy(rowFilter, "(STATUS==123 || STATUS==0 )" ); /* For sim data!!*/ } if( chatter >= J_CHATTY_NORMAL ) { RILlogMessage(NULL,Log_0, "##176## Event selection rowFilter string: %s",rowFilter); RILlogMessage(NULL,Log_0, "##1761## SCWnow->evtType: %d", (int) SCWnow->evtType); } /* * Only call this section if FULL events have been selected */ if( SCWnow->evtType == 0 || SCWnow->evtType == -1 ) { /* * Select the FULL events * [Previously the selection was 'COR' 2006-05-16/NJW] */ status = DAL3JEMXselectEvents(theSWG, jemxNum, FULL, ALL_PAR, (int)auxdata->n_GTI, auxdata->GTI_OBTstart, auxdata->GTI_OBTstop, rowFilter, status ); if( status == ISDC_OK ) { /* * Get number of events */ status = DAL3JEMXgetNumEvents( &nFullEvents, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_2, "##178## %d: Could not get number of selected full imaging events", status); return status; } RILlogMessage(NULL, Log_2, "##179## Number of full events selected: %d", (int) nFullEvents ); } else if( status == DAL3JEMX_NO_JEMX_EVENTS ) { nFullEvents = 0; status = ISDC_OK; } else { // error other than DAL3JEMX_NO_JEMX_EVENTS occurred RILlogMessage(NULL, Error_2, "##177## %d: Could not select full imaging events", status); return status; } /* * Define nEvents that will be used for the count of both FULL and REST events * If REST events are requested it will be redefined */ nEvents = nFullEvents; if( nFullEvents > 0) { /* * Allocate memory for the struct 'Events' that will hold all * FULL event data */ full_events = (Events *) malloc( nFullEvents * sizeof( Events ) ); if( full_events == NULL ) { RILlogMessage( NULL, Error_1,"##180## Memory allocation error"); status = J_ERROR_CODE_START + J_IMA_IROS_ERR + J_IIR_MALLOC_ERR; return( status ); } /* * Allocate memory and then read RAWX and RAWY */ bufferSize = nFullEvents * sizeof( short ); status = DALallocateDataBuffer( (void **)&rawx, bufferSize, status ); status = DALallocateDataBuffer( (void **)&rawy, bufferSize, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_2, "##181## %d: Could not allocate " "memory for RAWX/Y", status ); return( status ); } dataType = DAL_SHORT; status = DAL3JEMXgetEvents( RAWX, &dataType, (void *)rawx, status); status = DAL3JEMXgetEvents( RAWY, &dataType, (void *)rawy, status); if( status!=ISDC_OK) { RILlogMessage(NULL, Error_2, "##182## %d: Could not get RAWX/Y for the selected FULL events", status); return status; } for( i = 0; i < nFullEvents; i++) { full_events[i].rawx = *(rawx+i); full_events[i].rawy = *(rawy+i); } RILlogMessage( NULL, Log_0,"##1811## Got RAWX and RAWY"); /* * Allocate memory and then read STATUS */ bufferSize = nFullEvents * sizeof( unsigned short ); status = DALallocateDataBuffer( (void **)&ushortBuffer, bufferSize, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_2, "##183## %d: Could not allocate " "memory for STATUS", status ); return( status ); } dataType = DAL_USHORT; status = DAL3JEMXgetEvents( STATUS, &dataType, (void *)ushortBuffer, status); if( status!=ISDC_OK) { RILlogMessage(NULL, Error_2, "##184## %d: Could not get STATUS for the selected FULL events", status); return status; } for( i = 0; i < nFullEvents; i++) { full_events[i].status = *(ushortBuffer+i); if( i < 8 ) RILlogMessage( NULL, Log_0, "##1821## %ld evt status = %d", i, full_events[i].status); } RILlogMessage( NULL, Log_0,"##1812## Got STATUS"); /* * Now make sure byte buffer is big enough to handle all these events */ if( nBytes < nFullEvents ) { status = DALfreeDataBuffer( (void *)byteBuffer, status); if(status != ISDC_OK) { RILlogMessage(NULL, Error_2, "##192## %d: Could not free byte Buffer", status ); return status; } bufferSize = nFullEvents* sizeof(unsigned char); nBytes = nFullEvents; byteBuffer = NULL; status = DALallocateDataBuffer( (void **)&byteBuffer, bufferSize, status); if(status != ISDC_OK) { RILlogMessage(NULL, Error_2, "##193## %d: Could not allocate byte Buffer", status ); return status; } } /* * get PI */ RILlogMessage( NULL, Log_0,"##1931## parameter DETX = %d", (int) DETX ); RILlogMessage( NULL, Log_0,"##1931## parameter DETY = %d", (int) DETY ); RILlogMessage( NULL, Log_0,"##1931## parameter PI = %d", (int) PI ); dataType = DAL_BYTE; status = DAL3JEMXgetEvents( 24, &dataType, (void *)byteBuffer, status); if( status!=ISDC_OK) { RILlogMessage(NULL, Error_2, "##194## %d: Could not get PI for the selected FULL events", status); return status; } if( chatter >= J_CHATTY_MAXIMAL ) { RILlogMessage(NULL,Log_0, "##195## Full event PI values read."); } for( i = 0; i < nFullEvents; i++) { full_events[i].pi = (int) *(byteBuffer+i); } RILlogMessage( NULL, Log_0,"##1817## Got PI"); /* * get PHA */ dataType = DAL_BYTE; status = DAL3JEMXgetEvents(PHA, &dataType, (void *)byteBuffer, status); if( status!=ISDC_OK) { RILlogMessage(NULL, Error_2, "##194## %d: Could not get PHA for the selected FULL events", status); return status; } if( chatter >= J_CHATTY_MAXIMAL ) { RILlogMessage(NULL,Log_0, "##195## Full event PHA values read."); } for( i = 0; i < nFullEvents; i++) { full_events[i].pha = (int) *(byteBuffer+i); } RILlogMessage( NULL, Log_0,"##1818## Got PHA"); /* * Check that the OBT buffer is big enough for our event OBTs */ if( nOBTs < nFullEvents ) { status = DALfreeDataBuffer( (void *)obtBuffer, status); if(status != ISDC_OK) { RILlogMessage(NULL, Error_2, "##196## %d: Could not free obt Buffer", status ); return status; } bufferSize = nFullEvents * 4 * sizeof(OBTime); nOBTs = nFullEvents; obtBuffer = NULL; status = DALallocateDataBuffer( (void **)&obtBuffer, bufferSize, status); if(status != ISDC_OK) { RILlogMessage(NULL, Error_2, "##197## %d: Could not allocate new OBT Buffer", status ); return status; } if( chatter >= J_CHATTY_NORMAL ) { RILlogMessage(NULL,Log_0, "##198## Full event OBT buffer allocated to size: %d", (int) bufferSize); RILlogMessage(NULL,Log_0, "##199## nOBTs = %d.", (int) nOBTs); } } /* * Allocate memory for FULL OBTimes */ status = DALallocateDataBuffer( (void **)&fullEventOBT, bufferSize, status); if(status != ISDC_OK) { RILlogMessage(NULL, Error_2, "##200## %d: Could not allocate fullEventOBT", status ); return status; } /* * get full event OBTs */ dataType = DAL_INT; status = DAL3JEMXgetEvents(OB_TIME, &dataType, (void *)obtBuffer, status); if( status!=ISDC_OK) { RILlogMessage(NULL, Error_2, "##201## %d: Could not get OBTs for selected FULL events", status); return status; } if( chatter >= J_CHATTY_NORMAL ) { RILlogMessage(NULL,Log_0, "##202## Full event OBT values read."); } /* obtStart = *(obtBuffer); */ for( i = 0; i < nFullEvents; i++) { /* full_events[i].obt = *(obtBuffer+i); */ fullEventOBT[i] = *(obtBuffer+i); /* * if( obtStart > full_events[i].obt ) { * obtStart = full_events[i].obt; * } * if( obtEnd < full_events[i].obt ) { * obtEnd = full_events[i].obt; * } */ } if( chatter >= J_CHATTY_NORMAL ) { RILlogMessage(NULL,Log_0, "##203## All full event data read."); } } /* End if( nFullEvents>0) */ } /****************READING REST EVENT DATA*************************************/ if( SCWnow->evtType == 1 || SCWnow->evtType ==-1) { /* * Compose selection string */ strcpy(rowFilter,"(STATUS==0)" ); if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage(NULL,Log_0, "##204## Event selection rowFilter string: %s",rowFilter); } /* * Select the REST events * [Previously the selection was 'COR' 2006-05-16/NJW] */ status = DAL3JEMXselectEvents(theSWG, jemxNum, REST, ALL_PAR, (int)auxdata->n_GTI, auxdata->GTI_OBTstart, auxdata->GTI_OBTstop, rowFilter, status ); if( status == ISDC_OK ) { /* * Get number of selected REST events */ status = DAL3JEMXgetNumEvents( &nRestEvents, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_2, "##206## %d: Could not get number of selected rest imaging events", status); return status; } if( chatter > J_CHATTY_NORMAL ) { RILlogMessage(NULL,Log_0, "##207## Number of selected restricted events: %d", (int) nRestEvents); } } else if( status == DAL3JEMX_NO_JEMX_EVENTS ) { nRestEvents = 0; status = ISDC_OK; } else { RILlogMessage(NULL, Error_2, "##205## %d: Could not select restricted imaging events", status); return status; } nEvents = nFullEvents + nRestEvents; if( nRestEvents > 0) { /* * Allocate memory for the struct 'Events' that will hold all event data */ all_events = (Events *) malloc( nEvents * sizeof( Events ) ); if( all_events == NULL ) { RILlogMessage( NULL, Error_1,"##208## Memory allocation error"); status = J_ERROR_CODE_START + J_IMA_IROS_ERR + J_IIR_MALLOC_ERR; return( status ); } /* * If there are any FULL events stored in full_events then move them * over to the 'all_events' array */ if( nFullEvents > 0 ) { for( i = 0; i < nFullEvents; ++i ) { /* all_events[i].detx = full_events[i].detx; */ /* all_events[i].dety = full_events[i].dety; */ all_events[i].rawx = full_events[i].rawx; all_events[i].rawy = full_events[i].rawy; all_events[i].pi = full_events[i].pi; all_events[i].pha = full_events[i].pha; /* all_events[i].obt = full_events[i].obt; */ } free( full_events ); } /* * Allocate memory for all OBTimes */ /* * bufferSize = nEvents * 4 * sizeof(OBTime); * status = DALallocateDataBuffer( (void **)&allEventOBT, bufferSize, * status); * if(status != ISDC_OK) { * RILlogMessage(NULL, Error_2, * "##209## %d: Could not allocate allEventOBT", status ); * return status; * } * if( nFullEvents > 0 ) { * for( i = 0; i < nFullEvents; ++i ) { * allEventOBT[i] = fullEventOBT[i]; * } * } * status = DALfreeDataBuffer( (void *)fullEventOBT, status ); * if(status != ISDC_OK) { * RILlogMessage(NULL, Error_2, * "##210## %d: Could not free fullEventOBT", status ); * return status; * } */ /* * Allocate memory and then read RAWX and RAWY */ if( rawx != NULL ) status = DALfreeDataBuffer( (void *) rawx, status); if( rawy != NULL ) status = DALfreeDataBuffer( (void *) rawy, status); rawx = NULL; rawy = NULL; bufferSize = nRestEvents * sizeof( short ); status = DALallocateDataBuffer( (void **)&rawx, bufferSize, status ); status = DALallocateDataBuffer( (void **)&rawy, bufferSize, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_2, "##211## %d: Could not allocate " "memory for RAWX/Y", status ); return( status ); } dataType = DAL_SHORT; status = DAL3JEMXgetEvents( RAWX, &dataType, (void *)rawx, status); status = DAL3JEMXgetEvents( RAWY, &dataType, (void *)rawy, status); if( status!=ISDC_OK) { RILlogMessage(NULL, Error_2, "##212## %d: Could not get RAWX/Y for the selected REST events", status); return status; } for( i = 0; i < nRestEvents; i++) { all_events[nFullEvents + i].rawx = *(rawx+i); all_events[nFullEvents + i].rawy = *(rawy+i); } /* * Now make sure byte buffer is big enough to handle all these events */ if( nBytes < nRestEvents ) { status = DALfreeDataBuffer( (void *)byteBuffer, status); if(status != ISDC_OK) { RILlogMessage(NULL, Error_2, "##218## %d: Could not free byte Buffer", status ); return status; } bufferSize = nRestEvents * sizeof(unsigned char); nBytes = nRestEvents; status = DALallocateDataBuffer( (void **)&byteBuffer, bufferSize, status); if(status != ISDC_OK) { RILlogMessage(NULL, Error_2, "##219## %d: Could not allocate byte Buffer", status ); return status; } } /* * get REST_PI */ dataType = DAL_BYTE; status = DAL3JEMXgetEvents(REST_PI, &dataType, (void *)byteBuffer, status); if( status!=ISDC_OK) { RILlogMessage(NULL, Error_2, "##220## %d: Could not get PI for the selected REST events", status); return status; } for( i = 0; i < nRestEvents; i++) { all_events[nFullEvents + i].pi = (int) *(byteBuffer+i); } /* * get PHA */ dataType = DAL_BYTE; status = DAL3JEMXgetEvents(PHA, &dataType, (void *)byteBuffer, status); if( status!=ISDC_OK) { RILlogMessage(NULL, Error_2, "##194## %d: Could not get PHA for the selected REST events", status); return status; } if( chatter >= J_CHATTY_MAXIMAL ) { RILlogMessage(NULL,Log_0, "##195## REST event PHA values read."); } for( i = 0; i < nRestEvents; i++) { all_events[nFullEvents + i].pha = (int) *(byteBuffer+i); } /* * Check that the OBT buffer is big enough for rest event OBTs */ /* * if( nOBTs < nRestEvents ) { * status = DALfreeDataBuffer( (void *)obtBuffer, status); * if(status != ISDC_OK) { * RILlogMessage(NULL, Error_2, * "##221## %d: Could not free obt Buffer", status ); * return status; * } * bufferSize = nRestEvents * 4 * sizeof(OBTime); * nOBTs = nRestEvents; * status = DALallocateDataBuffer( (void **)&obtBuffer, bufferSize, * status); * if(status != ISDC_OK) { * RILlogMessage(NULL, Error_2, * "##222## %d: Could not allocate new OBT Buffer", status ); * return status; * } * } */ /* * get restricted event OBTs */ /* * dataType = DAL_INT; * status = DAL3JEMXgetEvents(OB_TIME, &dataType, (void *)obtBuffer, * status); * if( status!=ISDC_OK) { * RILlogMessage(NULL, Error_2, * "##223## %d: Could not get OBTs for selected REST events", status); * return status; * } * if( obtStart==0) { * obtStart = *(obtBuffer); * } * for( i = 0; i < nRestEvents; i++) { * all_events[nFullEvents + i].obt = *(obtBuffer+i); * allEventOBT[nFullEvents + i] = *(obtBuffer+i); * if( obtStart > all_events[nFullEvents + i].obt ) { * obtStart = all_events[nFullEvents + i].obt; * } * if( obtEnd < all_events[nFullEvents + i].obt ) { * obtEnd = all_events[nFullEvents + i].obt; * } * } */ } /* End if( nRestEvents>0) */ } /* End of 'if requested REST events */ /* * when no REST events have been requested or are found * then all events == full events */ if( nRestEvents == 0 ) { allEventOBT = fullEventOBT; all_events = full_events; } *numEvents = nEvents; SCWnow->numEvents = nEvents; /*********************** If no events found: Exit***************************/ if((nFullEvents == 0) && (nRestEvents == 0)) { RILlogMessage(NULL, Warning_2, "##224## No events found within GTI range. Data extraction stopped."); return status; } /* * * Compute IJD for all the events * */ bufferSize = nEvents * sizeof(double); status = DALallocateDataBuffer( (void **)&timeIJD, bufferSize, status); if(status != ISDC_OK) { RILlogMessage(NULL, Error_2, "##225## %d: Could not allocate memory for timeIJD", status ); return status; } status = DAL3AUXconvertOBT2IJD( theSWG, Accuracy, (int) nEvents, allEventOBT, timeIJD, status); if(status != ISDC_OK) { RILlogMessage(NULL, Error_2, "##226## %d: Error in OBT -> timeIJD", status ); return status; } if( chatter > J_CHATTY_NORMAL) { RILlogMessage(NULL,Log_0, "##227## Event OBT converted to IJD. First and last events are:"); RILlogMessage(NULL,Log_0,"##228## timeIJD[0] = %10.5f ", timeIJD[0]); RILlogMessage(NULL,Log_0,"##229## timeIJD[N-1] = %10.5f ", timeIJD[nEvents-1]); } /* * Copy to struct with all event data */ for( i = 0; i < nEvents; ++i ) { all_events[i].ijd = timeIJD[i]; } /*---------------------------------------------------------------------- * * Section for derivation of grey filter and deadtime correction factors * *---------------------------------------------------------------------- */ /* * Get correction for each event */ for( i = 0; i < nEvents; i++ ) { /* Search in the grey filter table */ status = j_iir_bin_search( auxdata->n_greyValues, auxdata->greyTimes, all_events[i].ijd, &indexg, status ); greyCorr = 32.0 / ((float) (auxdata->greyValues[indexg] + 1)); /* Search in the dead time table */ status = j_iir_bin_search( auxdata->n_deadTimes, auxdata->deadIJD, all_events[i].ijd, &indexd, status ); deadCorr = auxdata->rateCor[indexd]; all_events[i].corfac = greyCorr * deadCorr; /* Search in the gain table */ status = j_iir_bin_search( auxdata->n_gains, auxdata->scpTimes, all_events[i].ijd, &indexgn, status ); if( auxdata->scpGain[indexgn] < 10.0 || auxdata->scpGain[indexgn] > 35.0 ) { all_events[i].gain = 22.9999; } else { all_events[i].gain = auxdata->scpGain[indexgn]; } } /*********************** De-allocate buffer memory***************************/ if( chatter >= J_CHATTY_MAXIMAL ) { RILlogMessage(NULL,Log_0, "##230## Deallocate memory for all buffers"); } if( byteBuffer!= NULL ) { status = DALfreeDataBuffer( (void *) byteBuffer,status ); if( status!=ISDC_OK ) { RILlogMessage(NULL, Warning_2, "##231## %d: could not free memory for the byte buffer", status); status = ISDC_OK; } } if( obtBuffer!= NULL ) { status = DALfreeDataBuffer( (void *) obtBuffer,status ); if( status!=ISDC_OK ) { RILlogMessage(NULL, Warning_2, "##232## %d: could not free memory for the obt buffer", status); status = ISDC_OK; } } if( ushortBuffer!= NULL) { status = DALfreeDataBuffer( (void *) ushortBuffer,status ); if( status!=ISDC_OK ) { RILlogMessage(NULL, Warning_2, "##2331## %d: could not free memory for unsigned short buffer", status); status = ISDC_OK; } } if( chatter >= J_CHATTY_MAXIMAL ) { RILlogMessage(NULL,Log_0, "##236## Deallocate completed."); } /***************** END DEALLOCATE*********************************/ itmp = 2 * tAccuracy; RILlogMessage(NULL,Log_0,"##237## 2*tAccuracy = %d", itmp ); RILlogMessage( NULL, Log_0, "##238## greyCorr = %f", greyCorr ); *bufevents = all_events; /* TEST TEST */ m = (nEvents - 1)/100; for( i = 0; i < nEvents; i += m ) { RILlogMessage( NULL, Log_0,"##4400## Ev# %7ld rawx/y %3d %3d pi %3d pha %3d", i, all_events[i].rawx, all_events[i].rawy, all_events[i].pi, all_events[i].pha ); RILlogMessage( NULL, Log_0,"##4400## status %8d IJD %13.8lf gain %6.3f corfac %6.3f", all_events[i].status, all_events[i].ijd, all_events[i].gain, all_events[i].corfac ); } /* 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; if (logger->trace) traces(func_local, 99, logger); /* function exit timing end */ return( status ); } /***************************************************************************** Function: j_read_GTI Description: Reads Good Time Interval boundaries, allocating the corresponding buffers as required. Error codes (constants defined in header files): 0 == ISDC_OK ==> function executed with no errors < 0 (various) ==> ISDC system function error code, passed on J_IIR_MALLOC_ERR ==> not enough memory for some buffers Parameter arguments: name range I/O description theSWG !=NULL input handle to SWG jemxInstr JMX1 or JMX2 input instrument number gtiNames (strings) input Names of GTIs to be used nGTI >=0 output Number of Good Time Intervals found gtiStartOBT (array) output Start OBTimes of GTIs gtiEndOBT (array) output End OBTimes of GTIs gtiStartIJD (array) output Start IJDs of GTIs gtiEndIJD (array) output End IJDs of GTIs chatter 0 to 5 input Verbosity control variable callingStatus any input Error status on input *****************************************************************************/ int j_read_GTI(dal_element *theSWG, Instrument jemxInstr, char **gtiNames, int numNames, int *nGTI, OBTime **gtiStartOBT, OBTime **gtiEndOBT, double **gtiStartIJD, double **gtiEndIJD, struct log_con *logger, int chatter, int callingStatus) { char **foundNames=NULL; /* GTI names (used by DAL3HKcheckGTI) */ char **notFoundNames=NULL; /* GTI names (used by DAL3HKcheckGTI) */ int gtiNumFoundNames=0; /* Number of GTI names found in SWG */ int iGTI=0; /* Index to loop over GTI names */ int setupDefaultGTI=0; /* Boolean: should we set up a default GTI */ int status=ISDC_OK; static int func_local = -1, local_calling_num=0; clock_t calling_TT, TT_now; /* * exit function immediately if callingStatus is not OK on entry */ if(callingStatus != ISDC_OK) return(callingStatus); /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "j_read_GTI"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; if (logger->trace) traces(func_local, 0, logger); logger->func_calling_num = func_local; logger->func_times[local_calling_num] += TT_now - calling_TT; /* function entry timing end */ /* * Single-pass do loop, only used to allow clean exits (via continue) * if errors are encountered */ do { foundNames = malloc(J_IIR_MAX_GTI_NAMES*sizeof(char *)); notFoundNames = malloc(J_IIR_MAX_GTI_NAMES*sizeof(char *)); if (NULL==foundNames || NULL==notFoundNames) { RILlogMessage(NULL,Error_3, "##419## Not enough memory for GTI names."); status=J_IIR_MALLOC_ERR; continue; } for (iGTI=0; iGTI J_CHATTY_NORMAL ){ RILlogMessage(NULL,Log_1, "##421## Checking for GTIs %s ", gtiNames[0]); } status = DAL3HKcheckGTI(theSWG,jemxInstr,gtiNames,numNames, foundNames,notFoundNames,>iNumFoundNames, status); if (status != ISDC_OK) { RILlogMessage(NULL,Error_1,"##422## %s status = %d", "DAL3HKcheckGTI failed.", status); continue; } if(chatter >= J_CHATTY_VERBOSE ){ if ( gtiNumFoundNames > 0) { for (iGTI=0; iGTI0) { /* Determine upper limit of possible GTIs */ status = DAL3HKgetNumGTI(theSWG,jemxInstr,gtiNames,numNames, nGTI,status); if (status != ISDC_OK) { RILlogMessage(NULL,Error_1,"##424## %s status = %d", "DAL3HKgetNumGTI failed.", status); continue; } if (0 < *nGTI) { /* Allocate memory for GTI buffer */ if (chatter >= J_CHATTY_VERBOSE) { RILlogMessage(NULL,Log_1, "##425## %d Good Time Intervals found.", *nGTI); } *gtiStartOBT=malloc(*nGTI * sizeof(OBTime)); *gtiEndOBT =malloc(*nGTI * sizeof(OBTime)); *gtiStartIJD=malloc(*nGTI * sizeof(double)); *gtiEndIJD =malloc(*nGTI * sizeof(double)); if (NULL==*gtiStartOBT || NULL==*gtiEndOBT || NULL==*gtiStartIJD || NULL==*gtiEndIJD ) { RILlogMessage(NULL,Error_3, "##426## Not enough memory for GTI intervals."); status=J_IIR_MALLOC_ERR; continue; } /* Read actual good time intervals */ status = DAL3HKgetGTI(theSWG,jemxInstr, gtiNames,numNames, DAL3_NO_OBTIME, /* No further OBT */ DAL3_NO_OBTIME, /* selection */ nGTI, *gtiStartOBT,*gtiEndOBT, status); if (status != ISDC_OK) { RILlogMessage(NULL,Error_1,"##427## %s status = %d", "DAL3HKgetGTI failed.", status); continue; } /* Convert GTI OBTimes to IJD */ status = DAL3AUXconvertOBT2IJD(theSWG,TCOR_ANY,*nGTI, *gtiStartOBT,*gtiStartIJD, status); status = DAL3AUXconvertOBT2IJD(theSWG,TCOR_ANY,*nGTI, *gtiEndOBT,*gtiEndIJD, status); if (ISDC_OK != status) { RILlogMessage(NULL,Error_2, "##428## Error converting GTI OBT bounds to IJD! " "status = %d",status); continue; } else if (chatter >= J_CHATTY_VERY_VERBOSE) { RILlogMessage(NULL,Log_0, "##429## Converted GTI OBTs to IJD"); } } else { /* i.e. the upper limit of intervals is <1 */ setupDefaultGTI = 0; if (chatter >= J_CHATTY_NORMAL) { RILlogMessage(NULL,Warning_2, "##430## Apparently all the time in this dataset " "is to be considered bad!"); } status = J_IIR_NO_GTI; continue; } } else { /* i.e. we have no to work with */ setupDefaultGTI = 1; if (chatter >= J_CHATTY_NORMAL) { RILlogMessage(NULL,Warning_2,"##431## No GTI information found!"); } } /* Set up default GTI if no GTI information is available */ if (setupDefaultGTI) { if (chatter >= J_CHATTY_VERBOSE) { RILlogMessage(NULL,Log_2, "##432## Setting up default GTI spanning SWG"); } *gtiStartOBT=malloc(sizeof(OBTime)); *gtiEndOBT =malloc(sizeof(OBTime)); *gtiStartIJD=malloc(sizeof(double)); *gtiEndIJD =malloc(sizeof(double)); if (NULL==*gtiStartOBT || NULL==*gtiEndOBT || NULL==*gtiStartIJD || NULL==*gtiEndIJD) { RILlogMessage(NULL,Error_3, "##433## Not enough memory for GTI interval."); status=J_IIR_MALLOC_ERR; continue; } status = DAL3GENattributeGetOBT(theSWG,"OBTSTART",*gtiStartOBT, NULL,status); status = DAL3GENattributeGetOBT(theSWG,"OBTEND",*gtiEndOBT, NULL,status); if (ISDC_OK!=status) { RILlogMessage(NULL,Log_0, "##434## Missing OBTSTART, OBTEND. "); status = ISDC_OK; } status = DALattributeGet(theSWG,"TSTART",DAL_DOUBLE, (void*)*gtiStartIJD,NULL,NULL,status); status = DALattributeGet(theSWG,"TSTOP",DAL_DOUBLE, (void*)*gtiEndIJD,NULL,NULL,status); if (ISDC_OK!=status) { RILlogMessage(NULL,Log_0, "##435## Missing TSTART, TSTOP. "); *nGTI = 0; status = ISDC_OK; return(status); } if(**gtiEndIJD > **gtiStartIJD){ RILlogMessage(NULL,Log_0, "##436## Read GTI start and end times from " "SWG attributes"); RILlogMessage(NULL,Log_0, "##437## gtiStartIJD: %14.8f",*gtiStartIJD[0]); RILlogMessage(NULL,Log_0, "##438## gtiEndIJD: %14.8f",*gtiEndIJD[0]); *nGTI = 1; } else { if (chatter >= J_CHATTY_VERBOSE) { RILlogMessage(NULL,Log_0, "##439## Inconsistent TSTART, TSTOP values."); } *nGTI = 0; } } /* end of default setup */ } while(0); /* 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; if (logger->trace) traces(func_local, 99, logger); /* function exit timing end */ return(status); } /***************************************************************** * Name of source file: j_iir_get_gain.c * Version of source file: 4.0.12 * Parent component: j_ima_iros * Programmer: Niels J. Westergaard * Affiliation: National Space Institute/DTU * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325705 FAX: +45 35362475 * njw@space.dtu.dk * Purpose: Get the gain [PHA/keV] from JMXi-GAIN-SCP * Origin date: 100301 * Update history: 2.3.7 100301 First version * 4.0.12 120919 SPR ?: Introduce corrections by LP and Co. * Type of element: Function * Part of package: j_ima_iros * Name: j_iir_get_gain *****************************************************************/ int j_iir_get_gain( dal_element *theSWG, Instrument jemxNum, Auxdata *auxdata, struct log_con *logger, int chatter, int status) { char structName[DS_NAME_SIZE]; int loop = 0; int moop = 0; int noop = 0; int n_gains = 0; long numRows = 0; long nValuesRead = 0; long bufferSize = 0; float *scpGain = NULL; double *scpTimes = NULL; dal_element *extPtr = NULL; dal_dataType dataType = DAL_INT; if( status != ISDC_OK ) return status; 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_get_gain"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; if (logger->trace) traces(func_local, 0, logger); logger->func_calling_num = func_local; logger->func_times[local_calling_num] += TT_now - calling_TT; /* function entry timing end */ /* * assumes that jemxNum has been tested in j_ima_iros_params */ if( jemxNum == JMX1 ) strcpy( structName, "JMX1" ); if( jemxNum == JMX2 ) strcpy( structName, "JMX2" ); /* * Find the JMXi-GAIN-SCP data structure */ strcat( structName, "-GAIN-SCP" ); status = DALobjectFindElement( theSWG, structName, &extPtr, status); if( status != ISDC_OK ) { RILlogMessage(NULL, Error_2, "##241## %d: Could not find extension %s", status, structName); return status; } if( chatter >= J_CHATTY_MAXIMAL ){ RILlogMessage(NULL,Log_0, "##242## Data structure found"); } /* * Find number of values. */ dataType = DAL_DOUBLE; status = DALtableGetColStruct( extPtr, 0, &numRows, "TIME", &dataType, NULL, NULL, status); if( status != ISDC_OK ) { RILlogMessage(NULL, Error_2, "##243## %d : Couldn't find number of TIME values in %s", status, structName); return status; } if( numRows == 0 ) { status = J_ERROR_CODE_START + J_IMA_IROS_ERR + J_IIR_BAD_NUM_VALUES; RILlogMessage( NULL, Error_0,"##7726## : No rows found in SCP"); return status; } /* * Allocate double (scpTimes) and float (scpGain) buffer */ bufferSize = numRows * sizeof( double ); status = DALallocateDataBuffer( (void **) &scpTimes, bufferSize, status ); bufferSize = numRows * sizeof( float ); status = DALallocateDataBuffer( (void **) &scpGain, bufferSize, status ); if( status != ISDC_OK ) { RILlogMessage(NULL, Error_2, "##243## %d : Memory allocation error", status ); return status; } /* ------------------------------------------------------------------------ * Read TIME into scpTimes * ------------------------------------------------------------------------ */ dataType = DAL_DOUBLE; status = DALtableGetCol( extPtr, "TIME", 0, &dataType, &nValuesRead, (void *) scpTimes, status); if( status != ISDC_OK ){ RILlogMessage( NULL, Warning_0, "##277## %d: Could not get TIME values from %s", status, structName ); return status; } if( chatter >= J_CHATTY_MAXIMAL ){ RILlogMessage(NULL,Log_0, "##246## Read %ld TIME values", nValuesRead ); } if (numRows != nValuesRead ){ status = J_ERROR_CODE_START + J_IMA_IROS_ERR + J_IIR_BAD_NUM_VALUES; RILlogMessage( NULL,Error_0, "%d : Wrong number of TIME values read in from %s", status, structName ); return status; } /* ------------------------------------------------------------------------ * Read GAIN into scp_gain_arr * ------------------------------------------------------------------------ */ dataType = DAL_FLOAT; status = DALtableGetCol( extPtr, "GAIN", 0, &dataType, &nValuesRead, (void *) scpGain, status); if( status != ISDC_OK ){ RILlogMessage( NULL, Warning_0, "##278## %d: Could not get GAIN values from %s", status, structName ); return status; } if( chatter >= J_CHATTY_MAXIMAL ) { RILlogMessage(NULL,Log_0, "##246## Read %ld GAIN values",nValuesRead ); } if( numRows != nValuesRead ) { status = J_ERROR_CODE_START + J_IMA_IROS_ERR + J_IIR_BAD_NUM_VALUES; RILlogMessage( NULL, Error_0, "%d : Wrong number of GAIN values read in from %s", status, structName ); return status; } for(loop=0; loopn_gains = (int) numRows; auxdata->scpGain = scpGain; auxdata->scpTimes = scpTimes; /* 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; if (logger->trace) traces(func_local, 99, logger); /* function exit timing end */ return(status); } /***************************************************************** * Name of source file: j_iir_get_dead_time.c * Version of source file: 4.0.12 * Parent component: j_ima_iros * Programmer: Niels J. Westergaard * Affiliation: National Space Institute/DTU * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325705 FAX: +45 35362475 * njw@space.dtu.dk * Purpose: Get the dead_time from JMXi-DEAD-SCP * Origin date: 100304 * Update history: 2.3.7 100304 First version * 4.0.12 120919 SPR ?: Introduce corrections by LP and Co. * Type of element: Function * Part of package: j_ima_iros * Name: j_iir_get_dead_time *****************************************************************/ int j_iir_get_dead_time( dal_element *theSWG, Instrument jemxNum, Auxdata *auxdata, struct log_con *logger, int chatter, int status) { char structName[DS_NAME_SIZE]; int skipDEAD = 0; long i = 0; long nDeadTimes = 0; long bufferSize = 0; long nValuesRead = 0; float *floatBuffer = NULL; double *deadTimes = NULL; double *rateCor = NULL; double *deadEff = NULL; double *deadTimeIJD = NULL; OBTime *obtBuffer = NULL; OBTime *deadTimeOBT = NULL; dal_element *deadPtr = NULL; dal_dataType dataType = DAL_INT; TCOR_flag Accuracy = TCOR_ANY; 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_get_deadtime"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; if (logger->trace) traces(func_local, 0, logger); logger->func_calling_num = func_local; logger->func_times[local_calling_num] += TT_now - calling_TT; /* function entry timing end */ /* * The follow section does: * - The dead time values and time the time for which they are valid are * read from the DS. * - Memory for storage is allocated. * - The OBT times are transformed to IJD. * - The initial value of the Dead time correction (deadCorr) is * calculated and the time in IJD when it will change is stored in * deadTimeIJDNext * */ /* * Obtain Dead Time table information. */ if( jemxNum == JMX1 ) strcpy( structName, "JMX1" ); if( jemxNum == JMX2 ) strcpy( structName, "JMX2" ); strcat( structName, J_DEAD_DS); RILlogMessage(NULL, Log_0,"##141## Reading data structure: %s", structName); status = DALobjectFindElement(theSWG, structName, &deadPtr, status); if( status!=ISDC_OK ) { RILlogMessage(NULL, Warning_2, "##142## %d: Could not find extension %s", status, structName); status = ISDC_OK; /* Reset status to OK and go on. */ skipDEAD = 1; } if( !skipDEAD ) { /* blockC */ /* * Find how many Dead time values there are to read in */ if( chatter > J_CHATTY_VERBOSE ) RILlogMessage( NULL, Log_0, "##145## Mark"); status = DALtableGetColStruct( deadPtr, 0, &nDeadTimes, "DEADTIME", &dataType, NULL, NULL, status); if( status != ISDC_OK ) { RILlogMessage(NULL, Error_2, "##146## %d: Couldn't find number of dead times in %s", status, structName); return status; } if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##147## nDeadTimes = %ld", nDeadTimes ); } /* * If there are dead times, get the OBT values in the extension * First allocate space for the OBT_START and OBT_END values */ if( nDeadTimes == 0) { if( chatter > J_CHATTY_NORMAL ) RILlogMessage( NULL, Log_0, "##148## Mark"); status = J_IIR_NO_INPUT_VALUES; RILlogMessage(NULL, Error_2, "##149## %d: No dead time values available in SWG", status); return status; } bufferSize = nDeadTimes * 4 * sizeof(OBTime); status = DALallocateDataBuffer((void **)&obtBuffer, bufferSize, status ); if( status != ISDC_OK ) { RILlogMessage( NULL,Error_3, "##152## %d: Problem allocating memory for deadtime OBTime buffer", status ); return status ; } /* * Now read in the dead time OBTs */ status = DAL3GENtableGetOBT( deadPtr, "OB_TIME", 0, &nValuesRead, obtBuffer, status ); if( status != ISDC_OK ) { RILlogMessage( NULL,Error_3, "##153## %d: Could not read in dead time OBT values from %s", status, structName ); return status ; } if( nDeadTimes!= nValuesRead ) { status = J_IIR_BAD_NUM_VALUES ; RILlogMessage( NULL,Error_3, "##154## %d: Wrong number of dead time OBTs read in from %s", status, structName ); return status; } bufferSize = nDeadTimes * 4 * sizeof(OBTime); status = DALallocateDataBuffer( (void **)&deadTimeOBT, bufferSize, status); if(status != ISDC_OK) { RILlogMessage(NULL, Error_2, "##155## %d: Could not allocate memory for deadTimeOBT", status ); return status; } for( i = 0; i < nDeadTimes; i++ ) { deadTimeOBT[i] = *(obtBuffer + i); if( chatter > J_CHATTY_NORMAL && i < 10 ) { RILlogMessage( NULL, Log_0, "##156## deadTimeOBT: %lld", deadTimeOBT[i] ); } } if( chatter > J_CHATTY_NORMAL && nDeadTimes > 10 ) { RILlogMessage( NULL, Log_0, "##157## ... %ld more values", nDeadTimes-10 ); } /*------------------------------------------------------------------*/ /* * Make a transfer buffer for the dead times */ bufferSize = nDeadTimes * sizeof(float); status = DALallocateDataBuffer( (void **)&floatBuffer, bufferSize, status); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_2, "##158## %d: Could not allocate float values data buffer", status); return status; } dataType = DAL_FLOAT; status = DALtableGetCol( deadPtr, "DEADTIME", 0, &dataType, &nValuesRead, (void *)floatBuffer, status); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_2, "##159## %d: Could not get DEADTIME values from %s", status, structName ); return status; } if( nDeadTimes!= nValuesRead ) { status = J_IIR_BAD_NUM_VALUES ; RILlogMessage( NULL,Error_3, "##160## %d: Wrong number of dead time values read in from %s", status, structName ); return status; } /* * Allocate memory for 'deadTimes' (double) */ bufferSize = (long) nDeadTimes * sizeof(double); status = DALallocateDataBuffer( (void **)&deadTimes, bufferSize, status); if(status != ISDC_OK) { RILlogMessage(NULL, Error_2, "##161## %d: Could not allocate memory for deadTimes", status ); return status; } for ( i=0 ; i J_CHATTY_VERBOSE ) RILlogMessage( NULL, Log_0, "##163## Mark"); dataType = DAL_FLOAT; status = DALtableGetCol( deadPtr, "RATE_COR", 0, &dataType, &nValuesRead, (void *)floatBuffer, status); if( (DAL_ERROR_CODE_BASE - COL_NOT_FOUND) == status) { if( chatter > J_CHATTY_QUIET ) { RILlogMessage(NULL,Warning_1, "##164## The deadtime table apparently is of the " "old style without RATE_COR. Using DEADTIME"); } /* * Derive rateCor from deadTimes in this case */ for ( i=0; i < nDeadTimes ; i++) { rateCor[i] = 1.0/(1.0-deadTimes[i]); } status = ISDC_OK; } else if( status != ISDC_OK ) { RILlogMessage( NULL, Error_2, "##165## %d: Could not get RATE_COR values from %s", status, structName ); return status; } else { /* Normal situation */ if( chatter > J_CHATTY_QUIET ) { RILlogMessage( NULL, Log_0,"##165## The deadtime table is current style"); } for( i = 0; i < nDeadTimes; i++ ) { rateCor[i] = (double) *(floatBuffer + i); if( i < 10 ) RILlogMessage( NULL, Log_0, "##161## rateCor = %7.3lf\n", rateCor[i]); } } if( nDeadTimes != nValuesRead ) { status = J_IIR_BAD_NUM_VALUES; RILlogMessage( NULL,Error_3, "##166## %d: Wrong number of rate correction values read in from %s", status, structName ); return status; } /* *-----------------------------DEAD_EFF---------------------------- */ /* * Allocate memory */ bufferSize = (long) nDeadTimes * sizeof(double); status = DALallocateDataBuffer( (void **)&deadEff, bufferSize, status); if(status != ISDC_OK) { RILlogMessage(NULL, Error_2, "##167## %d: Could not allocate memory for deadEff", status ); return status; } status = DALtableGetCol( deadPtr, "DEAD_EFF", 0, &dataType, &nValuesRead, (void *)floatBuffer, status); if( (DAL_ERROR_CODE_BASE-COL_NOT_FOUND) == status) { if( J_CHATTY_NORMAL <= chatter ) { RILlogMessage(NULL,Warning_1, "##168## The deadtime table apparently is of the " "old style without DEAD_EFF. Using DEADTIME"); } status = ISDC_OK; for ( i=0 ; i J_CHATTY_QUIET ) { RILlogMessage( NULL, Log_0,"##165## The dead eff table is current style"); } for ( i=0; i < nDeadTimes; i++) { deadEff[i] = (double) *(floatBuffer + i); if( i < 10 ) RILlogMessage( NULL, Log_0, "##161## deadEff = %7.3lf\n", deadEff[i]); } } if( nDeadTimes!= nValuesRead ) { status = J_IIR_BAD_NUM_VALUES ; RILlogMessage( NULL,Error_3, "##170## %d: Wrong number of DEAD_EFF values read in from %s", status, structName ); return status; } } /* blockC */ /*------------------------------------------------------------------- * * Allocate memory for deadTimeIJD and convert from OBT -> IJD. * *------------------------------------------------------------------- */ if( nDeadTimes > 0) { bufferSize = nDeadTimes * sizeof(double); status = DALallocateDataBuffer( (void **)&deadTimeIJD, bufferSize, status); if(status != ISDC_OK) { RILlogMessage(NULL, Error_2, "##171## %d: Could not allocate memory for deadTimeIJD", status ); return status; } status = DAL3AUXconvertOBT2IJD( theSWG, Accuracy, (int) nDeadTimes, deadTimeOBT, deadTimeIJD, status); if(status != ISDC_OK) { RILlogMessage(NULL, Error_2, "##172## %d: Error when converting Dead times from OBT to IJD", status ); return status; } if( chatter > J_CHATTY_NORMAL ) { RILlogMessage(NULL,Log_0, "##173## Number of Dead times converted to IJD: %ld ", nDeadTimes ); } if( nDeadTimes > 0 && chatter > J_CHATTY_NORMAL ) { RILlogMessage(NULL,Log_0, "##174## Time(IJD), Dead time, rateCor, deadEff. (first 4)"); i = 0; while (i < 10 && i < nDeadTimes) { RILlogMessage(NULL,Log_0,"##175## %lf %lf %lf %lf", deadTimeIJD[i], deadTimes[i], rateCor[i], deadEff[i]); i++; } } } /* * Transfer pointers to Auxdata struct 'auxdata' for use in other * functions */ auxdata->n_deadTimes = (int) nDeadTimes; auxdata->deadIJD = deadTimeIJD; auxdata->deadTime = deadTimes; auxdata->deadEff = deadEff; auxdata->rateCor = rateCor; DALfreeDataBuffer( (void*) floatBuffer, status ); DALfreeDataBuffer( (void*) obtBuffer, status ); /* 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; if (logger->trace) traces(func_local, 99, logger); /* function exit timing end */ return(status); } /***************************************************************** * Name of source file: j_iir_get_greyfilter.c * Version of source file: 4.0.12 * Parent component: j_ima_iros * Programmer: Niels J. Westergaard * Affiliation: National Space Institute/DTU * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325705 FAX: +45 35362475 * njw@space.dtu.dk * Purpose: Get the grey filter adn time values * Origin date: 100303 * Update history: 2.3.7 100303 First version * 4.0.12 120919 SPR ?: Introduce corrections by LP and Co. * Type of element: Function * Part of package: j_ima_iros * Name: j_iir_get_greyfilter *****************************************************************/ int j_iir_get_greyfilter( dal_element *theSWG, Instrument jemxNum, Auxdata *auxdata, struct log_con *logger, int chatter, int status) { unsigned char *byteBuffer = NULL; char structName[DS_NAME_SIZE]; int *modeValues = NULL; int *greyValues = NULL; long i = 0; long nGreyChanges = 0; long bufferSize = 0; long nValuesRead = 0; double *statusIJD = NULL; OBTime *obtBuffer = NULL; OBTime *statusOBT = NULL; TCOR_flag accuracy = TCOR_ANY; dal_element *statusPtr = NULL; dal_dataType dataType = DAL_INT; 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_get_greyfilter"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; if (logger->trace) traces(func_local, 0, logger); logger->func_calling_num = func_local; logger->func_times[local_calling_num] += TT_now - calling_TT; /* function entry timing end */ /* * Find status history and get number of grey filter changes */ if( jemxNum == JMX1 ) strcpy( structName, "JMX1" ); if( jemxNum == JMX2 ) strcpy( structName, "JMX2" ); strcat( structName, J_STATHIS_DS); if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage(NULL, Log_0, "##94## Searching data structure: %s",structName ); } status = DALobjectFindElement( theSWG, structName, &statusPtr, status); if( status!=ISDC_OK ) { RILlogMessage(NULL, Warning_2, "##95## %d: Could not find extension %s", status, structName); return status; } status = DALtableGetNumRows( statusPtr, &nGreyChanges, status ); if( status != ISDC_OK ) { RILlogMessage( NULL,Error_2, "##99## %d: Error reading number of grey filter/mode changes", status ); return status ; } RILlogMessage(NULL, Log_0, "##98## Number of instrument status entries, nGreyChanges: %ld",nGreyChanges); if( nGreyChanges == 0 ) { RILlogMessage(NULL,Error_2, "##100## No instrument status entries found in %s", structName ); status = J_IIR_NO_INPUT_VALUES; return status ; } /* * Allocate memory buffer for MODE, GREY_FILTER and OB_TIME */ bufferSize = (long) nGreyChanges * sizeof(unsigned char); status = DALallocateDataBuffer((void **) &byteBuffer, bufferSize, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_2, "##101## %d: could not allocate byte buffer for instrument status", status ); return status; } bufferSize = (long) nGreyChanges * 4 * sizeof(OBTime); status = DALallocateDataBuffer((void **)&obtBuffer, bufferSize,status ); if( status != ISDC_OK ) { RILlogMessage( NULL,Error_3, "##102## %d: Problem allocating memory for grey filter OBTime buffer", status ); return status ; } if( chatter > J_CHATTY_NORMAL ) { RILlogMessage(NULL,Log_0, "##103## Grey filter OBT buffer allocated to size: %ld", bufferSize); } /* * Read status and grey filter changes */ dataType = DAL_BYTE; status = DALtableGetCol( statusPtr, "MODE", 0, &dataType, &nValuesRead, byteBuffer, status ); if( status != ISDC_OK ) { RILlogMessage( NULL,Error_3, "##104## %d: Could not read in instrument mode values from %s", status, structName ); return status ; } if( nValuesRead!= nGreyChanges ) { status = J_IIR_BAD_NUM_VALUES ; RILlogMessage( NULL,Error_3, "##105## %d: Wrong number of instrument mode values read in from %s", status, structName ); return status; } /* * Allocate memory for modeValues */ bufferSize = (long) nGreyChanges * sizeof(int); status = DALallocateDataBuffer( (void **)&modeValues, bufferSize, status); if(status != ISDC_OK) { RILlogMessage(NULL, Error_2, "##106## %d: Could not allocate memory for modeValues", status ); return status; } for( i = 0; i < nGreyChanges; i++ ) { modeValues[i] = (int) *(byteBuffer + i); } dataType = DAL_BYTE; status = DALtableGetCol( statusPtr, "GREY_FILTER", 0, &dataType, &nValuesRead, byteBuffer, status ); if( status != ISDC_OK ) { RILlogMessage( NULL,Error_3, "##107## %d: Could not read in grey filter values from %s", status, structName ); return status ; } if( nValuesRead != nGreyChanges ) { status = J_IIR_BAD_NUM_VALUES ; RILlogMessage( NULL,Error_3, "##108## %d: Wrong number of grey filter values read in from %s", status, structName ); return status; } /* * Allocate memory */ bufferSize = (long) nGreyChanges * sizeof(int); status = DALallocateDataBuffer( (void **)&greyValues, bufferSize, status); if(status != ISDC_OK) { RILlogMessage(NULL, Error_2, "##109## %d: Could not allocate memory for greyValues", status ); return status; } for( i = 0; i < nGreyChanges; i++ ) { greyValues[i] = (int) *(byteBuffer + i); } if( chatter > J_CHATTY_NORMAL ) RILlogMessage( NULL, Log_0, "##110## Mark"); status = DAL3GENtableGetOBT( statusPtr, "OB_TIME", 0, &nValuesRead, obtBuffer, status ); if( status != ISDC_OK ) { RILlogMessage( NULL,Error_3, "##111## %d: Could not read in instrument status OBT values from %s", status, structName ); return status ; } if( nValuesRead != nGreyChanges ) { status = J_IIR_BAD_NUM_VALUES ; RILlogMessage( NULL,Error_3, "##112## %d: Wrong number of instrument status OBTs read in from %s", status, structName ); return status; } bufferSize = nGreyChanges * 4 * sizeof(OBTime); status = DALallocateDataBuffer( (void **)&statusOBT, bufferSize, status); if(status != ISDC_OK) { RILlogMessage(NULL, Error_2, "##113## %d: Could not allocate memory for statusOBT", status ); return status; } for( i = 0; i < nGreyChanges; i++) { statusOBT[i] = *(obtBuffer + i); if( chatter > J_CHATTY_NORMAL && ( i < 5 || i >= nGreyChanges - 5 ) ) { RILlogMessage( NULL, Log_0, "##114## statusOBT: %lld", statusOBT[i] ); } } if( nGreyChanges > 10 ) { RILlogMessage( NULL, Log_0, "##115## ... %ld more values", nGreyChanges-10 ); } /****************************************************************** * * Allocate memory for statusIJD (Times of grey filter changes * in IJD). * ******************************************************************/ if( nGreyChanges > 0) { if( chatter > J_CHATTY_VERBOSE ) RILlogMessage( NULL, Log_0, "##116## Mark"); bufferSize = nGreyChanges * sizeof(double); status = DALallocateDataBuffer( (void **)&statusIJD, bufferSize, status); if( status != ISDC_OK ) { RILlogMessage(NULL, Error_2, "##117## %d: Could not allocate memory for statusIJD", status ); return status; } status = DAL3AUXconvertOBT2IJD( theSWG, accuracy, (int) nGreyChanges, statusOBT, statusIJD, status); if( status != ISDC_OK ) { RILlogMessage(NULL, Error_2, "##118## %d: Error when converting Grey filter times from OBT to IJD", status ); return status; } if( chatter > J_CHATTY_NORMAL ) { RILlogMessage(NULL,Log_0, "##119## Number of Grey filter times converted to IJD: %ld ", nGreyChanges ); } if( nGreyChanges > 0 && chatter > J_CHATTY_NORMAL ) { RILlogMessage(NULL,Log_0, "##120## Greyfilter time(IJD), Filter value, mode "); i = 0; while( i < 10 && i < nGreyChanges ) { RILlogMessage(NULL,Log_0,"##121## %13.8lf %12d %8d", statusIJD[i], greyValues[i], modeValues[i]); i++; } if( nGreyChanges > 10 ) { RILlogMessage( NULL, Log_0, "##122## ... %ld more values", nGreyChanges-10 ); } } } auxdata->n_greyValues = (int) nGreyChanges; auxdata->greyValues = greyValues; auxdata->greyTimes = statusIJD; DALfreeDataBuffer( (void *) byteBuffer, status ); DALfreeDataBuffer( (void *) obtBuffer, status ); /* 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; if (logger->trace) traces(func_local, 99, logger); /* function exit timing end */ return(status); } /***************************************************************** * Name of source file: j_iir_fill_adhoc_shd.c * Version of source file: 2.3.7 * Parent component: j_ima_iros * Programmer: Niels J. Westergaard * Affiliation: National Space Institute/DTU * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325705 FAX: +45 35362475 * njw@space.dtu.dk * Purpose: Create a shadowgram from the event list * Origin date: 071029 * Update history: 2.3.7 100308 First version * Type of element: Function * Part of package: j_ima_iros * Name: j_iir_fill_adhoc_shd *****************************************************************/ int j_iir_fill_adhoc_shd( double IJDstart, double IJDstop, int chanMin, int chanMax, Events *bufevents, long nEvents, Auxdata auxdata, Shd_adhoc shd_adhoc, struct log_con *logger, int chatter, int status) { int flag = 0; long i = 0; long i1 = 0; long i2 = 0; long idx = 0; float gain_sum = 0.0; float deadtime_sum = 0.0; float greyfilter_sum = 0.0; double ontime = 0.0; double time_step = 0.0; double time = 0.0; double *dblBuffer = NULL; static int func_local = -1, local_calling_num=0; clock_t calling_TT, TT_now; if( status != ISDC_OK ) return status; /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; logger->func_calling_num = 0; sprintf(logger->func_names[func_local], "fill_adhoc_shd"); if (logger->func_used_num > J_IIR_MAX_NUM_FUNCS) { sprintf(logger->tmptxt, "func_used_num > %d", J_IIR_MAX_NUM_FUNCS); logger->logstat = logprint(logger, logger->tmptxt, 6); logger->func_used_num = J_IIR_MAX_NUM_FUNCS; } } 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 */ /* * Initialize and then fill the shadowgram * assuming that the DAL3JEMX event selection has taken the GTIs * properly into account */ RILlogMessage( NULL, Log_0, "##5100## IJDs: %14.8f %14.8f, chans: %4i %4i", IJDstart, IJDstop, chanMin, chanMax ); /* Initialize the shadowgram */ for(i=0;i i1 ) i1++; RILlogMessage( NULL, Log_0, "##5102## evts-ijd(%ld) = %14.8f, evts-ijd(%ld) = %14.8f", i1, bufevents[i1].ijd, i2, bufevents[i2].ijd ); /* * Loop between the indices and update the shadowgram and calculate the average gain */ gain_sum = 0.0; if( i2 >= i1 && bufevents[i1].ijd >= IJDstart && bufevents[i2].ijd <= IJDstop ) { /* fine! */ shd_adhoc.nEvs = 0; for( i = i1; i <= i2; i++ ) { if( bufevents[i].pi < chanMin || bufevents[i].pi > chanMax ) continue; shd_adhoc.nEvs++; idx = bufevents[i].rawx + bufevents[i].rawy * J_IIR_DIM_STDSHDG; shd_adhoc.shd[idx]++; gain_sum += bufevents[i].gain; } shd_adhoc.gain = gain_sum / shd_adhoc.nEvs; } else { shd_adhoc.nEvs = 0; shd_adhoc.gain = 22.9999; /* presumably not used */ } RILlogMessage( NULL, Log_0, "##5103## nEvs = %ld, gain = %8.4f", shd_adhoc.nEvs, shd_adhoc.gain ); status = fits_test_output( "ad_hoc_shd_", shd_adhoc.shd, 256, logger, chatter, status ); RILlogMessage( NULL, Log_0, "##5104## %d: After fits_test_output", status ); if( status != ISDC_OK ) goto exittrace; /* * Calculate the ontime in seconds for the time-interval */ if( auxdata.n_GTI > 0 ) { /* skip this step if no GTIs were found */ RILlogMessage( NULL, Log_0, "##5105## auxdata.n_GTI = %d", auxdata.n_GTI ); /* step through the GTIs */ ontime = 0.0; for( i = 0; i < auxdata.n_GTI; i++ ) { /* skip this interval if GTI_IJDstop comes before IJDstart */ if( auxdata.GTI_IJDstop[i] < IJDstart ) continue; /* skip this interval and the following if GTI_IJDstart comes after IJDstop */ if( auxdata.GTI_IJDstart[i] > IJDstop ) break; /* The GTI interval starts before IJDstart */ if( auxdata.GTI_IJDstart[i] < IJDstart ) { /* and the GTI interval stops before IJDstop */ if( auxdata.GTI_IJDstop[i] < IJDstop ) { ontime = (auxdata.GTI_IJDstop[i] - IJDstart)/J_IIR_IJDSECOND; RILlogMessage( NULL, Log_0, "##5106## Partial ontime = %9.3lf s", ontime); } else { /* the GTI interval covers the entire period */ ontime = (IJDstop - IJDstart)/J_IIR_IJDSECOND; RILlogMessage( NULL, Log_0, "##5107## Final ontime = %9.3lf s", ontime); break; } } else { /* The GTI interval start after IJDstart */ /* and the GTI interval stops before IJDstop */ if( auxdata.GTI_IJDstop[i] < IJDstop ) { ontime += (auxdata.GTI_IJDstop[i] - auxdata.GTI_IJDstart[i])/J_IIR_IJDSECOND; RILlogMessage( NULL, Log_0, "##5108## Partial ontime = %9.3lf s", ontime); } else { /* the GTI interval stops after IJDstop */ ontime += (IJDstop - auxdata.GTI_IJDstart[i])/J_IIR_IJDSECOND; RILlogMessage( NULL, Log_0, "##5109## Partial ontime = %9.3lf s", ontime); break; } } } } else { /* disregard the GTI information since it is not there */ ontime = (IJDstop - IJDstart)/J_IIR_IJDSECOND; RILlogMessage( NULL, Log_0, "##5110## Final ontime = %9.3lf s", ontime); } shd_adhoc.exposure = ontime; /* preliminary value */ if( ontime > 0.0 ) { /* Start further analysis */ /* * Get the time averaged deadtime (or rather dead-fraction) */ /* Set the timestep to the smaller of 1 s and time-interval/10 */ /* (It is silently assumed that GTIs are of so long durations that we don't need to consider those for the time step.) */ time_step = IJDstop - IJDstart; if( time_step > 10.*J_IIR_IJDSECOND ) { time_step = J_IIR_IJDSECOND; } else if( time_step > J_IIR_IJDSECOND ) { time_step = 0.1*J_IIR_IJDSECOND; } else { time_step *= 0.1; } RILlogMessage( NULL, Log_0, "##5111## time_step (in s) : %8.5lf", time_step/J_IIR_IJDSECOND); RILlogMessage( NULL, Log_0, "##5112## auxdata.n_deadTimes = %d", auxdata.n_deadTimes ); RILlogMessage( NULL, Log_0, "##5113## auxdata.n_greyValues = %d", auxdata.n_greyValues ); deadtime_sum = 0.0; greyfilter_sum = 0.0; i2 = 0; for( time = IJDstart; time <= IJDstop; time += time_step ) { /* are we in a GTI ? - else skip */ flag = 0; if( auxdata.n_GTI > 0 ) { for( i = 0; i < auxdata.n_GTI; i++ ) { if( auxdata.GTI_IJDstart[i] <= time && auxdata.GTI_IJDstop[i] >= time ) { RILlogMessage( NULL, Log_0,"##5114## time = %14.8lf inside GTI #%ld", time, i ); flag = 1; break; } } } else { RILlogMessage( NULL, Log_0,"##5115## Disregarding GTI info" ); flag = 1; /* disregard the GTI information */ } if( !flag ) continue; i2++; /* count the number of accepted times */ /* what dead time applies ? */ status = j_iir_bin_search( (long) auxdata.n_deadTimes, auxdata.deadIJD, time, &i, status ); if( chatter > J_CHATTY_VERBOSE ) RILlogMessage( NULL, Log_0, "##5116## auxdata.deadIJD[%ld] = %14.8lf, dead = %7.4lf", i, auxdata.deadIJD[i], auxdata.deadTime[i] ); deadtime_sum += auxdata.deadTime[i]; /* what greyfilter applies ? */ status = j_iir_bin_search( auxdata.n_greyValues, auxdata.greyTimes, time, &i, status ); if( chatter > J_CHATTY_VERBOSE ) RILlogMessage( NULL, Log_0, "##5117## auxdata.greyTimes[%ld] = %14.8lf, grey = %d", i, auxdata.greyTimes[i], auxdata.greyValues[i] ); greyfilter_sum += (auxdata.greyValues[i] + 1)/32.; } shd_adhoc.exposure *= (1.-deadtime_sum/i2)*(greyfilter_sum/i2); } RILlogMessage( NULL, Log_0, "##5118## Final exposure : %9.3lf", shd_adhoc.exposure); exittrace: 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; } /***************************************************************** * Name of source file: shadowfit.c * Version of source file: 4.0.7 * Parent component: imagefit.c * Programmer: Niels Lund & Niels J. Westergaard * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325700 FAX: +45 35362475 * nl@spacecenter.dk, njw@spacecenter.dk * Purpose: Fit sources in shadowgram and determine flux errors * Origin date: 091221 * Update history: 1.0.0 091221 First version * 4.0.4 120430 SPR ?: Still better flux error estimation * 4.0.7 120710 SPR ?: Flux error estimates as in version 3.2.7 * Type of element: Function * Part of package: j_ima_iros * Name: shadowfit * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ int shadowfit( float shdg[], int jemx, int ee, int n_source, float srcx[], float srcy[], double *solut, int last, double *mrms, struct instr_data *jmx_id, struct log_con *logger, struct backpro *backproj, struct shadowgrams *sh, int chatter, int status ) { int i, j, k1, k2, loclast, src_num, backmodl, m, i5 = 0; int mk1, mk2, q, pixels = 0, index, badcount, negat; short baddistr[detdim]; static double mean[EEMAX+1], var[SCW_SRCMAX], rms[SCW_SRCMAX]; static double m0[SCW_SRCMAX], m1[SCW_SRCMAX], m2[SCW_SRCMAX]; static double obs_sum, obs_sum2, rms2; static double coeffs[SCW_SRCMAX * SCW_SRCMAX], rhs[SCW_SRCMAX], fun_k1; static double coeff2[SCW_SRCMAX * SCW_SRCMAX], rhs2[SCW_SRCMAX]; float funval, empty_sum, sum, eff_sum[SCW_SRCMAX], map_sum[SCW_SRCMAX]; float maxpif, maxeff, maxpifeff, pl_m0[20], pl_m1[20], pl_m2[20], sig, pvar; static int func_local = -1, local_calling_num=0, first = 1; clock_t calling_TT, TT_now; FILE *gnufil; if( status != ISDC_OK ) return( status ); /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "shadowfit"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ if (logger->trace) traces(func_local, 0, logger); if (logger->trace) traces(func_local, n_source, logger); i5 = logger->i5; /* NL 20120122 */ for (i=0; ibackmodels; empty_sum = 0.0; if (n_source <= backmodl) { for (i=0; isoft_gr[i] <= 0.0) continue; /* all pixels to be rejected are <=0 in soft_gr[i] */ m0[n_source] += 1.0; m1[n_source] += shdg[i]; m2[n_source] += shdg[i] * shdg[i]; } backproj->act_pix[ee] = m0[n_source]; empty_sum = m1[n_source]; if (m0[n_source] > 0.0) { mean[ee] = m1[n_source] / m0[n_source]; var[n_source] = m2[n_source] / m0[n_source] - mean[ee] * mean[ee]; rms[n_source] = sqrt(var[n_source]); } else { mean[ee] = 0.0; var[n_source] = 0.0; rms[n_source] = 0.0; } pixels = m0[n_source]; *mrms = var[n_source]; sprintf(logger->tmptxt, "##294## shadowfit: JEM-X%1d, E=%1d, events: %8.0lf, active pix: %7.0lf, cnts/pix: %7.3lf, rms: %7.2lf", jemx+1, ee, m1[n_source], m0[n_source], mean[ee], rms[n_source]); sprintf(logger->tmptxt2, " norm_chk: %e %e", (float)(m0[n_source])/backproj->act_pix[ee], empty_sum); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); if (logger->chatter == 1) logger->logstat = logprint(logger, logger->tmptxt, 4); if( chatter > J_CHATTY_NORMAL ) { RILlogMessage( NULL, Log_0,"##295## FOV_ff = %d", backproj->FOV_ff ); } } /* collect data */ if (logger->trace) traces(func_local, 10, logger); for (src_num=0; src_num 1) && (src_num == last)) loclast = last; if (((srcx[src_num] > 0.0) && (srcx[src_num] < backproj->sky_xdim) && (srcy[src_num] > 0.0) && (srcy[src_num] < backproj->sky_ydim)) || (src_num < 2)); else { sprintf(logger->error_text, "##296## shadowfit-1, bckmdls: %1d, n_source: %2d, " "bad srcx[%2d]: %6.1f, or bad srcy[%2d]: %6.1f", backmodl, n_source, src_num, srcx[src_num], src_num, srcy[src_num]); negat = -2; status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_IMFITERR2; goto return_negative; } if ((src_num == backmodl) && (srcx[backmodl] == 0.0) && (srcy[backmodl] == 0.0)) { sprintf(logger->error_text, "##297## shadowfit-1. Illegal call to fun"); negat = -3; status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_IMFITERR3; goto return_negative; } /* initialize source function */ status = FUN(src_num, 1, ee, srcx, srcy, jemx, loclast, &funval, jmx_id, logger, backproj, chatter, status); if (status != ISDC_OK) { sprintf(logger->error_text, "##298## Negative status (%d) from fun during function" " initialization", status); negat = -10; goto return_negative; } sum = 0.0; for (j=1; jpifeff_maps[src_num][j] >= 0.0) sum += backproj->pifeff_maps[src_num][j]; if (sum == 0.0) { sprintf(logger->error_text, "##299## In shadowfit: sum of src_map zero! src_num: %2d," " srcx: %6.1f, srcy: %6.1f", src_num, srcx[src_num], srcy[src_num]); negat = -4; status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_IMFITERR4; goto return_negative; } } if (logger->trace) traces(func_local, 20, logger); /* n_source = backmodl (currently: 2) means: constant + background model matching energy band */ for (k1=backmodl; k1 0.0) && (srcx[k1] < backproj->sky_xdim) && (srcy[k1] > 0.0) && (srcy[k1] < backproj->sky_ydim)) ; else { sprintf(logger->tmptxt, "##300## shadowfit-3, backmodels: %1d, n_source: %2d," " srcx[%2d]; %6.1f, srcy[%2d]: %6.1f", backmodl, n_source, k1, srcx[k1], k1, srcy[k1]); logger->logstat = logprint(logger, logger->tmptxt, 7); negat = -7; status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_IMFITERR7; goto return_negative; } } if (logger->trace) traces(func_local, 30, logger); for (k1=0; k1fit_funcs[k1][i] = 0.0; if (logger->trace) traces(func_local, 40, logger); for (i=1; isoft_gr[i] <= 0.0) continue; /* all pixels to be rejected are <0 in soft_gr !041018 */ obs_sum += shdg[i]; obs_sum2 += shdg[i] * shdg[i]; logger->fit_funcs[BASIC_SRCMAX+0][i] = shdg[i]; logger->fit_funcs[BASIC_SRCMAX+2][i] = backproj->effic[i]; for (k1=0; k1error_text, "##301## shadowfit-2. Illegal call to fun"); negat = -5; status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_IMFITERR5; goto return_negative; } if (backproj->pifeff_maps[k1][i] > 0.0) { m0[k1] += 1.0; map_sum[k1] += backproj->pif_maps[k1][i]; /* 'map_sum' accumulates 'pif_maps' without the 'effic' correction */ eff_sum[k1] += backproj->pif_maps[k1][i] * backproj->effic[i]; /* 'eff_sum' accumulates 'pifeff_maps' including the 'effic' correction */ } empty_sum = 0.0; if (k1 == 0) fun_k1 = 1.0 / backproj->act_pix[ee]; if (k1 == 1) { fun_k1 = backproj->empty_norm[i]; empty_sum += fun_k1; } if (k1 > 1) { if (backproj->norm_d[k1][ee] >= 0.0) fun_k1 = backproj->pifeff_maps[k1][i]; else fun_k1 = 0.0; } rhs[k1] += fun_k1 * shdg[i]; for (k2=k1; k2act_pix[ee]; if (k2 == 1) funval = backproj->empty_norm[i]; if (k2 > 1) { if (backproj->norm_d[k2][ee] >= 0.0) funval = backproj->pifeff_maps[k2][i]; else funval = 0.0; } coeffs[k1 + n_source*k2] += fun_k1 * funval; } } } if (logger->trace) traces(func_local, 60, logger); for (k1=0; k1 0.0) backproj->src_effic[k1] = eff_sum[k1] / map_sum[k1]; else backproj->src_effic[k1] = 1.0; } sprintf(logger->tmptxt, "In shadowfit: act_pix: %6.2f, [soft_gr>0]: %6.2f", backproj->act_pix[ee], m0[0]); if (logger->chatter == 1) logger->logstat = logprint(logger, logger->tmptxt, 5); logger->logstat = logprint(logger, logger->tmptxt, i5); for (k1=0; k1tmptxt, " "); for (k2=0; k2tmptxt2, " %lf", coeffs[k1*n_source+k2]); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } } if (rhs[k1] == 0.0) { logger->logstat = logprint(logger, logger->tmptxt, 0); sprintf(logger->tmptxt, "##302## rhs: %lf Source %2d" " is suspicious!", rhs[k1], k1); logger->logstat = logprint(logger, logger->tmptxt, 6); } } if (logger->trace) traces(func_local, 70, logger); if (n_source == 2) { for (k1=0; k1tmptxt, "##7123## shadowfit, background fit matrix: "); for (k2=0; k2tmptxt2, " %le", coeffs[k1*n_source+k2]); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } sprintf(logger->tmptxt2, " rhs: %lf", rhs[k1]); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); logger->logstat = logprint(logger, logger->tmptxt, i5); } } if (logger->trace) traces(func_local, 80, logger); /* for (i=0; itmptxt, "shadowfit0 %1d rhs: %8.4f, matrix: ", i, rhs[i]); for (j=0; jtmptxt2, " %8.5f", coeffs[i+n_source*j] * 1000.0); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } logger->logstat = logprint(logger, logger->tmptxt, i5); } sprintf(logger->tmptxt, "shadowfit0 9 solut"); logger->logstat = logprint(logger, logger->tmptxt, i5); */ /* SOLVE SOLVE SOLVE solve the equation system SOLVE SOLVE SOLVE */ status = gaussj_nr(coeffs, n_source, rhs, 1, logger); if (logger->trace) traces(func_local, 90, logger); if (status < 0) { sprintf(logger->error_text, "##303## In 'shadowfit': singular matrix I with %d components." " Status: %2d", n_source, status); negat = -33; status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_SNGLMTX; goto return_negative; } for (i=0; itmptxt, "shadowfit1 %1d solut: %8.2f ", i, rhs[i]); logger->logstat = logprint(logger, logger->tmptxt, i5); } if (logger->trace) traces(func_local, 100, logger); for (k1=0; k1tmptxt, "##7123## shadowfit, E: %1d, shadowgram counts: %7.0f, solution: %lf\n", ee, obs_sum, solut[k1]); logger->logstat = logprint(logger, logger->tmptxt, i5); } } m = 0; sh->resid[0] = 0.0; for (i=1; iresid[i] = 0.0; sh->backcmp[i] = 0.0; sh->backall[i] = 0.0; if (backproj->soft_gr[i] <= 0.0) continue; /* all pixels to be rejected are <0 in soft_gr !041018 */ m++; sh->resid[i] = shdg[i]; sh->backcmp[i] = solut[0] / backproj->act_pix[ee] + solut[1] * backproj->empty_norm[i]; for (k1=0; k1act_pix[ee]; if (k1 == 1) funval = backproj->empty_norm[i]; if (k1 > 1) { if (backproj->norm_d[k1][ee] >= 0.0) funval = backproj->pifeff_maps[k1][i]; else funval = 0.0; } sh->backall[i] += solut[k1] * funval; if (k1 == n_source-1) backproj->current_src_map[i] = solut[k1] * funval; if (k1 < BASIC_SRCMAX) logger->fit_funcs[k1][i] = funval; } sh->resid[i] -= sh->backall[i]; sh->resid[0] += sh->resid[i]; } for (i=1; isoft_gr[i] <= 0.0) continue; logger->fit_funcs[BASIC_SRCMAX+1][i] = sh->resid[i]; } if (logger->trace) traces(func_local, 110, logger); sprintf(logger->tmptxt, "##304## In shadowfit: act_pix: %d, residual sum: %8.4e", m, sh->resid[0]); logger->logstat = logprint(logger, logger->tmptxt, i5); sh->resid[0] = 0.0; /* calculate rms value from matrix used in the fit */ rms2 = obs_sum2; if (logger->trace) traces(func_local, 10000+n_source, logger); if (logger->trace) traces(func_local, 1000+last, logger); for (k1=0; k1error_text, "##306## In 'shadowfit': negative" " variance after fit: %10.1lf", rms2); negat = -6; status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_IMFITERR6; goto return_negative; } *mrms = rms2; if (last) { sprintf(logger->tmptxt, "##504## callng errorfit. ee: %2d", ee); logger->logstat = logprint(logger, logger->tmptxt, i5); if (logger->trace) traces(func_local, 65, logger); if (logger->trace) traces(func_local, 6500+backproj->backmodels, logger); if (logger->trace) traces(func_local, 65000+n_source, logger); status = errorfit(n_source, obs_sum2, rms2, rhs2, coeff2, solut, m0, backproj, logger, status); if (logger->trace) traces(func_local, 67000+n_source, logger); if (status < 0) { sprintf(logger->error_text, "##307## status error %d on return from 'errorfit'", status); negat = -34; status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_SNGLMTX; goto return_negative; } if (backproj->additional < 0) { if (logger->trace) traces(func_local, 70, logger); if (logger->trace) traces(func_local, 7000+backproj->backmodels, logger); if (logger->trace) traces(func_local, 70000+n_source, logger); for (k1=backproj->backmodels; k1trace) traces(func_local, 80, logger); status = j_pif_limits2(n_source-1, backproj, logger, status ); } /* status = errorfit2(n_source, backproj, logger, status); */ } status = ISDC_OK; escape: ; /* escape: ; */ 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 ); return_negative: /* return_negative: */ logger->logstat = logprint(logger, logger->error_text, i5); if (logger->trace) traces(func_local, 1000-negat, logger); if (logger->trace) traces(func_local, 999, logger); goto escape; } /* **************************************************************** * Name of source file: fluxerror.c * Version of source file: 4.0.7 * Parent component: None * Programmer: Niels Lund * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325716 FAX: +45 35362475 * nl@dnsc.dk * Purpose: calc flux error estimates based on sky_image analysis * Origin date: 20100129 * Update history: 1.0.0 20100129 First version * 4.0.7 120710 SPR ?: Flux error estimates as in version 3.2.7 * Type of element: Function * Part of package: j_ima_iros * Name: fluxerror * Required components: DAL, PIL, RIL, DAL3GEN **************************************************************** */ int fluxerror( int eeuser, int N_src, float peakval[2*EE256][SCW_SRCMAX], struct log_con *logger, struct backpro *backproj, struct shadowgrams *sh, goodsrc *GOODSRC, int status ) { int i, i5 = 0, jb, ee3; int nsrc, o_src_good; float exposure, Apix, rawcount; float Anoise = 0.5; /* estimated uncertainty on the Apix value (cm2) */ 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], "fluxerror"); 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); i5 = logger->i5; /* NL 20120122 */ jb = backproj->backmodels; /* for (nsrc=0; nsrc<=N_src; nsrc++) { */ for (nsrc=0; nsrcadditional >= 0) o_src_good = backproj->additional; * else continue; * } */ exposure = sh->accumT * GOODSRC[o_src_good].src_pixel_area[eeuser]; if (logger->trace) traces(func_local, (int)(10000+N_src), logger); if (logger->trace) traces(func_local, (int)(20000+o_src_good), logger); if (logger->trace) traces(func_local, (int)(30000+eeuser), logger); if (logger->trace) traces(func_local, (int)(100000+sh->accumT), logger); if (logger->trace) traces(func_local, (int)(200000+GOODSRC[o_src_good].src_pixel_area[eeuser]), logger); if (logger->trace) traces(func_local, (int)(300000+GOODSRC[o_src_good].fit_peakval[eeuser]), logger); if (logger->trace) traces(func_local, (int)(400000+GOODSRC[o_src_good].fit_backval[eeuser]), logger); if (exposure > 0.0) { /* * New derivation of absolute flux error: * * abs_error = sqrt(total_count_in peak) + (Anoise / src_pix_area) * fabs(signal_count_in peak) * * Assuming an error of Anoise cm2 on the area of the pixels that contribute to the source. * This is due to the imperfect modelling of the instrument geometrical response and * it becomes increasingly important towards the edge of the FOV [2005-05-20/NL & NJW] * */ if( GOODSRC[o_src_good].src_pixel_area[eeuser] > 0.0) { rawcount = GOODSRC[o_src_good].fit_peakval[eeuser]; Apix = GOODSRC[o_src_good].src_pixel_area[eeuser]; GOODSRC[o_src_good].flux_err[eeuser] = sqrt(rawcount) + (Anoise / Apix) * fabs(GOODSRC[o_src_good].fit_backval[eeuser]); GOODSRC[o_src_good].flux_err[eeuser] *= 100 / exposure; sprintf(logger->tmptxt, "##117## E%02d src#%d, rawcount: %7.1f, pkcnt: (raw img.) %7.1f, Apix: %5.1f, flux: %6.2f, flux_err: %6.3f , exposure: %7.0f", eeuser, o_src_good, rawcount, GOODSRC[o_src_good].fit_backval[eeuser], Apix, GOODSRC[o_src_good].flux[eeuser], GOODSRC[o_src_good].flux_err[eeuser], exposure); logger->logstat = logprint(logger, logger->tmptxt, i5); continue; } else { status = -1; goto poor_data; } } else status = -2; poor_data: GOODSRC[o_src_good].flux_err[eeuser] = -9.99; goto exittrace; } 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 ); exittrace: /* exittrace */ if (logger->trace) traces(func_local, 1000-status, logger); goto slut; } /***************************************************************** * Name of source file: errorfit.c * Version of source file: 4.0.12 * Parent component: imagefit.c * Programmer: Niels Lund & Niels J. Westergaard * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325700 FAX: +45 35362475 * nl@spacecenter.dk, njw@spacecenter.dk * Purpose: Determine errors in fited fluxes * Origin date: 091222 * Update history: 1.0.0 091222 First version * 4.0.4 120430 SPR ?: Still better flux error estimation * 4.0.12 120919 SPR ?: Introduce corrections by LP and Co. * Type of element: Function * Part of package: j_ima_iros * Name: errorfit * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ int errorfit( int n_source, double obs_sum2, double origrms2, double rhs[], double coeffs[], double solut[], double m0[], struct backpro *backproj, struct log_con *logger, int status) { int i, j, k1, k11, k2, src_num, m, q, mk1, mk2; int i5 = 5, iter=0, n_trial, imin = 0, imin2; double var, rms, rms2, newfit, rmsorig, rmsnew, rmslocal; static double RMS[25], FLUX[25]; double RMS_WANT, TRIAL_FLUX, dmin, dmin2, sign=-1.0; static double coeff2[SCW_SRCMAX * SCW_SRCMAX], rhs2[SCW_SRCMAX]; static double m_coeff[SCW_SRCMAX * SCW_SRCMAX], m_rhs[SCW_SRCMAX]; static double take_away_var[SCW_SRCMAX]; static double localsolut[SCW_SRCMAX], locrms2; static int func_local = -1, local_calling_num=0, first = 1; clock_t calling_TT, TT_now; if( status != ISDC_OK ) return( status ); /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "errorfit"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ if (logger->trace) traces(func_local, 0, logger); for (q=0; qerrsolut[q] = -8.88; if ((n_source > SCW_SRCMAX) || (n_source < 0.0)) { sprintf(logger->error_text, "##316## In 'errorfit': Bad n_source value: %d", n_source); /* negat = -35; */ status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_SNGLMTX; goto return_negative; } /* save rhs and coeffs before calling 'gaussj_nr' */ for (k1=0; k1error_text, "##317## In 'errorfit': singular matrix II with %d" " components. Status: %2d", n_source-1, status); /* negat = -35; */ status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_SNGLMTX; goto return_negative; } if (logger->trace) traces(func_local, 10, logger); /* calculate new rms value from matrix used in the fit */ rms2 = obs_sum2; for (k1=0; k1 0.0) rmslocal = rms2; else {status = -1; goto return_negative;} /* QQQQQ */ /* calculate rms-values for fits with sequential removal of one source */ sprintf(logger->tmptxt, "errorfitw, input solut: "); for (q=0; qtmptxt2, " %8.1f", solut[q]); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } logger->logstat = logprint(logger, logger->tmptxt, i5); sprintf(logger->tmptxt, "errorfitw, local solut: "); for (q=0; qtmptxt2, " %8.1f", localsolut[q]); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } logger->logstat = logprint(logger, logger->tmptxt, i5); /* recover original coefficient matrix */ for (k1=0; k1= q) mk1++; m_rhs[k1] = rhs[mk1]; for (k2=0; k2= q) mk2++; m_coeff[k1 + (n_source-1)*k2] = coeffs[mk1 + n_source*mk2]; /* source 'q' is removed from the m_rhs and m_coeff arrays in this loop */ } } /* save m_rhs and m_coeff before calling 'gaussj_nr' */ for (k1=0; k1error_text, "##307## In 'errorfit': singular matrix II with %d" " components. Status: %2d", n_source-1, status); /* negat = -35; */ status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_SNGLMTX; goto return_negative; } if (logger->trace) traces(func_local, 20, logger); /* calculate new rms value from matrix used in the fit */ rms2 = obs_sum2; for (k1=0; k1 0.0) rmsnew = rms2; else {status = -2; goto return_negative;} if (logger->trace) traces(func_local, 22, logger); if (q < backproj->backmodels) continue; /* skip error calculation for background components of fit */ if (logger->trace) traces(func_local, 24, logger); /* QQQQQ */ /* initiate iterative search for error estimate */ sign = -1.0; init_search: RMS[0] = rmslocal; FLUX[0] = localsolut[q]; RMS_WANT = rmslocal + 1.0; iter = 0; if (sign < 0.0) { RMS[1] = rmsnew; FLUX[1] = 0.0; n_trial = 2; if (logger->trace) traces(func_local, 26, logger); } else { TRIAL_FLUX = fabs(localsolut[0]) + fabs(localsolut[1]) + fabs(localsolut[q]); n_trial = 1; iter++; if (logger->trace) traces(func_local, 28, logger); goto calc_rms; } next_iteration: ; iter++; if (logger->trace) traces(func_local, 30, logger); if (logger->trace) traces(func_local, 3000+iter, logger); dmin = 10000000.0; dmin2 = 10000000.0; /* find the trial closest to desired rms-value */ for (i=0; itmptxt, "errorfitx trial: %2d, i: %2d, RMSorig: %8.1f, RMSwant: %6.1f, RMS[%2d]: %8.1f, FLUX[%2d]: %8.1f, imin: %2d", n_trial, i, RMS[0], RMS_WANT, i, RMS[i], i, FLUX[i], imin); logger->logstat = logprint(logger, logger->tmptxt, i5); } if (fabs(dmin) < 0.05) goto finished; if (iter >= 20) goto finished; imin2 = -1; if (dmin < 0.0) { /* search other trial just below desired rms-value */ for (i=0; i 0.0) && ((RMS_WANT - RMS[i]) <= dmin2)) { imin2 = i; dmin2 = RMS_WANT - RMS[i]; } } if (logger->trace) traces(func_local, 40, logger); } else { /* search other trial just above desired rms-value */ for (i=0; i 0.0) && ((RMS[i] - RMS_WANT) <= dmin2)) { imin2 = i; dmin2 = RMS[i] - RMS_WANT; } } if (logger->trace) traces(func_local, 42, logger); } if (imin2 < 0) { if (n_trial == 2) imin2 = 1 - imin; else { status = -3; goto return_negative; } } /* check if selected trial cases are both on the same side of 'RMS_WANT' */ if ((RMS_WANT - RMS[imin])*(RMS_WANT - RMS[imin2]) > 0.0) { TRIAL_FLUX = sign * (fabs(localsolut[0]) + fabs(localsolut[1])); if (logger->trace) traces(func_local, 50, logger); } else { TRIAL_FLUX = 0.5 * (FLUX[imin] + FLUX[imin2]); if (logger->trace) traces(func_local, 52, logger); } /* QQQQQ */ calc_rms: /* recover matrices prior to last call to 'gaussj_nr */ for (k1=0; k1= q) k11 = k1+1; m_rhs[k1] -= TRIAL_FLUX * coeffs[q + k11*n_source]; } if (logger->trace) traces(func_local, 60, logger); /* SOLVE */ status = gaussj_nr(m_coeff, n_source-1, m_rhs, 1, logger); if (status < 0) { sprintf(logger->error_text, "##307## In 'errorfit': singular matrix III with %d" " components. Status: %2d", n_source-1, status); /* negat = -35; */ status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_SNGLMTX; if (logger->trace) traces(func_local, 69, logger); goto return_negative; } if (logger->trace) traces(func_local, 70, logger); /* QQQQQ */ /* set up solution matrices for all 'n_source' sources prior to rms-calculation */ for (k1=n_source-1; k1>=0; k1--) { mk1 = k1; if (k1 >= q) mk1++; m_rhs[mk1] = m_rhs[k1]; /* make room for source q coefficient */ } m_rhs[q] = TRIAL_FLUX; /* insert value for source q coefficient */ /* now calculate new rms using all 'n_source' fit coefficients */ rms2 = obs_sum2; for (k1=0; k1trace) traces(func_local, 72, logger); if (rms2 > 0.0) rmsnew = rms2; else {status = -4; goto return_negative;} if (logger->trace) traces(func_local, 74, logger); RMS[n_trial] = rmsnew; FLUX[n_trial] = TRIAL_FLUX; n_trial++; goto next_iteration; /* QQQQQ */ finished: backproj->errsolut[q] = fabs(FLUX[imin] - localsolut[q]); sign = 1.0; sprintf(logger->tmptxt, "final errfit. src: %2d, orig/local rms: %7.1f %7.1f, flux: %7.1f %7.1f, flux_error: %7.1f, imin: %2d, Fimin: %7.1f\n", q, rmsorig, rmslocal, solut[q], localsolut[q], backproj->errsolut[q], imin, FLUX[imin]); logger->logstat = logprint(logger, logger->tmptxt, i5); } status = ISDC_OK; escape: ; 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 ); return_negative: logger->logstat = logprint(logger, logger->error_text, 6); if (logger->trace) traces(func_local, 999, logger); goto escape; } /***************************************************************** * Name of source file: errorfit2.c * Version of source file: 1.0.0 * Parent component: errorfit.c * Programmer: Niels Lund & Niels J. Westergaard * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325700 FAX: +45 35362475 * nl@spacecenter.dk, njw@spacecenter.dk * Purpose: Determine errors in fited fluxes * Origin date: 091222 * Update history: 1.0.0 20100120 First version * Type of element: Function * Part of package: j_ima_iros * Name: errorfit2 * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ int errorfit2( int n_source, struct backpro *backproj, struct log_con *logger, int status) { int i, j, nsrc, i5 = 0; double sum, signal_counts, backgr_counts; double abs_error_s_counts, divisor_counts; double abs_error_b_counts; double flux_counts, pix_ratio; double abs_variance_flux_counts; double temp; static int func_local = -1, local_calling_num=0, first = 1; clock_t calling_TT, TT_now; if( status != ISDC_OK ) return( status ); /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "errorfit2"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ i5 = logger->i5; /* NL 20120122 */ if (logger->trace) traces(func_local, 0, logger); backproj->errsolut2[ 0] = 0.0; backproj->errsolut2[ 1] = 0.0; for (nsrc=backproj->backmodels; nsrcerrsolut2[nsrc] = 99.99; backproj->abs_error[nsrc] = 999.0; backproj->flux_counts[nsrc] = 0.0; if (logger->trace) traces(func_local, 10, logger); sprintf(logger->tmptxt, "errorfit2# src: %2d, source/background pixels: %6d %6d", nsrc, backproj->pif_spix[nsrc], backproj->pif_bpix[nsrc]); logger->logstat = logprint(logger, logger->tmptxt, i5); if (backproj->pif_bpix[nsrc] == 0) continue; if (logger->trace) traces(func_local, 20, logger); signal_counts = backgr_counts = 0.0; pix_ratio = (double)(backproj->pif_spix[nsrc]) / (double)(backproj->pif_bpix[nsrc]); for (i=0; iskydim; i++) { if (backproj->soft_gr[i] <= 0.0) continue; signal_counts += (float)(backproj->pif_s_pickmap[nsrc][i]) * backproj->shadw[i]; backgr_counts += (float)(backproj->pif_b_pickmap[nsrc][i]) * backproj->shadw[i]; } if (logger->trace) traces(func_local, 21, logger); abs_error_s_counts = sqrt(abs(signal_counts) + 1.0); if (logger->trace) traces(func_local, 22, logger); abs_error_b_counts = sqrt(abs(backgr_counts) + 1.0); if (logger->trace) traces(func_local, 23, logger); temp = abs_error_s_counts*abs_error_s_counts + abs_error_b_counts*abs_error_b_counts * pix_ratio * pix_ratio * pix_ratio * pix_ratio; if (temp > 0.0) abs_variance_flux_counts = sqrt(temp); else continue; if (logger->trace) traces(func_local, 24, logger); backproj->abs_error[nsrc] = sqrt(abs_variance_flux_counts); backproj->flux_counts[nsrc] = signal_counts - backgr_counts * pix_ratio; if (backproj->flux_counts[nsrc] > abs_error_s_counts) divisor_counts = backproj->flux_counts[nsrc]; else divisor_counts = abs_error_s_counts; backproj->errsolut2[nsrc] = 1.0 + sqrt(abs_variance_flux_counts * abs_variance_flux_counts / divisor_counts * divisor_counts + 0.0002); if (logger->trace) traces(func_local, 30, logger); if (backproj->errsolut2[nsrc] > 99.99) { backproj->errsolut2[nsrc] = 99.99; if (logger->trace) traces(func_local, 50, logger); } } status = ISDC_OK; escape: ; 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 ); return_negative: logger->logstat = logprint(logger, logger->error_text, 6); if (logger->trace) traces(func_local, 999, logger); goto escape; } /***************************************************************** * Name of source file: calibout.c * Version of source file: 4.0.12 * Parent component: None * Programmer: Niels Lund & Niels J. Westergaard * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325705 FAX: +45 35362475 * njw@dnsc.dk * Purpose: Output data relevant for alignment and parameter adjustment for j_ima_iros. * Origin date: 070809 * Update history: 2.1.0 070809 First version * 2.2.0 071205 Flux determination has been improved * 2.2.1 071205 SPR 4742: Division by zero eliminated * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 4.0.5 120607 SPR ?: Still better flux error estimation * 4.0.12 120919 SPR ?: Introduce corrections by LP and Co. * Type of element: Function * Part of package: j_ima_iros * Name: calibout * Calls: * Returns: * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ /* **************************************************************************************** */ /* QQQQQQ */ int calibout( int jsrc, int n_common2, int ee_basic, int vigncorr, float diff_x, float diff_y, double solut0, double solut1, double solut2, float resid_data_peak0, float resid_data_peak1, float resid_data_peak2, char calibname[], dal_element *theSWG, /* pointer to the SWG */ swg_pointing *point, struct instr_data *jmx_id, struct log_con *logger, struct backpro *backproj, struct scwlist *SCWnow, struct shadowgrams *sh, goodsrc *GOODSRC, int chatter, int status ) { char cname2[32]; int i, i5 = 0; float flux, flux_err, check=1.0; static int first = 1; static long len_scw, len_src, len_pnt; outscw OUTSCW; /* structure containing all information about a science window */ outsrc OUTSRC; /* structure containing all information about a detected source */ FILE *calib, *calib2; 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], "calibout"); 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); if (jsrc == 0) { calib = fopen(calibname, "wb"); if (calib == NULL) { sprintf(logger->tmptxt, "could not open %s", calibname); logger->logstat = logprint(logger, logger->tmptxt, 0); return(-1); } len_scw = sizeof(outscw); len_src = sizeof(outsrc); len_pnt = sizeof(swg_pointing); sprintf(logger->tmptxt, "opened %s, sizeof(id_data): %8d, sizeof(scw data): %5ld, sizeof(src_data): %5ld, sizeof(point): %5ld", calibname, logger->len_jmx_id, len_scw, len_src, len_pnt); logger->logstat = logprint(logger, logger->tmptxt, 0); fwrite((struct instr_data*)(jmx_id), logger->len_jmx_id, 1, calib); fwrite(&(backproj->FOV_radius), 4, 1, calib); fwrite(&(backproj->indep), 8, 1, calib); i = logger->pix_fold_ctrl*1000000 + logger->develop; fwrite(&i, 4, 1, calib); fwrite(&vigncorr, 4, 1, calib); fwrite(&(sh->eval[0][0]), 8, 1, calib); fwrite(&(sh->eval[0][1]), 8, 1, calib); fwrite(&(sh->eval[1][0]), 8, 1, calib); fwrite(&(sh->eval[1][1]), 8, 1, calib); fwrite(&(sh->eval[2][0]), 8, 1, calib); fwrite(&(sh->eval[2][1]), 8, 1, calib); OUTSCW.orbit = backproj->aux_orbit; OUTSCW.pid = backproj->aux_pid; OUTSCW.pidv = backproj->aux_pidv; OUTSCW.p_RA = SCWnow->pointing_RA; OUTSCW.p_dec = SCWnow->pointing_dec; OUTSCW.p_rol = SCWnow->roll_angle; OUTSCW.J_RA = SCWnow->jmxRA; OUTSCW.J_dec = SCWnow->jmxdec; OUTSCW.accumT = sh->accumT; OUTSCW.totcn0 = sh->totcnt[0]; OUTSCW.totcn1 = sh->totcnt[1]; OUTSCW.totcn2 = sh->totcnt[2]; OUTSCW.solut0 = solut0; OUTSCW.solut1 = solut1; OUTSCW.stopc0 = backproj->stopcode[0]; OUTSCW.stopc1 = backproj->stopcode[1]; OUTSCW.stopc2 = backproj->stopcode[2]; OUTSCW.ncom2 = n_common2;; OUTSCW.Tx0 = jmx_id->Tx0; OUTSCW.offTx0 = jmx_id->off_Tx0; OUTSCW.Tx7 = jmx_id->Tx7; OUTSCW.offTx7 = jmx_id->off_Tx7; fwrite(&OUTSCW, len_scw, 1, calib); fwrite((swg_pointing*)(point), len_pnt, 1, calib); sprintf(cname2, "flux_%04d%04d%04d.txt", backproj->aux_orbit, backproj->aux_pid, backproj->aux_pidv); calib2 = fopen(cname2, "wt"); fprintf(calib2, "%2d %7.3f %7.3f %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f\n", n_common2, GOODSRC[jsrc].RA, GOODSRC[jsrc].dec, (GOODSRC[jsrc].xx - backproj->FOV_radius) * backproj->pix2mm, (GOODSRC[jsrc].yy - backproj->FOV_radius) * backproj->pix2mm, sh->accumT, sh->totcnt[0], sh->totcnt[1], sh->totcnt[2]); /* * GOODSRC[SCW_SRCMAX-2].src_strength[eeuser] = solut[0]; * GOODSRC[SCW_SRCMAX-2].errsolut[eeuser] = backproj->errsolut[0]; * GOODSRC[SCW_SRCMAX-1].src_strength[eeuser] = solut[1]; * GOODSRC[SCW_SRCMAX-1].errsolut[eeuser] = backproj->errsolut[1]; */ for (i=0; inumShds; i++) { flux = GOODSRC[jsrc].flux[i]; flux_err = GOODSRC[jsrc].errsolut[i]; if (fabs(flux > 0.001)) check = 2.0 * flux_err; else flux_err = check; fprintf(calib2, "%2d %f %f %7.3f\n", i, flux, flux_err, sh->totcnt[i]); } fclose(calib2); } else { calib = fopen(calibname, "ab"); } OUTSRC.xx = (GOODSRC[jsrc].xx - backproj->FOV_radius) * backproj->pix2mm; OUTSRC.yy = (GOODSRC[jsrc].yy - backproj->FOV_radius) * backproj->pix2mm; OUTSRC.diff_x = diff_x * backproj->pix2mm; OUTSRC.diff_y = diff_y * backproj->pix2mm; OUTSRC.RA = GOODSRC[jsrc].RA; OUTSRC.dec = GOODSRC[jsrc].dec; OUTSRC.catRA = GOODSRC[jsrc].catRA; OUTSRC.catdec = GOODSRC[jsrc].catdec; OUTSRC.preset = GOODSRC[jsrc].preset; OUTSRC.detects = GOODSRC[jsrc].detects; OUTSRC.s_detec = backproj->s_detect[GOODSRC[jsrc].src_id]; OUTSRC.px_are0 = GOODSRC[jsrc].src_pixel_area[0]; OUTSRC.px_are1 = GOODSRC[jsrc].src_pixel_area[1]; OUTSRC.px_are2 = GOODSRC[jsrc].src_pixel_area[2]; for (i=0; i<16; i++) { OUTSRC.flux[i] = GOODSRC[jsrc].flux[i+3]; OUTSRC.fluxer[i] = GOODSRC[jsrc].flux_err[i+3]; OUTSRC.fluxer2[i] = GOODSRC[jsrc].flux_err2[i+3]; OUTSRC.src_effic[i] = GOODSRC[jsrc].src_effic[i+3]; OUTSRC.sn[i] = GOODSRC[jsrc].sn[i+3]; } OUTSRC.res_pk0 = resid_data_peak0; OUTSRC.res_pk1 = resid_data_peak1; OUTSRC.res_pk2 = resid_data_peak2; OUTSRC.solut0 = solut0; OUTSRC.solut1 = solut1; OUTSRC.solut2 = solut2; fwrite(&OUTSRC, len_src, 1, calib); if (first++ < 10) i5 = 1 - 1; i5 = logger->i5; /* NL 20120122 */ sprintf(logger->tmptxt, "orb %4d %3d %3d src %2d Tx0/off %7.3f %7.3f Tx7/off %7.3f %7.3f x/y %7.3f %7.3f RA/dec %7.3f %7.3f\n", OUTSCW.orbit, OUTSCW.pid, OUTSCW.pidv, OUTSCW.ncom2, OUTSCW.Tx0, OUTSCW.offTx0, OUTSCW.Tx7, OUTSCW.offTx7, OUTSRC.xx, OUTSRC.yy, OUTSRC.RA, OUTSRC.dec); logger->logstat = logprint(logger, logger->tmptxt, i5); fclose(calib); 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(0); } /***************************************************************** * Name of source file: initGOOD.c * Version of source file: 1.0.0 * Parent component: None * Programmer: Niels Lund * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325716 FAX: +45 35362475 * nl@dnsc.dk * Purpose: print summary of source found and fit coefficients * Origin date: 20100210 * Update history: 1.0.0 20100210 First version * Type of element: Function * Part of package: j_ima_iros * Name: initGOOD * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ /* QQQQQQ */ int initGOOD( goodsrc *GOODSRC, struct log_con *logger, int status ) { int i, i5; 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], "initGOOD"); 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); i5 = logger->i5; /* BEGIN */ GOODSRC[logger->N_SRC2].scw_ID = 0; GOODSRC[logger->N_SRC2].xx = 0.0; GOODSRC[logger->N_SRC2].yy = 0.0; GOODSRC[logger->N_SRC2].catxx = 0.0; GOODSRC[logger->N_SRC2].catyy = 0.0; GOODSRC[logger->N_SRC2].RA = 0.0; GOODSRC[logger->N_SRC2].dec = 0.0; GOODSRC[logger->N_SRC2].catRA = 0.0; GOODSRC[logger->N_SRC2].catdec = 0.0; GOODSRC[logger->N_SRC2].diff_x = 0.0; GOODSRC[logger->N_SRC2].diff_y = 0.0; GOODSRC[logger->N_SRC2].srcnum = 0; GOODSRC[logger->N_SRC2].src_id = 0; GOODSRC[logger->N_SRC2].preset = 0; GOODSRC[logger->N_SRC2].detects = 0; for (i=0; iN_SRC2].src_strength[i] = 0.0; GOODSRC[logger->N_SRC2].src_pixel_area[i] = 0.0; GOODSRC[logger->N_SRC2].src_backgr_area[i] = 0.0; GOODSRC[logger->N_SRC2].variance_on_src_str[i] = 0.0; GOODSRC[logger->N_SRC2].sn[i] = 0.0; GOODSRC[logger->N_SRC2].sn2[i] = 0.0; GOODSRC[logger->N_SRC2].flux[i] = 0.0; GOODSRC[logger->N_SRC2].flux_err[i] = 0.0; GOODSRC[logger->N_SRC2].flux_err2[i] = 0.0; GOODSRC[logger->N_SRC2].src_effic[i] = 0.0; GOODSRC[logger->N_SRC2].avg_gain[i] = 0.0; GOODSRC[logger->N_SRC2].transmis[i] = 0.0; GOODSRC[logger->N_SRC2].errsolut[i] = 0.0; GOODSRC[logger->N_SRC2].errsolut2[i] = 0.0; GOODSRC[logger->N_SRC2].errsolut0[i] = 0.0; GOODSRC[logger->N_SRC2].mean_bkg[i] = 0.0; GOODSRC[logger->N_SRC2].peakval[i] = 0.0; GOODSRC[logger->N_SRC2].fit_peakval[i] = 0.0; GOODSRC[logger->N_SRC2].fit_backval[i] = 0.0; } /* END */ 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 ); exittrace: /* exittrace */ if (logger->trace) traces(func_local, 1000-status, logger); goto slut; /* * sprintf(logger->tmptxt2, " 'develop' ctrl param: %4d", logger->develop); * if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) * strcat(logger->tmptxt, logger->tmptxt2); * logger->logstat = logprint(logger, logger->tmptxt, i5); */ } /* * **************************************************************** * COMMENT ONLY ! *typedef struct { * stucture containing information * about source candidates found * * * unsigned scw_ID; * science window data_ID (establishes unique correspondence with 'scwlist' * * float xx; * source detector x-coordinate * * float yy; * source detector y-coordinate * * float catxx; * source detector x-coordinate corresp. to catalog pos. - preset src only * * float catyy; * source detector y-coordinate corresp. to catalog pos. - preset src only * * float RA; * source RA found by ima_iros (J2000) * * float dec; * source dec found by ima_iros (J2000)* * float catRA; * source RA from catalog - if source is preset (J2000) * * float catdec; * source dec from catalog - if source is preset (J2000)* * float diff_x; * deviation between expected and found source position * * float diff_y; * (for identified sources only) * * int srcnum; * running number of sources found * * int src_id; * source id = running number in user supplied catalog * * int preset; * indicator for pre-selected source coordinates * * int detects; * detection flags from source search * * * float src_strength[EE256]; * fitted source strength (cts/c/cm2/keV) (using pos. found from this energy band) * * float src_pixel_area[EE256]; * flux collection area for this source * * float src_backgr_area[EE256]; * area for background evaluation * * float variance_on_src_str[EE256]; * variance on source strength (cts/c/cm2/keV)**2 * * float sn[EE256]; * best signal to noise value among energy bands (relative to original sky_image) * * float sn2[EE256]; * best signal to noise value among energy bands (relative to residual sky_image) * * float flux[EE256]; * Derived flux value * * float flux_err[EE256]; * Derived flux error based on sky-image analysis (from 'fluxerror') * * float flux_err2[EE256]; * Derived flux error value * * float src_effic[EE256]; * Electronic efficiency * * float avg_gain[EE256]; * Average gain * * float transmis[EE256]; * Energy dependent correction factor for collimator transmission * * double errsolut[EE256]; * fractional error on flux (from 'errorfit') * * double errsolut2[EE256]; * fractional error on flux (from 'errorfit2') * * double errsolut0[EE256]; * fractional error on flux based on sky-image analysis (from 'fluxerror') * * float mean_bkg[EE256]; * background counts (from variance map) corresponding to this source * * float peakval[EE256]; * number of counts in peak * * float fit_peakval[EE256]; * number of counts in peak pixels (from 'final_fit') * * float fit_backval[EE256]; * number of cooresponding background counts (from 'final_fit') * *} goodsrc; */ /***************************************************************** * Name of source file: initUSER.c * Version of source file: 4.0.6 * Parent component: None * Programmer: Niels Lund * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325716 FAX: +45 35362475 * nl@dnsc.dk * Purpose: print summary of source found and fit coefficients * Origin date: 20100210 * Update history: 1.0.0 20100210 First version * 4.0.6 120628 SPR ?: Reduced memory allocation demands * Type of element: Function * Part of package: j_ima_iros * Name: initUSER * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ /* QQQQQQ */ int initUSER( int ee, userbin *USERBIN, struct log_con *logger, int status ) { int i, j, i5; 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], "initUSER"); 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); i5 = logger->i5; /* BEGIN */ USERBIN[ee].PImin = 0; USERBIN[ee].PImax = 0; USERBIN[ee].E_min = 0.0; USERBIN[ee].E_max = 0.0; USERBIN[ee].E_mean = 0.0; USERBIN[ee].x_rms = 0.0; USERBIN[ee].y_rms = 0.0; USERBIN[ee].abs_len = 0.0; USERBIN[ee].i_depth = 0.0; USERBIN[ee].act_pix = 0.0; USERBIN[ee].max_radius = 0.0; USERBIN[ee].avg_gain = 0.0; USERBIN[ee].eff_slope = 0.0; for (i=0; itrace) 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 ); exittrace: /* exittrace */ if (logger->trace) traces(func_local, 1000-status, logger); goto slut; /* * sprintf(logger->tmptxt2, " 'develop' ctrl param: %4d", logger->develop); * if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) * strcat(logger->tmptxt, logger->tmptxt2); * logger->logstat = logprint(logger, logger->tmptxt, i5); */ } /* * **************************************************************** * COMMENT ONLY ! typedef struct { * struct with data corresponding to one user-defined energy bin * int PImin; * min PI value * int PImax; * max PI value * float E_min; * min keV value * float E_max; * max keV value * float E_mean; * mean keV value * float x_rms; * mean x_rms value for this bin * float y_rms; * mean y_rms value for this bin * float abs_len; * mean abs_len value for this bin * float i_depth; * mean interaction depth for this bin * float act_pix; * total number of used detector pixels * float totcnt; * total number of accepted counts in f_shadgram * float max_radius; * max radius for nonzero pixel in f-shadgram * float avg_gain; * average gain [PHA/keV] from shdg keyword AVG_GAIN * float eff_slope; float variance[SKYDIM]; * variance image * float fst_imag[SKYDIM]; * first, cleaned sky image * float eff_imag[SKYDIM]; * efficiency image * int illumnew[SKYDIM]; * number of detector pixels illuminated from each sky pixel * float shadow[detdim]; * pixelfolded shadowgram * float soft_gr[detdim]; * background shadowgram * float f_shadgram[detdim]; * input shadowgram * float effic_shdg[detdim]; * electronic efficiency shadowgram * float pif_maps[SCW_SRCMAX][detdim]; float pifeff_maps[SCW_SRCMAX][detdim]; float pifnorm[SCW_SRCMAX]; } userbin; */ /* **************************************************************** * Name of source file: off_axis_transmisImag.c * Version of source file: 3.2.7 * Parent component: j_ima_iros * Programmer: Niels Lund * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325700 FAX: +45 35362475 * njw@spacecenter.dk, nl@spacecenter.dk * Purpose: Calculate additional off-axis corrections to source fluxes (image version) (in addition to the collimator tilt correction which is handled by jmx_lib_pif) * Origin date: 071122 * Update history: 1.0.0 200108 First version * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 3.2.7 100224 SPR 4915: Fixing logics for sparse shadowgrams * Type of element: Executable * Part of package: j_ima_iros * Name: off_axis_transmisImag.c * Required components: DAL, PIL, RIL, DAL3GEN **************************************************************** */ int off_axis_transmisImag( int shdg_num, userbin *USERBIN, /* shadowgram structure */ struct instr_data *jmx_id, struct backpro *backproj, struct log_con *logger) /* log control parameters */ { int i=0, j=0, k=0, index=0, jemx=0, status=0; int ixpar=0, iypar=0, Epar=0; static float transmit[10] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; float X_correct=0.0, Y_correct=0.0, xmm=0.0, ymm=0.0; float Emin=0.0, Emax=0.0; float par1=0.0, mm2deg=0.0; float Emean=0.0, usersum; 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], "off_axis_transI"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ if (logger->trace) traces(func_local, 0, logger); mm2deg = 180.0 / 3.14159 / jmx_id->mask_height; jemx = jmx_id->jmx_unit; Emin = USERBIN[shdg_num].E_min; Emax = USERBIN[shdg_num].E_max; Epar = XYvsE_Evals / 2; Emean = (Emin + Emax) / 2.0; for (i=0; i= jmx_id->Elist[i]) && (Emean < jmx_id->Elist[i+1])) Epar = i; status = -1; for (i=0; isky_xdim; i++) { xmm = (float)(i - backproj->FOV_radius) * backproj->pix2mm; for (j=0; jsky_ydim; j++) { ymm = (float)(j - backproj->FOV_radius) * backproj->pix2mm; index = i * backproj->sky_ydim + j; par1 = xmm * mm2deg; ixpar = (int)((par1 + 5.0) * 16.0 / 10.0); if (ixpar < 0) ixpar = 0; if (ixpar > 15) ixpar = 15; par1 = ymm * mm2deg; iypar = (int)((par1 + 5.0) * 16.0 / 10.0); if (iypar < 0) iypar = 0; if (iypar > 15) iypar = 15; X_correct = backproj->XvsEima[Epar][ixpar]; Y_correct = backproj->YvsEima[Epar][iypar]; status = coll_transmit(xmm, ymm, jmx_id, logger, transmit); if (status < 0) for (k=0; k<10; k++) transmit[k] = 1.0; /* goto exit_trace; */ USERBIN[shdg_num].eff_imag[index] *= transmit[7] * transmit[8] * X_correct * Y_correct; USERBIN[shdg_num].transcor[index] = transmit[7] * transmit[8] * X_correct * Y_correct; } } usersum = 2.7; /* normalization factor for pif-weighted images NL 20120105 */ usersum = 1.0; /* normalization factor for pif-weighted images NL 20120105 */ for (i=0; itrace) 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); } /***************************************************************** * Name of source file: skyout.c * Version of source file: 4.0.9 * Parent component: None * Programmer: Niels Lund * Affiliation: National Space institute/DTU * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325705 FAX: +45 35362475 * nl@space.dtu.dk * Purpose: output sky-images as fits files * Origin date: 070626 * Update history: 2.0.0 070626 First version * 2.1.0 070809 SCREWs 2021-2023 * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.2.0 071205 Flux determination has been improved * 2.2.1 071205 SPR 4742: Division by zero eliminated * 2.2.2 080111 Makes trigger rates from JEM-X HK available * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 4.0.5 120607 SPR ?: Still better flux error estimation * 4.0.9 120820 SPR ?: Improve FITS header content * Type of element: Function * Part of package: j_ima_iros * Name: skyout * Calls: * Returns: * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ /* **************************************************************************************** */ int skyout( dal_element *theSWG, /* pointer to the SWG */ struct instr_data *jmx_id, struct log_con *logger, struct backpro *backproj, struct shadowgrams *sh, struct fit_struc *f_struc2, float *imgpeak, float emin, float emax, int ee, /* index in the 'fitsimage' struct */ int ee_shd, /* index of shadowgram underlying */ int vigncorr, int chatter, int status ) { Instrument jemxNum; static char F_exttext00[J_IIR_TEXTSIZE]; static char F_exttext10[J_IIR_TEXTSIZE]; static char F_exttext01[J_IIR_TEXTSIZE]; static char F_exttext11[J_IIR_TEXTSIZE]; static char F_exttext02[J_IIR_TEXTSIZE]; static char F_exttext12[J_IIR_TEXTSIZE]; static char F_exttext03[J_IIR_TEXTSIZE]; static char F_exttext13[J_IIR_TEXTSIZE]; static char F_exttext04[J_IIR_TEXTSIZE]; static char F_exttext14[J_IIR_TEXTSIZE]; static char F_exttext05[J_IIR_TEXTSIZE]; static char F_exttext15[J_IIR_TEXTSIZE]; static char F_exttext06[J_IIR_TEXTSIZE]; static char F_exttext16[J_IIR_TEXTSIZE]; static char F_exttext07[J_IIR_TEXTSIZE]; static char F_exttext17[J_IIR_TEXTSIZE]; static char f_exttext[2][J_IIR_TEXTSIZE]; char *NoPifPtr, charO={'O'}, charo={'o'}; char elmntName[DS_NAME_SIZE]; static float localima[SKYDIM], skyvar[SKYDIM], skyvar5[SKYDIM]; float valmax = 0.0; float valmin = 0.0; float ff220 = 220.0; /* Compensation factor (2.2) to align image fluxes to fit fluxes and change from dm2 to cm2 units */ int i=0, j, skysize=0, i5, jj, start_index, end_index0, end_index1; 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], "skyout"); 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); i5 = logger->i5; skysize = backproj->skydim; if( jmx_id->jmx_unit == 0 ) { strcpy( elmntName, "JMX1-SKY.-IMA"); jemxNum = JMX1; } else { strcpy( elmntName, "JMX2-SKY.-IMA"); jemxNum = JMX2; } f_struc2->emin = emin; f_struc2->emax = emax; for (i=0; ifitsimage[ee][0][i] <= 0.0) { skyvar[i] = 100000.0; } else { if (logger->dontUseShdg[ee_shd] > 0) { skyvar[i] = 100000.0; } else { if (strstr( logger->skyImagesOut, "T_SIG" ) == NULL) skyvar[i] = ff220; else skyvar[i] = sqrt(backproj->fitsimage[ee][0][i]); } } if (backproj->fitsimage[ee][0][i] <= 0.0) { skyvar5[i] = 100000.0; } else { if (logger->dontUseShdg[ee_shd] > 0) { skyvar5[i] = 100000.0; } else { if (strstr( logger->skyImagesOut, "T_SIG" ) == NULL) skyvar5[i] = ff220; else skyvar5[i] = sqrt(backproj->fitsimage[ee][5][i]); } } } for (i=0; i<8; i++) for(j=0; jskyImagesOut, "NOPIF" ); start_index = 0; if ((strstr( logger->skyImagesOut, "PIF" ) != NULL) && (NoPifPtr == NULL)) start_index = 2; end_index0 = 13; end_index1 = 37; if (strstr( logger->skyImagesOut, "T_SIG" ) != NULL) { end_index0 = 19; end_index1 = 52; } strcpy(F_exttext00, "NOPIF_RAW_INT_SIGNI"); strcpy(F_exttext10, "NOPIF init. intens map - no flatfield Significance!"); strcpy(F_exttext01, "NOPIF_RECTIF._SIGNI"); strcpy(F_exttext11, "NOPIF Rectified initial intensity map Significance!"); strcpy(F_exttext02, "NOPIFVARIANCE"); strcpy(F_exttext12, "NOPIF Variance map"); strcpy(F_exttext03, "NOPIFRESIDUAL_SIGNI"); strcpy(F_exttext13, "NOPIF Residual intensity map Significance!"); strcpy(F_exttext04, "NOPIF_RES+SRC_SIGNI"); strcpy(F_exttext14, "NOPIF Residual intensity + sources Significance!"); strcpy(F_exttext05, "NOPIFEXPOSURE"); strcpy(F_exttext15, "NOPIF Exposure map"); strcpy(F_exttext06, "NOPIFSIGNIFIC"); strcpy(F_exttext16, "NOPIF Significance map"); status = ISDC_OK; /* QQQQ */ if (strstr( logger->skyImagesOut, "RAW_I" ) != NULL || strstr( logger->skyImagesOut, "RAWIN" ) != NULL ) { jj = 0; strcpy(f_struc2->imatype[0], "RAWINTENSITY"); if( logger->skipNeighborCor ) strcat(f_struc2->imatype[0], "U" ); strcpy(f_struc2->imatype[1], "Raw intensity map"); f_struc2->vigncor = 0; strcpy(f_struc2->bunit, "counts"); if (strstr(logger->skyImagesOut, "T_SIG") != NULL) strcpy(f_struc2->bunit, ""); for (i=0; ifitsimage[ee][1][i] == 0.0) localima[i] = NAN; else { if (logger->dontUseShdg[ee_shd] > 0) localima[i] = NAN; else localima[i] = backproj->fitsimage[ee][1][i] / skyvar5[i]; /* image normalization introduced NL 20120604 */ } } for(j=0; jskyImagesOut, "RAW_R" ) != NULL || strstr( logger->skyImagesOut, "RECTI" ) != NULL ) { jj = 1; strcpy(f_struc2->imatype[0], "RECTIFIED"); if( logger->skipNeighborCor ) strcat(f_struc2->imatype[0], "U" ); strcpy(f_struc2->imatype[1], "Raw rectified intensity map"); f_struc2->vigncor = vigncorr; if (vigncorr == 0) strcpy(f_struc2->bunit, "counts"); else strcpy(f_struc2->bunit, "counts/cm2/s"); if (strstr(logger->skyImagesOut, "T_SIG") != NULL) strcpy(f_struc2->bunit, ""); for (i=0; ifitsimage[ee][2][i] == 0.0) localima[i] = NAN; else { if (logger->dontUseShdg[ee_shd] > 0) localima[i] = NAN; else localima[i] = backproj->fitsimage[ee][2][i] / skyvar5[i]; /* image normalization introduced NL 20120604 */ } } for(j=0; jskyImagesOut, "VARIA" ) != NULL ) { jj = 2; strcpy(f_struc2->imatype[0], "VARIANCE"); if( logger->skipNeighborCor ) strcat(f_struc2->imatype[0], "U" ); strcpy(f_struc2->imatype[1], "Variance map"); f_struc2->vigncor = vigncorr; if (vigncorr == 0) strcpy(f_struc2->bunit, "counts2"); else strcpy(f_struc2->bunit, "counts2/cm4/s2"); for (i=0; ifitsimage[ee][0][i] == 0.0) localima[i] = NAN; else { if (logger->dontUseShdg[ee_shd] > 0) localima[i] = NAN; else localima[i] = backproj->fitsimage[ee][0][i] / (ff220 * ff220); /* image normalization introduced NL 20120604 */ } } for(j=0; jskyImagesOut, "RESID" ) != NULL ) { jj = 3; strcpy(f_struc2->imatype[0], "RESIDUAL"); if( logger->skipNeighborCor ) strcat(f_struc2->imatype[0], "U" ); strcpy(f_struc2->imatype[1], "Residual map"); f_struc2->vigncor = vigncorr; if (vigncorr == 0) strcpy(f_struc2->bunit, "counts"); else strcpy(f_struc2->bunit, "counts/cm2/s"); if (strstr(logger->skyImagesOut, "T_SIG") != NULL) strcpy(f_struc2->bunit, ""); for (i=0; ifitsimage[ee][3][i] == 0.0) localima[i] = NAN; else { if (logger->dontUseShdg[ee_shd] > 0) localima[i] = NAN; else localima[i] = backproj->fitsimage[ee][3][i] / skyvar[i]; /* image normalization introduced NL 20120604 */ } } for(j=0; jskyImagesOut, "RES+S" ) != NULL || strstr( logger->skyImagesOut, "RECON" ) != NULL ) { jj = 4; strcpy(f_struc2->imatype[0], "RECONSTRUCTED"); if( logger->skipNeighborCor ) strcat(f_struc2->imatype[0], "U" ); strcpy(f_struc2->imatype[1], "Residual map with found sources"); f_struc2->vigncor = vigncorr; if (vigncorr == 0) strcpy(f_struc2->bunit, "counts"); else strcpy(f_struc2->bunit, "counts/cm2/s"); if (strstr(logger->skyImagesOut, "T_SIG") != NULL) strcpy(f_struc2->bunit, ""); for (i=0; ifitsimage[ee][4][i] == 0.0) localima[i] = NAN; else { if (logger->dontUseShdg[ee_shd] > 0) localima[i] = NAN; else localima[i] = backproj->fitsimage[ee][4][i] / skyvar[i]; /* image normalization introduced NL 20120604 */ } } for(j=0; jskyImagesOut, "EXPOS" ) != NULL ) || ((strstr( logger->skyImagesOut, "PIF" ) != NULL) && (NoPifPtr == NULL))) { /* Always output exposure map if PIF imaging is requested */ jj = 5; strcpy(f_struc2->imatype[0], "EXPOSURE"); strcpy(f_struc2->imatype[1], "Exposure map"); strcpy(f_struc2->bunit, "s"); valmax = 10000.0; /* NOTE: The values in the exposure map are normalized to 100 cm2 eff. area. 20080201 Niels Lund */ for( i = 0; i < skysize; i++) { if (backproj->illumx[i] == 0) localima[i] = NAN; else { if (logger->dontUseShdg[ee_shd] > 0) localima[i] = NAN; else localima[i] = f_struc2->exposure * ((float)(backproj->illumx[i])) / valmax; } } for(j=0; jskyImagesOut, "SIGNI" ) != NULL ) { jj = 6; strcpy(f_struc2->imatype[0], "SIGNIFICANCE"); strcpy(f_struc2->imatype[1], "Significance map"); strcpy(f_struc2->bunit, ""); /* Get significance by (RES+SRC)/sqrt(VARIANCE) */ for( i = 0; i < skysize; i++) { if( backproj->fitsimage[ee][0][i] <= 0.0 || backproj->fitsimage[ee][4][i] == 0.0 ) localima[i] = NAN; else { if (logger->dontUseShdg[ee_shd] > 0) localima[i] = NAN; else localima[i] = backproj->fitsimage[ee][4][i] / sqrt( backproj->fitsimage[ee][0][i] ); } } for(j=0; jtrace) 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); errotrace: RILlogMessage( NULL, Error_1,"##10%d## %d: Error in outfit_isdc", jj, status); status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_ARRWRITEERR; goto exittrace; } /***************************************************************** * Name of source file: clean.c * Version of source file: 4.0.12 * Programmer: Niels Lund & Niels J. Westergaard * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325705 FAX: +45 35362475 * njw@space.dtu.dk * Purpose: Initiate the backprojection and source * finding processes * Origin date: 041122 * Update history: 1.0.0 041130 First version * 1.6.3 060915 An exposure (vignetting) map is now a product * 1.6.4 060928 Included test for zero divisor in peaktransfer.c * 1.6.5 061002 New defaults for par. skyImagesOut * 1.7.0 061110 Produces images with few or zero events (SPR 4594) * 1.7.1 061114 SPR 4603 Image unit (BUNIT) is now cts/dm2/s * 2.1.0 070809 SCREWS 2021-2023 * 2.1.0 070809 SCREWs 2021-2023 * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.2.0 071205 Flux determination has been improved * 2.2.1 071205 SPR 4742: Division by zero eliminated * 2.2.2 080111 Makes trigger rates from JEM-X HK available * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 4.0.12 120919 SPR ?: Introduce corrections by LP and Co. * Type of element: Function * Part of package: j_ima_iros * Name: clean * Returns: * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ int clean(float sky_r[SKYDIM], float skyim[SKYDIM], int ee, struct log_con *logger, struct backpro *backproj, int chatter, int status ) { int i, j, n, max_j0, max_j1, pass, pass_limit, ix, iy, ixj, iyj; int sky_h, min_j0, min_j1, useful, skypix, skypix_j, use[50]; /* test */ int useful_max = 0; int min_j2, max_j2, min_j3, max_j3; int chatter_orig = 0; float Skyval[50], Skyval2[50], max0, max1, min0, min1; float rms[5] = {0.0, 0.0, 0.0, 0.0, 0.0}; float max2, max3, min2, min3; float skysum, f_useful; static float temp1[SKY_XDIM][SKY_YDIM]; /* test */ float sky_r_min = 0.0; /* test */ float sky_r_max = 0.0; /* test */ float Skyval_min = 0.0; /* test */ float Skyval_max = 0.0; static int first = 1, indx[50], skysize, sky_ysize, j_loop; static float fac[50], gauss_val[15]; static int func_local = -1, local_calling_num=0; clock_t calling_TT, TT_now; if( status != ISDC_OK ) return( status ); /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "clean"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ if (logger->trace) traces(func_local, 1, logger); /* [test] */ chatter_orig = logger->chatter; /* [test] */ logger->chatter = 1; if (first) { first = 0; skysize = backproj->skydim; sky_ysize = backproj->sky_ydim; gauss_val[0] = 0.99; gauss_val[1] = 0.95; gauss_val[2] = 0.87; gauss_val[3] = 0.80; gauss_val[4] = 0.70; gauss_val[5] = 0.55; gauss_val[6] = 0.40; gauss_val[7] = 0.30; gauss_val[8] = 0.24; gauss_val[9] = 0.20; gauss_val[10] = 0.17; gauss_val[11] = 0.14; gauss_val[12] = 0.11; gauss_val[13] = 0.09; gauss_val[14] = 0.07; j_loop = 30; for (i=0; itmptxt, "##345## Clean: completed initialization of 'indx'"); logger->logstat = logprint(logger, logger->tmptxt, 5); } sky_h = (skysize - 1) / 2; if( chatter > J_CHATTY_VERY_VERBOSE ) { RILlogMessage(NULL,Log_0,"##346## skysize = %d, ee = %d", skysize, ee ); RILlogMessage(NULL,Log_0,"##347## SKYDIM = %d", SKYDIM ); } /* prepare for first pass */ /* test */ sky_r_min = sky_r[0]; /* test */ sky_r_max = sky_r[0]; for (skypix=0; skypix sky_r_max ) sky_r_max = sky_r[skypix]; /* test */ if( sky_r[skypix] < sky_r_min ) sky_r_min = sky_r[skypix]; } /* test */ if( chatter > J_CHATTY_VERY_VERBOSE ) { RILlogMessage( NULL, Log_0,"##348## sky_r min max: %e %e", sky_r_min, sky_r_max); } if ( chatter > J_CHATTY_VERBOSE ) rms[0] = rms_sky(sky_r, ee, backproj, logger); for (skypix=0; skypixaccess[skypix] > 0) skyim[skypix] = sky_r[skypix]; else skyim[skypix] = 0.0; } if ( chatter > J_CHATTY_VERBOSE ) rms[1] = rms_sky(skyim, ee, backproj, logger); /* pass begin */ pass_limit= 2; for (pass=0; passtmptxt, "##349## Clean: begin pass %1d", pass); logger->logstat = logprint(logger, logger->tmptxt, 5); /* test */ useful_max = 0; /* test */ Skyval_min = 1.e30; /* test */ Skyval_max = -1.e30; for (skypix=0; skypixaccess[skypix] == 0) goto next_skypix; /* avoid posits outside field of view */ useful = 0; skysum = f_useful = 0.0; if ((pass%2) == 0) { /* clean along X */ for (j=0; j= SKY_XDIM) goto next_xj; skypix_j = skypix + indx[j] * SKY_YDIM; if (skypix_j >= SKYDIM ) { RILlogMessage(NULL,Warning_1,"##350## skypix_j >= SKYDIM, reset!"); skypix_j = SKYDIM - 1; } Skyval[j] = temp1[ixj][iy] * fac[j]; /* test */ if( Skyval[j] < Skyval_min ) Skyval_min = Skyval[j]; /* test */ if( Skyval[j] > Skyval_max ) Skyval_max = Skyval[j]; if (backproj->access[skypix_j] > 0) { /* avoid posits flagged as inside source regions */ Skyval2[useful] = Skyval[j]; /* test */ if( useful > useful_max ) useful_max = useful; use[j] = 1; skysum += Skyval[j]; f_useful += fac[j]; useful++; } else goto next_xj; ixj = ix + indx[j+1]; /* negative displacement */ skypix_j = skypix + indx[j+1]; if (ixj < 0) goto next_xj; skypix_j = skypix + indx[j+1] * SKY_YDIM; if (skypix_j < 0) { RILlogMessage(NULL,Warning_1,"##351## skypix_j < 0, reset!"); skypix_j = 0; } Skyval[j+1] = temp1[ixj][iy] * fac[j+1]; if (backproj->access[skypix_j] > 0) { /* avoid posits flagged as inside source regions */ Skyval2[useful] = Skyval[j+1]; /* test */ if( useful > useful_max ) useful_max = useful; use[j+1] = 1; skysum += Skyval[j+1]; f_useful += fac[j+1]; useful++; } next_xj: ; } } else { /* clean along Y */ for (j=0; j= SKYDIM) { RILlogMessage(NULL,Warning_1,"##352## skypix_j >= SKYDIM, reset!"); skypix_j = SKYDIM - 1; } if (iyj >= SKY_YDIM) goto next_yj; Skyval[j] = temp1[ix][iyj] * fac[j]; /* test */ if( Skyval[j] < Skyval_min ) Skyval_min = Skyval[j]; /* test */ if( Skyval[j] > Skyval_max ) Skyval_max = Skyval[j]; if (backproj->access[skypix_j] > 0) { /* avoid posits flagged as inside source regions */ Skyval2[useful] = Skyval[j]; /* test */ if( useful > useful_max ) useful_max = useful; use[j] = 1; skysum += Skyval[j]; f_useful += fac[j]; useful++; } else goto next_yj; iyj = iy + indx[j+1]; /* negative displacement */ skypix_j = skypix + indx[j+1]; if (skypix_j < 0 ) { RILlogMessage(NULL,Warning_1,"##353## skypix_j < 0, reset!"); skypix_j = 0; } if (iyj < 0) goto next_yj; Skyval[j+1] = temp1[ix][iyj] * fac[j+1]; if (backproj->access[skypix_j] > 0) { /* avoid posits flagged as inside source regions */ Skyval2[useful] = Skyval[j+1]; /* test */ if( useful > useful_max ) useful_max = useful; use[j+1] = 1; skysum += Skyval[j+1]; f_useful += fac[j+1]; useful++; } next_yj: ; } } if ((useful == 0) || (f_useful < 0.01)) { skyim[skypix] = 0.0; goto next_skypix; } if (useful < 10) { /* test */ if( f_useful < 0.01 ) RILlogMessage(NULL,Warning_0,"##354## f_useful problem!"); skysum /= f_useful; skyim[skypix] = temp1[ix][iy] - skysum; goto next_skypix; } max0 = -100000.0; max_j0 = -1; min0 = 100000.0; min_j0 = -1; max1 = -100000.0; max_j1 = -1; min1 = 100000.0; min_j1 = -1; max2 = -100000.0; max_j2 = -1; min2 = 100000.0; min_j2 = -1; max3 = -100000.0; max_j3 = -1; min3 = 100000.0; min_j3 = -1; for (j=0; j= min3) goto next_j1; /* identify four smallest values */ if (Skyval[j] >= min2) { min3 = Skyval[j]; min_j3 = j; } else { if (Skyval[j] >= min1) { min3 = min2; min_j3 = min_j2; min2 = Skyval[j]; min_j2 = j; } else { if (Skyval[j] >= min0) { min3 = min2; min_j3 = min_j2; min2 = min1; min_j2 = min_j1; min1 = Skyval[j]; min_j1 = j; } else { min3 = min2; min_j3 = min_j2; min2 = min1; min_j2 = min_j1; min1 = min0; min_j1 = min_j0; min0 = Skyval[j]; min_j0 = j; } } } next_j1: ; } skysum = 0.0; n = 0; for (j=0; jtmptxt, "##355## Clean-error: useful1: %2d, differs from useful2: %2d", useful, n); goto return_negative; } if (f_useful < 0.0001) { sprintf(logger->tmptxt, "##356## Clean-error, f_useful close to zero or negative: %8.4f, useful: %3d", f_useful, useful); return_negative: if (logger->trace) traces(func_local, 98, logger); logger->logstat = logprint(logger, logger->tmptxt, 5); /* 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 */ /* test */ logger->chatter = chatter_orig; return(J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_CLEANERR); } /* test */ if( f_useful < 0.01 ) RILlogMessage(NULL,Warning_0,"##357## f_useful problem! %e", f_useful); skysum /= f_useful; skyim[skypix] = temp1[ix][iy] - skysum; next_skypix: ; } rms[pass+2] = rms_sky(skyim, ee, backproj, logger); sprintf(logger->tmptxt, "##358## Clean: completed pass %1d, exit rms %6.2f", pass, rms[pass+2]); logger->logstat = logprint(logger, logger->tmptxt, 5); /* RILlogMessage(NULL,Log_0,"##359## useful_max = %d", useful_max); RILlogMessage(NULL,Log_0,"##360## Skyval min max = %e %e", Skyval_min, Skyval_max); */ for (skypix=0; skypixtmptxt, "rms evolution: %6.2f %6.2f %6.2f %6.2f", rms[0], rms[1], rms[2], rms[3]); logger->logstat = logprint(logger, logger->tmptxt, 5); 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 */ /* [test] */ logger->chatter = chatter_orig; return( status ); } /***************************************************************** * Name of source file: clean0.c * Version of source file: 3.2.6 * Programmer: Niels Lund & Niels J. Westergaard * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325705 FAX: +45 35362475 * njw@space.dtu.dk * Purpose: Initiate the backprojection and source * finding processes * Origin date: 041122 * Update history: 1.0.0 080202 First version * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 1.6.3 060915 An exposure (vignetting) map is now a product * 1.6.4 060928 Included test for zero divisor in peaktransfer.c * 1.6.5 061002 New defaults for par. skyImagesOut * 1.7.0 061110 Produces images with few or zero events (SPR 4594) * 1.7.1 061114 SPR 4603 Image unit (BUNIT) is now cts/dm2/s * 2.1.0 070809 SCREWS 2021-2023 * 2.1.0 070809 SCREWs 2021-2023 * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.2.0 071205 Flux determination has been improved * 2.2.1 071205 SPR 4742: Division by zero eliminated * 2.2.2 080111 Makes trigger rates from JEM-X HK available * Type of element: Function * Part of package: j_ima_iros * Name: clean0 * Returns: * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ int clean0(float sky_r[SKYDIM], float skyim[SKYDIM], int ee, struct log_con *logger, struct backpro *backproj, int chatter, int status ) { int i, j, n, max_j0, max_j1, pass, pass_limit, ix, iy, ixj, iyj, i5 = 5; int sky_h, min_j0, min_j1, useful, skypix, skypix_j, use[50]; /* test */ int useful_max = 0; int min_j2, max_j2, min_j3, max_j3; int chatter_orig = 0; float Skyval[50], Skyval2[50], max0, max1, min0, min1; float rms[5] = { 0.0, 0.0, 0.0, 0.0, 0.0}; float max2, max3, min2, min3; float skysum, f_useful; static float temp1[SKY_XDIM][SKY_YDIM]; /* test */ float sky_r_min = 0.0; /* test */ float sky_r_max = 0.0; /* test */ float Skyval_min = 0.0; /* test */ float Skyval_max = 0.0; static int first = 1, indx[50], skysize, sky_ysize, j_loop; static float fac[50], gauss_val[15]; static int func_local = -1, local_calling_num=0; clock_t calling_TT, TT_now; if( status != ISDC_OK ) return( status ); /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "clean0"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ if (logger->trace) traces(func_local, 1, logger); /* [test] */ chatter_orig = logger->chatter; /* [test] */ logger->chatter = 1; if (first) { first = 0; skysize = backproj->skydim; sky_ysize = backproj->sky_ydim; gauss_val[0] = 0.99; gauss_val[1] = 0.95; gauss_val[2] = 0.87; gauss_val[3] = 0.80; gauss_val[4] = 0.70; gauss_val[5] = 0.55; gauss_val[6] = 0.40; gauss_val[7] = 0.30; gauss_val[8] = 0.24; gauss_val[9] = 0.20; gauss_val[10] = 0.17; gauss_val[11] = 0.14; gauss_val[12] = 0.11; gauss_val[13] = 0.09; gauss_val[14] = 0.07; j_loop = 30; for (i=0; itmptxt, "##345## Clean: completed initialization of 'indx'"); logger->logstat = logprint(logger, logger->tmptxt, i5); } sky_h = (skysize - 1) / 2; if( chatter > J_CHATTY_VERY_VERBOSE ) { RILlogMessage(NULL,Log_0,"##346## skysize = %d, ee = %d", skysize, ee ); RILlogMessage(NULL,Log_0,"##347## SKYDIM = %d", SKYDIM ); } /* prepare for first pass */ /* test */ sky_r_min = sky_r[0]; /* test */ sky_r_max = sky_r[0]; for (skypix=0; skypix sky_r_max ) sky_r_max = sky_r[skypix]; /* test */ if( sky_r[skypix] < sky_r_min ) sky_r_min = sky_r[skypix]; } /* test */ if( chatter > J_CHATTY_VERY_VERBOSE ) { RILlogMessage( NULL, Log_0,"##348## sky_r min max: %e %e", sky_r_min, sky_r_max); } if ( chatter > J_CHATTY_VERBOSE ) rms[0] = rms_sky(sky_r, ee, backproj, logger); for (skypix=0; skypixaccess[skypix] > 0) skyim[skypix] = sky_r[skypix]; else skyim[skypix] = 0.0; } if ( chatter > J_CHATTY_VERBOSE ) rms[1] = rms_sky(skyim, ee, backproj, logger); /* pass begin */ pass_limit= 2; for (pass=0; passtmptxt, "##349## Clean: begin pass %1d", pass); logger->logstat = logprint(logger, logger->tmptxt, i5); /* test */ useful_max = 0; /* test */ Skyval_min = 1.e30; /* test */ Skyval_max = -1.e30; for (skypix=0; skypixaccess[skypix] == 0) goto next_skypix; /* avoid posits outside field of view */ useful = 0; skysum = f_useful = 0.0; if ((pass%2) == 0) { /* clean along X */ for (j=0; j= SKY_XDIM) goto next_xj; skypix_j = skypix + indx[j] * SKY_YDIM; if (skypix_j >= SKYDIM ) { RILlogMessage(NULL,Warning_1,"##350## skypix_j >= SKYDIM, reset!"); skypix_j = SKYDIM - 1; } Skyval[j] = temp1[ixj][iy] * fac[j]; /* test */ if( Skyval[j] < Skyval_min ) Skyval_min = Skyval[j]; /* test */ if( Skyval[j] > Skyval_max ) Skyval_max = Skyval[j]; Skyval2[useful] = Skyval[j]; /* test */ if( useful > useful_max ) useful_max = useful; use[j] = 1; skysum += Skyval[j]; f_useful += fac[j]; useful++; ixj = ix + indx[j+1]; /* negative displacement */ skypix_j = skypix + indx[j+1]; if (ixj < 0) goto next_xj; skypix_j = skypix + indx[j+1] * SKY_YDIM; if (skypix_j < 0) { RILlogMessage(NULL,Warning_1,"##351## skypix_j < 0, reset!"); skypix_j = 0; } Skyval[j+1] = temp1[ixj][iy] * fac[j+1]; Skyval2[useful] = Skyval[j+1]; /* test */ if( useful > useful_max ) useful_max = useful; use[j+1] = 1; skysum += Skyval[j+1]; f_useful += fac[j+1]; useful++; next_xj: ; } } else { /* clean along Y */ for (j=0; j= SKYDIM) { RILlogMessage(NULL,Warning_1,"##352## skypix_j >= SKYDIM, reset!"); skypix_j = SKYDIM - 1; } if (iyj >= SKY_YDIM) goto next_yj; Skyval[j] = temp1[ix][iyj] * fac[j]; /* test */ if( Skyval[j] < Skyval_min ) Skyval_min = Skyval[j]; /* test */ if( Skyval[j] > Skyval_max ) Skyval_max = Skyval[j]; Skyval2[useful] = Skyval[j]; /* test */ if( useful > useful_max ) useful_max = useful; use[j] = 1; skysum += Skyval[j]; f_useful += fac[j]; useful++; iyj = iy + indx[j+1]; /* negative displacement */ skypix_j = skypix + indx[j+1]; if (skypix_j < 0 ) { RILlogMessage(NULL,Warning_1,"##353## skypix_j < 0, reset!"); skypix_j = 0; } if (iyj < 0) goto next_yj; Skyval[j+1] = temp1[ix][iyj] * fac[j+1]; Skyval2[useful] = Skyval[j+1]; /* test */ if( useful > useful_max ) useful_max = useful; use[j+1] = 1; skysum += Skyval[j+1]; f_useful += fac[j+1]; useful++; next_yj: ; } } if ((useful == 0) || (f_useful < 0.01)) { skyim[skypix] = 0.0; goto next_skypix; } if (useful < 10) { /* test */ if( f_useful < 0.01 ) RILlogMessage(NULL,Warning_0,"##354## f_useful problem!"); skysum /= f_useful; skyim[skypix] = temp1[ix][iy] - skysum; goto next_skypix; } max0 = -100000.0; max_j0 = -1; min0 = 100000.0; min_j0 = -1; max1 = -100000.0; max_j1 = -1; min1 = 100000.0; min_j1 = -1; max2 = -100000.0; max_j2 = -1; min2 = 100000.0; min_j2 = -1; max3 = -100000.0; max_j3 = -1; min3 = 100000.0; min_j3 = -1; for (j=0; j= min3) goto next_j1; /* identify four smallest values */ if (Skyval[j] >= min2) { min3 = Skyval[j]; min_j3 = j; } else { if (Skyval[j] >= min1) { min3 = min2; min_j3 = min_j2; min2 = Skyval[j]; min_j2 = j; } else { if (Skyval[j] >= min0) { min3 = min2; min_j3 = min_j2; min2 = min1; min_j2 = min_j1; min1 = Skyval[j]; min_j1 = j; } else { min3 = min2; min_j3 = min_j2; min2 = min1; min_j2 = min_j1; min1 = min0; min_j1 = min_j0; min0 = Skyval[j]; min_j0 = j; } } } next_j1: ; } skysum = 0.0; n = 0; for (j=0; jtmptxt, "##355## Clean-error: useful1: %2d, differs from useful2: %2d", useful, n); goto return_negative; } if (f_useful < 0.0001) { sprintf(logger->tmptxt, "##356## Clean-error, f_useful close to zero or negative: %8.4f, useful: %3d", f_useful, useful); return_negative: if (logger->trace) traces(func_local, 98, logger); logger->logstat = logprint(logger, logger->tmptxt, i5); /* 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 */ /* test */ logger->chatter = chatter_orig; return(J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_CLEANERR); } /* test */ if( f_useful < 0.01 ) RILlogMessage(NULL,Warning_0,"##357## f_useful problem! %e", f_useful); skysum /= f_useful; skyim[skypix] = temp1[ix][iy] - skysum; next_skypix: ; } rms[pass+2] = rms_sky(skyim, ee, backproj, logger); sprintf(logger->tmptxt, "##358## Clean: completed pass %1d, exit rms %6.2f", pass, rms[pass+2]); logger->logstat = logprint(logger, logger->tmptxt, i5); /* RILlogMessage(NULL,Log_0,"##359## useful_max = %d", useful_max); RILlogMessage(NULL,Log_0,"##360## Skyval min max = %e %e", Skyval_min, Skyval_max); */ for (skypix=0; skypixtmptxt, "rms evolution: %6.2f %6.2f %6.2f %6.2f", rms[0], rms[1], rms[2], rms[3]); logger->logstat = logprint(logger, logger->tmptxt, i5); 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 */ /* [test] */ logger->chatter = chatter_orig; return( status ); } /* *********************************************************************************** */ /***************************************************************** * Name of source file: skyval.c * Version of source file: 3.2.6 * Programmer: Niels Lund & Niels J. Westergaard * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325705 FAX: +45 35362475 * njw@space.dtu.dk * Purpose: Initiate the backprojection and source * finding processes * Origin date: 041122 * Update history: 1.0.0 041130 First version * 1.6.3 060915 An exposure (vignetting) map is now a product * 1.6.4 060928 Included test for zero divisor in peaktransfer.c * 1.6.5 061002 New defaults for par. skyImagesOut * 1.7.0 061110 Produces images with few or zero events (SPR 4594) * 1.7.1 061114 SPR 4603 Image unit (BUNIT) is now cts/dm2/s * 2.1.0 070809 SCREWS 2021-2023 * 2.1.0 070809 SCREWs 2021-2023 * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.2.0 071205 Flux determination has been improved * 2.2.1 071205 SPR 4742: Division by zero eliminated * 2.2.2 080111 Makes trigger rates from JEM-X HK available * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * Type of element: Function * Part of package: j_ima_iros * Name: skyval * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ int skyval(float sky[], int index, float *skval, int ee, struct log_con *logger, struct backpro *backproj) { static int func_local = -1, local_calling_num=0; clock_t calling_TT, TT_now; int status; /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "skyval"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ if ((index >= 0) && (index < backproj->skydim)) { if (backproj->access[index] > 0) *skval = sky[index]; else *skval = 0.0; status = 0; } else { sprintf(logger->error_text , "Illegal sky index in 'skyval': %8d", index); status = -1; } /* 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); } /***************************************************************** * Name of source file: clean2.c * Version of source file: 4.0.12 * Programmer: Niels Lund & Niels J. Westergaard * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325705 FAX: +45 35362475 * njw@space.dtu.dk * Purpose: Initiate the backprojection and source * finding processes * Origin date: 041122 * Update history: 1.0.0 041130 First version * 1.6.3 060915 An exposure (vignetting) map is now a product * 1.6.4 060928 Included test for zero divisor in peaktransfer.c * 1.6.5 061002 New defaults for par. skyImagesOut * 1.7.0 061110 Produces images with few or zero events (SPR 4594) * 1.7.1 061114 SPR 4603 Image unit (BUNIT) is now cts/dm2/s * 2.1.0 070809 SCREWS 2021-2023 * 2.1.0 070809 SCREWs 2021-2023 * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.2.0 071205 Flux determination has been improved * 2.2.1 071205 SPR 4742: Division by zero eliminated * 2.2.2 080111 Makes trigger rates from JEM-X HK available * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 4.0.12 120919 SPR ?: Introduce corrections by LP and Co. * Type of element: Function * Part of package: j_ima_iros * Name: clean2 * Returns: * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ int clean2( float sky_r[SKYDIM], float xx[], float yy[], int n_common, int backmodls, float skyim[SKYDIM], int ee, struct log_con *logger, struct backpro *backproj, int chatter, int status ) /* remove large scale background subtraction using information about detected sources */ { int i, j, n, jj, ix, iy, ii = 0, i5=0; int sky_l[SKYDIM]; static int func_local = -1, local_calling_num=0; clock_t calling_TT, TT_now; if( status != ISDC_OK ) return( status ); /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "clean2"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ if (logger->trace) traces(func_local, 1, logger); if (logger->trace) traces(func_local, 1000+n_common, logger); if (logger->trace) traces(func_local, 2000+ee, logger); for (i=0; isky_ydim; for (i=-2; i<3; i++) { for (j=-2; j<3; j++) { jj = ii + j * backproj->sky_ydim + i; if( jj < 0 || jj >= SKYDIM ) { RILlogMessage(NULL, Warning_1,"##362## jj = %d! reset to 0", jj); jj = 0; } sky_l[jj] = backproj->access[jj]; /* save access value */ backproj->access[jj] = -1; /* mark positions inside 7x7 pixel source region */ } } } /* clean image, avoid using source regions */ status = clean(sky_r, skyim, ee, logger, backproj, chatter, status ); if (ii > 0) { sprintf(logger->tmptxt, "skyimline after clean: "); for (i=0; i<20; i++) { sprintf(logger->tmptxt2, " %5.2f", skyim[ii+i]); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } logger->logstat = logprint(logger, logger->tmptxt, i5); } for (n=0; nsky_ydim; for (i=-2; i<3; i++) { for (j=-2; j<3; j++) { jj = ii + j * backproj->sky_ydim + i; backproj->access[jj] = sky_l[jj]; /* restore access value */ } } } 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 ); } /***************************************************************** * Name of source file: peaktransfer.c * Version of source file: 4.0.12 * Programmer: Niels Lund & Niels J. Westergaard * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325705 FAX: +45 35362475 * njw@space.dtu.dk * Purpose: Initiate the backprojection and source * finding processes * Origin date: 041122 * Update history: 1.0.0 041130 First version * 1.6.3 060915 An exposure (vignetting) map is now a product * 1.6.4 060928 Included test for zero divisor in peaktransfer.c * 1.6.5 061002 New defaults for par. skyImagesOut * 1.7.0 061110 Produces images with few or zero events (SPR 4594) * 1.7.1 061114 SPR 4603 Image unit (BUNIT) is now cts/dm2/s * 2.1.0 070809 SCREWS 2021-2023 * 2.1.0 070809 SCREWs 2021-2023 * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.2.0 071205 Flux determination has been improved * 2.2.1 071205 SPR 4742: Division by zero eliminated * 2.2.2 080111 Makes trigger rates from JEM-X HK available * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR XXXX Missing peaktransfer loop reinstalled (line 135-146) * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 4.0.12 120919 SPR ?: Introduce corrections by LP and Co. * Type of element: Function * Part of package: j_ima_iros * Name: peaktransfer * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ float peaktransfer(float x, float y, float sky_r[SKYDIM], float impeak[SKYDIM], float peakcount[], float mean_bkg[], int ee, float detsig[], struct backpro *backproj, struct log_con *logger) { int ix, iy, ixy, jj, ixx, iyy, sky_index, iix, iiy, i5 = 5; int i, j, q, type, offset, xs, ys, ydim, ixy_trans; int xsign[4] = {+1, +1, -1, -1}; int ysign[4] = {+1, -1, +1, -1}; int stat[36], stat2[36], skylist[36][4]; int xtype, ixy_max, qxy, Y, Y1, qoff[9]; static int isrc=0; float val[36], val2[36], skval; float pmax[4], qq, ima_max; double twosigma, m0, m1, m2; double mb0, mb1, mb2; 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], "peaktransfer"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ if (logger->trace) traces(func_local, 1, logger); if (logger->peak_last == 1) isrc++; twosigma = backproj->ima_sigma[ee]; /* type 0 1 2 3 X&Y between X between, Y centered X centered, Y between X&Y centered */ iix = x * 4.0; if (((iix%4) == 0) || ((iix%4) == 3)) type = 0; else type = 2; iiy = y * 4.0; if (((iiy%4) == 1) || ((iiy%4) == 2)) type++; ix = x; iy = y; if ((iix%4) == 3) ix++; if ((iiy%4) == 3) iy++; ydim = backproj->sky_ydim; ixy = ix * ydim + iy; /* index for peak center */ xtype = 0; pmax[0] = pmax[1] = pmax[2] = pmax[3] = 0.0; ixy_max = ixy; Y = ydim; Y1 = Y + 1; qoff[0] = 1; qoff[1] = -1; qoff[2] = Y; qoff[3] = -Y; qoff[4] = Y1; qoff[5] = -Y1; qoff[6] = Y-1; qoff[7] = -Y+1; qoff[8] = 0; for (i=0; i<9; i++) { /* find 4-block of pixels with highest count near indicated source position */ qxy = ixy + qoff[i]; qq = sky_r[qxy] + sky_r[qxy-1] + sky_r[qxy-Y] + sky_r[qxy-Y1]; if (qq > pmax[0]) {xtype = 0; pmax[0] = qq; ixy_max = qxy;} } peakcount[0] = pmax[0]; /* peakcount[0] contains peak counts in image map */ ixy = ixy_max; /* peakcount[1] contains peak counts in variance map */ peakcount[1] = backproj->fitsimage[ee][0][ixy] + backproj->fitsimage[ee][0][ixy-1] + backproj->fitsimage[ee][0][ixy-Y] + backproj->fitsimage[ee][0][ixy-Y1]; ixy_trans = ixy; ima_max = sky_r[ixy]; if (sky_r[ixy-1] > ima_max) { ima_max = sky_r[ixy-1]; ixy_trans = ixy - 1; } if (sky_r[ixy-Y] > ima_max) { ima_max = sky_r[ixy-Y]; ixy_trans = ixy - Y; } if (sky_r[ixy-Y1] > ima_max) { ima_max = sky_r[ixy-Y1]; ixy_trans = ixy - Y1; } for (i=3; i>=-3; i--) { for (j=-3; j<=3; j++) { jj = ixy_trans + j * ydim + i; impeak[jj] = sky_r[jj]; /* save peak counts into 'impeak'-image */ } } ix = ixy_max / ydim; iy = ixy_max % ydim; if (logger->peak_last == 1) { sprintf(logger->tmptxt, "##skyim##: src: %1d, ee: %2d, clean/orig 4peak cnt: %7.0f %7.0f, input X/Y: %7.2f %7.2f, final ix/iy: %3d, %3d", (isrc-1)/2, ee, peakcount[0], peakcount[1], x, y, ix, iy); logger->logstat = logprint(logger, logger-> tmptxt, i5); } /* background (mean and sigma) determination from 36 4-blocks around the source position */ jj = 0; for (i=0; i<3; i++) { for (j=0; j<3; j++) { if (j==0) offset = 3; else offset = 1; ixx = (i*2 + offset); iyy = (j*2 + 3) * ydim; for (q=0; q<4; q++) { xs = xsign[q]; ys = ysign[q]; sky_index = ixy + ixx*xs + iyy*ys; stat[jj] = skyval(sky_r, sky_index, &skval, ee, logger, backproj); val[jj] = skval; stat2[jj] = skyval(backproj->fitsimage[ee][0], sky_index, &skval, ee, logger, backproj); val2[jj] = skval; skylist[jj][0] = sky_index; stat[jj] += skyval(sky_r, sky_index + xs, &skval, ee, logger, backproj); val[jj] += skval; stat2[jj] += skyval(backproj->fitsimage[ee][0], sky_index + xs, &skval, ee, logger, backproj); val2[jj] += skval; skylist[jj][1] = sky_index + xs; stat[jj] += skyval(sky_r, sky_index + ys*ydim, &skval, ee, logger, backproj); val[jj] += skval; stat2[jj] += skyval(backproj->fitsimage[ee][0], sky_index + ys*ydim, &skval, ee, logger, backproj); val2[jj] += skval; skylist[jj][2] = sky_index + ys*ydim; stat[jj] += skyval(sky_r, sky_index + ys*ydim + xs, &skval, ee, logger, backproj); val[jj] += skval; stat2[jj] += skyval(backproj->fitsimage[ee][0], sky_index + ys*ydim + xs, &skval, ee, logger, backproj); val2[jj] += skval; skylist[jj][3] = sky_index + ys*ydim + xs; jj++; } } } m0 = m1 = m2 = 0.0; mb0 = mb1 = mb2 = 0.0; for (i=0; i<36; i++) { if (stat[i] != 0) { for (j=0; j<4; j++) skylist[i][j] = 0; continue; } m0 += 1.0; m1 += val[i]; m2 += val[i] * val[i]; mb0 += 1.0; mb1 += val2[i]; mb2 += val2[i] * val2[i]; } if (m0 < 9) { sprintf(logger->tmptxt, "Too few reference fields available for detsig determination (m0/m1/m2: %f %f %f )", m0, m1, m2); *detsig = 0.0; if (m0 > 0) *mean_bkg = (float)(m1) / (float)(m0); else *mean_bkg = 0.0; } else { m1 /= m0; /* mean background in cleaned image */ m2 /= m0; m2 = sqrt(m2 - m1*m1); /* estimated sigma in cleaned image */ peakcount[0] -= m1; /* correct cleaned peak count for residual background level */ detsig[0] = peakcount[0] / m2; mean_bkg[0] = m1; mb1 /= mb0; /* mean background in raw image */ mb2 /= mb0; mb2 = sqrt(mb2 - mb1*mb1); /* estimated sigma in raw image */ /* raw peak count must be kept as is - uncorrected for the image background - because it is required for estimation of the flux errors */ if (mb2 != 0.0) detsig[1] = (peakcount[1] - mb1) / mb2; else detsig[1] = 0.0; mean_bkg[1] = mb1; if (logger->peak_last == 1) { sprintf(logger->tmptxt, " ##skyim## clean bkg-m0/m1/m2: %f %f %f, peak: %f, detsig: %6.2f, Poisson: %f", m0, m1, m2, peakcount[0], detsig[0], sqrt(peakcount[1])); logger->logstat = logprint(logger, logger-> tmptxt, i5); sprintf(logger->tmptxt, " ##skyim## raw bkg-m0/m1/m2: %f %f %f, peak: %f, detsig: %6.2f, Poisson: %f", mb0, mb1, mb2, peakcount[1], detsig[1], sqrt(peakcount[1])); logger->logstat = logprint(logger, logger-> tmptxt, i5); } } /* The following section is a testprint which shows the pixels used for peak and background extraction disabled for production version. Niels Lund 20090322 if (logger->peak_last == 1) { sprintf(logger->tmptxt, "##skyim## "); for (j=-10; j<10; j++) { sprintf(logger->tmptxt2, " %3d ", ix+j); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } logger->logstat = logprint(logger, logger-> tmptxt, i5); for (i=10; i>=-10; i--) { sprintf(logger->tmptxt, "##skyim## %3d ", iy+i); for (j=-10; j<10; j++) { jj = ixy + j * ydim + i; pchar = ' '; if ((jj==mark[0][2]) || (jj==mark[1][2]) || (jj==mark[2][2]) || (jj==mark[3][2])) pchar = 'b'; if ((jj==mark[0][1]) || (jj==mark[1][1]) || (jj==mark[2][1]) || (jj==mark[3][1])) pchar = 'a'; if ((jj==mark[0][0]) || (jj==mark[1][0]) || (jj==mark[2][0]) || (jj==mark[3][0])) pchar = '*'; for (k=0; k<36; k++) if ((jj==skylist[k][0]) || (jj==skylist[k][1]) || (jj==skylist[k][2]) || (jj==skylist[k][3])) pchar = '#'; sprintf(logger->tmptxt2, "%5d%1c", (int)(sky_r[jj]+0.5), pchar); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } logger->logstat = logprint(logger, logger-> tmptxt, i5); } } */ 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(peakcount[0]); } /* **************************************************************** * Name of source file: findpeak2.c * Version of source file: 4.0.12 * Programmer: Niels Lund * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325716 FAX: +45 35362475 * nl@dnsc.dk * Purpose: Finding peak in image * Origin date: 041122 * Update history: 1.0.0 041130 First version * 1.0.4 050126 Test version for undue crash * 1.7.1 061114 SPR 4603 Image unit (BUNIT) is now cts/dm2/s * 1.8.0 061213 SPR 4640 Error in findpeak has been corrected * 1.8.1 070123 SPR 4590 int changed to long for 64 bit code * 1.8.2 070302 SPR xxxx peak evaluation center point can be set in the call * (set amx[0] = -sky_index for desired position before call) * 2.1.0 070809 SCREWs 2021-2023 * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.2.0 071205 Flux determination has been improved * 2.2.1 071205 SPR 4742: Division by zero eliminated * 2.2.2 080111 Makes trigger rates from JEM-X HK available * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090305 Protection added against division by zero in line 419 * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 4.0.12 120919 SPR ?: Introduce corrections by LP and Co. * Type of element: Function * Part of package: j_ima_iros **************************************************************** */ int findpeak(float *sky, double *sky_rms, double amax[], int ee, struct log_con *logger, struct backpro *backproj) /* Search the highest point in the backprojected sky image. * The 'access' array defines the field of view. Only the maximum peak will be identified and its position will be returned in amax[1] & [2] */ { int i5 = 5; int i, j, k, m, sky_index, m0=0, skymax, external=0; int status, smaxx = 0, smaxy = 0, xyskydim, ok; float x_cent, y_cent, contrib, skval, local_sky[SKYDIM]; float delcon, delx, dely, local_sky_sum, sky_sum, illum_sum, fits5_sum; double aval, blocal, m1=0.0, m2=0.0, mean, var, rms, excess, level; 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], "findpeak2"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ if (logger->trace) traces(func_local, 1, logger); blocal = -10.0e+10; sky_sum = local_sky_sum = illum_sum = fits5_sum = 0.0; for (i=0; iskydim; i++) { /* partially compensate for decrease in illumination at edge of FOV */ local_sky[i] = 0.0; /* added secure initialization of all local_sky values. NL 24-09 2007 */ if (jirisnan(sky[i])) { sprintf(logger->tmptxt, "##928## Error: findpeak: Sky NAN value for index: %6d", i); logger->logstat = logprint(logger, logger->tmptxt, 0); exit(0); } if (jirisnan(backproj->fitsimage[ee][5][i])) { sprintf(logger->tmptxt, "##938## Error: findpeak: backproj->fitsimage[ee][5] NAN value for index: %6d", i); logger->logstat = logprint(logger, logger->tmptxt, 0); exit(0); } else { if (backproj->illumx[i] > backproj->signiflim) { if (logger->edge != 0.0) local_sky[i] = sky[i] * logger->edge * backproj->fitsimage[ee][5][i]; } else { local_sky[i] = 0.0; } } if (jirisnan(sky[i])) { sprintf(logger->tmptxt, "##948## Error: findpeak: Sky NAN value for index: %6d", i); logger->logstat = logprint(logger, logger->tmptxt, 0); exit(0); } sky_sum += sky[i]; local_sky_sum += local_sky[i]; illum_sum += backproj->illumx[i]; fits5_sum += backproj->fitsimage[ee][5][i]; } sprintf(logger->tmptxt, "##914y## Findpeak: input sky_sum: %f, local_sky_sum: %f, ee: %2d, illum_sum: %f, edge: %f, fits5_sum: %f", sky_sum, local_sky_sum, ee, illum_sum, logger->edge, fits5_sum); logger->logstat = logprint(logger, logger->tmptxt, i5); k = m = 0; skymax = -1; m0 = 0; m1 = m2 = 0.0; xyskydim = backproj->sky_xdim; /* define peak point */ for (j=1; jaccess[sky_index] > 0) && /* the following five lines is a Stephane Paltani fix of a NaN problem 2007-09-18 */ ! jirisnan(local_sky[sky_index]) && ! jirisnan(local_sky[sky_index+1]) && ! jirisnan(local_sky[sky_index-1]) && ! jirisnan(local_sky[sky_index+xyskydim]) && ! jirisnan(local_sky[sky_index-xyskydim]) ) { aval = local_sky[sky_index] + local_sky[sky_index+1] + local_sky[sky_index-1] + local_sky[sky_index+xyskydim] + local_sky[sky_index-xyskydim]; m0++; m1 += aval; m2 += aval * aval; if (aval > blocal) { smaxy = i; smaxx = j; blocal = aval; skymax = k = sky_index; sprintf(logger->tmptxt, "##914x## Findpeak: aval-loop: %3d %3d %6d blocal: %8.5f", smaxx, smaxy, skymax, blocal); logger->logstat = logprint(logger, logger->tmptxt, i5); } m++; } } } if (amax[0] < 0.0) { /* use externally defined peak point */ external = 1; skymax = -amax[0]; smaxx = (int)(skymax / xyskydim); smaxy = skymax % xyskydim; } sprintf(logger->tmptxt, "##914## Findpeak: internal/external skymax: %6d %6.0f, XY: %6d %6d", k, -amax[0], smaxx, smaxy); logger->logstat = logprint(logger, logger->tmptxt, i5); k = 0; amax[0] = blocal; if ((m2 == 0.0) || (m0 == 0)) {status = -1; goto exittrace;} if ((local_sky[skymax] < 0.001) && (external == 0)) {status = -2; goto exittrace;} /* calculate peak excess, and peak centroid */ mean = m1 / m0; var = m2/m0 - mean * mean; rms = sqrt(var); *sky_rms = rms; status = skyval(local_sky, skymax + 4, &skval, ee, logger, backproj); level = skval; status += skyval(local_sky, skymax - 4, &skval, ee, logger, backproj); level += skval; status += skyval(local_sky, skymax + 4*xyskydim, &skval, ee, logger, backproj); level += skval; status += skyval(local_sky, skymax - 4*xyskydim, &skval, ee, logger, backproj); level += skval; status += skyval(local_sky, skymax + 4 + xyskydim, &skval, ee, logger, backproj); level += skval; status += skyval(local_sky, skymax - 4 + xyskydim, &skval, ee, logger, backproj); level += skval; status += skyval(local_sky, skymax + 4*xyskydim + 1, &skval, ee, logger, backproj); level += skval; status += skyval(local_sky, skymax - 4*xyskydim + 1, &skval, ee, logger, backproj); level += skval; status += skyval(local_sky, skymax + 4 - xyskydim, &skval, ee, logger, backproj); level += skval; status += skyval(local_sky, skymax - 4 - xyskydim, &skval, ee, logger, backproj); level += skval; status += skyval(local_sky, skymax + 4*xyskydim - 1, &skval, ee, logger, backproj); level += skval; status += skyval(local_sky, skymax - 4*xyskydim - 1, &skval, ee, logger, backproj); level += skval; status += skyval(local_sky, skymax + 4 + 2*xyskydim, &skval, ee, logger, backproj); level += skval; status += skyval(local_sky, skymax - 4 + 2*xyskydim, &skval, ee, logger, backproj); level += skval; status += skyval(local_sky, skymax + 4*xyskydim + 2, &skval, ee, logger, backproj); level += skval; status += skyval(local_sky, skymax - 4*xyskydim + 2, &skval, ee, logger, backproj); level += skval; status += skyval(local_sky, skymax + 4 - 2*xyskydim, &skval, ee, logger, backproj); level += skval; status += skyval(local_sky, skymax - 4 - 2*xyskydim, &skval, ee, logger, backproj); level += skval; status += skyval(local_sky, skymax + 4*xyskydim - 2, &skval, ee, logger, backproj); level += skval; status += skyval(local_sky, skymax - 4*xyskydim - 2, &skval, ee, logger, backproj); level += skval; status += skyval(local_sky, skymax + 4 + 3*xyskydim, &skval, ee, logger, backproj); level += skval; status += skyval(local_sky, skymax - 4 + 3*xyskydim, &skval, ee, logger, backproj); level += skval; status += skyval(local_sky, skymax + 4*xyskydim + 3, &skval, ee, logger, backproj); level += skval; status += skyval(local_sky, skymax - 4*xyskydim + 3, &skval, ee, logger, backproj); level += skval; status += skyval(local_sky, skymax + 4 - 3*xyskydim, &skval, ee, logger, backproj); level += skval; status += skyval(local_sky, skymax - 4 - 3*xyskydim, &skval, ee, logger, backproj); level += skval; status += skyval(local_sky, skymax + 4*xyskydim - 3, &skval, ee, logger, backproj); level += skval; status += skyval(local_sky, skymax - 4*xyskydim - 3, &skval, ee, logger, backproj); level += skval; sprintf(logger->tmptxt, "##914## Findpeak: status after summing bckgr level: %5d, sum_level: %f\n zYx Contribution map:", status, level/28.0); logger->logstat = logprint(logger, logger->tmptxt, i5); if ((status < 0) && (external == 0)) {status = -3; goto exittrace;} level /= 28.0; contrib = local_sky[skymax] - level; excess = contrib; x_cent = smaxx * contrib; y_cent = smaxy * contrib; for (k=1; k<4; k++) { ok = 0; delcon = delx = dely = 0.0; j = smaxx + k; i = smaxy; sky_index = j * backproj->sky_ydim + i; if ((sky_index >= 0) && (sky_index < backproj->skydim)) { if (backproj->illumx[sky_index] > backproj->signiflim) { contrib = local_sky[sky_index] - level; delcon += contrib; delx += contrib * (float)(j); dely += contrib * (float)(i); ok++; } } j = smaxx - k; i = smaxy; sky_index = j * backproj->sky_ydim + i; if ((sky_index >= 0) && (sky_index < backproj->skydim)) { if (backproj->illumx[sky_index] > backproj->signiflim) { contrib = local_sky[sky_index] - level; delcon += contrib; delx += contrib * (float)(j); dely += contrib * (float)(i); ok++; } } j = smaxx; i = smaxy + k; sky_index = j * backproj->sky_ydim + i; if ((sky_index >= 0) && (sky_index < backproj->skydim)) { if (backproj->illumx[sky_index] > backproj->signiflim) { contrib = local_sky[sky_index] - level; delcon += contrib; delx += contrib * (float)(j); dely += contrib * (float)(i); ok++; } } j = smaxx; i = smaxy - k; sky_index = j * backproj->sky_ydim + i; if ((sky_index >= 0) && (sky_index < backproj->skydim)) { if (backproj->illumx[sky_index] > backproj->signiflim) { contrib = local_sky[sky_index] - level; delcon += contrib; delx += contrib * (float)(j); dely += contrib * (float)(i); ok++; } } if (ok == 4) { excess += delcon; x_cent += delx; y_cent += dely; } } for (k=0; k<9; k++) { ok = 0; delcon = delx = dely = 0.0; j = smaxx + (int)(k / 3) + 1; i = smaxy + (k % 3) + 1; sky_index = j * backproj->sky_ydim + i; if ((sky_index >= 0) && (sky_index < backproj->skydim)) { if (backproj->illumx[sky_index] > backproj->signiflim) { contrib = local_sky[sky_index] - level; delcon += contrib; delx += contrib * (float)(j); dely += contrib * (float)(i); ok++; } } j = smaxx - (int)(k / 3) + 1; i = smaxy + (k % 3) + 1; sky_index = j * backproj->sky_ydim + i; if ((sky_index >= 0) && (sky_index < backproj->skydim)) { if (backproj->illumx[sky_index] > backproj->signiflim) { contrib = local_sky[sky_index] - level; delcon += contrib; delx += contrib * (float)(j); dely += contrib * (float)(i); ok++; } } j = smaxx + (int)(k / 3) + 1; i = smaxy - (k % 3) + 1; sky_index = j * backproj->sky_ydim + i; if ((sky_index >= 0) && (sky_index < backproj->skydim)) { if (backproj->illumx[sky_index] > backproj->signiflim) { contrib = local_sky[sky_index] - level; delcon += contrib; delx += contrib * (float)(j); dely += contrib * (float)(i); ok++; } } j = smaxx - (int)(k / 3) + 1; i = smaxy - (k % 3) + 1; sky_index = j * backproj->sky_ydim + i; if ((sky_index >= 0) && (sky_index < backproj->skydim)) { if (backproj->illumx[sky_index] > backproj->signiflim) { contrib = local_sky[sky_index] - level; delcon += contrib; delx += contrib * (float)(j); dely += contrib * (float)(i); ok++; } } if (ok == 4) { excess += delcon; x_cent += delx; y_cent += dely; } } excess = 0.0; x_cent = y_cent = 0.0; for (j=smaxx-3; j<=smaxx+3; j++) { sprintf(logger->tmptxt, " "); for (i=smaxy-3; i<=smaxy+3; i++) { sky_index = j * backproj->sky_ydim + i; if ((sky_index >= 0) && (sky_index < backproj->skydim)) { if (backproj->illumx[sky_index] > backproj->signiflim) contrib = local_sky[sky_index] - level; else contrib = 0.0; } else contrib = 0.0; excess += contrib; x_cent += contrib * (float)(j); y_cent += contrib * (float)(i); sprintf(logger->tmptxt2, " %+f", contrib); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } logger->logstat = logprint(logger, logger->tmptxt, i5); } if ((excess < 0.0) && (external == 0)) {status = -4; goto exittrace;} /* New test for (fabs(excess) < 1.0) added to prevent division by zero or meaningless amplification of position corrections Niels Lund 2009_03_05 */ if (fabs(excess) < 1.0) { x_cent = smaxx; y_cent = smaxy; status = -5; skymax = -5; } else { x_cent /= excess; y_cent /= excess; } amax[1] = x_cent; amax[2] = y_cent; amax[3] = excess; amax[4] = level; amax[5] = rms; sprintf(logger->tmptxt, "##914## Findpeak: skymax: %6d, 25pt-exc: %8.1f, lvl: %6.3f, skmap rms: %8.4f, XY: %6.2f %6.2f", skymax, amax[3], amax[4], amax[5], amax[1], amax[2]); logger->logstat = logprint(logger, logger->tmptxt, i5); status = skymax; exittrace: if (logger->trace) { if (status < 0) traces(func_local, 1000-status, logger); traces(func_local, 99, logger); } 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); } /***************************************************************** * Name of source file: backsky_init.c * Version of source file: 3.2.7 * Parent component: j_ima_iros_work * Programmer: Niels Lund & Niels J. Westergaard * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325700 FAX: +45 35362475 * nl@spacecenter.dk & njw@spacecenter.dk * Purpose: Initialize the back projection parameters. * Origin date: 041122 * Update history: 1.0.0 041130 First version * 1.0.4 050126 Test version for undue crash * 1.1.0 050131 Now reading FITS sky/backproj files * 1.1.1 050211 Keywords adapted to needs of j_ima_mosaic * 1.1.2 050303 Extra keyw:RLIMIDX, new cleaning * 1.1.3 050307 New DMAP: 51 radii * 1.1.3 050328 cast 'illum' to 'int' inside 'if'-statements * 1.1.5 050415 New clean again, updated flux determination * 1.1.6 050418 Now uses JMXi-DBKG-MOD as default for empty field shds * 1.2.0 050425 Deals with SPR 4102,4108 and reduces RAM requirement * 1.3.0 050503 Deals with SPR 4120 and copes with up to 6 shadowgrams * 1.3.1 050517 Deals with SPR 4143 and initializes ima_sigma properly * 1.3.2 050519 Closes SPR 4157 - bad size of three arrays * 1.3.3 050602 Changes some arrays to static (SPR 4202) * 1.4.0 050620 Include user defined sources (SCREW 1740) * 1.5.1 051129 Separating functions to jmx_lib_pif * 1.5.2 051202 Separating functions to jmx_lib_pif (2) * 1.5.3 051202 Give offX, x2x values in mm in IMOD-GRP * 1.5.4 060104 Bug in sh_depth corrected, detectmap now in mm * 1.5.5 060106 Introduced one more digit in logfile for src position * 1.5.6 060228 Removed parameter detMapFile and some obsolete variables * 1.5.7 060606 Shifted detCondMap to struct jmx_id and status_map * 1.5.8 060807 SPR 04551 Bad assignment of RLIMIDX corrected * 1.5.9 060807 SPR 04533 Resetting status variable has been removed * 1.5.10 060807 SPR 04523 Declaring testsum as float iso. int * 1.5.11 060807 SPR 04458 A warning log line has been added * 1.5.12 060907 SPR 04301 A relative VIGNDOL path is given * 1.6.0 060911 SCREW 1918 Image correction map and parameters introduced * 1.6.1 060912 SPR 4441 Shadowgrams with too few counts are excluded * 1.6.2 060915 SCREW 1842 A significance map can now be obtained * 1.6.3 060915 An exposure (vignetting) map is now a product * 1.6.4 060928 Included test for zero divisor in peaktransfer.c * 1.6.5 061002 New defaults for par. skyImagesOut * 1.7.0 061110 Produces images with few or zero events (SPR 4594) * 1.7.1 061114 SPR 4603 Image unit (BUNIT) is now cts/dm2/s * 1.8.0 061213 SPR 4640 Error in findpeak has been corrected * 1.8.1 070123 SPR 4590 int changed to long for 64 bit code * 2.1.0 070730 Active use of input source catalog * 2.1.0 070809 SCREWs 2021-2023 * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.2.0 071205 Flux determination has been improved * 2.2.1 071205 SPR 4742: Division by zero eliminated * 2.2.2 080111 Makes trigger rates from JEM-X HK available * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 3.2.7 100224 SPR 4915: Fixing logics for sparse shadowgrams * Local version 1.0 050207 Included snapshot call * Type of element: Function * Part of package: j_ima_iros * Name: backsky_init * Calls: * Returns: * Required components: DAL, PIL, RIL, DAL3GEN docend: Various remarks: Flow of program: *****************************************************************/ int backsky_init( int jemx, int dead_ano, struct log_con *logger, struct backpro *backproj, struct instr_data *jmx_id, struct shadowgrams *sh, struct backpro_lists *bp, userbin *USERBIN, struct scwlist *SCWnow, int chatter, int status ) { int i=0, j=0, ee=0, ee3=0; static int done_data_input = 0; float fx=0.0, fy=0.0; Instrument jemxNum; static int func_local = -1, local_calling_num=0; clock_t clock(void), calling_TT, TT_now; if( status != ISDC_OK ) return( status ); /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "backsky_init"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ if (logger->trace) traces(func_local, 1, logger); /* ++++ The following part is only executed once ! +++++++ */ if (done_data_input == 1) goto skip; done_data_input = 1; logger->fun_last = 0; logger->peak_last = 0; if( chatter > J_CHATTY_VERY_VERBOSE ) { RILlogMessage( NULL, Log_0,"##169## backsky_init called with backproj->indep = %f", backproj->indep ); } if( jmx_id->jmx_unit == 0 ) { jemxNum = JMX1; } else if( jmx_id->jmx_unit == 1 ) { jemxNum = JMX2; } else { RILlogMessage( NULL, Error_0, "##170## jmx_id->jmx_unit has illegal value: %d", jmx_id->jmx_unit ); return(J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_BADJEMXNUM ); } /* * Prior to the creation of jmx_lib_pif library the call of alignment_init * was placed here [NJW/2005-11-30] */ if( chatter > J_CHATTY_VERY_VERBOSE ) { RILlogMessage( NULL, Log_0,"##171## Before backpro8_init"); status = snapshot1( "##172##", backproj, sh, chatter, status ); } if( !backproj->makeNewBPL ) { status = backpro8_init( jemxNum, logger, bp, backproj, SCWnow, chatter, status ); } else { RILlogMessage( NULL, Log_0,"##173## Making new BPL: %s", backproj->newBackProjFile); } if (status != ISDC_OK ) { logger->logstat = logprint(logger, logger->error_text, 7); goto exittrace; } backproj->indep = bp->parameters[10]; if( chatter > J_CHATTY_VERY_VERBOSE ) { RILlogMessage( NULL, Log_0,"##174## After backpro8_init"); status = snapshot1( "##175##", backproj, sh, chatter, status ); } if (backproj->indep != 0.0) { for (ee=0; eeee_basic; ee++) { if( chatter > J_CHATTY_VERY_VERBOSE ) { RILlogMessage( NULL, Log_0,"##176## Before use of det_rad_lim[%2d]: %3d", ee, logger->det_rad_lim[ee]); } for (j=0; j (float)((logger->det_rad_lim[ee]) *(logger->det_rad_lim[ee]))) USERBIN[ee].soft_gr[j] = -1.0; } } } if( chatter > J_CHATTY_VERY_VERBOSE ) { RILlogMessage( NULL, Log_0,"##177## backproj->ee_basic = %d, signiflim: %d, sky_rad_lim: %f", backproj->ee_basic, backproj->signiflim, logger->sky_rad_lim ); RILlogMessage( NULL, Log_0,"##178## backproj->skydim = %d", backproj->skydim ); } ee3 = 3; if (backproj->ee_basic < ee3) ee3 = backproj->ee_basic; logger->det_rad_lim[ee3] = logger->det_rad_lim[0]; for (ee=1; eedet_rad_lim[ee] < logger->det_rad_lim[ee3]) logger->det_rad_lim[ee3] = logger->det_rad_lim[ee]; /* ****************** */ if( chatter > J_CHATTY_VERY_VERBOSE ) { RILlogMessage( NULL, Log_0,"##179## At end of backsky_init"); status = snapshot1( "##180##", backproj, sh, chatter, status ); } for (ee=0; eeee_basic; ee++) for (i=0; i<6; i++) for (j=0; jskydim; j++) backproj->fitsimage[ee][i][j] = 0.0; skip: exittrace: 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 ); } int saveparams(FILE *sd, int ee, struct instr_data *jmx_id, struct backpro *backproj, struct backpro_lists *bp, struct log_con *logger) { int i, imax; if (logger->develop > 1) fprintf(sd, "'imod_grp' data updated via call to 'jmx_lib_pif/update_imod_data.c'\n\n"); else fprintf(sd, "imod data used without changes\n\n"); fprintf(sd, "jmx_unit: %1d\n", jmx_id->jmx_unit); fprintf(sd, "ee-channel: %1d\n\n", ee); fprintf(sd, "mask_height: %f\n", jmx_id->mask_height); fprintf(sd, "mask_r: %f\n", jmx_id->mask_r); fprintf(sd, "hexa_dim: %f\n", jmx_id->hexa_dim); fprintf(sd, "struc_h1: %f\n", jmx_id->struc_h1); fprintf(sd, "struc_h2: %f\n\n", jmx_id->struc_h2); fprintf(sd, "coll_h : %f\n", jmx_id->coll_h ); fprintf(sd, "coll_r: %f\n", jmx_id->coll_r); fprintf(sd, "coll_pitch: %f\n", jmx_id->coll_pitch); fprintf(sd, "coll_w : %f\n", jmx_id->coll_w ); fprintf(sd, "c_tiltx: %f\n", jmx_id->c_tiltx); fprintf(sd, "c_tilty: %f\n", jmx_id->c_tilty); fprintf(sd, "coll_wb: %f\n", jmx_id->coll_wb); fprintf(sd, "coll_curv: %f\n\n", jmx_id->coll_curv); fprintf(sd, "indep: %f\n", backproj->indep); fprintf(sd, "coll_h_reduc: %f\n\n", bp->coll_h_reduc); fprintf(sd, "xshi : %f\n", jmx_id->xshi ); fprintf(sd, "yshi: %f\n\n", jmx_id->yshi); fprintf(sd, "alfa: %f\n", jmx_id->alfa); fprintf(sd, "beta: %f\n", jmx_id->beta); fprintf(sd, "gammav: %f\n\n", jmx_id->gammav); fprintf(sd, "offXmm: %f\n", jmx_id->offXmm); fprintf(sd, "offYmm: %f\n", jmx_id->offYmm); fprintf(sd, "phase2: %f\n", jmx_id->phase2); fprintf(sd, "x2xmm: %10.8f\n", jmx_id->x2xmm); fprintf(sd, "y2ymm: %10.8f\n", jmx_id->y2ymm); fprintf(sd, "scaleX: %f\n", jmx_id->scaleX); fprintf(sd, "scaleY: %f\n", jmx_id->scaleY); fprintf(sd, "pix_fold_ctrl:%2d\n", logger->pix_fold_ctrl); fprintf(sd, "develop: %5d\n", logger->develop); fprintf(sd, "offQrad: %f\n", jmx_id->offQrad); fprintf(sd, "offRrad: %f\n\n", jmx_id->offRrad); fprintf(sd, "numShds: %d\nabs_len: ", backproj->numShds); imax = backproj->numShds; if (imax > 10) imax = 10; for (i=0; iabs_len[i]); fprintf(sd, "\nabsolen: %f\n", jmx_id->absolen); fprintf(sd, "x_rms: "); for (i=0; ix_rms[i]); fprintf(sd, "\ny_rms: "); for (i=0; iy_rms[i]); fprintf(sd, "\nscatt_len: %d\n\n", jmx_id->scatt_len); fprintf(sd, "mm2rad: %f\n", jmx_id->mm2rad); fprintf(sd, "useHexpos: %1d\n", logger->useHexpos); fprintf(sd, "signiflim: %d\n\n", backproj->signiflim); fprintf(sd, "Tx0: %f\n", jmx_id->Tx0); fprintf(sd, "off_Tx0: %f\n", jmx_id->off_Tx0); fprintf(sd, "Ty0: %f\n", jmx_id->Ty0); fprintf(sd, "off_Ty0: %f\n", jmx_id->off_Ty0); fprintf(sd, "Tx7: %f\n", jmx_id->Tx7); fprintf(sd, "off_Tx7: %f\n", jmx_id->off_Tx7); fprintf(sd, "Ty7: %f\n", jmx_id->Ty7); fprintf(sd, "off_Ty7: %f\n\n", jmx_id->off_Ty7); fprintf(sd, "bpl_det_radlm %f\n", bp->bpl_det_rad_limit); fprintf(sd, "collp30: %f\n", bp->collp30); fprintf(sd, "coll_ptop: %f\n", bp->coll_ptop); fprintf(sd, "collp30top: %f\n", bp->collp30top); fprintf(sd, "coll_r2: %f\n", bp->coll_r2); fprintf(sd, "mask_r2: %f\n", bp->mask_r2); fprintf(sd, "cosal: %f\n", bp->cosal); fprintf(sd, "sinal: %f\n", bp->sinal); fprintf(sd, "cosbe: %f\n", bp->cosbe); fprintf(sd, "sinbe: %f\n", bp->sinbe); fprintf(sd, "cosga: %f\n", bp->cosga); fprintf(sd, "singa: %f\n", bp->singa); fprintf(sd, "m_fact: %f\n", bp->m_fact); fprintf(sd, "c_factb: %f\n", bp->c_factb); fprintf(sd, "c_fact: %f\n", bp->c_fact); fprintf(sd, "s_fact_l: %f\n", bp->s_fact_l); fprintf(sd, "s_fact_h: %f\n", bp->s_fact_h); fprintf(sd, "cot60: %f\n", bp->cot60); fprintf(sd, "rsin60: %f\n", bp->rsin60); if (chk_radcor_params(jmx_id->jmx_unit, jmx_id, logger)) fprintf(sd, "Errors in radcor parameters !!!!!!!!!!!!!!! \n"); else fprintf(sd, "Radcor parameters verified OK \n"); for (i=0; inum_eeff_vals; i++) { sprintf(logger->tmptxt, " After eeff-update: %2d %6.3f %6.3f", i, jmx_id->eeff_pha[i], jmx_id->eeff[i]); logger->logstat = logprint(logger, logger->tmptxt, 0); fprintf(sd, "%s\n", logger->tmptxt); } for (i=0; i<16; i++) { sprintf(logger->tmptxt, "After time_sl-update: %5.2f %5.2f %9.6f ", jmx_id->Elist[i], jmx_id->Elist[i+1], jmx_id->eeff_time_slope[i]); logger->logstat = logprint(logger, logger->tmptxt, 0); fprintf(sd, "%s\n", logger->tmptxt); } return(0); } /***************************************************************** * Name of source file: FUN.c * Version of source file: 3.2.6 * Parent component: None * Programmer: Niels Lund & Niels J. Westergaard * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325700 FAX: +45 35362475 * nl@spacecenter.dk, njw@spacecenter.dk * Purpose: Get the parameters and open files for the * j_ima_iros executable * Origin date: 041122 * Update history: 1.0.0 041130 First version * 1.0.4 050126 Test version for undue crash * 1.1.0 050131 Now reading FITS sky/backproj files * 1.1.1 050211 Keywords adapted to needs of j_ima_mosaic * 1.1.2 050303 Extra keyw:RLIMIDX, new cleaning * 1.1.3 050307 New DMAP: 51 radii * 1.1.4 050407 New clean, etc. * 1.1.4 050407 New clean, etc. * 1.1.5 050415 New clean again, updated flux determination * 1.1.6 050418 Now uses JMXi-DBKG-MOD as default for empty field shds * 1.2.0 050425 Deals with SPR 4102,4108 and reduces RAM requirement * 1.3.0 050503 Deals with SPR 4120 and copes with up to 6 shadowgrams * 1.3.1 050517 Deals with SPR 4143 and initializes ima_sigma properly * 1.3.2 050519 Closes SPR 4157 - bad size of three arrays * 1.3.3 050602 Changes some arrays to static (SPR 4202) * 1.4.0 050620 Include user defined sources (SCREW 1740) * 1.4.1 051125 Modified call to detectmap * 1.5.1 051129 Separating functions to jmx_lib_pif * 1.5.2 051202 Separating functions to jmx_lib_pif (2) * 1.5.3 051202 Give offX, x2x values in mm in IMOD-GRP * 1.5.4 060104 Bug in sh_depth corrected, detectmap now in mm * 1.5.5 060106 Introduced one more digit in logfile for src position * 1.5.6 060228 Removed parameter detMapFile and some obsolete variables * 1.5.7 060606 Shifted detCondMap to struct jmx_id and status_map * 1.5.8 060807 SPR 04551 Bad assignment of RLIMIDX corrected * 1.5.9 060807 SPR 04533 Resetting status variable has been removed * 1.5.10 060807 SPR 04523 Declaring testsum as float iso. int * 1.5.11 060807 SPR 04458 A warning log line has been added * 1.5.12 060907 SPR 04301 A relative VIGNDOL path is given * 1.6.0 060911 SCREW 1918 Image correction map and parameters introduced * 1.6.1 060912 SPR 4441 Shadowgrams with too few counts are excluded * 1.6.2 060915 SCREW 1842 A significance map can now be obtained * 1.6.3 060915 An exposure (vignetting) map is now a product * 1.6.4 060928 Included test for zero divisor in peaktransfer.c * 1.6.5 061002 New defaults for par. skyImagesOut * 1.7.0 061110 Produces images with few or zero events (SPR 4594) * 1.7.1 061114 SPR 4603 Image unit (BUNIT) is now cts/dm2/s * 1.8.0 061213 SPR 4640 Error in findpeak has been corrected * 1.8.1 070123 SPR 4590 int changed to long for 64 bit code * 2.1.0 070730 Active use of input source catalog * 2.1.0 070809 SCREWs 2021-2023 * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.2.0 071205 Flux determination has been improved * 2.2.1 071205 SPR 4742: Division by zero eliminated * 2.2.2 080111 Makes trigger rates from JEM-X HK available * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * Type of element: Function * Part of package: j_ima_iros * Name: fun * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* */ /* Niels Lund, February 2003 */ /* */ /* */ /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ int FUN( int k_value, int ii, int ee, float srcx[], float srcy[], int jemx, int last, float *value, struct instr_data *jmx_id, struct log_con *logger, struct backpro *backproj, int chatter, int currentStatus ) { static int src_list[SCW_SRCMAX], first = 1, i5, ee_old = -1; int i=0, j=0, n=0, ki=0, track_len=0; int internalStatus=0, sxy=0, n2_of_illum_pix=0, eex=0; int mmpix=0, no_pix_in_proj_area=0, n3_of_illum_pix=0; static char backmap[detdim]; static int odetmap[detdim]; static char initmap[detdim]; static float s_x[SCW_SRCMAX], s_y[SCW_SRCMAX], srcsum[EEMAX], pix_cnt[EEMAX]; float max_pix_val=0.0, sum1 = 0.0, sum2=0.0; float maskXmm=0.0, maskYmm=0.0, maskXpix=0.0, maskYpix=0.0; int comb_delta[500], track_delta[100], comb_len=0; float comb_list[500], track_list[100], sum=0.0; double x=0.0, y=0.0, r=0.0; float peakout=0.0, peakpif=0.0, peakpifeff=0.0; static int func_local = -1, local_calling_num=0; clock_t calling_TT, TT_now; if( currentStatus != ISDC_OK ) return( currentStatus ); /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "FUN"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; if (logger->trace) traces(func_local, 0, logger); logger->func_calling_num = func_local; logger->func_times[local_calling_num] += TT_now - calling_TT; /* function entry timing end */ i5 = logger->i5; internalStatus = 0; *value = 0.0; if( chatter > J_CHATTY_MAXIMAL ) { RILlogMessage( NULL, Log_0, "##308## fun called, k_value: %d, ii: %d, ee: %d, first: %d", k_value, ii, ee, first); } if (first) { first = 0; for( i=0; i < SCW_SRCMAX; i++) src_list[i] = 0; } if (ii == 0) goto backgr_evaluate; if (k_value < 0) { for( i=0; i < SCW_SRCMAX; i++) { src_list[i] = 0; backproj->norm_d[i][ee] = 1.0; } for (j=1; jpif_maps[0][j] = 1.0; backproj->pifeff_maps[0][j] = backproj->effic[j]; backproj->pif_maps[1][j] = 1.0; backproj->pifeff_maps[1][j] = backproj->effic[j]; } if( backproj->act_pix[ee] == 0.0 ) { RILlogMessage( NULL, Error_1, "##309## Pixelcount bad for ee=%d", ee); internalStatus = -1; goto escape; } sum = 0.0; for( i=0; i < detdim; i++) { if ( backproj->soft_gr[i] > 0.0 ) sum+= backproj->empty[ee][i]; } if( sum == 0.0 ) { RILlogMessage( NULL, Warning_1, "##310## sum == 0.0! reset to 1" ); sum = 1.0; } for( i=0; i < detdim; i++) backproj->empty_norm[i] = backproj->empty[ee][i] / sum; internalStatus = 0; goto escape; } if ((backproj->soft_gr[ii] <= 0.0) && (ii != 1)) { internalStatus = 0; goto escape; } if (k_value == 0) { if (backproj->act_pix[ee] == 0.0) { sprintf(logger->error_text, "##311## Pixelcount not defined" " for ee=%1d in 'fun'", ee); logger->logstat = logprint(logger, logger->error_text, 7); internalStatus = -1; goto escape; } *value = 1.0 / backproj->act_pix[ee]; internalStatus = 0; goto escape; } if (k_value == 1) { *value = backproj->empty[ee][ii]; internalStatus = 0; goto escape; } if (k_value < SCW_SRCMAX) { if ((src_list[k_value] == k_value) && (srcx[k_value] == s_x[k_value]) && (srcy[k_value] == s_y[k_value]) && (ee == ee_old)) goto evaluate; src_list[k_value] = k_value; s_x[k_value] = srcx[k_value]; s_y[k_value] = srcy[k_value]; ee_old == ee; if ((srcx[k_value] >= 0.0) && (srcx[k_value] < backproj->sky_xdim) && (srcy[k_value] >= 0.0) && (srcy[k_value] < backproj->sky_ydim)) ; else { sprintf(logger->error_text, "##312## Bad XY in 'fun' srcx[%2d];" " %6.1f, srcy[%2d]: %6.1f", k_value, srcx[k_value], k_value, srcy[k_value]); logger->logstat = logprint(logger, logger->error_text, 7); internalStatus = -2; goto escape; } sxy = (int)(srcx[k_value]) * backproj->sky_ydim + (int)(srcy[k_value]); maskXpix = srcx[k_value] - (float)(backproj->FOV_radius); maskYpix = srcy[k_value] - (float)(backproj->FOV_radius); maskXmm = maskXpix * backproj->pix2mm; maskYmm = maskYpix * backproj->pix2mm; if (logger->new_detmap) { internalStatus = detectmap2(maskXmm, maskYmm, &(backproj->detmap[k_value][0]), 0, jemx, jmx_id, logger); } if (logger->trace) traces(func_local, 1000+backproj->ee_max, logger); if (logger->trace) traces(func_local, 2000+ee, logger); for (eex=0; eex<=backproj->ee_max; eex++) { if (logger->trace) traces(func_local, 3000+eex, logger); if ((logger->fun_last == 0) && (eex != ee)) continue; /* normally, only calculate area for curr. ee-value */ if (logger->trace) traces(func_local, 4000+eex, logger); sum = 0.0; sum2 = 0.0; backproj->src_illum_cnts[k_value][eex] = 0.0; for (i=0; ixshi; y = (double)(i % 256) - 127.5 + jmx_id->yshi; r = sqrt(x*x + y*y); if ((backproj->soft_gr[i] > 0.0) && (r < (double)(logger->det_rad_lim[eex]))) { if (backproj->detmap[k_value][i] == 1) sum += 1.0; if (backproj->detmap[k_value][i] >= 1) backproj->src_illum_cnts[k_value][eex] += backproj->shadw[i]; if (backproj->detmap[k_value][i] == 2) sum2 += 1.0; } } if (sum2 > 0.0) backproj->norm_d[k_value][eex] = 1.0 / sum2; else backproj->norm_d[k_value][eex] = 0.0; if (logger->trace) traces(func_local, 5000+eex, logger); sprintf(logger->tmptxt, "##309## fun: ee, %2d, k_value: %2d, norm_d: %f", ee, k_value, backproj->norm_d[k_value][ee]); logger->logstat = logprint(logger, logger->tmptxt, i5); if (sum > 0.0) backproj->norm_db[k_value][eex] = 1.0 / sum; else backproj->norm_db[k_value][eex] = 0.0; } if (backproj->norm_d[k_value][ee] <= 0.0) { sprintf(logger->error_text, "##314## No data for sky_index %05d in 'fun', srcx/y: %6.1f %6.1f", sxy, srcx[k_value], srcy[k_value]); /* serious level changed from 7 to 6 by NJW [2009-03-26] */ logger->logstat = logprint(logger, logger->error_text, 6); internalStatus = -3; goto escape; } if (internalStatus < 0) { sprintf(logger->error_text, "##315## Negative status (%3d) on" " return from 'detectmap'", internalStatus); logger->logstat = logprint(logger, logger->error_text, 7); internalStatus = -4; goto escape; } maskXpix = sxy / backproj->sky_ydim; maskYpix = sxy % backproj->sky_ydim; maskXpix -= (backproj->sky_ydim - 1) / 2; maskYpix -= (backproj->sky_xdim - 1) / 2; maskXmm = maskXpix * backproj->pix2mm; maskYmm = maskYpix * backproj->pix2mm; /* calculate detector illumination from (fractional) source position */ /* backproj->detmap contains 2 in illuminated detector pixels, and 1 in area onto which mask pattern is projected */ track_len = sh_depth(maskXmm, maskYmm, track_list, track_delta, jmx_id, logger); if (track_len < 0) { sprintf(logger->error_text, "##317## Negative track_len (%3d)" " on return from 'sh_depth'", track_len); logger->logstat = logprint(logger, logger->error_text, 7); internalStatus = -5; goto escape; } /* calculate distribution of X-ray absorbtion points relative to entry point at window level. track_list contains fraction of (1) photon arriving at detector pixels specified in track_delta */ sum = 0.0; for (i=0; ierror_text, "##318## Negative comb_len (%3d)" " on return from 'shapecomb'", internalStatus); logger->logstat = logprint(logger, logger->error_text, 7); internalStatus = -6; goto escape; } sum = 0.0; for (i=0; idetmap[k_value][0]), comb_list, comb_delta, comb_len, &(backproj->pif_maps[k_value][0]), last, logger); /* backproj->pif_maps[k_value][] contains for each detector pixel the calculated number (float) of photons arriving from source k_value and distributed according to the detector resolution. These pif-values will be applied to the events according to randomized positions (hopefully compensating for the nonuniformity of the raw pixel grid) we will not need to include here a compensation for this nonuniformity. */ sum1 = sum2 = 0.0; n3_of_illum_pix = 0; for (i=1; ipifeff_maps[k_value][i] = backproj->effic[i] * backproj->pif_maps[k_value][i]; /* Here backproj->pifeff_maps[k_value][] contains for each detector pixel the calculated number (float) of detected photons arriving from source k_value, distributed according to the detector resolution and detected with the specific pixel efficiency */ if (backproj->soft_gr[i] <= 0.0) { backproj->pif_maps[k_value][i] = -1.0; backproj->pifeff_maps[k_value][i] = -1.0; } else { sum1 += backproj->pif_maps[k_value][i]; sum2 += backproj->pifeff_maps[k_value][i]; if (backproj->pifeff_maps[k_value][i] > 0.0) n3_of_illum_pix++; } if (backproj->pif_maps[k_value][i] > peakpif) peakpif = backproj->pif_maps[k_value][i]; if (backproj->pifeff_maps[k_value][i] > peakpifeff) peakpifeff = backproj->pifeff_maps[k_value][i]; } if( sum1 == 0.0 ) { RILlogMessage( NULL, Warning_1,"##319## sum1 == 0.0 in fun.c! Error return"); internalStatus = -8; goto escape; } if( sum2 == 0.0 ) { RILlogMessage( NULL, Warning_1,"##319## sum2 == 0.0 in fun.c! Error return"); internalStatus = -8; goto escape; } backproj->src_effic[k_value] = sum2 / sum1; if (logger->trace) traces(func_local, 1777, logger); n2_of_illum_pix = 0; for (i=1; ipifeff_maps[k_value][i] /= sum2; /* Now backproj->pifeff_maps[k_value][] contains for each detector pixel the calculated fraction of 1 detected photon arriving from source k_value, distributed according to the detector resolution and detected with specific efficiency of each pixel. Since the observed shadowgram data have been 'pixelfolded' to compensate for the nonunifor pixel size the pifeff maps assume shadowgram pixels of uniform size */ if (backproj->pifeff_maps[k_value][i] > peakout) peakout = backproj->pifeff_maps[k_value][i]; if (backproj->detmap[k_value][i] > 1) n2_of_illum_pix++; } if ((last) || (chatter > J_CHATTY_NORMAL)){ no_pix_in_proj_area = n2_of_illum_pix = 0; j = 1<soft_gr[i] >= 0.0) && (backproj->detmap[k_value][i] > 0)) { no_pix_in_proj_area++; /* count pixels in mask projected area */ initmap[i] |= j; srcsum[ee] += backproj->pifeff_maps[k_value][i]; } odetmap[i] += backproj->detmap[k_value][i] * j * j; if (backproj->detmap[k_value][i] > 1) n2_of_illum_pix++; if (backproj->pifeff_maps[k_value][i] > max_pix_val) { max_pix_val = backproj->pifeff_maps[k_value][i]; mmpix = i; } } } } evaluate: if (backproj->norm_d[k_value][ee] < 0.0) { internalStatus = -7; goto escape; } if (backproj->soft_gr[ii] >= 0.0) { *value = backproj->pifeff_maps[k_value][ii]; internalStatus = 0; goto escape; } internalStatus = 0; goto escape; backgr_evaluate: if (backproj->norm_d[k_value][ee] < 0.0) { *value = 0.0; internalStatus = 0; goto escape; } for (i=0; idetmap[k_value][i] > 0) && (backproj->soft_gr[i] >= 0.0)) { n++; ki = i + 771; /* pick four points around illuminated pixel (3+3 pixels away) */ if ((ki >= 0) && (ki < detdim)) backmap[ki] = 1; ki = i - 771; if ((ki >= 0) && (ki < detdim)) backmap[ki] = 1; ki = i + 765; if ((ki >= 0) && (ki < detdim)) backmap[ki] = 1; ki = i - 765; if ((ki >= 0) && (ki < detdim)) backmap[ki] = 1; } } sum = sum2 = 0.0; ki = 0; for (i=0; ipifeff_maps[k_value][i]; if (backmap[i] > 0) { ki++; if (backproj->soft_gr[i] >= 0.0) sum += backproj->shadw[i]; } } sum *= (float)(n) / ((float)(ki) + 0.0001); /* background count corresponding to the illuminated pixels */ *value = sum; internalStatus = 0; escape: currentStatus = J_ERROR_CODE_START + J_IMA_IROS_ERR; switch(internalStatus) { case 0: currentStatus = ISDC_OK; break; case -1: currentStatus += J_IIR_FUNERR1; break; case -2: currentStatus += J_IIR_FUNERR2; break; case -3: currentStatus += J_IIR_FUNERR3; break; case -4: currentStatus += J_IIR_FUNERR4; break; case -5: currentStatus += J_IIR_FUNERR5; break; case -6: currentStatus += J_IIR_FUNERR6; break; case -7: currentStatus += J_IIR_FUNERR7; break; case -8: currentStatus += J_IIR_FUNERR8; break; default: currentStatus += J_IIR_FUNERR8; break; /* added Niels Lund 20100215 */ } if (internalStatus) { RILlogMessage( NULL, Warning_1, "##320## Status after exit switch in 'fun': internal: %2d, current: %6d, offset: %6d", internalStatus, currentStatus, J_ERROR_CODE_START + J_IMA_IROS_ERR); } /* 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; if (logger->trace) traces(func_local, 99, logger); /* function exit timing end */ return(currentStatus); } /* ************************************************************************************************ */ /* */ /* Subroutine for analysis of the PIF-distribution, 'pif_maps[source_id][]', for a single */ /* source. Search for the optimal S/N ratio for flux determination by the proper choice of */ /* PIF-ranges to be used for signal extraction and for background subtraction. */ /* */ /* Niels Lund. November 2009 */ /* */ /* ************************************************************************************************ */ int j_pif_limits2( int source_id, struct backpro *backproj, struct log_con *logger, int status ) { int i, j, k, N[256], imax = 0, jmax = 0, i5 = 0; int N_b_old, PIFlolim, PIFhilim, N_back, N_signal, N_s_old; int Plolimbest, Philimbest, Xlolimbest, Xhilimbest; int PNlolimbest, PNhilimbest, XNlolimbest, XNhilimbest; int S_N_norm, S_N_normbest; int looplim = 250; float S_N_best, p_b, S_N, K, s_n, sigma_i; float p_s, S_X, sigma_x, S_X_best; static double f[256]; double M0[256], M1[256], Q0[256], Q1[256]; double topav, botav, SNsignal, SNvar; float SN, lowav, higav, b_hilim, b_lolim; static int first=0; FILE *gnufil; 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_pif_limits2"); 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); i5 = logger->i5; /* NL 20120122 */ if (first == 0) { for (i=0; i<256; i++) { f[i] = (double)(i) / (float)(looplim); } first = 1; /* gnufil = fopen("pifplot.gnu", "wt"); fclose(gnufil); */ } /* initializations */ backproj->pif_spix[0] = backproj->pif_bpix[0] = 0; backproj->pif_spix[source_id] = backproj->pif_bpix[source_id] = 0; for (i=0; i<256; i++) { M0[i] = M1[i] = Q0[i] = Q1[i] = 0.0; N[i] = 0; } /* set up distribution of pif values (the pif values are quantized in 'looplim' levels) */ for (j=0; jpif_maps[source_id][j] >= 0.0) { i = (int)(backproj->pif_maps[source_id][j] * looplim); if (i < looplim) N[i]++; } backproj->pif_s_pickmap[source_id][j] = backproj->pif_b_pickmap[source_id][j] = 0; backproj->pif_s_pickmap[0][j] = backproj->pif_b_pickmap[0][j] = 0; } Q0[0] = N[0]; /* Q0[i] = cumulative number of pixels with illum <= i */ M0[looplim] = N[looplim-1]; /* M0[i] = cumulative number of pixels with illum >= i */ Q1[0] = 0.0; /* Q1[i] = cumulative (illum * number of pixels with illum) <= i */ M1[looplim] = N[looplim-1] * f[looplim-1]; /* M1[i] = cumulative (illum * number of pixels with illum) >= i */ for (i=1; i PIFlolim; PIFhilim--) { /* loop over possible source sample limits */ N_signal = M0[PIFhilim]; /* get total number of pixels in signal sample */ if (N_signal == N_s_old) continue; N_s_old = N_signal; K = (float)(N_signal) / (float)(N_back); /* ratio of background to signal pixels */ S_N = 0.0; for (i=(looplim-1); i>=PIFhilim; i--) { if (N[i] == 0) continue; sigma_i = sqrt((1.0 + K) / (float)(N[i])) / (f[i] - p_b); s_n = 1.0 / (sigma_i * sigma_i); S_N += s_n; } p_s = (float)(M1[PIFhilim]) / (float)(N_signal); sigma_x = sqrt((1.0 + K) / (float)(N_signal)) / (p_s - p_b); S_X = 1.0 / (sigma_x * sigma_x); if (S_N > S_N_best) { S_N_best = S_N; Plolimbest = PIFlolim; Philimbest = PIFhilim; PNlolimbest = N_back; PNhilimbest = N_signal; } if (S_X > S_X_best) { S_X_best = S_X; Xlolimbest = PIFlolim; Xhilimbest = PIFhilim; XNlolimbest = N_back; XNhilimbest = N_signal; } } } sprintf(logger->tmptxt, "YYY%02d %4d S_N: %7.2f, lim: %2d / %3d, cnt: %5d / %5d / %5d S_X: %7.2f, lim: %2d / %3d, cnt: %5d / %5d / %5d\n", source_id, looplim, sqrt(S_N_best), Plolimbest, Philimbest, PNlolimbest, (int)(Q0[looplim-1] - PNhilimbest - PNlolimbest), PNhilimbest, sqrt(S_X_best), Xlolimbest, Xhilimbest, XNlolimbest, (int)(Q0[looplim-1] - XNhilimbest - XNlolimbest), XNhilimbest); logger->logstat = logprint(logger, logger->tmptxt, i5); backproj->pif_hilim[source_id] = (float)(Philimbest) / (float)(looplim); backproj->pif_lolim[source_id] = (float)(Plolimbest) / (float)(looplim); sprintf(logger->tmptxt, "pif_limits#. pif_lolim: %5.3f, pif_hilim: %5.3f", backproj->pif_hilim[source_id], backproj->pif_lolim[source_id]); logger->logstat = logprint(logger, logger->tmptxt, i5); for (j=0; jpif_maps[source_id][j] > backproj->pif_hilim[source_id]) { backproj->pif_s_pickmap[source_id][j] = 1; backproj->pif_spix[source_id]++; } if ((backproj->pif_maps[source_id][j] >= 0.0) && (backproj->pif_maps[source_id][j] < backproj->pif_lolim[source_id])) { backproj->pif_b_pickmap[source_id][j] = 1; backproj->pif_bpix[source_id]++; } } sprintf(logger->tmptxt, "pif_limits# src: %2d, source/background pixels: %6d %6d", source_id, backproj->pif_spix[source_id], backproj->pif_bpix[source_id]); logger->logstat = logprint(logger, logger->tmptxt, i5); /* Q0[i] = cumulative number of pixels with illum <= i */ /* M0[i] = cumulative number of pixels with illum >= i */ /* Q1[i] = cumulative (illum * number of pixels with illum) <= i */ /* M1[i] = cumulative (illum * number of pixels with illum) >= i */ backproj->pif_SNmax[0] = 0.0; for (i=0; i<150; i++) { if (N[i] == 0) continue; lowav = Q1[i] / Q0[i]; /* average source signal from low illumination pixel sample */ for (j=(looplim-1); j>i; j--) { if (N[j] == 0) continue; higav = M1[j] / M0[j]; /* average source signal from high illumination pixel sample */ SNsignal = (Q0[i] - M0[j] * Q1[i] / M1[j]); SN = SNsignal / sqrt(1.0 / M0[j] + 1.0 / Q0[i]); if (SN > backproj->pif_SNmax[0]) { backproj->pif_SNmax[0] = SN; imax = i; jmax = j; backproj->pif_hisignal[0] = higav; backproj->pif_losignal[0] = lowav; } } } backproj->pif_hilim[0] = (float)(jmax) / (float)(looplim); backproj->pif_lolim[0] = (float)(imax) / (float)(looplim); for (j=0; jpif_maps[source_id][j] > backproj->pif_hilim[0]) { backproj->pif_b_pickmap[0][j] = 1; backproj->pif_bpix[0]++; } if ((backproj->pif_maps[source_id][j] >= 0.0) && (backproj->pif_maps[source_id][j] < backproj->pif_lolim[0])) { backproj->pif_s_pickmap[0][j] = 1; backproj->pif_spix[0]++; } } /* nufil = fopen("pifplot.gnu", "at"); imax = (float)(looplim) * backproj->pif_hilim[source_id]; jmax = (float)(looplim) * backproj->pif_lolim[source_id]; if (jmax == 0) { fprintf(gnufil, "%5.3f %6.0lf\n", 0, Q0[0]); } else { for (i=0; i<=jmax; i++) fprintf(gnufil, "%5.3f %6.0lf\n", (float)(i)/(float)(looplim), Q0[i]); } fprintf(gnufil, "\n\n"); if (jmax == imax) { fprintf(gnufil, "%5.3f %6.0lf\n", (float)(imax)/(float)(looplim), Q0[imax]); } else { for (i=jmax; i<=imax; i++) fprintf(gnufil, "%5.3f %6.0lf\n", (float)(i)/(float)(looplim), Q0[i]); } fprintf(gnufil, "\n\n"); if (imax >= (looplim-1)) { fprintf(gnufil, "%5.3f %6.0lf\n", 1.0, Q0[(looplim-1)]); } else { for (i=imax; i= (looplim-1)) { fprintf(gnufil, "%5.3f %6d \n", 1.0, N[(looplim-1)]); } else { for (i=imax; itrace) 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 ); exittrace: /* exittrace */ if (logger->trace) traces(func_local, 1000-status, logger); goto slut; } /* ******************************************************************************** */ /***************************************************************** * Name of source file: j_fitprep.c * Version of source file: 4.0.12 * Parent component: None * Programmer: Niels Lund * Affiliation: DTU Space * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325705 FAX: +45 35362475 * nl@space.dtu.dk * Purpose: Prepare shadowgram data for source fitting * Origin date: 091207 * Update history: 1.0.0 091207 First version * 4.0.8 120813 SPR ?: Fixes bug in significance image * 4.0.12 120919 SPR ?: Introduce corrections by LP and Co. * Type of element: Function * Part of package: j_ima_iros * Name: j_fitprep * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ /* QQQQQQ */ int j_fitprep( int eeuser, dal_element *theSWG, /* pointer to the SWG */ struct instr_data *jmx_id, struct log_con *logger, struct backpro *backproj, struct shadowgrams *sh, struct backpro_lists *bp, struct scwlist *SCWnow, userbin *USERBIN, int chatter, int status ) { int i, j, k, n; int n_sources, fitcycles; int baseErr; int PIlop; int eeb, klow, khig, i5; int ch1, ch2, ch3, ch4, ch5, ch6, ch7; int chx1[4], chx2[4]; float totcnt[4]; static float xx[SCW_SRCMAX], yy[SCW_SRCMAX]; static float shadow[detdim]; static float resid[detdim]; float fitrms, factor, c_sum; float x, y, r; float aveffi; float meanE, shsum; float abs_len, escape, remaining; float X_rms[256], Y_rms[256]; float RMS_correction, rms_factor = 0.0, x_rms, y_rms; static double solut[SCW_SRCMAX]; double sh_rms2; 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_fitprep"); 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 */ /* 111111 */ /* QQQQQQ */ if (logger->trace) traces(func_local, 0, logger); i5 = logger->i5; /* NL 20120122 */ eeb = eeuser; if (eeb > backproj->ee_basic ) eeb = backproj->ee_basic; for (i=0; ifitsimage[eeb][0][i] = 0.0; backproj->fitsimage[eeb][1][i] = 0.0; backproj->fitsimage[eeb][2][i] = 0.0; backproj->fitsimage[eeb][3][i] = 0.0; backproj->fitsimage[eeb][4][i] = 0.0; backproj->fitsimage[eeb][5][i] = 0.0; USERBIN[eeuser].variance[i] = 0.0; USERBIN[eeuser].raw_imag[i] = 0.0; USERBIN[eeuser].fst_imag[i] = 0.0; USERBIN[eeuser].eff_imag[i] = 0.0; USERBIN[eeuser].illumnew[i] = 0; backproj->skyim_r[i] = 0.0; backproj->skyeff[i] = 0.0; backproj->illumx[i] = 0.0; } for (i=0; ibad_pix_shdg[i] = 0.0; logger->resid1[i] = 0.0; backproj->soft_gr[i] = 0.0; backproj->shadw[i] = 0.0; backproj->effic[i] = 0.0; backproj->src_only_map[i] = 0.0; backproj->current_src_map[i] = 0.0; for (j=0; jpif_maps[j][i] = 0.0; backproj->pifeff_maps[j][i] = 0.0; } USERBIN[eeuser].shadow[i] = 0.0; USERBIN[eeuser].soft_gr[i] = 0.0; USERBIN[eeuser].effic_shdg[i] = 0.0; USERBIN[eeuser].f_shadgram[i] = sh->f_shadgram[eeuser][i]; } backproj->map_cnt = 0; for (PIlop=0; PIlop<256; PIlop++) { X_rms[PIlop] = jmx_id->cposres[PIlop] / 2.36; Y_rms[PIlop] = jmx_id->bposres[PIlop] / 2.36; RMS_correction = 0.5; /* QQQQQ originally: 0.5; Niels Lund 20080421 */ if (jmx_id->jmx_unit == 0) { if (jmx_id->escale[PIlop] < 11.0) rms_factor = 1.0 + RMS_correction; if ((jmx_id->escale[PIlop] >= 11.0) && (jmx_id->escale[PIlop] < 35.0)) rms_factor = 1.0 + RMS_correction * (35.0 - jmx_id->escale[PIlop]) / 24.0; if (jmx_id->escale[PIlop] >= 35.0) rms_factor = 1.0; X_rms[PIlop] /= rms_factor; Y_rms[PIlop] /= rms_factor; } } for (i=0; inumBkgShds; i++) { meanE = 0.0; k = 0; for (j=0; j<256; j++) { if ((jmx_id->escale[j] >= sh->bkg_eval[i][0]) && (jmx_id->escale[j] <= sh->bkg_eval[i][1])) { k++; meanE += jmx_id->escale[j]; } } sh->E_mean_bkg[i] = meanE / (float)(k); c_sum = 0.0; for (n=0; nsoft_shdgr[i][n] > 0.0) c_sum += sh->soft_shdgr[i][n]; sprintf(logger->tmptxt, "j_fitprep: background shadowgram %1d (of %1d), E-mean: %6.2f keV, content: %f", i, sh->numBkgShds, sh->E_mean_bkg[i], c_sum); logger->logstat = logprint(logger, logger->tmptxt, i5); } jmx_id->absolen = 0.0; meanE = 0.0; x_rms = y_rms = abs_len = 0.0; /* New: abs_len ! NL 8/10 2007 */ for (j=sh->pival[eeuser][0]; j<=sh->pival[eeuser][1]; j++) { abs_len += jmx_id->attlen_xe[j] / 1.5; /* NOTE: 1.5 Bar ! NL 8/10 2007 */ x_rms += X_rms[j]; y_rms += Y_rms[j]; meanE += jmx_id->escale[j]; } USERBIN[eeuser].x_rms = x_rms / (sh->pival[eeuser][1] - sh->pival[eeuser][0] + 1); USERBIN[eeuser].y_rms = y_rms / (sh->pival[eeuser][1] - sh->pival[eeuser][0] + 1); /* abs_len calculation corrected. NL 8/10 2007 */ USERBIN[eeuser].abs_len = jmx_id->absolen = abs_len / (sh->pival[eeuser][1] - sh->pival[eeuser][0] + 1); USERBIN[eeuser].PImin = sh->pival[eeuser][0]; USERBIN[eeuser].PImax = sh->pival[eeuser][1]; USERBIN[eeuser].E_min = sh->eval[eeuser][0]; USERBIN[eeuser].E_max = sh->eval[eeuser][1]; meanE /= (sh->pival[eeuser][1] - sh->pival[eeuser][0] + 1); USERBIN[eeuser].E_mean = meanE; for (j=0; jxshi; y = (float)(j % 256) - 127.5 + jmx_id->yshi; r = sqrt(x*x + y*y); if ((sh->soft_shdgr[0][j] > 0.0) && (r < (float)(logger->det_rad_lim[eeuser]))) continue; jmx_id->spagj[j] = -1.0; } if (logger->trace) traces(func_local, 10, logger); status = electronic_eff(eeuser, SCWnow->orbit, sh, USERBIN, jmx_id, logger); if ( status != ISDC_OK ) { logger->logstat = logprint(logger, logger->error_text, 7); status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_IROSLOOPERR; if (logger->trace) traces(func_local, 19, logger); goto exittrace; } escape = exp(-1.0 / jmx_id->absolen); /* escaping fraction through 1 mm of Xe gas (1.5 Bar) */ remaining = 1.0; USERBIN[eeuser].i_depth = 0.0; for (n=0; n<55; n++) { USERBIN[eeuser].i_depth += (1.0 - escape) * remaining * ((float)(n) + 0.5); remaining *= escape; } USERBIN[eeuser].i_depth /= (1.0 - remaining); sprintf(logger->tmptxt, "fitprep: jmx%1d, e-bin: %3d, E_lo/hi: %5.2f %5.2f, meanE: %5.1f, abslen: %5.2f, rmsX/Y: %5.2f %5.2f, i_depth: %5.2f mm, eff_slope: %5.3f", jmx_id->jmx_unit+1, eeuser, sh->eval[eeuser][0], sh->eval[eeuser][1], meanE, USERBIN[eeuser].abs_len, USERBIN[eeuser].x_rms, USERBIN[eeuser].y_rms, USERBIN[eeuser].i_depth, USERBIN[eeuser].eff_slope); logger->logstat = logprint(logger, logger->tmptxt, i5); /* calculate the position scatter around the X-ray absorbtion point at this energy */ jmx_id->scatt_len = sh_xy(USERBIN[eeuser].x_rms, USERBIN[eeuser].y_rms, logger, jmx_id); /* ************************************************************************* */ /* * * */ /* * QQQQQQ * */ /* * Generate background shadowgrams * */ /* * * */ /* * * */ /* ************************************************************************* */ for (i=0; i<4; i++) chx1[i] = chx2[i] = 0; if (USERBIN[eeuser].E_mean <= sh->E_mean_bkg[0]) { for (i=0; icommon_select_map[i] > 0) USERBIN[eeuser].soft_gr[i] = sh->soft_shdgr[0][i]; else USERBIN[eeuser].soft_gr[i] = -1.0; chx1[0]++; if (USERBIN[eeuser].soft_gr[i] > 0.0) chx2[0]++; } klow = 0; khig = 1; factor = 0.0; goto job1done; } if (USERBIN[eeuser].E_mean >= sh->E_mean_bkg[sh->numBkgShds-1]) { for (i=0; icommon_select_map[i] > 0) USERBIN[eeuser].soft_gr[i] = sh->soft_shdgr[sh->numBkgShds-1][i]; else USERBIN[eeuser].soft_gr[i] = -1.0; chx1[3]++; if (USERBIN[eeuser].soft_gr[i] > 0.0) chx2[3]++; } klow = 2; khig = 3; factor = 1.0; goto job1done; } klow = 0; khig = 1; k_igen: /* k_igen */ if ((USERBIN[eeuser].E_mean > sh->E_mean_bkg[klow]) && (USERBIN[eeuser].E_mean <= sh->E_mean_bkg[khig])) { factor = (USERBIN[eeuser].E_mean - sh->E_mean_bkg[klow]) / (sh->E_mean_bkg[khig] - sh->E_mean_bkg[klow]); for (i=0; icommon_select_map[i] > 0) USERBIN[eeuser].soft_gr[i] = sh->soft_shdgr[klow][i] + factor * (sh->soft_shdgr[khig][i] - sh->soft_shdgr[klow][i]); else USERBIN[eeuser].soft_gr[i] = -1.0; chx1[klow]++; if (USERBIN[eeuser].soft_gr[i] > 0.0) chx2[klow]++; } goto job1done; } else { klow++; khig++; if (khig < sh->numBkgShds) goto k_igen; } job1done: ; sprintf(logger->tmptxt, "eeuser: %1d, klow0: chk1/2: %d %d, klow1: %d %d, klow2: %d %d, klow3: %d %d\n", eeuser, chx1[0], chx2[0], chx1[1], chx2[1], chx1[2], chx2[2], chx1[3], chx2[3]); logger->logstat = logprint(logger, logger->tmptxt, i5); ch1 = ch2 = ch3 = ch4 = ch5 = ch6 = ch7 = 0; for (i=0; i 0.0) ch1++; factor = 0.0; for (i=0; icommon_select_map[i] > 0) factor += USERBIN[eeuser].soft_gr[i]; if (factor <= 0.0) { sprintf(logger->tmptxt, "Error: j_fitprep: normalization factor = %f for eeuser: %3d, contrib: %d", factor, eeuser, ch1); logger->logstat = logprint(logger, logger->tmptxt, i5); status = -1; goto exittrace; /* Error return */ } for (i=0; icommon_select_map[i] > 0) USERBIN[eeuser].soft_gr[i] /= factor; c_sum = 0.0; for (j=0; jtmptxt, "In j_fprep: Shadowgram %3d contains %f counts\n", eeuser, c_sum); logger->logstat = logprint(logger, logger->tmptxt, i5); if (c_sum <= 10.0) { sprintf(logger->tmptxt, "Warning: j_fitprep: shadowgram %2d has too few events (%3.0f)", eeuser, c_sum); logger->logstat = logprint(logger, logger->tmptxt, 0); logger->dontUseShdg[eeuser] = 1; c_sum = set_shdg_text(USERBIN[eeuser].f_shadgram, c_sum, eeuser, backproj, jmx_id, sh, logger); } /* prepare variance maps and first backpro-images for all energy bands */ shsum = aveffi = 0.0; totcnt[eeb] = 0.0; for (i=0; ishadw[i] = USERBIN[eeuser].f_shadgram[i]; backproj->effic[i] = USERBIN[eeuser].effic_shdg[i]; if (backproj->effic[i] > 0.0) backproj->soft_gr[i] = backproj->empty[eeb][i] = USERBIN[eeuser].soft_gr[i]; else backproj->soft_gr[i] = backproj->empty[eeb][i] = -1.0; if (backproj->soft_gr[i] > 0.0) { shsum += 1.0; totcnt[eeb] += backproj->shadw[i]; aveffi += backproj->effic[i]; } } if (logger->trace) traces(func_local, 400000+shsum, logger); backproj->act_pix[eeuser] = USERBIN[eeuser].act_pix = shsum; aveffi /= shsum; sprintf(logger->tmptxt, "##999c## E%1d. In fitprep: calling rmscalc with 'USERBIN.f_shadgram'", eeuser); logger->logstat = logprint(logger, logger->tmptxt, i5); rmscalc(backproj->shadw, backproj->soft_gr, logger); sprintf(logger->tmptxt, "Before imageprep: totcnt[%2d] = %6.1f, used pixels: %5d, numShds: %3d, aveffi: %6.3f\n", eeb, totcnt[eeb], (int)(shsum), sh->numShds, aveffi); logger->logstat = logprint(logger, logger->tmptxt, i5); for (i=0; iskydim; i++) backproj->skyeff[i] = 0.0; if (logger->trace) traces(func_local, 20, logger); status = imageprep(jmx_id->jmx_unit, eeb, xx, yy, solut, &fitrms, &sh_rms2, &fitcycles, &n_sources, jmx_id, logger, backproj, bp, sh, chatter, status); /* status = fits_test_output( "raw_skyim_", backproj->skyim_r, 511, logger, chatter, status ); */ if ( status != ISDC_OK ) { if (logger->trace) traces(func_local, 29, logger); logger->logstat = logprint(logger, logger->error_text, 7); status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_IROSLOOPERR; goto exittrace; } totcnt[eeb] = 0.0; for (i=0; ishadw[i]; if (USERBIN[eeuser].soft_gr[i] > 0.0) totcnt[eeb] += backproj->shadw[i]; } if (totcnt[eeb] == 0.0) totcnt[eeb] = 1.0; USERBIN[eeuser].totcnt = totcnt[eeb]; sprintf(logger->tmptxt, "After imageprep: totcnt[%2d] = %6.1f, used pixels: %5d\n", eeb, totcnt[eeb], (int)(shsum)); logger->logstat = logprint(logger, logger->tmptxt, i5); for (i=0; iskydim; i++) { backproj->access[i] = 0; if (backproj->illumx[i] >= (int)(backproj->signiflim)) backproj->access[i] = 1; USERBIN[eeuser].variance[i] = backproj->fitsimage[eeb][0][i]; USERBIN[eeuser].raw_imag[i] = backproj->skyim_r[i]; USERBIN[eeuser].fst_imag[i] = backproj->fitsimage[eeb][2][i]; USERBIN[eeuser].eff_imag[i] = backproj->skyeff[i]; USERBIN[eeuser].illumnew[i] = backproj->illumx[i]; } if (logger->trace) traces(func_local, 30, logger); if ((logger->develop & 4096) == 0) { status = off_axis_transmisImag(eeuser, USERBIN, jmx_id, backproj, logger); } j = 0; for (i=0; iskydim; i++) { if (USERBIN[eeuser].eff_imag[i] != backproj->skyeff[i]) j++; } sprintf(logger->tmptxt, "After 'off_axis_transmisImag': number of modified pixels: %9d\n", j); logger->logstat = logprint(logger, logger->tmptxt, 0); if ( status != ISDC_OK ) { logger->logstat = logprint(logger, logger->error_text, 7); status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_IROSLOOPERR; if (logger->trace) traces(func_local, 39, logger); goto exittrace; } /* QQQQQQ */ exittrace: ; /* exittrace */ 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 ); } /* **************************************************************** * Name of source file: set_shdg_text.c * Version of source file: 4.0.12 * Parent component: None * Programmer: Niels Lund * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325716 FAX: +45 35362475 * nl@space.dtu.dk * Purpose: prepare text content in shadowgram to warn users of empty shadowgrams * Origin date: 20110701 * Update history: 1.0.0 20110701 First version * 4.0.12 120919 SPR ?: Introduce corrections by LP and Co. * Type of element: Function * Part of package: j_ima_iros * Name: set_shdg_text * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ /* QQQQQQ */ int set_shdg_text( float shadowgr[], float c_sum, int eeuser, struct backpro *backproj, struct instr_data *jmx_id, struct shadowgrams *sh, struct log_con *logger) { char txtline[65]; int i, j, k, i5 = 0, r_sum=0; int n, m, mm; int karakter[7][5]; 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], "set_shdg_text"); 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 */ /* 111111 */ /* QQQQQQ */ if (logger->trace) traces(func_local, 0, logger); i5 = logger->i5; sprintf(txtline, "%04d%04d%04d JMX%1d E%02d only %02d events - disregard output!", backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv, jmx_id->jmx_unit+1, eeuser, (int)(c_sum)); for (i=0; i<65536; i++) shadowgr[i] = 0.0; j = 256 * 128 + 95; for (i=0; i<62; i++) { getKarakter(atoi(&(txtline[i])), karakter); for (k=0; k<7; k++) { for (n=0; n<5; n++) { mm = j + k * 256 + n; shadowgr[mm] = (float)(karakter[k][n]); r_sum += karakter[k][n]; } } } return(r_sum); } /***************************************************************** * Name of source file: subshadowgram.c * Version of source file: 1.0.0 * Parent component: None * Programmer: Niels Lund * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325716 FAX: +45 35362475 * nl@dnsc.dk * Purpose: Generate a shadowgram for the next time slice * Temporary version * Origin date: 20100122 * Update history: 1.0.0 20100122 First version * Type of element: Executable * Part of package: j_ima_iros * Name: subshadowgram * Calls: * Returns: * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ int subshadowgram( Events *bufevents, struct shadowgrams *sh, struct scwlist *SCWnow, struct instr_data *jmx_id, struct backpro *backproj, struct log_con *logger, int status) { int i, j, k, q, qq, i5; int Estatus, ix, iy, sxy, mask; static int distr[32], Edistr[32]; double mean_gain, mean_corf, sumIJDdif, previousIJD; 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], "subshadowgram"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } 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); if( status != ISDC_OK ) goto exittrace; if(SCWnow->numEvents == 0) goto exittrace; i5 = logger->i5; /* * Struct Events with event information: *typedef struct { * int rawx; * int rawy; * int pi; * int pha; * int status; * float pif; * double ijd; * float gain; * float corfac; factor to correct for grey filter and * deadtime ( cor_fac > 1.0 ) * float coreeff; Electronic efficiency correction factor * float energy; Energy in keV from PI value by randomization *} Events; * * Estatus = jmx_id->status_map[sxy]; */ j = 0; k = -1; mean_gain = mean_corf = sumIJDdif = 0.0; previousIJD = bufevents[0].ijd; if (logger->trace) traces(func_local, 10, logger); if (logger->trace) traces(func_local, (int)(1000000+SCWnow->numEvents), logger); for (i=0; inumEvents; i++) { k = bufevents[i].status; ix = bufevents[i].rawx; iy = bufevents[i].rawy; sxy = ix * 256 + iy; if ((sxy >= 0) && (sxy < SKYDIM)) Estatus = (int)(jmx_id->status_map[sxy]); else Estatus = 0xFFFF; /* if ((i > 350) && (i < 500)) { sprintf(logger->tmptxt, "XEvents: %8d, X/Y: %3d %3d, pha: %5d, pi: %4d, gain: %5.2f, corf: %5.3f, IJD: %12.8f, status: %4x, Estatus: %4x", i, bufevents[i].rawx, bufevents[i].rawy, bufevents[i].pha, bufevents[i].pi, bufevents[i].gain, bufevents[i].corfac, bufevents[i].ijd, bufevents[i].status, Estatus); logger->logstat = logprint(logger, logger->tmptxt, i5); } */ if (i > 0) { mean_gain += bufevents[i].gain; mean_corf += bufevents[i].corfac * (bufevents[i].ijd - previousIJD); sumIJDdif += bufevents[i].ijd - previousIJD; } previousIJD = bufevents[i].ijd; } mean_corf /= sumIJDdif; mean_gain /= SCWnow->numEvents; mean_corf /= SCWnow->numEvents; for (i=0; i<32; i++) distr[i] = Edistr[i] = 0; for (i=0; inumEvents; i++) { ix = bufevents[i].rawx; iy = bufevents[i].rawy; sxy = ix * 256 + iy; Estatus = (int)(jmx_id->status_map[sxy]); k = bufevents[i].status; mask = 1; for (j=0; j<31; j++) { if ((k & mask) == mask) distr[(j+1)&0x1F]++; if ((Estatus & mask) == mask) Edistr[(j+1)&0x1F]++; mask <<= 1; mask &= 0xFFFFFFFF; } if (k == 0) distr[0]++; if (Estatus == 0) Edistr[0]++; } mask = 0; for (j=0; j<32; j++) { sprintf(logger->tmptxt, "Eventstatus values: %4x, Efile-status: %6d, XYstatusMap: %6d, flag value: %8d", j, distr[j], Edistr[j], mask); logger->logstat = logprint(logger, logger->tmptxt, i5); mask <<= 1; if (mask == 0) mask = 1; } /* sprintf(logger->tmptxt, "numEvents: %8d, gtiStartIJD: %12.8f, gtiStopIJD: %12.8f, numShds: %3d, accumT: %6.1f, avg_gain: %7.3f", SCWnow->numEvents, SCWnow->gtiStartIJD, SCWnow->gtiStopIJD, sh->numShds, sh->accumT, sh->avg_gain); logger->logstat = logprint(logger, logger->tmptxt, i5); */ sprintf(logger->tmptxt, "mean_gain: %6.3f, avg_gain: %6.3f, mean_corf: %6.4f, calc. timdif: %6.1f s, real timdif: %6.1f s, lastIJD %13.8f", mean_gain, sh->avg_gain, mean_corf, sh->accumT * mean_corf, (bufevents[SCWnow->numEvents-1].ijd - bufevents[0].ijd) * 86400.0, bufevents[SCWnow->numEvents-1].ijd); logger->logstat = logprint(logger, logger->tmptxt, i5); /* * SCWnow->ontime = onTime; * SCWnow->exposure = onTime / comb_corfac; * SCWnow->telapse = timeStartStop[1] - timeStartStop[0]; * SCWnow->deadc = 1./comb_corfac; */ /* function exit timing start */ exittrace: if (logger->trace) traces(func_local, 99, logger); 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); } /***************************************************************** * Name of source file: backpro8_d.c * Version of source file: 3.2.7 * Programmer: Niels Lund & Niels J. Westergaard * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325705 FAX: +45 35362475 * njw@space.dtu.dk * Purpose: Initiate the backprojection and source * finding processes * Origin date: 041122 * Update history: 1.0.0 041130 First version * 1.6.3 060915 An exposure (vignetting) map is now a product * 1.6.4 060928 Included test for zero divisor in peaktransfer.c * 1.6.5 061002 New defaults for par. skyImagesOut * 1.7.0 061110 Produces images with few or zero events (SPR 4594) * 1.7.1 061114 SPR 4603 Image unit (BUNIT) is now cts/dm2/s * 2.1.0 070809 SCREWS 2021-2023 * 2.1.0 070809 SCREWs 2021-2023 * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.2.0 071205 Flux determination has been improved * 2.2.1 071205 SPR 4742: Division by zero eliminated * 2.2.2 080111 Makes trigger rates from JEM-X HK available * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 3.2.7 100224 SPR 4915: Fixing logics for sparse shadowgrams * Type of element: Function * Part of package: j_ima_iros * Name: j_ima_iros_work * Returns: * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ int backpro8_d(float shdgr[detdim], float sky[SKYDIM], struct log_con *logger, struct backpro *backproj, struct backpro_lists *bp) /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* */ /* subroutine to backproject a JEM-X shadowgram as provided in shdgr[detdim] */ /* */ /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ { int det_index, length=0, sky_index, i; int list_index; int numlists, looplim, ix, M, mod, mm, pixlen, iii, status; double sky_X, sky_Y, fov_r2; /* unsigned short bad_reg[SKYDIM]; */ unsigned char *b_bot; float shdgr_val, shdgr_sum, shdgr_abs; static int first = 1, firstp = 1; 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], "backpro8_d"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ if (logger->trace) traces(func_local, 1, logger); for (i=0; iskydim; i++) sky[i] = 0.0; for (i=0; isoft_gr[i] <= 0.0) shdgr[i] = 0.0; fov_r2 = (double)(backproj->FOV_radius * backproj->FOV_radius) * 1.02; if (first) { for (i=0; iskydim; i++) { sky_X = (double)((int)(i / backproj->sky_ydim) - backproj->FOV_radius); sky_Y = (double)((i % backproj->sky_ydim) - backproj->FOV_radius); } /* for (i=0; itestimage[0][i] = 0.0; */ } shdgr_sum = shdgr_abs = 0.0; for (i=0; itmptxt, "##218## Shadowgram sum: %8.3e, abs. sum: %8.1f", shdgr_sum, shdgr_abs); logger->logstat = logprint(logger, logger->tmptxt, 5); iii = 0; M = detdim * 256; /* loop limit */ mod = detdim - 1; /* modulo parameter */ for (mm=256; mmd_allow_l' */ iii++; shdgr_val = shdgr[det_index]; if (shdgr_val == 0.0) continue; pixlen = (int)bp->d_allow_l[det_index]; if (pixlen == 0) continue; if (pixlen == 1) { sky_index = bp->o_allow_p[bp->o_allow_subl[det_index]]; sky[sky_index] += shdgr_val; continue; } looplim = det_index; if (det_index < detdim-257) { numlists = bp->o_allow_subl[(det_index+256)%mod] - bp->o_allow_subl[det_index]; } else { numlists = 0; } b_bot = bp->d_allow + bp->o_allow_st[det_index]; for (list_index=0; list_indexo_allow_p[bp->o_allow_subl[det_index] + list_index]; length = bp->o_allow_len[bp->o_allow_subl[det_index] + list_index]; while (length > 100) { length -= 100; sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); } switch (length) { case 100: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 99: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 98: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 97: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 96: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 95: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 94: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 93: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 92: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 91: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 90: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 89: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 88: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 87: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 86: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 85: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 84: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 83: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 82: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 81: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 80: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 79: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 78: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 77: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 76: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 75: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 74: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 73: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 72: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 71: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 70: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 69: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 68: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 67: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 66: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 65: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 64: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 63: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 62: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 61: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 60: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 59: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 58: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 57: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 56: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 55: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 54: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 53: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 52: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 51: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 50: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 49: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 48: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 47: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 46: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 45: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 44: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 43: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 42: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 41: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 40: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 39: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 38: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 37: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 36: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 35: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 34: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 33: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 32: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 31: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 30: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 29: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 28: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 27: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 26: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 25: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 24: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 23: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 22: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 21: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 20: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 19: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 18: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 17: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 16: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 15: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 14: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 13: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 12: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 11: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 10: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 9: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 8: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 7: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 6: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 5: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 4: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 3: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 2: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 1: sky[sky_index] += shdgr_val; sky_index += (int)(*b_bot++); case 0: sky[sky_index] += shdgr_val; break; default: sprintf(logger->tmptxt, "backpro8_d: switch default take for det_index: %6d length: %5d, sky_index: %7d", det_index, length, sky_index); logger->logstat = logprint(logger, logger->tmptxt, 7); status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_BACKPRO_BAD_DEFAULT; goto exittrace; break; } firstp = 0; } } /* remove dummy points outside the edges of the sky image */ for (sky_index=0; sky_indexskydim; sky_index++) { ix = sky_index / backproj->sky_ydim; if ((bp->ixy_lim[ix][0] >= sky_index) || (bp->ixy_lim[ix][1] <= sky_index)) sky[sky_index] = 0.0; } first = 0; status = 0; exittrace: 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); } /* ************************************************************************** */ /* ************************************************************************** */ int logprint(struct log_con *logger, char text[], int lm) { switch (lm) { case 0: case 1: case 2: case 3: case 4: case 5: if (lm <= logger->chatter) { RILlogMessage(NULL, Log_0, "zYx %s", text); } break; case 6: RILlogMessage(NULL, Warning_0, "zYx %s", text); break; case 7: RILlogMessage(NULL, Error_0, "zYx %s", text); sprintf(text, "Error calling routine: %s, Error text: XXX %s XXX", logger->func_names[logger->func_calling_num], text); break; default: break; } return(0); } /***************************************************************** * Name of source file: j_iir_get_bkgshds.c * Version of source file: 3.2.7 * Parent component: j_ima_iros * Programmer: Niels J. Westergaard & Niels Lund * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325700 FAX: +45 35362475 * njw@spacecenter.dk, nl@spacecenter.dk * Purpose: Read the background shadowgrams to use * Origin date: 041217 * Update history: 1.0.0 041223 First version * 1.0.4 050126 Test version for undue crash * 1.1.0 050131 Now reading FITS sky/backproj files * 1.1.1 050211 Keywords adapted to needs of j_ima_mosaic * 1.1.2 050303 Extra keyw:RLIMIDX, new cleaning * 1.1.3 050307 New DMAP: 51 radii * 1.1.4 050407 New clean, etc. * 1.1.4 050407 New clean, etc. * 1.1.5 050415 New clean again, updated flux determination * 1.1.6 050418 Now uses JMXi-DBKG-MOD as default for empty field shds * 1.2.0 050425 Deals with SPR 4102,4108 and reduces RAM requirement * 1.3.0 050503 Deals with SPR 4120 and copes with up to 6 shadowgrams * 1.3.1 050517 Deals with SPR 4143 and initializes ima_sigma properly * 1.3.2 050519 Closes SPR 4157 - bad size of three arrays * 1.3.3 050602 Changes some arrays to static (SPR 4202) * 1.4.0 050620 Include user defined sources (SCREW 1740) * 1.5.1 051129 Separating functions to jmx_lib_pif * 1.5.2 051202 Separating functions to jmx_lib_pif (2) * 1.5.3 051202 Give offX, x2x values in mm in IMOD-GRP * 1.5.4 060104 Bug in sh_depth corrected, detectmap now in mm * 1.5.5 060106 Introduced one more digit in logfile for src position * 1.5.6 060228 Removed parameter detMapFile and some obsolete variables * 1.5.7 060606 Shifted detCondMap to struct jmx_id and status_map * 1.5.8 060807 SPR 04551 Bad assignment of RLIMIDX corrected * 1.5.9 060807 SPR 04533 Resetting status variable has been removed * 1.5.10 060807 SPR 04523 Declaring testsum as float iso. int * 1.5.11 060807 SPR 04458 A warning log line has been added * 1.5.12 060907 SPR 04301 A relative VIGNDOL path is given * 1.6.0 060911 SCREW 1918 Image correction map and parameters introduced * 1.6.1 060912 SPR 4441 Shadowgrams with too few counts are excluded * 1.6.2 060915 SCREW 1842 A significance map can now be obtained * 1.6.3 060915 An exposure (vignetting) map is now a product * 1.6.4 060928 Included test for zero divisor in peaktransfer.c * 1.6.5 061002 New defaults for par. skyImagesOut * 1.7.0 061110 Produces images with few or zero events (SPR 4594) * 1.7.1 061114 SPR 4603 Image unit (BUNIT) is now cts/dm2/s * 1.8.0 061213 SPR 4640 Error in findpeak has been corrected * 1.8.1 070123 SPR 4590 int changed to long for 64 bit code * 2.1.0 070809 SCREWs 2021-2023 * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.2.0 071205 Flux determination has been improved * 2.2.1 071205 SPR 4742: Division by zero eliminated * 2.2.2 080111 Makes trigger rates from JEM-X HK available * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 3.2.7 100224 SPR 4915: Fixing logics for sparse shadowgrams * Type of element: Executable * Part of package: j_ima_iros * Name: j_iir_get_bkgshds * Calls: * Returns: * Required components: DAL, PIL, RIL, DAL3GEN Basic error code offset: J_ERROR_CODE_START + J_IMA_IROS_ERR *****************************************************************/ int j_iir_get_bkgshds( Instrument jemxNum, /* JMX1 or JMX2 */ dal_element *ptrImod, /* Pointer to IMOD group */ char *bkgShdDOL, /* DOL of bkg shadowgrams */ struct backpro *backproj, /* struct with backprojection info */ struct shadowgrams *sh, /* struct with shadowgram info */ struct log_con *logger, /* log control parameters */ int chatter, /* Level of debugging output */ int status) /* Status flag */ { /* Ordinary variables */ char structName[DS_NAME_SIZE]; char keyName[DS_NAME_SIZE]; int numAxes = 0, i=0; long loop = 0; long loop2 = 0; long startValues[3]={0,0,0}; long endValues[3]={0,0,0}; long numValues = 0; long axes[DAL_MAX_ARRAY_DIMENSION]; float sum = 0.0; float tmp_shd[detdim]; double dtmp = 0.0; /* DAL, RIL, PIL, COMMON declarations */ dal_element *bkgShdPtr = NULL; /* Shadowgram Pointer */ dal_dataType dalType; /* End of DAL etc. declarations */ static int func_local = -1, local_calling_num=0; clock_t calling_TT, TT_now; /* Immediate return if called while executable is in error condition */ if( status != ISDC_OK ) return( status ); /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "j_iir_get_bkgshds"); if (logger->func_used_num > J_IIR_MAX_NUM_FUNCS) { sprintf(logger->tmptxt, "func_used_num > %d", J_IIR_MAX_NUM_FUNCS); logger->logstat = logprint(logger, logger->tmptxt, 6); logger->func_used_num = J_IIR_MAX_NUM_FUNCS; } } 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); /* * Decide whether to use IMOD backgrounds from JMXi-DBKG-MOD * or override with bkgShdDOL * */ for (i=0; inumBkgShds = (int) axes[2]; if( sh->numBkgShds > NMAXBKGSHDS ) { RILlogMessage( NULL, Warning_0,"##3## The supplied number of " "background shadowgrams (%d) exceeds the allowed maximum (%d)", sh->numBkgShds, NMAXBKGSHDS ); RILlogMessage( NULL, Warning_0,"##3## Only the first %d will " "actually be used", NMAXBKGSHDS ); sh->numBkgShds = NMAXBKGSHDS; } if( dalType != DAL_FLOAT ) { RILlogMessage( NULL, Error_0, "##328## Unexpected bkg shd data type"); status = J_ERROR_CODE_START + J_IMA_IROS_ERR + J_IIR_WRONGDATATYPE; DALobjectClose( bkgShdPtr, DAL_SAVE, ISDC_OK ); goto exittrace; } /* * Get energy limits for the background (empty field) shadowgrams */ for( loop = 0; loop < sh->numBkgShds; loop++ ) { sprintf( keyName, "EMIN%3.3i", (int)(loop+1) ); status = DALattributeGetReal( bkgShdPtr, keyName, &dtmp, NULL, NULL, status ); if( status != ISDC_OK) goto exittrace; sh->bkg_eval[loop][0] = dtmp; sprintf( keyName, "EMAX%3.3i", (int)(loop+1) ); status = DALattributeGetReal( bkgShdPtr, keyName, &dtmp, NULL, NULL, status ); if( status != ISDC_OK) goto exittrace; sh->bkg_eval[loop][1] = dtmp; } /* * Read the background shadowgrams */ startValues[0] = 1; startValues[1] = 1; endValues[0] = J_IIR_DIM_STDSHDG; endValues[1] = J_IIR_DIM_STDSHDG; for( loop = 0; loop < sh->numBkgShds; loop++ ) { if( chatter > J_CHATTY_VERY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##329## Going to get image section"); } startValues[2] = loop + 1; endValues[2] = loop + 1; dalType = DAL_DT_UNKNOWN; status = DALarrayGetSection( bkgShdPtr, numAxes, startValues, endValues, &dalType, &numValues, tmp_shd, status); if( status != ISDC_OK ) goto exittrace; /* * Transpose to match expected orientation */ transpose_f( tmp_shd, J_IIR_DIM_STDSHDG ); sum = 0.0; for( loop2 = 0; loop2 < detdim; loop2++ ) { backproj->empty[loop][loop2] = tmp_shd[loop2]; sh->soft_shdgr[loop][loop2] = backproj->empty[loop][loop2]; if( backproj->empty[loop][loop2] > 0.0 ) sum += backproj->empty[loop][loop2]; } if( chatter > J_CHATTY_VERY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##331## empty shd #%ld" " has %f cts. Will be renormalized", loop, sum ); } for( loop2 = 0; loop2 < detdim; loop2++ ) { if( backproj->empty[loop][loop2] > 0.0 ) sh->soft_shdgr[loop][loop2] = backproj->empty[loop][loop2] = backproj->empty[loop][loop2] / sum; } } exittrace: 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 ); } /***************************************************************** * Name of source file: j_iir_get_psfsigma.c * Version of source file: 3.2.7 * Parent component: j_ima_iros * Programmer: Niels J. Westergaard & Niels Lund * Affiliation: National Space Institute/DTU * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325700 FAX: +45 35362475 * njw@space.dtu.dk, nl@space.dtu.dk * Purpose: Get the table values for sigma(PSF) * * Origin date: 090121 * Update history: 3.0.1 090121 First version * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 3.2.7 100224 SPR 4915: Fixing logics for sparse shadowgrams * Type of element: Function * Part of package: j_ima_iros * Name: j_iir_get_psfsigma * Required components: DAL, PIL, RIL, DAL3GEN Basic offset: J_ERROR_CODE_START + J_IMA_IROS_ERR *****************************************************************/ int j_iir_get_psfsigma( Instrument jemxNum, /* JMX1 or JMX2 */ dal_element *ptrImod, /* Pointer to IMOD group */ struct backpro *backproj, /* struct with backprojection data */ struct shadowgrams *sh, /* struct with shadowgrams */ struct log_con *logger, int chatter, /* Level of debugging output */ int status) /* Status flag */ { /* Ordinary variables */ char structName[DS_NAME_SIZE]; int loop = 0; long numRows = 0; long buffSize = 0; long startBin = 0; long endBin = 0; long numValues = 0; float *e_psfsigma = NULL; float *psfsigma = NULL; float result; /* DAL, RIL, PIL, COMMON declarations */ dal_element *elemPtr = NULL; /* Shadowgram Pointer */ dal_dataType dalType; /* End of DAL etc. declarations */ static int func_local = -1, local_calling_num=0; clock_t calling_TT, TT_now; /* Immediate return if called while executable is in error condition */ if( status != ISDC_OK ) return( status ); /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "j_iir_getpsfsigma"); if (logger->func_used_num > J_IIR_MAX_NUM_FUNCS) { sprintf(logger->tmptxt, "func_used_num > %d", J_IIR_MAX_NUM_FUNCS); logger->logstat = logprint(logger, logger->tmptxt, 6); logger->func_used_num = J_IIR_MAX_NUM_FUNCS; } } 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); /* * Get the PSF sigma (PSFS) table * */ if( jemxNum == JMX1 ) { strcpy( structName, "JMX1-PSFS-MOD" ); } else { strcpy( structName, "JMX2-PSFS-MOD" ); } status = DALobjectFindElement( ptrImod, structName, &elemPtr, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_2, "##418## Failed to open %s", structName ); goto exittrace; } /* * Get the number of background shadowgrams * and check axes etc. */ status = DALtableGetNumRows( elemPtr, &numRows, status); startBin = 1; endBin = numRows; status = DALtableGetBuffSize( elemPtr, "ENERGY", 0, DAL_FLOAT, startBin, endBin, &buffSize, status ); status = DALallocateDataBuffer( (void **) &e_psfsigma, buffSize, status ); status = DALallocateDataBuffer( (void **) &psfsigma, buffSize, status ); dalType = DAL_FLOAT; status = DALtableGetCol( elemPtr, "ENERGY", 0, &dalType, &numValues, e_psfsigma, status); status = DALtableGetCol( elemPtr, "PSFSIGMA", 0, &dalType, &numValues, psfsigma, status); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_0, "##419## Problem reading PSFS_IMOD, status = %d", status); goto exittrace; } for( loop = 0; loop < sh->numShds; loop++ ) { status = j_iir_lilipol( numValues, e_psfsigma, psfsigma, 0.5*(sh->eval[loop][0] + sh->eval[loop][1]), &result, status ); backproj->psfsigma[loop] = result; /* PSF sigma in degrees */ if( chatter > J_CHATTY_NORMAL ) { RILlogMessage( NULL, Log_0, "##423## shd#%d: psfsigma=%f", loop, backproj->psfsigma[loop] ); } } status = DALfreeDataBuffer( (void *) e_psfsigma, status ); status = DALfreeDataBuffer( (void *) psfsigma, status ); exittrace: 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 ); } /***************************************************************** * Name of source file: jemxlib_array_put.c * Version of source file: 3.2.7 * Parent component: None * Programmer: Niels J. Westergaard * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325705 FAX: +45 35362475 * njw@dnsc.dk * Purpose: Save an array to the index table * Origin date: 030903 * Update history: 0.0.0 041228 * 1.0.4 050126 Test version for undue crash * 1.1.0 050131 Now reading FITS sky/backproj files * 1.1.1 050211 Keywords adapted to needs of j_ima_mosaic * 1.1.2 050303 Extra keyw:RLIMIDX, new cleaning * 1.1.3 050307 New DMAP: 51 radii * 1.1.4 050407 New clean, etc. * 1.1.4 050407 New clean, etc. * 1.1.5 050415 New clean again, updated flux determination * 1.1.6 050418 Now uses JMXi-DBKG-MOD as default for empty field shds * 1.2.0 050425 Deals with SPR 4102,4108 and reduces RAM requirement * 1.2.1 050501 Introduce calls to 'function timing' and 'traces' * 1.3.0 050503 Deals with SPR 4120 and copes with up to 6 shadowgrams * 1.3.1 050517 Deals with SPR 4143 and initializes ima_sigma properly * 1.3.2 050519 Closes SPR 4157 - bad size of three arrays * 1.3.3 050602 Changes some arrays to static (SPR 4202) * 1.4.0 050620 Include user defined sources (SCREW 1740) * 1.5.1 051129 Separating functions to jmx_lib_pif * 1.5.2 051202 Separating functions to jmx_lib_pif (2) * 1.5.3 051202 Give offX, x2x values in mm in IMOD-GRP * 1.5.4 060104 Bug in sh_depth corrected, detectmap now in mm * 1.5.5 060106 Introduced one more digit in logfile for src position * 1.5.6 060228 Removed parameter detMapFile and some obsolete variables * 1.5.7 060606 Shifted detCondMap to struct jmx_id and status_map * 1.5.8 060807 SPR 04551 Bad assignment of RLIMIDX corrected * 1.5.9 060807 SPR 04533 Resetting status variable has been removed * 1.5.10 060807 SPR 04523 Declaring testsum as float iso. int * 1.5.11 060807 SPR 04458 A warning log line has been added * 1.5.12 060907 SPR 04301 A relative VIGNDOL path is given * 1.6.0 060911 SCREW 1918 Image correction map and parameters introduced * 1.6.1 060912 SPR 4441 Shadowgrams with too few counts are excluded * 1.6.2 060915 SCREW 1842 A significance map can now be obtained * 1.6.3 060915 An exposure (vignetting) map is now a product * 1.6.4 060928 Included test for zero divisor in peaktransfer.c * 1.6.5 061002 New defaults for par. skyImagesOut * 1.7.0 061110 Produces images with few or zero events (SPR 4594) * 1.7.1 061114 SPR 4603 Image unit (BUNIT) is now cts/dm2/s * 1.8.0 061213 SPR 4640 Error in findpeak has been corrected * 1.8.1 070123 SPR 4590 int changed to long for 64 bit code * 2.1.0 070809 SCREWs 2021-2023 * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.2.0 071205 Flux determination has been improved * 2.2.1 071205 SPR 4742: Division by zero eliminated * 2.2.2 080111 Makes trigger rates from JEM-X HK available * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 3.2.7 100224 SPR 4915: Fixing logics for sparse shadowgrams * Type of element: Function * Part of package: jemxlib * Name: jemxlib_array_put * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ int JEMXLIBarrayPut( dal_element *theSWG, /* Pointer to the SWG */ char *elmntName, /* Name of data structure */ dal_element **ptrElmnt, /* Pointer to the new element */ dal_element **ptrIdx, /* Pointer to the index table */ float *array, /* Array to be saved */ long *axes, /* Length of axes */ extraKeywords *kwds, /* Extra keywords for header */ struct log_con *logger, /* log control parameters */ int chatter, /* Level of debugging output */ int status ) /* Status flag */ { void *arrayBuff = NULL; char idxName[18]; /* Name of index table */ int numMembers = 0; /* Number of members in index table */ int numAxes = 0; /* Number of axes in array image */ long startValues[2]; long endValues[2]; dal_dataType DALtype; static int func_local = -1, local_calling_num=0; clock_t calling_TT, TT_now; /* Immediate return if called in error state */ if( status != ISDC_OK ) return( status );; /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "JEMXLIBarrayPut"); if (logger->func_used_num > J_IIR_MAX_NUM_FUNCS) { sprintf(logger->tmptxt, "func_used_num > %d", J_IIR_MAX_NUM_FUNCS); logger->logstat = logprint(logger, logger->tmptxt, 6); logger->func_used_num = J_IIR_MAX_NUM_FUNCS; } } 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); if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##338## JEMXLIBarrayPut has been called"); } /* * Find and return pointer to index table */ if( strqcpy( idxName, elmntName, 14 ) >= 14 ) { RILlogMessage( NULL, Error_0 ,"##339## elmntName too long"); status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_NAMETOOLONG; goto exittrace; } strcat( idxName, "-IDX" ); status = DALobjectFindElement( theSWG, idxName, ptrIdx, status ); /* * Find the number of members in the index table */ status = DAL3GENindexGetNumMembers(theSWG, elmntName, &numMembers, status); if( status != ISDC_OK ) goto exittrace; if( chatter > J_CHATTY_VERBOSE ) RILlogMessage( NULL, Log_0, "##340## Has found: %d members", numMembers); /* * Create and append the new array DS to this table * A template file is required for this job */ status = DAL3GENindexCreateMember( theSWG, elmntName, NULL, ptrElmnt, status ); if( status != ISDC_OK ) goto exittrace; if( chatter > J_CHATTY_VERBOSE ) RILlogMessage( NULL, Log_0, "##341## %s DS appended", elmntName); /* * Stamp the output DS */ status = CommonStampObject( *ptrElmnt, NULL, status ); if( status != ISDC_OK ) goto exittrace; /* * Update the new member with extra keywords */ if( chatter > J_CHATTY_VERBOSE ) RILlogMessage( NULL, Log_0, "##342## Going to update EVTS-SHD member and index table"); status = kwdsWrite( *ptrElmnt, kwds, logger, chatter, status ); if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##343## At return from kwdsWrite" " status = %d", status); } if( status != ISDC_OK ) goto exittrace; numAxes = 2; status = DALarrayModStruct( *ptrElmnt, DAL_FLOAT, numAxes, axes, status); /* Write the array to the data element */ startValues[0] = 1; startValues[1] = 1; endValues[0] = axes[0]; endValues[1] = axes[1]; arrayBuff = array; DALtype = DAL_FLOAT; status = DALarrayPutSection( *ptrElmnt, numAxes, startValues, endValues, DALtype, arrayBuff, status); if( status != ISDC_OK ) goto exittrace; if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##344## array has been put into IMAGE extension"); } exittrace: 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); } /***************************************************************** * Name of source file: backpro8_init.c * Version of source file: 3.2.7 * Parent component: None * Programmer: Niels Lund * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325700 FAX: +45 35362475 * nl@spacecenter.dk * Purpose: Initialize the backprojection process * Origin date: 041122 * Update history: 1.0.0 041130 First version * 1.0.4 050126 Test version for undue crash * 1.1.0 050131 Now reading FITS sky/backproj files * 1.1.1 050211 Keywords adapted to needs of j_ima_mosaic * 1.1.2 050303 Extra keyw:RLIMIDX, new cleaning * 1.1.3 050307 New DMAP: 51 radii * 1.1.4 050407 New clean, etc. * 1.1.4 050407 New clean, etc. * 1.1.5 050415 New clean again, updated flux determination * 1.1.6 050418 Now uses JMXi-DBKG-MOD as default for empty field shds * 1.1.7 050419 Revised for byte storage of lists. Error corrected * 1.2.0 050425 Deals with SPR 4102, 4108 and reduces RAM requirement * 1.4.0 050620 Include user defined sources (SCREW 1740) * 1.5.1 051129 Separating functions to jmx_lib_pif * 1.5.2 051202 Separating functions to jmx_lib_pif (2) * 1.5.3 051202 Give offX, x2x values in mm in IMOD-GRP * 1.5.4 060104 Bug in sh_depth corrected, detectmap now in mm * 1.5.5 060106 Introduced one more digit in logfile for src position * 1.5.6 060228 Removed parameter detMapFile and some obsolete variables * 1.5.7 060606 Shifted detCondMap to struct jmx_id and status_map * 1.5.8 060807 SPR 04551 Bad assignment of RLIMIDX corrected * 1.5.9 060807 SPR 04533 Resetting status variable has been removed * 1.5.10 060807 SPR 04523 Declaring testsum as float iso. int * 1.5.11 060807 SPR 04458 A warning log line has been added * 1.5.12 060907 SPR 04301 A relative VIGNDOL path is given * 1.6.0 060911 SCREW 1918 Image correction map and parameters introduced * 1.6.1 060912 SPR 4441 Shadowgrams with too few counts are excluded * 1.6.2 060915 SCREW 1842 A significance map can now be obtained * 1.6.3 060915 An exposure (vignetting) map is now a product * 1.6.4 060928 Included test for zero divisor in peaktransfer.c * 1.6.5 061002 New defaults for par. skyImagesOut * 1.7.0 061110 Produces images with few or zero events (SPR 4594) * 1.7.1 061114 SPR 4603 Image unit (BUNIT) is now cts/dm2/s * 1.8.0 061213 SPR 4640 Error in findpeak has been corrected * 1.8.1 070123 SPR 4590 int changed to long for 64 bit code * 2.1.0 070809 SCREWs 2021-2023 * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.2.0 071205 Flux determination has been improved * 2.2.1 071205 SPR 4742: Division by zero eliminated * 2.2.2 080111 Makes trigger rates from JEM-X HK available * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 3.2.7 100224 SPR 4915: Fixing logics for sparse shadowgrams * Type of element: Function * Part of package: j_ima_iros * Name: backpro8_init * Calls: * Returns: * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ int backpro8_init( Instrument jemxNum, struct log_con *logger, struct backpro_lists *bp, struct backpro *backproj, struct scwlist *SCWnow, int chatter, int status ) { int bytes = 0; int delta = 0; int sky_index = 0; int det_index = 0; unsigned int index_in = 0; static int first = 1; float cor = 0.0; int i = 0; int k = 0; int iii = 0; int ss = 0; int n255_bytes = 0; int sequence = 0; int seq_max = 0; int byte_index = 0; int odif_all = 0; int byt_c_index = 0; int old_det_index = 0; unsigned d_a_index = 0; unsigned read_index = 0; unsigned out_index = 0; unsigned char d_allow_x[1000]; unsigned char uchar255 = 255; int subl_max=0, subl_tot=0, sublist=0, rr2=0, fov_r=0, ydim=0, sum_subl=0; int list_index=0, det_i_max=0; int sub_bytes=0, working=0, b_bytes=0, remaining=0, nextpos=0; int ix1=0, ix2=0, ix_m=0, n_flag=0; int temppos=0; int yylim[2]={0,0}, M=0, mm=0; int mod=0, prn_cnt=0, d_index=0, kkk=0; unsigned ilen=0; static int func_local = -1, local_calling_num=0; clock_t calling_TT, TT_now; if( status != ISDC_OK ) return( status ); /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "backpro8_init"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ if (logger->trace) traces(func_local, 1, logger); /* if (logger->trace) traces(func_local, (int)(SCWnow), logger); */ if (chatter > J_CHATTY_NORMAL ) { sprintf(logger->tmptxt, "##181## Backprojection group: %s", logger->dolBPL); logger->logstat = logprint(logger, logger->tmptxt, 4); } status = j_iir_read_bpl( logger->dolBPL, jemxNum, bp, logger, chatter, status ); if( status != ISDC_OK ) { RILlogMessage(NULL, Error_1,"##182## %d: Problem getting BPL data", status ); goto exittrace; } bytes = bp->parameters[0]; /* length of 'bp->d_allow' list */ if( chatter > J_CHATTY_NORMAL ) { RILlogMessage( NULL, Log_0, "##183## Length of bp->d_allow list: %d", bytes ); } if (bytes > max_sky_bytes) { sprintf(logger->error_text, "##184## bp->d_allow underdimensioned, bytes = %10d", bytes); logger->logstat = logprint( logger, logger->error_text, 7 ); status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_DIMTOOSMALL; goto exittrace; } if (chatter > J_CHATTY_NORMAL ) { sprintf(logger->tmptxt, "##185## Start unpacking of bp->d_allow"); logger->logstat = logprint(logger, logger->tmptxt, 5); if (first == 0 ) first = 1; } /* ************************************************************************** */ fov_r = backproj->FOV_radius; rr2 = fov_r * fov_r; ydim = backproj->sky_ydim; yylim[0] = 0; yylim[1] = ydim; if( bp->skipNeighborCor ) { for( i = 0; i < SKYDIM; i++ ) bp->ima_cor[i] = 1.0; } else { for( i=0; iima_cor[i] > 0.001) { cor = bp->neighborCorNorm * exp((double)(bp->neighborCorPower * log(bp->ima_cor[i]))); bp->ima_cor[i] = 1.0 / cor; } } } for (i=-fov_r; i<=fov_r; i++) { k = sqrt((double)(rr2 - i*i)) + 0.5; bp->ixy_lim[i+fov_r][0] = (i+fov_r) * ydim + fov_r - k; bp->ixy_lim[i+fov_r][1] = (i+fov_r) * ydim + fov_r + k; if (k <= 127) { if ((i < 0) && ((fov_r+i) > yylim[0])) yylim[0] = fov_r + i; if ((i > 0) && ((fov_r+i) < yylim[1])) yylim[1] = fov_r + i; } } bytes = bp->parameters[0]; /* length of 'd_allow' list */ if (logger->test == 99) goto exittrace; if (logger->test == 20) goto exittrace; sprintf(logger->tmptxt, "Start reading compressed d_allow"); logger->logstat = logprint(logger, logger->tmptxt, 5); /* unsigned d_allow_p[detdim]; */ /* array giving the address of the first sky pixel visible from a given detector pixel */ /* unsigned short d_allow_l[detdim]; */ /* number of sky pixels visible from detector pixel i */ /* unsigned d_allow_st[detdim]; */ /* The d_allow_st array contains for each 16-bit pixel in the detector the 32-bit address of the start of the corresponding list in the d_allow array. */ /* unsigned char *d_allow; */ /* 65536 sky pixel address lists, stored as address differences */ /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! NOTE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! The d_allow-list and the corresponding arrays are [unfortunately] organized such that the index for the arrays should be incremented in steps of 256 (rather than by 1) to follow the organization of d_allow. The following code will generate a monotonically increasing list of pointers into d_allow ('d_a_index'): M = detdim * 256; for (mm=0; mm<=M; mm+=256) { det_index = mm % (detdim-1); ** index value for 'd_allow_st', 'd_allow_p' and 'd_allow_l' ** d_a_index = d_allow_st[det_index]; . . . } */ old_det_index = 0; sequence = 0; seq_max = 0; n255_bytes = 0; det_index = 0; index_in = 0; sublist = 0; sub_bytes = 0; working = 0; b_bytes = 1000; iii = 0; prn_cnt = 0; kkk = 0; byte_index = 0; /* index value into 'd_allow_x' */ read_index = 0; /* index value into 'd_allow' for 1st byte of 'd_allow_x' */ out_index = 0; /* index value into modified 'd_allow' stored back in memory */ for (i=0; i<1000; i++) d_allow_x[i] = *(bp->d_allow + read_index + i); /* read first 1000 bytes of 'd_allow' into 'd_allow_x' */ remaining = 1000; bytes -= b_bytes; /* * for (i=0; i< 1000; i++) { * if ((i%25) == 0) printf("\n %3d ", i); * printf("%3d ", (int)d_allow_x[i]); * } */ M = detdim * 256; /* loop limit */ mod = detdim - 1; /* modulo parameter */ for (mm=256; mmd_allow_l' */ old_det_index = det_index; d_a_index = bp->d_allow_st[det_index]; /* * if (iii < 128) { * if ((iii%8) == 0) printf("\n %3d ", iii); * printf("%6d %4d ", (int)d_a_index, (int)bp->d_allow_l[det_index]); * } */ iii++; byt_c_index = (int)d_a_index - (int)read_index; if (byt_c_index != byte_index) { sprintf(logger->tmptxt, "##186## Backpro8_init: %3d %3d, bad index: byte_idx:" " %6d, calc: %6d, d_a_idx %10u, read_idx: %10u %5d %4d", det_index/256, det_index%256, byte_index, byt_c_index, d_a_index, read_index, iii, b_bytes); logger->logstat = logprint(logger, logger->tmptxt, 7); status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_DIMTOOSMALL; goto exittrace; } while (byte_index >= 1000) { if( chatter > J_CHATTY_VERY_VERBOSE ) { sprintf(logger->tmptxt, "Reducing byte_index: %10d %5d %4d", byte_index, iii, b_bytes); logger->logstat = logprint(logger, logger->tmptxt, 5); } if (bytes <= 0) goto completed; read_index += b_bytes; /* index value into 'd_allow' for 1st byte of 'd_allow_x' */ for (i=0; id_allow + read_index + i); /* read 'b_bytes' bytes of 'd_allow' into 'd_allow_x' */ remaining = b_bytes; byte_index = 0; bytes -= b_bytes; if (bytes < b_bytes) b_bytes = bytes; } if ((ilen = (unsigned)(bp->d_allow_l[det_index])) == 0) { bp->o_allow_st[det_index] = out_index; bp->o_allow_subl[det_index] = list_index; goto next_det_index; } else { if (ilen == 1) { bp->o_allow_st[det_index] = out_index; bp->o_allow_subl[det_index] = list_index; bp->o_allow_p[list_index++] = bp->d_allow_p[det_index]; if (list_index >= max_list_length) { sprintf(logger->tmptxt, "list-index overflow 1"); logger->logstat = logprint(logger, logger->tmptxt, 7); status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_DIMTOOSMALL; goto exittrace; } goto next_det_index; } ilen--; if (working) goto loopstart; bp->o_allow_st[det_index] = out_index; bp->o_allow_subl[det_index] = list_index; bp->o_allow_p[list_index] = bp->d_allow_p[det_index]; sublist = 1; subl_tot = 0; sub_bytes = 0; n_flag = 0; sky_index = bp->d_allow_p[det_index]; working = 1; } loopstart: while (remaining >= 0) { if ((int)d_allow_x[byte_index] == (int)uchar255) { n255_bytes++; sequence++; remaining--; byte_index++; } else { if (sequence) { ix1 = sky_index / ydim; nextpos = sky_index + sequence * 255 + (int)(d_allow_x[byte_index]); if (sequence > seq_max) seq_max = sequence; sequence = 0; if ((bp->ixy_lim[ix1][1] - sky_index) > 255) goto new_sublist; ix2 = nextpos / ydim; if ((nextpos - bp->ixy_lim[ix2][0]) > 255) goto new_sublist; if ((ix2 - ix1) == 1) { bridge: delta = nextpos - sky_index; if (delta > 255) { delta = 255; temppos = sky_index + delta; ix_m = temppos / ydim; if ((ix_m > ix1) && (temppos > bp->ixy_lim[ix_m][0])) delta = bp->ixy_lim[ix_m][0] - sky_index; *(bp->d_allow + out_index) = delta; out_index++; sky_index += delta; sub_bytes++; ix1 = sky_index / ydim; goto bridge; } *(bp->d_allow + out_index) = delta; out_index++; sky_index += delta; sub_bytes++; } else { if ((ix2 < yylim[0]) || (ix1 > yylim[1])) goto bridge; new_sublist: bp->o_allow_len[list_index++] = sub_bytes; if (list_index >= max_list_length) { sprintf(logger->tmptxt, "list-index overflow 2"); logger->logstat = logprint(logger, logger->tmptxt, 7); status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_DIMTOOSMALL; goto exittrace; } sublist++; subl_tot += sub_bytes; sub_bytes = 0; n_flag = 0; ss = sublist % 16; bp->o_allow_p[list_index] = nextpos; sky_index = nextpos; } } else { sky_index += (int)(d_allow_x[byte_index]); *(bp->d_allow + out_index) = d_allow_x[byte_index]; out_index++; sub_bytes++; } remaining--; byte_index++; if (--ilen == 0) { /* we finished with the detector pixel */ bp->o_allow_len[list_index++] = sub_bytes; if (list_index >= max_list_length) { sprintf(logger->tmptxt, "list-index overflow 3"); logger->logstat = logprint(logger, logger->tmptxt, 7); status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_DIMTOOSMALL; goto exittrace; } subl_tot += sub_bytes; if (sublist > subl_max) { subl_max = sublist; det_i_max = det_index; } sum_subl += sublist; odif_all += subl_tot - ((int)(bp->d_allow_st[(det_index+256)%mod])-(int)(bp->d_allow_st[det_index])); det_index += 256; if (det_index == (detdim+255)) goto completed; if (det_index >= detdim) det_index -= detdim - 1; bp->o_allow_subl[det_index] = list_index; sublist = 0; working = 0; subl_tot = 0; sub_bytes = 0; sky_index = bp->d_allow_p[det_index]; goto next_det_index; } } if (remaining <= 0) { if (bytes <= 0) goto completed; read_index += b_bytes; /* index value into 'd_allow' for 1st byte of 'd_allow_x' */ for (i=0; id_allow + read_index + i); /* read 'b_bytes' bytes of 'd_allow' into 'd_allow_x' */ bytes -= b_bytes; if (bytes < b_bytes) b_bytes = bytes; remaining = b_bytes; byte_index = 0; } } next_det_index: ; } completed: bp->bytestretch = d_index; /* if (logger->trace) traces(func_local, bp->bytestretch+8000000, logger); */ if (logger->chatter >= 0) { sprintf(logger->tmptxt, "##187## Backpro8_init compl: bytlist lngth: out: %10u, in:" " %10.0f, subl_max: %4d, di_max: %7d, subl_tot: %7d", out_index, bp->parameters[0], subl_max, det_i_max, sum_subl); logger->logstat = logprint(logger, logger->tmptxt, 5); } exittrace: if (logger->trace) traces(func_local, 99, logger); /* if (logger->trace) traces(func_local, (int)(SCWnow), 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 ); } /* ************************************************************************** */ /***************************************************************** * Name of source file: j_iir_read_bpl.c * Version of source file: 3.2.7 * Parent component: None * Programmer: Niels Lund & Niels J. Westergaard * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325700 FAX: +45 35362475 * nl@spacecenter.dk, njw@spacecenter.dk * Purpose: Read the BPL data * Origin date: 041122 * Update history: 1.0.4 050128 First version * 1.1.0 050131 Now reading FITS sky/backproj files * 1.1.1 050211 Keywords adapted to needs of j_ima_mosaic * 1.1.2 050303 Extra keyw:RLIMIDX, new cleaning * 1.1.3 050307 New DMAP: 51 radii * 1.1.4 050407 New clean, etc. * 1.1.4 050407 New clean, etc. * 1.1.5 050415 New clean again, updated flux determination * 1.1.6 050418 Now uses JMXi-DBKG-MOD as default for empty field shds * 1.1.7 050419 Modifified for byte storage of bpl backprojection lists * 1.2.0 050425 Deals with SPR 4102,4108 and reduces RAM requirement * 1.3.0 050503 Deals with SPR 4120 and copes with up to 6 shadowgrams * 1.3.1 050517 Deals with SPR 4143 and initializes ima_sigma properly * 1.3.2 050519 Closes SPR 4157 - bad size of three arrays * 1.3.3 050602 Changes some arrays to static (SPR 4202) * 1.4.0 050620 Include user defined sources (SCREW 1740) * 1.5.1 051129 Separating functions to jmx_lib_pif * 1.5.2 051202 Separating functions to jmx_lib_pif (2) * 1.5.3 051202 Give offX, x2x values in mm in IMOD-GRP * 1.5.4 060104 Bug in sh_depth corrected, detectmap now in mm * 1.5.5 060106 Introduced one more digit in logfile for src position * 1.5.6 060228 Removed parameter detMapFile and some obsolete variables * 1.5.7 060606 Shifted detCondMap to struct jmx_id and status_map * 1.5.8 060807 SPR 04551 Bad assignment of RLIMIDX corrected * 1.5.9 060807 SPR 04533 Resetting status variable has been removed * 1.5.10 060807 SPR 04523 Declaring testsum as float iso. int * 1.5.11 060807 SPR 04458 A warning log line has been added * 1.5.12 060907 SPR 04301 A relative VIGNDOL path is given * 1.6.0 060911 SCREW 1918 Image correction map and parameters introduced * 1.6.1 060912 SPR 4441 Shadowgrams with too few counts are excluded * 1.6.2 060915 SCREW 1842 A significance map can now be obtained * 1.6.3 060915 An exposure (vignetting) map is now a product * 1.6.4 060928 Included test for zero divisor in peaktransfer.c * 1.6.5 061002 New defaults for par. skyImagesOut * 1.7.0 061110 Produces images with few or zero events (SPR 4594) * 1.7.1 061114 SPR 4603 Image unit (BUNIT) is now cts/dm2/s * 1.8.0 061213 SPR 4640 Error in findpeak has been corrected * 1.8.1 070123 SPR 4590 int changed to long for 64 bit code * 2.1.0 070809 SCREWs 2021-2023 * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.2.0 071205 Flux determination has been improved * 2.2.1 071205 SPR 4742: Division by zero eliminated * 2.2.2 080111 Makes trigger rates from JEM-X HK available * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 3.2.7 100224 SPR 4915: Fixing logics for sparse shadowgrams * Type of element: Function * Part of package: j_ima_iros * Name: j_iir_read_bpl * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ int j_iir_read_bpl( char *dolBPL, /* DOL of large bpl data structures */ Instrument jemxNum, /* JXM1 or JMX2 */ struct backpro_lists *bp, /* struct data array, returned */ struct log_con *logger, int chatter, /* level of chattiness */ int status) /* flag for status when called */ { char elementName[14]; char jemxName[5]; char keyword[9]; unsigned char d_allow_b[D_ALLOW_BINSIZE]; int numAxes = 0; long i = 0; long numValues = 0; long bytes = 0; long startRow = 0; long numRows = 0; long index = 0; long axes[3] = { 0, 0, 0}; long startValues[3] = { 0, 0, 0}; double dtmp = 0.0; dal_element *ptr_DataGrp = NULL; dal_element *ptr = NULL; dal_dataType DALtype; static int func_local = -1, local_calling_num=0; clock_t calling_TT, TT_now; /* No action if fault condition has been reported at time of call */ if( status != ISDC_OK ) goto exittrace; /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "j_iir_read_bpl"); if (logger->func_used_num > J_IIR_MAX_NUM_FUNCS) { sprintf(logger->tmptxt, "func_used_num > %d", J_IIR_MAX_NUM_FUNCS); logger->logstat = logprint(logger, logger->tmptxt, 6); logger->func_used_num = J_IIR_MAX_NUM_FUNCS; } } 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); /* * initialize correction parameters * Removed, now given as parameters * [2006-09-11/NJW] * * bp->neighborCorPower = 1.7; * bp->neighborCorNorm = 1.0; * for (i=0; iima_cor[i] = 1.0; */ /* Open the group */ status = DALobjectOpen( dolBPL, &ptr_DataGrp, status ); if( status != ISDC_OK ) goto exittrace; if( jemxNum == JMX1 ) { strcpy( jemxName, "JMX1" ); } else { strcpy( jemxName, "JMX2" ); } /*-------------------------------------------------------- * NCOR-BPL *-------------------------------------------------------- */ if( chatter > J_CHATTY_NORMAL ) { RILlogMessage( NULL, Log_0, "##388## Looking for NCOR-BPL"); } strcpy( elementName, jemxName ); strcat( elementName, "-NCOR-BPL" ); status = DALobjectFindElement( ptr_DataGrp, elementName, &ptr, status ); if( status != ISDC_OK ) goto exittrace; if( chatter > J_CHATTY_NORMAL ) { RILlogMessage( NULL, Log_0, "##389## Found NCOR-BPL"); } numAxes = 2; startValues[0] = 1; startValues[1] = 1; status = DALattributeGetReal( ptr, "NCORPOWR", &dtmp, NULL, NULL, status ); bp->neighborCorPower = dtmp; status = DALattributeGetReal( ptr, "NCORNORM", &dtmp, NULL, NULL, status ); bp->neighborCorNorm = dtmp; if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##390## %d: Could not read NCORPOWR/NORM", status ); goto exittrace; } status = DALarrayGetStruct( ptr, &DALtype, &numAxes, axes, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##391## %d: After GetStruct", status ); goto exittrace; } status = DALarrayGetSection( ptr, numAxes, startValues, axes, &DALtype, &numValues, bp->ima_cor, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##392## %d: Could not read bp->ima_cor", status ); goto exittrace; } /*-------------------------------------------------------- * DALL-BPL *-------------------------------------------------------- */ if( chatter > J_CHATTY_NORMAL ) { RILlogMessage( NULL, Log_0, "##393## Looking for DALL-BPL"); } strcpy( elementName, jemxName ); strcat( elementName, "-DALL-BPL" ); status = DALobjectFindElement( ptr_DataGrp, elementName, &ptr, status ); if( status != ISDC_OK ) goto exittrace; if( chatter > J_CHATTY_NORMAL ) { RILlogMessage( NULL, Log_0, "##394## Found DALL-BPL"); } /* Read the array data */ /* index_out = 0; */ status = DALattributeGetInt( ptr, "NUMBYTES", &bytes, NULL, NULL, status ); bp->byt_index = bytes; status = DALtableGetNumRows( ptr, &numRows, status ); if ((bp->d_allow = malloc(bytes)) == NULL) { RILlogMessage( NULL, Error_1, "##395## Not enough memory for 'd_allow' malloc (%ld bytes)", bytes); status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_WRONGNUMVALS; goto exittrace; } startRow = 0; index = 0; DALtype = DAL_BYTE; while (bytes >= D_ALLOW_BINSIZE) { startRow++; status = DALtableGetColBins( ptr, "D_ALLOW", 0, &DALtype, startRow, startRow, &numValues, d_allow_b, status ); if( numValues != D_ALLOW_BINSIZE ) { RILlogMessage( NULL, Error_1, "##396## numValues = %ld", numValues ); status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_WRONGNUMVALS; goto exittrace; } bytes -= D_ALLOW_BINSIZE; for (i=0; id_allow + index++) = (unsigned char) d_allow_b[i]; } if( bytes > 0 ) { /* Read the last row */ startRow++; status = DALtableGetColBins( ptr, "D_ALLOW", 0, &DALtype, startRow, startRow, &numValues, d_allow_b, status ); for (i=0; id_allow + index++) = (unsigned char) d_allow_b[i]; } if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##397## After reading d_allow, status = %d", status ); goto exittrace; } if( startRow != numRows ) { RILlogMessage( NULL, Error_1, "##398## Wrong number of rows: numRows = %ld, " "startRow = %ld", numRows, startRow ); status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_WRONGNUMROWS; goto exittrace; } /* * This came from the array writing part: * bp->parameters[0] = bp->byt_index; bp->parameters[3] = backproj->sky_xdim; bp->parameters[4] = -backproj->FOV_radius; bp->parameters[5] = backproj->sky_ydim; bp->parameters[6] = -backproj->FOV_radius; bp->parameters[7] = backproj->coll_model_yes; bp->parameters[8] = jmx_id->jmx_unit; bp->parameters[9] = backproj->FOV_radius; bp->parameters[19] = (float)(backproj->sky_version); */ /* fwrite(bp->parameters, 8, 20, bfil); */ /* fwrite(bp->d_allow_st, 4, detdim, bfil); */ /*-------------------------------------------------------- * DAST-BPL *-------------------------------------------------------- */ if( chatter > J_CHATTY_NORMAL ) { RILlogMessage( NULL, Log_0, "##399## Looking for DAST-BPL"); } strcpy( elementName, jemxName ); strcat( elementName, "-DAST-BPL" ); status = DALobjectFindElement( ptr_DataGrp, elementName, &ptr, status ); if( status != ISDC_OK ) goto exittrace; if( chatter > J_CHATTY_NORMAL ) { RILlogMessage( NULL, Log_0, "##400## Found DAST-BPL"); } /* Read the array data */ status = DALtableGetNumRows( ptr, &numRows, status ); startRow = 1; DALtype = DAL_INT; status = DALtableGetColBins( ptr, "D_ALLOW_ST", 0, &DALtype, startRow, startRow, &numValues, bp->d_allow_st, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##401## After reading d_allow_st, status = %d", status ); goto exittrace; } if( numValues != detdim ) { RILlogMessage( NULL, Error_1, "##402## numValues = %ld", numValues ); status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_WRONGNUMVALS; goto exittrace; } /* * Read parameters as keywords */ for( i = 0; i < 20; i++ ) { sprintf( keyword, "PARMTR%02d", (int) i ); status = DALattributeGetReal( ptr, keyword, &bp->parameters[i], NULL, NULL, status ); } if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##403## After keyword reading, status = %d", status ); goto exittrace; } /* fwrite(bp->d_allow_l, 2, detdim, bfil); */ /*-------------------------------------------------------- * DAWL-BPL *-------------------------------------------------------- */ if( chatter > J_CHATTY_NORMAL ) { RILlogMessage( NULL, Log_0, "##404## Looking for DAWL-BPL"); } strcpy( elementName, jemxName ); strcat( elementName, "-DAWL-BPL" ); status = DALobjectFindElement( ptr_DataGrp, elementName, &ptr, status ); if( status != ISDC_OK ) goto exittrace; if( chatter > J_CHATTY_NORMAL ) { RILlogMessage( NULL, Log_0, "##405## Found DAWL-BPL"); } /* Read the array data */ status = DALtableGetNumRows( ptr, &numRows, status ); startRow = 1; DALtype = DAL_SHORT; status = DALtableGetColBins( ptr, "D_ALLOW_L", 0, &DALtype, startRow, startRow, &numValues, bp->d_allow_l, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##406## After reading d_allow_l, status = %d", status ); goto exittrace; } if( numValues != detdim ) { RILlogMessage( NULL, Error_1, "##407## numValues = %ld", numValues ); status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_WRONGNUMVALS; goto exittrace; } /*-------------------------------------------------------- * DAWP-BPL *-------------------------------------------------------- */ if( chatter > J_CHATTY_NORMAL ) { RILlogMessage( NULL, Log_0, "##408## Looking for DAWP-BPL"); } strcpy( elementName, jemxName ); strcat( elementName, "-DAWP-BPL" ); status = DALobjectFindElement( ptr_DataGrp, elementName, &ptr, status ); if( status != ISDC_OK ) goto exittrace; if( chatter > J_CHATTY_NORMAL ) { RILlogMessage( NULL, Log_0, "##409## Found DAWP-BPL"); } /* Read the array data */ status = DALtableGetNumRows( ptr, &numRows, status ); startRow = 1; DALtype = DAL_ULONG; status = DALtableGetColBins( ptr, "D_ALLOW_P", 0, &DALtype, startRow, startRow, &numValues, bp->d_allow_p, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##410## After reading d_allow_p, status = %d", status ); goto exittrace; } if( numValues != detdim ) { RILlogMessage( NULL, Error_1, "##411## numValues = %ld", numValues ); status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_WRONGNUMVALS; goto exittrace; } /*-------------------------------------------------------- * DMAP-BPL *-------------------------------------------------------- */ if( chatter > J_CHATTY_NORMAL ) { RILlogMessage( NULL, Log_0, "##412## Looking for DMAP-BPL"); } strcpy( elementName, jemxName ); strcat( elementName, "-DMAP-BPL" ); status = DALobjectFindElement( ptr_DataGrp, elementName, &ptr, status ); if( status != ISDC_OK ) goto exittrace; if( chatter > J_CHATTY_NORMAL ) { RILlogMessage( NULL, Log_0, "##413## Found DMAP-BPL"); } numAxes = 3; startValues[0] = 1; startValues[1] = 1; startValues[2] = 1; status = DALarrayGetStruct( ptr, &DALtype, &numAxes, axes, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##414## After GetStruct, status = %d", status ); goto exittrace; } if( axes[2] < N_RAD_LIMITS ) { RILlogMessage( NULL, Warning_2,"##415## Only %ld maps in DMAP, expected %d", axes[2], N_RAD_LIMITS ); } if( axes[2] > N_RAD_LIMITS ) { RILlogMessage( NULL, Error_2,"##416## Too many (%ld) maps in DMAP, expected only %d", axes[2], N_RAD_LIMITS ); status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_WRONGNUMMAPS; goto exittrace; } status = DALarrayGetSection( ptr, numAxes, startValues, axes, &DALtype, &numValues, bp->illumin, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##417## After reading bp->illumin, status = %d", status ); goto exittrace; } status = DALobjectClose( ptr_DataGrp, DAL_SAVE, status ); exittrace: 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); } /***************************************************************** * Name of source file: j_iir_get_XYvsEima.c * Version of source file: 3.2.7 * Parent component: None * Programmer: Niels J. Westergaard & Niels Lund * Affiliation: National Space Institute/Technical University of Denmark * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325700 FAX: +45 35362475 * njw@spacecenter.dk, nl@spacecenter.dk * Purpose: Read the CIEX and CIEY data structures in IMOD * Origin date: 041221 * Type of element: Function * Part of package: j_ima_iros * Name: j_lpf_get_XYvsE * Required components: DAL, PIL, RIL, DAL3GEN, DAL3AUX * Update history: 2.0.0 080617 Copy of get_XYvsE.c * 2.0.0 080617 Reading IMOD * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 3.2.7 100224 SPR 4915: Fixing logics for sparse shadowgrams *****************************************************************/ int j_iir_get_XYvsEima( Instrument jemxNum, dal_element *imodPtr, struct backpro *backproj, int chatter, int status ) { char structName[DS_NAME_SIZE]; char jemxStr[5]; long numValues = 0; long loopi = 0; long loopj = 0; float ffbuffer[16][16]; dal_element *ptr = NULL; dal_dataType dalType; /* assume that jemxNum has already been checked for validity */ if( jemxNum == JMX1 ) { strcpy( jemxStr, "JMX1" ); } else { strcpy( jemxStr, "JMX2" ); } strcpy( structName, jemxStr ); strcat( structName, "-CIEX-MOD" ); status = DALobjectFindElement( imodPtr, structName, &ptr, status ); /*********** * NB! The energy table is identical to the one used by XvsE (IMOD: CFEX and CFEY) * and it is read by j_lpf_get_XYvsE subroutine * * 2008-08-13/NJW **********/ dalType = DAL_FLOAT; status = DALtableGetCol( ptr, "COEFFS", 0, &dalType, &numValues, ffbuffer, status ); for( loopj = 0; loopj < 16; loopj++ ) { for( loopi = 0; loopi < 16; loopi++ ) { backproj->XvsEima[loopi][loopj] = ffbuffer[loopi][loopj]; } } strcpy( structName, jemxStr ); strcat( structName, "-CIEY-MOD" ); status = DALobjectFindElement( imodPtr, structName, &ptr, status ); status = DALtableGetCol( ptr, "COEFFS", 0, &dalType, &numValues, ffbuffer, status ); for( loopj = 0; loopj < 16; loopj++ ) { for( loopi = 0; loopi < 16; loopi++ ) { backproj->YvsEima[loopi][loopj] = ffbuffer[loopi][loopj]; } } return status; } /***************************************************************** * Name of source file: hotpix_chk.c * Version of source file: 3.2.7 * Parent component: None * Programmer: Niels Lund & Niels J. Westergaard * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325700 FAX: +45 35362475 * nl@spacecenter.dk, njw@spacecenter.dk * Purpose: Get the parameters and open files for the * j_ima_iros executable * Origin date: 041122 * Update history: 1.0.0 041130 First version * 1.0.4 050126 Test version for undue crash * 1.1.0 050131 Now reading FITS sky/backproj files * 1.1.1 050211 Keywords adapted to needs of j_ima_mosaic * 1.1.2 050303 Extra keyw:RLIMIDX, new cleaning * 1.1.3 050307 New DMAP: 51 radii * 1.1.4 050407 New clean, etc. * 1.1.4 050407 New clean, etc. * 1.1.5 050415 New clean again, updated flux determination * 1.1.6 050418 Now uses JMXi-DBKG-MOD as default for empty field shds * 1.2.0 050425 Deals with SPR 4102,4108 and reduces RAM requirement * 1.3.0 050503 Deals with SPR 4120 and copes with up to 6 shadowgrams * 1.3.1 050517 Deals with SPR 4143 and initializes ima_sigma properly * 1.3.2 050519 Closes SPR 4157 - bad size of three arrays * 1.3.3 050602 Changes some arrays to static (SPR 4202) * 1.4.0 050620 Include user defined sources (SCREW 1740) * 1.5.1 051129 Separating functions to jmx_lib_pif * 1.5.2 051202 Separating functions to jmx_lib_pif (2) * 1.5.3 051202 Give offX, x2x values in mm in IMOD-GRP * 1.5.4 060104 Bug in sh_depth corrected, detectmap now in mm * 1.5.5 060106 Introduced one more digit in logfile for src position * 1.5.6 060228 Removed parameter detMapFile and some obsolete variables * 1.5.7 060606 Shifted detCondMap to struct jmx_id and status_map * 1.5.8 060807 SPR 04551 Bad assignment of RLIMIDX corrected * 1.5.9 060807 SPR 04533 Resetting status variable has been removed * 1.5.10 060807 SPR 04523 Declaring testsum as float iso. int * 1.5.11 060807 SPR 04458 A warning log line has been added * 1.5.12 060907 SPR 04301 A relative VIGNDOL path is given * 1.6.0 060911 SCREW 1918 Image correction map and parameters introduced * 1.6.1 060912 SPR 4441 Shadowgrams with too few counts are excluded * 1.6.2 060915 SCREW 1842 A significance map can now be obtained * 1.6.3 060915 An exposure (vignetting) map is now a product * 1.6.4 060928 Included test for zero divisor in peaktransfer.c * 1.6.5 061002 New defaults for par. skyImagesOut * 1.7.0 061110 Produces images with few or zero events (SPR 4594) * 1.7.1 061114 SPR 4603 Image unit (BUNIT) is now cts/dm2/s * 1.8.0 061213 SPR 4640 Error in findpeak has been corrected * 1.8.1 070123 SPR 4590 int changed to long for 64 bit code * 2.1.0 070809 SCREWs 2021-2023 * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.2.0 071205 Flux determination has been improved * 2.2.1 071205 SPR 4742: Division by zero eliminated * 2.2.2 080111 Makes trigger rates from JEM-X HK available * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 3.2.7 100224 SPR 4915: Fixing logics for sparse shadowgrams * Type of element: Function * Part of package: j_ima_iros * Name: hotpix_chk * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ float hotpix_chk( float shadowgr[detdim], int ee, struct backpro *backproj, struct log_con *logger) { int i, j, k, imax; float cnt_max = 0.0, mean, sigma, hotcts, min_cts, min_cts2, min_cts3; double m0, m1, m2; 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], "hotpix_chk"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 0); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ if (logger->trace) traces(func_local, 1, logger); m0 = m1 = m2 = 0.0; for (i=0; isoft_gr[i] <= 0.0) continue; if (shadowgr[i] > cnt_max) { cnt_max = shadowgr[i]; imax = i; } m0 += 1.0; m1 += shadowgr[i]; m2 += shadowgr[i] * shadowgr[i]; } k = 0; hotcts = 0.0; if (m0 <= 200.0) goto ret_m; /* for shadowgrams with very few counts hot pixel test is hardly useful */ mean = m1 / m0; sigma = sqrt(m2/m0 - mean*mean); min_cts = J_IIR_HOT_PIX_MIN_CTS; min_cts2 = J_IIR_HOT_PIX_MIN_CTS / 2.0; min_cts3 = J_IIR_HOT_PIX_MIN_CTS / 3.0; if (cnt_max < (min_cts + mean + logger->hotpix_lim * sigma)) goto ret_m; /* no hot pixels */ m0 = m1 = m2 = 0.0; j = 0; for (i=0; isoft_gr[i] <= 0.0) continue; if (shadowgr[i] < (min_cts3 + mean + sigma)) continue; /* prepare for new mean of "high count" pixels */ m0 += 1.0; m1 += shadowgr[i]; m2 += shadowgr[i] * shadowgr[i]; if (shadowgr[i] > (min_cts3 + mean + 4.0*sigma)) j++; /* count "high" pixels */ } if (j < 50) { for (i=0; isoft_gr[i] <= 0.0) continue; if (shadowgr[i] > (min_cts2 + mean + 4.0*sigma)) { backproj->soft_gr[i] = -1.0; /* eliminate "high" pixels */ hotcts += shadowgr[i]; shadowgr[i] = 0.0; } } k = j; goto ret_m; } mean = m1 / m0; sigma = sqrt(m2/m0 - mean*mean); if (cnt_max < (min_cts3 + mean + 3.0 * sigma)) { hotcts = k = 0; /* no hot pixels */ goto ret_m; } for (i=0; isoft_gr[i] <= 0.0) continue; if (shadowgr[i] > (min_cts2 + mean + 4.0*sigma)) { backproj->soft_gr[i] = -1.0; /* eliminate "high" pixels */ hotcts += shadowgr[i]; shadowgr[i] = 0.0; k++; } } ret_m: if (k > 0) { sprintf(logger->tmptxt, "##337## E%1d, Pixels removed: %4d," " counts removed: %6.0f !!!!!!!!!!!!!", ee, k, hotcts); logger->logstat = logprint(logger, logger->tmptxt, 3); } backproj->act_pix[ee] -= (float)(k); 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( hotcts ); } /* **************************************************************************************** */ /* **************************************************************************************** */ /***************************************************************** * Name of source file: pixelfold.c * Version of source file: 4.0.12 * Programmer: Niels Lund & Niels J. Westergaard * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325705 FAX: +45 35362475 * njw@space.dtu.dk * Purpose: Initiate the backprojection and source * finding processes * Origin date: 041122 * Update history: 1.0.0 041130 First version * 1.6.3 060915 An exposure (vignetting) map is now a product * 1.6.4 060928 Included test for zero divisor in peaktransfer.c * 1.6.5 061002 New defaults for par. skyImagesOut * 1.7.0 061110 Produces images with few or zero events (SPR 4594) * 1.7.1 061114 SPR 4603 Image unit (BUNIT) is now cts/dm2/s * 2.1.0 070809 SCREWS 2021-2023 * 2.1.0 070809 SCREWs 2021-2023 * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.2.0 071205 Flux determination has been improved * 2.2.1 071205 SPR 4742: Division by zero eliminated * 2.2.2 080111 Makes trigger rates from JEM-X HK available * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 4.0.12 120919 SPR ?: Introduce corrections by LP and Co. * Type of element: Function * Part of package: j_ima_iros * Name: pixelfold * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ int pixelfold(float det[], int ee, float shadw[detdim], float totcnt[], struct log_con *logger, struct backpro *backproj, struct instr_data *jmx_id) /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* */ /* pixelfold.c corrects for the nonuniform readout grid of */ /* real microstrid detector. The counts recorded in a */ /* particular telemetry pixel is distributed among idealized */ /* 1x1 mm2 pixels on an idealized microstrip detector */ /* */ /* Niels Lund, February 2003 */ /* */ /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ { int i, j, k, m, n, len, index, delta, val, valnum, jemx, status, i5 = 5; double sum1 = 0, sum2 = 0, loss1, valsum, vals; 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], "pixelfold"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ if (logger->trace) traces(func_local, 1, logger); jemx = jmx_id->jmx_unit; for (i=0; isoft_gr[i] <= 0.0)) continue; sum1 += det[i]; vals = 0.0; index = jmx_id->pixel_st[i]; len = jmx_id->pixel_list[index++]; for (j=0; jpixel_list[index++]; val = jmx_id->pixel_list[index++]; vals += val; k = ((delta & 15) - 8); m = ((delta & 240) - 128) * 16; n = i + k + m; if ((n < 0) || (n >= detdim)) { loss1 += val * det[i]; } else { shadw[n] += val * det[i]; } } valsum += vals / 255.0; valnum++; if ((vals > 260.0) || (vals < 250.0)) { index = jmx_id->pixel_st[i]; len = jmx_id->pixel_list[index++]; sprintf(logger->tmptxt, "%6d pixel: len: %1d, [delta/delta'/val]: ", i, len); logger->logstat = logprint(logger, logger->tmptxt, 5); n = 0; for (j=0; jpixel_list[index++]; val = jmx_id->pixel_list[index++]; n += val; k = ((delta & 15) - 8); m = ((delta & 240) - 128) * 16; m += k; sprintf(logger->tmptxt, " %2x/%+4d/%3d ", delta, m, val); logger->logstat = logprint(logger, logger->tmptxt, 5); } sprintf(logger->tmptxt, " sum: %3d", n); logger->logstat = logprint(logger, logger->tmptxt, 5); if ((vals > 260.0) || (vals < 250.0)) { sprintf(logger->tmptxt, "pixelfold: unacceptable vals value: %5.1f", vals); logger->logstat = logprint(logger, logger->tmptxt, 7); status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_PIXFOLDNORMERR; goto exittrace; } } } sum2 = 0.0; for (i=0; isoft_gr[i] <= 0.0) shadw[i] = 0; shadw[i] /= 255.0; sum2 += shadw[i]; } loss1 /= 255.0; /* for (i=0; itmptxt, "pixelfold: sum_in: %10.4lf, loss: %10.4lf, sum_out: %10.4lf, average valsum: %6.4lf", sum1, loss1, sum2, valsum/valnum); logger->logstat = logprint(logger, logger->tmptxt, i5); status = 0; exittrace: 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 */ totcnt[ee] = sum2; return(status); } /***************************************************************** * Name of source file: rmscalc.c * Version of source file: 3.2.6 * Programmer: Niels Lund & Niels J. Westergaard * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325705 FAX: +45 35362475 * njw@space.dtu.dk * Purpose: Initiate the backprojection and source * finding processes * Origin date: 041122 * Update history: 1.0.0 041130 First version * 1.6.3 060915 An exposure (vignetting) map is now a product * 1.6.4 060928 Included test for zero divisor in peaktransfer.c * 1.6.5 061002 New defaults for par. skyImagesOut * 1.7.0 061110 Produces images with few or zero events (SPR 4594) * 1.7.1 061114 SPR 4603 Image unit (BUNIT) is now cts/dm2/s * 2.1.0 070809 SCREWS 2021-2023 * 2.1.0 070809 SCREWs 2021-2023 * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.2.0 071205 Flux determination has been improved * 2.2.1 071205 SPR 4742: Division by zero eliminated * 2.2.2 080111 Makes trigger rates from JEM-X HK available * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * Type of element: Function * Part of package: j_ima_iros * Name: rmscalc * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ double rmscalc(float shad[], float soft_gr[], struct log_con *logger) { int i, i5; double m0, m1, m2, rms, var; 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], "rmscalc"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ if (logger->trace) traces(func_local, 1, logger); i5 = logger->i5; /* NL 20120122 */ m0 = m1 = m2 = 0.0; for (i=0; itmptxt, "##999a## rmscalc: m0: %7.1lf, m1: %8.4lf, m2: %10.1lf", m0, m1, m2); logger->logstat = logprint(logger, logger->tmptxt, i5); if (logger->trace) traces(func_local, 400000+m0, logger); if (logger->trace) traces(func_local, 10, logger); m1 /= m0; m2 /= m0; if (logger->trace) traces(func_local, 20, logger); var = m2 - m1 * m1; if (var > 0.0) rms = sqrt(var); else rms = 0.0; if (logger->trace) traces(func_local, 30, logger); sprintf(logger->tmptxt, "##999b## rmscalc: m0: %7.1lf, mean: %8.4lf, var: %10.1lf, rms: %8.4lf", m0, m1, var, rms); logger->logstat = logprint(logger, logger->tmptxt, i5); 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(rms); } /***************************************************************** * Name of source file: outfit_isdc.c * Version of source file: 3.2.7 * Parent component: None * Programmer: Niels Lund & Niels J. Westergaard * Affiliation: National Space Institute/DTU * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325700 FAX: +45 35362475 * nl@space.dtu.dk, njw@space.dtu.dk * Purpose: Output an array to an index table * Origin date: 041228 * Update history: 1.0.0 041228 First version * ... * 1.8.0 061213 SPR 4640 Error in findpeak has been corrected * 1.8.1 070123 SPR 4590 int changed to long for 64 bit code * 2.1.0 070809 SCREWs 2021-2023 * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.2.0 071205 Flux determination has been improved * 2.2.1 071205 SPR 4742: Division by zero eliminated * 2.2.2 080111 Makes trigger rates from JEM-X HK available * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 3.2.7 100224 SPR 4915: Fixing logics for sparse shadowgrams * Type of element: Function * Part of package: j_ima_iros * Name: outfit_isdc * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ int outfit_isdc( dal_element *theSWG, /* Pointer to the SWG */ int skyOrShd, Instrument jemxNum, char *elmntName, /* Holds name of data element e.g. JMX1-SKY.-IMA */ char exttext[2][J_IIR_TEXTSIZE], float image[], struct fit_struc *f_struc, struct log_con *logger, int ee, struct shadowgrams *sh, int chatter, int status ) { extraKeywords kwds; /* Struct to hold additional keywords */ dal_element *ptrElmnt = NULL; dal_element *ptrIdx = NULL; char tmp[80]; char filename[DAL_FILE_NAME_STRING]; char rel_filename[DAL_FILE_NAME_STRING]; char *cptr = NULL; int rlimidx = 0; long axes[2]; /* Holds the length of the axes */ static int func_local = -1, local_calling_num=0; clock_t calling_TT, TT_now; if( status != ISDC_OK ) return( status ); /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "outfit_isdc"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ if (logger->trace) traces(func_local, 1, logger); if( chatter > J_CHATTY_NORMAL ) { RILlogMessage( NULL, Log_0,"##332## outfit_isdc has been called"); } kwdsInit( KWALL, &kwds ); axes[0] = (long) f_struc->naxis1; axes[1] = (long) f_struc->naxis2; kwdsSetChar( &kwds, "INSTRUME", f_struc->instru, "Instrument"); kwdsSetChar( &kwds, "IMADESCR", exttext[0], exttext[1]); kwdsSetInt( &kwds, "JMX_UNIT", f_struc->jemx+1, "JEMX number"); kwdsSetInt( &kwds, "REVOL", f_struc->orbit, "INTEGRAL revolution number"); kwdsSetInt( &kwds, "PID", f_struc->pid, "Pointing ID"); kwdsSetInt( &kwds, "PIDV", f_struc->pidv, "Pointing ID sub number"); kwdsSetReal( &kwds, "E_MIN", f_struc->emin, "[keV] Lower energy limit"); kwdsSetReal( &kwds, "E_MAX", f_struc->emax, "[keV] Upper energy limit"); kwdsSetReal( &kwds, "EXPOSURE", f_struc->exposure, "[s] Effective integration time"); switch ( skyOrShd ) { case J_IIR_IS_SKY : status = dol2filename( logger->dolBPL, filename ); if( status != ISDC_OK ) { RILlogMessage( NULL, Warning_1,"##333## Improper DOL string: %s", logger->dolBPL ); if (logger->trace) traces(func_local, 10, logger); status = ISDC_OK; } else { if (logger->trace) traces(func_local, 15, logger); if( jemxNum == JMX1 ) { strcat( filename, "[JMX1-DMAP-BPL]" ); } else { strcat( filename, "[JMX2-DMAP-BPL]" ); } } /* * SPR 4301 Only give relative file name for VIGNDOL * 2006-09-07/NJW */ if( (cptr = strrchr( filename, '/' )) == NULL ) { /* Already relative */ strcpy( rel_filename, filename ); if (logger->trace) traces(func_local, 20, logger); } else { strcpy( rel_filename, cptr+1 ); if (logger->trace) traces(func_local, 25, logger); } kwdsSetChar( &kwds, "IMACASE", "IROS001", "Image generation specification"); strcpy( tmp, f_struc->imatype[0]); kwdsSetChar( &kwds, "IMATYPE", tmp, "Image type specification"); kwdsSetChar( &kwds, "VIGNDOL", rel_filename, "Image type specification"); kwdsSetInt( &kwds, "VARIA_ID", f_struc->varia_id, "Variance map identifier"); rlimidx = (logger->det_rad_lim[ee]-75+102)%51; /* corrected for version 1.5.8 2006-08-07/NJW */ kwdsSetInt( &kwds, "RLIMIDX", rlimidx, "Index for radius limit in vign.arr."); kwdsSetInt( &kwds, "VIGNCOR", f_struc->vigncor, "Vignetting corr. done if set"); kwdsSetChar( &kwds, "BUNIT", f_struc->bunit, "Pixel units"); kwdsSetChar( &kwds, "CTYPE1", "RA---TAN", "Coord system 1. axis"); kwdsSetChar( &kwds, "CTYPE2", "DEC--TAN", "Coord system 2. axis"); kwdsSetChar( &kwds, "CUNIT1", "deg", "Unit of coord system 1. axis"); kwdsSetChar( &kwds, "CUNIT2", "deg", "Unit of coord system 2. axis"); kwdsSetReal( &kwds, "CRVAL1", f_struc->crval1, "[deg] Ref value 1. axis"); kwdsSetReal( &kwds, "CRVAL2", f_struc->crval2, "[deg] Ref value 2. axis"); kwdsSetReal( &kwds, "ROT_ANG", f_struc->rot_ang, "[deg] Rotation angle"); kwdsSetReal( &kwds, "CRPIX1", f_struc->crpix1, "[pixel] Ref pixel 1. axis"); kwdsSetReal( &kwds, "CRPIX2", f_struc->crpix2, "[pixel] Ref pixel 2. axis"); kwdsSetReal( &kwds, "CD1_1", f_struc->cd1_1, "[deg] Coord syst transformation"); kwdsSetReal( &kwds, "CD1_2", f_struc->cd1_2, "[deg] Coord syst transformation"); kwdsSetReal( &kwds, "CD2_1", f_struc->cd2_1, "[deg] Coord syst transformation"); kwdsSetReal( &kwds, "CD2_2", f_struc->cd2_2, "[deg] Coord syst transformation"); kwdsSetReal( &kwds, "PSFSIGMA", f_struc->psfsigma, "[deg] FWHM/2.35482=sigma of PSF"); kwdsSetChar( &kwds, "BKG_MODL", f_struc->bkg_model, "Background model file"); if (logger->trace) traces(func_local, 30, logger); break; case J_IIR_IS_SHD : break; default: RILlogMessage( NULL, Error_0, "##334## Wrong skyOrShd parameter"); status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_WRONGSKYORSHD; if (logger->trace) traces(func_local, 60, logger); goto exittrace; } status = JEMXLIBarrayPut( theSWG, elmntName, &ptrElmnt, &ptrIdx, image, axes, &kwds, logger, chatter, status ); if( status != ISDC_OK ) { if (logger->trace) traces(func_local, 70, logger); goto exittrace; } if( skyOrShd == J_IIR_IS_SKY ) { status = DAL3GENattributeCopy( sh->ptr[ee], ptrElmnt, "CHANMIN,CHANMAX,CHANTYPE,TELAPSE,OBTSTART," "OBTEND,SHDIDEN,EVNTYPES," "SWID,SW_TYPE,SWBOUND," "ONTIME,DEADC," "E_MEAN,TSTART,TSTOP,RTSTART,RTSTOP", status ); if( status != ISDC_OK ) { if (logger->trace) traces(func_local, 80, logger); goto exittrace; } } /* * Update the columns in the index table with keyword values */ status = DAL3GENindexUpdate( ptrElmnt, ptrIdx, status); if( status == DAL3GEN_INDEX_KEY_NOT_FOUND ) { RILlogMessage( NULL, Warning_0, "##335## Index Key Not Found, reset status"); status = ISDC_OK; if (logger->trace) traces(func_local, 90, logger); } if( status != ISDC_OK ) goto exittrace; if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##336## EVTS-SHD member and index table have been updated"); } exittrace: 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); } /***************************************************************** * Name of source file: gaussj_nr.c * Version of source file: 4.0.12 * Programmer: Niels Lund & Niels J. Westergaard * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325705 FAX: +45 35362475 * njw@space.dtu.dk * Purpose: Initiate the backprojection and source * finding processes * Origin date: 041122 * Update history: 1.0.0 041130 First version * 1.6.3 060915 An exposure (vignetting) map is now a product * 1.6.4 060928 Included test for zero divisor in peaktransfer.c * 1.6.5 061002 New defaults for par. skyImagesOut * 1.7.0 061110 Produces images with few or zero events (SPR 4594) * 1.7.1 061114 SPR 4603 Image unit (BUNIT) is now cts/dm2/s * 2.1.0 070809 SCREWS 2021-2023 * 2.1.0 070809 SCREWs 2021-2023 * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.2.0 071205 Flux determination has been improved * 2.2.1 071205 SPR 4742: Division by zero eliminated * 2.2.2 080111 Makes trigger rates from JEM-X HK available * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 3.2.7 100224 SPR 4915: Fixing logics for sparse shadowgrams * 4.0.12 120919 SPR ?: Introduce corrections by LP and Co. * Type of element: Function * Part of package: j_ima_iros * Name: gaussj_nr * Returns: * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ int gaussj_nr(double a[], int n, double b[], int m, struct log_con *logger) /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* */ /* Niels Lund, February 2003 */ /* */ /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* ------------------------------------------------------------- docbegin: * Name of source file: * /home/nl/jemx/ipfread/jemx1-2/sky/gaussj_nr.c * Version of source file: 4.0.12 * Parent component: gaussj_nr from NJW * Programmer: Niels Lund (modification to avoid DAL/PIL/RIL dependencies) * Affiliation: Danish National Space Center * Purpose: Fit of shadowgram components for Iterative Removal of Sources * Origin date: 021220 * Update history: * Type of element: Function * Part of package: minisky.c * Required functions SWAP * 1.0.4 050126 Test version for undue crash * 1.1.0 050131 Now reading FITS sky/backproj files * 1.1.1 050211 Keywords adapted to needs of j_ima_mosaic * 1.1.2 050303 Extra keyw:RLIMIDX, new cleaning * 1.1.3 050307 New DMAP: 51 radii * 1.1.4 050407 New clean, etc. * 1.1.5 050415 New clean again, updated flux determination * 1.1.6 050418 Now uses JMXi-DBKG-MOD as default for empty field shds * 1.2.0 050425 Deals with SPR 4102,4108 and reduces RAM requirement * 1.3.0 050503 Deals with SPR 4120 and copes with up to 6 shadowgrams * 1.3.1 050517 Deals with SPR 4143 and initializes ima_sigma properly * 1.3.2 050519 Closes SPR 4157 - bad size of three arrays * 1.3.3 050602 Changes some arrays to static (SPR 4202) * 1.4.0 050620 Include user defined sources (SCREW 1740) * 1.5.1 051129 Separating functions to jmx_lib_pif * 1.5.2 051202 Separating functions to jmx_lib_pif (2) * 1.5.3 051202 Give offX, x2x values in mm in IMOD-GRP * 1.5.4 060104 Bug in sh_depth corrected, detectmap now in mm * 1.5.5 060106 Introduced one more digit in logfile for src position * 1.5.6 060228 Removed parameter detMapFile and some obsolete variables * 1.5.7 060606 Shifted detCondMap to struct jmx_id and status_map * 1.5.8 060807 SPR 04551 Bad assignment of RLIMIDX corrected * 1.5.9 060807 SPR 04533 Resetting status variable has been removed * 1.5.10 060807 SPR 04523 Declaring testsum as float iso. int * 1.5.11 060807 SPR 04458 A warning log line has been added * 1.5.12 060907 SPR 04301 A relative VIGNDOL path is given * 1.6.0 060911 SCREW 1918 Image correction map and parameters introduced * 1.6.1 060912 SPR 4441 Shadowgrams with too few counts are excluded * 1.6.2 060915 SCREW 1842 A significance map can now be obtained * 1.6.3 060915 An exposure (vignetting) map is now a product * 1.6.4 060928 Included test for zero divisor in peaktransfer.c * 1.6.5 061002 New defaults for par. skyImagesOut * 1.7.0 061110 Produces images with few or zero events (SPR 4594) * 1.7.1 061114 SPR 4603 Image unit (BUNIT) is now cts/dm2/s * 1.8.0 061213 SPR 4640 Error in findpeak has been corrected * 1.8.1 070123 SPR 4590 int changed to long for 64 bit code * 2.1.0 070809 SCREWs 2021-2023 * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.2.0 071205 Flux determination has been improved * 2.2.1 071205 SPR 4742: Division by zero eliminated * 2.2.2 080111 Makes trigger rates from JEM-X HK available * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 3.2.7 100224 SPR 4915: Fixing logics for sparse shadowgrams * 4.0.12 120919 SPR ?: Introduce corrections by LP and Co. Various remarks: Gauss-Jordan matrix inversion from "Numerical Recipes" adapted to follow the storage convention: a(i,j) = a[j*Ni + i] -------------------------------------------------------------- */ { int icol = 0, irow = 0, i, j, k, l, ll, status; int indxc[SCW_SRCMAX], indxr[SCW_SRCMAX], ipiv[SCW_SRCMAX]; double big, dum, pivinv; 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], "gaussj_nr"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6 ); } } calling_TT = logger->TT; logger->func_calls[func_local]++; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ if (logger->trace) traces(func_local, 1, logger); for (j=0;j= big) { big=fabs(a[k*n+j]); irow=j; icol=k; } } else { if (ipiv[k] > 1) { status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_SNGLMTX1; goto exittrace; /* singular matrix 1 */ } } } ++(ipiv[icol]); if (irow != icol) { for (l=0;l=0;l--) { if (indxr[l] != indxc[l]) for (k=0;ktrace) 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( ISDC_OK ); */ return( status ); } void kwdsInit( int type, extraKeywords *kwds ) { switch ( type ) { case KWCHAR : kwds->numChars = 0; break; case KWINT : kwds->numInts = 0; break; case KWREAL : kwds->numReals = 0; break; case KWALL : kwds->numChars = 0; kwds->numInts = 0; kwds->numReals = 0; break; default : RILlogMessage( NULL, Error_0, "##666## Invalid keyword type, no action"); } } void kwdsSetChar( extraKeywords *kwds, char *key, char *value, char *comm ) { if( kwds->numChars >= KWMAXNUMCHAR ) { RILlogMessage( NULL, Warning_0, "##667## Max number of char keywords exceeded - skip"); } else { strqcpy( kwds->charKey[kwds->numChars], key, KWSTRINGLENGTH ); strqcpy( kwds->charValue[kwds->numChars], value, KWSTRINGLENGTHVAL ); strqcpy( kwds->charComm[kwds->numChars], comm, KWSTRINGLENGTH ); kwds->numChars++; } } void kwdsSetInt( extraKeywords *kwds, char *key, long value, char *comm ) { if( kwds->numInts >= KWMAXNUMINT ) { RILlogMessage( NULL, Warning_0, "##668## Max number of int keywords exceeded - skip"); } else { strqcpy( kwds->intKey[kwds->numInts], key, KWSTRINGLENGTH ); kwds->intValue[kwds->numInts] = value; strqcpy( kwds->intComm[kwds->numInts], comm, KWSTRINGLENGTH ); kwds->numInts++; } } void kwdsSetReal( extraKeywords *kwds, char *key, double value, char *comm ) { if( kwds->numInts >= KWMAXNUMREAL ) { RILlogMessage( NULL, Warning_0, "##669## Max number of real keywords exceeded - skip"); } else { strqcpy( kwds->realKey[kwds->numReals], key, KWSTRINGLENGTH ); kwds->realValue[kwds->numReals] = value; strqcpy( kwds->realComm[kwds->numReals], comm, KWSTRINGLENGTH ); kwds->numReals++; } } /***************************************************************** * Name of source file: kwds_write.c * Version of source file: 3.2.7 * Parent component: None * Programmer: Niels J. Westergaard * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325700 FAX: +45 35362475 * njw@spacecenter.dk * Purpose: Write the keywords in struct extraKeywords * to specified FITS header * Origin date: 041228 * Update history: 1.0.0 041228 First version * 1.0.4 050126 Test version for undue crash * 1.1.0 050131 Now reading FITS sky/backproj files * 1.1.1 050211 Keywords adapted to needs of j_ima_mosaic * 1.1.2 050303 Extra keyw:RLIMIDX, new cleaning * 1.1.3 050307 New DMAP: 51 radii * 1.1.4 050407 New clean, etc. * 1.1.5 050415 New clean again, updated flux determination * 1.1.6 050418 Now uses JMXi-DBKG-MOD as default for empty field shds * 1.2.0 050425 Deals with SPR 4102,4108 and reduces RAM requirement * 1.2.1 050501 Introduce calls to 'function timing' and 'traces' * 1.3.0 050503 Deals with SPR 4120 and copes with up to 6 shadowgrams * 1.3.1 050517 Deals with SPR 4143 and initializes ima_sigma properly * 1.3.2 050519 Closes SPR 4157 - bad size of three arrays * 1.3.3 050602 Changes some arrays to static (SPR 4202) * 1.4.0 050620 Include user defined sources (SCREW 1740) * 1.5.1 051129 Separating functions to jmx_lib_pif * 1.5.2 051202 Separating functions to jmx_lib_pif (2) * 1.5.3 051202 Give offX, x2x values in mm in IMOD-GRP * 1.5.4 060104 Bug in sh_depth corrected, detectmap now in mm * 1.5.5 060106 Introduced one more digit in logfile for src position * 1.5.6 060228 Removed parameter detMapFile and some obsolete variables * 1.5.7 060606 Shifted detCondMap to struct jmx_id and status_map * 1.5.8 060807 SPR 04551 Bad assignment of RLIMIDX corrected * 1.5.9 060807 SPR 04533 Resetting status variable has been removed * 1.5.10 060807 SPR 04523 Declaring testsum as float iso. int * 1.5.11 060807 SPR 04458 A warning log line has been added * 1.5.12 060907 SPR 04301 A relative VIGNDOL path is given * 1.6.0 060911 SCREW 1918 Image correction map and parameters introduced * 1.6.1 060912 SPR 4441 Shadowgrams with too few counts are excluded * 1.6.2 060915 SCREW 1842 A significance map can now be obtained * 1.6.3 060915 An exposure (vignetting) map is now a product * 1.6.4 060928 Included test for zero divisor in peaktransfer.c * 1.6.5 061002 New defaults for par. skyImagesOut * 1.7.0 061110 Produces images with few or zero events (SPR 4594) * 1.7.1 061114 SPR 4603 Image unit (BUNIT) is now cts/dm2/s * 1.8.0 061213 SPR 4640 Error in findpeak has been corrected * 1.8.1 070123 SPR 4590 int changed to long for 64 bit code * 2.1.0 070809 SCREWs 2021-2023 * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.2.0 071205 Flux determination has been improved * 2.2.1 071205 SPR 4742: Division by zero eliminated * 2.2.2 080111 Makes trigger rates from JEM-X HK available * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 3.2.7 100224 SPR 4915: Fixing logics for sparse shadowgrams * Type of element: Function * Part of package: j_ima_iros * Name: kwdsWrite * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ int kwdsWrite( dal_element *ptr, /* DAL pointer to data element */ extraKeywords *kwds, /* holds the extra keywords */ struct log_con *logger, int chatter, int status ) { int i = 0; 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], "kwds_write"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ if (logger->trace) traces(func_local, 1, logger); if( chatter > J_CHATTY_VERY_VERBOSE ) { RILlogMessage( NULL, Log_0,"##368## %d char keywords", kwds->numChars ); RILlogMessage( NULL, Log_0,"##369## %d int keywords", kwds->numInts ); RILlogMessage( NULL, Log_0,"##370## %d real keywords", kwds->numReals ); } for( i = 0; i < kwds->numChars; i++ ) { status = DALattributePutChar( ptr, kwds->charKey[i], kwds->charValue[i], NULL, kwds->charComm[i], status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_0,"Keyw: %s with value: %s failed!", kwds->charKey[i], kwds->charValue[i] ); } } if( status != ISDC_OK ) { RILlogMessage( NULL, Error_0,"##371## After writing char kwds," " status = %d", status ); goto exittrace; } for( i = 0; i < kwds->numInts; i++ ) { status = DALattributePutInt( ptr, kwds->intKey[i], kwds->intValue[i], NULL, kwds->intComm[i], status ); } if( status != ISDC_OK ) { RILlogMessage( NULL, Error_0,"##372## After writing int kwds," " status = %d", status ); goto exittrace; } for( i = 0; i < kwds->numReals; i++ ) { status = DALattributePutReal( ptr, kwds->realKey[i], kwds->realValue[i], NULL, kwds->realComm[i], status ); } if( status != ISDC_OK ) { RILlogMessage( NULL, Error_0,"##373## After writing real kwds," " status = %d", status ); goto exittrace; } exittrace: if (logger->trace) traces(func_local, 99, logger); /* if (logger->trace) traces(func_local, (int)(SCWnow), 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 ); } /***************************************************************** * Name of source file: j_iir_lilipol.c * Version of source file: 3.2.7 * Parent component: j_ima_iros * Programmer: Niels J. Westergaard * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325705 FAX: +45 35362475 * njw@spacecenter.dk * Purpose: Linear interpolation * Origin date: 050419 * Update history: 1.1.6 050419 * 1.2.0 050425 Deals with SPR 4102,4108 and reduces RAM requirement * 1.3.0 050503 Deals with SPR 4120 and copes with up to 6 shadowgrams * 1.3.1 050517 Deals with SPR 4143 and initializes ima_sigma properly * 1.3.2 050519 Closes SPR 4157 - bad size of three arrays * 1.3.3 050602 Changes some arrays to static (SPR 4202) * 1.4.0 050620 Include user defined sources (SCREW 1740) * 1.5.1 051129 Separating functions to jmx_lib_pif * 1.5.2 051202 Separating functions to jmx_lib_pif (2) * 1.5.3 051202 Give offX, x2x values in mm in IMOD-GRP * 1.5.4 060104 Bug in sh_depth corrected, detectmap now in mm * 1.5.5 060106 Introduced one more digit in logfile for src position * 1.5.6 060228 Removed parameter detMapFile and some obsolete variables * 1.5.7 060606 Shifted detCondMap to struct jmx_id and status_map * 1.5.8 060807 SPR 04551 Bad assignment of RLIMIDX corrected * 1.5.9 060807 SPR 04533 Resetting status variable has been removed * 1.5.10 060807 SPR 04523 Declaring testsum as float iso. int * 1.5.11 060807 SPR 04458 A warning log line has been added * 1.5.12 060907 SPR 04301 A relative VIGNDOL path is given * 1.6.0 060911 SCREW 1918 Image correction map and parameters introduced * 1.6.1 060912 SPR 4441 Shadowgrams with too few counts are excluded * 1.6.2 060915 SCREW 1842 A significance map can now be obtained * 1.6.3 060915 An exposure (vignetting) map is now a product * 1.6.4 060928 Included test for zero divisor in peaktransfer.c * 1.6.5 061002 New defaults for par. skyImagesOut * 1.7.0 061110 Produces images with few or zero events (SPR 4594) * 1.7.1 061114 SPR 4603 Image unit (BUNIT) is now cts/dm2/s * 1.8.0 061213 SPR 4640 Error in findpeak has been corrected * 1.8.1 070123 SPR 4590 int changed to long for 64 bit code * 2.1.0 070809 SCREWs 2021-2023 * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.2.0 071205 Flux determination has been improved * 2.2.1 071205 SPR 4742: Division by zero eliminated * 2.2.2 080111 Makes trigger rates from JEM-X HK available * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 3.2.7 100224 SPR 4915: Fixing logics for sparse shadowgrams * Type of element: Function *****************************************************************/ int j_iir_lilipol( long n, /* Number of elements in array */ float *xv, /* Array with x values */ float *yv, /* Array with y values */ float x, /* x value for which function value is wanted */ float *plili, /* Result of interpolation */ int status) /* Fault condition flag */ { /* general function to make lin-lin interpolation in a table */ /* with ever increasing x-values */ long i, i1, i2; if( status != ISDC_OK ) return(status); /* If x value is outside range given by 'xv' then the closest 'y' value id returned */ *plili = yv[0]; if( x <= xv[0] ) return( status ); *plili = yv[n-1]; if( x >= xv[n-1] ) return( status ); /* Inside the range a binary search is used */ i1 = 0L; i2 = n - 1; do { i = (i1 + i2 ) / 2; if( x >= xv[i] ) { i1 = i; } else { i2 = i; } } while( i2 - i1 > 1 ); *plili = yv[i1] + (yv[i2]-yv[i1])*(x-xv[i1])/(xv[i2]-xv[i1]); return( status ); } /******************************************************** * * Function transpose_f * * Function to make a float square matrix transposition * in place for a 2D matrix in a 1D representation * * 2005-01-04/NJW * *******************************************************/ void transpose_f( float *a, int dim ) { int s = 0; int i = 0; int j = 0; float swap = 0.0; for( s = 1; s < 2*dim - 2; s++ ) { for( i = 0; i < (s+1)/2 && i < dim; i++ ) { j = s - i; if( j >= dim ) continue; swap = a[i*dim + j]; a[i*dim + j] = a[j*dim + i]; a[j*dim + i] = swap; } } } /* ******************************************************* Function strqcpy This is a function that acts like the Solaris C-function strlcpy. It copies at most numchar-1 characters from 'source' to 'target' and returns the number of characters in 'source'. 'target' is always 0-terminated. char t[n]; if( strqcpy( t, s, n ) >= n ) { printf("s has been truncated\n");} 2004-12-28/NJW ************************************************************/ int strqcpy( char *target, char *source, int numchar ) { char *t = NULL; char *s = NULL; char *s0 = NULL; t = target; s = source; for( s0 = s; s - s0 < numchar-1 && *s != '\0'; *(t++) = *(s++) ); *t = '\0'; if( *s != '\0' ) for(; *s != '\0'; s++); return (int) (s - s0); } float area3(float x1, float y1, float x2, float y2, float x3, float y3) { return( 0.5 * fabs((x1-x2) * (y1 - y3) - (x1 - x3) * (y1 - y2)) ); } float area4(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) { return(area3(x1, y1, x2, y2, x3, y3) + area3(x4, y4, x2, y2, x3, y3) ); } /***************************************************************** The function creates a file 'latestNumber.dat' in the current directory This file holds a single number which is updated for each call. Thus a series of unique strings are obtained (repeats after a million calls). *****************************************************************/ void getnextautoname( char *nextname ) { FILE *fp; char latestNumber[100]; char result[7]; long number; strcpy( latestNumber, "latestNumber.dat"); if( (fp = fopen( latestNumber, "r" )) == NULL ) { /* Does not exist, create and initialize */ if( (fp = fopen( latestNumber, "w" )) == NULL ) { printf("Unable to create 'latestNumber.dat - stop\n"); exit(0); } itoan( 0L, 6, result); fprintf(fp,"%ld", 0L); fclose(fp); } else { /* File exists and has been opened */ fscanf(fp, "%ld", &number); itoan( ++number, 6, result); fclose(fp); if( (fp = fopen( latestNumber, "w" )) == NULL ) { printf("Unable to create 'latestNumber.dat - stop\n"); exit(0); } fprintf(fp,"%ld", number); fclose(fp); } strcpy( nextname, result ); return; } /***************************************************************** docbegin: * Name of source file: itoan.c * Version of source file: 3.2.7 * Parent component: * Programmer: Niels J. Westergaard * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325705 FAX: +45 35362475 * njw@dnsc.dk * Purpose: Convert integer to string with given * number of characters disregarding the sign * Origin date: 981229 * Update history: * 1.0.4 050126 Test version for undue crash * 1.1.0 050131 Now reading FITS sky/backproj files * 1.1.1 050211 Keywords adapted to needs of j_ima_mosaic * 1.1.2 050303 Extra keyw:RLIMIDX, new cleaning * 1.1.3 050307 New DMAP: 51 radii * 1.1.4 050407 New clean, etc. * 1.1.5 050415 New clean again, updated flux determination * 1.1.6 050418 Now uses JMXi-DBKG-MOD as default for empty field shds * 1.2.0 050425 Deals with SPR 4102,4108 and reduces RAM requirement * 1.3.0 050503 Deals with SPR 4120 and copes with up to 6 shadowgrams * 1.3.1 050517 Deals with SPR 4143 and initializes ima_sigma properly * 1.3.2 050519 Closes SPR 4157 - bad size of three arrays * 1.3.3 050602 Changes some arrays to static (SPR 4202) * 1.4.0 050620 Include user defined sources (SCREW 1740) * 1.5.1 051129 Separating functions to jmx_lib_pif * 1.5.2 051202 Separating functions to jmx_lib_pif (2) * 1.5.3 051202 Give offX, x2x values in mm in IMOD-GRP * 1.5.4 060104 Bug in sh_depth corrected, detectmap now in mm * 1.5.5 060106 Introduced one more digit in logfile for src position * 1.5.6 060228 Removed parameter detMapFile and some obsolete variables * 1.5.7 060606 Shifted detCondMap to struct jmx_id and status_map * 1.5.8 060807 SPR 04551 Bad assignment of RLIMIDX corrected * 1.5.9 060807 SPR 04533 Resetting status variable has been removed * 1.5.10 060807 SPR 04523 Declaring testsum as float iso. int * 1.5.11 060807 SPR 04458 A warning log line has been added * 1.5.12 060907 SPR 04301 A relative VIGNDOL path is given * 1.6.0 060911 SCREW 1918 Image correction map and parameters introduced * 1.6.1 060912 SPR 4441 Shadowgrams with too few counts are excluded * 1.6.2 060915 SCREW 1842 A significance map can now be obtained * 1.6.3 060915 An exposure (vignetting) map is now a product * 1.6.4 060928 Included test for zero divisor in peaktransfer.c * 1.6.5 061002 New defaults for par. skyImagesOut * 1.7.0 061110 Produces images with few or zero events (SPR 4594) * 1.7.1 061114 SPR 4603 Image unit (BUNIT) is now cts/dm2/s * 1.8.0 061213 SPR 4640 Error in findpeak has been corrected * 1.8.1 070123 SPR 4590 int changed to long for 64 bit code * 2.1.0 070809 SCREWs 2021-2023 * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.2.0 071205 Flux determination has been improved * 2.2.1 071205 SPR 4742: Division by zero eliminated * 2.2.2 080111 Makes trigger rates from JEM-X HK available * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 3.2.7 100224 SPR 4915: Fixing logics for sparse shadowgrams * Type of element: Lowest level routine * Calls: integer - to be converted * integer - number of characters in return string * Returns: char string - character representation * Required components: reverse.c docend: *****************************************************************/ void itoan( long n, int nDigits, char s[]) { int i; if( n < 0 ) { /* record sign */ n = -n; /* make n positive */ } i = 0; do { /* generate digits in reverse order */ s[i++] = n % 10 + '0'; /* get next digit */ n /= 10; /* delete the digit */ } while( --nDigits > 0 ); s[i] = '\0'; reverse(s); } /***************************************************************** docbegin: * Name of source file: reverse.c * Version of source file: 3.2.7 * Parent component: * Programmer: Niels J. Westergaard * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325705 FAX: +45 35362475 * njw@dnsc.dk * Purpose: reverse a string * Origin date: 981229 * Update history: * 1.1.5 050415 New clean again, updated flux determination * 1.1.6 050418 Now uses JMXi-DBKG-MOD as default for empty field shds * 1.2.0 050425 Deals with SPR 4102,4108 and reduces RAM requirement * 1.3.0 050503 Deals with SPR 4120 and copes with up to 6 shadowgrams * 1.3.1 050517 Deals with SPR 4143 and initializes ima_sigma properly * 1.3.2 050519 Closes SPR 4157 - bad size of three arrays * 1.3.3 050602 Changes some arrays to static (SPR 4202) * 1.4.0 050620 Include user defined sources (SCREW 1740) * 1.5.1 051129 Separating functions to jmx_lib_pif * 1.5.2 051202 Separating functions to jmx_lib_pif (2) * 1.5.3 051202 Give offX, x2x values in mm in IMOD-GRP * 1.5.4 060104 Bug in sh_depth corrected, detectmap now in mm * 1.5.5 060106 Introduced one more digit in logfile for src position * 1.5.6 060228 Removed parameter detMapFile and some obsolete variables * 1.5.7 060606 Shifted detCondMap to struct jmx_id and status_map * 1.5.8 060807 SPR 04551 Bad assignment of RLIMIDX corrected * 1.5.9 060807 SPR 04533 Resetting status variable has been removed * 1.5.10 060807 SPR 04523 Declaring testsum as float iso. int * 1.5.11 060807 SPR 04458 A warning log line has been added * 1.5.12 060907 SPR 04301 A relative VIGNDOL path is given * 1.6.0 060911 SCREW 1918 Image correction map and parameters introduced * 1.6.1 060912 SPR 4441 Shadowgrams with too few counts are excluded * 1.6.2 060915 SCREW 1842 A significance map can now be obtained * 1.6.3 060915 An exposure (vignetting) map is now a product * 1.6.4 060928 Included test for zero divisor in peaktransfer.c * 1.6.5 061002 New defaults for par. skyImagesOut * 1.7.0 061110 Produces images with few or zero events (SPR 4594) * 1.7.1 061114 SPR 4603 Image unit (BUNIT) is now cts/dm2/s * 1.8.0 061213 SPR 4640 Error in findpeak has been corrected * 1.8.1 070123 SPR 4590 int changed to long for 64 bit code * 2.1.0 070809 SCREWs 2021-2023 * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.2.0 071205 Flux determination has been improved * 2.2.1 071205 SPR 4742: Division by zero eliminated * 2.2.2 080111 Makes trigger rates from JEM-X HK available * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 3.2.7 100224 SPR 4915: Fixing logics for sparse shadowgrams * Type of element: Lowest level routine * Part of package: * Name: * Calls: char string - to be reversed * Returns: char string - reversed version * Required components: string.h docend: *****************************************************************/ void reverse(char *s) { int c, i, j; for (i=0, j = strlen(s)-1; i < j; i++, j--) { c = s[i]; s[i] = s[j]; s[j] = c; } } /********************************************** Function dol2filename Returns the filename from the given DOL which can be of the 'filename[XXXX]' or filename+123 type 2005-02-10/NJW adapted from a much older version *************************************************/ int dol2filename( char *dol, char *filename ) { char *ptr = NULL; int pos = 0; int len = 0; strcpy( filename, dol ); len = strlen( filename ); /* See if the '[' character is present */ ptr = strchr( filename, '[' ); if( ptr != NULL ) { *ptr = '\0'; return( ISDC_OK ); } else { /* Possibly a +123 case */ pos = len - 1; while( filename[pos] >= '0' && filename[pos] <= '9' ) --pos; if( filename[pos] == '+' ) { filename[pos] = '\0'; return( ISDC_OK ); } else return(J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_BADDOLFORMAT); } } /***************************************************************** * Name of source file: fits_test_output.c * Version of source file: 3.2.7 * Programmer: Niels Lund & Niels J. Westergaard * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325705 FAX: +45 35362475 * njw@space.dtu.dk * Purpose: Intermediate image output for monitoring * of process * Origin date: 041122 * Update history: 1.0.0 041130 First version * 1.6.3 060915 An exposure (vignetting) map is now a product * 1.6.4 060928 Included test for zero divisor in peaktransfer.c * 1.6.5 061002 New defaults for par. skyImagesOut * 1.7.0 061110 Produces images with few or zero events (SPR 4594) * 1.7.1 061114 SPR 4603 Image unit (BUNIT) is now cts/dm2/s * 2.1.0 070809 SCREWS 2021-2023 * 2.1.0 070809 SCREWs 2021-2023 * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.2.0 071205 Flux determination has been improved * 2.2.1 071205 SPR 4742: Division by zero eliminated * 2.2.2 080111 Makes trigger rates from JEM-X HK available * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 3.2.7 100224 SPR 4915: Fixing logics for sparse shadowgrams * Type of element: Function * Part of package: j_ima_iros * Name: fits_test_output * Returns: * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ int fits_test_output( char *basefilename, float *inarray, int dim, struct log_con *logger, /* log control parameters */ int chatter, int status ) { fitsfile *ftestptr; char next_number[10]; char test_file_name[100]; int fits_status = 0; int i, j, ijlocal, ijin, localdim; long numValues = 0; long naxis = 2; long naxes[2]; static float array[512*512]; static int func_local = -1, local_calling_num=0; clock_t calling_TT, TT_now; /* Immediate return if called in error state */ if( status != ISDC_OK ) return( status );; /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "fits_test_output"); if (logger->func_used_num > J_IIR_MAX_NUM_FUNCS) { sprintf(logger->tmptxt, "func_used_num > %d", J_IIR_MAX_NUM_FUNCS); logger->logstat = logprint(logger, logger->tmptxt, 6); logger->func_used_num = J_IIR_MAX_NUM_FUNCS; } } 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); /* transfer 'inarray' to local 'array' to avoid modifications of 'inarray' */ localdim = dim; if (localdim > 512) localdim = 512; for (i=0; itrace) 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 ); } /***************************************************************** * Name of source file: skymap_gen.c * Version of source file: 3.2.7 * Parent component: None * Programmer: Niels Lund & Niels J. Westergaard * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325700 FAX: +45 35362475 * nl@spacecenter.dk, njw@spacecenter.dk * Purpose: Generate the skymap file * Origin date: 041122 * Update history: 1.0.0 041130 First version * 1.0.4 050126 Test version for undue crash * 1.1.0 050131 Now reading FITS sky/backproj files * 1.1.1 050211 Keywords adapted to needs of j_ima_mosaic * 1.1.2 050303 Extra keyw:RLIMIDX, new cleaning * 1.1.3 050307 New DMAP: 51 radii * 1.1.4 050407 New clean, etc. * 1.1.5 050415 New clean again, updated flux determination * 1.1.6 050418 Now uses JMXi-DBKG-MOD as default for empty field shds * 1.2.0 050425 Deals with SPR 4102,4108 and reduces RAM requirement * 1.3.0 050503 Deals with SPR 4120 and copes with up to 6 shadowgrams * 1.3.1 050517 Deals with SPR 4143 and initializes ima_sigma properly * 1.3.2 050519 Closes SPR 4157 - bad size of three arrays * 1.3.3 050602 Changes some arrays to static (SPR 4202) * 1.4.0 050620 Include user defined sources (SCREW 1740) * 1.5.1 051129 Separating functions to jmx_lib_pif * 1.5.2 051202 Separating functions to jmx_lib_pif (2) * 1.5.3 051202 Give offX, x2x values in mm in IMOD-GRP * 1.5.4 060104 Bug in sh_depth corrected, detectmap now in mm * 1.5.5 060106 Introduced one more digit in logfile for src position * 1.5.6 060228 Removed parameter detMapFile and some obsolete variables * 1.5.7 060606 Shifted detCondMap to struct jmx_id and status_map * 1.5.8 060807 SPR 04551 Bad assignment of RLIMIDX corrected * 1.5.9 060807 SPR 04533 Resetting status variable has been removed * 1.5.10 060807 SPR 04523 Declaring testsum as float iso. int * 1.5.11 060807 SPR 04458 A warning log line has been added * 1.5.12 060907 SPR 04301 A relative VIGNDOL path is given * 1.6.0 060911 SCREW 1918 Image correction map and parameters introduced * 1.6.1 060912 SPR 4441 Shadowgrams with too few counts are excluded * 1.6.2 060915 SCREW 1842 A significance map can now be obtained * 1.6.3 060915 An exposure (vignetting) map is now a product * 1.6.4 060928 Included test for zero divisor in peaktransfer.c * 1.6.5 061002 New defaults for par. skyImagesOut * 1.7.0 061110 Produces images with few or zero events (SPR 4594) * 1.7.1 061114 SPR 4603 Image unit (BUNIT) is now cts/dm2/s * 1.8.0 061213 SPR 4640 Error in findpeak has been corrected * 1.8.1 070123 SPR 4590 int changed to long for 64 bit code * 2.1.0 070809 SCREWs 2021-2023 * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.2.0 071205 Flux determination has been improved * 2.2.1 071205 SPR 4742: Division by zero eliminated * 2.2.2 080111 Makes trigger rates from JEM-X HK available * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 3.2.7 100224 SPR 4915: Fixing logics for sparse shadowgrams * Type of element: Function * Part of package: j_ima_iros * Name: skymap_gen * Calls: * Returns: * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ /* * NOTE: The jemx (jmx_id->jmx_unit) variable is 0 for JEM-X1 and 1 for JEM-X2 in these routines !! */ /* sky visibility across JEM-X detector surface */ /* October 2001. Version including interaction depth parameter, to accomodate high energy photons */ /* November 2002. Version includes: 1) parameters and notes in the "skymap.aux" file 2) alfa, beta, gammav angles describing relative twisting of the mask, collimator and MS-plate 3) x and y offsets of the MS plate wrt the collimator 4) Invert order of X and Y in 'detindex' and 'skyindex' to be consistent with usage in JEM-X TM-data */ /* December 2002. (skymaph.c) Version includes: Input of 4 smoothed shadowgrams "soft_shdg" based on real observations of empty fields. These shadowgrams are integrated over 4 energy bands: 3-9, 9-18, 18-36, 36-50 keV. "Dont-use" regions have been defined around the four calibration sources in the smoothed shadowgrams, these are indicated by zeroes in the corresponding pixel positions */ /* January 2003. (skymapi.c) Version includes: Basic skymap version which will only carry out the raytracing part corresponding to skymaph. The derivation of model shadowgrams for the internal and diffuse background is moved to another, independent program "backmodel.c" */ /* August 2003. (skymapk.c) Version includes: The "missing holes" in the mask are taken into account (mask pattern is imported from njw-file: "maskhole.txt") The mask support structure is modelled and its shadows are included. (file: "strukdef.c") */ /* March 2004. (skymapl.c) Version includes: Consistent use of 'alignment.dat' relative to midi_b5 */ /* May 2004. (skymapm.c) Version includes: New treatment of collimator dificiencies (tilt, curvature) via parameters in 'alignment.dat' Consistent use of 'alignment6.dat' relative to midi_b6 August 2004: consistent use of 'alignment8.dat' relative to 'mb9' */ /* August 2004 conversion to a subroutine included in the 'midisky' software (in mba.prj) */ /* unsigned char d_allow[byt_max]; - now part of the 'backpro_list' structure */ /* The d_allow array contains for each detector pixel a list of sky directions which have access to this pixel. ("access" here means that more half the pixel area is visible from above the mask along the direction in question) The number of sky-bins in the list corresponding to a given detector pixel is given as an entry in the d_allow_l array, the full 16-bit address of the first direction having access to the pixel is given in the d_allow_p array. The list itself is organized as a difference list: each direction defined by an 8-bit unsigned number giving the difference between in addresses of the previous direction and the current direction. Should two directions differ by more than 254 units, the difference will be written by N bytes with the value 255 and finally a byte with the remaining difference (after subtraction of N*255) (d_allow is generated by the skymap routine) */ /* unsigned d_allow_st[detdim]; - now part of the 'backpro_list' structure */ /* The d_allow_st array gives for each 16-bit pixel in the detector the 32-bit address of the corresponding list in the d_allow array. (generated by the skymap routine) */ /* short d_allow_l[detdim]; - now part of the 'backpro_list' structure */ /* array giving the length of the list in the d_allow array corresponding to a given detector pixel */ /* int d_allow_p[detdim]; - now part of the 'backpro_list' structure */ /* array giving the address of the first sky pixel visible from a given detector pixel */ /* ************************************************************* */ static struct image_cor IMA_CORR; int skymap_gen( struct instr_data *jmx_id, struct log_con *logger, struct backpro *backproj, struct backpro_lists *bp, struct shadowgrams *sh, int chatter, int status) { /* * NOTE: The jemx (jmx_id->jmx_unit) variable is 0 for JEM-X1 and 1 for JEM-X2 in these routines !! */ unsigned char d_allow_b[D_ALLOW_BINSIZE]; char skyfil[100]; char signs[51] = { '0','1','2','3','4','5','6','7','8','9', 'a','b','c','d','e','f','g','h','i','j', 'k','l','m','n','o','p','q','r','s','t', 'u','v','x','y','z','A','B','C','D','E', 'F','G','H','I','J','K','L','M','N','O','P'}; char templateName[TPL_NAME_SIZE]; char dataStrucName[DS_NAME_SIZE]; char strJMX[5]; char keyword[9]; short maskhole[22501]; float corval, corval2; int i = 0, ij; int j = 0; int all_anod = 0; int iorder = 0; int nr = 0; int m = 0; int ntal = 0; int ma = 0; int index_out = 0; int bytes = 0; int numAxes = 3; long numRows = 0; long startRow = 0; long axes[3]; long startValues[3]; long jtmp = 0; double temp_indep; struct image_cor *ima_corr = {&IMA_CORR}; dal_element *gptr = NULL; dal_element *ptr = NULL; time_t t; /* FILE *ofil, *bfil; */ 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], "skymap_gen"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } 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 */ /* logger->trace = 1; */ if (logger->trace) traces(func_local, 0, logger); for (j=0; jskydim; i++) bp->illumin[j][i] = 0; backproj->coll_model_yes = 1; /* include collimator modelling as default */ /* generate basic ideal mask pattern (not including production modifications) */ iorder = 22501; /* prime number of type: 4u + 1 */ nr = 1133; /* prime number used for shift between lines in mask array */ for (m=1; m<=iorder; m++) maskhole[m] = 0; for (m=1; m<=iorder-1; m++) { ntal = (m * m) % iorder; ma = ntal; ntal = (int)((ma * ma) % iorder); maskhole[ntal] = 1; } all_anod = 0; /* eliminate bad anodes as default */ temp_indep = backproj->indep; backproj->indep = 0.0; /* for 'first_round' put indep=0 */ if( jmx_id->jmx_unit == 0 ) { strcpy( strJMX, "JMX1" ); } else { strcpy( strJMX, "JMX2" ); } strcpy( templateName, strJMX ); strcat( templateName, "-BPL.-GRP.tpl" ); /* * Create the group structure */ status = DALobjectCreate( backproj->newBackProjFile, DAL_DISK, templateName, &gptr, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##219## Could not create JMXi-BPL.-GRP, status = %d", status); goto exittrace; } else if ( chatter > J_CHATTY_NORMAL ) { RILlogMessage( NULL, Log_0, "##220## OK after create %s", templateName ); } next_round: /* next_round: */ if (backproj->coll_model_yes == 1) sprintf(skyfil, "./skmap%1c%1dc%1d_%1c", backproj->sky_version, backproj->FOV_ff, jmx_id->jmx_unit+1, signs[(int)(backproj->indep)]); RILlogMessage( NULL, Log_0, "##221## Old skyfil name: %s", skyfil ); paltani_count_init(ima_corr); time(&t); bp->byt_index = 0; sprintf(logger->tmptxt, "##222## Calling skymap, byt_index: %10d, time: %s", bp->byt_index, ctime(&t)); logger->logstat = logprint(logger, logger->tmptxt, 5); status = skymap( backproj, jmx_id, logger, bp, sh, ima_corr, maskhole); if (status < 0) { time(&t); sprintf(logger->tmptxt, "##223## Returning from skymap, byt_index: %10d, time: %s, status: %3d", bp->byt_index, ctime(&t), status); logger->logstat = logprint(logger, logger->tmptxt, 2); goto exittrace; } time(&t); if (backproj->indep > 0.0) { for (i=0; iima_cor[ij] = ima_corr->ima_cor[1][i][j]; } } for (i=0; iima_cor[ij]; /* interpolation in Y */ if (corval > 0.0) { if (((j-4) > 0) && ((corval2 = ima_corr->ima_cor[1][i][j-4]) > 0.0)) { bp->ima_cor[ij-3] = (corval2 * 3.0 + corval) / 4.0; bp->ima_cor[ij-2] = (corval2 * 2.0 + corval * 2.0) / 4.0; bp->ima_cor[ij-1] = (corval2 + corval * 3.0) / 4.0; } } } } for (i=0; iima_cor[ij]; /* interpolation in X */ if (corval > 0.0) { if (((ij-4*SKY_YDIM) > 0) && ((corval2 = bp->ima_cor[ij-4*SKY_YDIM]) > 0.0)) { bp->ima_cor[ij-3*SKY_YDIM] = (corval2 * 3.0 + corval) / 4.0; bp->ima_cor[ij-2*SKY_YDIM] = (corval2 * 2.0 + corval * 2.0) / 4.0; bp->ima_cor[ij-1*SKY_YDIM] = (corval2 + corval * 3.0) / 4.0; } } } } strcpy( dataStrucName, strJMX ); strcat( dataStrucName, "-NCOR-BPL" ); strcpy( templateName, dataStrucName ); strcat( templateName, ".tpl" ); if( chatter > J_CHATTY_NORMAL ) { RILlogMessage( NULL, Log_0, "##224## NCOR: %s %s", dataStrucName, templateName ); } status = DAL3GENobjectAppend( gptr, DAL_DISK, dataStrucName, templateName, &ptr, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##225## After append NCOR (ima_cor), status = %d", status ); goto exittrace; } /* * Modify the array structure and write the array */ numAxes = 2; axes[0] = backproj->sky_xdim; axes[1] = backproj->sky_ydim; startValues[0] = 1; startValues[1] = 1; status = DALarrayModStruct( ptr, DAL_FLOAT, numAxes, axes, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##226## After ModStruct, status = %d", status ); goto exittrace; } status = DALarrayPutSection( ptr, numAxes, startValues, axes, DAL_FLOAT, bp->ima_cor, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##227## %d: Could not write bp->ima_cor", status ); goto exittrace; } /* * Write the keywords */ status = DALattributePutReal( ptr, "NCORPOWR", NEIGHBORCORPOWER, NULL, "Exponent of neighbor correction map", status ); status = DALattributePutReal( ptr, "NCORNORM", NEIGHBORCORNORM, NULL, "Norm. factor of neighbor correction map", status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##228## %d: Could not write keywords", status ); goto exittrace; } } if( chatter > J_CHATTY_QUIET ) { sprintf(logger->tmptxt, "##229## Returning from skymap, byt_index: %10d, time: %s", bp->byt_index, ctime(&t)); logger->logstat = logprint(logger, logger->tmptxt, 2); sprintf(logger->tmptxt, "##230## Returning statistics: Eliminated Remaining"); logger->logstat = logprint(logger, logger->tmptxt, 2); sprintf(logger->tmptxt, " 0 Detector radius check: %10u %10u", bp->loss[0], bp->gain[0]); logger->logstat = logprint(logger, logger->tmptxt, 2); sprintf(logger->tmptxt, " 1 Collim. top rad check: %10u %10u", bp->loss[1], bp->gain[1]); logger->logstat = logprint(logger, logger->tmptxt, 2); sprintf(logger->tmptxt, " 2 Outside coded mask: %10u %10u", bp->loss[2], bp->gain[2]); logger->logstat = logprint(logger, logger->tmptxt, 2); sprintf(logger->tmptxt, " 3 Detector yt>yd check: %10u %10u", bp->loss[3], bp->gain[3]); logger->logstat = logprint(logger, logger->tmptxt, 2); sprintf(logger->tmptxt, " 4 Detector ytloss[4], bp->gain[4]); logger->logstat = logprint(logger, logger->tmptxt, 2); sprintf(logger->tmptxt, " 5 Detector dyloss[5], bp->gain[5]); logger->logstat = logprint(logger, logger->tmptxt, 2); sprintf(logger->tmptxt, " 6 Detect dy>7-colw check: %10u %10u", bp->loss[6], bp->gain[6]); logger->logstat = logprint(logger, logger->tmptxt, 2); sprintf(logger->tmptxt, " 7 Detector xt>xd check: %10u %10u", bp->loss[7], bp->gain[7]); logger->logstat = logprint(logger, logger->tmptxt, 2); sprintf(logger->tmptxt, " 8 Detector xtloss[8], bp->gain[8]); logger->logstat = logprint(logger, logger->tmptxt, 2); sprintf(logger->tmptxt, " 9 Detector dxloss[9], bp->gain[9]); logger->logstat = logprint(logger, logger->tmptxt, 2); sprintf(logger->tmptxt, " 10 Detect dx>7-colw check: %10u %10u", bp->loss[10], bp->gain[10]); logger->logstat = logprint(logger, logger->tmptxt, 2); sprintf(logger->tmptxt, " 11 Blocked by ideal mask: %10u %10u", bp->loss[11], bp->gain[11]); logger->logstat = logprint(logger, logger->tmptxt, 2); sprintf(logger->tmptxt, " 12 Bl. by eliminated hole: %10u %10u", bp->loss[12], bp->gain[12]); logger->logstat = logprint(logger, logger->tmptxt, 2); sprintf(logger->tmptxt, " 13 Blocked by structure: %10u %10u", bp->loss[13], bp->gain[13]); logger->logstat = logprint(logger, logger->tmptxt, 2); sprintf(logger->tmptxt, " 15 Premature termination in backpro: %2d", bp->loss[15]); logger->logstat = logprint(logger, logger->tmptxt, 2); sprintf(logger->tmptxt, " Allowmax: %10u. Length distribution (100/bin): ", bp->allowmax); logger->logstat = logprint(logger, logger->tmptxt, 2); } for (i=0; i<100; i++) { sprintf(logger->tmptxt2, " %6d", bp->distri[i]); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); if ((i%10) == 9) { logger->logstat = logprint(logger, logger->tmptxt, 2); } } if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); logger->logstat = logprint(logger, logger->tmptxt, 2); time(&t); if (backproj->indep > 0) { /* only output 'skmap'-files if 'indep' > 0 */ time(&t); sprintf(logger->tmptxt, " Writing %s, byt_index: %10u, time: %s", backproj->newBackProjFile, bp->byt_index, ctime(&t)); logger->logstat = logprint(logger, logger->tmptxt, 2); /* * Append extension with d_allow table */ numRows = (bp->byt_index - 1)/D_ALLOW_BINSIZE + 1; jtmp = (long) bp->byt_index; if( chatter > J_CHATTY_NORMAL ) { RILlogMessage( NULL, Log_0, "##231## bp->byt_index: %ld, numRows: %ld", jtmp, numRows ); } strcpy( dataStrucName, strJMX ); strcat( dataStrucName, "-DALL-BPL" ); strcpy( templateName, dataStrucName ); strcat( templateName, ".tpl" ); status = DAL3GENobjectAppend( gptr, DAL_DISK, dataStrucName, templateName, &ptr, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##232## After append DALL (d_allow), status = %d", status ); goto exittrace; } else if ( chatter > J_CHATTY_NORMAL ) { RILlogMessage( NULL, Log_0, "##233## OK after append %s", dataStrucName ); } startRow = 0; status = DALtableAddRows( ptr, startRow, numRows, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##234## After AddRows, status = %d", status ); goto exittrace; } index_out = 0; bytes = bp->byt_index; status = DALattributePutInt( ptr, "NUMBYTES", (long) bytes, NULL, "Number of elements in d_allow", status ); startRow = 0; while (bytes >= D_ALLOW_BINSIZE) { for (i=0; id_allow[index_out++]); /* fwrite(d_allow_b, 1, 1000, bfil); */ startRow++; status = DALtablePutColBins( ptr, "D_ALLOW", 0, DAL_BYTE, startRow, startRow, D_ALLOW_BINSIZE, d_allow_b, status ); bytes -= D_ALLOW_BINSIZE; } if( bytes > 0 ) { /* Empty the buffer */ for (i=0; id_allow[index_out++]); /* fwrite(d_allow_b, 1, bytes, bfil); */ for( i = bytes; i < D_ALLOW_BINSIZE; i++ ) d_allow_b[i] = 0; startRow++; status = DALtablePutColBins( ptr, "D_ALLOW", 0, DAL_BYTE, startRow, startRow, D_ALLOW_BINSIZE, d_allow_b, status ); } if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##235## After writing d_allow, status = %d", status ); goto exittrace; } if( startRow != numRows ) { RILlogMessage( NULL, Error_1, "##236## Wrong number of rows: numRows = %ld, " "startRow = %ld", numRows, startRow ); status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_WRONGNUMROWS; goto exittrace; } time(&t); sprintf(logger->tmptxt, "##237## Completed writing %s, byt_index: %10u, time: %s", backproj->newBackProjFile, bp->byt_index, ctime(&t)); logger->logstat = logprint(logger, logger->tmptxt, 2); bp->parameters[0] = bp->byt_index; bp->parameters[3] = backproj->sky_xdim; bp->parameters[4] = -backproj->FOV_radius; /* was 'skyxoffs */ bp->parameters[5] = backproj->sky_ydim; bp->parameters[6] = -backproj->FOV_radius; /* was 'skyyoffs */ bp->parameters[7] = backproj->coll_model_yes; bp->parameters[8] = jmx_id->jmx_unit; bp->parameters[9] = backproj->FOV_radius; bp->parameters[19] = (float)(backproj->sky_version); strcpy( dataStrucName, strJMX ); strcat( dataStrucName, "-DAST-BPL" ); strcpy( templateName, dataStrucName ); strcat( templateName, ".tpl" ); status = DAL3GENobjectAppend( gptr, DAL_DISK, dataStrucName, templateName, &ptr, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##238## After append DAST (d_allow_st), status = %d", status ); goto exittrace; } startRow = 0; numRows = 1; status = DALtableAddRows( ptr, startRow, numRows, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##239## After AddRows, status = %d", status ); goto exittrace; } startRow = 1; status = DALtablePutColBins( ptr, "D_ALLOW_ST", 0, DAL_INT, startRow, startRow, detdim, bp->d_allow_st, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##240## After writing d_allow_st, status = %d", status ); goto exittrace; } /* * Add parameters as keywords */ for( i = 0; i < 20; i++ ) { sprintf( keyword, "PARMTR%02d", i ); status = DALattributePutReal( ptr, keyword, bp->parameters[i], NULL, "Parameter from array bp->parameters", status ); } if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##241## After keyword writing, status = %d", status ); goto exittrace; } strcpy( dataStrucName, strJMX ); strcat( dataStrucName, "-DAWL-BPL" ); strcpy( templateName, dataStrucName ); strcat( templateName, ".tpl" ); status = DAL3GENobjectAppend( gptr, DAL_DISK, dataStrucName, templateName, &ptr, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##242## After append DAWL (d_allow_l), status = %d", status ); goto exittrace; } startRow = 0; numRows = 1; status = DALtableAddRows( ptr, startRow, numRows, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##243## After AddRows, status = %d", status ); goto exittrace; } startRow = 1; status = DALtablePutColBins( ptr, "D_ALLOW_L", 0, DAL_SHORT, startRow, startRow, detdim, bp->d_allow_l, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##244## After writing d_allow_l, status = %d", status ); goto exittrace; } strcpy( dataStrucName, strJMX ); strcat( dataStrucName, "-DAWP-BPL" ); strcpy( templateName, dataStrucName ); strcat( templateName, ".tpl" ); status = DAL3GENobjectAppend( gptr, DAL_DISK, dataStrucName, templateName, &ptr, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##245## After append DAWP (d_allow_p), status = %d", status ); goto exittrace; } startRow = 0; numRows = 1; status = DALtableAddRows( ptr, startRow, numRows, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##246## After AddRows, status = %d", status ); goto exittrace; } startRow = 1; status = DALtablePutColBins( ptr, "D_ALLOW_P", 0, DAL_ULONG, startRow, startRow, detdim, bp->d_allow_p, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##247## After writing d_allow_st, status = %d", status ); goto exittrace; } strcpy( dataStrucName, strJMX ); strcat( dataStrucName, "-MHOL-BPL" ); strcpy( templateName, dataStrucName ); strcat( templateName, ".tpl" ); status = DAL3GENobjectAppend( gptr, DAL_DISK, dataStrucName, templateName, &ptr, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##248## After append MHOL (maskhole), status = %d", status ); goto exittrace; } startRow = 0; numRows = 1; status = DALtableAddRows( ptr, startRow, numRows, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##249## After AddRows, status = %d", status ); goto exittrace; } startRow = 1; status = DALtablePutColBins( ptr, "MASKHOLE", 0, DAL_USHORT, startRow, startRow, 22501, maskhole, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##250## After writing maskhole, status = %d", status ); goto exittrace; } } else { /* only output the 'detmap' illumination matrix if 'indep' = 0 */ sprintf(logger->tmptxt, " Entering section for 'illumin' output"); logger->logstat = logprint(logger, logger->tmptxt, 2); strcpy( dataStrucName, strJMX ); strcat( dataStrucName, "-DMAP-BPL" ); strcpy( templateName, dataStrucName ); strcat( templateName, ".tpl" ); if( chatter > J_CHATTY_NORMAL ) { RILlogMessage( NULL, Log_0, "##252## DMAP: %s %s", dataStrucName, templateName ); } status = DAL3GENobjectAppend( gptr, DAL_DISK, dataStrucName, templateName, &ptr, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##253## After append DMAP (detmap), status = %d", status ); goto exittrace; } /* * Modify the array structure and write the array */ numAxes = 3; axes[0] = backproj->sky_xdim; axes[1] = backproj->sky_ydim; axes[2] = N_RAD_LIMITS; startValues[0] = 1; startValues[1] = 1; startValues[2] = 1; /* previously DAL_DT_UNKNOWN [2005-04-18/NJW] */ status = DALarrayModStruct( ptr, DAL_USHORT, numAxes, axes, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##254## After ModStruct, status = %d", status ); goto exittrace; } status = DALarrayPutSection( ptr, numAxes, startValues, axes, DAL_USHORT, bp->illumin, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##255## After writing bp->illumin, status = %d", status ); goto exittrace; } backproj->indep = temp_indep; sprintf(logger->tmptxt, " leaving section for 'illumin' output, indep = %f", backproj->indep); logger->logstat = logprint(logger, logger->tmptxt, 2); goto next_round; } status = DALobjectClose( gptr, DAL_SAVE, status ); exittrace: 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( ISDC_OK ); */ return( status ); } /***************************************************************** * Name of source file: skymap.c * Version of source file: 4.0.12 * Parent component: None * Programmer: Niels Lund & Niels J. Westergaard * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325700 FAX: +45 35362475 * nl@spacecenter.dk, njw@spacecenter.dk * Purpose: Calculate sky visibility across the detector surface * Origin date: 041122 * Update history: 1.0.0 041130 First version * 1.0.4 050126 Test version for undue crash * 1.1.0 050131 Now reading FITS sky/backproj files * 1.1.1 050211 Keywords adapted to needs of j_ima_mosaic * 1.1.2 050303 Extra keyw:RLIMIDX, new cleaning * 1.1.3 050307 New DMAP: 51 radii * 1.1.4 050407 New clean, etc. * 1.1.5 050415 New clean again, updated flux determination * 1.1.6 050418 Now uses JMXi-DBKG-MOD as default for empty field shds * 1.2.0 050425 Deals with SPR 4102,4108 and reduces RAM requirement * 1.3.0 050503 Deals with SPR 4120 and copes with up to 6 shadowgrams * 1.3.1 050517 Deals with SPR 4143 and initializes ima_sigma properly * 1.3.2 050519 Closes SPR 4157 - bad size of three arrays * 1.3.3 050602 Changes some arrays to static (SPR 4202) * 1.4.0 050620 Include user defined sources (SCREW 1740) * 1.4.1 051125 Update call to struchk * 1.5.1 051129 Separating functions to jmx_lib_pif * 1.5.2 051202 Separating functions to jmx_lib_pif (2) * 1.5.3 051202 Give offX, x2x values in mm in IMOD-GRP * 1.5.4 060104 Bug in sh_depth corrected, detectmap now in mm * 1.5.5 060106 Introduced one more digit in logfile for src position * 1.5.6 060228 Removed parameter detMapFile and some obsolete variables * 1.5.7 060606 Shifted detCondMap to struct jmx_id and status_map * 1.6.0 060725 Reduce collimator height and eliminate coll_w during bpl-list generation * 1.5.8 060807 SPR 04551 Bad assignment of RLIMIDX corrected * 1.5.9 060807 SPR 04533 Resetting status variable has been removed * 1.5.10 060807 SPR 04523 Declaring testsum as float iso. int * 1.5.11 060807 SPR 04458 A warning log line has been added * 1.5.12 060907 SPR 04301 A relative VIGNDOL path is given * 1.6.0 060911 SCREW 1918 Image correction map and parameters introduced * 1.6.1 060912 SPR 4441 Shadowgrams with too few counts are excluded * 1.6.2 060915 SCREW 1842 A significance map can now be obtained * 1.6.3 060915 An exposure (vignetting) map is now a product * 1.6.4 060928 Included test for zero divisor in peaktransfer.c * 1.6.5 061002 New defaults for par. skyImagesOut * 1.7.0 061110 Produces images with few or zero events (SPR 4594) * 1.7.1 061114 SPR 4603 Image unit (BUNIT) is now cts/dm2/s * 1.8.0 061213 SPR 4640 Error in findpeak has been corrected * 1.8.1 070123 SPR 4590 int changed to long for 64 bit code * 2.1.0 070809 SCREWs 2021-2023 * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.2.0 071205 Flux determination has been improved * 2.2.1 071205 SPR 4742: Division by zero eliminated * 2.2.2 080111 Makes trigger rates from JEM-X HK available * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 3.2.7 100224 SPR 4915: Fixing logics for sparse shadowgrams * 4.0.12 120919 SPR ?: Introduce corrections by LP and Co. * Type of element: Function * Part of package: j_ima_iros * Name: skymap * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ int skymap( struct backpro *backproj, struct instr_data *jmx_id, struct log_con *logger, struct backpro_lists *bp, struct shadowgrams *sh, struct image_cor *ima_corr, short maskhole[]) /* sky visibility across JEM-X detector surface */ /* * Niels Lund, February 2001 Version 0.1 * Niels Lund, November 2002 Version 3.0 * Niels Lund, August 2003 Version 4.0 * Niels Lund, January 2005 Version 5.0 * * April 2001 Version 1.0 (skyxdim x skyydim sky pixels) * November 2002 Version 3.0 Detector units are mm. * August 2003 Version 4.0 Introduces structure shadowing and "eliminated holes" in mask pattern * January 2005 Version 5.0 Modified as a subroutine under j_ima_iros * Danish National Space Center * * NOTE: The jemx (jmx_id->jmx_unit) variable is 0 for JEM-X1 and 1 for JEM-X2 in these routines !! * * The XY-coordinate system used in this routine is aligned with * the detector collimator lamellae. The microstrip pattern is * approximately aligned with the lamellae. The cathode positions * are (nearly) along the X-axis, the backside positions nearly * along the Y-axis. The center of the detector is located at * position (128, 128). The central collimator crossing is * also at this position. The center of the collimator falls at * the corner between 4 pixel boundaries. * * The unit used for the X- and Y-positions on the detector are * 1 mm. Actually, the X- and Y-integer positions are only * approximately separated by 1 mm. A detailed map, specifying * the float values of the X- and Y-position of the four corners * of each pixel have been prepared by Carl Budtz-J. * * The full field of view of the JEM-X detector is defined by the * dimensions of the mask (535 mm diameter) and detector (250 mm * diameter) and by the mask-detector separation (about 3400 mm). * * An orthogonal direction grid of 'skyxdim'*'skyydim' sky pixels * is defined within the full field of view, which has a radius * of 'FOV_radius' pixels. * */ { int i, j, allownum, dif, iq, iv, ky, mx, mmm, njwhole, strblock; int xyacc, status=0; int zz20[SKY_XDIM], njw1, njw2, idy, jdx, ksy, msx, n255_bytes; int ee, sky_index, cur_index, m255, n_line=0; int pal_seq, pal_shf, pal_bit, im_seq; int nn = 0, rdet, rdet_lim; int nnn[4]; unsigned det_index; unsigned mx2, xd7, yd7, xc7, yc7, aind; unsigned char ch255; short bad_reg[backproj->skydim]; double xdet, ydet, xmask, ymask; double rm2; double ydet2, qmask, vmask, xcoll2, rrdet; double xdmod7, ydmod7, xtmod7, ytmod7, dxlow, dylow, dxhigh, dyhigh; double ycolbot, ycoltop, xcolbot, xcoltop, xrmask, yrmask, xmask2; double xrcbot, xrctop, yrcbot, yrctop, xrdet, yrdet; double fov_r2, testX, testY; static int first = 1; FILE *par_chk; 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], "skymap"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } 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); /* initializations */ skymap_init(backproj, jmx_id, logger, bp); if (logger->develop) { if (first) par_chk = fopen("skymap_par_chk.txt", "wt"); else par_chk = fopen("skymap_par_chk.txt", "at"); saveparams(par_chk, -1, jmx_id, backproj, bp, logger); fclose(par_chk); } /* Common-X is the direction from JEM-X2 towards JEM-X1 */ sprintf(logger->tmptxt, " msk_rot: %+5.2lf, col_rot: %+5.2lf, ms_rot %5.2lf, x/y_shft: %+4.2lf/%4.2lf", (double)(jmx_id->alfa / GTORAD), (double)(jmx_id->beta / GTORAD), (double)(jmx_id->gammav / GTORAD), jmx_id->xshi, jmx_id->yshi); logger->logstat = logprint(logger, logger->tmptxt, 4); bp->parameters[10] = backproj->indep; bp->parameters[11] = jmx_id->alfa; bp->parameters[12] = jmx_id->beta; bp->parameters[13] = jmx_id->gammav; bp->parameters[15] = jmx_id->xshi; bp->parameters[16] = jmx_id->yshi; bp->parameters[18] = jmx_id->mask_height; sprintf(logger->tmptxt, " c_fact: %10.6lf, c_factb: %10.6lf, m_fact: %10.6lf", bp->c_fact, bp->c_factb, bp->m_fact); logger->logstat = logprint(logger, logger->tmptxt, 4); ch255 = 255; for (i=0; id_allow_l[i] = 0; for (i=0; isky_xdim; i++) { j = (i + 8) / 20; if (j < 1) j = 1; if (j > 12) j = 12; zz20[i] = j - 1; } for (i=0; i<25; i++) bp->loss[i] = bp->gain[i] = 0; det_index = 0; sky_index = 0; cur_index = 0; allownum = 0; bp->byt_index = 0; bp->allowmax = 0; fov_r2 = (double)(backproj->FOV_radius * backproj->FOV_radius) * 1.02; if (first) { for (i=0; iskydim; i++) { bad_reg[i] = 1; testX = (double)((int)(i / backproj->sky_ydim) - backproj->FOV_radius); testY = (double)((i % backproj->sky_ydim) - backproj->FOV_radius); if ((testX*testX + testY*testY) < fov_r2) bad_reg[i] = 0; } first = 0; } sprintf(logger->tmptxt, "Starting main loop in skymap"); logger->logstat = logprint(logger, logger->tmptxt, 4); /* *************** main loop ********************* */ n255_bytes = 0; for (idy=0; idy<256; idy++) { /* loop over detector Y *********************************** */ yrdet = (double)(idy) - 127.5 + jmx_id->yshi; ydet2 = yrdet * yrdet; if ((idy%8) == 0) { sprintf(logger->tmptxt, " Det_radius Coll_rad. Mask_rad. +Y cross -Y cross +Y thick -Y thick"); sprintf(logger->tmptxt2, " Ideal_Mask Elimin_hole Struct Accept"); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); logger->logstat = logprint(logger, logger->tmptxt, 2); sprintf(logger->tmptxt, " "); for (mmm=0; mmm<13; mmm++) { if (mmm == 8) continue; if (mmm == 9) continue; if (mmm == 10) continue; sprintf(logger->tmptxt2, " %10u", bp->loss[mmm]); /* print loss counters for every 8th Y-value */ if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } sprintf(logger->tmptxt2, " %3d", idy); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); logger->logstat = logprint(logger, logger->tmptxt, 2); sprintf(logger->tmptxt, " "); for (mmm=0; mmm<13; mmm++) { if (mmm == 8) continue; if (mmm == 9) continue; if (mmm == 10) continue; sprintf(logger->tmptxt2, " %10u", bp->gain[mmm]); /* print gain counters for every 8th Y-value */ if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } sprintf(logger->tmptxt2, " %10u\n", bp->gain[mmm]); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); logger->logstat = logprint(logger, logger->tmptxt, 2); } allownum = 0; for (jdx=0; jdx<256; jdx++) { /* loop over detector X ************************************* */ if (n_line > 0) { if (logger->chatter == 7) { logger->logstat = logprint(logger, logger->tmptxt, 4); sprintf(logger->tmptxt, " "); } n_line = 0; } if (allownum > 0) { /* save length information for previous list */ if (allownum > 65535) { sprintf(logger->tmptxt, "allownum catastrophe !!!!!!!!!!!!!!!!!!!!!!!!!!!!! allownum: %7d\n", allownum); logger->logstat = logprint(logger, logger->tmptxt, 1); status = -1; goto exittrace; } bp->d_allow_l[det_index] = allownum; aind = allownum / 100; bp->distri[aind]++; if (allownum > bp->allowmax) bp->allowmax = allownum; allownum = 0; } det_index = jdx * 256 + idy; bp->d_allow_st[det_index] = bp->byt_index; bp->d_allow_l[det_index] = 0; n255_bytes = 0; xrdet = (double)(jdx) - 127.5 + jmx_id->xshi; rrdet = sqrt(ydet2 + xrdet*xrdet); rdet_lim = rrdet + 0.5; if (rdet_lim > 125) rdet_lim = 125; if (rdet_lim < 75) rdet_lim = 75; if (rdet_lim < (125-N_RAD_LIMITS+1)) rdet_lim = 125-N_RAD_LIMITS+1; /* corrected 21/8 2006 NL */ if (rrdet > bp->bpl_det_rad_limit) { /* detector radius check */ bp->loss[0] += backproj->skydim; continue; } else bp->gain[0] += backproj->skydim; xdet = xrdet * bp->cosga - yrdet * bp->singa; ydet = yrdet * bp->cosga + xrdet * bp->singa; /* xdet and ydet are coordinates of a detector pixel in a coord. system aligned after Common-X */ xyacc = 0; for (msx=0; msxsky_xdim; msx++) { /* loop over sky-direction X **************** */ mx = msx - backproj->FOV_radius; mx2 = mx * mx; xcolbot = (double)(mx) * bp->c_factb + xdet; xcoltop = (double)(mx) * bp->c_fact + xdet; xcoll2 = xcoltop * xcoltop; xrmask = (double)(mx) * bp->m_fact + xdet; xmask2 = xrmask * xrmask; dxlow = (double)(mx) * bp->s_fact_l; dxhigh = (double)(mx) * bp->s_fact_h; for (ksy=0; ksysky_ydim; ksy++) { /* loop over sky-direction Y ***************** */ ky = ksy - backproj->FOV_radius; ycolbot = (double)(ky) * bp->c_factb + ydet; ycoltop = (double)(ky) * bp->c_fact + ydet; if ((xcoll2 + ycoltop * ycoltop) > bp->coll_r2) { bp->loss[1] += 1; continue; /* Collimator top radius check */ } else bp->gain[1] += 1; yrmask = (double)(ky) * bp->m_fact + ydet; rm2 = yrmask * yrmask + xmask2; dylow = (double)(ky) * bp->s_fact_l; dyhigh = (double)(ky) * bp->s_fact_h; if (rm2 > bp->mask_r2) { /* the event falls outside the coded mask */ bp->loss[2]++; continue; } else bp->gain[2]++; xrcbot = xcolbot * bp->cosbe + ycolbot * bp->sinbe; /* rotation through - beta! */ yrcbot = ycolbot * bp->cosbe - xcolbot * bp->sinbe; xrctop = xcoltop * bp->cosbe + ycoltop * bp->sinbe; /* rotation through - beta! */ yrctop = ycoltop * bp->cosbe - xcoltop * bp->sinbe; /* determine open directions of collimator the collimator lamellae are located on positions: -126.9,-119.85, ... ,-21.15, -14.1, -7.05, 0, 7.05, 14.1, 21.15, ... , 119.85, 126.9 both in the X- and Y-direction */ yd7 = (int)((yrcbot + bp->collp30) / jmx_id->coll_pitch); /* determine bottom collimator hole index bp->collp30 >detector radius */ yc7 = (int)((yrctop + jmx_id->c_tilty + bp->collp30top) / bp->coll_ptop); /* determine top collimator hole index */ if (backproj->coll_model_yes) { if (yc7 > yd7) { bp->loss[3]++; continue; /* Y-collimator wall +crossing check */ /* the event is lost due to wall crossing in the collimator */ } else bp->gain[3]++; if (yc7 < yd7) { bp->loss[4]++; continue; /* Y-collimator wall -crossing check */ /* the event is lost due to wall crossing in the collimator */ } else bp->gain[4]++; if (bp->coll_h_reduc > 0.0) goto no_edge_check1; /* disregard thickness of collimator */ ydmod7 = yrcbot + bp->collp30 - jmx_id->coll_pitch * yd7; /* get remainder Ycoord within this hole */ if (ydmod7 < jmx_id->coll_wb) { /* the event is lost at the bottom edge of the collimator */ bp->loss[5]++; /* Y-collimator wall -thickness check */ continue; } if (ydmod7 > (jmx_id->coll_pitch - jmx_id->coll_wb)) { /* the event is lost at the bottom edge of the collimator */ bp->loss[6]++; /* Y-collimator wall +thickness check */ continue; } ytmod7 = yrctop + jmx_id->c_tilty + bp->collp30top - bp->coll_ptop * yc7; /* get remainder Ycoord within this hole */ if (ytmod7 < jmx_id->coll_w) { /* the event is lost at the top edge of the collimator */ bp->loss[5]++; /* Y-collimator wall -thickness check */ continue; } else bp->gain[5]++; if (ytmod7 > (bp->coll_ptop - jmx_id->coll_w)) { /* the event is lost at the top edge of the collimator */ bp->loss[6]++; /* Y-collimator wall +thickness check */ continue; } else bp->gain[6]++; no_edge_check1: ; } xd7 = (int)((xrcbot + bp->collp30) / jmx_id->coll_pitch); xc7 = (int)((xrctop + jmx_id->c_tiltx + bp->collp30top) / bp->coll_ptop); if (backproj->coll_model_yes) { if (xc7 > xd7) { /* the event is lost due to wall crossing in the collimator */ bp->loss[7]++; continue; } else bp->gain[7]++; if (xc7 < xd7) { /* the event is lost due to wall crossing in the collimator */ bp->loss[8]++; continue; } else bp->gain[8]++; if (bp->coll_h_reduc > 0.0) goto no_edge_check2; /* disregard thickness of collimator */ xdmod7 = xrcbot + bp->collp30 - jmx_id->coll_pitch * xd7; if (xdmod7 < jmx_id->coll_w) { /* the event is lost at the bottom edge of the collimator */ bp->loss[9]++; continue; } if (xdmod7 > (jmx_id->coll_pitch - jmx_id->coll_wb)) { /* the event is lost at the bottom edge of the collimator */ bp->loss[10]++; continue; } xtmod7 = xrctop + jmx_id->c_tiltx + bp->collp30top - bp->coll_ptop * xc7; if (xtmod7 < jmx_id->coll_w) { /* the event is lost at the top edge of the collimator */ bp->loss[9]++; continue; } else bp->gain[9]++; if (xtmod7 > (jmx_id->coll_pitch - jmx_id->coll_w)) { /* the event is lost at the top edge of the collimator */ bp->loss[10]++; continue; } else bp->gain[10]++; no_edge_check2: ; } xmask = xrmask * bp->cosal + yrmask * bp->sinal; ymask = yrmask * bp->cosal - xrmask * bp->sinal; sky_index = msx * backproj->sky_ydim + ksy; /* * Replaced by call of new (2005-01-31) function 'hexpos' */ qmask = xmask / jmx_id->hexa_dim - ymask * bp->cot60; vmask = ymask * bp->rsin60; iq = qmask + 22501.5; iv = vmask + 22501.5; nn = (iq + 1133 * iv) % 22501; iq = iq - 22501; iv = iv - 22501; njw1 = 99+iq+iv; njw2 = 100+iv; if( logger->useHexpos ) { nn = hexpos( xmask, ymask, nnn, jmx_id->hexa_dim ); njw1 = nnn[1]; njw2 = nnn[2]; } njwhole = 0; if ((njw1 >= 0) && (njw1 < 200) && (njw2 >= 0) && (njw2 < 200)) { if (jmx_id->njwmask[njw1][njw2] == J_MASK_OPEN_CELL) njwhole = 1; } else { sprintf(logger->tmptxt, "Index error for jemxmask: %3d %3d\n", njw1, njw2); logger->logstat = logprint(logger, logger->tmptxt, 4); status = -11; goto exittrace; } if ((int)(maskhole[nn]) > 0) { bp->gain[11]++; strblock = struchk(xmask, ymask, xdet, ydet, 0, jmx_id, logger); if (njwhole) { bp->gain[12]++; if (strblock == 0) { bp->gain[13]++; if (backproj->indep == 0) { ee = 0; if (sh->soft_shdgr[1][det_index] > 0.0) for (rdet=125; rdet>=rdet_lim; rdet--) bp->illumin[rdet-(125-N_RAD_LIMITS+1)][sky_index]++; } dif = 0; if (allownum |= 0) { if (sky_index < cur_index) { sprintf(logger->tmptxt, "sky_indexlogstat = logprint(logger, logger->tmptxt, 4); status = -14; goto exittrace; } dif = sky_index - cur_index; m255 = 0; while (dif > 254) { *(bp->d_allow + bp->byt_index) = ch255; bp->byt_index++; if (bp->byt_index > max_sky_bytes) { sprintf(logger->tmptxt, " byt_index exceeded range! idy,jdx,ksy,msx: %4d %4d %4d %4d", idy,jdx,ksy,msx); logger->logstat = logprint(logger, logger->tmptxt, 4); status = -12; goto exittrace; } dif -= 255; n255_bytes++; m255++; } *(bp->d_allow + bp->byt_index) = (unsigned char)(dif); bp->byt_index++; if (bp->byt_index > max_sky_bytes) { sprintf(logger->tmptxt, " byt_index exceeded range! idy,jdx,ksy,msx: %4d %4d %4d %4d, byt_index: %12d", idy,jdx,ksy,msx, bp->byt_index); logger->logstat = logprint(logger, logger->tmptxt, 2); status = -13; goto exittrace; } if ((idy == 28) && (jdx == 170)) { if (bad_reg[sky_index]) sprintf(logger->tmptxt2, " * "); else sprintf(logger->tmptxt2, " "); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); sprintf(logger->tmptxt2, "%3d %3d %6d", m255, dif, sky_index); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); if (((n_line%8) == 7) && (logger->chatter == 7)) { logger->logstat = logprint(logger, logger->tmptxt, 4); sprintf(logger->tmptxt, " "); } n_line++; } } else { if ((idy == 28) && (jdx == 170)) { m255 = dif = 0; if (bad_reg[sky_index]) sprintf(logger->tmptxt2, " * "); else sprintf(logger->tmptxt2, " "); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); sprintf(logger->tmptxt2, "%3d %3d %6d", m255, dif, sky_index); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); if (((n_line%8) == 7) && (logger->chatter == 7)) { logger->logstat = logprint(logger, logger->tmptxt, 4); sprintf(logger->tmptxt, " "); } n_line++; } bp->d_allow_p[det_index] = sky_index; } cur_index = sky_index; allownum++; /* save shadowgrams showing illuminated pixels for selected sky positions */ /* will be used to evaluate ratio of edge pixels to total pixels among illuminated pixels */ if (backproj->indep > 0) { if ((msx%4) == 3) { if ((ksy%4) == 3) { if ((im_seq = ima_corr->ima_seq[msx][ksy]) >= 0) { pal_seq = im_seq / 8; pal_shf = im_seq % 8; pal_bit = 1 << pal_shf; ima_corr->paltani[pal_seq][jdx][idy] |= (unsigned char)(pal_bit); } } } } } else { bp->loss[13]++; } } else { bp->loss[12]++; /* nl mask open, njw mask closed (eliminated hole) */ if (strblock == 0) bp->loss[14]++; /* eliminated hole and no structure blocking, suspicious case! */ } } else { bp->loss[11]++; } } } } } struchk(0.0, 0.0, 0.0, 0.0, 2, jmx_id, logger); if (backproj->indep > 0) paltani_eval(ima_corr); if (status < 0) goto exittrace; status = 0; exittrace: if (logger->trace) traces(func_local, 99 +status, 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); } /***************************************************************** * Name of source file: skymap_init.c * Version of source file: 3.2.7 * Parent component: None * Programmer: Niels Lund & Niels J. Westergaard * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325700 FAX: +45 35362475 * nl@spacecenter.dk, njw@spacecenter.dk * Purpose: Initialize skymap generation * Origin date: 041122 * Update history: 1.0.0 041130 First version * 1.0.4 050126 Test version for undue crash * 1.1.0 050131 Now reading FITS sky/backproj files * 1.1.1 050211 Keywords adapted to needs of j_ima_mosaic * 1.1.2 050303 Extra keyw:RLIMIDX, new cleaning * 1.1.3 050307 New DMAP: 51 radii * 1.1.4 050407 New clean, etc. * 1.1.5 050415 New clean again, updated flux determination * 1.1.6 050418 Now uses JMXi-DBKG-MOD as default for empty field shds * 1.2.0 050425 Deals with SPR 4102,4108 and reduces RAM requirement * 1.3.0 050503 Deals with SPR 4120 and copes with up to 6 shadowgrams * 1.3.1 050517 Deals with SPR 4143 and initializes ima_sigma properly * 1.3.2 050519 Closes SPR 4157 - bad size of three arrays * 1.3.3 050602 Changes some arrays to static (SPR 4202) * 1.4.0 050620 Include user defined sources (SCREW 1740) * 1.5.1 051129 Separating functions to jmx_lib_pif * 1.5.2 051202 Separating functions to jmx_lib_pif (2) * 1.5.3 051202 Give offX, x2x values in mm in IMOD-GRP * 1.5.4 060104 Bug in sh_depth corrected, detectmap now in mm * 1.5.5 060106 Introduced one more digit in logfile for src position * 1.5.6 060228 Removed parameter detMapFile and some obsolete variables * 1.5.7 060606 Shifted detCondMap to struct jmx_id and status_map * 1.6.0 060725 Reduce collimator height and eliminate coll_w during bpl list generation * 1.5.8 060807 SPR 04551 Bad assignment of RLIMIDX corrected * 1.5.9 060807 SPR 04533 Resetting status variable has been removed * 1.5.10 060807 SPR 04523 Declaring testsum as float iso. int * 1.5.11 060807 SPR 04458 A warning log line has been added * 1.5.12 060907 SPR 04301 A relative VIGNDOL path is given * 1.6.0 060911 SCREW 1918 Image correction map and parameters introduced * 1.6.1 060912 SPR 4441 Shadowgrams with too few counts are excluded * 1.6.2 060915 SCREW 1842 A significance map can now be obtained * 1.6.3 060915 An exposure (vignetting) map is now a product * 1.6.4 060928 Included test for zero divisor in peaktransfer.c * 1.6.5 061002 New defaults for par. skyImagesOut * 1.7.0 061110 Produces images with few or zero events (SPR 4594) * 1.7.1 061114 SPR 4603 Image unit (BUNIT) is now cts/dm2/s * 1.8.0 061213 SPR 4640 Error in findpeak has been corrected * 1.8.1 070123 SPR 4590 int changed to long for 64 bit code * 2.1.0 070809 SCREWs 2021-2023 * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.2.0 071205 Flux determination has been improved * 2.2.1 071205 SPR 4742: Division by zero eliminated * 2.2.2 080111 Makes trigger rates from JEM-X HK available * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 3.2.7 100224 SPR 4915: Fixing logics for sparse shadowgrams * Type of element: Function * Part of package: j_ima_iros * Name: skymap_init * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ void skymap_init(struct backpro *backproj, struct instr_data *jmx_id, struct log_con *logger, struct backpro_lists *bp) /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* */ /* skymap_init.c defines certain parameters to be used in the generation */ /* of skymaps. */ /* */ /* Niels Lund, March 2004 */ /* Uses NJW-mask and detector support struct. */ /* */ /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* * * The full field of view of the JEM-X detector is defined by the * dimensions of the mask (535 mm diameter) and detector (250 mm * diameter) and by the mask-detector separation (about 3400 mm). * * The full field of view, which has a radius of 'FOV_radius' pixels. * */ { int i, j; float c0_fact; 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], "skymap_init"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } 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, 1, logger); /* initializations */ sprintf(logger->tmptxt, "Entering skymap_init\n"); logger->logstat = logprint(logger, logger->tmptxt, 5); /* Common-X is the direction from JEM-X2 towards JEM-X1 */ bp->bpl_det_rad_limit = jmx_id->coll_r; /* detector radius limit used during bpl generation */ bp->collp30 = jmx_id->coll_pitch * 30.0; /* 30 time the collimator pitch, used in the "modulo" calc */ bp->coll_ptop = jmx_id->coll_pitch * jmx_id->coll_curv; bp->collp30top = bp->coll_ptop * 30.0; bp->coll_r2 = jmx_id->coll_r * jmx_id->coll_r; bp->mask_r2 = jmx_id->mask_r * jmx_id->mask_r; bp->cosal = cos(jmx_id->alfa); bp->sinal = sin(jmx_id->alfa); bp->cosbe = cos(jmx_id->beta); bp->sinbe = sin(jmx_id->beta); bp->cosga = cos(jmx_id->gammav); bp->singa = sin(jmx_id->gammav); c0_fact = 6.6 / backproj->FOV_radius; /* stepsize (mm) in skymap at collimator top level */ bp->m_fact = c0_fact * (jmx_id->mask_height + backproj->indep) / jmx_id->coll_h; /* corresponding stepsize (mm) at mask level */ bp->c_factb = c0_fact * (backproj->indep + bp->coll_h_reduc) / jmx_id->coll_h; /* corresponding stepsize (mm) at (reduced) bottom of collimator */ bp->c_fact = c0_fact * (jmx_id->coll_h + backproj->indep - bp->coll_h_reduc) / jmx_id->coll_h; /* corresponding stepsize (mm) at (reduced) top of collimator */ bp->s_fact_l = c0_fact * jmx_id->struc_h1 * 2.0 / jmx_id->coll_h; /* corresp. delta-step for low structure members (0.5 mm step) */ bp->s_fact_h = c0_fact * jmx_id->struc_h2 * 2.0 / jmx_id->coll_h; /* corresp. delta-step for high structure members (0.5 mm step) */ bp->cot60 = 1.0 / (jmx_id->hexa_dim * 1.73205081); bp->rsin60 = 2.0 * bp->cot60; for (j=0; jskydim; i++) bp->illumin[j][i] = 0; for (i=0; i<100; i++) bp->distri[i] = 0; for (i=0; i<25; i++) bp->gain[i] = bp->loss[i] = 0; for (i=0; id_allow_p[i] = 0; bp->d_allow_l[i] = 0; bp->d_allow_st[i] = 0; } for (i=0; id_allow[i] = 0; sprintf(logger->tmptxt, "##256## Completed skymap_init"); logger->logstat = logprint(logger, logger->tmptxt, 5); bp->allowmax = 0; bp->byt_index = 0; 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; } /***************************************************************** * Name of source file: mask_test.c * Version of source file: 3.2.7 * Programmer: Niels Lund & Niels J. Westergaard * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325705 FAX: +45 35362475 * njw@space.dtu.dk * Purpose: Initiate the backprojection and source * finding processes * Origin date: 041122 * Update history: 1.0.0 041130 First version * 1.6.3 060915 An exposure (vignetting) map is now a product * 1.6.4 060928 Included test for zero divisor in peaktransfer.c * 1.6.5 061002 New defaults for par. skyImagesOut * 1.7.0 061110 Produces images with few or zero events (SPR 4594) * 1.7.1 061114 SPR 4603 Image unit (BUNIT) is now cts/dm2/s * 2.1.0 070809 SCREWS 2021-2023 * 2.1.0 070809 SCREWs 2021-2023 * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.2.0 071205 Flux determination has been improved * 2.2.1 071205 SPR 4742: Division by zero eliminated * 2.2.2 080111 Makes trigger rates from JEM-X HK available * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 3.2.7 100224 SPR 4915: Fixing logics for sparse shadowgrams * Type of element: Function * Part of package: j_ima_iros * Name: mask_test * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ int mask_test( struct log_con *logger, struct instr_data *jmx_id, struct backpro_lists *bp ) { FILE *stream = NULL; int i, j; int iq, iv, nn, njw1, njw2; int m, iorder, nr, njwhole, maskhole[22501], ntal, ma; int numtests = 0; int num_ok = 0; int num_bad = 0; int num_nl_open = 0; int num_nl_clsd = 0; int num_njw_open = 0; int num_njw_clsd = 0; double qmask, vmask, xmask, ymask, r; /* generate basic ideal mask pattern (not including production modifications) */ iorder = 22501; /* prime number of type: 4u + 1 */ nr = 1133; /* prime number used for shift between lines in mask array */ for (m=1; m<=iorder; m++) maskhole[m] = 0; for (m=1; m<=iorder-1; m++) { ntal = (m * m) % iorder; ma = ntal; ntal = (int)((ma * ma) % iorder); maskhole[ntal] = 1; } if( (stream = fopen("mask_test_003.scm","w")) == NULL ) { RILlogMessage( NULL, Error_1, "Could not open test file"); return(-123); } fprintf( stream, "// jmx_id->hexa_dim = %f\n", jmx_id->hexa_dim ); fprintf( stream, "// bp->cot60 = %f\n", bp->cot60 ); fprintf( stream, "// bp->rsin60 = %f\n", bp->rsin60 ); numtests = 0; num_ok = 0; num_bad = 0; num_nl_open = 0; num_nl_clsd = 0; num_njw_open = 0; num_njw_clsd = 0; ymask = 0.0; for( i = -80; i < 81; i++ ) { for( j = -80; j < 81; j++ ) { xmask = 1.65 * (2*i + j); ymask = 1.65 * 1.732051 * j; /* sqrt(3) */ r = sqrt(xmask*xmask + ymask*ymask); if( r > 265.1 ) continue; numtests++; qmask = xmask / jmx_id->hexa_dim - ymask * bp->cot60; vmask = ymask * bp->rsin60; iq = qmask + 22501.5; iv = vmask + 22501.5; nn = (iq + 1133 * iv) % 22501; iq = iq - 22501; iv = iv - 22501; njw1 = 99+iq+iv; njw2 = 100+iv; njw1 = 199 - njw1; /* njw2 = 199 - njw2; */ njwhole = 0; if ((njw1 >= 0) && (njw1 < 200) && (njw2 >= 0) && (njw2 < 200)) { if (jmx_id->njwmask[njw1][njw2] == J_MASK_OPEN_CELL) { njwhole = 1; num_njw_open++; } else num_njw_clsd++; } else { sprintf(logger->tmptxt, "Index error for jemxmask: %3d %3d\n", njw1, njw2); logger->logstat = logprint(logger, logger->tmptxt, 2); return(-11); } if( maskhole[nn] == 1 ) num_nl_open++; else num_nl_clsd++; if ( maskhole[nn] == njwhole) num_ok++; else num_bad++; fprintf( stream, "%f %f %d %d\n", xmask, ymask, njwhole, maskhole[nn] ); } } RILlogMessage( NULL, Log_0, "##994## No change: num_ok: %d, num_bad: %d, " "numtests: %d", num_ok, num_bad, numtests ); RILlogMessage( NULL, Log_0, "##995## No change: num_njw_open: %d, num_njw_clsd: %d", num_njw_open, num_njw_clsd ); RILlogMessage( NULL, Log_0, "##996## No change: num_nl_open: %d, num_nl_clsd: %d", num_nl_open, num_nl_clsd ); fclose( stream ); return(0); } /*************************************************** Function to report on selected values from structures etc. 2005-02-07/NJW, updated 2005-04-13/NJW with GOODSRC, ictrl Part of j_ima_iros package ****************************************************/ int snapshot1( char *lognum, struct backpro *backproj, struct shadowgrams *sh, int chatter, int status ) { int i = 0; RILlogMessage( NULL, Log_0,"%s !snap1! chatter = %d, status = %d", lognum, chatter, status ); RILlogMessage( NULL, Log_0,"%s !snap1! backproj->skydim = %d", lognum, backproj->skydim ); RILlogMessage( NULL, Log_0,"%s !snap1! backproj->ee_basic = %d", lognum, backproj->ee_basic ); for( i = 0; i < backproj->ee_basic; i++ ) { RILlogMessage( NULL, Log_0,"%s !snap1! sh->eval[%d][0] = %f", lognum, i, sh->eval[i][0] ); RILlogMessage( NULL, Log_0,"%s !snap1! sh->eval[%d][1] = %f", lognum, i, sh->eval[i][1] ); } return( status ); } /*************************************************** Function to report on selected values from structures etc. 2005-12-01/NJW Part of j_ima_iros package ****************************************************/ int snapshot3( char *lognum, struct instr_data *jmx_id, int chatter, int status ) { if ( status != ISDC_OK ) return( status ); RILlogMessage( NULL, Log_0,"%s !snap3! chatter = %d", lognum, chatter ); RILlogMessage( NULL, Log_0,"%s !snap3! jmx_id->coll_pitch = %18.8e", lognum, jmx_id->coll_pitch ); RILlogMessage( NULL, Log_0,"%s !snap3! jmx_id->coll_h = %18.8e", lognum, jmx_id->coll_h ); RILlogMessage( NULL, Log_0,"%s !snap3! jmx_id->coll_w = %18.8e", lognum, jmx_id->coll_w ); RILlogMessage( NULL, Log_0,"%s !snap3! jmx_id->coll_r = %18.8e", lognum, jmx_id->coll_r ); RILlogMessage( NULL, Log_0,"%s !snap3! jmx_id->mask_r = %18.8e", lognum, jmx_id->mask_r ); RILlogMessage( NULL, Log_0,"%s !snap3! jmx_id->mask_height= %18.8e", lognum, jmx_id->mask_height); RILlogMessage( NULL, Log_0,"%s !snap3! jmx_id->hexa_dim = %18.8e", lognum, jmx_id->hexa_dim ); RILlogMessage( NULL, Log_0,"%s !snap3! jmx_id->struc_h2 = %18.8e", lognum, jmx_id->struc_h2 ); RILlogMessage( NULL, Log_0,"%s !snap3! jmx_id->struc_h1 = %18.8e", lognum, jmx_id->struc_h1 ); RILlogMessage( NULL, Log_0,"%s !snap3! jmx_id->alfa = %18.8e", lognum, jmx_id->alfa ); RILlogMessage( NULL, Log_0,"%s !snap3! jmx_id->beta = %18.8e", lognum, jmx_id->beta ); RILlogMessage( NULL, Log_0,"%s !snap3! jmx_id->gammav = %18.8e", lognum, jmx_id->gammav ); RILlogMessage( NULL, Log_0,"%s !snap3! jmx_id->xshi = %18.8e", lognum, jmx_id->xshi ); RILlogMessage( NULL, Log_0,"%s !snap3! jmx_id->yshi = %18.8e", lognum, jmx_id->yshi ); RILlogMessage( NULL, Log_0,"%s !snap3! jmx_id->c_tiltx = %18.8e", lognum, jmx_id->c_tiltx ); RILlogMessage( NULL, Log_0,"%s !snap3! jmx_id->c_tilty = %18.8e", lognum, jmx_id->c_tilty ); RILlogMessage( NULL, Log_0,"%s !snap3! jmx_id->coll_wb = %18.8e", lognum, jmx_id->coll_wb ); RILlogMessage( NULL, Log_0,"%s !snap3! jmx_id->coll_curv = %18.8e", lognum, jmx_id->coll_curv ); RILlogMessage( NULL, Log_0,"%s !snap3! jmx_id->scaleX = %18.8e", lognum, jmx_id->scaleX ); RILlogMessage( NULL, Log_0,"%s !snap3! jmx_id->scaleY = %18.8e", lognum, jmx_id->scaleY ); RILlogMessage( NULL, Log_0,"%s !snap3! jmx_id->phase2 = %18.8e", lognum, jmx_id->phase2 ); RILlogMessage( NULL, Log_0,"%s !snap3! jmx_id->x2xpix = %18.8e", lognum, jmx_id->x2xpix ); RILlogMessage( NULL, Log_0,"%s !snap3! jmx_id->y2ypix = %18.8e", lognum, jmx_id->y2ypix ); RILlogMessage( NULL, Log_0,"%s !snap3! jmx_id->offXpix = %18.8e", lognum, jmx_id->offXpix ); RILlogMessage( NULL, Log_0,"%s !snap3! jmx_id->offYpix = %18.8e", lognum, jmx_id->offYpix ); RILlogMessage( NULL, Log_0,"%s !snap3! jmx_id->offQrad = %18.8e", lognum, jmx_id->offQrad ); RILlogMessage( NULL, Log_0,"%s !snap3! jmx_id->offRrad = %18.8e", lognum, jmx_id->offRrad ); RILlogMessage( NULL, Log_0,"%s !snap3! jmx_id->mm2rad = %18.8e", lognum, jmx_id->mm2rad ); RILlogMessage( NULL, Log_0,"%s !snap3! jmx_id->x2xmm = %18.8e", lognum, jmx_id->x2xmm ); RILlogMessage( NULL, Log_0,"%s !snap3! jmx_id->y2ymm = %18.8e", lognum, jmx_id->y2ymm ); RILlogMessage( NULL, Log_0,"%s !snap3! jmx_id->offXmm = %18.8e", lognum, jmx_id->offXmm ); RILlogMessage( NULL, Log_0,"%s !snap3! jmx_id->offYmm = %18.8e", lognum, jmx_id->offYmm ); return( status ); } /***************************************************************** * Name of source file: j_iir_arcdist.c * Version of source file: 3.2.7 * Parent component: j_ima_iros * Programmer: Niels J. Westergaard * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325700 FAX: +45 35362475 * njw@spacecenter.dk * Purpose: Return the angular distance between two * points on the sphere * Origin date: 060907 * Update history: 1.5.12 060907 First version * 1.5.12 060907 SPR 04301 A relative VIGNDOL path is given * 2.1.0 070809 SCREWs 2021-2023 * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.2.0 071205 Flux determination has been improved * 2.2.1 071205 SPR 4742: Division by zero eliminated * 2.2.2 080111 Makes trigger rates from JEM-X HK available * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 3.2.7 100224 SPR 4915: Fixing logics for sparse shadowgrams * Type of element: Function * Part of package: j_ima_iros * Name: j_iir_arcdist *****************************************************************/ int j_iir_arcdist( float ra1, /* RA for point 1 */ float dec1, /* Declination for point 1 */ float ra2, /* RA for point 2 */ float dec2, /* Declination for point 2 */ float *arc, /* Resulting distance */ int status) /* Status flag */ { float arg = 0.0; if( status != ISDC_OK ) return( status ); arg = sin(dec1*GTORAD)*sin(dec2*GTORAD) + cos(dec1*GTORAD)*cos(dec2*GTORAD)*cos((ra2-ra1)*GTORAD); *arc = 0.0; if( arg < 1.0 ) *arc = acos(arg) / GTORAD; return( status ); } int shdg_to_fits( dal_element *theSWG, /* pointer to the SWG */ int eeuser, float shadowgram[], Instrument jemxNum, char elmntName[], char f_exttext[2][J_IIR_TEXTSIZE], struct fit_struc *f_struc1, struct log_con *logger, int ee3, struct shadowgrams *sh, int chatter, int status ) { int i, j, ij, ij_out; float shdg_fits[detdim]; /* char f_exttext[2][J_IIR_TEXTSIZE], */ f_struc1->emin = sh->eval[eeuser][0]; f_struc1->emax = sh->eval[eeuser][1]; ij_out = 0; for(i=0; i<256-logger->fits_shft; i++){ for (j=0; j<256; j++) { ij = i + j*256; shdg_fits[ij_out++] = shadowgram[ij]; } } status = outfit_isdc( theSWG, J_IIR_IS_SHD, jemxNum, elmntName, f_exttext, shdg_fits, f_struc1, logger, ee3, sh, chatter, status ); if (status != ISDC_OK) { RILlogMessage( NULL, Error_1,"##88## Error in outfit_isdc, status = %d", status); status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_ARRWRITEERR; } return(status); } /* ************************************************************************************ */ int paltani_eval(struct image_cor *ima_corr) { int i, j, k, m, sum, mask, pal_seq, pal_shf, im_seq, palx, paly, status=0; for (k=0; kima_cor[0][k][m] = 0.0; ima_corr->ima_cor[1][k][m] = 0.0; } } for (i=0; iima_seq[i][j]) >= 0) { pal_seq = im_seq / 8; pal_shf = im_seq % 8; mask = 1 << pal_shf; palx = ima_corr->ima_x[im_seq]; paly = ima_corr->ima_y[im_seq]; if ((palx != i) || (paly != j)) { printf( "paltani_eval: error in palx/paly: i: %3d, j: %3d, im_seq: %6d, palx: %3d, paly: %3d", i, j, im_seq, palx, paly); status = -1; goto getout; } for (k=1; k<255; k++) { for (m=1; m<255; m++) { sum = 0; if ((ima_corr->paltani[pal_seq][k ][m ] & mask) == 0) continue; ima_corr->ima_cor[0][palx][paly] += 1.0; /* count illuminated pixels */ if ((ima_corr->paltani[pal_seq][k-1][m-1] & mask) > 0) sum += 1; /* count corner neighbors */ if ((ima_corr->paltani[pal_seq][k-1][m+1] & mask) > 0) sum += 1; if ((ima_corr->paltani[pal_seq][k+1][m-1] & mask) > 0) sum += 1; if ((ima_corr->paltani[pal_seq][k+1][m+1] & mask) > 0) sum += 1; if ((ima_corr->paltani[pal_seq][k ][m-1] & mask) > 0) sum += 3; /* count side neighbors */ if ((ima_corr->paltani[pal_seq][k ][m+1] & mask) > 0) sum += 3; if ((ima_corr->paltani[pal_seq][k-1][m ] & mask) > 0) sum += 3; if ((ima_corr->paltani[pal_seq][k+1][m ] & mask) > 0) sum += 3; ima_corr->ima_cor[1][palx][paly] += (float)(sum) / 16.0; } } if (ima_corr->ima_cor[0][palx][paly] > 10.0) ima_corr->ima_cor[1][palx][paly] /= ima_corr->ima_cor[0][palx][paly]; else ima_corr->ima_cor[1][palx][paly] = -0.01; /* disregard regions with too small illumination */ } else ima_corr->ima_cor[1][i][j] = -0.01; /* intialized remaining pixels in prep. for interpolation */ } } getout: return(status); } /* ************************************************************************************ */ int paltani_count_init(struct image_cor *ima_corr) { int i, j, seq, rad2, status=0; seq = 0; for (i=0; iima_seq[i][j] = -1; if ((i%4) == 3) { if ((j%4) == 3) { rad2 = (i-255)*(i-255) + (j-255)*(j-255); if (rad2 <= 57400) { /* limit at 6.2 degrees */ ima_corr->ima_seq[i][j] = seq; ima_corr->ima_x[seq] = i; ima_corr->ima_y[seq] = j; seq++; if (seq >= 20000) { printf("In paltani_count_init, seq too large: %6d", seq); status = -1; goto getout; } } } } } } /* printf("paltani_count_init, final seq: %6d\n", seq); */ getout: return(status); } /* ************************************************************************************ */ /* ************************************************************************************ */ /* **************************************************************** * Name of source file: radcor.c * Version of source file: 4.0.12 * Programmer: Niels Lund * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325716 FAX: +45 35362475 * nl@dnsc.dk * Purpose: Correcting peak position from 'findpeak' for photon penetration dependences * Origin date: 071014 * Update history: 1.0.0 070302 First version * 2.1.0 070809 SCREWs 2021-2023 * 2.2.0 071014 improved fitting procedure * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.2.0 071205 Flux determination has been improved * 2.2.1 071205 SPR 4742: Division by zero eliminated * 2.2.2 080111 Makes trigger rates from JEM-X HK available * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 3.2.7 100224 SPR 4915: Fixing logics for sparse shadowgrams * 4.0.12 120919 SPR ?: Introduce corrections by LP and Co. * Type of element: Function * Part of package: j_ima_iros **************************************************************** */ int radcor(float x_pix, float y_pix, float abs_len, int jemx, float *x_out, float *y_out, struct instr_data *jmx_id, struct backpro *backproj, struct log_con *logger) /* ******************************************************************************** */ /* */ /* radcor calculates a correction to be applied to the coordinates returned by */ /* 'findpeak'. The correction shall compensate for the fact that 'findpeak' is */ /* operating on skyimages produced by the energy independent 'backpro' routine. */ /* The correction shall ensure correspondence between the 'pixel illumination */ /* functions' generated by 'detectmap' and the peak coordinates from 'backpro- */ /* findpeak'. Niels Lund. December 2006 */ /* Revised with improved fitting procedure October 2007 */ /* */ /* ******************************************************************************** */ { int i = 0, between, test=1, status; static int testcnt = -100; float xcent, ycent, radiusin, radiusout, shift, rshift, frac; float c0, c1, c2; static int func_local = -1, local_calling_num=0; clock_t clock(void), calling_TT, TT_now; /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "radcor"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 5); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ if (logger->trace) traces(func_local, 1, logger); xcent = x_pix - backproj->FOV_radius; ycent = y_pix - backproj->FOV_radius; radiusin = sqrt(xcent*xcent + ycent*ycent); /* printf("Completed radcor initialization, radiusin: %f\n", radiusin); */ if (abs_len <= jmx_id->RCabslen[0]) { c0 = jmx_id->RCcoeffs[0][0]; c1 = jmx_id->RCcoeffs[0][1]; c2 = jmx_id->RCcoeffs[0][2]; between = -1; goto ready; } if (abs_len >= jmx_id->RCabslen[8]) { c0 = jmx_id->RCcoeffs[8][0]; c1 = jmx_id->RCcoeffs[8][1]; c2 = jmx_id->RCcoeffs[8][2]; between = +1; goto ready; } for (i=0; i<8; i++) { if ((abs_len > jmx_id->RCabslen[i]) && (abs_len <= jmx_id->RCabslen[i+1])) { frac = (abs_len - jmx_id->RCabslen[i]) / (jmx_id->RCabslen[i+1] - jmx_id->RCabslen[i]); c0 = jmx_id->RCcoeffs[i+1][0] * frac + jmx_id->RCcoeffs[i][0] * (1.0 - frac); c1 = jmx_id->RCcoeffs[i+1][1] * frac + jmx_id->RCcoeffs[i][1] * (1.0 - frac); c2 = jmx_id->RCcoeffs[i+1][2] * frac + jmx_id->RCcoeffs[i][2] * (1.0 - frac); between = 0; goto ready; } } sprintf(logger->tmptxt, "radcor: Could not interpolate between data values"); logger->logstat = logprint(logger, logger->tmptxt, 5); status = -5; goto exittrace; ready: shift = c0 + c1 * radiusin + c2 *radiusin * radiusin; radiusout = radiusin + shift; rshift = radiusin / radiusout; /* minus */ *x_out = xcent * rshift + backproj->FOV_radius; *y_out = ycent * rshift + backproj->FOV_radius; if ((test) && (testcnt > 0)) { if (between == -1) { sprintf(logger->tmptxt, "'abs_len' below min table value !"); logger->logstat = logprint(logger, logger->tmptxt, 5); } if (between == +1) { sprintf(logger->tmptxt, "'abs_len' above max table value !"); logger->logstat = logprint(logger, logger->tmptxt, 5); } sprintf(logger->tmptxt, "index: %1d, abs_len: %6.2f, coeffs: %e %e %e, radiusin: %7.2f, shift: %5.2f, radiusout: %7.2f ", i, jmx_id->RCabslen[i], jmx_id->RCcoeffs[i][0], jmx_id->RCcoeffs[i][1], jmx_id->RCcoeffs[i][2], radiusin, shift, radiusout); logger->logstat = logprint(logger, logger->tmptxt, 5); if (between == 0) { sprintf(logger->tmptxt, "index: %1d, abs_len: %6.2f, coeffs: %e %e %e, radiusin: %7.2f, shift: %5.2f, radiusout: %7.2f ", i+1, jmx_id->RCabslen[i+1], jmx_id->RCcoeffs[i+1][0], jmx_id->RCcoeffs[i+1][1], jmx_id->RCcoeffs[i+1][2], radiusin, shift, radiusout); logger->logstat = logprint(logger, logger->tmptxt, 5); } sprintf(logger->tmptxt, "interpolated, abs_len: %6.2f, coeffs: %e %e %e, radiusin: %7.2f, shift: %5.2f, radiusout: %7.2f ", abs_len, c0, c1, c2, radiusin, shift, radiusout); logger->logstat = logprint(logger, logger->tmptxt, 5); testcnt--; } 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(0); exittrace: 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); } /* **************************************************************** * Name of source file: blankout.c * Version of source file: 3.2.7 * Programmer: Niels Lund * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325716 FAX: +45 35362475 * nl@dnsc.dk * Purpose: blank out 9x9 pixels in the sky image around specified point * Origin date: 070302 * Update history: 1.0.0 070302 First version * 2.1.0 070809 SCREWs 2021-2023 * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.2.0 071205 Flux determination has been improved * 2.2.1 071205 SPR 4742: Division by zero eliminated * 2.2.2 080111 Makes trigger rates from JEM-X HK available * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 3.2.7 100224 SPR 4915: Fixing logics for sparse shadowgrams * Type of element: Function * Part of package: j_ima_iros **************************************************************** */ int blankout(int blindnum, int blindspots[], float current_skyim[], struct backpro *backproj, struct log_con *logger) { int i, j, k, n, xvalstart, yvalstart; for (i=0; isky_ydim) - 4; yvalstart = (blindspots[i] % backproj->sky_ydim) - 4; for (j=0; j<9; j++) { for (k=0; k<9; k++) { n = (xvalstart + j) * backproj->sky_ydim + yvalstart + k; if ((n >= 0) && (n < backproj->skydim)) current_skyim[n] = 0.0; } } } return(0); } /* **************************************************** */ /************************************************************************** chk_radcor_params.c A member of the JEMX library 2007-11-21/NL ************************************************************************/ int chk_radcor_params( int jemx, /* 0 or 1 */ struct instr_data *jmx_id, struct log_con *logger) /* log control parameters */ { int i, j, status = 0; float RCabslen[9], RCcoeffs[9][3]; static int func_local = -1, local_calling_num=0; clock_t calling_TT, TT_now; if( status != ISDC_OK ) return( status ); /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "chk_radcor_params"); if (logger->func_used_num > J_IIR_MAX_NUM_FUNCS) { sprintf(logger->tmptxt, "func_used_num > %d", J_IIR_MAX_NUM_FUNCS); logger->logstat = logprint(logger, logger->tmptxt, 6); logger->func_used_num = J_IIR_MAX_NUM_FUNCS; } } 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); RCabslen[0] = 1.21; RCabslen[1] = 1.71; RCabslen[2] = 2.79; RCabslen[3] = 3.19; RCabslen[4] = 5.61; RCabslen[5] = 8.36; RCabslen[6] = 12.27; RCabslen[7] = 40.28; RCabslen[8] = 140.26; if (jemx == 0) { /**************************** JEM-X1 *********************************/ RCcoeffs[0][0] = 4.972788e-04; RCcoeffs[0][1] = -2.918953e-03; RCcoeffs[0][2] = -6.740669e-07; RCcoeffs[1][0] = 3.742374e-04; RCcoeffs[1][1] = -1.628204e-03; RCcoeffs[1][2] = -5.571775e-06; RCcoeffs[2][0] = 1.084288e-04; RCcoeffs[2][1] = 2.569084e-04; RCcoeffs[2][2] = -1.502362e-05; RCcoeffs[3][0] = -2.233527e-05; RCcoeffs[3][1] = 3.638332e-04; RCcoeffs[3][2] = -1.479299e-05; RCcoeffs[4][0] = -7.510725e-05; RCcoeffs[4][1] = 5.941416e-04; RCcoeffs[4][2] = -1.557492e-05; RCcoeffs[5][0] = -2.145983e-04; RCcoeffs[5][1] = 1.546343e-03; RCcoeffs[5][2] = -1.940279e-05; RCcoeffs[6][0] = -3.525795e-04; RCcoeffs[6][1] = 2.541330e-03; RCcoeffs[6][2] = -2.340116e-05; RCcoeffs[7][0] = -5.166134e-04; RCcoeffs[7][1] = 3.449489e-03; RCcoeffs[7][2] = -2.749584e-05; RCcoeffs[8][0] = -4.936565e-04; RCcoeffs[8][1] = 3.848434e-03; RCcoeffs[8][2] = -3.009891e-05; } else { /**************************** JEM-X2 ***************************************/ RCcoeffs[0][0] = -3.882304e-04; RCcoeffs[0][1] = -2.534531e-03; RCcoeffs[0][2] = -5.359455e-06; RCcoeffs[1][0] = -5.508711e-04; RCcoeffs[1][1] = -1.228138e-03; RCcoeffs[1][2] = -1.058899e-05; RCcoeffs[2][0] = -5.836030e-04; RCcoeffs[2][1] = 3.537585e-04; RCcoeffs[2][2] = -1.763657e-05; RCcoeffs[3][0] = -8.005117e-04; RCcoeffs[3][1] = 5.182366e-04; RCcoeffs[3][2] = -1.805717e-05; RCcoeffs[4][0] = -8.595651e-04; RCcoeffs[4][1] = 7.474988e-04; RCcoeffs[4][2] = -1.879913e-05; RCcoeffs[5][0] = -9.744854e-04; RCcoeffs[5][1] = 1.642081e-03; RCcoeffs[5][2] = -2.220506e-05; RCcoeffs[6][0] = -1.095397e-03; RCcoeffs[6][1] = 2.593331e-03; RCcoeffs[6][2] = -2.588369e-05; RCcoeffs[7][0] = -1.198769e-03; RCcoeffs[7][1] = 3.439622e-03; RCcoeffs[7][2] = -2.937418e-05; RCcoeffs[8][0] = -1.086318e-03; RCcoeffs[8][1] = 3.750430e-03; RCcoeffs[8][2] = -3.108117e-05; } for (i=0; i<9; i++) { for (j=0; j<3; j++) { if (RCcoeffs[i][j] == jmx_id->RCcoeffs[i][j]) continue; sprintf(logger->tmptxt, "parameter error in RCcoeffs[%1d][%1d], found: %11.6e, should be: %11.6e\n", i, j, jmx_id->RCcoeffs[i][j], RCcoeffs[i][j]); logger->logstat = logprint(logger, logger->tmptxt, logger->i5); status = -1; } if (RCabslen[i] == jmx_id->RCabslen[i]) continue; sprintf(logger->tmptxt, "parameter error in RCabslen[%1d], found: %6.2f , should be: %6.2f \n", i, jmx_id->RCabslen[i], RCabslen[i]); logger->logstat = logprint(logger, logger->tmptxt, logger->i5); status = -1; } 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 ); } /***************************************************************** * Name of source file: j_iir_write_srclres.c * Version of source file: 4.0.12 * Parent component: None * Programmer: Niels J. Westergaard & Niels Lund * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325705 FAX: +45 35362475 * njw@spacecenter.dk, nl@spacecenter.dk * Purpose: Write the JMXi-SRCL-RES data structure to disk * Origin date: 041122 * Update history: 1.1.1 050211 First version * 1.1.5 050415 New clean again, updated flux determination * 1.1.6 050418 Now uses JMXi-DBKG-MOD as default for empty field shds * 1.2.0 050425 Deals with SPR 4102,4108 and reduces RAM requirement * 1.3.0 050503 Deals with SPR 4120 and copes with up to 6 shadowgrams * 1.3.1 050517 Deals with SPR 4143 and initializes ima_sigma properly * 1.3.2 050519 Closes SPR 4157 - bad size of three arrays * 1.3.3 050602 Changes some arrays to static (SPR 4202) * 1.4.0 050620 Include user defined sources (SCREW 1740) * 1.5.1 051129 Separating functions to jmx_lib_pif * 1.5.2 051202 Separating functions to jmx_lib_pif (2) * 1.5.3 051202 Give offX, x2x values in mm in IMOD-GRP * 1.5.4 060104 Bug in sh_depth corrected, detectmap now in mm * 1.5.5 060106 Introduced one more digit in logfile for src position * 1.5.6 060228 Removed parameter detMapFile and some obsolete variables * 1.5.7 060606 Shifted detCondMap to struct jmx_id and status_map * 1.5.8 060807 SPR 04551 Bad assignment of RLIMIDX corrected * 1.5.9 060807 SPR 04533 Resetting status variable has been removed * 1.5.10 060807 SPR 04523 Declaring testsum as float iso. int * 1.5.11 060807 SPR 04458 A warning log line has been added * 1.5.12 060907 SPR 04301 A relative VIGNDOL path is given * 1.6.0 060911 SCREW 1918 Image correction map and parameters introduced * 1.6.1 060912 SPR 4441 Shadowgrams with too few counts are excluded * 1.6.2 060915 SCREW 1842 A significance map can now be obtained * 1.6.3 060915 An exposure (vignetting) map is now a product * 1.6.4 060928 Included test for zero divisor in peaktransfer.c * 1.6.5 061002 New defaults for par. skyImagesOut * 1.7.0 061110 Produces images with few or zero events (SPR 4594) * 1.7.1 061114 SPR 4603 Image unit (BUNIT) is now cts/dm2/s * 1.8.0 061213 SPR 4640 Error in findpeak has been corrected * 1.8.1 070123 SPR 4590 int changed to long for 64 bit code * 2.1.0 070730 Active use of input source catalog * 2.1.0 070809 SCREWs 2021-2023 * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed * 2.2.0 071205 Flux determination has been improved * 2.2.1 071205 SPR 4742: Division by zero eliminated * 2.2.2 080111 Makes trigger rates from JEM-X HK available * 2.2.2 081111 Makes trigger rates from JEM-X HK available * 3.0.0 081111 SCREW 2080+1918 Electronic eff. corrections * 3.0.1 090114 SCREW 2098+2102+2105 and SPR 4812 * 3.0.2 090121 New table of sigma(PSF) is read * 3.0.3 090324 SPR 4837 Floating point exceptions removed * 3.1.0 090401 SPR 4737,4846 floating exceptions and negative fluxes * 3.2.0 090422 SCREW 2135 Better time correction implemented * 3.2.1 090507 SPR 4863 Bug fix in interpolation algorithm * 3.2.2 090514 SPR 4866 Uninitialized variable problem * 3.2.3 090602 SPR 4875 Error in peak reintroduction * 3.2.4 090720 SPR 4886 Fix a divide by zero (BEO) * 3.2.6 091204 SCREW 2180/2181 Improve source finding/remove ghosts * 4.0.2 120321 SPR ?: Bug reported by JC, LP fixed * 4.0.4 120430 SPR ?: Still better flux error estimation * 4.0.5 120607 SPR ?: Still better flux error estimation * 4.0.7 120710 SPR ?: Flux error estimates as in version 3.2.7 * 4.0.12 120919 SPR ?: Introduce corrections by LP and Co. * Type of element: Function * Part of package: j_ima_iros * Name: j_iir_write_srclres * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ int j_iir_write_srclres( dal_element *theSWG, Instrument jemxNum, struct log_con *logger, goodsrc *GOODSRC, struct shadowgrams *sh, struct backpro *backproj, int chatter, int status ) { dal_element *srclresPtr = NULL; char srclresName[DS_NAME_SIZE]; int i = 0, eeuser=0, i5; int itmp[1]; long startRow = 0; long numValues = 0; long n_src = 0; float e_min[EE256]; float e_max[EE256]; float flux[EE256]; float flux_err[EE256]; float detsig = 0.0; float ftmp[1]; float cosx_jmx = 0.0; float cosy_jmx = 0.0; float cosz_jmx = 0.0; float arcmin_x = 0.0; float arcmin_y = 0.0; float detsig0 = 0.0; float detsig1 = 0.0; float detsig2 = 0.0; float check = 0.0; 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_srclres"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } 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, 1, logger); if( status != ISDC_OK ) goto exittrace; i5 = logger->i5; /* NL 20120122 */ /* * Prepare writing the energy limits */ for( n_src = 0; n_src < EE256; n_src++ ) { e_min[n_src] = 0.0; e_max[n_src] = 0.0; flux[n_src] = 0.0; flux_err[n_src] = 0.0; } sprintf(logger->tmptxt, "write_srclres: ee_max: %2d, N_SRC2: %2d", backproj->ee_max, logger->N_SRC2); logger->logstat = logprint(logger, logger->tmptxt, i5); for( n_src = 0; n_src < backproj->ee_max; n_src++ ) { e_min[n_src] = sh->eval[n_src][0]; e_max[n_src] = sh->eval[n_src][1]; } if( jemxNum == JMX1 ) { strcpy( srclresName, "JMX1-SRCL-RES" ); } else { strcpy( srclresName, "JMX2-SRCL-RES" ); } if( chatter > J_CHATTY_NORMAL ) { RILlogMessage( NULL, Log_0, "##374## Going to update: %s", srclresName ); } status = DALobjectFindElement( theSWG, srclresName, &srclresPtr, status ); if( status != ISDC_OK ) goto exittrace; if( logger->N_SRC2 == 0 ) { sprintf(logger->tmptxt, "##375## No sources found!"); logger->logstat = logprint(logger, logger->tmptxt, i5); RILlogMessage( NULL, Log_0, "##375## No sources found!"); goto exittrace; } /* * Add various keywords * * First copy from first shadowgram data structure */ if( sh->ptr[0] != NULL ) { status = DAL3GENattributeCopy( sh->ptr[0], srclresPtr, "TELAPSE,OBTSTART,OBTEND,REVOL,SWID,SWBOUND,SW_TYPE," "ONTIME,DEADC,EXPOSURE,TSTART,TSTOP", status ); if( status != ISDC_OK ) goto exittrace; } status = DALattributePutInt( srclresPtr, "EBIN_NUM", (long) sh->numShds, NULL, "Number of energy bins", status ); if( status != ISDC_OK ) goto exittrace; status = DALtableAddRows( srclresPtr, startRow, (long) logger->N_SRC2, status ); if( status != ISDC_OK ) goto exittrace; /* * LOOP over the found 'good' sources */ for( n_src = 0; n_src < logger->N_SRC2; n_src++ ) { startRow = n_src + 1; numValues = 1; ftmp[0] = GOODSRC[n_src].RA; status = DALtablePutColBins( srclresPtr, "RA_OBJ", 0, DAL_FLOAT, startRow, startRow, numValues, ftmp, status ); if( status != ISDC_OK ) goto exittrace; ftmp[0] = GOODSRC[n_src].dec; status = DALtablePutColBins( srclresPtr, "DEC_OBJ", 0, DAL_FLOAT, startRow, startRow, numValues, ftmp, status ); if( status != ISDC_OK ) goto exittrace; ftmp[0] = 2.1234 / 60.; /* Unit is degrees */ status = DALtablePutColBins( srclresPtr, "ERR_RAD", 0, DAL_FLOAT, startRow, startRow, numValues, ftmp, status ); if( status != ISDC_OK ) goto exittrace; itmp[0] = GOODSRC[n_src].preset; status = DALtablePutColBins( srclresPtr, "FLAG", 0, DAL_INT, startRow, startRow, numValues, itmp, status ); if( status != ISDC_OK ) goto exittrace; /* * modified data in cosx/y/z_jmx to facilitate alignment control * internal jemx-X position (in mm) is written into X_SRC * internal jemx-Y position (in mm) is written into Y_SRC * the deviation between the expected and the found source position * is written into DIFF_X and DIFF_Y resp. * following format: * cosx_jmx = (int)(diff_x * 1000.0 + 5000.0) * + (float)((int)(diff_y * 1000.0 + 5000.0)) / 10000.0; * (diff_x and diff_y are in mm) */ ftmp[0] = GOODSRC[n_src].xx - backproj->FOV_radius; status = DALtablePutColBins( srclresPtr, "X_SRC", 0, DAL_FLOAT, startRow, startRow, numValues, ftmp, status ); if( status != ISDC_OK ) goto exittrace; ftmp[0] = GOODSRC[n_src].yy - backproj->FOV_radius; status = DALtablePutColBins( srclresPtr, "Y_SRC", 0, DAL_FLOAT, startRow, startRow, numValues, ftmp, status ); if( status != ISDC_OK ) goto exittrace; ftmp[0] = GOODSRC[n_src].diff_x; status = DALtablePutColBins( srclresPtr, "DIFF_X", 0, DAL_FLOAT, startRow, startRow, numValues, ftmp, status ); if( status != ISDC_OK ) goto exittrace; ftmp[0] = GOODSRC[n_src].diff_y; status = DALtablePutColBins( srclresPtr, "DIFF_Y", 0, DAL_FLOAT, startRow, startRow, numValues, ftmp, status ); if( status != ISDC_OK ) goto exittrace; /* * Write approximate direction cosines to SRCL-RES */ arcmin_x = (GOODSRC[n_src].xx - backproj->FOV_radius) * (3.0/FOV_f); arcmin_y = (GOODSRC[n_src].yy - backproj->FOV_radius) * (3.0/FOV_f); cosy_jmx = (arcmin_x * 0.0174533) / 60.; /* Now in radians */ cosz_jmx = (arcmin_y * 0.0174533) / 60.; /* Now in radians */ cosx_jmx = sqrt(1. - cosy_jmx*cosy_jmx - cosz_jmx*cosz_jmx); ftmp[0] = cosx_jmx; status = DALtablePutColBins( srclresPtr, "COSX_JMX", 0, DAL_FLOAT, startRow, startRow, numValues, ftmp, status ); if( status != ISDC_OK ) goto exittrace; ftmp[0] = cosy_jmx; status = DALtablePutColBins( srclresPtr, "COSY_JMX", 0, DAL_FLOAT, startRow, startRow, numValues, ftmp, status ); if( status != ISDC_OK ) goto exittrace; ftmp[0] = cosz_jmx; status = DALtablePutColBins( srclresPtr, "COSZ_JMX", 0, DAL_FLOAT, startRow, startRow, numValues, ftmp, status ); if( status != ISDC_OK ) goto exittrace; /* * Write catalog source position to SRCL-RES */ ftmp[0] = GOODSRC[n_src].catRA; status = DALtablePutColBins( srclresPtr, "RA_CAT", 0, DAL_FLOAT, startRow, startRow, numValues, ftmp, status ); if( status != ISDC_OK ) goto exittrace; ftmp[0] = GOODSRC[n_src].catdec; status = DALtablePutColBins( srclresPtr, "DEC_CAT", 0, DAL_FLOAT, startRow, startRow, numValues, ftmp, status ); if( status != ISDC_OK ) goto exittrace; if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##376## After ERR_RAD, status = %d", status ); goto exittrace; } if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##377## Source # %ld," " RA dec err_rad written", n_src); } /* * Write the energy channel boundaries to SRCL-RES */ numValues = 256; status = DALtablePutColBins( srclresPtr, "E_MIN", 0, DAL_FLOAT, startRow, startRow, numValues, e_min, status ); if( status != ISDC_OK ) goto exittrace; status = DALtablePutColBins( srclresPtr, "E_MAX", 0, DAL_FLOAT, startRow, startRow, numValues, e_max, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##378## After E_MAX, status = %d", status ); goto exittrace; } if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##379## Source # %ld," " E_min e_max written", n_src); } /* * Prepare writing the flux and detection significance */ /* Loop over shadowgrams i.e. over the energy bins to assign fluxes etc. */ RILlogMessage( NULL, Log_0,"##7324## backproj->backmodels = %d", backproj->backmodels ); check = 1.0; detsig0 = detsig1 = detsig2 = 0.0; for( eeuser = 0; eeuser < sh->numShds; eeuser++ ) { flux[eeuser] = GOODSRC[n_src].flux[eeuser]; flux_err[eeuser] = GOODSRC[n_src].flux_err[eeuser]; if (fabs(flux[eeuser] > 0.001)) check = flux_err[eeuser]; else flux_err[eeuser] = check; /* Change normalization counts/dm2 -> counts / cm2. Decided on SDAST 44 20120529 */ flux[eeuser] *= 0.01; flux_err[eeuser] *= 0.01; sprintf(logger->tmptxt, "write_srclres, src: %2ld, Ebin: %2d, flux: %8.5f, flux_err: %6.5f, detsig[E]: %5.1f, errsolut: %6.3f, flux_err_last: %6.3f", n_src, eeuser, flux[eeuser], flux_err[eeuser], GOODSRC[n_src].sn[eeuser], GOODSRC[n_src].flux_err[eeuser], check); logger->logstat = logprint(logger, logger->tmptxt, i5); if ((eeuser == 0) && (flux_err[eeuser] > 0.0)) detsig0 = flux[0] / flux_err[0]; if ((eeuser == 1) && (sh->numShds > 1) && (flux_err[eeuser] > 0.0) && (backproj->ee_basic > 1)) detsig1 = flux[1] / flux_err[1]; if ((eeuser == 2) && (sh->numShds > 2) && (flux_err[eeuser] > 0.0) && (backproj->ee_basic > 2)) detsig2 = flux[2] / flux_err[2]; } status = DALtablePutColBins( srclresPtr, "FLUX", 0, DAL_FLOAT, startRow, startRow, numValues, flux, status ); if( status != ISDC_OK ) goto exittrace; status = DALtablePutColBins( srclresPtr, "FLUX_ERR", 0, DAL_FLOAT, startRow, startRow, numValues, flux_err, status ); if( status != ISDC_OK ) goto exittrace; detsig = sqrt(detsig0*detsig0 + detsig1*detsig1 + detsig2*detsig2); ftmp[0] = detsig; numValues = 1; status = DALtablePutColBins( srclresPtr, "DETSIG", 0, DAL_FLOAT, startRow, startRow, numValues, ftmp, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##380## After DETSIG, status = %d", status ); goto exittrace; } if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##381## Source # %3ld," " Flux flux_err detsig written", n_src); } } status = CommonStampObject( srclresPtr, NULL, status ); exittrace: if ((status < 0) && (logger->trace)) traces(func_local, 10000000-status, logger); 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 ); } /* **************************************************************** * Name of source file: summary_p.c * Version of source file: 4.0.12 * Parent component: None * Programmer: Niels Lund * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325716 FAX: +45 35362475 * nl@dnsc.dk * Purpose: print summary of source found and fit coefficients * Origin date: 20100120 * Update history: 1.0.0 20100120 First version * 4.0.4 120430 SPR ?: Still better flux error estimation * 4.0.5 120607 SPR ?: Still better flux error estimation * 4.0.10 120830 SPR ?: Initialize variables as suggested by valgrind * 4.0.12 120919 SPR ?: Introduce corrections by LP and Co. * Type of element: Function * Part of package: j_ima_iros * Name: summary_p * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ /* QQQQQQ */ int summary_p( int n_common2, int n_additional, double solut_e[EE256][SCW_SRCMAX], struct instr_data *jmx_id, struct backpro *backproj, struct shadowgrams *sh, struct scwlist *SCWnow, goodsrc *GOODSRC, struct log_con *logger, int chatter, int status ) { int jsrc, n_src, eelim, jb, iee, i5; int i, j, k; float val=0.0, diff_x, diff_y; float p50[7], p100[7]; double cmx, cmy, avr; 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], "summary_p"); 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 */ /* 111111 */ /* QQQQQQ */ if (logger->trace) traces(func_local, 0, logger); i5 = logger->i5; status = ISDC_OK; /* QQQQQ */ sprintf(logger->tmptxt, " "); sprintf(logger->tmptxt2, " "); /* ******************************************************************* */ /* */ /* Print summary results from one science window */ /* (only corresponding to basic energies and basic source set) */ /* */ /* */ /* ******************************************************************* */ sprintf(logger->tmptxt, " Orbit: %3d, PID(scw): %3d %d, JEM-X%1d, No of sources: %1d, Integr. time: %6.1lf s, ", backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv, jmx_id->jmx_unit+1, n_common2, sh->accumT); sprintf(logger->tmptxt2, "Pointg: RA/dec/R: %8.4f %+8.4f %6.2f, JMX: %8.4f %8.4f", SCWnow->pointing_RA, SCWnow->pointing_dec, SCWnow->roll_angle, SCWnow->jmxRA, SCWnow->jmxdec); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); logger->logstat = logprint(logger, logger->tmptxt, 2); sprintf(logger->tmptxt, "##107## stopcodes: %1x%1x%1x Shadowgram counts: ", backproj->stopcode[0], backproj->stopcode[1], backproj->stopcode[2]); for (iee=0; ieeee_basic; iee++) { sprintf(logger->tmptxt2, "%6.1f ", sh->totcnt[iee]); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } logger->logstat = logprint(logger, logger->tmptxt, 2); if (logger->pix_fold_ctrl == 1) sprintf(logger->tmptxt, "##108## Pixelfold Shadowgram counts/s: "); else sprintf(logger->tmptxt, "##108## No pixelfold Shadowgram counts/s: "); for (iee=0; ieeee_basic; iee++) { sprintf(logger->tmptxt2, "%6.2f ", sh->totcnt[iee] / sh->accumT); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } logger->logstat = logprint(logger, logger->tmptxt, 2); sprintf(logger->tmptxt, "##109## Flat background (cts/s): "); for (iee=0; ieeee_basic; iee++) { sprintf(logger->tmptxt2, "%6.2f ", (float)(solut_e[iee][0] / sh->accumT)); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } logger->logstat = logprint(logger, logger->tmptxt, 2); sprintf(logger->tmptxt, "develop: %5d, 'Empty field' bckgr: (cts/s): ", logger->develop); for (iee=0; ieeee_basic; iee++) { sprintf(logger->tmptxt2, "%6.2f ", (float)(solut_e[iee][1] / sh->accumT)); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } logger->logstat = logprint(logger, logger->tmptxt, 2); eelim = sh->numShds; if (eelim > 19) eelim = 19; jb = backproj->backmodels; /* ******************************************************************* */ /* NOW MAKE LOOP OVER DETECTED SOURCES FOR PRINTOUT */ /* ******************************************************************* */ for (jsrc=0; jsrcFOV_radius; cmy = GOODSRC[n_src].yy - backproj->FOV_radius; avr = sqrt(cmx*cmx + cmy*cmy); sprintf(logger->tmptxt, "x/y/r: %7.2f %7.2f %5.1f, srcfit:(cts/s): ", cmx, cmy, avr); for (iee=0; ieetmptxt2, "%6.2f ", (float)(solut_e[iee][jb+jsrc] / sh->accumT)); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } logger->logstat = logprint(logger, logger->tmptxt, 2); if (n_additional == -1) { sprintf(logger->tmptxt, " extra srcfit (cts/s): "); for (iee=0; ieetmptxt2, "%6.2f ", (float)(solut_e[iee][jb+jsrc+n_common2] / sh->accumT)); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } logger->logstat = logprint(logger, logger->tmptxt, 2); } sprintf(logger->tmptxt, "##111## Effective Flux Collection Area (cm2): "); for (iee=0; ieetmptxt2, "%6.2f ", GOODSRC[n_src].src_pixel_area[iee]); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } logger->logstat = logprint(logger, logger->tmptxt, 2); if (n_additional == -1) { sprintf(logger->tmptxt, "##111x# Eff.extra Flux Collection Area (cm2): "); for (iee=0; ieetmptxt2, "%6.2f ", GOODSRC[n_src+n_common2].src_pixel_area[iee]); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } logger->logstat = logprint(logger, logger->tmptxt, 2); } if (n_additional == -2) { sprintf(logger->tmptxt, "##111a# Scatter Flux Production Area (cm2): "); for (iee=0; ieetmptxt2, "%6.2f ", GOODSRC[n_src+n_common2].src_pixel_area[iee]); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } logger->logstat = logprint(logger, logger->tmptxt, 2); } if ((GOODSRC[n_src].preset & 3) > 0) sprintf(logger->tmptxt, "prset RA/dec: %8.4f %8.4f flux cts/dm2s: ", GOODSRC[n_src].RA, GOODSRC[n_src].dec); else { if ((GOODSRC[n_src].preset & 64) == 64) sprintf(logger->tmptxt, " cat RA/dec: %8.4f %8.4f flux cts/dm2s: ", GOODSRC[n_src].RA, GOODSRC[n_src].dec); else sprintf(logger->tmptxt, " RA/dec: %8.4f %8.4f flux cts/dm2s: ", GOODSRC[n_src].RA, GOODSRC[n_src].dec); } for (iee=0; ieetmptxt2, "%6.2f ", GOODSRC[n_src].flux[iee]); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } logger->logstat = logprint(logger, logger->tmptxt, 2); sprintf(logger->tmptxt, " Flux Error (from 'errorfit'):"); for (iee=0; ieetmptxt2, " %6.2f", GOODSRC[n_src].errsolut[iee]); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } logger->logstat = logprint(logger, logger->tmptxt, 2); sprintf(logger->tmptxt, "Detects: %03x %03x Detsig value: ", GOODSRC[n_src].detects, backproj->s_detect[GOODSRC[n_src].src_id]); for (iee=0; iee<3; iee++) { if (GOODSRC[n_src].errsolut[iee] > 0.0) { sprintf(logger->tmptxt2, " %6.2f", GOODSRC[n_src].flux[iee] / GOODSRC[n_src].errsolut[iee]); } else { sprintf(logger->tmptxt2, " ----- "); } if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } logger->logstat = logprint(logger, logger->tmptxt, 2); sprintf(logger->tmptxt, " Fractional Resid. Peak: "); for (iee=0; ieeee_basic; iee++) { if (backproj->orig_data_peak[iee][jsrc] != 0.0) val = backproj->resid_data_peak[iee][jsrc] / backproj->orig_data_peak[iee][jsrc]; else val = -9.99; sprintf(logger->tmptxt2, "%6.2f ", val); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } logger->logstat = logprint(logger, logger->tmptxt, 2); if (GOODSRC[n_src].src_id > 0) { diff_x = GOODSRC[n_src].diff_x; diff_y = GOODSRC[n_src].diff_y; } else { diff_x = 0; diff_y = 0; } if (logger->detImagesOut) { sprintf(logger->tmptxt, "srcDev: X/Y: %4d %4d, id:%4d, FrSkyFluxErr: ", (int)(diff_x*1000.0 + 5000.0), (int)(diff_y*1000.0 + 5000.0), GOODSRC[n_src].src_id); for (iee=0; ieeee_basic; iee++) { val = 9.99; if ((GOODSRC[n_src].flux[iee] != 0.0) && (GOODSRC[n_src].flux_err[iee] != 9.99)) val = 1.0 + GOODSRC[n_src].flux_err[iee] / GOODSRC[n_src].flux[iee]; sprintf(logger->tmptxt2, " %6.3f", val); /* if (n_additional == -1) { sprintf(logger->tmptxt, " extra contribution (cts/dm2s): "); for (iee=0; ieetmptxt2, "%6.2f ", GOODSRC[n_src+n_common2].flux[iee]); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } logger->logstat = logprint(logger, logger->tmptxt, 2); } */ /* * if (GOODSRC[n_src].sn[iee] != 0.0) { * sprintf(logger->tmptxt2, " %6.3f", (1.0+1.0/GOODSRC[n_src].sn[iee])); * } else { * sprintf(logger->tmptxt2, " %6.3f", 9.99); * } */ if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } /* for (iee=0; ieeee_basic; iee++) { if (GOODSRC[n_src].sn2[iee] != 0.0) { sprintf(logger->tmptxt2, " %6.3f", (1.0+1.0/GOODSRC[n_src].sn2[iee])); } else { sprintf(logger->tmptxt2, " %6.3f", 9.99); } if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } */ sprintf(logger->tmptxt2, " 'develop' ctrl param: %4d", logger->develop); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); logger->logstat = logprint(logger, logger->tmptxt, 2); } } sprintf(logger->tmptxt, "\n"); logger->logstat = logprint(logger, logger->tmptxt, 2); /* QQQQQQ */ status = ISDC_OK; slut: ; if (logger->trace) traces(func_local, 100000+logger->N_SRC2, logger); 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 ); exittrace: /* exittrace */ if (logger->trace) traces(func_local, 1000-status, logger); goto slut; } /***************************************************************** * Name of source file: initTslice.c * Version of source file: 1.0.0 * Parent component: None * Programmer: Niels Lund * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325716 FAX: +45 35362475 * nl@dnsc.dk * Purpose: initialize one member of the Tslices structure * Origin date: 20100226 * Update history: 1.0.0 20100226 First version * Type of element: Function * Part of package: j_ima_iros * Name: initTslice * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ /* QQQQQQ */ int initTslice( timeslices Tslice, struct log_con *logger, int status ) { int i, i5; 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], "initTslice"); 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); i5 = logger->i5; /* BEGIN */ Tslice.Tstart = 0.0; Tslice.Tstop = 0.0; Tslice.avGain = 22.0; Tslice.avCorf = 0.0; Tslice.onTime = 0.0; Tslice.exposure = 0.0; Tslice.telapse = 0.0; Tslice.deadc = 0.0; Tslice.Nevents = 0; Tslice.gainclass = 0; for (i=0; itrace) 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 ); exittrace: /* exittrace */ if (logger->trace) traces(func_local, 1000-status, logger); goto slut; } /* * **************************************************************** * COMMENT ONLY ! typedef struct { * stucture containing information about one time bin double Tstart; double Tstop; float avGain; float avCorf; float onTime; float exposure; float telapse; float deadc; int Nevents; int gainclass; float flux[EE256]; float fErr[EE256]; } timeslices; */ /* **************************************************************************************** */ void traces(int subnum, int tracenum, struct log_con *logger) { char name[25], spaces[25], hexchar; int i=0, j=0, len=0; long Li; static int depth=0, first=3; FILE *trace; len = strlen(logger->func_names[subnum]); if (len > 20) len = 20; j = 0; for (i=0; ifunc_names[subnum][i]; for (i=len; i<20;i++) name[i] = ' '; name[20] = 0; if (tracenum <= 1) depth++; if (depth > 15) depth = 15; j = 0; for (i=0; ifunc_calling_num, subnum, name, spaces, logger->develop); fclose(trace); if (tracenum == 99) depth--; if (depth < 0 ) depth = 0; return; } /* *********************************************************************************** */ double rms_sky(float sky[], int ee, struct backpro *backproj, struct log_con *logger) { int skypix; double m0, m1, m2, rms, var; 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], "rms_sky"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ if (logger->trace) traces(func_local, 1, logger); m0 = m1 = m2 = 0.0; for (skypix=0; skypixskydim; skypix++) { if (backproj->access[skypix] > 0) { m0 += 1.0; m1 += sky[skypix]; m2 += sky[skypix] * sky[skypix]; } } rms = 0.0; /* test for zero value introduced 2006-09-20/NJW as a reaction to Silvia Martinez trouble */ if( m0 > 0.0 ) { m1 /= m0; m2 /= m0; var = m2 - m1 * m1; if (var > 0.0) rms = sqrt(var); } else RILlogMessage( NULL, Warning_0,"##361## m0 == 0.0!" ); 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(rms); } void getKarakter(int kk, int karakter[7][5]) { int i, j; int kar_0[7][5] = {{0,1,1,1,0}, {1,0,0,0,1}, {1,0,0,0,1}, {1,0,0,0,1}, {1,0,0,0,1}, {1,0,0,0,1}, {0,1,1,1,0}}; int kar_1[7][5] = {{0,0,1,0,0}, {0,1,1,0,0}, {0,0,1,0,0}, {0,0,1,0,0}, {0,0,1,0,0}, {0,0,1,0,0}, {0,1,1,1,0}}; int kar_2[7][5] = {{0,1,1,1,0}, {1,0,0,0,1}, {0,0,0,0,1}, {0,0,0,1,0}, {0,0,1,0,0}, {0,1,0,0,0}, {1,1,1,1,1}}; int kar_3[7][5] = {{0,1,1,1,1}, {1,0,0,1,0}, {0,0,1,0,0}, {0,1,1,0,0}, {0,0,0,1,0}, {0,0,0,0,1}, {1,1,1,1,0}}; int kar_4[7][5] = {{0,0,1,0,1}, {0,1,0,0,1}, {1,1,1,1,1}, {0,0,0,0,1}, {0,0,0,0,1}, {0,0,0,0,1}, {0,0,0,0,1}}; int kar_5[7][5] = {{0,1,1,1,1}, {0,1,0,0,0}, {0,0,1,0,0}, {0,0,0,1,0}, {0,0,0,0,1}, {0,0,0,0,1}, {0,1,1,1,0}}; int kar_6[7][5] = {{0,0,1,1,1}, {0,1,0,0,0}, {1,0,0,0,0}, {1,1,1,1,0}, {1,0,0,0,1}, {1,0,0,0,1}, {0,1,1,1,0}}; int kar_7[7][5] = {{0,1,1,1,1}, {0,0,0,0,1}, {0,0,0,1,0}, {0,0,1,0,0}, {0,1,0,0,0}, {1,0,0,0,0}, {1,0,0,0,0}}; int kar_8[7][5] = {{0,1,1,1,0}, {1,0,0,0,1}, {0,1,1,1,0}, {1,0,0,0,1}, {1,0,0,0,1}, {1,0,0,0,1}, {0,1,1,1,0}}; int kar_9[7][5] = {{0,1,1,1,0}, {1,0,0,0,1}, {1,0,0,0,1}, {0,1,1,1,1}, {0,0,0,0,1}, {0,0,0,0,1}, {0,1,1,1,0}}; int kar_q[7][5] = {{0,1,1,1,0}, {1,0,0,0,1}, {0,0,0,1,0}, {0,0,1,0,0}, {0,0,1,0,0}, {0,0,0,0,0}, {0,0,1,0,0}}; int kar_e[7][5] = {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}}; switch (kk) { case 48+0: for (i=0; i<7; i++) for (j=0; j<5; j++) karakter[i][j] = kar_0[i][j]; break; case 48+1: for (i=0; i<7; i++) for (j=0; j<5; j++) karakter[i][j] = kar_1[i][j]; break; case 48+2: for (i=0; i<7; i++) for (j=0; j<5; j++) karakter[i][j] = kar_2[i][j]; break; case 48+3: for (i=0; i<7; i++) for (j=0; j<5; j++) karakter[i][j] = kar_3[i][j]; break; case 48+4: for (i=0; i<7; i++) for (j=0; j<5; j++) karakter[i][j] = kar_4[i][j]; break; case 48+5: for (i=0; i<7; i++) for (j=0; j<5; j++) karakter[i][j] = kar_5[i][j]; break; case 48+6: for (i=0; i<7; i++) for (j=0; j<5; j++) karakter[i][j] = kar_6[i][j]; break; case 48+7: for (i=0; i<7; i++) for (j=0; j<5; j++) karakter[i][j] = kar_7[i][j]; break; case 48+8: for (i=0; i<7; i++) for (j=0; j<5; j++) karakter[i][j] = kar_8[i][j]; break; case 48+9: for (i=0; i<7; i++) for (j=0; j<5; j++) karakter[i][j] = kar_9[i][j]; break; case 32: for (i=0; i<7; i++) for (j=0; j<5; j++) karakter[i][j] = 0; break; default: for (i=0; i<7; i++) for (j=0; j<5; j++) karakter[i][j] = kar_q[i][j]; break; } return; } /* * **************************************************************** * COMMENT ONLY ! typedef struct { * stucture containing information about one time bin double Tstart; double Tstop; float avGain; float avCorf; float onTime; float exposure; float telapse; float deadc; int Nevents; int gainclass; float flux[EE256]; float fErr[EE256]; } timeslices; */ /***************************************************************** * Name of source file: electronic_eff.c * Version of source file: 1.0.0 * Parent component: j_ima_iros * Programmer: Niels Lund * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325700 FAX: +45 35362475 * njw@spacecenter.dk, nl@spacecenter.dk * Purpose: Read the shadowgrams from a science window * Origin date: 071122 * Update history: 1.0.0 071122 First version 2009 04 29 Corrected initialization value for 'Epar' in line 80 - and limit logic in line 86 ff * Type of element: Executable * Part of package: j_ima_iros * Name: electronic_eff.c * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ int electronic_eff( int shdg_num, int orbitnum, struct shadowgrams *sh, /* All shadowgram information */ userbin *USERBIN, /* shadowgram structure */ struct instr_data *jmx_id, struct log_con *logger) /* log control parameters */ { int i, j, k, ix, iy, ixy, eff_distr[10], Epar, jemx, i5; int status = 0, eeuser; float SLOW_min, SLOW_mean, SLOW_max; float eff_min, eff_mean, eff_max; float eff_min99, eff_mean99, eff_max99; float eff_sum, eff_sum99; float eff_bot, eff_top, effic[2]; float slope1, slope2, Emean, time_slope_val, tim_correction; float initval1, initval2, fraction, eeff_initial_val; static int func_local = -1, local_calling_num=0, first=1; clock_t calling_TT, TT_now; /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; logger->func_calling_num = 0; sprintf(logger->func_names[func_local], "electronic_eff"); if (logger->func_used_num > J_IIR_MAX_NUM_FUNCS) { sprintf(logger->tmptxt, "func_used_num > %d", J_IIR_MAX_NUM_FUNCS); logger->logstat = logprint(logger, logger->tmptxt, 6); logger->func_used_num = J_IIR_MAX_NUM_FUNCS; } } 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); i5 = logger->i5; i5 = 0; jemx = jmx_id->jmx_unit; eeuser = shdg_num; /* for (i=0; ieeff_time_slope[i]; */ if (logger->trace) traces(func_local, 10000 + (int)(jmx_id->eeff_time_origin), logger); if (first) { sprintf(logger->tmptxt, "eeff_time_origin: %f, number of slope channels: %3d", jmx_id->eeff_time_origin, XYvsE_Evals); logger->logstat = logprint(logger, logger->tmptxt, i5); for (i=0; itmptxt, "Elow/high: %f %f, eeff_time_slope: %f, eeff_value_origin: %f", jmx_id->Elist[i], jmx_id->Elist[i+1], jmx_id->eeff_time_slope[i], jmx_id->eeff_value_origin[i]); logger->logstat = logprint(logger, logger->tmptxt, i5); } first = 0; if (logger->trace) traces(func_local, 20000 + (int)(jmx_id->eeff_time_origin), logger); } Epar = XYvsE_Evals - 1; /* changed from 'Epar = 8'. Niels Lund 2009-04-29 */ Emean = (USERBIN[eeuser].E_min + USERBIN[eeuser].E_max) / 2.0; for (i=0; i= jmx_id->Elist[i]) && (Emean < jmx_id->Elist[i+1])) Epar = i; if (Epar < 0 ) Epar = 0; if (Epar > XYvsE_Evals-2) Epar = XYvsE_Evals-2; slope1 = jmx_id->eeff_time_slope[Epar]; /* logic changed to improve performance outside normal E-range. Niels Lund. 2009-05-06 */ initval1 = jmx_id->eeff_value_origin[Epar]; slope2 = jmx_id->eeff_time_slope[Epar+1]; initval2 = jmx_id->eeff_value_origin[Epar+1]; fraction = (Emean - (jmx_id->Elist[Epar] + jmx_id->Elist[Epar+1]) / 2.0) / (jmx_id->Elist[Epar+1] - jmx_id->Elist[Epar]); if ((fraction >= -0.5) && (fraction <= 0.5)) { time_slope_val = slope1 + (slope2 - slope1) * fraction; eeff_initial_val = initval1 + (initval2 - initval1) * fraction; } else { if (fraction < -0.5) { time_slope_val = 1.5 * slope1 - 0.5 * slope2; eeff_initial_val = 1.5 * initval1 - 0.5 * initval2; } else { time_slope_val = 1.5 * slope2 - 0.5 * slope1; eeff_initial_val = 1.5 * initval2 - 0.5 * initval1; } } tim_correction = eeff_initial_val + time_slope_val * (orbitnum - jmx_id->eeff_time_origin); if ((logger->develop & 8192) == 8192) tim_correction = 1.0; sprintf(logger->tmptxt, "ee%02d, slp1: %9.6f, slp2: %9.6f, Eav: %4.1fi, E1/2: %4.1f %4.1f, tim_cor: %5.3f, slope: %9.6f, orbs: %3d %3.0f, initval: %5.3f", shdg_num, slope1, slope2, USERBIN[eeuser].E_mean, jmx_id->Elist[Epar+1], jmx_id->Elist[Epar], tim_correction, time_slope_val, orbitnum, jmx_id->eeff_time_origin, eeff_initial_val); logger->logstat = logprint(logger, logger->tmptxt, i5); eff_bot = 1.0; eff_top = 0.0; for (i=0; i<10;i++) eff_distr[i] = 0.0; j = 0; eff_sum = eff_sum99 = 0.0; for (ix=0; ix<256; ix++) { for (iy=0; iy<256; iy++) { ixy = 256*ix + iy; USERBIN[eeuser].effic_shdg[ixy] = 1.00; /* initialization */ if (jmx_id->spagj[ixy] < 0.0) { j++; USERBIN[eeuser].effic_shdg[ixy] = 0.00; continue; } SLOW_min = USERBIN[eeuser].E_min * sh->avg_gain * (1.0 + jmx_id->curtain[ix]) * jmx_id->spagj[ixy]; SLOW_mean = USERBIN[eeuser].E_mean * sh->avg_gain * (1.0 + jmx_id->curtain[ix]) * jmx_id->spagj[ixy]; SLOW_max = USERBIN[eeuser].E_max * sh->avg_gain * (1.0 + jmx_id->curtain[ix]) * jmx_id->spagj[ixy]; status = get_effic(SLOW_min, jmx_id, effic, status); eff_min = effic[0]; eff_min99 = effic[1]; status = get_effic(SLOW_mean, jmx_id, effic, status); eff_mean = effic[0]; eff_mean99 = effic[1]; status = get_effic(SLOW_max, jmx_id, effic, status); eff_max = effic[0]; eff_max99 = effic[1]; USERBIN[eeuser].effic_shdg[ixy] = 0.25 * (eff_min + eff_max + eff_mean + eff_mean) * tim_correction; eff_sum += USERBIN[eeuser].effic_shdg[ixy]; eff_sum99 += 0.25 * (eff_min99 + eff_max99 + eff_mean99 + eff_mean99) * tim_correction; if (eff_bot > USERBIN[eeuser].effic_shdg[ixy]) eff_bot = USERBIN[eeuser].effic_shdg[ixy]; if (eff_top < USERBIN[eeuser].effic_shdg[ixy]) eff_top = USERBIN[eeuser].effic_shdg[ixy]; } } USERBIN[eeuser].eff_slope = 1.0; if (eff_sum99 > 0.0) USERBIN[eeuser].eff_slope = (eff_sum - eff_sum99) * 100.0 / eff_sum99; sprintf(logger->tmptxt, "orbit: %3d, ee%02d avg_gain: %5.2f, E: %5.2f %5.2f %5.2f", orbitnum, shdg_num, sh->avg_gain, USERBIN[eeuser].E_min, USERBIN[eeuser].E_mean, USERBIN[eeuser].E_max); logger->logstat = logprint(logger, logger->tmptxt, i5); for (ixy=0; ixyspagj[ixy] < 0.0) continue; eff_mean = USERBIN[eeuser].effic_shdg[ixy]; j = (int)((eff_mean + 1.0e-6) * 9.99 / (eff_top + 1.0e-6)); eff_distr[j]++; } sprintf(logger->tmptxt, "EEFF: min: "); if (eeuser == 0) logger->logstat = logprint(logger, logger->tmptxt, i5); k = 0; sprintf(logger->tmptxt, "EEFF: min: %5.3f, max: %5.3f, distr: ", eff_bot, eff_top); for (i=0; i<10; i++) { k += eff_distr[i]; sprintf(logger->tmptxt2," %5d", eff_distr[i]); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } sprintf(logger->tmptxt2," sum: %5d", k); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); logger->logstat = logprint(logger, logger->tmptxt, i5); if (logger->trace) traces(func_local, 30000 + (int)(jmx_id->eeff_time_origin), logger); status = ISDC_OK; 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(0); } /***************************************************************** * Name of source file: j_iir_get_radec_init.c * Version of source file: 1.6.0 * Parent component: None * Programmer: Niels J. Westergaard & Niels Lund * Affiliation: National Space Institute/Technical University of Denmark * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325700 FAX: +45 35362475 * njw@spacecenter.dk, nl@spacecenter.dk * Purpose: Get INTEGRAL attitude either from OSIM-PDEF * or from DAL3AUXgetPointing * Origin date: 041221 * Update history: 1.0.0 041221 Merged from j_ibr_get_pointing and getRAdec_init.c * Type of element: Function * Part of package: j_ima_iros * Name: j_iir_get_radec_init * Calls: * Returns: * Required components: DAL, PIL, RIL, DAL3GEN, DAL3AUX * 1.0.4 050126 Test version for undue crash * 1.1.0 050131 Now reading FITS sky/backproj files * 1.1.1 050211 Keywords adapted to needs of j_ima_mosaic * 1.1.2 050303 Extra keyw:RLIMIDX, new cleaning * 1.1.3 050307 New DMAP: 51 radii * 1.1.4 050407 New clean, etc. * 1.1.4 050407 New clean, etc. * 1.1.5 050415 New clean again, updated flux determination * 1.1.6 050418 Now uses JMXi-DBKG-MOD as default for empty field shds * 1.2.0 050425 Deals with SPR 4102,4108 and reduces RAM requirement * 1.3.0 050503 Deals with SPR 4120 and copes with up to 6 shadowgrams * 1.3.1 050517 Deals with SPR 4143 and initializes ima_sigma properly * 1.3.2 050519 Closes SPR 4157 - bad size of three arrays * 1.3.3 050602 Changes some arrays to static (SPR 4202) * 1.4.0 050620 Include user defined sources (SCREW 1740) * 1.6.0 060911 SCREW 1918 Image correction map and new parameters introduced * 2.0.0 070327 New tangentprojection center, new transformation algorithm *****************************************************************/ int j_iir_get_radec_init( dal_element *theSWG, /* pointer to SWG */ Instrument jemxNum, /* JEMX identifier */ swg_pointing *point, /* struct with pointing parameters */ float *p_RA, float *p_dec, float *p_posang, struct log_con *logger, struct instr_data *jmx_id, int chatter, /* Level of debugging output */ int status) { char memberName[DS_NAME_SIZE]; static char location[1000]; int i, j, jemx, numFound = 0; double ra_scx = 0.0; double dec_scx = 0.0; double ra_scz = 0.0; double dec_scz = 0.0; double posangIsdc = 0.0; double crl, srl, cdc, sdc, cRA, sRA, offX, offY, height, phase2; double delx, dely, delz, sdlx, cdlx, sdly, cdly, sdlz, cdlz; dal_element *member = NULL; FILE *par_chk; static int func_local = -1, local_calling_num=0, first=1; clock_t clock(void), 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_get_radec_init"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ if (logger->trace) traces(func_local, 0, logger); if( jemxNum == JMX1 ) { strcpy( memberName, "JMX1" ); jemx = 0; } else { strcpy( memberName, "JMX2" ); jemx = 1; } strcat( memberName, "-GNRL-GTI" ); status = DAL3GENindexFindMember( theSWG, memberName,"GTI_NAME == 'MERGED'", &numFound, &member, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##623## %d: Could not find GTI member", status); goto exittrace; } else { RILlogMessage( NULL, Log_0, "##624## Found %s (MERGED) alright", memberName ); status = DALelementGetLocation( member, location, status ); RILlogMessage( NULL, Log_0, "##3## Location: %s", location ); } if( numFound == 1 ) { if( chatter > J_CHATTY_QUIET ) RILlogMessage( NULL, Log_0,"##625## get pointing from GTI header"); status = DALattributeGetReal( member, "RA_SCX", &ra_scx, NULL, NULL, status); status = DALattributeGetReal( member, "DEC_SCX", &dec_scx, NULL, NULL, status); status = DALattributeGetReal( member, "RA_SCZ", &ra_scz, NULL, NULL, status); status = DALattributeGetReal( member, "DEC_SCZ", &dec_scz, NULL, NULL, status); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##626## %d: Trouble getting attributes", status); goto exittrace; } } else { RILlogMessage( NULL, Error_1, "##627## %d: Too many GTI data structures", status); status = J_ERROR_CODE_START + J_LIB_PIF_ERR + J_LPF_BADNUMGTIDS; goto exittrace; } /* * Translate to 'midisky' variables */ *p_RA = (float) ra_scx; *p_dec = (float) dec_scx; status = DAL3AUXcalcPosAngle( ra_scx, dec_scx, ra_scz, dec_scz, &posangIsdc, status); *p_posang = (float) posangIsdc; if ((logger->develop & 2) == 2) status = update_imod_data( jemx, jmx_id, logger, chatter, status); point->j_RA = *p_RA * GTORAD; point->j_dec = *p_dec * GTORAD; point->posvink = (180.0 - *p_posang) * GTORAD; point->j_posangle = *p_posang * GTORAD; if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage(NULL, Log_0,"##628## point->j_RA = %7.4f, j_dc = %7.4f, posangle = %7.4f", point->j_RA, point->j_dec, point->j_posangle ); } if (logger->develop > 0) { if (first) { par_chk = fopen("radec_par_chk.txt", "wt"); first = 0; } else par_chk = fopen("radec_par_chk.txt", "at"); saveparam2(par_chk, -1, jmx_id, logger); fclose(par_chk); } point->Xcenter = cos(point->j_dec) * cos(point->j_RA); /* X towards spring equinox */ point->Ycenter = cos(point->j_dec) * sin(point->j_RA); /* Y perpendicular to X and Z */ point->Zcenter = sin(point->j_dec); /* Z towards North */ point->cosvink = cos(point->posvink); point->sinvink = sin(point->posvink); point->cosph2 = cos(jmx_id->phase2); point->sinph2 = sin(jmx_id->phase2); /* ***** start of insertion from new getRAdec3.c ************************** */ point->cosj_dec = cdc = cos(point->j_dec); point->sinj_dec = sdc = sin(point->j_dec); point->cosj_RA = cRA = cos(point->j_RA); point->sinj_RA = sRA = sin(point->j_RA); crl = cos(*p_posang * GTORAD); srl = sin(*p_posang * GTORAD); point->INTEGRALinSKY[0][0] = point->Xcenter; point->INTEGRALinSKY[0][1] = point->Ycenter; point->INTEGRALinSKY[0][2] = point->Zcenter; point->INTEGRALinSKY[1][0] = -srl * sdc * cRA - crl * sRA; point->INTEGRALinSKY[1][1] = -srl * sdc * sRA + crl * cRA; point->INTEGRALinSKY[1][2] = srl * cdc; point->INTEGRALinSKY[2][0] = -crl * sdc * cRA + srl * sRA; point->INTEGRALinSKY[2][1] = -crl * sdc * sRA - srl * cRA; point->INTEGRALinSKY[2][2] = crl * cdc; /* printf("INTEGRALinSKY X: %+f %+f %+f\n", * point->INTEGRALinSKY[0][0], point->INTEGRALinSKY[0][1], point->INTEGRALinSKY[0][2]); * printf("INTEGRALinSKY Y: %+f %+f %+f\n", * point->INTEGRALinSKY[1][0], point->INTEGRALinSKY[1][1], point->INTEGRALinSKY[1][2]); * printf("INTEGRALinSKY Z: %+f %+f %+f\n\n", * point->INTEGRALinSKY[2][0], point->INTEGRALinSKY[2][1], point->INTEGRALinSKY[2][2]); * printf("X dot Y: %f\n", point->INTEGRALinSKY[0][0] * point->INTEGRALinSKY[1][0] + * point->INTEGRALinSKY[0][1] * point->INTEGRALinSKY[1][1] + * point->INTEGRALinSKY[0][2] * point->INTEGRALinSKY[1][2]); * * printf("Z dot Y: %f\n", point->INTEGRALinSKY[2][0] * point->INTEGRALinSKY[1][0] + * point->INTEGRALinSKY[2][1] * point->INTEGRALinSKY[1][1] + * point->INTEGRALinSKY[2][2] * point->INTEGRALinSKY[1][2]); */ /* Relation between spacecraft (INTEGRAL) axes and JEM-X axes: Spacecraft X-axis (boresight) is almost parallel to JEM-X Z-axes. Spacecraft Y-axis is almost parallel to JEM-X1 X-axis. Spacecraft Z-axis is almost parallel to JEM-X1 Y-axis. Spacecraft Y-axis is almost antiparallel to JEM-X2 X-axis. Spacecraft Z-axis is almost antiparallel to JEM-X2 Y-axis. Historically the misalignment between the JEM-X coordinate system and the INTEGRAL coordinate system has been described by giving the coordinates of the startracker boresight axis in the JEM-X coordinate system (offXmm, offYmm), and the rotation (phase2) of the INTEGRAL system wrt the JEM-X one. */ offX = jmx_id->offXmm; offY = jmx_id->offYmm; height = jmx_id->mask_height; phase2 = jmx_id->phase2; /* printf("Offsets before T-corrections: X/Y: %f %f\n", offX, offY); */ /* temperature correction introduced Jan 2007 */ offX += jmx_id->off_Tx0 + jmx_id->Tx0 * jmx_id->SC_HK[0+jemx]; offX += jmx_id->off_Tx7 + jmx_id->Tx7 * jmx_id->SC_HK[7+jemx]; offY += jmx_id->off_Ty0 + jmx_id->Ty0 * jmx_id->SC_HK[0+jemx]; offY += jmx_id->off_Ty7 + jmx_id->Ty7 * jmx_id->SC_HK[7+jemx]; /* printf("Offsets after T-corrections: X/Y: %f %f\n", offX, offY); * printf("Temperature values: detector: %6.2f, mask: %6.2f\n", * jmx_id->SC_HK[7+jemx], jmx_id->SC_HK[0+jemx]); */ delx = atan(offX / height); dely = atan(offY / height); delz = phase2; cdlx = cos(delx); sdlx = sin(delx); cdly = cos(dely); sdly = sin(dely); cdlz = cos(delz); sdlz = sin(delz); point->JMXinINTEGRAL[0][0] = -sdlx * cdlz - sdly * sdlz; point->JMXinINTEGRAL[0][1] = cdlx * cdlz; point->JMXinINTEGRAL[0][2] = sdlz * cdlx; point->JMXinINTEGRAL[1][0] = -sdly * cdlz + sdlx * sdlz; point->JMXinINTEGRAL[1][1] = -sdlz * cdly; point->JMXinINTEGRAL[1][2] = cdly * cdlz; point->JMXinINTEGRAL[2][0] = cdlx * cdly; point->JMXinINTEGRAL[2][1] = sdlx; point->JMXinINTEGRAL[2][2] = sdly; status = normalize(point->JMXinINTEGRAL[0]); /* normalize to unit length */ status += normalize(point->JMXinINTEGRAL[1]); status += normalize(point->JMXinINTEGRAL[2]); if (status < 0) { sprintf(logger->tmptxt, "Cannot normalize a null-vector!"); logger->logstat = logprint(logger, logger->tmptxt, 3); goto exittrace; } /* printf("JMXinINTEGRAL X: %+f %+f %+f\n", * point->JMXinINTEGRAL[0][0], point->JMXinINTEGRAL[0][1], point->JMXinINTEGRAL[0][2]); * printf("JMXinINTEGRAL Y: %+f %+f %+f\n", * point->JMXinINTEGRAL[1][0], point->JMXinINTEGRAL[1][1], point->JMXinINTEGRAL[1][2]); * printf("JMXinINTEGRAL Z: %+f %+f %+f\n\n", * point->JMXinINTEGRAL[2][0], point->JMXinINTEGRAL[2][1], point->JMXinINTEGRAL[2][2]); */ for (i=0; i< 3; i++) { for (j=0; j< 3; j++) point->JMXinSKY[i][j] = point->JMXinINTEGRAL[i][0] * point->INTEGRALinSKY[0][j] + point->JMXinINTEGRAL[i][1] * point->INTEGRALinSKY[1][j] + point->JMXinINTEGRAL[i][2] * point->INTEGRALinSKY[2][j]; } /* printf("JMXinSKY X: %+f %+f %+f\n", * point->JMXinSKY[0][0], point->JMXinSKY[0][1], point->JMXinSKY[0][2]); * printf("JMXinSKY Y: %+f %+f %+f\n", * point->JMXinSKY[1][0], point->JMXinSKY[1][1], point->JMXinSKY[1][2]); * printf("JMXinSKY Z: %+f %+f %+f\n\n", * point->JMXinSKY[2][0], point->JMXinSKY[2][1], point->JMXinSKY[2][2]); */ point->jmxdec = asin(point->JMXinSKY[2][2]) / GTORAD; point->jmxRA = atan2(point->JMXinSKY[2][1], point->JMXinSKY[2][0]) / GTORAD; if (point->jmxRA < 0.0) point->jmxRA += 360.0; if (logger->chatter == 2) { sprintf(logger->tmptxt, "getRAdec_init: cos/sinvink %7.3lf %7.3lf, cos/sinph2: %7.3lf %7.3lf\n", point->cosvink, point->sinvink, point->cosph2, point->sinph2); logger->logstat = logprint(logger, logger->tmptxt, 3); } if (logger->chatter >= 0) { sprintf(logger->tmptxt, "Pointing transformation initialized\nSpacecraft pointing:"); logger->logstat = logprint(logger, logger->tmptxt, 3); sprintf(logger->tmptxt, " RA: %10.6f, dec: %10.6f, JEM-X%1d pointing: RA: %10.6f, dec: %10.6f", *p_RA, *p_dec, jemx+1, point->jmxRA, point->jmxdec); logger->logstat = logprint(logger, logger->tmptxt, 3); } /* ***** end of insertion from new getRAdec3.c ************************** */ logger->pointdata = 1; /* flag for available pointing */ if ( chatter > J_CHATTY_VERBOSE ) { sprintf(logger->tmptxt, "##629## getRAdec_init: cos/sinvink %7.3lf %7.3lf, cos/sinph2: %7.3lf %7.3lf\n", point->cosvink, point->sinvink, point->cosph2, point->sinph2); logger->logstat = logprint(logger, logger->tmptxt, 5); } if ( chatter > J_CHATTY_VERBOSE ) { sprintf(logger->tmptxt, "##630## Pointing transformation initialized"); logger->logstat = logprint(logger, logger->tmptxt, 5); } exittrace: 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 ); } /* *********************************************************** */ int normalize(double M[3]) { /* normalize M to unit length */ double length, s2=0.0; s2 += M[0]*M[0]; s2 += M[1]*M[1]; s2 += M[2]*M[2]; length = sqrt(s2); if (length == 0.0) return(-1); M[0] /= length; M[1] /= length; M[2] /= length; return(0); } /* *********************************************************** */ int saveparam2(FILE *sd, int ee, struct instr_data *jmx_id, struct log_con *logger) { fprintf(sd, "jmx_unit: %1d\n", jmx_id->jmx_unit); fprintf(sd, "ee-channel: %1d\n\n", ee); fprintf(sd, "mask_height: %f\n", jmx_id->mask_height); fprintf(sd, "mask_r: %f\n", jmx_id->mask_r); fprintf(sd, "hexa_dim: %f\n", jmx_id->hexa_dim); fprintf(sd, "struc_h1: %f\n", jmx_id->struc_h1); fprintf(sd, "struc_h2: %f\n\n", jmx_id->struc_h2); fprintf(sd, "coll_h : %f\n", jmx_id->coll_h ); fprintf(sd, "coll_r: %f\n", jmx_id->coll_r); fprintf(sd, "coll_pitch: %f\n", jmx_id->coll_pitch); fprintf(sd, "coll_w : %f\n", jmx_id->coll_w ); fprintf(sd, "c_tiltx: %f\n", jmx_id->c_tiltx); fprintf(sd, "c_tilty: %f\n", jmx_id->c_tilty); fprintf(sd, "coll_wb: %f\n", jmx_id->coll_wb); fprintf(sd, "coll_curv: %f\n\n", jmx_id->coll_curv); fprintf(sd, "xshi : %f\n", jmx_id->xshi ); fprintf(sd, "yshi: %f\n\n", jmx_id->yshi); fprintf(sd, "alfa: %f\n", jmx_id->alfa); fprintf(sd, "beta: %f\n", jmx_id->beta); fprintf(sd, "gammav: %f\n\n", jmx_id->gammav); fprintf(sd, "offXmm: %f\n", jmx_id->offXmm); fprintf(sd, "offYmm: %f\n", jmx_id->offYmm); fprintf(sd, "phase2: %f\n", jmx_id->phase2); fprintf(sd, "x2xmm: %10.8f\n", jmx_id->x2xmm); fprintf(sd, "y2ymm: %10.8f\n", jmx_id->y2ymm); fprintf(sd, "scaleX: %f\n", jmx_id->scaleX); fprintf(sd, "scaleY: %f\n", jmx_id->scaleY); fprintf(sd, "offQrad: %f\n", jmx_id->offQrad); fprintf(sd, "offRrad: %f\n\n", jmx_id->offRrad); fprintf(sd, "\nabsolen: %f\n", jmx_id->absolen); fprintf(sd, "\nscatt_len: %d\n\n", jmx_id->scatt_len); fprintf(sd, "mm2rad: %f\n", jmx_id->mm2rad); fprintf(sd, "useHexpos: %1d\n\n", logger->useHexpos); fprintf(sd, "Tx0: %f\n", jmx_id->Tx0); fprintf(sd, "off_Tx0: %f\n", jmx_id->off_Tx0); fprintf(sd, "Ty0: %f\n", jmx_id->Ty0); fprintf(sd, "off_Ty0: %f\n", jmx_id->off_Ty0); fprintf(sd, "Tx7: %f\n", jmx_id->Tx7); fprintf(sd, "off_Tx7: %f\n", jmx_id->off_Tx7); fprintf(sd, "Ty7: %f\n", jmx_id->Ty7); fprintf(sd, "off_Ty7: %f\n\n", jmx_id->off_Ty7); return(0); } /****************************************************************************** File name: jemxlib_get_status_map.c Version: see below Component: Developer: Peter Kretschmar, ISDC Peter.Kretschmar@obs.unige.ch Purpose: Utility functions to access JEM-X Instrument Model (IMOD) data. *****************************************************************************/ /* * Revision 0.2.0 2004/01/23 * Revision 1.0.0 2004-12-27/NJW * Revision 2.0.0 2006-06-06/NJW put array under struct jmx_id (instr_data) * for jmx_lib_pif self consistency * */ /***************************************************************************** Function: JEMXLIBgetStatusMap Description: Find the detector map for the given JEM-X instrument in the instrument model group and read in the data Error codes: 0 == ISDC_OK ==> function executed with no errors < 0 (various) ==> ISDC system function error code, passed on Parameter arguments: name range I/O description instModGrp !=NULL input handle to instrument model group jemxInstr JMX1 or JMX2 input instrument number detMap (array) output 2D array with DETE-MOD values chatter 0 to 5 input verbosity control variable callingStatus any input error status on input *****************************************************************************/ int JEMXLIBgetStatusMap( dal_element *instModGrp, Instrument jemxInstr, struct instr_data *jmx_id, struct log_con *logger, /* log control parameters */ int chatter, int callingStatus) { /* * Local variable definitions */ dal_element *detModPtr = NULL; /* handle to JMXi-DETE-MOD */ dal_dataType dalType; char detModName[14]; int status = ISDC_OK; /* local status flag */ long endValues[2] = {J_NUM_X_PIXELS,J_NUM_Y_PIXELS}; long startValues[2] = { 1, 1}; long numValues = 0; static int func_local = -1, local_calling_num=0; clock_t calling_TT, TT_now; /* exit function immediately if status is not OK on entry */ if( callingStatus != ISDC_OK ) return( callingStatus ); /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; logger->func_calling_num = 0; sprintf(logger->func_names[func_local], "JEMXLIBgetStatusMap"); if (logger->func_used_num > J_IIR_MAX_NUM_FUNCS) { sprintf(logger->tmptxt, "func_used_num > %d", J_IIR_MAX_NUM_FUNCS); logger->logstat = logprint(logger, logger->tmptxt, 6); logger->func_used_num = J_IIR_MAX_NUM_FUNCS; } } 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); switch(jemxInstr) { case JMX1: strcpy(detModName,"JMX1"); break; case JMX2: strcpy(detModName,"JMX2"); break; default: status = J_ERROR_CODE_START+J_LIB_PIF_ERR+J_LPF_BADJEMXNUM; RILlogMessage(NULL,Error_1, "JEM-X instrument number %i impossible!",jemxInstr); break; } strcat(detModName, J_DETECTOR_DS); status = DALobjectFindElement( instModGrp, detModName, &detModPtr, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##509## Could not find %s", detModName ); goto exittrace; } dalType = DAL_DT_UNKNOWN; status = DALarrayGetSection( detModPtr, 2, startValues, endValues, &dalType, &numValues, jmx_id->status_map, status); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##510## Could not read 'status_map'" ); goto exittrace; } /* * Transpose to get correct orientation */ transpose_usi( jmx_id->status_map, J_IIR_DIM_STDSHDG ); exittrace: 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); } /****************************************************************************** File name: jemxlib_get_mask.c Version: see below Component: Developer: Peter Kretschmar, ISDC Peter.Kretschmar@obs.unige.ch Purpose: Utility functions to access JEM-X Instrument Model (IMOD) data. *****************************************************************************/ /* * Revision 0.2.0 2004/01/23 * Revision 1.0.0 2004-12-27/NJW * */ /***************************************************************************** Function: JEMXLIBgetMask Description: Find the mask map for the given JEM-X instrument in the instrument model group and read in the data Error codes: 0 == ISDC_OK ==> function executed with no errors < 0 (various) ==> ISDC system function error code, passed on Parameter arguments: name range I/O description instModGrp !=NULL input handle to instrument model group jemxInstr JMX1 or JMX2 input instrument number detMap (array) output 2D array with DETE-MOD values chatter 0 to 5 input verbosity control variable callingStatus any input error status on input *****************************************************************************/ int JEMXLIBgetMask( dal_element *instModGrp, Instrument jemxInstr, struct instr_data *jmx_id, struct log_con *logger, /* log control parameters */ int chatter, int callingStatus) { /* * Local variable definitions */ dal_element *maskModPtr = NULL; /* handle to JMXi-MASK-MOD */ dal_dataType dalType; char maskModName[14]; short int *buffer = NULL; int status = ISDC_OK; /* local status flag */ int i = 0; int j = 0; long endValues[2] = {J_IIR_SKEWMASK_DIM,J_IIR_SKEWMASK_DIM}; long startValues[2] = { 1, 1}; long numValues = 0; long index = 0; static int func_local = -1, local_calling_num=0; clock_t calling_TT, TT_now; /* exit function immediately if status is not OK on entry */ if( callingStatus != ISDC_OK ) return( callingStatus ); /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; logger->func_calling_num = 0; sprintf(logger->func_names[func_local], "JEMXLIBgetMask"); if (logger->func_used_num > J_IIR_MAX_NUM_FUNCS) { sprintf(logger->tmptxt, "func_used_num > %d", J_IIR_MAX_NUM_FUNCS); logger->logstat = logprint(logger, logger->tmptxt, 6); logger->func_used_num = J_IIR_MAX_NUM_FUNCS; } } 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); switch(jemxInstr) { case JMX1: strcpy(maskModName,"JMX1"); break; case JMX2: strcpy(maskModName,"JMX2"); break; default: status = J_ERROR_CODE_START+J_LIB_PIF_ERR+J_LPF_BADJEMXNUM; RILlogMessage(NULL,Error_1, "JEM-X instrument number %i impossible!",jemxInstr); break; } strcat(maskModName, J_MASK_DS); status = DALobjectFindElement( instModGrp, maskModName, &maskModPtr, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##619## Could not find %s", maskModName ); goto exittrace; } if( chatter >= J_CHATTY_MAXIMAL ) { RILlogMessage( NULL, Log_0,"##620## get_mask: Has found %s", maskModName ); } /* * Allocate temporary memory */ buffer = (short int *) malloc( J_IIR_SKEWMASK_DIM*J_IIR_SKEWMASK_DIM*sizeof(short int) ); if( buffer == NULL ) { RILlogMessage( NULL, Error_2, "##621## Memory allocation error"); status = J_ERROR_CODE_START+J_LIB_PIF_ERR+J_LPF_MALLOC_ERR; goto exittrace; } dalType = DAL_DT_UNKNOWN; status = DALarrayGetSection( maskModPtr, 2, startValues, endValues, &dalType, &numValues, buffer, status); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##622## Could not read 'MASK-MOD'" ); goto exittrace; } /* * Transfer data to struct * The mask values are inverted in the x-directions as verified * with the help of the testing function 'mask_test' * This is valid for JMX2 and must be verified for JMX1 * [2005-01-14/NJW] */ for( j = 0; j < J_IIR_SKEWMASK_DIM; j++ ) { for( i = 0; i < J_IIR_SKEWMASK_DIM; i++ ) { index = j * J_IIR_SKEWMASK_DIM + i; jmx_id->njwmask[J_IIR_SKEWMASK_DIM-1-j][i] = buffer[index]; } } exittrace: /* * De-allocate memory */ if( buffer != NULL ) free( buffer ); 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); } /***************************************************************** * Name of source file: j_lpf_get_sc_hk.c * Version of source file: 1.1.0 * Programmer: Niels J. Westergaard & Niels Lund * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325700 FAX: +45 35362475 * njw@spacecenter.dk, nl@spacecenter.dk * Purpose: Get INTEGRAL spacecraft HK temperature data * Origin date: 070307 * Update history: 1.0.0 041221 Merged from j_ibr_get_pointing and getRAdec_init.c * Type of element: Function * Part of package: jmx_lib_pif *****************************************************************/ int j_lpf_get_sc_hk( dal_element *theSWG, /* pointer to SWG */ struct instr_data *jmx_id, int chatter, /* Level of debugging output */ int status) { char memberName[DS_NAME_SIZE]; long numRows = 0; long numValues = 0; long loop = 0; float *fbuffer = NULL; float sum = 0.0; dal_element *member = NULL; dal_dataType dataType; strcpy( memberName, "INTL-PLM.-CNV" ); status = DALobjectFindElement( theSWG, memberName, &member, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##623## %d: Could not find INTL-PLM.CNV", status); return status; } RILlogMessage( NULL, Log_0, "##624## Found %s alright", memberName ); /* * Allocate memory for the tables to read */ status = DALtableGetNumRows( member, &numRows, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_0,"##3## %d: GetNumRows", status); return status; } fbuffer = (float *) malloc( numRows * sizeof( float ) ); if( fbuffer == NULL ) { status = -123456; RILlogMessage( NULL, Error_0,"##3## %d: Memory allocation error", status); return status; } dataType = DAL_FLOAT; status = DALtableGetCol( member, "TCS__JEMX__MASK___PY", 0, &dataType, &numValues, (void *) fbuffer, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_0,"##3## %d: Reading JMASK PY", status); return status; } sum = 0.0; for(loop=0;loopSC_HK[0] = sum / numValues; status = DALtableGetCol( member, "TCS__JEMX__MASK___MY", 0, &dataType, &numValues, (void *) fbuffer, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_0,"##3## %d: Reading JMASK MY", status); return status; } sum = 0.0; for(loop=0;loopSC_HK[1] = sum / numValues; status = DALtableGetCol( member, "TCS__TH__IBIS__MASK", 0, &dataType, &numValues, (void *) fbuffer, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_0,"##3## %d: Reading IBIS MASK", status); return status; } sum = 0.0; for(loop=0;loopSC_HK[2] = sum / numValues; status = DALtableGetCol( member, "OMC__LENS__TEMP1", 0, &dataType, &numValues, (void *) fbuffer, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_0,"##3## %d: Reading OMC T1", status); return status; } sum = 0.0; for(loop=0;loopSC_HK[3] = sum / numValues; status = DALtableGetCol( member, "OMC__LENS__TEMP2", 0, &dataType, &numValues, (void *) fbuffer, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_0,"##3## %d: Reading OMC T2", status); return status; } sum = 0.0; for(loop=0;loopSC_HK[4] = sum / numValues; status = DALtableGetCol( member, "JDPE1__TEMP__MON", 0, &dataType, &numValues, (void *) fbuffer, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_0,"##3## %d: Reading DPE 1", status); return status; } sum = 0.0; for(loop=0;loopSC_HK[5] = sum / numValues; status = DALtableGetCol( member, "JDPE2__TEMP__MON", 0, &dataType, &numValues, (void *) fbuffer, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_0,"##3## %d: Reading DPE 2", status); return status; } sum = 0.0; for(loop=0;loopSC_HK[6] = sum / numValues; status = DALtableGetCol( member, "JDFEE1__THERM__C", 0, &dataType, &numValues, (void *) fbuffer, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_0,"##3## %d: Reading DFEE 1", status); return status; } sum = 0.0; for(loop=0;loopSC_HK[7] = sum / numValues; status = DALtableGetCol( member, "JDFEE2__THERM__C", 0, &dataType, &numValues, (void *) fbuffer, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_0,"##3## %d: Reading DFEE 2", status); return status; } sum = 0.0; for(loop=0;loopSC_HK[8] = sum / numValues; RILlogMessage( NULL, Log_0,"##3## Temps: %6.1f%6.1f%6.1f%6.1f%6.1f%6.1f%6.1f%6.1f%6.1f", jmx_id->SC_HK[0], jmx_id->SC_HK[1], jmx_id->SC_HK[2], jmx_id->SC_HK[3], jmx_id->SC_HK[4], jmx_id->SC_HK[5], jmx_id->SC_HK[6], jmx_id->SC_HK[7], jmx_id->SC_HK[8]); if( fbuffer != NULL ) free( fbuffer ); return( status ); } /***************************************************************** * Name of source file: j_lpf_get_jemx_hk.c * Version of source file: 1.1.0 * Programmer: Niels J. Westergaard & Niels Lund * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325700 FAX: +45 35362475 * njw@spacecenter.dk, nl@spacecenter.dk * Purpose: Get JEMX HK countrate information * Origin date: 070307 * Update history: 1.0.0 041221 Merged from j_ibr_get_pointing and getRAdec_init.c * Type of element: Function * Part of package: jmx_lib_pif *****************************************************************/ int j_lpf_get_jemx_hk( dal_element *theSWG, /* pointer to SWG */ Instrument jemxNum, /* JMX1 or JMX2 */ struct instr_data *jmx_id, /* instrument information */ int chatter, /* Level of debugging output */ int status) { char memberName[DS_NAME_SIZE]; long numRows = 0; long numValues = 0; long loop = 0; int *jbuffer = NULL; float sum = 0.0; dal_element *member = NULL; dal_dataType dataType; if( jemxNum == JMX1 ) { strcpy( memberName, "JMX1-" ); } else { strcpy( memberName, "JMX2-" ); } strcat( memberName, "CSSW-HRW" ); status = DALobjectFindElement( theSWG, memberName, &member, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##623## %d: Could not find %s", status, memberName ); return status; } RILlogMessage( NULL, Log_0, "##624## Found %s alright", memberName ); /* * Allocate memory for the tables to read */ status = DALtableGetNumRows( member, &numRows, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_0,"##3## %d: GetNumRows", status); return status; } jbuffer = (int *) malloc( numRows * sizeof( int ) ); if( jbuffer == NULL ) { status = -123456; RILlogMessage( NULL, Error_0,"##3## %d: Memory allocation error", status); return status; } dataType = DAL_INT; status = DALtableGetCol( member, "HARDWARE__TRIGGER", 0, &dataType, &numValues, (void *) jbuffer, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_0,"##3## %d: Reading HARDWARE__TRIGGER", status); return status; } sum = 0.0; for(loop=0;loopJMX_HK[0] = sum / numValues; status = DALtableGetCol( member, "SOFTWARE__TRIGGER", 0, &dataType, &numValues, (void *) jbuffer, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_0,"##3## %d: Reading SOFTWARE__TRIGGER", status); return status; } sum = 0.0; for(loop=0;loopJMX_HK[1] = sum / numValues; status = DALtableGetCol( member, "ACCEPTED__EVENTS", 0, &dataType, &numValues, (void *) jbuffer, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_0,"##3## %d: Reading ACCEPTED__EVENTS", status); return status; } sum = 0.0; for(loop=0;loopJMX_HK[2] = sum / numValues; RILlogMessage( NULL, Log_0,"##777## Trigger rates: %8.0f%8.0f%8.0f", jmx_id->JMX_HK[0], jmx_id->JMX_HK[1], jmx_id->JMX_HK[2] ); if( jbuffer != NULL ) free( jbuffer ); return( status ); } /* **************************************************************** */ int detectmap2( float x_sourcemm, float y_sourcemm, int srcfun[], int last, int jemx, struct instr_data *jmx_id, struct log_con *logger) /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* */ /* detectmap.c generates a list of detector pixels which are */ /* illuminated from a particular sky position. */ /* */ /* Niels Lund, February 2003 */ /* Updated for NJW-mask and detector support struct. Sep. 2003 */ /* Updated for collimator strip bending/bulging. Nov. 2007 */ /* */ /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* Illumination JEM-X detector surface for source at position (x_sourcemm, y_sourcemm). Derived from skymap version 3.0 * Niels Lund, January 2003 Version 1.0 * Danish Space Research Institute * * NOTE: The jemx variable is 0 for JEM-X1 and 1 for JEM-X2 in these routines !! * * The XY-coordinate system used in this routine is aligned with * the detector collimator lamellae. The microstrip pattern is * approximately aligned with the lamellae. The cathode positions * are (nearly) along the X-axis, the backside positions nearly * along the Y-axis. The center of the detector is located at * position (128, 128). The central collimator crossing is * also at this position. The center of the collimator falls at * the corner between 4 pixel boundaries. * * The unit used for the X- and Y-positions on the detector are * 1 mm. Actually, the X- and Y-integer positions are only * approximately separated by 1 mm. A detailed map, specifying * the float values of the X- and Y-position of the four corners * of each pixel have been prepared by Carl Budtz-J and are * applied to the data using subroutine "pixelfold". * * The full field of view of the JEM-X detector is defined by the * dimensions of the mask (535 mm diameter) and detector (250 mm * diameter) and by the mask-detector separation (about 3400 mm). * * 1.5.4 060104 Bug in sh_depth corrected, detectmap now in mm * * */ { int i, j, allownum, iq, iv, ky, mx, iqp, ivp, status, i5 = 0; int xyacc, njw1, njw2; int strblock, njwOK, p_count=0; int nn = 0; int nnn[4]; unsigned det_index, sky_index; unsigned mx2, xd7, yd7, xc7, yc7, ym7, xm7, cur_index; static double collp30; /* 30 times the collimator pitch */ static double cosbe, sinbe, cosga, singa; static double cosalx, sinalx, cosaly, sinaly; static double rsin60, cot60; static double coll_ptop, collp30top, coll_pmid, collp30mid, jmx_idMMcoll_w = 0.0; /* = 0.225; QQQQQ NL 20080530 */ double coll_r2, xdet, ydet, xmask, ymask; double r_sky, c_factt, c_factb, c_factc, m_fact, mask_r2, rm2; double ydet2, qmask, vmask, xcoll2, c_tiltxh, c_tiltyh, xrcmid, yrcmid; double xdmod7, ydmod7, xtmod7, ytmod7, xmmod7, ymmod7, c0_fact, xcolmid, ycolmid; double ycolbot, ycoltop, xcolbot, xcoltop, xrmask, yrmask, xmask2; double xrcbot, xrctop, yrcbot, yrctop, xrdet, yrdet; /* static struct MaskSS MSS, *mss; */ struct MaskSS *mss; static int func_local = -1, local_calling_num=0; clock_t clock(void), calling_TT, TT_now; /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "detectmap"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ if (logger->trace) traces(func_local, 0, logger); /* initializations */ mss = jmx_id->mss; /* &MSS; */ mss->pi = 3.14159265; mss->twopi = mss->pi * 2.0; mss->gtorad = mss->pi / 180.0; collp30 = jmx_id->coll_pitch * 30.0; /* 30 time the collimator pitch, used in the "modulo" calc */ coll_ptop = jmx_id->coll_pitch * jmx_id->coll_curv; collp30top = coll_ptop * 30.0; coll_pmid = jmx_id->coll_pitch * ((jmx_id->coll_curv - 1.0) * 0.5 + 1.0); collp30mid = coll_pmid * 30.0; c_tiltxh = 0.5 * jmx_id->c_tiltx; c_tiltyh = 0.5 * jmx_id->c_tilty; coll_r2 = jmx_id->coll_r * jmx_id->coll_r; mask_r2 = jmx_id->mask_r * jmx_id->mask_r; cosalx = cos(jmx_id->alfa); sinalx = sin(jmx_id->alfa); cosaly = cos(jmx_id->alfa); sinaly = sin(jmx_id->alfa); cosbe = cos(jmx_id->beta); sinbe = sin(jmx_id->beta); cosga = cos(jmx_id->gammav); singa = sin(jmx_id->gammav); r_sky = jmx_id->mask_r + jmx_id->coll_r; /* field of view radius */ /* ray movement at collimator top level corresp. to 1 mm movement at mask level */ c0_fact = jmx_id->coll_h / jmx_id->mask_height; /* this routine calculates illumination at the detector window level (indepc = 0.0) */ m_fact = 1.0; /* corresponding movement at mask level */ c_factb = 0.0; /* corresponding movement at bottom of collimator (this calculation is valid for the level of the detector window) */ c_factc = c0_fact/2.0; /* corresponding movement at the mid plane of the collimator */ c_factt = c0_fact; /* corresponding movement at top of collimator */ sprintf(logger->tmptxt, "##505## detectmap: c_factt: %6.2lf, m_fact: %6.2lf, c_factb: %6.2lf, x/y_source: %6.1f/%6.1f", c_factt, m_fact, c_factb, x_sourcemm, y_sourcemm); logger->logstat = logprint(logger, logger->tmptxt, i5); sprintf(logger->tmptxt, "detectmap: collim.pitch %6.3lf, curv: %6.4lf, radius: %6.2lf, tiltx/y: %6.4lf %6.4lf", jmx_id->coll_pitch, jmx_id->coll_curv, jmx_id->coll_r, jmx_id->c_tiltx, jmx_id->c_tilty); logger->logstat = logprint(logger, logger->tmptxt, i5); sprintf(logger->tmptxt, "detectmap: alfa: %6.3lf, beta: %6.4lf, gamma: %6.2lf, coll_h: %6.2lf, mask_H: %6.1lf", jmx_id->alfa, jmx_id->beta, jmx_id->gammav, jmx_id->coll_h, jmx_id->mask_height); logger->logstat = logprint(logger, logger->tmptxt, i5); sprintf(logger->tmptxt, "detectmap: hexa_dim: %6.2lf, x/y_shift: %6.3lf %6.3lf, coll_w/wb: %6.3lf, %6.3lf", jmx_id->hexa_dim, jmx_id->xshi, jmx_id->yshi, jmx_id->coll_w, jmx_id->coll_wb); logger->logstat = logprint(logger, logger->tmptxt, i5); cot60 = 1.0 / (jmx_id->hexa_dim * 1.73205081); rsin60 = 2.0 * cot60; det_index = 0; sky_index = 0; cur_index = 0; allownum = 0; /* *************** main loop ********************* */ for (i=0; i<256; i++) { /* loop over detector Y */ yrdet = (double)(i) - 127.5 + jmx_id->yshi; ydet2 = yrdet * yrdet; for (j=0; j<256; j++) { /* loop over detector X */ det_index = j * 256 + i; srcfun[det_index] = 0; xrdet = (double)(j) - 127.5 + jmx_id->xshi; if ((ydet2 + xrdet*xrdet) > coll_r2) continue; /* detector radius check */ xdet = xrdet * cosga - yrdet * singa; ydet = yrdet * cosga + xrdet * singa; /* xdet and ydet are coordinates of a detector pixel in a coord. system aligned after Common-X */ xyacc = 0; mx = x_sourcemm; mx2 = mx * mx; xcolbot = x_sourcemm * c_factb + xdet; xcoltop = x_sourcemm * c_factt + xdet; xcolmid = x_sourcemm * c_factc + xdet; xcoll2 = xcoltop * xcoltop; xrmask = x_sourcemm * m_fact + xdet; xmask2 = xrmask * xrmask; ky = y_sourcemm; ycolbot = y_sourcemm * c_factb + ydet; ycoltop = y_sourcemm * c_factt + ydet; ycolmid = y_sourcemm * c_factc + ydet; if ((xcoll2 + ycoltop * ycoltop) > coll_r2) continue; /* Collimator top radius check */ yrmask = y_sourcemm * m_fact + ydet; rm2 = yrmask * yrmask + xmask2; if (rm2 > mask_r2) continue; /* the event falls outside the coded mask */ srcfun[det_index] = 1; /* indicate area on which the mask pattern is projected */ xrcbot = xcolbot * cosbe + ycolbot * sinbe; /* rotation through -jmx_id->beta! */ yrcbot = ycolbot * cosbe - xcolbot * sinbe; xrctop = xcoltop * cosbe + ycoltop * sinbe; /* rotation through -jmx_id->beta! */ yrctop = ycoltop * cosbe - xcoltop * sinbe; xrcmid = xcolmid * cosbe + ycolmid * sinbe; /* rotation through -jmx_id->beta! */ yrcmid = ycolmid * cosbe - xcolmid * sinbe; /* determine open directions of collimator, the collimator lamellae are located on positions: (the collimator midplane must be kept invariant even if the collimator tilt is nonzero !) -126.9,-119.85, ... ,-21.15, -14.1, -7.05, 0, 7.05, 14.1, 21.15, ... , 119.85, 126.9 both in the X- and Y-direction */ yd7 = (int)((yrcbot - c_tiltyh + collp30) / jmx_id->coll_pitch); /* determine bottom collimator hole index collp30 >detector radius */ yc7 = (int)((yrctop + c_tiltyh + collp30top) / coll_ptop); /* determine top collimator hole index */ ym7 = (int)((yrcmid + collp30mid) / coll_pmid); /* determine top collimator hole index */ if (yc7 > yd7) continue; /* the event is lost due to wall crossing in the collimator */ if (yc7 < yd7) continue; /* the event is lost due to wall crossing in the collimator */ ymmod7 = yrcmid + collp30 - jmx_id->coll_pitch * ym7; ydmod7 = yrcbot - c_tiltyh + collp30 - jmx_id->coll_pitch * yd7; /* get remainder Ycoord within this hole */ if (ydmod7 < jmx_id->coll_wb) continue; /* the event is lost at the bottom edge of the collimator */ if (ydmod7 > (jmx_id->coll_pitch - jmx_id->coll_wb)) continue; /* the event is lost at the bottom edge of the collimator */ ytmod7 = yrctop + c_tiltyh + collp30top - coll_ptop * yc7; /* remainder Ycoord within this hole */ if (ytmod7 < jmx_id->coll_w) continue; /* the event is lost at the top edge of the collimator */ /* Y-collimator wall -thickness check */ if (ytmod7 > (coll_ptop - jmx_id->coll_w)) continue; /* the event is lost at the top edge of the collimator */ /* Y-collimator wall +thickness check */ if (ymmod7 < jmx_idMMcoll_w) continue; /* the event is lost at the bulge of the collimator */ if (ymmod7 > (coll_pmid - jmx_idMMcoll_w)) continue; /* the event is lost at the bulge of the collimator */ /* completed checking in the Y-direction *** YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY ****** */ xd7 = (int)((xrcbot - c_tiltxh + collp30) / jmx_id->coll_pitch); /* determine bottom collimator hole index collp30 >detector radius */ xc7 = (int)((xrctop + c_tiltxh + collp30top) / coll_ptop); /* determine top collimator hole index */ xm7 = (int)((xrcmid + collp30mid) / coll_pmid); /* determine top collimator hole index */ if (xc7 > xd7) continue; /* the event is lost due to wall crossing in the collimator */ if (xc7 < xd7) continue; /* the event is lost due to wall crossing in the collimator */ xmmod7 = xrcmid + collp30 - jmx_id->coll_pitch * xm7; xdmod7 = xrcbot - c_tiltxh + collp30 - jmx_id->coll_pitch * xd7; /* get remainder Xcoord within this hole */ if (xdmod7 < jmx_id->coll_wb) continue; /* the event is lost at the bottom edge of the collimator */ if (xdmod7 > (jmx_id->coll_pitch - jmx_id->coll_wb)) continue; /* the event is lost at the bottom edge of the collimator */ xtmod7 = xrctop + c_tiltxh + collp30top - coll_ptop * xc7; /* get remainder Xcoord within this hole */ if (xtmod7 < jmx_id->coll_w) continue; /* the event is lost at the top edge of the collimator */ if (xtmod7 > (coll_ptop - jmx_id->coll_w)) continue; /* the event is lost at the top edge of the collimator */ if (xmmod7 < jmx_idMMcoll_w) continue; /* the event is lost at the bulge of the collimator */ if (xmmod7 > (coll_pmid - jmx_idMMcoll_w)) continue; /* the event is lost at the bulge of the collimator */ /* completed checking in the X-direction *** XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ****** */ xmask = xrmask * cosalx + yrmask * sinalx; ymask = yrmask * cosaly - xrmask * sinaly; /* * Replaced by new (2005-01-31) function 'hexpos' */ qmask = xmask / jmx_id->hexa_dim - ymask * cot60; vmask = ymask * rsin60; iqp = qmask + 22501.5; ivp = vmask + 22501.5; iq = iqp - 22501; iv = ivp - 22501; njw1 = 99 + iq + iv; njw2 = 100 + iv; if( logger->useHexpos ) { nn = hexpos( xmask, ymask, nnn, jmx_id->hexa_dim ); njw1 = nnn[1]; njw2 = nnn[2]; } if ( logger->useHexpos > 99 ) { srcfun[det_index] += 1; allownum++; continue; /* special case where the mask blocking must not be included */ /* used in search for off-axis transients */ } if ((njw1 < 0) || (njw1 > 199) || (njw1 < 0) || (njw1 > 199)) { if (p_count < 3) { sprintf(logger->tmptxt, "njw1/2 outside limits: %4d/%4d, i/j: %3d/%3d, x/y_sourcemm: %6.2f/%6.2f, x/ymask: %10.4f, %10.4f, nnn[0]: %d", njw1, njw2, i, j, x_sourcemm, y_sourcemm, xmask, ymask, nnn[0]); logger->logstat = logprint(logger, logger->tmptxt, 6); p_count++; } njw1 = njw2 = 0; } if (jmx_id->njwmask[njw1][njw2] == J_MASK_OPEN_CELL) { njwOK++; strblock = struchk(xmask, ymask, xdet, ydet, last, jmx_id, logger); if (strblock < 0) { status = J_ERROR_CODE_START+J_LIB_PIF_ERR+J_LPF_DIMTOOSMALL; goto exittrace;; } if (strblock == 0) { srcfun[det_index] += 1; allownum++; } } } } sprintf(logger->tmptxt, "source area: %5d, pixelmap", allownum); logger->logstat = logprint(logger, logger->tmptxt, i5); if (last) struchk(30.0, 30.0, 1.0, 1.0, 2, jmx_id, logger); /* dummy call to initiate statistics print */ if (logger->chatter > J_CHATTY_NORMAL ) { sprintf(logger->tmptxt, "##506## detectmap complete: allownum: %6d, srcfun: ", allownum); sprintf(logger->tmptxt2, "%2d %2d %2d %2d %2d %2d %2d %2d %2d %2d %2d %2d", srcfun[detdim/2 - 6], srcfun[detdim/2 - 5], srcfun[detdim/2 - 4], srcfun[detdim/2 - 3], srcfun[detdim/2 - 2], srcfun[detdim/2 - 1], srcfun[detdim/2 - 0], srcfun[detdim/2 + 1], srcfun[detdim/2 + 2], srcfun[detdim/2 +3], srcfun[detdim/2 + 4], srcfun[detdim/2 + 5]); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); if (logger->chatter == 1) logger->logstat = logprint(logger, logger->tmptxt, 5); } status = 0; exittrace: 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); } /* *************************************** */ int getRAdec(float x, float y, int jemx, float *s_RA, float *s_dec, swg_pointing *point, struct log_con *logger, struct instr_data *jmx_id) { double SRCY, SRCZ, SRCX, SRC_R; float z; static int func_local = -1, local_calling_num=0; clock_t clock(void), calling_TT, TT_now; /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "getRAdec"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ if (logger->trace) traces(func_local, 1, logger); /* scale correction */ x *= jmx_id->scaleX; y *= jmx_id->scaleY; /* nonlinearity correction */ x += jmx_id->x2xmm * x * fabs(x); y += jmx_id->y2ymm * y * fabs(y); z = jmx_id->mask_height; SRCX = point->JMXinSKY[0][0] * x + point->JMXinSKY[1][0] * y + point->JMXinSKY[2][0] * z; SRCY = point->JMXinSKY[0][1] * x + point->JMXinSKY[1][1] * y + point->JMXinSKY[2][1] * z; SRCZ = point->JMXinSKY[0][2] * x + point->JMXinSKY[1][2] * y + point->JMXinSKY[2][2] * z; SRC_R = sqrt(SRCX*SRCX + SRCY*SRCY + SRCZ*SRCZ); *s_dec = asin(SRCZ / SRC_R); *s_RA = atan2(SRCY, SRCX); if (*s_RA < 0.0) *s_RA += TWOPI; *s_dec /= GTORAD; *s_RA /= GTORAD; 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(0); } /* ************************************************************************************ */ /* */ /* Name of source file: getxy.c */ /* */ /* Version of source file: 1.7.0 */ /* */ /* Author: Niels Lund, Danish National Space Center */ /* Original version July 2001 */ /* */ /* 1.4.0 050609 Introduction of pre-selected sources */ /* */ /* */ /* ************************************************************************************ */ int getxy(float s_RA, float s_dec, int jemx, float *x, float *y, struct instr_data *jmx_id, swg_pointing *point, struct log_con *logger) { double SRCY, SRCZ, SRCX, xx, yy, zz, height; double xxx, yyy; static int func_local = -1, local_calling_num=0; int status; clock_t clock(void), calling_TT, TT_now; /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "getxy"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ if (logger->trace) traces(func_local, 1, logger); height = jmx_id->mask_height; s_dec *= GTORAD; s_RA *= GTORAD; SRCX = cos((double)(s_dec)) * cos((double)(s_RA)); SRCY = cos((double)(s_dec)) * sin((double)(s_RA)); SRCZ = sin((double)(s_dec)); xx = point->JMXinSKY[0][0] * SRCX + point->JMXinSKY[0][1] * SRCY + point->JMXinSKY[0][2] * SRCZ; yy = point->JMXinSKY[1][0] * SRCX + point->JMXinSKY[1][1] * SRCY + point->JMXinSKY[1][2] * SRCZ; zz = point->JMXinSKY[2][0] * SRCX + point->JMXinSKY[2][1] * SRCY + point->JMXinSKY[2][2] * SRCZ; if (zz < 0.99) { status = -1; sprintf(logger->tmptxt, "getxy: point outside field of view"); logger->logstat = logprint(logger, logger->tmptxt, 3); goto retur; } xx *= height / zz; yy *= height / zz; /* nonexact, but safe, even for zero coefficient */ xxx = xx - jmx_id->x2xmm * xx * fabs(xx); yyy = yy - jmx_id->y2ymm * yy * fabs(yy); /* scale correction */ xxx /= jmx_id->scaleX; yyy /= jmx_id->scaleY; *x = xxx; *y = yyy; status = 0; retur: 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); } /* *********************************************************** */ int sh_xy(double x_rms, double y_rms, struct log_con *logger, struct instr_data *jmx_id) /* , struct instr_data jmx_idN) */ { /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* */ /* Calculate the distribution of actual detection points */ /* relative to the photon interaction position on a 1x1 mm2 */ /* grid. The rms uncertainty in the X and Y position */ /* determination (in mm) are given in x_rms and y_rms. */ /* */ /* Niels Lund, February 2003 */ /* */ /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* Calculate the distribution of actual detection points relative to the photon interaction position on a 1x1 mm2 grid. The rms uncertainty in the X and Y position determination (in mm) are given in x_rms and y_rms. */ int i, j, k, m, n, nold, status; double x_dist[21], y_dist[21], id, t, f, pi_c, q, sum, x, y, xfac, yfac, x_gauss[21], y_gauss[21]; static int func_local = -1, local_calling_num=0; clock_t clock(void), calling_TT, TT_now; /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "sh_xy"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ if (logger->trace) traces(func_local, 1, logger); pi_c = 1.0 / sqrt(2.0 * 3.14159); for (i=0; i<21; i++) { id = (double)(2 * i + 1); x = 0.5 * id / x_rms; f = pi_c * exp(-x * x / 2.0); x_gauss[i] = f; t = 1.0 / (1.0 + 0.2316419 * x); q = f * t * (0.31938153 - t * (.356563782 - t * (1.781477937 - t * (1.821255978 - t * 1.330274429)))); /* Abramowitz & Stegun, Hdbk of Math. Funct., NBS 1968 */ x_dist[i] = q; y = 0.5 * id / y_rms; f = pi_c * exp(-y * y / 2.0); y_gauss[i] = f; t = 1.0 / (1.0 + 0.2316419 * y); q = f * t * (0.31938153 - t * (.356563782 - t * (1.781477937 - t * (1.821255978 - t * 1.330274429)))); /* Abramowitz & Stegun, Hdbk of Math. Funct., NBS 1968 */ y_dist[i] = q; } x_dist[20] = x_dist[19]; y_dist[20] = y_dist[19]; for (i=19; i>0; i--) { x_dist[i] = x_dist[i-1] - x_dist[i]; y_dist[i] = y_dist[i-1] - y_dist[i]; } x_dist[0] = 1.0 - 2.0 * x_dist[0]; y_dist[0] = 1.0 - 2.0 * y_dist[0]; sum = -x_dist[0]; for (i=0; i<21; i++) { id = (double)(2 * i + 1); x = 0.5 * id / x_rms; sum += 2 * x_dist[i]; } sum = -y_dist[0]; for (i=0; i<21; i++) { id = (double)(2 * i + 1); y = 0.5 * id / y_rms; sum += 2 * y_dist[i]; } n = 0; for (i=-20; i<=20; i++) { k = i + 20; xfac = x_dist[(int)(abs(i))]; for (j=-20; j<=20; j++) { m = j + 20; yfac = y_dist[(int)(abs(j))]; nold = n; if (xfac * yfac > 0.0001) { jmx_id->scatt_list[n] = xfac * yfac; jmx_id->scatt_delta[n] = i * det_ydim + j; n++; if (n >= 500) { sprintf(logger->tmptxt, "scatt_list length exceeded"); logger->logstat = logprint(logger, logger->tmptxt, 7); status = -1; goto exittrace; } } } } status = n; jmx_id->scatt_len = n; exittrace: 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); } int shapefold(int det[], float comb_list[], int comb_delta[], int comb_len, float det_out[], int last, struct log_con *logger) { /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* */ /* shapefold.c calculates the distribution of one photon */ /* arriving at "window" pixel (X,Y) among the neighboring */ /* pixels at the microstrip plate. */ /* */ /* Niels Lund, February 2003 */ /* */ /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ int i, j, k, sum1; double loss1; static int func_local = -1, local_calling_num=0; clock_t clock(void), calling_TT, TT_now; /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "shapefold"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ if (logger->trace) traces(func_local, 1, logger); for (i=0; i 1) { sum1++; for (j=0; j= detdim)) loss1 += comb_list[j]; else det_out[k] += comb_list[j]; } } } 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(sum1); } int sh_depth(float maskXmm, float maskYmm, float track_list[], int track_delta[], struct instr_data *jmx_id, struct log_con *logger) { /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* */ /* sh_depth calculates the penetration of X-rays down into */ /* the detector gas. sh_depth calculates which section of */ /* a given track which projects to a certain mm interval on */ /* the microstrip plate. Which sections are relevant at a */ /* given energy is calculated at the end of the routine. */ /* */ /* Niels Lund, February 2003 */ /* */ /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* * Version 1.5.4 060104 Calculate track lengths projecting to individual detector pixels for photons penetrating into the detector. The photon is assumed to come from a sky-direction corresponding to "(maskXmm, maskYmm)" and to enter the detector at detector pixel (0,0) at the window level. For calculation purposes each 1x1 mm2 detector pixel is subdivided into 4x4 subpixels. The first two array indices in the arrays "det_step", "track" and "kt_max" are the sub_pixel coords. The last index in "det_step" and "track" indicates the number of sequential wall crossings for the track going from pixel to pixel (1x1 mm2 pixels) as it penetrates down the depth of the detector. The last entry in these two arrays corresponds to the point where the track exits the bottom of the detector. The array "det_step" contains the 1x1 mm2 detector pixel coordinates for the traversed pixels. (actually the one-dmensional coordinate difference with respect to the entry point) The array "track" contains the corresponding track length (in mm) measured from the entry point at the window until the track leaves this detector pixel (entering another pixel or leaving through the detector bottom). kt_max is a control array holding the largest index value used for the third index of det_step and track (must be less than 16!) * 1.5.4 060104 Bug in sh_depth corrected, detectmap now in mm * 2.1.1 070918 SPR 4729: Floating Point Exception * 2.1.2 070920 SPR 4731: Missing inialization fixed * 2.1.3 070920 SPR 4734: Another issing inialization fixed * 2.1.4 070921 SPR 4736: Fixing use of isnan function * 2.1.5 070925 SPR 4737: Bad array dimensioning fixed */ int i, j, ix, iy, kx, ky, kt, ibot_x[4], ibot_y[4], max_kx[8], max_ky[8]; int k, m, n, kt_max[4][4], det_step[4][4][16], det_xy0, track_len=0, w; int status, i5 = 5; float track_l_x[8][4], track_l_y[8][4], t, alfa_x, alfa_y, proj_max_x, proj_max_y, wx, wy; float top_x[4], top_y[4], wallx_z[8][4], wally_z[8][4], full_track, bot_x[4], bot_y[4]; float track[4][4][16], escape, det_depth = -55.0, sky_x, sky_y; /* float driftY_tilt, driftX_tilt; */ float det[detdim]; static int func_local = -1, local_calling_num=0; clock_t clock(void), calling_TT, TT_now; /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "sh_depth"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ if (logger->trace) traces(func_local, 1, logger); det_xy0 = 128 * 256 + 128; /* 'jsign' has been eliminated. # 'jsign' is a criminal notion in the current j_ima_iros where # the ONLY!!! transformation to the external world comes after # all internal calculations are completed !!!. NL 5/10 2007 # # jsign = 1; # if (jemx == 0) jsign = -1; */ for (k=0; k<4; k++) { for (m=0; m<4; m++) { kt_max[k][m] = 0; for (n=0; n<16; n++) { track[k][m][n] = 0.0; det_step[k][m][n] = 0; } } } for (i=0; i<8; i++) { max_kx[i] = max_ky[i] = 0; } /* 2007 10 18 Experiment introducing drift tilt in the Y direction */ /* drift tilt given in mm for the whole detector thickness */ /* driftY_tilt = 2.0; sky_y = -maskYmm + driftY_tilt * jmx_id->mask_height / det_depth; */ /* sky-coordinates in a mm scale on the mask */ sky_x = -maskXmm; sky_y = -maskYmm; alfa_x = sky_x / jmx_id->mask_height; alfa_y = sky_y / jmx_id->mask_height; proj_max_x = alfa_x * det_depth; proj_max_y = alfa_y * det_depth; sprintf(logger->tmptxt, "At entry to sh_depth: mask_mm(X/Y): %6.1f %6.1f, proj_max(X/Y): %6.3f %6.3f", maskXmm, maskYmm, proj_max_x, proj_max_y); logger->logstat = logprint(logger, logger->tmptxt, i5); /* calculate depth (Z-coordinate) of intersection of sky line with X-coordinate boundaries */ /* max depth (negative!) is -55 mm */ ix = 0; for (i=-3; i<=3; i+=2) { /* loop over sub-pixel collumns */ kx = 0; wx = 0.5; top_x[ix] = (double)(i) / 8.0; bot_x[ix] = top_x[ix] + proj_max_x; ibot_x[ix] = (int)(bot_x[ix] + 256.5) - 256; /* itop_x is by definition allways 0 */ if (fabs(sky_x) < 0.001) { wallx_z[kx][0] = wallx_z[kx][1] = wallx_z[kx][2] = wallx_z[kx][3] = det_depth; max_kx[0] = max_kx[1] = max_kx[2] = max_kx[3] = 1; goto noshift_x; } more_kx: if (sky_x > 0) wallx_z[kx][ix] = -(wx + top_x[ix]) / alfa_x; else wallx_z[kx][ix] = (wx - top_x[ix]) / alfa_x; max_kx[ix] = kx + 1; if (max_kx[ix] > 8) { sprintf(logger->tmptxt, "sh_depth error return, max_kx[%3d]: %3d", ix, max_kx[ix]); logger->logstat = logprint(logger, logger->tmptxt, 7); status = -2; goto exittrace; } if (wallx_z[kx][ix] > det_depth) { kx++; wx += 1.0; if (kx < 8) goto more_kx; } wallx_z[kx][ix] = det_depth; ix++; } noshift_x: /* calculate depth (Z-coordinate) of intersection of sky line with Y-coordinate boundaries */ /* max depth (negative!) is -55 mm */ wy = 0.5; iy = 0; for (i=-3; i<=3; i+=2) { /* loop over sub-pixel rows */ ky = 0; wy = 0.5; top_y[iy] = (double)(i) / 8.0; bot_y[iy] = top_y[iy] + proj_max_y; ibot_y[iy] = (int)(bot_y[iy] + 256.5) - 256; /* itop_y is by definition allways 0 */ if (fabs(sky_y) < 0.001) { wally_z[ky][0] = wally_z[ky][1] = wally_z[ky][2] = wally_z[ky][3] = det_depth; max_ky[0] = max_ky[1] = max_ky[2] = max_ky[3] = 1; goto noshift_y; } more_ky: if (sky_y > 0) wally_z[ky][iy] = -(wy + top_y[iy]) / alfa_y; else wally_z[ky][iy] = (wy - top_y[iy]) / alfa_y; max_ky[iy] = ky + 1; if (max_ky[iy] > 8) {status = -3; goto exittrace;} if (wally_z[ky][iy] > det_depth) { ky++; wy += 1.0; if (ky < 8) goto more_ky; } wally_z[ky][iy] = det_depth; iy++; } noshift_y: /* calculate track length and (X,Y)-coordinates for each wall intersection */ full_track = sqrt((det_depth*det_depth) + (top_x[0]-bot_x[0])*(top_x[0]-bot_x[0]) + (top_y[0]-bot_y[0])*(top_y[0]-bot_y[0])); for (ix=0; ix<4; ix++) { /* loop over sub-pixel collums */ for (kx=0; kx 16) {status = -4; goto exittrace;} kt_max[i][j] = kt; if (t < full_track) goto igen; nextj: ; } } for (i=0; iabsolen); if (n == 0) det[det_xy0 + det_step[k][m][n]] += 1.0 - escape; else det[det_xy0 + det_step[k][m][n]] += exp(-track[k][m][n-1] / jmx_id->absolen) - escape; } } } track_len = 0; for (i=0; i 0.0) { track_list[track_len] = det[i] / 16.0; track_delta[track_len] = det_xy0 - i; /* sign inverted 4/2 2003 nl */ track_len++; if (track_len > 100) { sprintf(logger->tmptxt, "More than 100 track entries"); logger->logstat = logprint(logger, logger->tmptxt, 7); status = -5; goto exittrace; } } } status = track_len; exittrace: 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 */ sprintf(logger->tmptxt, "Before return from sh_depth: track_len: %3d", track_len); logger->logstat = logprint(logger, logger->tmptxt, i5); return(status); } int shapecomb(float track_list[], int track_delta[], int track_len, float comb_list[], int comb_delta[], struct log_con *logger, struct instr_data *jmx_id) /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* */ /* shapecomb.c combines the output from a "smearing" subroutine: */ /* sh_depth.c [track_list/_delta] and a penetration subroutine: */ /* sh_xy.c [scatt_list/_delta] and forms the combined smearing effect */ /* in [comb_list/_delta] to be applied to the idealized shadowgram */ /* generated by detectmap.c */ /* */ /* Niels Lund, February 2003 */ /* */ /* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ { int i, j, k, n, i0, i1, status; float temp[detdim]; static int func_local = -1, local_calling_num=0; clock_t clock(void), calling_TT, TT_now; /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "shapecomb"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ if (logger->trace) traces(func_local, 1, logger); for (i=0; i 0.0) { for (j=0; jscatt_len; j++) { k = 32768 + i + jmx_id->scatt_delta[j]; temp[k] += temp[i] * jmx_id->scatt_list[j]; } } } n = 0; i1 = i0 + 32768; for (i=32768; i 0.0) { comb_list[n] = temp[i]; comb_delta[n] = i - i1; n++; if (n > 1000) { sprintf(logger->error_text, "comb_len > 1000 in subr. shapecomb"); status = -1; goto exittrace; } } } status = n; exittrace: 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); } int sign(int x, struct log_con *logger) /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* */ /* sign.c returns +1 for positive integers and -1 for */ /* negative integers. */ /* */ /* Niels Lund, February 2003 */ /* */ /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ { static int func_local = -1, local_calling_num=0; clock_t clock(void), calling_TT, TT_now; /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "sign"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ /* 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 */ if (x) return(x/abs(x)); return(1); } /* * 1.5.2 060726 Moved declaration of MaskSS structure to alignment_init * Placed pointer to 'struct MaskSS' in struct 'instr_data'. * Eliminated 'struct MaskSS *mss' as parameter in 'struchk'. */ /* void s_turn(double xin, double yin, double angle, double *xout, double *yout, int prin, struct log_con *logger, struct MaskSS *mss); void bar(double endx[2], double endy[2], double w, int mark, struct log_con *logger, struct MaskSS *mss); void ring(double ri, double ro, int mark, struct log_con *logger, struct MaskSS *mss); void bolt(double xc, double yc, double r, int mark, int prin, struct log_con *logger, struct MaskSS *mss); */ /* *************************************************************** */ void struktu( struct log_con *logger, struct MaskSS *mss) { int i, j, k, mark; double onax; static int func_local = -1, local_calling_num=0; clock_t clock(void), calling_TT, TT_now; /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "struktu"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ if (logger->trace) traces(func_local, 1, logger); mark = 1; /* mark for wide shadow border */ ring(mss->ringri2[0], mss->ringro2[0], mark, logger, mss); /* ring 1 shadow region (check at 21 mm) */ mark = 0; /* mark for narrow shadow border */ ring(mss->ringri2[1], mss->ringro2[1], mark, logger, mss); /* ring 2 shadow region (check at 10 mm) */ ring(mss->ringri2[2], mss->ringro2[2], mark, logger, mss); /* ring 3 shadow region (check at 10 mm) */ for (i=0; i<6; i++) { mark = 1; /* mark for wide shadow border */ bar(mss->longspx[i], mss->longspy[i], mss->longspw2, mark, logger, mss); bolt(mss->bolt1x[i], mss->bolt1y[i], mss->bolt1s, mark, 1, logger, mss); bolt(mss->bolt2x[i], mss->bolt2y[i], mss->bolt2s, mark, 1, logger, mss); mark = 0; /* mark for narrow shadow border */ bolt(mss->bolt3x[i], mss->bolt3y[i], mss->bolt3s, mark, 1, logger, mss); bar(mss->shortspx[i], mss->shortspy[i], mss->shortspw2, mark, logger, mss); bolt(mss->joint1x[i], mss->joint1y[i], mss->joint1r2, mark, 1, logger, mss); bolt(mss->joint2x[i], mss->joint2y[i], mss->joint2r2, mark, 1, logger, mss); } mark = 64; /* mark for exclusion */ ring(mss->ringri[0], mss->ringro[0], mark, logger, mss); /* mark ring 1 in struk array (excluded) */ mark = 32; /* mark for exclusion at 10 mm */ ring(mss->ringri[1], mss->ringro[1], mark, logger, mss); /* mark ring 2 (exclude at 10 mm) */ ring(mss->ringri[2], mss->ringro[2], mark, logger, mss); /* mark ring 3 (exclude at 10 mm) */ for (i=0; i<6; i++) { mark = 64; /* mark for exclusion */ bar(mss->longspx[i], mss->longspy[i], mss->longspw, mark, logger, mss); bolt(mss->bolt1x[i], mss->bolt1y[i], mss->bolt1r, mark, 1, logger, mss); bolt(mss->bolt2x[i], mss->bolt2y[i], mss->bolt2r, mark, 1, logger, mss); mark = 32; /* mark solid regions for exclusion at 10 mm) */ bar(mss->shortspx[i], mss->shortspy[i], mss->shortspw, mark, logger, mss); bolt(mss->joint1x[i], mss->joint1y[i], mss->joint1r, mark, 1, logger, mss); bolt(mss->joint2x[i], mss->joint2y[i], mss->joint2r, mark, 1, logger, mss); bolt(mss->bolt3x[i], mss->bolt3y[i], mss->bolt3r, mark, 1, logger, mss); } k = 0; for (i=-250; i<250; i++) { for (j=-250; j<250; j++) { if ((i*i+j*j) > 62500) continue; if (mss->struk[550+i][550+j] >= 32) k++; } } onax = (double)(k) / (3.14159 * 250.0 * 250.0); /* sprintf(logger->tmptxt, "\nOn-axis blocking by support structure: %6.3lf", onax); logger->logstat = logprint(logger, logger->tmptxt, logger->0); strucpr2(1, 0, mss); strucpr2(1, 250, mss); strucpr2(2, 0, mss); strucpr2(2, 150, mss); strucpr2(2, 300, mss); strucpr2(2, 400, mss); strucpr2(4, 0, mss); strucpr2(8, 0, mss); */ 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; } /* *************************************************************** */ void bar(double endx[2], double endy[2], double w, int mark, struct log_con *logger, struct MaskSS *mss) { int i, j; double length, xv, yv, dx, dy, r, rin, rout; static int func_local = -1, local_calling_num=0; clock_t clock(void), calling_TT, TT_now; /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "bar"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ if (logger->trace) traces(func_local, 1, logger); length = sqrt((endx[0]-endx[1])*(endx[0]-endx[1]) + (endy[0]-endy[1])*(endy[0]-endy[1])); rin = sqrt(endx[0]*endx[0] + endy[0]*endy[0]); rout = sqrt(endx[1]*endx[1] + endy[1]*endy[1]); /* sprintf(logger->tmptxt, "Bar length: %7.2lf, rin: %7.2lf, rout: %7.2lf, endxy: %7.2lf/%7.2lf", length, rin, rout, endx[0], endy[0]); logger->logstat = logprint(logger, logger->tmptxt, 0); */ r = w / 2.0; j = length / 0.5 + 1; dx = (endx[0]-endx[1]) / j; dy = (endy[0]-endy[1]) / j; for (i=0; i<=j; i++) { xv = endx[1] + i * dx; yv = endy[1] + i * dy; bolt(xv, yv, r, mark, 0, logger, mss); } /* strucprint((endx[0]+endx[1])/2.0, (endy[0]+endy[1])/2.0, mss); */ 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; } /* *************************************************************** */ void ring(double ri, double ro, int mark, struct log_con *logger, struct MaskSS *mss) { int ix, iy, xlow, xhigh, ylow, yhigh, n; double xv, yv, dn = 0.0, rc, rv; static int func_local = -1, local_calling_num=0; clock_t clock(void), calling_TT, TT_now; /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "ring"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ if (logger->trace) traces(func_local, 1, logger); xlow = 550 - ro * 2.0; xhigh = 550 + ro * 2.0; ylow = 550 - ro * 2.0; yhigh = 550 + ro * 2.0; rc = (ri + ro) / 2.0; if (xlow < 0) xlow = 0; if (xhigh > 1099) xhigh = 1099; if (ylow < 0) ylow = 0; if (yhigh > 1099) yhigh = 1099; n = 0; for (ix=xlow; ix<=xhigh; ix++) { for (iy=ylow; iy<=yhigh; iy++) { xv = (double)(ix - 550) / 2.0; yv = (double)(iy - 550) / 2.0; if (circle(dn, dn, ro, xv, yv, &rv, logger, mss) == 1) { if (rv > ri) { if (mark <= 1) mss->struk[ix][iy] = strukupdate(xv, yv, rv, logger, mss) + mark; if (mark > 1) mss->struk[ix][iy] = mark; n++; } } } } /* strucprint(rc, 0.0, mss); strucprint(0.0, rc, mss); strucprint(-rc, 0.0, mss); strucprint(0.0, -rc, mss); */ /* sprintf(logger->tmptxt, "Ring: ri/ro: %6.2lf/%6.2lf, number of affected pixels: %6d, mark: %1d", ri, ro, n, mark); logger->logstat = logprint(logger, logger->tmptxt, 0); */ 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; } /* *************************************************************** */ void bolt(double xc, double yc, double r, int mark, int prin, struct log_con *logger, struct MaskSS *mss) { int ix, iy, ixlow, ixhigh, iylow, iyhigh; double xv, yv, rv, rb; static int func_local = -1, local_calling_num=0; clock_t clock(void), calling_TT, TT_now; /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "bolt"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ ixlow = (xc - r) * 2.0 + 550.0; ixhigh = (xc + r) * 2.0 + 550.0; iylow = (yc - r) * 2.0 + 550.0; iyhigh = (yc + r) * 2.0 + 550.0; if (ixlow < 0) ixlow = 0; if (ixhigh > 1099) ixhigh = 1099; if (iylow < 0) iylow = 0; if (iyhigh > 1099) iyhigh = 1099; for (ix=ixlow; ix<=ixhigh; ix++) { for (iy=iylow; iy<=iyhigh; iy++) { xv = (double)(ix - 550) / 2.0; yv = (double)(iy - 550) / 2.0; if (circle(xc, yc, r, xv, yv, &rb, logger, mss) == 1) { if (mark > 1) mss->struk[ix][iy] = mark; if (mark <= 1) { rv = sqrt(xv*xv + yv*yv); mss->struk[ix][iy] = strukupdate(xv, yv, rv, logger, mss) + mark; } } } } /* if (prin == 1) strucprint(xc, yc, mss); */ /* 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; } /* *************************************************************** */ int circle(double xc, double yc, double r, double x, double y, double *rv, struct log_con *logger, struct MaskSS *mss) { int inside; static int m=0; static int func_local = -1, local_calling_num=0; clock_t clock(void), calling_TT, TT_now; /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "circle"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ inside = 0; if ((*rv = sqrt((x-xc)*(x-xc) + (y-yc)*(y-yc))) <= r) inside = 1; m++; /* if (m < 1000) { sprintf(logger->tmptxt, "Circle: m: %3d, xc/yc: %5.1lf/%5.1lf, r: %5.1lf, x/y: %6.1lf/%6.1lf, inside: %1d", m, xc, yc, r, x, y, inside); logger->logstat = logprint(logger, logger->tmptxt, 0); } */ /* 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(inside); } /* *************************************************************** */ void strukdef( struct log_con *logger, struct MaskSS *mss) { int i, j, prin; double ta; static int func_local = -1, local_calling_num=0; clock_t clock(void), calling_TT, TT_now; /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "strukdef"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ if (logger->trace) traces(func_local, 1, logger); mss->twist = -4.286; /* twist angle for entire support structure */ mss->r_twist = mss->twist * mss->gtorad; mss->pi6 = mss->pi / 6.0; for (i=0; i<1100; i++) for (j=0; j<1100; j++) mss->struk[i][j] = 0; if (logger->trace) traces(func_local, 2, logger); mss->ringri[0] = 45.0; /* inner radius of ring 1 */ mss->ringro[0] = 48.0; /* outer radius of ring 1 */ mss->ringri2[0] = 45.0 - 3.5; /* inner radius of shadow region */ mss->ringro2[0] = 48.0 + 3.5; /* outer radius of shadow region */ mss->ringri[1] = 114.9; /* inner radius of ring 2 */ mss->ringro[1] = 117.1; /* outer radius of ring 2 */ mss->ringri2[1] = 114.9 - 1.7; /* inner radius of shadow region */ mss->ringro2[1] = 117.1 + 1.7; /* outer radius of shadow region */ mss->ringri[2] = 210.0; /* inner radius of ring 3 */ mss->ringro[2] = 212.2; /* outer radius of ring 3 */ mss->ringri2[2] = 210.0 - 1.7; /* inner radius of shadow region */ mss->ringro2[2] = 212.2 + 1.7; /* outer radius of shadow region */ mss->rx[0] = (mss->ringri[0] + mss->ringro[0]) / 2.0; mss->rx[1] = (mss->ringri[1] + mss->ringro[1]) / 2.0; mss->rx[2] = (mss->ringri[2] + mss->ringro[2]) / 2.0; mss->rx[3] = 267.5; /* NOTE: the initial coordinates are not yet twisted by -4.286 degrees ! */ mss->longspx[0][0] = 46.5; /* inner end of long spoke */ mss->longspx[0][1] = 268.0; /* outer end of long spoke */ mss->longspy[0][0] = 0.0; /* inner end of long spoke */ mss->longspy[0][1] = 0.0; /* outer end of long spoke */ mss->longspw = 2.2; /* width of long spoke */ mss->longspw2 = 2.2 + 7.0; /* width of long spoke shadow */ mss->longsph = 21.25; /* height of long spoke */ mss->offs_lsp = 30.0 + mss->twist; /* angular offset of first long spoke */ mss->shortspx[0][0] = 116.0; /* inner end of short spoke */ mss->shortspx[0][1] = 211.0; /* outer end of short spoke */ mss->shortspy[0][0] = 0.0; /* inner end of short spoke */ mss->shortspy[0][1] = 0.0; /* outer end of short spoke */ mss->shortspw = 2.2; /* width of short spoke */ mss->shortspw2 = 2.2 + 3.4; /* width of shadow region */ mss->shortsph = 10.25; /* height of short spoke */ mss->offs_ssp = 0.0 + mss->twist; /* angular offset of first short spoke */ mss->bolt1x[0] = 49.5; /* x coordinate of bolt1 */ mss->bolt1y[0] = 0.0; /* y coordinate of bolt1 */ mss->bolt1r = 4.5; /* radius of bolt1 */ mss->bolt1s = 4.5 + 3.5; /* radius of bolt1 shadow */ mss->offs_b1 = 30.0 + mss->twist; /* angular offset of first bolt in 1. bolt set */ mss->bolt2x[0] = 116.0; /* x coordinate of bolt2 */ mss->bolt2y[0] = 0.0; /* y coordinate of bolt2 */ mss->bolt2r = 4.5; /* radius of bolt */ mss->bolt2s = 4.5 + 3.5; /* radius of bolt2 shadow */ mss->offs_b2 = 30.0 + mss->twist; /* angular offset of first bolt in 2. bolt set */ mss->bolt3x[0] = 211.4; /* x coordinate of bolt3 */ mss->bolt3y[0] = 0.0; /* y coordinate of bolt3 */ mss->bolt3r = 3.5; /* radius of bolt */ mss->bolt3s = 3.5 + 3.5; /* radius of bolt3 shadow */ mss->offs_b3 = 0.0 + mss->twist; /* angular offset of first bolt in 3. bolt set */ mss->joint1x[0] = 211.4; /* x coordinate of joint1 */ mss->joint1y[0] = 0.0; /* y coordinate of joint1 */ mss->joint1r = 3.34; /* radius of joint1 */ mss->joint1r2 = 3.34 + 1.7; /* outer radius of shadow region */ mss->offs_j1 = 30.0 + mss->twist; /* angular offset of first joint in 1. joint set */ mss->joint2x[0] = 117.1; /* x coordinate of joint2 */ mss->joint2y[0] = 0.0; /* y coordinate of joint2 */ mss->joint2r = 2.5; /* radius of joint2 */ mss->joint2r2 = 2.5 + 1.7; /* radius of shadow region */ mss->offs_j2 = 0.0 + mss->twist; /* angular offset of first joint in 2. joint set */ for (j=1; j<7; j++) { i = j % 6; ta = 60.0 * i; /* if ((i%3) == 0) prin = 1; else prin = 0; */ s_turn(mss->longspx[0][0], mss->longspy[0][0], ta+mss->offs_lsp, &mss->longspx[i][0], &mss->longspy[i][0], prin, logger, mss); s_turn(mss->longspx[0][1], mss->longspy[0][1], ta+mss->offs_lsp, &mss->longspx[i][1], &mss->longspy[i][1], prin, logger, mss); /* len = sqrt((mss->longspx[i][0]-mss->longspx[i][1]) * (mss->longspx[i][0]-mss->longspx[i][1]) + (mss->longspy[i][0]-mss->longspy[i][1]) * (mss->longspy[i][0]-mss->longspy[i][1])); sprintf(logger->tmptxt, "long %1d: x1/y1: %7.2lf/%7.2lf, x2/y2: %7.2lf/%7.2lf, length: %7.2lf", i, mss->longspx[i][0], mss->longspy[i][0], mss->longspx[i][1], mss->longspy[i][1], len); logger->logstat = logprint(logger, logger->tmptxt, 0); */ s_turn(mss->shortspx[0][0], mss->shortspy[0][0], ta+mss->offs_ssp, &mss->shortspx[i][0], &mss->shortspy[i][0], prin, logger, mss); s_turn(mss->shortspx[0][1], mss->shortspy[0][1], ta+mss->offs_ssp, &mss->shortspx[i][1], &mss->shortspy[i][1], prin, logger, mss); /* len = sqrt((mss->shortspx[i][0]-mss->shortspx[i][1]) * (mss->shortspx[i][0]-mss->shortspx[i][1]) + (mss->shortspy[i][0]-mss->shortspy[i][1]) * (mss->shortspy[i][0]-mss->shortspy[i][1])); sprintf(logger->tmptxt, "short %1d: x1/y1: %7.2lf/%7.2lf, x2/y2: %7.2lf/%7.2lf, length: %7.2lf", i, mss->shortspx[i][0], mss->shortspy[i][0], mss->shortspx[i][1], mss->shortspy[i][1], len); logger->logstat = logprint(logger, logger->tmptxt, 0); */ prin = 0; s_turn(mss->bolt1x[0], mss->bolt1y[0], ta+mss->offs_b1, &mss->bolt1x[i], &mss->bolt1y[i], prin, logger, mss); s_turn(mss->bolt2x[0], mss->bolt2y[0], ta+mss->offs_b2, &mss->bolt2x[i], &mss->bolt2y[i], prin, logger, mss); s_turn(mss->bolt3x[0], mss->bolt3y[0], ta+mss->offs_b3, &mss->bolt3x[i], &mss->bolt3y[i], prin, logger, mss); s_turn(mss->joint1x[0], mss->joint1y[0], ta+mss->offs_j1, &mss->joint1x[i], &mss->joint1y[i], prin, logger, mss); s_turn(mss->joint2x[0], mss->joint2y[0], ta+mss->offs_j2, &mss->joint2x[i], &mss->joint2y[i], prin, logger, mss); } struktu(logger, mss); /* build structure image array */ 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; } /* *************************************************************** */ void s_turn(double xin, double yin, double angle, double *xout, double *yout, int prin, struct log_con *logger, struct MaskSS *mss) { double sin_a, cos_a; static int func_local = -1, local_calling_num=0; clock_t clock(void), calling_TT, TT_now; /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "s_turn"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ /* if (logger->trace) traces(func_local, 1, logger); */ sin_a = sin(angle*mss->gtorad); cos_a = cos(angle*mss->gtorad); *xout = cos_a * xin - sin_a * yin; *yout = cos_a * yin + sin_a * xin; if (prin == 1) { sprintf(logger->tmptxt, "angle: %6.2lf, sin %6.4lf, cos %6.4lf, x/y in: %6.2lf/%6.2lf, x/y out: %6.2lf/%6.2lf", angle, sin_a, cos_a, xin, yin, *xout, *yout); logger->logstat = logprint(logger, logger->tmptxt, 5); } /* 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; } /* *************************************************************** */ void strucprint(double offx, double offy, struct log_con *logger, struct MaskSS *mss) { int i, j, s_offi, s_offj; char princhar; static int func_local = -1, local_calling_num=0; clock_t clock(void), calling_TT, TT_now; /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "strukprint"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ if (logger->trace) traces(func_local, 1, logger); s_offi = 550 + (int)(offy * 2.0 + 0.5); s_offj = 550 + (int)(offx * 2.0 + 0.5); if (s_offi < 21) s_offi = 21; if (s_offi > 1078) s_offi = 1078; if (s_offj < 64) s_offj = 64; if (s_offj > 1035) s_offj = 1035; sprintf(logger->tmptxt, "offx: %7.1lf, offy: %7.1lf, off_ix: %5d, off_iy: %5d\n", offx, offy, s_offi, s_offj); logger->logstat = logprint(logger, logger->tmptxt, 5); for (i=21; i>=-21; i--) { logger->tmptxt[0] = 0; for (j=-64; j<=64; j++) { if (mss->struk[s_offj+j][s_offi+i] < 10) princhar = '0' + mss->struk[s_offj+j][s_offi+i]; else princhar = 'A' + mss->struk[s_offj+j][s_offi+i] - 10; sprintf(logger->tmptxt2, "%1c", princhar); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); /* if (mss->struk[s_offj+j][s_offi+i] > 0) sprintf(logger->tmptxt2, "%1x", mss->struk[s_offj+j][s_offi+i]); else sprintf(logger->tmptxt2, "."); */ } sprintf(logger->tmptxt2, " "); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); logger->logstat = logprint(logger, logger->tmptxt, 5); } sprintf(logger->tmptxt, " "); logger->logstat = logprint(logger, logger->tmptxt, 5); /* 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 */ } /* *************************************************************** */ void strucpr2(int step, int off, struct log_con *logger, struct MaskSS *mss) { int i, j, s_offi, s_offj; char princhar; static int func_local = -1, local_calling_num=0; clock_t clock(void), calling_TT, TT_now; /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "strukpr2"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ s_offi = 550 + off; s_offj = 550; if (s_offi < 64*step) s_offi = 64 * step; if (s_offi > (1099 - 64*step)) s_offi = 1099 - 64*step; if (s_offj < 64*step) s_offj = 64 * step; if (s_offj > (1099 - 64*step)) s_offj = 1099 - 64*step; sprintf(logger->tmptxt, "offx: 0.0, offy: 0.0, off_ix: 550, off_iy: 550, step: %2d \n", step); logger->logstat = logprint(logger, logger->tmptxt, 5); for (i=64*step; i>=-64*step; i-=step) { logger->tmptxt[0] = 0; for (j=-64*step; j<=64*step; j+=step) { if (mss->struk[s_offj+j][s_offi+i] < 10) princhar = '0' + mss->struk[s_offj+j][s_offi+i]; else if (mss->struk[s_offj+j][s_offi+i] < 64) princhar = 'A' + (mss->struk[s_offj+j][s_offi+i] & 0x1F) - 10; else princhar = '¤'; if (mss->struk[s_offj+j][s_offi+i] == 0) { princhar = ' '; if (((i/step) % 16) == 0) princhar = '-'; if (((j/step) % 16) == 0) princhar = '|'; } sprintf(logger->tmptxt2, "%1c", princhar); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); /* if (mss->struk[s_offj+j][s_offi+i] > 0) sprintf(logger->tmptxt, "%1x", mss->struk[s_offj+j][s_offi+i]); else sprintf(logger->tmptxt, "."); */ } sprintf(logger->tmptxt2, " "); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); logger->logstat = logprint(logger, logger->tmptxt, 5); } sprintf(logger->tmptxt, "\n"); logger->logstat = logprint(logger, logger->tmptxt, 5); 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 */ } /* *************************************************************** */ int strukupdate(double xv, double yv, double rv, struct log_con *logger, struct MaskSS *mss) { int m6, m12; static int func_local = -1, local_calling_num=0; clock_t clock(void), calling_TT, TT_now; /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "strukupdate"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ if (rv < mss->rx[0]) { /* 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(0); } m12 = (atan2(yv, xv) + mss->twopi - mss->r_twist) / mss->pi6; m12 %= 2; m6 = (atan2(yv, xv) + mss->twopi - mss->r_twist - mss->pi6) / (mss->pi6 * 2.0); m6 %= 2; /* 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 */ /* if (rv < mss->rx[1]) return(8 + m6); if (rv < mss->rx[2]) return(16 + m12); if (rv < mss->rx[3]) return(32 + m6); */ if (rv < mss->rx[1]) return(2+2*m6); if (rv < mss->rx[2]) return(8+8*m12); if (rv < mss->rx[3]) return(2+2*m6); return(0); } /* *************************************************************** */ int struchk(double xm, double ym, double x_det, double y_det, int last, struct instr_data *jmx_id, struct log_con *logger) /* The "struk" array contains information about the mask support structure and its shadowing of the mask. The array covers a 550x550 mm2 area with pixels of 0.5x0.5 mm2. The access tests should be done in the following order: 1) calculate intersection of ray with the mask plane. Find corresponding pixel in the "struk" array. 2) If the pixel value is 0 access is allowed along this path (in open areas between structural members) 3) If the pixel value is >= 32 access is forbidden along this path (hit solid structure or mask elim. hole) 4) If the pixel value is >0 and <32: (in potential shadow area close to a structural member) 4a) If the pixel value is odd, (close to a structural member of 21 mm height) Calculate intersection points of this photon with two leves at +/- 21.25 mm 4b) If the pixel value is even, (close to a structural member of 10 mm height) Calculate intersection points of this photon with two leves at +/- 10.25 mm 5) If the pixel value in any of the two new points is 64 access is forbidden. (hit solid structure) 6) If the pixel value in any of the two new points is 32 and the first pixel value was even, access is forbidden. (hit solid structure) 7) If the pixel value in both of the two new points is >= 0 and the two values are different, access is forbidden. (traverse solid structure) 8) Otherwise access is allowed. The following symbols are used in the pixels of struk: 0: free access, no further tests are required. 32: access blocked by solid material in mask support structure of 10.25 mm height. 64: access blocked by solid material in mask support structure of 21.25 mm height. 1, 3, 5, 7, 9: 17: Photon close to high structure. Test required at plus/minus 21.25 mm from the mask plane. 2, 4, 6, 8, 16: Photon close to low structure. Test required at plus/minus 10.25 mm from the mask plane. */ { int i, j, ix, iy, ixb, iyb, ixu, iyu, sbval, suval; double xb, yb, xu, yu, dxl, dyl, dxh, dyh, xdif, ydif; static int p_count[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, first = 1; static int func_local = -1, local_calling_num=0; clock_t clock(void), calling_TT, TT_now; struct MaskSS *mss; /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "struchk"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ mss = jmx_id->mss; if (first) { strukdef(logger, mss); /* initialize structure definitions */ first = 0; } xb = xu = xm * 2.0 + 550.5; yb = yu = ym * 2.0 + 550.5; xdif = xm - x_det; ydif = ym - y_det; dxl = xdif * 2.0 * mss->shortsph / jmx_id->mask_height; dyl = ydif * 2.0 * mss->shortsph / jmx_id->mask_height; dxh = xdif * 2.0 * mss->longsph / jmx_id->mask_height; dyh = ydif * 2.0 * mss->longsph / jmx_id->mask_height; ix = xb; iy = yb; if ((ix < 0) || (ix > 1099) || (iy < 0) || (iy > 1099)) { sprintf(logger->tmptxt, "ix/iy outside limits: %4d/%4d, x/y_mask: %6.2f/%6.2f, x/y_det: %6.2f/%6.2f", ix, iy, xm, ym, x_det, y_det); logger->logstat = logprint(logger, logger->tmptxt, 6); ix = iy = 0; } i = 0; if (mss->struk[ix][iy] == 0) { if (last) p_count[7]++; goto retu; /* in open areas between structural members */ } i = 1; if (mss->struk[ix][iy] >= 32) { if (last) p_count[0]++; goto retu; /* hit solid structure */ } if ((mss->struk[ix][iy]%2) == 0) { /* struk value is even - close to a structural member of 10 mm height */ xb -= dxl; yb -= dyl; ixb = xb; iyb = yb; if ((ixb < 0) || (ixb > 1099) || (iyb < 0) || (iyb > 1099)) { sprintf(logger->tmptxt, "ixb/iyb outside limits: %4d/%4d, x/y_mask: %6.2f/%6.2f, x/y_det: %6.2f/%6.2f", ixb, iyb, xm, ym, x_det, y_det); logger->logstat = logprint(logger, logger->tmptxt, 6); ixb = iyb = 0; } sbval = mss->struk[ixb][iyb]; if (sbval >= 32) { if (last) p_count[1]++; goto retu; /* hit solid structure */ } xu += dxl; yu += dyl; ixu = xu; iyu = yu; if ((ixu < 0) || (ixu > 1099) || (iyu < 0) || (iyu > 1099)) { sprintf(logger->tmptxt, "ixu/iyu outside limits: %4d/%4d, x/y_mask: %6.2f/%6.2f, x/y_det: %6.2f/%6.2f", ixu, iyu, xm, ym, x_det, y_det); logger->logstat = logprint(logger, logger->tmptxt, 6); ixu = iyu = 0; } suval = mss->struk[ixu][iyu]; if (suval >= 32) { if (last) p_count[2]++; goto retu; /* hit solid structure */ } if ((sbval > 0) && (suval > 0) && ((sbval&0xffe) != (suval&0xffe))) { if (last) p_count[3]++; goto retu; /* traverse structure */ } } else { /* struk value is odd - close to a structural member of 21 mm height */ xb = xu = xm * 2.0 + 550.5; yb = yu = ym * 2.0 + 550.5; xb -= dxh; yb -= dyh; ixb = xb; iyb = yb; if ((ixb < 0) || (ixb > 1099) || (iyb < 0) || (iyb > 1099)) { sprintf(logger->tmptxt, "ixb/iyb2 outside limits: %4d/%4d, x/y_mask: %6.2f/%6.2f, x/y_det: %6.2f/%6.2f", ixb, iyb, xm, ym, x_det, y_det); logger->logstat = logprint(logger, logger->tmptxt, 6); ixb = iyb = 0; } sbval = mss->struk[ixb][iyb]; if (sbval >= 64) { if (last) p_count[4]++; goto retu; /* hit solid structure */ } xu += dxh; yu += dyh; ixu = xu; iyu = yu; if ((ixu < 0) || (ixu > 1099) || (iyu < 0) || (iyu > 1099)) { sprintf(logger->tmptxt, "ixu/iyu2 outside limits: %4d/%4d, x/y_mask: %6.2f/%6.2f, x/y_det: %6.2f/%6.2f", ixu, iyu, xm, ym, x_det, y_det); logger->logstat = logprint(logger, logger->tmptxt, 6); ixu = iyu = 0; } suval = mss->struk[ixu][iyu]; if (suval >= 64) { if (last) p_count[5]++; goto retu; /* hit solid structure */ } if ((sbval > 0) && (suval > 0) && ((sbval&0xffe) != (suval&0xffe))) { if (last) p_count[6]++; goto retu; /* traverse structure */ } } if (last) p_count[8]++; i = 0; retu: if (last < 2) { /* 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 */ if (i > 0) return(1); else return(0); } sprintf(logger->tmptxt, "Strukdef statistics:"); logger->logstat = logprint(logger, logger->tmptxt, 5); sprintf(logger->tmptxt, " msk_level low_under low_over low_trav hgh_under hgh_over hgh_trav init_OK final_OK"); logger->logstat = logprint(logger, logger->tmptxt, 5); logger->tmptxt[0] = 0; for (j=0; j<9; j++) { sprintf(logger->tmptxt2, "%8d ", p_count[j]); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); p_count[j] = 0; } sprintf(logger->tmptxt2, " "); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); logger->logstat = logprint(logger, logger->tmptxt, 5); /* 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 */ if (i > 0) return(1); else return(0); } int hexpos(double xmask, double ymask, int nnn[4], double hexa_dim) /* routine to find which mask cell hexagon corresponds to (xmask, ymask) */ { float qmask, vmask, umask, yyvc, sqrt3; int iq, iv, iu, nn, iyvc; int iqh[3], ivh[3], iuh[3], iqc = 0, ivc = 0, iuc = 0; int iorder, nr, ma, ntal, m; static int first=1, maskhole[22501]; static double hexa_half, sin60, cos60, cot60, rsin60; if (first) { first = 0; /* generate basic ideal mask pattern (not including production modifications) */ iorder = 22501; /* prime number of type: 4u + 1 */ nr = 1133; /* prime number used for shift between lines in mask array */ for (m=0; m= dim ) continue; swap = a[i*dim + j]; a[i*dim + j] = a[j*dim + i]; a[j*dim + i] = swap; } } } /************************************************************************** JEMXLIBgetInstrData * Version of source file: 2.1.0 A member of the INTEGRAL/JEMX specific library 2006-05-24/NJW Built as a combination of jemxlib_get_iros_imod_data and ../j_ima_iros/j_iir_dpos_attlen 2007-06-27/NJW The reading of the pixelfold data has been included. The version 1.8.0 will replace JEMXLIBgetIrosImodData and alignment_init in j_ima_iros. Niels J. Westergaard Danish National Space Center Juliane Maries Vej 30 DK 2100 Copenhagen Denmark Email: njw@spacecenter.dk This version replaces 'alignment_init' used in j_ima_iros alignment_init calls JEMXLIBgetIrosImodData and executes the five statements: jmx_id->coll_wb += jmx_id->coll_w; jmx_id->alfa *= GTORAD; jmx_id->beta *= GTORAD; jmx_id->gammav *= GTORAD; jmx_id->mm2rad = 1. / jmx_id->mask_height; that are included here ************************************************************************/ int JEMXLIBgetInstrData( char *instMod, /* DOL of IMOD group */ dal_element *ptr_instMod, /* Pointer to IMOD group */ Instrument jemxNum, /* JMX1 or JMX2 */ struct instr_data *jmx_id, /* holds the instrument data */ struct log_con *logger, /* log control parameters */ int chatter, int status) { dal_element *ptr_IROS = NULL; dal_element *elemPtr = NULL; /* DS Pointer */ dal_dataType dalType; unsigned char cbuffer[20000]; char jemxStr[5]; char structName[DS_NAME_SIZE]; char keyword[9]; int loop = 0; int j = 0; int k = 0; long i = 0; long istart = 0; long numRows = 0; long buffSize = 0; long startBin = 0; long endBin = 0; long numValues = 0; long startValues[2] = {1,1}; long endValues[2] = {256,256}; float *e_min = NULL; float *e_max = NULL; float *energy_pos = NULL; float *energy_att = NULL; float *energy_qef = NULL; float *cposres = NULL; float *bposres = NULL; float *attlen_xe = NULL; float *quanteff = NULL; float result = 0.0; double dtmp = 0.0; /* * MaskSS to be declared static; carried over from alignment_init */ static struct MaskSS MSS; static int func_local = -1, local_calling_num=0; clock_t calling_TT, TT_now; if( status != ISDC_OK ) return( status ); RILlogMessage( NULL, Log_0, "##748a## status = %d", status ); jmx_id->mss = &MSS; RILlogMessage( NULL, Log_0, "##748b## status = %d", status ); /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; logger->func_calling_num = 0; sprintf(logger->func_names[func_local], "JEMXLIBgetInstrData"); if (logger->func_used_num > J_IIR_MAX_NUM_FUNCS) { sprintf(logger->tmptxt, "func_used_num > %d", J_IIR_MAX_NUM_FUNCS); logger->logstat = logprint(logger, logger->tmptxt, 6); logger->func_used_num = J_IIR_MAX_NUM_FUNCS; } } logger->func_calls[func_local]++; RILlogMessage( NULL, Log_0, "##748c## status = %d", status ); 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); RILlogMessage( NULL, Log_0, "##748d## status = %d", status ); /* * Initialize */ if( jemxNum == JMX1 ) { strcpy( jemxStr, "JMX1" ); } else { strcpy( jemxStr, "JMX2" ); } RILlogMessage( NULL, Log_0, "##748e## status = %d", status ); if( ptr_instMod == NULL ) { /* * Open the -IMOD-GRP */ RILlogMessage( NULL, Log_0,"##511## The -IMOD-GRP to open: %s", instMod); status = DALobjectOpen(instMod, &ptr_instMod, status); if( status != ISDC_OK ) goto exittrace; /* On error: jump to end */ if( chatter > J_CHATTY_NORMAL ) { RILlogMessage( NULL, Log_0,"##512## The INST MOD group has now been opened"); } } strcpy( structName, jemxStr ); strcat( structName, "-IROS-MOD" ); RILlogMessage( NULL, Log_0, "##748f## status = %d", status ); status = DALobjectFindElement( ptr_instMod, structName, &ptr_IROS, status); if( status != ISDC_OK ) { RILlogMessage( NULL, Log_0, "##513## status = %d", status); goto exittrace; } if( chatter > J_CHATTY_NORMAL ) RILlogMessage( NULL, Log_0, "##514## jlib giid"); status = DALattributeGetReal( ptr_IROS, "COLPITCH", &dtmp, NULL, NULL, status ); jmx_id->coll_pitch = dtmp; if( status != ISDC_OK ) { RILlogMessage( NULL, Log_0, "##515## status = %d", status); goto exittrace; } if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##516## jlib giid, coll_pitch = %f", jmx_id->coll_pitch); } status = DALattributeGetReal( ptr_IROS, "COLLH", &dtmp, NULL, NULL, status ); jmx_id->coll_h = dtmp; if( status != ISDC_OK ) { RILlogMessage( NULL, Log_0, "##517## status = %d", status); goto exittrace; } if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##518## jlib giid, coll_h = %f", jmx_id->coll_h); } status = DALattributeGetReal( ptr_IROS, "COLLW", &dtmp, NULL, NULL, status ); jmx_id->coll_w = dtmp; if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##519## jlib giid, coll_w = %f", jmx_id->coll_w); } status = DALattributeGetReal( ptr_IROS, "COLLR", &dtmp, NULL, NULL, status ); jmx_id->coll_r = dtmp; if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##520## jlib giid, coll_r = %f", jmx_id->coll_r); } status = DALattributeGetReal( ptr_IROS, "MASKR", &dtmp, NULL, NULL, status ); jmx_id->mask_r = dtmp; if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##521## jlib giid, coll_r = %f", jmx_id->coll_r); } status = DALattributeGetReal( ptr_IROS, "MASKSEP", &dtmp, NULL, NULL, status ); jmx_id->mask_height = dtmp; if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##522## jlib giid, mask_height = %f", jmx_id->mask_height); } /* * statement from alignment_init: */ jmx_id->mm2rad = 1. / jmx_id->mask_height; status = DALattributeGetReal( ptr_IROS, "HEXADIM", &dtmp, NULL, NULL, status ); jmx_id->hexa_dim = dtmp; if( status != ISDC_OK ) { RILlogMessage( NULL, Log_0, "##523## status = %d", status); goto exittrace; } if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##524## jlib giid, hexa_dim = %f", jmx_id->hexa_dim); } status = DALattributeGetReal( ptr_IROS, "STRUCH2", &dtmp, NULL, NULL, status ); jmx_id->struc_h2 = dtmp; if( status != ISDC_OK ) { RILlogMessage( NULL, Log_0, "##525## status = %d", status); goto exittrace; } if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##526## jlib giid, struc_h2 = %f", jmx_id->struc_h2); } status = DALattributeGetReal( ptr_IROS, "STRUCH1", &dtmp, NULL, NULL, status ); jmx_id->struc_h1 = dtmp; if( status != ISDC_OK ) { RILlogMessage( NULL, Log_0, "##527## status = %d", status); goto exittrace; } if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##528## jlib giid, struc_h1 = %f", jmx_id->struc_h1); } status = DALattributeGetReal( ptr_IROS, "ALPHA", &dtmp, NULL, NULL, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Log_0, "##529## status = %d", status); goto exittrace; } /* * statement from alignment_init: */ jmx_id->alfa = dtmp * GTORAD; if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##530## jlib giid, alfa = %f", jmx_id->alfa); } status = DALattributeGetReal( ptr_IROS, "BETA", &dtmp, NULL, NULL, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Log_0, "##531## status = %d", status); goto exittrace; } /* * statement from alignment_init: */ jmx_id->beta = dtmp * GTORAD; if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##532## jlib giid, beta = %f", jmx_id->beta); } status = DALattributeGetReal( ptr_IROS, "GAMMA", &dtmp, NULL, NULL, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Log_0, "##533## status = %d", status); goto exittrace; } if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##534## jlib giid, gammav = %f", jmx_id->gammav); } /* * statement from alignment_init: */ jmx_id->gammav = dtmp * GTORAD; status = DALattributeGetReal( ptr_IROS, "XSHIFT", &dtmp, NULL, NULL, status ); jmx_id->xshi = dtmp; if( status != ISDC_OK ) { RILlogMessage( NULL, Log_0, "##535## status = %d", status); goto exittrace; } if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##536## jlib giid, xshi = %f", jmx_id->xshi); } status = DALattributeGetReal( ptr_IROS, "YSHIFT", &dtmp, NULL, NULL, status ); jmx_id->yshi = dtmp; if( status != ISDC_OK ) { RILlogMessage( NULL, Log_0, "##537## status = %d", status); goto exittrace; } if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##538## jlib giid, yshi = %f", jmx_id->yshi); } status = DALattributeGetReal( ptr_IROS, "CTILTX", &dtmp, NULL, NULL, status ); jmx_id->c_tiltx = dtmp; if( status != ISDC_OK ) { RILlogMessage( NULL, Log_0, "##539## status = %d", status); goto exittrace; } if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##540## jlib giid, c_tiltx = %f", jmx_id->c_tiltx); } status = DALattributeGetReal( ptr_IROS, "CTILTY", &dtmp, NULL, NULL, status ); jmx_id->c_tilty = dtmp; if( status != ISDC_OK ) { RILlogMessage( NULL, Log_0, "##541## status = %d", status); goto exittrace; } if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##542## jlib giid, c_tilty = %f", jmx_id->c_tilty); } status = DALattributeGetReal( ptr_IROS, "COLLWB", &dtmp, NULL, NULL, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Log_0, "##543## status = %d", status); goto exittrace; } if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##544## jlib giid, coll_wb = %f", jmx_id->coll_wb); } /* * statement from alignment_init: */ jmx_id->coll_wb = dtmp + jmx_id->coll_w; /* *status = DALattributeGetReal( ptr_IROS, "COLLCORN", &dtmp, * NULL, NULL, status ); *jmx_id-> = dtmp; *if( status != ISDC_OK ) { RILlogMessage( NULL, Log_0, * "##545## status = %d", status); goto exittrace; } */ /* *status = DALattributeGetReal( ptr_IROS, "INDEP", &dtmp, * NULL, NULL, status ); *jmx_id-> = dtmp; */ status = DALattributeGetReal( ptr_IROS, "COLLCURV", &dtmp, NULL, NULL, status ); jmx_id->coll_curv = dtmp; if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##546## jlib giid, coll_curv = %f", jmx_id->coll_curv); } /* *status = DALattributeGetReal( ptr_IROS, "MASKSCAL", &dtmp, * NULL, NULL, status ); *jmx_id-> = dtmp; */ status = DALattributeGetReal( ptr_IROS, "SCALEX", &dtmp, NULL, NULL, status ); jmx_id->scaleX = dtmp; if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##547## jlib giid, scaleX = %f", jmx_id->scaleX); } status = DALattributeGetReal( ptr_IROS, "SCALEY", &dtmp, NULL, NULL, status ); jmx_id->scaleY = dtmp; if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##548## jlib giid, scaleY = %f", jmx_id->scaleY); } status = DALattributeGetReal( ptr_IROS, "PHASE2", &dtmp, NULL, NULL, status ); jmx_id->phase2 = dtmp; if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##549## jlib giid, phase2 = %f", jmx_id->phase2); } status = DALattributeGetReal( ptr_IROS, "X2X_MM", &dtmp, NULL, NULL, status ); jmx_id->x2xmm = dtmp; if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##550## jlib giid, x2xmm = %f", jmx_id->x2xmm); } status = DALattributeGetReal( ptr_IROS, "Y2Y_MM", &dtmp, NULL, NULL, status ); jmx_id->y2ymm = dtmp; if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##551## jlib giid, y2ymm = %f", jmx_id->y2ymm); } status = DALattributeGetReal( ptr_IROS, "OFFX_MM", &dtmp, NULL, NULL, status ); jmx_id->offXmm = dtmp; if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##552## jlib giid, offXmm = %f", jmx_id->offXmm); } status = DALattributeGetReal( ptr_IROS, "OFFY_MM", &dtmp, NULL, NULL, status ); jmx_id->offYmm = dtmp; if( status != ISDC_OK ) { RILlogMessage( NULL, Log_0, "##553## status = %d", status); goto exittrace; } if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##554## jlib giid, offYmm = %f", jmx_id->offYmm); } status = DALattributeGetReal( ptr_IROS, "OFFQ_RAD", &dtmp, NULL, NULL, status ); jmx_id->offQrad = dtmp; if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##555## jlib giid, offQrad = %f", jmx_id->offQrad); } status = DALattributeGetReal( ptr_IROS, "OFFR_RAD", &dtmp, NULL, NULL, status ); jmx_id->offRrad = dtmp; if( status != ISDC_OK ) { RILlogMessage( NULL, Log_0,"##556## status = %d", status); goto exittrace; } if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##557## jlib giid, offRrad = %f", jmx_id->offRrad); } /* * New keywords introduced in version 2.1.0 as of 2007-08-09 */ status = DALattributeGetReal( ptr_IROS, "TX0", &dtmp, NULL, NULL, status ); jmx_id->Tx0 = dtmp; if( status != ISDC_OK ) { RILlogMessage( NULL, Log_0,"##556## status = %d", status); goto exittrace; } if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##557## jlib giid, Tx0 = %f", jmx_id->Tx0); } status = DALattributeGetReal( ptr_IROS, "OFFTX0", &dtmp, NULL, NULL, status ); jmx_id->off_Tx0 = dtmp; if( status != ISDC_OK ) { RILlogMessage( NULL, Log_0,"##556## status = %d", status); goto exittrace; } if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##557## jlib giid, off_Tx0 = %f", jmx_id->off_Tx0); } status = DALattributeGetReal( ptr_IROS, "TY0", &dtmp, NULL, NULL, status ); jmx_id->Ty0 = dtmp; if( status != ISDC_OK ) { RILlogMessage( NULL, Log_0,"##556## status = %d", status); goto exittrace; } if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##557## jlib giid, Ty0 = %f", jmx_id->Ty0); } status = DALattributeGetReal( ptr_IROS, "OFFTY0", &dtmp, NULL, NULL, status ); jmx_id->off_Ty0 = dtmp; if( status != ISDC_OK ) { RILlogMessage( NULL, Log_0,"##556## status = %d", status); goto exittrace; } if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##557## jlib giid, off_Ty0 = %f", jmx_id->off_Ty0); } status = DALattributeGetReal( ptr_IROS, "TX7", &dtmp, NULL, NULL, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Log_0,"##556## status = %d", status); goto exittrace; } jmx_id->Tx7 = dtmp; if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##557## jlib giid, Tx7 = %f", jmx_id->Tx7); } status = DALattributeGetReal( ptr_IROS, "OFFTX7", &dtmp, NULL, NULL, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Log_0,"##556## status = %d", status); goto exittrace; } jmx_id->off_Tx7 = dtmp; if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##557## jlib giid, off_Tx7 = %f", jmx_id->off_Tx7); } status = DALattributeGetReal( ptr_IROS, "TY7", &dtmp, NULL, NULL, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Log_0,"##556## status = %d", status); goto exittrace; } jmx_id->Ty7 = dtmp; if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##557## jlib giid, Ty7 = %f", jmx_id->Ty7); } status = DALattributeGetReal( ptr_IROS, "OFFTY7", &dtmp, NULL, NULL, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Log_0,"##556## status = %d", status); goto exittrace; } jmx_id->off_Ty7 = dtmp; if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##557## jlib giid, off_Ty7 = %f", jmx_id->off_Ty7); } /* * New radCor keywords as of version 2.2.0 */ for( i = 0; i < J_NUM_RCCOEFS; i++ ) { sprintf( keyword,"RCAL%04li",i); status = DALattributeGetReal( ptr_IROS, keyword, &dtmp, NULL, NULL, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Log_0,"##556## %d, for keyword %s", status, keyword); goto exittrace; } jmx_id->RCabslen[i] = dtmp; } k = 0; for( i = 0; i < J_NUM_RCCOEFS; i++ ) { for( j = 0; j < J_NUM_RCCOEFSB; j++ ) { sprintf( keyword,"RCCF%04i",k++); status = DALattributeGetReal( ptr_IROS, keyword, &dtmp, NULL, NULL, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Log_0,"##556## %d, for keyword %s", status, keyword); goto exittrace; } jmx_id->RCcoeffs[i][j] = dtmp; } } /* * Get the PI energy table * */ if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##558## Going to read IMOD table FBDS"); } strcpy( structName, jemxStr ); strcat( structName, "-FBDS-MOD" ); status = DALobjectFindElement( ptr_instMod, structName, &elemPtr, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_2, "##559## Failed to open %s", structName ); goto exittrace; } status = DALtableGetNumRows( elemPtr, &numRows, status); if( status != ISDC_OK ) goto exittrace; if( numRows != J_NUM_SCI_BINS ) { RILlogMessage( NULL, Error_0, "##560## bad number of rows in FBDS"); status = J_ERROR_CODE_START+J_LIB_PIF_ERR+J_LPF_BADNUMROWS; goto exittrace; } startBin = 1; endBin = numRows; status = DALtableGetBuffSize( elemPtr, "E_MIN", 0, DAL_FLOAT, startBin, endBin, &buffSize, status ); status = DALallocateDataBuffer( (void **) &e_min, buffSize, status ); status = DALallocateDataBuffer( (void **) &e_max, buffSize, status ); dalType = DAL_FLOAT; status = DALtableGetCol( elemPtr, "E_MIN", 0, &dalType, &numValues, e_min, status); status = DALtableGetCol( elemPtr, "E_MAX", 0, &dalType, &numValues, e_max, status); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_0, "##561## Problem reading FBDS_IMOD, status = %d", status); goto exittrace; } for( loop = 0; loop < J_NUM_SCI_BINS; loop++ ) { jmx_id->e_min[loop] = e_min[loop]; jmx_id->e_max[loop] = e_max[loop]; jmx_id->escale[loop] = 0.5 * (e_min[loop] + e_max[loop]); if( chatter > J_CHATTY_VERY_VERBOSE && loop%7 == 0 ) { RILlogMessage( NULL, Log_0, "##562## instr_data e_min e_max escale %d %f %f %f", loop, jmx_id->e_min[loop], jmx_id->e_max[loop], jmx_id->escale[loop] ); } } status = DALfreeDataBuffer( (void *) e_min, status ); status = DALfreeDataBuffer( (void *) e_max, status ); /* * Get the detector position accuracy table * */ if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##563## Going to read IMOD table DPOS"); } strcpy( structName, jemxStr ); strcat( structName, "-DPOS-MOD" ); status = DALobjectFindElement( ptr_instMod, structName, &elemPtr, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_2, "##564## Failed to open %s", structName ); goto exittrace; } status = DALtableGetNumRows( elemPtr, &numRows, status); startBin = 1; endBin = numRows; status = DALtableGetBuffSize( elemPtr, "ENERGY", 0, DAL_FLOAT, startBin, endBin, &buffSize, status ); status = DALallocateDataBuffer( (void **) &energy_pos, buffSize, status ); status = DALallocateDataBuffer( (void **) &cposres, buffSize, status ); status = DALallocateDataBuffer( (void **) &bposres, buffSize, status ); dalType = DAL_FLOAT; status = DALtableGetCol( elemPtr, "ENERGY", 0, &dalType, &numValues, energy_pos, status); status = DALtableGetCol( elemPtr, "CPOSRES", 0, &dalType, &numValues, cposres, status); status = DALtableGetCol( elemPtr, "BPOSRES", 0, &dalType, &numValues, bposres, status); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_0, "##565## Problem reading DPOS_IMOD, status = %d", status); goto exittrace; } for( loop = 0; loop < J_NUM_SCI_BINS; loop++ ) { status = j_lpf_lilipol( numValues, energy_pos, cposres, jmx_id->escale[loop], &result, status ); jmx_id->cposres[loop] = result; status = j_lpf_lilipol( numValues, energy_pos, bposres, jmx_id->escale[loop], &result, status ); jmx_id->bposres[loop] = result; } status = DALfreeDataBuffer( (void *) energy_pos, status ); status = DALfreeDataBuffer( (void *) cposres, status ); status = DALfreeDataBuffer( (void *) bposres, status ); /* * Get the detector Xe attenuation table * */ if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##566## Going to read IMOD table ATXE"); } strcpy( structName, jemxStr ); strcat( structName, "-ATXE-MOD" ); status = DALobjectFindElement( ptr_instMod, structName, &elemPtr, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_2, "##567## Failed to open %s", structName ); goto exittrace; } status = DALtableGetNumRows( elemPtr, &numRows, status); startBin = 1; endBin = numRows; status = DALtableGetBuffSize( elemPtr, "ENERGY", 0, DAL_FLOAT, startBin, endBin, &buffSize, status ); status = DALallocateDataBuffer( (void **) &energy_att, buffSize, status ); status = DALallocateDataBuffer( (void **) &attlen_xe, buffSize, status ); dalType = DAL_FLOAT; status = DALtableGetCol( elemPtr, "ENERGY", 0, &dalType, &numValues, energy_att, status); status = DALtableGetCol( elemPtr, "ATTLEN", 0, &dalType, &numValues, attlen_xe, status); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_0, "##568## Problem reading ATXE-IMOD, status = %d", status); goto exittrace; } for( loop = 0; loop < J_NUM_SCI_BINS; loop++ ) { status = j_lpf_lilipol( numValues, energy_att, attlen_xe, jmx_id->escale[loop], &result, status ); jmx_id->attlen_xe[loop] = result / 1.5; /* correct for pressure 1.5 bar */ } status = DALfreeDataBuffer( (void *) energy_att, status ); status = DALfreeDataBuffer( (void *) attlen_xe, status ); /* * Get the detector quantum efficiency table * */ if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##569## Going to read IMOD table QEFF"); } strcpy( structName, jemxStr ); strcat( structName, "-QEFF-MOD" ); status = DALobjectFindElement( ptr_instMod, structName, &elemPtr, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_2, "##570## Failed to open %s", structName ); goto exittrace; } status = DALtableGetNumRows( elemPtr, &numRows, status); startBin = 1; endBin = numRows; status = DALtableGetBuffSize( elemPtr, "ENERGY", 0, DAL_FLOAT, startBin, endBin, &buffSize, status ); status = DALallocateDataBuffer( (void **) &energy_qef, buffSize, status ); status = DALallocateDataBuffer( (void **) &quanteff, buffSize, status ); dalType = DAL_FLOAT; status = DALtableGetCol( elemPtr, "ENERGY", 0, &dalType, &numValues, energy_qef, status); status = DALtableGetCol( elemPtr, "QUANTEFF", 0, &dalType, &numValues, quanteff, status); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_0, "##571## Problem reading QEFF-IMOD, status = %d", status); goto exittrace; } for( loop = 0; loop < J_NUM_SCI_BINS; loop++ ) { status = j_lpf_lilipol( numValues, energy_qef, quanteff, jmx_id->escale[loop], &result, status ); jmx_id->quanteff[loop] = result; } status = DALfreeDataBuffer( (void *) energy_qef, status ); status = DALfreeDataBuffer( (void *) quanteff, status ); /* *-------------------------------------------------------------- * SECTION FOR READING pixelfold DATA *-------------------------------------------------------------- */ /* * PXFL-MOD -> jmx_id->pixel_list */ strcpy( structName, jemxStr ); strcat( structName, "-PXFL-MOD" ); status = DALobjectFindElement( ptr_instMod, structName, &elemPtr, status); if( status != ISDC_OK ) { RILlogMessage( NULL, Log_0, "##558## status = %d", status); goto exittrace; } numRows = 0; status = DALtableGetNumRows( elemPtr, &numRows, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_0, "##559## %d: Error", status ); goto exittrace; } RILlogMessage( NULL, Log_0,"##560## Returned number of rows: %ld\n", numRows); istart = 0; for( loop = 0; loop < numRows; loop++ ) { dalType = DAL_BYTE; status = DALtableGetColBins( elemPtr, "LIST", 0, &dalType, loop+1, loop+1, &numValues, cbuffer, status ); if( status != ISDC_OK ) { RILlogMessage(NULL, Error_0,"##561## %d: loop = %d", status, loop ); goto exittrace; } for(i=0;i<20000;i++) jmx_id->pixel_list[istart+i] = cbuffer[i]; istart += 20000; } /* * PXFS-MOD -> jmx_id->pixel_st */ strcpy( structName, jemxStr ); strcat( structName, "-PXFS-MOD" ); status = DALobjectFindElement( ptr_instMod, structName, &elemPtr, status); if( status != ISDC_OK ) { RILlogMessage( NULL, Log_0, "##562## %d: Can't find element", status); goto exittrace; } dalType = DAL_INT; status = DALarrayGetSection( elemPtr, 2, startValues, endValues, &dalType, &numValues, jmx_id->pixel_st, status ); if( status != ISDC_OK ) { RILlogMessage(NULL, Error_0,"##563## %d: Problem reading array", status ); goto exittrace; } exittrace: 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 ); } /***************************************************************** * Name of source file: j_lpf_lilipol.c * Version of source file: 1.7.0 * Parent component: j_ima_iros * Programmer: Niels J. Westergaard * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325705 FAX: +45 35362475 * njw@spacecenter.dk * Purpose: Linear interpolation * Origin date: 050419 * Update history: 1.1.6 050419 * 1.2.0 050425 Deals with SPR 4102,4108 and reduces RAM requirement * 1.3.0 050503 Deals with SPR 4120 and copes with up to 6 shadowgrams * 1.3.1 050517 Deals with SPR 4143 and initializes ima_sigma properly * 1.3.2 050519 Closes SPR 4157 - bad size of three arrays * 1.3.3 050602 Changes some arrays to static (SPR 4202) * 1.4.0 050620 Include user defined sources (SCREW 1740) * 1.5.1 051129 Separating functions to jmx_lib_pif * 1.5.2 051202 Separating functions to jmx_lib_pif (2) * 1.5.3 051202 Give offX, x2x values in mm in IMOD-GRP * 1.5.4 060104 Bug in sh_depth corrected, detectmap now in mm * 1.5.5 060106 Introduced one more digit in logfile for src position * 1.5.6 060228 Removed parameter detMapFile and some obsolete variables * 1.7.0 061110 Get pointing from GTI file (SCREW 1883) * Type of element: Function *****************************************************************/ int j_lpf_lilipol( long n, /* Number of elements in array */ float *xv, /* Array with x values */ float *yv, /* Array with y values */ float x, /* x value for which function value is wanted */ float *plili, /* Result of interpolation */ int status) /* Fault condition flag */ { /* general function to make lin-lin interpolation in a table */ /* with ever increasing x-values */ long i, i1, i2; if( status != ISDC_OK ) return(status); /* If x value is outside range given by 'xv' then the closest 'y' value id returned */ *plili = yv[0]; if( x <= xv[0] ) return( status ); *plili = yv[n-1]; if( x >= xv[n-1] ) return( status ); /* Inside the range a binary search is used */ i1 = 0L; i2 = n - 1; do { i = (i1 + i2 ) / 2; if( x >= xv[i] ) { i1 = i; } else { i2 = i; } } while( i2 - i1 > 1 ); *plili = yv[i1] + (yv[i2]-yv[i1])*(x-xv[i1])/(xv[i2]-xv[i1]); return( status ); } /************************************************************************** update_imod_data.c A temporary member of the JEMX library 2007-03-26/NL Update history: October 2007: 'indep' and 'coll_h_reduc' values updated November 2007: Updated JMX2 alignment params according to crab2_pixfA and -fG January 2008: Updated alignment fits according to cr71_e16A results April 4, 2008: Comments added. November 23, 2008: Dummy-version with no updates p***********************************************************************/ int update_imod_data( int jemx, /* 0 or 1 */ struct instr_data *jmx_id, struct log_con *logger, /* log control parameters */ int chatter, int status) { static int func_local = -1, local_calling_num=0; clock_t calling_TT, TT_now; if( status != ISDC_OK ) return( status ); /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; logger->func_calling_num = 0; sprintf(logger->func_names[func_local], "update_imod_data"); if (logger->func_used_num > J_IIR_MAX_NUM_FUNCS) { sprintf(logger->tmptxt, "func_used_num > %d", J_IIR_MAX_NUM_FUNCS); logger->logstat = logprint(logger, logger->tmptxt, 6); logger->func_used_num = J_IIR_MAX_NUM_FUNCS; } } 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); 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 ); } /****************************************************************** * * Version of source file: 0.3.0 * Function name: j_isg_array_all * File name: j_isg_array_all.c * Parent component: j_ima_shadowgram * Programmer: Carol Anne Oxborrow * Affiliation: Danish Space Research Institute * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * oxborrow@dsri.dk * Purpose: Retrieve any JEMX array * from the I/O SWG file in FITS format * Origin date: 2000/09/22 * Update history: * 1999/12/14 0.00 NJW Copied from JSIMGLgetJEMXArrShort.c * 2000/09/07 1.00 CAO Broadened to a general array-fetching routine * for use in j_src_lc and j_src_spectra. * Now handles all data types,not just short * integers. * 0.1.2 060424 Test of data reading * 0.1.3 060426 Test of data reading (2) * 0.1.4 060505 Test of data reading (3) * 0.1.5 060515 Added ijd to struct: Events * 0.1.6 060517 Added function j_spr_get_sources * 0.2.0 060628 Added spectral and PIF writing * 0.3.0 060830 Electronic efficiency included * 2000/09/22 1.1 CAO No change from 1.0 * 2006-03-16 1.2 NJW Skips return of pointer to data array extension * * Type of element: Function * Part of package: j_ima_shadowgram * Returns: Zero (ISDC_OK): function completed without error * Negative: function could not completed due to * an error condition * Required components: DAL, PIL, RIL * *****************************************************************/ int j_lpf_array_all( dal_element *theGroup, /* The consolidated I/O group */ char *elementName, /* DS name of data element to get */ void *array, /* pointer to array, returned */ int nAxes, /* Number of axes in array to get */ long *dimAxes, /* Dimension of axes of array */ int chatter, /* Level of monitoring output */ int status) /* flag for status when called */ { void *arrayBuffer = NULL; int numAxes=0; int i = 0; long axes[DAL_MAX_ARRAY_DIMENSION]; long startValues[DAL_MAX_ARRAY_DIMENSION]; long bufferSize = 0; long numValues; long numPixels = 0; long j = 0; dal_element *elementPtr = NULL; dal_dataType arrayType; /* No action if fault condition has been reported at time of call */ if( status != ISDC_OK ){ RILlogMessage(NULL, Error_2, "Non-zero status flag passed to j_lpf_array_all"); return( status ); } /* Find the correct element */ status = DALobjectFindElement( theGroup, elementName, &elementPtr, status ); if( status != ISDC_OK ){ RILlogMessage(NULL, Error_2, "%d : Could not find array %s", status, elementName); return( status ); } /* Get the structure of the data array */ status = DALarrayGetStruct( elementPtr, &arrayType, &numAxes, axes, status); if( status != ISDC_OK ){ RILlogMessage(NULL, Error_2, "%d : Could not read in array %s structure", status, elementName); return( status ); } if ( numAxes != nAxes){ status = J_LPF_WRONG_DIMS ; RILlogMessage(NULL, Error_2, "%d : Array %s has wrong number of axes: expected: %d found: %d", status, elementName, nAxes, numAxes); return status ; } for ( i=0 ; i J_CHATTY_NORMAL ) { switch ( arrayType ) { case DAL_BYTE : RILlogMessage(NULL,Log_0,"##5123## %s is DAL_BYTE",elementName); break; case DAL_INT : RILlogMessage(NULL,Log_0,"##5123## %s is DAL_INT",elementName); break; case DAL_SHORT : RILlogMessage(NULL,Log_0,"##5123## %s is DAL_SHORT",elementName); break; case DAL_LONG : RILlogMessage(NULL,Log_0,"##5123## %s is DAL_LONG",elementName); break; case DAL_FLOAT : RILlogMessage(NULL,Log_0,"##5123## %s is DAL_FLOAT",elementName); break; case DAL_DOUBLE : RILlogMessage(NULL,Log_0,"##5123## %s is DAL_DOUBLE",elementName); break; default : RILlogMessage(NULL,Log_0,"##5123## Unsupported dataType"); } } status = DALallocateDataBuffer( &arrayBuffer, bufferSize, status); if ( status!= ISDC_OK){ RILlogMessage(NULL, Error_2, "%d : could not allocate the array data buffer for %s ", status, elementName); return status; } /* Read the array data */ status = DALarrayGetSection( elementPtr, numAxes, startValues, axes, &arrayType, &numValues, arrayBuffer, status); if( status != ISDC_OK ){ RILlogMessage(NULL, Error_2, "%d : could not read in array %s", status, elementName); return status ; } numPixels = 1; for ( i=0 ; i J_CHATTY_NORMAL){ RILlogMessage(NULL, Log_0,"##254## Reading data structure: %s, status: %d", structName, status); } dimAxes[0] = (long) J_NUM_X_PIXELS; dimAxes[1] = (long) J_NUM_Y_PIXELS; dimAxes[2] = 2; offset = dimAxes[0] * dimAxes[1]; /* * Read SPAG-MOD array. */ status = j_lpf_array_all( ptrIMOD, structName, (void*) buffer, 3, dimAxes, chatter, status); if( status != ISDC_OK ){ RILlogMessage( NULL, Log_0, "##255## Error getting JEMX SPAG table in DS: %s", structName); return status; } for ( i=0; ispagf[i][j] = (1. + 0.01 * buffer[j*J_NUM_X_PIXELS + i]) * buffer[offset + j*J_NUM_X_PIXELS + i]; jmx_id->spagj[i*J_NUM_X_PIXELS + j] = jmx_id->spagf[i][j]; } } if( chatter > J_CHATTY_NORMAL ){ RILlogMessage(NULL,Log_0, "##256## SPAG table read"); } if( buffer != NULL ) free( buffer ); if( chatter > J_CHATTY_NORMAL ) { for( j = 8; j < J_NUM_Y_PIXELS; j += 16 ) { k = 0; for( i = 16; i < J_NUM_X_PIXELS; i += 32 ) { x[k++] = jmx_id->spagf[i][j]; } RILlogMessage(NULL,Log_0,"##1## %5.2f%5.2f%5.2f%5.2f%5.2f%5.2f%5.2f%5.2f", x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7]); } } return( status ); } /***************************************************************** * Name of source file: j_lpf_get_EEFF_CFTM_CURT.c * Version of source file: 1.1.0 * Parent component: None * Programmer: Niels J. Westergaard * Affiliation: National Space Institute/DTU * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325705 FAX: +45 35362475 * njw@space.dtu.dk * Purpose: Get the EEFF, CFTM, and CURT from IMOD group * Origin date: 080704 * Update history: 0.2.0 080707 copied from j_shg_get_EEFF.c * 1.1.0 090416 Updated to read EEFF_ORIGIN column * Type of element: Function * Part of package: jmx_lib_pif * Name: j_lpf_get_EEFF_CFTM_CURT *****************************************************************/ int j_lpf_get_EEFF_CFTM_CURT( Instrument jemxNum, dal_element *ptrIMOD, struct instr_data *jmx_id, int chatter, int status) { char structName[DS_NAME_SIZE]; char jemxStr[5]; int loop = 0; long numRows = 0; long nValuesRead = 0; long bufferSize = 0; float *linpha = NULL; float *elec_eff = NULL; float *time_slope = NULL; float *eeff_origin = NULL; float *energy_lo = NULL; float *energy_hi = NULL; float *curtain = NULL; double dtmp = 0.0; dal_element *extPtr = NULL; dal_dataType dataType = DAL_INT; /* * assumes that jemxNum has been tested beforehand */ if( jemxNum == JMX1 ) strcpy( jemxStr, "JMX1" ); else strcpy( jemxStr, "JMX2" ); /* ---------------------------------------------------- * Get the electronic efficiency table EEFF * ---------------------------------------------------- */ strcpy( structName, jemxStr); strcat( structName, "-EEFF-MOD" ); if( chatter >= J_CHATTY_MAXIMAL ){ RILlogMessage(NULL, Log_0,"##240## Reading data structure: %s, status: %d", structName, status); } status = DALobjectFindElement( ptrIMOD, structName, &extPtr, status); if( status != ISDC_OK ) { RILlogMessage(NULL, Error_2, "##241## %d: Could not find extension %s", status, structName); return status; } if( chatter >= J_CHATTY_MAXIMAL ){ RILlogMessage(NULL,Log_0, "##242## Data structure found"); } /* * Find number of values. */ status = DALtableGetColStruct( extPtr, 0, &numRows, "LINPHA", &dataType, NULL, NULL, status); if( status != ISDC_OK ) { RILlogMessage(NULL, Error_2, "##243## %d : Couldn't find number of LINPHA values in %s", status, structName); return status; } /* * Allocate float buffer */ bufferSize = numRows * sizeof( float ); status = DALallocateDataBuffer( (void **) &linpha, bufferSize, status ); status = DALallocateDataBuffer( (void **) &elec_eff, bufferSize, status ); if (status!=ISDC_OK){ RILlogMessage(NULL, Error_2, "##243## %d : Memory allocation error", status ); return status; } /* ------------------------------------------------------------------------ * Read LINPHA * ------------------------------------------------------------------------ */ status = DALtableGetCol( extPtr, "LINPHA", 0, &dataType, &nValuesRead, (void *) linpha, status); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_2, "##245## %d: Could not get LINPHA values from %s", status, structName ); return status; } if( chatter >= J_CHATTY_MAXIMAL ){ RILlogMessage(NULL,Log_0, "##246## Read %ld LINPHA values", nValuesRead ); } if( numRows != nValuesRead ) { status = J_ERROR_CODE_START + J_LIB_PIF_ERR + J_LPF_BADNUMROWS; RILlogMessage( NULL,Error_3, "%d : Wrong number of LINPHA values read in from %s", status, structName ); return status; } /* ------------------------------------------------------------------------ * Read ELEC_EFF * ------------------------------------------------------------------------ */ status = DALtableGetCol( extPtr, "ELEC_EFF", 0, &dataType, &nValuesRead, (void *) elec_eff, status); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_2, "##245## %d: Could not get ELEC_EFF values from %s", status, structName ); return status; } if( chatter >= J_CHATTY_MAXIMAL ) { RILlogMessage(NULL,Log_0, "##246## Read %ld ELEC_EFF values",nValuesRead ); } if( numRows != nValuesRead ) { status = J_ERROR_CODE_START + J_LIB_PIF_ERR + J_LPF_BADNUMROWS; RILlogMessage( NULL,Error_3, "%d : Wrong number of ELEC_EFF values read in from %s", status, structName ); return status; } /* * Copy to struct instr_data (jmx_id) */ for( loop = 0; loop < numRows; loop++ ) { jmx_id->eeff_pha[loop] = linpha[loop]; jmx_id->eeff[loop] = elec_eff[loop]; } jmx_id->num_eeff_vals = numRows; if( chatter > J_CHATTY_VERBOSE ) { for(loop=0; loop= J_CHATTY_MAXIMAL ) { RILlogMessage(NULL, Log_0,"##240## Reading data structure: %s, status: %d", structName, status); } extPtr = NULL; status = DALobjectFindElement( ptrIMOD, structName, &extPtr, status); if (status!=ISDC_OK){ RILlogMessage(NULL, Error_2, "##241## %d : Could not find extension %s", status, structName); return status; } if( chatter >= J_CHATTY_MAXIMAL ){ RILlogMessage(NULL,Log_0, "##242## Data structure found"); } /* * Find number of values. */ status = DALtableGetColStruct( extPtr, 0, &numRows, "TIMESLOPE", &dataType, NULL, NULL, status); if( status != ISDC_OK ) { RILlogMessage(NULL, Error_2, "##243## %d : Couldn't find number of TIMESLOPE values in %s", status, structName); return status; } bufferSize = numRows * sizeof( float ); status = DALallocateDataBuffer( (void **) &time_slope, bufferSize, status ); status = DALallocateDataBuffer( (void **) &eeff_origin, bufferSize, status ); status = DALallocateDataBuffer( (void **) &energy_lo, bufferSize, status ); status = DALallocateDataBuffer( (void **) &energy_hi, bufferSize, status ); if( status!=ISDC_OK) { RILlogMessage(NULL, Error_2, "##243## %d : Memory allocation error", status ); return status; } if( numRows != XYvsE_Evals ) { status = J_ERROR_CODE_START + J_LIB_PIF_ERR + J_LPF_BADNUMROWS; RILlogMessage( NULL, Error_2, "##244## %d: Wrong number of energy values", status ); return status; } /* ------------------------------------------------------------------------ * Read TIMESLOPE, EEFF_ORIGIN, ENERGY_LO, and ENERGY_HI * ------------------------------------------------------------------------ */ status = DALtableGetCol( extPtr, "TIMESLOPE", 0, &dataType, &nValuesRead, (void *) time_slope, status); status = DALtableGetCol( extPtr, "EEFF_ORIGIN", 0, &dataType, &nValuesRead, (void *) eeff_origin, status); status = DALtableGetCol( extPtr, "ENERGY_LO", 0, &dataType, &nValuesRead, (void *) energy_lo, status); status = DALtableGetCol( extPtr, "ENERGY_HI", 0, &dataType, &nValuesRead, (void *) energy_hi, status); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_2, "##245## %d: Could not get TIMESLOPE,ENERGY_LO/HI values from %s", status, structName ); return status; } if( chatter >= J_CHATTY_MAXIMAL ){ RILlogMessage(NULL,Log_0, "##246## Read %ld TIMESLOPE values",nValuesRead ); } if( numRows != nValuesRead ){ status = J_ERROR_CODE_START + J_LIB_PIF_ERR + J_LPF_BADNUMROWS; RILlogMessage( NULL,Error_3, "##246## %d: Wrong number of TIMESLOPE values read in from %s", status, structName ); return status; } for( loop = 0; loop < XYvsE_Evals; loop++ ) { jmx_id->eeff_time_slope[loop] = time_slope[loop]; jmx_id->eeff_value_origin[loop] = eeff_origin[loop]; jmx_id->Elist[loop] = energy_lo[loop]; } jmx_id->Elist[XYvsE_Evals] = energy_hi[XYvsE_Evals-1]; /* * Get keyword value for time origin */ status = DALattributeGetReal( extPtr, "REVOLORI", &dtmp, NULL, NULL, status ); jmx_id->eeff_time_origin = (float) dtmp; /* ---------------------------------------------------- * Get the curtain function table CURT * ---------------------------------------------------- */ strcpy( structName, jemxStr); strcat( structName, "-CURT-MOD" ); if( chatter >= J_CHATTY_MAXIMAL ){ RILlogMessage(NULL, Log_0,"##240## Reading data structure: %s, status: %d", structName, status); } status = DALobjectFindElement( ptrIMOD, structName, &extPtr, status); if( status != ISDC_OK ) { RILlogMessage(NULL, Error_2, "##241## %d: Could not find extension %s", status, structName); return status; } if( chatter >= J_CHATTY_MAXIMAL ){ RILlogMessage(NULL,Log_0, "##242## Data structure found"); } /* * Find number of values. */ status = DALtableGetColStruct( extPtr, 0, &numRows, "CURTAIN", &dataType, NULL, NULL, status); if( status != ISDC_OK ) { RILlogMessage(NULL, Error_2, "##243## %d : Couldn't find number of CURTAIN values in %s", status, structName); return status; } /* * Allocate float buffer */ bufferSize = numRows * sizeof( float ); status = DALallocateDataBuffer( (void **) &curtain, bufferSize, status ); if (status!=ISDC_OK){ RILlogMessage(NULL, Error_2, "##243## %d : Memory allocation error", status ); return status; } /* ------------------------------------------------------------------------ * Read CURTAIN * ------------------------------------------------------------------------ */ dataType = DAL_FLOAT; status = DALtableGetCol( extPtr, "CURTAIN", 0, &dataType, &nValuesRead, (void *) curtain, status); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_2, "##245## %d: Could not get CURTAIN values from %s", status, structName ); return status; } if( chatter >= J_CHATTY_MAXIMAL ){ RILlogMessage(NULL,Log_0, "##246## Read %ld CURTAIN values",nValuesRead ); } if( numRows != nValuesRead ) { status = J_ERROR_CODE_START + J_LIB_PIF_ERR + J_LPF_BADNUMROWS; RILlogMessage( NULL,Error_3, "%d : Wrong number of CURTAIN values read in from %s", status, structName ); return status; } /* * Copy to struct instr_data (jmx_id) */ for( loop = 0; loop < numRows; loop++ ) { jmx_id->curtain[loop] = curtain[loop]; } if( chatter > J_CHATTY_VERBOSE ) { for(loop=0; loopsigma_cx = dtmp; status = DALattributeGetReal( ptr, "SIGMACY", &dtmp, NULL, NULL, status ); jmx_id->sigma_cy = dtmp; strcpy( structName, jemxStr ); strcat( structName, "-CFEX-MOD" ); status = DALobjectFindElement( imodPtr, structName, &ptr, status ); dalType = DAL_FLOAT; status = DALtableGetCol( ptr, "ENERGY_LO", 0, &dalType, &numValues, fbuffer, status ); for( loop = 0; loop < numValues; loop++ ) jmx_id->Elist[loop] = fbuffer[loop]; status = DALtableGetCol( ptr, "ENERGY_HI", 0, &dalType, &numValues, fbuffer, status ); jmx_id->Elist[numValues] = fbuffer[numValues-1]; status = DALtableGetCol( ptr, "COEFFS", 0, &dalType, &numValues, ffbuffer, status ); for( loopj = 0; loopj < 16; loopj++ ) { for( loopi = 0; loopi < 16; loopi++ ) { jmx_id->XvsE[loopi][loopj] = ffbuffer[loopi][loopj]; } } strcpy( structName, jemxStr ); strcat( structName, "-CFEY-MOD" ); status = DALobjectFindElement( imodPtr, structName, &ptr, status ); status = DALtableGetCol( ptr, "COEFFS", 0, &dalType, &numValues, ffbuffer, status ); for( loopj = 0; loopj < 16; loopj++ ) { for( loopi = 0; loopi < 16; loopi++ ) { jmx_id->YvsE[loopi][loopj] = ffbuffer[loopi][loopj]; } } return status; } void fine_anoder(short AA[256]) { int i; for (i=0; i<256; i++) AA[i] = 0; AA[ 3] = 1; AA[ 4] = 1; AA[ 5] = 1; AA[ 6] = 1; AA[ 7] = 1; AA[ 8] = 1; AA[ 9] = 1; AA[ 10] = 1; AA[ 11] = 1; AA[ 12] = 1; AA[ 13] = 1; AA[ 14] = 1; AA[ 15] = 1; AA[ 16] = 1; AA[ 26] = 1; AA[ 27] = 1; AA[ 28] = 1; AA[ 29] = 1; AA[ 30] = 1; AA[ 31] = 1; AA[ 32] = 1; AA[ 33] = 1; AA[ 34] = 1; AA[ 35] = 1; AA[ 36] = 1; AA[ 37] = 1; AA[ 38] = 1; AA[ 44] = 1; AA[ 45] = 1; AA[ 46] = 1; AA[ 51] = 1; AA[ 55] = 1; AA[ 56] = 1; AA[ 57] = 1; AA[ 58] = 1; AA[ 59] = 1; AA[ 60] = 1; AA[ 61] = 1; AA[ 62] = 1; AA[ 63] = 1; AA[ 64] = 1; AA[ 65] = 1; AA[ 66] = 1; AA[ 67] = 1; AA[ 68] = 1; AA[ 69] = 1; AA[ 79] = 1; AA[ 86] = 1; AA[ 87] = 1; AA[ 88] = 1; AA[ 93] = 1; AA[ 97] = 1; AA[102] = 1; AA[103] = 1; AA[104] = 1; AA[105] = 1; AA[106] = 1; AA[107] = 1; AA[108] = 1; AA[109] = 1; AA[110] = 1; AA[111] = 1; AA[112] = 1; AA[113] = 1; AA[123] = 1; AA[124] = 1; AA[125] = 1; AA[126] = 1; AA[127] = 1; AA[128] = 1; AA[129] = 1; AA[130] = 1; AA[131] = 1; AA[132] = 1; AA[133] = 1; AA[134] = 1; AA[135] = 1; AA[136] = 1; AA[137] = 1; AA[143] = 1; AA[147] = 1; AA[148] = 1; AA[149] = 1; AA[150] = 1; AA[151] = 1; AA[152] = 1; AA[153] = 1; AA[154] = 1; AA[155] = 1; AA[156] = 1; AA[157] = 1; AA[158] = 1; AA[167] = 1; AA[168] = 1; AA[169] = 1; AA[173] = 1; AA[174] = 1; AA[175] = 1; AA[176] = 1; AA[177] = 1; AA[178] = 1; AA[179] = 1; AA[180] = 1; AA[181] = 1; AA[190] = 1; AA[191] = 1; AA[192] = 1; AA[193] = 1; AA[194] = 1; AA[199] = 1; AA[200] = 1; AA[201] = 1; AA[202] = 1; AA[217] = 1; AA[218] = 1; AA[222] = 1; AA[223] = 1; AA[224] = 1; AA[225] = 1; AA[226] = 1; AA[227] = 1; AA[228] = 1; AA[229] = 1; AA[230] = 1; AA[231] = 1; AA[232] = 1; AA[236] = 1; AA[237] = 1; AA[238] = 1; AA[239] = 1; AA[240] = 1; AA[241] = 1; AA[242] = 1; AA[243] = 1; AA[244] = 1; AA[245] = 1; AA[246] = 1; AA[247] = 1; AA[248] = 1; AA[249] = 1; AA[250] = 1; AA[251] = 1; return; } /* Calculation of transmission function for JEM-X collimattor with Gaussian scatter of the lamellae directions */ /* Niels Lund, December 2007 Updated 2008-12-03/NJW with call of DAL3GENrandomDoubleX01 */ /* **************************************************************************************** */ int coll_transmit(float xmm, float ymm, struct instr_data *jmx_id, struct log_con *logger, float transmit[]) /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* */ /* Transmission function for 'random' collimator. December 2007 */ /* The transmission functions are calculated in 2' steps (-400' to +400') */ /* */ /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ { int i=0, j=0, num=0, index=0, index_shift=0; int status=0; char gnunavn[100]; static int first = 1, jemx, devgnulim = 1; static float transmix[401], transmiy[401], transmi0[401]; static float transmi0x[401], transmi0y[401], transmi00[401]; static double arcmin=0.0, opn=0.0, Mmm2min=0.0, Cmm2min=0.0; static double angle=0.0, dstep=0.0; static double pi=0.0, twopi=0.0, delta=0.0, theta=0.0; double fact=0.0; double r1, r2, g1, g2; FILE *gnufil=NULL; 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], "coll_transmit"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ pi = 3.14159; twopi = pi * 2.0; arcmin = pi / (180.0 * 60.0); dstep = 2.0; /* step size in arcmin */ evaluate: /* evaluate */ if (first == 0) { /* not before static data have been elaborated */ /* if (logger->trace) traces(func_local, 10, logger); */ angle = xmm * Mmm2min; index = (int)(angle / dstep + 1200.0) - 1000; transmit[0] = 0.01; transmit[2] = 0.01; transmit[7] = transmit[8] = 1.0; /* if (logger->trace) traces(func_local, 1000+index, logger); */ if (index < 0) goto xdone;; if (index > 399) goto xdone; fact = angle / dstep + 200.0 - (float)(index); transmit[0] = transmix[index] * (1.0 - fact) + transmix[index+1] * fact; /* transmit[0] is the corrected transmission in X */ transmit[2] = transmi0[index] * (1.0 - fact) + transmi0[index+1] * fact; /* transmit[2] is the idealized transmission in X (zero mean tilt and no spread in the tilt) */ transmit[7] = transmi0x[index] * (1.0 - fact) + transmi0x[index+1] * fact; /* transmit[7] is the tilt spread correction in X corresponding to data already corrected for mean tilt */ xdone: angle = ymm * Mmm2min; index = (int)(angle / dstep + 1200.0) - 1000; transmit[1] = 0.01; transmit[3] = 0.01; /* if (logger->trace) traces(func_local, 2000+index, logger); */ if (index < 0) goto ydone;; if (index > 399) goto ydone; fact = angle / dstep + 200.0 - (float)(index); transmit[1] = transmiy[index] * (1.0 - fact) + transmiy[index+1] * fact; /* transmit[1] is the corrected transmission in Y */ transmit[3] = transmi0[index] * (1.0 - fact) + transmi0[index+1] * fact; /* transmit[3] is the idealized transmission in Y (no mean tilt and no spread in the tilt) */ transmit[8] = transmi0y[index] * (1.0 - fact) + transmi0y[index+1] * fact; /* transmit[8] is the tilt spread correction in Y corresponding to data already corrected for mean tilt */ ydone: if (transmit[2] <= 0.01) {status = -1; goto exit_trace;} transmit[4] = transmit[0] / transmit[2]; /* transmit[4] is the ratio of the idealized to the corrected X-correction */ if (transmit[3] <= 0.01) {status = -2; goto exit_trace;} transmit[5] = transmit[1] / transmit[3]; /* transmit[5] is the ratio of the idealized to the corrected Y-correction */ if (transmit[4] > 3.0) {status = -3; goto exit_trace;} if (transmit[5] > 3.0) {status = -4; goto exit_trace;} transmit[6] = transmit[4] * transmit[5]; /* transmit[6] is the product of the X- and Y-transmission correction */ if (transmit[6] > 3.0) {status = -5; goto exit_trace;} status = 0; exit_trace: /* if (status < 0) { sprintf(logger->tmptxt, "coll_transmit: x/ymm: %6.1f %6.1f, fact: %f, index: %4d, transmit[7/8]: %f %f\n", xmm, ymm, fact, index, transmit[7], transmit[8]); logger->logstat = logprint(logger, logger->tmptxt, 0); for (i=0; i<9; i++) { sprintf(logger->tmptxt2, "%9.4f ", transmit[i]); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } logger->logstat = logprint(logger, logger->tmptxt, 0); } */ /* if (logger->trace) traces(func_local, 1000000+status, logger); 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); } /* QQQQ Only executed with first call !! */ if (logger->trace) traces(func_local, 0, logger); first = 0; opn = jmx_id->coll_pitch - 2.0 * jmx_id->coll_w; Cmm2min = 1.0 / (jmx_id->coll_h * arcmin); /* collimator mm to arcmin */ Mmm2min = 1.0 / (jmx_id->mask_height * arcmin); /* mask mm to arcmin */ jemx = jmx_id->jmx_unit; for (i=0; i<401; i++) { transmix[i] = transmiy[i] = transmi0[i] = 0.0; transmi0x[i] = transmi0y[i] = transmi00[i] = 0.0; } if (logger->trace) traces(func_local, 10, logger); num = 10000; for (j=0; j<31; j++) { theta = (float)(j) * dstep; for (i=0; isigma_cx) * arcmin; delta = opn - jmx_id->coll_h * fabs(sin(angle)); if (delta < 0.0) delta = 0.0; transmix[200+j] += delta; /* transmix only used for temporary storage here */ angle = (theta + g2 * jmx_id->sigma_cx) * arcmin; delta = opn - jmx_id->coll_h * fabs(sin(angle)); if (delta < 0.0) delta = 0.0; transmix[200+j] += delta; /* generate rounded peak in center */ } } if (logger->trace) traces(func_local, 20, logger); for (j=0; j<401; j++) { angle = (float)(j-200) * dstep * arcmin; delta = opn - jmx_id->coll_h * fabs(sin(angle)); if (delta < 0.0) delta = 0.0; transmi0[j] = delta; transmi00[j] = delta; /* save idealized transmission for later */ } if (logger->trace) traces(func_local, 30, logger); if (logger->develop > devgnulim) { sprintf(gnunavn, "collim_trans%1d.gnu", jemx+1); gnufil = fopen(gnunavn, "wt"); for (j=0; j<401; j++) fprintf(gnufil, "%f %f\n", (float)(j-200)/30.0 , transmi0[j]/opn); fprintf(gnufil, "\n\n"); } for (j=0; j<31; j++) { transmix[200+j] /= (num * 2.0); transmi0[200+j] = transmix[200+j]; /* transfer rounded peak from transmix to transmi0 */ transmi0[200-j] = transmix[200+j]; } for (j=0; j<401; j++) { if (transmi00[j] > 0.0) transmi00[j] = transmi0[j] / transmi00[j]; else transmi00[j] = 1.0; } if (logger->trace) traces(func_local, 50, logger); if (logger->develop > devgnulim) { for (j=0; j<401; j++) fprintf(gnufil, "%f %f\n", (float)(j-200)/30.0 , transmi00[j]); fprintf(gnufil, "\n\n"); } angle = -jmx_id->c_tiltx * Cmm2min; index_shift = (int)(angle / dstep + 100.0) - 100; fact = angle / dstep - (float)(index_shift); for (j=0; j<401; j++) { /* shift collimator response according to 'c_tiltx' */ transmix[j] = 0.0; transmi0x[j] = 0.0; if ((j+index_shift) < 0) continue; if ((j+index_shift+1) > 399) continue; transmix[j] = transmi0[j+index_shift] * (1.0 - fact) + transmi0[j+index_shift+1] * fact; transmi0x[j] = transmi00[j+index_shift] * (1.0 - fact) + transmi00[j+index_shift+1] * fact; } if (logger->trace) traces(func_local, 60, logger); if (logger->develop > devgnulim) { for (j=0; j<401; j++) fprintf(gnufil, "%f %f\n", (float)(j-200)/30.0 , transmi0x[j]); fprintf(gnufil, "\n\n"); } /* repeat for Y collimator parameters */ for (j=0; j<31; j++) { theta = (float)(j) * dstep; for (i=0; isigma_cy) * arcmin; delta = opn - jmx_id->coll_h * fabs(sin(angle)); if (delta < 0.0) delta = 0.0; transmiy[200+j] += delta; /* transmiy only used for temporary storage here */ angle = (theta + g2 * jmx_id->sigma_cy) * arcmin; delta = opn - jmx_id->coll_h * fabs(sin(angle)); if (delta < 0.0) delta = 0.0; transmiy[200+j] += delta; } } if (logger->trace) traces(func_local, 70, logger); for (j=0; j<401; j++) { angle = (float)(j-200) * dstep * arcmin; delta = opn - jmx_id->coll_h * fabs(sin(angle)); if (delta < 0.0) delta = 0.0; transmi0[j] = delta; transmi00[j] = delta; /* save idealized transmission for later */ } for (j=0; j<31; j++) { transmiy[200+j] /= (num * 2.0); transmi0[200+j] = transmiy[200+j]; /* transfer data from transmix to transmi0 */ transmi0[200-j] = transmiy[200+j]; } for (j=0; j<401; j++) { if (transmi00[j] > 0.0) transmi00[j] = transmi0[j] / transmi00[j]; else transmi00[j] = 1.0; } if (logger->trace) traces(func_local, 80, logger); if (logger->develop > devgnulim) { for (j=0; j<401; j++) fprintf(gnufil, "%f %f\n", (float)(j-200)/30.0 , transmi00[j]); fprintf(gnufil, "\n\n"); } angle = -jmx_id->c_tilty * Cmm2min; index_shift = (int)(angle / dstep + 100.0) - 100; fact = angle / dstep - (float)(index_shift); /* printf("Y tilty: %7.4f, mm2min: %7.5f, angle: %8.5f, dstep: %5.3f, index_shift: %2d, fact: %6.3f\n", -jmx_id->c_tilty, Cmm2min, angle, dstep, index_shift, fact); */ for (j=0; j<401; j++) { transmiy[j] = 0.0; transmi0y[j] = 0.0; if ((j+index_shift) < 0) continue; if ((j+index_shift+1) > 399) continue; transmiy[j] = transmi0[j+index_shift] * (1.0 - fact) + transmi0[j+index_shift+1] * fact; transmi0y[j] = transmi00[j+index_shift] * (1.0 - fact) + transmi00[j+index_shift+1] * fact; /* if (abs(j-200) <= 10) * printf("Y T00[%3d]: %5.3f, T00[%3d]: %5.3f, (1-F): %6.3f, T00[%3d]: %5.3f, (F): %6.3f, T0y[%3d]: %5.3f\n", * j, transmi00[j], j+index_shift, transmi00[j+index_shift], 1.0-fact, * j+index_shift+1, transmi00[j+index_shift+1], fact, j, transmi0y[j]); */ } if (logger->trace) traces(func_local, 90, logger); if (logger->develop > devgnulim) { for (j=0; j<401; j++) fprintf(gnufil, "%f %f\n", (float)(j-200)/30.0 , transmi0y[j]); fprintf(gnufil, "\n\n"); } for (j=0; j<401; j++) { /* redefine transmi0 as unshifted, perfect collimator */ angle = (float)(j-200) * dstep * arcmin; delta = opn - jmx_id->coll_h * fabs(sin(angle)); if (delta < 0.0) delta = 0.0; transmi0[j] = delta; } if (gnufil != NULL) fclose(gnufil); if (logger->trace) traces(func_local, 99, logger); goto evaluate; } /***************************************************************** * Name of source file: off_axis_transmission.c * Version of source file: 1.0.1 * Parent component: j_ima_iros * Programmer: Niels Lund * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325700 FAX: +45 35362475 * njw@spacecenter.dk, nl@spacecenter.dk * Purpose: Calculate additional off-axis corrections to source fluxes (single pos. version) (in addition to the collimator tilt correction which is handled by jmx_lib_pif) * Origin date: 071122 * Update history: 1.0.0 200108 First version * Type of element: Executable * Part of package: j_ima_iros * Name: off_axis_transmission.c * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ int off_axis_transmission( float xmm, float ymm, float Emin, float Emax, float *transmis, struct instr_data *jmx_id, struct log_con *logger) /* log control parameters */ { int i, jemx, status, status1, i5 = 5; int ixpar, iypar, Epar; static int kk=0; float R2, transmit[10]; float X_correct, Y_correct, Eval=0.0; float par1, mm2deg, Emean; 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], "off_axis_transM"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->func_used_num--; logger->logstat = logprint(logger, logger->tmptxt, 6); } } logger->func_calls[func_local]++; calling_TT = logger->TT; logger->TT = TT_now = clock(); local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; logger->func_times[local_calling_num] += difftime(TT_now, calling_TT); /* function entry timing end */ if (logger->trace) traces(func_local, 0, logger); *transmis = 1.0; status = -1; mm2deg = 180.0 / 3.14159 / jmx_id->mask_height; R2 = xmm*xmm + ymm*ymm; if (R2 > 375.0 * 375.0) goto escape; jemx = jmx_id->jmx_unit; /* * The call of get_XYvsE has been moved to j_ima_iros_prepare * and become j_lpf_get_XYvsE that reads the data from IMOD * [2008-07-07/NJW] * * if (first) { * get_XYvsE(jemx, jmx_id); * first = 0; * } */ Epar = 8; Emean = (Emin + Emax) / 2.0; for (i=0; i= jmx_id->Elist[i]) && (Emean < jmx_id->Elist[i+1])) Epar = i; par1 = xmm * mm2deg; ixpar = (int)((par1 + 5.0) * XvsE_Xvals / 10.0); if (ixpar < 0) ixpar = 0; if (ixpar > XvsE_Xvals - 1) ixpar = XvsE_Xvals - 1; par1 = ymm * mm2deg; iypar = (int)((par1 + 5.0) * YvsE_Yvals / 10.0); if (iypar < 0) iypar = 0; if (iypar > YvsE_Yvals - 1) iypar = YvsE_Yvals - 1; X_correct = jmx_id->XvsE[Epar][ixpar]; Y_correct = jmx_id->YvsE[Epar][iypar]; status1 = coll_transmit(xmm, ymm, jmx_id, logger, transmit); *transmis = transmit[7] * transmit[8] * X_correct * Y_correct; status = 0; sprintf(logger->tmptxt, "%4d, %2d %2d JMX%1d, x/ymm: %6.1f %6.1f, Emin/max: %5.2f %5.2f %5.2f ix/y: %2d %2d, Epar: %2d, trans: %5.3f %5.3f %5.3f %5.3f %5.3f\n", kk++, status, status1, jemx+1, xmm, ymm, Emin, Emax, Eval, ixpar, iypar, Epar, transmit[7], transmit[8], X_correct, Y_correct, *transmis); logger->logstat = logprint(logger, logger->tmptxt, i5); escape: 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); } /***************************************************************** * Name of source file: get_effic.c * Version of source file: 2.0.0 * Parent component: jmx_lib_pif * Programmer: Niels Lund * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * Phone: +45 35325700 FAX: +45 35362475 * njw@spacecenter.dk, nl@spacecenter.dk * Purpose: Calculate efficiency at a given pixel for a given energy. * Evaluate efficiency vs gain slope * Origin date: 071122 * Update history: 1.0.0 071122 First version * 2.0.0 20100125 Version with slope evaluation. * Type of element: Executable * Part of package: jmx_lib_pif * Name: get_effic.c *****************************************************************/ int get_effic(float slow, struct instr_data *jmx_id, float effic[2], int status) /* interpolates the efficiency value based on the 'slow' signal */ { int i; static int k=0; float efficL, efficH, slowL, slowH, slow99; if (slow < jmx_id->eeff_pha[0]) { effic[0] = 0.000001; effic[1] = 0.0000005; goto getout2; } if (slow >= jmx_id->eeff_pha[jmx_id->num_eeff_vals-1]) { effic[0] = jmx_id->eeff[jmx_id->num_eeff_vals-1]; goto getout1; } for (i=0; inum_eeff_vals-1; i++) { slowL = jmx_id->eeff_pha[i]; slowH = jmx_id->eeff_pha[i+1]; efficL = jmx_id->eeff[i]; efficH = jmx_id->eeff[i+1]; if (slow <= slowH) { effic[0] = (efficL * (slowH - slow) + efficH * (slow - slowL)) / (slowH - slowL); goto getout1; } effic[0] = efficH; } getout1: slow99 = slow * 0.99; if (slow99 >= jmx_id->eeff_pha[jmx_id->num_eeff_vals-1]) { effic[1] = jmx_id->eeff[jmx_id->num_eeff_vals-1]; goto getout2; } for (i=0; inum_eeff_vals-1; i++) { slowL = jmx_id->eeff_pha[i]; slowH = jmx_id->eeff_pha[i+1]; efficL = jmx_id->eeff[i]; efficH = jmx_id->eeff[i+1]; if (slow99 <= slowH) { effic[1] = (efficL * (slowH - slow99) + efficH * (slow99 - slowL)) / (slowH - slowL); goto getout2; } effic[1] = efficH; } getout2: k++; return(status); } /* ****************************************************************************** */