00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef XSH_MODEL_KERNEL_H
00030 #define XSH_MODEL_KERNEL_H
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include <math.h>
00042 #include <string.h>
00043 #include <cpl.h>
00044 #include <xsh_data_instrument.h>
00045 #include <xsh_data_order.h>
00046
00047
00048
00049
00050
00051
00052 #define NIR_FIX 36
00053
00054
00055
00056
00057
00058 typedef double DOUBLE;
00059
00060
00061 typedef DOUBLE vec[4];
00062 typedef DOUBLE cvec[4];
00063 typedef DOUBLE mat[4][4];
00064
00065 typedef int detloc[3];
00066 typedef int XY[3];
00067
00068 typedef struct {
00069 DOUBLE best,min,max;
00070 int flag;
00071 char name[20];
00072 } ann_all_par;
00073
00074 typedef struct
00075 {
00076 int counter;
00077 double x;
00078 double y;
00079 int arm;
00080 double wave;
00081 double flux;
00082 int slit_pos;
00083 int order;
00084 } coord ;
00085
00086 struct xs_3
00087 {
00088
00089 int arm;
00090 double chipxpix,chipypix;
00091 double xsize_corr, ysize_corr;
00092 int ASIZE, BSIZE, SIZE;
00093 int morder, morder_min, morder_max;
00094 DOUBLE blaze_pad;
00095 DOUBLE temper, t_ir_p2, t_ir_p3;
00096 DOUBLE mues, nues, taues, slit_scale, es_s, es_w, es_x, es_xf, es_y, es_y_tot;
00097 DOUBLE fcol;
00098 DOUBLE mup1, cmup1, nup1, taup1;
00099 DOUBLE rind, rind2, rind3, rind_a1, rind_a2, rind_a3, rind_b1, rind_b2, rind_lm1, rind_lm2, rind_lm3, rind_wta0, rind_wta1, rind_wta2, rind_wtb0, rind_wtb1, rind_wtb2;
00100 DOUBLE rind_delta;
00101 DOUBLE mup2, nup2, taup2;
00102 DOUBLE mup3, nup3, taup3;
00103 DOUBLE mup4, nup4, taup4;
00104 DOUBLE mup5, nup5, taup5;
00105 DOUBLE mup6, nup6, taup6;
00106
00107 DOUBLE mug, nug, taug, sg, grat_alpha, grat_beta;
00108 DOUBLE mud, nud, taud, pix, pix_X, pix_Y, offx, offy, flipx, flipy, xpospix, ypospix, fdet;
00109
00110 detloc chippix;
00111 double xdet,ydet;
00112
00113 double chipx, chipy, chipxup, chipyup, chipxdown, chipydown, chiprot;
00114
00115
00116 double pc_x_xx, pc_x_x1, pc_x_yy, pc_x_y1, pc_x_xy, pc_x_x3, pc_x_x2y, pc_x_y2x, pc_x_y3;
00117 double pc_y_xx, pc_y_x1, pc_y_yy, pc_y_y1, pc_y_xy, pc_y_x3, pc_y_x2y, pc_y_y2x, pc_y_y3;
00118
00119 double pc4_x_xy3,pc4_x_x3y,pc4_x_x2y2,pc4_x_x4,pc4_x_y4;
00120 double pc4_y_xy3,pc4_y_x3y,pc4_y_x2y2,pc4_y_x4,pc4_y_y4;
00121
00122
00123 double d2_x3, d2_x2, d2_x1;
00124 double d2_y3x3, d2_y3x2, d2_y3x1,d2_y3x0,d2_y2x3, d2_y2x2, d2_y2x1,d2_y2x0,d2_y1x3, d2_y1x2, d2_y1x1,d2_y1x0;
00125
00126 double ca_x0,ca_x1,ca_y0,ca_y1;
00127
00128
00129 mat e_slit;
00130 mat mup_ir_cor, mup_ir_cor_out, toprism1, toprism2, toprism3, toprism4, toprism5, toprism6, prism_out, ret_prism2, ret_prism1, ret_prism_out1,ret_prism4, ret_prism3, ret_prism_out2,ret_prism6, ret_prism5, ret_prism_out3,todetector;
00131 mat tograt, grat_out;
00132 DOUBLE slit[10];
00133
00134
00135 double config_mjd;
00136 };
00137 typedef struct xs_3 xsh_xs_3;
00138
00139
00140
00141
00142
00143
00144 int xsh_3_readfile(double * abest, double * amin, double * amax, int * aname, const char *, struct xs_3 *, ann_all_par *);
00145 void xsh_3_init(struct xs_3 *);
00146 void xsh_ref_ind_read_old(const char * ref_ind_file, DOUBLE ** ref_ind, DOUBLE temper);
00147 void xsh_ref_ind_read(int arm, DOUBLE ** ref_ind, DOUBLE temper);
00148 void xsh_3_eval(DOUBLE lambda, int morder, DOUBLE ** ref_ind, struct xs_3 *p_xs_3);
00149 void xsh_3_eval_check(DOUBLE lambda, int morder, DOUBLE ** ref_ind, struct xs_3 *p_xs_3);
00150 void xsh_3_detpix(struct xs_3 *p_xs_3);
00151 void xsh_3_detpix_check(struct xs_3 *p_xs_3);
00152
00153 DOUBLE *xsh_alloc1Darray(int asize);
00154 int * xsh_alloc1Darray_INT(int asize);
00155 double** xsh_alloc2Darray( int asize, int bsize);
00156 double *** xsh_alloc3Darray2(int asize,int bsize,int csize);
00157 double *** xsh_alloc3Darray(int asize,int bsize,int csize);
00158 int ** xsh_alloc2Darray_i(int asize, int bsize);
00159 float ** xsh_alloc2Darray_f(int asize, int bsize);
00160 int xsh_free2Darray(double ** ccdtemp, int asize);
00161 int xsh_free3Darray(double *** ccdtemp, int asize,int bsize);
00162 int xsh_free2Darray_i(int ** ccdtemp, int asize);
00163 int xsh_free2Darray_f(float ** ccdtemp, int asize);
00164 double * xsh_copy2D_to_1D(double ** ccdtemp, int asize, int bsize);
00165 double** xsh_copy1D_to_2D(double * oneDccdtemp, int asize, int bsize);
00166
00167 void xsh_addvectors(vec, vec);
00168 void xsh_addvectors3D(vec, vec);
00169 void xsh_subtractvectors(vec,vec);
00170 DOUBLE xsh_scalarproduct(vec,vec);
00171 void xsh_multiply(vec a, DOUBLE k);
00172 void xsh_multiplythreematrix(mat A, mat B, mat C,mat D);
00173 void xsh_showvector(vec a);
00174
00175
00176 void xsh_normz(vec a);
00177 void xsh_normall(vec a);
00178
00179 void xsh_showmatrix(mat A);
00180 void xsh_initializematrix(mat A);
00181 void xsh_multiplymatrix(mat A,mat B, mat C);
00182
00183
00184 void xsh_matrixforvector(vec a,mat B,vec c);
00185 void xsh_transpose(mat A,mat B);
00186
00187 void xsh_rotationmatrix(mat A, const char axis, const DOUBLE angle);
00188 void xsh_rotin(mat A,const DOUBLE x_angle, const DOUBLE y_angle,
00189 const DOUBLE z_angle);
00190 void xsh_refract(vec, DOUBLE, vec);
00191
00192 void xsh_model_get_xy(xsh_xs_3* p_xs_3,
00193 xsh_instrument* instr,
00194 double lambda_nm,
00195 int morder,
00196 double slit,
00197 double* x,
00198 double* y);
00199 cpl_vector** xsh_model_locus(struct xs_3* p_xs_3,
00200 xsh_instrument* instr,
00201 double ent_slit_pos);
00202 cpl_frame* xsh_model_spectralformat_create(struct xs_3* p_xs_3,
00203 const char* tab_filename);
00204 cpl_table* xsh_model_THE(struct xs_3* p_xs_3,
00205 const char* line_list,
00206 xsh_instrument* instr,
00207 int num_ph,
00208 double sep_ph);
00209 cpl_frame* xsh_model_THE_create(struct xs_3* p_xs_3,
00210 xsh_instrument* instr,
00211 const char* line_list,
00212 int num_ph,
00213 double sep_ph,
00214 const char* THE_filename);
00215
00216 cpl_frame* xsh_model_pipe_anneal(cpl_frame* cfg_frame,
00217 cpl_frame* resid_frame,
00218 int maxit,
00219 double ann_fac,
00220 int scenario,int rec_id);
00221
00222 double xsh_model_sellmeier_ext(int arm, double temper, double lam_sqr);
00223 double xsh_model_ref_ind_air(double temper, double lam_sqr);
00224
00225 void xsh_model_binxy(struct xs_3* p_xs_3,
00226 int bin_X,
00227 int bin_Y);
00228 cpl_vector * xsh_model_refining_detect(const cpl_vector* in,
00229 int fwhm,
00230 double sigma,
00231 int display);
00232 int xsh_model_first_anneal(
00233 cpl_parameterlist* parlist,
00234 cpl_frameset* frameset);
00235
00236 int xsh_model_first_anneal_save(const cpl_table *, xsh_instrument*,
00237 cpl_parameterlist *,cpl_frameset *) ;
00238
00239 int xsh_model_map_ifu(double xifu,
00240 double yifu,
00241 xsh_xs_3* p_xs_3);
00242
00243 int xsh_model_offset(DOUBLE disp_pix_shift,
00244 DOUBLE slit_pix_shift,
00245 struct xs_3* p_xs_3);
00246
00247 void xsh_order_edge_list_fit(xsh_order_list *list, int size, double* order,
00248 double* posx, double* posy,
00249 int deg_poly, int edge);
00250
00251 cpl_frame* xsh_model_order_edges_tab_create(xsh_xs_3* p_xs_3,
00252 const char* tab_filename);
00253 cpl_error_code
00254 xsh_model_maps_create(xsh_xs_3* p_xs_3,
00255 xsh_instrument* instr,
00256 const char * wtag,
00257 const char * stag,
00258 cpl_frame** wmap_frame,
00259 cpl_frame** smap_frame);
00260
00261 #endif