156 cpl_ensure (nwave>0, CPL_ERROR_ILLEGAL_INPUT, NULL);
157 cpl_ensure (nrow>0, CPL_ERROR_ILLEGAL_INPUT, NULL);
158 cpl_ensure (oi_name, CPL_ERROR_NULL_INPUT, NULL);
163 cpl_table * oi_table = NULL;
168 oi_table = cpl_table_new(nrow * 6);
170 cpl_table_new_column (oi_table,
"TARGET_ID", CPL_TYPE_INT);
171 cpl_table_set_column_savetype(oi_table,
"TARGET_ID", CPL_TYPE_SHORT);
172 if (init) cpl_table_fill_column_window_int (oi_table,
"TARGET_ID", 0, nrow * 6, 0);
174 cpl_table_new_column (oi_table,
"TIME", CPL_TYPE_DOUBLE);
175 if (init) cpl_table_fill_column_window_double (oi_table,
"TIME", 0, nrow * 6, 0);
176 cpl_table_set_column_unit (oi_table,
"TIME",
"s");
178 cpl_table_new_column (oi_table,
"MJD", CPL_TYPE_DOUBLE);
179 if (init) cpl_table_fill_column_window_double (oi_table,
"MJD", 0, nrow * 6, 0.0);
180 cpl_table_set_column_unit (oi_table,
"MJD",
"d");
182 cpl_table_new_column (oi_table,
"INT_TIME", CPL_TYPE_DOUBLE);
183 if(init) cpl_table_fill_column_window_double (oi_table,
"INT_TIME", 0, nrow * 6, 0.0);
184 cpl_table_set_column_unit (oi_table,
"INT_TIME",
"s");
186 cpl_table_new_column_array (oi_table,
"VISDATA", CPL_TYPE_DOUBLE_COMPLEX, nwave);
187 cpl_table_set_column_unit (oi_table,
"VISDATA",
"e");
188 cpl_table_new_column_array (oi_table,
"VISERR", CPL_TYPE_DOUBLE_COMPLEX, nwave);
189 cpl_table_set_column_unit (oi_table,
"VISERR",
"e");
191 cpl_table_new_column_array (oi_table,
"VISAMP", CPL_TYPE_DOUBLE, nwave);
192 cpl_table_new_column_array (oi_table,
"VISAMPERR", CPL_TYPE_DOUBLE, nwave);
194 cpl_table_new_column_array (oi_table,
"VISPHI", CPL_TYPE_DOUBLE, nwave);
195 cpl_table_set_column_unit (oi_table,
"VISPHI",
"deg");
197 cpl_table_new_column_array (oi_table,
"VISPHIERR", CPL_TYPE_DOUBLE, nwave);
198 cpl_table_set_column_unit (oi_table,
"VISPHIERR",
"deg");
200 cpl_table_new_column_array (oi_table,
"RVIS", CPL_TYPE_DOUBLE, nwave);
201 cpl_table_set_column_unit (oi_table,
"RVIS",
"e");
203 cpl_table_new_column_array (oi_table,
"RVISERR", CPL_TYPE_DOUBLE, nwave);
204 cpl_table_set_column_unit (oi_table,
"RVISERR",
"e");
206 cpl_table_new_column_array (oi_table,
"IVIS", CPL_TYPE_DOUBLE, nwave);
207 cpl_table_set_column_unit (oi_table,
"IVIS",
"e");
209 cpl_table_new_column_array (oi_table,
"IVISERR", CPL_TYPE_DOUBLE, nwave);
210 cpl_table_set_column_unit (oi_table,
"IVISERR",
"e");
212 cpl_table_new_column (oi_table,
"UCOORD", CPL_TYPE_DOUBLE);
213 if(init) cpl_table_fill_column_window_double (oi_table,
"UCOORD", 0, nrow * 6, 0.0);
214 cpl_table_set_column_unit (oi_table,
"UCOORD",
"m");
216 cpl_table_new_column (oi_table,
"VCOORD", CPL_TYPE_DOUBLE);
217 if(init) cpl_table_fill_column_window_double (oi_table,
"VCOORD", 0, nrow * 6, 0.0);
218 cpl_table_set_column_unit (oi_table,
"VCOORD",
"m");
220 cpl_table_new_column_array (oi_table,
"STA_INDEX", CPL_TYPE_INT, 2);
221 cpl_table_set_column_savetype(oi_table,
"STA_INDEX", CPL_TYPE_SHORT);
224 oi_table = cpl_table_new(nrow * 6);
225 cpl_table_new_column (oi_table,
"TARGET_ID", CPL_TYPE_INT);
226 cpl_table_set_column_savetype(oi_table,
"TARGET_ID", CPL_TYPE_SHORT);
227 if(init) cpl_table_fill_column_window_int (oi_table,
"TARGET_ID", 0, nrow * 6, 0);
228 cpl_table_new_column (oi_table,
"TIME", CPL_TYPE_DOUBLE);
229 if(init) cpl_table_fill_column_window_double (oi_table,
"TIME", 0, nrow * 6, 0);
230 cpl_table_set_column_unit (oi_table,
"TIME",
"s");
231 cpl_table_new_column (oi_table,
"MJD", CPL_TYPE_DOUBLE);
232 if(init) cpl_table_fill_column_window_double (oi_table,
"MJD", 0, nrow * 6, 0.0);
233 cpl_table_set_column_unit (oi_table,
"MJD",
"d");
234 cpl_table_new_column (oi_table,
"INT_TIME", CPL_TYPE_DOUBLE);
235 if(init) cpl_table_fill_column_window_double (oi_table,
"INT_TIME",
237 cpl_table_set_column_unit (oi_table,
"INT_TIME",
"s");
238 cpl_table_new_column_array (oi_table,
"VIS2DATA",
239 CPL_TYPE_DOUBLE, nwave);
241 cpl_table_new_column_array (oi_table,
"VIS2ERR",
242 CPL_TYPE_DOUBLE, nwave);
243 cpl_table_new_column (oi_table,
"UCOORD", CPL_TYPE_DOUBLE);
244 if(init) cpl_table_fill_column_window_double (oi_table,
"UCOORD",
246 cpl_table_set_column_unit (oi_table,
"UCOORD",
"m");
247 cpl_table_new_column (oi_table,
"VCOORD", CPL_TYPE_DOUBLE);
248 if(init) cpl_table_fill_column_window_double (oi_table,
"VCOORD",
250 cpl_table_set_column_unit (oi_table,
"VCOORD",
"m");
252 cpl_table_new_column_array (oi_table,
"STA_INDEX", CPL_TYPE_INT, 2);
253 cpl_table_set_column_savetype(oi_table,
"STA_INDEX", CPL_TYPE_SHORT);
256 oi_table = cpl_table_new(nrow * 4);
257 cpl_table_new_column (oi_table,
"TARGET_ID", CPL_TYPE_INT);
258 cpl_table_set_column_savetype(oi_table,
"TARGET_ID", CPL_TYPE_SHORT);
259 if(init) cpl_table_fill_column_window_int (oi_table,
"TARGET_ID",
261 cpl_table_new_column (oi_table,
"TIME", CPL_TYPE_DOUBLE);
262 if(init) cpl_table_fill_column_window_double (oi_table,
"TIME", 0, nrow * 4, 0);
263 cpl_table_set_column_unit (oi_table,
"TIME",
"s");
264 cpl_table_new_column (oi_table,
"MJD", CPL_TYPE_DOUBLE);
265 if(init) cpl_table_fill_column_window_double (oi_table,
"MJD", 0, nrow * 4, 0.0);
266 cpl_table_set_column_unit (oi_table,
"MJD",
"d");
267 cpl_table_new_column (oi_table,
"INT_TIME", CPL_TYPE_DOUBLE);
268 cpl_table_set_column_unit (oi_table,
"INT_TIME",
"s");
269 if(init) cpl_table_fill_column_window_double (oi_table,
"INT_TIME",
271 cpl_table_new_column_array (oi_table,
"T3AMP", CPL_TYPE_DOUBLE, nwave);
272 cpl_table_new_column_array (oi_table,
"T3AMPERR", CPL_TYPE_DOUBLE, nwave);
273 cpl_table_new_column_array (oi_table,
"T3PHI", CPL_TYPE_DOUBLE, nwave);
274 cpl_table_set_column_unit (oi_table,
"T3PHI",
"deg");
275 cpl_table_new_column_array (oi_table,
"T3PHIERR",
276 CPL_TYPE_DOUBLE, nwave);
277 cpl_table_set_column_unit (oi_table,
"T3PHIERR",
"deg");
278 cpl_table_new_column (oi_table,
"U1COORD", CPL_TYPE_DOUBLE);
279 if(init) cpl_table_fill_column_window_double (oi_table,
"U1COORD",
281 cpl_table_set_column_unit (oi_table,
"U1COORD",
"m");
282 cpl_table_new_column (oi_table,
"V1COORD", CPL_TYPE_DOUBLE);
283 if(init) cpl_table_fill_column_window_double (oi_table,
"V1COORD",
285 cpl_table_set_column_unit (oi_table,
"V1COORD",
"m");
286 cpl_table_new_column (oi_table,
"U2COORD", CPL_TYPE_DOUBLE);
287 if(init) cpl_table_fill_column_window_double (oi_table,
"U2COORD",
289 cpl_table_set_column_unit (oi_table,
"U2COORD",
"m");
290 cpl_table_new_column (oi_table,
"V2COORD", CPL_TYPE_DOUBLE);
291 if(init) cpl_table_fill_column_window_double (oi_table,
"V2COORD",
293 cpl_table_set_column_unit (oi_table,
"V2COORD",
"m");
294 cpl_table_new_column_array (oi_table,
"STA_INDEX", CPL_TYPE_INT, 3);
295 cpl_table_set_column_savetype(oi_table,
"STA_INDEX", CPL_TYPE_SHORT);
298 oi_table = cpl_table_new(nrow * 4);
299 cpl_table_new_column (oi_table,
"TARGET_ID", CPL_TYPE_INT);
300 cpl_table_set_column_savetype(oi_table,
"TARGET_ID", CPL_TYPE_SHORT);
301 if(init) cpl_table_fill_column_window_int (oi_table,
"TARGET_ID",
303 cpl_table_new_column (oi_table,
"TIME", CPL_TYPE_DOUBLE);
304 cpl_table_set_column_unit (oi_table,
"TIME",
"s");
305 if(init) cpl_table_fill_column_window_double (oi_table,
"TIME", 0, nrow * 4, 0);
306 cpl_table_new_column (oi_table,
"MJD", CPL_TYPE_DOUBLE);
307 cpl_table_set_column_unit (oi_table,
"MJD",
"d");
308 if(init) cpl_table_fill_column_window_double (oi_table,
"MJD", 0, nrow * 4, 0.0);
309 cpl_table_new_column (oi_table,
"INT_TIME", CPL_TYPE_DOUBLE);
310 cpl_table_set_column_unit (oi_table,
"INT_TIME",
"s");
311 if(init) cpl_table_fill_column_window_double (oi_table,
"INT_TIME",
313 cpl_table_new_column_array (oi_table,
"FLUX",CPL_TYPE_DOUBLE, nwave);
314 cpl_table_set_column_unit (oi_table,
"FLUX",
"e");
315 cpl_table_new_column_array (oi_table,
"FLUXERR",CPL_TYPE_DOUBLE, nwave);
316 cpl_table_set_column_unit (oi_table,
"FLUXERR",
"e");
317 cpl_table_new_column (oi_table,
"STA_INDEX", CPL_TYPE_INT);
318 cpl_table_set_column_savetype(oi_table,
"STA_INDEX", CPL_TYPE_SHORT);
319 if(init) cpl_table_fill_column_window_int (oi_table,
"STA_INDEX",
323 cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
324 "The name of the table is incorrect");
329 cpl_table_new_column_array (oi_table,
"FLAG", CPL_TYPE_INT, nwave);
330 cpl_table_set_column_savetype(oi_table,
"FLAG", CPL_TYPE_BOOL);
331 cpl_array * bool_array = cpl_array_new(nwave, CPL_TYPE_INT);
332 cpl_array_fill_window_int(bool_array, 0, nwave, CPL_FALSE);
333 cpl_table_fill_column_window_array (oi_table,
"FLAG",
334 0, cpl_table_get_nrow(oi_table), bool_array);
335 cpl_array_delete (bool_array);
613 cpl_ensure (
wave_data, CPL_ERROR_NULL_INPUT, -1);
614 cpl_ensure (lambda_max>lambda_min, CPL_ERROR_ILLEGAL_INPUT, -1);
615 cpl_ensure (lambda_min>1e-6 && lambda_min<3e-6, CPL_ERROR_ILLEGAL_INPUT, -1);
616 cpl_ensure (lambda_max>1e-6 && lambda_max<3e-6, CPL_ERROR_ILLEGAL_INPUT, -1);
618 int n_wave = cpl_table_get_column_depth (
wave_data,
"DATA1");
619 int n_region = cpl_table_get_ncol (
wave_data);
621 double wave, max_wave=0., min_wave = 3*pow(10, -6);
622 double sc_medium_res, sc_high_res, sc_low_res;
623 cpl_size ind_min=0, ind_max=n_wave-1;
627 while ((lambda_min-max_wave >= 0.0001*pow(10, -6)) && (ind_min < n_wave)) {
628 for (
int region=0; region < n_region; region++){
630 wave=cpl_array_get(cpl_table_get_array(
wave_data, regname, 0), ind_min, NULL);
631 if (wave >=max_wave) max_wave=wave;
640 while ((lambda_max-min_wave <= -0.0001*pow(10, -6)) && (ind_max >= 0)) {
641 for (
int region=0; region < n_region; region++){
643 wave=cpl_array_get(cpl_table_get_array(
wave_data, regname, 0), ind_max, NULL);
644 if (wave <=min_wave) min_wave=wave;
653 cpl_array * all_steps = cpl_array_new (n_region * (n_wave-1), CPL_TYPE_DOUBLE);
654 for (
int region=0; region < n_region; region++) {
656 for (wave=0; wave < n_wave-1; wave ++)
657 cpl_array_set (all_steps, region*(n_wave-1)+wave, fabs (cpl_array_get (data, wave+1, NULL) - cpl_array_get (data, wave, NULL) ));
660 double res = cpl_array_get_median (all_steps);
661 FREE (cpl_array_delete, all_steps);
664 n_element = ind_max-ind_min+1;
678 sc_low_res = 0.0418181818 * pow(10, -6);
679 sc_medium_res = 0.0022009569 * pow(10, -6);
680 sc_high_res = 0.0002642248 * pow(10, -6);
684 if (( res >= 0.95*sc_low_res) && (res <= 1.05*sc_low_res)) {
685 n_element = round(((lambda_max-lambda_min)/sc_low_res) + 2);
686 cpl_msg_info (cpl_func,
"Chosen SC LOW spectral resolution element = %e m, n_element = %i", sc_low_res, n_element);
691 if ((res >= 0.95*sc_medium_res ) && (res <= 1.05*sc_medium_res)) {
692 n_element = round(((lambda_max-lambda_min)/sc_medium_res) + 1);
693 cpl_msg_info (cpl_func,
"Chosen SC MEDIUM fixed spectral element = %e m, n_element = %i", sc_medium_res, n_element);
699 if ((res >= 0.9*sc_high_res ) && (res <= 1.1*sc_high_res)) {
700 n_element = round(((lambda_max-lambda_min)/sc_high_res) + 1);
701 cpl_msg_info (cpl_func,
"Chosen SC HIGH fixed spectral element = %e m, n_element = %i", sc_high_res, n_element);
706 cpl_msg_info (cpl_func,
"min=%e, max=%e, n=%f, res=%e, n=%i", lambda_min, lambda_max, (lambda_max-lambda_min)/res, res, n_element);
709 if (n_element > n_wave)