ERIS Pipeline Reference Manual 1.8.10
eris_nix_dfs.c
1/* $Id$
2 *
3 * This file is part of the ERIS/NIX Pipeline
4 * Copyright (C) 2017 European Southern Observatory
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 /*
22 * $Author$
23 * $Date$
24 * $Rev$
25 */
26
27#ifdef HAVE_CONFIG_H
28#include <config.h>
29#endif
30
31/*-----------------------------------------------------------------------------
32 Includes
33 -----------------------------------------------------------------------------*/
34
35#include <string.h>
36#include <libgen.h>
37#include <cpl.h>
38#include <hdrl.h>
39#include "eris_nix_dfs.h"
40#include "eris_nix_utils.h"
41#include "eris_pfits.h"
42/*----------------------------------------------------------------------------*/
46/*----------------------------------------------------------------------------*/
47
50/*----------------------------------------------------------------------------*/
56/*----------------------------------------------------------------------------*/
57cpl_error_code eris_nix_dfs_set_groups(cpl_frameset * set) {
58
59 if (cpl_error_get_code() != CPL_ERROR_NONE) return cpl_error_get_code();
60
61 cpl_frame * frame = NULL;
62 int i = 0;
63
64 /* Loop on frames */
65
66 cpl_frameset_iterator * fsiter = cpl_frameset_iterator_new(set);
67 frame = cpl_frameset_iterator_get(fsiter);
68 while (frame) {
69
70 const char * tag = cpl_frame_get_tag(frame);
71 int data_found = 0;
72
73 if (tag == NULL) {
74 cpl_msg_error(cpl_func, "Frame %d has no tag", i);
75 } else if (!strcmp(tag, ERIS_NIX_RAW_DARK_DO_CATG) ||
76 !strcmp(tag, ERIS_NIX_RAW_PERSISTENCE_IMG_DO_CATG) ||
77 !strcmp(tag, ERIS_NIX_RAW_PERSISTENCE_CUBE_DO_CATG) ||
78 !strcmp(tag, ERIS_NIX_RAW_FLAT_LAMP_ON_DO_CATG) ||
79 !strcmp(tag, ERIS_NIX_RAW_FLAT_LAMP_OFF_DO_CATG) ||
80 !strcmp(tag, ERIS_NIX_RAW_FLAT_SKY_DO_CATG) ||
81 !strcmp(tag, ERIS_NIX_RAW_FLAT_SKY_LSS_DO_CATG) ||
82 !strcmp(tag, ERIS_NIX_RAW_FLAT_TWILIGHT_DO_CATG) ||
83 !strcmp(tag, ERIS_NIX_RAW_PUPIL_LAMP_DO_CATG) ||
84 !strcmp(tag, ERIS_NIX_RAW_PUPIL_SKY_DO_CATG) ||
85 !strcmp(tag, ERIS_NIX_RAW_PUPIL_DARK_DO_CATG) ||
86 !strcmp(tag, ERIS_NIX_RAW_PUPIL_BKG_DO_CATG) ||
87 !strcmp(tag, ERIS_NIX_RAW_PUPIL_LAMP_OPEN_DO_CATG) ||
88 !strcmp(tag, ERIS_NIX_RAW_PUPIL_LAMP_MASK_DO_CATG) ||
89 !strcmp(tag, ERIS_NIX_RAW_PUPIL_SKY_OPEN_DO_CATG) ||
90 !strcmp(tag, ERIS_NIX_RAW_PUPIL_SKY_MASK_DO_CATG) ||
91 !strcmp(tag, ERIS_NIX_RAW_PUPIL_DARK_OPEN_DO_CATG) ||
92 !strcmp(tag, ERIS_NIX_RAW_PUPIL_DARK_MASK_DO_CATG) ||
93 !strcmp(tag, ERIS_NIX_RAW_OBJECT_APP_DO_CATG) ||
94 !strcmp(tag, ERIS_NIX_RAW_OBJECT_FPC_DO_CATG) ||
95 !strcmp(tag, ERIS_NIX_RAW_OBJECT_SAM_DO_CATG) ||
96 !strcmp(tag, ERIS_NIX_RAW_OBJECT_JITTER_DO_CATG) ||
97 !strcmp(tag, ERIS_NIX_RAW_SKY_FPC_DO_CATG) ||
98 !strcmp(tag, ERIS_NIX_RAW_SKY_APP_DO_CATG) ||
99 !strcmp(tag, ERIS_NIX_RAW_SKY_JITTER_DO_CATG) ||
100 !strcmp(tag, ERIS_NIX_RAW_STD_JITTER_DO_CATG) ||
101 !strcmp(tag, ERIS_NIX_RAW_OBJECT_LSS_JITTER_DO_CATG) ||
102 !strcmp(tag, ERIS_NIX_RAW_STD_APP_DO_CATG) ||
103 !strcmp(tag, ERIS_NIX_RAW_STD_FPC_DO_CATG) ||
104 !strcmp(tag, ERIS_NIX_RAW_STD_SAM_DO_CATG) ||
105 !strcmp(tag, ERIS_NIX_RAW_SKY_LSS_JITTER_DO_CATG) ||
106 !strcmp(tag, ERIS_NIX_RAW_STD_LSS_JITTER_DO_CATG)) {
107
108 cpl_frame_set_group(frame, CPL_FRAME_GROUP_RAW);
109 data_found = 1;
110
111 } else if (!strcmp(tag, ERIS_NIX_COEFFS_CUBE_PRO_CATG) ||
112 !strcmp(tag, ERIS_NIX_DET_LIN_INFO_PRO_CATG) ||
113 !strcmp(tag, ERIS_NIX_GAIN_PRO_CATG) ||
114 !strcmp(tag, ERIS_NIX_MASTER_BPM_LAMP_PRO_CATG) ||
115 !strcmp(tag, ERIS_NIX_MASTER_BPM_LSS_PRO_CATG) ||
116 !strcmp(tag, ERIS_NIX_MASTER_BPM_SKY_PRO_CATG) ||
117 !strcmp(tag, ERIS_NIX_MASTER_DARK_IMG_PRO_CATG) ||
118 !strcmp(tag, ERIS_NIX_MASTER_DARK_IFU_PRO_CATG) ||
119 !strcmp(tag, ERIS_NIX_MASTER_FLAT_LAMP_HIFREQ_PRO_CATG) ||
120 !strcmp(tag, ERIS_NIX_MASTER_FLAT_LAMP_LOFREQ_PRO_CATG) ||
121 !strcmp(tag, ERIS_NIX_MASTER_FLAT_LSS_HIFREQ_PRO_CATG) ||
122 !strcmp(tag, ERIS_NIX_MASTER_FLAT_LSS_LOFREQ_PRO_CATG) ||
123 !strcmp(tag, ERIS_NIX_MASTER_FLAT_SKY_LOFREQ_PRO_CATG) ||
124 !strcmp(tag, ERIS_NIX_MASTER_FLAT_SKY_HIFREQ_PRO_CATG) ||
125 !strcmp(tag, ERIS_NIX_MASTER_FLAT_TWILIGHT_LOFREQ_PRO_CATG)||
126 !strcmp(tag, ERIS_NIX_MASTER_STARTRACE_PRO_CATG)||
127 !strcmp(tag, ERIS_NIX_MASTER_WAVE_PRO_CATG)||
128 !strcmp(tag, ERIS_NIX_NL_BPM_PRO_CATG) ||
129 !strcmp(tag, ERIS_NIX_PHOT_DATA_PRO_CATG) ||
130 !strcmp(tag, ERIS_NIX_WCS_MATCHED_CATALOGUE_PRO_CATG) ||
131 !strcmp(tag, ERIS_NIX_WCS_REFINE_PRO_CATG) ||
132 !strcmp(tag, ERIS_NIX_REFERENCE_DARK_PRO_CATG)) {
133
134 cpl_frame_set_group(frame, CPL_FRAME_GROUP_CALIB);
135 data_found = 1;
136
137 } else if (!strcmp(tag, ERIS_NIX_CALIB_OBJECT_JITTER_PRO_CATG) ||
138 !strcmp(tag, ERIS_NIX_CAL_DET_OBJECT_JITTER_PRO_CATG) ||
139 !strcmp(tag, ERIS_NIX_CAL_DET_SKY_JITTER_PRO_CATG) ||
140 !strcmp(tag, ERIS_NIX_CAL_DET_STD_JITTER_PRO_CATG) ||
141 !strcmp(tag, ERIS_NIX_CAL_DET_OBJECT_LSS_JITTER_PRO_CATG) ||
142 !strcmp(tag, ERIS_NIX_CAL_DET_SKY_LSS_JITTER_PRO_CATG) ||
143 !strcmp(tag, ERIS_NIX_CAL_DET_STD_LSS_JITTER_PRO_CATG) ||
144 !strcmp(tag, ERIS_NIX_CAL_PHOT_CATALOGUE_PRO_CATG) ||
145 !strcmp(tag, ERIS_NIX_CAL_PHOT_MATCH_CATALOGUE_PRO_CATG) ||
146 !strcmp(tag, ERIS_NIX_CAL_PHOT_OBJECT_JITTER_PRO_CATG) ||
147 !strcmp(tag, ERIS_NIX_CAL_PHOT_REF_CATALOGUE_PRO_CATG) ||
148 !strcmp(tag, ERIS_NIX_CAL_PHOT_STD_JITTER_PRO_CATG) ||
149 !strcmp(tag, ERIS_NIX_CAL_WCS_CATALOGUE_PRO_CATG) ||
150 !strcmp(tag, ERIS_NIX_CAL_WCS_MATCH_CATALOGUE_PRO_CATG) ||
151 !strcmp(tag, ERIS_NIX_CAL_WCS_OBJECT_JITTER_PRO_CATG) ||
152 !strcmp(tag, ERIS_NIX_CAL_WCS_REF_CATALOGUE_PRO_CATG) ||
153 !strcmp(tag, ERIS_NIX_CAL_WCS_REPORT_PRO_CATG) ||
154 !strcmp(tag, ERIS_NIX_CAL_WCS_STD_JITTER_PRO_CATG) ||
155 !strcmp(tag, ERIS_NIX_CORRECTED_OBJECT_LSS_JITTER_PRO_CATG) ||
156 !strcmp(tag, ERIS_NIX_CORRECTED_STD_LSS_JITTER_PRO_CATG) ||
157 !strcmp(tag, ERIS_NIX_IMG_CATALOGUE_PRO_CATG) ||
158 !strcmp(tag, ERIS_NIX_IMG_OBS_COMBINED_PRO_CATG) ||
159 !strcmp(tag, ERIS_NIX_IMG_STD_COMBINED_PRO_CATG) ||
160 !strcmp(tag, ERIS_NIX_LSS_OBS_COMBINED_PRO_CATG) ||
161 !strcmp(tag, ERIS_NIX_LSS_STD_COMBINED_PRO_CATG) ||
162 !strcmp(tag, ERIS_NIX_SKYSUB_OBJECT_JITTER_PRO_CATG) ||
163 !strcmp(tag, ERIS_NIX_SKYSUB_STD_JITTER_PRO_CATG) ||
164 !strcmp(tag, ERIS_NIX_SKYSUB_OBJECT_LSS_JITTER_PRO_CATG) ||
165 !strcmp(tag, ERIS_NIX_SKYSUB_STD_LSS_JITTER_PRO_CATG)) {
166
167/*
168 cpl_frame_set_group(frame, CPL_FRAME_GROUP_PRODUCT);
169*/
170 cpl_frame_set_group(frame, CPL_FRAME_GROUP_RAW);
171 data_found = 1;
172 } else {
173 cpl_frame_set_group(frame, CPL_FRAME_GROUP_NONE);
174 data_found = 1;
175 }
176
177 if (!data_found) {
178 if(tag != NULL) {
179 cpl_error_set_message("eris_nix_dfs_set_groups",
180 CPL_ERROR_UNSUPPORTED_MODE,
181 "data tag not recognised: %s", tag);
182 }
183 break;
184 }
185
186 cpl_frameset_iterator_advance(fsiter, 1);
187 frame = cpl_frameset_iterator_get(fsiter);
188 i++;
189 }
190 enu_check_error_code("Could not identify RAW and CALIB frames");
191
192 cleanup:
193 cpl_frameset_iterator_delete(fsiter);
194
195 return cpl_error_get_code();
196}
197
198
199/*----------------------------------------------------------------------------*/
216/*----------------------------------------------------------------------------*/
217cpl_error_code enu_dfs_save_bpm(
218 const char * procat,
219 cpl_frameset * allframes,
220 const cpl_parameterlist * parlist,
221 const cpl_frameset * usedframes,
222 const master_bpm * mbad_pix_map,
223 const char * recipe,
224 const cpl_propertylist * applist,
225 const char * pipe_id,
226 const char * filename) {
227
228 if (cpl_error_get_code() != CPL_ERROR_NONE) return cpl_error_get_code();
229
230 cpl_propertylist * plist = NULL;
231
232 if (applist == NULL) {
233 plist = cpl_propertylist_new();
234 } else {
235 plist = cpl_propertylist_duplicate(applist);
236 }
237 cpl_propertylist_append_string(plist, CPL_DFS_PRO_CATG, procat);
238 cpl_dfs_save_image(allframes, NULL, parlist, usedframes, NULL,
239 mbad_pix_map->bpm, CPL_TYPE_INT, recipe, plist, NULL, pipe_id, filename);
240 cpl_ensure_code(!cpl_error_get_code(), cpl_error_get_code());
241
242 /* Cleanup */
243
244 cpl_propertylist_delete(plist);
245
246 return cpl_error_get_code();
247}
248
249
250/*----------------------------------------------------------------------------*/
271/*----------------------------------------------------------------------------*/
272
273cpl_error_code enu_dfs_save_catalogue(cpl_frameset * frameset,
274 cpl_frame * image,
275 const cpl_parameterlist * parlist,
276 const cpl_table * catalogue,
277 const cpl_propertylist * tablelist,
278 const char * cat_name,
279 const char * recipe,
280 const char * pipe_id,
281 const char * preface,
282 const char * procat) {
283
284 /* immediate return for some conditions */
285
286 if (cpl_error_get_code() != CPL_ERROR_NONE) return cpl_error_get_code();
287 if (!catalogue) return CPL_ERROR_NONE;
288
289 /* otherwise, check inputs */
290
291 cpl_ensure_code(image, CPL_ERROR_NULL_INPUT);
292 cpl_ensure_code(cat_name, CPL_ERROR_NULL_INPUT);
293 cpl_ensure_code(preface, CPL_ERROR_NULL_INPUT);
294
295 cpl_propertylist * applist = NULL;
296 cpl_propertylist * image_plist = NULL;
297 char * prodname = NULL;
298 cpl_frame * product_frame = NULL;
299 cpl_propertylist * tablelist_copy = NULL;
300
301 /* ..create a product frameset containing the input image of the
302 catalogue */
303
304 cpl_frameset * provenance = cpl_frameset_new();
305 cpl_frameset_insert(provenance, image);
306
307 /* ..create the product filename and frame */
308
309 prodname = enu_repreface(cpl_frame_get_filename(image), preface);
310 product_frame = cpl_frame_new();
311 cpl_frame_set_filename(product_frame, prodname);
312 cpl_frame_set_tag(product_frame, procat);
313 cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_ANY);
314 cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT);
315 cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL);
316
317 /* ..set up the phase3/IDP keywords for the primary header */
318
319 applist = cpl_propertylist_new();
320
321 /* ..copy some items from the image header */
322
323 image_plist = cpl_propertylist_load(cpl_frame_get_filename(image), 0);
324 cpl_propertylist_copy_property_regexp(applist,
325 image_plist,
326 "ORIGIN|TELESCOP|INSTRUME|FILTER|"
327 "OBJECT|RA|DEC|EQUINOX|RADESYS|"
328 "TIMESYS|EXPTIME|TEXPTIME|MJD-OBS|"
329 "MJD-END|PROG_ID|OBID[1-9]([0-9])*|"
330 "NCOMBINE|OBSTECH|PROCSOFT|"
331 "REFERENC",
332 CPL_FALSE);
333 enu_check_error_code("error copying image HDU info to applist");
334
335 /* ..add other standard keywords */
336
338 product_frame,
339 frameset,
340 parlist,
341 recipe,
342 pipe_id,
343 image,
344 provenance,
345 CPL_FALSE);
346
347 /* ..set new catg */
348
349 cpl_propertylist_update_string(applist, "PRODCATG", "SCIENCE.SRCTBL");
350 cpl_propertylist_update_string(applist, CPL_DFS_PRO_CATG, procat);
351
352 /* ..Point the PROV1 keyword to the associated image */
353
354 if (cpl_frame_get_filename(image)) {
355 char * filename = cpl_strdup(cpl_frame_get_filename(image));
356 cpl_propertylist_update_string(applist, "PROV1", basename(filename));
357 cpl_free(filename);
358 }
359
360 /* ..and set the plist for the table extension */
361
362 if (tablelist != NULL) {
363 tablelist_copy = cpl_propertylist_duplicate(tablelist);
364 } else {
365 tablelist_copy = cpl_propertylist_new();
366 }
367 cpl_propertylist_update_string(tablelist_copy, "EXTNAME", "PHASE3CATALOG");
368
369 /* OK, save the table */
370
371 cpl_table_save(catalogue,
372 applist,
373 tablelist_copy,
374 prodname,
375 CPL_IO_CREATE);
376
377 enu_check_error_code("error saving dfs table");
378
379 /* save the product frame to the overall frameset so that DFS knows a new
380 product has been created */
381
382 cpl_frameset_insert(frameset, cpl_frame_duplicate(product_frame));
383
384 cleanup:
385
386 cpl_propertylist_delete(applist);
387 cpl_propertylist_delete(image_plist);
388 cpl_free(prodname);
389 cpl_frame_delete(product_frame);
390 cpl_propertylist_delete(tablelist_copy);
391
392 return cpl_error_get_code();
393}
394
395
396/*----------------------------------------------------------------------------*/
420/*----------------------------------------------------------------------------*/
421cpl_error_code enu_dfs_save_himage(cpl_frameset * allframes,
422 const cpl_parameterlist * parlist,
423 const cpl_frameset * provenance,
424 const cpl_boolean prov_raw,
425 const hdrl_image * image,
426 const hdrl_imagelist * imagelist,
427 const mef_extension_list* mefs,
428 const char * recipe,
429 const cpl_frame * inherit_frame,
430 const cpl_propertylist * applist,
431 const cpl_propertylist * wcs_plist,
432 const char * pipe_id,
433 const char * filename) {
434
435 if (cpl_error_get_code() != CPL_ERROR_NONE) return cpl_error_get_code();
436
437 cpl_msg_debug(cpl_func, "enu_dfs_save_himage entry");
438
439 cpl_ensure_code(allframes, CPL_ERROR_NULL_INPUT);
440 cpl_ensure_code(parlist, CPL_ERROR_NULL_INPUT);
441 cpl_ensure_code(provenance, CPL_ERROR_NULL_INPUT);
442 cpl_ensure_code(recipe, CPL_ERROR_NULL_INPUT);
443 cpl_ensure_code(applist, CPL_ERROR_NULL_INPUT);
444 cpl_ensure_code(pipe_id, CPL_ERROR_NULL_INPUT);
445 cpl_ensure_code(filename, CPL_ERROR_NULL_INPUT);
446
447 const cpl_frame * inherit = NULL;
448 cpl_propertylist * inherit_plist = NULL;
449 cpl_frameset * product_frameset = NULL;
450 cpl_propertylist * plist = NULL;
451
452 int conf = CPL_FALSE;
453 int bkgd = CPL_FALSE;
454 int bkge = CPL_FALSE;
455 int bkgc = CPL_FALSE;
456
457 cpl_propertylist * dicd = NULL;
458
459 /* find what optional extensions are present */
460
461 if (mefs) {
462 for (cpl_size i=0; i<mefs->size; i++) {
463 cpl_msg_info(cpl_func, "%d", (int)i);
464 cpl_msg_info(cpl_func, "%s", mefs->mef[i]->name);
465 if (!strcmp(mefs->mef[i]->name, "CONFIDENCE")) conf = CPL_TRUE;
466 if (!strcmp(mefs->mef[i]->name, "BKG_DATA")) bkgd = CPL_TRUE;
467 if (!strcmp(mefs->mef[i]->name, "BKG_ERR")) bkge = CPL_TRUE;
468 if (!strcmp(mefs->mef[i]->name, "BKG_CONF")) bkgc = CPL_TRUE;
469 }
470 }
471
472 /* the code generally follows the procedure of cpl_dfs_product_save */
473
474 /* ..report what is happening */
475
476 const char * procat = cpl_propertylist_get_string(applist,
477 CPL_DFS_PRO_CATG);
478 cpl_ensure_code(procat != NULL, cpl_error_get_code());
479 cpl_msg_info(cpl_func, "Writing MEF product(%s): %s", procat, filename);
480
481 /* ..construct a frameset for the product */
482
483 product_frameset = cpl_frameset_duplicate(provenance);
484
485 /* ..if inherit_frame is NULL, use the first frame in the frameset */
486
487 if (inherit_frame) {
488 inherit = inherit_frame;
489 } else {
490 cpl_frameset_iterator * frameset_iter = cpl_frameset_iterator_new(
491 allframes);
492 inherit = cpl_frameset_iterator_get_const(frameset_iter);
493 cpl_frameset_iterator_delete(frameset_iter);
494 }
495
496 /* ..create product frame and insert it in the product frameset */
497
498 cpl_frame * product_frame = cpl_frame_new();
499 cpl_frame_set_filename(product_frame, filename);
500 cpl_frame_set_tag(product_frame, procat);
501 cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_ANY);
502 cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT);
503 cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL);
504
505 cpl_frameset_insert(product_frameset, product_frame);
506
507 /* ..construct the propertylist for the primary header... */
508
509 plist = cpl_propertylist_duplicate(applist);
511 product_frame,
512 product_frameset,
513 parlist,
514 recipe,
515 pipe_id,
516 inherit,
517 provenance,
518 prov_raw);
519
520 /* ..save the propertylist to HDU 0 */
521 cpl_propertylist_update_string(plist, "ESO PRO REC1 ID", recipe);
522
523 cpl_propertylist_save(plist, filename, CPL_IO_CREATE);
524 enu_check_error_code("error saving header 0");
525
526 /* Now for the extensions
527 ..construct a list of the DICD keywords common to all extensions */
528
529 dicd = cpl_propertylist_new();
530 cpl_propertylist_append_string(dicd, "HDUCLASS", "ESO");
531 cpl_propertylist_append_string(dicd, "HDUDOC", "SDP");
532 cpl_propertylist_append_string(dicd, "HDUVERS", "SDP version 8");
533 cpl_propertylist_append_string(dicd, "SCIDATA", "DATA");
534 cpl_propertylist_append_string(dicd, "ERRDATA", "ERR");
535 cpl_propertylist_append_string(dicd, "QUALDATA", "DQ");
536 if (conf) {
537 cpl_propertylist_append_string(dicd, "CONFDATA", "CONFIDENCE");
538 }
539 if (bkgd) {
540 cpl_propertylist_append_string(dicd, "BKGDATA", "BKG_DATA");
541 }
542 if (bkge) {
543 cpl_propertylist_append_string(dicd, "BKGERR", "BKG_ERR");
544 }
545 if (bkgc) {
546 cpl_propertylist_append_string(dicd, "BKGCONF", "BKG_CONF");
547 }
548 cpl_size hlist_sz = 0;
549 if (image || imagelist) {
550
551 /* ..save image data to HDU 1, copy wcs header info only */
552
553 cpl_propertylist * header = cpl_propertylist_duplicate(dicd);
554 cpl_propertylist_update_string(header, "EXTNAME", "DATA");
555 cpl_propertylist_update_string(header, "HDUCLAS1", "IMAGE");
556 cpl_propertylist_update_string(header, "HDUCLAS2", "DATA");
557 cpl_propertylist_erase(header, "SCIDATA");
558
559 if (wcs_plist) cpl_propertylist_append(header, wcs_plist);
560
561 /* ..copy mandatory keywords from the applist to the extension
562 header */
563
564 const char * data_mandatory[] = {"BUNIT",
565 "CUNIT1",
566 "CUNIT2",
567 "FLUXCAL"};
568 const int count_data_mandatory = sizeof(data_mandatory) /
569 sizeof(char *);
570
571 const char * data_mandatory2[] = {"PHOTSYS",
572 "ABMAGLIM",
573 "ABMAGSAT",
574 "PSF_FWHM",
575 "PHOTZP",
576 "PHOTZPER",
577 "ZPMETHOD"};
578 const int count_data_mandatory2 = sizeof(data_mandatory2) /
579 sizeof(char *);
580
581
582 const char * ins_mode = "ins_mode";
583 if(cpl_propertylist_has(plist,"ESO INS1 MODE")) {
584 ins_mode = cpl_propertylist_get_string(plist, "ESO INS1 MODE");
585 }
586 //cpl_msg_info(cpl_func,"ins_mode: %s",ins_mode);
587
588 for (int mandi=0; mandi < count_data_mandatory; mandi++) {
589 if (!cpl_propertylist_has(header, data_mandatory[mandi])) {
590 if (cpl_propertylist_has(applist, data_mandatory[mandi])) {
591 cpl_propertylist_copy_property(header, applist,
592 data_mandatory[mandi]);
593 }
594 }
595 }
596
597 if(strcmp(ins_mode,"nixLSS") != 0) {
598 //cpl_msg_info(cpl_func,"add mandatory 2");
599 for (int mandi2=0; mandi2 < count_data_mandatory2; mandi2++) {
600 if (!cpl_propertylist_has(header, data_mandatory2[mandi2])) {
601 if (cpl_propertylist_has(applist, data_mandatory2[mandi2])) {
602 cpl_propertylist_copy_property(header, applist,
603 data_mandatory2[mandi2]);
604 }
605 }
606 }
607 }
608
609 /* ..fill mandatory keywords that are still missing */
610 for (int mandi=0; mandi < count_data_mandatory; mandi++) {
611 if (!cpl_propertylist_has(header, data_mandatory[mandi])) {
612 if (!strcmp(data_mandatory[mandi], "BUNIT")) {
613 cpl_propertylist_update_string(header, "BUNIT",
614 "unknown");
615 } else if (!strcmp(data_mandatory[mandi], "CUNIT1")) {
616 cpl_propertylist_update_string(header, "CUNIT1", "deg");
617 } else if (!strcmp(data_mandatory[mandi], "CUNIT2")) {
618 cpl_propertylist_update_string(header, "CUNIT2", "deg");
619 } else if (!strcmp(data_mandatory[mandi], "FLUXCAL")) {
620 cpl_propertylist_update_string(header, "FLUXCAL",
621 "UNCALIBRATED");
622 } else {
623 cpl_msg_info(cpl_func,
624 "missing extension keyword %s not handled",
625 data_mandatory[mandi]);
626 }
627 }
628 }
629 /* if not nixLSS..fill mandatory keywords that are still missing */
630 if(strcmp(ins_mode,"nixLSS") != 0) {
631 //cpl_msg_info(cpl_func,"add2 mandatory 2");
632 for (int mandi2=0; mandi2 < count_data_mandatory2; mandi2++) {
633 if (!cpl_propertylist_has(header, data_mandatory2[mandi2])) {
634
635 if (!strcmp(data_mandatory2[mandi2], "PHOTSYS")) {
636 cpl_propertylist_update_string(header, "PHOTSYS", "VEGA");
637 } else if (!strcmp(data_mandatory2[mandi2], "ABMAGLIM")) {
638 cpl_msg_info(cpl_func, "dummy value for ABMAGLIM");
639 cpl_propertylist_update_double(header, "ABMAGLIM", 0.0);
640 } else if (!strcmp(data_mandatory2[mandi2], "ABMAGSAT")) {
641 cpl_msg_info(cpl_func, "dummy value for ABMAGSAT");
642 cpl_propertylist_update_double(header, "ABMAGSAT", 0.0);
643 } else if (!strcmp(data_mandatory2[mandi2], "PSF_FWHM")) {
644 cpl_msg_info(cpl_func, "dummy value for PSF_FWHM");
645 cpl_propertylist_update_double(header, "PSF_FWHM", -1.0);
646 } else if (!strcmp(data_mandatory2[mandi2], "PHOTZP")) {
647 cpl_msg_info(cpl_func, "PHOTZP not found, set to 0.0");
648 cpl_propertylist_update_double(header, "PHOTZP", 0.0);
649 cpl_propertylist_set_comment(header, "PHOTZP", "Photometric "
650 "zeropoint so that MAG=-2.5*"
651 "log(data)+PHOTZP+APCOR");
652 } else if (!strcmp(data_mandatory2[mandi2], "PHOTZPER")) {
653 cpl_msg_info(cpl_func, "PHOTZPER not found, set to 0.0");
654 cpl_propertylist_update_double(header, "PHOTZPER", 0.0);
655 cpl_propertylist_set_comment(header, "PHOTZPER", "Error on "
656 "PHOTZP");
657 } else if (!strcmp(data_mandatory2[mandi2], "ZPMETHOD")) {
658 cpl_msg_info(cpl_func, "ZPMETHOD not found");
659 cpl_propertylist_update_string(header, "ZPMETHOD",
660 "PHOTZP not calculated");
661 cpl_propertylist_set_comment(header, "ZPMETHOD",
662 "Method of ZP calculation");
663 } else {
664 cpl_msg_info(cpl_func,
665 "missing extension keyword %s not handled",
666 data_mandatory[mandi2]);
667 }
668 }
669 }
670 }
671
672 if (image) {
673 cpl_image_save(hdrl_image_get_image_const(image),
674 filename,
675 HDRL_TYPE_DATA,
676 header,
677 CPL_IO_EXTEND);
678 }
679 //exit(0);
680 if (imagelist) {
681
682 /* create a temporary cpl_imagelist of the image planes */
683
684 cpl_imagelist * tlist = cpl_imagelist_new();
685 hlist_sz = hdrl_imagelist_get_size(imagelist);
686 if(hlist_sz > 1) {
687 for (cpl_size i = 0; i < hlist_sz; i++) {
688 const hdrl_image * timage = hdrl_imagelist_get(imagelist, i);
689
690 //char* filename2 = cpl_sprintf("warp4_%s", filename);
691 //cpl_image_save(hdrl_image_get_image((hdrl_image *) timage),
692 // filename2, CPL_TYPE_UNSPECIFIED, NULL,
693 // CPL_IO_CREATE);
694 //cpl_free(filename2);
695
696 cpl_imagelist_set(tlist,
697 (cpl_image *) hdrl_image_get_image_const(timage), i);
698 }
699
700 cpl_imagelist_save(tlist,
701 filename,
702 CPL_TYPE_DOUBLE,
703 header,
704 CPL_IO_EXTEND);
705
706 cpl_imagelist_unwrap(tlist);
707 } else {
708 const hdrl_image * timage = hdrl_imagelist_get(imagelist, 0);
709 eris_ifu_plist_erase_wcs3D(header);
710 cpl_image_save(hdrl_image_get_image_const(timage),
711 filename,
712 HDRL_TYPE_DATA,
713 header,
714 CPL_IO_EXTEND);
715 }
716 }
717
718 cpl_propertylist_delete(header);
719 enu_check_error_code("failed to save header 1");
720
721 /* ..save image err to HDU 2 */
722
723 header = cpl_propertylist_duplicate(dicd);
724 cpl_propertylist_update_string(header, "EXTNAME", "ERR");
725 cpl_propertylist_update_string(header, "HDUCLAS1", "IMAGE");
726 cpl_propertylist_update_string(header, "HDUCLAS2", "ERROR");
727 cpl_propertylist_update_string(header, "HDUCLAS3", "RMSE");
728 cpl_propertylist_erase(header, "ERRDATA");
729 if (cpl_propertylist_has(applist, "BUNIT")) {
730 cpl_propertylist_copy_property(header, applist, "BUNIT");
731 }
732
733 if (wcs_plist) cpl_propertylist_append(header, wcs_plist);
734
735 if (image) {
736 cpl_image_save(hdrl_image_get_error_const(image), filename,
737 HDRL_TYPE_ERROR, header, CPL_IO_EXTEND);
738 }
739 if (imagelist) {
740 cpl_imagelist * tlist = cpl_imagelist_new();
741 hlist_sz = hdrl_imagelist_get_size(imagelist);
742 if(hlist_sz > 1) {
743 for (cpl_size i = 0; i < hlist_sz; i++) {
744 const hdrl_image * timage = hdrl_imagelist_get(imagelist, i);
745 cpl_imagelist_set(tlist,
746 (cpl_image *) hdrl_image_get_error_const(timage),
747 i);
748 }
749 cpl_imagelist_save(tlist,
750 filename,
751 CPL_TYPE_DOUBLE,
752 header,
753 CPL_IO_EXTEND);
754 cpl_imagelist_unwrap(tlist);
755 } else {
756 hdrl_image* timage = hdrl_imagelist_get(imagelist, 0);
757 eris_ifu_plist_erase_wcs3D(header);
758 cpl_image_save(hdrl_image_get_image_const(timage),
759 filename,
760 CPL_TYPE_DOUBLE,
761 header,
762 CPL_IO_EXTEND);
763 }
764 }
765
766 cpl_propertylist_delete(header);
767 enu_check_error_code("failed to save header 2");
768
769 /* ..save image mask to HDU 3 */
770
771 header = cpl_propertylist_duplicate(dicd);
772 cpl_propertylist_update_string(header, "EXTNAME", "DQ");
773 cpl_propertylist_update_string(header, "HDUCLAS1", "IMAGE");
774 cpl_propertylist_update_string(header, "HDUCLAS2", "QUALITY");
775 cpl_propertylist_update_string(header, "HDUCLAS3", "MASKZERO");
776 cpl_propertylist_erase(header, "QUALDATA");
777
778 if (wcs_plist) cpl_propertylist_append(header, wcs_plist);
779
780 /* get the mask 'non const' as in this case one is created if it
781 does not exist */
782
783 if (image) {
784 cpl_mask_save(hdrl_image_get_mask((hdrl_image *) image), filename,
785 header, CPL_IO_EXTEND);
786 }
787 if (imagelist) {
788 const hdrl_image * timage = hdrl_imagelist_get(imagelist, 0);
789 if(hlist_sz == 1) {
790 eris_ifu_plist_erase_wcs3D(header);
791 }
792 cpl_mask_save(hdrl_image_get_mask((hdrl_image *) timage), filename,
793 header, CPL_IO_EXTEND);
794 }
795
796 cpl_propertylist_delete(header);
797 enu_check_error_code("failed to save header 3");
798 }
799
800 /* save the optional extensions */
801
802 if (mefs) {
803 cpl_msg_info(cpl_func, "..there are %d mefs", (int) (mefs->size));
804
805 for (cpl_size i=0; i<mefs->size; i++) {
806 cpl_propertylist * header = NULL;
807 if (mefs->mef[i]->plist) {
808 header = cpl_propertylist_duplicate(mefs->mef[i]->plist);
809 } else {
810 header = cpl_propertylist_new();
811 }
812
813 /* keywords for ESO DICD conformance */
814
815 cpl_propertylist_copy_property_regexp(header, dicd, ".+",
816 CPL_FALSE);
817 cpl_propertylist_update_string(header, "EXTNAME",
818 mefs->mef[i]->name);
819
820 cpl_msg_info(cpl_func, "..saving mef %s", mefs->mef[i]->name);
821 if (!strcmp(mefs->mef[i]->name, "CONFIDENCE")) {
822 cpl_propertylist_update_string(header, "HDUCLAS1", "IMAGE");
823 cpl_propertylist_update_string(header, "HDUCLAS2", "CONF");
824 cpl_propertylist_erase(header, "CONFDATA");
825 } else if (!strcmp(mefs->mef[i]->name, "BKG_DATA")) {
826 cpl_propertylist_update_string(header, "HDUCLAS1", "IMAGE");
827 cpl_propertylist_update_string(header, "HDUCLAS2", "BKG_DATA");
828 cpl_propertylist_erase(header, "BKGDATA");
829 if (cpl_propertylist_has(applist, "BUNIT")) {
830 cpl_propertylist_copy_property(header, applist, "BUNIT");
831 }
832 } else if (!strcmp(mefs->mef[i]->name, "BKG_ERR")) {
833 cpl_propertylist_update_string(header, "HDUCLAS1", "IMAGE");
834 cpl_propertylist_update_string(header, "HDUCLAS2", "BKG_ERROR");
835 cpl_propertylist_update_string(header, "HDUCLAS3", "RMSE");
836 cpl_propertylist_erase(header, "BKGERR");
837 if (cpl_propertylist_has(applist, "BUNIT")) {
838 cpl_propertylist_copy_property(header, applist, "BUNIT");
839 }
840 } else if (!strcmp(mefs->mef[i]->name, "BKG_CONF")) {
841 cpl_propertylist_update_string(header, "HDUCLAS1", "IMAGE");
842 cpl_propertylist_update_string(header, "HDUCLAS2", "BKG_CONF");
843 cpl_propertylist_erase(header, "BKGCONF");
844 } else if (!strcmp(mefs->mef[i]->data_type,
845 MEF_EXTENSION_CONTAINING_IMAGE)) {
846 cpl_propertylist_update_string(header, "HDUCLAS1",
847 MEF_EXTENSION_CONTAINING_IMAGE);
848 } else if (!strcmp(mefs->mef[i]->data_type,
849 MEF_EXTENSION_CONTAINING_MASK)) {
850 cpl_propertylist_update_string(header, "HDUCLAS1",
851 MEF_EXTENSION_CONTAINING_MASK);
852 } else if (!strcmp(mefs->mef[i]->data_type,
853 MEF_EXTENSION_CONTAINING_TABLE)) {
854 cpl_propertylist_update_string(header, "HDUCLAS1",
855 MEF_EXTENSION_CONTAINING_TABLE);
856 }
857
858 /* copy wcs if present */
859
860 if (wcs_plist) cpl_propertylist_append(header, wcs_plist);
861
862 /* save the header */
863 if(hlist_sz == 1) {
864 eris_ifu_plist_erase_wcs3D(header);
865 }
866 enu_mef_extension_save(mefs->mef[i], filename, header,
867 CPL_IO_EXTEND);
868 cpl_propertylist_delete(header);
869 enu_check_error_code("failed to save MEF extension %d", (int) i);
870 }
871 }
872
873 /* save the new frame to the overall frameset so that DFS knows a new
874 product has been created */
875
876 cpl_frameset_insert(allframes, cpl_frame_duplicate(product_frame));
877
878 cleanup:
879
880 cpl_propertylist_delete(dicd);
881 cpl_propertylist_delete(inherit_plist);
882 cpl_propertylist_delete(plist);
883 cpl_frameset_delete(product_frameset);
884
885 return cpl_error_get_code();
886}
887
888
889/*----------------------------------------------------------------------------*/
905/*----------------------------------------------------------------------------*/
906
907cpl_error_code enu_dfs_save_limage(cpl_frameset * allframes,
908 const cpl_parameterlist * parlist,
909 const cpl_frameset * provenance,
910 const cpl_boolean prov_raw,
911 const located_image * limage,
912 const char * recipe,
913 const cpl_frame * inherit,
914 cpl_propertylist * applist,
915 const char * pipe_id,
916 const char * filename) {
917
918 if (cpl_error_get_code() != CPL_ERROR_NONE) return cpl_error_get_code();
919
920 cpl_msg_debug(cpl_func, "enu_dfs_save_limage entry");
921
922 cpl_ensure_code(filename, CPL_ERROR_NULL_INPUT);
923 cpl_ensure_code(limage, CPL_ERROR_NULL_INPUT);
924 cpl_ensure_code(applist, CPL_ERROR_NULL_INPUT);
925
926 cpl_propertylist * wcs_plist = NULL;
927
928 /* how many mefs? */
929
930 int nmefs = 0;
931 if (limage->confidence) nmefs++;
932 if (limage->bkg) nmefs = nmefs + 2;
933 if (limage->bkg_confidence) nmefs++;
934
935 mef_extension_list * mefs = NULL;
936 if (nmefs > 0) mefs = enu_mef_extension_list_new(nmefs);
937 cpl_msg_info(cpl_func, "nmefs %d", nmefs);
938
939 int imef = 0;
940 if (limage->confidence) {
941 cpl_msg_info(cpl_func, "CONF");
942 mefs->mef[imef] = enu_mef_new_image("CONFIDENCE",
943 limage->confidence, NULL);
944 imef++;
945 }
946 if (limage->bkg) {
947 cpl_msg_info(cpl_func, "BKG");
948 mefs->mef[imef] = enu_mef_new_image("BKG_DATA",
950 limage->bkg), NULL);
951 imef++;
952 cpl_msg_info(cpl_func, "BKG_ERR");
953 mefs->mef[imef] = enu_mef_new_image("BKG_ERR",
955 limage->bkg), NULL);
956 imef++;
957 }
958 if (limage->bkg_confidence) {
959 cpl_msg_info(cpl_func, "BKG_CONF");
960 mefs->mef[imef] = enu_mef_new_image("BKG_CONF",
961 limage->bkg_confidence, NULL);
962 imef++;
963 }
964
965 /* extract the wcs propertylist from the located image */
966
967 wcs_plist = cpl_propertylist_duplicate(limage->plist);
968 cpl_propertylist_erase_regexp(wcs_plist,
969 "CRPIX1|CRPIX2|CRPIX3|"
970 "CRVAL1|CRVAL2|CRVAL3|"
971 "CDELT1|CDELT2|CDELT3|"
972 "CD1_1|CD1_2|CD1_3|"
973 "CD2_1|CD2_2|CD2_3|"
974 "CD3_1|CD3_2|CD3_3|"
975 "CTYPE1|CTYPE2|CTYPE3|"
976 "CUNIT1|CUNIT2|CUNIT3",
977 CPL_TRUE);
978
979 /* copy other important keywords to applist unless an overriding value
980 is already there */
981
982 if (!cpl_propertylist_has(applist, "BUNIT")) {
983 cpl_propertylist_copy_property(applist, limage->plist, "BUNIT");
984 }
985 if (!cpl_propertylist_has(applist, "PSF_FWHM")) {
986 if(cpl_propertylist_has(limage->plist, "PSF_FWHM")) {
987 cpl_propertylist_copy_property(applist, limage->plist, "PSF_FWHM");
988 }
989 }
990 if (!cpl_propertylist_has(applist, "ABMAGLIM")) {
991 if (cpl_propertylist_has(limage->plist, "ABMAGLIM")) {
992 cpl_propertylist_copy_property(applist, limage->plist, "ABMAGLIM");
993 }
994 }
995
996 cpl_msg_info(cpl_func, ".. writing %s", filename);
997 enu_dfs_save_himage(allframes,
998 parlist,
999 provenance,
1000 prov_raw,
1001 limage->himage,
1002 limage->himagelist,
1003 mefs,
1004 recipe,
1005 inherit,
1006 applist,
1007 wcs_plist,
1008 pipe_id,
1009 filename);
1010
1012 cpl_propertylist_delete(wcs_plist);
1013
1014 return cpl_error_get_code();
1015}
1016
1017
1018/*----------------------------------------------------------------------------*/
1033/*----------------------------------------------------------------------------*/
1034
1035cpl_error_code enu_dfs_setup_product_header(cpl_propertylist * header,
1036 const cpl_frame * product_frame,
1037 const cpl_frameset * framelist,
1038 const cpl_parameterlist * parlist,
1039 const char * recipe_id,
1040 const char * pipe_id,
1041 const cpl_frame * inherit,
1042 const cpl_frameset * provenance,
1043 cpl_boolean prov_raw) {
1044
1045 if (cpl_error_get_code() != CPL_ERROR_NONE) return cpl_error_get_code();
1046
1047 cpl_ensure_code(header, CPL_ERROR_NULL_INPUT);
1048 cpl_ensure_code(product_frame, CPL_ERROR_NULL_INPUT);
1049 cpl_ensure_code(framelist, CPL_ERROR_NULL_INPUT);
1050 cpl_ensure_code(parlist, CPL_ERROR_NULL_INPUT);
1051 cpl_ensure_code(recipe_id, CPL_ERROR_NULL_INPUT);
1052 cpl_ensure_code(pipe_id, CPL_ERROR_NULL_INPUT);
1053 cpl_ensure_code(inherit, CPL_ERROR_NULL_INPUT);
1054 cpl_ensure_code(provenance, CPL_ERROR_NULL_INPUT);
1055
1056 cpl_propertylist * inherit_plist = NULL;
1057 cpl_propertylist * input_header = NULL;
1058
1059 /* ..add old-style DFS keywords to header but do not overwrite RA,DEC
1060 keywords if already present */
1061
1062 input_header = cpl_propertylist_duplicate(header);
1063 cpl_dfs_setup_product_header(header,
1064 product_frame,
1065 framelist,
1066 parlist,
1067 recipe_id,
1068 pipe_id,
1069 CPL_DFS_PRO_DID,
1070 inherit);
1071 cpl_propertylist_copy_property_regexp(header,
1072 input_header,
1073 "RA|DEC",
1074 CPL_FALSE);
1075 if (cpl_propertylist_has(header, "RA")) {
1076 cpl_propertylist_set_comment(header, "RA",
1077 "[deg] RA (J2000) pointing");
1078 }
1079 if (cpl_propertylist_has(header, "DEC")) {
1080 cpl_propertylist_set_comment(header, "DEC",
1081 "[deg] DEC (J2000) pointing");
1082 }
1083
1084 /* ..remove any obsolete DICD, data-specific, WCS or keywords that
1085 should just not be in the primary header */
1086
1087 cpl_propertylist_erase_regexp(header,
1088 "HDUCLASS|HDUDOC|HDUVERS|SCIDATA|ERRDATA|"
1089 "QUALDATA|CONFDATA|BKGDATA|BKGERR|BKGCONF|"
1090 "CRPIX1|CRPIX2|CRVAL1|CRVAL2|CDELT1|CDELT2|"
1091 "CTYPE1|CTYPE2|CUNIT1|CUNIT2|"
1092 "CD1_1|CD1_2|CD2_1|CD2_2|"
1093 "PHOTSYS|PHOTZP|PHOTZERR|ABMAGSAT|ABMAGLIM|"
1094 "MJD-OBS|PSF_FWHM|BUNIT",
1095 CPL_FALSE);
1096
1097 /* ..add the PROVIi keywords from the provenance frames */
1098
1099 int iprov = 0;
1100 cpl_frameset_iterator * it = cpl_frameset_iterator_new(provenance);
1101 const cpl_frame * frame = cpl_frameset_iterator_get_const(it);
1102 while (frame) {
1103 iprov++;
1104 /* get the name of the raw data file */
1105 char * filename = cpl_strdup(cpl_frame_get_filename(frame));
1106 char * pch = NULL;
1107 if (prov_raw) {
1108 /* want name of raw data file */
1109 pch = strstr(filename, "ERIS.20");
1110 if (!pch) {
1111 pch = filename;
1112 }
1113 } else {
1114 pch = filename;
1115 }
1116 char * pname = cpl_sprintf("PROV%.0i", iprov);
1117 cpl_propertylist_update_string(header, pname, basename(pch));
1118 cpl_free(filename);
1119 cpl_free(pname);
1120 cpl_frameset_iterator_advance(it, 1);
1121 frame = cpl_frameset_iterator_get(it);
1122 }
1123 cpl_frameset_iterator_delete(it); it = NULL;
1124 enu_check_error_code("error storing PROVenance keywords");
1125
1126 /* ..copy any missing mandatory keywords from the propertylist
1127 associated with inherit */
1128
1129 const char * inherit_fname = cpl_frame_get_filename(inherit);
1130 inherit_plist = cpl_propertylist_load(inherit_fname, 0);
1131 enu_check_error_code("error reading propertylist from inherit");
1132
1133 const char * mandatory[] = {"TELESCOP",
1134 "INSTRUME",
1135 "FILTER",
1136 "OBJECT",
1137 "RA",
1138 "DEC",
1139 "EQUINOX",
1140 "RADESYS",
1141 "TIMESYS",
1142 "EXPTIME",
1143 "TEXPTIME",
1144 "MJD-OBS",
1145 "MJD-END",
1146 "PROG_ID",
1147 "NCOMBINE",
1148 "FLUXCAL",
1149 "PROCSOFT",
1150 "REFERENC",
1151 "OBSTECH",
1152 "OBID1"};
1153
1154 const int count_mandatory = sizeof(mandatory) / sizeof(char *);
1155 for (int mandi=0; mandi < count_mandatory; mandi++) {
1156 if (!cpl_propertylist_has(header, mandatory[mandi])) {
1157 if (cpl_propertylist_has(inherit_plist, mandatory[mandi])) {
1158 cpl_msg_info(cpl_func, "copying from inherit %s",
1159 mandatory[mandi]);
1160 cpl_propertylist_copy_property(header, inherit_plist,
1161 mandatory[mandi]);
1162 }
1163 }
1164 }
1165
1166 /* ..try to fill mandatory keywords that are still missing */
1167
1168 for (int mandi=0; mandi < count_mandatory; mandi++) {
1169 if (!cpl_propertylist_has(header, mandatory[mandi])) {
1170 if (!strcmp(mandatory[mandi], "FILTER")) {
1171 const char * filter = NULL;
1172 if (inherit_plist) {
1173 filter = enu_get_filter(inherit_plist);
1174 }
1175 if (filter) {
1176 cpl_propertylist_update_string(header, "FILTER",
1177 filter);
1178 } else {
1179 cpl_propertylist_update_string(header, "FILTER",
1180 "unknown");
1181 }
1182 } else if (!strcmp(mandatory[mandi], "RADESYS")) {
1183 const char * radesys = NULL;
1184 if (inherit_plist && cpl_propertylist_has(inherit_plist,
1185 "RADECSYS")) {
1186 radesys = cpl_propertylist_get_string(inherit_plist,
1187 "RADECSYS");
1188 }
1189 if (radesys) {
1190 cpl_propertylist_update_string(header, "RADESYS",
1191 radesys);
1192 } else {
1193 cpl_propertylist_update_string(header, "RADESYS",
1194 "unknown");
1195 }
1196 } else if (!strcmp(mandatory[mandi], "TIMESYS")) {
1197 cpl_propertylist_update_string(header, "TIMESYS",
1198 "UTC");
1199 } else if (!strcmp(mandatory[mandi], "PROG_ID")) {
1200 const char * prog_id = NULL;
1201 if (inherit_plist && cpl_propertylist_has(inherit_plist,
1202 "ESO OBS PROG ID")) {
1203 prog_id = cpl_propertylist_get_string(inherit_plist,
1204 "ESO OBS PROG ID");
1205 }
1206 if (prog_id) {
1207 cpl_propertylist_update_string(header, "PROG_ID",
1208 prog_id);
1209 } else {
1210 cpl_propertylist_update_string(header, "PROG_ID",
1211 "unknown");
1212 }
1213 } else if (!strcmp(mandatory[mandi], "OBSTECH")) {
1214 const char * obstech = NULL;
1215 if (inherit_plist) {
1216 if (cpl_propertylist_has(inherit_plist, "ESO DPR TECH")) {
1217 obstech = cpl_propertylist_get_string(
1218 inherit_plist, "ESO DPR TECH");
1219 } else if (cpl_propertylist_has(inherit_plist, "ESO PRO TECH")) {
1220 obstech = cpl_propertylist_get_string(
1221 inherit_plist, "ESO PRO TECH");
1222 }
1223 }
1224 if (obstech) {
1225 cpl_propertylist_update_string(header, "OBSTECH",
1226 obstech);
1227 } else {
1228 cpl_propertylist_update_string(header, "OBSTECH",
1229 "unknown");
1230 }
1231 } else if (!strcmp(mandatory[mandi], "FLUXCAL")) {
1232 cpl_propertylist_update_string(header, "FLUXCAL",
1233 "UNCALIBRATED");
1234 } else if (!strcmp(mandatory[mandi], "PROCSOFT")) {
1235 cpl_propertylist_update_string(header, "PROCSOFT", pipe_id);
1236 } else if (!strcmp(mandatory[mandi], "REFERENC")) {
1237 cpl_propertylist_update_string(header, "REFERENC",
1238 " ");
1239 } else if (!strcmp(mandatory[mandi], "OBID1")) {
1240 int obid = -1;
1241 if (inherit_plist && cpl_propertylist_has(inherit_plist,
1242 "ESO OBS ID")) {
1243 obid = cpl_propertylist_get_int(inherit_plist, "ESO OBS ID");
1244 }
1245 cpl_propertylist_update_int(header, "OBID1", obid);
1246 } else {
1247 cpl_msg_warning(cpl_func, "missing %s", mandatory[mandi]);
1248 }
1249 }
1250 }
1251
1252 cleanup:
1253 cpl_propertylist_delete(inherit_plist);
1254 cpl_propertylist_delete(input_header);
1255
1256 return cpl_error_get_code();
1257}
1258
1259
1260
cpl_error_code enu_dfs_save_limage(cpl_frameset *allframes, const cpl_parameterlist *parlist, const cpl_frameset *provenance, const cpl_boolean prov_raw, const located_image *limage, const char *recipe, const cpl_frame *inherit, cpl_propertylist *applist, const char *pipe_id, const char *filename)
Save a located image structure to a MEF.
Definition: eris_nix_dfs.c:907
cpl_error_code eris_nix_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
Definition: eris_nix_dfs.c:57
cpl_error_code enu_dfs_save_bpm(const char *procat, cpl_frameset *allframes, const cpl_parameterlist *parlist, const cpl_frameset *usedframes, const master_bpm *mbad_pix_map, const char *recipe, const cpl_propertylist *applist, const char *pipe_id, const char *filename)
Save a master_bpm as a DFS-compliant pipeline product.
Definition: eris_nix_dfs.c:217
cpl_error_code enu_dfs_setup_product_header(cpl_propertylist *header, const cpl_frame *product_frame, const cpl_frameset *framelist, const cpl_parameterlist *parlist, const char *recipe_id, const char *pipe_id, const cpl_frame *inherit, const cpl_frameset *provenance, cpl_boolean prov_raw)
Add phase3/IDP keywords to a pipeline product propertyist list.
cpl_error_code enu_dfs_save_catalogue(cpl_frameset *frameset, cpl_frame *image, const cpl_parameterlist *parlist, const cpl_table *catalogue, const cpl_propertylist *tablelist, const char *cat_name, const char *recipe, const char *pipe_id, const char *preface, const char *procat)
Save a catalogue as DFS product.
Definition: eris_nix_dfs.c:273
cpl_error_code enu_dfs_save_himage(cpl_frameset *allframes, const cpl_parameterlist *parlist, const cpl_frameset *provenance, const cpl_boolean prov_raw, const hdrl_image *image, const hdrl_imagelist *imagelist, const mef_extension_list *mefs, const char *recipe, const cpl_frame *inherit_frame, const cpl_propertylist *applist, const cpl_propertylist *wcs_plist, const char *pipe_id, const char *filename)
Save an hdrl_image/imagelist as a DFS-compliant MEF pipeline product.
Definition: eris_nix_dfs.c:421
mef_extension * enu_mef_new_image(const char *name, const cpl_image *data, const cpl_propertylist *plist)
Create a mef_extension to hold a cpl_image.
mef_extension_list * enu_mef_extension_list_new(cpl_size size)
Construct a new mef_extension_list.
cpl_error_code enu_mef_extension_save(const mef_extension *mef, const char *filename, const cpl_propertylist *plist, unsigned mode)
Save a mef_extension struct to FITS file.
char * enu_repreface(const char *filename, const char *preface)
Preface a raw filename with a string.
void enu_mef_extension_list_delete(mef_extension_list *list)
Delete a mef_extension_list and its contents.
const char * enu_get_filter(const cpl_propertylist *plist)
Get the filter used in an observation.
cpl_mask * hdrl_image_get_mask(hdrl_image *himg)
get cpl bad pixel mask from image
Definition: hdrl_image.c:157
cpl_image * hdrl_image_get_error(hdrl_image *himg)
get error as cpl image
Definition: hdrl_image.c:131
const cpl_image * hdrl_image_get_error_const(const hdrl_image *himg)
get error as cpl image
Definition: hdrl_image.c:144
cpl_image * hdrl_image_get_image(hdrl_image *himg)
get data as cpl image
Definition: hdrl_image.c:105
const cpl_image * hdrl_image_get_image_const(const hdrl_image *himg)
get data as cpl image
Definition: hdrl_image.c:118
cpl_size hdrl_imagelist_get_size(const hdrl_imagelist *himlist)
Get the number of images in the imagelist.
hdrl_image * hdrl_imagelist_get(const hdrl_imagelist *himlist, cpl_size inum)
Get an image from a list of images.