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