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 #ifdef HAVE_CONFIG_H
00027 #include <config.h>
00028 #endif
00029
00030
00037
00040
00041
00042
00043
00044 #include <math.h>
00045 #include <xsh_drl.h>
00046
00047 #include <xsh_utils_table.h>
00048 #include <xsh_badpixelmap.h>
00049 #include <xsh_data_pre.h>
00050 #include <xsh_dfs.h>
00051 #include <xsh_pfits.h>
00052 #include <xsh_error.h>
00053 #include <xsh_msg.h>
00054 #include <xsh_fit.h>
00055 #include <xsh_data_instrument.h>
00056 #include <xsh_data_localization.h>
00057 #include <xsh_data_spectrum.h>
00058 #include <xsh_data_slice_offset.h>
00059 #include <xsh_data_rec.h>
00060 #include <xsh_ifu_defs.h>
00061
00062 #include <cpl.h>
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 cpl_frame* xsh_compute_slice_dist( cpl_frameset *loc_frame_set,
00073 cpl_frame *order_tab_frame, cpl_frame *slitmap_frame,
00074 cpl_frameset *rec_frameset,
00075 double slicedist_lambda,
00076 xsh_instrument *instrument)
00077 {
00078 cpl_frame * result = NULL ;
00079 cpl_frame *loc_frame = NULL;
00080 cpl_frame *rec_frame = NULL;
00081 xsh_slice_offset *slice = NULL ;
00082 xsh_localization *loc_down = NULL, *loc_cen = NULL, *loc_up = NULL;
00083 char fname[256];
00084 double slit_down, slit_cen, slit_up;
00085 double sdown, sldown, slup, sup;
00086 double dist_up, dist_down;
00087 double lambda;
00088
00089 xsh_rec_list *reclist = NULL;
00090
00091 XSH_ASSURE_NOT_NULL( loc_frame_set);
00092 XSH_ASSURE_NOT_NULL( rec_frameset);
00093 XSH_ASSURE_NOT_NULL( instrument);
00094
00095 xsh_msg( "Get Localization table for slitlet %s",
00096 SlitletName[LOWER_IFU_SLITLET] ) ;
00097 check( loc_frame = cpl_frameset_get_frame( loc_frame_set, 0));
00098 xsh_msg( " '%s'", cpl_frame_get_filename( loc_frame ) ) ;
00099 check( loc_down = xsh_localization_load( loc_frame));
00100
00101 xsh_msg( "Get Localization table for slitlet %s",
00102 SlitletName[CENTER_IFU_SLITLET] ) ;
00103 check( loc_frame = cpl_frameset_get_frame( loc_frame_set, 1));
00104 xsh_msg( " '%s'", cpl_frame_get_filename( loc_frame ) ) ;
00105 check( loc_cen = xsh_localization_load( loc_frame));
00106
00107 xsh_msg( "Get Localization table for slitlet %s",
00108 SlitletName[UPPER_IFU_SLITLET] ) ;
00109 check( loc_frame = cpl_frameset_get_frame( loc_frame_set, 2));
00110 xsh_msg( " '%s'", cpl_frame_get_filename( loc_frame ));
00111 check( loc_up = xsh_localization_load( loc_frame));
00112
00113 check( rec_frame = cpl_frameset_get_frame( rec_frameset, 0));
00114 check( reclist = xsh_rec_list_load( rec_frame, instrument));
00115
00116 check( slice = xsh_slice_offset_create());
00117
00118 if ( slicedist_lambda < 0){
00119 check( lambda = xsh_rec_list_get_lambda_max( reclist));
00120 }
00121 else{
00122 lambda = slicedist_lambda;
00123 }
00124 xsh_msg(" Evaluate at lambda %f", lambda);
00125 check( slit_down = cpl_polynomial_eval_1d(loc_down->cenpoly,
00126 lambda, NULL));
00127 check( slit_cen = cpl_polynomial_eval_1d(loc_cen->cenpoly,
00128 lambda, NULL));
00129 check( slit_up = cpl_polynomial_eval_1d(loc_up->cenpoly,
00130 lambda, NULL));
00131
00132 xsh_msg("SLIT center from localization [%f,%f,%f]", slit_down, slit_cen,
00133 slit_up);
00134
00135 check( xsh_get_slit_edges(
00136 slitmap_frame, &sdown, &sldown, &slup, &sup, instrument));
00137
00138 xsh_msg("EDGES form order tab [%f,[%f %f],%f]",sdown, sldown,
00139 slup, sup);
00140
00141 dist_up = 2*slup-slit_cen-slit_up;
00142 dist_down = 2*sldown-slit_cen-slit_down;
00143 xsh_msg("DISTANCES edgU-->Up = %f edgU-->cen %f ==> %f", slup-slit_up,
00144 slup-slit_cen, dist_up);
00145 xsh_msg("DISTANCES edgD-->Down = %f edgD-->cen %f ==> %f", sldown-slit_down,
00146 sldown-slit_cen, dist_down);
00147
00148 slice->cen_up = dist_up;
00149 slice->cen_down = dist_down;
00150
00151 sprintf( fname, "SLICE_OFFSET_%s.fits",
00152 xsh_instrument_arm_tostring( instrument));
00153 check( result = xsh_slice_offset_save( slice, fname, instrument));
00154
00155 cleanup:
00156 xsh_localization_free( &loc_down);
00157 xsh_localization_free( &loc_cen);
00158 xsh_localization_free( &loc_up);
00159 xsh_slice_offset_free( &slice);
00160 xsh_rec_list_free( &reclist);
00161
00162 if ( cpl_error_get_code() != CPL_ERROR_NONE ) {
00163 xsh_free_frame( &result);
00164 }
00165 return result;
00166 }
00167
00168