00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifdef HAVE_CONFIG_H
00028 # include <config.h>
00029 #endif
00030
00031
00032
00033 #include "sinfo_detlin_ini_by_cpl.h"
00034 #include "sinfo_hidden.h"
00035 #include "sinfo_raw_types.h"
00036 #include "sinfo_functions.h"
00037 #include "sinfo_file_handling.h"
00038
00039
00040
00041 static void
00042 parse_section_frames(detlin_config *,
00043 cpl_frameset* sof, cpl_frameset** raw,int* status);
00044 static void
00045 parse_section_response(detlin_config *, cpl_parameterlist* cpl_cfg);
00046
00047
00066 detlin_config *
00067 sinfo_parse_cpl_input_detlin(cpl_parameterlist * cpl_cfg, cpl_frameset* sof,
00068 cpl_frameset** raw)
00069 {
00070
00071 detlin_config * cfg ;
00072 int status ;
00073
00074
00075
00076
00077
00078 cfg = sinfo_detlin_cfg_create();
00079
00080
00081
00082
00083
00084
00085 status = 0 ;
00086 parse_section_response(cfg, cpl_cfg);
00087 parse_section_frames(cfg, sof, raw, &status);
00088 if (status > 0) {
00089 sinfo_msg_error("parsing cpl input");
00090 sinfo_detlin_free(&cfg);
00091 cfg = NULL ;
00092 return NULL ;
00093 }
00094 return cfg ;
00095 }
00096
00108 static void
00109 parse_section_frames(detlin_config * cfg,
00110 cpl_frameset * sof,
00111 cpl_frameset** raw,
00112 int* status)
00113 {
00114
00115 int i=0;
00116 char* tag=NULL;
00117 int nraw = 0;
00118 int nraw_good = 0;
00119 cpl_frame* frame=NULL;
00120 char spat_res[FILE_NAME_SZ];
00121 char lamp_status[FILE_NAME_SZ];
00122 char band[FILE_NAME_SZ];
00123 int ins_set=0;
00124
00125 sinfo_extract_raw_frames_type(sof,raw,RAW_LINEARITY_LAMP);
00126
00127 nraw=cpl_frameset_get_size(*raw);
00128
00129 if (nraw < 1) {
00130 sinfo_msg_error( "Too few (%d) raw frames (%s) present in"
00131 "frameset!Aborting...",nraw, RAW_LINEARITY_LAMP);
00132 (*status)++;
00133 return;
00134 }
00135
00136
00137
00138
00139
00140 cfg->framelist = cpl_malloc(nraw * sizeof(char*));
00141
00142
00143 for (i=0 ; i<nraw ; i++) {
00144
00145 frame = cpl_frameset_get_frame(*raw,i);
00146 if(sinfo_file_exists((char*)cpl_frame_get_filename(frame))==1)
00147 {
00148 tag = (char*)cpl_frame_get_tag(frame) ;
00149 if(sinfo_is_flat_lindet(tag) || sinfo_is_dark(tag)) {
00150
00151 cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame));
00152 nraw_good++;
00153 }
00154 }
00155 }
00156
00157
00158 cfg->nframes = nraw_good ;
00159 strcpy(cfg -> outName, BP_LIN_OUT_FILENAME);
00160
00161 frame = cpl_frameset_get_frame(*raw,0);
00162 sinfo_get_spatial_res(frame,spat_res);
00163
00164 switch(sinfo_frame_is_on(frame))
00165 {
00166 case 0:
00167 strcpy(lamp_status,"on");
00168 break;
00169 case 1:
00170 strcpy(lamp_status,"off");
00171 break;
00172 case -1:
00173 strcpy(lamp_status,"undefined");
00174 break;
00175 default:
00176 strcpy(lamp_status,"undefined");
00177 break;
00178
00179
00180 }
00181
00182 sinfo_get_band(frame,band);
00183 sinfo_msg("spatial resolution: %s lamp status: %s band: %s \n",
00184 spat_res, lamp_status, band);
00185
00186
00187 sinfo_get_ins_set(band,&ins_set);
00188
00189 if (nraw_good < (cfg->order+1)) {
00190 sinfo_msg_error( "Too few (%d) raw frames (%s) present in"
00191 "frameset as we do a %d order polymnomial fit"
00192 "!Aborting...",nraw_good,
00193 RAW_LINEARITY_LAMP,cfg->order);
00194
00195 (*status)++;
00196 return;
00197 }
00198
00199
00200 return;
00201 }
00210 static void
00211 parse_section_response(detlin_config * cfg,cpl_parameterlist * cpl_cfg)
00212 {
00213 cpl_parameter *p;
00214
00215 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_lin.order");
00216 cfg -> order = cpl_parameter_get_int(p);
00217
00218 p = cpl_parameterlist_find(cpl_cfg,"sinfoni.bp_lin.thresh_sigma_factor");
00219 cfg->threshSigmaFactor = (float) cpl_parameter_get_double(p);
00220
00221 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_lin.low_rejection");
00222 cfg -> loReject = (float) cpl_parameter_get_double(p);
00223
00224 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_lin.high_rejection");
00225 cfg -> hiReject = (float) cpl_parameter_get_double(p);
00226
00227 p = cpl_parameterlist_find(cpl_cfg,"sinfoni.bp_lin.nlin_threshold");
00228 cfg->nonlinearThresh = (float) cpl_parameter_get_double(p);
00229
00230
00231 strcpy(cfg->coeffsCubeName, BP_LIN_COEFFS_CUBE_OUT_FILENAME);
00232
00233 return ;
00234 }
00241 void
00242 sinfo_detlin_free(detlin_config ** cfg)
00243 {
00244 int i=0;
00245 if(*cfg!=NULL) {
00246 for(i=0;i<(*cfg)->nframes; i++) {
00247 if((*cfg)->framelist[i] != NULL) cpl_free((*cfg)->framelist[i]);
00248 }
00249 cpl_free((*cfg)->framelist);
00250 sinfo_detlin_cfg_destroy((*cfg));
00251 *cfg = NULL;
00252 }
00253 return;
00254
00255 }