Subject: Re: JEMX lib & struct - maybe relevant? Hello all: I have now modified my midisky program to replace all global commons with structures. The structures are defined in my header file which I attach. I plan next week to discuss with Niels Jorgen about which of my parameters already exist in the IMOD structures. I will then rename my variables follow the existing conventions. niels *********************************************************************** /* Constants, global variables and function prototypes for midi_b *** In all of the midi_b routines the variable "jemx" has the value 0 for JEM-X1 and 1 for JEM-X2 */ #include #include #include #include #include #include #include #define FOV_f 1 /* FOV_f=1 means 255x255 skymaps, FOV_f=2 means 511x511 skymaps */ #define FOV_rad (128*FOV_f-1) /* field of view radius in pixels */ #define sky_xdim (2*FOV_rad+1) /* x-dimension of skymap */ #define sky_ydim (2*FOV_rad+1) /* y-dimension of skymap */ #define skydim 65025 /* sky_xdim*sky_ydim */ /* length of (linear) skymap array */ #define max_sky_bytes (200000000*FOV_f) /* max number of bytes in d_allow array */ #define max_candidates 20 /* max number of sky_map peak candidates accepted in search */ #define detdim 65536 /* lenght of linearized detector array (256X*256Y) */ #define det_ydim 256 #define sourcmax 20 /* max number of components in shadowgram fits */ #define accumax 10000 /* max number of multiple detection source candidates */ #define SWAP(a,b) {double temp=(a);(a)=(b);(b)=temp;} /* function used in "gaussj_nr" */ struct euclid { /* structure with math constants */ double pi; /* pi */ double twopi; /* 2*pi */ double gtorad; /* pi/180.0 */ }; struct instr_data { /* structure with data describing the instrument geometry */ double coll_pitch; /* collimator pitch, nominally 7.05 mm */ double coll_h; /* height of collimator, nominally 57 mm */ double coll_w; /* halfthickness of lamellae, nominally 0.225 mm */ double coll_r; /* collimator radius nominally 125 mm */ double xshi; /* shift of microstrip X-axis (cathode number) wrt center collimator lamella (mm) */ double yshi; /* shift of microstrip Y-axis (backplane number) wrt center collimator lamella (mm)*/ double c_tiltx; /* average tilt of all collimator X lamellae - (mm shift of top edge wrt bottom edge) */ double c_tilty; /* average tilt of all collimator Y lamellae - (mm shift of top edge wrt bottom edge) */ float coll_wb; /* additional halfthickness of collimator bottom edge (in excess of coll_w) (mm) */ double coll_curv; /* scale factor for collimator pitch at top surfacce of the collimator */ double mask_r; /* radius of coded mask pattern nominally 267.5 mm */ double mask_height; /* distance from detectot window to coded mask plane nominally 3401 mm */ double hexa_dim; /* flat-to-flat dimension of the mask elements nominally 3.3 mm*/ int njwmask[200][200]; /* mask description array a la Niels Joergen */ double alfa; /* twist of mask X-axis wrt 'common-X' ('common-X' from JEM-X2 towards JEM-X1) */ double beta; /* twist of collimator X-axis wrt 'common-X' */ double gammav; /* twist of microstrip X-axis wrt 'common-X' */ /* +++++++++++++++++++ JEM-X to sky conversion */ double phase2; /* twist of 'common-X' wrt star tracker Y */ double x2x; /* quadratic term in transformation from JEM-X X-coord to sky Y-coord */ double y2y; /* quadratic term in transformation from JEM-X Y-coord to sky Z-coord */ double offX; /* zero offset of JEM-X X-coord wrt star tracker Y-coord */ double offY; /* zero offset of JEM-X Y-coord wrt star tracker Z-coord */ double scaleX; /* scale factor in transformation from JEM-X X-coord to sky Y-coord */ double scaleY; /* scale factor in transformation from JEM-X Y-coord to sky Z-coord */ double offQ; /* offset applied after transformation to star tracker coord. system */ double offR; /* offset applied after transformation to star tracker coord. system */ /* ++++++++++++++++++++ absorbtion & position uncertainty */ double absolen; /* mean absorbtion length of photons in the counter gas at current energy (mm) */ double scatt_len; /* rms value of the photon localization accuracy at current energy */ int scatt_delta[500]; /* derived distribution of detection points around interaction point (packed) */ float scatt_list[500]; /* derived distribution of detection points around interaction point (packed) */ int pixel_st[detdim]; /* input data for pixelfold routine */ unsigned char pixel_list[500000]; /* input data for pixelfold routine */ }; struct log_con { /* structure with control parameters and log messages */ char tmptxt[200]; /* text string for logging output */ char tmptxt2[128]; /* text string for logging output */ char error_text[128]; /* text string for logging error output */ int logstat; /* return status of logging routine */ int lognum; /* control parameter for logging routine */ int test; /* test output control */ int o_ctrl; /* image output control */ int pix_fold_ctrl; /* choice of pixelfold routine: 0: NL, 1: NJW */ char func_names[200][25]; /* names used in function calling frequency and time usage statistics */ int func_used_num; /* total number of different subroutines invoked */ int func_calling_num; /* identifier for calling routine */ double func_times[200]; /* accumulated time for each subroutine */ int func_calls[200]; /* Accumulated calls for each subroutine */ clock_t TT; /* clock structure (from time.h) */ char sweethome[200]; /* path to directory containing 'reference' directory */ char sweethome2[200]; /* path to 'reference' directory */ }; struct backpro { /* structure containing data for shadowgram backprojection and source search */ int FOV_radius; /* no of pixels corresponding to 6.6 degrees */ double indep; /* assumed interaction depth for photons during calculation of backprojection lists */ int backmodels; /* number of functions used to fit the background (normally 2) */ double pix2rad; /* conversion constant, JEM-X center image sky pixels to radians on the sky */ float soft_gr[detdim]; /* array holding information about which pixels to use in the data shadowgrams */ float empty[4][detdim]; /* empty field shadowgrams corresponding to four energy ranges */ float shadw[detdim]; /* shadowgram to be analyzed */ double empty_aux[30]; /* auxiliary information concerning the empty field shadowgrams */ double soft_tot[30]; /* auxiliary information concerning the the soft_tot shadowgram (use/dont_use pixels) */ double parameters[20]; /* auxiliary information concerning the backprojection lists */ float fitsimage[4][5][skydim]; /* sky images prepared for output */ float skyim_r[skydim]; /* raw sky image - before removal of large scale features */ int illum[skydim]; /* number of detector pixels illuminated as function of sky pixel number */ char access[skydim]; /* used/not_used sky pixels - limited by corresponding value of 'illum' */ int signiflim; /* threshold value used when defining 'access' from 'illum' */ float rsignif[skydim]; /* array for 'edge-enhancement' in source search - derived from values in 'illum' */ float com_RA[20]; /* RA-values for sources detected */ float com_dec[20]; /* dec-values for sources detected */ int aux_orbit; /* revolution number for current SCW */ int aux_pid; /* pid-value for current SCW */ int aux_pidv; /* sub-pid-value for current SCW */ }; struct imagerec { /* structure prepared for communication with routine for output of FITS sky-images */ double icen[2]; /* image center, RA and dec */ int idim[2]; /* image dimensions (x and y) */ double idel[2]; /* image scales (x and y) */ double irot[2][2]; /* image rotation (2x2 matrix) */ char imagtype[255]; /* imagetype 'textstring */ char imagextn[255]; /* imageextension 'textstring */ double ee_limits[2]; /* energy limits */ char instrum[10]; /* instrument ID 'textstring */ double rotang; /* INTEGRAL rotang */ double crpix[2]; /* ??? */ double ontime; /* shadowgram integration time */ int jmx_unit; int revol; /* revolution number for current SCW */ int pid; /* pid-value for current SCW */ int pidv; /* sub-pid-value for current SCW */ int n_extract; /* number of sources removed before generating final sky-image */ char comment[5][128]; }; int backpro_d(float shdgr[detdim], float skyim[skydim], struct log_con *logger, struct backpro *bacproj); int backpro_init(char skyfil[], double parameters[], struct log_con *logger); int findpeak(float *skyimage, int *smaxx, int *smaxy, double *amax, float edge, struct log_con *logger, struct backpro *backproj); float fturn(int jemx, float pos, struct log_con *logger); int imagefit(float shdg[], int jemx, int ee, float resid[], int n_source, float srcx[], float srcy[], double *solut, float norm_d[], float sumfun[], int last, double *rms, struct euclid *g_const, struct instr_data *jmx_id, struct log_con *logger, struct backpro *backproj); int fun(int k, int ii, int ee, float srcx[], float srcy[], int jemx, float norm_d[], int last, float *value, struct euclid *g_const, struct instr_data *jmx_id, struct log_con *logger, struct backpro *backproj); int fun2(int k, int ii, float *value, struct log_con *logger); int gaussj_nr(double *a, int n, double *b, int m, struct log_con *logger); int detecmap(float x_source, float y_source, char srcfun[detdim], int last, int jemx, float *norm, struct euclid *g_const, struct instr_data *jmx_id, struct log_con *logger, struct backpro *backproj); int pixelfold(short det[], int ee, float shadow[detdim], struct log_con *logger, struct backpro *backproj, struct instr_data *jmx_id); double rmscalc(float shad[], float soft_gr[], struct log_con *logger); double rmscalc_i(short sh[], float soft_gr[], struct log_con *logger); double shapefold(char det[], float comb_list[], int comb_delta[], int comb_len, float det_out[], int last, struct log_con *logger); 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); int irosloop(int jemx, int ee, float xx[sourcmax], float yy[sourcmax], float norm_d[sourcmax], double solut[sourcmax], float sumfun[sourcmax], float *goodrms, double *sh_rms2, int *goodfits, int *goodnsrc, float resid[detdim], float edge, float goodbet_g[sourcmax], int iterations, double limit_fraction, struct euclid *g_const, struct instr_data *jmx_id, struct log_con *logger, struct backpro *backproj); int getRAdec_init(int jemx, double p_RA[10000], double p_dec[10000], double p_posang[10000], struct euclid *g_const, struct log_con *logger, struct instr_data *jmx_id, struct backpro *backproj); int getRAdec(float x, float y, int jemx, float *s_RA, float *s_dec, struct euclid *g_const, struct log_con *logger, struct instr_data *jmx_id, struct backpro *backproj); int getxy(float s_RA, float s_dec, int jemx, float *x, float *y, struct euclid *g_const, struct instr_data *jmx_id, struct backpro *backproj, struct log_con *logger); void clean(float skyim_r[skydim], float skyim[skydim], struct log_con *logger); void clean2(float sky_r[skydim], float xx[], float yy[], int n_common, int backmodels, float skyim[skydim], struct log_con *logger, struct backpro *backproj); int logprint(char *text, int lognum); int struchk(double xm, double ym, double x_det, double y_det, int last, struct euclid *g_const, struct instr_data *jmx_id, struct log_con *logger); int sh_xy(double x_rms, double y_rms, struct log_con *logger, struct instr_data *jmx_id); int sh_depth(int sky_index, float track_list[], int track_delta[], int jemx, struct instr_data *jmx_id, struct log_con *logger, struct backpro *backproj); int sign(int x, struct log_con *logger);