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