36 #include "irplib_utils.h"
37 #include "irplib_pfits.h"
43 #include <sys/types.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 *
function,
127 cpl_errorstate prestate = cpl_errorstate_get();
129 value = cpl_propertylist_get_double(
self, key);
131 if (cpl_errorstate_is_equal(prestate)) {
132 cpl_msg_debug(
function,
"FITS card '%s' [double]: %g", key, value);
135 (void)cpl_error_set_message_macro(
function, cpl_error_get_code(), file,
136 line,
"Missing FITS card "
137 " [double]: '%s' ", key);
158 const char * key,
const char *
function,
159 const char * file,
unsigned line)
162 cpl_errorstate prestate = cpl_errorstate_get();
164 value = cpl_propertylist_get_int(
self, key);
166 if (cpl_errorstate_is_equal(prestate)) {
167 cpl_msg_debug(
function,
"FITS card '%s' [int]: %d", key, value);
170 (void)cpl_error_set_message_macro(
function, cpl_error_get_code(), file,
171 line,
"Missing FITS card "
172 " [int]: '%s' ", key);
193 const char *
function,
198 cpl_errorstate prestate = cpl_errorstate_get();
200 value = cpl_propertylist_get_string(
self, key);
202 if (cpl_errorstate_is_equal(prestate)) {
203 cpl_msg_debug(
function,
"FITS card '%s' [string]: %s", key, value);
206 (void)cpl_error_set_message_macro(
function, cpl_error_get_code(), file,
207 line,
"Missing FITS card "
208 " [string]: '%s' ", key);
226 const char* (*pfind)(
const char *,
233 if (cpl_error_get_code())
return cpl_error_get_code();
235 cpl_ensure_code(
self != NULL, CPL_ERROR_NULL_INPUT);
236 cpl_ensure_code(pfind != NULL, CPL_ERROR_NULL_INPUT);
240 const cpl_propertylist * plist
243 cpl_ensure_code(frame != NULL, cpl_error_get_code());
244 cpl_ensure_code(plist != NULL, cpl_error_get_code());
246 cpl_ensure_code(!irplib_dfs_check_frame_tag(frame, plist, pfind),
247 cpl_error_get_code());
250 return cpl_error_get_code();
275 if (cpl_error_get_code())
return -1;
277 cpl_ensure(words != NULL, CPL_ERROR_NULL_INPUT, -2);
278 cpl_ensure(format != NULL, CPL_ERROR_NULL_INPUT, -3);
281 error = regcomp(&re,
"^ *%s( +%s)* *$", REG_EXTENDED | REG_NOSUB);
284 cpl_ensure(!error, CPL_ERROR_ILLEGAL_INPUT, -4);
286 status = regexec(&re, format, (
size_t)0, NULL, 0);
291 cpl_msg_error(cpl_func,
"Regexp counter must consist of space-separated"
292 " %%s, not: %s", format);
293 cpl_ensure(0, CPL_ERROR_ILLEGAL_INPUT, -5);
296 va_start(ap, format);
299 for (; format != NULL; format = strchr(++format,
'%')) {
301 const char * regexp = va_arg(ap,
const char *);
303 if (regexp == NULL) {
305 cpl_ensure(0, CPL_ERROR_ILLEGAL_INPUT, -6);
308 error = regcomp(&re, regexp, REG_EXTENDED | REG_NOSUB);
312 cpl_ensure(0, CPL_ERROR_ILLEGAL_INPUT, -7);
315 status = regexec(&re, words, (
size_t)0, NULL, 0);
319 if (status != 0)
break;
325 return format == NULL ? 0 : 1;
339 const irplib_framelist * rawframes)
342 char * newcomment = NULL;
346 double astart0 = -1.0;
348 double airmass = 0.0;
349 cpl_errorstate prestate = cpl_errorstate_get();
352 skip_if(
self == NULL);
354 for (iframe = 0; iframe < nframes; iframe++) {
355 const cpl_propertylist * plist
357 double astart = DBL_MAX;
358 double aend = DBL_MAX;
361 if (!cpl_errorstate_is_equal(prestate)) {
362 irplib_error_recover(prestate,
"No propertylist found for frame %d:",
368 astart = irplib_pfits_get_double(plist,
"ESO TEL AIRM START");
369 if (cpl_errorstate_is_equal(prestate)) {
371 aend = irplib_pfits_get_double(plist,
"ESO TEL AIRM END");
374 aend = irplib_pfits_get_double(plist,
"ESO TEL AIRM END");
375 if (cpl_errorstate_is_equal(prestate)) {
376 if (iframe == nframes - 1) aend0 = aend;
377 astart = irplib_pfits_get_double(plist,
"ESO TEL AIRM START");
381 if (cpl_errorstate_is_equal(prestate)) {
382 airmi = 0.5 * (astart + aend);
384 const char * filename = cpl_frame_get_filename(
386 irplib_error_recover(prestate,
"Could not get FITS key from %s",
389 airmi = irplib_pfits_get_double(plist,
"AIRMASS");
391 if (!cpl_errorstate_is_equal(prestate)) {
392 irplib_error_recover(prestate,
"Could not get FITS key from %s",
404 if (nmass == 0 && astart0 > 0.0 && aend0 > 0.0) {
405 airmass = 0.5 * (astart0 + aend0);
409 const char * key =
"AIRMASS";
410 const char * comment = cpl_propertylist_get_comment(
self, key);
412 cpl_errorstate_set(prestate);
414 airmass /= (double)nmass;
416 bug_if(cpl_propertylist_update_double(
self, key, airmass));
418 if (comment == NULL) {
419 bug_if(cpl_propertylist_set_comment(
self, key,
"Averaged air mass "
422 newcomment = cpl_sprintf(
"%s (Recalculated)",
424 bug_if(cpl_propertylist_set_comment(
self, key, newcomment));
431 cpl_free(newcomment);
433 return cpl_error_get_code();
449 static cpl_error_code irplib_dfs_check_frame_tag(
const cpl_frame *
self,
450 const cpl_propertylist * plist,
462 cpl_errorstate prestate = cpl_errorstate_get();
465 cpl_ensure_code(
self != NULL, CPL_ERROR_NULL_INPUT);
467 file = cpl_frame_get_filename(
self);
469 cpl_ensure_code(file != NULL, cpl_error_get_code());
471 tag = cpl_frame_get_tag(
self);
473 cpl_ensure_code(tag != NULL, cpl_error_get_code());
479 if (!cpl_errorstate_is_equal(prestate)) {
480 if (cpl_msg_get_level() <= CPL_MSG_DEBUG) {
481 cpl_msg_warning(cpl_func,
"File %s has missing or incomplete DPR "
483 cpl_errorstate_dump(prestate, CPL_FALSE, NULL);
485 cpl_errorstate_set(prestate);
489 cpl_ensure_code(pfind != NULL, CPL_ERROR_NULL_INPUT);
491 docatg = (*pfind)(catg, type, tech);
493 if (docatg == NULL) {
494 if (cpl_msg_get_level() <= CPL_MSG_DEBUG)
495 cpl_msg_warning(cpl_func,
"File %s has tag %s but unknown DPR "
496 "triplet: (CATG;TYPE;TECH)=(%s;%s;%s)", file, tag,
498 }
else if (strcmp(tag, docatg) != 0) {
499 if (cpl_msg_get_level() <= CPL_MSG_DEBUG)
500 cpl_msg_warning(cpl_func,
"File %s has tag %s but DPR triplet of "
501 "%s: (CATG;TYPE;TECH)=(%s;%s;%s)", file, tag,
502 docatg, catg, type, tech);
506 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_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.