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)
69 cpl_init(CPL_INIT_DEFAULT);
70 if (getenv(
"ESOREX_MSG_LEVEL") && !strncmp(getenv(
"ESOREX_MSG_LEVEL"),
72 cpl_msg_set_level(CPL_MSG_DEBUG);
81 for (i = 1; i < argc; i++) {
82 if (strncmp(argv[i],
"-i", 3) == 0) {
90 }
else if (strncmp(argv[i],
"-", 1) == 0) {
93 if (iname && toname) {
104 int extension = cpl_fits_find_extension(iname, EXTNAME_DQ);
105 cpl_image *image = cpl_image_load(iname, CPL_TYPE_INT, 0, extension);
110 cpl_propertylist *header = cpl_propertylist_load(iname, 0);
111 int nx = cpl_image_get_size_x(image),
112 ny = cpl_image_get_size_y(image);
114 printf(
"Read %dx%d image of IFU %hhu from \"%s\"\n", nx, ny, nifu, iname);
120 cpl_table_dump(table, 0, 1000, stdout);
123 cpl_size nrow = cpl_table_get_nrow(table);
124 printf(
"%"CPL_SIZE_FORMAT
" bad pixel%s found\n", nrow, nrow != 1 ?
"s" :
"");
129 cpl_propertylist *htest = cpl_propertylist_load(tiname, 0);
131 cpl_propertylist_delete(htest);
133 printf(
"WARNING: could not open input table \"%s\"!\n", tiname);
139 cpl_table *intable = NULL;
142 char *extifu = cpl_sprintf(
"CHAN%02hhu", nifu);
154 cpl_propertylist *pheader = NULL;
157 pheader = cpl_propertylist_load_regexp(iname, 0,
"TELESCOP|INSTRUME|"
161 cpl_propertylist_erase_regexp(pheader,
"ESO DET DEV[0-9] (SHUT |EXP )|"
162 "ESO DET (EXP |[DU]IT|NDIT|DKTM)", 0);
163 cpl_propertylist_erase_regexp(pheader,
"ESO DET (CHIP |OUT[1-4])", 0);
164 cpl_propertylist_update_string(pheader,
"OBJECT",
165 "Bad pixel table for MUSE (BADPIX_TABLE)");
166 cpl_propertylist_update_string(pheader,
"PIPEFILE", toname);
167 cpl_propertylist_set_comment(pheader,
"PIPEFILE",
168 "pretend to be a pipeline output file");
172 cpl_propertylist_erase_regexp(header,
"^EXT|ESO DET (CHIP |OUT[1-4])", 1);
174 cpl_error_code rc = cpl_table_save(table, pheader, header, toname,
175 pheader ? CPL_IO_CREATE : CPL_IO_EXTEND);
176 if (rc != CPL_ERROR_NONE) {
177 fprintf(stderr,
"Saving to \"%s\" failed (rc=%d): %s\n", toname, rc,
178 cpl_error_get_message());
180 printf(
"Saved to \"%s\"\n", toname);
182 cpl_propertylist_delete(pheader);
184 cpl_table_delete(table);
185 cpl_image_delete(image);
186 cpl_propertylist_delete(header);
188 if (cpl_msg_get_level() == CPL_MSG_DEBUG) {
189 printf(
"Output file \"%s\" has primary header and %"CPL_SIZE_FORMAT
190 " extensions\n", toname, cpl_fits_count_extensions(toname));
191 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.