00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "detlin_ini_by_cpl.h"
00018
00019
00020
00021
00022
00023 static void parse_section_frames(detlin_config *,
00024 cpl_frameset* sof, cpl_frameset** raw,int* status);
00025 static void parse_section_response(detlin_config *, cpl_parameterlist* cpl_cfg);
00026
00027
00028
00039
00040
00041 detlin_config *
00042 parse_cpl_input_detlin(cpl_parameterlist * cpl_cfg, cpl_frameset* sof,
00043 cpl_frameset** raw)
00044 {
00045
00046 const cxchar * _id = "parse_cpl_input_detlin";
00047 detlin_config * cfg ;
00048 int status ;
00049
00050
00051
00052
00053
00054 cfg = detlin_cfg_create();
00055
00056
00057
00058
00059
00060
00061 status = 0 ;
00062 parse_section_response(cfg, cpl_cfg);
00063 parse_section_frames(cfg, sof, raw, &status);
00064 if (status > 0) {
00065 cpl_msg_error(_id,"parsing cpl input");
00066 detlin_free(cfg);
00067 cfg = NULL ;
00068 return NULL ;
00069 }
00070 return cfg ;
00071 }
00072
00073 static void
00074 parse_section_frames(detlin_config * cfg,
00075 cpl_frameset * sof,
00076 cpl_frameset** raw,
00077 int* status)
00078 {
00079
00080 const cxchar * _id = "detlin_ini_by_cpl";
00081 int i=0;
00082 char* tag=NULL;
00083 int nraw = 0;
00084 int nraw_good = 0;
00085 cpl_frame* frame=NULL;
00086 char spat_res[FILE_NAME_SZ];
00087 char lamp_status[FILE_NAME_SZ];
00088 char band[FILE_NAME_SZ];
00089 int ins_set=0;
00090
00091 sinfoni_extract_raw_frames_type(sof,raw,RAW_LINEARITY_LAMP);
00092
00093 nraw=cpl_frameset_get_size(*raw);
00094
00095 if (nraw < 1) {
00096 cpl_msg_error(_id, "Too few (%d) raw frames (%s) present in"
00097 "frameset!Aborting...",nraw, RAW_LINEARITY_LAMP);
00098 (*status)++;
00099 return;
00100 }
00101
00102
00103
00104
00105
00106 cfg->framelist = cpl_malloc(nraw * sizeof(char*));
00107
00108
00109 for (i=0 ; i<nraw ; i++) {
00110
00111 frame = cpl_frameset_get_frame(*raw,i);
00112 if(file_exists((char*)cpl_frame_get_filename(frame))==1)
00113 {
00114 tag = (char*)cpl_frame_get_tag(frame) ;
00115 if(sinfoni_is_flat_lindet(tag) || sinfoni_is_dark(tag)) {
00116
00117
00118 cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame));
00119 nraw_good++;
00120 }
00121 }
00122 }
00123
00124
00125 cfg->nframes = nraw_good ;
00126 strcpy(cfg -> outName, BP_LIN_OUT_FILENAME);
00127
00128 frame = cpl_frameset_get_frame(*raw,0);
00129 sinfoni_get_spatial_res(frame,spat_res);
00130
00131 switch(sinfoni_frame_is_on(frame))
00132 {
00133 case 0:
00134 strcpy(lamp_status,"on");
00135 break;
00136 case 1:
00137 strcpy(lamp_status,"off");
00138 break;
00139 case -1:
00140 strcpy(lamp_status,"undefined");
00141 break;
00142 default:
00143 strcpy(lamp_status,"undefined");
00144 break;
00145
00146
00147 }
00148
00149 sinfoni_get_band(frame,band);
00150 cpl_msg_info(_id,"spatial resolution: %s lamp status: %s band: %s \n",
00151 spat_res, lamp_status, band);
00152
00153
00154 sinfoni_get_ins_set(band,&ins_set);
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164 if (nraw_good < (cfg->order+1)) {
00165 cpl_msg_error(_id, "Too few (%d) raw frames (%s) present in"
00166 "frameset as we do a %d order polymnomial fit"
00167 "!Aborting...",nraw_good, RAW_LINEARITY_LAMP,cfg->order);
00168
00169 (*status)++;
00170 return;
00171 }
00172
00173
00174 return;
00175 }
00176
00177 static void
00178 parse_section_response(detlin_config * cfg,cpl_parameterlist * cpl_cfg)
00179 {
00180 cpl_parameter *p;
00181
00182 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_lin.order");
00183 cfg -> order = cpl_parameter_get_int(p);
00184
00185 p = cpl_parameterlist_find(cpl_cfg,"sinfoni.bp_lin.thresh_sigma_factor");
00186 cfg->threshSigmaFactor = (float) cpl_parameter_get_double(p);
00187
00188 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_lin.low_rejection");
00189 cfg -> loReject = (float) cpl_parameter_get_double(p);
00190
00191 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_lin.high_rejection");
00192 cfg -> hiReject = (float) cpl_parameter_get_double(p);
00193
00194 p = cpl_parameterlist_find(cpl_cfg,"sinfoni.bp_lin.nlin_threshold");
00195 cfg->nonlinearThresh = (float) cpl_parameter_get_double(p);
00196
00197
00198 strcpy(cfg->coeffsCubeName, BP_LIN_COEFFS_CUBE_OUT_FILENAME);
00199
00200 return ;
00201 }
00202
00203 void
00204 detlin_free(detlin_config * cfg)
00205 {
00206 int i=0;
00207 for(i=0;i<cfg->nframes; i++) {
00208 if(cfg->framelist[i] != NULL) cpl_free(cfg->framelist[i]);
00209 }
00210 cpl_free(cfg->framelist);
00211 detlin_cfg_destroy(cfg);
00212
00213 return;
00214
00215 }