69#define mm2nm 1000000.0
72#if defined VERBOSE && VERBOSE > 0
73#define XSH_TRACE_MSG(array) \
74xsh_msg("array: %g, %g, %g, %g",array[0],array[1],array[2],array[3]);
76#define XSH_TRACE_MSG(array)
142 const char* tag=NULL;
155 }
else if(rec_id==1) {
166 }
else if (rec_id ==2 ) {
179 }
else if (rec_id ==3 ) {
193 }
else if (rec_id ==4 ) {
206 }
else if (rec_id ==5 ) {
227 const int size,
const int annealed,
228 cpl_propertylist* resid_header,
229 cpl_frame* resid_frame,
230 cpl_propertylist** result)
250 const char* resid_tbl_name=NULL;
251 cpl_table* resid_tbl=NULL;
257 check(resid_tbl_name=cpl_frame_get_filename(resid_frame));
259 check(resid_tbl=cpl_table_load(resid_tbl_name,1,0));
260 check(cpl_table_fill_column_window(resid_tbl,
262 check(cpl_table_fill_column_window(resid_tbl,
265 check(pxm=cpl_table_get_data_double(resid_tbl,
267 check(pym=cpl_table_get_data_double(resid_tbl,
271 for (jj=0;jj<
size;jj++) {
273 morder_cnt=msp_coord[jj].
order;
275 xsh_3_eval(p_wlarray[jj],morder_cnt,ref_ind,p_xs_3);
297 check(cpl_table_save(resid_tbl, resid_header, NULL,resid_tbl_name, CPL_IO_DEFAULT));
300 check(resx_min=cpl_table_get_column_min(resid_tbl,
302 check(resx_max=cpl_table_get_column_max(resid_tbl,
304 check(resx_avg=cpl_table_get_column_mean(resid_tbl,
306 check(resx_med=cpl_table_get_column_median(resid_tbl,
308 check(resx_rms=cpl_table_get_column_stdev(resid_tbl,
312 check(resy_min=cpl_table_get_column_min(resid_tbl,
314 check(resy_max=cpl_table_get_column_max(resid_tbl,
316 check(resy_avg=cpl_table_get_column_mean(resid_tbl,
318 check(resy_med=cpl_table_get_column_median(resid_tbl,
320 check(resy_rms=cpl_table_get_column_stdev(resid_tbl,
322 check(ndat=cpl_table_get_nrow(resid_tbl));
332 cpl_propertylist_append_int(*result,
"ESO QC MODEL NDAT",ndat) ;
361 return cpl_error_get_code();
447 if (p_xs_3->
arm!=2) {
477 DOUBLE lambda_um,lamf,rind_up,rind_down,xx,yy,dndT;
478 vec vres,slitpos2,slitpos,detproj;
480 mat mech={ {1,0,0,0},
481 {morder*(p_xs_3->
sg),1,0,0},
484 mat chrom_corr={ {1,0,0,0},
504 slitpos[1]=1.0*p_xs_3->
es_x;
510 if (p_xs_3->
arm==0) {
511 if (lambda>0.000425) {
512 slitpos[2]=-1.0*p_xs_3->
es_y_tot*(1.0+(lambda-0.000425)*p_xs_3->
offx);
515 slitpos[2]=-1.0*p_xs_3->
es_y_tot*(1.0+(lambda-0.000425)*p_xs_3->
offy);
518 else if (p_xs_3->
arm==1) {
519 if (lambda>0.000650) {
520 slitpos[2]=1.0*(p_xs_3->
es_y_tot)*(1.0+(lambda-0.000900)*p_xs_3->
offx);
523 slitpos[2]=1.0*(p_xs_3->
es_y_tot)*(1.0+(lambda-0.000018)*p_xs_3->
offy);
526 else if (p_xs_3->
arm==2) {
527 if (lambda>0.001400) {
528 slitpos[2]=1.0*(p_xs_3->
es_y_tot-p_xs_3->
es_y)*(1.0+(lambda-0.001600)*p_xs_3->
offx)+p_xs_3->
es_y;
531 slitpos[2]=1.0*(p_xs_3->
es_y_tot)*(1.0+(lambda-0.000990)*p_xs_3->
offy);
536 if (p_xs_3->
arm==0) {
563 lambda_um=lambda*
mm2um;
564 lamf=lambda_um*lambda_um;
566 if (p_xs_3->
arm==1) {
569 p_xs_3->
rind=sqrt(ref_ind[0][0]*lamf/(lamf-ref_ind[0][3])+ref_ind[0][1]*lamf/(lamf-ref_ind[0][4])+ref_ind[0][2]*lamf/(lamf-ref_ind[0][5])+1.0);
572 double lam_ig2=0.04963984;
573 double H=71.0867E-06;
574 double G=-50.2451E-06;
577 R=lamf/(lamf-lam_ig2);
578 dndT=(G*R+H*R*R)/(2.0*p_xs_3->
rind);
617 if (p_xs_3->
arm==2) {
626 rind_up=sqrt(ref_ind[1][0]*lamf/(lamf-ref_ind[1][3]*ref_ind[1][3])+ref_ind[1][1]*lamf/(lamf-ref_ind[1][4]*ref_ind[1][4])+ref_ind[1][2]*lamf/(lamf-ref_ind[1][5]*ref_ind[1][5])+1.0);
629 rind_down=sqrt(ref_ind[0][0]*lamf/(lamf-ref_ind[0][3]*ref_ind[0][3])+ref_ind[0][1]*lamf/(lamf-ref_ind[0][4]*ref_ind[0][4])+ref_ind[0][2]*lamf/(lamf-ref_ind[0][5]*ref_ind[0][5])+1.0);
632 p_xs_3->
rind2=rind_down+((p_xs_3->
t_ir_p2-ref_ind[0][6])/(ref_ind[1][6]-ref_ind[0][6]))*(rind_up-rind_down);
659 rind_up=sqrt(ref_ind[1][0]*lamf/(lamf-ref_ind[1][3]*ref_ind[1][3])+ref_ind[1][1]*lamf/(lamf-ref_ind[1][4]*ref_ind[1][4])+ref_ind[1][2]*lamf/(lamf-ref_ind[1][5]*ref_ind[1][5])+1.0);
662 rind_down=sqrt(ref_ind[0][0]*lamf/(lamf-ref_ind[0][3]*ref_ind[0][3])+ref_ind[0][1]*lamf/(lamf-ref_ind[0][4]*ref_ind[0][4])+ref_ind[0][2]*lamf/(lamf-ref_ind[0][5]*ref_ind[0][5])+1.0);
665 p_xs_3->
rind3=rind_down+((p_xs_3->
t_ir_p3-ref_ind[0][6])/(ref_ind[1][6]-ref_ind[0][6]))*(rind_up-rind_down);
731 if (p_xs_3->
arm==2) {
838 xx=(p_xs_3->
flipx)*(p_xs_3->
fdet)/((vres[3]/vres[1])*cos(p_xs_3->
nud)-sin(p_xs_3->
nud));
839 yy=(p_xs_3->
flipy)*(p_xs_3->
fdet)/((vres[3]/vres[2])*cos(p_xs_3->
mud)-sin(p_xs_3->
mud));
846 xx=(p_xs_3->
flipx)*(p_xs_3->
fdet)*vres[1];
847 yy=(p_xs_3->
flipy)*(p_xs_3->
fdet)*vres[2];
852 xx=(p_xs_3->
flipx)*(p_xs_3->
fdet)*2.0*vres[1];
853 yy=(p_xs_3->
flipy)*(p_xs_3->
fdet)*2.0*vres[2];
858 detproj[1]=xx*cos(-p_xs_3->
taud)+yy*sin(-p_xs_3->
taud);
859 detproj[2]=-xx*sin(-p_xs_3->
taud)+yy*cos(-p_xs_3->
taud);
865 p_xs_3->
morder=(float)(morder);
867 p_xs_3->
xdet=vres[1];
868 p_xs_3->
ydet=vres[2];
885 double xdet_c, xdet_c2, xdet_c3, ydet_c, ydet_c2, ydet_c3;
889 double pc_x, pc_y, dstn_x, dstn_y;
890 double xdet_c4, ydet_c4;
892 int array_size_fix=0;
908 double ydet3=ydet2*p_xs_3->
ydet;
910 double xdet3=xdet2*p_xs_3->
xdet;
913 xdet_c2=xdet_c*xdet_c;
914 xdet_c3=xdet_c2*xdet_c;
915 xdet_c4=xdet_c3*xdet_c;
918 ydet_c2=ydet_c*ydet_c;
919 ydet_c3=ydet_c2*ydet_c;
920 ydet_c4=ydet_c3*ydet_c;
928 (p_xs_3->
pc_x_xy*xdet_c*ydet_c)+
943 (p_xs_3->
pc_y_xy*xdet_c*ydet_c)+
980 dstn_y=(p_xs_3->
d2_x3*ydet_c3)+(p_xs_3->
d2_x2*ydet_c2)+(p_xs_3->
d2_x1*ydet_c);
991 else if (p_xs_3->
arm==2) {
996 if (p_xs_3->
d2_x3!=0.0) {
997 dstn_x=(p_xs_3->
d2_x3*xdet_c3)+(p_xs_3->
d2_x2*xdet_c2)+(p_xs_3->
d2_x1*xdet_c);
1007 dstn_y=(d2_y3*ydet_c3)+(d2_y2*ydet_c2)+(d2_y1*ydet_c);
1047 if(p_xs_3->
arm!=2) {
1058 if (p_xs_3->
pix_X>0.029) {
1061 if (p_xs_3->
pix_Y>0.029) {
1132 FILE *p_ref_ind_file;
1135 p_ref_ind_file=fopen(ref_ind_file,
"r");
1136 if(p_ref_ind_file==NULL) {
1137 printf(
"couldn't find ref_ind file\n");
1138 cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT);
1143 while (fscanf(p_ref_ind_file,
"%64lf %64lf %64lf %64lf %64lf %64lf %64lf\n",
1144 &ref_ind[ii][6],&ref_ind[ii][0],&ref_ind[ii][1],&ref_ind[ii][2],
1145 &ref_ind[ii][3],&ref_ind[ii][4],&ref_ind[ii][5]) !=EOF)
1148 if (temper>=ref_ind[ii][6])
1153 for (jj=0; jj<7; jj++)
1155 ref_ind[0][jj]=ref_ind[ii][jj];
1158 else if (temper<ref_ind[ii][6] && flag==1)
1162 for (jj=0; jj<7; jj++)
1164 ref_ind[1][jj]=ref_ind[ii][jj];
1170 if (flag!=2) printf(
"******* Temperature out of range! ******* %lf \n", temper);
1171 fclose(p_ref_ind_file);
1192 for (ii=2; ii<8; ii+=1) {
1193 for (jj=0;jj<7;jj+=1){
1201 ref_ind_T[ii][jj]=
znse[ii-2][jj];
1205 if (temper>=ref_ind_T[ii][6])
1210 for (jj=0; jj<7; jj++) {
1211 ref_ind_T[0][jj]=ref_ind_T[ii][jj];
1214 else if (temper<ref_ind_T[ii][6] && flag==1)
1218 for (jj=0; jj<7; jj++) {
1219 ref_ind_T[1][jj]=ref_ind_T[ii][jj];
1225 printf(
"******* Temperature out of range! ******* %lf \n", temper);
1226 for (jj=0; jj<7; jj++) {
1227 ref_ind_T[1][jj]=ref_ind_T[7][jj];
1244 if ((array=(
int *)cpl_malloc(asize*
sizeof(
int))) == NULL)
1246 printf(
"ERROR allocation memory for array1D int\n");
1260 if ((array=(
DOUBLE *)cpl_malloc(asize*
sizeof(
DOUBLE))) == NULL)
1262 printf(
"ERROR allocation memory for array1D double\n");
1279 if ((ccdtemp=(
double **)cpl_malloc(asize*
sizeof(
double *))) == NULL)
1281 printf(
"ERROR allocating memory for ccdtemp at the initial pointer\n");
1285 for (ii = 0; ii < asize; ii++)
1287 if ( (ccdtemp[ii]=(
double *)cpl_malloc(bsize*
sizeof(
double))) == NULL)
1289 printf(
"ERROR allocating doublle memory for ccdtemp at row=%d\n",ii);
1307 if ((ccdtemp=(
float **)cpl_malloc(asize*
sizeof(
float *))) == NULL)
1309 printf(
"ERROR allocating memory for ccdtemp at the initial pointer\n");
1313 for (ii = 0; ii < asize; ii++)
1315 if ( (ccdtemp[ii]=(
float *)cpl_malloc(bsize*
sizeof(
float))) == NULL)
1317 printf(
"ERROR allocating float memory for ccdtemp at row=%d\n",ii);
1336 if ((ccdtemp=(
int **)cpl_malloc(asize*
sizeof(
int *))) == NULL)
1338 printf(
"ERROR allocating memory for ccdtemp at the initial pointer\n");
1342 for (ii = 0; ii < asize; ii++)
1344 if ( (ccdtemp[ii]=(
int *)cpl_malloc(bsize*
sizeof(
int))) == NULL)
1346 printf(
"ERROR allocating int memory for ccdtemp at row=%d\n",ii);
1363 const int my_asize=asize;
1364 for (i=my_asize-1; i >=0; i--)
1366 if (ccdtemp[i] !=NULL) cpl_free(ccdtemp[i]);
1369 printf(
"Error freeing memory at row= %d\n", i);
1373 if( ccdtemp !=NULL) cpl_free(ccdtemp);
1376 printf(
"Error freeing memory at the initial pointer");
1392 for (i=asize-1; i >=0; i--)
1394 if (ccdtemp[i] !=NULL) cpl_free(ccdtemp[i]);
1397 printf(
"Error freeing memory at row= %d\n", i);
1401 if( ccdtemp !=NULL) cpl_free(ccdtemp);
1404 printf(
"Error freeing memory at the initial pointer");
1420 for (i=asize-1; i >=0; i--)
1422 if (ccdtemp[i] !=NULL) cpl_free(ccdtemp[i]);
1425 printf(
"Error freeing memory at row= %d\n", i);
1429 if( ccdtemp !=NULL) cpl_free(ccdtemp);
1432 printf(
"Error freeing memory at the initial pointer");
1449 double *oneDccdtemp=NULL;
1450 if ( (oneDccdtemp=(
double *)cpl_malloc(asize*bsize*
sizeof(
double))) == NULL)
1452 printf(
"ERROR allocating memory for oneDccdtemp\n");
1456 for (ii = 0; ii < asize; ii++)
1458 for (jj = 0; jj < bsize; jj++)
1460 oneDccdtemp[kk]=ccdtemp[ii][jj];
1479 double **ccdtemp=NULL;
1482 for (ii = 0; ii < asize; ii++)
1484 for (jj = 0; jj < bsize; jj++)
1486 ccdtemp[ii][jj]=oneDccdtemp[kk];
1506 if ((ccdtemp=(
double ***)cpl_malloc(asize*
sizeof(
double **))) == NULL)
1508 printf(
"ERROR allocating memory for ccdtemp at the initial pointer\n");
1529 if ((ccdtemp=(
double ***)cpl_malloc(asize*
sizeof(
double **))) == NULL)
1531 printf(
"ERROR allocating memory for ccdtemp at the initial pointer\n");
1535 for (ii = 0; ii < asize; ii++)
1537 if ( (ccdtemp[ii]=(
double **)cpl_malloc(bsize*
sizeof(
double*))) == NULL)
1539 printf(
"ERROR allocating memory for ccdtemp at row=%d\n",ii);
1544 for (jj = 0; jj < bsize; jj++)
1546 if ( (ccdtemp[ii][jj]=(
double *)cpl_malloc(csize*
sizeof(
double))) == NULL)
1548 printf(
"ERROR allocating memory for ccdtemp at row=%d\n",ii);
1568 for (i=asize-1; i >=0; i--)
1573 printf(
"Error freeing memory at slide= %d\n", i);
1577 if( ccdtemp !=NULL) cpl_free(ccdtemp);
1580 printf(
"Error freeing memory at the 3D initial pointer");
1607 for(i=0; i<
vectordim-1; i++) a[i]+=b[i+1];
1634 for(i=0; i<
vectordim; i++) scalar += a[i]*b[i];
1655 for(i=0; i<
vectordim; i++) printf(
"%lf ", a[i]*1000.0);
1669 double x2_sqr = a[2]*a[2];
1676 double x1_sqr = a[1]*a[1];
1683 double sum_sqrs = x1_sqr + x2_sqr;
1684 if (sum_sqrs > 1.0) {
1685 double norm = 1./sqrt (sum_sqrs);
1691 if (a[3]>=0) a[3]=sqrt(1.0- sum_sqrs);
1692 else a[3]=-sqrt(1.0-sum_sqrs);
1710 mag=1./sqrt(a[1]*a[1]+a[2]*a[2]+a[3]*a[3]);
1729 A[i][j] +=B[i][k]*
C[k][j];
1757 printf(
"%lf %lf %lf %lf\n", A[i][0],A[i][1],A[i][2],A[i][3]);
1806 temp[i] +=B[i][j]*c_j;
1837 double sin_a=sin(angle);
1838 double cos_a=cos(angle);
1846 A[2][2]=A[3][3]=cos_a;
1856 A[1][1]=A[3][3]=cos_a;
1865 A[1][1]=A[2][2]=cos_a;
1870 printf(
"Error on creating rotation matrix\n");
1917 mat mech={ {1,0,0,0},
1923 alpha=atan(in2[1]/in2[3]);
1947 DOUBLE phi, pheta, y_signflag, z_signflag, sin_refrangle;
1950 phi=atan(sqrt(a[1]*a[1]+a[2]*a[2])/a[3]);
1951 pheta=atan(a[1]/a[2]);
1952 if (a[2]<0.0) y_signflag=-1.0;
1953 if (a[3]<0.0) z_signflag=-1.0;
1955 sin_refrangle = sin(phi)/rind;
1957 b[1]=z_signflag*y_signflag*sin(pheta)*sin_refrangle;
1958 b[2]=z_signflag*y_signflag*cos(pheta)*sin_refrangle;
1959 b[3]=z_signflag*cos(asin(sin_refrangle));
2008static cpl_error_code
2010 const double slit_max,
2013 cpl_propertylist** plist)
2017 double med_slit_cen=0;
2018 double med_slit_up=0;
2019 double med_slit_lo=0;
2020 double med_slit_slicup=0;
2021 double med_slit_sliclo=0;
2025 med_slit_cen = (slit_min+slit_max)/2.0;
2029 med_slit_slicup =
IFU_HI+med_slit_cen;
2030 med_slit_sliclo =
IFU_LOW+med_slit_cen;
2036 for( morder = p_xs_3->
morder_min; morder <= p_xs_3->morder_max; morder++){
2044 for( morder = p_xs_3->
morder_min; morder <= p_xs_3->morder_max; morder++){
2052 return cpl_error_get_code();
2072 const char * wtag,
const char * stag, cpl_frame** wmap_frame,
2073 cpl_frame** smap_frame,
const int save_tmp)
2079 DOUBLE blaze_wav, lam_min, lam_max, lam_inc;
2084 int slitlet, slitlet_min, slitlet_max;
2086 double slit_min, slit_max, slit_inc, slit_x, slit_y;
2091 cpl_image* ccd_wave_ima = NULL;
2092 cpl_image* ccd_slit_ima = NULL;
2093 cpl_image* ccd_mask_ima = NULL;
2094 cpl_image* ccd_imap_ima = NULL;
2096 cpl_polynomial * fit_wave_2d = NULL;
2097 cpl_polynomial * fit_slit_2d = NULL;
2098 cpl_matrix * mat_xy_sampling_points = NULL;
2099 cpl_vector * vec_w_sampling_points = NULL;
2100 cpl_vector * vec_s_sampling_points = NULL;
2102 cpl_vector* val = NULL;
2103 double* pval = NULL;
2106 double* oneD_AB = NULL;
2107 cpl_propertylist* plist = NULL;
2109 int array_size_fix = 0;
2118 cpl_table* tab_xy = NULL;
2135 xsh_msg(
"Generate physical model based wave and slit maps");
2143 slit_min =
IFU_LOW + 0.000001;
2144 slit_max =
IFU_HI - 0.000001;
2145 slit_inc = 0.05 * (slit_max - slit_min) *
binx;
2151 slit_inc = 0.02 * (slit_max - slit_min) *
binx;
2183 es_x_config = p_xs_3->
es_x;
2185 size_x = p_xs_3->
ASIZE + array_size_fix;
2186 size_y = p_xs_3->
BSIZE;
2189 ccd_wave_ima = cpl_image_new(size_x, size_y, CPL_TYPE_DOUBLE);
2190 ccd_slit_ima = cpl_image_new(size_x, size_y, CPL_TYPE_DOUBLE);
2191 ccd_mask_ima = cpl_image_new(size_x, size_y, CPL_TYPE_INT);
2192 ccd_imap_ima = cpl_image_new(size_x, size_y, CPL_TYPE_INT);
2194 ccd_wav = cpl_image_get_data_double(ccd_wave_ima);
2195 ccd_slit = cpl_image_get_data_double(ccd_slit_ima);
2196 ccd_imap = cpl_image_get_data_int(ccd_imap_ima);
2197 ccd_mask = cpl_image_get_data_int(ccd_mask_ima);
2200 const cpl_size max_deg_2d_w = 5;
2201 const cpl_size max_deg_2d_s = 5;
2203 double x_ord_min = 9999;
2204 double x_ord_max = -1;
2205 double y_ord_min = 9999;
2206 double y_ord_max = -1;
2207 cpl_error_code error2d;
2220 double two_sin_times_minus_nug=2 * (sin(-p_xs_3->
nug));
2222 val = cpl_vector_new(2);
2223 pval = cpl_vector_get_data(val);
2226 for (morder_cnt = p_xs_3->
morder_min; morder_cnt <= p_xs_3->morder_max;
2231 blaze_wav = two_sin_times_minus_nug / (morder_cnt * p_xs_3->
sg);
2233 * ((double) (morder_cnt) / ((double) (morder_cnt) - 0.5));
2235 * ((double) (morder_cnt) / (0.5 + (double) (morder_cnt)));
2236 lam_inc = (lam_max - lam_min) / (0.5 * size_y);
2243 for (slitlet = slitlet_min; slitlet < slitlet_max + 1; slitlet++) {
2253 if (slitlet == -1) {
2256 }
else if (slitlet == 1) {
2264 for (slit_y = slit_min; slit_y <= slit_max; slit_y += slit_inc) {
2268 cpl_msg_error(__func__,
"Outside slitlet array");
2269 return CPL_ERROR_UNSPECIFIED;
2277 for (lambda = lam_min - p_xs_3->
blaze_pad;
2278 lambda <= lam_max + p_xs_3->blaze_pad; lambda += lam_inc) {
2280 lambda_nm = lambda *
mm2nm;
2282 xsh_3_eval(lambda, morder_cnt, ref_ind, p_xs_3);
2289 if (p_xs_3->
chippix[0] == 1) {
2306 fit_size = fit_index;
2313 mat_xy_sampling_points = cpl_matrix_new(2, fit_size);
2314 vec_w_sampling_points = cpl_vector_new(fit_size);
2315 vec_s_sampling_points = cpl_vector_new(fit_size);
2320 tab_xy = cpl_table_new(fit_size);
2321 cpl_table_new_column(tab_xy,
"X", CPL_TYPE_DOUBLE);
2322 cpl_table_new_column(tab_xy,
"Y", CPL_TYPE_DOUBLE);
2323 cpl_table_new_column(tab_xy,
"W", CPL_TYPE_DOUBLE);
2324 cpl_table_new_column(tab_xy,
"S", CPL_TYPE_DOUBLE);
2325 cpl_table_new_column(tab_xy,
"ord", CPL_TYPE_INT);
2327 cpl_table_fill_column_window_int(tab_xy,
"ord", 0, fit_size, 0);
2328 cpl_table_fill_column_window_double(tab_xy,
"X", 0, fit_size, 0);
2329 cpl_table_fill_column_window_double(tab_xy,
"Y", 0, fit_size, 0);
2330 cpl_table_fill_column_window_double(tab_xy,
"W", 0, fit_size, 0);
2331 cpl_table_fill_column_window_double(tab_xy,
"S", 0, fit_size, 0);
2344 pxy = cpl_matrix_get_data(mat_xy_sampling_points);
2345 pw = cpl_vector_get_data(vec_w_sampling_points);
2346 ps = cpl_vector_get_data(vec_s_sampling_points);
2348 ptx = cpl_table_get_data_double(tab_xy,
"X");
2349 pty = cpl_table_get_data_double(tab_xy,
"Y");
2350 pts = cpl_table_get_data_double(tab_xy,
"S");
2351 ptw = cpl_table_get_data_double(tab_xy,
"W");
2352 pto = cpl_table_get_data_int(tab_xy,
"ord");
2362 for (slit_y = slit_min; slit_y <= slit_max; slit_y += slit_inc) {
2366 cpl_msg_error(__func__,
"Outside slitlet array");
2367 return CPL_ERROR_UNSPECIFIED;
2375 for (lambda = lam_min - p_xs_3->
blaze_pad;
2376 lambda <= lam_max + p_xs_3->blaze_pad; lambda += lam_inc) {
2378 lambda_nm = lambda *
mm2nm;
2380 xsh_3_eval(lambda, morder_cnt, ref_ind, p_xs_3);
2388 if (p_xs_3->
chippix[0] == 1) {
2390 if (p_xs_3->
chippix[1] >= 1 && p_xs_3->
chippix[1] < size_x + 1 &&
2396 pw[fit_index] = lambda_nm;
2397 ps[fit_index] = slit_y;
2398 check(cpl_matrix_set(mat_xy_sampling_points,0,fit_index,x_val));
2399 check(cpl_matrix_set(mat_xy_sampling_points,1,fit_index,y_val));
2400 pto[fit_index] = morder_cnt;
2401 ptx[fit_index] = x_val;
2402 pty[fit_index] = y_val;
2403 pts[fit_index] = slit_y;
2404 ptw[fit_index] = lambda_nm;
2410 x_ord_min = (x_ord_min < x_val) ? x_ord_min : x_val;
2411 x_ord_max = (x_ord_max > x_val) ? x_ord_max : x_val;
2413 y_ord_min = (y_ord_min < y_val) ? y_ord_min : y_val;
2414 y_ord_max = (y_ord_max > y_val) ? y_ord_max : y_val;
2429 fit_wave_2d = cpl_polynomial_new(2);
2430 fit_slit_2d = cpl_polynomial_new(2);
2431 sprintf(filename,
"tab_xy_%2.2d.fits", morder_cnt);
2435 "SIZES vec=%" CPL_SIZE_FORMAT
" ncol=%" CPL_SIZE_FORMAT
" nrow=%" CPL_SIZE_FORMAT
" pol size=%" CPL_SIZE_FORMAT
"", cpl_vector_get_size(vec_w_sampling_points), cpl_matrix_get_ncol(mat_xy_sampling_points), cpl_matrix_get_nrow(mat_xy_sampling_points), cpl_polynomial_get_dimension(fit_wave_2d));
2453 error2d=cpl_polynomial_fit(fit_wave_2d,mat_xy_sampling_points, NULL,vec_w_sampling_points, NULL, CPL_FALSE,NULL, &max_deg_2d_w));
2457 error2d=cpl_polynomial_fit(fit_slit_2d,mat_xy_sampling_points, NULL,vec_s_sampling_points, NULL, CPL_FALSE,NULL, &max_deg_2d_s));
2459 sx = (int) (x_ord_max - x_ord_min + 0.5);
2462 x_min = (int) (x_ord_min + 0.5);
2463 y_min = (int) (y_ord_min + 0.5);
2464 x_max = (int) (x_ord_max + 0.5);
2465 y_max = (int) (y_ord_max + 0.5);
2468 memset(ccd_mask,0,
sizeof(
int)*size_x*size_y);
2469 int jj_times_size_x=0;
2470 for (jj = y_min; jj <= y_max; jj++) {
2471 jj_times_size_x=jj * size_x;
2472 for (ii = x_min; ii <= x_max; ii++) {
2473 ccd_mask[jj_times_size_x + ii] = 1;
2481 int y_det_times_size_x=0;
2482 for (j = 0; j < sy; j++) {
2486 pval[1] = y_det + 1;
2489 y_det_times_size_x=y_det*size_x;
2490 for (i = 0; i < sx; i++) {
2492 pval[0] = x_det + 1;
2495 int pix_pos=y_det_times_size_x + x_det;
2496 if (ccd_mask[pix_pos] == 1) {
2497 s_val = cpl_polynomial_eval(fit_slit_2d, val);
2498 if (s_val > slit_min) {
2499 if (s_val < slit_max) {
2501 w_val = cpl_polynomial_eval(fit_wave_2d, val);
2503 ccd_wav[pix_pos] = w_val;
2504 ccd_slit[pix_pos] = s_val;
2505 ccd_imap[pix_pos] = i_val;
2521 cpl_msg_error(__func__,
"Cannot free 2D array ref_ind");
2522 return CPL_ERROR_UNSPECIFIED;
2529 check(plist=cpl_propertylist_new());
2530 sprintf(filename,
"%s.fits", wtag);
2540 cpl_image_save(ccd_wave_ima,filename,CPL_BPP_IEEE_FLOAT,plist,CPL_IO_DEFAULT));
2547 CPL_FRAME_GROUP_PRODUCT, CPL_FRAME_LEVEL_FINAL);
2550 " wave map frame %s %s", cpl_frame_get_filename(*wmap_frame), cpl_frame_get_tag(*wmap_frame));
2556 check(plist=cpl_propertylist_new());
2557 sprintf(filename,
"%s.fits", stag);
2563 cpl_image_save(ccd_slit_ima,filename,CPL_BPP_IEEE_FLOAT,plist,CPL_IO_DEFAULT));
2567 cpl_image_save(ccd_imap_ima,filename,CPL_BPP_32_SIGNED,NULL,CPL_IO_EXTEND));
2575 CPL_FRAME_GROUP_PRODUCT, CPL_FRAME_LEVEL_FINAL);
2577 " slit map frame %s %s", cpl_frame_get_filename(*smap_frame), cpl_frame_get_tag(*smap_frame));
2598 return cpl_error_get_code();
2619 double xifu_mm, yifu_mm,es_x_tot;
2676 double ent_slit_pos)
2678 int n_order, morder_cnt;
2681 DOUBLE blaze_wav, lam_min, lam_max;
2682 DOUBLE pixwavlast, pixylast, pixxlast;
2683 int chipdist_current;
2684 double* trace_lam=NULL;
2685 double* trace_xdisp=NULL;
2687 cpl_vector** loci=NULL ;
2726 trace_out=fopen(
"trace.dat",
"w");
2728 cpl_msg_error(__func__,
"Cannot allocate 2D array");
2733 cpl_msg_error(__func__,
"Cannot allocate 2D array");
2738 cpl_msg_error(__func__,
"Cannot allocate 2D array");
2747 if ((loci=cpl_malloc(n_order*
sizeof(cpl_vector *)))==NULL) {
2748 cpl_msg_error(__func__,
"Cannot allocate loci array");
2752 for (ii=0; ii<n_order; ii++) {
2753 loci[ii] = cpl_vector_new(p_xs_3->
SIZE) ;
2754 cpl_vector_fill(loci[ii], 0.0) ;
2756 for (morder_cnt=p_xs_3->
morder_min; morder_cnt<=p_xs_3->morder_max; morder_cnt+=1) {
2757 for (ii=0;ii<p_xs_3->
SIZE;ii+=1) {
2760 trace_xdisp[ii]=0.0;
2762 blaze_wav=2*(sin(-p_xs_3->
nug))/(morder_cnt*p_xs_3->
sg);
2763 lam_max=blaze_wav*((double)(morder_cnt)/((double)(morder_cnt)-0.5));
2764 lam_min=blaze_wav*((double)(morder_cnt)/(0.5+(double)(morder_cnt)));
2766 chipdist_current=3000;
2774 for (lambda=lam_min-p_xs_3->
blaze_pad; lambda<=lam_max+p_xs_3->blaze_pad;
2775 lambda+=(lam_max-lam_min)/10000.0) {
2776 lambda_nm=
mm2nm*lambda;
2777 xsh_3_eval(lambda,morder_cnt,ref_ind,p_xs_3);
2798 trace_lam[p_xs_3->
chippix[2]-1]=pixwavlast+(lambda_nm-pixwavlast)*
2799 ((
double)(chipdist_current)-0.5-pixylast)/(p_xs_3->
ypospix-pixylast);
2800 trace_xdisp[p_xs_3->
chippix[2]-1]=pixxlast+(p_xs_3->
xpospix-pixxlast)*
2801 ((
double)(chipdist_current)-0.5-pixylast)/(p_xs_3->
ypospix-pixylast);
2802 trace_mm[p_xs_3->
chippix[2]-1]=morder_cnt;
2803 chipdist_current=p_xs_3->
chippix[2]+1;
2810 pixwavlast=lambda_nm;
2812 for (ii=0;ii<p_xs_3->
SIZE;ii+=1) {
2813 fprintf(trace_out,
"%d %lf %lf %d\n", trace_mm[ii], trace_lam[ii], trace_xdisp[ii], ii);
2815 cpl_vector_set(loci[morder_cnt-p_xs_3->
morder_min], ii, trace_xdisp[ii]) ;
2819 cpl_free(trace_lam);
2820 cpl_free(trace_xdisp);
2825 cpl_msg_error(__func__,
"Cannot free 2D array ref_ind");
2853 double ent_slit_pos,
2871 lambda=lambda_nm/
mm2nm;
2909 if (ref_ind != NULL){
2928 if (bin_X!=1 || bin_Y!=1) {
2931 if (p_xs_3->
arm==0) {
2933 cpl_msg_info(__func__,
"Setting %d x %d binning for UVB arm",bin_X,bin_Y);
2937 else if (p_xs_3->
arm==1) {
2939 cpl_msg_info(__func__,
"Setting %d x %d binning for VIS arm",bin_X,bin_Y);
2945 cpl_msg_warning(__func__,
"NIR arm does not support binned data");
2952 p_xs_3->
pix_X=p_xs_3->
pix*(float)(bin_X);
2953 p_xs_3->
pix_Y=p_xs_3->
pix*(float)(bin_Y);
2954 p_xs_3->
ASIZE=instr_config->
nx;
2955 p_xs_3->
ASIZE/=bin_X;
2956 p_xs_3->
BSIZE=instr_config->
ny;
2957 p_xs_3->
BSIZE/=bin_Y;
2958 p_xs_3->
SIZE=instr_config->
ny;
2959 p_xs_3->
SIZE/=bin_Y;
2981 const char* tab_filename)
3022 int blz_frac_xmin=0;
3023 int blz_frac_ymin=0;
3025 int blz_frac_xmax=0;
3026 int blz_frac_ymax=0;
3031 cpl_table* sf_tab = NULL;
3032 cpl_table* sf_tab2 = NULL;
3033 cpl_frame* sf_frame=NULL;
3034 cpl_frame* sf_frame2=NULL;
3035 cpl_propertylist *sf_plist = NULL;
3036 cpl_propertylist *x_plist = NULL;
3040 const char* tag=NULL;
3041 const char* tag2=NULL;
3042 char tab_filename2[256];
3049 if (strcmp(tab_filename,
"spec_form.fits")==0) {
3055 sprintf(tab_filename2,
"long_%s",tab_filename);
3058 if (p_xs_3->
arm==0) {
3060 tag=
"SPEC_FORM_UVB";
3061 tag2=
"SPECTRAL_FORMAT_TAB_UVB";
3063 baseline=0.00000025;
3067 else if (p_xs_3->
arm==1) {
3069 tag=
"SPEC_FORM_VIS";
3070 tag2=
"SPECTRAL_FORMAT_TAB_VIS";
3076 else if (p_xs_3->
arm==2) {
3078 tag=
"SPEC_FORM_NIR";
3079 tag2=
"SPECTRAL_FORMAT_TAB_NIR";
3089 CPL_FRAME_TYPE_TABLE,
3090 CPL_FRAME_GROUP_PRODUCT,
3091 CPL_FRAME_LEVEL_FINAL));
3101 check(sf_tab = cpl_table_new(tab_size));
3102 check(cpl_table_new_column(sf_tab,
"ORDER", CPL_TYPE_INT) );
3103 check(cpl_table_new_column(sf_tab,
"LAMP", CPL_TYPE_STRING) );
3104 check(cpl_table_new_column(sf_tab,
"WLMIN", CPL_TYPE_FLOAT) );
3105 check(cpl_table_new_column(sf_tab,
"WLMAX", CPL_TYPE_FLOAT) );
3106 check(cpl_table_new_column(sf_tab,
"DISP_MIN", CPL_TYPE_FLOAT) );
3107 check(cpl_table_new_column(sf_tab,
"DISP_MAX", CPL_TYPE_FLOAT) );
3108 check(cpl_table_new_column(sf_tab,
"LFSR", CPL_TYPE_FLOAT) );
3109 check(cpl_table_new_column(sf_tab,
"UFSR", CPL_TYPE_FLOAT) );
3110 check(cpl_table_new_column(sf_tab,
"WLMINFUL", CPL_TYPE_FLOAT) );
3111 check(cpl_table_new_column(sf_tab,
"WLMAXFUL", CPL_TYPE_FLOAT) );
3114 check(sf_tab2 = cpl_table_new(tab_size));
3115 check(cpl_table_new_column(sf_tab2,
"ORDER", CPL_TYPE_INT) );
3116 check(cpl_table_new_column(sf_tab2,
"LAMP", CPL_TYPE_STRING) );
3117 check(cpl_table_new_column(sf_tab2,
"WLMIN", CPL_TYPE_FLOAT) );
3118 check(cpl_table_new_column(sf_tab2,
"WLEN0", CPL_TYPE_FLOAT) );
3119 check(cpl_table_new_column(sf_tab2,
"WLMAX", CPL_TYPE_FLOAT) );
3120 check(cpl_table_new_column(sf_tab2,
"XDISP_CEN", CPL_TYPE_INT) );
3121 check(cpl_table_new_column(sf_tab2,
"BLZ_FRAC_WLMIN", CPL_TYPE_DOUBLE) );
3122 check(cpl_table_new_column(sf_tab2,
"BLZ_FRAC_WLMEAN", CPL_TYPE_DOUBLE) );
3123 check(cpl_table_new_column(sf_tab2,
"BLZ_FRAC_WLMAX", CPL_TYPE_DOUBLE) );
3124 check(cpl_table_new_column(sf_tab2,
"WLCEN", CPL_TYPE_DOUBLE) );
3125 check(cpl_table_new_column(sf_tab2,
"BAND", CPL_TYPE_FLOAT) );
3126 check(cpl_table_new_column(sf_tab2,
"BLZ_FRAC_DISP_MIN", CPL_TYPE_INT) );
3127 check(cpl_table_new_column(sf_tab2,
"BLZ_FRAC_DISP_MAX", CPL_TYPE_INT) );
3128 check(cpl_table_new_column(sf_tab2,
"DISP_MIN", CPL_TYPE_FLOAT) );
3129 check(cpl_table_new_column(sf_tab2,
"DISP_MAX", CPL_TYPE_FLOAT) );
3130 check(cpl_table_new_column(sf_tab2,
"BLZ_FRAC_XDISP_MIN", CPL_TYPE_INT) );
3131 check(cpl_table_new_column(sf_tab2,
"BLZ_FRAC_XDISP_MAX", CPL_TYPE_INT) );
3132 check(cpl_table_new_column(sf_tab2,
"LFSR", CPL_TYPE_FLOAT) );
3133 check(cpl_table_new_column(sf_tab2,
"BLAZE", CPL_TYPE_FLOAT) );
3134 check(cpl_table_new_column(sf_tab2,
"UFSR", CPL_TYPE_FLOAT) );
3135 check(cpl_table_new_column(sf_tab2,
"FSR", CPL_TYPE_FLOAT) );
3136 check(cpl_table_new_column(sf_tab2,
"BIN_LFSR", CPL_TYPE_DOUBLE) );
3137 check(cpl_table_new_column(sf_tab2,
"BIN_BLAZE", CPL_TYPE_DOUBLE) );
3138 check(cpl_table_new_column(sf_tab2,
"BIN_UFSR", CPL_TYPE_DOUBLE) );
3139 check(cpl_table_new_column(sf_tab2,
"WLMINFUL", CPL_TYPE_FLOAT) );
3140 check(cpl_table_new_column(sf_tab2,
"WLMAXFUL", CPL_TYPE_FLOAT) );
3142 for (morder_cnt=p_xs_3->
morder_min-extra_ord;morder_cnt<=p_xs_3->morder_max+extra_ord;morder_cnt+=1) {
3143 blaze_wav=2000000.0*(sin(-p_xs_3->
nug))/(morder_cnt*p_xs_3->
sg);
3144 ufsr=blaze_wav*((double)(morder_cnt)/((double)(morder_cnt)-0.5));
3145 lfsr=blaze_wav*((double)(morder_cnt)/(0.5+(double)(morder_cnt)));
3159 for (lambda_nm=lfsr-(1.5*fsr);lambda_nm<ufsr+(1.5*fsr);lambda_nm+=fsr/(3.0*p_xs_3->
SIZE)) {
3165 lambda=lambda_nm/
mm2nm;
3166 xsh_3_eval(lambda,morder_cnt,ref_ind,p_xs_3);
3176 wlmin_full=lambda_nm;
3181 blaze=((sin(sinc_arg))/sinc_arg)*((sin(sinc_arg))/sinc_arg);
3190 if ((cen_flag==0 && p_xs_3->
chippix[disp_coord]>=p_xs_3->
SIZE/2
3191 && p_xs_3->
arm<2) ||
3192 (cen_flag==0 && p_xs_3->
chippix[disp_coord]<=p_xs_3->
SIZE/2
3193 && p_xs_3->
arm==2)) {
3194 yc=p_xs_3->
chippix[3-disp_coord];
3198 if (blaze_flag==0 && blaze>blaze_min) {
3200 blz_frac_xmin=p_xs_3->
chippix[disp_coord];
3201 blz_frac_ymin=p_xs_3->
chippix[3-disp_coord];
3204 if (blaze_flag==1 && blaze>blaze_min) {
3206 blz_frac_xmax=p_xs_3->
chippix[disp_coord];
3207 blz_frac_ymax=p_xs_3->
chippix[3-disp_coord];
3209 if (blaze_flag==1 && blaze<blaze_min) {
3212 if (fsr_flag==0 && lambda_nm>lfsr*(1.0-buff)) {
3214 xmin=p_xs_3->
chippix[disp_coord];
3215 lam_low=lambda-baseline;
3216 xsh_3_eval(lam_low,morder_cnt,ref_ind,p_xs_3);
3219 lam_hi=lambda+baseline;
3220 xsh_3_eval(lam_hi,morder_cnt,ref_ind,p_xs_3);
3223 if (x_low>0.0 && x_hi>0.0) {
3224 if (p_xs_3->
arm==2) {
3225 binlfsr=((lam_hi-lam_low)/(x_low-x_hi))*
mm2nm;
3228 binlfsr=((lam_hi-lam_low)/(x_hi-x_low))*
mm2nm;
3235 if (fsr_flag==1 && lambda_nm>blaze_wav) {
3238 lam_low=lambda-baseline;
3239 xsh_3_eval(lam_low,morder_cnt,ref_ind,p_xs_3);
3242 lam_hi=lambda+baseline;
3243 xsh_3_eval(lam_hi,morder_cnt,ref_ind,p_xs_3);
3246 if (x_low>0.0 && x_hi>0.0) {
3247 if (p_xs_3->
arm==2) {
3248 binblaze=((lam_hi-lam_low)/(x_low-x_hi))*
mm2nm;
3251 binblaze=((lam_hi-lam_low)/(x_hi-x_low))*
mm2nm;
3259 xmax=p_xs_3->
chippix[disp_coord];
3260 if (lambda_nm>ufsr*(1.0+buff)) {
3262 lam_low=lambda-baseline;
3263 xsh_3_eval(lam_low,morder_cnt,ref_ind,p_xs_3);
3266 lam_hi=lambda+baseline;
3267 xsh_3_eval(lam_hi,morder_cnt,ref_ind,p_xs_3);
3270 if (x_low>0.0 && x_hi>0.0) {
3271 if (p_xs_3->
arm==2) {
3272 binufsr=((lam_hi-lam_low)/(x_low-x_hi))*
mm2nm;
3275 binufsr=((lam_hi-lam_low)/(x_hi-x_low))*
mm2nm;
3290 wlmax_full=lambda_nm;
3295 wlmean=(wlmin+wlmax)/2.0;
3325 if (morder_cnt>=p_xs_3->
morder_min && morder_cnt<=p_xs_3->morder_max) {
3326 check(cpl_table_set_int(sf_tab,
"ORDER", morder_cnt-p_xs_3->
morder_min,morder_cnt));
3329 check(cpl_table_set_float(sf_tab,
"WLMIN", morder_cnt-p_xs_3->
morder_min,(
float)((1.0-buff)*lfsr)));
3330 check(cpl_table_set_float(sf_tab,
"WLMAX", morder_cnt-p_xs_3->
morder_min,(
float)((1.0+buff)*ufsr)));
3331 check(cpl_table_set_float(sf_tab,
"DISP_MIN", morder_cnt-p_xs_3->
morder_min+extra_ord, (
float)(xmin)));
3332 check(cpl_table_set_float(sf_tab,
"DISP_MAX", morder_cnt-p_xs_3->
morder_min+extra_ord, (
float)(xmax)));
3333 check(cpl_table_set_float(sf_tab,
"DISP_MIN", morder_cnt-p_xs_3->
morder_min+extra_ord, (
float)(xmin)));
3334 check(cpl_table_set_float(sf_tab,
"DISP_MAX", morder_cnt-p_xs_3->
morder_min+extra_ord, (
float)(xmax)));
3335 check(cpl_table_set_float(sf_tab,
"WLMINFUL", morder_cnt-p_xs_3->
morder_min,(
float)(wlmin_full)));
3336 check(cpl_table_set_float(sf_tab,
"WLMAXFUL", morder_cnt-p_xs_3->
morder_min,(
float)(wlmax_full)));
3337 check(cpl_table_set_float(sf_tab,
"LFSR", morder_cnt-p_xs_3->
morder_min+extra_ord, (
float)(lfsr)));
3338 check(cpl_table_set_float(sf_tab,
"UFSR", morder_cnt-p_xs_3->
morder_min+extra_ord, (
float)(ufsr)));
3339 if (p_xs_3->
arm==0 && morder_cnt>20) {
3340 check(cpl_table_set_string(sf_tab,
"LAMP", morder_cnt-p_xs_3->
morder_min,
"D2"));
3343 check(cpl_table_set_string(sf_tab,
"LAMP", morder_cnt-p_xs_3->
morder_min,
"QTH"));
3346 check(cpl_table_set_int(sf_tab2,
"ORDER", morder_cnt-p_xs_3->
morder_min+extra_ord,morder_cnt));
3347 if (p_xs_3->
arm==0 && morder_cnt>20) {
3348 check(cpl_table_set_string(sf_tab2,
"LAMP", morder_cnt-p_xs_3->
morder_min,
"D2"));
3351 check(cpl_table_set_string(sf_tab2,
"LAMP", morder_cnt-p_xs_3->
morder_min,
"QTH"));
3353 check(cpl_table_set_int(sf_tab2,
"XDISP_CEN", morder_cnt-p_xs_3->
morder_min+extra_ord,yc));
3355 check(cpl_table_set_double(sf_tab2,
"BLZ_FRAC_WLMIN", morder_cnt-p_xs_3->
morder_min+extra_ord,wlmin));
3356 check(cpl_table_set_double(sf_tab2,
"BLZ_FRAC_WLMAX", morder_cnt-p_xs_3->
morder_min+extra_ord,wlmax));
3357 check(cpl_table_set_double(sf_tab2,
"BLZ_FRAC_WLMEAN", morder_cnt-p_xs_3->
morder_min+extra_ord,wlmean));
3359 check(cpl_table_set_float(sf_tab2,
"WLMIN", morder_cnt-p_xs_3->
morder_min+extra_ord,(1.0-buff)*lfsr) );
3360 check(cpl_table_set_float(sf_tab2,
"WLMAX", morder_cnt-p_xs_3->
morder_min+extra_ord,(1.0+buff)*ufsr));
3361 check(cpl_table_set_float(sf_tab2,
"BAND", morder_cnt-p_xs_3->
morder_min+extra_ord,band));
3362 check(cpl_table_set_float(sf_tab2,
"WLEN0", morder_cnt-p_xs_3->
morder_min+extra_ord,((1.0-buff)*lfsr+(1.0+buff)*ufsr)/2.0));
3363 check(cpl_table_set_float(sf_tab2,
"WLMINFUL", morder_cnt-p_xs_3->
morder_min,(
float)(wlmin_full)));
3364 check(cpl_table_set_float(sf_tab2,
"WLMAXFUL", morder_cnt-p_xs_3->
morder_min,(
float)(wlmax_full)));
3365 check(cpl_table_set_double(sf_tab2,
"WLCEN", morder_cnt-p_xs_3->
morder_min+extra_ord,wlcen));
3366 check(cpl_table_set_int(sf_tab2,
"BLZ_FRAC_DISP_MIN", morder_cnt-p_xs_3->
morder_min+extra_ord, blz_frac_xmin) );
3367 check(cpl_table_set_int(sf_tab2,
"BLZ_FRAC_DISP_MAX", morder_cnt-p_xs_3->
morder_min+extra_ord, blz_frac_xmax) );
3368 check(cpl_table_set_float(sf_tab2,
"DISP_MIN", morder_cnt-p_xs_3->
morder_min+extra_ord, (
float)(xmin)) );
3369 check(cpl_table_set_float(sf_tab2,
"DISP_MAX", morder_cnt-p_xs_3->
morder_min+extra_ord, (
float)(xmax)) );
3370 check(cpl_table_set_int(sf_tab2,
"BLZ_FRAC_XDISP_MIN", morder_cnt-p_xs_3->
morder_min+extra_ord, blz_frac_ymin) );
3371 check(cpl_table_set_int(sf_tab2,
"BLZ_FRAC_XDISP_MAX", morder_cnt-p_xs_3->
morder_min+extra_ord, blz_frac_ymax) );
3372 check(cpl_table_set_float(sf_tab2,
"LFSR", morder_cnt-p_xs_3->
morder_min+extra_ord, (
float)(lfsr)));
3373 check(cpl_table_set_float(sf_tab2,
"BLAZE", morder_cnt-p_xs_3->
morder_min+extra_ord, (
float)(blaze_wav)));
3374 check(cpl_table_set_float(sf_tab2,
"UFSR", morder_cnt-p_xs_3->
morder_min+extra_ord, (
float)(ufsr)));
3375 check(cpl_table_set_float(sf_tab2,
"FSR", morder_cnt-p_xs_3->
morder_min+extra_ord, (
float)(ufsr-lfsr)));
3376 check(cpl_table_set_double(sf_tab2,
"BIN_LFSR", morder_cnt-p_xs_3->
morder_min+extra_ord, binlfsr) );
3377 check(cpl_table_set_double(sf_tab2,
"BIN_BLAZE", morder_cnt-p_xs_3->
morder_min+extra_ord, binblaze) );
3378 check(cpl_table_set_double(sf_tab2,
"BIN_UFSR", morder_cnt-p_xs_3->
morder_min+extra_ord, binufsr ));
3381 sf_plist = cpl_propertylist_new();
3384 cpl_msg_info(__func__,
"Save the tables") ;
3386 x_plist=cpl_propertylist_new();
3393 check(cpl_table_save(sf_tab2, sf_plist, x_plist, tab_filename, CPL_IO_DEFAULT));
3394 xsh_msg(
" sf table %s %s %s", tab_filename, cpl_frame_get_filename(sf_frame),
3395 cpl_frame_get_tag(sf_frame));
3403 if (ref_ind != NULL){
3407 if ( cpl_error_get_code() != CPL_ERROR_NONE){
3441 const char* line_list,
3444 const char* THE_filename)
3450 DOUBLE blaze_wav, lam_min, lam_max, inten;
3451 cpl_table *lines_tab = NULL;
3452 int lines_number, line_no ;
3455 cpl_table* THE_tab = NULL;
3459 cpl_frame* THE_frame=NULL;
3460 cpl_propertylist *THE_plist = NULL;
3461 const char* tag=NULL;
3499 THE_tab = cpl_table_new(tab_size);
3508 if ((lines_tab = cpl_table_load(line_list, 1, 0))==NULL) {
3509 cpl_msg_error(__func__,
"Cannot find line list %s", line_list);
3512 lines_number = cpl_table_get_nrow(lines_tab) ;
3516 check(cpl_table_cast_column(lines_tab,
"DWAVELENGTH",
3522 check(cpl_table_cast_column(lines_tab,
"DFLUX",
3526 for (line_no=0 ; line_no<lines_number ; line_no++) {
3534 check(lambda_nm=cpl_table_get_float(lines_tab,
3536 check(inten = cpl_table_get(lines_tab,
3543 for (morder_cnt=p_xs_3->
morder_min;morder_cnt<=p_xs_3->morder_max; morder_cnt+=1) {
3545 blaze_wav=2*(sin(-p_xs_3->
nug))/(morder_cnt*p_xs_3->
sg);
3546 lam_max=blaze_wav*((double)(morder_cnt)/((double)(morder_cnt)-0.5));
3547 lam_min=blaze_wav*((double)(morder_cnt)/(0.5+(double)(morder_cnt)));
3548 lambda=lambda_nm*1e-6;
3549 if (lambda>lam_min-p_xs_3->
blaze_pad && lambda<lam_max+p_xs_3->blaze_pad) {
3550 for (spos_int=0;spos_int<num_ph; spos_int+=1) {
3552 spos=sep_ph*(spos_int-((num_ph-1)/2));
3556 spos=p_xs_3->
slit[spos_int];
3558 else if (num_ph==1) {
3559 spos=p_xs_3->
slit[4];
3564 xsh_3_eval(lambda,morder_cnt,ref_ind,p_xs_3);
3585 THE_plist = cpl_propertylist_new();
3587 check( cpl_table_set_size(THE_tab,fitsrow));
3589 check( cpl_table_save(THE_tab, THE_plist, NULL, THE_filename,
3604 CPL_FRAME_TYPE_TABLE,
3605 CPL_FRAME_GROUP_PRODUCT,
3606 CPL_FRAME_LEVEL_FINAL));
3608 xsh_msg(
" THE table %s %s",THE_filename,tag);
3615 if ( cpl_error_get_code() != CPL_ERROR_NONE){
3618 if (ref_ind != NULL){
3679 cpl_frame* resid_frame,
3685 cpl_table* conf_tab = NULL;
3686 const int model_coeff_num=300;
3689 double abest[model_coeff_num];
3690 double amin[model_coeff_num];
3691 double amax[model_coeff_num];
3692 int aname[model_coeff_num];
3699 DOUBLE* p_wlarray = NULL;
3700 cpl_frame* MODEL_CONF_OPT_frame=NULL;
3701 cpl_propertylist* MODEL_CONFIG_plist=NULL ;
3703 double *vlambda=NULL, *thpre_x=NULL, *thpre_y=NULL,
3704 *xgauss=NULL, *ygauss=NULL, *vorder=NULL;
3705 int *slitindex=NULL;
3706 coord* msp_coord = NULL;
3707 char out_cfg_filename[256];
3712 cpl_table* resid_tbl = NULL;
3713 cpl_propertylist *resid_header = NULL;
3714 const char* tag=NULL;
3720 p_all_par=&all_par[0];
3729 for (ii=0;ii<model_coeff_num;ii++) {
3730 sprintf((p_all_par+ii)->name,
"%s",
"\n");
3741 cpl_frame_get_filename(cfg_frame),
3742 cpl_frame_get_tag(cfg_frame),
3752 for (ii=0;ii<model_coeff_num;ii++) {
3770 for (ii=0;ii<100;ii++) {
3772 if (strncmp((p_all_par+ii)->name,
"fdet",4)==0) {
3773 abest[jj]=p_xs_3->
fdet;
3774 amin[jj]=p_xs_3->
fdet-(1.0*ann_fac);
3775 amax[jj]=p_xs_3->
fdet+(1.0*ann_fac);
3803 if (strncmp((p_all_par+ii)->name,
"mup1",4)==0) {
3810 if (strncmp((p_all_par+ii)->name,
"nup1",4)==0) {
3817 if (p_xs_3->
arm==2) {
3820 if (strncmp((p_all_par+ii)->name,
"mup3",4)==0) {
3827 if (strncmp((p_all_par+ii)->name,
"nup3",4)==0) {
3836 if (strncmp((p_all_par+ii)->name,
"mup5",4)==0) {
3843 if (strncmp((p_all_par+ii)->name,
"nup5",4)==0) {
3852 if (strncmp((p_all_par+ii)->name,
"mug",3)==0) {
3859 if (strncmp((p_all_par+ii)->name,
"nug",3)==0) {
3866 if (strncmp((p_all_par+ii)->name,
"taug",4)==0) {
3874 if (strncmp((p_all_par+ii)->name,
"mud",3)==0) {
3881 if (strncmp((p_all_par+ii)->name,
"nud",3)==0) {
3888 if (strncmp((p_all_par+ii)->name,
"taud",4)==0) {
3897 if (strncmp((p_all_par+ii)->name,
"es_y",4)==0) {
3898 abest[jj]=p_xs_3->
es_y;
3899 amin[jj]=p_xs_3->
es_y-(1.0*ann_fac);
3900 amax[jj]=p_xs_3->
es_y+(1.0*ann_fac);
3905 if (strncmp((p_all_par+ii)->name,
"chipx",5)==0) {
3906 abest[jj]=p_xs_3->
chipx;
3907 amin[jj]=p_xs_3->
chipx-(5.0*ann_fac);
3908 amax[jj]=p_xs_3->
chipx+(5.0*ann_fac);
3912 if (strncmp((p_all_par+ii)->name,
"chipy",5)==0) {
3913 abest[jj]=p_xs_3->
chipy;
3914 amin[jj]=p_xs_3->
chipy-(5.0*ann_fac);
3915 amax[jj]=p_xs_3->
chipy+(5.0*ann_fac);
3920 if (strncmp((p_all_par+ii)->name,
"sg",2)==0) {
3921 abest[jj]=p_xs_3->
sg;
3922 amin[jj]=p_xs_3->
sg-(1.0*ann_fac);
3923 amax[jj]=p_xs_3->
sg+(1.0*ann_fac);
3937 if (strncmp((p_all_par+ii)->name,
"taues",5)==0) {
3945 if (strncmp((p_all_par+ii)->name,
"fcol",4)==0) {
3946 abest[jj]=p_xs_3->
fcol;
3947 amin[jj]=p_xs_3->
fcol-(5.0*ann_fac);
3948 amax[jj]=p_xs_3->
fcol+(5.0*ann_fac);
3953 if (strncmp((p_all_par+ii)->name,
"slit_scale",10)==0) {
3962 if (strncmp((p_all_par+ii)->name,
"es_x",4)==0) {
3963 abest[jj]=p_xs_3->
es_x;
3964 amin[jj]=p_xs_3->
es_x-(0.1*ann_fac);
3965 amax[jj]=p_xs_3->
es_x+(0.1*ann_fac);
3976 for (ii=0;ii<100;ii++) {
3987 if (strncmp((p_all_par+ii)->name,
"es_y",4)==0) {
3988 abest[jj]=p_xs_3->
es_y;
3989 amin[jj]=p_xs_3->
es_y-(0.01*ann_fac);
3990 amax[jj]=p_xs_3->
es_y+(0.01*ann_fac);
3996 if (strncmp((p_all_par+ii)->name,
"es_x",4)==0) {
3997 abest[jj]=p_xs_3->
es_x;
3998 amin[jj]=p_xs_3->
es_x-(0.01*ann_fac);
3999 amax[jj]=p_xs_3->
es_x+(0.01*ann_fac);
4005 if (strncmp((p_all_par+ii)->name,
"mup1",4)==0) {
4012 if (strncmp((p_all_par+ii)->name,
"nup1",4)==0) {
4028 if (strncmp((p_all_par+ii)->name,
"mup2",4)==0) {
4035 if (strncmp((p_all_par+ii)->name,
"nup2",4)==0) {
4049 if (p_xs_3->
arm==2) {
4052 if (strncmp((p_all_par+ii)->name,
"mup3",4)==0) {
4059 if (strncmp((p_all_par+ii)->name,
"nup3",4)==0) {
4075 if (strncmp((p_all_par+ii)->name,
"mup4",4)==0) {
4082 if (strncmp((p_all_par+ii)->name,
"nup4",4)==0) {
4098 if (strncmp((p_all_par+ii)->name,
"mup5",4)==0) {
4105 if (strncmp((p_all_par+ii)->name,
"nup5",4)==0) {
4121 if (strncmp((p_all_par+ii)->name,
"mup6",4)==0) {
4128 if (strncmp((p_all_par+ii)->name,
"nup6",4)==0) {
4144 if (strncmp((p_all_par+ii)->name,
"mug",3)==0) {
4151 if (strncmp((p_all_par+ii)->name,
"nug",3)==0) {
4158 if (strncmp((p_all_par+ii)->name,
"taug",4)==0) {
4166 if (strncmp((p_all_par+ii)->name,
"mud",3)==0) {
4169 amin[jj]=p_xs_3->
mud/
DEG2RAD-(0.005*ann_fac);
4170 amax[jj]=p_xs_3->
mud/
DEG2RAD+(0.005*ann_fac);
4173 if (strncmp((p_all_par+ii)->name,
"nud",3)==0) {
4176 amin[jj]=p_xs_3->
nud/
DEG2RAD-(0.005*ann_fac);
4177 amax[jj]=p_xs_3->
nud/
DEG2RAD+(0.005*ann_fac);
4180 if (strncmp((p_all_par+ii)->name,
"taud",4)==0) {
4188 if (strncmp((p_all_par+ii)->name,
"fdet",4)==0) {
4189 abest[jj]=p_xs_3->
fdet;
4190 amin[jj]=p_xs_3->
fdet-(0.1*ann_fac);
4191 amax[jj]=p_xs_3->
fdet+(0.1*ann_fac);
4196 if (strncmp((p_all_par+ii)->name,
"chipx",5)==0) {
4197 abest[jj]=p_xs_3->
chipx;
4198 amin[jj]=p_xs_3->
chipx-(0.05*ann_fac);
4199 amax[jj]=p_xs_3->
chipx+(0.05*ann_fac);
4203 if (strncmp((p_all_par+ii)->name,
"chipy",5)==0) {
4204 abest[jj]=p_xs_3->
chipy;
4205 amin[jj]=p_xs_3->
chipy-(0.05*ann_fac);
4206 amax[jj]=p_xs_3->
chipy+(0.05*ann_fac);
4211 if (strncmp((p_all_par+ii)->name,
"sg",2)==0) {
4212 abest[jj]=p_xs_3->
sg;
4213 amin[jj]=p_xs_3->
sg-(0.5*ann_fac);
4214 amax[jj]=p_xs_3->
sg+(0.5*ann_fac);
4220 if (strncmp((p_all_par+ii)->name,
"pc_x_y1",7)==0) {
4222 amin[jj]=p_xs_3->
pc_x_y1-(0.01*ann_fac);
4223 amax[jj]=p_xs_3->
pc_x_y1+(0.01*ann_fac);
4227 if (strncmp((p_all_par+ii)->name,
"pc_y_x1",7)==0) {
4229 amin[jj]=p_xs_3->
pc_y_x1-(0.01*ann_fac);
4230 amax[jj]=p_xs_3->
pc_y_x1+(0.01*ann_fac);
4234 if (strncmp((p_all_par+ii)->name,
"pc_x_x1",7)==0) {
4236 amin[jj]=p_xs_3->
pc_x_x1-(0.01*ann_fac);
4237 amax[jj]=p_xs_3->
pc_x_x1+(0.01*ann_fac);
4241 if (strncmp((p_all_par+ii)->name,
"pc_y_y1",7)==0) {
4243 amin[jj]=p_xs_3->
pc_y_y1-(0.01*ann_fac);
4244 amax[jj]=p_xs_3->
pc_y_y1+(0.01*ann_fac);
4252 if (strncmp((p_all_par+ii)->name,
"slit_scale",10)==0) {
4260 if (strncmp((p_all_par+ii)->name,
"taues",5)==0) {
4283 if (strncmp((p_all_par+ii)->name,
"fcol",4)==0) {
4284 abest[jj]=p_xs_3->
fcol;
4285 amin[jj]=p_xs_3->
fcol-(0.1*ann_fac);
4286 amax[jj]=p_xs_3->
fcol+(0.1*ann_fac);
4366 if (scenario>=5 && scenario<8) {
4373 if (strncmp((p_all_par+ii)->name,
"chipx",5)==0) {
4374 abest[jj]=p_xs_3->
chipx;
4375 amin[jj]=p_xs_3->
chipx-(0.1*ann_fac);
4376 amax[jj]=p_xs_3->
chipx+(0.1*ann_fac);
4380 if (strncmp((p_all_par+ii)->name,
"chipy",5)==0) {
4381 abest[jj]=p_xs_3->
chipy;
4382 amin[jj]=p_xs_3->
chipy-(0.1*ann_fac);
4383 amax[jj]=p_xs_3->
chipy+(0.1*ann_fac);
4418 if (strncmp((p_all_par+ii)->name,
"pc_x_x1",7)==0) {
4420 amin[jj]=p_xs_3->
pc_x_x1-(0.001*ann_fac);
4421 amax[jj]=p_xs_3->
pc_x_x1+(0.001*ann_fac);
4425 if (strncmp((p_all_par+ii)->name,
"pc_x_xx",7)==0) {
4427 amin[jj]=p_xs_3->
pc_x_xx-(0.0001*ann_fac);
4428 amax[jj]=p_xs_3->
pc_x_xx+(0.0001*ann_fac);
4432 if (strncmp((p_all_par+ii)->name,
"pc_x_y1",7)==0) {
4434 amin[jj]=p_xs_3->
pc_x_y1-(0.001*ann_fac);
4435 amax[jj]=p_xs_3->
pc_x_y1+(0.001*ann_fac);
4439 if (strncmp((p_all_par+ii)->name,
"pc_x_yy",7)==0) {
4441 amin[jj]=p_xs_3->
pc_x_yy-(0.0001*ann_fac);
4442 amax[jj]=p_xs_3->
pc_x_yy+(0.0001*ann_fac);
4446 if (strncmp((p_all_par+ii)->name,
"pc_x_xy",7)==0) {
4448 amin[jj]=p_xs_3->
pc_x_xy-(0.0001*ann_fac);
4449 amax[jj]=p_xs_3->
pc_x_xy+(0.0001*ann_fac);
4453 if (strncmp((p_all_par+ii)->name,
"pc_x_x2y",8)==0) {
4455 amin[jj]=p_xs_3->
pc_x_x2y-(0.00001*ann_fac);
4456 amax[jj]=p_xs_3->
pc_x_x2y+(0.00001*ann_fac);
4460 if (strncmp((p_all_par+ii)->name,
"pc_x_y2x",8)==0) {
4462 amin[jj]=p_xs_3->
pc_x_y2x-(0.00001*ann_fac);
4463 amax[jj]=p_xs_3->
pc_x_y2x+(0.00001*ann_fac);
4467 if (strncmp((p_all_par+ii)->name,
"pc_x_x3",7)==0) {
4469 amin[jj]=p_xs_3->
pc_x_x3-(0.00001*ann_fac);
4470 amax[jj]=p_xs_3->
pc_x_x3+(0.00001*ann_fac);
4474 if (strncmp((p_all_par+ii)->name,
"pc_x_y3",7)==0) {
4476 amin[jj]=p_xs_3->
pc_x_y3-(0.00001*ann_fac);
4477 amax[jj]=p_xs_3->
pc_x_y3+(0.00001*ann_fac);
4481 if (strncmp((p_all_par+ii)->name,
"pc_y_x1",7)==0) {
4483 amin[jj]=p_xs_3->
pc_y_x1-(0.001*ann_fac);
4484 amax[jj]=p_xs_3->
pc_y_x1+(0.001*ann_fac);
4488 if (strncmp((p_all_par+ii)->name,
"pc_y_xx",7)==0) {
4490 amin[jj]=p_xs_3->
pc_y_xx-(0.0001*ann_fac);
4491 amax[jj]=p_xs_3->
pc_y_xx+(0.0001*ann_fac);
4495 if (strncmp((p_all_par+ii)->name,
"pc_y_y1",7)==0) {
4497 amin[jj]=p_xs_3->
pc_y_y1-(0.001*ann_fac);
4498 amax[jj]=p_xs_3->
pc_y_y1+(0.001*ann_fac);
4502 if (strncmp((p_all_par+ii)->name,
"pc_y_yy",7)==0) {
4504 amin[jj]=p_xs_3->
pc_y_yy-(0.0001*ann_fac);
4505 amax[jj]=p_xs_3->
pc_y_yy+(0.0001*ann_fac);
4509 if (strncmp((p_all_par+ii)->name,
"pc_y_xy",7)==0) {
4511 amin[jj]=p_xs_3->
pc_y_xy-(0.0001*ann_fac);
4512 amax[jj]=p_xs_3->
pc_y_xy+(0.0001*ann_fac);
4516 if (strncmp((p_all_par+ii)->name,
"pc_y_x2y",8)==0) {
4518 amin[jj]=p_xs_3->
pc_y_x2y-(0.00001*ann_fac);
4519 amax[jj]=p_xs_3->
pc_y_x2y+(0.00001*ann_fac);
4523 if (strncmp((p_all_par+ii)->name,
"pc_y_y2x",8)==0) {
4525 amin[jj]=p_xs_3->
pc_y_y2x-(0.00001*ann_fac);
4526 amax[jj]=p_xs_3->
pc_y_y2x+(0.00001*ann_fac);
4530 if (strncmp((p_all_par+ii)->name,
"pc_y_x3",7)==0) {
4532 amin[jj]=p_xs_3->
pc_y_x3-(0.00001*ann_fac);
4533 amax[jj]=p_xs_3->
pc_y_x3+(0.00001*ann_fac);
4537 if (strncmp((p_all_par+ii)->name,
"pc_y_y3",7)==0) {
4539 amin[jj]=p_xs_3->
pc_y_y3-(0.00001*ann_fac);
4540 amax[jj]=p_xs_3->
pc_y_y3+(0.00001*ann_fac);
4544 if (p_xs_3->
arm<2) {
4545 if (strncmp((p_all_par+ii)->name,
"d2_x1",5)==0) {
4546 abest[jj]=p_xs_3->
d2_x1;
4547 amin[jj]=p_xs_3->
d2_x1-(0.01*ann_fac);
4548 amax[jj]=p_xs_3->
d2_x1+(0.01*ann_fac);
4552 if (strncmp((p_all_par+ii)->name,
"d2_x2",5)==0) {
4553 abest[jj]=p_xs_3->
d2_x2;
4554 amin[jj]=p_xs_3->
d2_x2-(0.001*ann_fac);
4555 amax[jj]=p_xs_3->
d2_x2+(0.001*ann_fac);
4559 if (strncmp((p_all_par+ii)->name,
"d2_x3",5)==0) {
4560 abest[jj]=p_xs_3->
d2_x3;
4561 amin[jj]=p_xs_3->
d2_x3-(0.0001*ann_fac);
4562 amax[jj]=p_xs_3->
d2_x3+(0.0001*ann_fac);
4567 else if (p_xs_3->
arm==2) {
4568 if (strncmp((p_all_par+ii)->name,
"pc4_x_xy3",9)==0) {
4570 amin[jj]=p_xs_3->
pc4_x_xy3-(0.000001*ann_fac);
4571 amax[jj]=p_xs_3->
pc4_x_xy3+(0.000001*ann_fac);
4575 if (strncmp((p_all_par+ii)->name,
"pc4_x_x3y",9)==0) {
4577 amin[jj]=p_xs_3->
pc4_x_x3y-(0.000001*ann_fac);
4578 amax[jj]=p_xs_3->
pc4_x_x3y+(0.000001*ann_fac);
4582 if (strncmp((p_all_par+ii)->name,
"pc4_x_x2y2",10)==0) {
4584 amin[jj]=p_xs_3->
pc4_x_x2y2-(0.000001*ann_fac);
4585 amax[jj]=p_xs_3->
pc4_x_x2y2+(0.000001*ann_fac);
4589 if (strncmp((p_all_par+ii)->name,
"pc4_x_x4",8)==0) {
4591 amin[jj]=p_xs_3->
pc4_x_x4-(0.000001*ann_fac);
4592 amax[jj]=p_xs_3->
pc4_x_x4+(0.000001*ann_fac);
4596 if (strncmp((p_all_par+ii)->name,
"pc4_x_y4",8)==0) {
4598 amin[jj]=p_xs_3->
pc4_x_y4-(0.000001*ann_fac);
4599 amax[jj]=p_xs_3->
pc4_x_y4+(0.000001*ann_fac);
4603 if (strncmp((p_all_par+ii)->name,
"pc4_y_xy3",9)==0) {
4605 amin[jj]=p_xs_3->
pc4_y_xy3-(0.000001*ann_fac);
4606 amax[jj]=p_xs_3->
pc4_y_xy3+(0.000001*ann_fac);
4610 if (strncmp((p_all_par+ii)->name,
"pc4_y_xy3",9)==0) {
4612 amin[jj]=p_xs_3->
pc4_y_xy3-(0.000001*ann_fac);
4613 amax[jj]=p_xs_3->
pc4_y_xy3+(0.000001*ann_fac);
4617 if (strncmp((p_all_par+ii)->name,
"pc4_y_x2y2",10)==0) {
4619 amin[jj]=p_xs_3->
pc4_y_x2y2-(0.000001*ann_fac);
4620 amax[jj]=p_xs_3->
pc4_y_x2y2+(0.000001*ann_fac);
4624 if (strncmp((p_all_par+ii)->name,
"pc4_y_x4",8)==0) {
4626 amin[jj]=p_xs_3->
pc4_y_x4-(0.000001*ann_fac);
4627 amax[jj]=p_xs_3->
pc4_y_x4+(0.000001*ann_fac);
4631 if (strncmp((p_all_par+ii)->name,
"pc4_y_y4",8)==0) {
4633 amin[jj]=p_xs_3->
pc4_y_y4-(0.000001*ann_fac);
4634 amax[jj]=p_xs_3->
pc4_y_y4+(0.000001*ann_fac);
4638 if (strncmp((p_all_par+ii)->name,
"ca_x0",5)==0) {
4639 abest[jj]=p_xs_3->
ca_x0;
4640 amin[jj]=p_xs_3->
ca_x0-(0.000001*ann_fac);
4641 amax[jj]=p_xs_3->
ca_x0+(0.000001*ann_fac);
4645 if (strncmp((p_all_par+ii)->name,
"ca_x1",5)==0) {
4646 abest[jj]=p_xs_3->
ca_x1;
4647 amin[jj]=p_xs_3->
ca_x1-(0.000001*ann_fac);
4648 amax[jj]=p_xs_3->
ca_x1+(0.000001*ann_fac);
4652 if (strncmp((p_all_par+ii)->name,
"ca_y0",5)==0) {
4653 abest[jj]=p_xs_3->
ca_y0;
4654 amin[jj]=p_xs_3->
ca_y0-(0.000001*ann_fac);
4655 amax[jj]=p_xs_3->
ca_y0+(0.000001*ann_fac);
4659 if (strncmp((p_all_par+ii)->name,
"ca_y1",5)==0) {
4660 abest[jj]=p_xs_3->
ca_y1;
4661 amin[jj]=p_xs_3->
ca_y1-(0.000001*ann_fac);
4662 amax[jj]=p_xs_3->
ca_y1+(0.000001*ann_fac);
4671 if (strncmp((p_all_par+ii)->name,
"es_x",4)==0) {
4672 abest[jj]=p_xs_3->
es_x;
4673 amin[jj]=p_xs_3->
es_x-(1.0*ann_fac);
4674 amax[jj]=p_xs_3->
es_x+(1.0*ann_fac);
4680 if (p_xs_3->
arm==0) {
4682 if (strncmp((p_all_par+ii)->name,
"mud",3)==0) {
4689 if (strncmp((p_all_par+ii)->name,
"nud",3)==0) {
4696 if (strncmp((p_all_par+ii)->name,
"taud",4)==0) {
4704 if (strncmp((p_all_par+ii)->name,
"fdet",4)==0) {
4705 abest[jj]=p_xs_3->
fdet;
4706 amin[jj]=p_xs_3->
fdet-(0.05*ann_fac);
4707 amax[jj]=p_xs_3->
fdet+(0.05*ann_fac);
4712 if (strncmp((p_all_par+ii)->name,
"chipx",5)==0) {
4713 abest[jj]=p_xs_3->
chipx;
4714 amin[jj]=p_xs_3->
chipx-(0.05*ann_fac);
4715 amax[jj]=p_xs_3->
chipx+(0.05*ann_fac);
4719 if (strncmp((p_all_par+ii)->name,
"chipy",5)==0) {
4720 abest[jj]=p_xs_3->
chipy;
4721 amin[jj]=p_xs_3->
chipy-(0.05*ann_fac);
4722 amax[jj]=p_xs_3->
chipy+(0.05*ann_fac);
4727 if (strncmp((p_all_par+ii)->name,
"sg",2)==0) {
4728 abest[jj]=p_xs_3->
sg;
4729 amin[jj]=p_xs_3->
sg-(0.02*ann_fac);
4730 amax[jj]=p_xs_3->
sg+(0.02*ann_fac);
4735 else if (p_xs_3->
arm==1) {
4736 if (strncmp((p_all_par+ii)->name,
"mup1",4)==0) {
4744 if (strncmp((p_all_par+ii)->name,
"nug",3)==0) {
4751 if (strncmp((p_all_par+ii)->name,
"taud",4)==0) {
4759 if (strncmp((p_all_par+ii)->name,
"fdet",4)==0) {
4760 abest[jj]=p_xs_3->
fdet;
4761 amin[jj]=p_xs_3->
fdet-(0.1*ann_fac);
4762 amax[jj]=p_xs_3->
fdet+(0.1*ann_fac);
4767 if (strncmp((p_all_par+ii)->name,
"chipx",5)==0) {
4768 abest[jj]=p_xs_3->
chipx;
4769 amin[jj]=p_xs_3->
chipx-(0.05*ann_fac);
4770 amax[jj]=p_xs_3->
chipx+(0.05*ann_fac);
4774 if (strncmp((p_all_par+ii)->name,
"chipy",5)==0) {
4775 abest[jj]=p_xs_3->
chipy;
4776 amin[jj]=p_xs_3->
chipy-(0.05*ann_fac);
4777 amax[jj]=p_xs_3->
chipy+(0.05*ann_fac);
4782 if (strncmp((p_all_par+ii)->name,
"sg",2)==0) {
4783 abest[jj]=p_xs_3->
sg;
4784 amin[jj]=p_xs_3->
sg-(0.01*ann_fac);
4785 amax[jj]=p_xs_3->
sg+(0.01*ann_fac);
4790 else if (p_xs_3->
arm==2) {
4792 if (strncmp((p_all_par+ii)->name,
"mup1",4)==0) {
4800 if (strncmp((p_all_par+ii)->name,
"nug",3)==0) {
4807 if (strncmp((p_all_par+ii)->name,
"mud",3)==0) {
4814 if (strncmp((p_all_par+ii)->name,
"nud",3)==0) {
4822 if (strncmp((p_all_par+ii)->name,
"fdet",4)==0) {
4823 abest[jj]=p_xs_3->
fdet;
4824 amin[jj]=p_xs_3->
fdet-(0.2*ann_fac);
4825 amax[jj]=p_xs_3->
fdet+(0.2*ann_fac);
4830 if (strncmp((p_all_par+ii)->name,
"chipx",5)==0) {
4831 abest[jj]=p_xs_3->
chipx;
4832 amin[jj]=p_xs_3->
chipx-(0.075*ann_fac);
4833 amax[jj]=p_xs_3->
chipx+(0.075*ann_fac);
4837 if (strncmp((p_all_par+ii)->name,
"chipy",5)==0) {
4838 abest[jj]=p_xs_3->
chipy;
4839 amin[jj]=p_xs_3->
chipy-(0.075*ann_fac);
4840 amax[jj]=p_xs_3->
chipy+(0.075*ann_fac);
4845 if (strncmp((p_all_par+ii)->name,
"taues",5)==0) {
4853 if (strncmp((p_all_par+ii)->name,
"fcol",4)==0) {
4854 abest[jj]=p_xs_3->
fcol;
4855 amin[jj]=p_xs_3->
fcol-(1.0*ann_fac);
4856 amax[jj]=p_xs_3->
fcol+(1.5*ann_fac);
4864 if (p_xs_3->
arm!=2) {
4865 cpl_msg_error(__func__,
"This scenario is only valid for NIR AFC exposures");
4868 if (strncmp((p_all_par+ii)->name,
"mug",3)==0) {
4876 if (strncmp((p_all_par+ii)->name,
"nug",3)==0) {
4884 if (strncmp((p_all_par+ii)->name,
"fdet",4)==0) {
4885 abest[jj]=p_xs_3->
fdet;
4886 amin[jj]=p_xs_3->
fdet-(0.4*ann_fac);
4887 amax[jj]=p_xs_3->
fdet+(0.4*ann_fac);
4891 if (strncmp((p_all_par+ii)->name,
"taud",4)==0) {
4899 if (strncmp((p_all_par+ii)->name,
"chipx",5)==0) {
4900 abest[jj]=p_xs_3->
chipx;
4901 amin[jj]=p_xs_3->
chipx-(0.1*ann_fac);
4902 amax[jj]=p_xs_3->
chipx+(0.1*ann_fac);
4906 if (strncmp((p_all_par+ii)->name,
"chipy",5)==0) {
4907 abest[jj]=p_xs_3->
chipy;
4908 amin[jj]=p_xs_3->
chipy-(0.1*ann_fac);
4909 amax[jj]=p_xs_3->
chipy+(0.1*ann_fac);
4920 cpl_msg_error(__func__,
"The use of the phys mod config file optimisation flags and ranges was specified, however the input phys mod config has no optimisation flags set");
4925 resid_header = resid_tab->
header;
4942 if (p_xs_3->
arm==0) {
4943 wav_den_bin_sz=25.0;
4945 else if (p_xs_3->
arm==1) {
4946 wav_den_bin_sz=50.0;
4949 wav_den_bin_sz=125.0;
4951 for (kk=0;kk<40;kk+=1) {
4954 for (kk=0;kk<
size;kk+=1){
4955 if (vlambda[kk]>0.0) {
4956 wav_den[(int)(vorder[kk])]+=1;
4962 for (jj=0;jj<
size;jj+=1){
4964 msp_coord[kk].
wave=*(vlambda+jj);
4965 msp_coord[kk].
x= *(xgauss+jj) ;
4971 msp_coord[kk].
flux=10000.0/(float)(wav_den[(
int)(vorder[jj])]);
4972 msp_coord[kk].
order=(int)(*(vorder+jj));
4973 msp_coord[kk].
y= *(ygauss+jj);
4974 msp_coord[kk].
slit_pos=slitindex[jj];
4976 msp_coord[kk].
arm=p_xs_3->
arm;
4983 if (p_xs_3->
arm==0) {
4986 else if (p_xs_3->
arm==1) {
4989 else if (p_xs_3->
arm==2) {
4993 printf(
"Arm not set. \n");
5001 for(ii=0;ii<
size;ii++) {
5002 p_wlarray[ii]=msp_coord[ii].
wave*1e-6;
5006 printf (
"Before anneal: \n");
5007 for (ii=0;ii<adim;ii++) {
5008 printf(
"%d %s %lf \n", aname[ii], (p_all_par+aname[ii])->name, abest[ii]);
5013 for (jj=0;jj<
size;jj++) {
5014 int morder_cnt=msp_coord[jj].
order;
5018 xsh_3_eval(p_wlarray[jj],morder_cnt,ref_ind,p_xs_3);
5020 printf(
"check %d %lf %lf %d %d %lf %lf %lf %lf %d %lf %lf \n",
5028 MODEL_CONFIG_plist=cpl_propertylist_new();
5030 resid_header,resid_frame,
5031 &MODEL_CONFIG_plist));
5046 cpl_free(p_wlarray);
5051 resid_header,resid_frame,
5052 &MODEL_CONFIG_plist));
5057 sprintf(out_cfg_filename,
"%s.fits",tag);
5064 check(cpl_table_save(conf_tab, MODEL_CONFIG_plist, NULL, out_cfg_filename, CPL_IO_DEFAULT));
5069 CPL_FRAME_TYPE_TABLE,
5070 CPL_FRAME_GROUP_PRODUCT,
5071 CPL_FRAME_LEVEL_FINAL));
5072 xsh_msg_dbg_medium(
"optimised model parameter table %s %s", cpl_frame_get_filename(MODEL_CONF_OPT_frame),cpl_frame_get_tag(MODEL_CONF_OPT_frame));
5079 if ( cpl_error_get_code() != CPL_ERROR_NONE){
5089 return MODEL_CONF_OPT_frame;
5122 if (strncmp(listname,findname,strlen(findname))==0) {
5125 *min=setbest-(fac*gfac);
5126 *
max=setbest=(fac*gfac);
5145 typedef DOUBLE sellmeier_mat[3][5];
5147 double ref_ind,top,bottom;
5149 sellmeier_mat S_UVB={{1.10127, -4.94251E-05, 5.27414E-07, -1.59700E-09, 1.75949E-12},
5150 {1.78752E-05, 4.76391E-05, -4.49019E-07, 1.44546E-09, -1.57223E-12},
5151 {0.793552, -1.27815E-03, 1.84595E-05, -9.20275E-08, 1.48829E-10}};
5152 sellmeier_mat L_UVB={{-0.08906, 9.08730E-06, -6.53638E-08, 7.77072E-11, 6.84605E-14},
5153 {0.297562, -859578E-04, 6.59069E-06, -1.09482E-08, 7.85145E-13},
5154 {9.34454, -7.09788E-03, 1.01968E-04, -5.07660E-07, 8.21348E-10}};
5156 sellmeier_mat S_NIR={{0.104940144,5.40E-06,3.23E-08,1.83E-13,-3.60E-14},
5157 {0.996335571,-3.29E-06,1.48E-08,-3.01E-11,4.99E-14},
5158 {0.832484961,6.38E-04,-2.40E-06,6.10E-10,4.77E-12}};
5159 sellmeier_mat L_NIR={{-3.07E-03,-2.56E-05,6.21E-07,-2.54E-09,2.88E-12},
5160 {9.40E-02,-1.59E-06,1.28E-08,1.82E-12,-3.01E-14},
5161 {9.598633568,3.15E-03,-1.22E-05,5.48E-09,1.96E-11}};
5169 for (ii=0;ii<3;ii++) {
5171 for (jj=0;jj<5;jj++) {
5172 top+=S_UVB[ii][jj]*T[jj];
5173 bottom+=L_UVB[ii][jj]*T[jj];
5175 ref_ind+=(top*lam_sqr)/(lam_sqr-(bottom*bottom));
5179 for (ii=0;ii<3;ii++) {
5181 for (jj=0;jj<5;jj++) {
5182 top+=S_NIR[ii][jj]*T[jj];
5183 bottom+=L_NIR[ii][jj]*T[jj];
5185 ref_ind+=(top*lam_sqr)/(lam_sqr-(bottom*bottom));
5188 return sqrt(ref_ind);
5204 double n288=0, n_air=0;
5205 n288=1.0+(6432.8+((2949810.0*lam_sqr)/(146.0*lam_sqr-1.0))+((25540.0*lam_sqr)/(41.0*lam_sqr-1.0)))*1.0E-08;
5206 n_air=1.0+(n288-1.0)/(1.0+0.0034785*(temper-288.0));
5222 const cpl_vector * in,
5227 cpl_vector * filtered =NULL;
5228 cpl_vector * spec_clean =NULL;
5229 double * pspec_clean =NULL;
5231 cpl_vector * conv_kernel =NULL;
5232 cpl_vector * big_detected =NULL;
5233 double * pbig_detected =NULL;
5234 cpl_vector * detected =NULL;
5235 double * pdetected =NULL;
5236 double max=0, med=0, stdev=0, cur_val=0 ;
5237 int nb_det=0, nb_samples=0 ;
5242 if (in == NULL)
return NULL ;
5246 check(nb_samples = cpl_vector_get_size(in)) ;
5251 if ((filtered=cpl_vector_filter_median_create(in, filt_size))==NULL){
5252 cpl_msg_error(__func__,
"Cannot filter the spectrum") ;
5255 spec_clean = cpl_vector_duplicate(in) ;
5256 cpl_vector_subtract(spec_clean, filtered) ;
5257 cpl_vector_delete(filtered) ;
5262 "set grid;set xlabel 'Position (pixels)';set ylabel 'Intensity (ADU)';",
5263 "t 'Filtered extracted spectrum' w lines",
"", spec_clean);
5269 if ((conv_kernel = cpl_wlcalib_xc_convolve_create_kernel(fwhm,
5271 cpl_msg_error(cpl_func,
"Cannot create convolution kernel") ;
5272 cpl_vector_delete(spec_clean) ;
5277 if (cpl_wlcalib_xc_convolve(spec_clean, conv_kernel)) {
5278 cpl_msg_error(cpl_func,
"Cannot smoothe the signal");
5279 cpl_vector_delete(spec_clean) ;
5280 cpl_vector_delete(conv_kernel) ;
5283 cpl_vector_delete(conv_kernel) ;
5288 "set grid;set xlabel 'Position (pixels)';set ylabel 'Intensity (ADU)';",
5289 "t 'Convolved extracted spectrum' w lines",
"", spec_clean);
5293 big_detected = cpl_vector_duplicate(spec_clean) ;
5294 pbig_detected = cpl_vector_get_data(big_detected) ;
5295 pspec_clean = cpl_vector_get_data(spec_clean) ;
5298 pspec_clean[0] = pspec_clean[nb_samples-1] = 0.0 ;
5301 max = cpl_vector_get_max(spec_clean) ;
5302 stdev = cpl_vector_get_stdev(spec_clean) ;
5303 med = cpl_vector_get_median_const(spec_clean) ;
5307 while (
max > med + stdev *
sigma) {
5310 while (pspec_clean[i] <
max) i++ ;
5311 if (i<=0 || i>=nb_samples-1) break ;
5314 pbig_detected[nb_det] = (pspec_clean[i]*i +
5315 pspec_clean[i-1]*(i-1) + pspec_clean[i+1]*(i+1)) /
5316 (pspec_clean[i]+pspec_clean[i-1]+pspec_clean[i+1]);
5319 pbig_detected[nb_det] ++ ;
5326 cur_val = pspec_clean[i] ;
5327 while (j>=0 && pspec_clean[j] < cur_val) {
5328 cur_val = pspec_clean[j] ;
5329 pspec_clean[j] = 0.0 ;
5334 cur_val = pspec_clean[i] ;
5335 while (j<=nb_samples-1 && pspec_clean[j] < cur_val) {
5336 cur_val = pspec_clean[j] ;
5337 pspec_clean[j] = 0.0 ;
5341 pspec_clean[i] = 0.0 ;
5344 max = cpl_vector_get_max(spec_clean) ;
5345 stdev = cpl_vector_get_stdev(spec_clean) ;
5346 med = cpl_vector_get_median_const(spec_clean) ;
5348 cpl_vector_delete(spec_clean) ;
5354 detected = cpl_vector_new(nb_det) ;
5355 pdetected = cpl_vector_get_data(detected) ;
5356 pbig_detected = cpl_vector_get_data(big_detected) ;
5357 for (i=0 ; i<nb_det ; i++) pdetected[i] = pbig_detected[i] ;
5359 cpl_vector_delete(big_detected) ;
5362 if(cpl_error_get_code() != CPL_ERROR_NONE) {
5380 cpl_frame* xs_config =NULL;
5381 cpl_frame* meas_coord =NULL;
5382 cpl_parameter* param=NULL;
5384 const char* arm=NULL;
5388 cpl_table * conf_tab = NULL;
5391 int sizearraywavelengths=0, adim=0;
5393 struct xs_3 xs_model, *p_xs_3;
5402 coord *msp_coord = NULL;
5403 DOUBLE ** ref_ind = NULL;
5404 DOUBLE *p_wlarray = NULL;
5405 cpl_table * meas_coord_temp=NULL;
5406 double ann_fac=1.0000000000001;
5410 FILE* file_list=NULL;
5416 const char * name_i=NULL ;
5422 if( (nraw=cpl_frameset_get_size(frameset)) ==0)
goto cleanup;
5424 param = cpl_parameterlist_find(parlist,
"xsh.xsh_model_compute.arm");
5425 arm = cpl_parameter_get_string(param);
5426 xsh_msg(
"User selected arm '%s'. Recipe expects '%s' input data",
arm,
arm);
5428 param = cpl_parameterlist_find(parlist,
"xsh.xsh_model_compute.niter");
5429 MAXIT = cpl_parameter_get_int(param);
5431 coord_switch = cpl_parameter_get_int(cpl_parameterlist_find(parlist,
"xsh.xsh_model_compute.coord_frame"));
5453 cpl_error_set(cpl_func, CPL_ERROR_ILLEGAL_INPUT);
5465 check(param = cpl_parameterlist_find(parlist,
5466 "xsh.xsh_model_compute.name_i"));
5467 check(name_i = cpl_parameter_get_string(param));
5469 if ( NULL == (file_list = fopen (name_i,
"r" ) ) )
5476 while ( fscanf( file_list,
"%64g %64g %64g %64d",&wave, &
x, &
y, &ord ) != EOF )
5483 check(meas_coord_temp=cpl_table_new(nrows));
5484 check(cpl_table_new_column(meas_coord_temp,
"Wavelength",CPL_TYPE_DOUBLE));
5485 check(cpl_table_new_column(meas_coord_temp,
"x",CPL_TYPE_DOUBLE));
5486 check(cpl_table_new_column(meas_coord_temp,
"y",CPL_TYPE_DOUBLE));
5487 check(cpl_table_new_column(meas_coord_temp,
"ORDER",CPL_TYPE_INT));
5489 check(cpl_table_fill_column_window(meas_coord_temp,
"Wavelength",0,nrows,-1));
5490 check(cpl_table_fill_column_window(meas_coord_temp,
"x",0,nrows,-1));
5491 check(cpl_table_fill_column_window(meas_coord_temp,
"y",0,nrows,-1));
5492 check(cpl_table_fill_column_window(meas_coord_temp,
"ORDER",0,nrows,-1));
5494 check(pw=cpl_table_get_data_double(meas_coord_temp,
"Wavelength"));
5495 check(px=cpl_table_get_data_double(meas_coord_temp,
"x"));
5496 check(py=cpl_table_get_data_double(meas_coord_temp,
"y"));
5497 check(po=cpl_table_get_data_int(meas_coord_temp,
"ORDER"));
5499 if ( NULL == (file_list = fopen (name_i,
"r" ) ) )
5506 while ( fscanf( file_list,
"%64g %64g %64g %64d",&wave, &
x, &
y, &ord ) != EOF )
5517 check(cpl_table_save(meas_coord_temp, NULL, NULL,
"lin_xy_hand.fits",
5523 CPL_FRAME_TYPE_TABLE,
5524 CPL_FRAME_GROUP_CALIB,
5525 CPL_FRAME_LEVEL_TEMPORARY));
5533 p_all_par=&all_par[0];
5535 cknull_msg(meas_coord_temp=cpl_table_load(cpl_frame_get_filename(meas_coord),1,0),
"Cannot load table %s",cpl_frame_get_filename(meas_coord));
5536 check(sizearraywavelengths=cpl_table_get_nrow(meas_coord_temp));
5543 cpl_frame_get_filename(xs_config),
5544 cpl_frame_get_tag(xs_config),
5550 for (ii=0;ii<300;ii++) {
5559 for (ii=0;ii<100;ii++) {
5563 if (strncmp((p_all_par+ii)->name,
"temper",6)==0) {
5565 abest[jj]=p_xs_3->
temper;
5566 amin[jj]=p_xs_3->
temper-(5.0*ann_fac);
5567 amax[jj]=p_xs_3->
temper+(5.0*ann_fac);
5570 if (strncmp((p_all_par+ii)->name,
"fcol",4)==0) {
5572 abest[jj]=p_xs_3->
fcol;
5573 amin[jj]=p_xs_3->
fcol-(5.0*ann_fac);
5574 amax[jj]=p_xs_3->
fcol+(5.0*ann_fac);
5577 if (strncmp((p_all_par+ii)->name,
"mup1",4)==0) {
5584 if (strncmp((p_all_par+ii)->name,
"nup1",4)==0) {
5592 if (p_xs_3->
arm==2) {
5595 if (strncmp((p_all_par+ii)->name,
"cmup1",5)==0) {
5602 if (strncmp((p_all_par+ii)->name,
"mup3",4)==0) {
5609 if (strncmp((p_all_par+ii)->name,
"nup3",4)==0) {
5618 if (strncmp((p_all_par+ii)->name,
"mup5",4)==0) {
5625 if (strncmp((p_all_par+ii)->name,
"nup5",4)==0) {
5635 if (strncmp((p_all_par+ii)->name,
"mug",3)==0) {
5642 if (strncmp((p_all_par+ii)->name,
"nug",3)==0) {
5650 if (strncmp((p_all_par+ii)->name,
"taud",4)==0) {
5658 if (strncmp((p_all_par+ii)->name,
"fdet",4)==0) {
5659 abest[jj]=p_xs_3->
fdet;
5660 amin[jj]=p_xs_3->
fdet-(10.0*ann_fac);
5661 amax[jj]=p_xs_3->
fdet+(10.0*ann_fac);
5667 if (strncmp((p_all_par+ii)->name,
"chipx",5)==0) {
5668 abest[jj]=p_xs_3->
chipx;
5669 amin[jj]=p_xs_3->
chipx-(15.0*ann_fac);
5670 amax[jj]=p_xs_3->
chipx+(15.0*ann_fac);
5674 if (strncmp((p_all_par+ii)->name,
"chipy",5)==0) {
5675 abest[jj]=p_xs_3->
chipy;
5676 amin[jj]=p_xs_3->
chipy-(15.0*ann_fac);
5677 amax[jj]=p_xs_3->
chipy+(15.0*ann_fac);
5682 if (strncmp((p_all_par+ii)->name,
"sg",2)==0) {
5683 abest[jj]=p_xs_3->
sg;
5684 amin[jj]=p_xs_3->
sg-(1.0*ann_fac);
5685 amax[jj]=p_xs_3->
sg+(1.0*ann_fac);
5695 if (p_xs_3->
arm==0) {
5698 else if (p_xs_3->
arm==1) {
5701 else if (p_xs_3->
arm==2) {
5705 printf(
"Arm not set. \n");
5715 for (ii=0; ii<sizearraywavelengths; ii++) {
5717 if (coord_switch==1) {
5718 msp_coord[ii].
x=cpl_table_get_double(meas_coord_temp,
"x",ii,NULL);
5719 msp_coord[ii].
y=cpl_table_get_double(meas_coord_temp,
"y",ii,NULL);
5724 if (p_xs_3->
arm==0) {
5725 msp_coord[ii].
x=2097-cpl_table_get_double(meas_coord_temp,
"x",ii,NULL);
5726 msp_coord[ii].
y=3001-cpl_table_get_double(meas_coord_temp,
"y",ii,NULL);
5728 if (p_xs_3->
arm==1) {
5729 msp_coord[ii].
x=-10.0+cpl_table_get_double(meas_coord_temp,
"x",ii,NULL);
5730 msp_coord[ii].
y=0.0+cpl_table_get_double(meas_coord_temp,
"y",ii,NULL);
5732 if (p_xs_3->
arm==2) {
5733 msp_coord[ii].
x=-20.0+cpl_table_get_double(meas_coord_temp,
"y",ii,NULL);
5734 msp_coord[ii].
y=2045.0-cpl_table_get_double(meas_coord_temp,
"x",ii,NULL);
5735 printf(
"%lf %lf \n",msp_coord[ii].
x,msp_coord[ii].
y);
5738 msp_coord[ii].
arm=p_xs_3->
arm;
5739 msp_coord[ii].
flux=100.0;
5741 msp_coord[ii].
wave=cpl_table_get_double(meas_coord_temp,
"Wavelength",ii,NULL);
5742 msp_coord[ii].
order=cpl_table_get_int(meas_coord_temp,
"ORDER",ii,NULL);
5743 p_wlarray[ii]=msp_coord[ii].
wave*1e-6;
5748 printf (
"Before anneal: \n");
5749 for (ii=0;ii<adim;ii++) {
5750 printf(
"%d %s %lf \n", aname[ii], (p_all_par+aname[ii])->name, abest[ii]);
5756 for (jj=0;jj<sizearraywavelengths;jj++) {
5762 printf(
"check %d %lf %lf %d %d %lf %lf %lf %lf %d\n",
5766 msp_coord[jj].
order);
5778 sizearraywavelengths,
5785 cpl_msg_info(__func__,
"Save the products") ;
5786 cpl_msg_indent_more() ;
5788 parlist,frameset) == -1) {
5789 cpl_msg_error(__func__,
"Cannot save products") ;
5790 cpl_msg_indent_less() ;
5795 cpl_msg_indent_less() ;
5801 cpl_free(p_wlarray);
5805 if (cpl_error_get_code())
5823 const cpl_table* out_table,
5825 cpl_parameterlist* parlist,
5829 cpl_propertylist* plist=NULL ;
5830 cpl_frame* product_frame=NULL ;
5831 cpl_frameset* raws=NULL;
5832 cpl_frame* ref_frame=NULL;
5836 raws=cpl_frameset_new();
5838 check(ref_frame=cpl_frameset_get_frame(raws,0));
5839 check(plist=cpl_propertylist_load(cpl_frame_get_filename(ref_frame),0));
5843 sprintf(name_o,
"%s%s",
5846 cpl_msg_info(__func__,
"Writing %s" , name_o) ;
5849 cpl_propertylist_append_int(plist,
"Num_pinh",9);
5854 CPL_FRAME_GROUP_PRODUCT,
5855 CPL_FRAME_LEVEL_FINAL));
5857 if (cpl_table_save(out_table, plist, NULL, name_o,
5858 CPL_IO_DEFAULT) != CPL_ERROR_NONE) {
5859 cpl_msg_error(__func__,
"Cannot save the product");
5872 if (cpl_error_get_code())
5900 struct xs_3* p_xs_3)
5902 if (p_xs_3->
arm!=2) {
5920 if (
first->order < secnd->
order )
return -1 ;
5921 else if (
first->order > secnd->
order )
return 1 ;
5928 static FILE * fgnu = NULL, * freg = NULL ;
5929 static const char * gnuname =NULL ;
5936 if ( fgnu == NULL ) {
5938 fgnu = fopen( gnuname,
"w" ) ;
5939 fprintf( fgnu,
"set term x11\nplot " ) ;
5942 else first_call = 0 ;
5943 ppcent = pcent + fpos ;
5945 sprintf( fname,
"order_%s_%02d.dat",
arm,
order ) ;
5946 fout = fopen( fname,
"w" ) ;
5948 if ( !first_call ) fprintf( fgnu,
"," ) ;
5949 fprintf( fgnu,
"'%s' u 1:2 w points pt 5 t''", fname ) ;
5951 for( i = fpos ; i<npos; i++, ppcent++ )
5952 fprintf( fout,
"%d %d %.3lf\n",
5957 fprintf( fgnu,
"\n" ) ;
5962 if ( freg == NULL ) {
5963 freg = fopen(
"order_create.reg",
"w" ) ;
5965 fprintf( freg,
"# Region file format: DS9 version 4.0\n" ) ;
5966 fprintf( freg,
"global color=red font=\"helvetica 4 normal\"select=1 highlite=1 edit=1 move=1 delete=1 include=1 fixed=0 source\n" ) ;
5967 fprintf( freg,
"image\n# RED center_x center_y (pixels)\n" ) ;
5968 for( ppcent = pcent+fpos, i = fpos ; i <npos ; i++, ppcent++ ) {
5969 fprintf( freg,
"point(%d.,%d.) #point=cross color=red font=\"helvetica 4 normal\"\n", ppcent->
pos_x, ppcent->
pos_y ) ;
5998 int nb_keep_order=0;
5999 cpl_vector *vx = NULL;
6000 cpl_vector *vy = NULL;
6009 xsh_msg(
"Fit a polynomial of degree %d by order",deg_poly);
6012 for(i=1; i <=
size; i++) {
6017 int absorder =
order[i-1];
6020 (absorder <= list->absorder_max) ){
6023 check( vx = cpl_vector_wrap( ordersize, &(posx[i-ordersize])));
6024 check( vy = cpl_vector_wrap( ordersize, &(posy[i-ordersize])));
6026 nborder+1,
order[i-1],ordersize);
6028 "You must have more points to fit correctly this order");
6032 }
else if (edge==0) {
6035 }
else if (edge==1) {
6039 list->
list[nb_keep_order].
order = nborder;
6047 xsh_msg(
"WARNING skipping absorder %d because is not in range",
6068 double * vorder = NULL, * po =NULL;
6069 double * pos_x = NULL, * px =NULL;
6070 double * pos_y = NULL, * py =NULL;
6080 for( i = 0 ; i<npos ; i++, po++, px++, py++, pcent++ ) {
6081 *po = pcent->
order ;
6082 *px = pcent->
pos_x ;
6083 *py = pcent->
pos_y ;
6111 const char* tab_filename)
6116 DOUBLE blaze_wav=0, lam_min=0, lam_max=0, lam_inc=0;
6120 int iord=0,fpos=0,edge=0;
6121 double es_x_config=0;
6123 cpl_propertylist* plist=NULL;
6129 cpl_frame* order_edges_frame=NULL;
6132 const char* tag=NULL;
6149 if (p_xs_3->
arm==0) {
6150 tag=
"XSH_ORDER_TAB_EDGES_SLIT_UVB";
6154 else if (p_xs_3->
arm==1) {
6155 tag=
"XSH_ORDER_TAB_EDGES_VIS";
6160 tag=
"XSH_ORDER_TAB_EDGES_NIR";
6172 es_x_config=p_xs_3->
es_x;
6174 for (edge=-1;edge<2;edge++) {
6181 blaze_wav=2*(sin(-p_xs_3->
nug))/(morder_cnt*p_xs_3->
sg);
6182 lam_max=blaze_wav*((double)(morder_cnt)/((double)(morder_cnt)-0.5));
6183 lam_min=blaze_wav*((double)(morder_cnt)/(0.5+(double)(morder_cnt)));
6184 lam_inc=(lam_max-lam_min)/(99.99);
6186 for (lambda=lam_min; lambda<=lam_max; lambda+=lam_inc) {
6187 lambda_nm=lambda*
mm2nm;
6188 xsh_3_eval(lambda,morder_cnt,ref_ind,p_xs_3);
6190 if (lambda==lam_min) low_y=p_xs_3->
chippix[2];
6196 printf(
"%d %d %d %d %lf %lf %lf \n",edge, morder_cnt, ii, fpos, lambda_nm,p_xs_3->
xpospix,p_xs_3->
ypospix);
6197 centers[ii].
order = morder_cnt;
6200 centers[ii].
flux = 0.0 ;
6207 printf(
"%d %d %d, %d %d \n", ii, fpos, morder_cnt, low_y, up_y);
6221 cpl_msg_error(__func__,
"Cannot free 2D array ref_ind");
6225 check(plist=cpl_propertylist_new());
6227 sprintf(filename,
"%s.fits",tag);
6229 cpl_msg_info(__func__,
"Save the tables") ;
6236 return order_edges_frame;
static xsh_instrument * instrument
xsh_order_list * xsh_order_list_create(xsh_instrument *instr)
create an empty order list
cpl_frame * xsh_order_list_save(xsh_order_list *order_list, xsh_instrument *instrument, const char *filename, const char *tag, const int ny)
Save an order list to a frame.
double * xsh_resid_tab_get_lambda_data(xsh_resid_tab *resid)
Get the size of the residual tab.
double * xsh_resid_tab_get_ygauss_data(xsh_resid_tab *resid)
Get the ygauss array of the residual tab.
void xsh_resid_tab_free(xsh_resid_tab **resid)
Free memory associated to a resid_tab.
xsh_resid_tab * xsh_resid_tab_load(cpl_frame *resid_tab_frame)
Load a residual tab from a frame.
double * xsh_resid_tab_get_thpre_y_data(xsh_resid_tab *resid)
Get the thpre_y array of the residual tab.
double * xsh_resid_tab_get_thpre_x_data(xsh_resid_tab *resid)
Get the slit_index array of the residual tab.
double * xsh_resid_tab_get_order_data(xsh_resid_tab *resid)
Get the Orders array of the residual tab.
double * xsh_resid_tab_get_xgauss_data(xsh_resid_tab *resid)
Get the xgauss array of the residual tab.
#define XSH_ASSURE_NOT_ILLEGAL(cond)
#define XSH_ASSURE_NOT_ILLEGAL_MSG(cond, msg)
#define XSH_ASSURE_NOT_NULL(pointer)
#define cknull_msg(NULLEXP,...)
const char * xsh_instrument_arm_tostring(xsh_instrument *i)
Get the string associated with an arm.
int xsh_instrument_get_binx(xsh_instrument *instrument)
void xsh_instrument_set_arm(xsh_instrument *i, XSH_ARM arm)
Set an arm on instrument structure.
XSH_MODE xsh_instrument_get_mode(xsh_instrument *i)
Get a mode on instrument structure.
XSH_INSTRCONFIG * xsh_instrument_get_config(xsh_instrument *i)
Get the instrument default set of keywords.
int xsh_instrument_get_biny(xsh_instrument *instrument)
XSH_ARM xsh_instrument_get_arm(xsh_instrument *i)
Get an arm on instrument structure.
void xsh_instrument_free(xsh_instrument **instrument)
free an instrument structure
xsh_instrument * xsh_instrument_new(void)
create new instrument structure
int xsh_model_readfits(double *abest, double *amin, double *amax, int *aname, const char *xs_config_file, const char *xs_config_tag, struct xs_3 *p_xs_3, ann_all_par *p_all_par)
void xsh_transpose(mat A, mat B)
matrix transposal
void xsh_refract(vec b, DOUBLE rind, vec a)
Calculate the new vector after a given incident vector passes a boundary between two materials.
double * xsh_copy2D_to_1D(double **ccdtemp, int asize, int bsize)
copy 2D to 1D array
int ** xsh_alloc2Darray_i(int asize, int bsize)
allocates memory for a 2D array of integers
int xsh_model_open_param(char *listname, char *findname, int *ref, int setref, double *best, double setbest, double *min, double *max, double gfac, double fac, int counter)
Open a parameter in the model config structure for annealing and set the limits.
int xsh_model_offset(DOUBLE slit_pix_shift, DOUBLE disp_pix_shift, struct xs_3 *p_xs_3)
convert a pixel shift measured on the detector to a shift in detector centroid
double xsh_model_sellmeier_ext(int arm, double temper, double lam_sqr)
Get the refractive index for a given temperature and wavelength from the (hard coded) extended Sellme...
float ** xsh_alloc2Darray_f(int asize, int bsize)
allocates memory for a 2D array of floats
void xsh_ref_ind_read(int arm, DOUBLE **ref_ind_T, DOUBLE temper)
Load the refractive index coeffs for a given arm and temperature.
void xsh_matrixforvector(vec a, mat B, vec c)
Realize a*B*c.
static int comp_center2(const void *one, const void *two)
void xsh_ref_ind_read_old(const char *ref_ind_file, DOUBLE **ref_ind, DOUBLE temper)
Load the refractive index array for a given arm and temperature. This old routine is only retained to...
static void save_centers(CENTER_ORDER *pcent, int fpos, int npos, const char *arm)
cpl_vector * xsh_model_refining_detect(const cpl_vector *in, int fwhm, double sigma, int display)
Detect the brightest features in a spectrum.
double xsh_physmod_grating(vec in, int m, double sg, mat in_rot, mat exit_rot, vec out)
Calculate the new vector after a given incident vector is reflected in a prism (i....
void xsh_addvectors3D(vec a, vec b)
add 2 vectors a+=b
void xsh_subtractvectors(vec a, vec b)
subtract 2 vectors a-=b
void xsh_model_get_xy(xsh_xs_3 *p_xs_3, xsh_instrument *instr, double lambda_nm, int morder, double ent_slit_pos, double *x, double *y)
Compute the detector location (floating point pixels) of a given wavelength/entrance slit position.
int xsh_model_map_ifu(double xifu, double yifu, xsh_xs_3 *p_xs_3)
Map the IFU position to spectrograph slit position using transformation provided by Ana for IFU2.
int xsh_free2Darray_f(float **ccdtemp, int asize)
free memory for a 2D array of floats
void xsh_3_detpix(struct xs_3 *p_xs_3)
Takes the physical x,y position at the detector array and converts this to a pixel position.
cpl_frame * xsh_model_order_edges_tab_create(xsh_xs_3 *p_xs_3, const char *tab_filename)
Create an order edges table using the phys mod.
void xsh_model_binxy(xsh_xs_3 *p_xs_3, int bin_X, int bin_Y)
corrects model for detector's binning
double *** xsh_alloc3Darray(int asize, int bsize, int csize)
allocate 3D array
int xsh_model_first_anneal_save(const cpl_table *out_table, xsh_instrument *instr, cpl_parameterlist *parlist, cpl_frameset *set)
Save the product of the recipe.
static cpl_error_code xsh_model_compute_residuals(xsh_xs_3 *p_xs_3, coord *msp_coord, DOUBLE *p_wlarray, DOUBLE **ref_ind, const int size, const int annealed, cpl_propertylist *resid_header, cpl_frame *resid_frame, cpl_propertylist **result)
void xsh_3_eval(DOUBLE lambda, int morder, DOUBLE **ref_ind, struct xs_3 *p_xs_3)
Compute the physical x,y position at the detector array for a given wavelength, order and parameter c...
void xsh_normz(vec a)
normalize vector
double *** xsh_alloc3Darray2(int asize, int bsize, int csize)
allocate 3D array
DOUBLE xsh_scalarproduct(vec a, vec b)
implements scalar product
void xsh_initializematrix(mat A)
initialize matrix A
int xsh_free3Darray(double ***ccdtemp, int asize, int bsize)
free 3D array
double ** xsh_copy1D_to_2D(double *oneDccdtemp, int asize, int bsize)
copy 1D to 2D array
cpl_frame * xsh_model_spectralformat_create(xsh_xs_3 *p_xs_3, const char *tab_filename)
creates the model spectral format table
static void xsh_copyvector(vec a, vec b)
double xsh_model_ref_ind_air(double temper, double lam_sqr)
Return the refractive index of air at a given wavelength and temperature.
static const char * xsh_get_tag_opt_mod_cfg(xsh_xs_3 *p_xs_3, int rec_id)
void xsh_multiplymatrix(mat A, mat B, mat C)
multiply three matrixes A=B*C
void xsh_showmatrix(mat A)
Show matrix.
int xsh_model_first_anneal(cpl_parameterlist *parlist, cpl_frameset *frameset)
Interpret the command line options and execute the data processing.
DOUBLE * xsh_alloc1Darray(int asize)
allocates memory for an array of doubles
int xsh_free2Darray(double **ccdtemp, int asize)
free memory for a 2D array of doubles
int * xsh_alloc1Darray_INT(int asize)
allocates memory for an array of integers
void xsh_3_init(struct xs_3 *p_xs_3)
Pre-compute a number of non-wavelength dependent secondary parameters required by the model.
void xsh_showvector(vec a)
show vector content
static cpl_error_code xsh_model_compute_slitmap_kw(const double slit_min, const double slit_max, xsh_xs_3 *p_xs_3, xsh_instrument *instr, cpl_propertylist **plist)
cpl_error_code xsh_model_maps_create(xsh_xs_3 *p_xs_3, xsh_instrument *instr, const char *wtag, const char *stag, cpl_frame **wmap_frame, cpl_frame **smap_frame, const int save_tmp)
Compute the wavelength and slit maps.
static void xsh_nullmatrix(mat A)
void xsh_multiplythreematrix(mat A, mat B, mat C, mat D)
multiply three matrixes A=B*C*D
void xsh_order_edge_list_fit(xsh_order_list *list, int size, double *order, double *posx, double *posy, int deg_poly, int edge)
Fit edge of an order.
cpl_frame * xsh_model_THE_create(xsh_xs_3 *p_xs_3, xsh_instrument *instr, const char *line_list, int num_ph, double sep_ph, const char *THE_filename)
Compute the THE table (centroid for each feature in lamp spectrum)
double ** xsh_alloc2Darray(int asize, int bsize)
allocates memory for a 2D array of doubles
cpl_vector ** xsh_model_locus(struct xs_3 *p_xs_3, xsh_instrument *instr, double ent_slit_pos)
Compute the locus of the spectrum.
void xsh_addvectors(vec a, vec b)
add 2 vectors a+=b
static void xsh_nullvector(vec a)
void xsh_rotationmatrix(mat A, const char axis, const DOUBLE angle)
matrix rotation
static void fit_order_edge_list(xsh_order_list *list, int npos, CENTER_ORDER *pcent, int degree, int edge)
void xsh_multiply(vec a, DOUBLE k)
applies scalar product to vector
void xsh_normall(vec a)
normalize vector
void xsh_rotin(mat A, const DOUBLE x_angle, const DOUBLE y_angle, const DOUBLE z_angle)
matrix rotation
int xsh_free2Darray_i(int **ccdtemp, int asize)
free memory for a 2D array of integers
cpl_frame * xsh_model_pipe_anneal(cpl_frame *cfg_frame, cpl_frame *resid_frame, int maxit, double ann_fac, int scenario, int rec_id)
Run the annealing (optimisation) algoritm to improve the fit of the model parameter set to a given wa...
cpl_table * xsh_model_anneal_comp(ann_all_par *p_all_par, int nparam, double *abest, double *amin, double *amax, int *aname, struct xs_3 *p_xs_3, int DS_size, coord *msp_coord, DOUBLE *p_wlarray, DOUBLE **ref_ind, int maxit)
Use the simulated annealing algorithm to adjust the model parameters so that the metric (mean Euclide...
#define xsh_msg_warning(...)
Print an warning message.
#define xsh_msg_dbg_medium(...)
#define xsh_msg_error(...)
Print an error message.
#define xsh_msg(...)
Print a message on info level.
#define xsh_msg_dbg_low(...)
void xsh_pfits_set_pcatg(cpl_propertylist *plist, const char *value)
Write the PCATG value.
void xsh_pfits_set_slitmap_median_cen(cpl_propertylist *plist, double value)
void xsh_pfits_set_slitmap_median_slicup(cpl_propertylist *plist, double value)
void xsh_pfits_set_slitmap_order_cen(cpl_propertylist *plist, int absorder, double value)
cpl_error_code xsh_pfits_set_wcs(cpl_propertylist *header, const double crpix1, const double crval1, const double cdelt1, const double crpix2, const double crval2, const double cdelt2)
void xsh_pfits_set_slitmap_median_edglo(cpl_propertylist *plist, double value)
void xsh_pfits_set_slitmap_order_edgup(cpl_propertylist *plist, int absorder, double value)
void xsh_pfits_set_slitmap_median_edgup(cpl_propertylist *plist, double value)
void xsh_pfits_set_slitmap_order_slicup(cpl_propertylist *plist, int absorder, double value)
void xsh_pfits_set_slitmap_median_sliclo(cpl_propertylist *plist, double value)
void xsh_pfits_set_slitmap_order_edglo(cpl_propertylist *plist, int absorder, double value)
void xsh_pfits_set_slitmap_order_sliclo(cpl_propertylist *plist, int absorder, double value)
void xsh_unwrap_vector(cpl_vector **v)
Unwrap a vector and set the pointer to NULL.
void xsh_free_polynomial(cpl_polynomial **p)
Deallocate a polynomial and set the pointer to NULL.
void xsh_free_vector(cpl_vector **v)
Deallocate a vector and set the pointer to NULL.
void xsh_free_image(cpl_image **i)
Deallocate an image and set the pointer to NULL.
void xsh_free_frame(cpl_frame **f)
Deallocate a frame and set the pointer to NULL.
void xsh_free_frameset(cpl_frameset **f)
Deallocate a frame set and set the pointer to NULL.
char * xsh_stringcat_any(const char *s,...)
Concatenate an arbitrary number of strings.
void xsh_free_matrix(cpl_matrix **m)
Deallocate a matrix and set the pointer to NULL.
void xsh_free_table(cpl_table **t)
Deallocate a table and set the pointer to NULL.
void xsh_free_propertylist(cpl_propertylist **p)
Deallocate a property list and set the pointer to NULL.
void xsh_add_temporary_file(const char *name)
Add temporary file to temprary files list.
cpl_polynomial * edguppoly
cpl_polynomial * edglopoly
cpl_propertylist * header
#define XSH_ARCLIST_TABLE_COLNAME_WAVELENGTH
#define XSH_ARCLIST_TABLE_COLNAME_FLUX
#define IFU_MAP_RIGHT_C2Y
#define IFU_MAP_RIGHT_C2X
#define IFU_MAP_RIGHT_C1Y
#define IFU_MAP_RIGHT_C0Y
#define IFU_MAP_RIGHT_C1X
#define IFU_MAP_RIGHT_C0X
#define XSH_RESID_TAB_TABLE_COLNAME_YTHANNEAL
int xsh_resid_tab_get_size(xsh_resid_tab *resid)
#define XSH_RESID_TAB_TABLE_COLNAME_RESIDYMODEL
#define XSH_RESID_TAB_TABLE_COLNAME_XGAUSS
#define XSH_RESID_TAB_TABLE_COLNAME_YGAUSS
#define XSH_RESID_TAB_TABLE_COLNAME_RESIDXMODEL
int * xsh_resid_tab_get_slit_index(xsh_resid_tab *resid)
#define XSH_RESID_TAB_TABLE_COLNAME_XTHANNEAL
#define XSH_THE_MAP_TABLE_COLNAME_SLITINDEX
#define XSH_THE_MAP_TABLE_COLNAME_WAVELENGTH
#define XSH_THE_MAP_TABLE_COLNAME_DETECTORX
#define XSH_THE_MAP_TABLE_COLNAME_SLITPOSITION
#define XSH_THE_MAP_TABLE_COLNAME_ORDER
#define XSH_THE_MAP_TABLE_COLNAME_DETECTORY
int xsh_print_rec_status(const int val)
Check if an error has happened and returns error kind and location.
void xsh_add_product_table(cpl_frame *frame, cpl_frameset *frameset, const cpl_parameterlist *parameters, const char *recipe_id, xsh_instrument *instrument, const char *final_prefix)
Save Table product (input frame has several extensions, 1 table per extension)
cpl_error_code xsh_dfs_extract_raw_frames(cpl_frameset *input, cpl_frameset *raws)
split input sof in groups: raw and calib
char * xsh_get_tag_from_arm(const char *tag, xsh_instrument *instr)
Find arm specific tag from base and instrument setting.
cpl_frame * xsh_frame_product(const char *fname, const char *tag, cpl_frame_type type, cpl_frame_group group, cpl_frame_level level)
Creates a frame with given characteristics.
cpl_frame * xsh_find_frame_with_tag(cpl_frameset *frames, const char *tag, xsh_instrument *instr)
Find frame with a given tag.
#define XSH_MOD_CFG_OPT_REC_VIS
#define XSH_MOD_CFG_OPT_AFC_NIR
#define XSH_MOD_CFG_OPT_REC_UVB
#define XSH_MOD_CFG_OPT_WAV_SLIT_VIS
#define XSH_MOD_CFG_OPT_FMT_NIR
#define XSH_MOD_CFG_OPT_2D_VIS
#define XSH_MOD_CFG_OPT_WAV_IFU_VIS
#define XSH_MOD_CFG_OPT_FMT_UVB
#define XSH_MOD_CFG_OPT_2D_UVB
#define XSH_MOD_CFG_OPT_WAV_IFU_UVB
#define XSH_MOD_CFG_OPT_WAV_IFU_NIR
#define XSH_MOD_CFG_OPT_FMT_VIS
#define XSH_MOD_CFG_OPT_WAV_SLIT_UVB
#define XSH_MOD_CFG_OPT_WAV_SLIT_NIR
#define XSH_MOD_CFG_OPT_AFC_UVB
#define XSH_MOD_CFG_OPT_2D_NIR
#define XSH_MOD_CFG_OPT_AFC_VIS
#define XSH_MOD_CFG_OPT_REC_NIR
static const int vectordim
#define XSH_TRACE_MSG(array)
static double schott_sf6_manu[6][7]
static double silica_zemax[6][7]
#define XSH_SPECTRALFORMAT_DIST_ORDER
#define XSH_QC_MODEL_ANNEAL_RESX_MAX
#define XSH_QC_MODEL_ANNEAL_RESY_RMS
#define XSH_QC_MODEL_PREDICT_RESY_MAX
#define XSH_QC_MODEL_ANNEAL_RESX_MED
#define XSH_QC_MODEL_PREDICT_RESX_MAX
#define XSH_QC_MODEL_PREDICT_RESX_MIN
#define XSH_QC_MODEL_ANNEAL_RESX_AVG
#define XSH_QC_MODEL_ANNEAL_RESY_MAX
#define XSH_QC_MODEL_ANNEAL_RESY_MED
#define XSH_QC_MODEL_PREDICT_RESY_MIN
#define XSH_QC_MODEL_PREDICT_RESX_MED
#define XSH_QC_MODEL_PREDICT_RESY_RMS
#define XSH_QC_MODEL_PREDICT_RESX_AVG
#define XSH_QC_MODEL_PREDICT_RESY_AVG
#define XSH_QC_MODEL_PREDICT_RESY_MED
#define XSH_QC_MODEL_ANNEAL_RESY_AVG
#define XSH_QC_MODEL_ANNEAL_RESY_MIN
#define XSH_QC_MODEL_ANNEAL_RESX_RMS
#define XSH_QC_MODEL_ANNEAL_RESX_MIN
#define XSH_QC_MODEL_PREDICT_RESX_RMS
#define XSH_FREE(POINTER)
#define XSH_CALLOC(POINTER, TYPE, SIZE)
cpl_polynomial * xsh_polynomial_fit_1d_create(const cpl_vector *x_pos, const cpl_vector *values, int degree, double *mse)