#include #include #ifndef ACIS_PROCESS_EVENTS_H #include "acis_process_events.h" #endif /*H************************************************************************** * Copyright (c) 1996, Smithsonian Astrophysical Observatory You may do anything you like with this file except remove this copyright. * FUNCTION NAME: find_asca_grade() * DEVELOPEMENT: tools * DESCRIPTION: This function groups the flight grades (0-255) by the ASCA grading scheme to produce a subset of grades (0-7). The routine uses the size of an event island to determine whether to apply continuous clocking ASCA grades or time exposure ASCA grades. * REVISION HISTORY: Ref. No. Date -------- ---- 1.1 08 Feb 1996 *H**************************************************************************/ short find_asca_grade(short flt_grd, /* I - flt grade of event */ short evt_sz) /* I - number of pixels in event */ { short asca_grade; /* return value- asca grade 0-7 */ if (evt_sz == CC_ISLAND_SZ) { /* set ASCA grade for continuous clocking mode data 1x3 pixel event */ switch (flt_grd) { case 0: /* S (1/1) */ asca_grade = ASCA_GRADE_S; break; case 1: /* (1/1) */ asca_grade = ASCA_GRADE_PL; break; case 2: /* (1/1) */ asca_grade = ASCA_GRADE_PR; break; case 3: /* Fallthrough intended */ default: /* Other */ asca_grade = ASCA_GRADE_DEFAULT; break; } /* end switch (flt_grd) */ } else { switch (flt_grd) { case 0: /* S (1/1) */ asca_grade = ASCA_GRADE_S; break; case 1: /* S+ ( 1/15) fallthru intented */ case 4: /* S+ ( 2/15) fallthru intented */ case 5: /* S+ ( 3/15) fallthru intented */ case 32: /* S+ ( 4/15) fallthru intented */ case 33: /* S+ ( 5/15) fallthru intented */ case 36: /* S+ ( 6/15) fallthru intented */ case 37: /* S+ ( 7/15) fallthru intented */ case 128: /* S+ ( 8/15) fallthru intented */ case 129: /* S+ ( 9/15) fallthru intented */ case 132: /* S+ (10/15) fallthru intented */ case 133: /* S+ (11/15) fallthru intented */ case 160: /* S+ (12/15) fallthru intented */ case 161: /* S+ (13/15) fallthru intented */ case 164: /* S+ (14/15) fallthru intented */ case 165: /* S+ (15/15) fallthru intented */ asca_grade = ASCA_GRADE_S_PLUS; break; case 2: /* Pv (1/8) fallthru intented */ case 34: /* Pv (2/8) fallthru intented */ case 64: /* Pv (3/8) fallthru intented */ case 65: /* Pv (4/8) fallthru intented */ case 68: /* Pv (5/8) fallthru intented */ case 69: /* Pv (6/8) fallthru intented */ case 130: /* Pv (7/8) fallthru intented */ case 162: /* Pv (8/8) fallthru intented */ asca_grade = ASCA_GRADE_PV; break; case 8: /* Pr (1/4) fallthru intented */ case 12: /* Pr (2/4) fallthru intented */ case 136: /* Pr (3/4) fallthru intented */ case 140: /* Pr (4/4) fallthru intented */ asca_grade = ASCA_GRADE_PL; break; case 16: /* Pl (1/4) fallthru intented */ case 17: /* Pl (2/4) fallthru intented */ case 48: /* Pl (3/4) fallthru intented */ case 49: /* Pl (4/4) fallthru intented */ asca_grade = ASCA_GRADE_PR; break; case 3: /* P+ ( 1/32) fallthru intented */ case 6: /* P+ ( 2/32) fallthru intented */ case 9: /* P+ ( 3/32) fallthru intented */ case 13: /* P+ ( 4/32) fallthru intended */ case 20: /* P+ ( 5/32) fallthru intented */ case 21: /* P+ ( 6/32) fallthru intented */ case 35: /* P+ ( 7/32) fallthru intented */ case 38: /* P+ ( 8/32) fallthru intented */ case 40: /* P+ ( 9/32) fallthru intented */ case 44: /* P+ (10/32) fallthru intented */ case 52: /* P+ (11/32) fallthru intented */ case 53: /* P+ (12/32) fallthru intented */ case 96: /* P+ (13/32) fallthru intented */ case 97: /* P+ (14/32) fallthru intented */ case 100: /* P+ (15/32) fallthru intented */ case 101: /* P+ (16/32) fallthru intented */ case 131: /* P+ (17/32) fallthru intented */ case 134: /* P+ (18/32) fallthru intented */ case 137: /* P+ (19/32) fallthru intented */ case 141: /* P+ (20/32) fallthru intented */ case 144: /* P+ (21/32) fallthru intented */ case 145: /* P+ (22/32) fallthru intented */ case 163: /* P+ (23/32) fallthru intented */ case 166: /* P+ (24/32) fallthru intented */ case 168: /* P+ (25/32) fallthru intented */ case 172: /* P+ (26/32) fallthru intented */ case 176: /* P+ (27/32) fallthru intented */ case 177: /* P+ (28/32) fallthru intented */ case 192: /* P+ (29/32) fallthru intented */ case 193: /* P+ (30/32) fallthru intented */ case 196: /* P+ (31/32) fallthru intented */ case 197: /* P+ (32/32) fallthru intented */ asca_grade = ASCA_GRADE_P_PLUS; break; case 11: /* L+Q ( 1/16) fallthru intented */ case 10: /* L+Q ( 2/16) fallthru intented */ case 18: /* L+Q ( 3/16) fallthru intented */ case 22: /* L+Q ( 4/16) fallthru intented */ case 50: /* L+Q ( 5/16) fallthru intented */ case 54: /* L+Q ( 6/16) fallthru intented */ case 72: /* L+Q ( 7/16) fallthru intented */ case 76: /* L+Q ( 8/16) fallthru intented */ case 80: /* L+Q ( 9/16) fallthru intented */ case 81: /* L+Q (10/16) fallthru intented */ case 104: /* L+Q (11/16) fallthru intented */ case 108: /* L+Q (12/16) fallthru intented */ case 138: /* L+Q (13/16) fallthru intented */ case 139: /* L+Q (14/16) fallthru intented */ case 208: /* L+Q (15/16) fallthru intented */ case 209: /* L+Q (16/16) fallthru intented */ asca_grade = ASCA_GRADE_L_AND_Q; break; default: /* Other */ asca_grade = ASCA_GRADE_DEFAULT; break; } /* end switch (flt_grd) */ } /* end else if (evt_sz == CC_ISLAND_SZ) */ return (asca_grade); } /*H************************************************************************** * Copyright (c) 1996, Smithsonian Astrophysical Observatory You may do anything you like with this file except remove this copyright. * FUNCTION NAME: find_acis_grade() * DEVELOPEMENT: tools * DESCRIPTION: This function groups the flight grades (0-255) by the ACIS grading scheme to produce a subset of grades (0-8). * NOTES The ACIS grades for continuous clocking data have not been defined yet and the ones contained below are merely a place-holder. * REVISION HISTORY: Ref. No. Date -------- ---- 1.1 08 Feb 1996 *H**************************************************************************/ short find_acis_grade(short flt_grd, /* I - flt grade of event */ short evt_sz) /* I - number of pixels in event */ { short acis_grade; /* return value- acis grade 0-8 */ if (evt_sz == CC_ISLAND_SZ) { /* set ACIS grade for continuous clocking mode data 1x3 pixel event */ switch (flt_grd) { case 0: /* Single (1/1) */ acis_grade = ACIS_GRADE_SINGLE; break; case 1: /* Right (1/1) */ acis_grade = ACIS_GRADE_SINGLE; break; case 2: /* Left (1/1) */ acis_grade = ACIS_GRADE_SINGLE; break; case 3: /* All (1/1) */ acis_grade = ACIS_GRADE_ALL; break; default: /* Other */ acis_grade = ACIS_GRADE_DEFAULT; break; } /* end switch */ } else { /* set ACIS grade for timed exposure mode data 3x3 pixel event */ switch (flt_grd) { case 0: /* Single (1/1) */ acis_grade = ACIS_GRADE_SINGLE; break; case 2: /* Vertical (1/2) fallthru intented */ case 64: /* Vertical (2/2) fallthru intented */ acis_grade = ACIS_GRADE_VERT; break; case 8: /* Horizontal (1/2) fallthru intented */ case 16: /* Horizontal (2/2) fallthru intented */ acis_grade = ACIS_GRADE_HORIZ; break; case 10: /* Triple (1/4) fallthru intented */ case 18: /* Triple (2/4) fallthru intented */ case 72: /* Triple (3/4) fallthru intented */ case 80: /* Triple (4/4) fallthru intented */ acis_grade = ACIS_GRADE_TRIPLE; break; case 11: /* Quadruple (1/4) fallthru intented */ case 22: /* Quadruple (2/4) fallthru intented */ case 104: /* Quadruple (3/4) fallthru intented */ case 208: /* Quadruple (4/4) fallthru intented */ acis_grade = ACIS_GRADE_QUAD; break; case 3: /* Geo ( 1/31) fallthru intented */ case 6: /* Geo ( 2/31) fallthru intented */ case 7: /* Geo ( 3/31) fallthru intented */ case 9: /* Geo ( 4/31) fallthru intented */ case 20: /* Geo ( 5/31) fallthru intented */ case 24: /* Geo ( 6/31) fallthru intented */ case 25: /* Geo ( 7/31) fallthru intented */ case 26: /* Geo ( 8/31) fallthru intented */ case 28: /* Geo ( 9/31) fallthru intented */ case 40: /* Geo (10/31) fallthru intented */ case 41: /* Geo (11/31) fallthru intented */ case 56: /* Geo (12/31) fallthru intented */ case 57: /* Geo (13/31) fallthru intented */ case 66: /* Geo (14/31) fallthru intented */ case 67: /* Geo (15/31) fallthru intented */ case 70: /* Geo (16/31) fallthru intented */ case 71: /* Geo (17/31) fallthru intented */ case 74: /* Geo (18/31) fallthru intented */ case 82: /* Geo (19/31) fallthru intented */ case 88: /* Geo (20/31) fallthru intended */ case 90: /* Geo (21/31) fallthru intented */ case 96: /* Geo (22/31) fallthru intented */ case 98: /* Geo (23/31) fallthru intented */ case 144: /* Geo (24/31) fallthru intented */ case 148: /* Geo (25/31) fallthru intented */ case 152: /* Geo (26/31) fallthru intented */ case 156: /* Geo (27/31) fallthru intented */ case 192: /* Geo (28/31) fallthru intented */ case 194: /* Geo (29/31) fallthru intented */ case 224: /* Geo (30/31) fallthru intented */ case 226: /* Geo (31/31) fallthru intented */ acis_grade = ACIS_GRADE_GEO; break; case 1: /* Diagonal ( 1/15) fallthru intented */ case 4: /* Diagonal ( 2/15) fallthru intented */ case 5: /* Diagonal ( 3/15) fallthru intented */ case 32: /* Diagonal ( 4/15) fallthru intented */ case 33: /* Diagonal ( 5/15) fallthru intented */ case 36: /* Diagonal ( 6/15) fallthru intented */ case 37: /* Diagonal ( 7/15) fallthru intented */ case 128: /* Diagonal ( 8/15) fallthru intented */ case 129: /* Diagonal ( 9/15) fallthru intented */ case 132: /* Diagonal (10/15) fallthru intented */ case 133: /* Diagonal (11/15) fallthru intented */ case 160: /* Diagonal (12/15) fallthru intented */ case 161: /* Diagonal (13/15) fallthru intented */ case 164: /* Diagonal (14/15) fallthru intented */ case 165: /* Diagonal (15/15) fallthru intented */ acis_grade = ACIS_GRADE_DIAG; break; case 255: /* All (1/1) */ acis_grade = ACIS_GRADE_ALL; break; default: /* Other */ acis_grade = ACIS_GRADE_DEFAULT; break; } /* end switch (flt_grd) */ } /* end else if (evt_sz == CC_ISLAND_SZ) */ return (acis_grade); } /*H************************************************************************** * Copyright (c) 1996, Smithsonian Astrophysical Observatory You may do anything you like with this file except remove this copyright. * FUNCTION NAME: calculate_centroid() * DEVELOPEMENT: tools * DESCRIPTION: This function determines the average or "centroid" position of the event. It is determined by a weighted average of the pha values which are over the split threshold level. centx = chipx + SUM( deltax[i]*(phas[i]/sumpha) ) centy = chipy + SUM( deltay[i]*(phas[i]/sumpha) ) where deltax[i] = chipx[pixel i] - chipx = "offset from center" = 0,1,-1 deltay[i] = chipy[pixel i] - chipy = "offset from center" = 0,1,-1 * NOTES: A new flag direction was added to the routine. The flag should be set to either ADET_CENT_APPLY or ADET_CENT_UNDO. The first value will cause the routine to calculate the centroided value of a pair of coordinates. The latter value will cause the routine to remove the centroided affect from a pair of coordinates; the result- the undoing of a previously applied centroid. y coordinate centroid offsets are not calculated for continuous clocking mode data. * REVISION HISTORY: Ref. No. Date -------- ---- 1.1 13 Feb 1996 *H**************************************************************************/ void calculate_centroid(EVENT_REC_P_T evt_p, /* I - event data */ INPUT_PARMS_P_T inp_p, /* I - input parameters */ short direction, /* I - apply/undo centroid */ double dchpx, /* I - value of chip x */ double dchpy, /* I - value of chip y */ double *dcentx, /* O - x axis centroid pos */ double *dcenty) /* O - y axis centroid pos */ { register double spha = 0.0; double tempx = dchpx, tempy = dchpy; double adjusted_phas[9] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; switch (inp_p->supported_mode) { case MODE_FNT_CC: /* sum up the phas in the CC mode event island */ if (evt_p->phas[0] > inp_p->threshold) { spha += (adjusted_phas[0] = evt_p->phas[0] - inp_p->threshold); } if (evt_p->phas[1] > inp_p->threshold) { spha += evt_p->phas[1] - inp_p->threshold; } if (evt_p->phas[2] > inp_p->threshold) { spha += (adjusted_phas[2] = evt_p->phas[2] - inp_p->threshold); } if (spha > 0) { if (direction == ADET_CENT_APPLY) { tempx -= adjusted_phas[0]/spha; tempx += adjusted_phas[2]/spha; } else { tempx += adjusted_phas[0]/spha; tempx -= adjusted_phas[2]/spha; } } break; case MODE_FNT_TE: /* fallthrough intended */ case MODE_FNT_BS: /* fallthrough intended */ case MODE_FNT_BSMP: /* sum up the phas in the 3x3 event island */ if (evt_p->phas[0] > inp_p->threshold) { spha += (adjusted_phas[0] = evt_p->phas[0] - inp_p->threshold); } if (evt_p->phas[1] > inp_p->threshold) { spha += (adjusted_phas[1] = evt_p->phas[1] - inp_p->threshold); } if (evt_p->phas[2] > inp_p->threshold) { spha += (adjusted_phas[2] = evt_p->phas[2] - inp_p->threshold); } if (evt_p->phas[3] > inp_p->threshold) { spha += (adjusted_phas[3] = evt_p->phas[3] - inp_p->threshold); } if (evt_p->phas[4] > inp_p->threshold) { spha += evt_p->phas[4] - inp_p->threshold; } if (evt_p->phas[5] > inp_p->threshold) { spha += (adjusted_phas[5] = evt_p->phas[5] - inp_p->threshold); } if (evt_p->phas[6] > inp_p->threshold) { spha += (adjusted_phas[6] = evt_p->phas[6] - inp_p->threshold); } if (evt_p->phas[7] > inp_p->threshold) { spha += (adjusted_phas[7] = evt_p->phas[7] - inp_p->threshold); } if (evt_p->phas[8] > inp_p->threshold) { spha += (adjusted_phas[8] = evt_p->phas[8] - inp_p->threshold); } if (spha > 0) { if (direction == ADET_CENT_APPLY) { tempx -= adjusted_phas[0]/spha; tempx -= adjusted_phas[3]/spha; tempx -= adjusted_phas[6]/spha; tempx += adjusted_phas[2]/spha; tempx += adjusted_phas[5]/spha; tempx += adjusted_phas[8]/spha; tempy -= adjusted_phas[0]/spha; tempy -= adjusted_phas[1]/spha; tempy -= adjusted_phas[2]/spha; tempy += adjusted_phas[6]/spha; tempy += adjusted_phas[7]/spha; tempy += adjusted_phas[8]/spha; } else { tempx += adjusted_phas[0]/spha; tempx += adjusted_phas[3]/spha; tempx += adjusted_phas[6]/spha; tempx -= adjusted_phas[2]/spha; tempx -= adjusted_phas[5]/spha; tempx -= adjusted_phas[8]/spha; tempy += adjusted_phas[0]/spha; tempy += adjusted_phas[1]/spha; tempy += adjusted_phas[2]/spha; tempy -= adjusted_phas[6]/spha; tempy -= adjusted_phas[7]/spha; tempy -= adjusted_phas[8]/spha; } } /* end if spha > 0 */ break; case MODE_VFNT_TE: /* sum up the inner phas in the 5x5 event island */ if (evt_p->phas[6] > inp_p->threshold) { spha += (adjusted_phas[0] = evt_p->phas[6] - inp_p->threshold); } if (evt_p->phas[7] > inp_p->threshold) { spha += (adjusted_phas[1] = evt_p->phas[7] - inp_p->threshold); } if (evt_p->phas[8] > inp_p->threshold) { spha += (adjusted_phas[2] = evt_p->phas[8] - inp_p->threshold); } if (evt_p->phas[11] > inp_p->threshold) { spha += (adjusted_phas[3] = evt_p->phas[11] - inp_p->threshold); } if (evt_p->phas[12] > inp_p->threshold) { spha += evt_p->phas[12] - inp_p->threshold; } if (evt_p->phas[13] > inp_p->threshold) { spha += (adjusted_phas[5] = evt_p->phas[13] - inp_p->threshold); } if (evt_p->phas[16] > inp_p->threshold) { spha += (adjusted_phas[6] = evt_p->phas[16] - inp_p->threshold); } if (evt_p->phas[17] > inp_p->threshold) { spha += (adjusted_phas[7] = evt_p->phas[17] - inp_p->threshold); } if (evt_p->phas[18] > inp_p->threshold) { spha += (adjusted_phas[8] = evt_p->phas[18] - inp_p->threshold); } if (spha > 0) { if (direction == ADET_CENT_APPLY) { tempx -= adjusted_phas[0]/spha; tempx -= adjusted_phas[3]/spha; tempx -= adjusted_phas[6]/spha; tempx += adjusted_phas[2]/spha; tempx += adjusted_phas[5]/spha; tempx += adjusted_phas[8]/spha; tempy -= adjusted_phas[0]/spha; tempy -= adjusted_phas[1]/spha; tempy -= adjusted_phas[2]/spha; tempy += adjusted_phas[6]/spha; tempy += adjusted_phas[7]/spha; tempy += adjusted_phas[8]/spha; } else { tempx += adjusted_phas[0]/spha; tempx += adjusted_phas[3]/spha; tempx += adjusted_phas[6]/spha; tempx -= adjusted_phas[2]/spha; tempx -= adjusted_phas[5]/spha; tempx -= adjusted_phas[8]/spha; tempy += adjusted_phas[0]/spha; tempy += adjusted_phas[1]/spha; tempy += adjusted_phas[2]/spha; tempy -= adjusted_phas[6]/spha; tempy -= adjusted_phas[7]/spha; tempy -= adjusted_phas[8]/spha; } } /* end if spha > 0 */ break; default: /* do nothing */ break; } *dcentx = tempx; *dcenty = tempy; } /*H************************************************************************** * Copyright (c) 1996, Smithsonian Astrophysical Observatory You may do anything you like with this file except remove this copyright. * FUNCTION NAME: verify_scheme_request() * DEVELOPEMENT: tools * DESCRIPTION: This function is called by acis_process_events to ensure that the chosen grading grading scheme is valid. Valid requests are ASCA, ACIS, or NONE. The routine sets a flag in the input parameters data structure and returns a value of TRUE if the scheme is valid. If the scheme is invalid, a value of FALSE is returned. * NOTES The routine is case sensitive so the input parameters must be set correctly. The actual accepted values (GRADE_MODE_ACIS, GRADE_MODE_ASCA, GRADE_MODE_NONE) can be found in acis_process_events.h * REVISION HISTORY: Ref. No. Date -------- ---- 1.1 08 Apr 1996 *H**************************************************************************/ boolean verify_scheme_request( INPUT_PARMS_P_T inp_p, /* I/O - params including */ char* scheme, /* I - grading scheme */ STATISTICS_P_T stat_p) /* I/O - statistical counts */ { boolean status = TRUE; if (strcmp(scheme, GRADE_MODE_ASCA) == 0) { inp_p->scheme = ADET_ASCA_SCHEME; } else { if (strcmp(scheme, GRADE_MODE_ACIS) == 0) { inp_p->scheme = ADET_ACIS_SCHEME; } else { if (strcmp(scheme, GRADE_MODE_NONE) == 0) { inp_p->scheme = ADET_NO_SCHEME; } else { status = FALSE; stat_p->error_flag = ACIS_PROCESS_EVENTS_ERROR_2; } } } return (status); } /******************************************************************************* * DESCRIPTION: The routine make_wcs_updates() is called by acis_process_events to add wcs information to the header of the output event file. The routine returns a value of TRUE if an error occurred. * NOTES: The routine will write a wcs coordinate transform for systems based upon the value of the stop parameter (ie. if the stop param is sky, then sky, det, and tdet wcs transforms will be written out regardless of whether or not the coordinates are listed in the output eventdef. *******************************************************************************/ boolean make_wcs_updates( EVENT* out_ptr, /* I - output event file handle */ EVENT_REC_P_T evt_p, /* I - data structure for a single event */ INPUT_PARMS_P_T inp_p) /* I - data structure for input paramaters */ { boolean err_occurred = FALSE; /* True if an error has occurred */ wcsHandle wcs = NULL; /* pointer to output qpoe for wcs */ /* if unable to open wcs - set error flag */ if ((wcs = wcs_evtopen(out_ptr)) != NULL) { switch (inp_p->stop) { case ADET_SKY_VAL: /* fallthrough intended */ wcs_put_xyevt(wcs, inp_p->fpsys, "focal", ADET_SKY_X_COL, ADET_SKY_Y_COL); wcs_put_wldevt(wcs, inp_p->fpsys, "world", ADET_SKY_X_COL, ADET_SKY_Y_COL); case ADET_DET_VAL: /* fallthrough intended */ wcs_put_xyevt(wcs, inp_p->fpsys, "dfp", ADET_DET_X_COL, ADET_DET_Y_COL); case ADET_TDET_VAL: wcs_put_detevt(wcs, find_tdetsys_in_int(inp_p->acis_sys), "tdet", ADET_TDET_X_COL, ADET_TDET_Y_COL); break; default: /* do nothing */ break; } wcs_evtclose(wcs); } else { err_occurred = TRUE; } return (err_occurred); } /******************************************************************************* * DESCRIPTION: The following routine, set_grating_type() is used by acis_process_events to set an internal 'grating' flag used in detemining coordinate transformations. This flag has nothing to do with actually performing gratings; it is merely to state whether gratings will be (or have been) run on the input data since transformations such as sky coordinates are sensitive to this. * NOTES: *******************************************************************************/ short set_grating_type(EVENT* evt_ptr ) /* I - pointer to input event file */ { short grating_type = ADET_NO_GRATING; if (evt_header_exists(evt_ptr, GRATINGS) == 1) { char grating[SZ_KEYWORD]; evt_str_read_header(evt_ptr, GRATINGS, grating, SZ_KEYWORD); if (strcmp(grating, LETG_KEY) == 0) { grating_type = ADET_LE_GRATING; } else if (strcmp(grating, HETG_KEY) == 0) { grating_type = ADET_HE_GRATING; } else if (strcmp(grating, TOGA_KEY) == 0) { grating_type = ADET_TG_GRATING; } } return (grating_type); } /******************************************************************************* * DESCRIPTION: The function setup_output_axes is called by acis_process_events to determine the output event file axes and axes lengths. If a coordinate transformation is specified as the stop coordinate, then the stop coords become the axes, provided they exist in the output eventdef. For example, if the stop parameter is set to det, then detx and dety are used as the output axes. If the axes do not exist in the output eventdef then an error status is returned. If the stop param is set to "none" then the axes from the first usable input file are used provided they exist in the output eventdef. * NOTES: *******************************************************************************/ ERR_MASK_T setup_output_axes ( EVENT* evt_ptr, /* I - input event file handle */ char** in_att_names, /* I - input file column names */ EVENT* out_ptr, /* O - output event file handle */ char** out_att_names, /* I - output file column names */ INPUT_PARMS_P_T inp_p, /* I - input parameters */ short num_out_cols, /* I - number of output columns */ short* out_evt_map ) /* I - output file column mapping */ { ERR_MASK_T err_mask = ERR_MASK_NO_ERRS; short stop_col[ADET_NUM_AXES]; short count = 0; if (inp_p->stop == ADET_NONE_VAL) { short key[ADET_NUM_AXES]; boolean found_x = FALSE; boolean found_y = FALSE; /* determine position of key cols in input column list */ key[ADET_X_AXIS] = evt_key_x(evt_ptr); key[ADET_Y_AXIS] = evt_key_y(evt_ptr); /* check if input key columns are in output file */ while ((count < num_out_cols) && ((found_x == FALSE) || (found_y == FALSE))) { if (strcmp(in_att_names[key[ADET_X_AXIS]], out_att_names[count]) == NULL) { found_x = TRUE; } else if (strcmp(in_att_names[key[ADET_Y_AXIS]], out_att_names[count]) == NULL) { found_y = TRUE; } count++; } if ((found_x) && (found_y)) { /* both keys found in output file column list */ evt_set_file(out_ptr, in_att_names[key[ADET_X_AXIS]], in_att_names[key[ADET_Y_AXIS]], -1, NULL, inp_p->page_size, inp_p->bkt_size); } else { /* output file is missing at least one input file key column */ err_mask |= ERR_MASK_AXES_DNE; } } else { /* use columns from last coordinate transform for keys */ short axes_name_pos[ADET_NUM_AXES] = { -1, -1}; map_start_column(inp_p->stop, &stop_col[ADET_X_AXIS], &stop_col[ADET_Y_AXIS]); while ((count -1) && (axes_name_pos[ADET_X_AXIS] < num_out_cols)) && ((axes_name_pos[ADET_Y_AXIS] > -1) && (axes_name_pos[ADET_Y_AXIS] < num_out_cols))) { VEC2_LONG axes_l = {0, 0}; int axes_len[ADET_NUM_AXES]; switch (inp_p->stop) { case ADET_SKY_VAL: /* fallthrough intended */ case ADET_TAN_VAL: /* fallthrough intended */ case ADET_DET_VAL: pix_fp_image_dimn(inp_p->fpsys, axes_l); break; default: pix_tdet_image_dimn(pix_find_tdetsys_in_int(inp_p->acis_sys), axes_l); break; } axes_len[ADET_X_AXIS] = (int) axes_l[ADET_X_AXIS]; axes_len[ADET_Y_AXIS] = (int) axes_l[ADET_Y_AXIS]; evt_set_file(out_ptr, out_att_names[axes_name_pos[ADET_X_AXIS]], out_att_names[axes_name_pos[ADET_Y_AXIS]], 2, axes_len, inp_p->page_size, inp_p->bkt_size); evt_str_write_header(out_ptr, X_AXIS_KEY, out_att_names[axes_name_pos[ADET_X_AXIS]], ""); evt_str_write_header(out_ptr, Y_AXIS_KEY, out_att_names[axes_name_pos[ADET_Y_AXIS]], ""); } else { err_mask |= ERR_MASK_AXES_DNE; } } return (err_mask); } /******************************************************************************* * DESCRIPTION: The routine set_up_mirror() is called by acis_process_events to set staging/fam data needed by the pixel library to perform coordinate transformations. The routine attempts to load keyword values provided in the input file headers. If the keywords do not exist in the file headers, default values of 0 are used. *******************************************************************************/ void set_up_mirror(EVENT* evt_ptr, /* I - pointer to input event file handle */ char* evtfile, /* I - name of input event file */ DITHER_REC_P_T dth_p) /* O - pointer to dither record */ { if ((evt_header_exists(evt_ptr, STG_X_KEY) == 1) && ((evt_header_exists(evt_ptr, STG_Y_KEY) == 1) && (evt_header_exists(evt_ptr, STG_Z_KEY) == 1))) { dth_p->pos[STG_AIMPOINT_X] = load_double_key_value(evt_ptr, STG_X_KEY); dth_p->pos[STG_AIMPOINT_Y] = load_double_key_value(evt_ptr, STG_Y_KEY); dth_p->pos[STG_AIMPOINT_Z] = load_double_key_value(evt_ptr, STG_Z_KEY); } else { err_msg(ADET_STAGE_WARN, evtfile); } if ((evt_header_exists(evt_ptr, STG_ANG3_KEY) == 1) && ((evt_header_exists(evt_ptr, STG_ANG2_KEY) == 1) && (evt_header_exists(evt_ptr, STG_ANG1_KEY) == 1))) { dth_p->theta[STG_ANG1_NDX] = load_double_key_value(evt_ptr, STG_ANG1_KEY); dth_p->theta[STG_ANG2_NDX] = load_double_key_value(evt_ptr, STG_ANG2_KEY); dth_p->theta[STG_ANG3_NDX] = load_double_key_value(evt_ptr, STG_ANG3_KEY); } else { err_msg(ADET_STG_ANG_WARN, evtfile); } if ((evt_header_exists(evt_ptr, HPY_YAW_KEY) == 1) && (evt_header_exists(evt_ptr, HPY_PIT_KEY) == 1)) { dth_p->hpy[HPY_YAW] = load_double_key_value(evt_ptr, HPY_YAW_KEY); dth_p->hpy[HPY_PIT] = load_double_key_value(evt_ptr, HPY_PIT_KEY); } else { err_msg(ADET_HPY_WARN, evtfile); } if (evt_header_exists(evt_ptr, LASSZ_KEY) == 1) { dth_p->lass[LASSZ_NDX] = load_double_key_value(evt_ptr, LASSZ_KEY); pix_set_aimpoint(dth_p->lass); } else { err_msg(ADET_LASSZ_WARN, evtfile); } pix_set_mirror (dth_p->hpy, dth_p->pos, dth_p->theta); } void get_predicted_beam_position( EVENT* evt_ptr, /* I - input event file handle */ INPUT_PARMS_P_T inp_p) /* O - input parmater data structure*/ { VEC3_DBLE foa = {0.0, 0.0, 0.0}; if (inp_p->found_foa = ((evt_header_exists(evt_ptr, FOA_X_KEY) == 1) && ((evt_header_exists(evt_ptr, FOA_Y_KEY) == 1) && (evt_header_exists(evt_ptr, FOA_Z_KEY) == 1)))) { PIX_HEADER pix_hdr_buf; VECS_CHAR chip; VEC2_DBLE cpc; VEC1_DBLE scale; foa[ADET_X_AXIS] = load_double_key_value(evt_ptr, FOA_X_KEY); foa[ADET_Y_AXIS] = load_double_key_value(evt_ptr, FOA_Y_KEY); foa[ADET_Z_AXIS] = load_double_key_value(evt_ptr, FOA_Z_KEY); pix_fpc_to_cpc(&pix_hdr_buf, foa, chip, cpc); pix_chip_scale_in_mmppix(inp_p->instrume, scale); inp_p->cy0 = cpc[1] / scale[0]; } }