MOONS Pipeline Reference Manual 0.13.1
moo_pfits.c
1/*
2 * This file is part of the MOONS Pipeline
3 * Copyright (C) 2002-2016 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 Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20#ifdef HAVE_CONFIG_H
21#include <config.h>
22#endif
23
24/*-----------------------------------------------------------------------------
25 Includes
26 -----------------------------------------------------------------------------*/
27
28#include <cpl.h>
29#include <string.h>
30#include "moo_detector.h"
31#include "moo_utils.h"
32#include "moo_pfits.h"
33
34/*----------------------------------------------------------------------------*/
39/*----------------------------------------------------------------------------*/
40
43/*-----------------------------------------------------------------------------
44 Function codes
45 -----------------------------------------------------------------------------*/
46
47moo_outputs *
48moo_outputs_new(int nb)
49{
50 moo_outputs *res = cpl_calloc(1, sizeof(moo_outputs));
51 res->nb = nb;
52 res->outputs = cpl_calloc(nb, sizeof(moo_output));
53
54 return res;
55}
56
57void
58moo_outputs_delete(moo_outputs *res)
59{
60 if (res != NULL) {
61 cpl_free(res->outputs);
62 cpl_free(res);
63 }
64}
65
66moo_outputs *
67moo_outputs_load(cpl_propertylist *header, moo_detector_type type)
68{
69 moo_outputs *outputs = NULL;
70 cpl_ensure(header != NULL, CPL_ERROR_NULL_INPUT, NULL);
71
72 int nbout = 0;
73
74 moo_try_check(nbout = moo_pfits_get_det_outputs(header), " ");
75
76 cpl_errorstate prestate = cpl_errorstate_get();
77 moo_try_check(outputs = moo_outputs_new(nbout), " ");
78
79 outputs->minx = 1;
80 outputs->miny = 1;
81
82 for (int i = 1; i <= nbout; i++) {
83 float roni = NAN;
84 float gaini = NAN;
85 int nx, ny, x, y, prscx, prscy, ovscx, ovscy;
86 if (type == MOO_TYPE_RI) {
87 roni = moo_pfits_get_det_outi_ron(header, i);
88 gaini = moo_pfits_get_det_outi_gain(header, i);
89 nx = moo_pfits_get_det_outi_nx(header, i);
90 ny = moo_pfits_get_det_outi_ny(header, i);
91 x = moo_pfits_get_det_outi_x(header, i);
92 y = moo_pfits_get_det_outi_y(header, i);
93 prscx = moo_pfits_get_det_outi_prscx(header, i);
94 prscy = moo_pfits_get_det_outi_prscy(header, i);
95 ovscx = moo_pfits_get_det_outi_ovscx(header, i);
96 ovscy = moo_pfits_get_det_outi_ovscy(header, i);
97 }
98 else {
99 roni = moo_pfits_get_det_chip_ron(header);
100 gaini = 1 / moo_pfits_get_det_chip_outi_gain(header, i);
101 nx = moo_pfits_get_det_chip_outi_nx(header, i);
102 ny = moo_pfits_get_det_chip_outi_ny(header, i);
103 x = moo_pfits_get_det_chip_outi_x(header, i);
104 y = moo_pfits_get_det_chip_outi_y(header, i);
105 prscx = moo_pfits_get_det_chip_outi_prscx(header, i);
106 prscy = moo_pfits_get_det_chip_outi_prscy(header, i);
107 ovscx = moo_pfits_get_det_chip_outi_ovscx(header, i);
108 ovscy = moo_pfits_get_det_chip_outi_ovscy(header, i);
109 }
110
111 outputs->outputs[i - 1].nx = nx;
112 outputs->outputs[i - 1].ny = ny;
113 outputs->outputs[i - 1].x = x;
114 if (outputs->minx > x) {
115 outputs->minx = x;
116 }
117 if (outputs->miny > y) {
118 outputs->miny = y;
119 }
120
121 if (i == 1) {
122 if (x < nx) {
123 outputs->outputs[i - 1].dx = 1;
124 }
125 else {
126 outputs->outputs[i - 1].dx = x - (nx - 1);
127 }
128 outputs->outputs[i - 1].dy = 1;
129 }
130 else {
131 int oldx = outputs->outputs[i - 2].x;
132 int oldy = outputs->outputs[i - 2].y;
133 int onx = outputs->outputs[i - 2].nx;
134 int ony = outputs->outputs[i - 2].ny;
135
136 if (x == oldx) {
137 outputs->outputs[i - 1].dx = outputs->outputs[i - 2].dx;
138 }
139 else if (x > oldx) {
140 outputs->outputs[i - 1].dx = outputs->outputs[i - 2].dx + onx;
141 }
142 else {
143 outputs->outputs[i - 1].dx = outputs->outputs[i - 2].dx - onx;
144 }
145
146 if (y == oldy) {
147 outputs->outputs[i - 1].dy = outputs->outputs[i - 2].dy;
148 }
149 else if (y > oldy) {
150 outputs->outputs[i - 1].dy = outputs->outputs[i - 2].dy + ony;
151 }
152 else {
153 outputs->outputs[i - 1].dy = outputs->outputs[i - 2].dy - ony;
154 }
155 }
156
157 outputs->outputs[i - 1].y = y;
158 outputs->outputs[i - 1].ron = roni;
159 outputs->outputs[i - 1].gain = gaini;
160 outputs->outputs[i - 1].prscx = prscx;
161 outputs->outputs[i - 1].prscy = prscy;
162 outputs->outputs[i - 1].ovscx = ovscx;
163 outputs->outputs[i - 1].ovscy = ovscy;
164 }
165
166moo_try_cleanup:
167 if (!cpl_errorstate_is_equal(prestate)) {
168 moo_outputs_delete(outputs);
169 outputs = NULL;
170 }
171
172 return outputs;
173}
174
175cpl_error_code
176moo_outputs_get_det_size(moo_outputs *self, int *nx, int *ny)
177{
178 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
179 cpl_ensure_code(nx != NULL, CPL_ERROR_NULL_INPUT);
180 cpl_ensure_code(ny != NULL, CPL_ERROR_NULL_INPUT);
181
182 int nbout = self->nb;
183 int minx = self->minx;
184 int miny = self->miny;
185
186 int sx = 0;
187 int sy = 0;
188
189 for (int i = 0; i < nbout; i++) {
190 int x = self->outputs[i].x;
191 int y = self->outputs[i].y;
192
193 if (x == minx) {
194 sy += self->outputs[i].ny;
195 }
196 if (y == miny) {
197 sx += self->outputs[i].nx;
198 }
199 }
200
201 *nx = sx;
202 *ny = sy;
203
204 return CPL_ERROR_NONE;
205}
206/*----------------------------------------------------------------------------*/
216/*----------------------------------------------------------------------------*/
217cpl_image *
218moo_outputs_create_det(moo_outputs *self,
219 cpl_image *raw,
220 int nx,
221 int ny,
222 moo_detector_type dtype)
223{
224 cpl_image *result = NULL;
225
226 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
227 cpl_ensure(raw != NULL, CPL_ERROR_NULL_INPUT, NULL);
228
229 cpl_type type = cpl_image_get_type(raw);
230 int naxis1 = cpl_image_get_size_x(raw);
231 int naxis2 = cpl_image_get_size_y(raw);
232
233 result = cpl_image_new(nx, ny, type);
234
235 for (int i = 0; i < self->nb; i++) {
236 int rx = self->outputs[i].x;
237 int ry = self->outputs[i].y;
238 int prscx = self->outputs[i].prscx;
239 int prscy = self->outputs[i].prscy;
240 int rnx = self->outputs[i].nx;
241 int rny = self->outputs[i].ny;
242
243 if (((nx - rx) < rx) && (dtype == MOO_TYPE_RI)) {
244 rx = naxis1 - prscx - rnx + 1;
245 }
246 else {
247 rx = rx + prscx;
248 }
249
250 if (((ny - ry) < ry) && (dtype == MOO_TYPE_RI)) {
251 ry = naxis2 - prscy - rny + 1;
252 }
253 else {
254 ry = ry + prscy;
255 }
256
257 int x = self->outputs[i].dx;
258 int y = self->outputs[i].dy;
259 /*cpl_msg_info("test", "OUT%d extract[%d,%d-->%d,%d]", i, rx, ry,
260 rx + rnx - 1, ry + rny - 1);
261 */
262 cpl_image *extract =
263 cpl_image_extract(raw, rx, ry, rx + rnx - 1, ry + rny - 1);
264 /*cpl_msg_info("test", "OUT%d copy[%d,%d]", i, x, y);
265 */
266 cpl_image_copy(result, extract, x, y);
267 cpl_image_delete(extract);
268 }
269 return result;
270}
271/*----------------------------------------------------------------------------*/
277/*----------------------------------------------------------------------------*/
278const char *
279moo_pfits_get_arcfile(const cpl_propertylist *plist)
280{
281 const char *value = cpl_propertylist_get_string(plist, MOO_PFITS_ARCFILE);
282
283 cpl_ensure(value != NULL, cpl_error_get_code(), NULL);
284
285 return value;
286}
287/*----------------------------------------------------------------------------*/
293/*----------------------------------------------------------------------------*/
294const char *
295moo_pfits_get_date(const cpl_propertylist *plist)
296{
297 const char *value = cpl_propertylist_get_string(plist, MOO_PFITS_DATE);
298
299 cpl_ensure(value != NULL, cpl_error_get_code(), NULL);
300
301 return value;
302}
303/*----------------------------------------------------------------------------*/
309/*----------------------------------------------------------------------------*/
310const char *
311moo_pfits_get_dateobs(const cpl_propertylist *plist)
312{
313 const char *value = cpl_propertylist_get_string(plist, MOO_PFITS_DATEOBS);
314
315 cpl_ensure(value != NULL, cpl_error_get_code(), NULL);
316
317 return value;
318}
319
320/*----------------------------------------------------------------------------*/
326/*----------------------------------------------------------------------------*/
327double
328moo_pfits_get_mjdobs(const cpl_propertylist *plist)
329{
330 cpl_errorstate prestate = cpl_errorstate_get();
331 double value = cpl_propertylist_get_double(plist, MOO_PFITS_MJDOBS);
332 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
333
334 return value;
335}
336
337/*----------------------------------------------------------------------------*/
343/*----------------------------------------------------------------------------*/
344const char *
345moo_pfits_get_extname(const cpl_propertylist *plist)
346{
347 const char *value = cpl_propertylist_get_string(plist, MOO_PFITS_EXTNAME);
348
349 cpl_ensure(value != NULL, cpl_error_get_code(), NULL);
350
351 return value;
352}
353
354/*----------------------------------------------------------------------------*/
360/*----------------------------------------------------------------------------*/
361double
362moo_pfits_get_dit(const cpl_propertylist *plist)
363{
364 cpl_errorstate prestate = cpl_errorstate_get();
365 const double value = cpl_propertylist_get_double(plist, MOO_PFITS_DET_DIT);
366
367 /* Check for a change in the CPL error state */
368 /* - if it did change then propagate the error and return */
369 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
370
371 return value;
372}
373
374/*----------------------------------------------------------------------------*/
380/*----------------------------------------------------------------------------*/
381int
382moo_pfits_get_ndit(const cpl_propertylist *plist)
383{
384 cpl_errorstate prestate = cpl_errorstate_get();
385 const int value = cpl_propertylist_get_int(plist, MOO_PFITS_DET_NDIT);
386
387 /* Check for a change in the CPL error state */
388 /* - if it did change then propagate the error and return */
389 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0);
390
391 return value;
392}
393
394/*----------------------------------------------------------------------------*/
400/*----------------------------------------------------------------------------*/
401int
402moo_pfits_get_live(const cpl_propertylist *plist)
403{
404 cpl_errorstate prestate = cpl_errorstate_get();
405 const int value = cpl_propertylist_get_bool(plist, MOO_PFITS_DET_LIVE);
406
407 /* Check for a change in the CPL error state */
408 /* - if it did change then propagate the error and return */
409 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0);
410
411 return value;
412}
413
414/*----------------------------------------------------------------------------*/
420/*----------------------------------------------------------------------------*/
421int
422moo_pfits_get_det_outputs(const cpl_propertylist *plist)
423{
424 cpl_errorstate prestate = cpl_errorstate_get();
425 const int value = cpl_propertylist_get_int(plist, MOO_PFITS_DET_OUTPUTS);
426
427 /* Check for a change in the CPL error state */
428 /* - if it did change then propagate the error and return */
429 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0);
430
431 return value;
432}
433
434/*----------------------------------------------------------------------------*/
441/*----------------------------------------------------------------------------*/
442float
443moo_pfits_get_det_outi_ron(const cpl_propertylist *plist, int i)
444{
445 cpl_errorstate prestate = cpl_errorstate_get();
446 char *kw = cpl_sprintf(MOO_PFITS_DET_OUTI_RON, i);
447 const float value = cpl_propertylist_get_float(plist, kw);
448 cpl_free(kw);
449 /* Check for a change in the CPL error state */
450 /* - if it did change then propagate the error and return */
451 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
452
453 return value;
454}
455
456/*----------------------------------------------------------------------------*/
462/*----------------------------------------------------------------------------*/
463float
464moo_pfits_get_det_chip_ron(const cpl_propertylist *plist)
465{
466 cpl_errorstate prestate = cpl_errorstate_get();
467 const float value =
468 cpl_propertylist_get_float(plist, MOO_PFITS_DET_CHIP_RON);
469 /* Check for a change in the CPL error state */
470 /* - if it did change then propagate the error and return */
471 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
472
473 return value;
474}
475
476/*----------------------------------------------------------------------------*/
483/*----------------------------------------------------------------------------*/
484float
485moo_pfits_get_det_outi_gain(const cpl_propertylist *plist, int i)
486{
487 cpl_errorstate prestate = cpl_errorstate_get();
488 char *kw = cpl_sprintf(MOO_PFITS_DET_OUTI_GAIN, i);
489 const float value = cpl_propertylist_get_float(plist, kw);
490 cpl_free(kw);
491 /* Check for a change in the CPL error state */
492 /* - if it did change then propagate the error and return */
493 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
494
495 return value;
496}
497
498/*----------------------------------------------------------------------------*/
505/*----------------------------------------------------------------------------*/
506float
507moo_pfits_get_det_chip_outi_gain(const cpl_propertylist *plist, int i)
508{
509 cpl_errorstate prestate = cpl_errorstate_get();
510 char *kw = cpl_sprintf(MOO_PFITS_DET_CHIP_OUTI_GAIN, i);
511 const float value = cpl_propertylist_get_float(plist, kw);
512 cpl_free(kw);
513 /* Check for a change in the CPL error state */
514 /* - if it did change then propagate the error and return */
515 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
516
517 return value;
518}
519
520/*----------------------------------------------------------------------------*/
527/*----------------------------------------------------------------------------*/
528int
529moo_pfits_get_det_outi_nx(const cpl_propertylist *plist, int i)
530{
531 cpl_errorstate prestate = cpl_errorstate_get();
532 char *kw = cpl_sprintf(MOO_PFITS_DET_OUTI_NX, i);
533 const int value = cpl_propertylist_get_int(plist, kw);
534 cpl_free(kw);
535 /* Check for a change in the CPL error state */
536 /* - if it did change then propagate the error and return */
537 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0);
538
539 return value;
540}
541
542/*----------------------------------------------------------------------------*/
549/*----------------------------------------------------------------------------*/
550int
551moo_pfits_get_det_chip_outi_nx(const cpl_propertylist *plist, int i)
552{
553 cpl_errorstate prestate = cpl_errorstate_get();
554 char *kw = cpl_sprintf(MOO_PFITS_DET_CHIP_OUTI_NX, i);
555 const int value = cpl_propertylist_get_int(plist, kw);
556 cpl_free(kw);
557 /* Check for a change in the CPL error state */
558 /* - if it did change then propagate the error and return */
559 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0);
560
561 return value;
562}
563
564/*----------------------------------------------------------------------------*/
571/*----------------------------------------------------------------------------*/
572int
573moo_pfits_get_det_outi_ny(const cpl_propertylist *plist, int i)
574{
575 cpl_errorstate prestate = cpl_errorstate_get();
576 char *kw = cpl_sprintf(MOO_PFITS_DET_OUTI_NY, i);
577 const int value = cpl_propertylist_get_int(plist, kw);
578 cpl_free(kw);
579 /* Check for a change in the CPL error state */
580 /* - if it did change then propagate the error and return */
581 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0);
582
583 return value;
584}
585
586/*----------------------------------------------------------------------------*/
593/*----------------------------------------------------------------------------*/
594int
595moo_pfits_get_det_chip_outi_ny(const cpl_propertylist *plist, int i)
596{
597 cpl_errorstate prestate = cpl_errorstate_get();
598 char *kw = cpl_sprintf(MOO_PFITS_DET_CHIP_OUTI_NY, i);
599 const int value = cpl_propertylist_get_int(plist, kw);
600 cpl_free(kw);
601 /* Check for a change in the CPL error state */
602 /* - if it did change then propagate the error and return */
603 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0);
604
605 return value;
606}
607
608/*----------------------------------------------------------------------------*/
615/*----------------------------------------------------------------------------*/
616int
617moo_pfits_get_det_outi_x(const cpl_propertylist *plist, int i)
618{
619 cpl_errorstate prestate = cpl_errorstate_get();
620 char *kw = cpl_sprintf(MOO_PFITS_DET_OUTI_X, i);
621 const int value = cpl_propertylist_get_int(plist, kw);
622 cpl_free(kw);
623 /* Check for a change in the CPL error state */
624 /* - if it did change then propagate the error and return */
625 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0);
626
627 return value;
628}
629
630/*----------------------------------------------------------------------------*/
637/*----------------------------------------------------------------------------*/
638int
639moo_pfits_get_det_chip_outi_x(const cpl_propertylist *plist, int i)
640{
641 cpl_errorstate prestate = cpl_errorstate_get();
642 char *kw = cpl_sprintf(MOO_PFITS_DET_CHIP_OUTI_X, i);
643 const int value = cpl_propertylist_get_int(plist, kw);
644 cpl_free(kw);
645 /* Check for a change in the CPL error state */
646 /* - if it did change then propagate the error and return */
647 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0);
648
649 return value;
650}
651
652/*----------------------------------------------------------------------------*/
659/*----------------------------------------------------------------------------*/
660int
661moo_pfits_get_det_outi_y(const cpl_propertylist *plist, int i)
662{
663 cpl_errorstate prestate = cpl_errorstate_get();
664 char *kw = cpl_sprintf(MOO_PFITS_DET_OUTI_Y, i);
665 const int value = cpl_propertylist_get_int(plist, kw);
666 cpl_free(kw);
667 /* Check for a change in the CPL error state */
668 /* - if it did change then propagate the error and return */
669 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0);
670
671 return value;
672}
673
674/*----------------------------------------------------------------------------*/
681/*----------------------------------------------------------------------------*/
682int
683moo_pfits_get_det_chip_outi_y(const cpl_propertylist *plist, int i)
684{
685 cpl_errorstate prestate = cpl_errorstate_get();
686 char *kw = cpl_sprintf(MOO_PFITS_DET_CHIP_OUTI_Y, i);
687 const int value = cpl_propertylist_get_int(plist, kw);
688 cpl_free(kw);
689 /* Check for a change in the CPL error state */
690 /* - if it did change then propagate the error and return */
691 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0);
692
693 return value;
694}
695
696cpl_error_code
697moo_pfits_set_det_outi_x(cpl_propertylist *plist, int i, int v)
698{
699 char *kw = cpl_sprintf(MOO_PFITS_DET_OUTI_X, i);
700 cpl_error_code code = cpl_propertylist_set_int(plist, kw, v);
701 cpl_free(kw);
702
703 return code;
704}
705
706cpl_error_code
707moo_pfits_set_det_chip_outi_x(cpl_propertylist *plist, int i, int v)
708{
709 char *kw = cpl_sprintf(MOO_PFITS_DET_CHIP_OUTI_X, i);
710 cpl_error_code code = cpl_propertylist_set_int(plist, kw, v);
711 cpl_free(kw);
712
713 return code;
714}
715
716cpl_error_code
717moo_pfits_set_det_outi_y(cpl_propertylist *plist, int i, int v)
718{
719 char *kw = cpl_sprintf(MOO_PFITS_DET_OUTI_Y, i);
720 cpl_error_code code = cpl_propertylist_set_int(plist, kw, v);
721 cpl_free(kw);
722
723 return code;
724}
725
726cpl_error_code
727moo_pfits_set_det_chip_outi_y(cpl_propertylist *plist, int i, int v)
728{
729 char *kw = cpl_sprintf(MOO_PFITS_DET_CHIP_OUTI_Y, i);
730 cpl_error_code code = cpl_propertylist_set_int(plist, kw, v);
731 cpl_free(kw);
732
733 return code;
734}
735
736/*----------------------------------------------------------------------------*/
743/*----------------------------------------------------------------------------*/
744int
745moo_pfits_get_det_outi_prscx(const cpl_propertylist *plist, int i)
746{
747 cpl_errorstate prestate = cpl_errorstate_get();
748 char *kw = cpl_sprintf(MOO_PFITS_DET_OUTI_PRSCX, i);
749 const int value = cpl_propertylist_get_int(plist, kw);
750 cpl_free(kw);
751 /* Check for a change in the CPL error state */
752 /* - if it did change then propagate the error and return */
753 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0);
754
755 return value;
756}
757
758/*----------------------------------------------------------------------------*/
765/*----------------------------------------------------------------------------*/
766int
767moo_pfits_get_det_chip_outi_prscx(const cpl_propertylist *plist, int i)
768{
769 cpl_errorstate prestate = cpl_errorstate_get();
770 char *kw = cpl_sprintf(MOO_PFITS_DET_CHIP_OUTI_PRSCX, i);
771 const int value = cpl_propertylist_get_int(plist, kw);
772 cpl_free(kw);
773 /* Check for a change in the CPL error state */
774 /* - if it did change then propagate the error and return */
775 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0);
776
777 return value;
778}
779
780/*----------------------------------------------------------------------------*/
787/*----------------------------------------------------------------------------*/
788int
789moo_pfits_get_det_outi_prscy(const cpl_propertylist *plist, int i)
790{
791 cpl_errorstate prestate = cpl_errorstate_get();
792 char *kw = cpl_sprintf(MOO_PFITS_DET_OUTI_PRSCY, i);
793 const int value = cpl_propertylist_get_int(plist, kw);
794 cpl_free(kw);
795 /* Check for a change in the CPL error state */
796 /* - if it did change then propagate the error and return */
797 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0);
798
799 return value;
800}
801
802/*----------------------------------------------------------------------------*/
809/*----------------------------------------------------------------------------*/
810int
811moo_pfits_get_det_chip_outi_prscy(const cpl_propertylist *plist, int i)
812{
813 cpl_errorstate prestate = cpl_errorstate_get();
814 char *kw = cpl_sprintf(MOO_PFITS_DET_CHIP_OUTI_PRSCY, i);
815 const int value = cpl_propertylist_get_int(plist, kw);
816 cpl_free(kw);
817 /* Check for a change in the CPL error state */
818 /* - if it did change then propagate the error and return */
819 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0);
820
821 return value;
822}
823
824/*----------------------------------------------------------------------------*/
831/*----------------------------------------------------------------------------*/
832int
833moo_pfits_get_det_outi_ovscx(const cpl_propertylist *plist, int i)
834{
835 cpl_errorstate prestate = cpl_errorstate_get();
836 char *kw = cpl_sprintf(MOO_PFITS_DET_OUTI_OVSCX, i);
837 const int value = cpl_propertylist_get_int(plist, kw);
838 cpl_free(kw);
839 /* Check for a change in the CPL error state */
840 /* - if it did change then propagate the error and return */
841 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0);
842
843 return value;
844}
845
846/*----------------------------------------------------------------------------*/
853/*----------------------------------------------------------------------------*/
854int
855moo_pfits_get_det_chip_outi_ovscx(const cpl_propertylist *plist, int i)
856{
857 cpl_errorstate prestate = cpl_errorstate_get();
858 char *kw = cpl_sprintf(MOO_PFITS_DET_CHIP_OUTI_OVSCX, i);
859 const int value = cpl_propertylist_get_int(plist, kw);
860 cpl_free(kw);
861 /* Check for a change in the CPL error state */
862 /* - if it did change then propagate the error and return */
863 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0);
864
865 return value;
866}
867
868/*----------------------------------------------------------------------------*/
875/*----------------------------------------------------------------------------*/
876int
877moo_pfits_get_det_outi_ovscy(const cpl_propertylist *plist, int i)
878{
879 cpl_errorstate prestate = cpl_errorstate_get();
880 char *kw = cpl_sprintf(MOO_PFITS_DET_OUTI_OVSCY, i);
881 const int value = cpl_propertylist_get_int(plist, kw);
882 cpl_free(kw);
883 /* Check for a change in the CPL error state */
884 /* - if it did change then propagate the error and return */
885 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0);
886
887 return value;
888}
889
890/*----------------------------------------------------------------------------*/
897/*----------------------------------------------------------------------------*/
898int
899moo_pfits_get_det_chip_outi_ovscy(const cpl_propertylist *plist, int i)
900{
901 cpl_errorstate prestate = cpl_errorstate_get();
902 char *kw = cpl_sprintf(MOO_PFITS_DET_CHIP_OUTI_OVSCY, i);
903 const int value = cpl_propertylist_get_int(plist, kw);
904 cpl_free(kw);
905 /* Check for a change in the CPL error state */
906 /* - if it did change then propagate the error and return */
907 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0);
908
909 return value;
910}
911
912/*----------------------------------------------------------------------------*/
918/*----------------------------------------------------------------------------*/
919int
920moo_pfits_get_det_chip_nx(const cpl_propertylist *plist)
921{
922 cpl_errorstate prestate = cpl_errorstate_get();
923 const int value = cpl_propertylist_get_int(plist, MOO_PFITS_DET_CHIP_NX);
924
925 /* Check for a change in the CPL error state */
926 /* - if it did change then propagate the error and return */
927 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0);
928
929 return value;
930}
931
932/*----------------------------------------------------------------------------*/
938/*----------------------------------------------------------------------------*/
939int
940moo_pfits_get_det_chip_ny(const cpl_propertylist *plist)
941{
942 cpl_errorstate prestate = cpl_errorstate_get();
943 const int value = cpl_propertylist_get_int(plist, MOO_PFITS_DET_CHIP_NY);
944
945 /* Check for a change in the CPL error state */
946 /* - if it did change then propagate the error and return */
947 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0);
948
949 return value;
950}
951
952/*----------------------------------------------------------------------------*/
958/*----------------------------------------------------------------------------*/
959int
960moo_pfits_get_det_chip_live(const cpl_propertylist *plist)
961{
962 cpl_errorstate prestate = cpl_errorstate_get();
963 const int value = cpl_propertylist_get_bool(plist, MOO_PFITS_DET_CHIP_LIVE);
964
965 /* Check for a change in the CPL error state */
966 /* - if it did change then propagate the error and return */
967 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0);
968
969 return value;
970}
971
972/*----------------------------------------------------------------------------*/
978/*----------------------------------------------------------------------------*/
979int
980moo_pfits_get_naxis(const cpl_propertylist *plist)
981{
982 cpl_errorstate prestate = cpl_errorstate_get();
983 const int value = cpl_propertylist_get_int(plist, MOO_PFITS_NAXIS);
984
985 /* Check for a change in the CPL error state */
986 /* - if it did change then propagate the error and return */
987 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
988
989 return value;
990}
991
992/*----------------------------------------------------------------------------*/
998/*----------------------------------------------------------------------------*/
999int
1000moo_pfits_get_naxis1(const cpl_propertylist *plist)
1001{
1002 cpl_errorstate prestate = cpl_errorstate_get();
1003 const int value = cpl_propertylist_get_int(plist, MOO_PFITS_NAXIS1);
1004
1005 /* Check for a change in the CPL error state */
1006 /* - if it did change then propagate the error and return */
1007 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
1008
1009 return value;
1010}
1011
1012/*----------------------------------------------------------------------------*/
1018/*----------------------------------------------------------------------------*/
1019int
1020moo_pfits_get_naxis2(const cpl_propertylist *plist)
1021{
1022 cpl_errorstate prestate = cpl_errorstate_get();
1023 const int value = cpl_propertylist_get_int(plist, MOO_PFITS_NAXIS2);
1024
1025 /* Check for a change in the CPL error state */
1026 /* - if it did change then propagate the error and return */
1027 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
1028
1029 return value;
1030}
1031/*----------------------------------------------------------------------------*/
1037/*----------------------------------------------------------------------------*/
1038double
1039moo_pfits_get_exptime(const cpl_propertylist *plist)
1040{
1041 cpl_errorstate prestate = cpl_errorstate_get();
1042 const double value = cpl_propertylist_get_double(plist, MOO_PFITS_EXPTIME);
1043
1044 /* Check for a change in the CPL error state */
1045 /* - if it did change then propagate the error and return */
1046 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
1047
1048 return value;
1049}
1050
1051/*----------------------------------------------------------------------------*/
1058/*----------------------------------------------------------------------------*/
1059cpl_error_code
1060moo_pfits_update_exptime(cpl_propertylist *plist, double value)
1061{
1062 cpl_ensure_code(plist != NULL, CPL_ERROR_NULL_INPUT);
1063 cpl_propertylist_update_double(plist, MOO_PFITS_EXPTIME, value);
1064
1065 return CPL_ERROR_NONE;
1066}
1067
1068/*----------------------------------------------------------------------------*/
1075/*----------------------------------------------------------------------------*/
1076cpl_error_code
1077moo_pfits_update_ra(cpl_propertylist *plist, double value)
1078{
1079 cpl_ensure_code(plist != NULL, CPL_ERROR_NULL_INPUT);
1080 cpl_propertylist_update_double(plist, MOO_PFITS_RA, value);
1081
1082 return CPL_ERROR_NONE;
1083}
1084
1085/*----------------------------------------------------------------------------*/
1092/*----------------------------------------------------------------------------*/
1093cpl_error_code
1094moo_pfits_update_dec(cpl_propertylist *plist, double value)
1095{
1096 cpl_ensure_code(plist != NULL, CPL_ERROR_NULL_INPUT);
1097 cpl_propertylist_update_double(plist, MOO_PFITS_DEC, value);
1098
1099 return CPL_ERROR_NONE;
1100}
1101
1102/*----------------------------------------------------------------------------*/
1108/*----------------------------------------------------------------------------*/
1109int
1110moo_pfits_get_slit_offset(const cpl_propertylist *plist)
1111{
1112 cpl_errorstate prestate = cpl_errorstate_get();
1113 const int value =
1114 cpl_propertylist_get_int(plist, MOO_PFITS_INS_SLIT_OFFSET);
1115
1116 /* Check for a change in the CPL error state */
1117 /* - if it did change then propagate the error and return */
1118 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0);
1119
1120 return value;
1121}
1122
1123/*----------------------------------------------------------------------------*/
1129/*----------------------------------------------------------------------------*/
1130moo_mode_type
1131moo_pfits_get_mode(const cpl_propertylist *plist)
1132{
1133 moo_mode_type result = MOO_MODE_LR;
1134 cpl_errorstate prestate = cpl_errorstate_get();
1135 const char *value = cpl_propertylist_get_string(plist, MOO_PFITS_INS_MODE);
1136 /* Check for a change in the CPL error state */
1137 /* - if it did change then propagate the error and return */
1138 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(),
1139 MOO_MODE_LR);
1140
1141 if (strcmp(value, MOO_MODE_HR_NAME) == 0) {
1142 result = MOO_MODE_HR;
1143 }
1144
1145 return result;
1146}
1147
1148/*----------------------------------------------------------------------------*/
1154/*----------------------------------------------------------------------------*/
1155double
1156moo_pfits_get_crpix2(const cpl_propertylist *plist)
1157{
1158 cpl_errorstate prestate = cpl_errorstate_get();
1159 const double value = cpl_propertylist_get_double(plist, MOO_PFITS_CRPIX2);
1160
1161 /* Check for a change in the CPL error state */
1162 /* - if it did change then propagate the error and return */
1163 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
1164
1165 return value;
1166}
1167
1168/*----------------------------------------------------------------------------*/
1174/*----------------------------------------------------------------------------*/
1175double
1176moo_pfits_get_crval1(const cpl_propertylist *plist)
1177{
1178 cpl_errorstate prestate = cpl_errorstate_get();
1179 const double value = cpl_propertylist_get_double(plist, MOO_PFITS_CRVAL1);
1180
1181 /* Check for a change in the CPL error state */
1182 /* - if it did change then propagate the error and return */
1183 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
1184
1185 return value;
1186}
1187
1188/*----------------------------------------------------------------------------*/
1194/*----------------------------------------------------------------------------*/
1195double
1196moo_pfits_get_crpix1(const cpl_propertylist *plist)
1197{
1198 cpl_errorstate prestate = cpl_errorstate_get();
1199 const double value = cpl_propertylist_get_double(plist, MOO_PFITS_CRPIX1);
1200
1201 /* Check for a change in the CPL error state */
1202 /* - if it did change then propagate the error and return */
1203 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
1204
1205 return value;
1206}
1207
1208/*----------------------------------------------------------------------------*/
1214/*----------------------------------------------------------------------------*/
1215double
1216moo_pfits_get_cdelt2(const cpl_propertylist *plist)
1217{
1218 cpl_errorstate prestate = cpl_errorstate_get();
1219 const double value = cpl_propertylist_get_double(plist, MOO_PFITS_CDELT2);
1220
1221 /* Check for a change in the CPL error state */
1222 /* - if it did change then propagate the error and return */
1223 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
1224
1225 return value;
1226}
1227
1228/*----------------------------------------------------------------------------*/
1234/*----------------------------------------------------------------------------*/
1235double
1236moo_pfits_get_cdelt1(const cpl_propertylist *plist)
1237{
1238 cpl_errorstate prestate = cpl_errorstate_get();
1239 const double value = cpl_propertylist_get_double(plist, MOO_PFITS_CDELT1);
1240
1241 /* Check for a change in the CPL error state */
1242 /* - if it did change then propagate the error and return */
1243 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
1244
1245 return value;
1246}
1247
1248/*----------------------------------------------------------------------------*/
1254/*----------------------------------------------------------------------------*/
1255double
1256moo_pfits_get_cd1_1(const cpl_propertylist *plist)
1257{
1258 cpl_errorstate prestate = cpl_errorstate_get();
1259 const double value = cpl_propertylist_get_double(plist, MOO_PFITS_CD1_1);
1260
1261 /* Check for a change in the CPL error state */
1262 /* - if it did change then propagate the error and return */
1263 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
1264
1265 return value;
1266}
1267
1268/*----------------------------------------------------------------------------*/
1274/*----------------------------------------------------------------------------*/
1275double
1276moo_pfits_get_cd2_2(const cpl_propertylist *plist)
1277{
1278 cpl_errorstate prestate = cpl_errorstate_get();
1279 const double value = cpl_propertylist_get_double(plist, MOO_PFITS_CD2_2);
1280
1281 /* Check for a change in the CPL error state */
1282 /* - if it did change then propagate the error and return */
1283 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
1284
1285 return value;
1286}
1287/*----------------------------------------------------------------------------*/
1293/*----------------------------------------------------------------------------*/
1294double
1295moo_pfits_get_tel_airm_start(const cpl_propertylist *plist)
1296{
1297 cpl_errorstate prestate = cpl_errorstate_get();
1298 const double value =
1299 cpl_propertylist_get_double(plist, MOO_PFITS_TEL_AIRM_START);
1300 /* Check for a change in the CPL error state */
1301 /* - if it did change then propagate the error and return */
1302 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
1303
1304 return value;
1305}
1306
1307/*----------------------------------------------------------------------------*/
1313/*----------------------------------------------------------------------------*/
1314double
1315moo_pfits_get_tel_airm_end(const cpl_propertylist *plist)
1316{
1317 cpl_errorstate prestate = cpl_errorstate_get();
1318 const double value =
1319 cpl_propertylist_get_double(plist, MOO_PFITS_TEL_AIRM_END);
1320 /* Check for a change in the CPL error state */
1321 /* - if it did change then propagate the error and return */
1322 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
1323
1324 return value;
1325}
1326
1327/*----------------------------------------------------------------------------*/
1334/*----------------------------------------------------------------------------*/
1335cpl_error_code
1336moo_pfits_update_ncoadd(cpl_propertylist *plist, int v)
1337{
1338 cpl_error_code code =
1339 cpl_propertylist_update_int(plist, MOO_PFITS_PRO_NCOADD, v);
1340 return code;
1341}
1342
1343/*----------------------------------------------------------------------------*/
1349/*----------------------------------------------------------------------------*/
1350int
1351moo_pfits_get_pro_ncoadd(const cpl_propertylist *plist)
1352{
1353 cpl_errorstate prestate = cpl_errorstate_get();
1354
1355 const int value = cpl_propertylist_get_int(plist, MOO_PFITS_PRO_NCOADD);
1356 /* Check for a change in the CPL error state */
1357 /* - if it did change then propagate the error and return */
1358 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0);
1359
1360 return value;
1361}
1362/*----------------------------------------------------------------------------*/
1368/*----------------------------------------------------------------------------*/
1369const char *
1370moo_pfits_get_pro_wavesol_model(const cpl_propertylist *plist)
1371{
1372 cpl_errorstate prestate = cpl_errorstate_get();
1373 const char *value =
1374 cpl_propertylist_get_string(plist, MOO_PFITS_PRO_WAVESOL_MODEL);
1375 /* Check for a change in the CPL error state */
1376 /* - if it did change then propagate the error and return */
1377 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), NULL);
1378
1379 return value;
1380}
1381
1382/*----------------------------------------------------------------------------*/
1388/*----------------------------------------------------------------------------*/
1389const char *
1390moo_pfits_get_obs_start(const cpl_propertylist *plist)
1391{
1392 cpl_errorstate prestate = cpl_errorstate_get();
1393 const char *value = cpl_propertylist_get_string(plist, MOO_PFITS_OBS_START);
1394 /* Check for a change in the CPL error state */
1395 /* - if it did change then propagate the error and return */
1396 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), NULL);
1397
1398 return value;
1399}
1400
1401/*----------------------------------------------------------------------------*/
1407/*----------------------------------------------------------------------------*/
1408const char *
1409moo_pfits_get_pro_rec1_id(const cpl_propertylist *plist)
1410{
1411 cpl_errorstate prestate = cpl_errorstate_get();
1412 const char *value = "";
1413
1414 if (cpl_propertylist_has(plist, MOO_PFITS_PRO_REC1_ID)) {
1415 value = cpl_propertylist_get_string(plist, MOO_PFITS_PRO_REC1_ID);
1416 }
1417 /* Check for a change in the CPL error state */
1418 /* - if it did change then propagate the error and return */
1419 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0);
1420
1421 return value;
1422}
1423
1424/*----------------------------------------------------------------------------*/
1430/*----------------------------------------------------------------------------*/
1431const char *
1432moo_pfits_get_pro_wavesol_degx(const cpl_propertylist *plist)
1433{
1434 cpl_errorstate prestate = cpl_errorstate_get();
1435 const char *value =
1436 cpl_propertylist_get_string(plist, MOO_PFITS_PRO_WAVESOL_DEGX);
1437 /* Check for a change in the CPL error state */
1438 /* - if it did change then propagate the error and return */
1439 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0);
1440
1441 return value;
1442}
1443
1444/*----------------------------------------------------------------------------*/
1450/*----------------------------------------------------------------------------*/
1451int
1452moo_pfits_get_pro_wavesol_degy(const cpl_propertylist *plist)
1453{
1454 cpl_errorstate prestate = cpl_errorstate_get();
1455 int value = cpl_propertylist_get_int(plist, MOO_PFITS_PRO_WAVESOL_DEGY);
1456 /* Check for a change in the CPL error state */
1457 /* - if it did change then propagate the error and return */
1458 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0);
1459
1460 return value;
1461}
1462/*----------------------------------------------------------------------------*/
1468/*----------------------------------------------------------------------------*/
1469cpl_error_code
1470moo_pfits_append_hduclass(cpl_propertylist *plist)
1471{
1472 cpl_ensure_code(plist != NULL, CPL_ERROR_NULL_INPUT);
1473
1474 cpl_propertylist_append_string(plist, MOO_PFITS_HDUCLASS,
1475 MOO_PFITS_HDUCLASS_V);
1476 cpl_propertylist_set_comment(plist, MOO_PFITS_HDUCLASS,
1477 MOO_PFITS_HDUCLASS_C);
1478
1479 cpl_propertylist_append_string(plist, MOO_PFITS_HDUDOC, MOO_PFITS_HDUDOC_V);
1480 cpl_propertylist_set_comment(plist, MOO_PFITS_HDUDOC, MOO_PFITS_HDUDOC_C);
1481
1482 cpl_propertylist_append_string(plist, MOO_PFITS_HDUVERS,
1483 MOO_PFITS_HDUVERS_V);
1484 cpl_propertylist_set_comment(plist, MOO_PFITS_HDUVERS, MOO_PFITS_HDUVERS_C);
1485
1486 cpl_propertylist_append_string(plist, MOO_PFITS_HDUCLAS1,
1487 MOO_PFITS_HDUCLAS1_V);
1488 cpl_propertylist_set_comment(plist, MOO_PFITS_HDUCLAS1,
1489 MOO_PFITS_HDUCLAS1_C);
1490
1491 return CPL_ERROR_NONE;
1492}
1493
1494/*----------------------------------------------------------------------------*/
1502/*----------------------------------------------------------------------------*/
1503cpl_error_code
1504moo_pfits_append_hduclass_data(cpl_propertylist *plist,
1505 moo_detector_type type,
1506 int ntas)
1507{
1508 cpl_ensure_code(plist != NULL, CPL_ERROR_NULL_INPUT);
1509
1511
1512 cpl_propertylist_append_string(plist, MOO_PFITS_HDUCLAS2,
1513 MOO_PFITS_HDUCLAS2_DATA);
1514 cpl_propertylist_set_comment(plist, MOO_PFITS_HDUCLAS2,
1515 MOO_PFITS_HDUCLAS2_DATA_C);
1516 const char *err_extname = moo_detector_get_err_extname(type, ntas);
1517 cpl_propertylist_append_string(plist, MOO_PFITS_ERRDATA, err_extname);
1518 cpl_propertylist_set_comment(plist, MOO_PFITS_ERRDATA, MOO_PFITS_ERRDATA_C);
1519 const char *qual_extname = moo_detector_get_qual_extname(type, ntas);
1520 cpl_propertylist_append_string(plist, MOO_PFITS_QUALDATA, qual_extname);
1521 cpl_propertylist_set_comment(plist, MOO_PFITS_QUALDATA,
1522 MOO_PFITS_QUALDATA_C);
1523 return cpl_error_get_code();
1524}
1525
1526/*----------------------------------------------------------------------------*/
1535/*----------------------------------------------------------------------------*/
1536cpl_error_code
1537moo_pfits_append_hduclass_error(cpl_propertylist *plist,
1538 moo_detector_type type,
1539 int ntas,
1540 const cpl_propertylist *sci_header)
1541{
1542 cpl_ensure_code(plist != NULL, CPL_ERROR_NULL_INPUT);
1543
1545
1546 cpl_propertylist_append_string(plist, MOO_PFITS_HDUCLAS2,
1547 MOO_PFITS_HDUCLAS2_ERROR);
1548 cpl_propertylist_set_comment(plist, MOO_PFITS_HDUCLAS2,
1549 MOO_PFITS_HDUCLAS2_ERROR_C);
1550 cpl_propertylist_append_string(plist, MOO_PFITS_HDUCLAS3,
1551 MOO_PFITS_HDUCLAS3_ERROR_MSE);
1552 cpl_propertylist_set_comment(plist, MOO_PFITS_HDUCLAS3,
1553 MOO_PFITS_HDUCLAS3_ERROR_MSE_C);
1554
1555 const char *extname = moo_detector_get_extname(type, ntas);
1556 cpl_propertylist_append_string(plist, MOO_PFITS_SCIDATA, extname);
1557 cpl_propertylist_set_comment(plist, MOO_PFITS_SCIDATA, MOO_PFITS_SCIDATA_C);
1558
1559 const char *qual_extname = moo_detector_get_qual_extname(type, ntas);
1560 cpl_propertylist_append_string(plist, MOO_PFITS_QUALDATA, qual_extname);
1561 cpl_propertylist_set_comment(plist, MOO_PFITS_QUALDATA,
1562 MOO_PFITS_QUALDATA_C);
1563 cpl_propertylist_copy_property(plist, sci_header, MOO_PFITS_CRPIX1);
1564 cpl_propertylist_copy_property(plist, sci_header, MOO_PFITS_CRVAL1);
1565 cpl_propertylist_copy_property(plist, sci_header, MOO_PFITS_CTYPE1);
1566 cpl_propertylist_copy_property(plist, sci_header, MOO_PFITS_CD1_1);
1567 cpl_propertylist_copy_property(plist, sci_header, MOO_PFITS_CUNIT1);
1568
1569 cpl_propertylist_copy_property(plist, sci_header, MOO_PFITS_CRPIX2);
1570 cpl_propertylist_copy_property(plist, sci_header, MOO_PFITS_CRVAL2);
1571
1572 cpl_propertylist_copy_property(plist, sci_header, MOO_PFITS_CTYPE2);
1573 cpl_propertylist_copy_property(plist, sci_header, MOO_PFITS_CD2_2);
1574
1575 cpl_propertylist_copy_property(plist, sci_header, MOO_PFITS_BUNIT);
1576 return cpl_error_get_code();
1577}
1578
1579/*----------------------------------------------------------------------------*/
1589/*----------------------------------------------------------------------------*/
1590cpl_error_code
1592 moo_detector_type type,
1593 int ntas,
1594 const cpl_propertylist *sci_header,
1595 int mask)
1596{
1597 cpl_ensure_code(plist != NULL, CPL_ERROR_NULL_INPUT);
1598
1600
1601 cpl_propertylist_append_string(plist, MOO_PFITS_HDUCLAS2,
1602 MOO_PFITS_HDUCLAS2_QUALITY);
1603 cpl_propertylist_set_comment(plist, MOO_PFITS_HDUCLAS2,
1604 MOO_PFITS_HDUCLAS2_QUALITY_C);
1605 cpl_propertylist_append_string(plist, MOO_PFITS_HDUCLAS3,
1606 MOO_PFITS_HDUCLAS3_QUALITY_FLAG32);
1607 cpl_propertylist_set_comment(plist, MOO_PFITS_HDUCLAS3,
1608 MOO_PFITS_HDUCLAS3_QUALITY_FLAG32_C);
1609 const char *extname = moo_detector_get_extname(type, ntas);
1610 cpl_propertylist_append_string(plist, MOO_PFITS_SCIDATA, extname);
1611 cpl_propertylist_set_comment(plist, MOO_PFITS_SCIDATA, MOO_PFITS_SCIDATA_C);
1612 const char *err_extname = moo_detector_get_err_extname(type, ntas);
1613 cpl_propertylist_append_string(plist, MOO_PFITS_ERRDATA, err_extname);
1614 cpl_propertylist_set_comment(plist, MOO_PFITS_ERRDATA, MOO_PFITS_ERRDATA_C);
1615 cpl_propertylist_append_int(plist, MOO_PFITS_QUALMASK, mask);
1616 cpl_propertylist_set_comment(plist, MOO_PFITS_QUALMASK,
1617 MOO_PFITS_QUALMASK_C);
1618 cpl_propertylist_copy_property(plist, sci_header, MOO_PFITS_CRPIX1);
1619 cpl_propertylist_copy_property(plist, sci_header, MOO_PFITS_CRPIX2);
1620 cpl_propertylist_copy_property(plist, sci_header, MOO_PFITS_CRVAL1);
1621 cpl_propertylist_copy_property(plist, sci_header, MOO_PFITS_CRVAL2);
1622 cpl_propertylist_copy_property(plist, sci_header, MOO_PFITS_CTYPE1);
1623 cpl_propertylist_copy_property(plist, sci_header, MOO_PFITS_CUNIT1);
1624
1625 cpl_propertylist_copy_property(plist, sci_header, MOO_PFITS_CTYPE2);
1626 cpl_propertylist_copy_property(plist, sci_header, MOO_PFITS_CD1_1);
1627 cpl_propertylist_copy_property(plist, sci_header, MOO_PFITS_CD2_2);
1628
1629 return cpl_error_get_code();
1630}
1631/*----------------------------------------------------------------------------*/
1638/*----------------------------------------------------------------------------*/
1639cpl_error_code
1640moo_pfits_set_fluxcal(cpl_propertylist *plist, const char *val)
1641{
1642 const char *keyname = MOO_PFITS_FLUXCAL;
1643 const char *keycomment = MOO_PFITS_FLUXCAL_C;
1644 cpl_error_code status = CPL_ERROR_NONE;
1645 cpl_ensure_code(plist != NULL, CPL_ERROR_NULL_INPUT);
1646
1647 if (cpl_propertylist_has(plist, keyname)) {
1648 status = cpl_propertylist_set_string(plist, keyname, val);
1649 }
1650 else {
1651 cpl_propertylist_append_string(plist, keyname, val);
1652 cpl_propertylist_set_comment(plist, keyname, keycomment);
1653 }
1654 return status;
1655}
1656
1657/*----------------------------------------------------------------------------*/
1664/*----------------------------------------------------------------------------*/
1665cpl_error_code
1666moo_pfits_set_wlmin(cpl_propertylist *plist, double val)
1667{
1668 const char *keyname = MOO_PFITS_WAVELMIN;
1669 const char *keycomment = MOO_PFITS_WAVELMIN_C;
1670 cpl_error_code status = CPL_ERROR_NONE;
1671 cpl_ensure_code(plist != NULL, CPL_ERROR_NULL_INPUT);
1672
1673 if (cpl_propertylist_has(plist, keyname)) {
1674 status = cpl_propertylist_set_double(plist, keyname, val);
1675 }
1676 else {
1677 cpl_propertylist_append_double(plist, keyname, val);
1678 cpl_propertylist_set_comment(plist, keyname, keycomment);
1679 }
1680 return status;
1681}
1682
1683/*----------------------------------------------------------------------------*/
1690/*----------------------------------------------------------------------------*/
1691cpl_error_code
1692moo_pfits_set_wlmax(cpl_propertylist *plist, double val)
1693{
1694 const char *keyname = MOO_PFITS_WAVELMAX;
1695 const char *keycomment = MOO_PFITS_WAVELMAX_C;
1696 cpl_error_code status = CPL_ERROR_NONE;
1697 cpl_ensure_code(plist != NULL, CPL_ERROR_NULL_INPUT);
1698
1699 if (cpl_propertylist_has(plist, keyname)) {
1700 status = cpl_propertylist_set_double(plist, keyname, val);
1701 }
1702 else {
1703 cpl_propertylist_append_double(plist, keyname, val);
1704 cpl_propertylist_set_comment(plist, keyname, keycomment);
1705 }
1706 return status;
1707}
1708
1709/*----------------------------------------------------------------------------*/
1716/*----------------------------------------------------------------------------*/
1717cpl_error_code
1718moo_pfits_set_spec_bin(cpl_propertylist *plist, double val)
1719{
1720 const char *keyname = MOO_PFITS_SPECBIN;
1721 const char *keycomment = MOO_PFITS_SPECBIN_C;
1722 cpl_error_code status = CPL_ERROR_NONE;
1723 cpl_ensure_code(plist != NULL, CPL_ERROR_NULL_INPUT);
1724
1725 if (cpl_propertylist_has(plist, keyname)) {
1726 status = cpl_propertylist_set_double(plist, keyname, val);
1727 }
1728 else {
1729 cpl_propertylist_append_double(plist, keyname, val);
1730 cpl_propertylist_set_comment(plist, keyname, keycomment);
1731 }
1732 return status;
1733}
const char * moo_detector_get_err_extname(moo_detector_type type, int ntas)
Get the ERROR extension name of a detector.
Definition: moo_detector.c:66
const char * moo_detector_get_extname(moo_detector_type type, int ntas)
Get the extension name of a detector.
Definition: moo_detector.c:137
enum _moo_detector_type_ moo_detector_type
The type code type.
Definition: moo_detector.h:64
const char * moo_detector_get_qual_extname(moo_detector_type type, int ntas)
Get the QUAL extension name of a detector.
Definition: moo_detector.c:101
@ MOO_TYPE_RI
Definition: moo_detector.h:46
double moo_pfits_get_tel_airm_end(const cpl_propertylist *plist)
find out the TEL.AIRM.END value
Definition: moo_pfits.c:1315
int moo_pfits_get_pro_ncoadd(const cpl_propertylist *plist)
find out the PRO.NOCAODD value
Definition: moo_pfits.c:1351
int moo_pfits_get_det_chip_outi_ovscx(const cpl_propertylist *plist, int i)
find out the ESO DET CHIP OUTI OVSCX value
Definition: moo_pfits.c:855
int moo_pfits_get_det_outputs(const cpl_propertylist *plist)
find out the ESO DET OUTPUTS value
Definition: moo_pfits.c:422
double moo_pfits_get_cdelt1(const cpl_propertylist *plist)
find out the CDELT1 value
Definition: moo_pfits.c:1236
int moo_pfits_get_det_outi_prscy(const cpl_propertylist *plist, int i)
find out the ESO DET OUTI PRSCY value
Definition: moo_pfits.c:789
int moo_pfits_get_ndit(const cpl_propertylist *plist)
find out the ESO DET NDIT value
Definition: moo_pfits.c:382
int moo_pfits_get_det_chip_outi_y(const cpl_propertylist *plist, int i)
find out the ESO DET CHIP OUTI Y value
Definition: moo_pfits.c:683
double moo_pfits_get_cd1_1(const cpl_propertylist *plist)
find out the CD1_1 value
Definition: moo_pfits.c:1256
const char * moo_pfits_get_pro_wavesol_degx(const cpl_propertylist *plist)
find out the PRO.WAVESOL.DEGX value
Definition: moo_pfits.c:1432
int moo_pfits_get_det_outi_ovscx(const cpl_propertylist *plist, int i)
find out the ESO DET OUTI OVSCX value
Definition: moo_pfits.c:833
int moo_pfits_get_det_chip_outi_prscy(const cpl_propertylist *plist, int i)
find out the ESO DET CHIP OUTI PRSCY value
Definition: moo_pfits.c:811
int moo_pfits_get_det_outi_ny(const cpl_propertylist *plist, int i)
find out the ESO DET OUTI NY value
Definition: moo_pfits.c:573
const char * moo_pfits_get_pro_wavesol_model(const cpl_propertylist *plist)
find out the PRO.WAVESOL.MODEL value
Definition: moo_pfits.c:1370
cpl_error_code moo_pfits_append_hduclass_quality(cpl_propertylist *plist, moo_detector_type type, int ntas, const cpl_propertylist *sci_header, int mask)
Set the HDUCLASS QUALITY Keyword.
Definition: moo_pfits.c:1591
int moo_pfits_get_det_outi_ovscy(const cpl_propertylist *plist, int i)
find out the ESO DET OUTI OVSCY value
Definition: moo_pfits.c:877
int moo_pfits_get_det_chip_outi_ovscy(const cpl_propertylist *plist, int i)
find out the ESO DET OUTI CHIP OVSCY value
Definition: moo_pfits.c:899
int moo_pfits_get_det_chip_ny(const cpl_propertylist *plist)
find out the ESO DET CHIP NY value
Definition: moo_pfits.c:940
const char * moo_pfits_get_date(const cpl_propertylist *plist)
find out the date
Definition: moo_pfits.c:295
int moo_pfits_get_det_chip_outi_prscx(const cpl_propertylist *plist, int i)
find out the ESO DET CHIP OUTI PRSCX value
Definition: moo_pfits.c:767
int moo_pfits_get_pro_wavesol_degy(const cpl_propertylist *plist)
find out the PRO.WAVESOL.DEGY value
Definition: moo_pfits.c:1452
int moo_pfits_get_det_chip_live(const cpl_propertylist *plist)
find out the ESO DET CHIP LIVE value
Definition: moo_pfits.c:960
moo_mode_type moo_pfits_get_mode(const cpl_propertylist *plist)
find out the INS SLIT MODE value
Definition: moo_pfits.c:1131
int moo_pfits_get_det_chip_outi_nx(const cpl_propertylist *plist, int i)
find out the ESO DET OUTI CHIP NX value
Definition: moo_pfits.c:551
cpl_error_code moo_pfits_set_spec_bin(cpl_propertylist *plist, double val)
Set the SPEC_BIN Keyword.
Definition: moo_pfits.c:1718
float moo_pfits_get_det_chip_ron(const cpl_propertylist *plist)
find out the ESO DET CHIP RON value
Definition: moo_pfits.c:464
int moo_pfits_get_naxis1(const cpl_propertylist *plist)
find out the NAXIS1 value
Definition: moo_pfits.c:1000
double moo_pfits_get_tel_airm_start(const cpl_propertylist *plist)
find out the TEL.AIRM.START value
Definition: moo_pfits.c:1295
cpl_error_code moo_pfits_update_exptime(cpl_propertylist *plist, double value)
Set the EXPTIME value.
Definition: moo_pfits.c:1060
int moo_pfits_get_det_outi_prscx(const cpl_propertylist *plist, int i)
find out the ESO DET OUTI PRSCX value
Definition: moo_pfits.c:745
cpl_error_code moo_pfits_append_hduclass_error(cpl_propertylist *plist, moo_detector_type type, int ntas, const cpl_propertylist *sci_header)
Set the HDUCLASS ERROR Keyword.
Definition: moo_pfits.c:1537
const char * moo_pfits_get_pro_rec1_id(const cpl_propertylist *plist)
find out the PRO.REC1.ID value
Definition: moo_pfits.c:1409
cpl_error_code moo_pfits_set_wlmin(cpl_propertylist *plist, double val)
Set the WAVELMIN Keyword.
Definition: moo_pfits.c:1666
double moo_pfits_get_dit(const cpl_propertylist *plist)
find out the DIT value
Definition: moo_pfits.c:362
cpl_error_code moo_pfits_update_dec(cpl_propertylist *plist, double value)
Set the DEC value.
Definition: moo_pfits.c:1094
double moo_pfits_get_crpix2(const cpl_propertylist *plist)
find out the CRPIX2 value
Definition: moo_pfits.c:1156
cpl_error_code moo_pfits_append_hduclass_data(cpl_propertylist *plist, moo_detector_type type, int ntas)
Set the HDUCLASS DATA Keyword.
Definition: moo_pfits.c:1504
cpl_error_code moo_pfits_set_wlmax(cpl_propertylist *plist, double val)
Set the WAVELMAX Keyword.
Definition: moo_pfits.c:1692
float moo_pfits_get_det_chip_outi_gain(const cpl_propertylist *plist, int i)
find out the ESO DET OUTI CHIP GAIN value
Definition: moo_pfits.c:507
int moo_pfits_get_live(const cpl_propertylist *plist)
find out the ESO DET LIVE value
Definition: moo_pfits.c:402
double moo_pfits_get_mjdobs(const cpl_propertylist *plist)
find out the MJD-OBS
Definition: moo_pfits.c:328
int moo_pfits_get_slit_offset(const cpl_propertylist *plist)
find out the INS SLIT OFFSET value
Definition: moo_pfits.c:1110
double moo_pfits_get_crval1(const cpl_propertylist *plist)
find out the CRVAL1 value
Definition: moo_pfits.c:1176
const char * moo_pfits_get_dateobs(const cpl_propertylist *plist)
find out the DATE-OBS
Definition: moo_pfits.c:311
int moo_pfits_get_det_chip_nx(const cpl_propertylist *plist)
find out the ESO DET CHIP NX value
Definition: moo_pfits.c:920
const char * moo_pfits_get_extname(const cpl_propertylist *plist)
find out the EXTNAME
Definition: moo_pfits.c:345
int moo_pfits_get_det_chip_outi_x(const cpl_propertylist *plist, int i)
find out the ESO DET CHIP OUTI X value
Definition: moo_pfits.c:639
cpl_error_code moo_pfits_update_ra(cpl_propertylist *plist, double value)
Set the RA value.
Definition: moo_pfits.c:1077
float moo_pfits_get_det_outi_ron(const cpl_propertylist *plist, int i)
find out the ESO DET OUTI RON value
Definition: moo_pfits.c:443
int moo_pfits_get_naxis2(const cpl_propertylist *plist)
find out the NAXIS2 value
Definition: moo_pfits.c:1020
double moo_pfits_get_crpix1(const cpl_propertylist *plist)
find out the CRPIX1 value
Definition: moo_pfits.c:1196
cpl_image * moo_outputs_create_det(moo_outputs *self, cpl_image *raw, int nx, int ny, moo_detector_type dtype)
Create the DET data from RAW header and DATA.
Definition: moo_pfits.c:218
int moo_pfits_get_det_outi_nx(const cpl_propertylist *plist, int i)
find out the ESO DET OUTI NX value
Definition: moo_pfits.c:529
double moo_pfits_get_cdelt2(const cpl_propertylist *plist)
find out the CDELT2 value
Definition: moo_pfits.c:1216
int moo_pfits_get_det_outi_y(const cpl_propertylist *plist, int i)
find out the ESO DET OUTI Y value
Definition: moo_pfits.c:661
float moo_pfits_get_det_outi_gain(const cpl_propertylist *plist, int i)
find out the ESO DET OUTI GAIN value
Definition: moo_pfits.c:485
int moo_pfits_get_det_outi_x(const cpl_propertylist *plist, int i)
find out the ESO DET OUTI X value
Definition: moo_pfits.c:617
cpl_error_code moo_pfits_append_hduclass(cpl_propertylist *plist)
Set the HDUCLASS Keyword.
Definition: moo_pfits.c:1470
double moo_pfits_get_cd2_2(const cpl_propertylist *plist)
find out the CD2_2 value
Definition: moo_pfits.c:1276
cpl_error_code moo_pfits_update_ncoadd(cpl_propertylist *plist, int v)
set the ESO PRO NCOADD value
Definition: moo_pfits.c:1336
int moo_pfits_get_det_chip_outi_ny(const cpl_propertylist *plist, int i)
find out the ESO DET CHIP OUTI NY value
Definition: moo_pfits.c:595
const char * moo_pfits_get_obs_start(const cpl_propertylist *plist)
find out the PRO.WAVESOL.MODEL value
Definition: moo_pfits.c:1390
cpl_error_code moo_pfits_set_fluxcal(cpl_propertylist *plist, const char *val)
Set the FLUXCAL Keyword.
Definition: moo_pfits.c:1640
const char * moo_pfits_get_arcfile(const cpl_propertylist *plist)
find out the arcfile
Definition: moo_pfits.c:279
double moo_pfits_get_exptime(const cpl_propertylist *plist)
find out the EXPTIME value
Definition: moo_pfits.c:1039
int moo_pfits_get_naxis(const cpl_propertylist *plist)
find out the NAXIS value
Definition: moo_pfits.c:980