37 #include <sys/types.h>
43 #include "irplib_utils.h"
44 #include "irplib_pfits.h"
50 static cpl_error_code irplib_dfs_check_frame_tag(
const cpl_frame *,
51 const cpl_propertylist *,
81 return irplib_pfits_get_string(
self,
"ESO DPR CATG");
93 return irplib_pfits_get_string(
self,
"ESO DPR TECH");
105 return irplib_pfits_get_string(
self,
"ESO DPR TYPE");
122 const char * key,
const char *
function,
123 const char * file,
unsigned line)
126 cpl_errorstate prestate = cpl_errorstate_get();
128 value = cpl_propertylist_get_bool(
self, key);
130 if (cpl_errorstate_is_equal(prestate)) {
131 cpl_msg_debug(
function,
"FITS card '%s' [bool]: %c", key,
135 (void)cpl_error_set_message_macro(
function, cpl_error_get_code(), file,
136 line,
"Missing FITS card "
137 " [bool]: '%s' ", key);
157 const char *
function,
162 cpl_errorstate prestate = cpl_errorstate_get();
164 value = cpl_propertylist_get_double(
self, key);
166 if (cpl_errorstate_is_equal(prestate)) {
167 cpl_msg_debug(
function,
"FITS card '%s' [double]: %g", key, value);
170 (void)cpl_error_set_message_macro(
function, cpl_error_get_code(), file,
171 line,
"Missing FITS card "
172 " [double]: '%s' ", key);
193 const char * key,
const char *
function,
194 const char * file,
unsigned line)
197 cpl_errorstate prestate = cpl_errorstate_get();
199 value = cpl_propertylist_get_int(
self, key);
201 if (cpl_errorstate_is_equal(prestate)) {
202 cpl_msg_debug(
function,
"FITS card '%s' [int]: %d", key, value);
205 (void)cpl_error_set_message_macro(
function, cpl_error_get_code(), file,
206 line,
"Missing FITS card "
207 " [int]: '%s' ", key);
228 const char *
function,
233 cpl_errorstate prestate = cpl_errorstate_get();
235 value = cpl_propertylist_get_string(
self, key);
237 if (cpl_errorstate_is_equal(prestate)) {
238 cpl_msg_debug(
function,
"FITS card '%s' [string]: %s", key, value);
241 (void)cpl_error_set_message_macro(
function, cpl_error_get_code(), file,
242 line,
"Missing FITS card "
243 " [string]: '%s' ", key);
261 const char* (*pfind)(
const char *,
268 if (cpl_error_get_code())
return cpl_error_get_code();
270 cpl_ensure_code(
self != NULL, CPL_ERROR_NULL_INPUT);
271 cpl_ensure_code(pfind != NULL, CPL_ERROR_NULL_INPUT);
275 const cpl_propertylist * plist
278 cpl_ensure_code(frame != NULL, cpl_error_get_code());
279 cpl_ensure_code(plist != NULL, cpl_error_get_code());
281 cpl_ensure_code(!irplib_dfs_check_frame_tag(frame, plist, pfind),
282 cpl_error_get_code());
285 return cpl_error_get_code();
310 if (cpl_error_get_code())
return -1;
312 cpl_ensure(words != NULL, CPL_ERROR_NULL_INPUT, -2);
313 cpl_ensure(format != NULL, CPL_ERROR_NULL_INPUT, -3);
316 error = regcomp(&re,
"^ *%s( +%s)* *$", REG_EXTENDED | REG_NOSUB);
319 cpl_ensure(!error, CPL_ERROR_ILLEGAL_INPUT, -4);
321 status = regexec(&re, format, (
size_t)0, NULL, 0);
326 cpl_msg_error(cpl_func,
"Regexp counter must consist of space-separated"
327 " %%s, not: %s", format);
328 cpl_ensure(0, CPL_ERROR_ILLEGAL_INPUT, -5);
331 va_start(ap, format);
334 for (; format != NULL; format = strchr(++format,
'%')) {
336 const char * regexp = va_arg(ap,
const char *);
338 if (regexp == NULL) {
340 cpl_ensure(0, CPL_ERROR_ILLEGAL_INPUT, -6);
343 error = regcomp(&re, regexp, REG_EXTENDED | REG_NOSUB);
347 cpl_ensure(0, CPL_ERROR_ILLEGAL_INPUT, -7);
350 status = regexec(&re, words, (
size_t)0, NULL, 0);
354 if (status != 0)
break;
360 return format == NULL ? 0 : 1;
374 const irplib_framelist * rawframes)
377 char * newcomment = NULL;
381 double astart0 = -1.0;
383 double airmass = 0.0;
384 cpl_errorstate prestate = cpl_errorstate_get();
387 skip_if(
self == NULL);
389 for (iframe = 0; iframe < nframes; iframe++) {
390 const cpl_propertylist * plist
392 double astart = DBL_MAX;
393 double aend = DBL_MAX;
396 if (!cpl_errorstate_is_equal(prestate)) {
397 irplib_error_recover(prestate,
"No propertylist found for frame %d:",
403 astart = irplib_pfits_get_double(plist,
"ESO TEL AIRM START");
404 if (cpl_errorstate_is_equal(prestate)) {
406 aend = irplib_pfits_get_double(plist,
"ESO TEL AIRM END");
409 aend = irplib_pfits_get_double(plist,
"ESO TEL AIRM END");
410 if (cpl_errorstate_is_equal(prestate)) {
411 if (iframe == nframes - 1) aend0 = aend;
412 astart = irplib_pfits_get_double(plist,
"ESO TEL AIRM START");
416 if (cpl_errorstate_is_equal(prestate)) {
417 airmi = 0.5 * (astart + aend);
419 const char * filename = cpl_frame_get_filename(
421 irplib_error_recover(prestate,
"Could not get FITS key from %s",
424 airmi = irplib_pfits_get_double(plist,
"AIRMASS");
426 if (!cpl_errorstate_is_equal(prestate)) {
427 irplib_error_recover(prestate,
"Could not get FITS key from %s",
439 if (nmass == 0 && astart0 > 0.0 && aend0 > 0.0) {
440 airmass = 0.5 * (astart0 + aend0);
444 const char * key =
"AIRMASS";
445 const char * comment = cpl_propertylist_get_comment(
self, key);
447 irplib_error_recover(prestate,
"Could not get FITS key:");
449 airmass /= (double)nmass;
451 bug_if(cpl_propertylist_update_double(
self, key, airmass));
453 if (comment == NULL) {
454 bug_if(cpl_propertylist_set_comment(
self, key,
"Averaged air mass "
457 newcomment = cpl_sprintf(
"%s (Recalculated)",
459 bug_if(cpl_propertylist_set_comment(
self, key, newcomment));
466 cpl_free(newcomment);
468 return cpl_error_get_code();
484 static cpl_error_code irplib_dfs_check_frame_tag(
const cpl_frame *
self,
485 const cpl_propertylist * plist,
498 cpl_errorstate prestate = cpl_errorstate_get();
501 cpl_ensure_code(
self != NULL, CPL_ERROR_NULL_INPUT);
503 file = cpl_frame_get_filename(
self);
505 cpl_ensure_code(file != NULL, cpl_error_get_code());
507 tag = cpl_frame_get_tag(
self);
509 cpl_ensure_code(tag != NULL, cpl_error_get_code());
515 if (!cpl_errorstate_is_equal(prestate)) {
516 if (cpl_msg_get_level() <= CPL_MSG_DEBUG) {
517 cpl_msg_warning(cpl_func,
"File %s has missing or incomplete DPR "
519 cpl_errorstate_dump(prestate, CPL_FALSE, NULL);
521 cpl_errorstate_set(prestate);
524 cpl_ensure_code(pfind != NULL, CPL_ERROR_NULL_INPUT);
526 docatg = (*pfind)(catg, type, tech);
528 if (docatg == NULL) {
529 if (cpl_msg_get_level() <= CPL_MSG_DEBUG)
530 cpl_msg_warning(cpl_func,
"File %s has tag %s but unknown DPR "
531 "triplet: (CATG;TYPE;TECH)=(%s;%s;%s)", file, tag,
533 }
else if (strcmp(tag, docatg) != 0) {
534 if (cpl_msg_get_level() <= CPL_MSG_DEBUG)
535 cpl_msg_warning(cpl_func,
"File %s has tag %s but DPR triplet of "
536 "%s: (CATG;TYPE;TECH)=(%s;%s;%s)", file, tag,
537 docatg, catg, type, tech);
541 return CPL_ERROR_NONE;
const char * irplib_pfits_get_dpr_catg(const cpl_propertylist *self)
The data category.
const char * irplib_pfits_get_string_macro(const cpl_propertylist *self, const char *key, const char *function, const char *file, unsigned line)
Get the value of a property of type string.
const char * irplib_pfits_get_dpr_type(const cpl_propertylist *self)
The data type.
cpl_boolean irplib_pfits_get_bool_macro(const cpl_propertylist *self, const char *key, const char *function, const char *file, unsigned line)
Get the value of a property of type boolean.
cpl_error_code irplib_pfits_set_airmass(cpl_propertylist *self, const irplib_framelist *rawframes)
Update/Set the AIRMASS property.
const char * irplib_pfits_get_dpr_tech(const cpl_propertylist *self)
The data technique.
const cpl_propertylist * irplib_framelist_get_propertylist_const(const irplib_framelist *self, int pos)
Get the propertylist of the specified frame in the framelist.
double irplib_pfits_get_double_macro(const cpl_propertylist *self, const char *key, const char *function, const char *file, unsigned line)
Get the value of a property of type double.
int irplib_pfits_get_int_macro(const cpl_propertylist *self, const char *key, const char *function, const char *file, unsigned line)
Get the value of a property of type int.
cpl_error_code irplib_dfs_check_framelist_tag(const irplib_framelist *self, const char *(*pfind)(const char *, const char *, const char *))
Check the tags in a frameset (group raw only)
const cpl_frame * irplib_framelist_get_const(const irplib_framelist *self, int pos)
Get the specified frame from the framelist.
int irplib_dfs_find_words(const char *words, const char *format,...)
Match a string with word(s) against a list of 1-word-regexps.
int irplib_framelist_get_size(const irplib_framelist *self)
Get the size of a framelist.