58 #define PRINT_USAGE(rc) \ 59 fprintf(stderr, "Usage: %s [ -i INTABLE ] INFILE OUTTABLE\n", argv[0]); \ 60 cpl_end(); return (rc); 62 int main(
int argc,
char **argv)
64 cpl_init(CPL_INIT_DEFAULT);
71 if (getenv(
"ESOREX_MSG_LEVEL") && !strncmp(getenv(
"ESOREX_MSG_LEVEL"),
73 cpl_msg_set_level(CPL_MSG_DEBUG);
82 for (i = 1; i < argc; i++) {
83 if (strncmp(argv[i],
"-i", 3) == 0) {
91 }
else if (strncmp(argv[i],
"-", 1) == 0) {
94 if (iname && toname) {
105 int extension = cpl_fits_find_extension(iname, EXTNAME_DQ);
106 cpl_image *image = cpl_image_load(iname, CPL_TYPE_INT, 0, extension);
111 cpl_propertylist *header = cpl_propertylist_load(iname, 0);
112 int nx = cpl_image_get_size_x(image),
113 ny = cpl_image_get_size_y(image);
115 printf(
"Read %dx%d image of IFU %hhu from \"%s\"\n", nx, ny, nifu, iname);
121 cpl_table_dump(table, 0, 1000, stdout);
124 cpl_size nrow = cpl_table_get_nrow(table);
125 printf(
"%"CPL_SIZE_FORMAT
" bad pixel%s found\n", nrow, nrow != 1 ?
"s" :
"");
130 cpl_propertylist *htest = cpl_propertylist_load(tiname, 0);
132 cpl_propertylist_delete(htest);
134 printf(
"WARNING: could not open input table \"%s\"!\n", tiname);
140 cpl_table *intable = NULL;
143 char *extifu = cpl_sprintf(
"CHAN%02hhu", nifu);
155 cpl_propertylist *pheader = NULL;
158 pheader = cpl_propertylist_load_regexp(iname, 0,
"TELESCOP|INSTRUME|" 162 cpl_propertylist_erase_regexp(pheader,
"ESO DET DEV[0-9] (SHUT |EXP )|" 163 "ESO DET (EXP |[DU]IT|NDIT|DKTM)", 0);
164 cpl_propertylist_erase_regexp(pheader,
"ESO DET (CHIP |OUT[1-4])", 0);
165 cpl_propertylist_update_string(pheader,
"OBJECT",
166 "Bad pixel table for MUSE (BADPIX_TABLE)");
167 cpl_propertylist_update_string(pheader,
"PIPEFILE", toname);
168 cpl_propertylist_set_comment(pheader,
"PIPEFILE",
169 "pretend to be a pipeline output file");
173 cpl_propertylist_erase_regexp(header,
"^EXT|ESO DET (CHIP |OUT[1-4])", 1);
175 cpl_error_code rc = cpl_table_save(table, pheader, header, toname,
176 pheader ? CPL_IO_CREATE : CPL_IO_EXTEND);
177 if (rc != CPL_ERROR_NONE) {
178 fprintf(stderr,
"Saving to \"%s\" failed (rc=%d): %s\n", toname, rc,
179 cpl_error_get_message());
181 printf(
"Saved to \"%s\"\n", toname);
183 cpl_propertylist_delete(pheader);
185 cpl_table_delete(table);
186 cpl_image_delete(image);
187 cpl_propertylist_delete(header);
189 if (cpl_msg_get_level() == CPL_MSG_DEBUG) {
190 printf(
"Output file \"%s\" has primary header and %"CPL_SIZE_FORMAT
191 " extensions\n", toname, cpl_fits_count_extensions(toname));
192 cpl_errorstate_dump(0, CPL_FALSE, NULL);
cpl_table * muse_quality_convert_dq(cpl_image *aDQ)
Convert a data quality (DQ) image extension to a bad pixel table.
unsigned char muse_utils_get_ifu(const cpl_propertylist *aHeaders)
Find out the IFU/channel from which this header originated.
cpl_error_code muse_quality_copy_badpix_table(const char *aInFile, const char *aOutFile, int aExtension, const cpl_table *aTable)
Copy bad pixel table on disk, replacing the table in one extension.
cpl_table * muse_quality_merge_badpix_from_file(const cpl_table *aTable, const char *aInFile, const char *aExtname, int *aExt)
Merge bad pixel table in memory with table from file on disk.
void muse_processing_recipeinfo(cpl_plugin *)
Output main pipeline configuration, inputs, and parameters.