27 #include "muse_pfits.h" 49 if (!aHeader || !aLines || !aPrefix) {
50 cpl_error_set(__func__, CPL_ERROR_NULL_INPUT);
53 if (cpl_table_get_nrow(aLines) < 1) {
54 cpl_error_set(__func__, CPL_ERROR_DATA_NOT_FOUND);
58 char keyword[KEYWORD_LENGTH];
59 int i, ngroups = cpl_table_get_column_max(aLines,
"group") + 1;
60 for (i = 0; i < ngroups; i++) {
61 cpl_table_unselect_all(aLines);
62 cpl_table_or_selected_int(aLines,
"group", CPL_EQUAL_TO, i);
63 cpl_table *gtable = cpl_table_extract_selected(aLines);
65 cpl_table_get_column_maxpos(gtable,
"flux", &irow);
66 const char *name = cpl_table_get_string(gtable,
"name", irow);
67 double wavelength = cpl_table_get_double(gtable,
"lambda", irow, NULL),
68 flux = cpl_table_get_double(gtable,
"flux", irow, NULL);
69 snprintf(keyword, KEYWORD_LENGTH,
"%s LINE%i NAME", aPrefix, i+1);
70 cpl_propertylist_append_string(aHeader, keyword, name);
71 snprintf(keyword, KEYWORD_LENGTH,
"%s LINE%i AWAV", aPrefix, i+1);
72 cpl_propertylist_append_double(aHeader, keyword, wavelength);
73 snprintf(keyword, KEYWORD_LENGTH,
"%s LINE%i FLUX", aPrefix, i+1);
74 if (!isfinite(flux)) {
77 cpl_propertylist_append_double(aHeader, keyword, -9999.999);
78 cpl_msg_error(__func__,
"Sky-line fit failed for group %d, computed " 79 "flux is infinite!", i+1);
81 cpl_propertylist_append_double(aHeader, keyword, flux);
83 cpl_table_delete(gtable);
85 cpl_table_unselect_all(aLines);
105 if (!aHeader || !aContinuum || !aPrefix) {
106 cpl_error_set(__func__, CPL_ERROR_NULL_INPUT);
109 cpl_size irow, nrow = cpl_table_get_nrow(aContinuum);
111 cpl_error_set(__func__, CPL_ERROR_DATA_NOT_FOUND);
116 for (irow = 0; irow < nrow; irow++) {
117 flux += cpl_table_get_double(aContinuum,
"flux", irow, NULL);
119 char keyword[KEYWORD_LENGTH];
120 snprintf(keyword, KEYWORD_LENGTH,
"%s CONT FLUX", aPrefix);
121 if (!isfinite(flux)) {
123 cpl_propertylist_append_double(aHeader, keyword, -9999.999);
124 cpl_msg_error(__func__,
"Sky-continuum contains infinite values, fit may " 127 cpl_propertylist_append_double(aHeader, keyword, flux);
130 prev = cpl_table_get_double(aContinuum,
"flux", 0, NULL),
131 l_prev = cpl_table_get_double(aContinuum,
"lambda", 0, NULL);
132 for (irow = 1; irow < nrow; irow++) {
133 double cur = cpl_table_get_double(aContinuum,
"flux", irow, NULL),
134 l_cur = cpl_table_get_double(aContinuum,
"lambda", irow, NULL),
135 dev = fabs((cur - prev)/ (l_cur - l_prev));
142 snprintf(keyword, KEYWORD_LENGTH,
"%s CONT MAXDEV", aPrefix);
143 cpl_propertylist_append_double(aHeader, keyword, maxdev);
void muse_sky_qc_lines(cpl_propertylist *aHeader, cpl_table *aLines, const char *aPrefix)
Fill a header with the QC parameters for the sky lines.
void muse_sky_qc_continuum(cpl_propertylist *aHeader, cpl_table *aContinuum, const char *aPrefix)
Fill a header with the QC parameters for the sky continuum.