00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "cubecreate_ini_by_cpl.h"
00018
00019
00020
00021
00022
00023
00024 static void parse_section_frames(cube_config *,
00025 cpl_frameset* sof,cpl_frameset** stk, int* status);
00026 static void parse_section_resampling(cube_config *, cpl_parameterlist* cpl_cfg);
00027 static void parse_section_calibration(cube_config *);
00028 static void parse_section_cubecreation(cube_config *, cpl_parameterlist* cpl_cfg);
00029 static void parse_section_finetuning(cube_config *, cpl_parameterlist* cpl_cfg);
00030
00031
00032
00033
00034
00045
00046
00047 cube_config * parse_cpl_input_cube(cpl_parameterlist* cpl_cfg, cpl_frameset* sof, cpl_frameset** stk)
00048 {
00049 cube_config * cfg = cube_cfg_create();
00050 const cxchar * _id = "parse_cpl_input_cube";
00051 int status=0;
00052
00053
00054
00055
00056 parse_section_resampling (cfg, cpl_cfg);
00057 parse_section_calibration (cfg);
00058 parse_section_cubecreation (cfg, cpl_cfg);
00059 parse_section_finetuning (cfg, cpl_cfg);
00060 parse_section_frames (cfg, sof,stk,&status);
00061 if (status > 0) {
00062 cpl_msg_error(_id,"parsing cpl input");
00063 cube_cfg_destroy(cfg);
00064 cfg = NULL ;
00065 return NULL ;
00066 }
00067 return cfg ;
00068 }
00069
00070 static void
00071 parse_section_frames(cube_config * cfg,
00072 cpl_frameset * sof,
00073 cpl_frameset ** stk,
00074 int* status)
00075 {
00076 const char* _id = "parse_section_frames";
00077 cpl_frame* frame = NULL;
00078 int wave_map=0;
00079 int pos_slit=0;
00080 int halo_sp=0;
00081 int first_col=0;
00082 int stk_frm=0;
00083
00084 int * labels ;
00085 int nlabels ;
00086 cpl_frameset * cur_set ;
00087 cpl_frame * cur_frame ;
00088 char * tag;
00089 int i=0;
00090 char spat_res[FILE_NAME_SZ];
00091 char lamp_status[FILE_NAME_SZ];
00092 char band[FILE_NAME_SZ];
00093 int ins_set=0;
00094
00095
00096 if ((labels = cpl_frameset_labelise(sof, sinfoni_compare_tags,
00097 &nlabels )) == NULL) {
00098 cpl_msg_error(_id, "Cannot labelise the input frames") ;
00099 (*status)++;
00100 return ;
00101 }
00102 if (nlabels == 1) {
00103
00104
00105 cur_frame = cpl_frameset_get_frame(sof, 0) ;
00106 tag = (char*)cpl_frame_get_tag(cur_frame) ;
00107 if (sinfoni_is_stack(tag)) {
00108 *stk = cpl_frameset_duplicate(sof) ;
00109 }
00110 } else {
00111
00112 for (i=0 ; i<nlabels ; i++) {
00113 cur_set = cpl_frameset_extract(sof, labels, i) ;
00114 cur_frame = cpl_frameset_get_frame(cur_set, 0) ;
00115 tag = (char*)cpl_frame_get_tag(cur_frame) ;
00116
00117 if (sinfoni_is_stack(tag) == 1 || sinfoni_is_mflat(tag) == 1 ) {
00118
00119 *stk = cpl_frameset_duplicate(cur_set) ;
00120
00121 frame = cpl_frameset_get_frame(*stk, 0) ;
00122
00123
00124
00125 strcpy(cfg -> inFrame,cpl_strdup(cpl_frame_get_filename(frame)));
00126 stk_frm=1;
00127 } else if (sinfoni_is_wavemap(tag)) {
00128
00129 strcpy(cfg -> wavemap,
00130 cpl_strdup(cpl_frame_get_filename(cur_frame)));
00131 cpl_msg_info(_id,"cfg -> wavemap %s\n",cfg -> wavemap);
00132 wave_map=1;
00133 } else if (sinfoni_is_halosp(tag)) {
00134
00135 strcpy(cfg -> halospectrum,
00136 cpl_strdup(cpl_frame_get_filename(cur_frame)));
00137 halo_sp=1;
00138 } else if (sinfoni_is_distlist(tag)) {
00139
00140 strcpy(cfg -> poslist,
00141 cpl_strdup(cpl_frame_get_filename(cur_frame)));
00142 pos_slit=1;
00143 } else if (sinfoni_is_firstcol(tag)) {
00144
00145 strcpy(cfg -> firstCol,
00146 cpl_strdup(cpl_frame_get_filename(cur_frame)));
00147 first_col=1;
00148 }
00149 cpl_frameset_delete(cur_set) ;
00150 }
00151 }
00152 cpl_free(labels) ;
00153 if (stk_frm == 0) {
00154 cpl_msg_error(_id, "Cannot find stk frm") ;
00155 (*status)++;
00156 return ;
00157 }
00158 if (wave_map == 0) {
00159 cpl_msg_error(_id, "Cannot find wave map") ;
00160 (*status)++;
00161 return ;
00162 }
00163 if (pos_slit == 0) {
00164 cpl_msg_error(_id, "Cannot find pos slit") ;
00165 (*status)++;
00166 return ;
00167 }
00168 if (first_col == 0) {
00169 cpl_msg_error(_id, "Cannot find first col") ;
00170 (*status)++;
00171 return ;
00172 }
00173
00174 frame = cpl_frameset_get_frame(*stk,0);
00175
00176 sinfoni_get_spatial_res(frame,spat_res);
00177 switch(sinfoni_frame_is_on(frame))
00178 {
00179
00180 case 0:
00181 strcpy(lamp_status,"on");
00182 break;
00183 case 1:
00184 strcpy(lamp_status,"off");
00185 break;
00186 case -1:
00187 strcpy(lamp_status,"undefined");
00188 break;
00189 default:
00190 strcpy(lamp_status,"undefined");
00191 break;
00192 }
00193 sinfoni_get_band(frame,band);
00194 cpl_msg_info(_id,"stat_res: %s lamp_status: %s band: %s",
00195 spat_res, lamp_status, band);
00196
00197
00198 sinfoni_get_ins_set(band,&ins_set);
00199
00200
00201
00202
00203 if (*stk == NULL) {
00204 cpl_msg_error(_id, "Cannot find input stacked frames in the input list") ;
00205 (*status)++;
00206 return ;
00207 }
00208
00209 if(NULL != cpl_frameset_find(sof,PRO_FIRST_COL)) {
00210 frame = cpl_frameset_find(sof,PRO_FIRST_COL);
00211 } else {
00212 cpl_msg_error(_id,"Frame %s not found!", PRO_FIRST_COL);
00213 (*status)++;
00214 return;
00215 }
00216
00217 if (cfg -> halocorrectInd) {
00218 if(NULL != cpl_frameset_find(sof,PRO_HALO_SPECT)) {
00219 frame = cpl_frameset_find(sof,PRO_HALO_SPECT);
00220 strcpy(cfg -> halospectrum,cpl_strdup(cpl_frame_get_filename(frame)));
00221 } else {
00222 cpl_msg_error(_id,"Frame %s not found!", PRO_HALO_SPECT);
00223 (*status)++;
00224 return;
00225 }
00226
00227 }
00228 strcpy(cfg -> outName, QCFLAT_OUT_FILENAME);
00229 return;
00230 }
00231
00232
00233
00234 static void
00235 parse_section_resampling(cube_config * cfg,cpl_parameterlist * cpl_cfg)
00236 {
00237 cpl_parameter* p;
00238 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.cubecreate.n_coeffs");
00239 cfg -> ncoeffs = cpl_parameter_get_int(p);
00240
00241 cfg -> nrows=2560;
00242
00243 return ;
00244 }
00245
00246 static void
00247 parse_section_calibration(cube_config * cfg)
00248
00249 {
00250
00251
00252
00253
00254
00255
00256 cfg -> halocorrectInd=0;
00257
00258 return;
00259 }
00260
00261 static void
00262 parse_section_cubecreation(cube_config * cfg,cpl_parameterlist * cpl_cfg)
00263 {
00264
00265 cpl_parameter* p;
00266 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.cubecreate.nord_south_index");
00267 cfg -> northsouthInd = cpl_parameter_get_bool(p);
00268
00269 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.cubecreate.nslits");
00270 cfg -> nslits = cpl_parameter_get_default_int(p);
00271
00272 return ;
00273 }
00274
00275 static void
00276 parse_section_finetuning(cube_config * cfg,cpl_parameterlist * cpl_cfg)
00277 {
00278
00279 cpl_parameter* p;
00280 char* s;
00281
00282 s = (char*) cpl_calloc(1,sizeof(char ));
00283 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.cubecreate.fine_tuning_method");
00284 strcpy(s, cpl_parameter_get_string(p));
00285 cfg -> method = s[0];
00286
00287 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.cubecreate.order");
00288 cfg -> order = cpl_parameter_get_int(p);
00289 cpl_free(s);
00290
00291
00292 }
00293
00294 void
00295 cube_free(cube_config * cfg)
00296 {
00297
00298 cube_cfg_destroy(cfg);
00299
00300 return;
00301
00302 }