# /***************************************************************** * Name of source file: backpro8_2.c * Version of source file: 6.0.0 * 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 * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * Type of element: Function * Part of package: j_ima_iros * Name: backpro8_2 * Returns: * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ #include 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_d.c * Version of source file: 6.0.0 * 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 * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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, i5; int list_index; int numlists, looplim, ix, M, mod, mm, pixlen, iii, status; /* 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); i5 = logger->i5; for (i=0; iskydim; i++) sky[i] = 0.0; for (i=0; isoft_gr[i] <= 0.0) shdgr[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, i5); 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); } /* ************************************************************************** */ /***************************************************************** * Name of source file: backpro8_init.c * Version of source file: 6.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 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 * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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); */ sprintf(logger->tmptxt, "##181## Backprojection group: %s", logger->dolBPL); logger->logstat = logprint(logger, logger->tmptxt, 0); 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: backpro8_W.c * Version of source file: 6.0.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 * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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: backsky_init.c * Version of source file: 6.0.0 * 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 * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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 ); } /* **************************************************************** * Name of source file: blankout.c * Version of source file: 6.0.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@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 * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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); } /* **************************************************** */ /***************************************************************** * Name of source file: calibout.c * Version of source file: 6.0.0 * 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. * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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; OUTSCW.gtiStartIJD = logger->gtiStartIJD; OUTSCW.gtiStopIJD = logger->gtiStopIJD; 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 %8.1f %8.1f %8.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; if (logger->LC) { if (i < 3) { fprintf(calib2, "%2d %9.2f %9.2f %8.0f\n", i, flux, flux_err, sh->totcnt[i]); } else { fprintf(calib2, "%2d %9.2f %9.2f %8.0f %9.2f %9.2f %8.0f\n", i, flux, flux_err, sh->totcnt[i], 100.0*logger->LC_flux[i], 100.0*logger->LC_fl_err[i], logger->LC_counts[i]); } } else { fprintf(calib2, "%2d %9.2f %9.2f %8.0f\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.LC_flux[i] = logger->LC_flux[i+3]; OUTSRC.LC_fl_err[i] = logger->LC_fl_err[i+3]; OUTSRC.LC_counts[i] = logger->LC_counts[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); } /************************************************************************** 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: clean0.c * Version of source file: 6.0.0 * 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 * 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 * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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: clean2.c * Version of source file: 6.0.0 * 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. * 5.1.2 151106 Running version with LC generation * 5.1.16 160930 Update 'clean2', ex2trEvTslc', 'initPIF_LC' and 'work2d' to avoid crashes due to marginal user srcs * 5.1.19 161002 Update 'clean2' and 'srcidentify'o avoid potential index errors * 6.0.0 180112 Introduces LC generation and burst detection * 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=5; 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 */ i5 = logger->i5; 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; sprintf(logger->tmptxt, "Saving source %2d, ix/iy: %3d %3d, ii: %8d", n, ix, iy, ii); logger->logstat = logprint(logger, logger->tmptxt, i5); 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 5x5 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++) { if ((ii+i) < SKYDIM) { if (!jirisnan(skyim[ii+i])) sprintf(logger->tmptxt2, " %5.2f", skyim[ii+i]); else {sprintf(logger->tmptxt2, " NAN "); if (logger->trace) traces(func_local, 91, logger); } } else {sprintf(logger->tmptxt2, " - "); if (logger->trace) traces(func_local, 92, logger); } 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; sprintf(logger->tmptxt, "Restoring source %2d, ix/iy: %3d %3d, ii: %8d", n, ix, iy, ii); logger->logstat = logprint(logger, logger->tmptxt, i5); 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,"##362A## jj = %d! reset to 0", jj); jj = 0; } if ((jj >= 0) && (jj < SKYDIM)) 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: clean.c * Version of source file: 6.0.0 * 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. * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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 ); } /* 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; } /* **************************************************************** */ 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 = 5; 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 */ i5 = logger->i5; 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); } /***************************************************************** * Name of source file: electronic_eff.c * Version of source file: 6.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 * ?.?.? 090429 Corrected initialization value for 'Epar' in line 80 * - and limit logic in line 86 ff * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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; 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; logger->tim_correction = tim_correction; 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; if ((ixy%8192 ) == 120) { sprintf(logger->tmptxt, "EE_effic: %6d, avg_gain: %f, SLOW: %f %f %f, eff_min/mean/max: %f %f %f, final: %f", ixy, sh->avg_gain, eff_min, eff_mean, eff_max, SLOW_min, SLOW_mean, SLOW_max, USERBIN[eeuser].effic_shdg[ixy]); logger->logstat = logprint(logger, logger->tmptxt, i5); } 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: electronic_effLC.c * Version of source file: 6.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 * 5.1.2 151106 Running version with LC generation * 5.1.8 160401 Include evaluation of LC-flux corrections to align with fitted fluxes * 6.0.0 180112 Introduces LC generation and burst detection * Type of element: Executable * Part of package: j_ima_iros * Name: electronic_effLC.c * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ int electronic_effLC( int eeuser, timeslices *Tslice, struct instr_data *jmx_id, userbin *USERBIN, struct log_con *logger) /* log control parameters */ { int i, k, ix, iy, ixy, jemx, i5, index_low, index_hig; int status = 0; float LC_CntWgts[2][16] = { 5.37 ,7.93,18.97,16.36, 5.13, 4.95, 5.19, 3.63, 3.37, 3.18, 2.91,14.44,11.33, 5.84, 4.38, 5.60, 6.55 ,8.90,22.82,21.91, 7.07, 6.62, 6.85, 4.73, 4.22, 3.98, 3.84,18.10,14.36, 7.47, 5.74, 7.23 }; float Elow, Ehig, frac_low, frac_hig, sum_wgt, sum_val; float SLOW_min, SLOW_mean, SLOW_max; float eff_min, eff_mean, eff_max; float effic[2], tim_correction; 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_effLC"); 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); /* RILlogMessage(NULL, Log_0,"##1240## LC_CntWgts values J1: %4d %4d %4d %4d %4d, J2: %4d %4d %4d %4d %4d", LC_CntWgts[0][0], LC_CntWgts[0][1], LC_CntWgts[0][2], LC_CntWgts[0][3], LC_CntWgts[0][4], LC_CntWgts[1][0], LC_CntWgts[1][1], LC_CntWgts[1][2], LC_CntWgts[1][3], LC_CntWgts[1][4]); */ i5 = logger->i5; jemx = jmx_id->jmx_unit; tim_correction = logger->tim_correction; sprintf(logger->tmptxt, "EE_effLC: tim:correction: %f", tim_correction); logger->logstat = logprint(logger, logger->tmptxt, i5); for (ix=0; ix<256; ix++) { for (iy=0; iy<256; iy++) { ixy = 256*ix + iy; Tslice->effic_shdgLC[ixy] = 1.00; /* initialization */ if (jmx_id->spagj[ixy] < 0.0) { Tslice->effic_shdgLC[ixy] = 0.00; continue; } SLOW_min = logger->E_min[eeuser] * Tslice->avGain * (1.0 + jmx_id->curtain[ix]) * jmx_id->spagj[ixy]; SLOW_mean = logger->E_mean[eeuser] * Tslice->avGain * (1.0 + jmx_id->curtain[ix]) * jmx_id->spagj[ixy]; SLOW_max = logger->E_max[eeuser] * Tslice->avGain * (1.0 + jmx_id->curtain[ix]) * jmx_id->spagj[ixy]; status = get_effic(SLOW_min, jmx_id, effic, status); eff_min = effic[0]; status = get_effic(SLOW_mean, jmx_id, effic, status); eff_mean = effic[0]; status = get_effic(SLOW_max, jmx_id, effic, status); eff_max = effic[0]; Tslice->effic_shdgLC[ixy] = 0.25 * (eff_min + eff_max + eff_mean + eff_mean) * tim_correction; if ((ixy%8192 ) == 120) { sprintf(logger->tmptxt, "EE_effLCB: %6d, avg_gain: %f, SLOW: %f %f %f, eff_min/mean/max: %f %f %f, final: %f", ixy, Tslice->avGain, SLOW_min, SLOW_mean, SLOW_max, eff_min, eff_mean, eff_max, Tslice->effic_shdgLC[ixy]); logger->logstat = logprint(logger, logger->tmptxt, i5); } } } /* * LC-flux/Fit-flux for NL 16 standard energy bands Ehigh 3.0 3.5 4.5 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 12.0 16.0 20.0 25.0 35.0 keV * before orbit 102 JEMX1 0.25 0.42 0.94 0.97 0.85 0.85 0.90 0.83 0.85 0.83 0.81 1.03 1.04 1.15 1.44 2.43 * after orbit 102 JEMX1 0.80 0.82 0.94 0.97 0.85 0.85 0.90 0.83 0.85 0.83 0.81 1.03 1.04 1.15 1.44 2.43 * before orbit 102 JEMX2 0.62 0.64 0.94 0.98 0.87 0.87 0.91 0.85 0.87 0.85 0.83 1.05 1.06 1.14 1.41 2.37 * after orbit 102 JEMX2 0.79 0.82 0.94 0.98 0.87 0.87 0.91 0.85 0.87 0.85 0.83 1.05 1.06 1.14 1.41 2.37 Derived 26/1 2016 by 'fluxana' LC_CntWgts[2][16] = { 537 ,793,1897,1636, 513, 495, 519, 363, 337, 318, 291,1444,1133, 584, 438, 560, 655 ,890,2282,2191, 707, 662, 685, 473, 422, 398, 384,1810,1436, 747, 574, 723 jmx_id->LCcor[ 0] = 0.80; jmx_id->LCcor[ 1] = 0.82; jmx_id->LCcor[ 2] = 0.94; jmx_id->LCcor[ 3] = 0.98; jmx_id->LCcor[ 4] = 0.86; jmx_id->LCcor[ 5] = 0.86; jmx_id->LCcor[ 6] = 0.90; jmx_id->LCcor[ 7] = 0.84; jmx_id->LCcor[ 8] = 0.86; jmx_id->LCcor[ 9] = 0.84; jmx_id->LCcor[10] = 0.82; jmx_id->LCcor[11] = 1.04; jmx_id->LCcor[12] = 1.05; jmx_id->LCcor[13] = 1.14; jmx_id->LCcor[14] = 1.42; jmx_id->LCcor[15] = 2.40; */ Elow = USERBIN[eeuser].E_min; if (Elow < jmx_id->Elist[0]) Elow = jmx_id->Elist[0]; if (Elow > jmx_id->Elist[XYvsE_Evals]) Elow = jmx_id->Elist[XYvsE_Evals]; Ehig = USERBIN[eeuser].E_max; if (Ehig < jmx_id->Elist[0]) Elow = jmx_id->Elist[0]; if (Ehig > jmx_id->Elist[XYvsE_Evals]) Elow = jmx_id->Elist[XYvsE_Evals]; /* Find for each of the two E-interval borders the calibration bin in which they are located */ index_low = XYvsE_Evals; frac_low = 1.0; for (i=1; i< XYvsE_Evals; i++) { if (Elow <= jmx_id->Elist[i]) { index_low = i - 1; frac_low = (jmx_id->Elist[i] - Elow) / (jmx_id->Elist[i] - jmx_id->Elist[i-1]); break; } } index_hig = XYvsE_Evals; frac_hig = 1.0; for (i=1; i<= XYvsE_Evals; i++) { if (Ehig <= jmx_id->Elist[i]) { index_hig = i-1; frac_hig = (Ehig - jmx_id->Elist[i-1]) / (jmx_id->Elist[i] - jmx_id->Elist[i-1]); break; } } sum_val = sum_wgt = 0.00001; sum_val += frac_low * jmx_id->LCcor[index_low] * LC_CntWgts[jemx][index_low]; sum_wgt += frac_low * LC_CntWgts[jemx][index_low]; sprintf(logger->tmptxt, "J%1d eeuser: %2d, index_low: %2d, frac_low: %4.2f, sum_val: %7.2f; sum_wgt: %7.2f, Cor: %5.2f, CW: %4.2f", jemx, eeuser, index_low, frac_low, sum_val, sum_wgt, jmx_id->LCcor[index_low], LC_CntWgts[jemx][index_low]); logger->logstat = logprint(logger, logger->tmptxt, i5); sum_val += frac_hig * jmx_id->LCcor[index_hig] * LC_CntWgts[jemx][index_hig]; sum_wgt += frac_hig * LC_CntWgts[jemx][index_hig]; sprintf(logger->tmptxt, "J%1d eeuser: %2d, index_hig: %2d, frac_hig: %4.2f, sum_val: %7.2f; sum_wgt: %7.2f, Cor %5.2f, CW: %4.2f", jemx, eeuser, index_hig, frac_hig, sum_val, sum_wgt, jmx_id->LCcor[index_hig], LC_CntWgts[jemx][index_hig]); logger->logstat = logprint(logger, logger->tmptxt, i5); for (i=index_low+1; iLCcor[i] * LC_CntWgts[jemx][i]; sum_wgt += LC_CntWgts[jemx][i]; sprintf(logger->tmptxt, "J%1d eeuser: %2d, index: %2d, sum_val: %7.2f; sum_wgt: %7.2f, Cor %5.2f, CW: %4.2f", jemx, eeuser, i, sum_val, sum_wgt, jmx_id->LCcor[i], LC_CntWgts[jemx][i]); logger->logstat = logprint(logger, logger->tmptxt, i5); } USERBIN[eeuser].LCcorrec = sum_val / sum_wgt; sprintf(logger->tmptxt, "eeuser: %2d, Elow/high: %5.1lf %5.1lf, LCcorrec: %4.2f", eeuser, Elow, Ehig, USERBIN[eeuser].LCcorrec); logger->logstat = logprint(logger, logger->tmptxt, 0); 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: errorfit2.c * Version of source file: 6.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 * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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: errorfit.c * Version of source file: 6.0.0 * 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. * 5.1.2 151106 Running version with LC generation * 5.1.10 160829 Circumvent analysis blocking caused by small amount of data in 'errorfit' * 6.0.0 180112 Introduces LC generation and burst detection * Type of element: Function * Part of package: j_ima_iros * Name: errorfit * Required components: DAL, PIL, RIL, DAL3GEN * See line 303 and 383 *****************************************************************/ 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 finished; /* 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: if (status == -3) {status = ISDC_OK; backproj->errsolut[q] = -8.88;} else 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: ex2trEvTslc.c * Version of source file: 6.0.0 * Parent component: None * Programmer: Niels Lund * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * nl@space.dtu.dk * Purpose: Extract events for current source & energy from event list and place in timeslices * Origin date: 20130328 * Update history: 1.0.0 20130328 First version * 5.1.2 151106 Running version with LC generation * 5.1.8 160404 Include correction of LC-fluxes to align with fitted fluxes * 5.1.9 160415 Update of light curve output and keywords according to agreement with ISDC * 5.1.16 160930 Update 'clean2', ex2trEvTslc', 'initPIF_LC' and 'work2d' to avoid crashes due to marginal user srcs * 5.1.24 161227 Correct work2d. Handling of 'edge'-bursts, Handling of bursts after 'summary_p', * 5.1.25 161228 Correct work2d. Initialization of Tslices[].threshold. 'Eliminate bad print in 'ex2trEvTslc' * 6.0.0 180112 Introduces LC generation and burst detection * Type of element: Function * Part of package: j_ima_iros * Name: ex2trEvTslc * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ /* QQQQQQ */ int ex2trEvTslc( int allsrc, int eeuser, timeslices *Tslice, Events *bufevents, pifmap *PIFmap, struct shadowgrams *sh, struct backpro *backproj, userbin *USERBIN, struct log_con *logger, int status) { int i, j, k, m, i5, nevent, ixy, prevent, bad, chan; static int oldsrc=1000, old_ee=1000; float sum_effic, num_effic, flux = 0.0, bflux = 0.0, ff, bff; float sum_Weffic, num_Weffic, fl_err = 0.0, bfl_err = 0.0, sumChans = 0.0; float sum_srcCounts = 0.0, sum_srcWCounts = 0.0, sum_bkgCounts = 0.0, sum_bkgWCounts = 0.0; float sum_final_expo = 0.0, sum_av_WEff = 0.0; float sumflux0, sumflux1, sumflux2=0.0; float bsumflux0, bsumflux1, bsumflux2=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], "ex2trEvTslc"); 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; if ((allsrc != oldsrc) || (eeuser != old_ee)) { oldsrc = allsrc; old_ee = eeuser; j = k = m = 0; for (i=0; icommon_select_map[i] > 0) { j++; for (chan=0; chanNumTimeBins; chan++) if (Tslice[chan].effic_shdgLC[i] <= 0.0) bad |= 1; } if (bad == 0) backproj->soft_gr[i] = USERBIN[eeuser].soft_gr[i]; else backproj->soft_gr[i] = -1.0; /* this pixel should not be used */ if (backproj->soft_gr[i] > 0.0) k++; if (USERBIN[eeuser].soft_gr[i] > 0.0) m++; } if ((allsrc > 0) && (allsrc < 90)) { sprintf(logger->tmptxt, "extrE E%1d src%02d select_map: %5d, USERBIN.soft_gr: %5d, backproj->soft_gr: %5d", eeuser, allsrc, j, k, m); logger->logstat = logprint(logger, logger->tmptxt, i5); } } nevent = 0; if ((allsrc > 0) && (allsrc < 90)) { sprintf(logger->tmptxt, "extrE S%2d E%1d, wsrc_sill: %6.0f, wpixA: %6.0f, pixA: %6.0f, wbkg_sill: %6.0f, wpixA: %6.0f, pixA: %6.0f\n", allsrc, eeuser, PIFmap[allsrc].wsrc_src_illum, PIFmap[allsrc].wsrc_pixel_area, PIFmap[allsrc].src_pixel_area, PIFmap[allsrc].wbkg_src_illum, PIFmap[allsrc].wbkg_pixel_area, PIFmap[allsrc].bkg_pixel_area); logger->logstat = logprint(logger, logger->tmptxt, i5); } sumflux0 = sumflux1 = sumflux2 = 0.0; bsumflux0 = bsumflux1 = bsumflux2 = 0.0; for (chan=0; chanNumTimeBins; chan++) { Tslice[chan].srcWCounts = 0.0; Tslice[chan].srcCounts = 0.0; Tslice[chan].bkgWCounts = 0.0; Tslice[chan].bkgCounts = 0.0; if (allsrc == 0) { Tslice[chan].Events = 0.0; Tslice[chan].wEvents = 0.0; } Tslice[chan].av_WEff = 1.0; Tslice[chan].av_Eff = 1.0; Tslice[chan].burstflag = 0; Tslice[chan].wflux[allsrc] = 0.0; Tslice[chan].wfErr[allsrc] = 0.0; Tslice[chan].wbflux[allsrc] = 0.0; Tslice[chan].wbfErr[allsrc] = 0.0; flux = 0.0; } if ((PIFmap[allsrc].wsrc_src_illum == 0.0) || (PIFmap[allsrc].wsrc_pixel_area == 0.0) || (PIFmap[allsrc].wbkg_pixel_area == 0.0)) if (allsrc > 0) goto skip_LC_eval; for (chan=0; chanNumTimeBins; chan++) { Tslice[chan].srcWCounts = 0.0; Tslice[chan].srcCounts = 0.0; Tslice[chan].bkgWCounts = 0.0; Tslice[chan].bkgCounts = 0.0; if (allsrc == 0) { Tslice[chan].Events = 0.0; Tslice[chan].wEvents = 0.0; } Tslice[chan].av_WEff = 1.0; Tslice[chan].av_Eff = 1.0; Tslice[chan].burstflag = 0; flux = 0.0; /* Tslice[chan].dontUse &= 0xFFFD; */ /* mask away dontUse-flags specific for previous source */ if (Tslice[chan].dontUse > 0) goto nextTslice; sum_effic = num_effic = 0.0; sum_Weffic = num_Weffic = 0.0; /* loop over eventlist */ while (nevent < logger->numEvents) { if (bufevents[nevent].ijd < Tslice[chan].Tstart) goto nextevent; if (bufevents[nevent].ijd >= Tslice[chan].Tstop) goto next_chan; ixy = bufevents[nevent].rawx * 256 + bufevents[nevent].rawy; if ((ixy < 0) || (ixy >= detdim)) { sprintf(logger->tmptxt, "%7d, rawx/y: %4d %4d", nevent, bufevents[nevent].rawx, bufevents[nevent].rawy); logger->logstat = logprint(logger, logger->tmptxt, i5); goto nextevent; } if ((backproj->soft_gr[ixy] > 0.0) && (bufevents[nevent].status < 1024)) { if ((bufevents[nevent].pi >= sh->pival[eeuser][0]) && (bufevents[nevent].pi < sh->pival[eeuser][1])) { if (allsrc == 0) { Tslice[chan].Events += 1.0; Tslice[chan].wEvents += PIFmap[allsrc].wgt_map[ixy]; goto nextevent; } if (PIFmap[allsrc].bkg_pixel_map[ixy] > 0.0) { sum_effic += Tslice[chan].effic_shdgLC[ixy]; num_effic += 1.0; sum_Weffic += Tslice[chan].effic_shdgLC[ixy] * PIFmap[allsrc].wgt_map[ixy]; num_Weffic += PIFmap[allsrc].wgt_map[ixy]; Tslice[chan].bkgCounts += 1.0; Tslice[chan].bkgWCounts += PIFmap[allsrc].wgt_map[ixy]; } if (PIFmap[allsrc].src_pixel_map[ixy] > 0.0) { sum_effic += Tslice[chan].effic_shdgLC[ixy]; num_effic += 1.0; sum_Weffic += Tslice[chan].effic_shdgLC[ixy] * PIFmap[allsrc].wgt_map[ixy]; num_Weffic += PIFmap[allsrc].wgt_map[ixy]; Tslice[chan].srcCounts += 1.0; Tslice[chan].srcWCounts += PIFmap[allsrc].wgt_map[ixy]; } } } nextevent: /* nextevent: */ nevent++; } next_chan: /* next_chan */ if (allsrc == 0) goto nextTslice; Tslice[chan].av_WEff = Tslice[chan].av_Eff = 1.0; if ((num_Weffic > 0.0) && (sum_Weffic > 0.0)) Tslice[chan].av_WEff = sum_Weffic / num_Weffic; if ((num_effic > 0.0) && (sum_effic > 0.0)) Tslice[chan].av_Eff = sum_effic / num_effic; bflux = 0.0; flux = 0.0; bfl_err = 0.0; fl_err = 0.0; if ((PIFmap[allsrc].wsrc_pixel_area > 0.0) && (PIFmap[allsrc].wbkg_pixel_area > 0.0)) { sum_srcCounts += Tslice[chan].srcCounts; sum_srcWCounts += Tslice[chan].srcWCounts; sum_bkgCounts += Tslice[chan].bkgCounts; sum_bkgWCounts += Tslice[chan].bkgWCounts; sum_final_expo += Tslice[chan].final_expo; sum_av_WEff += Tslice[chan].av_WEff; sumChans += 1.0; /* get source flux */ flux = Tslice[chan].srcWCounts * PIFmap[allsrc].hi_illum_wfac2 / PIFmap[allsrc].wsrc_pixel_area - Tslice[chan].bkgWCounts * PIFmap[allsrc].lo_illum_wfac2 / PIFmap[allsrc].wbkg_pixel_area; /* Calculate absolute count error (Poisson only) */ ff = PIFmap[allsrc].wsrc_pixel_area / PIFmap[allsrc].wbkg_pixel_area; fl_err = sqrt(Tslice[chan].srcWCounts + ff * ff * Tslice[chan].bkgWCounts); fl_err *= (PIFmap[allsrc].hi_illum_wfac2 / PIFmap[allsrc].wsrc_pixel_area); /* get background flux (Note: The background is specific for each specific source) */ bflux = Tslice[chan].bkgWCounts * PIFmap[allsrc].lo_illum_wfac3 / PIFmap[allsrc].wbkg_pixel_area - Tslice[chan].srcWCounts * PIFmap[allsrc].hi_illum_wfac3 / PIFmap[allsrc].wsrc_pixel_area; /* Calculate absolute count error (Poisson only) */ bff = PIFmap[allsrc].wbkg_src_illum / PIFmap[allsrc].wsrc_src_illum / (ff * ff); bfl_err = sqrt(Tslice[chan].bkgWCounts + bff * bff * Tslice[chan].srcWCounts); bfl_err *= (PIFmap[allsrc].lo_illum_wfac3 / PIFmap[allsrc].wbkg_pixel_area); } if ((Tslice[chan].av_WEff > 0.0) && (Tslice[chan].final_expo > 0.0)) { flux *= 100.0 / (Tslice[chan].final_expo * Tslice[chan].av_WEff); bflux *= 100.0 / (Tslice[chan].final_expo * Tslice[chan].av_WEff); fl_err *= 100.0 / (Tslice[chan].final_expo * Tslice[chan].av_WEff); bfl_err *= 100.0 / (Tslice[chan].final_expo * Tslice[chan].av_WEff); if (allsrc >= 90) flux = 100.0 * Tslice[chan].srcWCounts / (Tslice[chan].final_expo * Tslice[chan].av_WEff); sumflux0 += 1.0; sumflux1 += flux; sumflux2 += flux * flux; bsumflux0 += 1.0; bsumflux1 += bflux; bsumflux2 += bflux * bflux; } else { Tslice[chan].dontUse |= 1; /* set dontUse flag for this time bin */ flux = 0.0; bflux = 0.0; } if ((allsrc > 0) && (allsrc < 90) && (chan%100 == 50)) { sprintf(logger->tmptxt, "extrE: srcCts: %3.0f %5.1f, bkgCts: %3.0f %5.1f, flux: %7.4f +/- %7.4f, bkg: %7.4f +/- %7.4f, av_WEff: %6.4f", Tslice[chan].srcCounts, Tslice[chan].srcWCounts, Tslice[chan].bkgCounts, Tslice[chan].bkgWCounts, flux, fl_err, bflux, bfl_err, Tslice[chan].av_WEff); logger->logstat = logprint(logger, logger->tmptxt, i5); } nextTslice: /* nextTslice: */ Tslice[chan].wflux[allsrc] = flux / USERBIN[eeuser].LCcorrec; Tslice[chan].wfErr[allsrc] = fl_err / USERBIN[eeuser].LCcorrec; Tslice[chan].wbflux[allsrc] = bflux / USERBIN[eeuser].LCcorrec; Tslice[chan].wbfErr[allsrc] = bfl_err / USERBIN[eeuser].LCcorrec; } skip_LC_eval: ; if ((allsrc == 0) || (allsrc >= 90)) goto slut; if ((PIFmap[allsrc].wsrc_pixel_area > 0.0) && (PIFmap[allsrc].wbkg_pixel_area > 0.0)) { /* Get overall source flux */ flux = sum_srcWCounts * PIFmap[allsrc].hi_illum_wfac2 / PIFmap[allsrc].wsrc_pixel_area - sum_bkgWCounts * PIFmap[allsrc].lo_illum_wfac2 / PIFmap[allsrc].wbkg_pixel_area; /* Calculate absolute count error (Poisson only) */ ff = PIFmap[allsrc].wsrc_pixel_area / PIFmap[allsrc].wbkg_pixel_area; fl_err = sqrt(sum_srcWCounts + ff * ff * sum_bkgWCounts); fl_err *= (PIFmap[allsrc].hi_illum_wfac2 / PIFmap[allsrc].wsrc_pixel_area); /* Get overall background flux */ bflux = sum_bkgWCounts * PIFmap[allsrc].lo_illum_wfac3 / PIFmap[allsrc].wbkg_pixel_area - sum_srcWCounts * PIFmap[allsrc].hi_illum_wfac3 / PIFmap[allsrc].wsrc_pixel_area; /* calculate absolute count error (Poisson only) */ bff = PIFmap[allsrc].wbkg_src_illum / PIFmap[allsrc].wsrc_src_illum / (ff * ff); bfl_err = sqrt(sum_bkgWCounts + bff * bff * sum_srcWCounts); bfl_err *= (PIFmap[allsrc].lo_illum_wfac3 / PIFmap[allsrc].wbkg_pixel_area); } sum_av_WEff /= (sumChans + 0000001); if ((sum_av_WEff > 0.0) && (sum_final_expo > 0.0)) { flux *= 100.0 / (sum_final_expo * sum_av_WEff); bflux *= 100.0 / (sum_final_expo * sum_av_WEff); fl_err *= 100.0 / (sum_final_expo * sum_av_WEff); bfl_err *= 100.0 / (sum_final_expo * sum_av_WEff); sprintf(logger->tmptxt, "extrE:§Src %1d E %2d TotsrcCt %5.0f %7.1f bkgCts %5.0f %7.1f flux %7.4f +/- %7.4f bkg %6.4f +/- %6.4f", allsrc, eeuser, sum_srcCounts, sum_srcWCounts, sum_bkgCounts, sum_bkgWCounts, flux, fl_err, bflux, bfl_err); logger->logstat = logprint(logger, logger->tmptxt, i5); } if (allsrc == backproj->backmodels) { logger->LC_flux[eeuser] = flux / USERBIN[eeuser].LCcorrec; logger->LC_fl_err[eeuser] = fl_err / USERBIN[eeuser].LCcorrec; logger->LC_counts[eeuser] = sum_srcWCounts; } /* if ((sumflux0 > 0.0) && (bsumflux0 > 0.0)) { flux = sumflux1 / sumflux0; fl_err = sqrt(sumflux2 / sumflux0 - flux * flux); bflux = bsumflux1 / bsumflux0; bfl_err = sqrt(bsumflux2 / bsumflux0 - bflux * bflux); sprintf(logger->tmptxt, "extrE:§Src %1d E %2d TotsrcCt %5.0f %7.1f Mean & RMS for %4.0f fluxes %7.4f +/- %7.4f %7.4f bkg %6.4f +/- %6.4f", allsrc, eeuser, sum_srcCounts, sum_srcWCounts, sumflux0, flux, fl_err, fl_err/sqrt(sumflux0), bflux, bfl_err); logger->logstat = logprint(logger, logger->tmptxt, 0); } */ 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 ); } /***************************************************************** * Name of source file: fill_burst_shd.c * Version of source file: 6.0.0 * 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 35325705 FAX: +45 35362475 * njw@space.dtu.dk, nl@space.dtu.dk * Purpose: Create a burst shadowgram from the event list * Origin date: 20130321 * Update history: 1.0 20130321 First version * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * Type of element: Function * Part of package: j_ima_iros * Name: fill_burst_shd *****************************************************************/ int fill_burst_shd( double IJDstart, double IJDstop, int EchanMin, int EchanMax, Events *bufevents, long nEvents, Auxdata auxdata, Shd_adhoc *shd_burst, 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 float temp_shd[detdim]; 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_burst_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 */ if (logger->trace) traces(func_local, 0, logger); /* * 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, nEvents: %8ld", IJDstart, IJDstop, EchanMin, EchanMax, nEvents ); /* Initialize the shadowgram */ for(i=0;ishd[i] = 0.0; /* Update the shd_burst struct */ shd_burst->tstart = IJDstart; shd_burst->tstop = IJDstop; shd_burst->chanMin = EchanMin; shd_burst->chanMax = EchanMax; /* Define event-time buffer to use as argument for 'j_iir_bin_search' since it must have a double-pointer */ dblBuffer = (double *) malloc( nEvents * sizeof(double) ); for(i=0;itrace) traces(func_local, 10, logger); if( i2 > 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_burst->nEvs = 0; for( i = i1; i <= i2; i++ ) { if( bufevents[i].pi < EchanMin || bufevents[i].pi > EchanMax ) continue; shd_burst->nEvs++; idx = bufevents[i].rawx * J_IIR_DIM_STDSHDG + bufevents[i].rawy; shd_burst->shd[idx]++; gain_sum += bufevents[i].gain; } if (shd_burst->nEvs > 0) shd_burst->gain = gain_sum / shd_burst->nEvs; else shd_burst->gain = 22.9999; /* presumably not used */ } else { shd_burst->nEvs = 0; shd_burst->gain = 22.9999; /* presumably not used */ } if (logger->trace) traces(func_local, 20, logger); RILlogMessage( NULL, Log_0, "##5103## nEvs = %ld, gain = %8.4f", shd_burst->nEvs, shd_burst->gain ); /* for (i=0; ishd[i]; status = fits_test_output( "burst_shd_", temp_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); } if (logger->trace) traces(func_local, 30, logger); shd_burst->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_burst->exposure *= (1.-deadtime_sum/i2)*(greyfilter_sum/i2); } RILlogMessage( NULL, Log_0, "##5118## Final exposure : %9.3lf", shd_burst->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: final_fit.c * Version of source file: 6.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: 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 * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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][BASIC_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 = 5, logi5; int i, j, k, chk_no, q; int isrc, jsrc, n_src, jb, pd, allsrc, iisum; 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); logger->eeuser = 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; for (allsrc=backproj->backmodels; allsrcsoft_gr[i] > 0.0) iisum += backproj->pif_b_pickmap[allsrc][i]; if (logger->trace) traces(func_local, 2000000+allsrc*100000+iisum, logger); } if (logger->trace) traces(func_local, 10030+backproj->additional, logger); if (status != ISDC_OK) { if (logger->trace) traces(func_local, 77000, logger); if (logger->trace) traces(func_local, 1000000-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, 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, 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, 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]; GOODSRC[SCW_SRCMAX-2].src_strength[eeuser] = solut[0]; /* Save fitted flux and flux error for source components */ 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:B ee: %2d, jsrc:§%2d, o_src_good: %2d, src_pix_A: %5.2f, src_str: %6.1f, eff/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, GOODSRC[o_src_good].transmis[eeuser]); 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", 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, 0); 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, 0); } } 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: 6.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 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 * 5.1.2 151106 Running version with LC generation * 5.1.16 160930 Update 'clean2,ex2trEvTslc,initPIF_LC,work2d' to avoid crashes due to marginal user srcs * 5.1.23 161220 Correct peaktransfer & final_sky. Endless loop in peaktransfer for sources near edge of FOV * 5.1.33 171206 Write RTSTART/STOP in sky_ima, srcl_res iros_lc files. Introduce logger->LCgtiREF * 5.1.34 171214 Correct flux error calculation for user sources (new parameter in call to final_sky) * 6.0.0 170112 Rename V5.1.34 to V6.0.0 * 6.0.0 180112 Introduces LC generation and burst detection * 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, int n_commonX, 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 = 5, ix, iy, ixy, jj; int jemx, dim1, dim2, bitpix, ipeak; int map_n, xvalstart, yvalstart, n; int skysize, NoPifFlag = 0; int j_src, pktr; 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], Skyim_R[SKYDIM], WGT_SKY[SKYDIM], FIM0[SKYDIM], FIM1[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); if (logger->trace) traces(func_local, 10000+n_commonX, 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); if (logger->burst_image == 1) goto burst_image; 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 (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, "Asource %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); } 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]); if (weight_shdg[i] > 1.0) weight_shdg[i] = 1.0; if (weight_shdg[i] < 0.0) weight_shdg[i] = 0.0; } else weight_shdg[i] = 0.0; } /* NLNLNL */ eff_imag_max = -1000.0; eff_imag_min = +1000.0; varim_min = 1.0e20; varim_max = -1.0e20; for (i=0; isoft_gr[i] > 0.0) { if (eff_imag_min > weight_shdg[i]) eff_imag_min = weight_shdg[i]; if (eff_imag_max < weight_shdg[i]) eff_imag_max = weight_shdg[i]; if (sh->backall[i] > varim_max) varim_max = sh->backall[i]; if (sh->backall[i] < varim_min) varim_min = sh->backall[i]; } } sprintf(logger->tmptxt, "##8634A## eeuser: %2d, wgt_shdg_min/max: %6.3e %6.3e, backall min/max: %6.3e %6.3e", eeuser, eff_imag_min, eff_imag_max, varim_min, varim_max); logger->logstat = logprint(logger, logger->tmptxt, i5); /* NLNLNL */ 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); /* NLNLNL */ eff_imag_max = -1000.0; eff_imag_min = +1000.0; varim_min = 1.0e20; varim_max = -1.0e20; 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 (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]; } } sprintf(logger->tmptxt, "##8634B## eeuser: %2d,wgtsky_min/max: %6.3e %6.3e, fitsima[ee][0]: %6.3e %6.3e", eeuser, eff_imag_min, eff_imag_max, varim_min, varim_max); logger->logstat = logprint(logger, logger->tmptxt, i5); /* NLNLNL */ if (logger->trace) traces(func_local, 1000+n_common2, logger); if (n_common2 > 0) { for (n_src=0; n_srcsoft_gr[i] > 0.0) { if (sh->backam1[n_src][i] == 0.0) { status = -10; goto exittrace; } weight_shdg[i] = sh->backcmp[i] * sh->backcmp[i] / (sh->backam1[n_src][i] * sh->backam1[n_src][i]); if (weight_shdg[i] > 1.0) weight_shdg[i] = 1.0; if (weight_shdg[i] < 0.0) weight_shdg[i] = 0.0; } else weight_shdg[i] = 0.0; } if (logger->trace) traces(func_local, 2000+n_src, logger); status = backpro8_W(sh->resid, USERBIN[eeuser].effic_shdg, weight_shdg, USERBIN[eeuser].shadow, logger->resid1, Skyim_R, WGT_SKY, FIM0, FIM1, logger, backproj, bp); if (logger->trace) traces(func_local, 3000+status, logger); status = srcimatransfer(xx[backproj->backmodels+isrc], yy[backproj->backmodels+isrc], Skyim_R, WGT_SKY, FIM0, FIM1, backproj->skyim_r, weight_sky, backproj->fitsimage[ee3][0], backproj->fitsimage[ee3][1], backproj->sky_ydim, logger); if (logger->trace) traces(func_local, 4000+status, logger); /* NLNLNL */ eff_imag_max = -1000.0; eff_imag_min = +1000.0; varim_min = 1.0e20; varim_max = -1.0e20; for (i=0; isoft_gr[i] > 0.0) { if (eff_imag_min > weight_shdg[i]) eff_imag_min = weight_shdg[i]; if (eff_imag_max < weight_shdg[i]) eff_imag_max = weight_shdg[i]; if (sh->backam1[n_src][i] > varim_max) varim_max = sh->backam1[n_src][i]; if (sh->backam1[n_src][i] < varim_min) varim_min = sh->backam1[n_src][i]; } } sprintf(logger->tmptxt, "##8634C## src: %1d, ee: %2d,weight_min/max: %6.3e %6.3e, backam1[%1d]: %6.3e %6.3e", n_src, eeuser, eff_imag_min, eff_imag_max, n_src, varim_min, varim_max); logger->logstat = logprint(logger, logger->tmptxt, i5); /* NLNLNL */ } } } else { status = backpro8_d(sh->resid, backproj->skyim_r, logger, backproj, bp); } if (n_commonX == 0) { sprintf(logger->tmptxt, "##80## No 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, "Bsource %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 ); sprintf(logger->tmptxt, "Return from clean2 A, status: %d", status); logger->logstat = logprint(logger, logger->tmptxt, i5); /* 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 ); sprintf(logger->tmptxt, "Return from clean2 B, status: %d", status); logger->logstat = logprint(logger, logger->tmptxt, i5); /* 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; sprintf(logger->tmptxt, "Csource %1d: X: %6.2f, Y: %6.2f, eeuser: %2d, ee3: %2d", isrc, xx[backproj->backmodels+isrc], yy[backproj->backmodels+isrc], eeuser, ee3); logger->logstat = logprint(logger, logger->tmptxt, i5); if (logger->trace) traces(func_local, 100000+1000*logger->peak_last+isrc, logger); 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); if (peakval[eeuser][isrc] < 0) { sprintf(logger->tmptxt, "Source %2d too close to the edge, no imagetransfer done", isrc); logger->logstat = logprint(logger, logger->tmptxt, 0); mean_bkg[0] = 1.0; peakcount[0] = peakcount[1] = 1.0; peakval[eeuser][isrc] = 1.0; detsig[0] = 1.0; } 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_commonX].src_pixel_area[eeuser]; * GOODSRC[logger->n_commonX].flux_err[eeuser] = sqrt(rawcount) + (Anoise / Apix) * fabs(peakcount[0]); * GOODSRC[logger->n_commonX].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; if (logger->trace) traces(func_local, 5000+1000*logger->peak_last+isrc, logger); pktr = peaktransfer(xx[backproj->backmodels+isrc], yy[backproj->backmodels+isrc], imgpeak[ee3], backproj->fitsimage[ee3][4], peakcount, mean_bkg, ee3, detsig, backproj, logger); if (pktr < 0) { detsig[0] = 1.0; } 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 ); sprintf(logger->tmptxt, "Return from clean2 C, status: %d", status); logger->logstat = logprint(logger, logger->tmptxt, i5); 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 */ findpeak2(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 */ findpeak2(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 */ logger->logstat = logprint(logger, logger->tmptxt, 0); 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]; /* NLNLNL 2014 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, i5); } 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, i5); 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, i5); } vigncorr = 1; } else vigncorr = 0; sprintf(logger->tmptxt, "##8834## eeuser: %2d, n_factor: %6.3e, eff_imag_min: %6.3e, eff_imag_max: %6.3e", 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: %6.3e, nn_f_max: %6.3e, varim_min: %6.3e, varim_max: %6.3e", 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 */ f_struc2->RTStart = logger->RTStart; f_struc2->RTStop = logger->RTStop; /* +++++++++++++++++++++++++++++++++++++++++++++++++ */ /* 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)) { /* ( strstr( logger->skyImagesOut, "NONE" ) == NULL) && (logger->LC == 0)) { logger->LC==0 elim. NLNLNL */ if (logger->trace) traces(func_local, 70, logger); skyout( theSWG, jmx_id, logger, backproj, sh, f_struc2, USERBIN, imgpeak[ee3], e_minim, e_maxim, ee3, eeuser, vigncorr, chatter, status); /* NLNLNL 20140827 nnF, 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, USERBIN, imgpeak[ee3], e_minim, e_maxim, ee3, eeuser, vigncorr, chatter, status); /* NLNLNL 20140827 nnF, 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; /* BBBBB */ burst_image: if (logger->trace) traces(func_local, 1000000+(int)(logger->burst_Tstart*100.0), logger); if (logger->trace) traces(func_local, 1000000+(int)(logger->burst_Tstop*100.0), logger); f_struc2->exposure = (logger->burst_Tstop - logger->burst_Tstart) * 86400.0; f_struc2->RTStart = logger->burst_Tstart; f_struc2->RTStop = logger->burst_Tstop; ee3 = eeuser; if (ee3 > backproj->ee_basic ) ee3 = backproj->ee_basic; 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 burst sky image as FITS */ logger->skipNeighborCor = bp->skipNeighborCor; if ( strstr( logger->skyImagesOut, "NONE" ) == NULL) { if (logger->trace) traces(func_local, 85, logger); skyout( theSWG, jmx_id, logger, backproj, sh, f_struc2, USERBIN, imgpeak[ee3], e_minim, e_maxim, ee3, eeuser, vigncorr, chatter, status); } logger->burst_image = 0; /* reset flag */ goto slut; } /* **************************************************************** * Name of source file: findpeak2.c * Version of source file: 6.0.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@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 * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * Type of element: Function * Part of package: j_ima_iros **************************************************************** */ int findpeak2(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, smaxy, xyskydim, ok; float x_cent, y_cent, contrib, 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, skval; 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); amax[2] = 0.0; amax[3] = 0.0; amax[4] = 0.0; amax[5] = 0.0; 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: %lf\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); } /* 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); } /* **************************************************** */ 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; } /***************************************************************** * Name of source file: fits_test_output.c * Version of source file: 6.0.0 * 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 * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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, 10, logger); /* * Compose filename */ strcpy( test_file_name, basefilename ); getnextautoname( next_number ); strcat( test_file_name, next_number ); strcat( test_file_name, ".fits" ); RILlogMessage( NULL, Log_0, "##363## test file: %s", test_file_name); if (logger->trace) traces(func_local, 20, logger); fits_status = 0; fits_create_file( &ftestptr, test_file_name, &fits_status ); if( fits_status != 0 ) { RILlogMessage( NULL, Error_0, "##364## CFITSIO error %d", fits_status); status = -1000 - fits_status; goto exittrace; } if (logger->trace) traces(func_local, 30, logger); naxes[0] = dim; naxes[1] = dim; numValues = naxes[0]*naxes[1]; fits_create_img( ftestptr, FLOAT_IMG, naxis, naxes, &fits_status); if( fits_status != 0 ) { RILlogMessage( NULL, Error_0, "##365## CFITSIO error %d", fits_status); status = -1000 - fits_status; goto exittrace; } if (logger->trace) traces(func_local, 40, logger); fits_write_img( ftestptr, TFLOAT, 1L, numValues, array, &fits_status); if( fits_status != 0 ) { RILlogMessage( NULL, Error_0, "##366## CFITSIO error %d", fits_status); status = -1000 - fits_status; goto exittrace; } if (logger->trace) traces(func_local, 50, logger); fits_close_file( ftestptr, &fits_status ); if( fits_status != 0 ) { RILlogMessage( NULL, Error_0, "##367## CFITSIO error %d", fits_status); status = -1000 - fits_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: fluxerror.c * Version of source file: 6.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: 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 * 5.1.2 151106 Running version with LC generation * 5.1.34 171214 Correct flux error calculation for user sources (new parameter in call to final_sky) * 6.0.0 170112 Rename V5.1.34 to V6.0.0 * 6.0.0 180112 Introduces LC generation and burst detection * 6.0.9 180925 Reinstate writing of burst images in sky_ima files. * 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( GOODSRC[o_src_good].src_pixel_area[eeuser] < 1.0) GOODSRC[o_src_good].flux[eeuser] = 0.001; /* NLNLNL 20180925 */ 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 (logger->trace) traces(func_local, (int)(500000+GOODSRC[o_src_good].flux[eeuser]*1000.0), 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] > 1.5) { rawcount = GOODSRC[o_src_good].fit_peakval[eeuser]; Apix = GOODSRC[o_src_good].src_pixel_area[eeuser]; if (Apix > 0.0) { /* NLNLNL 20180925 */ 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; } else { /* NLNLNL 20180925 */ GOODSRC[o_src_good].flux_err[eeuser] = 1.0; } /* NLNLNL 20180925 */ 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); if (logger->trace) traces(func_local, (int)(600000+GOODSRC[o_src_good].flux_err[eeuser]*1000.0), logger); 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: FUN.c * Version of source file: 6.0.0 * 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 * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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 allsrc, 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, allsrc: %d, ii: %d, ee: %d, first: %d", allsrc, 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 (allsrc < 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 (allsrc == 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 (allsrc == 1) { *value = backproj->empty[ee][ii]; internalStatus = 0; goto escape; } if (allsrc < SCW_SRCMAX) { if ((src_list[allsrc] == allsrc) && (srcx[allsrc] == s_x[allsrc]) && (srcy[allsrc] == s_y[allsrc]) && (ee == ee_old)) goto evaluate; src_list[allsrc] = allsrc; s_x[allsrc] = srcx[allsrc]; s_y[allsrc] = srcy[allsrc]; ee_old == ee; if ((srcx[allsrc] >= 0.0) && (srcx[allsrc] < backproj->sky_xdim) && (srcy[allsrc] >= 0.0) && (srcy[allsrc] < backproj->sky_ydim)) ; else { sprintf(logger->error_text, "##312## Bad XY in 'fun' srcx[%2d];" " %6.1f, srcy[%2d]: %6.1f", allsrc, srcx[allsrc], allsrc, srcy[allsrc]); logger->logstat = logprint(logger, logger->error_text, 7); internalStatus = -2; goto escape; } sxy = (int)(srcx[allsrc]) * backproj->sky_ydim + (int)(srcy[allsrc]); maskXpix = srcx[allsrc] - (float)(backproj->FOV_radius); maskYpix = srcy[allsrc] - (float)(backproj->FOV_radius); maskXmm = maskXpix * backproj->pix2mm; maskYmm = maskYpix * backproj->pix2mm; if (logger->new_detmap) { internalStatus = detectmap2(maskXmm, maskYmm, &(backproj->detmap[allsrc][0]), 0, jemx, jmx_id, logger); } for (eex=0; eex<=backproj->ee_max; eex++) { if ((logger->fun_last == 0) && (eex != ee)) continue; /* normally, only calculate area for curr. ee-value */ sum = 0.0; sum2 = 0.0; backproj->src_illum_cnts[allsrc][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[allsrc][i] == 1) sum += 1.0; if (backproj->detmap[allsrc][i] >= 1) backproj->src_illum_cnts[allsrc][eex] += backproj->shadw[i]; if (backproj->detmap[allsrc][i] == 2) sum2 += 1.0; } } if (sum2 > 0.0) backproj->norm_d[allsrc][eex] = 1.0 / sum2; else backproj->norm_d[allsrc][eex] = 0.0; sprintf(logger->tmptxt, "##309## fun: eex: %2d, ee: %2d, allsrc: %2d, norm_d: %f", eex, ee, allsrc, backproj->norm_d[allsrc][ee]); logger->logstat = logprint(logger, logger->tmptxt, i5); if (sum > 0.0) backproj->norm_db[allsrc][eex] = 1.0 / sum; else backproj->norm_db[allsrc][eex] = 0.0; } if (backproj->norm_d[allsrc][ee] <= 0.0) { sprintf(logger->error_text, "##314## No data for sky_index %05d in 'fun', srcx/y: %6.1f %6.1f", sxy, srcx[allsrc], srcy[allsrc]); /* 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[allsrc][0]), comb_list, comb_delta, comb_len, &(backproj->pif_maps[allsrc][0]), last, logger); /* backproj->pif_maps[allsrc][] contains for each detector pixel the calculated number (float) of photons arriving from source allsrc 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[allsrc][i] = backproj->effic[i] * backproj->pif_maps[allsrc][i]; /* Here backproj->pifeff_maps[allsrc][] contains for each detector pixel the calculated number (float) of detected photons arriving from source allsrc, distributed according to the detector resolution and detected with the specific pixel efficiency */ if (backproj->soft_gr[i] <= 0.0) { backproj->pif_maps[allsrc][i] = -1.0; backproj->pifeff_maps[allsrc][i] = -1.0; } else { sum1 += backproj->pif_maps[allsrc][i]; sum2 += backproj->pifeff_maps[allsrc][i]; if (backproj->pifeff_maps[allsrc][i] > 0.0) n3_of_illum_pix++; } if (backproj->pif_maps[allsrc][i] > peakpif) peakpif = backproj->pif_maps[allsrc][i]; if (backproj->pifeff_maps[allsrc][i] > peakpifeff) peakpifeff = backproj->pifeff_maps[allsrc][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[allsrc] = sum2 / sum1; n2_of_illum_pix = 0; for (i=1; ipifeff_maps[allsrc][i] /= sum2; /* Now backproj->pifeff_maps[allsrc][] contains for each detector pixel the calculated fraction of 1 detected photon arriving from source allsrc, 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[allsrc][i] > peakout) peakout = backproj->pifeff_maps[allsrc][i]; if (backproj->detmap[allsrc][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[allsrc][i] > 0)) { no_pix_in_proj_area++; /* count pixels in mask projected area */ initmap[i] |= j; srcsum[ee] += backproj->pifeff_maps[allsrc][i]; } odetmap[i] += backproj->detmap[allsrc][i] * j * j; if (backproj->detmap[allsrc][i] > 1) n2_of_illum_pix++; if (backproj->pifeff_maps[allsrc][i] > max_pix_val) { max_pix_val = backproj->pifeff_maps[allsrc][i]; mmpix = i; } } } } evaluate: if (backproj->norm_d[allsrc][ee] < 0.0) { internalStatus = -7; goto escape; } if (backproj->soft_gr[ii] >= 0.0) { *value = backproj->pifeff_maps[allsrc][ii]; internalStatus = 0; goto escape; } internalStatus = 0; goto escape; backgr_evaluate: if (backproj->norm_d[allsrc][ee] < 0.0) { *value = 0.0; internalStatus = 0; goto escape; } for (i=0; idetmap[allsrc][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[allsrc][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); } /***************************************************************** * Name of source file: FUNedge.c * Version of source file: 6.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: Get the parameters and open files for the * j_ima_iros executable * Origin date: 131105 * Update history: 1.0.0 131105 First version * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * Type of element: Function * Part of package: j_ima_iros * Name: FUNedge * Required components: DAL, PIL, RIL, DAL3GEN * 6.0.11 181009 In FUNedge: indicate bad status if local_calling_num has been upset * 6.0.12 181010 Test version to locate index error in FUNedge *****************************************************************/ /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* */ /* Niels Lund, February 2003 */ /* */ /* */ /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ int FUNedge( int edgsrc, int ee, float maskXmm, float maskYmm, int jemx, int last, struct instr_data *jmx_id, struct log_con *logger, struct backpro *backproj, int chatter, int currentStatus ) { int i5; int i=0, j=0, n=0, ki=0, track_len=0; int internalStatus=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; 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], "FUNedge"); 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(); if (logger->trace) traces(func_local, 0, logger); if (logger->func_calling_num > 149) { local_calling_num = 149; } else { local_calling_num = logger->func_calling_num; } logger->func_calling_num = func_local; logger->func_times[local_calling_num] += TT_now - calling_TT; /* function entry timing end */ if (logger->trace) traces(func_local, 1000+local_calling_num, logger); if (logger->trace) traces(func_local, 2000+func_local, logger); if (logger->trace) traces(func_local, 10000+local_calling_num, logger); i5 = logger->i5; internalStatus = 0; if( chatter > J_CHATTY_MAXIMAL ) { RILlogMessage( NULL, Log_0, "##308## FUNedge called, edgsrc: %d, ee: %d", edgsrc, ee); } if (edgsrc >= 80) { internalStatus = detectmap2(maskXmm, maskYmm, &(backproj->detmap[edgsrc][0]), 0, jemx, jmx_id, logger); for (eex=0; eex<=backproj->ee_max; eex++) { if ((logger->fun_last == 0) && (eex != ee)) continue; /* normally, only calculate area for curr. ee-value */ sum = 0.0; sum2 = 0.0; backproj->src_illum_cnts[edgsrc][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[edgsrc][i] == 1) sum += 1.0; if (backproj->detmap[edgsrc][i] >= 1) backproj->src_illum_cnts[edgsrc][eex] += backproj->shadw[i]; if (backproj->detmap[edgsrc][i] == 2) sum2 += 1.0; } } if (sum2 > 0.0) backproj->norm_d[edgsrc][eex] = 1.0 / sum2; else backproj->norm_d[edgsrc][eex] = 0.0; sprintf(logger->tmptxt, "##309## FUNedge: ee, %2d, edgsrc: %2d, norm_d: %f", ee, edgsrc, backproj->norm_d[edgsrc][ee]); logger->logstat = logprint(logger, logger->tmptxt, i5); if (sum > 0.0) backproj->norm_db[edgsrc][eex] = 1.0 / sum; else backproj->norm_db[edgsrc][eex] = 0.0; if (logger->trace) traces(func_local, 1000+eex, logger); } if (backproj->norm_d[edgsrc][ee] <= 0.0) { sprintf(logger->error_text, "##314## No data in 'FUNedge' for srcx/y: %6.1f %6.1f", maskXmm, maskYmm); /* 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; } if (logger->trace) traces(func_local, 20000+local_calling_num, logger); /* 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; } if (logger->trace) traces(func_local, 30000+local_calling_num, logger); /* 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; } if (logger->trace) traces(func_local, 40000+local_calling_num, logger); if (logger->trace) traces(func_local, 41000+comb_len, logger); if (logger->trace) traces(func_local, 42000+last, logger); sum = 0.0; for (i=0; idetmap[edgsrc][0]), comb_list, comb_delta, comb_len, &(backproj->pif_maps[edgsrc][0]), last, logger); /* backproj->pif_maps[edgsrc][] contains for each detector pixel the calculated number (float) of photons arriving from edge-source edgsrc 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. */ if (logger->trace) traces(func_local, 50000+local_calling_num, logger); sum1 = sum2 = 0.0; n3_of_illum_pix = 0; for (i=1; ipifeff_maps[edgsrc][i] = backproj->effic[i] * backproj->pif_maps[edgsrc][i]; /* Here backproj->pifeff_maps[edgsrc][] contains for each detector pixel the calculated number (float) of detected photons arriving from edge-source edgsrc, distributed according to the detector resolution and detected with the specific pixel efficiency */ if (backproj->soft_gr[i] <= 0.0) { backproj->pif_maps[edgsrc][i] = -1.0; backproj->pifeff_maps[edgsrc][i] = -1.0; } else { sum1 += backproj->pif_maps[edgsrc][i]; sum2 += backproj->pifeff_maps[edgsrc][i]; if (backproj->pifeff_maps[edgsrc][i] > 0.0) n3_of_illum_pix++; } if (backproj->pif_maps[edgsrc][i] > peakpif) peakpif = backproj->pif_maps[edgsrc][i]; if (backproj->pifeff_maps[edgsrc][i] > peakpifeff) peakpifeff = backproj->pifeff_maps[edgsrc][i]; } if( sum1 == 0.0 ) { RILlogMessage( NULL, Warning_1,"##319## sum1 == 0.0 in FUNedge.c! Error return"); internalStatus = -8; goto escape; } if (logger->trace) traces(func_local, 60000+local_calling_num, logger); if( sum2 == 0.0 ) { RILlogMessage( NULL, Warning_1,"##319## sum2 == 0.0 in FUNedge.c! Error return"); internalStatus = -8; goto escape; } backproj->src_effic[edgsrc] = sum2 / sum1; n2_of_illum_pix = 0; for (i=1; ipifeff_maps[edgsrc][i] /= sum2; /* Now backproj->pifeff_maps[edgsrc][] contains for each detector pixel the calculated fraction of 1 detected photon arriving from edge-source edgsrc, 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[edgsrc][i] > peakout) peakout = backproj->pifeff_maps[edgsrc][i]; if (backproj->detmap[edgsrc][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[edgsrc][i] > 0)) { no_pix_in_proj_area++; /* count pixels in mask projected area */ initmap[i] |= j; srcsum[ee] += backproj->pifeff_maps[edgsrc][i]; } odetmap[i] += backproj->detmap[edgsrc][i] * j * j; if (backproj->detmap[edgsrc][i] > 1) n2_of_illum_pix++; if (backproj->pifeff_maps[edgsrc][i] > max_pix_val) { max_pix_val = backproj->pifeff_maps[edgsrc][i]; mmpix = i; } } } if (logger->trace) traces(func_local, 70000+local_calling_num, logger); } internalStatus = 0; if (logger->trace) traces(func_local, 80000+local_calling_num, logger); 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 'FUNedge': internal: %2d, current: %6d, offset: %6d", internalStatus, currentStatus, J_ERROR_CODE_START + J_IMA_IROS_ERR); } if (logger->trace) traces(func_local, 90000+local_calling_num, logger); if (logger->trace) traces(func_local, 3000+local_calling_num, logger); if (logger->trace) traces(func_local, 4000+func_local, logger); /* function exit timing start */ TT_now = clock(); logger->func_times[func_local] += difftime(TT_now, logger->TT); logger->TT = TT_now; if ((local_calling_num > 148) || (local_calling_num < 0)) { /* NLNLNL 20181009 indicate bad status if local_calling_num has been upset */ logger->func_calling_num = 149; currentStatus = -19; } else logger->func_calling_num = local_calling_num; if (logger->trace) traces(func_local, 99, logger); /* function exit timing end */ return(currentStatus); } /***************************************************************** * Name of source file: gaussj_nr.c * Version of source file: 6.0.0 * 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. * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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: 6.0.0 * 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. * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection 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 ); } /***************************************************************** * Name of source file: j_iir_lilipol.c * Version of source file: 6.0.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.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 * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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: 6.0.0 * 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 * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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: 6.0.0 * 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 * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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: get_effic.c * Version of source file: 6.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. * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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); } /* ****************************************************************************** */ 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; } /***************************************************************** * Name of source file: getNumShds.c * Version of source file: 6.0.0 * 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 * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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)); } /* *************************************** */ 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: 6.0.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); } /***************************************************************** * Name of source file: gnuTslice.c * Version of source file: 6.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 * 5.1.2 151106 Running version with LC generation * 5.1.9 160415 Update of light curve output and keywords according to agreement with ISDC * 6.0.0 180112 Introduces LC generation and burst detection * Type of element: Function * Part of package: j_ima_iros * Name: gnuTslice * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ /* QQQQQQ */ int gnuTslice( int allsrc, int eeuser, float rmsFlux, int orbit, int pid, int pidv, timeslices *Tslice, int chanmax[], struct log_con *logger, FILE *gnufil, int status) { int i, j, k, SIGN, i5, ntime, ncr=1, nch; int kmin, kmax, mmin, mmax; float flux, bflux, error1, error2, error, sumold, sum, fmax, slicelength; float Ccnt, fluxmax[5], threshold1, threshold2, signif, gnuTime; float signifsum, flerr, bflerr; double m0, m1, m2, mean[5], rms[5], gnut, gnuT1=-1.0, gnux; static int func_local = -1, local_calling_num=0, plotnumber=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], "gnuTslice"); 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; gnut = (double)((int)((Tslice[0].Tstart + Tslice[0].Tstop) / 20.0) * 10.0); plotnumber++; goto num2; /* 111111111111111111111111111111111111111111111111111111111111111111111111111111111 */ /* ncr = 1; gnuT1 = -1.0; for (ntime=0; ntimeNumTimeBins; ntime++) { if (((Tslice[ntime].dontUse&1) == 0) && ((double)(Tslice[ntime].exposure) > (Tslice[ntime].Tstop - Tslice[ntime].Tstart) * 0.1)) { flux = Tslice[ntime].wflux[allsrc]; flux += (float)(eeuser - 3); gnuTime = Tslice[ntime].Tstart - gnut; if (gnuT1 < 0.0) gnuT1 = gnuTime; fprintf(gnufil, "%12.6lf %e\n", gnuTime , flux); ncr = 0; } else { if (ncr < 1) fprintf(gnufil, "\n"); ncr = 1; } } gnuT1 = 0.010 * (int)(gnuT1 * 100.0); fprintf(gnufil, "\n"); for (gnux=gnuT1; gnux<=gnuTime; gnux+=(gnuTime-gnuT1)*0.01) fprintf(gnufil, "%12.6lf %6.2f\n", gnux, (float)(eeuser - 3)); fprintf(gnufil, "\n"); for (j=0; j<128; j++) { if (chanmax[j] > 0) { gnuTime = Tslice[chanmax[j]].Tstart - gnut; fprintf(gnufil, "%12.6lf %6.2f\n", gnuTime, 0.0); fprintf(gnufil, "%12.6lf %6.2f\n", gnuTime, (float)(eeuser - 3)); fprintf(gnufil, "\n"); } } fprintf(gnufil, "%12.6lf %6.2f\n", gnuT1, 0.00); fprintf(gnufil, "%12.6lf %6.2f\n", gnuT1+0.0001, (float)(eeuser - 1)); fprintf(gnufil, "\n\n"); */ /* 222222222222222222222222222222222222222222222222222222222222222222222222222222222 */ num2: if (logger->trace) traces(func_local, 1000000, logger); if (logger->trace) traces(func_local, 1000000+logger->NumTimeBins, logger); if (logger->trace) traces(func_local, 1000000+eeuser, logger); if (logger->trace) traces(func_local, 1000000+allsrc, logger); ncr = 1; for (ntime=0; ntimeNumTimeBins; ntime++) { if (((Tslice[ntime].dontUse&1) == 0) && (rmsFlux > 0.00001)) { flux = Tslice[ntime].wflux[allsrc] / rmsFlux; fprintf(gnufil, "%4d %10.6f\n", ntime , flux); ncr = 0; } else { if (ncr < 1) fprintf(gnufil, "\n"); ncr = 1; } } if (ncr == 1) fprintf(gnufil, "\n"); else fprintf(gnufil, "\n\n"); for (ntime=0; ntimeNumTimeBins; ntime++) { if (((Tslice[ntime].dontUse&1) == 0) && (rmsFlux > 0.00001) && ((double)(Tslice[ntime].exposure) > (Tslice[ntime].Tstop - Tslice[ntime].Tstart) * 0.1)) { flux = Tslice[ntime].wflux[allsrc]; flerr = Tslice[ntime].wfErr[allsrc]; gnuTime = (Tslice[ntime].Tstart + Tslice[ntime].Tstop - 2.0 * gnut) / 2.0; fprintf(gnufil, "%8.6lf %10.6f %10.6f\n", gnuTime , flux, flerr); ncr = 0; } else { if (ncr < 1) fprintf(gnufil, "\n"); ncr = 1; } } if (ncr == 1) fprintf(gnufil, "\n"); else fprintf(gnufil, "\n\n"); for (ntime=0; ntimeNumTimeBins; ntime++) { if (((Tslice[ntime].dontUse&1) == 0) && (rmsFlux > 0.00001) && ((double)(Tslice[ntime].exposure) > (Tslice[ntime].Tstop - Tslice[ntime].Tstart) * 0.1)) { bflux = Tslice[ntime].wbflux[allsrc]; bflerr = Tslice[ntime].wbfErr[allsrc]; gnuTime = (Tslice[ntime].Tstart + Tslice[ntime].Tstop - 2.0 * gnut) / 2.0; fprintf(gnufil, "%12.6lf %12.6f %12.6f\n", gnuTime , bflux, bflerr); ncr = 0; } else { if (ncr < 1) fprintf(gnufil, "\n"); ncr = 1; } } if (ncr == 1) fprintf(gnufil, "\n"); else fprintf(gnufil, "\n\n"); goto slut; gnuT1 = 0.010 * (int)(gnuT1 * 100.0); fprintf(gnufil, "\n"); for (gnux=gnuT1; gnux<=gnuTime; gnux+=(gnuTime-gnuT1)*0.01) fprintf(gnufil, "%12.6lf %10.6f\n", gnux, 3.0 * (float)(eeuser - 3)); fprintf(gnufil, "\n"); for (j=0; j<128; j++) { if (chanmax[j] > 0) { gnuTime = (Tslice[ntime].Tstart + Tslice[ntime].Tstop - 2.0 * gnut) / 2.0; flux = Tslice[chanmax[j]].wflux[allsrc] / rmsFlux; flux += 3.0 * (float)(eeuser - 3); fprintf(gnufil, "%12.6lf %10.6f\n", gnuTime, 0.0); fprintf(gnufil, "%12.6lf %10.6f\n", gnuTime, flux); fprintf(gnufil, "\n"); } } fprintf(gnufil, "%12.6lf %10.6f\n", gnuT1, 3.0*(float)(eeuser + 3)); fprintf(gnufil, "%12.6lf %10.6f\n", gnuT1+0.0001, 3.0*(float)(eeuser + 3)); fprintf(gnufil, "\n\n"); 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); } 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; mfunc_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); i5 = logger->i5; if (first) { for (j=0; j<3; j++) for (i=0; i<256; i++) X_distr[j][i] = 0.0; first = 0; } m0 = m1 = m2 = 0.0; for (i=0; isoft_gr[i] <= 0.0) continue; yyy = i % 256; xxx = (i - yyy) / 256; X_distr[ee][xxx] += shadowgr[i]; 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, i5); } backproj->act_pix[ee] -= (float)(k); if (ee == 2) { max = 0.0; for (i=0; i<256; i+=16) { sprintf(logger->tmptxt, "##337## X%3d ", i); for (j=0; j<16; j++) { if ((X_distr[1][i+j] + X_distr[2][i+j]) < 10.0) sprintf(logger->tmptxt2, " - "); else { val = X_distr[0][i+j] / (X_distr[1][i+j] + X_distr[2][i+j]); sprintf(logger->tmptxt2, "%5.1f ", val); if (val > max) { ijmax = i+j; max = val; } } 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, "##337## Max value: %6.2f, count0: %8.0f; count1: %8.0f, count[2]: %8.0f", max, X_distr[0][ijmax], X_distr[1][ijmax], X_distr[2][ijmax]); logger->logstat = logprint(logger, logger->tmptxt, i5); if (max > 2.2) { for (i = 0; i<256; i++) { xxx = ijmax * 256 + i; backproj->soft_gr[xxx] = -1.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( hotcts ); } /* **************************************************************************************** */ /* ***************************************************** */ /***************************************************************** * Name of source file: imageprep.c * Version of source file: 6.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@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. * 6.0.0 180112 Introduces LC generation and burst detection * 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 eeuser, 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, j, nsrc = 0, fitcnt, i5, ee3; 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, maxp; 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 */ ee3 = eeuser; if (ee3 > backproj->ee_basic) ee3 = backproj->ee_basic; /* 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, eeuser, shadow, sh, 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])+logger->edge2); else backproj->fitsimage[ee3][5][i] = 0.01; /* = 1.0; modified 17/12 2013 Niels Lund */ } 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 shadowfit (2), 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, "##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; } maxp = 0.0; testsum = 0.0; sprintf(logger->tmptxt, "##9270## Returning from backpro8_d 2"); logger->logstat = logprint(logger, logger->tmptxt, 5); 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: initGOOD.c * Version of source file: 6.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 * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * Type of element: Function * Part of package: j_ima_iros * Name: initGOOD * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ /* QQQQQQ */ int initGOOD( int eeuser, 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; i = eeuser; GOODSRC[logger->N_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: initPIF_LC.c * Version of source file: 6.0.0 * 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: Initialize PIFmap light-curve parameters * Origin date: 20130429 * Update history: 1.0.0 20130314 First version * 5.1.2 151106 Running version with LC generation * 5.1.16 160930 Update 'clean2', ex2trEvTslc', 'initPIF_LC' and 'work2d' to avoid crashes due to marginal user srcs * 6.0.0 180112 Introduces LC generation and burst detection * Type of element: Function * Part of package: j_ima_iros * Name: initPIF_LC * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ int initPIF_LC( int lstsrc, int presrc, double solut_e[], pifmap *PIFmap, struct backpro *backproj, struct shadowgrams *sh, struct log_con *logger, int status) { int i, j, k, i5; float wbkg_pixel_area, pixel_wgt, combi, divisor; float av_src_illum, av_wsrc_illum, av_bkg_illum, av_wbkg_illum; 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], "initPIF_LC"); 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); i5 = logger->i5; /* transfer PIF-maps to structure PIFmap */ if (logger->trace) traces(func_local, 1000+lstsrc, logger); if (logger->trace) traces(func_local, 1000+presrc, logger); status = ISDC_OK; status = source_weight(lstsrc, backproj, logger, sh, &(PIFmap->wgt_map[0]), status); if (status != ISDC_OK) goto return_negative; PIFmap->wsrc_pixel_area = PIFmap->wbkg_pixel_area = PIFmap->wsrc_src_illum = PIFmap->wbkg_src_illum = 0.00000001; PIFmap->src_pixel_area = PIFmap->bkg_pixel_area = PIFmap->src_src_illum = PIFmap->bkg_src_illum = 0.00000001; wbkg_pixel_area = pixel_wgt = 0.00000001; for (i=0; isoft_gr[i] <= 0.0) continue; PIFmap->src_pixel_map[i] = backproj->pif_s_pickmap[lstsrc][i]; PIFmap->bkg_pixel_map[i] = backproj->pif_b_pickmap[lstsrc][i]; PIFmap->wsrc_pixel_area += PIFmap->src_pixel_map[i] * PIFmap->wgt_map[i]; PIFmap->wbkg_pixel_area += PIFmap->bkg_pixel_map[i] * PIFmap->wgt_map[i]; wbkg_pixel_area += backproj->pif_b_pickmap[lstsrc][i]; pixel_wgt += PIFmap->wgt_map[i]; PIFmap->src_src_illum += PIFmap->src_pixel_map[i] * backproj->pif_maps[lstsrc][i]; PIFmap->bkg_src_illum += PIFmap->bkg_pixel_map[i] * backproj->pif_maps[lstsrc][i]; PIFmap->wsrc_src_illum += PIFmap->src_pixel_map[i] * PIFmap->wgt_map[i] * backproj->pif_maps[lstsrc][i]; PIFmap->wbkg_src_illum += PIFmap->bkg_pixel_map[i] * PIFmap->wgt_map[i] * backproj->pif_maps[lstsrc][i]; } PIFmap->av_src_fit = solut_e[lstsrc]; PIFmap->src_pixel_area = backproj->pif_spix[lstsrc]; PIFmap->bkg_pixel_area = backproj->pif_bpix[lstsrc]; if ((PIFmap->wsrc_pixel_area <= 0.0) || (PIFmap->wbkg_pixel_area <= 0.0) || (PIFmap->src_pixel_area <= 0.0) || (PIFmap->bkg_pixel_area <= 0.0)) {status = -7; goto return_negative;} /* */ av_src_illum = av_wsrc_illum = av_bkg_illum = av_wbkg_illum = 0.0; av_src_illum = PIFmap->src_src_illum / PIFmap->src_pixel_area; av_wsrc_illum = PIFmap->wsrc_src_illum / PIFmap->wsrc_pixel_area; av_bkg_illum = PIFmap->bkg_src_illum / PIFmap->bkg_pixel_area; av_wbkg_illum = PIFmap->wbkg_src_illum / PIFmap->wbkg_pixel_area; if ((av_src_illum > 1.0) || (av_wsrc_illum > 1.0) || (av_bkg_illum > 1.0) || (av_wbkg_illum > 1.0)) { sprintf(logger->tmptxt, "src%02f, av_src_illum: %5.3f, av_wsrc_illum: %5.3f, av_bkg_illum: %5.3f, av_wbkg_illum: %5.3f", presrc, av_src_illum, av_wsrc_illum, av_bkg_illum, av_wbkg_illum); status = -11; goto return_negative; } /* */ sprintf(logger->tmptxt, "initPFLC_src%02d wbkg_sillum: %8.1f, wsrc_wpixArea: %8.1f, combi: %6.1f, src_pixel_area: %8.1f", presrc, PIFmap->wbkg_src_illum, PIFmap->wsrc_pixel_area, PIFmap->wsrc_src_illum * PIFmap->wbkg_pixel_area / PIFmap->wsrc_pixel_area, PIFmap->src_pixel_area); logger->logstat = logprint(logger, logger->tmptxt, i5); sprintf(logger->tmptxt, "initPFLC_src%02d src_sillum: %8.1f, wbkg_pixArea: %8.1f, combi: %6.1f, bkg_pixel_area: %8.1f", presrc, PIFmap->src_src_illum, PIFmap->wbkg_pixel_area, PIFmap->bkg_src_illum * PIFmap->src_pixel_area / PIFmap->bkg_pixel_area, PIFmap->bkg_pixel_area); logger->logstat = logprint(logger, logger->tmptxt, i5); /* calculate weight factors to be applied to observed counts */ if (logger->trace) traces(func_local, 1400+presrc, logger); divisor = (PIFmap->wsrc_src_illum - PIFmap->wbkg_src_illum * PIFmap->wsrc_pixel_area / PIFmap->wbkg_pixel_area); if (logger->trace) traces(func_local, 1000000+(int)(divisor), logger); if (divisor != 0.0) PIFmap->hi_illum_wfact = 1.0 / divisor; else PIFmap->hi_illum_wfact = 0.001; divisor = (av_wsrc_illum - av_wbkg_illum); if (divisor > 0.01) { PIFmap->hi_illum_wfac2 = PIFmap->lo_illum_wfac2 = 1.0 / divisor; PIFmap->lo_illum_wfac3 = av_wsrc_illum / divisor; PIFmap->hi_illum_wfac3 = av_wbkg_illum / divisor; } else { PIFmap->hi_illum_wfac2 = 0.000001; PIFmap->lo_illum_wfac2 = 0.000001; PIFmap->hi_illum_wfac3 = 0.000001; PIFmap->lo_illum_wfac3 = 0.000001; } if (logger->trace) traces(func_local, 1415, logger); if (logger->trace) traces(func_local, (int)(10000000+PIFmap->wsrc_src_illum ), logger); if (logger->trace) traces(func_local, (int)(10000000+PIFmap->wsrc_pixel_area), logger); if (logger->trace) traces(func_local, (int)(10000000+PIFmap->wbkg_src_illum ), logger); if (logger->trace) traces(func_local, (int)(10000000+PIFmap->wbkg_pixel_area), logger); if (logger->trace) traces(func_local, 1415, logger); divisor = (PIFmap->wsrc_src_illum * PIFmap->wbkg_pixel_area / PIFmap->wsrc_pixel_area - PIFmap->wbkg_src_illum); if (logger->trace) traces(func_local, 1000000+(int)(divisor), logger); if (divisor != 0.0) PIFmap->lo_illum_wfact = 1.0 / divisor; else PIFmap->lo_illum_wfact = 0.001; if (logger->trace) traces(func_local, 1416, logger); divisor = (PIFmap->src_src_illum - PIFmap->bkg_src_illum * PIFmap->src_pixel_area / PIFmap->bkg_pixel_area); if (logger->trace) traces(func_local, 1000000+(int)(divisor), logger); if (divisor != 0.0) PIFmap->hi_illum_fact = 1.0 / divisor; else PIFmap->hi_illum_fact = 0.001; if (logger->trace) traces(func_local, 1417, logger); divisor = (PIFmap->src_src_illum * PIFmap->bkg_pixel_area / PIFmap->src_pixel_area - PIFmap->bkg_src_illum); if (logger->trace) traces(func_local, 1000000+(int)(divisor), logger); if (divisor != 0.0) PIFmap->lo_illum_fact = 1.0 / divisor; else PIFmap->lo_illum_fact = 0.001; divisor = (av_src_illum - av_bkg_illum); if (divisor != 0.0) { PIFmap->hi_illum_fac2 = PIFmap->lo_illum_fac2 = 1.0 / divisor; PIFmap->lo_illum_fac3 = av_src_illum / divisor; PIFmap->hi_illum_fac3 = av_bkg_illum / divisor; } else { PIFmap->hi_illum_fac2 = 0.000001; PIFmap->lo_illum_fac2 = 0.000001; PIFmap->hi_illum_fac3 = 0.000001; PIFmap->lo_illum_fac3 = 0.000001; } if (logger->trace) traces(func_local, 1420, logger); sprintf(logger->tmptxt, "initPFLC_src%02d hi/lo_illum_wfact: %8.6f %8.6f, hi/lo_illum_fact: %8.6f %8.6f, pixel_wgt: %7.1f", presrc, PIFmap->hi_illum_wfact, PIFmap->lo_illum_wfact, PIFmap->hi_illum_fact, PIFmap->lo_illum_fact, pixel_wgt); logger->logstat = logprint(logger, logger->tmptxt, i5); if (logger->trace) traces(func_local, 1420, logger); 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: */ if (logger->trace) traces(func_local, 1000-status, logger); if (logger->trace) traces(func_local, 999, logger); goto escape; } /***************************************************************** * Name of source file: initTsliceGlobal.c * Version of source file: 6.0.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: Initialize Tslices-structure elements * Origin date: 071029 * Update history: 2.3.7 100308 First version * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * Type of element: Function * Part of package: j_ima_iros * Name: initTsliceGlobal *****************************************************************/ int initTsliceGlobal( timeslices *Tslices, Auxdata auxdata, Events *bufevents, struct shadowgrams *sh, struct log_con *logger, int chatter, int status) { int flag = 0, nevent, i5 = 5; static int first=1; long i = 0; long i1 = 0; long i2 = 0; long idx = 0; float gain_sum = 0.0, gain_events = 0.0; float deadtime_sum = 0.0; float greyfilter_sum = 0.0; static float old_avGain = 22.0; double ontime = 0.0; double time_step = 0.0; double time = 0.0; double *dblBuffer = NULL; double IJDstart; double IJDstop; double sumDT, oldijd; static int func_local = -1, local_calling_num=0, calls = 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], "initTslGlobal"); 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 */ i5 = logger->i5; /* * Initialize Tslices and then fill the gain, deadtime, greyfilter and DontUseFlag * assuming that the DAL3JEMX event selection has taken the GTIs properly into account * Tslices->Tstart and ->Tstop has been initialized in 'main' */ calls++; if ((calls < 2) && (logger->trace)) traces(func_local, 0, logger); IJDstart = Tslices->Tstart; IJDstop = Tslices->Tstop; Tslices->onTime = 0.0; Tslices->gainclass = 0; Tslices->livetime = 1.0; Tslices->exposure = 0.0; Tslices->avCorf = 0.0; Tslices->srcWCounts = 0.0; Tslices->srcCounts = 0.0; Tslices->bkgWCounts = 0.0; Tslices->bkgCounts = 0.0; Tslices->Events = 0.0; Tslices->wEvents = 0.0; Tslices->burstflag = 0; Tslices->dontUse = 0; for (i=0; iwbflux[i] = 0.0; Tslices->wbfErr[i] = 0.0; Tslices->wflux[i] = 0.0; Tslices->wfErr[i] = 0.0; } /* * Calculate the ontime in seconds for the time-interval * Identify and flag 'dont_use' time intervals */ if( auxdata.n_GTI > 0 ) { /* skip this step if no GTIs were found */ if ((calls < 2) && (logger->trace)) traces(func_local, 2, logger); /* step through the GTIs */ ontime = 0.0; for( i = 0; i < auxdata.n_GTI; i++ ) { if ((calls < 2) && (logger->trace)) traces(func_local, 3, logger); /* skip this GTI-interval if GTI_IJDstop comes before IJDstart */ if( auxdata.GTI_IJDstop[i] < IJDstart ) { sprintf(logger->tmptxt, "GTI-Stop[%02d] comes before IJD-start: GTI-Stop: %lf, IJDstart: %lf", i, auxdata.GTI_IJDstop[i], IJDstart); logger->logstat = logprint(logger, logger->tmptxt, 5); continue; } /* skip this GTI-interval and all following GTI-intervals if GTI_IJDstart comes after IJDstop */ if (auxdata.GTI_IJDstart[i] > IJDstop) { sprintf(logger->tmptxt, "GTI-Start[%02d] comes after IJD-stop: GTI-Start: %lf, IJDstop: %lf", i, auxdata.GTI_IJDstart[i], IJDstop); logger->logstat = logprint(logger, logger->tmptxt, 5); Tslices->dontUse = 1; if ((calls < 2) && (logger->trace)) traces(func_local, 4, logger); break; } if( auxdata.GTI_IJDstart[i] < IJDstart ) { if( auxdata.GTI_IJDstop[i] < IJDstop ) { /* The GTI interval starts before IJDstart and the GTI interval stops before IJDstop */ ontime = (auxdata.GTI_IJDstop[i] - IJDstart)/J_IIR_IJDSECOND; if ((calls < 2) && (logger->trace)) traces(func_local, 5, logger); } else { /* the GTI interval covers the entire period */ ontime = (IJDstop - IJDstart)/J_IIR_IJDSECOND; if ((calls < 2) && (logger->trace)) traces(func_local, 6, logger); break; } } else { /* The GTI interval start after IJDstart */ if( auxdata.GTI_IJDstop[i] < IJDstop ) { /* and the GTI interval stops before IJDstop */ ontime += (auxdata.GTI_IJDstop[i] - auxdata.GTI_IJDstart[i])/J_IIR_IJDSECOND; if ((calls < 2) && (logger->trace)) traces(func_local, 7, logger); } else { /* the GTI interval stops after IJDstop */ ontime += (IJDstop - auxdata.GTI_IJDstart[i])/J_IIR_IJDSECOND; if ((calls < 2) && (logger->trace)) traces(func_local, 8, logger); break; } } } } else { /* disregard the GTI information since it is not there */ if ((calls < 2) && (logger->trace)) traces(func_local, 9, logger); ontime = (IJDstop - IJDstart)/J_IIR_IJDSECOND; if (auxdata.GTI_IJDstart[i] > IJDstop) { sprintf(logger->tmptxt, "No GTI-data is found, assume all time bins valid"); logger->logstat = logprint(logger, logger->tmptxt, i5); } } if (ontime == 0.0) { if ((calls < 2) && (logger->trace)) traces(func_local, 10, logger); Tslices->dontUse = 1; goto exittrace; } Tslices->onTime = ontime; Tslices->exposure = ontime; /* preliminary value */ if( ontime > 0.0 ) { /* Start further analysis */ if ((calls < 2) && (logger->trace)) traces(func_local, 11, logger); /* * 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; } } deadtime_sum = 0.0; greyfilter_sum = 0.0; i2 = 0; if ((calls < 2) && (logger->trace)) traces(func_local, 1000000+i2, logger); 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 ((calls < 2) && (logger->trace)) traces(func_local, 1300000+i2+100*i, logger); /* check that this event is inside a "GoodTime-Interval" */ if( auxdata.GTI_IJDstart[i] <= time && auxdata.GTI_IJDstop[i] >= time ) { /* RILlogMessage( NULL, Log_0,"##5114## time = %14.8lf inside GTI #%ld", time, i ); */ if ((calls < 2) && (logger->trace)) traces(func_local, 1500000+i2+100*i, logger); flag = 1; /* we are inside */ break; } } } else { if ((calls < 2) && (logger->trace)) traces(func_local, 1700000+i2, logger); RILlogMessage( NULL, Log_0,"##5115## Disregarding GTI info" ); flag = 1; /* GTI nonexistent - disregard the GTI information */ } if ((calls < 2) && (logger->trace)) traces(func_local, 1800000+i2, logger); if( !flag ) continue; /* if we are not inside GTI - skip this time bin */ if ((calls < 2) && (logger->trace)) traces(func_local, 2000000+i2, logger); i2++; /* count the number of accepted time intervals */ /* 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]; if ((calls < 2) && (logger->trace)) traces(func_local, 3000000+i2-1, logger); /* 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.; if ((calls < 2) && (logger->trace)) traces(func_local, 4000000+i2-1, logger); } if (i2 > 0) { Tslices->final_expo = Tslices->exposure * (1.-deadtime_sum/i2)*(greyfilter_sum/i2); Tslices->greyfilter = greyfilter_sum / i2; Tslices->livetime = 1.0 - deadtime_sum / i2; } else { Tslices->final_expo = Tslices->exposure; Tslices->greyfilter = 1.0; Tslices->livetime = 1.0; } if ((calls < 2) && (logger->trace)) traces(func_local, 50, logger); /* loop over eventlist */ gain_sum = old_avGain; gain_events = 1.0; sumDT = 0.0; if (first) {first = 0; oldijd = bufevents[0].ijd;} for (nevent=0; neventnumEvents; nevent++) { if ((bufevents[nevent].status < 1024) && (bufevents[nevent].pi >= sh->pival[0][0])) { if (bufevents[nevent].ijd < Tslices->Tstart) continue; if (bufevents[nevent].ijd >= Tslices->Tstop) break; gain_events += 1.0; gain_sum += bufevents[nevent].gain; sumDT += (bufevents[nevent].ijd - oldijd) * (bufevents[nevent].ijd - oldijd); oldijd = bufevents[nevent].ijd; } } if ((calls < 2) && (logger->trace)) traces(func_local, 60, logger); old_avGain = Tslices->avGain = gain_sum / gain_events; Tslices->sumDTsq = sumDT * Tslices->onTime * Tslices->onTime / gain_events; if ((calls < 2) && (logger->trace)) traces(func_local, 70, logger); sprintf(logger->tmptxt, "##7111## n_deadTimes = %d, n_greyValues = %d, final exposure: %5.1lf s, onTime: %5.1lf, avGain: %5.2f, evenT: %lf, %6.0f", auxdata.n_deadTimes, auxdata.n_greyValues, Tslices->final_expo, Tslices->onTime, Tslices->avGain, Tslices->sumDTsq, gain_events); logger->logstat = logprint(logger, logger->tmptxt, i5); } else { sprintf(logger->tmptxt, "##5112## onTime: %lf, dontUse: %1d", Tslices->onTime, Tslices->dontUse); logger->logstat = logprint(logger, logger->tmptxt, i5); } exittrace: /* exittrace */ if ((calls < 2) && (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: initUSER.c * Version of source file: 6.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 * 4.0.6 120628 SPR ?: Reduced memory allocation demands * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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: irosloop2.c * Version of source file: 6.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@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. * 5.1.2 151106 Running version with LC generation * 5.1.34 171214 Correct flux error calculation for user sources (new parameter in call to final_sky) * 6.0.0 180112 Introduces LC generation and burst detection * 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 Line 380 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 Line 504 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, Line 784 generate residual shadowgram. Stop if last source power too small Go back to A (search for more sources) Line 909 *****************************************************************/ int irosloop2( int jemx, int ee, float xx_iir[SCW_SRCMAX], float yy_iir[SCW_SRCMAX], int src_id[SCW_SRCMAX], int sxy[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, int chatter, int status) { int i5 = 5; int i, j, m, k, km=2, tours, nsrc, ngrp, fitcnt = 0, flag3=0; int mini_rms, mini_const, local_sxy=0, sxy_list[SCW_SRCMAX]; int sxy2, pxy, psxy, back_rdy = 0; int xvalstart, yvalstart, sky_index; int ghoststep[2]; int baseErr = J_ERROR_CODE_START + J_IMA_IROS_ERR; static float skyim[SKYDIM]; static float peak_array[11][11]; static float back_array[11][11]; 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; } /* QQQQQQ */ /* ************************************************************************** */ /* */ /* Fit shadowgram with background components and preset sources */ /* */ /* ************************************************************************** */ /* Test output: peak image for preset type 3 source (nsrc = 2) NLNLNL 20171229 */ j = (int)((int)(xx[nsrc-1]+0.5)*backproj->sky_ydim + (int)(yy[nsrc-1]+0.5)); psxy = j; sprintf(logger->tmptxt, "##280## Flag3 source position: sxy: %7d, XY: %+4d %+4d, ngrp: %2d %2d, E%1d, val: %6.1f", j, (int)(xx[nsrc-1]+0.5), (int)(yy[nsrc-1]+0.5), ngrp, nsrc, ee, backproj->fitsimage[ee][2][j]); logger->logstat = logprint(logger, logger->tmptxt, i5); flag3 = 1; k =2; for (j=-5; j<=5; j++) { sprintf(logger->tmptxt, "P%2d %03d", k, (int)(yy[nsrc-1]+j+0.5)); for (i=-5; i<=5; i++) { pxy = (int)((int)(xx[nsrc-1]+i+0.5)*backproj->sky_ydim + (int)(yy[nsrc-1]+j+0.5)); if ((pxy > 0) && (pxy < SKYDIM)) { sprintf(logger->tmptxt2, " %6.1f ", backproj->fitsimage[ee][2][pxy]); peak_array[5+i][5+j] = backproj->fitsimage[ee][2][pxy]; } else { sprintf(logger->tmptxt2, " "); peak_array[5+i][5+j] = 10000000.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, " "); logger->logstat = logprint(logger, logger->tmptxt, i5); /* 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]; } sprintf(logger->tmptxt, "##272## Calling clean, testsum = %f", testsum); 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, "##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, i5); /* 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 */ local_sxy = findpeak2(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 (local_sxy < 0) { backproj->stopcode[ee] = 7; sprintf(logger->tmptxt, "##276## stop for findpeak bad residual map, sxy: %d ", local_sxy); logger->logstat = logprint(logger, logger->tmptxt, i5); ngrp--; nsrc--; /* disregard last found source */ goto nextee; } sprintf(logger->tmptxt, " ##914## After findpeak2 call_1: 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], local_sxy); if (nsrc >= 3) logger->logstat = logprint(logger, logger->tmptxt, i5); xvalstart = (int)(amx[1]) - 20; yvalstart = (int)(amx[2]) - 20; /* ************************************************************ */ /* */ /* 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; 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]; ngrp = nsrc - 1; xx_iir[ngrp] = xx[ngrp] = xnow; yy_iir[ngrp] = yy[ngrp] = ynow; sxy_list[ngrp] = local_sxy; /* Test output peak image NLNLNL 20171225 */ if ((flag3 > 0) && (nsrc == 3)) km = 1; else km = 2; for (k=nsrc-km; k 2)) psxy = sxy_list[k]; sprintf(logger->tmptxt, "##280## Dominant source position: sxy: %6d, XY: %+4d %+4d, ngrp: %2d %2d, E%1d", psxy, (int)(psxy/backproj->sky_ydim), (int)(psxy%backproj->sky_ydim), k, nsrc, ee); logger->logstat = logprint(logger, logger->tmptxt, i5); for (j=-5; j<=5; j++) { if (k == nsrc-1) sprintf(logger->tmptxt, "S%2d %03d", k, (int)(psxy%backproj->sky_ydim)+j); else sprintf(logger->tmptxt, "R%2d %03d", k, (int)(psxy%backproj->sky_ydim)+j); for (i=-5; i<=5; i++) { pxy = psxy + i * backproj->sky_ydim + j; if ((pxy > 0) && (pxy < SKYDIM)) { if (k == nsrc-2) { if (backproj->blindspots[pxy] == 0) sprintf(logger->tmptxt2, " %6.1f ", skyim[pxy]); else sprintf(logger->tmptxt2, "B%6.1f ", skyim[pxy]); back_array[5+i][5+j] = skyim[pxy]; back_rdy = 1; } else { if (backproj->blindspots[pxy] == 0) sprintf(logger->tmptxt2, " %6.1f ", current_skyim[pxy]); else sprintf(logger->tmptxt2, "B%6.1f ", current_skyim[pxy]); peak_array[5+i][5+j] = current_skyim[pxy]; back_rdy = 0; } } else { if (k == nsrc-2) { back_array[5+i][5+j] = 10000000.0; back_rdy = 1; } else { peak_array[5+i][5+j] = 10000000.0; back_rdy = 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, i5); } sprintf(logger->tmptxt, " "); logger->logstat = logprint(logger, logger->tmptxt, i5); if ((back_rdy) && (nsrc < 7)) peak_analysis(peak_array, back_array, jemx, ee, psxy, nsrc, backproj, logger); } /* ******************************************************** */ /* */ /* 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, i5); 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 findpeak2 just calculates the centroid */ /* for the last source peak subtracted during shadowfit */ /* */ /* ************************************************************ */ /* QQQQQQ */ amx2[0] = -local_sxy; /* keep the initial source position fixed at original position */ /* sprintf(logger->tmptxt, " ##914## Prior to findpeak2 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, i5); else logger->logstat = logprint(logger, logger->tmptxt, i5); */ /* skyim contains the sky_image contribution from the current source */ sxy2 = findpeak2(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, i5); 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; } /* ******************************************************************** */ /* */ /* 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; 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; } fitcnt++; /* ++++++++++++++++++++++++++++++++++++++++++++++++++ begin of new src identification */ /* ************************************************************************* */ /* ************************************************************************* */ /* * * */ /* * * */ /* * Try to identify the last source found with a catalog source * */ /* * (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) == 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, i5); 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; } /* ******************************************************** */ /* */ /* 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] = local_sxy; backproj->blindnum++; /* check for potential ghosts, eliminate these as well. Note: one more instance in work2d! NL 2009-12-03 */ if (((local_sxy + ghoststep[0]) > 0) && ((local_sxy + ghoststep[0]) < backproj->skydim)) { backproj->blindspots[backproj->blindnum] = local_sxy + ghoststep[0]; backproj->blindnum++; } if (((local_sxy + ghoststep[1]) > 0) && ((local_sxy + ghoststep[1]) < backproj->skydim)) { backproj->blindspots[backproj->blindnum] = local_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 ); } /* ***************************************************************** */ int peak_analysis( float peak_array[11][11], float back_array[11][11], int jemx, int ee, int psxy, int nsrc, struct backpro *backproj, struct log_con *logger) { int i, j, k, i5 = 5, xxx, yyy, ngood_be, ngood_pe, ngood_bc, ngood_pc; float m0, m1, m2, value; float mean_pe, mean_be, sig_be, sig_pe, excs_p, excs_b, excs_rat; float mean_pc, mean_bc, sig_bc, sig_pc, sigma_R; 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], "peak_analysis"); 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); i5 = logger->i5; m0 = m1 = m2 = 0.0; for (i=0; i<11; i++) { for (j=0; j<11; j++) { if ((j < 2) || (j > 8) || (i < 2) || (i > 8)) { if (peak_array[i][j] < 10000000.0) { m0 += 1.0; m1 += peak_array[i][j]; m2 += peak_array[i][j] * peak_array[i][j]; } } } } if (logger->trace) traces(func_local, 10, logger); if (m0 < 10.0) { return(1); } else { ngood_pe = m0; mean_pe = m1 / m0; sig_pe = sqrt((double)(m2 / m0 - mean_pe * mean_pe)); } if (logger->trace) traces(func_local, 20, logger); m0 = m1 = m2 = 0.0; for (i=0; i<11; i++) { for (j=0; j<11; j++) { if ((j < 2) || (j > 8) || (i < 2) || (i > 8)) { if (back_array[i][j] < 10000000.0) { m0 += 1.0; m1 += back_array[i][j]; m2 += back_array[i][j] * back_array[i][j]; } } } } if (logger->trace) traces(func_local, 30, logger); if (m0 < 10.0) { return(2); } else { ngood_be = m0; mean_be = m1 / m0; sig_be = sqrt((double)(m2 / m0 - mean_be * mean_be)); } if (logger->trace) traces(func_local, 40, logger); m0 = m1 = m2 = 0.0; for (i=3; i<8; i++) { for (j=3; j<8; j++) { if (peak_array[i][j] < 10000000.0) { m0 += 1.0; m1 += peak_array[i][j] - mean_pe; } } } if (logger->trace) traces(func_local, 50, logger); if (m0 < 25.0) { return(3); } else { ngood_pc = m0; excs_p = m1 / m0; } if (logger->trace) traces(func_local, 60, logger); m0 = m1 = m2 = 0.0; for (i=3; i<8; i++) { for (j=3; j<8; j++) { if (back_array[i][j] < 10000000.0) { m0 += 1.0; m1 += back_array[i][j] - mean_be; } } } if (logger->trace) traces(func_local, 70, logger); if (m0 < 25.0) { return(4); } else { ngood_bc = m0; excs_b = m1 / m0; } if (logger->trace) traces(func_local, 80, logger); yyy = psxy % backproj->sky_ydim; xxx = (psxy - yyy) / backproj->sky_ydim; xxx -= backproj->FOV_radius; yyy -= backproj->FOV_radius; /* estimate error on the background excess */ sigma_R = (sig_be / 5.0 + sig_be / 8.5); value = excs_b; if (sigma_R > excs_b) value = sigma_R; sprintf(logger->tmptxt, "#pa %12s J%1dE%1dn%1d XY %4d %4d N %2d %2d %2d %2d av %5.1f %5.1f sg %5.2f %5.2f ex%7.1f %6.1f s%4.1f R %5.2f", logger->scw_file_name, jemx+1, ee, nsrc-2, xxx, yyy, ngood_pe, ngood_be, ngood_pc, ngood_bc, mean_pe, mean_be, sig_pe / 8.4, sig_be / 8.4, excs_p, excs_b, sigma_R, value / excs_p); 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(0); } /***************************************************************** * Name of source file: jemxlib_array_put.c * Version of source file: 6.0.0 * 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 * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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); } /************************************************************************** JEMXLIBgetInstrData * Version of source file: 6.0.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 ); } /****************************************************************************** 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); } /****************************************************************************** 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); } /* ******************************************************************************** */ /***************************************************************** * Name of source file: j_fitprep.c * Version of source file: 6.0.0 * 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. * 6.0.0 180112 Introduces LC generation and burst detection * 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]; } 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]; logger->E_min[eeuser] = USERBIN[eeuser].E_min = sh->eval[eeuser][0]; logger->E_max[eeuser] = USERBIN[eeuser].E_max = sh->eval[eeuser][1]; meanE /= (sh->pival[eeuser][1] - sh->pival[eeuser][0] + 1); logger->E_mean[eeuser] = 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, 0); /* 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; job2done: 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, i5); 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", eeuser, totcnt[eeuser], (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, eeuser, 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", 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", j); logger->logstat = logprint(logger, logger->tmptxt, i5); 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: j_iir_arcdist.c * Version of source file: 6.0.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 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 * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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 ); } /***************************************************************** * Name of source file: j_iir_bin_search.c * Version of source file: 6.0.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 * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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: j_iir_get_bkgshds.c * Version of source file: 6.0.0 * 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 * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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 fusk = 1; /* QaD solution to avoid using the parameter: bkgShdDOL */ 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; iLC ) */ if( fusk == 1 ) { /* Use default solution i.e. get shadowgrams from IMOD */ /* Including 'logger->LC' in the if-statement has been introduced as a quick and dirty solution to the LC output problem (2015-04-09/NJW) */ if( jemxNum == JMX1 ) { strcpy( structName, "JMX1-DBKG-MOD" ); } else { strcpy( structName, "JMX2-DBKG-MOD" ); } status = DALobjectFindElement( ptrImod, structName, &bkgShdPtr, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_2, "##120## Failed to open %s", structName ); goto exittrace; } } else { /* * * Get pointer to user selected data structure with bkg shadowgrams * */ status = DALobjectOpen( bkgShdDOL, &bkgShdPtr, status); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_2, "##121## Failed to open %s", bkgShdDOL ); goto exittrace; } } /* * Get the number of background shadowgrams * and check axes etc. */ status = DALarrayGetStruct( bkgShdPtr, &dalType, &numAxes, axes, status); if( status != ISDC_OK ) { goto exittrace; } sh->numBkgShds = (int) axes[2]; if( sh->numBkgShds > NMAXBKGSHDS ) { RILlogMessage( NULL, Warning_0,"##122## The supplied number of " "background shadowgrams (%d) exceeds the allowed maximum (%d)", sh->numBkgShds, NMAXBKGSHDS ); RILlogMessage( NULL, Warning_0,"##123## Only the first %d will " "actually be used", NMAXBKGSHDS ); sh->numBkgShds = NMAXBKGSHDS; } if( dalType != DAL_FLOAT ) { RILlogMessage( NULL, Error_0, "##124## 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, "##125## 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, "##126## 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_dead_time.c * Version of source file: 6.0.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: 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. * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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_events. c * Name of Function: j_iir_get_events * Version of source file: 6.0.0 * 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. * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * *****************************************************************************/ 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; if (m < 1) m = 1; 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 ); } /***************************************************************** * Name of source file: j_iir_get_gain.c * Version of source file: 6.0.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: 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. * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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_greyfilter.c * Version of source file: 6.0.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: 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. * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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_get_psfsigma.c * Version of source file: 6.0.0 * 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 * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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: j_iir_get_radec_init.c * Version of source file: 6.0.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 * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection *****************************************************************/ 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); } /* *********************************************************** */ /***************************************************************** * Name of source file: j_iir_get_shds.c * Version of source file: 6.0.0 * 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 * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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_get_XYvsEima.c * Version of source file: 6.0.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: 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 * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection *****************************************************************/ 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: j_iir_read_bpl.c * Version of source file: 6.0.0 * 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 * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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_Write_LC.c * Version of source file: 6.0.0 * Purpose: Write light curve component in j_ima_iros * Date: 2015/03/30 * Programmer: Niels Lund * Derived from component: Stefan Larsson's j_src_lc.c * Update history: 1.0.0 20150330 First version * 5.1.2 151106 Running version with LC generation * 5.1.8 160404 Include correction of LC-fluxes to align with fitted fluxes * 5.1.9 160415 Update of light curve output and keywords according to agreement with ISDC * 5.1.10 160829 Circumvent analysis blocking caused by small amount of data in 'errorfit' * 5.1.11 160913 Update 'write_srcl_res' and 'work2d' to include 'pure burst' sources. * 5.1.12 160914 Update 'j_iir_Write_LC' to avoid floating point exc. for very short observation times * 5.1.14 160922 Update 'j_iir_Write_LC' to avoid floating point exc. for few time bins * 5.1.21 161028 Update 'j_iir_Write_LC' to avoid floating point exc. for unknown burst src seen only at high energy * 5.1.29 170310 Multiply 'rateBuff, errBuff, bRateBuff and bErrBuff' by 100 before output in 'j_iir_Write_LC.c' * 5.1.30 170804 Modify max number of light curve energy bins (user def. + 3) from 7 to MAX_LC_EBINS * 5.1.31 170827 Limit burst search activity to energy bands with more than 25% of total SCW counts * 5.1.32 170906 Introduce 'typedef image_cor' and malloc of this structure (used in 'paltani_subs.c') * 5.1.33 171206 Write RTSTART/STOP in sky_ima, srcl_res iros_lc files. Introduce logger->LCgtiREF * 6.0.0 180112 Introduces LC generation and burst detection * 6.0.7 180913 Modified log and reg files to include %11.6lf burst start and stop times, and add obsID * 6.0.8 180916 Block writing of burst images into sky_ima files. Assure output of light curves for user sources ******************************************************************************/ /* ======================================================= * Write everything required to the output data structure(s). * A single function is used for both normal and folded * lightcurves - nPhaseBins is used as flag to distinguish * the two cases. * ======================================================= */ /* if we have folded lightcurves we must make sure to write * only nPhaseBin entries */ /* **************************************************************************** */ #define J_SRC_ACCURACY 1e-6 int j_iir_Write_LC( dal_element *theSWG, Auxdata auxdata, struct instr_data *jmx_id, struct log_con *logger, swg_pointing *point, struct backpro *backproj, struct shadowgrams *sh, goodsrc *GOODSRC, timeslices *Tslices, b_list *B_list, long nPhaseBins, int chatter, int status) { int i, j, k, ALLsrc, ntime, i5; float m0, m1, m2, mb0, mb1, mb2, m00, m01, m02; char sourceName[32], gnuname[128], textline[256], nameLC[14], False[14]; float xmm, ymm, fj; FILE* gnufil; Instrument jemxInstr; char srcID[SCW_SRCMAX][DAL_MED_STRING]; char srcNAME[SCW_SRCMAX][DAL_MED_STRING]; float srcRA[SCW_SRCMAX]; float srcDec[SCW_SRCMAX]; long nSources; long nOutLCBins; int nChanBins; double timeStep; double timeStart; double tElapse; double onTime; double meanDead; double DELTA_T; double RTStart = 0.0; /* To be used for writing keyword (attribute) NJW 2017-11-23 */ double RTStop = 0.0; /* To be used for writing keyword (attribute) NJW 2017-11-23 */ float srcOffAxisAngle[SCW_SRCMAX]; float srcVignet[SCW_SRCMAX]; float active_pix; float x, y, r; float geoarea, npixsource, npixbackgr; dal_element *dalPtr=NULL; /* generic DAL pointer */ dal_dataType dType=DAL_DT_UNKNOWN; /* needed for DAL calls */ char nameEbds[14]; /* name of energy boundaries table */ char typeName[FLEN_CARD]; /* FULL or REST */ char appFlag[2] = "F"; double *rateBuff=NULL; /* local buffer for rate per energy */ double *errBuff=NULL; /* local buffer for error per energy */ double *bRateBuff=NULL; /* local buffer for bRate per energy */ double *bErrBuff=NULL; /* local buffer for bError per energy */ double *timeLC=NULL; /* local buffer for for mid-Times */ double *timeDel=NULL; /* local buffer for for delta-Times */ double *fracExp=NULL; /* local buffer for fractional exposure */ double timeErr=1.0/8192.0; /* JEM-X time uncertainty */ double timeErrRel=0.0; /* JEM-X time relative uncertainty */ double rate=0.0; /* Keep rate value during calc */ double bRate=0.0; /* Keep bRate value during calc */ double srcRate=0.0; /* Net source rate */ double bkgRate=0.0; /* Background rate */ double time=0.0; /* Live time for a bin */ double sumtime=0.0; /* Sum of time for bins */ double sumRate=0.0; /* Sum of net rate for all timebins */ double sumBRate=0.0; /* Sum of bkg. rates for all time bins*/ double sumNRate=0.0; /* Sum of nRate for all timebins */ double rateVariance=0.0; /* Variance of illum. rate */ double bRateVariance=0.0; /* Variance of shadow. rate */ double sumSrcVariance=0.0; /* Sum of source error variances */ double sumBkgVariance=0.0; /* Sum of backgr. error variances */ double avgRate=0.0; double avgRateErr=0.0; double bavgRate=0.0; double bavgRateErr=0.0; double srcVariance = 0.0; double bkgVariance = 0.0; float deltaT=0.0; /* TIMEDEL */ float detSig = 0.0; /* Detection significance */ long numRead=0; /* counter of read values */ int iSource=0; /* loop over sources */ long nRate=0; /* Number of events (illum. area) */ int eChan=0; /* loop over channels */ int giveEbounds=1; /* boolean: do we have energy bounds? */ static int func_local = -1, local_calling_num=0; clock_t calling_TT, TT_now; /* function entry timing start */ if (func_local < 0) { func_local = logger->func_used_num++; sprintf(logger->func_names[func_local], "j_iir_Write_LC"); if (logger->func_used_num > 199) { sprintf(logger->tmptxt, "func_used_num > 199"); logger->logstat = logprint(logger, logger->tmptxt, 6); logger->func_used_num = 199; } } logger->func_calls[func_local]++; logger->TT = TT_now = clock(); calling_TT = logger->TT; local_calling_num = logger->func_calling_num; logger->func_calling_num = func_local; /* function entry timing end */ if (logger->trace) traces(func_local, 0, logger); /* * exit function immediately if callingStatus is not OK on entry */ if (status != ISDC_OK) goto exitnow; if (logger->trace) traces(func_local, 5, logger); i5 = logger->i5; nChanBins = sh->numShds - backproj->ee_basic; if (nChanBins > MAX_LC_EBIN - backproj->ee_basic) nChanBins = MAX_LC_EBIN - backproj->ee_basic; nSources = logger->N_SRCT; jemxInstr = jmx_id->jmx_unit;; for (ntime=0; ntimeNumTimeBins; ntime++) { Tslices[ntime].dontUse &= 1; /* mask away 'used time bin' flags when starting */ } nOutLCBins = logger->NumTimeBins; /* if (nPhaseBins == 0) nPhaseBins = 1; */ /* NL 100914 Do not accept zero nPhaseBins */ if (0 < nPhaseBins) { nOutLCBins = nPhaseBins; } if (logger->trace) traces(func_local, 7000000 + nOutLCBins + nPhaseBins*10000, logger); /* Allocate local buffers */ status = DALallocateDataBuffer( (void **)&rateBuff, nOutLCBins * sizeof(double), status ); status = DALallocateDataBuffer( (void **)&errBuff, nOutLCBins * sizeof(double), status ); status = DALallocateDataBuffer( (void **)&bRateBuff, nOutLCBins * sizeof(double), status ); status = DALallocateDataBuffer( (void **)&bErrBuff, nOutLCBins * sizeof(double), status ); status = DALallocateDataBuffer( (void **)&timeLC, nOutLCBins * sizeof(double), status ); status = DALallocateDataBuffer( (void **)&fracExp, nOutLCBins * sizeof(double), status ); status = DALallocateDataBuffer( (void **)&timeDel, nPhaseBins * sizeof(double), status ); if (ISDC_OK!=status) { RILlogMessage(NULL,Error_2, "##733## (Write_LC) Error allocating buffers!"); goto exitnow; } if (logger->trace) traces(func_local, 10, logger); if (logger->NumTimeBins > 1) deltaT = timeStep = (Tslices[1].Tstop - Tslices[1].Tstart); else deltaT = timeStep = (Tslices[0].Tstop - Tslices[0].Tstart); for (ntime=0; ntimetrace) traces(func_local, 10000+ (int)(deltaT + 0.01), logger); DELTA_T = deltaT * 86400.0; if (DELTA_T < 0.0001) DELTA_T = 0.0001; if (logger->trace) traces(func_local, 20000+ (int)(DELTA_T + 0.01), logger); for (ntime=0; ntimeNumTimeBins; ntime++) { *(timeLC + ntime) = (Tslices[ntime].Tstart + Tslices[ntime].Tstop) / 2.0; if (Tslices[ntime].dontUse) *(fracExp + ntime) = 0.0; else *(fracExp + ntime) = Tslices[ntime].final_expo / DELTA_T; } timeStart = Tslices[0].Tstart; if (logger->trace) traces(func_local, 11, logger); /* Compute energy channel number (0-255) at the center of the energy band. */ if (logger->trace) traces(func_local, 12, logger); RILlogMessage( NULL, Log_0, "##734## jmx_id->jmx_unit: %d", jmx_id->jmx_unit ); /* if (1 == jmx_id->jmx_unit) strcpy(nameLC,"JMX1-SRC.-"); */ strcpy(nameLC,"JMX1-SRC.-"); if (1 == jmx_id->jmx_unit) strcpy(nameLC,"JMX2-SRC.-"); /* distinguish between folded lightcurve and normal one */ if (nPhaseBins > 0) { strcat(nameLC, "FLC"); /* FLC */ } else { strcat(nameLC, "LCR"); /* LCR */ } if (logger->trace) traces(func_local, 15, logger); /* * Now to the actual output data */ dalPtr=NULL; if (logger->trace) traces(func_local, 1000000 + 10000*nSources + nChanBins, logger); for (iSource=0; iSourceallsrc_lc[iSource]; if (logger->trace) traces(func_local, 30000+100*iSource, logger); for (eChan=backproj->ee_basic; eChanee_basic; eChan++) { /* loop over E-bands. Ends in 657 */ if (logger->trace) traces(func_local, 40000+100*iSource+eChan, logger); /* find total number of axtive pixels. Used as reference for vignetting factors */ active_pix = 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[eChan]))) active_pix += 1.0; } if (active_pix < 1.0) active_pix = 256.0 * 256.0 * 3.14169 / 4.0; if (logger->trace) traces(func_local, 2000000+(int)(active_pix), logger); /* Create new child of detector lightcurve Index */ RILlogMessage( NULL, Log_0, "##735## nameLC: %s", nameLC ); status = DAL3GENindexCreateMember(theSWG, nameLC, NULL, &dalPtr, status); if (ISDC_OK!=status) { RILlogMessage(NULL, Error_1, "##736## (Write_LC) Can not correctly create output LC number %d!, status: %d", eChan+1-backproj->ee_basic, status); goto exitnow; /**** * RILlogMessage(NULL, Warning_1, "##737## (Write_LC) Can not correctly create output LC number %d!, status: %d", * eChan+1-backproj->ee_basic, status); * RILlogMessage(NULL, Log_0, "##738## Reset status to ISDC_OK"); * status = ISDC_OK; ***/ } if (logger->trace) traces(func_local,20, logger); /* get the light curve data from gnu-files output by j_ima_iros 'work2d' ver. 5.1.2 */ /* For all energy bands, but only for first source: Read also the detector light curve */ if (iSource > 0) goto skipGlobal; if (logger->trace) traces(func_local,30, logger); sprintf(gnuname, "J%1d_lc_%04d%04d%04d_Global_E%02d.gnu", jmx_id->jmx_unit+1, backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv, eChan); sprintf(logger->tmptxt, "DALNAVN: E: %2d, J%1d_lc_%04d%04d%04d_Global_E%02d.gnu", eChan, jmx_id->jmx_unit+1, backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv, eChan); logger->logstat = logprint(logger, logger->tmptxt, 0); m00 = m01 = m02 = 0.0; if ((gnufil = fopen(gnuname, "rt")) != NULL) { sprintf(logger->tmptxt,"Successfully opened %s for reading in WLC2", gnuname); logger->logstat = logprint(logger, logger->tmptxt, i5); if (logger->trace) traces(func_local,40, logger); for (ntime=0; ntimeNumTimeBins; ntime++) { Tslices[ntime].wflux[0] = 0.0; /* dummy initialization value */ if (Tslices[ntime].dontUse) continue; fgets(textline, 200, gnufil); if (feof(gnufil)) goto udoneA; sscanf(textline, "%d %f", &j, &(Tslices[ntime].wflux[0])); /* Detector light curve in wflux[0] */ m00 += 1.0; m01 += Tslices[ntime].wflux[0]; m02 += Tslices[ntime].wflux[0] * Tslices[ntime].wflux[0]; k = strlen(textline); textline[k-1] = 0; } udoneA: fclose(gnufil); gnufil = NULL; } else { sprintf(logger->tmptxt,"Could not open %s for reading, inserting dummy data", gnuname); logger->logstat = logprint(logger, logger->tmptxt, 0); if (logger->trace) traces(func_local,45, logger); for (ntime=0; ntimeNumTimeBins; ntime++) { Tslices[ntime].wflux[0] = 0.0; } } /* transfer light curve to bRateBuff */ /* OBSOLETE - all source light curves are now supplied with their proper error values * if (logger->trace) traces(func_local,50, logger); * * for (ntime=0; ntimeNumTimeBins; ntime++) { * * if ((m2 == 0.0) || (Tslices[ntime].dontUse)) { * Tslices[ntime].wflux[ 0] = 0.0; * Tslices[ntime].wflux[88] = 1.0; * } else { * Tslices[ntime].wflux[88] = avgRateErr; * } * * bRateBuff[ntime] = Tslices[ntime].wflux[0]; * bErrBuff[ntime] = Tslices[ntime].wflux[88]; * } */ if (logger->trace) traces(func_local,60, logger); skipGlobal: ALLsrc = logger->allsrc_lc[iSource]; txtConvert(GOODSRC[ALLsrc].name, sourceName, logger); srcRA[iSource] = GOODSRC[ALLsrc].RA; srcDec[iSource] = GOODSRC[ALLsrc].dec; strcpy(srcNAME[iSource], GOODSRC[ALLsrc].name); strcpy(srcID[iSource], GOODSRC[ALLsrc].ISDCname); sprintf(gnuname, "J%1d_lc_%04d%04d%04d_%s_E%02d.gnu", jmx_id->jmx_unit+1, backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv, sourceName, eChan); sprintf(logger->tmptxt, "DALNAVN: ALLsrc %2d, E: %2d, %20s J%1d_lc_%04d%04d%04d_%s_E%02d.gnu", ALLsrc, eChan, GOODSRC[ALLsrc].name, jmx_id->jmx_unit+1, backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv, sourceName, eChan ); logger->logstat = logprint(logger, logger->tmptxt, 0); if (logger->trace) traces(func_local, 130, logger); m0 = m1 = m2 = 0.0; mb0 = mb1 = mb2 = 0.0; if ((gnufil = fopen(gnuname, "rt")) != NULL) { sprintf(logger->tmptxt,"Successfully opened %s for reading in WLC2", gnuname); logger->logstat = logprint(logger, logger->tmptxt, i5); if (logger->trace) traces(func_local, 132, logger); /* skip light curve intended for 'regfile' */ for (ntime=0; ntimeNumTimeBins; ntime++) { if (Tslices[ntime].dontUse) continue; fgets(textline, 200, gnufil); if (feof(gnufil)) goto udoneX; /* premature eof */ } /* skip two trailing blank lines */ fgets(textline, 200, gnufil); if (feof(gnufil)) goto udoneX; /* premature eof */ fgets(textline, 200, gnufil); if (feof(gnufil)) goto udoneX; /* premature eof */ if (logger->trace) traces(func_local, 133, logger); /* now we should be at the start of the source light curve */ for (ntime=0; ntimeNumTimeBins; ntime++) { Tslices[ntime].wflux[1] = 0.0; /* dummy initialization value */ if (Tslices[ntime].dontUse) continue; fgets(textline, 200, gnufil); if (feof(gnufil)) goto udoneX; /* premature eof */ sscanf(textline, "%f %f %f", &fj, &(Tslices[ntime].wflux[1]), &(Tslices[ntime].wflux[89])); m0 += 1.0; m1 += Tslices[ntime].wflux[1]; m2 += Tslices[ntime].wflux[1] * Tslices[ntime].wflux[1]; k = strlen(textline); textline[k-1] = 0; } /* skip two trailing blank lines */ fgets(textline, 200, gnufil); if (feof(gnufil)) goto udoneX; /* premature eof */ fgets(textline, 200, gnufil); if (feof(gnufil)) goto udoneX; /* premature eof */ if (logger->trace) traces(func_local, 134, logger); /* now we should be at the start of the source background light curve */ for (ntime=0; ntimeNumTimeBins; ntime++) { Tslices[ntime].wflux[2] = 0.0; /* dummy initialization value */ if (Tslices[ntime].dontUse) continue; fgets(textline, 200, gnufil); if (feof(gnufil)) { if (logger->trace) traces(func_local, ntime+3000000, logger); if (logger->trace) traces(func_local, logger->NumTimeBins+4000000, logger); goto udoneX; /* premature eof */ } sscanf(textline, "%f %f %f", &fj, &(Tslices[ntime].wflux[2]), &(Tslices[ntime].wflux[90])); mb0 += 1.0; mb1 += Tslices[ntime].wflux[2]; mb2 += Tslices[ntime].wflux[2] * Tslices[ntime].wflux[2]; k = strlen(textline); textline[k-1] = 0; } fclose(gnufil); gnufil = NULL; /* end of reading light curves */ sprintf(logger->tmptxt,"Read %4.0f source flux and %4.0f background flux values from %s", m0, mb0, gnuname); logger->logstat = logprint(logger, logger->tmptxt, 0); } else { sprintf(logger->tmptxt,"Could not open %s for reading, inserting dummy data", gnuname); logger->logstat = logprint(logger, logger->tmptxt, 0); if (logger->trace) traces(func_local, 136, logger); goto udoneY; udoneX: sprintf(logger->tmptxt,"No data in %s, inserting dummy data", gnuname); logger->logstat = logprint(logger, logger->tmptxt, 0); if (logger->trace) traces(func_local, 1136, logger); udoneY: for (ntime=0; ntimeNumTimeBins; ntime++) { Tslices[ntime].wflux[1] = 0.0; Tslices[ntime].wflux[89] = 1.0; Tslices[ntime].wflux[2] = 0.0; Tslices[ntime].wflux[90] = 1.0; } m0 = mb0 = m2 = mb2 = 0.0; } if (logger->trace) traces(func_local, 140, logger); /* calculate flux mean and standard devation */ if ((m0 > 0.0) && (m2 > 0.0)) { if (logger->trace) traces(func_local, 141, logger); avgRate = m1 / m0; if (logger->trace) traces(func_local, 142, logger); if ((m2 / m0 - avgRate * avgRate) > 0.0) avgRateErr = sqrt(m2 / m0 - avgRate * avgRate); else avgRateErr = 1.0; if (logger->trace) traces(func_local, 143, logger); } else { avgRate = 0.0; avgRateErr = 1.0; } if ((mb0 > 0.0) && (mb2 > 0.0)) { bavgRate = mb1 / mb0; if (logger->trace) traces(func_local, 144, logger); if ((mb2 / mb0 - bavgRate * bavgRate) > 0.0) bavgRateErr = sqrt(mb2 / mb0 - bavgRate * bavgRate); else bavgRateErr = 1.0; if (logger->trace) traces(func_local, 145, logger); } else { bavgRate = 0.0; bavgRateErr = 1.0; } /* transfer light curves to rateBuff & bRateBuff */ if (logger->trace) traces(func_local, 146, logger); for (ntime=0; ntimeNumTimeBins; ntime++) { if ((m0 == 0.0) || (m2 == 0.0) || (Tslices[ntime].dontUse)) { Tslices[ntime].wflux[ 1] = 0.0; Tslices[ntime].wflux[89] = 1.0; } rateBuff[ntime] = 100.0 * Tslices[ntime].wflux[1]; errBuff[ntime] = 100.0 * Tslices[ntime].wflux[89]; if ((mb0 == 0.0) || (mb2 == 0.0) || (Tslices[ntime].dontUse)) { Tslices[ntime].wflux[ 2] = 0.0; Tslices[ntime].wflux[90] = 1.0; } bRateBuff[ntime] = 100.0 * Tslices[ntime].wflux[2]; bErrBuff[ntime] = 100.0 * Tslices[ntime].wflux[90]; } if (logger->trace) traces(func_local, 150, logger); /* Write the source IDs. */ RILlogMessage( NULL, Log_0, "##739## nSources = %ld", nSources ); RILlogMessage( NULL, Log_0, "##740## iSource = %d, srcID[iSource] = %s %s", iSource, srcID[iSource], srcNAME[iSource] ); status = DALattributePut(dalPtr, "SOURCEID", DAL_CHAR, (void*)&(srcID[iSource]), NULL, NULL, status); if (ISDC_OK!=status) { RILlogMessage(NULL,Error_1, "##741## (Write_LC) Error writing SOURCEID keyword!"); goto exitnow; } status = DALattributePut(dalPtr, "NAME", DAL_CHAR, (void*)&(srcNAME[iSource]), NULL, NULL, status); if (ISDC_OK!=status) { RILlogMessage(NULL,Error_1, "##741## (Write_LC) Error writing NAME keyword!"); goto exitnow; } status = DALattributePut(dalPtr, "CREATOR", DAL_CHAR, (void*)("j_ima_iros"), NULL, NULL, status); if (ISDC_OK!=status) { RILlogMessage(NULL,Error_1, "##741## (Write_LC) Error writing CREATOR keyword!"); goto exitnow; } status = DALattributePut(dalPtr, "CONFIGUR", DAL_CHAR, (void*)&COMPONENT_VERSION, NULL, NULL, status); if (ISDC_OK!=status) { RILlogMessage(NULL,Error_1, "##741## (Write_LC) Error writing CREATOR keyword!"); goto exitnow; } /* Removed VIGNAPP = "FALSE" NLNLNL 20160415 * strcpy(False, "F"); * status = DALattributePut(dalPtr, "VIGNAPP", DAL_BOOL, (void*)&False, NULL, NULL, status); * if (ISDC_OK!=status) { * RILlogMessage(NULL,Error_1, "##741## (Write_LC) Error writing CREATOR keyword!"); * goto exitnow; * } */ if (logger->trace) traces(func_local, 160, logger); /* Write angle offset from the center of the field of view. */ i = getxy( srcRA[iSource], srcDec[iSource], jmx_id->jmx_unit, &xmm, &ymm, jmx_id, point, logger); if (logger->trace) traces(func_local, 1000+i, logger); if (logger->trace) traces(func_local, 1000+iSource, logger); if (i == 0) { srcOffAxisAngle[iSource] = sqrt(xmm*xmm + ymm*ymm) / jmx_id->mask_height * 180.0 / 3.14159; } else srcOffAxisAngle[iSource] = 0.0; if (logger->trace) traces(func_local, 5000000+(int)(srcOffAxisAngle[iSource]), logger); if (logger->trace) traces(func_local, 170, logger); status = DALattributePut(dalPtr, "OFFANGLE", DAL_FLOAT, (void*)&srcOffAxisAngle[iSource], NULL, NULL, status); if (ISDC_OK!=status) { RILlogMessage(NULL,Error_1, "##742## (Write_LC) Error writing OFFANGLE keyword!"); goto exitnow; } /* Removed GEOARA, NPIXSOU and NPIXBACK keywords NLNLNL 20160415 * geoarea = 100.0; reference value: 100 cm2 * * status = DALattributePut(dalPtr, "GEOAREA", DAL_FLOAT, * (void*)&geoarea, NULL, NULL, status); * if (ISDC_OK!=status) { * RILlogMessage(NULL,Error_1, "##742## (Write_LC) Error writing GEOAREA keyword!"); * goto exitnow; * } * * Write the NPIXSOU value. * * * npixsource = 100.0 * GOODSRC[ALLsrc].src_pixel_area[eChan]; * * status = DALattributePut(dalPtr, "NPIXSOU", DAL_FLOAT, * (void*)&npixsource, NULL, NULL, status); * if (ISDC_OK!=status) { * RILlogMessage(NULL,Error_1, "##742## (Write_LC) Error writing NPIXSOU eyword!"); * goto exitnow; * } * * Write the NPIXBACK value. * * * npixbackgr = 100.0 * GOODSRC[ALLsrc].src_backgr_area[eChan]; * * status = DALattributePut(dalPtr, "NPIXBACK", DAL_FLOAT, * (void*)&npixbackgr, NULL, NULL, status); * if (ISDC_OK!=status) { * RILlogMessage(NULL,Error_1, "##742## (Write_LC) Error writing NPIXSOU eyword!"); * goto exitnow; * } * * Write the vignetting value. The vignetting area given here is impractical. * Will use 100 cm2 as reference area instead. * NLNLNL 20160415 * srcVignet[iSource] = GOODSRC[ALLsrc].src_pixel_area[eChan] / active_pix; */ srcVignet[iSource] = GOODSRC[ALLsrc].src_pixel_area[eChan] / 100.0; status = DALattributePut(dalPtr, "VIGNET", DAL_FLOAT, (void*)&srcVignet[iSource], NULL, NULL, status); if (ISDC_OK!=status) { RILlogMessage(NULL,Error_1, "##742## (Write_LC) Error writing VIGNET keyword!"); goto exitnow; } /* Write the source coordinates. */ status = DALattributePut(dalPtr, "RA_OBJ", DAL_FLOAT, (void*)&srcRA[iSource], NULL, NULL, status); if (ISDC_OK!=status) { RILlogMessage(NULL, Error_1, "##743## (Write_LC) Error writing RA_OBJ keyword!"); goto exitnow; } /* Write the source coordinates. */ status = DALattributePut(dalPtr, "DEC_OBJ", DAL_FLOAT, (void*)&srcDec[iSource], NULL, NULL, status); if (ISDC_OK!=status) { RILlogMessage(NULL,Error_1, "##744## (Write_LC) Error writing DEC_OBJ keyword!"); goto exitnow; } if (logger->trace) traces(func_local, 180, logger); /* Add sufficient rows */ status = DALtableAddRows(dalPtr, 0, nOutLCBins, status); if (ISDC_OK!=status) { RILlogMessage(NULL,Error_1, "##745## (Write_LC) Can not add %ld rows to table!", nOutLCBins); goto exitnow; } if (logger->trace) traces(func_local, 190, logger); /* Write column TIME for normal lightcurves or PHASE and PHASEDEL for folded lightcurves */ if (0 == nPhaseBins) { status = DALtablePutCol(dalPtr, "TIME", 0, DAL_DOUBLE, nOutLCBins, (void*)timeLC, status); if (ISDC_OK!=status) { RILlogMessage(NULL, Error_1, "##746## (Write_LC) Can not write column TIME!"); goto exitnow; } if (logger->trace) traces(func_local, 195, logger); /* Write TIMEDEL. */ /* *********** NJW 2015-05-29 */ status = DALattributePut(dalPtr, "TIMEDEL", DAL_FLOAT, (void*)&deltaT, NULL, NULL, status); if (ISDC_OK!=status) { RILlogMessage(NULL, Error_1, "##747## (Write_LC) Error writing TIMEDEL keyword!"); goto exitnow; } /* ***********/ status = DALtablePutCol(dalPtr, "FRACEXP", 0, DAL_DOUBLE, nOutLCBins, (void*)fracExp, status); if (ISDC_OK!=status) { RILlogMessage(NULL, Error_1, "##748## (Write_LC) Can not write column FRACEXP!"); goto exitnow; } } else { status = DALtablePutCol(dalPtr, "PHASE", 0, DAL_DOUBLE, nOutLCBins, (void*)timeLC, status); if (ISDC_OK!=status) { RILlogMessage(NULL, Error_1, "##749## (Write_LC) Can not write column TIME!"); goto exitnow; } status = DALtablePutCol(dalPtr,"PHASEDEL", 0, DAL_DOUBLE, nOutLCBins, (void*)timeDel, status); if (ISDC_OK!=status) { RILlogMessage(NULL, Error_1, "##750## (Write_LC) Can not write column PHASEDEL!"); goto exitnow; } } /* *********** NJW 2017-12-06 Copy TELAPSE, ONTIME, DEADC, and EXPOSURE from first shadowgram */ status = DAL3GENattributeCopy(sh->ptr[0], dalPtr, "TELAPSE,ONTIME,DEADC,EXPOSURE", status); if (ISDC_OK!=status) { RILlogMessage(NULL,Error_1, "##783## (Write_LC) Problems copying" " time keywords from the first SHd! status=%d",status); goto exitnow; } /* ***********/ if (logger->trace) traces(func_local, 210, logger); /* Write columns RATE and ERROR regardless of LC type */ status = DALtablePutCol(dalPtr,"RATE", 0, DAL_DOUBLE,nOutLCBins, (void*)rateBuff,status); if (ISDC_OK!=status) { RILlogMessage(NULL, Error_1, "##751## (Write_LC) Can not write column RATE!"); goto exitnow; } status = DALtablePutCol(dalPtr,"ERROR", 0, DAL_DOUBLE,nOutLCBins, (void*)errBuff,status); if (ISDC_OK!=status) { RILlogMessage(NULL, Error_1, "##752## (Write_LC) Can not write column ERROR!"); goto exitnow; } if (logger->trace) traces(func_local, 220, logger); /* Write columns BRATE and BERROR regardless of LC type */ status = DALtablePutCol(dalPtr,"BRATE", 0, DAL_DOUBLE,nOutLCBins, (void*)bRateBuff,status); if (ISDC_OK!=status) { RILlogMessage(NULL, Error_1, "##753## (Write_LC) Can not write column BRATE!"); goto exitnow; } status = DALtablePutCol(dalPtr,"BERROR", 0, DAL_DOUBLE,nOutLCBins, (void*)bErrBuff,status); if (ISDC_OK!=status) { RILlogMessage(NULL, Error_1, "##754## (Write_LC) Can not write column BERROR!"); goto exitnow; } if (logger->trace) traces(func_local, 230, logger); /* Set keywords for channel and energy boundaries */ status = DALattributePut(dalPtr,"CHANMIN", DAL_INT, (void*)&(sh->pival[eChan][0]), NULL, NULL, status); status = DALattributePut(dalPtr,"CHANMAX", DAL_INT, (void*)&(sh->pival[eChan][1]), NULL, NULL, status); if (logger->trace) traces(func_local, 240, logger); if (logger->trace) traces(func_local, 1000+eChan, logger); if (giveEbounds) { status = DALattributePut(dalPtr,"E_MIN", DAL_FLOAT, (void*)&(jmx_id->escale[sh->pival[eChan][0]]), NULL, NULL, status); status = DALattributePut(dalPtr,"E_MAX", DAL_FLOAT, (void*)&(jmx_id->escale[sh->pival[eChan][1]]), NULL, NULL, status); if (ISDC_OK!=status) { RILlogMessage(NULL, Error_1, "##755## (Write_LC) Error writing channel/energy keywords!"); goto exitnow; } } if (logger->trace) traces(func_local, 250, logger); if(avgRate > 0.0 && avgRateErr > 0.0){ detSig = avgRate/avgRateErr; }else { detSig = 0.0; } status = DALattributePut(dalPtr, "DETSIG", DAL_FLOAT, (void*)&detSig, NULL, NULL, status); if (ISDC_OK!=status) { RILlogMessage(NULL,Error_1, "##756## (Write_LC) Error writing DETSIG keyword!"); goto exitnow; } /********* The following piece of code has been replaced by copying from first shadowgram * because the values here are incorrrect - see about 80 lines above. NJW 2017-12-06 * * tElapse = Tslices[logger->NumTimeBins - 1].Tstop - Tslices[0].Tstart; * * slash* set further keywords: elapsed time and on time *slash * * status = DALattributePut(dalPtr, "TELAPSE", DAL_DOUBLE, (void*)&tElapse, NULL, NULL, status); * if (ISDC_OK!=status) { * RILlogMessage(NULL,Error_1, "##756## (Write_LC) Error writing TELAPSE keyword!"); * goto exitnow; * } * * onTime = sh->accumT; * status = DALattributePut(dalPtr,"ONTIME",DAL_DOUBLE, (void*)&onTime, NULL, NULL, status); * if (ISDC_OK!=status) { * RILlogMessage(NULL,Error_1, "##757## (Write_LC) Error writing ONTIME keyword!"); * goto exitnow; * } * * if (tElapse > 0.0) meanDead = onTime / tElapse; else meanDead = 0.0; * slash* mean dead time correction factor *slash * status = DALattributePut(dalPtr,"DEADC",DAL_DOUBLE, (void*)&meanDead, NULL, NULL, status); * if (ISDC_OK!=status) { * RILlogMessage(NULL,Error_1, "##758## (Write_LC) Error writing DEADC keyword!"); * goto exitnow; * } * ************************/ /*************** Statements added by NJW 2017-11-23 */ RTStart = logger->RTStart; RTStop = logger->RTStop; status = DALattributePut(dalPtr,"RTSTART",DAL_DOUBLE, (void*)&RTStart, NULL, NULL, status); status = DALattributePut(dalPtr,"RTSTOP",DAL_DOUBLE, (void*)&RTStop, NULL, NULL, status); if (ISDC_OK!=status) { RILlogMessage(NULL,Error_1, "##795## (Write_LC) Error writing RTSTART or RTSTOP keyword!"); goto exitnow; } /****************** End of added statements */ /* average countrate and error */ status = DALattributePut(dalPtr,"SRCCNT",DAL_DOUBLE, (void*)(&avgRate), NULL, NULL, status); if (ISDC_OK!=status) { RILlogMessage(NULL,Error_1, "##759## (Write_LC) Error writing SRCCNT keyword!"); goto exitnow; } status = DALattributePut(dalPtr,"SRCCNTE",DAL_DOUBLE, (void*)(&avgRateErr), NULL, NULL, status); if (ISDC_OK!=status) { RILlogMessage(NULL,Error_1, "##760## (Write_LC) Error writing SRCCNTE keyword!"); goto exitnow; } if (logger->trace) traces(func_local, 260, logger); /* for folded lightcurves record also period and phase zero */ if (0 < nPhaseBins) { if (logger->trace) traces(func_local, 270, logger); status = DALattributePut(dalPtr,"PERIOD", DAL_DOUBLE, (void*)&timeStep, NULL, NULL, status); if (ISDC_OK!=status) { RILlogMessage(NULL,Error_1, "##761## (Write_LC) Error writing PERIOD keyword!"); goto exitnow; } status = DALattributePut(dalPtr,"PHASZERO", DAL_DOUBLE, (void*)&timeStart, NULL, NULL, status); if (ISDC_OK!=status) { RILlogMessage(NULL,Error_1, "##762## (Write_LC) Error writing PHASZERO keyword!"); goto exitnow; } } if (logger->trace) traces(func_local, 280, logger); /* data type used */ strcpy(typeName,"FULL"); status = DALattributePut(dalPtr, "DATAMODE", DAL_CHAR, (void*)&typeName, NULL, NULL, status); if (ISDC_OK!=status) { RILlogMessage(NULL, Error_1, "##763## (Write_LC) Error writing DATAMODE keyword!"); goto exitnow; } if (logger->NumTimeBins > 1) timeErrRel = timeErr / deltaT; else timeErrRel = 1.0; /* The relative uncertainty is not really known */ status = DALattributePut(dalPtr, "TIERRELA",DAL_DOUBLE, (void*)&timeErrRel, NULL, NULL, status); if (ISDC_OK!=status) { RILlogMessage(NULL,Error_1, "##764## (Write_LC) Error writing TIERRELA keyword!"); goto exitnow; } /* JEM-X events have an uncertainty of 1/8192 sec */ status = DALattributePut(dalPtr, "TIERABSO",DAL_DOUBLE, (void*)&timeErr, NULL, NULL, status); if (ISDC_OK!=status) { RILlogMessage(NULL,Error_1, "##765## (Write_LC) Error writing TIERABSO keyword!"); goto exitnow; } if (logger->trace) traces(func_local, 290, logger); /* Copy standard keywords from SWG */ status = DAL3GENattributeCopy(theSWG,dalPtr, "REVOL,SWID,SW_TYPE,SWBOUND,OBTSTART,OBTEND,TSTART,TSTOP",status); if (ISDC_OK!=status) { RILlogMessage(NULL,Warning_2, "##766## (Write_LC) Problems copying standard keywords from the SWG! status=%d",status); RILlogMessage(NULL,Log_2, "##767## (Write_LC) Resetting status to ISDC_OK."); status = ISDC_OK; } if(chatter > J_CHATTY_VERBOSE){ status = CommonStampObject(dalPtr,"Wrote lightcurve data",status); } if (status != ISDC_OK) { RILlogMessage(NULL,Error_2, "##768## Problem stamping lightcurve! status=%d", status); } status = DAL3GENindexUpdate(dalPtr,theSWG,status); if (status != ISDC_OK) { /********* * RILlogMessage(NULL,Error_2, "##769## Error updating lightcurve index! status=%d", status); **********/ RILlogMessage(NULL,Warning_1, "##769## Error updating lightcurve index! status=%d", status); RILlogMessage(NULL,Log_1, "##769## Reset status to ISDC_OK"); status = ISDC_OK; } if (logger->trace) traces(func_local, 300, logger); } /* end of loop over energy channels (begins line 211) */ } /* end of loop over sources (begins line 205) */ if (rateBuff != NULL) { DALfreeDataBuffer(rateBuff, ISDC_OK); } if (errBuff != NULL) { DALfreeDataBuffer(errBuff, ISDC_OK); } if (bRateBuff != NULL) { DALfreeDataBuffer(bRateBuff, ISDC_OK); } if (bErrBuff != NULL) { DALfreeDataBuffer(bErrBuff, ISDC_OK); } if (timeLC != NULL) { DALfreeDataBuffer(timeLC, ISDC_OK); } if (fracExp != NULL) { DALfreeDataBuffer(fracExp, ISDC_OK); } if (timeDel != NULL) { DALfreeDataBuffer(timeDel, ISDC_OK); } if (logger->trace) traces(func_local, 310, logger); slut: ; if (logger->trace) traces(func_local, 99, logger); /* function exit timing start */ TT_now = clock(); logger->func_times[func_local] += difftime(TT_now, logger->TT); logger->TT = TT_now; logger->func_calling_num = local_calling_num; /* function exit timing end */ return( status ); udone0: status = -99; exitnow: /* exitnow */ if (logger->trace) traces(func_local, 6000000-status, logger); goto slut; } /***************************************************************** * Name of source file: j_iir_write_srclres.c * Version of source file: 6.0.7 * 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. * 5.1.2 151106 Running version with LC generation * 5.1.11 160913 Update 'write_srcl_res' and 'work2d' to include 'pure burst' sources. * 5.1.15 160925 Update 'j_iir_write_srclres' to include all sources checked by j_ima_iros * 5.1.32 171101 Also copy RTSTART and RTSTOP from first shadowgram * 5.1.33 171206 Write RTSTART/STOP in sky_ima, srcl_res iros_lc files. Introduce logger->LCgtiREF * 5.1.34 171214 Correct flux error calculation for user sources (new parameter in call to final_sky) * 6.0.0 170112 Rename V5.1.34 to V6.0.0 * 6.0.0 180112 Introduces LC generation and burst detection * 6.0.7 180913 Modified log and reg files to include %11.6lf burst start and stop times, and add obsID * 6.0.8 180916 Block writing of burst images into sky_ima files. Assure output of light curves for user sources * 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, ee, i5, n, m, iSource, iS2, exnum=0; int itmp[1]; static int reord[MAX_NUM_PRESET_SRCS]; 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; double RTStart = 0.0; /* To be used for writing keyword (attribute) NL 2017-11-29 */ double RTStop = 0.0; /* To be used for writing keyword (attribute) NL 2017-11-29 */ 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 (ee = 0; ee < EE256; ee++ ) { e_min[ee] = 0.0; e_max[ee] = 0.0; flux[ee] = 0.0; flux_err[ee] = 0.0; } logger->N_SRCT = logger->N_SRC2; if (logger->N_SRCT < logger->N_SRC3) logger->N_SRCT = logger->N_SRC3; sprintf(logger->tmptxt, "write_srclres: ee_max: %2d, N_SRC2: %2d, N_SRC3: %2d, N_SRCT: %2d", backproj->ee_max, logger->N_SRC2, logger->N_SRC3, logger->N_SRCT); logger->logstat = logprint(logger, logger->tmptxt, 0); for( ee = 0; ee < backproj->ee_max; ee++ ) { e_min[ee] = sh->eval[ee][0]; e_max[ee] = sh->eval[ee][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; sprintf(logger->tmptxt, "##375A## Sources found. N_SRC2: %2d, N_SRC3: %2d, N_SRCT: %2d", logger->N_SRC2, logger->N_SRC3, logger->N_SRCT); logger->logstat = logprint(logger, logger->tmptxt, 0); if( logger->N_SRCT == 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 ); */ status = DAL3GENattributeCopy( sh->ptr[0], srclresPtr, "TELAPSE,OBTSTART,OBTEND,REVOL,SWID,SWBOUND,SW_TYPE," "ONTIME,DEADC,EXPOSURE,TSTART,TSTOP,RTSTART,RTSTOP", status ); if( status != ISDC_OK ) goto exittrace; /*************** Statements added by NL 2017-11-29 */ RTStart = logger->RTStart; status = DALattributePut( srclresPtr,"RTSTART",DAL_DOUBLE, (void*)&RTStart, NULL, NULL, status); if (ISDC_OK!=status) { RILlogMessage(NULL,Error_1, "##795## (Write_LC) Error writing RTSTART keyword!"); goto exittrace; } RTStop = logger->RTStop; status = DALattributePut( srclresPtr,"RTSTOP",DAL_DOUBLE, (void*)&RTStop, NULL, NULL, status); if (ISDC_OK!=status) { RILlogMessage(NULL,Error_1, "##795## (Write_LC) Error writing RTSTOP keyword!"); goto exittrace; } /****************** End of added statements */ } status = DALattributePutInt( srclresPtr, "EBIN_NUM", (long) sh->numShds, NULL, "Number of energy bins", 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_SRCT), status ); if( status != ISDC_OK ) goto exittrace; /* * LOOP over the found 'good' sources and the user requested sources */ /* Include all user defined sources and "pure burst sources" */ for( iSource = 0; iSource < logger->N_SRCT; iSource++ ) { n = logger->allsrc_ptr[iSource]; if (GOODSRC[n].bnum > 0) GOODSRC[n].preset |= 512; sprintf(logger->tmptxt, "iS: %2d, n: %2d, srclreY: bnum: %2d, detects: %4d, preset: %5d, signif: %5.1f, RA/dec: %7.3f %7.3f", iSource, n, GOODSRC[n].bnum, GOODSRC[n].detects, GOODSRC[n].preset, GOODSRC[n].LC_signif, GOODSRC[n].RA, GOODSRC[n].dec); logger->logstat = logprint(logger, logger->tmptxt, 0); } /* Make sure that significant sources are placed first in the srcl_res list */ n_src = 0; for( iSource = 0; iSource < logger->N_SRCT; iSource++ ) { n = logger->allsrc_ptr[iSource]; if (GOODSRC[n].preset < 1024) continue; reord[n_src++] = n; } for( iSource = 0; iSource < logger->N_SRCT; iSource++ ) { n = logger->allsrc_ptr[iSource]; if ((GOODSRC[n].preset >= 512) && (GOODSRC[n].preset < 1024)) {reord[n_src++] = n; continue;} } for( iSource = 0; iSource < logger->N_SRCT; iSource++ ) { n = logger->allsrc_ptr[iSource]; if (GOODSRC[n].preset >= 512 ) continue; reord[n_src++] = n; } for( iSource = 0; iSource < logger->N_SRCT; iSource++ ) { n_src = reord[iSource]; startRow = iSource + 1; numValues = 1; exnum = 0; ftmp[0] = GOODSRC[n_src].RA; status = DALtablePutColBins( srclresPtr, "RA_OBJ", 0, DAL_FLOAT, startRow, startRow, numValues, ftmp, status ); if( status != ISDC_OK ) {exnum = 1; 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 ) {exnum = 2; 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 ) {exnum = 3; goto exittrace;} itmp[0] = GOODSRC[n_src].preset; status = DALtablePutColBins( srclresPtr, "FLAG", 0, DAL_INT, startRow, startRow, numValues, itmp, status ); if( status != ISDC_OK ) {exnum = 4; 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 ) {exnum = 5; 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 ) {exnum = 6; 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 ) {exnum = 7; 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 ) {exnum = 8; 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 ) {exnum = 9; goto exittrace;} ftmp[0] = cosy_jmx; status = DALtablePutColBins( srclresPtr, "COSY_JMX", 0, DAL_FLOAT, startRow, startRow, numValues, ftmp, status ); if( status != ISDC_OK ) {exnum = 10; goto exittrace;} ftmp[0] = cosz_jmx; status = DALtablePutColBins( srclresPtr, "COSZ_JMX", 0, DAL_FLOAT, startRow, startRow, numValues, ftmp, status ); if( status != ISDC_OK ) {exnum = 11; 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 ) {exnum = 12; 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 ) {exnum = 13; goto exittrace;} if( status != ISDC_OK ) { RILlogMessage( NULL, Error_1, "##376## After ERR_RAD, status = %d", status ); {exnum = 14; 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 ) {exnum = 15; 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 ); {exnum = 16; 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]; check = 1.0; flux_err[eeuser] = GOODSRC[n_src].flux_err[eeuser]; if (fabs(flux[eeuser]) > 0.00001) check = flux_err[eeuser]; 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, "§srclres, src: %2ld, E: %2d, flx: %8.5f, flxerr: %6.5f, detsg[E]: %5.1f, errsolut: %6.3f, flxErrLast: %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, 0); 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 ) {exnum = 17; goto exittrace;} status = DALtablePutColBins( srclresPtr, "FLUX_ERR", 0, DAL_FLOAT, startRow, startRow, numValues, flux_err, status ); if( status != ISDC_OK ) {exnum = 18; goto exittrace;} detsig = sqrt(detsig0*detsig0 + detsig1*detsig1 + detsig2*detsig2); if (detsig < 0.01) detsig = GOODSRC[n_src].LC_signif; 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 ); {exnum = 19; goto exittrace;} } if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##381## Source # %3ld," " Flux flux_err detsig written", n_src); } sprintf(logger->tmptxt, "srclreZ: iS: %2d n_src: %2d, bnum: %2d, detects: %4d, preset: %5d, signif: %5.1f, RA/dec: %7.3f %7.3f", iSource, n_src, GOODSRC[n_src].bnum, GOODSRC[n_src].detects, GOODSRC[n_src].preset, detsig, GOODSRC[n_src].RA, GOODSRC[n_src].dec); logger->logstat = logprint(logger, logger->tmptxt, 0); } status = CommonStampObject( srclresPtr, NULL, status ); exittrace: sprintf(logger->tmptxt, "At exit from srclresQ, exnum: %2d, status: %d", exnum, status); logger->logstat = logprint(logger, logger->tmptxt, 0); 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: j_ima_iros_params.c * Version of source file: 6.0.0 * 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 * 5.1.2 151106 Running version with LC generation * 5.1.33 171206 Write RTSTART/STOP in sky_ima, srcl_res iros_lc files. Introduce logger->LCgtiREF * 5.1.34 171214 Correct flux error calculation for user sources (new parameter in call to final_sky) * 6.0.0 180112 Rename V5.1.34 to V6.0.0 * 6.0.0 180112 Introduces LC generation and burst detection * Type of element: Function * Part of package: j_ima_iros * Name: j_ima_iros_params * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ int j_ima_iros_params( dal_element **theSWG, Instrument *jemxNum, char *instMod, /* DOL of Instrument Model data */ /* char *bkgShdDOL, * DOL of empty field shadowgrams * * QaD solution to OC writing (2015-04-09/NJW) */ 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 outDOLs[DAL_MAX_STRING]; char strjemxNum[5], *charptr, *charptr2, tempstr[256]; int clobber = 0; /* Boolean - clean output index table ? */ int intJemxNum = 0; /* int; for PIL value retrieval */ int i, 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("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 = 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); if (logger->trace) traces(func_local, 10, logger); status = PILGetString("skyImagesOut", logger->skyImagesOut); sprintf(logger->tmptxt, "Raw skyImagesOut: %s ", logger->skyImagesOut); logger->logstat = logprint(logger, logger->tmptxt, 0); i = strlen(logger->skyImagesOut); if (logger->trace) traces(func_local, 1000+i, logger); itmp = 0; status = PILGetBool("makeLCs", &itmp); if ((strstr( logger->skyImagesOut, "LC" ) != NULL) || (itmp == 1)) logger->LC = 1; else logger->LC = 0; if (strstr( logger->skyImagesOut, "noLC" ) != NULL) logger->LC = 0; RILlogMessage( NULL, Log_0,"##49## In j_ima_iros_params, logger->LC = %d", logger->LC ); itmp = 0; status = PILGetBool("doBurstSearch", &itmp); if ((strstr( logger->skyImagesOut, "BUsrch" ) != NULL) || (itmp == 1)) logger->BUsrch = 1; else logger->BUsrch = 0; if (strstr( logger->skyImagesOut, "noBUsrch" ) != NULL) logger->BUsrch = 0; RILlogMessage( NULL, Log_0,"##49## In j_ima_iros_params, logger->BUsrch = %d", logger->BUsrch ); 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) */ logger->XRA = logger->Xdec = -1.0; logger->thrs = 7.0; logger->thrg = 6.0; logger->TIMEstep = 4.0; logger->LCgtiRef = 0.0; if(logger->LC) { status = PILGetReal("burstThreshSrc", &dtmp); logger->thrs = dtmp; status = PILGetReal("burstThreshDet", &dtmp); logger->thrg = dtmp; status = PILGetReal("timeStep", &dtmp); logger->TIMEstep = dtmp; status = PILGetReal("referenceTime", &dtmp); logger->LCgtiRef = dtmp; if ((charptr = strstr( logger->skyImagesOut, "XXRA")) != NULL) { strcpy(tempstr, charptr); if ((charptr2 = strstr( tempstr, ",")) == NULL) { logger->XRA = -1.0; goto LC6; } *charptr2 = 0; logger->XRA = atof(&(tempstr[4])); if (logger->XRA < 0.0) logger->XRA = -1.0; } else logger->XRA = -1.0; LC6: ; if ((charptr = strstr( logger->skyImagesOut, "XDEC")) != NULL) { strcpy(tempstr, charptr); if ((charptr2 = strstr( tempstr, ",")) == NULL) { logger->Xdec = -1.0; goto LC7; } *charptr2 = 0; logger->Xdec = atof(&(tempstr[4])); } else logger->Xdec = -1.0; LC7: ; } RILlogMessage( NULL, Log_0, "zYx ##49## In jiir_params, thrs: %5.1f, thrg: %5.1f, Tstep: %10.6f, LCgtiRef: %10.3f, XRA/dec: %7.3f %7.3f\n", logger->thrs, logger->thrg, logger->TIMEstep, logger->LCgtiRef, logger->XRA, logger->Xdec); if (strstr( logger->skyImagesOut, "TRACE")) {logger->trace = 1; logger->i5 = 0;} if (strstr( logger->skyImagesOut, "DEVEL")) {logger->develop = 1;} status = PILGetBool("detImagesOut", &itmp ); logger->detImagesOut = itmp; status = PILGetBool("userImagesOut", &itmp ); logger->userImagesOut = itmp; status = PILGetBool("burstImagesOut", &itmp ); logger->burstImagesOut = itmp; if (strstr( logger->skyImagesOut, "BURSTIMA")) logger->burstImagesOut = 1; 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,"##50## just before logger->trace == 0 : value = %lu", logger->trace ); if (logger->trace == 0) { status = PILGetBool("useTrace", &itmp); logger->trace = itmp; RILlogMessage( NULL, Log_0,"##51## just after logger->trace == 0 : value = %lu", logger->trace ); if( itmp ) { trace = fopen("imatrace.txt", "a"); fprintf(trace, " main %d\n", 0); if (trace != NULL) fclose(trace); trace = NULL; } } status = PILGetString("tracestring", logger->tracestring ); RILlogMessage( NULL, Log_0,"##52## 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" ); } strcpy( outDOLs, "skyRes,listRes" ); ///// LP ///// if( logger->LC ) ///strcat( outDOLs, ",bkgShdDOL" ); strcat( outDOLs, ",lcnewRes" ); ///// LP ///// RILlogMessage( NULL, Log_0,"##521## outDOLs: %s. logger->LC = %d", outDOLs, logger->LC ); 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, "##53## CommonPreparePARsStrings returned: %d", status); /* return( status); */ } RILlogMessage(NULL,Log_0,"##54## 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: 6.0.0 * 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 * 5.1.2 151106 Running version with LC generation * 5.1.33 171206 Write RTSTART/STOP in sky_ima, srcl_res iros_lc files. Introduce logger->LCgtiREF * 6.0.0 180112 Introduces LC generation and burst detection * 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, * QaD solution */ 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 bkgShdDOL_dummy[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, i5 = 0; int *catFlag = NULL; int *CLASS_OBJcat = NULL; int laop = 0, 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; double temp1 = 0.0, temp2 = 0.0; 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; i5 = logger->i5; /* * 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, "##55## 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,"##56## 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, "##57## 0 Control data file: %s ", resultxt); /* logger->logstat = logprint(logger, logger->tmptxt, 4); */ if( chatter > J_CHATTY_NORMAL ) RILlogMessage(NULL,Log_0,"##58## j_ima_iros_prepare"); if( chatter > J_CHATTY_NORMAL ) RILlogMessage(NULL,Log_0,"##59## 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,"##60## 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, "##61## %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, logger, chatter, status ); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_0, "##62## %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,"##63## j_ima_iros_prepare"); if( chatter > J_CHATTY_NORMAL ) { RILlogMessage( NULL, Log_0,"##64## 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,"##65## 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, "##66## 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, "##67## 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, "##68## status = %d", status); } if( status != ISDC_OK ) goto exittrace; if( chatter > J_CHATTY_NORMAL ) { RILlogMessage( NULL, Log_0,"##69## 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,"##70## %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, "##71## 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,"##72## 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,"##73## 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,"##74## 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,"##75## status = %d", status ); if (status != ISDC_OK ) { sprintf(logger->tmptxt, "##76## 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,"##77## status = %d", status ); if (status != ISDC_OK ) { sprintf(logger->tmptxt, "##78## Bad or missing alignment.dat, exiting!"); logger->logstat = logprint(logger, logger->tmptxt, 7); goto exittrace; } /* Verify time_slope_data */ sprintf(logger->tmptxt, "##79## 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, 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; logger->pix2mm = backproj->pix2mm; backproj->pix2rad = backproj->pix2mm / jmx_id->mask_height; if( chatter > J_CHATTY_NORMAL ) RILlogMessage( NULL, Log_0,"##80## 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( "##81##", jmx_id, chatter, status ); } sprintf(logger->tmptxt, "##82## 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, 0); /* 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,"##83## 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, avg_gain-UB: %5.3f, avg_gain-sh: %5.3f", i, c_sum, USERBIN[i].avg_gain, sh->avg_gain); logger->logstat = logprint(logger, logger->tmptxt, i5); } if (sh->numShds > EE256) { sprintf(logger->tmptxt, "##84## 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, "##85## %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, * "##86## 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, "##87## itmp = %d drl_par = %f", itmp, logger->drl_par[itmp]); RILlogMessage( NULL, Log_0, "##88## E%d (%4.1f keV) has det_rad_lim = %d mm", i, e_mean, logger->det_rad_lim[i] ); RILlogMessage( NULL, Log_0, "##89## itmp = %d ima_sigma_table = %f", itmp, ima_sigma_table[itmp]); RILlogMessage( NULL, Log_0, "##90## 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_dummy, /* 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( "##91##", 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( "##92##", backproj, sh, chatter, status ); } if (status != ISDC_OK) { sprintf(logger->tmptxt, "##93## ref_file_name: %s, jemx: %1d, orbit: %3d", logger->ref_file_name, jemx+1, backproj->aux_orbit); /* sprintf(logger->tmptxt, "##94## 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, "##95## Bad status on return from backsky_init"); logger->logstat = logprint(logger, logger->error_text, 7); goto exittrace; } 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, "##96## %d: After j_iir_get_radec_init", status ); goto exittrace; } if( chatter > J_CHATTY_VERBOSE ) { RILlogMessage( NULL, Log_0, "##97## RAdec: %f %f", p_RA, p_dec); RILlogMessage( NULL, Log_0, "##98## posang: %f", p_posang); } if( chatter > J_CHATTY_VERY_VERBOSE ) { status = snapshot1( "##99##", 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; /* ------------------------------------------------------------ * 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, "##100## %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, "##101## %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, "##102## %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_IIRCATSRCRLIM 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); sprintf(logger->tmptxt, "QZQZ %3d class: %5d, Err_Rad: %7.5f, RA/dec: %8.4f %8.4f, flag: %2d, adist %4.1f, limit: %4.1f", (int)(loop), CLASS_OBJcat[loop], ERR_OBJcat[loop], RA_OBJcat[loop], DEC_OBJcat[loop], catFlag[loop], adist, J_IIR_CATSRCRLIM); logger->logstat = logprint(logger, logger->tmptxt, i5); if ((catFlag[loop] & 1) == 1) { if ( adist < J_IIR_CATSRCRLIM ) { /* Extract this one */ if ((num_flag3 >= 3) && (catFlag[loop] & 2)) goto skip_flag3; /* don't accept more than 3 flag-3 srcs */ /* if (CLASS_OBJcat[loop] == 32768) goto skip_flag3; */ /* TEST NL20150528: reject special sources */ if (catFlag[loop] & 2) 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, "QZQA %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, i5); 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, "QZQB %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, i5); } } } } } } /* * Move the low priority sources up adjacent to the high 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, i5); 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]; laop = backproj->preset_src; sprintf(logger->tmptxt, "QZQC %3d class: %5d, Err_Rad: %7.5f, RA/dec: %8.4f %8.4f, flag: %2d, src_id: %3d", (int)(laop), CLASS_OBJcat[laop], ERR_OBJcat[laop], RA_OBJcat[laop], DEC_OBJcat[laop], catFlag[laop], backproj->preset_src_id[backproj->preset_src+1]); logger->logstat = logprint(logger, logger->tmptxt, i5); backproj->preset_src++; } } sprintf(logger->tmptxt, "prepare: after selection: j_ima_iros catalog entries: %3d", backproj->preset_src); logger->logstat = logprint(logger, logger->tmptxt, i5); } else { RILlogMessage( NULL, Warning_0, "##103## %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, "##104## 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,"##105## gtiStartIJD = %13.8f, OBT = %20llu", gtiStartIJD[i], gtiStartOBT[i]); RILlogMessage( NULL, Log_0,"##106## gtiEndIJD = %13.8f, OBT = %20llu", gtiEndIJD[i], gtiEndOBT[i]); } } else { RILlogMessage( NULL, Log_0,"##107## 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,"##108## GTI_IJDstart = %13.8f, OBT = %20llu", auxdata->GTI_IJDstart[i], auxdata->GTI_OBTstart[i]); RILlogMessage( NULL, Log_0,"##109## GTI_IJDstop = %13.8f, OBT = %20llu", auxdata->GTI_IJDstop[i], auxdata->GTI_OBTstop[i]); } } /* END TEST TEST */ /* Get 'Requested timeStart/Stop' and convert into IJD NLNLNL 20171122 */ logger->TSTART = auxdata->GTI_IJDstart[0]; logger->TSTOP = auxdata->GTI_IJDstop[auxdata->n_GTI-1]; status = DALattributeGetReal( sh->ptr[0], "RTSTART", &temp1, NULL, NULL, status); status = DALattributeGetReal( sh->ptr[0], "RTSTOP ", &temp2, NULL, NULL, status); if (temp1 > 0.0) logger->RTStart = temp1; if (temp2 > 0.0) logger->RTStop = temp2; if (temp1 <= -1.0) logger->RTStart = logger->TSTART; if (temp2 <= -1.0) logger->RTStop = logger->TSTOP; if ((temp1<0.0) && (temp1>-1.0)) logger->RTStart = logger->TSTART - (logger->TSTOP - logger->TSTART) * temp1; if ((temp2<0.0) && (temp2>-1.0)) logger->RTStop = logger->TSTART - (logger->TSTOP - logger->TSTART) * temp2; sprintf(logger->tmptxt, "# timeStart: %12.7lf, timeStop: %12.7lf, Requested Start/Stop: %12.7lf %12.7lf, indata: %12.7lf %12.7lf", logger->TSTART, logger->TSTOP, logger->RTStart, logger->RTStop, temp1, temp2); logger->logstat = logprint(logger, logger->tmptxt, 0); status = j_iir_get_gain( theSWG, jemxNum, auxdata, logger, chatter, status); if( status != ISDC_OK ) { RILlogMessage( NULL, Error_0,"##110## %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,"##111## IJD = %13.8f, gain = %7.3f", auxdata->scpTimes[i], auxdata->scpGain[i]); } } else { RILlogMessage( NULL, Log_0,"##112## 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,"##113## %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,"##114## IJD = %13.8f, grey = %3i", auxdata->greyTimes[i], auxdata->greyValues[i]); } } else { RILlogMessage( NULL, Log_0,"##115## 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,"##116## %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,"##117## 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,"##118## 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,"##119## %d: After j_iir_get_events", status); goto exittrace; } logger->numEvents = *numEvents; 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, i5); 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 ); } /* ************************************************************* */ /****************************************************************** * * Version of source file: 6.0.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 * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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_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; loopLCcor[loop] = testval_LCcor[loop]; } /*------------------------------------------------------------------------ * CFLC origin (CFLC data structure) *------------------------------------------------------------------------ */ /* * Get the cflc_origin tables */ strcpy( structName, jemxStr); strcat( structName, "-CFLC-MOD" ); if( chatter >= 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, Warning_0, "##241## %d : Could not find extension %s", status, structName); status = ISDC_OK; goto skip_CFLC; } 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 **) &cflc_origin, 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, CFLC_ORIGIN, ENERGY_LO, and ENERGY_HI * ------------------------------------------------------------------------ */ status = DALtableGetCol( extPtr, "TIMESLOPE", 0, &dataType, &nValuesRead, (void *) time_slope, status); status = DALtableGetCol( extPtr, "CFLC_ORIGIN", 0, &dataType, &nValuesRead, (void *) cflc_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,CFLC,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->LCcor[loop] = cflc_origin[loop]; printf("CFLC LCcor values: chan: %2d, read: %5.2d, chk: %5.2d \n", loop, jmx_id->LCcor[loop], testval_LCcor[loop]); } /* * Clean up local memory allocations */ if ((void*) cflc_origin != NULL) status = DALfreeDataBuffer( (void *) cflc_origin, status ); skip_CFLC: status = DALfreeDataBuffer( (void *) linpha, status ); status = DALfreeDataBuffer( (void *) elec_eff, status ); status = DALfreeDataBuffer( (void *) time_slope, status ); status = DALfreeDataBuffer( (void *) energy_lo, status ); status = DALfreeDataBuffer( (void *) energy_hi, status ); status = DALfreeDataBuffer( (void *) curtain, status ); status = DALfreeDataBuffer( (void *) eeff_origin, status ); return status; } /***************************************************************** * Name of source file: j_lpf_get_jemx_hk.c * Version of source file: 6.0.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 * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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 */ struct log_con *logger, 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; logger->numHKvalues = numValues; for(loop=0;loopHWcounts[(int)(loop)%1024] = (float) jbuffer[loop]; } jmx_id->JMX_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 ); } /***************************************************************** * Name of source file: j_lpf_get_sc_hk.c * Version of source file: 6.0.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 * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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_spag_mod.c * Version of source file: 6.0.0 * 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: Read the IMOD array: SPAG and FULB and transfer to * struct imod_rmf (spagf) * Origin date: 060720 * Update history: 1.0.0 071102 Copied from j_isg_get_spag_mod.c * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * Type of element: Function * Part of package: jmx_lib_pif * Name: j_lpf_get_spag_mod *****************************************************************/ int j_lpf_get_spag_mod( Instrument jemxNum, dal_element *ptrIMOD, struct instr_data *jmx_id, int chatter, int status) { char structName[DS_NAME_SIZE]; char jemxStr[5]; int i = 0; int j = 0; int k = 0; long offset = 0; long dimAxes[3]; long buffersize = 0; float *buffer = NULL; float x[16]; /* return immediately if in error condition when called */ if( status != ISDC_OK ) return( status ); /* * Allocate memory for temporary storage * The factor of 2 because there are two layers in the array */ buffersize = J_NUM_X_PIXELS * J_NUM_Y_PIXELS * 2; RILlogMessage( NULL, Log_0, "##253a## buffersize = %ld", buffersize ); buffer = (float *) malloc( buffersize * sizeof(float) ); if( buffer == NULL ) { status = J_ERROR_CODE_START + J_LIB_PIF_ERR + J_LPF_MALLOC_ERR; RILlogMessage( NULL, Error_1,"##253## Memory allocation failed!"); return( status ); } if( jemxNum == JMX1 ) strcpy( jemxStr, "JMX1" ); else strcpy( jemxStr, "JMX2" ); /************************************************************************* READING DATA STRUCTURE JMXi-SPAG-MOD **************************************************************************/ /* * Create structure name of JEMX instr. data : */ strcpy( structName, jemxStr ); strcat( structName, J_SPATGAIN_DS); if( chatter > 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_XYvsE.c * Version of source file: 6.0.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 * 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 * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection *****************************************************************/ int j_lpf_get_XYvsE( Instrument jemxNum, dal_element *imodPtr, struct instr_data *jmx_id, int chatter, int status ) { char structName[DS_NAME_SIZE]; char jemxStr[5]; int jemx = 0; /* NB: JEMX number 0 or 1 */ long numValues = 0; long loop = 0; long loopi = 0; long loopj = 0; float fbuffer[16]; float ffbuffer[16][16]; double dtmp = 0.0; dal_element *ptr = NULL; dal_dataType dalType; /* assume that jemxNum has already been checked for validity */ if( jemxNum == JMX1 ) { jemx = 0; strcpy( jemxStr, "JMX1" ); } else { jemx = 1; strcpy( jemxStr, "JMX2" ); } strcpy( structName, jemxStr ); strcat( structName, "-COLL-MOD" ); status = DALobjectFindElement( imodPtr, structName, &ptr, status ); status = DALattributeGetReal( ptr, "SIGMACX", &dtmp, NULL, NULL, status ); jmx_id->sigma_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; } /***************************************************************** * Name of source file: j_lpf_lilipol.c * Version of source file: 6.0.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) * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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 ); } /* ************************************************************************************************ */ /* */ /* 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 numberOfFitFunctions, int allsrc, struct backpro *backproj, struct log_con *logger, int status ) { int i, j, k, N[256], imax = 0, jmax = 0, i5 = 5; 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, hilim_factor=1.0; 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 */ sprintf(logger->tmptxt, "At entry: YYY%02d %02d", numberOfFitFunctions, allsrc); logger->logstat = logprint(logger, logger->tmptxt, i5); 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[allsrc] = backproj->pif_bpix[allsrc] = 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) */ k = 0; for (j=0; jpif_maps[allsrc][j] > 0.0) k++; if (backproj->pif_maps[allsrc][j] >= 0.0) { i = (int)(backproj->pif_maps[allsrc][j] * looplim); if (i < looplim) N[i]++; } backproj->pif_s_pickmap[allsrc][j] = backproj->pif_b_pickmap[allsrc][j] = 0; backproj->pif_s_pickmap[0][j] = backproj->pif_b_pickmap[0][j] = 0; } sprintf(logger->tmptxt, "After j-loop, pixels with positive pif_map values %6d", k); logger->logstat = logprint(logger, logger->tmptxt, i5); if (k == 0) {status = -1; goto exittrace;} 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 signal to background 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 %02d %4d S_N: %7.2f, lim: %2d / %3d, cnt: %5d / %5d / %5d S_X: %7.2f, lim: %2d / %3d, cnt: %5d / %5d / %5d", numberOfFitFunctions, allsrc, 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[allsrc] = (float)(Philimbest) / (float)(looplim); backproj->pif_lolim[allsrc] = (float)(Plolimbest) / (float)(looplim); if ((allsrc > 0) && (allsrc < 90)) hilim_factor = 1.0; sprintf(logger->tmptxt, "Apif_limits#. pif_lolim: %5.3f, pif_hilim: %5.3f, hilim_factor: %4.2f", backproj->pif_lolim[allsrc], backproj->pif_hilim[allsrc], hilim_factor); logger->logstat = logprint(logger, logger->tmptxt, i5); for (j=0; jpif_maps[allsrc][j] >= backproj->pif_hilim[allsrc]*hilim_factor) { backproj->pif_s_pickmap[allsrc][j] = 1; backproj->pif_spix[allsrc]++; } if ((backproj->pif_maps[allsrc][j] >= 0.0) && (backproj->pif_maps[allsrc][j] <= backproj->pif_lolim[allsrc])) { backproj->pif_b_pickmap[allsrc][j] = 1; backproj->pif_bpix[allsrc]++; } } sprintf(logger->tmptxt, "Apif_limits# src: %2d, source/background pixels: %6d %6d", allsrc, backproj->pif_spix[allsrc], backproj->pif_bpix[allsrc]); logger->logstat = logprint(logger, logger->tmptxt, i5); /* gnufil = fopen("pifplot.gnu", "at"); imax = (float)(looplim) * backproj->pif_hilim[allsrc]; jmax = (float)(looplim) * backproj->pif_lolim[allsrc]; 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; } /***************************************************************************** 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); } 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: 6.0.0 * 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 * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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: LCcorrelation.c * Version of source file: 6.0.0 * 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@space.dtu.dk * Purpose: Calculate correlation coefficient * Origin date: 161209 * Update history: 1.0.0 041130 First version * 5.1.33 171114 Correct missing "function exit timing start" in this file (LCcorelation) * 6.0.0 180112 Introduces LC generation and burst detection * 6.0.9 180925 Reinstate writing of burst images in sky_ima files. * Type of element: Function * Part of package: j_ima_iros * Name: LCcorrelation * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ /* QQQQQQ */ int LCcorrelation( int eeuser, timeslices *Tslices, struct log_con *logger, int start_chan, int end_chan, float *correl, int status ) { int i, j, k, i5, ital, istart, iend, length; float tal, m0, m1, m2, rmsG, rmsS, rmsfact, avG, avS, avGl, avSl, dcorrel; 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], "LCcorrelation"); 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 */ /* QQQQQQ */ if (logger->trace) traces(func_local, 0, logger); i5 = logger->i5; /* NL 20120122 */ length = end_chan - start_chan + 1; if (length < 3) length = 3; istart = start_chan - length; iend = end_chan + length; if (istart < 0) istart = 0; if (iend > logger->NumTimeBins) iend = logger->NumTimeBins; length = iend - istart; if (logger->trace) traces(func_local, 5, logger); if (logger->trace) traces(func_local, 100000+logger->NumTimeBins, logger); if (logger->trace) traces(func_local, 200000+eeuser, logger); /* get standard deviation for distribution 1 */ m0 = m1 = m2 = 0.0; for (i=0; iNumTimeBins; i++) { if (logger->trace) traces(func_local, 1000000+i*1000000+(int)(Tslices[i].dontUse&1), logger); if (Tslices[i].dontUse&1 == 1) continue; m0 += 1.0; if (logger->trace) traces(func_local, 1000000+i*1000000+(int)(m0), logger); ital = 0; if (Tslices[i].GlobalLC[eeuser%MAX_LC_EBIN] > 0.0) ital = 200000; if (Tslices[i].GlobalLC[eeuser%MAX_LC_EBIN] < 0.0) ital = 100000; if (logger->trace) traces(func_local, 1000000+i*1000000+ital+(int)(Tslices[i].GlobalLC[eeuser%MAX_LC_EBIN]*1000.0), logger); m1 += Tslices[i].GlobalLC[eeuser%MAX_LC_EBIN]; if (logger->trace) traces(func_local, 1000000+i*1000000+(int)(m1), logger); m2 += Tslices[i].GlobalLC[eeuser%MAX_LC_EBIN] * Tslices[i].GlobalLC[eeuser%MAX_LC_EBIN]; if (logger->trace) traces(func_local, 1000000+i*1000000+(int)(m2), logger); } sprintf(logger->tmptxt, "E%1d After summation of GlobalLC: m0/m1/m2: %f %f %f, time bins: %d, useable: %f", eeuser%MAX_LC_EBIN, m0, m1, m2, logger->NumTimeBins, m0); logger->logstat = logprint(logger, logger->tmptxt, 0); if (logger->trace) traces(func_local, 2, logger); if (m0 > 3.0) { avG = m1 / m0; tal = m2 - avG * avG; if (tal > 0.0) rmsG = sqrt(tal); else rmsG = 1.0; } else {avG = 0.0; rmsG = 1.0;} if (logger->trace) traces(func_local, 4, logger); /* get standard deviation for distribution 2 */ m0 = m1 = m2 = 0.0; for (i=0; iNumTimeBins; i++) { if (Tslices[i].dontUse&1 == 1) continue; m0 += 1.0; m1 += Tslices[i].wflux[1]; m2 += Tslices[i].wflux[1] * Tslices[i].wflux[1]; } if (m0 > 3.0) { avS = m1 / m0; if ((m2 - avS*avS) > 0.0) rmsS = sqrt(m2 - avS*avS); else rmsS = 1.0; } else {avS = 0.0; rmsS = 1.0;} if (logger->trace) traces(func_local, 6, logger); rmsfact = sqrt(rmsG * rmsS); /* get mean value over interval of interest for distribution 1 */ m0 = m1 = m2 = 0.0; for (i=istart; i 3.0) { avGl = m1 / m0; } else avGl = 0.0; /* get mean value over interval of interest for distribution 2 */ m0 = m1 = m2 = 0.0; for (i=istart; i 3.0) { avSl = m1 / m0; } else avSl = 0.0; *correl = 0.0; for (i=0; itmptxt, "CBin: %3d, Glocal: %6.3f, Slocal: %6.3f, Prod: %6.3f, rmsfact: %5.3f, correl: %6.3f", i, (Tslices[j].GlobalLC[eeuser] - avGl), (Tslices[j].wflux[1] - avSl), dcorrel, rmsfact, *correl); logger->logstat = logprint(logger, logger->tmptxt, 0); } if (rmsfact > 0.0) *correl /= rmsfact; else *correl = 0.0; /* NLNLNL 20180927 */ 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); logger->func_write[logger->func_calling_num]++; } break; case 6: RILlogMessage(NULL, Warning_0, "zYx %s", text); logger->func_write[logger->func_calling_num]++; 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); logger->func_write[logger->func_calling_num]++; break; default: break; } return(0); } /***************************************************************** * Name of source file: mask_test.c * Version of source file: 6.0.0 * 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 * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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); } /* * 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); } /* **************************************************************** * Name of source file: off_axis_transmisImag.c * Version of source file: 6.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: 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 * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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: off_axis_transmission.c * Version of source file: 6.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: 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 * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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: outfit_isdc.c * Version of source file: 6.0.0 * 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 * 5.1.2 151106 Running version with LC generation * 5.1.33 171206 Write RTSTART/STOP in sky_ima, srcl_res iros_lc files. Introduce logger->LCgtiREF * 6.0.0 180112 Introduces LC generation and burst detection * 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, dimen = 0, i=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); logger->amin = 1.0e10; logger->amax = -1.0e10; logger->mnan = 0; 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; dimen = f_struc->naxis1 * f_struc->naxis2; for (i=0; imnan++; continue;} if (logger->amin > image[i]) logger->amin = image[i]; if (logger->amax < image[i]) logger->amax = image[i]; } 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"); kwdsSetReal( &kwds, "RTSTART", f_struc->RTStart, "[IJD] Requested Start Time"); /* NLNLNL 20171122 */ kwdsSetReal( &kwds, "RTSTOP", f_struc->RTStop, "[IJD] Requested Stop Time"); /* NLNLNL 20171122 */ 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); } if (logger->burst_image == 0) kwdsSetChar( &kwds, "IMACASE", "IROS001", "Image generation specification"); else kwdsSetChar( &kwds, "IMACASE", "IROS_BURST", "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 ) { /* if(logger->burst_image == 0) 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 ); else */ status = DAL3GENattributeCopy( sh->ptr[ee], ptrElmnt, "CHANMIN,CHANMAX,CHANTYPE,TELAPSE,OBTSTART," "OBTEND,SHDIDEN,EVNTYPES," "SWID,SW_TYPE,SWBOUND," "ONTIME,DEADC," "E_MEAN,TSTART,TSTOP", status ); /* NLNLNL 20170920 */ 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); } /* 5.1.32 170906 Introduce 'typedef image_cor' and malloc of this structure */ /* ************************************************************************************ */ int paltani_eval(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(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: peaktransfer.c * Version of source file: 6.0.0 * 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. * 5.1.2 151106 Running version with LC generation * 5.1.23 161220 Correct peaktransfer & final_sky. Endless loop in peaktransfer for sources near edge of FOV * 6.0.0 180112 Introduces LC generation and burst detection * 6.0.9 180925 Reinstate writing of burst images in sky_ima files. * 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 imgpeak[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, 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 ixy_max, qxy, Y, Y1, qoff[9]; static int isrc=0; double 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]; i5 = logger->i5; iix = x * 4.0; iiy = y * 4.0; ix = x; iy = y; if ((ix < 4) || (ix > 506) || (iy < 4) || (iy > 506)) goto near_edge; ydim = backproj->sky_ydim; /* sprintf(logger->tmptxt, "sky_r[ixy] / backproj->fitsimage[%1d][0][ixy]", ee); logger->logstat = logprint(logger, logger-> tmptxt, i5); for (i=iy+3; i>=iy-3; i--) { i = (i + backproj->sky_ydim) % backproj->sky_ydim; j = (ix - 3 + backproj->sky_ydim) % backproj->sky_ydim; ixy = j * backproj->sky_ydim + i; sprintf(logger->tmptxt, "R %5d", ixy); for (j=ix-3; j<=ix+3; j++) { j = (j + backproj->sky_ydim) % backproj->sky_ydim; ixy = j * backproj->sky_ydim + i; sprintf(logger->tmptxt2, "%2d %2d %7.2f ", j, i, sky_r[ixy]); 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, 3, logger); for (i=iy+3; i>=iy-3; i--) { i = (i + backproj->sky_ydim) % backproj->sky_ydim; j = (ix - 3 + backproj->sky_ydim) % backproj->sky_ydim; ixy = j * backproj->sky_ydim + i; sprintf(logger->tmptxt, "F %5d", ixy); for (j=ix-3; j<=ix+3; j++) { j = (j + backproj->sky_ydim) % backproj->sky_ydim; ixy = j * backproj->sky_ydim + i; sprintf(logger->tmptxt2, "%2d %2d %7.2f ", j, i, backproj->fitsimage[ee][0][ixy]); 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, 6, logger); if ((iix%4) == 3) ix++; if ((iiy%4) == 3) iy++; ixy = ix * ydim + iy; /* index for peak center */ sprintf(logger->tmptxt, "peaktransf inp: isrc: %2d, x/y: %6.2f %6.2f, iix/y: %5d %5d, ix/y: %4d %4d, ixy: %6d", isrc, x, y, iix, iiy, ix, iy, ixy); logger->logstat = logprint(logger, logger-> tmptxt, i5); if (logger->trace) traces(func_local, 1000+isrc, logger); 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; sprintf(logger->tmptxt, "peaktransfer qoff: %3d %3d %3d %3d %3d %3d %3d %3d %3d", qoff[0], qoff[1], qoff[2], qoff[3], qoff[4], qoff[5], qoff[6], qoff[7], qoff[8]); logger->logstat = logprint(logger, logger-> tmptxt, i5); sprintf(logger->tmptxt, "4blks; "); 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]) {pmax[0] = qq; ixy_max = qxy;} sprintf(logger->tmptxt2, "%1d %4d %7.2f ", i, qxy, qq); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); if ((i%3) == 2) logger->logstat = logprint(logger, logger-> tmptxt, i5); } 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]; if (logger->trace) traces(func_local, 20, logger); 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; } sprintf(logger->tmptxt, "peaktransfer pkcnt0/1: %7.2f %7.2f, ixy: %4d, ima_max: %7.2f, ixy_trans: %4d", peakcount[0], peakcount[1], ixy, ima_max, ixy_trans); logger->logstat = logprint(logger, logger-> tmptxt, i5); for (i=3; i>=-3; i--) { for (j=-3; j<=3; j++) { jj = ixy_trans + j * ydim + i; imgpeak[jj] = sky_r[jj]; /* save peak counts into 'imgpeak'-image */ } } if (logger->trace) traces(func_local, 30, logger); 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.2f %7.2f, 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++; } } } if (logger->trace) traces(func_local, 40, logger); 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 (logger->trace) traces(func_local, 50, logger); if (m0 < 9) { if (logger->trace) traces(func_local, 51, logger); sprintf(logger->tmptxt, "Too few reference fields available for detsig determination (m0/m1/m2: %7.2f %7.2f %7.2f )", m0, m1, m2); logger->logstat = logprint(logger, logger-> tmptxt, i5); *detsig = 0.0; if (m0 > 0) *mean_bkg = (float)(m1) / (float)(m0); else *mean_bkg = 0.0; } else { if (logger->trace) traces(func_local, 52, logger); 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 */ if (m2 > 0.0) detsig[0] = peakcount[0] / m2; else detsig[0] = 1.0; /* NLNLNL 20180925 */ mean_bkg[0] = m1; if (logger->trace) traces(func_local, 53, logger); if (mb0 > 0.0) { /* NLNLNL 20180925 */ if (logger->trace) traces(func_local, 54, logger); mb1 /= mb0; /* mean background in raw image */ mb2 /= mb0; mb2 = sqrt(mb2 - mb1*mb1); /* estimated sigma in raw image */ } else { mb0 = 0.0; mb1 = 0.0; mb2 = 0.0; } /* NLNLNL 20180925 */ if (logger->trace) traces(func_local, 55, logger); /* 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; if (logger->trace) traces(func_local, 56, logger); mean_bkg[1] = mb1; if (logger->peak_last == 1) { sprintf(logger->tmptxt, " ##src %2d clean bkg-m0/m1/m2: %7.2f %7.2f %7.2f, peak: %7.2f, detsig: %6.2f, Poisson: %7.2f", (isrc-1)/2, m0, m1, m2, peakcount[0], detsig[0], sqrt(peakcount[1])); logger->logstat = logprint(logger, logger-> tmptxt, i5); sprintf(logger->tmptxt, " ##src %2d raw bkg-m0/m1/m2: %7.2f %7.2f %7.2f, peak: %7.2f, detsig: %6.2f, Poisson: %7.2f", (isrc-1)/2, mb0, mb1, mb2, peakcount[1], detsig[1], sqrt(peakcount[1])); logger->logstat = logprint(logger, logger-> tmptxt, i5); } if (logger->trace) traces(func_local, 57, logger); } /* 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, 60, logger); eksit: ; 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]); near_edge: ; peakcount[0] = -1; goto eksit; } /* **************************************************************************************** */ /***************************************************************** * Name of source file: pixelfold.c * Version of source file: 6.0.0 * 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. * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * Type of element: Function * Part of package: j_ima_iros * Name: pixelfold * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ int pixelfold( float det[], int eeuser, float shadw[detdim], struct shadowgrams *sh, 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, ee, 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); i5 = logger->i5; jemx = jmx_id->jmx_unit; ee = eeuser; if (ee > backproj->ee_basic) ee = backproj->ee_basic; 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: eeuser: %2d, sum_in: %10.4lf, loss: %10.4lf, sum_out: %10.4lf, average valsum: %6.4lf", eeuser, sum1, loss1, sum2, valsum/valnum); logger->logstat = logprint(logger, logger->tmptxt, i5); status = 0; exittrace: if (logger->trace) traces(func_local, 1000000+(int)(sum2), 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 */ sh->totcnt[eeuser] = sum2; return(status); } /* ************************************************************************************ */ /* **************************************************************** * Name of source file: radcor.c * Version of source file: 6.0.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@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. * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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: rmscalc.c * Version of source file: 6.0.0 * 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 * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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); } /* *********************************************************************************** */ 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); } 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); } 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, i5; i5 = logger->i5; 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, i5); 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, i5); fprintf(sd, "%s\n", logger->tmptxt); } return(0); } /* **************************************************************** * Name of source file: set_shdg_text.c * Version of source file: 6.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@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. * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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 = 5, 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]; } } } if (logger->trace) traces(func_local, 99, logger); return(r_sum); } /***************************************************************** * Name of source file: shadowfit.c * Version of source file: 6.0.0 * 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 * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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 = 5, Nsrc; int mk1, mk2, q, pixels = 0, index, badcount, negat=0, allsrc; 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: %6.0lf, active pix: %5.0lf, cnts/pix: %5.3lf, rms: %5.3lf", jemx+1, ee, m1[n_source], m0[n_source], mean[ee], rms[n_source]); sprintf(logger->tmptxt2, " norm_chk: %4.2f %7.1f", (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); logger->logstat = logprint(logger, logger->tmptxt, i5); 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 (allsrc=0; allsrc 1) && (allsrc == last)) loclast = last; if (((srcx[allsrc] > 0.0) && (srcx[allsrc] < backproj->sky_xdim) && (srcy[allsrc] > 0.0) && (srcy[allsrc] < backproj->sky_ydim)) || (allsrc < 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, allsrc, srcx[allsrc], allsrc, srcy[allsrc]); negat = -2; status = J_ERROR_CODE_START+J_IMA_IROS_ERR+J_IIR_IMFITERR2; goto return_negative; } if ((allsrc == 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(allsrc, 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[allsrc][j] >= 0.0) sum += backproj->pifeff_maps[allsrc][j]; if (sum == 0.0) { sprintf(logger->error_text, "##299## In shadowfit: sum of src_map zero! allsrc: %2d," " srcx: %6.1f, srcy: %6.1f", allsrc, srcx[allsrc], srcy[allsrc]); 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 (allsrc=backmodl; allsrc 0.0) && (srcx[allsrc] < backproj->sky_xdim) && (srcy[allsrc] > 0.0) && (srcy[allsrc] < 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, allsrc, srcx[allsrc], allsrc, srcy[allsrc]); 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 (allsrc=0; allsrcfit_funcs[allsrc][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 (allsrc=0; allsrc 0.0) backproj->src_effic[allsrc] = eff_sum[allsrc] / map_sum[allsrc]; else backproj->src_effic[allsrc] = 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, "##7123A## ee: %2d, k1: %1d, backgr fit matrix: ", ee, k1); for (k2=0; k2tmptxt2, " %le %le Q%1d ", coeffs[k1*n_source+k2], (coeffs[k1*n_source+k2]/coeffs[0]-1.0), 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); */ /* NLNLNL 20141013 make sure backcmp[i] and backall[i] is initialized m = 0; sh->resid[0] = 0.0; for (i=1; iresid[i] = 0.0; sh->backcmp[i] = 0.0; sh->backall[i] = 0.0; for (j=0; j<10; j++) sh->backam1[j][i] = 0.0; } NLNLNL 20141013 */ /* 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 (allsrc=0; allsrctmptxt, "shadowfit1 %1d solut: %8.2f ", allsrc, rhs[allsrc]); logger->logstat = logprint(logger, logger->tmptxt, i5); } if (logger->trace) traces(func_local, 100, logger); for (allsrc=0; allsrctmptxt, "##7123B## shadowfit, E: %1d, shadowgram counts: %7.0f, solution: %7.1lf\n", ee, obs_sum, solut[allsrc]); logger->logstat = logprint(logger, logger->tmptxt, i5); } } /* NLNLNL 20141013 */ /* Only define resid, backcmp and backall when 'additional'==-1 */ if (backproj->additional < 0) { m = 0; sh->resid[0] = 0.0; for (i=1; iresid[i] = 0.0; sh->backcmp[i] = 0.0; sh->backall[i] = 0.0; for (j=0; j<10; j++) sh->backam1[j][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 (allsrc=0; allsrcact_pix[ee]; if (allsrc == 1) funval = backproj->empty_norm[i]; if (allsrc > 1) { if (backproj->norm_d[allsrc][ee] >= 0.0) funval = backproj->pifeff_maps[allsrc][i]; else funval = 0.0; } sh->backall[i] += solut[allsrc] * funval; for (j=0; j<10; j++) if (j == (allsrc-backproj->backmodels)) continue; else sh->backam1[j][i] += solut[allsrc] * funval; if (allsrc == n_source-1) backproj->current_src_map[i] = solut[allsrc] * funval; if (allsrc < BASIC_SRCMAX) logger->fit_funcs[allsrc][i] = funval; } sh->resid[i] -= sh->backall[i]; sh->resid[0] += sh->resid[i]; } } /* NLNLNL 20141013 */ 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); status = errorfit(n_source, obs_sum2, rms2, rhs2, coeff2, solut, m0, backproj, logger, status); if (status < 0) { if (logger->trace) traces(func_local, 67, logger); if (logger->trace) traces(func_local, 1000000-status, logger); 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) { for (allsrc=backproj->backmodels; allsrctrace) traces(func_local, 7000000+n_source*100+allsrc, logger); status = j_pif_limits2(n_source, allsrc, backproj, logger, status ); } } else { Nsrc = backproj->additional + backproj->backmodels; Nsrc = n_source-1; if (logger->trace) traces(func_local, 8000000+n_source*100+Nsrc, logger); status = j_pif_limits2( n_source, Nsrc, backproj, logger, status ); } } status = ISDC_OK; escape: ; /* escape: ; */ sprintf(logger->tmptxt, "##5504## %s, call from: %12s, ee: %1d %2d, n_source: %2d, additional src: %2d, negat: %d", logger->scw_file_name, logger->func_names[local_calling_num], ee, logger->eeuser, n_source, backproj->additional, negat); 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( 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; } 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 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); if (logger->trace) traces(func_local, 1000+local_calling_num, logger); if (logger->trace) traces(func_local, 2000+func_local, 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, 3000+local_calling_num, logger); if (logger->trace) traces(func_local, 4000+func_local, 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(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); } /* 6.0.8 180916 Block writing of burst images into sky_ima files. Assure output of light curves for user sources */ 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]; 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], "shdg_t0_fits"); 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 */ /* 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; } /* 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 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); } /***************************************************************** * Name of source file: skymap.c * Version of source file: 6.0.0 * 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. * 5.1.2 151106 Running version with LC generation * 5.1.31 170827 Limit burst search activity to energy bands with more than 25% of total SCW counts * 5.1.32 170906 Introduce 'typedef image_cor' and malloc of this structure (used in 'paltani_subs.c') * 6.0.0 180112 Introduces LC generation and burst detection * 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, 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) { if ((idy%128) == 0) { sprintf(logger->tmptxt, " Y 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, "%3d ", idy); 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_gen.c * Version of source file: 6.0.0 * 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 * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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; long image_cor_len; double temp_indep; /* struct image_cor *ima_corr = {&IMA_CORR}; */ image_cor *ima_corr = NULL; 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); image_cor_len = sizeof(image_cor); if ((ima_corr = (image_cor*)(malloc(image_cor_len))) == NULL) { RILlogMessage( NULL, Error_1, "##935## Not enough memory for 'ima_corr' malloc (%ld bytes)", image_cor_len); exit(0); } 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_init.c * Version of source file: 6.0.0 * 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 * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * 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: skyout.c * Version of source file: 6.0.0 * 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 * 5.1.2 151106 Running version with LC generation * 5.1.33 171206 Write RTSTART/STOP in sky_ima, srcl_res iros_lc files. Introduce logger->LCgtiREF * 6.0.0 180112 Introduces LC generation and burst detection * 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, userbin *USERBIN, 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], minmaxname[128]; 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; FILE *minmax; /* 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); if (logger->trace) traces(func_local, 1000000 + ee*1000 + ee_shd, logger); i5 = logger->i5; if ((logger->develop > 0) && (minmax == NULL)) { sprintf(minmaxname, "J%1d_%s.mmx", jmx_id->jmx_unit+1, logger->scw_file_name); minmax = fopen(minmaxname, "at"); } 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; /* if (logger->LC <= 1) { */ 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; /* if (logger->LC == 2) goto lc_signi_out; */ /* 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] = imgpeak[i]; /* else localima[i] = backproj->fitsimage[ee][1][i] / skyvar5[i]; */ /* image normalization introduced NL 20120604 */ } } for(j=0; jdevelop > 0) fprintf(minmax, "%20s %4.1f to %4.1f keV, min/max: %7.4e %7.4e Nnan: %6d\n", f_struc2->imatype, emin, emax, logger->amin, logger->amax, logger->mnan); } /* QQQQ */ if( strstr( logger->skyImagesOut, "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; jdevelop > 0) fprintf(minmax, "%20s %4.1f to %4.1f keV, min/max: %7.4e %7.4e Nnan: %6d\n", f_struc2->imatype, emin, emax, logger->amin, logger->amax, logger->mnan); } /* QQQQ */ if( strstr( logger->skyImagesOut, "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; jdevelop > 0) fprintf(minmax, "%20s %4.1f to %4.1f keV, min/max: %7.4e %7.4e Nnan: %6d\n", f_struc2->imatype, emin, emax, logger->amin, logger->amax, logger->mnan); } /* QQQQ */ if( strstr( logger->skyImagesOut, "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; jdevelop > 0) fprintf(minmax, "%20s %4.1f to %4.1f keV, min/max: %7.4e %7.4e Nnan: %6d\n", f_struc2->imatype, emin, emax, logger->amin, logger->amax, logger->mnan); } /* QQQQ */ if( strstr( logger->skyImagesOut, "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; jdevelop > 0) fprintf(minmax, "%20s %4.1f to %4.1f keV, min/max: %7.4e %7.4e Nnan: %6d\n", f_struc2->imatype, emin, emax, logger->amin, logger->amax, logger->mnan); } /* QQQQ */ if ((strstr( logger->skyImagesOut, "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; jdevelop > 0) fprintf(minmax, "%20s %4.1f to %4.1f keV, min/max: %7.4e %7.4e Nnan: %6d\n", f_struc2->imatype, emin, emax, logger->amin, logger->amax, logger->mnan); } /* QQQQ */ 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; jLC==-999) { if (logger->trace) traces(func_local, 555, logger); /* delay output of significance map until light curve analysis is completed */ for( i = 0; i < skysize; i++) { USERBIN[ee_shd].signific[i] = localima[i]; } strcpy(f_exttext[0], &F_exttext06[start_index]); strcpy(f_exttext[1], &F_exttext16[start_index]); strcpy(USERBIN[ee_shd].f_exttext[0], f_exttext[0]); strcpy(USERBIN[ee_shd].f_exttext[1], f_exttext[1]); } else { if (logger->trace) traces(func_local, 666, logger); if( strstr( logger->skyImagesOut, "SIGNI" ) != NULL ) { status = outfit_isdc( theSWG, J_IIR_IS_SKY, jemxNum, elmntName, f_exttext, localima, f_struc2, logger, ee_shd, sh, chatter, status ); if (status != ISDC_OK) goto errotrace; if (logger->develop > 0) fprintf(minmax, "%20s %4.1f to %4.1f keV, min/max: %7.4e %7.4e Nnan: %6d\n", f_struc2->imatype, emin, emax, logger->amin, logger->amax, logger->mnan); } } exittrace: /* exittrace */ if (logger->develop > 0) if (minmax != NULL) fclose(minmax); 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); 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; lc_signi_out: if (logger->trace) traces(func_local, 777, logger); jj = 6; strcpy(f_struc2->imatype[0], "SIGNIFICANCE"); strcpy(f_struc2->imatype[1], "Significance map"); strcpy(f_struc2->bunit, ""); for( i = 0; i < skysize; i++) localima[i] = USERBIN[ee_shd].signific[i]; for(j=0; jimatype, emin, emax, logger->amin, logger->amax, logger->mnan); goto exittrace; burst_image: strcpy(f_struc2->bunit, "counts/cm2/s"); strcpy(f_exttext[0], "PifRctBrstSigni"); strcpy(f_exttext[1], "PIF Rectified Burst intensity map Significance!"); status = outfit_isdc( theSWG, J_IIR_IS_SKY, jemxNum, elmntName, f_exttext, localima, f_struc2, logger, ee, sh, chatter, status ); if (status != ISDC_OK) goto errotrace; goto exittrace; } /***************************************************************** * Name of source file: skyval.c * Version of source file: 6.0.0 * 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 * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * Type of element: Function * Part of package: j_ima_iros * Name: skyval * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ int skyval(float sky[], int index, double *skval, int ee, struct log_con *logger, struct backpro *backproj) { static int func_local = -1, local_calling_num=0, old_local=1000; 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 ((ee == 3) && (old_local != local_calling_num)){ if (logger->trace) traces(func_local, 0, logger); if (logger->trace) traces(func_local, 77777, logger); if (logger->trace) traces(func_local, local_calling_num, logger); old_local = local_calling_num; if (logger->trace) traces(func_local, 99, logger); } if ((index >= 0) && (index < backproj->skydim)) { if (backproj->access[index] > 0) { if (jirisnan(sky[index])) { sprintf(logger->tmptxt, "##7938## Error: skval: NAN value for index: %6d", index); logger->logstat = logprint(logger, logger->tmptxt, 0); if (logger->trace) traces(func_local, 0, logger); if (logger->trace) traces(func_local, index, logger); if (logger->trace) traces(func_local, 99, logger); exit(0); } *skval = sky[index]; } else *skval = 0.0; status = 0; } else { sprintf(logger->error_text , "Illegal sky index in 'skyval': %8d", index); if (logger->trace) traces(func_local, 1, logger); if (logger->trace) traces(func_local, index, logger); if (logger->trace) traces(func_local, 99, logger); 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); } /*************************************************** 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: source_weight2.c * Version of source file: 6.0.0 * 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: Caalculate source weight factor to be used for light curve generation * Origin date: 201303141 * Update history: 1.0.0 20130314 First version * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * Type of element: Function * Part of package: j_ima_iros * Name: source_weight2 * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ int source_weight2( struct backpro *backproj, struct log_con *logger, struct shadowgrams *sh, float wgt_map[], int status) { int i, j, k, negpix; float wgt_sum; 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], "source_weight2"); 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); /* ************************************************************************ */ wgt_sum = 0.0; negpix = 0; for (i=0; isoft_gr[i] > 0.0) { /* if (sh->backall[i] <= 0.0) { status = -10; goto return_negative; } */ if (sh->backall[i] <= 0.0) { negpix++; backproj->soft_gr[i] = -1.0; wgt_map[i] = 0.0; } else { wgt_map[i] = sh->backcmp[i] * sh->backcmp[i] / (sh->backall[i] * sh->backall[i]); if (wgt_map[i] > 1.0) wgt_map[i] = 1.0; } } else wgt_map[i] = 0.0; wgt_sum += wgt_map[i]; } if (logger->trace) traces(func_local, 2000000, logger); if (logger->trace) traces(func_local, 2000000+(int)(wgt_sum), logger); if (logger->trace) traces(func_local, 2000000+negpix, logger); /* ************************************************************************ */ 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: */ if (logger->trace) traces(func_local, 1000-status, logger); if (logger->trace) traces(func_local, 999, logger); goto escape; } /***************************************************************** * Name of source file: source_weight.c * Version of source file: 6.0.0 * 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: Caalculate source weight factor to be used for light curve generation * Origin date: 201303141 * Update history: 1.0.0 20130314 First version * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * Type of element: Function * Part of package: j_ima_iros * Name: source_weight * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ int source_weight( int allsrc, struct backpro *backproj, struct log_con *logger, struct shadowgrams *sh, float *wgt_map, int status) { int i, j, k, reasrc, negpix; float wgt_sum; 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], "source_weight"); 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); /* ************************************************************************ */ wgt_sum = 0.0; negpix = 0; k = 0; reasrc = allsrc - backproj->backmodels; for (i=0; isoft_gr[i] > 0.0) { /* if (sh->backam1[reasrc][i] <= 0.0) { status = -10; goto return_negative; } */ if (sh->backam1[reasrc][i] <= 0.0) { negpix++; backproj->soft_gr[i] = -1.0; wgt_map[i] = 0.0; } else { wgt_map[i] = sh->backcmp[i] * sh->backcmp[i] / (sh->backam1[reasrc][i] * sh->backam1[reasrc][i]); if (wgt_map[i] > 1.0) wgt_map[i] = 1.0; if ((wgt_map[i] > 0.0) && (wgt_map[i] < 1.0)) k++; } } else wgt_map[i] = 0.0; wgt_sum += wgt_map[i]; } if (logger->trace) traces(func_local, 1000000+reasrc, logger); if (logger->trace) traces(func_local, 1000000+negpix, logger); if (logger->trace) traces(func_local, (int)(wgt_sum), logger); if (logger->trace) traces(func_local, 1000000+k, logger); /* ************************************************************************ */ 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: */ if (logger->trace) traces(func_local, 1000-status, logger); if (logger->trace) traces(func_local, 999, logger); goto escape; } /***************************************************************** * Name of source file: srcidentify2.c * Version of source file: 6.0.0 * Parent component: srcidentify * 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: Identify found sources with catalog sources * Origin date: 20160923 * Update history: 1.0.0 20160923 First version * 5.1.29 170804 New version with direct access to ISDC gnrl_refr_cat (supplied by Carlo Ferrigno) * 5.1.34 171214 Correct flux error calculation for user sources (new parameter in call to final_sky) * 6.0.0 170112 Rename V5.1.34 to V6.0.0 * 6.0.0 180112 Introduces LC generation and burst detection * Type of element: Function * Part of package: j_ima_iros * Name: srcidentify2 * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ int srcidentify2(dal_element *theswg, float RA, float dec, char srcname[], char ISDCname[], int *flag, struct instr_data *jmx_id, swg_pointing *point, struct log_con *logger) { int i, j, k, idnum, ID, status, i5; float *R=NULL; /* RA arrays */ float *D=NULL; /* dec arrays */ float *E=NULL; /* Error radius */ unsigned int *F=NULL; /* flag */ unsigned int *C=NULL; /* class */ char **N=NULL; /* source names */ char **I=NULL; /* ISDC unique names */ float dRA, ddec, g2rad = 3.14159 / 180.0; float xmm, ymm, xx, yy, rr; long CatEntries = 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], "srcidentify"); 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; sprintf(logger->tmptxt, "Entering 'srcidentify2', RA/dec: %7.3f %7.3f\n", RA, dec); logger->logstat = logprint(logger, logger->tmptxt, i5); do { dal_element *zz=NULL; char catalog_id[300]; sprintf(catalog_id,"JMX%d-SRCL-CAT", jmx_id->jmx_unit+1); status=DALobjectFindElement(theswg,catalog_id,&zz,status); if (status!=ISDC_OK){ RILlogMessage(NULL,Error_1,"j_ima_iros cannot find %s in swg", catalog_id); break; } long CatEntries=0; dal_dataType tt=DAL_FLOAT; dal_dataType ti=DAL_INT; dal_dataType tu=DAL_UINT; long bla=0; status=DALtableGetNumRows(zz,&(CatEntries),status); if (status!=ISDC_OK) break; if (CatEntries==0){ RILlogMessage(NULL,Log_0,"No sources in %s ", catalog_id); } else if (i5 == 0) RILlogMessage(NULL,Log_0,"%s contains %d sources", catalog_id, CatEntries); sprintf(logger->tmptxt, "%s contains %d sources", catalog_id, CatEntries); logger->logstat = logprint(logger, logger->tmptxt, i5); if (CatEntries>0) { status=DALallocateDataBuffer((void**)&R,CatEntries*sizeof(float),status); status=DALallocateDataBuffer((void**)&D,CatEntries*sizeof(float),status); status=DALallocateDataBuffer((void**)&E,CatEntries*sizeof(float),status); status=DALallocateDataBuffer((void**)&F,CatEntries*sizeof(unsigned int),status); status=DALallocateDataBuffer((void**)&C,CatEntries*sizeof(unsigned int),status); status=DALallocateStringBuffer(&N,CatEntries,22,status); status=DALallocateStringBuffer(&I,CatEntries,11,status); if (status!=ISDC_OK) { RILlogMessage(NULL,Error_1,"j_ima_iros allocation error in catalog extraction"); break; } status=DALtableGetCol(zz,"RA_OBJ",1,&tt,&(bla),(void *)R,status); if (status!=ISDC_OK) break; sprintf(logger->tmptxt, "Passed DALtableGetCol RA_OBJ\n"); logger->logstat = logprint(logger, logger->tmptxt, i5); status=DALtableGetCol(zz,"DEC_OBJ",1,&tt,&(bla),(void *)D,status); if (status!=ISDC_OK) break; sprintf(logger->tmptxt, "Passed DALtableGetCol DEC_OBJ\n"); logger->logstat = logprint(logger, logger->tmptxt, i5); status=DALtableGetCol(zz,"ERR_RAD",1,&tt,&(bla),(void *)E,status); if (status!=ISDC_OK) break; sprintf(logger->tmptxt, "Passed DALtableGetCol ERR_RAD\n"); logger->logstat = logprint(logger, logger->tmptxt, i5); status=DALtableGetColStrings(zz,"NAME",1,1,(long)CatEntries,&(bla),N,status); if (status!=ISDC_OK) break; sprintf(logger->tmptxt, "Passed DALtableGetColStrings NAME\n"); logger->logstat = logprint(logger, logger->tmptxt, i5); status=DALtableGetColStrings(zz,"SOURCE_ID",1,1,(long)CatEntries,&(bla),I,status); if (status!=ISDC_OK) break; sprintf(logger->tmptxt, "Passed DALtableGetColStrings SOURCE_ID\n"); logger->logstat = logprint(logger, logger->tmptxt, i5); status=DALtableGetCol(zz,"CLASS",1,&ti,&(bla),(void *)C,status); if (status!=ISDC_OK) break; sprintf(logger->tmptxt, "Passed DALtableGetCol CLASS\n"); logger->logstat = logprint(logger, logger->tmptxt, i5); status=DALtableGetCol(zz,"FLAG",1,&ti,&(bla),(void *)F,status); if (status!=ISDC_OK) break; sprintf(logger->tmptxt, "Passed DALtableGetCol FLAG\n"); logger->logstat = logprint(logger, logger->tmptxt, i5); } //status=DALobjectClose(zz,DAL_SAVE,status); //This should not be done, as the swg is open, tobe checked /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ for (i=0; itmptxt, "Looping over found sources: %3d, RA/dec: %7.3f %7.3f, name: %s\n", i, R[i], D[i], N[i]); logger->logstat = logprint(logger, logger->tmptxt, i5); status = getxy(R[i], D[i], jmx_id->jmx_unit, &xmm, &ymm, jmx_id, point, logger); if (status < 0) continue; /* remove offending source (outside FOV) */ xx = xmm / logger->pix2mm; yy = ymm / logger->pix2mm; rr = sqrt(xmm*xmm + ymm*ymm) / logger->pix2mm; sprintf(logger->tmptxt, "Catalog src in FOV, X/Y/R: %6.1f %6.1f %6.1f, RA,dec: %7.3f %7.3f, fl: %1d, ZXZ %s !%s!", xx, yy, rr, R[i], D[i], F[i], N[i], I[i]); logger->logstat = logprint(logger, logger->tmptxt, i5); } /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ identify: ; if (dec > 0.0) sprintf(srcname, "ZZ%06dP%05d", (int)(RA*1000.0 + 0.5), (int)(dec*1000.0 + 0.5)); else sprintf(srcname, "ZZ%06dM%05d", (int)(RA*1000.0 + 0.5), (int)(-dec*1000.0 + 0.5)); idnum = 0; for (i=0; isrcIDlimit) && (ddec < logger->srcIDlimit)) { ID = i; idnum++; } } if (idnum == 1) { *flag = (int)(F[ID]); /* *class = C[ID]; */ strcpy(srcname, N[ID]); strcpy(ISDCname, I[ID]); } if (idnum > 1) { *flag = (int)(F[ID]) | 128; /* *class = C[ID]; */ strcpy(srcname, N[ID]); strcpy(ISDCname, I[ID]); } DALfreeDataBuffer(R,status); DALfreeDataBuffer(D,status); DALfreeDataBuffer(E,status); DALfreeDataBuffer(F,status); DALfreeDataBuffer(C,status); DALfreeStringBuffer(N,CatEntries,status); DALfreeStringBuffer(I,CatEntries,status); if (status!=ISDC_OK) break; } while(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(idnum); } /***************************************************************** * Name of source file: srcimatransfer.c * Version of source file: 6.0.0 * 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: Transfer a single source imageregion in four sky-images * Origin date: 041122 * Update history: 1.0.0 20130213irst version * 1.6.3 060915 An exposure (vignetting) map is now a product * 1.6.4 060928 Included test for zero divisor in srcimatransfer.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 srcimatransfer 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. * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * Type of element: Function * Part of package: j_ima_iros * Name: srcimatransfer * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ int srcimatransfer(float x, float y, float from1[], float from2[], float from3[], float from4[], float to1[], float to2[], float to3[], float to4[], int ydim, 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, ixy_trans; int xsign[4] = {+1, +1, -1, -1}; int ysign[4] = {+1, -1, +1, -1}; int xtype, ixy_max, qxy, Y, Y1, qoff[9]; float pmax[4], qq, ima_max; 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], "srcimatransfer"); 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); /* 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++; 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 = to1[qxy] + to1[qxy-1] + to1[qxy-Y] + to1[qxy-Y1]; if (qq > pmax[0]) {xtype = 0; pmax[0] = qq; ixy_max = qxy;} } ixy = ixy_max; ixy_trans = ixy; ima_max = to1[ixy]; if (to1[ixy-1] > ima_max) { ima_max = to1[ixy-1]; ixy_trans = ixy - 1; } if (to1[ixy-Y] > ima_max) { ima_max = to1[ixy-Y]; ixy_trans = ixy - Y; } if (to1[ixy-Y1] > ima_max) { ima_max = to1[ixy-Y1]; ixy_trans = ixy - Y1; } for (i=3; i>=-3; i--) { for (j=-3; j<=3; j++) { jj = ixy_trans + j * ydim + i; to1[jj] = from1[jj]; /* perform peak image transfer */ to2[jj] = from2[jj]; to3[jj] = from3[jj]; to4[jj] = from4[jj]; } } 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: summary_p.c * Version of source file: 6.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: 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 * 5.1.2 151106 Running version with LC generation * 5.1.30 170804 Modify max number of light curve energy bins (user def. + 3) from 7 to MAX_LC_EBIN * 5.1.31 170827 Limit burst search activity to energy bands with more than 25% of total SCW counts * 5.1.32 170906 Introduce 'typedef image_cor' and malloc of this structure (used in 'paltani_subs.c') * 5.1.34 171214 Correct flux error calculation for user sources (new parameter in call to final_sky) * 6.0.0 170112 Rename V5.1.34 to V6.0.0 * 6.0.0 180112 Introduces LC generation and burst detection * 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][BASIC_SRCMAX], struct instr_data *jmx_id, struct backpro *backproj, struct shadowgrams *sh, struct scwlist *SCWnow, goodsrc *GOODSRC, pifmap *PIFmap, timeslices *Tslices, b_list *B_list, int chanmax[], struct log_con *logger, int chatter, int status ) { char filename[64]; int jsrc, n_src, eelim, jb, iee, i5, reasrc, allsrc, lc_num; int i, ii, j, k, m, ee_lc_i, ee_lc_j, burstSrcs=0, bursts=0, gburst=0, eburst=0; int jlim, eeuser, kmin, kmax, imax, srcID, n_source, realbursts, eelooplim=0; unsigned triggers; float val=0.0, diff_x, diff_y, sigmax, signif, IDfact, IDfac2; float BTdiff, rmsFlux, diffuse_signif[8]; double cmx, cmy, avr, BT1, BT2; static int func_local = -1, local_calling_num=0; clock_t calling_TT, TT_now; FILE *gnufil; /* 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 */ if (logger->trace) traces(func_local, 0, logger); i5 = logger->i5; status = ISDC_OK; /* QQQQQ */ /* * B_list[logger->b_listnum].sourceID = allsrc; * B_list[logger->b_listnum].start_chan = kmin; * B_list[logger->b_listnum].end_chan = kmax; * B_list[logger->b_listnum].ee = eeuser; * B_list[logger->b_listnum].signif = signif; * B_list[logger->b_listnum].rmsFlux = rmsFlux; * B_list[logger->b_listnum].SLCsignif[8] * B_list[logger->b_listnum].GLCsignif[8] * B_list[logger->b_listnum].Isignif[8] */ if (logger->trace) traces(func_local, 10, logger); if (logger->trace) traces(func_local, 20+logger->b_listnum, logger); for (i=0; ib_listnum; i++) { ee_lc_i = B_list[i].ee & logger->LCMAXMASK; if (logger->trace) traces(func_local, 30+ee_lc_i, logger); if (B_list[i].GLCsignif[ee_lc_i] > B_list[i].SLCsignif[ee_lc_i]) sigmax = B_list[i].GLCsignif[ee_lc_i]; else sigmax = B_list[i].SLCsignif[ee_lc_i]; sprintf(logger->tmptxt, "B_list%02d: src%02d ee%1d start/end chan: %3d %3d, lc_num: %2d, LCsignif: %5.2f, rms: %6.4f", i, B_list[i].sourceID, B_list[i].ee, B_list[i].start_chan, B_list[i].end_chan, B_list[i].lc_num, sigmax, B_list[i].rmsFlux); logger->logstat = logprint(logger, logger->tmptxt, 2); } if (logger->trace) traces(func_local, 40, logger); eelim = sh->numShds; if (eelim > MAX_LC_EBIN) eelim = MAX_LC_EBIN; for (eeuser=backproj->ee_basic; eeusertrace) traces(func_local, 100+eeuser, logger); for (i=0; ib_listnum; i++) { if (logger->trace) traces(func_local, (100+eeuser)*100+i, logger); imax = -1; if (eeuser != B_list[i].ee) continue; ee_lc_i = B_list[i].ee & logger->LCMAXMASK; B_list[i].ee |= 0x400; kmin = B_list[i].start_chan; kmax = B_list[i].end_chan; IDfact = 1.0; if (B_list[i].GLCsignif[ee_lc_i] > 1.2 * B_list[i].SLCsignif[ee_lc_i]) sigmax = B_list[i].GLCsignif[ee_lc_i]; else {sigmax = B_list[i].SLCsignif[ee_lc_i]; IDfact = 1.2;} imax = i; sprintf(logger->tmptxt, "BA e%1d s%02d c%3d %3d S%4.1f; ", eeuser, B_list[imax].sourceID, kmin, kmax, sigmax); for (j=i+1; jb_listnum; j++) { if (logger->trace) traces(func_local, ((100+eeuser)*100+i)*100+j, logger); if (eeuser != B_list[j].ee) continue; ee_lc_j = B_list[j].ee & logger->LCMAXMASK; if ((kmax >= (B_list[j].start_chan-1)) && (kmin <= (B_list[j].end_chan+1))) { B_list[j].ee |= 0x400; if (kmin >= B_list[j].start_chan) kmin = B_list[j].start_chan; if (kmax <= B_list[j].end_chan) kmax = B_list[j].end_chan; IDfac2 = 1.0; if (B_list[j].GLCsignif[ee_lc_j] > 1.2 * B_list[j].SLCsignif[ee_lc_j]) signif = B_list[j].GLCsignif[ee_lc_j]; else {signif = B_list[j].SLCsignif[ee_lc_j]; IDfac2 = 1.2;} if (sigmax*IDfact <= signif*IDfac2) { sigmax = signif; imax = j; } sprintf(logger->tmptxt2, " s%02d c%3d %3d S%4.1f; ", B_list[j].sourceID, B_list[j].start_chan, B_list[j].end_chan, signif); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } } if (imax < 0) continue; sprintf(logger->tmptxt2, " slut s%02d c%3d %3d S%4.1f; ", B_list[imax].sourceID, kmin, kmax, sigmax); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); logger->logstat = logprint(logger, logger->tmptxt, 2); B_list[imax].ee |= 0x2000; /* indicate that this light curve has been selected for output */ srcID = B_list[imax].sourceID; rmsFlux = B_list[imax].rmsFlux; lc_num = B_list[imax].lc_num; ee_lc_i = B_list[imax].ee & logger->LCMAXMASK; B_list[imax].sigmax = sigmax; /* save sigmax for this specific burst trigger */ sprintf(logger->tmptxt, "Sum_p: Found most signif source: src%02d ee%1d: chmin/max: %3d %3d, signif: %4.1f", srcID, eeuser, kmin, kmax, sigmax); logger->logstat = logprint(logger, logger->tmptxt, 2); } logger->logstat = logprint(logger, logger->tmptxt, i5); } if (logger->trace) traces(func_local, 190000+logger->b_listnum, logger); for (i=0; ib_listnum; i++) { if (logger->trace) traces(func_local, 192000+logger->b_listnum, logger); j = B_list[i].ee; B_list[i].ee &= (0x2000 | logger->LCMAXMASK); /* remove 'used' indicators from first pass */ sprintf(logger->tmptxt, "BC B_list[%d].ee: %04x %04x", i, j, B_list[i].ee); logger->logstat = logprint(logger, logger->tmptxt, i5); } if (logger->trace) traces(func_local, 193000+logger->b_listnum, logger); realbursts = 0; if (logger->trace) traces(func_local, 200000+logger->b_listnum, logger); for (i=0; ib_listnum; i++) { triggers = 0; imax = -1; for (j=0; j<8; j++) diffuse_signif[j] = 0.0; if ((B_list[i].ee & 0x2000) == 0) continue; /* use only selected bursts from first pass */ if (logger->trace) traces(func_local, 310000+i, logger); if ((B_list[i].ee & 0x400) != 0) continue; /* dont use bursts more than once */ if (logger->trace) traces(func_local, 320100+imax, logger); ee_lc_i = B_list[i].ee & logger->LCMAXMASK; B_list[i].ee |= 0x400; kmin = B_list[i].start_chan; kmax = B_list[i].end_chan; sigmax = B_list[i].sigmax; IDfact = 1.0; if ((B_list[i].sourceID > 0) && (B_list[i].sourceID < 90)) IDfact = 1.2; imax = i; triggers |= (1<tmptxt, "BB s%02d e%1d c%3d %3d S%4.1f %4.1f %4.1f; ", B_list[imax].sourceID, ee_lc_i, kmin, kmax, sigmax, B_list[i].GLCsignif[ee_lc_i], B_list[i].SLCsignif[ee_lc_i]); if (i >= logger->b_listnum-1) continue; for (j=i+1; jb_listnum; j++) { if (logger->trace) traces(func_local, 321000+j, logger); if ((B_list[j].ee & 0x400) != 0) continue; /* dont use bursts more than once */ if (logger->trace) traces(func_local, 322000+j, logger); if ((B_list[j].ee & 0x2000) == 0) continue; /* use only selected bursts from first pass */ if (logger->trace) traces(func_local, 323000+j, logger); if ((B_list[i].sourceID > 0) && (B_list[j].sourceID > 0) && (B_list[i].sourceID < 90) && (B_list[j].sourceID < 90) && (B_list[i].sourceID != B_list[j].sourceID)) continue; /* don't mix bursts from two known sources */ if (logger->trace) traces(func_local, 324000+j, logger); if ((kmax >= (B_list[j].start_chan-1)) && (kmin <= (B_list[j].end_chan+1))) { if (logger->trace) traces(func_local, 325000+j, logger); B_list[j].ee |= 0x400; if (kmin >= B_list[j].start_chan) kmin = B_list[j].start_chan; if (kmax <= B_list[j].end_chan) kmax = B_list[j].end_chan; ee_lc_j = B_list[j].ee & logger->LCMAXMASK; signif = B_list[j].sigmax; triggers |= (1< 0) && (B_list[j].sourceID < 90)) IDfac2 = 1.2; if (sigmax*IDfact <= signif*IDfac2) { sigmax = signif; imax = j; } sprintf(logger->tmptxt2, " s%02d e%1d c%3d %3d S%4.1f %4.1f %4.1f; ", B_list[j].sourceID, (B_list[j].ee&logger->LCMAXMASK), B_list[j].start_chan, B_list[j].end_chan, signif, B_list[j].GLCsignif[ee_lc_j], B_list[j].SLCsignif[ee_lc_j]); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } if (logger->trace) traces(func_local, 324500+j, logger); } /* repeat coalescense-loop to assure that no orphans are left un-attached (orphan example 084000600010 */ if (logger->trace) traces(func_local, 324600, logger); if (logger->trace) traces(func_local, 324700+i, logger); if (logger->trace) traces(func_local, 324800+j, logger); if (logger->trace) traces(func_local, 324900+imax, logger); if (logger->trace) traces(func_local, 326000+j, logger); for (j=i+1; jb_listnum; j++) { if ((B_list[j].ee & 0x400) != 0) continue; /* dont use bursts more than once */ if ((B_list[j].ee & 0x2000) == 0) continue; /* use only selected bursts from first pass */ if ((B_list[i].sourceID > 0) && (B_list[j].sourceID > 0) && (B_list[i].sourceID < 90) && (B_list[j].sourceID < 90) && (B_list[i].sourceID != B_list[j].sourceID)) continue; /* don't mix bursts from two known sources */ if ((kmax >= (B_list[j].start_chan-1)) && (kmin <= (B_list[j].end_chan+1))) { if (logger->trace) traces(func_local, 327000+j, logger); B_list[j].ee |= 0x400; if (kmin >= B_list[j].start_chan) kmin = B_list[j].start_chan; if (kmax <= B_list[j].end_chan) kmax = B_list[j].end_chan; ee_lc_j = B_list[j].ee & logger->LCMAXMASK; signif = B_list[j].sigmax; IDfac2 = 1.0; triggers |= (1< 0) && (B_list[j].sourceID < 90)) IDfac2 = 1.2; if (sigmax*IDfact <= signif*IDfac2) { sigmax = signif; imax = j; } if ((B_list[imax].sourceID == 0) || (B_list[imax].sourceID >= 90)) { B_list[j].iy = GOODSRC[B_list[imax].sourceID-backproj->backmodels].yy; B_list[j].ix = GOODSRC[B_list[imax].sourceID-backproj->backmodels].xx; sprintf(B_list[j].name[ee_lc_j], "UnID"); continue; } B_list[j].iy = GOODSRC[B_list[imax].sourceID-backproj->backmodels].yy; B_list[j].ix = GOODSRC[B_list[imax].sourceID-backproj->backmodels].xx; if ((ii=strlen(GOODSRC[B_list[imax].sourceID-backproj->backmodels].name)) > 30) { if (logger->trace) traces(func_local, 920000+j, logger); printf("B Illegal string length for GOODSRC[%2d].name, length: %d\n", B_list[imax].sourceID-backproj->backmodels, ii); exit(0); } sprintf(B_list[j].name[ee_lc_j], "%s", GOODSRC[B_list[imax].sourceID-backproj->backmodels].name); sprintf(logger->tmptxt2, " x%02d e%1d c%3d %3d S%4.1f %4.1f %4.1f; ", B_list[j].sourceID, (B_list[j].ee & logger->LCMAXMASK), B_list[j].start_chan, B_list[j].end_chan, signif, B_list[j].GLCsignif[ee_lc_j], B_list[j].SLCsignif[ee_lc_j]); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } } if (logger->trace) traces(func_local, 326100+imax, logger); if (logger->trace) traces(func_local, 326100+B_list[imax].sourceID, logger); if (logger->trace) traces(func_local, 326100+triggers, logger); if (logger->trace) traces(func_local, 326100+ee_lc_i , logger); if (imax < 0) goto tmp_skip; /* NLNLNL 2015 */ ee_lc_i = B_list[imax].ee & logger->LCMAXMASK; B_list[imax].triggers = triggers; if ((B_list[imax].sourceID == 0) || (B_list[imax].sourceID >= 90)) { B_list[imax].iy = 0.0; B_list[imax].ix = 0.0; sprintf(B_list[imax].name[ee_lc_i], "%s", "UnID"); if (logger->trace) traces(func_local, 290000+imax, logger); sprintf(logger->tmptxt2, " SLUT s%02d c%3d %3d S%4.1f, t%02X, imax: %2d", B_list[imax].sourceID, kmin, kmax, sigmax, B_list[imax].triggers, imax); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); logger->logstat = logprint(logger, logger->tmptxt, i5); goto noPointSrc; } if (logger->trace) traces(func_local, 888881, logger); B_list[imax].iy = GOODSRC[B_list[imax].sourceID-backproj->backmodels].yy; B_list[imax].ix = GOODSRC[B_list[imax].sourceID-backproj->backmodels].xx; if (logger->trace) traces(func_local, 888882, logger); if ((ii=strlen(GOODSRC[B_list[imax].sourceID-backproj->backmodels].name)) > 30) { if (logger->trace) traces(func_local, 930000, logger); printf("C Illegal string length for GOODSRC[%2d].name, length: %d\n", B_list[imax].sourceID-backproj->backmodels, ii); exit(0); } sprintf(B_list[imax].name[ee_lc_i], "%s",GOODSRC[B_list[imax].sourceID-backproj->backmodels].name); if (logger->trace) traces(func_local, 888883, logger); if (logger->trace) traces(func_local, 290000+imax, logger); sprintf(logger->tmptxt2, " SLUT s%02d c%3d %3d S%4.1f, t%02X, imax: %2d", B_list[imax].sourceID, kmin, kmax, sigmax, B_list[imax].triggers, imax); if (logger->trace) traces(func_local, 888884, logger); 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, 888885, logger); sprintf(logger->tmptxt, "B_list.ix.iy.name: %3d %3d %s, GOODSRC->xx,yy: %5.1f %5.1f, pix2mm: %5.2f, FOV_radius: %3d", B_list[imax].ix, B_list[imax].iy, B_list[imax].name[B_list[imax].ee & logger->LCMAXMASK], GOODSRC[B_list[imax].sourceID-backproj->backmodels].xx, GOODSRC[B_list[imax].sourceID-backproj->backmodels].yy, backproj->pix2mm, backproj->FOV_radius); logger->logstat = logprint(logger, logger->tmptxt, 2); noPointSrc: if (logger->trace) traces(func_local, 326200, logger); realbursts++; B_list[imax].ee |= 0x4000; B_list[imax].start_chan = kmin; B_list[imax].end_chan = kmax; if (B_list[imax].sourceID == 0) { for (j=0; j<8; j++) diffuse_signif[j] += sigmax; } if (B_list[imax].sourceID >= 90) { j = B_list[imax].sourceID-90; diffuse_signif[j] += sigmax; j = (j+1) % 8; diffuse_signif[j] += sigmax; j = (j+6) % 8; diffuse_signif[j] += sigmax; } if (logger->trace) traces(func_local, 610000+imax, logger); ee_lc_i = B_list[imax].ee & logger->LCMAXMASK; B_list[imax].GLCsignif[ee_lc_i] = diffuse_signif[0]; sprintf(logger->tmptxt, "%2d, imax; %2d, diffuse_signif: %4.1f", 90, imax, diffuse_signif[0]); logger->logstat = logprint(logger, logger->tmptxt, i5); for (j=1; j<8; j++) { ee_lc_i = B_list[imax].ee & logger->LCMAXMASK; if (B_list[imax].GLCsignif[ee_lc_i] < diffuse_signif[j]) B_list[imax].GLCsignif[ee_lc_i] = diffuse_signif[j]; sprintf(logger->tmptxt, "%2d, imax; %2d, diffuse_signif: %4.1f", 90+j, imax, diffuse_signif[j]); logger->logstat = logprint(logger, logger->tmptxt, i5); } } if (logger->trace) traces(func_local, 620000+imax, logger); for (i=0; ib_listnum; i++) { if ((B_list[i].ee & 0x6000) == 0) continue; /* use only primary selected bursts from first pass */ ee_lc_i = B_list[i].ee & logger->LCMAXMASK; kmin = B_list[i].start_chan; kmax = B_list[i].end_chan; ee_lc_i = B_list[i].ee & logger->LCMAXMASK; B_list[i].ID[ee_lc_i] = B_list[i].sourceID; for (j=i+1; jb_listnum; j++) { if ((B_list[j].ee & 0x2000) == 0) continue; /* use only selected bursts from first pass */ if ((kmax >= (B_list[j].start_chan-1)) && (kmin <= (B_list[j].end_chan+1))) { if (kmin >= B_list[j].start_chan) kmin = B_list[j].start_chan; if (kmax <= B_list[j].end_chan) kmax = B_list[j].end_chan; ee_lc_j = B_list[j].ee & logger->LCMAXMASK; B_list[i].GLCsignif[ee_lc_j] = B_list[j].GLCsignif[ee_lc_j]; B_list[i].SLCsignif[ee_lc_j] = B_list[j].SLCsignif[ee_lc_j]; /* B_list[i].triggers = B_list[j].triggers; */ B_list[i].ID[ee_lc_j] = B_list[j].sourceID; } } } if (logger->trace) traces(func_local, 630000+imax, logger); k = 0; eelooplim = backproj->ee_basic + 4; if (eelooplim > eelim) eelooplim = eelim; for (i=0; ib_listnum; i++) { if ((B_list[i].ee & 0x4000) == 0) continue; B_list[i].maxSLC = 0.0; sprintf(logger->tmptxt, "J%1d_%04d%04d%04d Selected burst %1d burstnum: %2d, E%1d %04X, signifs: ID/S/G: ", jmx_id->jmx_unit+1 ,backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv, ++k, i, B_list[i].ee & logger->LCMAXMASK, B_list[i].ee); /* for (j=backproj->ee_basic; jee_basic; jtmptxt2, " %02d %4.1f %4.1f, ", B_list[i].ID[j], B_list[i].SLCsignif[j], B_list[i].GLCsignif[j]); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); if (B_list[i].maxSLC < B_list[i].SLCsignif[j]) B_list[i].maxSLC = B_list[i].SLCsignif[j]; } logger->logstat = logprint(logger, logger->tmptxt, 2); } tmp_skip: ; sprintf(logger->tmptxt, " "); logger->logstat = logprint(logger, logger->tmptxt, 2); if (logger->trace) traces(func_local, 640000+imax, logger); /* ******************************************************************* */ /* */ /* Print summary results from one science window */ /* (only corresponding to basic energies and basic source set) */ /* (plus burst sources, if detected) */ /* */ /* ******************************************************************* */ eburst = 0; for (i=90; i<98; i++) eburst += PIFmap[i].BURST_NUM; bursts = burstSrcs = 0; n_source = backproj->backmodels + backproj->preset_src_N_SRC2[backproj->preset_src-1]; for (i=2; i<89; i++) { if (PIFmap[i].BURST_NUM > 0) burstSrcs++; bursts += PIFmap[i].BURST_NUM; } gburst = PIFmap[0].BURST_NUM; sprintf(logger->tmptxt2, " "); sprintf(logger->tmptxt, "Orbit: %4d, PID(scw): %3d %d, JMX%1d, Src: %1d, ObsT: %6.1lf s, ", backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv, jmx_id->jmx_unit+1, n_common2, sh->accumT); sprintf(logger->tmptxt2, "RA/dec/R: %7.3f %7.3f %4.0f, Burstsrc: %2d b%2d g%2d e%2d r%2d", SCWnow->pointing_RA, SCWnow->pointing_dec, SCWnow->roll_angle, burstSrcs, bursts, gburst, eburst, realbursts); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); logger->logstat = logprint(logger, logger->tmptxt, 2); if (logger->trace) traces(func_local, 650000+imax, logger); 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->trace) traces(func_local, 660000+imax, logger); 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); if (sh->accumT > 0.0) { 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 ((m=(GOODSRC[n_src].preset & 3)) > 0) sprintf(logger->tmptxt, "!prst%1dRA/dec: %8.4f %8.4f flux cts/dm2s: ", m, 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); } } /* ******************************************************************* */ /* NOW MAKE LOOP OVER USER SOURCES FOR POSSIBLE BURST PRINTOUT */ /* ******************************************************************* */ for (reasrc=0; reasrcN_SRC2; reasrc++) { allsrc = reasrc + backproj->backmodels; if (PIFmap[allsrc].BURST_NUM > 0) { BT2 = 0.0; for (i=1; i<=PIFmap[allsrc].BURST_NUM; i++) { if (i > 24) continue; BT1 = (PIFmap[allsrc].burstTstart[i] + PIFmap[allsrc].burstTstop[i]) / 2.0; BTdiff = BT2 - BT1; /* if (fabs(BTdiff*86400.0) < 5.0) continue; *//* avoid printing the same burst twice */ BT2 = BT1; sprintf(logger->tmptxt, "E%1d Burst RA/dec: %8.4f %8.4f, Signif: %4.1f, Events: %6.0f, Tcenter(IJD): %11.6lf", PIFmap[allsrc].eeuser[i], GOODSRC[reasrc+1].RA, GOODSRC[reasrc+1].dec, PIFmap[allsrc].burstSignif[i], PIFmap[allsrc].burstEvents[i], BT1); logger->logstat = logprint(logger, logger->tmptxt, 2); } } } if (PIFmap[0].BURST_NUM > 0) { BT2 = 0.0; for (i=1; i<=PIFmap[0].BURST_NUM; i++) { if (i > 24) continue; BT1 = (PIFmap[0].burstTstart[i] + PIFmap[0].burstTstop[i]) / 2.0; BTdiff = BT2 - BT1; if (fabs(BTdiff*86400.0) < 5.0) continue; /* avoid printing the same burst twice */ BT2 = BT1; sprintf(logger->tmptxt, "E%1d Unidentified burst, Signif: %4.1lf, Events: %6.0lf, Tcenter(IJD): %11.6lf", PIFmap[0].eeuser[i], PIFmap[0].burstSignif[i], PIFmap[0].burstEvents[i], BT1); logger->logstat = logprint(logger, logger->tmptxt, 2); } } if (PIFmap[1].BURST_NUM > 0) { BT2 = 0.0; for (i=1; i<=PIFmap[1].BURST_NUM; i++) { if (i > 24) continue; BT1 = (PIFmap[1].burstTstart[i] + PIFmap[1].burstTstop[i]) / 2.0; BTdiff = BT2 - BT1; if (fabs(BTdiff*86400.0) < 5.0) continue; /* avoid printing the same burst twice */ BT2 = BT1; sprintf(logger->tmptxt, "Unidentified burst in allE, Signif: %4.1f, Events: %6.0f, Tcenter(IJD): %11.6lf", PIFmap[1].burstSignif[i], PIFmap[1].burstEvents[i], BT1); 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; } /* **************************************************************************************** */ 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; double Diff_TT; static int first=3; FILE *trace; static clock_t traces_TT, TT_now; 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 == 0) || (tracenum == 1)) { logger->depth++; if (logger->depth > 15) logger->depth = 15; logger->trace_call_num[logger->depth] = subnum; } j = 0; for (i=0; idepth; i++) spaces[j++] = '.'; for (i=logger->depth; i<15; i++) spaces[j++] = ' '; spaces[j] = 0; if (first & 1) { first = 0; traces_TT = clock(); trace = fopen("../imatrace.txt", "wt"); } else trace = fopen("imatrace.txt", "at"); TT_now = clock(); Diff_TT = (double)(difftime(TT_now, traces_TT)) / CLOCKS_PER_SEC; fprintf(trace, "%8d %3d %3d %20s %16s %4d, %10.6lf\n", tracenum, subnum, logger->trace_call_num[logger->depth-1], name, spaces, logger->develop, Diff_TT); traces_TT = TT_now; fclose(trace); if (tracenum == 99) { logger->depth--; if (logger->depth < 0 ) logger->depth = 0; } logger->tracecalls[subnum]++; return; } /******************************************************** * * Function transpose_usi * * Function to make a unsigned short int square matrix transposition * in place for a 2D matrix in a 1D representation * * 2005-01-06/NJW * *******************************************************/ void transpose_usi( unsigned short int *a, int dim ) { int s = 0; int i = 0; int j = 0; unsigned short int swap = 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; } } } /***************************************************************** * Name of source file: TslABurstChk.c * Version of source file: 6.0.0 * Parent component: None * Programmer: Niels Lund * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * nl@space.dtu.dk * Purpose: initialize one member of the Tslices structure * Origin date: 20130310 * Update history: 1.0.0 20130310 First version * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * Type of element: Function * Part of package: j_ima_iros * Name: TslABurstChk * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ /* QQQQQQ */ int TslABurstChk( int chanmax, float meanFlux, float rmsFlux, float threshold[], int eeuser, timeslices *Tslices, pifmap *PIFmap, b_list *B_list, struct backpro *backproj, struct log_con *logger, int status) { char bfl; static int pnum = 0; int i, j, k, iib, SIGN, i5, ntime, ncr=1, nch, nch2, nchDontUse=0; int kmin, kmax, mmin, mmax, kkmin, kkmax, jsrc, reasrc, NdontUse=0; int allsrc = 0, ee_lc; float flux, error1, error2, error, sumold, sum, fmax, slicelength; float Ccnt, signif=0.0, maxEvents=0.0, sum2=0.0; float exposure, meanCounts, meanWCounts, RMSfact; double burstTstart, burstTstop, localmean, localrms, m0, m1, m2; float trigSignif=0.0, burstSignif=0.0, burstEvents=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], "TslABurstChk"); 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; burstEvents = 0.0; nchDontUse = 0; flux = Tslices[chanmax].Events; sum = flux; nch = 1.0; burstTstart = Tslices[chanmax].Tstart; burstTstop = Tslices[chanmax].Tstop; if (meanFlux <= 0.0) {status = -1; goto escape;} if (rmsFlux <= 0.0) {status = -2; goto escape;} RMSfact = sqrt(Tslices[chanmax].Events / meanFlux); if (RMSfact > 0.0) trigSignif = burstSignif = (flux - meanFlux) / (rmsFlux * RMSfact); else {RMSfact = 1.0; trigSignif = burstSignif = 0.0;} sprintf(logger->tmptxt, "TslAB: S%02d E%1d B%2d, call vals: mean: %5.1lf, excss: %5.1lf, RMS: %4.1f, RMSfct: %4.1lf, sgnf: %4.1f, chmax: %3d", allsrc, eeuser, PIFmap[allsrc].BURST_NUM, meanFlux, Tslices[chanmax].Events - meanFlux, sqrt(Tslices[chanmax].Events), RMSfact, trigSignif, chanmax); logger->logstat = logprint(logger, logger->tmptxt, i5); kmin = kmax = chanmax; for (j=1; j<10; j++){ k = chanmax + j; if (logger->trace) traces(func_local, 7990, logger); if ((k >= 0) && (k < logger->NumTimeBins)) { if (Tslices[k].dontUse > 0) goto minus_sign; nch += 1.0; flux = Tslices[k].Events; sum += flux; sum2 += Tslices[k].Events; nch2 = k - kmin + 1; if ((nch2 > 0) && (sum2 > 0.0)) { signif = (sum - meanFlux * nch2) / (rmsFlux * sqrt(nch2) * sqrt(sum2 / (nch2 * meanFlux))); } else signif = 0.0; if ((signif >= burstSignif) && (signif > 0.0)) { if (logger->trace) traces(func_local, 7991, logger); burstTstop = Tslices[k].Tstop; burstSignif = signif; kmax = k; } else {nch -= 1.0; sum -= flux; sum2 -= Tslices[k].Events;} } minus_sign: /* minus_sign: */ k = chanmax - j; if (logger->trace) traces(func_local, 7992, logger); if ((k >= 0) && (k < logger->NumTimeBins)) { if (Tslices[k].dontUse > 0) continue; nch += 1.0; flux = Tslices[k].Events; sum += flux; sum2 += Tslices[k].Events; nch2 = kmax - k + 1; if ((nch2 > 0) && (sum2 > 0.0)) { signif = (sum - meanFlux * nch2) / (rmsFlux * sqrt(nch2) * sqrt(sum2 / (nch2 * meanFlux))); } else signif = 0.0; if ((signif >= burstSignif) && (signif > 0.0)) { if (logger->trace) traces(func_local, 7993, logger); burstTstart = Tslices[k].Tstart; burstSignif = signif; kmin = k; } else {nch -= 1.0; sum -= flux; sum2 -= Tslices[k].Events;} } } nch2 = kmax - kmin + 1; if (nch2 > 0) { RMSfact = sqrt(sum2 / (nch2 * meanFlux)); if ((RMSfact > 0.0) && (rmsFlux > 0.0)) { signif = (sum - meanFlux * nch2) / (rmsFlux * RMSfact * sqrt(nch2)); } else signif = 0.0; } else signif = 0.0; sprintf(logger->tmptxt, "TslAB: %12s End E%1d TSt/stp: %10.5lf %10.5lf, Sgnf: %4.1f, ch: %2d, ID; %2d, kmin/max: %3d %3d", logger->scw_file_name, eeuser, burstTstart, burstTstop, signif, nch2, allsrc, kmin, kmax); if (signif >= threshold[1]) { if (logger->trace) traces(func_local, 7994, logger); burstEvents = 0.0; for (k=kmin; k<=kmax; k++) { if (Tslices[k].dontUse > 0) continue; nch += 1.0; burstEvents += Tslices[k].Events - meanFlux; } if (burstEvents < 10.0) { burstSignif = 0.0; signif = 0.0; if (logger->trace) traces(func_local, 7000000+burstEvents, logger); goto reject; } burstSignif = signif; sprintf(logger->tmptxt2, " Events %4.0lf ACCPT", burstEvents); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); logger->logstat = logprint(logger, logger->tmptxt, i5); } else { reject: burstEvents = 0.0; if (logger->trace) traces(func_local, 7995, logger); for (k=kmin; k<=kmax; k++) { if (Tslices[k].dontUse > 0) continue; burstEvents += Tslices[k].Events - meanFlux; } sprintf(logger->tmptxt2, " Events %3.0lf, REJCT", burstEvents); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); logger->logstat = logprint(logger, logger->tmptxt, i5); } if (signif >= threshold[1]) { burstSignif = signif; if (logger->trace) traces(func_local, 7996, logger); for (iib=1; iib 24) continue; /* loop over already accepted bursts from this source and update * if this burst has been found before (in another E-interval) */ if ((burstTstart <= PIFmap[allsrc].burstTstop[iib]) && (burstTstop >= PIFmap->burstTstart[iib])) { if (burstSignif > PIFmap[allsrc].burstSignif[iib]) { PIFmap[allsrc].burstTstart[iib] = burstTstart; PIFmap[allsrc].burstTstop[iib] = burstTstop; PIFmap[allsrc].burstEvents[iib] = burstEvents; PIFmap[allsrc].eeuser[iib] = eeuser; } PIFmap[allsrc].burstSignif[iib] = sqrt(PIFmap[allsrc].burstSignif[iib]*PIFmap[allsrc].burstSignif[iib] + burstSignif*burstSignif); } } if (logger->trace) traces(func_local, 7997, logger); if (PIFmap[allsrc].BURST_NUM < 24) PIFmap[allsrc].BURST_NUM++; else goto slut_used; PIFmap[allsrc].burstTstart[PIFmap[allsrc].BURST_NUM] = burstTstart; PIFmap[allsrc].burstTstop[PIFmap[allsrc].BURST_NUM] = burstTstop; PIFmap[allsrc].burstEvents[PIFmap[allsrc].BURST_NUM] = burstEvents; PIFmap[allsrc].burstSignif[PIFmap[allsrc].BURST_NUM] = burstSignif; PIFmap[allsrc].eeuser[PIFmap[allsrc].BURST_NUM] = eeuser; if (logger->trace) traces(func_local, 7997, logger); kkmin = kmin - 10; kkmax = kmax + 10; if (kkmin < 0) kkmin = 0; if (kkmax >= logger->NumTimeBins ) kkmax = logger->NumTimeBins; for (ntime=kkmin; ntime 0) { sprintf(logger->tmptxt, "BCHK1: %02d %1d %3d DONT USE (%1d)", pnum, PIFmap[allsrc].BURST_NUM, ntime, Tslices[ntime].dontUse); continue; } signif = (Tslices[ntime].Events - meanFlux)/ rmsFlux; if ((ntime >= kmin) && (ntime <= kmax)) if (Tslices[ntime].threshold < signif) Tslices[ntime].threshold = signif;/* update Tslices.threshold */ if (Tslices[ntime].burstflag == 2) { bfl = '2'; } else bfl = ' '; sprintf(logger->tmptxt, "BCHK1: %02d %1d %3d rms: %7.4f, mean: %-8.4f, Events: %5.1lf, signf: %4.1f, bflag: %1c", pnum, PIFmap[allsrc].BURST_NUM, ntime, rmsFlux, meanFlux, Tslices[ntime].Events, signif, bfl); if (ntime == chanmax) { sprintf(logger->tmptxt2, " TRIG signif: %4.1f", burstSignif); 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, "BCHK1"); logger->logstat = logprint(logger, logger->tmptxt, i5); pnum++; /* update 'B_list' for this SCW */ B_list[logger->b_listnum].sourceID = allsrc; B_list[logger->b_listnum].start_chan = kmin; B_list[logger->b_listnum].end_chan = kmax; B_list[logger->b_listnum].chanmax = chanmax; B_list[logger->b_listnum].ee = eeuser; ee_lc = eeuser & 7; B_list[logger->b_listnum].GLCsignif[ee_lc] = burstSignif; B_list[logger->b_listnum].rmsFlux = rmsFlux; B_list[logger->b_listnum].lc_num = 0; if (logger->b_listnum < 63) logger->b_listnum++; sprintf(logger->tmptxt, "Ylc_update: b_listnum: %2d, lc_num[b_listnum-1]: %2d", logger->b_listnum, B_list[logger->b_listnum-1].lc_num); logger->logstat = logprint(logger, logger->tmptxt, i5); } slut_used: /* indicate used channels as 'used' */ for (k=kmin; k<=kmax; k++) Tslices[k].dontUse |= 2; for (k=kmin-3; k<=kmax+3; k++) { if ((k < 0) || (k >= logger->NumTimeBins)) continue; RMSfact = sqrt(Tslices[k].Events / meanFlux); flux = Tslices[k].Events; if ((RMSfact > 0.0) && (rmsFlux > 0.0)) { if ((flux - meanFlux) / (rmsFlux * RMSfact) > threshold[0]) Tslices[k].dontUse |= 2; } } if (PIFmap[allsrc].BURST_NUM) { sprintf(logger->tmptxt, "AB At end of sequence, E%1d Src%02d, # of Bursts: %1d", eeuser, allsrc, PIFmap[allsrc].BURST_NUM); logger->logstat = logprint(logger, logger->tmptxt, i5); } slut: Tslices[chanmax].dontUse |= 4; NdontUse = 0; for (i=0; iNumTimeBins; i++) if (Tslices[i].dontUse > 0) NdontUse++; if (logger->trace) traces(func_local, 1000+NdontUse, 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 ); escape: sprintf(logger->tmptxt, "Return status from TslCheckABst: %d", status); logger->logstat = logprint(logger, logger->tmptxt, i5); goto slut; } /***************************************************************** * Name of source file: TslBurstChk.c * Version of source file: 6.0.0 * Parent component: None * Programmer: Niels Lund * Affiliation: Danish National Space Center * Contact address: Juliane Maries Vej 30 * DK-2100 Copenhagen, Denmark * nl@space.dtu.dk * Purpose: initialize one member of the Tslices structure * Origin date: 20130310 * Update history: 1.0.0 20130310 First version * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection * Type of element: Function * Part of package: j_ima_iros * Name: TslBurstChk * Required components: DAL, PIL, RIL, DAL3GEN *****************************************************************/ /* QQQQQQ */ int TslBurstChk( int chanmax, float meanFlux, float rmsFlux, float threshold[], int allsrc, int eeuser, float evRA, float evdec, timeslices *Tslices, pifmap *PIFmap, b_list *B_list, struct backpro *backproj, struct log_con *logger, int status) { char bfl; static int pnum = 0; int i, j, k, iib, SIGN, i5, ntime, ncr=1, nch, nch2, nchDontUse=0; int ee_lc, kmin, kmax, mmin, mmax, kkmin, kkmax, jsrc, reasrc, NdontUse=0; float flux, error1, error2, error, sumold, sum, fmax, slicelength; float Ccnt, signif, localmax, localsignif, maxEvents, sum2; float exposure, RMSfact, newthreshold; double burstTstart, burstTstop, m0, m1, m2; float trigSignif=0.0, burstSignif=0.0, burstEvents=0.0, burstwEvents=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], "TslBurstChk"); 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; burstEvents = 0.0; burstwEvents = 0.0; nchDontUse = 0; /* timeslices *Tslices, */ flux = Tslices[chanmax].wflux[allsrc]; sum = flux; nch = 1.0; sum2 = Tslices[chanmax].Events; burstTstart = Tslices[chanmax].Tstart; burstTstop = Tslices[chanmax].Tstop; if (meanFlux <= 0.0) {status = -1; goto escape;} if (rmsFlux <= 0.0) {status = -2; goto escape;} if (backproj->avEE_events <= 0.0) {status = -3; goto escape;} if ((chanmax > 0) && (chanmax < logger->NumTimeBins-1)) { if (Tslices[chanmax - 1].dontUse || Tslices[chanmax + 1].dontUse) {status = -4; goto escape;} } RMSfact = sqrt(Tslices[chanmax].Events / backproj->avEE_events); if (RMSfact > 0.0) trigSignif = burstSignif = (flux - meanFlux) / (rmsFlux * RMSfact); else {RMSfact = 1.0; trigSignif = burstSignif = 0.0;} sprintf(logger->tmptxt, "TslBB: S%02d E%1d B%2d, call values: mean: %6.2lf, rms: %5.3lf, RMSfact: %5.1lf, max: %4.1lf, signif: %4.1f, chanmax: %3d", allsrc, eeuser, PIFmap[allsrc].BURST_NUM, meanFlux, rmsFlux, RMSfact, flux, trigSignif, chanmax); logger->logstat = logprint(logger, logger->tmptxt, i5); nchDontUse = 0; kmin = kmax = chanmax; for (j=1; j<10; j++){ k = chanmax + j; if (k < logger->NumTimeBins) { if (Tslices[k].dontUse > 0) { nchDontUse++; goto minus_sign; } nch += 1.0; flux = Tslices[k].wflux[allsrc]; sum += flux; sum2 += Tslices[k].Events; nch2 = k - kmin + 1; if ((nch2 > 0) && (sum2 > 0.0)) { signif = (sum - meanFlux * nch2) / (rmsFlux * sqrt(nch2) * sqrt(sum2 / (nch2 * backproj->avEE_events))); } else signif = 0.0; if ((signif >= burstSignif) && (signif > 0.0)) { burstTstop = Tslices[k].Tstop; burstSignif = signif; kmax = k; } else {nch -= 1.0; sum -= flux; sum2 -= Tslices[k].Events;} sprintf(logger->tmptxt, "TslBX: k: %3d, nch: %2d, nch2: %2d, flx: %5.2f, sum: %6.2f, evnts: %4.1f, sum2: %5.2f, signi: %5.2f, Bsigni: %5.2f, kmax: %3d", k, nch, nch2, flux, sum, Tslices[k].Events, sum2, signif, burstSignif, kmax); logger->logstat = logprint(logger, logger->tmptxt, i5); } minus_sign: /* minus_sign: */ k = chanmax - j; if (k > 0) { if (Tslices[k].dontUse > 0) { nchDontUse++; continue; } nch += 1.0; flux = Tslices[k].wflux[allsrc]; sum += flux; sum2 += Tslices[k].Events; nch2 = kmax - k + 1; if ((nch2 > 0) && (sum2 > 0.0)) { signif = (sum - meanFlux * nch2) / (rmsFlux * sqrt(nch2) * sqrt(sum2 / (nch2 * backproj->avEE_events))); } else signif = 0.0; if ((signif >= burstSignif) && (signif > 0.0)) { burstTstart = Tslices[k].Tstart; burstSignif = signif; kmin = k; } else {nch -= 1.0; sum -= flux; sum2 -= Tslices[k].Events;} sprintf(logger->tmptxt, "TslBX: k: %3d, nch: %2d, nch2: %2d, flx: %5.2f, sum: %6.2f, evnts: %4.1f, sum2: %5.2f, signi: %5.2f, Bsigni: %5.2f, kmin: %3d", k, nch, nch2, flux, sum, Tslices[k].Events, sum2, signif, burstSignif, kmin); logger->logstat = logprint(logger, logger->tmptxt, i5); } } nch2 = kmax - kmin + 1; if ((nch2 > 0) && (sum2 > 0.0)) { signif = (sum - meanFlux * nch2) / (rmsFlux * sqrt(nch2) * sqrt(sum2 / (nch2 * backproj->avEE_events))); } else signif = 0.0; sprintf(logger->tmptxt, "TslBB: %12s End E%1d TSt/stp: %10.5lf %10.5lf, Sgnf: %4.1f, ch: %2d, ID; %2d, kmin/max: %3d %3d", logger->scw_file_name, eeuser, burstTstart, burstTstop, signif, nch2, allsrc, kmin, kmax); if (signif >= threshold[1]) { burstEvents = burstwEvents = 0.0; for (k=kmin; k<=kmax; k++) { if (Tslices[k].dontUse > 0) continue; nch += 1.0; burstwEvents += Tslices[k].srcWCounts; burstEvents += Tslices[k].srcCounts; } if (burstEvents < 10.0) { burstSignif = 0.0; signif = 0.0; goto reject; } burstSignif = signif; sprintf(logger->tmptxt2, " Events %4.0f %6.1lf, ACCPT", burstEvents, burstwEvents); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); logger->logstat = logprint(logger, logger->tmptxt, i5); } else { burstEvents = burstwEvents = 0.0; for (k=kmin; k<=kmax; k++) { burstwEvents += Tslices[k].srcWCounts; burstEvents += Tslices[k].srcCounts; } reject: sprintf(logger->tmptxt2, " Events %3.0lf %4.1lf, REJCT", burstEvents, burstwEvents); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); logger->logstat = logprint(logger, logger->tmptxt, i5); goto slut; } if (signif >= threshold[1]) { for (iib=1; iib 24) continue; if ((burstTstart <= PIFmap[allsrc].burstTstop[iib]) && (burstTstop >= PIFmap->burstTstart[iib])) { if (burstSignif > PIFmap[allsrc].burstSignif[iib]) { PIFmap[allsrc].burstTstart[iib] = burstTstart; PIFmap[allsrc].burstTstop[iib] = burstTstop; PIFmap[allsrc].burstEvents[iib] = burstEvents; PIFmap[allsrc].eeuser[iib] = eeuser; } PIFmap[allsrc].burstSignif[iib] = sqrt(PIFmap[allsrc].burstSignif[iib]*PIFmap[allsrc].burstSignif[iib] + burstSignif*burstSignif); } } if (PIFmap[allsrc].BURST_NUM < 24) PIFmap[allsrc].BURST_NUM++; else goto slut_used; PIFmap[allsrc].burstTstart[PIFmap[allsrc].BURST_NUM] = burstTstart; PIFmap[allsrc].burstTstop[PIFmap[allsrc].BURST_NUM] = burstTstop; PIFmap[allsrc].burstEvents[PIFmap[allsrc].BURST_NUM] = burstEvents; PIFmap[allsrc].burstSignif[PIFmap[allsrc].BURST_NUM] = burstSignif; PIFmap[allsrc].eeuser[PIFmap[allsrc].BURST_NUM] = eeuser; PIFmap[allsrc].burstdec[PIFmap[allsrc].BURST_NUM] = evdec; PIFmap[allsrc].burstRA[PIFmap[allsrc].BURST_NUM] = evRA; kkmin = kmin - 10; kkmax = kmax + 10; if (kkmin < 0) kkmin = 0; if (kkmax >= logger->NumTimeBins ) kkmax = logger->NumTimeBins; for (ntime=kkmin; ntime 0) continue; signif = (Tslices[ntime].wflux[allsrc] - meanFlux)/ rmsFlux; if ((ntime >= kmin) && (ntime <= kmax)) { bfl = '*'; if (Tslices[ntime].threshold < signif) Tslices[ntime].threshold = signif;/* update Tslices.threshold */ } else bfl = ' '; if (Tslices[ntime].burstflag == 2) bfl = '2'; } pnum++; /* update 'B_list' for this SCW */ B_list[logger->b_listnum].sourceID = allsrc; B_list[logger->b_listnum].start_chan = kmin; B_list[logger->b_listnum].end_chan = kmax; B_list[logger->b_listnum].chanmax = chanmax; B_list[logger->b_listnum].ee = eeuser; ee_lc = eeuser & 7; if (allsrc >= 90) B_list[logger->b_listnum].GLCsignif[ee_lc] = burstSignif; else B_list[logger->b_listnum].SLCsignif[ee_lc] = burstSignif; B_list[logger->b_listnum].rmsFlux = rmsFlux; B_list[logger->b_listnum].lc_num = 0; B_list[logger->b_listnum].RA = evRA; B_list[logger->b_listnum].dec = evdec; if (logger->b_listnum < 63) logger->b_listnum++; sprintf(logger->tmptxt, "Xlc_update: b_listnum: %2d, lc_num[b_listnum-1]: %2d", logger->b_listnum, B_list[logger->b_listnum-1].lc_num); logger->logstat = logprint(logger, logger->tmptxt, i5); } slut_used: if (kmax >= logger->NumTimeBins) kmax = logger->NumTimeBins - 1; if (kmin < 0) kmin = 0; for (k=kmin; k<=kmax; k++) Tslices[k].dontUse |= 2; for (k=kmin-3; k<=kmax+3; k++) { if ((k < 0) || (k >= logger->NumTimeBins)) continue; if (Tslices[k].dontUse > 0) continue; flux = Tslices[k].wflux[allsrc]; RMSfact = sqrt(Tslices[k].Events / backproj->avEE_events); if ((RMSfact > 0.0) && (rmsFlux > 0.0)) { if ((flux - meanFlux) / (rmsFlux * RMSfact) > threshold[0]) Tslices[k].dontUse |= 2; } } slut: Tslices[0].dontUse = 29; Tslices[chanmax].dontUse |= 4; NdontUse = 0; for (i=0; iNumTimeBins; i++) if (Tslices[i].dontUse > 0) NdontUse++; if (logger->trace) traces(func_local, 1000+NdontUse, 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 ); escape: if (logger->trace) traces(func_local, 900000-status, logger); sprintf(logger->tmptxt, "Return status from TslCheckBst: %d", status); logger->logstat = logprint(logger, logger->tmptxt, i5); goto slut; } /************************************************************************** update_imod_data.c A temporary member of the JEMX library 2007-03-26/NL * 5.1.2 151106 Running version with LC generation * 6.0.0 180112 Introduces LC generation and burst detection 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 ); } /***************************************************************** * Name of source file: j_ima_iros_work.c * Version of source file: 6.0.13 * 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 * 5.0.0 121001 Introduction of light curve generation * 5.0.1 150510 Introduction of time-averaging of burst-background estimate * 5.1.2 151106 Running version with LC generation * 5.1.9 160415 Update of light curve output and keywords according to agreement with ISDC * 5.1.10 160829 Circumvent analysis blocking caused by small amount of data in 'errorfit' * 5.1.11 160913 Update 'write_srcl_res' and 'work2d' to include 'pure burst' sources. * 5.1.12 160914 Update 'j_iir_Write_LC' to avoid floating point exc. for very short observation times * 5.1.14 160916 Update '*work2d.c' to avoid floating point exc. for very few time bins * 5.1.15 160925 Update 'j_iir_write_srclres' to include all sources checked by j_ima_iros * 5.1.16 160930 Update 'clean2,ex2trEvTslc,initPIF_LC,work2d' to avoid crashes due to marginal user srcs * 5.1.19 161002 Update 'clean2' and 'srcidentify'o avoid potential index errors * 5.1.20 161006 Update 'work2d'. Protect against illegal values in sqrt call in line 3808 * 5.1.22 161215 Correct work2d.c. Wrong index in image transfer (line 3810). Update 'srcidentify'. * 5.1.23 161220 Correct peaktransfer & final_sky. Endless loop in peaktransfer for sources near edge of FOV * 5.1.24 161227 Correct work2d. Handling of 'edge'-bursts, Handling of bursts after 'summary_p', * 5.1.25 161228 Correct work2d. Initialization of Tslices[].threshold. 'Eliminate bad print in ex2trEvTslc * 5.1.26 170102 Correct work2d. Handling of small number of time bins. * 5.1.28 170214 Replace 'srcidentify' (hard coded source list) with 'srcidentify2' reading the ISDC catalog * 5.1.29 170310 Multiply 'rateBuff,errBuff,bRateBuff,bErrBuff' by 100 before output in 'j_iir_Write_LC' * 5.1.30 170804 Modify max number of light curve energy bins (user def. + 3) from 7 to MAX_LC_EBIN * 5.1.31 170827 Limit burst search activity to energy bands with more than 25% of total SCW counts * 5.1.32 170906 Introduce 'typedef image_cor' and malloc of this structure (used in 'paltani_subs.c') * 5.1.33 171206 Write RTSTART/STOP in sky_ima, srcl_res iros_lc files. Introduce logger->LCgtiREF * 5.1.34 171214 Correct flux error calculation for user sources (new parameter in call to final_sky) * 6.0.0 170112 Rename V5.1.34 to V6.0.0 * 6.0.7 180913 Modified log and reg files to include %11.6lf burst start and stop times, and add obsID * 6.0.8 180916 Block writing of burst images into sky_ima files. Assure output of light curves for user sources * 6.0.9 180928 Reinstate writing of burst images in sky_ima files. * 6.0.10 181001 Assured initialization of Tslices[].GlobalLC[]-array * 6.0.11 181009 Indicate bad status in FUNedge if local_calling_num has been upset * 6.0.12 181010 Test version to locate index error in FUNedge * 6.0.13 181209 Update definition of edgeXmm and edgeYmm in work2d.c * 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, pifmap *PIFmap, timeslices *Tslices, b_list *B_list, Shd_adhoc shd_adhoc, Shd_adhoc shd_burst, /* lc_auxData *LC_AuxData, */ int chatter, int status ) { Instrument jemxNum; char ID_string[13], burst_txt[32], MPdec, Stext[12], chsign; char f_exttext[2][J_IIR_TEXTSIZE], regsrcnam[64]; char elmntName[DS_NAME_SIZE], sourcename[32], ISDCname[17]; static char SHAPE[64][10], COLOR[64][8], SourceName[32], regtext[128]; int eeb, eeuser, eelim, kMAX, i5 = 5, allsrc, reasrc, allWEpos, allWEzero; int jb, ix, iy, oldaccessum, newaccessum, jemx, addnew, old_b_listnum; int ch1, ch2, ch3, ch4, ch5, ch6, ch7, I_RA, I_dec, ibu, N_SRC2orig=0; int imin=0, jlim, jj, xix, yiy, newflag, tstsrc, eeE; int ibu2, Uibu[20], Uibu2[20], NdontUse=0, MMM=1; int preset_temp = 0, n_additional, xsrc, presrc, firstAddSource, oldBURST_NUM=0; int sky_index, sky_index0, ghoststep[2], srclist_index, prevent=0, jjee, jee; int iki, kk_offs=0, k_offset=0, kk_off2=0, srcID, doneID[20]; int preset_src_orig, catflag, ChanMax=0, chanlim=5; long Llength = 0L; 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 burst_skyim[20][MAX_LC_EBIN][SKYDIM], skyim_mask[SKYDIM], localima[SKYDIM]; static float s_reject[EE256]; static float s_accept[EE256]; static float totcnt_o[EE256+1]; static float take_away_var[SCW_SRCMAX]; static int ubin_shd[detdim], ubin_totcnt; static int ubin_shd2[detdim], ubin_totcnt2; static int src_id[SCW_SRCMAX]; static int I_sxy[SCW_SRCMAX]; static int miniCorner[6][2]; static int burst_ima_qual[20][MAX_LC_EBIN]; static int burst_lc_output[100][MAX_LC_EBIN]; static int src_lc_output[16][MAX_LC_EBIN]; static int preset_ibu[MAX_NUM_PRESET_SRCS], ibu_preset[20], ibu_N_SRC2[20]; static short used_ee[EE256][N_SRCMAX], used2[N_SRCMAX], preset[SCW_SRCMAX]; static short AA[256]; static double solut_e[EE256][BASIC_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 evRA=0.0, evdec=0.0, catRA, catdec; int map_n, xvalstart, yvalstart, n, s_field; int ylow, yhigh, ShNNN, skymax, miniIndex=0, ee_mask, NumUnknown; int ii, sxy_skymax; int chanmax[128], burst_num, ipr=0, bstsrc; int maxchan=-1, stepplot=0; float wbkg_pixel_area, wbkg_pixel_wgt, fitval, plotv, plsigma, contrib, sumE; float m0=0.0, m1=0.0, m2=0.0, fluxmax=0.0, meanFlux=0.0, rmsFlux=0.0, rmsFlux0=0.0; float correl, threshold[10], LCtal; float fitrms, factor, pkval, ShSUM, old_avGain, Isignif, sflux; float diff_x, diff_y, x, y, r, events, events2; float cmx, cmy, avr, aveffi, avillu; float funval, transmis, Emin, Emax, burst_sum; float sumX, sumY, sumgood, T_burst, T_total; float s_dec, s_RA, maxval; float avX0, avY0, xmm, ymm, Gmean[MAX_LC_EBIN]; float peakcount[2], xxx, yyy; float fk, sum_str, tot_area, sn_best, sn_temp; float temptot, tempgood; float sn_new, normfact, fact1, fact2, xx_dif, yy_dif; float s_sum, c_sum; float hot_reject, best_signif; 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, wsum, sum3, sum2; float abs_len, escape, remaining, signif; float rawcount, Apix, Anoise = 0.5; float Skymax, Skymin, m01; /* float pifnum, pifmax, pifmean, pifmin, pifval, pifzero; */ float edgeXmm[9], edgeYmm[9]; float X_rms[256], Y_rms[256], flux, RMSfact, evX, evY; float RMS_correction, rms_factor, x_rms, y_rms, rms, mean, var, mean2, mean3; float mean1, rms1, rr, NBsigniflim = 4.0, av_expo; float allEvents, allEEvents, allSrcEvents, allBkgEvents, allWSrcEvents, allWBkgEvents; float maxflux=0.0, xscale=1.0, AllCounts=0.0, B_AllCnts=0.0; int i, j, k, ej, kkkk, num_flag1_srcs, num_flag3_srcs, ichan, kscale=1, kscale2=1; int chk_no, skysize, CHANmax, IMA_qual=0; int pixels, j_src, psrc, pd, current_start[20], current_end[20], current_ibu; int bitpix, dim1, dim2, ee_lc; int isrc, jsrc, n_src1, n_src2; int n_common, n_common2; int iee, iiee, vigncorr = 1; /* default: vignetting correction will be applied ! */ int n_sources, n_sources_ini, fitcycles; int e1, e2, ksrc, sxy; int n_src, flag1src = 0, Bburst_num=-1; int ij, ij_out, burst_number[10]; int baseErr, listlim; int e1_stop, e2_stop, ic_stop, jc_stop; int PIlop, BlistNum, ALLsrc, ntb, ilc; int ntime, nevent, ixy, edgsrc, lstsrc, iisum, iicat, reg_mask = 0; int edgeI, sourceID, last = 0, NOTIMEBINS = 0, FEWTIMEBINS = 0; double quality, diff, sum; double sh_rms2; double xrms, yrms, burstTime; 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, old_psrc = 0; FILE *par_chk, *gnufil1, *gnufil2, *regfil1, *regfil2, *isdcat; char calibname[100], gnuname1[64], gnutext[256], regname1[64], textline[200], regnam2[64]; char gnuname2[64]; char *ptrA, *ptrB; maps_src = (MAPS_SRC*)maps; long nEvents; 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 */ /* 111111 */ /* QQQQQQ */ if (logger->trace) traces(func_local, 0, logger); sprintf(ID_string, "%04d%04d%04d", backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv); strcpy(logger->scw_file_name, ID_string); sprintf(logger->tmptxt, "fk5q %s", ID_string); logger->logstat = logprint(logger, logger->tmptxt, 0); i5 = logger->i5; /* NL 20120122 */ threshold[0] = 3.5; /* current low threshold */ threshold[1] = logger->thrs; /* current high threshold */ threshold[2] = 3.5; /* low threshold for found sources */ threshold[3] = logger->thrs; /* high threshold for found sources */ threshold[4] = 3.5; /* low threshold for user sources */ threshold[5] = logger->thrs; /* high threshold for user sources */ threshold[6] = 3.5; /* low threshold for global sources */ threshold[7] = logger->thrg; /* high threshold for global sources */ threshold[8] = 3.5; /* low threshold for edge sources */ threshold[9] = logger->thrg; /* high threshold for edge sources */ logger->srcIDlimit = 0.05; logger->b_listnum = 0; logger->burst_image = 0; old_b_listnum = 0; for (ibu=0; ibu<20; ibu++) { for (iee=0; iee<8; iee++) burst_ima_qual[ibu][iee] = 0; Uibu[ibu] = -1; Uibu2[ibu] = -1; doneID[ibu] = 0; ibu_preset[ibu] = 0; ibu_N_SRC2[ibu] = 0; } for (ibu=0; ibu<100; ibu++) for (iee=0; iee<8; iee++) burst_lc_output[ibu][iee] = 0; for (ibu=0; ibu<16; ibu++) for (iee=0; iee<8; iee++) src_lc_output[ibu][iee] = 0; for (i=0; i<64; i++) B_list[i].sourceID = -1; i = MAX_LC_EBIN; sprintf(logger->tmptxt, "In main: MAXLCEBIN %d, LCMASK: %d\n", i, logger->LCMAXMASK); logger->logstat = logprint(logger, logger->tmptxt, 0); sprintf(logger->tmptxt, "thresholds: "); for (i=0; i<10; i++) { sprintf(logger->tmptxt2, "%02d %4.1f ", i, threshold[i]); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); burst_number[i] = 0; } logger->logstat = logprint(logger, logger->tmptxt, 0); status = ISDC_OK; logger->new_detmap = 1; for (i=0; iNumTimeBins; i++) Tslices[i].burstflag = 0; 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; for (i=0; i<64; i++) {sprintf(COLOR[i], "white"); sprintf(SHAPE[i], "cross");} for (i=0; i<64; i++) logger->allsrc_ptr[i] = 0; sprintf(COLOR[2], "black"); sprintf(COLOR[3], "cyan"); sprintf(COLOR[4], "green"); sprintf(COLOR[5], "magenta"); sprintf(COLOR[6], "yellow"); sprintf(COLOR[7], "red"); sprintf(SHAPE[0], "circle"); sprintf(SHAPE[1], "diamond"); sprintf(SHAPE[2], "x"); sprintf(SHAPE[3], "arrow"); sprintf(SHAPE[4], "cross"); miniCorner[3][0] = 2; miniCorner[3][1] = 469; miniCorner[2][0] = 2; miniCorner[2][1] = 424; miniCorner[1][0] = 2; miniCorner[1][1] = 379; miniCorner[0][0] = 2; miniCorner[0][1] = 334; /* *************************************************************************** */ /* */ /* 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; icposres[PIlop] / 2.36; Y_rms[PIlop] = jmx_id->bposres[PIlop] / 2.36; RMS_correction = 0.5; 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); } /* 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++; } for (j=0; jempty[j][i] = 0.0; /* ************************************************************************* */ /* * * */ /* * Section 0 ends * */ /* * * */ /* * QQQQQQ * */ /* * Section 1: Make loop over search energy bins and generate * */ /* * corresponding background shadowgrams * */ /* * * */ /* ************************************************************************* */ backproj->additional = -1; 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; if (logger->trace) traces(func_local, 155+eeuser*1000, logger); sprintf(logger->tmptxt, "work2d: after fitprep: E: %2d, totcnt: %7.1f", eeuser, sh->totcnt[eeuser]); logger->logstat = logprint(logger, logger->tmptxt, i5); } if (logger->trace) traces(func_local, 155, logger); /* prepare header data for fits files */ sprintf(ID_string, "%04d%04d%04d", backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv); strcpy(logger->scw_file_name, ID_string); if (logger->trace) traces(func_local, 165, logger); if ((logger->develop & 1) == 1) { sprintf(regname1, "J%1d_%s.reg", jmx_id->jmx_unit+1, ID_string); regfil1 = fopen(regname1, "wt"); fprintf(regfil1, "# Region file format: DS9 version 4.0 %s\n", regname1); fprintf(regfil1, "global color=black font=\"helvetica 10 normal\" select=1 highlite=1 edit=1 move=1 delete=1 include=1 fixed=0 source\n"); fprintf(regfil1, "# RA/dec/R: %7.4f %7.4f %4.0f, jmxRA/dec: %7.4f %7.4f, ObsT: %6.1lf s\n", point->j_RA / GTORAD, point->j_dec / GTORAD, point->j_posangle / GTORAD, point->jmxRA, point->jmxdec, sh->accumT); fprintf(regfil1, "IMAGE;text(382.0, 510.0) # text={JEM-X%1d_%s} font=\"helvetica 14 normal\"\n", jmx_id->jmx_unit+1, ID_string); fprintf(regfil1, "IMAGE;text(450.0, 490.0) # text={ObsT: %6.1lf s} font=\"helvetica 8 normal\" \n", sh->accumT); sprintf(logger->tmptxt, "Burst thresholds (sigma):"); for (i=4; i<10; i+=2) { sprintf(logger->tmptxt2, " %4.1f %4.1f,", threshold[i], threshold[i+1]); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } fprintf(regfil1, "IMAGE;text(360.0, -10.0) # text={%s} font=\"helvetica 8 normal\" \n", logger->tmptxt); } sprintf(logger->tmptxt2, " Energy bands: "); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); eelim = sh->numShds - backproj->ee_basic; for (j=backproj->ee_basic; jnumShds; j++) { sprintf(logger->tmptxt2, " %4.1f %4.1f,", jmx_id->escale[sh->pival[j][0]], jmx_id->escale[sh->pival[j][1]]); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } if ((logger->develop & 1) == 1) fprintf(regfil1, "# %s\n", logger->tmptxt); if (logger->trace) traces(func_local, 255, logger); 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; itrace) traces(func_local, 355, logger); /* QQQQQQ Section 2: check for user defined sources */ sprintf(logger->tmptxt, "##8777## In work: preset_src: %d\n", backproj->preset_src); logger->logstat = logprint(logger, logger->tmptxt, i5); j = backproj->preset_src + SCW_SRCMAX + 18; 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; /* dummy call to find catalog sources in FOV */ srcidentify2(theSWG, SCWnow->jmxRA, SCWnow->jmxdec, sourcename, ISDCname, &catflag, jmx_id, point, logger); ISDCname[16] = 0; num_flag1_srcs = 0; num_flag3_srcs = 0; n = backproj->preset_src; if (logger->trace) traces(func_local, 455, logger); /* Eliminate offending user specified sources */ if (backproj->preset_src > 0) { for (i=0; ipreset_src; i++) { if ((fabs(backproj->preset_src_RA[i] - logger->XRA) < 0.03) && (fabs(backproj->preset_src_dec[i] - logger->Xdec) < 0.03)) backproj->preset_src_flag[i] = 3; 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; backproj->preset_src_rr[i] = sqrt(xmm*xmm + ymm*ymm) / backproj->pix2mm; if ((backproj->preset_src_flag[i] & 3) == 3) num_flag3_srcs++; if ((backproj->preset_src_flag[i] & 3) == 1) num_flag1_srcs++; logger->srcIDlimit = 0.035; srcidentify2(theSWG, backproj->preset_src_RA[i], backproj->preset_src_dec[i], sourcename, ISDCname, &catflag, jmx_id, point, logger); logger->srcIDlimit = 0.05; ISDCname[16] = 0; sprintf(logger->tmptxt, "Catalog Source in FOV, X/Y/R: %6.1f %6.1f %6.1f, RAdec: %7.3f %7.3f flag: %d, ZZZ%s", backproj->preset_src_xx[i]-backproj->FOV_radius, backproj->preset_src_yy[i]-backproj->FOV_radius, backproj->preset_src_rr[i], backproj->preset_src_RA[i], backproj->preset_src_dec[i], backproj->preset_src_flag[i], sourcename); logger->logstat = logprint(logger, logger->tmptxt, 0); } } } if (logger->trace) traces(func_local, 555, logger); 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, 0); 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, 0); /* ************************************************************************* */ /* * * */ /* * QQQQQQ * */ /* * Section 3: 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) != 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, i5); /* 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++; } } } if (logger->trace) traces(func_local, 655, logger); /* find common names for preset sources */ j = k = 0; /* isdcat = fopen("/r6/jemx/catalogs/XrBursters_cat.reg", "rt"); */ for (i=0; ipreset_src; i++) { sprintf(backproj->preset_src_name[i], "PresetSrc%04d_%02d", iicat, i); /* if ((isdcat != NULL) && (logger->develop)) { */ evRA = backproj->preset_src_RA[i]; evdec = backproj->preset_src_dec[i]; iicat = 9999; sprintf(sourcename, "PresetSrc%04d_%02d", iicat, i); /* status = catnib(isdcat, evRA, evdec, sourcename, &iicat, logger, status); if (iicat > 0) sprintf(sourcename, "PresetSrc%04d_%02d", iicat, i); */ logger->srcIDlimit = 0.035; srcidentify2(theSWG, evRA, evdec, sourcename, ISDCname, &catflag, jmx_id, point, logger); logger->srcIDlimit = 0.05; ISDCname[16] = 0; sprintf(backproj->preset_src_name[i], "%s", sourcename); /* } */ sprintf(logger->tmptxt, "PresetSRC%02d: RA/dec: %7.3lf %7.3lf, flag: %4d, name: %s", i, evRA, evdec, backproj->preset_src_flag[i], backproj->preset_src_name[i]); logger->logstat = logprint(logger, logger->tmptxt, i5); } /* if (isdcat != NULL) fclose(isdcat); */ isdcat = NULL; if (logger->trace) traces(func_local, 755, logger); /* ************************************************************************* */ /* ************************************************************************* */ /* * * */ /* * Section 4: * */ /* * Here starts the source finding loop over the basic energy bands * */ /* * (ends approximately in line 1050) * */ /* * * */ /* * * */ /* ************************************************************************* */ /* ************************************************************************* */ /* 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 */ } /* * 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, eeb , shdg_fits, jemxNum, elmntName, f_exttext, f_struc1, logger, eeb, sh, chatter, status ); if (status != ISDC_OK) goto exittrace; NLNLNL 20180916 */ /* 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, eeb , shadow_r, jemxNum, elmntName, f_exttext, f_struc1, logger, eeb, sh, chatter, status ); if (status != ISDC_OK) goto exittrace; NLNLNL 20180916 */ /* output pixelfolded shadowgram as FITS */ strcpy(f_exttext[0], "PIXFOLD_SHDGR"); strcpy(f_exttext[1], "Pixelfold shadowgram"); /* status = shdg_to_fits(theSWG, eeb , shadow, jemxNum, elmntName, f_exttext, f_struc1, logger, eeb, sh, chatter, status ); if (status != ISDC_OK) goto exittrace; NLNLNL 20180916 */ } 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); par_chk = NULL; } /* **************************************************************************************** */ /* */ /* 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 */ /* */ /* **************************************************************************************** */ backproj->additional = -1; 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->trace) traces(func_local, 91000+logger->dontUseShdg[eeb], logger); if (logger->dontUseShdg[eeb] > 0) { n_sources = backproj->backmodels; } else { status = irosloop2(jmx_id->jmx_unit, eeb, xx, yy, src_id, I_sxy, solut, &fitrms, &sh_rms2, &fitcycles, &n_sources, goodbet, preset, jmx_id, logger, backproj, bp, sh, 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, map_cnt: %3d", eeb, n_sources, backproj->stopcode[eeb], backproj->map_cnt); 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].sxy = I_sxy[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 725) * */ /* * * */ /* *************************************************************************** */ /* *************************************************************************** */ /* 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); } 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; /* *************************************************************************** */ /* *************************************************************************** */ /* * * */ /* * * */ /* * Section 5: * */ /* * START OF BLOCK IDENTIFYING COMMON SOURCES BETWEEN BASIC ENERGY BANDS * */ /* * (Ends approximately in line 1430) * */ /* * * */ /* * * */ /* *************************************************************************** */ /* *************************************************************************** */ /* 444444 */ /* QQQQQQ */ /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ kkkk = 0; logger->N_SRC2 = 0; for (e1=0; e1ee_basic; e1++) { initGOOD(e1, GOODSRC, logger, status); 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); } 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].sxy = CANDSRC[n_src1].sxy; 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 RA/dec: %7.3lf %7.3lf", 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, GOODSRC[logger->N_SRC2].RA, GOODSRC[logger->N_SRC2].dec); 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(e1, 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 1175) * */ /* * * */ /* * * */ /* *************************************************************************** */ /* *************************************************************************** */ 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 */ /* *************************************************************************** */ /* *************************************************************************** */ /* * * */ /* * * */ /* * Section 6: * */ /* * START OF BLOCK IDENTIFYING STRONG SOURCES IN SINGLE ENERGY BANDS * */ /* * (Ends approximately in line 1560) * */ /* * * */ /* * * */ /* *************************************************************************** */ /* *************************************************************************** */ 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].sxy = CANDSRC[n_src1].sxy; 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(e1, 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 1465) * */ /* * * */ /* * * */ /* *************************************************************************** */ /* *************************************************************************** */ /* 666666 */ /* QQQQQQ */ sourcefull2: /* sourcefull2 */ n_common2 = kkkk; sprintf(logger->tmptxt, "##098765## After sourcefind, n_common2: %2d, N_SRC2: %2d", n_common2, logger->N_SRC2); logger->logstat = logprint(logger, logger->tmptxt, i5); for (i=0; iN_SRC2; i++) { sprintf(logger->tmptxt, "##098765## i: %2d, RA/dec: %7.3f %7.3f, name: %30s", i, GOODSRC[i].RA, GOODSRC[i].dec, GOODSRC[i].name); logger->logstat = logprint(logger, logger->tmptxt, i5); } /* *********************************************************************************** */ /* *********************************************************************************** */ /* * * */ /* * * */ /* * Section 7: * */ /* * 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 1650) * */ /* * * */ /* *********************************************************************************** */ /* *********************************************************************************** */ sprintf(logger->tmptxt, "Number of catalog sources: %3d, number of found sources: %3d", backproj->preset_src, n_common2); logger->logstat = logprint(logger, logger->tmptxt, 0); 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) { backproj->preset_src_flag[j] |= 8; 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] & 3); } 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; } /* ***************************************************************************** */ /* ***************************************************************************** */ /* * * */ /* * * */ /* * Section 8: * */ /* * FITTING LOOP FOR BASIC SOURCE SET OVER SEARCH ENERGY INTERVALS * */ /* * (Ends approximately in line 1910) * */ /* * * */ /* * * */ /* ***************************************************************************** */ /* ***************************************************************************** */ /* 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++; AllCounts = 0.0; for (eeuser=0; eeuseree_basic; eeuser++) { if (eeuser == 0) logger->new_detmap = 1; else logger->new_detmap = 0; if (logger->trace) traces(func_local, (int)(6300000+eeuser), logger); backproj->additional = -1; status = final_fit( eeuser, n_common2, solut_e, jmx_id, logger, backproj, sh, SCWnow, GOODSRC, USERBIN, chatter, status); totcnt_o[eeuser] = sh->totcnt[eeuser]; AllCounts += totcnt_o[eeuser]; sprintf(logger->tmptxt, "work2d: eeuser: %2d, totcnt_o: %7.1f, AllCounts: %7.1f", eeuser, totcnt_o[eeuser], AllCounts); logger->logstat = logprint(logger, logger->tmptxt, i5); if (logger->trace) traces(func_local, 99180, logger); kMAX = backproj->backmodels + n_common2; if (kMAX > BASIC_SRCMAX) kMAX = BASIC_SRCMAX; if (logger->trace) traces(func_local, 1000+kMAX, logger); /* output fit functions as FITS */ for (allsrc=0; allsrctmptxt2, "Src %1d E %1d FITmap * 10**4", allsrc, 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[allsrc][ij] * solut_e[eeuser][allsrc]; ShSUM += shdg_fits[ij]; } } } if (logger->trace) traces(func_local, 181+allsrc, logger); sprintf(logger->tmptxt, "##EE: %2d, fit_function%1d: sum: %7.1f, solut_e: %7.1f, used_pixels: %5d", eeuser, allsrc, ShSUM/solut_e[eeuser][allsrc], solut_e[eeuser][allsrc], ShNNN); logger->logstat = logprint(logger, logger->tmptxt, 0); /* 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; } NLNLNL 20180916 */ } /* 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; } NLNLNL 20180916 */ /* 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; } NLNLNL 20180916 */ /* 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; } NLNLNL 20180916 */ for (jsrc=0; jsrcbackmodels+n_common2; jsrc++) { sprintf(logger->tmptxt, "##3217a## E: %2d, src: %3d, solut_e: %f ", 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; NLNLNL 20180916 */ } /* ************************************************************** */ /* */ /* Section 9: */ /* Use final residual shadowgram to form sky image */ /* */ /* ************************************************************** */ /* QQQQQQ */ /* 757575 */ if (logger->trace) traces(func_local, 4000+logger->detImagesOut, logger); if (logger->trace) traces(func_local, 5000+logger->userImagesOut, logger); if (logger->trace) traces(func_local, 6000+eeuser, logger); /* logger->detImagesOut = 0; NLNLNL 20171211 */ logger->userImagesOut = 1; for (i=0; ilocalima[i] = 0.0; status = final_sky( eeuser, n_common2, n_common2, peakval, theSWG, jmx_id, logger, backproj, sh, bp, SCWnow, GOODSRC, USERBIN, chatter, status ); sprintf(logger->tmptxt, "Return from final_sky A, status: %d", status); logger->logstat = logprint(logger, logger->tmptxt, 0); if (status != ISDC_OK) goto exittrace; if (logger->trace) traces(func_local, 6000, logger); if (logger->trace) traces(func_local, 66000 + status, logger); status = fluxerror( eeuser, n_common2, peakval, logger, backproj, sh, GOODSRC, status ); sprintf(logger->tmptxt, "Return from fluxerror A, E: %2d, status: %d", eeuser, status); logger->logstat = logprint(logger, logger->tmptxt, 0); if (logger->trace) traces(func_local, 6100, logger); if (logger->trace) traces(func_local, 6100 + status, logger); kMAX = ksrc; if (kMAX > BASIC_SRCMAX) kMAX = BASIC_SRCMAX; if (logger->trace) traces(func_local, 99180, logger); if (logger->trace) traces(func_local, 2000+kMAX, logger); } /* end of ee-loop over basic energy bands */ /* *************************************************************************** */ /* *************************************************************************** */ /* * * */ /* * * */ /* * END OF BLOCK PROCESSING BASIC SOURCE SET FOR SEARCH ENERGY BANDS * */ /* * (begins approximately in line 1713 * */ /* * * */ /* * * */ /* *************************************************************************** */ /* *************************************************************************** */ /* 888888 */ /* QQQQQQ */ /* Section 10: */ /* identify found sources and find 'common names' */ sprintf(logger->tmptxt, "Start source ID loop"); logger->logstat = logprint(logger, logger->tmptxt, 0); for (allsrc=backproj->backmodels; allsrcbackmodels; sprintf(GOODSRC[ALLsrc].name, "US%02d", ALLsrc+1); evRA = GOODSRC[ALLsrc].RA; evdec = GOODSRC[ALLsrc].dec; sprintf(logger->tmptxt, "Before srcidentify2, ALLsrc: %2d, RA/dec: %7.3f %7.3f, %s", ALLsrc, evRA, evdec, GOODSRC[ALLsrc].name); logger->logstat = logprint(logger, logger->tmptxt, 0); srcidentify2(theSWG, evRA, evdec, GOODSRC[ALLsrc].name, GOODSRC[ALLsrc].ISDCname, &catflag, jmx_id, point, logger); sprintf(logger->tmptxt, "Return from srcidentify2, ALLsrc: %2d, RA/dec: %7.3f %7.3f, %s", ALLsrc, evRA, evdec, GOODSRC[ALLsrc].name); logger->logstat = logprint(logger, logger->tmptxt, 0); GOODSRC[ALLsrc].ISDCname[16] = 0; sflux = GOODSRC[ALLsrc].flux[0] + GOODSRC[ALLsrc].flux[1] + GOODSRC[ALLsrc].flux[2]; /* save text for 'regfil1' */ cmx = GOODSRC[ALLsrc].xx - backproj->FOV_radius; cmy = GOODSRC[ALLsrc].yy - backproj->FOV_radius; rr = sqrt(cmx*cmx + cmy*cmy); status = getxy(evRA, evdec, jmx_id->jmx_unit, &xmm, &ymm, jmx_id, point, logger); if ((fabs(xmm - cmx * backproj->pix2mm) > 0.1) || (fabs(ymm - cmy * backproj->pix2mm) > 0.1)) { sprintf(logger->tmptxt, "Inconsistent RA/dec A"); logger->logstat = logprint(logger, logger->tmptxt, 0); } sprintf(logger->tmptxt, "Return from getxy, ALLsrc: %2d", ALLsrc); logger->logstat = logprint(logger, logger->tmptxt, 0); sprintf(GOODSRC[ALLsrc].regsrctxt, "fk5;point(%8.4lf, %8.4lf) # point=cross 20 text={%s} color=white", evRA, evdec, GOODSRC[ALLsrc].name); if ((logger->develop & 1) == 1) { fprintf(regfil1, "%s\n", GOODSRC[ALLsrc].regsrctxt); sprintf(logger->tmptxt, "%s", GOODSRC[ALLsrc].regsrctxt); logger->logstat = logprint(logger, logger->tmptxt, 0); fprintf(regfil1, "#fk5x IJDstart/stop %10.5lf %10.5lf, Obstime: %7.1f, cm2: %5.1f, R: %6.2f, flux: %5.1f, XY: %5.1f %5.1f\n", logger->RTStart, logger->RTStop, sh->accumT, GOODSRC[ALLsrc].src_pixel_area[0], rr, sflux, GOODSRC[ALLsrc].xx, GOODSRC[ALLsrc].yy); sprintf(logger->tmptxt, "#fk5x IJDstart/stop %10.5lf %10.5lf, Obstime: %7.1f, cm2: %5.1f, R: %6.2f, flux: %5.1f, XY: %5.1f %5.1f", logger->RTStart, logger->RTStop, sh->accumT, GOODSRC[ALLsrc].src_pixel_area[0], rr, sflux, GOODSRC[ALLsrc].xx, GOODSRC[ALLsrc].yy); logger->logstat = logprint(logger, logger->tmptxt, 0); } GOODSRC[ALLsrc].reg_used = 0xFFFF; sprintf(logger->tmptxt, " Found source. SCW ID#: %02d, RA/dec: %7.3f %7.3f, X/Y/R: %5.1f %5.1f %5.1f, name: %s %s", allsrc, evRA, evdec, GOODSRC[ALLsrc].xx, GOODSRC[ALLsrc].yy, rr, GOODSRC[ALLsrc].name, GOODSRC[ALLsrc].ISDCname); logger->logstat = logprint(logger, logger->tmptxt, 0); if (eeuser == backproj->ee_basic) { logger->allsrc_ptr[allsrc-backproj->backmodels] = allsrc - backproj->backmodels;; } } if ((logger->develop & 1) == 1) { fprintf(regfil1, "# End of DS9 region file %s\n", regname1); fclose(regfil1); } /* *************************************************************************** */ /* *************************************************************************** */ /* * * */ /* * * */ /* * Section 11: * */ /* * 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 3360) * */ /* * * */ /* * * */ /* *************************************************************************** */ /* *************************************************************************** */ /* 999999 */ /* QQQQQQ */ /* LOOP OVER USER ENERGY BANDS -- ENDS in approx. line 3790 */ for (eeuser=backproj->ee_basic; eeusernumShds; eeuser++) { for (ntime=0; ntimeNumTimeBins; ntime++) { Tslices[ntime].dontUse &= 1; /* mask away 'used time bin' flag when starting on a new energy band */ Tslices[ntime].GlobalLC[eeuser%MAX_LC_EBIN] = 0.0; /* NLNLNL 20180928 missing initialization! */ } sprintf(regnam2, "J%1d_%04d%04d%04d_E%02d.reg", jmx_id->jmx_unit+1, backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv, eeuser); if ((logger->develop & 1) == 1) { if ((regfil2 = fopen(regnam2, "wt")) != NULL) { fprintf(regfil2, "# Region file format: DS9 version 4.0 %s\n", regnam2); fprintf(regfil2, "global color=red font=\"helvetica 8 normal\" \n"); fclose(regfil2); } } prevent = 0; logger->eeuser = 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); sprintf(logger->tmptxt, "work2d: after fitprep: E: %2d, totcnt: %7.1f", eeuser, sh->totcnt[eeuser]); logger->logstat = logprint(logger, logger->tmptxt, i5); backproj->additional = -1; status = final_fit( eeuser, n_common2, solut_e, jmx_id, logger, backproj, sh, SCWnow, GOODSRC, USERBIN, chatter, status); totcnt_o[eeuser] = sh->totcnt[eeuser]; sprintf(logger->tmptxt, "work2d: eeuser: %2d, totcnt_o: %7.1f, AllCounts: %7.1f", eeuser, totcnt_o[eeuser], AllCounts); logger->logstat = logprint(logger, logger->tmptxt, i5); kMAX = backproj->backmodels + n_common2; if (kMAX > BASIC_SRCMAX) kMAX = BASIC_SRCMAX; if (logger->trace) traces(func_local, 99180, logger); if (logger->trace) traces(func_local, 3000+kMAX, logger); if (logger->trace) traces(func_local, (int)(GOODSRC[logger->N_SRC2-1].src_pixel_area[eeuser])+2, logger); if ((logger->LC == 0) || (logger->numEvents < logger->NumTimeBins)) { if (logger->trace) traces(func_local, 1000000+logger->numEvents, logger); if (logger->trace) traces(func_local, 1000000+logger->NumTimeBins, logger); goto NoTimeBins1; } /* ************************************************************** */ /* Section 12: */ /* CALCULATE LIGHT CURVES FOR THE BASIC SOURCE SET */ /* ************************************************************** */ /* QQQQQQ */ /* calculate electronic efficiency for each timeslice */ old_avGain =0.0; for (ntime=0; ntimeNumTimeBins; ntime++) { if ((fabs(Tslices[ntime].avGain - old_avGain) < 0.1) || (Tslices[ntime].dontUse > 0) || (Tslices[ntime].avGain < 0.5)) { if (ntime == 0) for (i=0; itrace) traces(func_local, 7771, logger); status = ex2trEvTslc(0, eeuser, &(Tslices[0]), &(bufevents[0]), &(PIFmap[0]), sh, backproj, USERBIN, logger, status); backproj->avEE_events = sum2 = 0.0; j = 0; for (ntime=0; ntimeNumTimeBins; ntime++) { if (Tslices[ntime].dontUse) continue; if (Tslices[ntime].exposure < logger->timestep * 0.01) {Tslices[ntime].dontUse = 1; continue;} contrib = Tslices[ntime].Events * logger->timestep * 86400.0 / Tslices[ntime].exposure ; backproj->avEE_events += contrib; sum2 += contrib * contrib; j++; } sprintf(logger->tmptxt, "E%1d, NumTimeBinsA0: %6d, sumEvents: %8.1f, sum-square: %e, bins: %4d", eeuser, logger->NumTimeBins, backproj->avEE_events, sum2, j); logger->logstat = logprint(logger, logger->tmptxt, i5); /**/ if (j == 0) {NOTIMEBINS = 1; goto NoTimeBins1;} /**/ backproj->avEE_events /= (float)(j); if (j < 5) rmsFlux0 = sqrt(backproj->avEE_events); else rmsFlux0 = sqrt(sum2 / (float)(j) - backproj->avEE_events * backproj->avEE_events); if (j < 5) goto FewTimeBins0; sprintf(logger->tmptxt, "E%1d, NumTimeBinsA: %6d, meanEvents: %6.1lf, rms: %6.2lf, bins: %4d", eeuser, logger->NumTimeBins, backproj->avEE_events, rmsFlux0, j); logger->logstat = logprint(logger, logger->tmptxt, i5); /* re-calculate mean and rms after excluding strongly deviant time bins */ j = 0; sum = wsum = sum2 = 0.0; for (ntime=0; ntimeNumTimeBins; ntime++) { if (Tslices[ntime].dontUse) continue; contrib = Tslices[ntime].Events * logger->timestep * 86400.0 / Tslices[ntime].exposure; if (fabs(contrib - backproj->avEE_events) > 3.0 * rmsFlux0) continue; /* do not include strongly deviant time bins in calculation of mean count rate and rmsFlux0 */ sum += contrib; sumE += Tslices[ntime].Events; sum2 += contrib * contrib; j++; } if (j == 0) {NOTIMEBINS = 1; goto NoTimeBins1;} backproj->avEE_events = sum / (float)(j); if (j == 1) rmsFlux0 = sqrt(sumE); else rmsFlux0 = sqrt(sum2 / (float)(j) - backproj->avEE_events * backproj->avEE_events); FewTimeBins0: Gmean[eeuser%MAX_LC_EBIN] = backproj->avEE_events; for (ntime=0; ntimeNumTimeBins; ntime++) { if (Tslices[ntime].dontUse) continue; Tslices[ntime].Gevents[eeuser%MAX_LC_EBIN] = Tslices[ntime].Events; } sprintf(logger->tmptxt, "E%1d, NumTimeBinsB: %6d, meanEvents: %6.1lf, rms: %6.2lf, bins: %4d", eeuser, logger->NumTimeBins, backproj->avEE_events, rmsFlux0, j); logger->logstat = logprint(logger, logger->tmptxt, i5); /* QQQQQQ Begin loop over basic sources to extract light curves. Ends aprox 2360 */ for (allsrc=backproj->backmodels; allsrcbackmodels; for (i=0; i<128; i++) chanmax[i] = -1; for (i=0; iNumTimeBins; i++) Tslices[i].dontUse &= MMM; /* mask away flags from prev. source */ if (eeuser == 3) PIFmap[allsrc].BURST_NUM = 0; burst_num = oldBURST_NUM = PIFmap[allsrc].BURST_NUM; if (logger->trace) traces(func_local, 100000+allsrc*1000 + eeuser*100+ PIFmap[allsrc].BURST_NUM , logger); iisum =0.0; for (i=0; isoft_gr[i] > 0.0) iisum += backproj->pif_b_pickmap[allsrc][i]; ALLsrc = allsrc - backproj->backmodels; sprintf(logger->tmptxt, "##4343A## initPIF_LC E%2d, allsrc: %2d, allsrc: %2d, ALLsrc: %2d, RA/dec: %7.3f %7.3f, %20s %s", eeuser, allsrc, allsrc, ALLsrc, GOODSRC[ALLsrc].RA, GOODSRC[ALLsrc].dec, GOODSRC[ALLsrc].name, GOODSRC[ALLsrc].ISDCname); logger->logstat = logprint(logger, logger->tmptxt, i5); /* transfer PIF-maps to structure PIFmap */ status = initPIF_LC(allsrc, allsrc, &(solut_e[eeuser][0]), &(PIFmap[allsrc]), backproj, sh, logger, status); if (status != ISDC_OK) continue; /* goto next source */ allEvents = allEEvents = allSrcEvents = allBkgEvents = allWSrcEvents = allWBkgEvents = allWEpos = allWEzero = 0.0; /* Extract events for current source & energy from event list and place in timeslices */ if (logger->trace) traces(func_local, 7772, logger); status = ex2trEvTslc(allsrc,eeuser,&(Tslices[0]),&(bufevents[0]),&(PIFmap[0]),sh,backproj,USERBIN,logger,status); /* QQQQQQ */ /* Section 13: */ /* here starts the burst search in the light curves of the found sources */ if (logger->trace) traces(func_local, 200001, logger); m0 = m1 = m2 = 0.0; for (ntime=0; ntimeNumTimeBins; ntime++) { if (Tslices[ntime].dontUse) continue; flux = Tslices[ntime].wflux[allsrc]; m0 += 1.0; m1 += flux; m2 += flux * flux; } if (logger->trace) traces(func_local, 3000000+(int)(1000.0*m0), logger); if (logger->trace) traces(func_local, 3000000+(int)(1000.0*m1), logger); if (logger->trace) traces(func_local, 3000000+(int)(m2), logger); if ((m0 > 0.0) && (m1 > 0.0)) { meanFlux = m1 / m0; if ((m2 / m0 - meanFlux * meanFlux) > 0.0) rmsFlux = sqrt(m2 / m0 - meanFlux * meanFlux); else rmsFlux = 1.0; if (rmsFlux == 0.0) {rmsFlux = m1; goto FewTimeBins1;} } else goto FewTimeBins1; if (logger->trace) traces(func_local, 200002, logger); sprintf(logger->tmptxt, "E%1d, src%1d m0: %lf, meanFlux: %f, rms: %f", eeuser, allsrc, m0, meanFlux, rmsFlux); logger->logstat = logprint(logger, logger->tmptxt, i5); if ((logger->NumTimeBins < 8) || (eeuser > MAX_LC_EBIN)) { FEWTIMEBINS = 1; goto FewTimeBins1; } m0 = m1 = m2 = 0.0; for (ntime=0; ntimeNumTimeBins; ntime++) { if (Tslices[ntime].dontUse) continue; allEvents += Tslices[ntime].Events; allEEvents += Tslices[ntime].wEvents; allWSrcEvents += Tslices[ntime].srcWCounts; allSrcEvents += Tslices[ntime].srcCounts; allWBkgEvents += Tslices[ntime].bkgWCounts; allBkgEvents += Tslices[ntime].bkgCounts; if (Tslices[ntime].av_WEff > 0.0) allWEpos++; else allWEzero++; flux = Tslices[ntime].wflux[allsrc]; if (fabs(flux - meanFlux) > 3.0*rmsFlux) continue; m0 += 1.0; m1 += flux; m2 += flux * flux; } if (logger->trace) traces(func_local, 200003, logger); if ((m0 > 0.0) && (m1 > 0.0)) { meanFlux = m1 / m0; if ((m2 / m0 - meanFlux * meanFlux) > 0.0) rmsFlux = sqrt(m2 / m0 - meanFlux * meanFlux); else rmsFlux = 1.0; } else goto FewTimeBins1; if (logger->trace) traces(func_local, 200004, logger); sprintf(logger->tmptxt, "E%1d, src%02d allev: %7.1f, allEEv: %7.1f, allWSrcEv: %7.1f, allWBkgEv: %7.1f, av_WEff>0/=0: %3d, %3d, meanFlux: %f, rms: %f", eeuser, allsrc, allEvents, allEEvents, allWSrcEvents, allWBkgEvents, allWEpos, allWEzero, meanFlux, rmsFlux); logger->logstat = logprint(logger, logger->tmptxt, i5); evRA = GOODSRC[allsrc-backproj->backmodels].RA; evdec = GOODSRC[allsrc-backproj->backmodels].dec; PIFmap[allsrc].burstRA[24] = evRA; PIFmap[allsrc].burstdec[24] = evdec; sprintf(PIFmap[allsrc].name, "%s", GOODSRC[ALLsrc].name); threshold[0] = threshold[2]; threshold[1] = threshold[3]; for (ntime=0; ntimeNumTimeBins-0; ntime++) Tslices[ntime].threshold = threshold[0]; more_bursts_1: /* more_bursts_1 */ fluxmax = 0.0; chanmax[burst_num] = -1; if (totcnt_o[eeuser] < 0.25*AllCounts) goto FewTimeBins1; /* only check bursts 'rich' user bands */ j = k = 0; for (ntime=0; ntimeNumTimeBins-0; ntime++) { if (Tslices[ntime].dontUse) { j += (Tslices[ntime].dontUse & 1); k += (Tslices[ntime].dontUse & 2); continue; } if (Tslices[ntime].wflux[allsrc] > fluxmax) { fluxmax = Tslices[ntime].wflux[allsrc]; chanmax[burst_num] = ntime; } } if (chanmax[burst_num] < 0) goto FewTimeBins1; if ((chanmax[burst_num] < chanlim) || (abs(logger->NumTimeBins - chanmax[burst_num]) < chanlim)) { Tslices[chanmax[burst_num]].dontUse |= 2; goto more_bursts_1; } if (backproj->avEE_events > 0.0) { RMSfact = sqrt(Tslices[chanmax[burst_num]].Events / backproj->avEE_events); if ((RMSfact > 0.0) && (rmsFlux > 0.0)) signif = (fluxmax - meanFlux) / (rmsFlux * RMSfact); else signif = 0.0; } else goto FewTimeBins1; if (logger->trace) traces(func_local, 200005, logger); /* if threshold exceeded call TslBurstChk (for the basic source set) */ if ((signif > Tslices[chanmax[burst_num]].threshold) && (logger->BUsrch > 0)) { sprintf(logger->tmptxt, "FBXE%1d S%02d bst_num %2d chmax %4d flxmax %6.2lf mean %6.2lf signi %4.1lf NoUse %2d %4d RMSfact %5.1lf", eeuser, allsrc, burst_num, chanmax[burst_num], fluxmax, meanFlux, signif, j, k/2, RMSfact); status = TslBurstChk(chanmax[burst_num], meanFlux, rmsFlux, threshold, allsrc, eeuser, evRA, evdec, &(Tslices[0]), &(PIFmap[0]), &(B_list[0]), backproj, logger, status); } ChanMax = chanmax[burst_num]; NdontUse = 0; for (i=0; iNumTimeBins; i++) if (Tslices[i].dontUse > 0) NdontUse++; if (logger->trace) traces(func_local, 1000000+1000*allsrc+100*eeuser+PIFmap[allsrc].BURST_NUM, logger); if (logger->trace) traces(func_local, 2000000+1000*allsrc+100*eeuser+burst_num, logger); if (PIFmap[allsrc].BURST_NUM > burst_num) { burst_num = PIFmap[allsrc].BURST_NUM; if (logger->trace) traces(func_local, 3000000+1000*allsrc+100*eeuser+PIFmap[allsrc].BURST_NUM, logger); BlistNum = logger->b_listnum - 1; sprintf(logger->tmptxt, "Burst found (found src): %2d, RA/dec: %8.4f %8.4f, name: %s !%s!, BlNum: %d, NdntUse: %d, chnmax %4d %4d", allsrc, evRA, evdec, GOODSRC[ALLsrc].name, GOODSRC[ALLsrc].ISDCname, BlistNum, NdontUse, ChanMax, chanmax[burst_num]); logger->logstat = logprint(logger, logger->tmptxt, i5); B_list[BlistNum].RA = evRA; B_list[BlistNum].dec = evdec; status = getxy(evRA, evdec, jmx_id->jmx_unit, &xmm, &ymm, jmx_id, point, logger); B_list[BlistNum].xvalstart = xmm / backproj->pix2mm + backproj->FOV_radius; B_list[BlistNum].yvalstart = ymm / backproj->pix2mm + backproj->FOV_radius; /* save data from burst in 'found source' for 'regfil2' */ sprintf(B_list[BlistNum].regsrctxt, "fk5;point(%8.4f, %8.4f) # point=%s %d text={} color=%s", evRA, evdec, SHAPE[1], (int)(20+GOODSRC[ALLsrc].bnum*2), COLOR[eeuser]); GOODSRC[ALLsrc].reg_used = 0xFFFF; B_list[BlistNum].chanmax = chanmax[burst_num] = ChanMax; sprintf(B_list[BlistNum].regtxtlin, "t_chn %3d %3d mx %3d", B_list[BlistNum].start_chan, B_list[BlistNum].end_chan, chanmax[burst_num]); sprintf(regnam2, "J%1d_%04d%04d%04d_E%02d.reg", jmx_id->jmx_unit+1, backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv, eeuser); cmx = GOODSRC[ALLsrc].xx - backproj->FOV_radius; cmy = GOODSRC[ALLsrc].yy - backproj->FOV_radius; rr = sqrt(cmx*cmx + cmy*cmy); status = getxy(evRA, evdec, jmx_id->jmx_unit, &xmm, &ymm, jmx_id, point, logger); if ((fabs(xmm - cmx * backproj->pix2mm) > 0.1) || (fabs(ymm - cmy * backproj->pix2mm) > 0.1)) { sprintf(logger->tmptxt, "Inconsistent RA/dec B"); logger->logstat = logprint(logger, logger->tmptxt, 0); } GOODSRC[ALLsrc].LC_signif = B_list[BlistNum].SLCsignif[eeuser%MAX_LC_EBIN]; if ((logger->develop & 1) == 1) { if ((regfil2 = fopen(regnam2, "at")) != NULL) { fprintf(regfil2, "%s\n", B_list[BlistNum].regsrctxt); sprintf(logger->tmptxt, "%s\n", B_list[BlistNum].regsrctxt); logger->logstat = logprint(logger, logger->tmptxt, 0); eeE = eeuser%MAX_LC_EBIN; fprintf(regfil2, "#fk5y IJDstart/stop %10.5lf %10.5lf, Obstime: %7.1f, cm2: %5.1f, R: %6.2f, signif: %5.1f, %s, XY: %5.1f %5.1f\n", Tslices[B_list[BlistNum].start_chan].Tstart, Tslices[B_list[BlistNum].end_chan].Tstop, sh->accumT, GOODSRC[ALLsrc].src_pixel_area[eeuser], rr, B_list[BlistNum].SLCsignif[eeE], B_list[BlistNum].regtxtlin, GOODSRC[ALLsrc].xx, GOODSRC[ALLsrc].yy); fclose(regfil2); sprintf(logger->tmptxt, "#fk5y E%1d IJDst/stp %10.5lf %10.5lf, Obst: %7.1f, cm2: %5.1f, R: %6.2f, sign: %5.1f, %s, XY: %5.1f %5.1f\n", eeuser, Tslices[B_list[BlistNum].start_chan].Tstart, Tslices[B_list[BlistNum].end_chan].Tstop, sh->accumT, GOODSRC[ALLsrc].src_pixel_area[eeuser], rr, B_list[BlistNum].SLCsignif[eeE], B_list[BlistNum].regtxtlin, GOODSRC[ALLsrc].xx, GOODSRC[ALLsrc].yy); logger->logstat = logprint(logger, logger->tmptxt, 0); } } GOODSRC[ALLsrc].burstptr[GOODSRC[ALLsrc].bnum] = BlistNum; GOODSRC[ALLsrc].bnum++; if (PIFmap[allsrc].BURST_NUM < 24) goto more_bursts_1; } else chanmax[burst_num] = 0; FewTimeBins1: /* FewTimeBins1 */ /* output gnuplot lightcurves for basic source set */ txtConvert(GOODSRC[ALLsrc].name, SourceName, logger); if (logger->trace) traces(func_local, 200006, logger); if (logger->trace) traces(func_local, 200000+eeuser, logger); sprintf(gnuname1, "J%1d_lc_%04d%04d%04d_%s_E%02d.gnu", jmx_id->jmx_unit+1, backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv, SourceName, eeuser); sprintf(logger->tmptxt, "GNUNAVN: ALLsrc: %2d N_SRC2: %2d %20s J%1d_lc_%04d%04d%04d_%s_E%02d.gnu", ALLsrc, logger->N_SRC2, GOODSRC[ALLsrc].name, jmx_id->jmx_unit+1, backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv, SourceName, eeuser); logger->logstat = logprint(logger, logger->tmptxt, i5); /* save light curve for later use */ if ((gnufil1 = fopen(gnuname1, "wt")) != NULL) { ilc = allsrc; if (eeuser == backproj->ee_basic) { logger->N_SRC3 = logger->N_SRC2; /* N_SRC3 is used to control output of fits-lightcurves */ logger->allsrc_lc[allsrc-backproj->backmodels] = allsrc - backproj->backmodels;; } /* fact1 = GOODSRC[ALLsrc].src_pixel_area[eeuser]; fact2 = GOODSRC[ALLsrc].src_backgr_area[eeuser]; for (ntime=0; ntimeNumTimeBins; ntime++) { if (Tslices[ntime].dontUse) continue; Tslices[ntime].wflux[allsrc] *= fact1; Tslices[ntime].wfErr[allsrc] *= fact1; Tslices[ntime].wbflux[allsrc] *= fact2; Tslices[ntime].wbfErr[allsrc] *= fact2; } rmsFlux *= GOODSRC[ALLsrc].src_pixel_area[eeuser]; NLNLNL 20160415 */ status = gnuTslice(allsrc, eeuser, rmsFlux, backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv, Tslices, chanmax, logger, gnufil1, status); fclose(gnufil1); gnufil1 = NULL; /* rmsFlux /= (GOODSRC[ALLsrc].src_pixel_area[eeuser] + 0.00001); NLNLNL 20160415 */ } if (logger->trace) traces(func_local, 200007, logger); if (PIFmap[allsrc].BURST_NUM > oldBURST_NUM) { if (logger->trace) traces(func_local, 200008, logger); old_b_listnum = logger->b_listnum; } } /* end of loop over basic source list for light curve extraction (begins app. line 2110) */ NoTimeBins1: ; /* QQQQQQ */ /* ************************************************************** */ /* */ /* Section 14: */ /* LOOP OVER ADDITIONAL SOURCES */ /* */ /* ************************************************************** */ if (logger->trace) traces(func_local, 200009, logger); flag1src = 0; for (psrc=0; psrcpreset_src; psrc++) if ((backproj->preset_src_flag[psrc] & 3) == 1) flag1src++; for (psrc=0; psrcpreset_src; psrc++) { /* beginning of loop over preset sources ('psrc' loop variable) - ends in 2945 */ for (i=0; i<128; i++) chanmax[i] = -1; for (i=0; iNumTimeBins; i++) Tslices[i].dontUse &= MMM; /* mask away flags from prev. source */ if ((backproj->preset_src_flag[psrc] & 3) != 1) continue; /* this source should not be testet in this loop */ if ((backproj->preset_src_flag[psrc] & 8) == 8) 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; logger->allsrc_ptr[logger->N_SRC2] = logger->N_SRC2; sprintf(logger->tmptxt, "##4545## n_common2: %1d, psrc: %2d, X/Y: %7.2f %7.2f, backproN_SRC2: %2d, loggerN_SRC2: %2d, name: %s", n_common2, psrc, backproj->preset_src_xx[psrc], backproj->preset_src_yy[psrc], backproj->preset_src_N_SRC2[psrc], logger->N_SRC2, backproj->preset_src_name); 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]; evRA = GOODSRC[backproj->preset_src_N_SRC2[psrc]].catRA = backproj->preset_src_RA[psrc]; evdec = 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]; sxy = backproj->preset_src_xx[psrc] * backproj->sky_ydim + backproj->preset_src_yy[psrc]; GOODSRC[backproj->preset_src_N_SRC2[psrc]].sxy = sxy; GOODSRC[backproj->preset_src_N_SRC2[psrc]].preset |= 1; sprintf(GOODSRC[backproj->preset_src_N_SRC2[psrc]].name, "%s", backproj->preset_src_name[psrc]); sprintf(logger->tmptxt, "Preset source. SCW ID#: %02d, RA/dec: %7.3f %7.3f, X/Y/R: %5.1f %5.1f %5.1f, name: %s", logger->N_SRC2 + backproj->backmodels, backproj->preset_src_RA[psrc], backproj->preset_src_dec[psrc], backproj->preset_src_xx[psrc], backproj->preset_src_yy[psrc], backproj->preset_src_rr[psrc], backproj->preset_src_name[psrc]); logger->logstat = logprint(logger, logger->tmptxt, i5); } else { addnew = 0; logger->new_detmap = 0; } evRA = GOODSRC[backproj->preset_src_N_SRC2[psrc]].catRA = backproj->preset_src_RA[psrc]; evdec = GOODSRC[backproj->preset_src_N_SRC2[psrc]].catdec = backproj->preset_src_dec[psrc]; backproj->srclist[n_common2] = backproj->preset_src_N_SRC2[psrc]; backproj->additional = backproj->preset_src_N_SRC2[psrc]; 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) traces(func_local, 470000+eeuser, logger); if (addnew) { logger->N_SRC2++; if (logger->trace) traces(func_local, 471000+logger->N_SRC2, logger); initGOOD(eeuser, GOODSRC, logger, status); addnew = 0; } if (logger->trace) traces(func_local, 623000+logger->N_SRC2, logger); if (logger->trace) traces(func_local, 624000+n_common2, logger); for (jsrc=0; jsrcbackmodels+n_common2+1; jsrc++) { sprintf(logger->tmptxt, "##3217b## E: %2d, solut_e: %f", eeuser, solut_e[eeuser][jsrc]); logger->logstat = logprint(logger, logger->tmptxt, i5); } if (logger->trace) traces(func_local, 623100+eeuser, logger); if (NOTIMEBINS) goto NoTimeBins4; /* ************************************************************** */ /* Section 15: */ /* THIS IS THE RIGHT PLACE FOR CALCULATION OF LIGHT CURVES */ /* FOR THE USER DEFINED SOURCE SET */ /* ************************************************************** */ /* QQQQQQ */ presrc = backproj->backmodels + backproj->preset_src_N_SRC2[psrc]; lstsrc = backproj->backmodels + n_common2; for (i=0; i<128; i++) chanmax[i] = -1; if (eeuser == 3) PIFmap[presrc].BURST_NUM = 0; burst_num = oldBURST_NUM = PIFmap[presrc].BURST_NUM; if (logger->trace) traces(func_local, 623120+eeuser, logger); if ((logger->LC == 0) || (logger->numEvents < logger->NumTimeBins)) goto NoTimeBins2; if (logger->trace) traces(func_local, 3700000+eeuser*100+ psrc, logger); if (logger->trace) traces(func_local, 3700000+eeuser*100+ presrc, logger); if (logger->trace) traces(func_local, 3700000+eeuser*100+ lstsrc, logger); if (firstAddSource == 0) { firstAddSource = 1; if (logger->trace) traces(func_local, 623400+eeuser, logger); status = source_weight2(backproj, logger, sh, PIFmap[presrc].wgt_map, status); for (i=0; i 1.0) PIFmap[presrc].wgt_map[i] = 1.0; if (logger->trace) traces(func_local, 623500+eeuser, logger); } else { for (i=0; i 1.0) PIFmap[presrc].wgt_map[i] = 1.0; if (PIFmap[presrc-1].wgt_map[i] < 0.0) PIFmap[presrc].wgt_map[i] = 0.0; PIFmap[presrc].wgt_map[i] = PIFmap[presrc-1].wgt_map[i]; } } if (logger->trace) traces(func_local, 7720000+presrc, logger); if( status != ISDC_OK ) { if (logger->trace) traces(func_local, 7720099, logger); RILlogMessage( NULL, Warning_0, "##273## source_weight2 returned: %d, status reset!", status); status = ISDC_OK; } if (logger->trace) traces(func_local, 7730000+logger->NumTimeBins, logger); sprintf(logger->tmptxt, "##4343B## initPIF_LC E%2d, lstsrc %2d, presrc: %2d, psrc: %2d, RA/dec: %7.3f %7.3f, %20s", eeuser, lstsrc, presrc, psrc, backproj->preset_src_RA[psrc], backproj->preset_src_dec[psrc], backproj->preset_src_name[psrc]); logger->logstat = logprint(logger, logger->tmptxt, i5); /* transfer PIF-maps to structure PIFmap */ status = initPIF_LC(lstsrc, presrc, &(solut_e[eeuser][0]), &(PIFmap[presrc]), backproj, sh, logger, status); if (status != ISDC_OK) { if (logger->trace) traces(func_local, 7100000+presrc, logger); status = ISDC_OK; continue; /* goto next user-defined source */ } if (logger->trace) traces(func_local, 7700000+presrc, logger); if (PIFmap[presrc].src_pixel_area < 2.0) { if (logger->trace) traces(func_local, 7100000+(int)(1000.0*PIFmap[presrc].src_pixel_area)+presrc, logger); continue; /* do not derive light curves for very marginal sources */ } if (logger->trace) traces(func_local, 7710000+presrc, logger); /* * Renormalization removed 20160219 NLNLNL PIFmap[presrc].wsrc_pixel_area *= 0.01; PIFmap[presrc].wbkg_pixel_area *= 0.01; PIFmap[presrc].src_pixel_area *= 0.01; PIFmap[presrc].bkg_pixel_area *= 0.01; */ PIFmap[presrc].burstRA[24] = backproj->preset_src_RA[psrc]; PIFmap[presrc].burstdec[24] = backproj->preset_src_dec[psrc]; sprintf(PIFmap[presrc].name, "%s", backproj->preset_src_name[psrc]); /* if (firstAddSource == 0) { firstAddSource = 1; if (logger->trace) traces(func_local, 623400+eeuser, logger); status = source_weight2(backproj, logger, sh, PIFmap[presrc].wgt_map, status); if (logger->trace) traces(func_local, 623500+eeuser, logger); } else { for (i=0; itrace) traces(func_local, 7720000+presrc, logger); if( status != ISDC_OK ) { if (logger->trace) traces(func_local, 7720099, logger); RILlogMessage( NULL, Warning_0, "##273## source_weight2 returned: %d, status reset!", status); status = ISDC_OK; } if (logger->trace) traces(func_local, 7730000+logger->NumTimeBins, logger); */ /* Extract events for current source & energy from event list and place in timeslices */ /* Calculate fluxes, corrected for exposure, deadtime, greyfilter and efficiency */ for (ntime=0; ntimeNumTimeBins; ntime++) { Tslices[ntime].srcWCounts = 0.0; Tslices[ntime].srcCounts = 0.0; Tslices[ntime].bkgWCounts = 0.0; Tslices[ntime].bkgCounts = 0.0; } if (logger->trace) traces(func_local, 7773, logger); status = ex2trEvTslc(presrc,eeuser,&(Tslices[0]),&(bufevents[0]),&(PIFmap[0]),sh,backproj,USERBIN,logger,status); if( status != ISDC_OK ) { RILlogMessage( NULL, Warning_0, "##273## ex2trEvTslc returned: %d, status reset!", status); status = ISDC_OK; } if ((logger->NumTimeBins < 10) || (eeuser > MAX_LC_EBIN)) goto gnu_out_2; if (logger->trace) traces(func_local, 7740000+presrc, logger); m0 = m1 = m2 = 0.0; for (ntime=0; ntimeNumTimeBins; ntime++) { if (Tslices[ntime].dontUse) continue; flux = Tslices[ntime].wflux[presrc]; m0 += 1.0; if (!jirisnan(flux)) { m1 += flux; m2 += flux * flux; } else {if (logger->trace) traces(func_local, 7730000+(int)(m0), logger);} if (logger->trace) traces(func_local, 7730000+(int)(m0), logger); if (logger->trace) traces(func_local, (int)(fabs(m1*100.0))+2, logger); } if (logger->trace) traces(func_local, 7750000+presrc, logger); if (logger->trace) traces(func_local, 7750000+(int)(m0), logger); if (logger->trace) traces(func_local, (int)(fabs(m1))+2, logger); /* Calculate mean flux, rmsFlux, and find maxflux and maxchan */ if (m0 > 0.0) { /* if ((m1 <= 0.0) && (PIFmap[presrc].BURST_NUM > 0))) */ if (logger->trace) traces(func_local, 7000000+(int)(100.0*m1), logger); meanFlux = m1 / m0; if ((m2 / m0 - meanFlux * meanFlux) > 0.0) rmsFlux = sqrt(m2 / m0 - meanFlux * meanFlux); else rmsFlux = 1.0; } else continue; if (logger->trace) traces(func_local, 7760000+eeuser, logger); m0 = m1 = m2 = 0.0; for (ntime=0; ntimeNumTimeBins; ntime++) { if (Tslices[ntime].dontUse) continue; allEEvents += Tslices[ntime].wEvents; allWSrcEvents += Tslices[ntime].srcWCounts; allSrcEvents += Tslices[ntime].srcCounts; allWBkgEvents += Tslices[ntime].bkgWCounts; allBkgEvents += Tslices[ntime].bkgCounts; flux = Tslices[ntime].wflux[presrc]; if (fabs(flux-meanFlux) > 3.0*rmsFlux) continue; m0 += 1.0; m1 += flux; m2 += flux * flux; } if (logger->trace) traces(func_local, 7770000+presrc, logger); /* Calculate mean flux, rmsFlux, and find maxflux and maxchan */ if (m0 > 5) { meanFlux = m1 / m0; if ((m2 / m0 - meanFlux * meanFlux) > 0.0) rmsFlux = sqrt(m2 / m0 - meanFlux * meanFlux); else rmsFlux = 1.0; if (logger->trace) traces(func_local, 7780000+(int)(100.0*m1), logger); } else { if (logger->trace) traces(func_local, 7790000+presrc, logger); continue; } if (logger->trace) traces(func_local, 25000+presrc, logger); sprintf(logger->tmptxt, "ZBE%1d, src%02d allev: %7.1f, EEv: %7.1f, SrcEv: %7.1f, BkgEv: %7.1f, WSrcEv: %7.1f, WBkgEv: %7.1f", eeuser, presrc, allEvents, allEEvents, allSrcEvents, allBkgEvents, allWSrcEvents, allWBkgEvents); logger->logstat = logprint(logger, logger->tmptxt, i5); more_bursts_2: threshold[0] = threshold[4]; threshold[1] = threshold[5]; for (ntime=0; ntimeNumTimeBins-0; ntime++) Tslices[ntime].threshold = threshold[0]; fluxmax = -10000.0; chanmax[burst_num] = -1; if (totcnt_o[eeuser] < 0.25*AllCounts) goto gnu_out_2; /* only check bursts 'rich' user bands */ j = k = 0; for (ntime=0; ntimeNumTimeBins-0; ntime++) { if (Tslices[ntime].dontUse) { j += (Tslices[ntime].dontUse & 1); k += (Tslices[ntime].dontUse & 2); continue; } flux = Tslices[ntime].wflux[presrc]; if (flux > fluxmax) { fluxmax = flux; chanmax[burst_num] = ntime; } } if (chanmax[burst_num] < 0) goto gnu_out_2; if ((chanmax[burst_num] < chanlim) || (abs(logger->NumTimeBins - chanmax[burst_num]) < chanlim)) { Tslices[chanmax[burst_num]].dontUse |= 2; goto more_bursts_2; } if (logger->trace) traces(func_local, 8111000+burst_num, logger); if (logger->trace) traces(func_local, 8112000+chanmax[burst_num], logger); if (Tslices[chanmax[burst_num]].srcWCounts < 6.0) { if (logger->trace) traces(func_local, 8120000+100*presrc+(int)(Tslices[chanmax[burst_num]].srcWCounts), logger); goto gnu_out_2; /* do not accept burst triggers based on very few counts */ } if (backproj->avEE_events > 0.0) { RMSfact = sqrt(Tslices[chanmax[burst_num]].Events / backproj->avEE_events); if ((RMSfact > 0.0) && (rmsFlux > 0.0)) signif = (fluxmax - meanFlux) / (rmsFlux * RMSfact); else signif = 0.0; } else signif = 0.0; /* if (signif > Tslices[chanmax[burst_num]].threshold) { */ if ((signif > Tslices[chanmax[burst_num]].threshold) && (logger->BUsrch > 0)) { /* QQQQQQ if threshold exceeded call TslBurstChk (for the user source set) */ sprintf(logger->tmptxt, "UBXE%1d, S%02d, brst_nm: %2d, chnmx: %4d, flxmx: %6.2lf, mean: %6.2lf, signf: %4.1lf, dntUs bns: %2d %4d, RMSfact: %5.1lf", eeuser, presrc, burst_num, chanmax[burst_num], fluxmax, meanFlux, signif, j, k/2, RMSfact); logger->logstat = logprint(logger, logger->tmptxt, i5); Bburst_num = burst_num; status = TslBurstChk(chanmax[burst_num], meanFlux, rmsFlux, threshold, presrc, eeuser, evRA, evdec, &(Tslices[0]), &(PIFmap[0]), &(B_list[0]), backproj, logger, status); } else goto gnu_out_2; if( status != ISDC_OK ) { RILlogMessage( NULL, Warning_0, "##273## TslBurstChk returned: %d, source %2d skipped!", status, presrc); if (logger->trace) traces(func_local, 8140000+100*presrc+Tslices[chanmax[burst_num]].srcWCounts, logger); goto gnu_out_2; } NdontUse = 0; for (i=0; iNumTimeBins; i++) if (Tslices[i].dontUse > 0) NdontUse++; if (logger->trace) traces(func_local, 1000*presrc+NdontUse, logger); if (logger->trace) traces(func_local, 3000000+1000*presrc+100*eeuser+PIFmap[presrc].BURST_NUM, logger); if (logger->trace) traces(func_local, 7000000+1000*psrc+100*eeuser+PIFmap[presrc].BURST_NUM, logger); reg_mask = 1< burst_num) { burst_num = PIFmap[presrc].BURST_NUM; if (logger->trace) traces(func_local, 4000000+1000*presrc+100*eeuser+burst_num, logger); ALLsrc = backproj->preset_src_N_SRC2[psrc]; BlistNum = logger->b_listnum - 1; sprintf(GOODSRC[ALLsrc].name, "%s", backproj->preset_src_name[psrc]); if ((GOODSRC[ALLsrc].reg_used & reg_mask) == 0) sprintf(regsrcnam, "%s", GOODSRC[ALLsrc].name); else sprintf(regsrcnam, ""); B_list[BlistNum].RA = evRA; B_list[BlistNum].dec = evdec; B_list[BlistNum].chanmax = chanmax[Bburst_num]; status = getxy(evRA, evdec, jmx_id->jmx_unit, &xmm, &ymm, jmx_id, point, logger); B_list[BlistNum].xvalstart = xmm / backproj->pix2mm + backproj->FOV_radius; B_list[BlistNum].yvalstart = ymm / backproj->pix2mm + backproj->FOV_radius; sprintf(logger->tmptxt, "Burst found (user src): %2d, RA/dec: %8.4f %8.4f, name: %s !%s!, BlNum: %4d, NdontUse: %2d, chanmax: %4d", presrc, evRA, evdec, GOODSRC[ALLsrc].name, GOODSRC[ALLsrc].ISDCname, BlistNum, NdontUse, chanmax[Bburst_num]); logger->logstat = logprint(logger, logger->tmptxt, i5); /* save data from burst in 'user source' for 'regfil2' */ sprintf(B_list[BlistNum].regsrctxt, "fk5;point(%8.4f, %8.4f) # point=%s %d text={%s} color=%s\n", evRA, evdec, SHAPE[1], (int)(20+GOODSRC[ALLsrc].bnum*2), regsrcnam, COLOR[eeuser]); sprintf(B_list[BlistNum].regtxtlin, "t_chn %3d %3d mx %3d", B_list[BlistNum].start_chan, B_list[BlistNum].end_chan, B_list[BlistNum].chanmax); GOODSRC[ALLsrc].burstptr[GOODSRC[ALLsrc].bnum] = BlistNum; GOODSRC[ALLsrc].bnum++; /* GOODSRC[ALLsrc].src_pixel_area[eeuser] = 0.01 * PIFmap[presrc].src_pixel_area;*/ /* NL 20150602 */ GOODSRC[ALLsrc].src_pixel_area[eeuser] = 0.01 * PIFmap[presrc].wsrc_pixel_area; /* NL 20160424 */ sprintf(regnam2, "J%1d_%04d%04d%04d_E%02d.reg", jmx_id->jmx_unit+1, backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv, eeuser); if ((GOODSRC[ALLsrc].reg_used & reg_mask) == 0) sprintf(sourcename, backproj->preset_src_name[psrc]); else sprintf(sourcename, ""); GOODSRC[ALLsrc].reg_used |= reg_mask; cmx = GOODSRC[ALLsrc].xx - backproj->FOV_radius; cmy = GOODSRC[ALLsrc].yy - backproj->FOV_radius; rr = sqrt(cmx*cmx + cmy*cmy); status = getxy(evRA, evdec, jmx_id->jmx_unit, &xmm, &ymm, jmx_id, point, logger); if ((fabs(xmm - cmx * backproj->pix2mm) > 0.1) || (fabs(ymm - cmy * backproj->pix2mm) > 0.1)) { sprintf(logger->tmptxt, "Inconsistent RA/dec C"); logger->logstat = logprint(logger, logger->tmptxt, 0); } GOODSRC[ALLsrc].LC_signif = B_list[BlistNum].SLCsignif[eeuser%MAX_LC_EBIN]; if ((logger->develop & 1) == 1) { if ((regfil2 = fopen(regnam2, "at")) != NULL) { fprintf(regfil2, "fk5;point(%8.4f, %8.4f) # point=%s %d text={%s} color=%s\n", evRA, evdec, SHAPE[1], (int)(20+GOODSRC[ALLsrc].bnum*2), sourcename, COLOR[eeuser]); sprintf(logger->tmptxt, "fk5;point(%8.4f, %8.4f) # point=%s %d text={%s} color=%s\n", evRA, evdec, SHAPE[1], (int)(20+GOODSRC[ALLsrc].bnum*2), sourcename, COLOR[eeuser]); logger->logstat = logprint(logger, logger->tmptxt, 0); eeE = eeuser%MAX_LC_EBIN; fprintf(regfil2, "#fk5z IJDst/stp %10.5lf %10.5lf Obst %6.1f cm2 %4.1f R %5.1f sign %5.1f %s XY %5.1f %5.1f\n", Tslices[B_list[BlistNum].start_chan].Tstart, Tslices[B_list[BlistNum].end_chan].Tstop, sh->accumT, GOODSRC[ALLsrc].src_pixel_area[eeuser], rr, B_list[BlistNum].SLCsignif[eeE], B_list[BlistNum].regtxtlin, GOODSRC[ALLsrc].xx, GOODSRC[ALLsrc].yy); fclose(regfil2); sprintf(logger->tmptxt, "#fk5z E%1d IJDst/stp %10.5lf %10.5lf Obst %6.1f cm2 %4.1f R %5.1f sign %5.1f %s XY %5.1f %5.1f\n", eeuser, Tslices[B_list[BlistNum].start_chan].Tstart, Tslices[B_list[BlistNum].end_chan].Tstop, sh->accumT, GOODSRC[ALLsrc].src_pixel_area[eeuser], rr, B_list[BlistNum].SLCsignif[eeE], B_list[BlistNum].regtxtlin, GOODSRC[ALLsrc].xx, GOODSRC[ALLsrc].yy); logger->logstat = logprint(logger, logger->tmptxt, 0); } } burstTime = (PIFmap[presrc].burstTstart[burst_num] + PIFmap[presrc].burstTstop[burst_num]) / 2.0; I_RA = (int)(evRA * 100.0); I_dec = (int)(fabs(evdec * 100.0)); MPdec = 'p'; if (evdec < 0.0) MPdec = 'm'; sprintf(logger->tmptxt, "BF_E%1d, src%1d, B_FLAG: %1d, oldBF: %1d, b_Tstart/stop: %lf %lf, b_Ev: %6.1f, burstTime: %lf", eeuser, presrc, burst_num, oldBURST_NUM, PIFmap[presrc].burstTstart[burst_num], PIFmap[presrc].burstTstop[burst_num], PIFmap[presrc].burstEvents[burst_num], burstTime); logger->logstat = logprint(logger, logger->tmptxt, i5); } else chanmax[burst_num] = 0; if (PIFmap[presrc].BURST_NUM < 24) goto more_bursts_2; gnu_out_2: ; /* gnu_out_2 */ if (logger->trace) traces(func_local, 5000000, logger); if ((PIFmap[presrc].BURST_NUM > oldBURST_NUM) || (logger->USER1_lc == 1) || (PIFmap[presrc].BURST_NUM > 0)) { if (logger->trace) traces(func_local, 5000001, logger); if (PIFmap[presrc].BURST_NUM > 0) { GOODSRC[ALLsrc].preset | 512; if (GOODSRC[ALLsrc].sn[eeuser%MAX_LC_EBIN] < B_list[BlistNum].SLCsignif[eeuser%MAX_LC_EBIN]) GOODSRC[ALLsrc].sn[eeuser%MAX_LC_EBIN] = B_list[BlistNum].SLCsignif[eeuser%MAX_LC_EBIN]; } txtConvert(backproj->preset_src_name[psrc], SourceName, logger); sprintf(gnuname1, "J%1d_lc_%04d%04d%04d_%s_E%02d.gnu", jmx_id->jmx_unit+1, backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv, SourceName, eeuser); sprintf(logger->tmptxt, "GNUNAVN: presrc: %2d ALLsrc: %2d, N_SRC2: %2d %20s J%1d_lc_%04d%04d%04d_%s_E%02d.gnu, Apix: %6.1f", presrc, ALLsrc, logger->N_SRC2, backproj->preset_src_name[psrc], jmx_id->jmx_unit+1, backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv, SourceName, eeuser, PIFmap[presrc].src_pixel_area); logger->logstat = logprint(logger, logger->tmptxt, i5); if ((gnufil1 = fopen(gnuname1, "wt")) != NULL) { ilc = presrc; if ((PIFmap[presrc].BURST_NUM > oldBURST_NUM) && (eeuser == backproj->ee_basic)) { logger->N_SRC3++; /* N_SRC3 controls output of fits-lc */ logger->allsrc_lc[logger->N_SRC3-1] = backproj->preset_src_N_SRC2[psrc]; GOODSRC[ALLsrc].bnum++; } /* fact1 = GOODSRC[ALLsrc].src_pixel_area[eeuser]; fact2 = GOODSRC[ALLsrc].src_backgr_area[eeuser]; for (ntime=0; ntimeNumTimeBins; ntime++) { if (Tslices[ntime].dontUse) continue; Tslices[ntime].wflux[allsrc] *= fact1; Tslices[ntime].wfErr[allsrc] *= fact1; Tslices[ntime].wbflux[allsrc] *= fact2; Tslices[ntime].wbfErr[allsrc] *= fact2; } rmsFlux *= GOODSRC[ALLsrc].src_pixel_area[eeuser]; NLNLNL 20160415 */ status = gnuTslice(presrc, eeuser, rmsFlux, backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv, Tslices, chanmax, logger, gnufil1, status); fclose(gnufil1); gnufil1 = NULL; /* rmsFlux /= (GOODSRC[ALLsrc].src_pixel_area[eeuser] + 0.00001); NLNLNL 20160415 */ } } else if (logger->trace) traces(func_local, 5000007, logger); if (PIFmap[presrc].BURST_NUM > oldBURST_NUM) { if (logger->trace) traces(func_local, 5000002, logger); /* save light curve for later use */ BlistNum = logger->b_listnum - 1; for (i=old_b_listnum; ib_listnum; i++) strcpy(B_list[i].regtxtlin, textline); old_b_listnum = logger->b_listnum; } else { /* if ((backproj->preset_src_flag[psrc] & 5) == 5) { */ if ((backproj->preset_src_flag[psrc] & 3) == 3) { if (logger->trace) traces(func_local, 5000003, logger); txtConvert(backproj->preset_src_name[psrc], SourceName, logger); sprintf(gnuname1, "J%1d_lc_%04d%04d%04d_%s_E%02d.gnu", jmx_id->jmx_unit+1, backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv, SourceName, eeuser); if ((gnufil1 = fopen(gnuname1, "wt")) != NULL) { ilc = presrc; /* rmsFlux *= GOODSRC[ALLsrc].src_pixel_area[eeuser]; NLNLNL 20160415 */ status = gnuTslice(presrc, eeuser, rmsFlux, backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv, Tslices, chanmax, logger, gnufil1, status); fclose(gnufil1); gnufil1 = NULL; /* rmsFlux /= (GOODSRC[ALLsrc].src_pixel_area[eeuser] + 0.00001); NLNLNL 20160415 */ } goto NoTimeBins4; } } /* QQQQQQ */ NoTimeBins2: ; } /* end of loop over preset sources ('psrc' loop variable) - starts in 2430 */ /* *************************************************************************** */ /* *************************************************************************** */ /* * * */ /* * 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 2380 - about 470 lines) * */ /* * * */ /* *************************************************************************** */ /* *************************************************************************** */ sprintf(logger->tmptxt, "##198765## After introduction of preset sources, N_SRC2: %2d, N_SRC3: %2d, eeuser: %2d", logger->N_SRC2, logger->N_SRC3, eeuser); logger->logstat = logprint(logger, logger->tmptxt, i5); for (i=0; iN_SRC2; i++) { sprintf(logger->tmptxt, "##198765## i: %2d, RA/dec: %7.3f %7.3f, name: %30s, ptr: %2d", i, GOODSRC[i].RA, GOODSRC[i].dec, GOODSRC[i].name, logger->allsrc_ptr[i]); logger->logstat = logprint(logger, logger->tmptxt, i5); } if (logger->trace) traces(func_local, 6000000, logger); if ((logger->LC == 0) || (logger->NumTimeBins < 1) || (eeuser > MAX_LC_EBIN)) goto NoTimeBins4; if (logger->trace) traces(func_local, 6000001, logger); /* Section 16: */ /* generate global light curve */ /* calculate weight map for global light curve (in PIFmap[0].wgt_map) */ if (eeuser == 3) PIFmap[0].BURST_NUM = 0; burst_num = oldBURST_NUM = PIFmap[0].BURST_NUM; lstsrc = backproj->backmodels + n_common2; for (i=0; i<128; i++) chanmax[i] = -1; for (i=0; iNumTimeBins; i++) Tslices[i].dontUse &= MMM; /* mask away flags from prev. source */ status = source_weight2(backproj, logger, sh, PIFmap[0].wgt_map, status); for (i=0; i 1.0) PIFmap[0].wgt_map[i] = 1.0; PIFmap[0].wsrc_pixel_area = 0.0; PIFmap[0].src_pixel_area = 0.0; for (i=0; isoft_gr[i] <= 0.0) continue; PIFmap[0].wsrc_pixel_area += PIFmap[0].wgt_map[i]; PIFmap[0].src_pixel_area += 1.0; } allEvents = allEEvents = allSrcEvents = allBkgEvents = allWSrcEvents = allWBkgEvents = allWEpos = allWEzero = 0.0; for (ntime=0; ntimeNumTimeBins; ntime++) { /* Tslices[ntime].dontUse &= 0xFFFD; */ /* Remove old "used-bin" indicators from 'dontUse' parameters */ if (Tslices[ntime].dontUse) continue; allEvents += Tslices[ntime].Events; allEEvents += Tslices[ntime].wEvents; } if (totcnt_o[eeuser] < 0.25*AllCounts) goto gnu_out_7; /* only check bursts 'rich' user bands */ more_bursts_3: /* more_bursts_3 */ /* Find next peak channel in light curve */ if (logger->trace) traces(func_local, 6000002, logger); threshold[0] = threshold[6]; threshold[1] = threshold[7]; for (ntime=0; ntimeNumTimeBins-0; ntime++) Tslices[ntime].threshold = threshold[0]; fluxmax = 0.0; chanmax[burst_num] = -1; j = k = 0; for (ntime=0; ntimeNumTimeBins-0; ntime++) { Tslices[ntime].wflux[1] = 0; Tslices[ntime].wflux[0] = 0; if (Tslices[ntime].dontUse) { j += (Tslices[ntime].dontUse & 1); k += (Tslices[ntime].dontUse & 2); if ((Tslices[ntime].dontUse&1) == 0) Tslices[ntime].wflux[1] = Tslices[ntime].Events; continue; } Tslices[ntime].wflux[1] = Tslices[ntime].Events; Tslices[ntime].wflux[0] = Tslices[ntime].Events; if ((ntime < 0) || (ntime >= logger->NumTimeBins-0)) continue; if (Tslices[ntime].Events > fluxmax) { fluxmax = Tslices[ntime].Events; chanmax[burst_num] = ntime; } } if (chanmax[burst_num] < 0) goto gnu_out_3; if ((chanmax[burst_num] < chanlim) || (abs(logger->NumTimeBins - chanmax[burst_num]) < chanlim)) { Tslices[chanmax[burst_num]].dontUse |= 2; goto more_bursts_3; } if (logger->trace) traces(func_local, 6000003, logger); kscale = logger->NumTimeBins / 511; kscale2 = (int)(511/logger->NumTimeBins); if (kscale2 < 1) kscale2 = 1; kscale++; av_expo = 0.0; k = 0; for (i=0; iNumTimeBins; i+=kscale) { for (j=0; j= logger->NumTimeBins) continue; if (Tslices[i+j].dontUse&1 == 1) continue; av_expo += Tslices[i+j].final_expo; k++; } } if (k == 0) goto gnu_out_3; av_expo /= logger->TIMEstep * (float)(k); if (logger->trace) traces(func_local, 6000004, logger); if (logger->trace) traces(func_local, 1000000+(int)(av_expo*100.0), logger); meanFlux = backproj->avEE_events; if (meanFlux <= 0.0) goto no_time_bins_3; if (logger->trace) traces(func_local, 6000005, logger); if ((chanmax[burst_num] >= 0) && (meanFlux > 0.0)) { RMSfact = sqrt(Tslices[chanmax[burst_num]].Events / meanFlux); } else RMSfact = 0.0; if (RMSfact == 0.0) {RMSfact = 1.0; goto gnu_out_3;} if (rmsFlux0 > 0.0) { signif = (fluxmax - meanFlux) / (rmsFlux0 * RMSfact); } else goto gnu_out_3; if (logger->trace) traces(func_local, 6000006, logger); sprintf(logger->tmptxt, "GBXE%1d, burst: %2d, chmax: %4d, flxmax: %6.2lf, mean: %6.2lf, signif: %4.1lf, dontUse: %2d %4d, RMSfact: %5.1lf, av_expo: %5.3lf", eeuser, burst_num, chanmax[burst_num], fluxmax, meanFlux, signif, j, k/2, RMSfact, av_expo); logger->logstat = logprint(logger, logger->tmptxt, i5); if (logger->trace) traces(func_local, 6000007, logger); /* if (signif > 1.2 * Tslices[chanmax[burst_num]].threshold) { */ /* if (signif > 1.2 * threshold[0]) { */ if ((signif > 1.2 * threshold[0]) && (logger->BUsrch > 0)) { if (logger->trace) traces(func_local, 6000008, logger); status = TslABurstChk(chanmax[burst_num], meanFlux, rmsFlux0, threshold, eeuser, &(Tslices[0]), &(PIFmap[0]), &(B_list[0]), backproj, logger, status); if (logger->trace) traces(func_local, 6000009, logger); NdontUse = 0; for (i=0; iNumTimeBins; i++) if (Tslices[i].dontUse > 0) NdontUse++; if (logger->trace) traces(func_local, 1000+NdontUse, logger); if (logger->trace) traces(func_local, 3300000+100*PIFmap[0].BURST_NUM+burst_num, logger); if (PIFmap[0].BURST_NUM > burst_num) burst_num = PIFmap[0].BURST_NUM; else chanmax[burst_num] = 0; if (PIFmap[0].BURST_NUM < 24) goto more_bursts_3; } gnu_out_3: /* gnu_out_3 */ if (logger->trace) traces(func_local, 6000010, logger); if (rmsFlux0 > 0.0) { if (logger->trace) traces(func_local, 6000011, logger); kscale = logger->NumTimeBins / 511; kscale2 = (int)(511/logger->NumTimeBins); if (kscale2 < 1) kscale2 = 1; kscale++; imin = (511 - logger->NumTimeBins / kscale) / 2; if (logger->NumTimeBins < 256) imin = (511 - logger->NumTimeBins * kscale2 - kscale2 / 2) / 2; if (kscale2 > 2) stepplot = kscale2; else stepplot = 0; sprintf(regnam2, "J%1d_%04d%04d%04d_E%02d.reg", jmx_id->jmx_unit+1, backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv, eeuser); sprintf(gnuname1, "J%1d_lc_%04d%04d%04d_Global_E%02d.gnu", jmx_id->jmx_unit+1, backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv, eeuser); if ((gnufil1 = fopen(gnuname1, "wt")) != NULL) { ilc = 0; status = gnuTslice(1, eeuser, rmsFlux0, backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv, Tslices, chanmax, logger, gnufil1, status); fclose(gnufil1); gnufil1 = NULL; } av_expo = 0.0; k = 0; for (i=0; iNumTimeBins; i+=kscale) { for (j=0; j= logger->NumTimeBins) continue; if (Tslices[i+j].dontUse&1 == 1) continue; av_expo += Tslices[i+j].final_expo; k++; } } if (k == 0) goto gnu_out_7; av_expo /= logger->TIMEstep * (float)(k); if ((logger->develop & 1) == 1) { if ((regfil2 = fopen(regnam2, "at")) != NULL) { /* NLNLNL fprintf(regfil2, "global color=red font=\"helvetica 8 normal\" \n"); */ j = eeuser; fprintf(regfil2, "IMAGE;text( 85.0, -10.0) # text={Energy band: %4.1f to %4.1f keV}\n", jmx_id->escale[sh->pival[j][0]], jmx_id->escale[sh->pival[j][1]]); plsigma = 20.0; /* set 1-sigma y-scale for light curve plot */ if (logger->trace) traces(func_local, 6000012, logger); fprintf(regfil2, "IMAGE;polygon %d %d ", imin-1, (int)(2.0 * plsigma +0.5)); kscale = logger->NumTimeBins / 511; kscale2 = (int)(511/logger->NumTimeBins); if (kscale2 < 1) kscale2 = 1; kscale++; imin = (511 - logger->NumTimeBins / kscale) / 2; if (logger->NumTimeBins < 256) imin = (511 - logger->NumTimeBins * kscale2 - kscale2 / 2) / 2; if (kscale2 > 2) stepplot = kscale2; else stepplot = 0; for (i=0; iNumTimeBins; i+=kscale) { plotv = 0.0; for (j=0; j= logger->NumTimeBins) continue; if (Tslices[i+j].dontUse&1 == 1) continue; if (Tslices[i+j].final_expo == 0.0) continue; plotv += Tslices[i+j].wflux[1] * logger->TIMEstep / Tslices[i+j].final_expo - meanFlux / av_expo; Tslices[i+j].GlobalLC[eeuser%MAX_LC_EBIN] = Tslices[i+j].wflux[1] * logger->TIMEstep / Tslices[i+j].final_expo - meanFlux / av_expo; } sprintf(logger->tmptxt, "##4343V##, E%1d %4d Orig globalLC: %f, normalized global LC: %f", eeuser, i, LCtal, Tslices[i].GlobalLC[eeuser%MAX_LC_EBIN]); logger->logstat = logprint(logger, logger->tmptxt, i5); plotv /= (sqrt((double)(kscale)) * rmsFlux0); plotv *= plsigma; plotv += 0.5 + 2.0 * plsigma; if (plotv > 511.0) plotv = 511.0; if (plotv < 0.0) plotv = 0.0; fprintf(regfil2, "%d %d ", (int)(i/kscale)*kscale2+imin, (int)(plotv)); if (stepplot) fprintf(regfil2, "%d %d ", (int)(i/kscale)*kscale2+imin+stepplot, (int)(plotv)); } if (logger->trace) traces(func_local, 43431, logger); if (logger->trace) traces(func_local, 1000+eeuser, logger); m0 = m1 = m2 = 0.0; for (i=0; iNumTimeBins; i++) { if (Tslices[i].dontUse&1 == 1) continue; m0 += 1.0; m1 += Tslices[i].GlobalLC[eeuser%MAX_LC_EBIN]; m2 += Tslices[i].GlobalLC[eeuser%MAX_LC_EBIN] * Tslices[i].GlobalLC[eeuser%MAX_LC_EBIN]; } if (m0 > 1.0) { m1 /= m0; if ((m2 - m1*m1) > 0.0) m2 = sqrt(m2 - m1 * m1); else m2 = 1.0; } else {m1 = 0.0; m2 = 1.0;} for (i=0; iNumTimeBins; i++) { /* normalize GlobalLC for correlation calculations */ if (Tslices[i].dontUse&1 == 1) continue; LCtal = Tslices[i].GlobalLC[eeuser%MAX_LC_EBIN]; Tslices[i].GlobalLC[eeuser%MAX_LC_EBIN] = (Tslices[i].GlobalLC[eeuser%MAX_LC_EBIN] - m1) / m2; if (logger->trace) traces(func_local, 43432, logger); sprintf(logger->tmptxt, "##4343X##, E%1d %4d Orig globalLC: %f, normalized global LC: %f", eeuser, i, LCtal, Tslices[i].GlobalLC[eeuser%MAX_LC_EBIN]); logger->logstat = logprint(logger, logger->tmptxt, i5); } if (logger->trace) traces(func_local, 43433, logger); fprintf(regfil2, "%d %d\n", (int)((float)(logger->NumTimeBins*kscale2) / (float)(kscale)+imin)+1, (int)(2.0 * plsigma +0.5)); fprintf(regfil2, "IMAGE;line(%d,%d,%d,%d) # dashlist = 5 10 dash = 1\n", imin, (int)(threshold[1]*plsigma), (int)((float)(logger->NumTimeBins*kscale2) / (float)(kscale))+imin+stepplot, (int)(threshold[1]*plsigma)); fprintf(regfil2, "IMAGE;text(%d,%d) # text={0} color = black\n", imin-15, (int)(2.0 * plsigma) - 10); fprintf(regfil2, "IMAGE;text(%d,%d) # text={Channel Width: %4.1f s} color = black\n", (int)(263), (int)(2.0 * plsigma) - 35, (float)(kscale)*logger->TIMEstep); fprintf(regfil2, "IMAGE;text(%d,%d) # text={%d} color = black\n", (int)(511 - imin + 20), (int)(2.0 * plsigma) - 10, logger->NumTimeBins); fprintf(regfil2, "IMAGE;text(%d,%d) # text={Threshold} color = black\n", 475, (int)(threshold[1]*plsigma) - 10); fclose(regfil2); regfil2 = NULL; } } } /* end of Global light curve section. Starts in 2860 */ gnu_out_7: ; if (logger->trace) traces(func_local, 6000020, logger); /* save burst data for 'regfil1' */ if (PIFmap[0].BURST_NUM > oldBURST_NUM) { /* i = burst_number[0]; i %= 5; j = (eeuser - 3) % 3; sprintf(textline, "IMAGE;point(%8.4lf, %8.4lf) # point=%s %d text={} color=%s", 256.0, 256.0, SHAPE[0], 100+i+3*j, COLOR[eeuser]); burst_number[0]++; for (i=old_b_listnum; ib_listnum; i++) strcpy(B_list[i].regsrctxt, textline); */ old_b_listnum = logger->b_listnum; } no_time_bins_3: ; /* QQQQQQ */ /* ************************************************************** */ /* */ /* Section 17: */ /* GENERATE LIGHT CURVES FOR DETECTOR EDGE FIELDS */ /* */ /* ************************************************************** */ if (totcnt_o[eeuser] < 0.25*AllCounts) goto NoTimeBins4; /* only check bursts 'rich' user bands */ /* ************************************************************** */ /* */ /* Initialize PIFmaps for edge transient search */ /* */ /* ************************************************************** */ if (logger->trace) traces(func_local, 44880000, logger); /* if (eeuser == 3) { */ /* NLNLNL 20181209 - do not restrict definition of edgeX/Ymm to E-band 3 ! */ 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); /* } */ status = source_weight2(backproj, logger, sh, PIFmap[1].wgt_map, status); for (i=0; i 1.0) PIFmap[1].wgt_map[i] = 1.0; for (ej=1; ej<9; ej++) { /* beginning of edge field loop 'ej' 1-9. Ends in line 3672 */ if (logger->trace) traces(func_local, 44880000+ej, logger); edgsrc = 89 + ej; for (i=0; iNumTimeBins; i++) Tslices[i].dontUse &= MMM; /* mask away flags from prev. source */ burst_num = oldBURST_NUM = PIFmap[edgsrc].BURST_NUM; for (i=0; isoft_gr[i] <= 0.0) continue; PIFmap[edgsrc].wsrc_pixel_area += PIFmap[edgsrc].wgt_map[i]; PIFmap[edgsrc].src_pixel_area += 1.0; } edgeI = logger->useHexpos; sprintf(logger->tmptxt, "##5343X## Before call to FUNedge: E%2d, edgsrc %2d, ej: %2d, edgeX/Ymm: %6.1f %6.1f : last: %2d", eeuser, edgsrc, ej, edgeXmm[ej], edgeYmm[ej], last); logger->logstat = logprint(logger, logger->tmptxt, 0); logger->useHexpos = 100; status = FUNedge(edgsrc, eeuser, edgeXmm[ej], edgeYmm[ej], jmx_id->jmx_unit, last, jmx_id, logger, backproj, chatter, status); logger->useHexpos = edgeI; if (status < 0) continue; /* NLNLNL 20180925 */ lstsrc = backproj->backmodels + n_common2; if (logger->trace) traces(func_local, 7300000+100*edgsrc+eeuser, logger); status = ISDC_OK; status = j_pif_limits2(lstsrc, edgsrc, backproj, logger, status ); if (logger->trace) traces(func_local, 7311111, logger); if (status < 0) continue; if (logger->trace) traces(func_local, 7310000+100*lstsrc, logger); if (logger->trace) traces(func_local, 7310000+100*lstsrc+n_common2, logger); for (i=0; isoft_gr[i] <= 0.0) continue; backproj->pif_s_pickmap[lstsrc][i] = backproj->pif_s_pickmap[edgsrc][i]; backproj->pif_b_pickmap[lstsrc][i] = backproj->pif_b_pickmap[edgsrc][i]; backproj->pif_maps[lstsrc][i] = backproj->pif_maps[edgsrc][i]; } if (logger->trace) traces(func_local, 7330000, logger); backproj->pif_spix[lstsrc] = backproj->pif_spix[edgsrc]; backproj->pif_bpix[lstsrc] = backproj->pif_bpix[edgsrc]; solut_e[eeuser][lstsrc] = 0.0; if (logger->trace) traces(func_local, 7340000, logger); for (ntime=0; ntimeNumTimeBins; ntime++) { Tslices[ntime].srcWCounts = 0.0; Tslices[ntime].srcCounts = 0.0; Tslices[ntime].bkgWCounts = 0.0; Tslices[ntime].bkgCounts = 0.0; } sprintf(logger->tmptxt, "##4343C## initPIF_LC E%2d, lstsrc %2d, edgsrc: %2d, ej: %2d, XRA/dc: %7.3f %7.3f, Edge%02d", eeuser, lstsrc, edgsrc, ej, evRA, evdec, edgsrc); logger->logstat = logprint(logger, logger->tmptxt, i5); status = initPIF_LC(lstsrc, edgsrc, &(solut_e[eeuser][0]), &(PIFmap[edgsrc]), backproj, sh, logger, status); if (status < 0) continue; /* Extract events for current source & energy from event list and place in timeslices */ /* Calculate fluxes, corrected for exposure, deadtime, greyfilter and efficiency */ if (logger->trace) traces(func_local, 7774, logger); status = ex2trEvTslc(edgsrc,eeuser,&(Tslices[0]),&(bufevents[0]),&(PIFmap[0]),sh,backproj,USERBIN,logger,status); if( status != ISDC_OK ) { RILlogMessage( NULL, Warning_0, "##273## ex2trEvTslc returned: %d, status reset!", status); status = ISDC_OK; } for (ntime=0; ntimeNumTimeBins; ntime++) { /* Tslices[ntime].dontUse &= 0xFFFD; */ /* Remove old "used-bin" indicators from 'dontUse' parameters */ } m0 = m1 = m2 = 0.0; for (ntime=0; ntimeNumTimeBins; ntime++) { if (Tslices[ntime].dontUse) continue; flux = Tslices[ntime].wflux[edgsrc]; m0 += 1.0; m1 += flux; m2 += flux * flux; } if (logger->trace) traces(func_local, 7750000+edgsrc, logger); /* Calculate mean flux, rmsFlux, and find maxflux and maxchan */ if ((m0 > 0.0) && (m1 > 0.0)) { meanFlux = m1 / m0; if ((m2 / m0 - meanFlux * meanFlux) > 0.0) rmsFlux = sqrt(m2 / m0 - meanFlux * meanFlux); else rmsFlux = 1.0; } else continue; if (logger->trace) traces(func_local, 7760000+edgsrc, logger); allEEvents = allSrcEvents = allBkgEvents = allWSrcEvents = allWBkgEvents = allWEpos = allWEzero = 0.0; m0 = m1 = m2 = 0.0; for (ntime=0; ntimeNumTimeBins; ntime++) { if (Tslices[ntime].dontUse) continue; allEEvents += Tslices[ntime].wEvents; allWSrcEvents += Tslices[ntime].srcWCounts; allSrcEvents += Tslices[ntime].srcCounts; allWBkgEvents += Tslices[ntime].bkgWCounts; allBkgEvents += Tslices[ntime].bkgCounts; flux = Tslices[ntime].wflux[edgsrc]; if (fabs(flux-meanFlux) > 3.0*rmsFlux) continue; m0 += 1.0; m1 += flux; m2 += flux * flux; } if (logger->trace) traces(func_local, 7770000+edgsrc, logger); /* Calculate mean flux, rmsFlux, and find maxflux and maxchan */ if (m0 > 5) { meanFlux = m1 / m0; if ((m2 / m0 - meanFlux * meanFlux) > 0.0) rmsFlux = sqrt(m2 / m0 - meanFlux * meanFlux); else rmsFlux = 1.0; } else continue; /* proceed to next edge source */ if (logger->trace) traces(func_local, 25000+edgsrc, logger); sprintf(logger->tmptxt, "EBE%1d, src%2d allev %7.1f EEv %8.1f SrcEv %7.1f BkgEv %7.1f WSrcEv %7.1f WBkgEv %7.1f m012 %5.0f %6.1f %6.1f", eeuser, edgsrc, allEvents, allEEvents, allSrcEvents, allBkgEvents, allWSrcEvents, allWBkgEvents, m0, m1, m2); logger->logstat = logprint(logger, logger->tmptxt, i5); more_bursts_4: /* more_bursts_4 */ fluxmax = -10000.0; threshold[0] = threshold[8]; threshold[1] = threshold[9]; for (ntime=0; ntimeNumTimeBins-0; ntime++) Tslices[ntime].threshold = threshold[0]; chanmax[burst_num] = -1; if (totcnt_o[eeuser] < 0.25*AllCounts) goto gnu_out_4; /* only check bursts 'rich' user bands */ j = k = 0; for (ntime=0; ntimeNumTimeBins-0; ntime++) { if (Tslices[ntime].dontUse) { j += (Tslices[ntime].dontUse & 1); k += (Tslices[ntime].dontUse & 2); continue; } flux = Tslices[ntime].wflux[edgsrc]; if (flux > fluxmax) { fluxmax = flux; chanmax[burst_num] = ntime; } } if (logger->trace) traces(func_local, 25100, logger); if ((chanmax[burst_num] < 1) || (chanmax[burst_num] > logger->NumTimeBins-1)) goto gnu_out_4; sprintf(logger->tmptxt, "EXXE%1d S%02d bstnum %2d chmax %4d flmax %6.2lf mean %6.2lf sgnf %4.1lf NoUse: %2d %4d RMSfct %3.1lf thr %3.1f, cntmax: %5.1f", eeuser, edgsrc, burst_num, chanmax[burst_num], fluxmax, meanFlux, signif, j, k/2, RMSfact, 1.2*Tslices[chanmax[burst_num]].threshold, Tslices[chanmax[burst_num]].srcWCounts); logger->logstat = logprint(logger, logger->tmptxt, i5); if (logger->trace) traces(func_local, 8110000+(int)(10.0*Tslices[chanmax[burst_num]].srcWCounts), logger); if (Tslices[chanmax[burst_num]].srcWCounts < 4.0) { if (logger->trace) traces(func_local, 8120000+(int)(10.0*edgsrc+Tslices[chanmax[burst_num]].srcWCounts),logger); goto gnu_out_4; /* do not accept burst triggers based on very few counts */ } if ((chanmax[burst_num] < chanlim) || (abs(logger->NumTimeBins - chanmax[burst_num]) < chanlim)) { Tslices[chanmax[burst_num]].dontUse |= 2; goto more_bursts_4; } if (backproj->avEE_events > 0.0) RMSfact = sqrt(Tslices[chanmax[burst_num]].Events / backproj->avEE_events); else continue; if ((RMSfact > 0.0) && (rmsFlux > 0.0)) signif = (fluxmax - meanFlux) / (rmsFlux * RMSfact); else continue; sprintf(logger->tmptxt, "EBXE%1d S%02d bst_num %2d chanmax %4d flxmax %6.2lf mean %6.2lf signf %4.1lf dontUsbns: %2d %4d RMSfact %3.1lf thresh %3.1f", eeuser, edgsrc, burst_num, chanmax[burst_num], fluxmax, meanFlux, signif, j, k/2, RMSfact, 1.2*Tslices[chanmax[burst_num]].threshold); logger->logstat = logprint(logger, logger->tmptxt, i5); /* if (signif > 1.2 * Tslices[chanmax[burst_num]].threshold) { */ /* if (signif > 1.2 * threshold[0]) { */ if ((signif > 1.2 * threshold[0]) && (logger->BUsrch > 0)) { status = TslBurstChk(chanmax[burst_num], meanFlux, rmsFlux, threshold, edgsrc, eeuser, evRA, evdec, &(Tslices[0]), &(PIFmap[0]), &(B_list[0]), backproj, logger, status); } else goto gnu_out_4; if( status != ISDC_OK ) { RILlogMessage( NULL, Warning_0, "##273## TslBurstChk returned: %d, source %2d skipped!", status, edgsrc); if (logger->trace) traces(func_local, 8140000+100*edgsrc+Tslices[chanmax[burst_num]].srcWCounts, logger); goto gnu_out_4; } ChanMax = chanmax[burst_num]; NdontUse = 0; for (i=0; iNumTimeBins; i++) if (Tslices[i].dontUse > 0) NdontUse++; if (logger->trace) traces(func_local, 1000*edgsrc+NdontUse, logger); if (logger->trace) traces(func_local, 5000000+1000*edgsrc+100*eeuser+PIFmap[edgsrc].BURST_NUM, logger); if (PIFmap[edgsrc].BURST_NUM > burst_num) { burst_num = PIFmap[edgsrc].BURST_NUM; chanmax[burst_num] = ChanMax; sprintf(logger->tmptxt, "Burst %2d found for edge source#: %3d, chanmax: %3d, NdontUse: %d", burst_num+1, edgsrc, chanmax[burst_num], NdontUse); logger->logstat = logprint(logger, logger->tmptxt, i5); burstTime = (PIFmap[edgsrc].burstTstart[burst_num] + PIFmap[edgsrc].burstTstop[burst_num]) / 2.0; sprintf(logger->tmptxt, "EBF_E%1d, src%1d, B_FLAG: %1d, oldBF: %1d, b_Tstart/stop: %lf %lf, b_Ev: %6.1f, burstTime: %lf", eeuser, edgsrc, burst_num, oldBURST_NUM, PIFmap[edgsrc].burstTstart[burst_num], PIFmap[edgsrc].burstTstop[burst_num], PIFmap[edgsrc].burstEvents[burst_num], burstTime); logger->logstat = logprint(logger, logger->tmptxt, i5); } if (logger->trace) traces(func_local, 4000060, logger); Tslices[chanmax[burst_num]].dontUse |= 2; chanmax[burst_num] = 0; if (PIFmap[edgsrc].BURST_NUM < 24) goto more_bursts_4; gnu_out_4: if (PIFmap[edgsrc].BURST_NUM > oldBURST_NUM) { sprintf(gnuname1, "J%1d_lc_%04d%04d%04d_Edge%02d_E%02d.gnu", jmx_id->jmx_unit+1, backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv, edgsrc, eeuser); if ((gnufil1 = fopen(gnuname1, "wt")) != NULL) { ilc = edgsrc; status = gnuTslice(edgsrc, eeuser, rmsFlux, backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv, Tslices, chanmax, logger, gnufil1, status); fclose(gnufil1); gnufil1 = NULL; } /* save burst data for 'regfil1' */ evX = edgeXmm[edgsrc - 89] / backproj->pix2mm + 256.0; evY = edgeYmm[edgsrc - 89] / backproj->pix2mm + 256.0; /* i = burst_number[edgsrc - 89]; i %= 5; j = (eeuser - 3) % 3; sprintf(textline, "IMAGE;point(%8.4lf, %8.4lf) # point=%s %d text={} color=%s", evX, evY, SHAPE[0], 100+i+j*3, COLOR[eeuser]); burst_number[edgsrc - 89]++; for (i=old_b_listnum; ib_listnum; i++) strcpy(B_list[i].regsrctxt, textline); */ old_b_listnum = logger->b_listnum; } } /* end of edge field loop 'ej' 1-9. Starts in line 3406 */ /* ************************************************************** */ /* */ /* END OF LOOP OVER DETECTOR EDGE FIELDS */ /* */ /* ************************************************************** */ NoTimeBins4: ; finalSKY: ; /* ************************************************************** */ /* */ /* Section 18: */ /* Backproject final residual shadowgram to form sky image */ /* */ /* ************************************************************** */ if (logger->trace) traces(func_local, 14000+logger->detImagesOut, logger); if (logger->trace) traces(func_local, 15000+logger->userImagesOut, logger); if (logger->trace) traces(func_local, 16000+eeuser, logger); backproj->additional = -1; /* logger->detImagesOut = 0 NLNLNL 20171211 */; logger->userImagesOut = 1; for (i=0; ilocalima[i] = 0.0; status = final_sky( eeuser, n_common2, logger->N_SRC2, peakval, theSWG, jmx_id, logger, /* NLNLNL */ backproj, sh, bp, SCWnow, GOODSRC, USERBIN, chatter, status ); /* Changed n_common2 to N_SRC2 ! */ sprintf(logger->tmptxt, "Return from final_sky B, status: %d", status); logger->logstat = logprint(logger, logger->tmptxt, 0); if (status != ISDC_OK) {status += 10; goto exittrace;} if (logger->trace) traces(func_local, 6000, logger); if (logger->trace) traces(func_local, 67000+status, logger); if (logger->LC > 0) { if ( strstr( logger->skyImagesOut, "NONE" ) != NULL) goto noImagesOut; Skymin = 1000.0; Skymax = -1000.0; m01 = m1 = m2 = 0.0; for (i=0; i 0.0) { if (Skymin > USERBIN[eeuser].signific[i]) Skymin = USERBIN[eeuser].signific[i]; if (Skymax < USERBIN[eeuser].signific[i]) Skymax = USERBIN[eeuser].signific[i]; m01 += 1.0; m1 += USERBIN[eeuser].signific[i]; m2 += USERBIN[eeuser].signific[i] * USERBIN[eeuser].signific[i]; } else { USERBIN[eeuser].signific[i] = 0.0; } } if (logger->trace) traces(func_local, 67100, logger); if (logger->trace) traces(func_local, 1000000+m01, logger); /* if (logger->trace) traces(func_local, 1000000+(int)(Skymin*1000.0), logger); if (logger->trace) traces(func_local, 1000000+(int)(Skymax*1000.0), logger); */ if (logger->trace) traces(func_local, 67110, logger); if (m01 > 100.0) { mean1 = m1 / m01; if ((m2 / m01 - mean1 * mean1) > 0.0) rms1 = sqrt(m2 / m01 - mean1 * mean1); else rms1 = 1.0; } else { mean1 = 0.0; rms1 = 1.0; } if (logger->trace) traces(func_local, 67200, logger); if (logger->trace) traces(func_local, 1000000+(int)(mean1 ), logger); if (logger->trace) traces(func_local, 1000000+(int)(rms1 ), logger); Skymin = 1000.0; Skymax = -1000.0; m0 = m1 = m2 = 0.0; for (i=0; i 0.0) { USERBIN[eeuser].signific[i] -= mean1; USERBIN[eeuser].signific[i] /= rms1; if (Skymin > USERBIN[eeuser].signific[i]) Skymin = USERBIN[eeuser].signific[i]; if (Skymax < USERBIN[eeuser].signific[i]) Skymax = USERBIN[eeuser].signific[i]; if (fabs(USERBIN[eeuser].signific[i]) > 4.0) continue; m0 += 1.0; m1 += USERBIN[eeuser].signific[i]; m2 += USERBIN[eeuser].signific[i] * USERBIN[eeuser].signific[i]; } } if (logger->trace) traces(func_local, 67300, logger); if (m0 > 0.0) { mean = m1 / m0; if ((m2 / m0 - mean * mean) > 0.0) rms = sqrt(m2 / m0 - mean * mean); else rms = 1.0; } else { if (logger->trace) traces(func_local, 3880001, logger); } if (logger->trace) traces(func_local, 67400, logger); sprintf(logger->tmptxt, "Signi_skyim E%2d, min/max: %6.1f %6.1f, m0: %5.0f loss: %5.0f, mean: %6.3f %6.3f, rms: %5.3f %5.3f", eeuser, Skymin, Skymax, m01, m01-m0, mean1, mean, rms1, rms); logger->logstat = logprint(logger, logger->tmptxt, i5); if (logger->trace) traces(func_local, 67500, logger); } if (logger->trace) traces(func_local, (int)(GOODSRC[logger->N_SRC2-1].src_pixel_area[eeuser])+2, logger); noImagesOut: if (GOODSRC[logger->N_SRC2-1].src_pixel_area[eeuser] > 1.0) /* NLNLNL 20180925 */ status = fluxerror( eeuser, logger->N_SRC2, peakval, logger, backproj, sh, GOODSRC, status ); else GOODSRC[logger->N_SRC2-1].flux_err[eeuser] = 1.0; /* NLNLNL 20180925 */ } /* end of eeuser loop - begins approx in line 2070 */ backproj->additional = -1; /* QQQQQQ */ /* AAAAAA */ /* ******************************************************************* */ /* */ /* Section 19: */ /* FINAL SUMMARY PRINTOUT */ /* */ /* ******************************************************************* */ /* QQQQQQ */ sprintf(logger->tmptxt, "##298765## Before summary print, N_SRC2: %2d, N_SRC3: %2d", logger->N_SRC2, logger->N_SRC3); logger->logstat = logprint(logger, logger->tmptxt, i5); for (i=0; iN_SRC2; i++) { sprintf(logger->tmptxt, "##298765## i: %2d, RA/dec: %7.3f %7.3f, name: %30s, ptr: %2d", i, GOODSRC[i].RA, GOODSRC[i].dec, GOODSRC[i].name, logger->allsrc_ptr[i]); logger->logstat = logprint(logger, logger->tmptxt, i5); } sprintf(calibname, "c%1d_%04d%04d%04d.bin", jmx_id->jmx_unit+1, backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv); 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, &(PIFmap[0]), &(Tslices[0]), &(B_list[0]), chanmax, logger, chatter, status ); /* ******************************************************************* */ /* */ /* Section 20: */ /* GENERATE SKY-IMAGES FOR ACCEPTED BURST TIME PERIODS */ /* (ONLY FOR BURSTS WITHOUT IDENTIFIED SOURCE ORIGIN) */ /* */ /* ******************************************************************* */ sprintf(logger->tmptxt, "Return from summary_p\n"); logger->logstat = logprint(logger, logger->tmptxt, 0); if (logger->trace) traces(func_local, 300001, logger); if ((logger->LC == 0) || (logger->b_listnum == 0)) goto NoBurstImages; for (i=0; ifitsimage[0][0][i]; /* introduce 'blindspots' corresponding to the 'found' sources */ for (tstsrc=0; tstsrcsky_ydim] = 0; skyim_mask[GOODSRC[tstsrc].sxy - backproj->sky_ydim] = 0; skyim_mask[GOODSRC[tstsrc].sxy + backproj->sky_ydim + 1] = 0; skyim_mask[GOODSRC[tstsrc].sxy - backproj->sky_ydim - 1] = 0; skyim_mask[GOODSRC[tstsrc].sxy + backproj->sky_ydim + 1] = 0; skyim_mask[GOODSRC[tstsrc].sxy - backproj->sky_ydim - 1] = 0; skyim_mask[GOODSRC[tstsrc].sxy + 1] = 0; skyim_mask[GOODSRC[tstsrc].sxy - 1] = 0; } if (logger->trace) traces(func_local, 300002, logger); listlim = logger->b_listnum; for (ibu=0; ibu logger->NumTimeBins-2)) continue; if ((B_list[ibu].end_chan < 1) || (B_list[ibu].end_chan > logger->NumTimeBins-2)) continue; ee_lc = B_list[ibu].ee & logger->LCMAXMASK; if (totcnt_o[ee_lc] < 0.25*AllCounts) continue; /* skip 'meagre' E-bands */ m0 = m1 = 0.0; for (ntime = B_list[ibu].start_chan; ntime<=B_list[ibu].end_chan; ntime++) { if (Tslices[ntime].dontUse&1 == 1) continue; m0 += Gmean[ee_lc ]; m1 += (Tslices[ntime].Gevents[ee_lc ] - Gmean[ee_lc ]); } if (m0 > 0.0) B_list[ibu].GLCsignif[ee_lc ] = m1 / sqrt(m0); else B_list[ibu].GLCsignif[ee_lc ] = 1.0; sprintf(logger->tmptxt, "A%2d srcID%2d E%1d %4X st/endCh: %3d %3d ", ibu, B_list[ibu].sourceID, ee_lc, B_list[ibu].ee, B_list[ibu].start_chan, B_list[ibu].end_chan); if (logger->trace) traces(func_local, 320000+ibu, logger); sprintf(logger->tmptxt2, "SLC/GLCsig: %4.1f %4.1f, RA/dec: %7.3f %7.3f rms: %5.2f b_listnum: %2d", B_list[ibu].SLCsignif[ee_lc], B_list[ibu].GLCsignif[ee_lc], B_list[ibu].RA, B_list[ibu].dec, B_list[ibu].rmsFlux, logger->b_listnum); if (logger->trace) traces(func_local, 330000+ibu, logger); 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, 340000, logger); /* ***************************************************** */ /* */ /* Section 21: */ /* LOOP OVER BURST PERIODS */ /* (loop ends in line 4182 (approx)) */ /* */ /* ***************************************************** */ N_SRC2orig = logger->N_SRC2; preset_src_orig = backproj->preset_src; psrc = backproj->preset_src; if (listlim > 20) listlim = 20; for (ibu=0; ibutrace) traces(func_local, 350000+ibu, logger); if ((B_list[ibu].ee & 0x4000) == 0) continue; /* only use ibu-values selected in 'summary_p' */ for (i=0; i<8; i++) B_list[ibu].src_pixel_area[i] = 0.0; if ((B_list[ibu].sourceID > 0) && (B_list[ibu].sourceID < 90)) { B_list[ibu].ee |= 0x8000; /* indicate that the sourceID is established based on light curves only */ continue; /* skip all identified sources */ } if (logger->trace) traces(func_local, 351000+ibu, logger); /* loop over (first 4 at most) user energy bins */ eelim = sh->numShds - backproj->ee_basic; if (eelim > MAX_LC_EBIN - backproj->ee_basic) eelim = MAX_LC_EBIN - backproj->ee_basic; bstsrc = logger->N_SRC2; old_psrc = psrc; IMA_qual = 0; for (eeuser=backproj->ee_basic; eeuseree_basic; eeuser++) { /* loop over energy bands (ends 4233) */ if (logger->trace) traces(func_local, 352000+eeuser, logger); if (eeuser == backproj->ee_basic) PIFmap[bstsrc].BURST_NUM = 0; burst_num = oldBURST_NUM = PIFmap[bstsrc].BURST_NUM; if (totcnt_o[eeuser] < 0.25*AllCounts) continue; /* skip 'meagre' E-bands */ sxy_skymax = 0; sprintf(logger->tmptxt, "Imaging loop: ibu: %2d, eeuser: %1d, trig: %02X", ibu, eeuser, B_list[ibu].triggers); logger->logstat = logprint(logger, logger->tmptxt, i5); ee_mask = 1<trace) traces(func_local, 352000+ee_mask, logger); if ((B_list[ibu].triggers & ee_mask) != ee_mask) continue; /* skip over uninteresting energy bands */ if (logger->trace) traces(func_local, 352000+eeuser, logger); if (logger->trace) traces(func_local, 300004, logger); for (i=0; itrace) traces(func_local, 300005, logger); sprintf(burst_txt, "BurstImaJ%1d_%04d%04d%04d_E%1d_C%03d_%02d_", jmx_id->jmx_unit+1, backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv, eeuser, B_list[ibu].start_chan, (B_list[ibu].end_chan - B_list[ibu].start_chan)); sprintf(logger->tmptxt, "ibu: %1d, Tchannels: %3d %3d, TimeBins: %4d, E-range: %5d %5d, buffer events: %12ld", ibu, B_list[ibu].start_chan, B_list[ibu].end_chan, logger->NumTimeBins, sh->pival[eeuser][0], sh->pival[eeuser][1], logger->numEvents); logger->logstat = logprint(logger, logger->tmptxt, i5); if (logger->trace) traces(func_local, 300007, logger); status = ISDC_OK; current_start[ibu] = B_list[ibu].start_chan; current_end[ibu] = B_list[ibu].end_chan; current_ibu = ibu; /* m0 = m1 = 0.0; for (ntime = B_list[ibu].start_chan; ntime<=B_list[ibu].end_chan; ntime++) { m0 += Gmean[eeuser]; m1 += (Tslices[ntime].Gevents[eeuser] - Gmean[eeuser]); } if (m0 > 0.0) B_list[ibu].GLCsignif[eeuser] = m1 / sqrt(m0); else B_list[ibu].GLCsignif[eeuser] = 1.0; */ /* ***************************************************** */ /* */ /* Section 22: */ /* FILL BURST SHADOWGRAM */ /* */ /* ***************************************************** */ status = fill_burst_shd(Tslices[B_list[ibu].start_chan].Tstart, Tslices[B_list[ibu].end_chan].Tstop, sh->pival[eeuser][0], sh->pival[eeuser][1], bufevents, logger->numEvents, auxdata, &(shd_burst), logger, chatter, status); events = 0.0; events2 = 0.0; m0 = m1 = m2 = 0.0; for (i=0; isoft_gr[i] <= 0.0) continue; events += shd_burst.shd[i]; m0 += 1.0; m1 += shd_burst.shd[i]; m2 += shd_burst.shd[i] * shd_burst.shd[i]; } if (m1 < 100.0) goto recover1; if (m0 > 0.0) { m1 /= m0; if ((m2 / m0 - m1 * m1) > 0.0) rms = sqrt(m2 / m0 - m1 * m1); else rms = 1.0; } else goto recover1; sprintf(logger->tmptxt, "fill_burst_shd returned %6.0f %6.0f %6ld events, rms: %6.4f, scw events: %7.0lf", events, events2, shd_burst.nEvs, rms, USERBIN[eeuser].totcnt); logger->logstat = logprint(logger, logger->tmptxt, i5); if (logger->trace) traces(func_local, 300008, logger); if( status != ISDC_OK ) { RILlogMessage( NULL, Warning_0, "##273## fill_burst_shd returned: %d, status reset!", status); sprintf(logger->tmptxt, "%s: fill_burst_shd return status: %d", burst_txt, status); logger->logstat = logprint(logger, logger->tmptxt, i5); status = ISDC_OK; } if (logger->trace) traces(func_local, 300009, logger); /* ***************************************************** */ /* */ /* SUBTRACT RESCALED SHADOGRAM FOR FULL SCW */ /* */ /* ***************************************************** */ m0 = m1 = m2 = mean2 = mean3 = 0.0; for (i=0; isoft_gr[i] > 0.0) { m0 += 1.0; m1 += shd_burst.shd[i]; mean2 += ubin_shd[i]; mean3 += fabs(ubin_shd[i]); m2 += shd_burst.shd[i] * shd_burst.shd[i]; } else shd_burst.shd[i] = 0.0; } if (m0 > 0.0) { mean = m1 / m0; mean2 /= m0; mean3 /= m0; if ((m2 / m0 - mean * mean) > 0.0) rms = sqrt(m2 / m0 - mean * mean); else rms = 1.0; } else goto recover1; T_total = (Tslices[logger->NumTimeBins-1].Tstop - Tslices[0].Tstart) * 86400.0; T_burst = (Tslices[current_end[ibu]].Tstop - Tslices[current_start[ibu]].Tstart) * 86400.0; sprintf(logger->tmptxt, "Before ubin normalization: T_burst: %5.1f, T_total: %6.1f, mean_ubin_shd: %6.4f, fabs: %6.1f", T_burst, T_total, mean2, mean3); logger->logstat = logprint(logger, logger->tmptxt, i5); sprintf(logger->tmptxt, "Before ubin normalization: m0: %6.1f, mean: %6.3f, rms: %6.4f", m0, mean, rms); logger->logstat = logprint(logger, logger->tmptxt, i5); m0 = m1 = m2 = 0.0; for (i=0; isoft_gr[i] > 0.0) { shd_burst.shd[i] -= (ubin_shd[i] * T_burst / T_total); m0 += 1.0; m1 += shd_burst.shd[i]; m2 += shd_burst.shd[i] * shd_burst.shd[i]; } else shd_burst.shd[i] = 0.0; } if (m0 > 0.0) { mean = m1 / m0; if ((m2 / m0 - mean * mean) > 0.0) rms = sqrt(m2 / m0 - mean * mean); else rms = 1.0; } else goto NoPointSrc1; sprintf(logger->tmptxt, "After ubin normalization: m0: %6.1f, mean: %6.3f, rms: %6.4f", m0, mean, rms); logger->logstat = logprint(logger, logger->tmptxt, i5); m0 = m1 = m2 = 0.0; for (i=0; isoft_gr[i] > 0.0) { sh->f_shadgram[eeuser][i] = shd_burst.shd[i] - mean; m0 += 1.0; m1 += sh->f_shadgram[eeuser][i]; m2 += sh->f_shadgram[eeuser][i] * sh->f_shadgram[eeuser][i]; } else sh->f_shadgram[eeuser][i] = 0.0; } if (m0 > 0.0) { mean = m1 / m0; if ((m2 / m0 - mean * mean) > 0.0) rms = sqrt(m2 / m0 - mean * mean); else rms = 1.0; } else goto NoPointSrc1; sprintf(logger->tmptxt, "After zero normalization: m0: %6.1f, mean: %6.3f, rms: %6.4f", m0, mean, rms); logger->logstat = logprint(logger, logger->tmptxt, i5); for (i=0; isoft_gr[i] > 0.0) { sh->f_shadgram[eeuser][i] = shd_burst.shd[i]; } else sh->f_shadgram[eeuser][i] = 0.0; } /* ***************************************************** */ /* */ /* Section 23: */ /* IMAGE BACKPROJECTION */ /* */ /* ***************************************************** */ logger->burstimage = 1; status = j_fitprep(eeuser, theSWG, jmx_id, logger, backproj, sh, bp, SCWnow, USERBIN, chatter, status); logger->burstimage = 0; sprintf(logger->tmptxt, "work2d: after fitprep: E: %2d, totcnt: %7.1f", eeuser, sh->totcnt[eeuser]); logger->logstat = logprint(logger, logger->tmptxt, i5); burst_ima_qual[ibu][eeuser] = 0; Skymin = 1000.0; Skymax = -1000.0; m01 = m1 = m2 = 0.0; for (i=0; i 0.0) && (USERBIN[eeuser].variance[i] > 0.0)) { burst_skyim[ibu][eeuser][i] = USERBIN[eeuser].fst_imag[i] / sqrt(USERBIN[eeuser].variance[i] + 5.0); if (Skymin > burst_skyim[ibu][eeuser][i]) Skymin = burst_skyim[ibu][eeuser][i]; if (Skymax < burst_skyim[ibu][eeuser][i]) Skymax = burst_skyim[ibu][eeuser][i]; m01 += 1.0; m1 += burst_skyim[ibu][eeuser][i]; m2 += burst_skyim[ibu][eeuser][i] * burst_skyim[ibu][eeuser][i]; } else { skyim_mask[i] = 0.0; burst_skyim[ibu][eeuser][i] = 0.0; } } if (m01 > 100.0) { mean1 = m1 / m01; if ((m2 / m01 - mean1 * mean1) > 0.0) rms1 = sqrt(m2 / m01 - mean1 * mean1); else rms1 = 1.0; } else { if (logger->trace) traces(func_local, 3890000, logger); burst_ima_qual[ibu][eeuser] = 0; } Skymin = 1000.0; Skymax = -1000.0; m0 = m1 = m2 = 0.0; for (i=0; i burst_skyim[ibu][eeuser][i]) Skymin = burst_skyim[ibu][eeuser][i]; if (Skymax < burst_skyim[ibu][eeuser][i]) { Skymax = burst_skyim[ibu][eeuser][i]; sxy_skymax = i; } if (fabs(burst_skyim[ibu][eeuser][i]) > 4.0) continue; m0 += 1.0; m1 += burst_skyim[ibu][eeuser][i]; m2 += burst_skyim[ibu][eeuser][i] * burst_skyim[ibu][eeuser][i]; } B_list[ibu].sxy_skymax[eeuser] = sxy_skymax; /* if ((ee_lc >= backproj->ee_basic) && (burst_ima_qual[ibu][ee_lc] > 0)) { */ logger->burst_image = 1; logger->burst_Tstart = Tslices[current_start[ibu]].Tstart; logger->burst_Tstop = Tslices[current_end[ibu]].Tstop; /* if (logger->trace) traces(func_local, 9780400+ibu, logger); if (logger->trace) traces(func_local, 9780400+ee_lc, logger); */ for (i=0; ilocalima[i] = NAN; else logger->localima[i] = burst_skyim[ibu][eeuser][i]; } if (logger->burstImagesOut > 0) { status = fits_test_output(burst_txt, burst_skyim[ibu][eeuser], 511, logger, chatter, status ); status = final_sky( eeuser, n_common2, n_common2, peakval, theSWG, jmx_id, logger, backproj, sh, bp, SCWnow, GOODSRC, USERBIN, chatter, status ); /* NLNLNL 20180914 */ } logger->burst_image = 0; if (m0 > 100.0) { mean = m1 / m0; if ((m2 / m0 - mean * mean) > 0.0) rms = sqrt(m2 / m0 - mean * mean); else rms = 1.0; } else { if (logger->trace) traces(func_local, 3890001, logger); burst_ima_qual[ibu][eeuser] = 0; } xxx = (float)((int)(sxy_skymax / backproj->sky_ydim)); yyy = (float)(sxy_skymax % backproj->sky_ydim); B_list[ibu].ISsignif[eeuser] = (Skymax - mean) / rms; sprintf(logger->tmptxt, "Bst_im %2d E%1d, min/max: %4.1f %5.2f, x/y: %5.1f %5.1f, m0: %5.0f loss: %5.0f, av: %6.3f %6.3f, rms: %5.3f %5.3f, signif: %4.1f", ibu, eeuser, Skymin, Skymax, xxx, yyy, m01, m01-m0, mean1, mean, rms1, rms, B_list[ibu].ISsignif[eeuser]); logger->logstat = logprint(logger, logger->tmptxt, i5); /* determine RA and dec of the source candidates found at this energy */ xmm = (xxx - backproj->FOV_radius) * backproj->pix2mm; ymm = (yyy - backproj->FOV_radius) * backproj->pix2mm; getRAdec(xmm, ymm, jmx_id->jmx_unit, &s_RA, &s_dec, point, logger, jmx_id); sprintf(logger->tmptxt, "Bst_im2: ibu: %1d, xmm/ymm: %6.1f %6.1f, RA/dec: %7.3f %7.3f", ibu, xmm, ymm, s_RA, s_dec); logger->logstat = logprint(logger, logger->tmptxt, i5); if (B_list[ibu].ISsignif[eeuser] > NBsigniflim) { /* ends in 4218 */ /* ***************************************************** */ /* SATISFACTORY DOMINATING SOURCE FOUND */ /* (EXCESS > 4 * LOCAL MAP RMS) */ /* ***************************************************** */ IMA_qual = 1; B_list[ibu].ee = 0xE000 + eeuser; /* check candidate against 'found' and 'preset' sources */ /* (including already accepted 'new' burst candidates) */ newflag = 1; for (tstsrc=0; tstsrcN_SRC2; tstsrc++) { diff_x = xxx - GOODSRC[tstsrc].xx; diff_y = yyy - GOODSRC[tstsrc].yy; diff = diff_x * diff_x + diff_y *diff_y; diff = sqrt(diff); if (diff < 1.5) {j = tstsrc; newflag = 0;} } if (logger->trace) traces(func_local, 3910000, logger); if (newflag) if (logger->trace) traces(func_local, 3920000+logger->N_SRC2, logger); if (B_list[ibu].ISsignif[eeuser] > NBsigniflim) if (logger->trace) traces(func_local, 3930000+logger->N_SRC2, logger); if ((newflag) || (B_list[ibu].ISsignif[eeuser] > NBsigniflim)) { if (logger->trace) traces(func_local, 3940000, logger); NBsigniflim = B_list[ibu].ISsignif[eeuser]; if (logger->trace) traces(func_local, 3950000+(int)(NBsigniflim * 10.0), logger); GOODSRC[logger->N_SRC2].xx = backproj->preset_src_xx[psrc] = xxx; GOODSRC[logger->N_SRC2].yy = backproj->preset_src_yy[psrc] = yyy; xmm = (xxx - backproj->FOV_radius) * backproj->pix2mm; ymm = (yyy - backproj->FOV_radius) * backproj->pix2mm; getRAdec(xmm, ymm, jmx_id->jmx_unit, &s_RA, &s_dec, point, logger, jmx_id); GOODSRC[logger->N_SRC2].RA = backproj->preset_src_RA[psrc] = s_RA; GOODSRC[logger->N_SRC2].dec = backproj->preset_src_dec[psrc] = s_dec; i = srcidentify2(theSWG, s_RA, s_dec, backproj->preset_src_name[psrc], backproj->preset_src_Iname[psrc], &catflag, jmx_id, point, logger); backproj->preset_src_Iname[psrc][16] = 0; strcpy(GOODSRC[logger->N_SRC2].name, backproj->preset_src_name[psrc]); strcpy(GOODSRC[logger->N_SRC2].ISDCname, backproj->preset_src_Iname[psrc]); B_list[ibu].IDima[eeuser] = logger->N_SRC2; B_list[ibu].sourceID = logger->N_SRC2; B_list[ibu].ix = (int)(xxx+0.5); B_list[ibu].iy = (int)(yyy+0.5); B_list[ibu].RA = s_RA; B_list[ibu].dec = s_dec; B_list[ibu].xvalstart = xmm / backproj->pix2mm + backproj->FOV_radius; B_list[ibu].yvalstart = ymm / backproj->pix2mm + backproj->FOV_radius; strcpy(B_list[ibu].name[eeuser], backproj->preset_src_name[psrc]); B_list[ibu].ee = 0xE000+eeuser; sprintf(logger->tmptxt, "New burst src: X/Y: %5.1f %5.1f %s, RA/dec: %7.3f %7.3f, psrc: %2d, N_SRC2: %2d, %s, ibu: %d, i: %d", xxx, yyy, backproj->preset_src_name[psrc], backproj->preset_src_RA[psrc], backproj->preset_src_dec[psrc], psrc+1, logger->N_SRC2+1, GOODSRC[logger->N_SRC2].name, ibu, i); logger->logstat = logprint(logger, logger->tmptxt, i5); preset_ibu[psrc] = ibu; ibu_preset[ibu ] = psrc; ibu_N_SRC2[ibu ] = logger->N_SRC2; logger->new_detmap = 1; backproj->preset_src_N_SRC2[psrc] = logger->N_SRC2; sprintf(logger->tmptxt, "##4547## n_common2: %1d, psrc: %2d, X/Y: %7.2f %7.2f, backproN_SRC2: %2d, loggerN_SRC2: %2d, eeuser: %1d", n_common2, psrc, backproj->preset_src_xx[psrc], backproj->preset_src_yy[psrc], backproj->preset_src_N_SRC2[psrc], logger->N_SRC2, eeuser); 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 = 77; sxy = backproj->preset_src_xx[psrc] * backproj->sky_ydim + backproj->preset_src_yy[psrc]; GOODSRC[backproj->preset_src_N_SRC2[psrc]].sxy = sxy; sprintf(GOODSRC[backproj->preset_src_N_SRC2[psrc]].name, "%s", backproj->preset_src_name[psrc]); backproj->preset_src++; psrc++; if (newflag) { logger->N_SRC2++; initGOOD(eeuser, GOODSRC, logger, status); newflag = 0; } if (logger->trace) traces(func_local, 3960000+logger->N_SRC2, logger); } else { sprintf(logger->tmptxt, "Source refound: %32s, RA/dec: %7.3f %7.3f, N_SRC2: %2d", GOODSRC[j].name, GOODSRC[j].RA, GOODSRC[j].dec, j); } } NoPointSrc1: recover1: for (i=0; iLCMAXMASK; for (i=0; itrace) traces(func_local, 3971000+i, logger); } } /* end of loop over energies (eeuser) (begins 3843) */ ee_lc = B_list[ibu].ee & logger->LCMAXMASK; if (IMA_qual > 0) burst_ima_qual[ibu][ee_lc] = 1; } /* end of loop over burst detections (ibu) (begins 3766) */ sprintf(logger->tmptxt, "##398765## After analysis of 'global bursts' N_SRC2: %2d, N_SRC3: %2d", logger->N_SRC2, logger->N_SRC3); logger->logstat = logprint(logger, logger->tmptxt, i5); for (i=0; iN_SRC2; i++) { sprintf(logger->tmptxt, "##398765## i: %2d, RA/dec: %7.3f %7.3f, name: %30s, ptr: %2d", i, GOODSRC[i].RA, GOODSRC[i].dec, GOODSRC[i].name, logger->allsrc_ptr[i]); logger->logstat = logprint(logger, logger->tmptxt, i5); } /* SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS */ /* Section 24: */ /* generate light curves for dominant source found during burst time intervals */ /* the generation logic is similar to the one used for 'user-sources' * (maybe better 'found sources', because refined pifmaps have not been generated NL 20150423 ?): * - an outer loop over the 'user energy bands' * - an inner loop over the new, dominant, sources (max one per E-band) * */ eelim = sh->numShds - backproj->ee_basic; if (eelim > MAX_LC_EBIN - backproj->ee_basic) eelim = MAX_LC_EBIN - backproj->ee_basic; logger->N_SRC2 = N_SRC2orig; if (logger->trace) traces(func_local, 470100+logger->N_SRC2, logger); if (preset_src_orig == backproj->preset_src) goto NoBurstImages; for (i=0; iNumTimeBins; i++) Tslices[i].dontUse &= 1; /* mask away peak count ch. flags from prev. sources */ for (eeuser=backproj->ee_basic; eeuseree_basic; eeuser++) { /* loop over 'rich' E-bands (end 4454) */ if (eeuser == backproj->ee_basic) PIFmap[bstsrc].BURST_NUM = 0; burst_num = oldBURST_NUM = PIFmap[bstsrc].BURST_NUM; if (totcnt_o[eeuser] < 0.25*AllCounts) continue; /* skip 'meagre' E-bands */ status = source_weight2(backproj, logger, sh, PIFmap[1].wgt_map, status); for (i=0; i 1.0) PIFmap[1].wgt_map[i] = 1.0; /* loop over new sources, found in global-lc_sky-images (end 4458) */ for (psrc=preset_src_orig; psrcpreset_src; psrc++) { ibu = preset_ibu[psrc]; backproj->srclist[n_common2] = backproj->preset_src_N_SRC2[psrc]; backproj->additional = backproj->preset_src_N_SRC2[psrc]; status = final_fit( eeuser, n_common2, solut_e, jmx_id, logger, backproj, sh, SCWnow, GOODSRC, USERBIN, chatter, status); if (logger->trace) traces(func_local, 471100+status, logger); if (logger->trace) traces(func_local, 723000+logger->N_SRC2, logger); if (logger->trace) traces(func_local, 623100+eeuser, logger); bstsrc = backproj->backmodels + backproj->preset_src_N_SRC2[psrc]; lstsrc = backproj->backmodels + n_common2; for (i=0; i<128; i++) chanmax[i] = -1; if (eeuser == 3) PIFmap[bstsrc].BURST_NUM = 0; burst_num = oldBURST_NUM = PIFmap[bstsrc].BURST_NUM; if ((logger->LC == 0) || (logger->numEvents < logger->NumTimeBins)) goto NoTimeBins2; if (logger->trace) traces(func_local, 700000+eeuser*100+ bstsrc, logger); sprintf(logger->tmptxt, "##4343D## initPIF_LC E%2d, lstsrc %2d, bstsrc: %2d, psrc: %2d, RA/dec: %7.3f %7.3f, %20s", eeuser, lstsrc, edgsrc, psrc, s_RA, s_dec, backproj->preset_src_name[psrc]); logger->logstat = logprint(logger, logger->tmptxt, i5); /* transfer PIF-maps to structure PIFmap */ status = initPIF_LC(lstsrc, bstsrc, &(solut_e[eeuser][0]), &(PIFmap[bstsrc]), backproj, sh, logger, status); if (logger->trace) traces(func_local, 310017, logger); if (status < 0) goto nextbstsrc; /* Extract events for current source & energy from event list and place in timeslices */ /* Calculate fluxes, corrected for exposure, deadtime, greyfilter and efficiency */ for (i=0; iNumTimeBins; i++) Tslices[i].dontUse &= 1; /* mask away flags from prev. sources */ if (logger->trace) traces(func_local, 7775, logger); status = ex2trEvTslc(bstsrc, eeuser, &(Tslices[0]), &(bufevents[0]), &(PIFmap[0]), sh, backproj, USERBIN, logger, status); if( status != ISDC_OK ) { if (logger->trace) traces(func_local, 399012, logger); RILlogMessage( NULL, Warning_0, "##273## ex2trEvTslc returned: %d, status reset!", status); status = ISDC_OK; } for (ntime=0; ntimeNumTimeBins; ntime++) { /* sprintf(logger->tmptxt, "extrEvt: bstsrc: %3d, ntime: %3d, wflux: %7.3f %7.3f, dontUse: %d", bstsrc, ntime, Tslices[ntime].wflux[bstsrc], Tslices[ntime].wbflux[bstsrc], Tslices[ntime].dontUse); logger->logstat = logprint(logger, logger->tmptxt, i5); */ Tslices[ntime].srcWCounts = 0.0; Tslices[ntime].srcCounts = 0.0; Tslices[ntime].bkgWCounts = 0.0; Tslices[ntime].bkgCounts = 0.0; } if (logger->trace) traces(func_local, 600002, logger); /* Calculate mean flux, rmsFlux, and find maxflux and maxchan */ maxflux = 0.0; maxchan = -1; m0 = m1 = m2 = 0.0; for (ntime=0; ntimeNumTimeBins; ntime++) { if (Tslices[ntime].dontUse) continue; flux = Tslices[ntime].wflux[bstsrc]; m0 += 1.0; m1 += flux; m2 += flux * flux; if (maxflux < flux) {maxflux = flux; maxchan = ntime;} if ((ntime > 5) && (ntime < 10)) { sprintf(logger->tmptxt, "ExtrLCburstA: ntime: %3d, flux: %5.2f, m0/m1/m2: %4.0f %6.3f %7.3f", ntime, flux, m0, m1, m2); logger->logstat = logprint(logger, logger->tmptxt, i5); } } if ((m0 > 0.0) && (m1 > 0.0)) { meanFlux = m1 / m0; if ((m2 / m0 - meanFlux * meanFlux) > 0.0) rmsFlux = sqrt(m2 / m0 - meanFlux * meanFlux); else rmsFlux = 1.0; } else { meanFlux = 0.0; rmsFlux = 99.9; goto nextbstsrc; } if (logger->trace) traces(func_local, 610003, logger); allEEvents = allSrcEvents = allBkgEvents = allWSrcEvents = allWBkgEvents = allWEpos = allWEzero = 0.0; m0 = m1 = m2 = 0.0; for (ntime=0; ntimeNumTimeBins; ntime++) { if (Tslices[ntime].dontUse) continue; allEEvents += Tslices[ntime].wEvents; allWSrcEvents += Tslices[ntime].srcWCounts; allSrcEvents += Tslices[ntime].srcCounts; allWBkgEvents += Tslices[ntime].bkgWCounts; allBkgEvents += Tslices[ntime].bkgCounts; flux= (Tslices[ntime].wflux[bstsrc] - meanFlux) / rmsFlux; if (fabs(flux) > 3.0) continue; m0 += 1.0; m1 += flux; m2 += flux * flux; if ((ntime > 5) && (ntime < 10)) { sprintf(logger->tmptxt, "ExtrLCburstB: ntime: %3d, flux: %5.2f, m0/m1/m2: %4.0f %6.3f %7.3f", ntime, flux, m0, m1, m2); logger->logstat = logprint(logger, logger->tmptxt, i5); } } if (m0 > 5) { meanFlux = m1 / m0; if ((m2 / m0 - meanFlux * meanFlux) > 0.0) rmsFlux = sqrt(m2 / m0 - meanFlux * meanFlux); else rmsFlux = 1.0; } else { meanFlux = 0.0; rmsFlux = 99.9; goto nextbstsrc; } if (logger->trace) traces(func_local, 610004, logger); sprintf(logger->tmptxt, "BBE%1d, src%2d allev: %7.1f, allEEv: %7.1f, allSrcEv: %7.1f, allBkgEv: %7.1f, allWSrcEv: %7.1f, allWBkgEv: %7.1f, m012: %5.0f %6.1f %6.1f", eeuser, bstsrc, allEvents, allEEvents, allSrcEvents, allBkgEvents, allWSrcEvents, allWBkgEvents, m0, m1, m2); logger->logstat = logprint(logger, logger->tmptxt, i5); if (logger->trace) traces(func_local, 600006, logger); B_list[ibu].src_pixel_area[eeuser] = 0.01 * PIFmap->wsrc_pixel_area; /* NLNLNL 20160224 */ strcpy(B_list[ibu].name[eeuser], backproj->preset_src_name[psrc]); txtConvert(backproj->preset_src_name[psrc], SourceName, logger); sprintf(gnuname1, "J%1d_lc_%04d%04d%04d_%s_E%02d.gnu", jmx_id->jmx_unit+1, backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv, SourceName, eeuser); if ((gnufil1 = fopen(gnuname1, "wt")) != NULL) { ilc = bstsrc; if (eeuser == (B_list[ibu].ee & logger->LCMAXMASK)) logger->N_SRC3++; /* N_SRC3 controls output of fits-lc */ logger->N_SRCT = logger->N_SRC2; if (logger->N_SRCT < logger->N_SRC3) logger->N_SRCT = logger->N_SRC3; logger->allsrc_lc[logger->N_SRC3-1] = backproj->preset_src_N_SRC2[psrc]; logger->allsrc_ptr[logger->N_SRCT-1] = backproj->preset_src_N_SRC2[psrc]; GOODSRC[logger->N_SRC3-1].bnum++; /* for (ntime=1; ntimeNumTimeBins-1; ntime++) { if (Tslices[ntime].dontUse) continue; Tslices[ntime].flux *= GOODSRC[ALLsrc].src_pixel_area[eeuser]; Tslices[ntime].fl_err *= GOODSRC[ALLsrc].src_pixel_area[eeuser]; Tslices[ntime].bflux *= GOODSRC[ALLsrc].backgr_pixel_area[eeuser]; Tslices[ntime].bfl_err *= GOODSRC[ALLsrc].backgr_pixel_area[eeuser]; } rmsFlux *= GOODSRC[ALLsrc].src_pixel_area[eeuser]; */ status = gnuTslice(bstsrc, eeuser, rmsFlux, backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv, Tslices, chanmax, logger, gnufil1, status); fclose(gnufil1); gnufil1 = NULL; } nextbstsrc: ; } /* end of loop over new, dominant sources (psrc) begins in line 4266 (approx) */ /* ***************************************************** */ /* */ /* END OF LOOP OVER NEW, DOMINANT, SOURCES */ /* */ /* ***************************************************** */ } /* end of loop over energies (eeuser) begins in line 4185 (approx) */ /* ******************************************************** */ /* */ /* END OF EEUSER LOOP */ /* */ /* ******************************************************** */ sprintf(logger->tmptxt, "##498765## After final loop over dominant sources, N_SRC2: %2d, N_SRC3: %2d", logger->N_SRC2, logger->N_SRC3); logger->logstat = logprint(logger, logger->tmptxt, i5); for (i=0; iN_SRC2; i++) { sprintf(logger->tmptxt, "##498765## i: %2d, RA/dec: %7.3f %7.3f, name: %30s, ptr: %2d", i, GOODSRC[i].RA, GOODSRC[i].dec, GOODSRC[i].name, logger->allsrc_ptr[i]); logger->logstat = logprint(logger, logger->tmptxt, i5); } if (logger->trace) traces(func_local, 783000, logger); /* Section 25: */ /* print full list of burst detections */ /* and combine identical source candidates into short list of candidates */ /* eliminate candidates whose light curves have already been searched for bursts (such cases should not exist) */ for (ibu=0; ibub_listnum; ibu++) { if (B_list[ibu].sourceID < 0) continue; ee_lc = B_list[ibu].ee & logger->LCMAXMASK; if (totcnt_o[ee_lc] < 0.25*AllCounts) continue; /* skip 'meagre' E-bands */ sprintf(logger->tmptxt, "B%2d srcID%2d ID%2d IDima%2d Etrig %1d %4X st/end/maxChan: %3d %3d %3d, SGsig: %4.1f %4.1f, Ix/y/sign:", ibu, B_list[ibu].sourceID, B_list[ibu].ID[ee_lc], B_list[ibu].IDima[ee_lc], ee_lc, B_list[ibu].ee, B_list[ibu].start_chan, B_list[ibu].end_chan, B_list[ibu].chanmax, B_list[ibu].SLCsignif[ee_lc], B_list[ibu].GLCsignif[ee_lc]); for (j=0; jee_basic; sprintf(logger->tmptxt2, " %3d %3d %4.1f", (int)(B_list[ibu].sxy_skymax[jj] / backproj->sky_ydim), B_list[ibu].sxy_skymax[jj] % backproj->sky_ydim, B_list[ibu].ISsignif[jj]); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); } logger->logstat = logprint(logger, logger->tmptxt, i5); } NoBurstImages: ; /* NoBurstImages: */ status = ISDC_OK; if (logger->LC == 0) goto slut; k = 0; jlim = sh->numShds; if (jlim > MAX_LC_EBIN) jlim = MAX_LC_EBIN; for (ibu=0; ibub_listnum; ibu++) { ee_lc = B_list[ibu].ee & logger->LCMAXMASK; if (totcnt_o[ee_lc] < 0.25*AllCounts) continue; /* skip 'meagre' E-bands */ if (logger->trace) traces(func_local, 1000000 + logger->b_listnum*10000 + ee_lc*100 + jlim, logger); if ((B_list[ibu].ee & 0x4000) == 0) continue; /* use only primary bursts from summary_p and from imaging */ if (B_list[ibu].end_chan == 0) continue; /* use only sensible bursts */ sprintf(logger->tmptxt, "J%1d_%04d%04d%04d E%d b# %2d, Id/S/G/I Id/I:", jmx_id->jmx_unit+1 ,backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv, ee_lc, ibu); for (j=backproj->ee_basic; jtrace) traces(func_local, 2100000+j, logger); if (logger->trace) traces(func_local, 1000000+(int)(AllCounts), logger); if (logger->trace) traces(func_local, 100000+(int)(sh->totcnt[j]), logger); if (totcnt_o[j] < 0.25*AllCounts) continue; /* skip 'meagre' E-bands */ if (B_list[ibu].IDima[j] < 0) sprintf(Stext, "--"); else { if (B_list[ibu].IDima[j] < 100) sprintf(Stext, "%02d", B_list[ibu].IDima[j]); else sprintf(Stext, "U%1d", B_list[ibu].IDima[j]-100); } sprintf(logger->tmptxt2, " %02d %4.1f %4.1f %4.1f %2s %4.1f |", B_list[ibu].ID[j], B_list[ibu].SLCsignif[j], B_list[ibu].GLCsignif[j], B_list[ibu].ISsignif[j], Stext, B_list[ibu].Isignif[j]); if ((strlen(logger->tmptxt) + strlen(logger->tmptxt2)) < MAX_STR_LEN) strcat(logger->tmptxt, logger->tmptxt2); if (logger->trace) traces(func_local, 3100000+j, logger); } logger->logstat = logprint(logger, logger->tmptxt, i5); ee_lc = B_list[ibu].ee & logger->LCMAXMASK; sprintf(logger->tmptxt, "b# %02d, b_listnum: %2d, triggers: %02X, %s, EE: %04X, eeuser: %d", ibu, logger->b_listnum, B_list[ibu].triggers, B_list[ibu].name, B_list[ibu].ee, ee_lc); logger->logstat = logprint(logger, logger->tmptxt, i5); if (logger->trace) traces(func_local, 1000000 + logger->b_listnum*10000 + ee_lc*100 + jlim, logger); } sprintf(logger->tmptxt, " "); logger->logstat = logprint(logger, logger->tmptxt, i5); /* ***************************************************************** */ /* */ /* Section 26: */ /* FINAL OUTPUT OF SELECTED BURST LIGHT CURVES TO REGFILE */ /* */ /* ***************************************************************** */ /* 4444444444444444444444444444444444444444444444444444444444444444444444 */ k_offset = 1; ee_lc = -1; if (logger->trace) traces(func_local, 9780008, logger); if (logger->trace) traces(func_local, 9781000+logger->b_listnum, logger); for (ibu=0; ibub_listnum; ibu++) { /* loop over burst periods [ibu] (ends in 4871) S026L_ibu */ ee_lc = B_list[ibu].ee & logger->LCMAXMASK; B_AllCnts = AllCounts * (B_list[ibu].end_chan - B_list[ibu].start_chan + 1) / logger->NumTimeBins; if (logger->trace) traces(func_local, 9782000+ibu , logger); if (logger->trace) traces(func_local, 9782000+ee_lc, logger); if (logger->trace) traces(func_local, 1000000+(int)(sh->totcnt[ee_lc]), logger); if (logger->trace) traces(func_local, 1000000+(int)(B_AllCnts), logger); if (totcnt_o[ee_lc] < 0.25*B_AllCnts) {ee_lc = -1; continue;} /* skip 'meagre' E-bands */ if (logger->trace) traces(func_local, 9780009, logger); sprintf(logger->tmptxt, "%2d B_list.ee: %04X %1d\n", ibu, B_list[ibu].ee, ee_lc); logger->logstat = logprint(logger, logger->tmptxt, i5); if (logger->trace) traces(func_local, 9780001, logger); if ((B_list[ibu].ee&0xF000) != 0xE000) {ee_lc = -1; continue;} if (logger->trace) traces(func_local, 9780002, logger); if ((logger->burst_lc_out == 0) && (burst_ima_qual[ibu][ee_lc] == 0)) continue; if (logger->trace) traces(func_local, 9780003, logger); srcID = B_list[ibu].sourceID; if ((srcID <= 0) || (srcID >= 90)) {ee_lc = -1; continue;} if (logger->trace) traces(func_local, 9780004, logger); xxx = (float)((int)(B_list[ibu].sxy_skymax[ee_lc] / backproj->sky_ydim)); yyy = (float)(B_list[ibu].sxy_skymax[ee_lc] % backproj->sky_ydim); if (logger->trace) traces(func_local, 9780014, logger); sprintf(logger->tmptxt, "%2d B_list.srcID: %2d, ix.iy.name: %5.1f %5.1f %s, x/yvalstart: %5.1f %5.1f", ibu, srcID, xxx, yyy, B_list[ibu].name[ee_lc], B_list[ibu].xvalstart, B_list[ibu].yvalstart); logger->logstat = logprint(logger, logger->tmptxt, i5); if (logger->trace) traces(func_local, 9780214, logger); eelim = sh->numShds - backproj->ee_basic; if (eelim > MAX_LC_EBIN - backproj->ee_basic) eelim = MAX_LC_EBIN - backproj->ee_basic; for (eeuser=backproj->ee_basic; eeuseree_basic; eeuser++) { /* loop over eeuser (ends in 4863) S026L_eeuser */ if (burst_lc_output[srcID][eeuser] > 0) { kk_offs = 2 * burst_lc_output[srcID][eeuser]; if (kk_offs > 63) kk_offs = 63; kk_off2 = kk_offs + 2; } else { burst_lc_output[srcID][eeuser] = k_offset; kk_offs = 2 * k_offset; if (kk_offs > 63) kk_offs = 63; kk_off2 = kk_offs + 2; } if (logger->trace) traces(func_local, 9780005, logger); if (logger->trace) traces(func_local, 9780005+eeuser*10, logger); sprintf(regnam2, "J%1d_%04d%04d%04d_E%02d.reg", jmx_id->jmx_unit+1, backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv, eeuser); printf("qxq %s\n", regnam2); GOODSRC[srcID].LC_signif = B_list[ibu].ISsignif[ee_lc]; if ((logger->develop & 1) == 1) { if ((regfil2 = fopen(regnam2, "at")) != NULL) { /* regfil2 write section (ends in 4815) */ /* if (eeuser == ee_lc) { */ fprintf(regfil2, "IMAGE;line(%d,%d,%d,%d) # dashlist = 8 6 dash = 1 color=%s\n", B_list[ibu].iy+1, B_list[ibu].ix+1, (int)(B_list[ibu].start_chan*kscale2/kscale+imin), (int)(kk_off2 * plsigma), COLOR[k_offset+2]); fprintf(regfil2, "IMAGE;line(%d,%d,%d,%d) # dashlist = 8 6 dash = 1 color=%s\n", B_list[ibu].iy+1, B_list[ibu].ix+1, (int)(B_list[ibu].end_chan*kscale2/kscale+imin), (int)(kk_off2 * plsigma), COLOR[k_offset+2]); if (logger->trace) traces(func_local, 9780006, logger); /* } */ if (kk_offs < 2 * k_offset) {ee_lc = -1; goto end_lightcurve;} if (B_list[ibu].ID[ee_lc] > 0) goto skip_fk5_print; reg_mask = 1<tmptxt, "fk5;point(%8.4f, %8.4f) # point=%s %d text={%s} color=%s\n", B_list[ibu].RA, B_list[ibu].dec, textline, 20, regsrcnam, COLOR[k_offset+2]); logger->logstat = logprint(logger, logger->tmptxt, 0); GOODSRC[srcID].reg_used |= reg_mask; if (logger->trace) traces(func_local, 9780007, logger); cmx = GOODSRC[srcID ].xx - backproj->FOV_radius; cmy = GOODSRC[srcID ].yy - backproj->FOV_radius; rr = sqrt(cmx*cmx + cmy*cmy); if (logger->trace) traces(func_local, 9780017, logger); status = getxy(B_list[ibu].RA, B_list[ibu].dec, jmx_id->jmx_unit, &xmm, &ymm, jmx_id, point, logger); if ((fabs(xmm - cmx * backproj->pix2mm) > 0.1) || (fabs(ymm - cmy * backproj->pix2mm) > 0.1)) { if (logger->trace) traces(func_local, 9780027, logger); sprintf(logger->tmptxt, "Inconsistent D B_list.name: %20s, GOODSRC.name: %20s", B_list[ibu].name[ee_lc], GOODSRC[srcID].name); logger->logstat = logprint(logger, logger->tmptxt, i5); } if (logger->trace) traces(func_local, 9780037, logger); /* B_list[ibu].ISsignif[ee_lc] = 99.0; GOODSRC[srcID].src_pixel_area[0] = 999.0; */ sprintf(regtext, " t_ch %3d %3d max %3d E%1d ibu%1d %14s", B_list[ibu].start_chan, B_list[ibu].end_chan, B_list[ibu].chanmax, (B_list[ibu].ee & logger->LCMAXMASK), ibu, B_list[ibu].name[ee_lc]); if (logger->trace) traces(func_local, 9780047, logger); fprintf(regfil2, "#fk5u IJDst/stp %11.6lf %11.6lf Obst %6.1f cm2 %4.1f R %5.1f sign %5.1f %s XY %5.1f %5.1f\n", Tslices[B_list[ibu].start_chan].Tstart, Tslices[B_list[ibu].end_chan].Tstop, sh->accumT, GOODSRC[srcID].src_pixel_area[ee_lc], rr, B_list[ibu].ISsignif[ee_lc], regtext, GOODSRC[srcID ].xx, GOODSRC[srcID ].yy); if (logger->trace) traces(func_local, 9780057, logger); sprintf(logger->tmptxt, "#fk5u E%1d IJDst/stp %11.6lf %11.6lf Obst %6.1f cm2 %4.1f R %5.1f sign %5.1f %s XY %5.1f %5.1f\n", eeuser, Tslices[B_list[ibu].start_chan].Tstart, Tslices[B_list[ibu].end_chan].Tstop, sh->accumT, GOODSRC[srcID].src_pixel_area[ee_lc], rr, B_list[ibu].ISsignif[ee_lc], regtext, GOODSRC[srcID ].xx, GOODSRC[srcID ].yy); logger->logstat = logprint(logger, logger->tmptxt, 0); if (logger->trace) traces(func_local, 9780057, logger); skip_fk5_print: /* recover lightcurves from gnu-files */ if (logger->trace) traces(func_local, 9780010+eeuser, logger); txtConvert(B_list[ibu].name[ee_lc], SourceName, logger); sprintf(gnuname2, "J%1d_lc_%04d%04d%04d_%s_E%02d.gnu", jmx_id->jmx_unit+1, backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv, SourceName, eeuser); if (logger->trace) traces(func_local, 9780020+eeuser, logger); m0 = m1 = m2 = 0.0; if ((gnufil2 = fopen(gnuname2, "rt")) != NULL) { if (logger->trace) traces(func_local, 9780030+eeuser, logger); sprintf(logger->tmptxt,"Successfully opened %s for reading", gnuname2); logger->logstat = logprint(logger, logger->tmptxt, i5); for (ntime=0; ntimeNumTimeBins; ntime++) { if ((Tslices[ntime].dontUse & 1) > 0) continue; fgets(textline, 200, gnufil2); if (feof(gnufil2)) goto udoneAN; sscanf(textline, "%d %f", &j, &(Tslices[ntime].wflux[1])); m0 += 1.0; m1 += Tslices[ntime].wflux[1]; m2 += Tslices[ntime].wflux[1] * Tslices[ntime].wflux[1]; k = strlen(textline); textline[k-1] = 0; } if (logger->trace) traces(func_local, 9780040+eeuser, logger); udoneAN: fclose(gnufil2); gnufil2 = NULL; if (m0 > 4) { mean = m1 / m0; if ((m2 / m0 - mean * mean) > 0.0) rmsFlux = sqrt(m2 / m0 - mean * mean); else rmsFlux = 1.0; } else { mean = 0.0; rmsFlux = 99.9; ee_lc = -1; goto end_lightcurve; } if (logger->trace) traces(func_local, 9780050+eeuser, logger); } else { if (logger->trace) traces(func_local, 9780060+eeuser, logger); sprintf(logger->tmptxt,"Could not open %s for reading", gnuname2); logger->logstat = logprint(logger, logger->tmptxt, 0); ee_lc = -1; goto end_lightcurve; } if (logger->trace) traces(func_local, 9780070+eeuser, logger); m0 = m1 = m2 = 0.0; for (ntime=0; ntimeNumTimeBins; ntime++) { if (Tslices[ntime].dontUse & 1) continue; if (fabs(Tslices[ntime].wflux[1] - mean) / rmsFlux > 3.0) continue; m0 += 1.0; m1 += Tslices[ntime].wflux[1]; m2 += Tslices[ntime].wflux[1] * Tslices[ntime].wflux[1]; } if (logger->trace) traces(func_local, 9780080+eeuser, logger); if (m0 > 4) { mean = m1 / m0; if ((m2 / m0 - mean * mean) > 0.0) rmsFlux = sqrt(m2 / m0 - mean * mean); else rmsFlux = 1.0; for (ntime=0; ntimeNumTimeBins; ntime++) { if (Tslices[ntime].dontUse & 1) continue; Tslices[ntime].wflux[1] -= mean; } } else { mean = 0.0; rmsFlux = 99.9; ee_lc = -1; goto end_lightcurve; } if (logger->trace) traces(func_local, 9780090+eeuser, logger); fprintf(regfil2, "IMAGE;polygon %d %d ", imin-1, (int)(kk_off2 * plsigma + 0.5)); if (logger->trace) traces(func_local, 9780100+eeuser, logger); kscale = logger->NumTimeBins / 511; kscale2 = (int)(511/logger->NumTimeBins); if (kscale2 < 1) kscale2 = 1; kscale++; if (logger->NumTimeBins < 256) imin = (511 - logger->NumTimeBins * kscale2 - kscale2 / 2) / 2; if (kscale2 > 2) stepplot = kscale2; else stepplot = 0; for (i=0; iNumTimeBins; i+=kscale) { plotv = 0.0; for (j=0; j= logger->NumTimeBins) continue; if (Tslices[i+j].dontUse&1 == 1) continue; plotv += Tslices[i+j].wflux[1]; } plotv /= (sqrt((double)(kscale)) * rmsFlux); plotv *= plsigma; plotv += 0.5 + kk_off2 * plsigma; if (plotv > 511.0) plotv = 511.0; if (plotv < 0.0) plotv = 0.0; fprintf(regfil2, "%d %d ", (int)(i/kscale)*kscale2+imin, (int)(plotv)); if (stepplot) fprintf(regfil2, "%d %d ", (int)(i/kscale)*kscale2+imin+stepplot, (int)(plotv)); } if (logger->trace) traces(func_local, 9780110+eeuser, logger); fprintf(regfil2, "%d %d # color=%s\n", (int)((float)(logger->NumTimeBins*kscale2) / (float)(kscale))+imin+1, (int)(kk_off2 * plsigma +0.5), COLOR[k_offset+2]); status = LCcorrelation(eeuser, Tslices, logger, B_list[ibu].start_chan, B_list[ibu].end_chan, &correl, status); fprintf(regfil2, "#fk5c Correlation: %5.3f\n", correl); B_list[ibu].correl = correl; end_lightcurve: fclose(regfil2); regfil2 = NULL; if (logger->trace) traces(func_local, 9780140+eeuser, logger); } /* end of regfile2 write sequence (start in line 4629) */ } /* end of develop-if sequence */ if (logger->trace) traces(func_local, 9780150+eeuser, logger); } /* end of eeuser-loop (start in line 4721) S026L_eeuser */ if (logger->trace) traces(func_local, 9780200+k_offset, logger); if (kk_offs == 2 * k_offset) k_offset++; if (logger->trace) traces(func_local, 9780300, logger); if (logger->trace) traces(func_local, 9780300+k_offset, logger); if (logger->trace) traces(func_local, 9780300+ibu, logger); if (logger->trace) traces(func_local, 9780300+ee_lc, logger); if (logger->trace) traces(func_local, 9780300+burst_ima_qual[ibu][ee_lc], logger); } /* end of ibu-loop (start in line 4608) S026L_ibu */ if (logger->trace) traces(func_local, 9780500+k_offset, logger); /* 66666666666666666666666666666666666666666666666666666666666666666666666666666 */ /* QQQQQQ */ if (logger->trace) traces(func_local, 9880000+n_common2, logger); /* Section 27: */ /* loop to write light curves for all detected sources into *_Sxx.reg */ for (isrc=0; isrctrace) traces(func_local, 9881000+isrc, logger); for (eeuser=backproj->ee_basic; eeuseree_basic; eeuser++) { /* loop over eeuser (ends in 4978) */ if (src_lc_output[isrc][eeuser] > 0) { kk_offs = 2 * src_lc_output[isrc][eeuser]; if (kk_offs > 63) kk_offs = 63; kk_off2 = kk_offs + 2; } else { src_lc_output[isrc][eeuser] = k_offset; kk_offs = 2 * k_offset; if (kk_offs > 63) kk_offs = 63; kk_off2 = kk_offs + 2; } if (logger->trace) traces(func_local, 9882000+eeuser, logger); if (logger->trace) traces(func_local, 9882000+imin , logger); sprintf(regnam2, "J%1d_%04d%04d%04d_S%02d.reg", jmx_id->jmx_unit+1, backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv, eeuser); printf("qzq %s\n", regnam2); if ((logger->develop & 1) == 1) { if ((regfil2 = fopen(regnam2, "at")) != NULL) { /* regfil2 write section (ends in 4546 */ if (isrc == 0) fprintf(regfil2, "# Region file format: DS9 version 4.0 %s\n", regnam2); fprintf(regfil2, "IMAGE;line(%d,%d,%d,%d) # dashlist = 8 6 dash = 1 color=%s\n", (int)(GOODSRC[isrc].yy+1), (int)(GOODSRC[isrc].xx+1), (int)(imin), (int)(kk_off2 * plsigma), COLOR[k_offset+2]); fprintf(regfil2, "IMAGE;line(%d,%d,%d,%d) # dashlist = 8 6 dash = 1 color=%s\n", (int)(GOODSRC[isrc].yy+1), (int)(GOODSRC[isrc].xx+1), (int)(imin + logger->NumTimeBins*kscale2/kscale), (int)(kk_off2 * plsigma), COLOR[k_offset+2]); if (logger->trace) traces(func_local, 9880006, logger); if (kk_offs < 2 * k_offset) goto end_lightcurve2; /* recover lightcurves from gnu-files */ if (logger->trace) traces(func_local, 9880010+eeuser, logger); txtConvert(GOODSRC[isrc].name, SourceName, logger); sprintf(gnuname2, "J%1d_lc_%04d%04d%04d_%s_E%02d.gnu", jmx_id->jmx_unit+1, backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv, SourceName, eeuser); if (logger->trace) traces(func_local, 9880020, logger); if (logger->NumTimeBins < 5) goto end_lightcurve2; m0 = m1 = m2 = 0.0; if ((gnufil2 = fopen(gnuname2, "rt")) != NULL) { if (logger->trace) traces(func_local, 9880030, logger); sprintf(logger->tmptxt,"Successfully opened %s for reading", gnuname2); logger->logstat = logprint(logger, logger->tmptxt, i5); for (ntime=0; ntimeNumTimeBins; ntime++) { if ((Tslices[ntime].dontUse & 1) > 0) continue; fgets(textline, 200, gnufil2); if (feof(gnufil2)) goto udoneAN2; sscanf(textline, "%d %f", &j, &(Tslices[ntime].wflux[1])); m0 += 1.0; m1 += Tslices[ntime].wflux[1]; m2 += Tslices[ntime].wflux[1] * Tslices[ntime].wflux[1]; k = strlen(textline); textline[k-1] = 0; } if (logger->trace) traces(func_local, 9880040, logger); udoneAN2: fclose(gnufil2); gnufil2 = NULL; if (m0 > 4) { mean = m1 / m0; if ((m2 / m0 - mean * mean) > 0.0) rmsFlux = sqrt(m2 / m0 - mean * mean); else rmsFlux = 1.0; if (logger->trace) traces(func_local, 9880052, logger); } else { mean = 0.0; rmsFlux = 99.9; if (logger->trace) traces(func_local, 9880053, logger); } } else { if (logger->trace) traces(func_local, 9880060, logger); sprintf(logger->tmptxt,"Could not open %s for reading", gnuname2); logger->logstat = logprint(logger, logger->tmptxt, i5); goto next_sru; } if (logger->trace) traces(func_local, 9880070, logger); m0 = m1 = m2 = 0.0; for (ntime=0; ntimeNumTimeBins; ntime++) { if (Tslices[ntime].dontUse & 1) continue; if (fabs(Tslices[ntime].wflux[1] - mean) / (rmsFlux+0.0001) > 3.0) continue; m0 += 1.0; m1 += Tslices[ntime].wflux[1]; m2 += Tslices[ntime].wflux[1] * Tslices[ntime].wflux[1]; } if (logger->trace) traces(func_local, 9880080, logger); if (m0 > 4) { mean = m1 / m0; if ((m2 / m0 - mean * mean) > 0.0) rmsFlux = sqrt(m2 / m0 - mean * mean); else rmsFlux = 1.0; for (ntime=0; ntimeNumTimeBins; ntime++) { if (Tslices[ntime].dontUse & 1) continue; Tslices[ntime].wflux[1] -= mean; } } else { mean = 0.0; rmsFlux = 99.9; goto end_lightcurve2; goto next_sru; } if (logger->trace) traces(func_local, 9880090, logger); fprintf(regfil2, "IMAGE;polygon %d %d ", imin-1, (int)(kk_off2 * plsigma + 0.5)); kscale = logger->NumTimeBins / 511; kscale2 = (int)(511/logger->NumTimeBins); if (kscale2 < 1) kscale2 = 1; kscale++; if (logger->trace) traces(func_local, 9880100, logger); if (logger->trace) traces(func_local, 9880100+kscale, logger); for (i=0; iNumTimeBins; i+=kscale) { plotv = 0.0; for (j=0; j= logger->NumTimeBins) continue; if (Tslices[i+j].dontUse&1 == 1) continue; plotv += Tslices[i+j].wflux[1]; } plotv /= (sqrt((double)(kscale)) * (rmsFlux+0.00001)); plotv *= plsigma; plotv += 0.5 + kk_off2 * plsigma; if (plotv > 511.0) plotv = 511.0; if (plotv < 0.0) plotv = 0.0; fprintf(regfil2, "%d %d ", (int)(i/kscale)*kscale2+imin, (int)(plotv)); if (stepplot) fprintf(regfil2, "%d %d ", (int)(i/kscale)*kscale2+imin+stepplot, (int)(plotv)); } if (logger->trace) traces(func_local, 9880110, logger); fprintf(regfil2, "%d %d # color=%s\n", (int)((float)(logger->NumTimeBins*kscale2) / (float)(kscale))+imin+1, (int)(kk_off2 * plsigma +0.5), COLOR[k_offset+2]); end_lightcurve2: fclose(regfil2); regfil2 = NULL; if (logger->trace) traces(func_local, 9880140, logger); } /* end of regfile2 write sequence (start in line 4529) */ } if (logger->trace) traces(func_local, 9880150, logger); } /* end of eeuser-loop (start in line 4830) */ if (logger->trace) traces(func_local, 9880200+k_offset, logger); if (kk_offs == 2 * k_offset) k_offset++; if (logger->trace) traces(func_local, 9880200+k_offset, logger); if (logger->trace) traces(func_local, 9880200+ibu, logger); next_sru: ; } /* end of isrc-loop (start in line 4831) */ if (logger->trace) traces(func_local, 9880300+k_offset, logger); /* 77777777777777777777777777777777777777777777777777777777777777777777777777777 */ slut: ; /* slut: */ if (logger->trace) traces(func_local, 100000+logger->N_SRC2, logger); if (logger->trace) traces(func_local, 99, logger); if ((logger->LC > 0) && ((logger->develop & 1) == 1)) { eelim = sh->numShds - backproj->ee_basic; for (eeuser=backproj->ee_basic; eeuseree_basic; eeuser++) { /* loop over eeuser */ sprintf(regnam2, "J%1d_%04d%04d%04d_E%02d.reg", jmx_id->jmx_unit+1, backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv, eeuser); if ((regfil2 = fopen(regnam2, "at")) != NULL) { fprintf(regfil2, "# End of DS9 region file %s\n", regnam2); fclose(regfil2); } sprintf(regnam2, "J%1d_%04d%04d%04d_S%02d.reg", jmx_id->jmx_unit+1, backproj->aux_orbit, backproj->aux_pid, sh->aux_pidv, eeuser); if ((regfil2 = fopen(regnam2, "at")) != NULL) { fprintf(regfil2, "# End of DS9 region file %s\n", regnam2); fclose(regfil2); } } } /* *************************************************************************** */ /* 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, 1234567, logger); if (logger->trace) traces(func_local, 1000-status, logger); goto slut; } /* *********************************************************************************** */ void txtConvert(char srcname[], char SrcName[], struct log_con *logger) { int i, i5; i5 = 0; for (i=0; i<31; i++) { if (srcname[i] == 0) { SrcName[i] = 0; return; } if (srcname[i] == ' ') { SrcName[i] = '_'; continue; } SrcName[i] = srcname[i]; } SrcName[i] = 0; sprintf(logger->tmptxt, "Convert %s to %s", srcname, SrcName); logger->logstat = logprint(logger, logger->tmptxt, i5); return; }