CR2RE Pipeline Reference Manual 1.6.8
cr2res_idp.c
1/*
2 * This file is part of the CR2RES Pipeline
3 * Copyright (C) 2002,2003 European Southern Observatory
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA
18 */
19
20#ifdef HAVE_CONFIG_H
21#include <config.h>
22#endif
23
24/*-----------------------------------------------------------------------------
25 Includes
26 -----------------------------------------------------------------------------*/
27
28#include <string.h>
29#include <math.h>
30
31#include <cpl.h>
32
33#include "cr2res_idp.h"
34#include "cr2res_pfits.h"
35#include "cr2res_utils.h"
36#include "cr2res_dfs.h"
37#include "cr2res_io.h"
38#include "cr2res_qc.h"
39
40/*-----------------------------------------------------------------------------
41 Functions prototypes
42 -----------------------------------------------------------------------------*/
43
44static int cr2res_idp_copy_spec(
45 cpl_table * out,
46 const cpl_table * in,
47 cpl_size out_start_idx,
48 int det_nr,
49 int order,
50 int tracenb,
51 const char * setting,
52 int error_method,
53 int nab) ;
54static int cr2res_idp_copy_pol(
55 cpl_table * out,
56 const cpl_table * in,
57 cpl_size out_start_idx,
58 int det_nr,
59 int order,
60 const char * setting) ;
61
62/*----------------------------------------------------------------------------*/
66/*----------------------------------------------------------------------------*/
67
70/*----------------------------------------------------------------------------*/
83/*----------------------------------------------------------------------------*/
85 const char * filename,
86 cpl_frameset * allframes,
87 cpl_frameset * rawframes,
88 const cpl_parameterlist * parlist,
89 cpl_table ** tables,
90 cpl_propertylist * main_qc_plist,
91 cpl_propertylist ** ext_plist,
92 const char * procatg,
93 const char * recipe)
94{
95 cpl_table * idp_tab ;
96 const cpl_array * wlen_arr;
97 cpl_array * tmp_arr;
98 char * idp_filename ;
99 cpl_frame * out_frame ;
100 const cpl_frame * ref_frame ;
101 const char * ref_fname ;
102 cpl_propertylist * pri_head ;
103 cpl_propertylist * ext_head ;
104 double dit, exptime, texptime, mjd_start, mjd_end,
105 wmin, wmax, resol, spec_bin ;
106 const char * progid ;
107 const char * slitname ;
108 const char * setting ;
109 const char * poltype ;
110 int err, i, ndit, nframes, nraw, obid, nrows, ord ;
111 char * keyname;
112 char * tmp_string;
113 const cpl_parameter * param ;
114 int error_method ;
115 int nab;
116
117 const char *nod_catg = "OBS_NODDING_EXTRACT";
118
119 poltype = NULL;
120
121 cpl_msg_info(__func__, "Create IDPs for %s", filename) ;
122 /* Output file name */
123 idp_filename = cpl_sprintf("idp_%s", filename) ;
124
125 /* Create the Primary header */
126 ref_frame = cpl_frameset_get_position_const(rawframes, 0) ;
127 ref_fname = cpl_frame_get_filename(ref_frame) ;
128 pri_head = cpl_propertylist_load(ref_fname, 0);
129
130
131 cr2res_qc_dup_mtrlgy_key(rawframes, pri_head);
132
133 /* Create the first EXTENSION header */
134 ext_head = cpl_propertylist_new() ;
135
136 /* Read spectral setting because we need it to make the table*/
137 setting = cpl_propertylist_get_string(pri_head, "ESO INS WLEN ID");
138
139 /* Create the big table */
140 // NEED TO PASS ERRMETHOD AND NABCYCLES, ERRMETHOD IS IN THE PARLIST, NAB IS IN THE MAIN HEADER
141
142 param = cpl_parameterlist_find_const(parlist,
143 "cr2res.cr2res_obs_nodding.error_method");
144 if (strcmp(cpl_parameter_get_string(param), "Horne") == 0)
145 error_method = CR2RES_EXTRACT_ERROR_HORNE;
146 else
147 error_method = CR2RES_EXTRACT_ERROR_POISSON;
148 if (strncmp(procatg, nod_catg, strlen(nod_catg)) == 0)
149 {
150 //nab = cpl_frameset_count_tags(rawframes,CR2RES_OBS_NODDING_JITTER_RAW) / 2;
151 nab = 1;
152 if (strcmp(procatg, CR2RES_OBS_NODDING_EXTRACTC_IDP_PROCATG) == 0)
153 nab = nab * 2;
154 }
155 else
156 nab = 0;
157
158 idp_tab = cr2res_idp_create_table(tables, recipe, setting, error_method, nab);
159
160 /* Get wmin / wmax */
161 wlen_arr = cpl_table_get_array(idp_tab, CR2RES_IDP_COL_WAVE, 0);
162 nrows = cpl_array_get_size(wlen_arr);
163 wmin = cpl_array_get_double(wlen_arr, 0, &err) ;
164 wmax = cpl_array_get_double(wlen_arr, nrows-1, &err) ;
165
166 /* Prepare frame */
167 out_frame = cpl_frame_new();
168 cpl_frame_set_filename(out_frame, idp_filename);
169 cpl_frame_set_type(out_frame, CPL_FRAME_TYPE_ANY);
170 cpl_frame_set_group(out_frame, CPL_FRAME_GROUP_PRODUCT);
171 cpl_frame_set_level(out_frame, CPL_FRAME_LEVEL_FINAL);
172
173 // Set the PRO.CATG
174 cpl_frame_set_tag(out_frame, procatg);
175 cpl_propertylist_append_string(pri_head, CPL_DFS_PRO_CATG, procatg);
176
177 // TODO: split this type by recipe
178 cpl_propertylist_append_string(pri_head, CR2RES_HEADER_DRS_TYPE,
179 CR2RES_EXTRACT_1D_IDP_DRSTYPE) ;
180
181 if (!strcmp(recipe, "cr2res_obs_nodding")) {
182 cpl_propertylist_update_string(pri_head, "OBSTECH", "NODDING") ;
183 }
184 else if (!strcmp(recipe, "cr2res_obs_staring")) {
185 cpl_propertylist_update_string(pri_head, "OBSTECH", "STARING") ;
186 }
187 else if (!strcmp(recipe, "cr2res_obs_2d")) {
188 cpl_propertylist_update_string(pri_head, "OBSTECH", "GENERIC_OFFSET") ;
189 }
190 else if (!strcmp(recipe, "cr2res_obs_pol")) {
191 cpl_propertylist_update_string(pri_head, "OBSTECH", "POLARIMETRY") ;
192 }
193 cpl_propertylist_set_comment(pri_head, "OBSTECH",
194 "Technique of observation") ;
195
196 /* RADECSYS renamed to RADESYS */
197 if (cpl_propertylist_has(pri_head, "RADECSYS")) {
198 if (!cpl_propertylist_has(pri_head, "RADESYS")) {
199 const cpl_property *_property =
200 cpl_propertylist_get_property_const(pri_head, "RADECSYS");
201 cpl_property *property = cpl_property_duplicate(_property);
202 cpl_property_set_name(property, "RADESYS");
203 cpl_propertylist_append_property(pri_head, property);
204 cpl_property_delete(property);
205 }
206 cpl_propertylist_erase(pri_head, "RADECSYS");
207 }
208
209 cpl_dfs_setup_product_header(pri_head, out_frame, allframes,
210 parlist, recipe, VERSION, "PRO-1.16", ref_frame);
211
212 /* Add Keywords to primary header */
213 // ESO INS FILT1 NAME ---> FILTER
214 if (cpl_propertylist_has(pri_head, "ESO INS FILT1 NAME")) {
215 cpl_propertylist_update_string(pri_head, "FILTER",
216 cpl_propertylist_get_string(pri_head, "ESO INS FILT1 ID")) ;
217 cpl_propertylist_set_comment(pri_head, "FILTER",
218 "");
219 }
220
221 /* Collect data from main header */
222 dit = cr2res_pfits_get_dit(pri_head);
223 ndit = cr2res_pfits_get_ndit(pri_head) ;
224
225 nframes = cpl_frameset_get_size(rawframes);
226 nraw = 0;
227
228 cpl_errorstate tempes = cpl_errorstate_get();
229
230 for (i = 1; i <= nframes; i++) {
231 const char *fname;
232 keyname = cpl_sprintf("ESO PRO REC1 RAW%d NAME", i);
233 fname = cpl_propertylist_get_string(pri_head, keyname);
234 cpl_free(keyname);
235 if (fname != NULL){
236 keyname = cpl_sprintf("PROV%d", i);
237 cpl_propertylist_update_string(pri_head, keyname, fname);
238 cpl_free(keyname);
239 nraw++;
240 }
241 }
242
243 cpl_errorstate_set(tempes);
244
245 /* Add QC from the first Extension ext_plist[0] */
246 if (ext_plist[0] != NULL)
247 cpl_propertylist_copy_property_regexp(ext_head, ext_plist[0], "QC*", 0);
248
249 cpl_propertylist_update_int(pri_head, "NCOMBINE", nraw);
250 exptime = dit * ndit * nraw;
251 cpl_propertylist_update_double(pri_head, "EXPTIME", exptime);
252 cpl_propertylist_set_comment(pri_head, "EXPTIME",
253 "[s] Total integration time per pixel");
254
255 texptime = exptime ;
256 cpl_propertylist_update_double(pri_head, "TEXPTIME", texptime);
257 cpl_propertylist_set_comment(pri_head, "TEXPTIME",
258 "[s] Total integration time of exposures");
259
260 cr2res_idp_compute_mjd(rawframes, &mjd_start, &mjd_end) ;
261 if (mjd_start > 0.0) {
262 cpl_propertylist_update_double(pri_head, "MJD-OBS", mjd_start) ;
263 cpl_propertylist_set_comment(pri_head, "MJD-OBS",
264 "[d] Start of observations (days)");
265 }
266 if (mjd_end > 0.0) {
267 cpl_propertylist_update_double(pri_head, "MJD-END", mjd_end) ;
268 cpl_propertylist_set_comment(pri_head, "MJD-END",
269 "[d] End of observations (days)");
270 }
271
272 if (mjd_end > 0 && mjd_start > 0) {
273 cpl_propertylist_update_double(ext_head, "TELAPSE",
274 (mjd_end-mjd_start)*24*3600) ;
275 cpl_propertylist_set_comment(ext_head, "TELAPSE",
276 "Total elapsed time in seconds [s]") ;
277
278 cpl_propertylist_update_double(ext_head, "TMID",
279 (mjd_end+mjd_start)/2.0) ;
280 cpl_propertylist_set_comment(ext_head, "TMID",
281 "Exposure midpoint [MJD]") ;
282 }
283
284 progid = cr2res_pfits_get_progid(pri_head) ;
285 cpl_propertylist_update_string(pri_head, "PROG_ID", progid) ;
286 cpl_propertylist_set_comment(pri_head, "PROG_ID",
287 "ESO programme identification");
288
289 obid = cr2res_pfits_get_obs_id(pri_head) ;
290 cpl_propertylist_update_int(pri_head, "OBID1", obid);
291 cpl_propertylist_set_comment(pri_head, "OBID1", "Observation block ID");
292
293 if (!strcmp(recipe, "cr2res_obs_2d"))
294 cpl_propertylist_update_bool(pri_head, "EXT_OBJ", 1) ;
295 else
296 cpl_propertylist_update_bool(pri_head, "EXT_OBJ", 0) ;
297 cpl_propertylist_set_comment(pri_head, "EXT_OBJ",
298 "True for extended objects, cr2res_obs_2d was used") ;
299
300 cpl_propertylist_update_string(pri_head, "FLUXCAL", "UNCALIBRATED") ;
301 cpl_propertylist_set_comment(pri_head, "FLUXCAL",
302 "Type of flux calibration");
303
304 cpl_propertylist_update_int(pri_head, "FLUXERR", -1) ;
305 cpl_propertylist_set_comment(pri_head, "FLUXERR",
306 "Fractional uncertainty [%%] on the flux scale");
307
308 cpl_propertylist_update_bool(pri_head, "TOT_FLUX", 0) ;
309 cpl_propertylist_set_comment(pri_head, "TOT_FLUX",
310 "True if flux data represent the total source flux.");
311
312 /* Find blaze to decide if continuum normalized or not,
313 * but set false anyway for now, code left in case this
314 * changes again.*/
315 if ( cpl_frameset_find_const(allframes,
316 CR2RES_CAL_FLAT_EXTRACT_1D_PROCATG) != NULL) {
317 cpl_propertylist_update_bool(pri_head, "CONTNORM", 0) ;
318 } else {
319 cpl_propertylist_update_bool(pri_head, "CONTNORM", 0) ;
320 }
321 cpl_propertylist_set_comment(pri_head, "CONTNORM",
322 "TRUE if the spectrum has been divided by the blaze") ;
323
324
325 cpl_propertylist_update_string(pri_head, "SPECSYS", "TOPOCENT") ;
326 cpl_propertylist_set_comment(pri_head, "SPECSYS",
327 "Frame of reference for spectral coordinates");
328
329 cpl_propertylist_update_string(pri_head, "PROCSOFT",
330 PACKAGE "/" PACKAGE_VERSION) ;
331 cpl_propertylist_set_comment(pri_head, "PROCSOFT", "ESO pipeline version");
332
333 cpl_propertylist_update_string(pri_head, "REFERENC", "") ;
334 cpl_propertylist_set_comment(pri_head, "REFERENC", "Reference publication");
335
336 cpl_propertylist_update_string(pri_head, "PRODCATG", "SCIENCE.SPECTRUM") ;
337 cpl_propertylist_set_comment(pri_head, "PRODCATG", "Data product category");
338
339
340 cpl_propertylist_update_double(pri_head, "WAVELMIN", wmin) ;
341 cpl_propertylist_set_comment(pri_head, "WAVELMIN",
342 "Minimum Wavelength [nm]") ;
343
344 cpl_propertylist_update_double(pri_head, "WAVELMAX", wmax) ;
345 cpl_propertylist_set_comment(pri_head, "WAVELMAX",
346 "Maximum Wavelength [nm]") ;
347
348 cpl_propertylist_update_double(pri_head, "SPEC_VAL", (wmax+wmin)/2.0) ;
349 cpl_propertylist_set_comment(pri_head, "SPEC_VAL",
350 "Characteristic spectral coordinate value [nm]") ;
351
352 cpl_propertylist_update_double(pri_head, "SPEC_BW", wmax-wmin) ;
353 cpl_propertylist_set_comment(pri_head, "SPEC_BW",
354 "Width of the spectrum [nm]") ;
355
356 cpl_propertylist_update_string(pri_head, "SPECSYS", "TOPOCENT") ;
357 cpl_propertylist_set_comment(pri_head, "SPECSYS",
358 "") ;
359
360 tmp_arr = cpl_array_new(cpl_array_get_size(wlen_arr)-1, CPL_TYPE_DOUBLE);
361 for (i=1; i<cpl_array_get_size(wlen_arr);i++){
362 cpl_array_set_double(tmp_arr, i-1,
363 cpl_array_get_double(wlen_arr,i, NULL)-
364 cpl_array_get_double(wlen_arr,i-1, NULL)
365 );
366 }
367 spec_bin = cpl_array_get_median(tmp_arr);
368 cpl_array_delete(tmp_arr);
369 cpl_propertylist_update_double(pri_head, "SPEC_BIN", spec_bin) ;
370 cpl_propertylist_set_comment(pri_head, "SPEC_BIN",
371 "Median spectral bin width [nm]") ;
372
373 slitname = cpl_propertylist_get_string(pri_head,"ESO INS SLIT1 ID");
374 if (!strcmp(slitname,"w_0.2")) {
375 cpl_propertylist_update_double(ext_head, "APERTURE", 5.5555555E-5) ;
376 cpl_propertylist_update_double(pri_head, "SPEC_RES", SPEC_RESOL_SLIT02);
377 }
378 else if (!strcmp(slitname,"w_0.4")) {
379
380 cpl_propertylist_update_double(ext_head, "APERTURE", 1.1111111E-4) ;
381 cpl_propertylist_update_double(pri_head, "SPEC_RES", SPEC_RESOL_SLIT04);
382 }
383 cpl_propertylist_set_comment(ext_head, "APERTURE",
384 "Slit width in deg") ;
385 cpl_propertylist_set_comment(pri_head, "SPEC_RES",
386 "Nominal resolving power for the given slit");
387
388 /* Get some keys from the extension headers*/
389 tmp_arr = cpl_array_new(12*CR2RES_NB_DETECTORS, CPL_TYPE_DOUBLE);
390 cpl_array * tmp_arr_sig = cpl_array_new(CR2RES_NB_DETECTORS, CPL_TYPE_DOUBLE);
391 for (i=0; i<CR2RES_NB_DETECTORS; i++){
392 resol = cpl_propertylist_get_double(ext_plist[i], CR2RES_HEADER_QC_SIGNAL);
393 if (resol==0){
394 cpl_error_reset();
395 } else {
396 cpl_array_set_double(tmp_arr_sig, i, resol);
397 }
398 for (ord=0; ord < 12; ord++){
399 keyname = cpl_sprintf(CR2RES_HEADER_QC_SNR, ord+1);
400 resol = cpl_propertylist_get_double(ext_plist[i], keyname);
401 if (resol==0){
402 cpl_error_reset();
403 } else {
404 /* FIXME: The error propagation is not correct. PIPE-11912
405 * Correction_factor = <Error_propagated_corrected> / <Error_propagated>
406 * where
407 * <Error_propagated_corrected> = [((a*<Error_propagated>)**2 + b**2)**0.5]
408 * where a=2.12 and b=26.1, as above.
409 */
410 double perr = cpl_array_get_double(tmp_arr_sig, i, NULL) / resol;
411 double corr = sqrt(pow(2.08*perr,2) + nab*25.2*25.2) / perr;
412 cpl_array_set_double(tmp_arr, ord + (i*12),resol/corr);
413 if(i==0){
414 cpl_propertylist_update_double(ext_head, keyname, resol/corr) ;
415 }
416 }
417 cpl_free(keyname);
418 }
419 }
420 cpl_propertylist_update_double(pri_head, "SNR",
421 cpl_array_get_median(tmp_arr)) ;
422 cpl_propertylist_set_comment(pri_head, "SNR",
423 "Median signal-to-noise in all detector-orders");
424 cpl_array_delete(tmp_arr);
425
426 if (!strcmp(recipe,"cr2res_obs_pol")) {
427 /* Find Pol.TYPE */
428 poltype = cr2res_pfits_get_poltype(pri_head);
429 tmp_string = cpl_sprintf("/I/%s/",poltype);
430 cpl_propertylist_update_string(pri_head, "STOKES", tmp_string);
431 cpl_free(tmp_string);
432 }
433
434 /* Remove the ASSON keywords */
435 cpl_propertylist_erase_regexp(pri_head, "ASSO*", 0);
436
437 /* Add QC from the main Extension */
438 if (main_qc_plist != NULL) {
439 cpl_propertylist_copy_property_regexp(pri_head, main_qc_plist, "QC*",
440 0);
441 }
442
443 /* Save the main header */
444 cpl_propertylist_save(pri_head, idp_filename, CPL_IO_CREATE);
445
446
447 /* Add Keywords to extension header */
448 cpl_propertylist_update_string(ext_head, "EXTNAME", "SPECTRUM") ;
449
450 cpl_propertylist_update_double(ext_head, "RA",
451 cpl_propertylist_get_double(pri_head, "RA"));
452 cpl_propertylist_set_comment(ext_head, "RA",
453 cpl_propertylist_get_comment(pri_head, "RA"));
454 cpl_propertylist_update_double(ext_head, "DEC",
455 cpl_propertylist_get_double(pri_head, "DEC"));
456 cpl_propertylist_set_comment(ext_head, "DEC",
457 cpl_propertylist_get_comment(pri_head, "DEC"));
458 cpl_propertylist_update_string(ext_head, "OBJECT",
459 cpl_propertylist_get_string(pri_head, "OBJECT"));
460 cpl_propertylist_set_comment(ext_head, "OBJECT",
461 cpl_propertylist_get_comment(pri_head, "OBJECT"));
462 tmp_string = cpl_sprintf("%s - %f",
463 cpl_propertylist_get_string(pri_head, "OBJECT"), mjd_start);
464
465 cpl_propertylist_update_string(ext_head, "TITLE", tmp_string);
466 cpl_free(tmp_string);
467 cpl_propertylist_set_comment(ext_head, "TITLE",
468 "Title is OBJECT and MJD at start");
469
470 cpl_propertylist_update_double(ext_head, "SPEC_VAL", (wmax+wmin)/2.0) ;
471 cpl_propertylist_set_comment(ext_head, "SPEC_VAL",
472 "Characteristic spectral coordinate value [nm]") ;
473 cpl_propertylist_update_double(ext_head, "SPEC_BW", wmax-wmin) ;
474 cpl_propertylist_set_comment(ext_head, "SPEC_BW",
475 "Width of the spectrum [nm]") ;
476
477 cpl_propertylist_update_string(ext_head, "VOPUB", "ESO/SAF") ;
478 cpl_propertylist_set_comment(ext_head, "VOPUB", "VO Publishing Authority") ;
479 cpl_propertylist_update_string(ext_head, "VOCLASS", "SPECTRUM V1.0") ;
480 cpl_propertylist_set_comment(ext_head, "VOCLASS",
481 "Data Model name and version") ;
482 cpl_propertylist_update_int(ext_head, "NELEM", nrows) ;
483 cpl_propertylist_set_comment(ext_head, "NELEM", "Length of the data array");
484
485 cpl_propertylist_update_string(ext_head, "TUTYP1",
486 "spec:Data.SpectralAxis.Value");
487 cpl_propertylist_update_string(ext_head, "TUCD1", "em.wl");
488 cpl_propertylist_update_double(ext_head, "TDMIN1", wmin);
489 cpl_propertylist_update_double(ext_head, "TDMAX1", wmax);
490
491 cpl_propertylist_update_string(ext_head, "TUTYP2",
492 "spec:Data.FluxAxis.Value");
493 cpl_propertylist_update_string(ext_head, "TUCD2",
494 "phot.flux.density;em.wl;stat.uncalib");
495
496 cpl_propertylist_update_string(ext_head, "TUTYP3",
497 "spec:Data.FluxAxis.Accuracy.StatError");
498 cpl_propertylist_update_string(ext_head, "TUCD3",
499 "stat.error;phot.flux.density;em.wl;stat.uncalib");
500
501 cpl_propertylist_update_string(ext_head, "TUTYP4",
502 "spec:Data.FluxAxis.Accuracy.QualityStatus");
503 cpl_propertylist_update_string(ext_head, "TUCD4",
504 "meta.code.qual");
505
506 cpl_propertylist_update_string(ext_head, "TUTYP5",
507 "");
508 cpl_propertylist_update_string(ext_head, "TUCD5",
509 "instr.order");
510
511 cpl_propertylist_update_string(ext_head, "TUTYP6",
512 "");
513 cpl_propertylist_update_string(ext_head, "TUCD6",
514 "meta.number;instr.det");
515
516 if (!strcmp(recipe,"cr2res_obs_pol")) { // POL
517 cpl_propertylist_update_string(ext_head, "TUTYP7", "");
518 tmp_string = cpl_sprintf("phot.count;phys.polarization.stokes.%s",
519 poltype);
520 cpl_propertylist_update_string(ext_head, "TUCD7", tmp_string);
521 cpl_free(tmp_string);
522
523 cpl_propertylist_update_string(ext_head, "TUTYP8", "");
524 tmp_string = cpl_sprintf("stat.error;phys.polarization.stokes.%s",
525 poltype);
526 cpl_propertylist_update_string(ext_head, "TUCD8", tmp_string);
527 cpl_free(tmp_string);
528 } else { // Nodding and staring
529 cpl_propertylist_update_string(ext_head, "TUTYP7",
530 "");
531 cpl_propertylist_update_string(ext_head, "TUCD7",
532 "pos.cartesian.x;instr.det");
533
534 cpl_propertylist_update_string(ext_head, "TUTYP8",
535 "");
536 cpl_propertylist_update_string(ext_head, "TUCD8",
537 "meta.number"); // TraceNb
538
539 }
540 /* For Y pixel coordinate in OBS_2D
541 TUCDi = pos.cartesian.y;instr.det
542
543 for pol
544 phot.count;phys.polarization.stokes.I
545 */
546
547 /* Remove keywords */
548 cpl_propertylist_erase(ext_head, "CRDER3");
549 cpl_propertylist_erase(ext_head, "CUNIT3");
550 cpl_propertylist_erase(ext_head, "BUNIT");
551 cpl_propertylist_erase(ext_head, "CTYPE1");
552 cpl_propertylist_erase(ext_head, "CUNIT2");
553 cpl_propertylist_erase(ext_head, "CSYER1");
554 cpl_propertylist_erase(ext_head, "CSYER2");
555 cpl_propertylist_erase(ext_head, "CDELT1");
556 cpl_propertylist_erase(ext_head, "CRPIX1");
557 cpl_propertylist_erase(ext_head, "CRVAL1");
558 cpl_propertylist_erase(ext_head, "CUNIT1");
559
560
561 /* Save the table */
562 cpl_table_save(idp_tab, NULL, ext_head, idp_filename, CPL_IO_EXTEND) ;
563
564 /* Insert it in the Frameset */
565 cpl_frameset_insert(allframes, out_frame);
566
567 /* Clean */
568 cpl_free(idp_filename) ;
569 cpl_table_delete(idp_tab) ;
570 cpl_propertylist_delete(pri_head) ;
571 cpl_propertylist_delete(ext_head) ;
572
573 return 0 ;
574}
575
576/*----------------------------------------------------------------------------*/
582/*----------------------------------------------------------------------------*/
584 cpl_table ** tables,
585 const char * recipe,
586 const char * setting,
587 int error_method,
588 int nab)
589{
590 cpl_table * idp_tab ;
591 cpl_table * tmp_tab ;
592 cpl_array * col_names ;
593 const char * col_name ;
594 char * col_kind ;
595 cpl_type col_type;
596 cpl_propertylist * sort_list ;
597 int order, trace_nb ;
598 cpl_size i, j, ntot, ncols, nrows, nb_selected ;
599
600 /* Check Inputs */
601 if (tables == NULL) return NULL ;
602
603 /* Count the Rows */
604 ntot = 0 ;
605 for (i=0 ; i<CR2RES_NB_DETECTORS ; i++) {
606 if (tables[i] != NULL) {
607 col_names = cpl_table_get_column_names(tables[i]);
608 ncols = cpl_table_get_ncol(tables[i]) ;
609 if (strcmp(recipe, "cr2res_obs_pol")) { // nodding and staring
610 for (j=0 ; j<ncols ; j++) {
611 col_name = cpl_array_get_string(col_names, j);
612 col_kind = cr2res_dfs_SPEC_colname_parse(col_name,
613 &order, &trace_nb) ;
614 if (col_kind != NULL &&
615 !strcmp(col_kind, CR2RES_COL_SPEC_SUFFIX)) {
616 /* Handle this extracted spectrum */
617 ntot += cpl_table_get_nrow(tables[i]) ;
618 }
619 if (col_kind != NULL) cpl_free(col_kind) ;
620 }
621 } else { // POL
622 for (j=0 ; j<ncols ; j++) {
623 col_name = cpl_array_get_string(col_names, j);
624 col_kind = cr2res_dfs_POL_colname_parse(col_name,
625 &order) ;
626 if (col_kind != NULL &&
627 !strcmp(col_kind, CR2RES_COL_POL_INTENS_SUFFIX)) {
628 /* Handle this extracted spectrum */
629 ntot += cpl_table_get_nrow(tables[i]) ;
630 }
631 if (col_kind != NULL) cpl_free(col_kind) ;
632 }
633 }
634 cpl_array_delete(col_names) ;
635 }
636 }
637 cpl_msg_info(__func__, "Found %lld total rows.", ntot);
638
639 /* Create the table */
640 tmp_tab = cpl_table_new(ntot) ;
641 cpl_table_new_column(tmp_tab, CR2RES_IDP_COL_WAVE, CPL_TYPE_DOUBLE);
642 cpl_table_new_column(tmp_tab, CR2RES_IDP_COL_FLUX, CPL_TYPE_DOUBLE);
643 cpl_table_new_column(tmp_tab, CR2RES_IDP_COL_ERR, CPL_TYPE_DOUBLE);
644 cpl_table_new_column(tmp_tab, CR2RES_IDP_COL_QUAL, CPL_TYPE_INT);
645 cpl_table_new_column(tmp_tab, CR2RES_IDP_COL_ORDER, CPL_TYPE_INT);
646 cpl_table_new_column(tmp_tab, CR2RES_IDP_COL_DETEC, CPL_TYPE_INT);
647 if (strcmp(recipe, "cr2res_obs_pol")) { // nodding and staring
648 cpl_table_new_column(tmp_tab, CR2RES_IDP_COL_XPOS, CPL_TYPE_INT);
649 cpl_table_new_column(tmp_tab, CR2RES_IDP_COL_TRACE, CPL_TYPE_INT);
650 } else {
651 cpl_table_new_column(tmp_tab, CR2RES_IDP_COL_STOKES, CPL_TYPE_DOUBLE);
652 cpl_table_new_column(tmp_tab,
653 CR2RES_IDP_COL_STOKESERR, CPL_TYPE_DOUBLE);
654
655 }
656
657 /* Fill the table */
658 ntot = 0 ;
659 for (i=0 ; i<CR2RES_NB_DETECTORS ; i++) {
660 if (tables[i] != NULL) {
661 col_names = cpl_table_get_column_names(tables[i]);
662 ncols = cpl_table_get_ncol(tables[i]) ;
663 if (strcmp(recipe, "cr2res_obs_pol")) { // nodding and staring
664 for (j=0 ; j<ncols ; j++) {
665 col_name = cpl_array_get_string(col_names, j);
666 col_kind = cr2res_dfs_SPEC_colname_parse(col_name,
667 &order, &trace_nb) ;
668 if (col_kind != NULL &&
669 !strcmp(col_kind, CR2RES_COL_SPEC_SUFFIX)) {
670 /* Handle this extracted spectrum */
671 cr2res_idp_copy_spec(tmp_tab, tables[i], ntot, i+1,
672 order, trace_nb, setting, error_method, nab); ;
673 ntot += cpl_table_get_nrow(tables[i]) ;
674 }
675 if (col_kind != NULL) cpl_free(col_kind) ;
676 }
677 } else {
678 for (j=0 ; j<ncols ; j++) {
679 col_name = cpl_array_get_string(col_names, j);
680 col_kind = cr2res_dfs_POL_colname_parse(col_name, &order);
681 if (col_kind != NULL &&
682 !strcmp(col_kind, CR2RES_COL_POL_INTENS_SUFFIX)) {
683 cr2res_idp_copy_pol(tmp_tab, tables[i], ntot, i + 1,
684 order, setting);
685 ntot += cpl_table_get_nrow(tables[i]) ;
686 }
687 if (col_kind != NULL) cpl_free(col_kind) ;
688 }
689 }
690 cpl_array_delete(col_names) ;
691 }
692 }
693 /*Remove any rows with NaN as the wavelength value*/
694 cpl_table_unselect_all(tmp_tab) ;
695 int ii;
696 for (ii = 0; ii < ntot; ii++) {
697 double wave;
698 wave = cpl_table_get_double(tmp_tab,CR2RES_IDP_COL_WAVE,ii, NULL) ;
699 if (isnan(wave)) {
700 cpl_table_select_row(tmp_tab, ii) ;
701 }
702 }
703 cpl_table_erase_selected(tmp_tab) ;
704
705
706 /* Sort by the wavelengths */
707 sort_list = cpl_propertylist_new() ;
708 cpl_propertylist_append_bool(sort_list, CR2RES_IDP_COL_WAVE, 0) ;
709 //cpl_propertylist_append_bool(sort_list, CR2RES_IDP_COL_XPOS, 1) ;
710 cpl_table_sort(tmp_tab, sort_list) ;
711 cpl_propertylist_delete(sort_list) ;
712
713 cpl_table_unselect_all(tmp_tab) ;
714 /*Find first valid row*/
715 int flag = 0;
716 for (ii = 0; ii < ntot; ii++) {
717 cpl_table_get_double(tmp_tab,CR2RES_IDP_COL_WAVE,ii, &flag) ;
718 if(!flag) break;
719 cpl_table_select_row(tmp_tab, ii);
720 }
721
722 /* Identify close values */
723 for (i = ii+1; i < ntot; i++) {
724 double cur_val, pre_val;
725 flag = 0;
726 pre_val = cpl_table_get_double(tmp_tab,CR2RES_IDP_COL_WAVE,i-1, NULL);
727 cur_val = cpl_table_get_double(tmp_tab,CR2RES_IDP_COL_WAVE,i, &flag) ;
728 if (fabs(pre_val-cur_val) < 1e-3 || flag) {
729 cpl_table_select_row(tmp_tab, i) ;
730 }
731 }
732
733 nb_selected = cpl_table_count_selected(tmp_tab) ;
734 if (nb_selected > 0) {
735 cpl_msg_info(__func__,
736 "IDP Creation - Double defined WLs : %"CPL_SIZE_FORMAT,
737 nb_selected) ;
738 }
739 cpl_table_erase_selected(tmp_tab) ;
740
741 /* Transform table to single row with arrays */
742 col_names = cpl_table_get_column_names(tmp_tab);
743 ncols = cpl_table_get_ncol(tmp_tab);
744 nrows = cpl_table_get_nrow(tmp_tab);
745 idp_tab = cpl_table_new(1);
746 for (j = 0; j < ncols; j++) {
747 cpl_array *tmp_arr;
748 col_name = cpl_array_get_string(col_names, j);
749 cpl_msg_debug(__func__,"colname: %s", col_name);
750 col_type = cpl_table_get_column_type(tmp_tab, col_name);
751 tmp_arr = cpl_array_new(nrows, col_type);
752 if (col_type==CPL_TYPE_DOUBLE){
753 cpl_array_copy_data_double(tmp_arr,
754 cpl_table_get_data_double_const(tmp_tab, col_name));
755 } else if (col_type==CPL_TYPE_INT){
756 cpl_array_copy_data_int(tmp_arr,
757 cpl_table_get_data_int_const(tmp_tab, col_name));
758 } else {continue;}
759 cpl_table_new_column_array(idp_tab, col_name, col_type, nrows);
760 cpl_table_set_array(idp_tab, col_name, 0, tmp_arr);
761 cpl_array_delete(tmp_arr);
762 }
763 cpl_array_delete(col_names) ;
764 cpl_table_delete(tmp_tab);
765
766
767 /* Set the units */
768 cpl_table_set_column_unit(idp_tab, CR2RES_IDP_COL_WAVE, "nm") ;
769 cpl_table_set_column_unit(idp_tab, CR2RES_IDP_COL_DETEC, " ") ;
770 cpl_table_set_column_unit(idp_tab, CR2RES_IDP_COL_ORDER, " ") ;
771 cpl_table_set_column_unit(idp_tab, CR2RES_IDP_COL_QUAL, " ") ;
772 cpl_table_set_column_unit(idp_tab, CR2RES_IDP_COL_FLUX, "adu") ;
773 cpl_table_set_column_unit(idp_tab, CR2RES_IDP_COL_ERR, "adu") ;
774 if (strcmp(recipe, "cr2res_obs_pol")) { // nodding and staring
775 cpl_table_set_column_unit(idp_tab, CR2RES_IDP_COL_TRACE, " ") ;
776 cpl_table_set_column_unit(idp_tab, CR2RES_IDP_COL_XPOS, "pixel") ;
777 } else {
778 cpl_table_set_column_unit(idp_tab, CR2RES_IDP_COL_STOKES, " ") ;
779 cpl_table_set_column_unit(idp_tab, CR2RES_IDP_COL_STOKESERR, " ") ;
780 }
781
782 return idp_tab ;
783
784}
785
786/*----------------------------------------------------------------------------*/
792/*----------------------------------------------------------------------------*/
794 cpl_frameset * fset,
795 double * mjd_start,
796 double * mjd_end)
797{
798 cpl_frame * cur_frame ;
799 const char * cur_fname ;
800 cpl_propertylist * plist ;
801 double mjd_end_cur, mjd_end_max, mjd_obs, dit,
802 mjd_start_cur, mjd_start_min ;
803 int i, nframes, ndit ;
804
805 /* Initialise */
806 mjd_end_max = -1.0 ;
807 mjd_start_min = 1e10 ;
808 nframes = cpl_frameset_get_size(fset) ;
809
810 cpl_errorstate tempes = cpl_errorstate_get();
811 cpl_error_reset();
812
813 /* Loop */
814 for (int ifr = 0; ifr <= 1; ifr++) {
815 for (i = 0; i < nframes; i++) {
816 cur_frame = cpl_frameset_get_position(fset, i);
817 if (ifr == 0 &&
818 cpl_frame_get_group(cur_frame) != CPL_FRAME_GROUP_RAW)
819 continue;
820 cur_fname = cpl_frame_get_filename(cur_frame);
821
822 /* Get header infos */
823 plist = cpl_propertylist_load(cur_fname, 0);
824 dit = cr2res_pfits_get_dit(plist);
825 ndit = cr2res_pfits_get_ndit(plist);
826 mjd_obs = cr2res_pfits_get_mjd_obs(plist);
827 if (cpl_error_get_code() == CPL_ERROR_NONE) {
828 /* Compute current value */
829 mjd_start_cur = mjd_obs;
830 mjd_end_cur = mjd_obs + (dit * ndit / (24 * 60 * 60));
831 }
832 else {
833 mjd_end_cur = -2.0;
834 mjd_start_cur = 1e11;
835 cpl_error_reset();
836 }
837 /* Update max */
838 if (mjd_end_cur > mjd_end_max)
839 mjd_end_max = mjd_end_cur;
840 if (mjd_start_cur < mjd_start_min) {
841 mjd_start_min = mjd_start_cur;
842 }
843 cpl_propertylist_delete(plist);
844 }
845 if (mjd_start_min != 1e10)
846 break;
847 }
848
849 cpl_errorstate_set(tempes);
850
851 if (mjd_start_min < 1e9) {
852 *mjd_start = mjd_start_min ;
853 } else {
854 *mjd_start = -1.0 ;
855 }
856 if (mjd_end_max > 0.0) *mjd_end = mjd_end_max ;
857 else *mjd_end = -1.0 ;
858 return 0 ;
859}
860
863/*----------------------------------------------------------------------------*/
875/*----------------------------------------------------------------------------*/
876static int cr2res_idp_copy_spec(
877 cpl_table * out,
878 const cpl_table * in,
879 cpl_size out_start_idx,
880 int det_nr,
881 int order,
882 int tracenb,
883 const char * setting,
884 int error_method,
885 int nab)
886{
887 char * spec_name ;
888 char * wave_name ;
889 char * err_name ;
890 const double * pspec ;
891 const double * pwave ;
892 const double * perr ;
893 cpl_size in_size, out_size, i, edgepix ;
894
895 /* Check entries */
896 if (out == NULL || in == NULL) return -1 ;
897 in_size = cpl_table_get_nrow(in) ;
898 out_size = cpl_table_get_nrow(out) ;
899
900 /* Get the Spectrum */
901 spec_name = cr2res_dfs_SPEC_colname(order, tracenb) ;
902 if ((pspec = cpl_table_get_data_double_const(in, spec_name)) == NULL) {
903 cpl_msg_error(__func__, "Cannot find the spectrum") ;
904 cpl_free(spec_name) ;
905 return -1 ;
906 }
907 cpl_free(spec_name) ;
908
909 /* Get the Wavelength */
910 wave_name = cr2res_dfs_WAVELENGTH_colname(order, tracenb) ;
911 if ((pwave = cpl_table_get_data_double_const(in, wave_name)) == NULL) {
912 cpl_msg_error(__func__, "Cannot find the wavelength") ;
913 cpl_free(wave_name) ;
914 return -1 ;
915 }
916 cpl_free(wave_name) ;
917
918 /* Get the Spectrum Error */
919 err_name = cr2res_dfs_SPEC_ERR_colname(order, tracenb) ;
920 if ((perr = cpl_table_get_data_double_const(in, err_name)) == NULL) {
921 cpl_msg_error(__func__, "Cannot find the spectrum error") ;
922 cpl_free(err_name) ;
923 return -1 ;
924 }
925 cpl_free(err_name) ;
926
927 /* copy line by line */
928 for (i=0 ; i<in_size ; i++) {
929 if (out_start_idx + i <out_size) {
930 //if (!isnan(pwave[i]))
931 cpl_table_set_double(out, CR2RES_IDP_COL_WAVE,
932 out_start_idx + i, pwave[i]) ;
933 //if (!isnan(pspec[i]))
934 cpl_table_set_double(out, CR2RES_IDP_COL_FLUX,
935 out_start_idx + i, pspec[i]) ;
936 //if (!isnan(perr[i])){
937 /* FIXME: PIPE-11912 - Error propagation is not correct.
938 * Scale up the propagated errors (column name ERR) according to
939 * the following empirically derived equation:
940 * Error_propagated_corrected = ((a*Error_propagated)^2 + b^2)^0.5
941 * where a=2.12 and b=26.1.
942 * For the record, these factors were measured with uncertainties
943 * of 0.02 and 1.2, respectively.
944 * NEED TO ADD HIERARCH ESO SEQ NABCYCLES
945 */
946 if (error_method == CR2RES_EXTRACT_ERROR_POISSON && nab > 0 && perr[i] != 0.0) {
947 double err_corrected = sqrt(pow(2.08*perr[i],2) + nab*pow(25.2,2));
948 cpl_table_set_double(out, CR2RES_IDP_COL_ERR,
949 out_start_idx + i, err_corrected) ;
950 }
951 else{
952 cpl_table_set_double(out, CR2RES_IDP_COL_ERR,
953 out_start_idx + i, perr[i]) ;
954 }
955
956 if (i<5 || (i>=CR2RES_DETECTOR_SIZE-5)) edgepix = 2;
957 else edgepix=0;
958 cpl_table_set_int(out, CR2RES_IDP_COL_QUAL, out_start_idx + i,
959 edgepix + cr2res_wl_is_ghost(setting, pwave[i]));
960 cpl_table_set_int(out, CR2RES_IDP_COL_XPOS, out_start_idx + i,
961 i+1) ;
962 cpl_table_set_int(out, CR2RES_IDP_COL_DETEC, out_start_idx + i,
963 det_nr) ;
964 cpl_table_set_int(out, CR2RES_IDP_COL_ORDER, out_start_idx + i,
965 order) ;
966 cpl_table_set_int(out, CR2RES_IDP_COL_TRACE, out_start_idx + i,
967 tracenb) ;
968 }
969 }
970 return 0 ;
971}
972
973/*----------------------------------------------------------------------------*/
984/*----------------------------------------------------------------------------*/
985static int cr2res_idp_copy_pol(
986 cpl_table * out,
987 const cpl_table * in,
988 cpl_size out_start_idx,
989 int det_nr,
990 int order,
991 const char * setting)
992{
993 char * spec_name ;
994 char * wave_name ;
995 char * err_name ;
996 char * stokes_name ;
997 char * stokeserr_name ;
998 const double * pspec ;
999 const double * pwave ;
1000 const double * perr ;
1001 const double * pstokes ;
1002 const double * pstokeserr ;
1003 cpl_size in_size, out_size, i, edgepix ;
1004
1005 /* Check entries */
1006 if (out == NULL || in == NULL) return -1 ;
1007 in_size = cpl_table_get_nrow(in) ;
1008 out_size = cpl_table_get_nrow(out) ;
1009
1010 /* Get the Spectrum */
1011 spec_name = cr2res_dfs_POL_INTENS_colname(order) ;
1012 if ((pspec = cpl_table_get_data_double_const(in, spec_name)) == NULL) {
1013 cpl_msg_error(__func__, "Cannot find the intensity spec") ;
1014 cpl_free(spec_name) ;
1015 return -1 ;
1016 }
1017 cpl_free(spec_name) ;
1018
1019 /* Get the Wavelength */
1020 wave_name = cr2res_dfs_POL_WAVELENGTH_colname(order) ;
1021 if ((pwave = cpl_table_get_data_double_const(in, wave_name)) == NULL) {
1022 cpl_msg_error(__func__, "Cannot find the wavelength") ;
1023 cpl_free(wave_name) ;
1024 return -1 ;
1025 }
1026 cpl_free(wave_name) ;
1027
1028 /* Get the Spectrum Error */
1029 err_name = cr2res_dfs_POL_INTENS_ERROR_colname(order) ;
1030 if ((perr = cpl_table_get_data_double_const(in, err_name)) == NULL) {
1031 cpl_msg_error(__func__, "Cannot find the intensity error") ;
1032 cpl_free(err_name) ;
1033 return -1 ;
1034 }
1035 cpl_free(err_name) ;
1036
1037 /* Get the Stokes */
1038 stokes_name = cr2res_dfs_POL_STOKES_colname(order) ;
1039 if ((pstokes = cpl_table_get_data_double_const(in, stokes_name)) == NULL) {
1040 cpl_msg_error(__func__, "Cannot find the Stokes spectrum") ;
1041 cpl_free(stokes_name) ;
1042 return -1 ;
1043 }
1044 cpl_free(stokes_name) ;
1045
1046 /* Get the stokes err */
1047 stokeserr_name = cr2res_dfs_POL_STOKES_ERROR_colname(order) ;
1048 if ((pstokeserr = cpl_table_get_data_double_const(in, stokeserr_name)) == NULL) {
1049 cpl_msg_error(__func__, "Cannot find the Stokes error") ;
1050 cpl_free(stokeserr_name) ;
1051 return -1 ;
1052 }
1053 cpl_free(stokeserr_name) ;
1054
1055 /* copy line by line */
1056 for (i=0 ; i<in_size ; i++) {
1057 if (out_start_idx + i <out_size) {
1058 if (!isnan(pwave[i]))
1059 cpl_table_set_double(out, CR2RES_IDP_COL_WAVE,
1060 out_start_idx + i, pwave[i]) ;
1061 if (!isnan(pspec[i]))
1062 cpl_table_set_double(out, CR2RES_IDP_COL_FLUX,
1063 out_start_idx + i, pspec[i]) ;
1064 if (!isnan(perr[i]))
1065 cpl_table_set_double(out, CR2RES_IDP_COL_ERR,
1066 out_start_idx + i, perr[i]) ;
1067 if (!isnan(pstokes[i]))
1068 cpl_table_set_double(out, CR2RES_IDP_COL_STOKES,
1069 out_start_idx + i, pstokes[i]) ;
1070 if (!isnan(pstokeserr[i]))
1071 cpl_table_set_double(out, CR2RES_IDP_COL_STOKESERR,
1072 out_start_idx + i, pstokeserr[i]) ;
1073
1074 if (i<5 || (i>=CR2RES_DETECTOR_SIZE-5)) edgepix = 2;
1075 else edgepix=0;
1076 cpl_table_set_int(out, CR2RES_IDP_COL_QUAL, out_start_idx + i,
1077 edgepix + cr2res_wl_is_ghost(setting, pwave[i]));
1078 cpl_table_set_int(out, CR2RES_IDP_COL_XPOS, out_start_idx + i,
1079 i+1) ;
1080 cpl_table_set_int(out, CR2RES_IDP_COL_DETEC, out_start_idx + i,
1081 det_nr) ;
1082 cpl_table_set_int(out, CR2RES_IDP_COL_ORDER, out_start_idx + i,
1083 order) ;
1084 }
1085 }
1086 return 0 ;
1087}
1088
1089/*---------------------------------------------------------------------------*/
1096/*---------------------------------------------------------------------------*/
1097int cr2res_wl_is_ghost(const char * setting, double wl){
1098 cpl_vector * start;
1099 cpl_vector * end;
1100 cpl_bivector * ghosts;
1101 cpl_size nghosts;
1102 int i;
1103
1104 ghosts = cr2res_get_ghosts(setting);
1105 if (ghosts == NULL)
1106 return 0;
1107 start = cpl_bivector_get_x(ghosts);
1108 end = cpl_bivector_get_y(ghosts);
1109 nghosts = cpl_vector_get_size(start);
1110
1111 for (i=0; i<nghosts; i++){
1112 if ( wl > cpl_vector_get(start,i) && wl < cpl_vector_get(end,i)) {
1113 cpl_bivector_delete(ghosts);
1114 return 1;
1115 }
1116 }
1117 cpl_bivector_delete(ghosts);
1118 return 0;
1119}
1120/*---------------------------------------------------------------------------*/
1126/*---------------------------------------------------------------------------*/
1127cpl_bivector * cr2res_get_ghosts(const char * setting){
1128 cpl_vector * start;
1129 cpl_vector * end;
1130 int nghost;
1131
1132 if (!strcmp(setting,"Y1029")) {
1133 nghost = 9;
1134 start = cpl_vector_new(nghost);
1135 end = cpl_vector_new(nghost);
1136 cpl_vector_set(start, 0, 955.51); cpl_vector_set(end, 0, 956.59);
1137 cpl_vector_set(start, 1, 972.36); cpl_vector_set(end, 1, 973.46);
1138 cpl_vector_set(start, 2, 990.18); cpl_vector_set(end, 2, 990.81);
1139 cpl_vector_set(start, 3, 1008.18); cpl_vector_set(end, 3, 1008.82);
1140 cpl_vector_set(start, 4, 1026.81); cpl_vector_set(end, 4, 1027.47);
1141 cpl_vector_set(start, 5, 1046.15); cpl_vector_set(end, 5, 1046.90);
1142 cpl_vector_set(start, 6, 1066.29); cpl_vector_set(end, 6, 1067.05);
1143 cpl_vector_set(start, 7, 1087.15); cpl_vector_set(end, 7, 1087.93);
1144 cpl_vector_set(start, 8, 1108.83); cpl_vector_set(end, 8, 1109.63);
1145 } else if (!strcmp(setting,"Y1028")) {
1146 nghost = 9;
1147 start = cpl_vector_new(nghost);
1148 end = cpl_vector_new(nghost);
1149 cpl_vector_set(start, 0, 954.15); cpl_vector_set(end, 0, 955.20);
1150 cpl_vector_set(start, 1, 971.25); cpl_vector_set(end, 1, 971.87);
1151 cpl_vector_set(start, 2, 988.65); cpl_vector_set(end, 2, 989.23);
1152 cpl_vector_set(start, 3, 1006.61); cpl_vector_set(end, 3, 1007.24);
1153 cpl_vector_set(start, 4, 1025.23); cpl_vector_set(end, 4, 1025.90);
1154 cpl_vector_set(start, 5, 1044.60); cpl_vector_set(end, 5, 1045.25);
1155 cpl_vector_set(start, 6, 1064.67); cpl_vector_set(end, 6, 1065.33);
1156 cpl_vector_set(start, 7, 1085.46); cpl_vector_set(end, 7, 1086.18);
1157 cpl_vector_set(start, 8, 1107.18); cpl_vector_set(end, 8, 1107.91);
1158 } else if (!strcmp(setting,"J1226")) {
1159 nghost = 9;
1160 start = cpl_vector_new(nghost);
1161 end = cpl_vector_new(nghost);
1162 cpl_vector_set(start, 0, 1119.44); cpl_vector_set(end, 0, 1020.33);
1163 cpl_vector_set(start, 1, 1142.78); cpl_vector_set(end, 1, 1143.76);
1164 cpl_vector_set(start, 2, 1167.12); cpl_vector_set(end, 2, 1168.08);
1165 cpl_vector_set(start, 3, 1192.52); cpl_vector_set(end, 3, 1193.49);
1166 cpl_vector_set(start, 4, 1219.01); cpl_vector_set(end, 4, 1220.04);
1167 cpl_vector_set(start, 5, 1246.71); cpl_vector_set(end, 5, 1247.76);
1168 cpl_vector_set(start, 6, 1275.70); cpl_vector_set(end, 6, 1276.80);
1169 cpl_vector_set(start, 7, 1306.05); cpl_vector_set(end, 7, 1307.15);
1170 cpl_vector_set(start, 8, 1337.98); cpl_vector_set(end, 8, 1338.94);
1171 } else if (!strcmp(setting,"J1228")) {
1172 nghost = 9;
1173 start = cpl_vector_new(nghost);
1174 end = cpl_vector_new(nghost);
1175 cpl_vector_set(start, 0, 1121.21); cpl_vector_set(end, 0, 1122.12);
1176 cpl_vector_set(start, 1, 1144.57); cpl_vector_set(end, 1, 1145.53);
1177 cpl_vector_set(start, 2, 1168.98); cpl_vector_set(end, 2, 1169.91);
1178 cpl_vector_set(start, 3, 1194.37); cpl_vector_set(end, 3, 1195.38);
1179 cpl_vector_set(start, 4, 1220.92); cpl_vector_set(end, 4, 1221.95);
1180 cpl_vector_set(start, 5, 1248.68); cpl_vector_set(end, 5, 1249.72);
1181 cpl_vector_set(start, 6, 1277.71); cpl_vector_set(end, 6, 1278.83);
1182 cpl_vector_set(start, 7, 1308.12); cpl_vector_set(end, 7, 1309.17);
1183 cpl_vector_set(start, 8, 1339.95); cpl_vector_set(end, 8, 1341.03);
1184 } else if (!strcmp(setting,"J1232")) {
1185 nghost = 9;
1186 start = cpl_vector_new(nghost);
1187 end = cpl_vector_new(nghost);
1188 cpl_vector_set(start, 0, 1124.71); cpl_vector_set(end, 0, 1125.60);
1189 cpl_vector_set(start, 1, 1148.15); cpl_vector_set(end, 1, 1149.46);
1190 cpl_vector_set(start, 2, 1172.62); cpl_vector_set(end, 2, 1173.55);
1191 cpl_vector_set(start, 3, 1198.13); cpl_vector_set(end, 3, 1199.08);
1192 cpl_vector_set(start, 4, 1224.77); cpl_vector_set(end, 4, 1225.74);
1193 cpl_vector_set(start, 5, 1252.56); cpl_vector_set(end, 5, 1253.59);
1194 cpl_vector_set(start, 6, 1281.74); cpl_vector_set(end, 6, 1282.74);
1195 cpl_vector_set(start, 7, 1312.19); cpl_vector_set(end, 7, 1313.26);
1196 cpl_vector_set(start, 8, 1344.15); cpl_vector_set(end, 8, 1345.23);
1197 } else if (!strcmp(setting,"H1559")) {
1198 nghost = 2;
1199 start = cpl_vector_new(nghost);
1200 end = cpl_vector_new(nghost);
1201 cpl_vector_set(start, 0, 1682.63); cpl_vector_set(end, 0, 1682.97);
1202 cpl_vector_set(start, 1, 1735.50); cpl_vector_set(end, 1, 1737.42);
1203 } else if (!strcmp(setting,"H1567")) {
1204 nghost = 1;
1205 start = cpl_vector_new(nghost);
1206 end = cpl_vector_new(nghost);
1207 cpl_vector_set(start, 0, 1744.20); cpl_vector_set(end, 0, 1745.84);
1208 } else if (!strcmp(setting,"H1575")) {
1209 nghost = 1;
1210 start = cpl_vector_new(nghost);
1211 end = cpl_vector_new(nghost);
1212 cpl_vector_set(start, 0, 1753.20); cpl_vector_set(end, 0, 1754.28);
1213 } else {
1214 return NULL;
1215 }
1216
1217 return cpl_bivector_wrap_vectors(start,end);
1218}
char * cr2res_dfs_POL_colname_parse(const char *colname, int *order_idx)
Parse a column name ORDER_TYPE format.
Definition: cr2res_dfs.c:531
char * cr2res_dfs_POL_STOKES_ERROR_colname(int order_idx)
Get the POL_STOKES_ERROR column name for a given order.
Definition: cr2res_dfs.c:241
char * cr2res_dfs_SPEC_ERR_colname(int order_idx, int trace)
Get the ERR column name for a given order/trace.
Definition: cr2res_dfs.c:414
char * cr2res_dfs_POL_INTENS_ERROR_colname(int order_idx)
Get the POL_INTENS_ERROR column name for a given order.
Definition: cr2res_dfs.c:306
char * cr2res_dfs_WAVELENGTH_colname(int order_idx, int trace)
Get the WAVELENGTH column name for a given order/trace.
Definition: cr2res_dfs.c:396
char * cr2res_dfs_POL_STOKES_colname(int order_idx)
Get the POL_STOKES column name for a given order.
Definition: cr2res_dfs.c:225
char * cr2res_dfs_SPEC_colname_parse(const char *colname, int *order_idx, int *trace)
Parse a column name ORDER_TRACE_TYPE format.
Definition: cr2res_dfs.c:505
char * cr2res_dfs_POL_INTENS_colname(int order_idx)
Get the POL_INTENS column name for a given order.
Definition: cr2res_dfs.c:290
char * cr2res_dfs_SPEC_colname(int order_idx, int trace)
Get the SPEC column name for a given order/trace.
Definition: cr2res_dfs.c:378
char * cr2res_dfs_POL_WAVELENGTH_colname(int order_idx)
Get the POL_WAVELENGTH column name for a given order.
Definition: cr2res_dfs.c:209
int cr2res_idp_save(const char *filename, cpl_frameset *allframes, cpl_frameset *rawframes, const cpl_parameterlist *parlist, cpl_table **tables, cpl_propertylist *main_qc_plist, cpl_propertylist **ext_plist, const char *procatg, const char *recipe)
Save an IDP file.
Definition: cr2res_idp.c:84
int cr2res_idp_compute_mjd(cpl_frameset *fset, double *mjd_start, double *mjd_end)
Compute mjd start and end.
Definition: cr2res_idp.c:793
cpl_table * cr2res_idp_create_table(cpl_table **tables, const char *recipe, const char *setting, int error_method, int nab)
Convert EXTRACT_1D tables into IDP table.
Definition: cr2res_idp.c:583
const char * cr2res_pfits_get_progid(const cpl_propertylist *plist)
find out the PROG ID
Definition: cr2res_pfits.c:124
double cr2res_pfits_get_dit(const cpl_propertylist *plist)
find out the DIT value
Definition: cr2res_pfits.c:199
double cr2res_pfits_get_mjd_obs(const cpl_propertylist *plist)
find out the MJD-OBS value
Definition: cr2res_pfits.c:217
int cr2res_pfits_get_ndit(const cpl_propertylist *plist)
find out the NDIT value
Definition: cr2res_pfits.c:363
const char * cr2res_pfits_get_poltype(const cpl_propertylist *plist)
find out the POL TYPE value
Definition: cr2res_pfits.c:241
int cr2res_pfits_get_obs_id(const cpl_propertylist *plist)
find out the OBS ID value
Definition: cr2res_pfits.c:375