58 #define PRINT_USAGE(rc) \ 59 fprintf(stderr, "Usage: %s [ -s ] [ -d ] FILENAME\n", argv[0]); \ 60 cpl_end(); return (rc); 62 int main(
int argc,
char **argv)
64 cpl_init(CPL_INIT_DEFAULT);
73 cpl_boolean dodelete = CPL_FALSE,
77 for (i = 1; i < argc; i++) {
78 if (strncmp(argv[i],
"-s", 3) == 0) {
80 }
else if (strncmp(argv[i],
"-d", 3) == 0) {
82 }
else if (strncmp(argv[i],
"-", 1) == 0) {
94 cpl_errorstate state = cpl_errorstate_get();
97 int next = cpl_fits_count_extensions(iname);
101 cpl_propertylist *header = cpl_propertylist_load(iname, 0);
103 printf(
"Splitting \"%s\" (PRO.CATG %s, %d extensions).\n", iname, tag, next);
106 cpl_frameset *fset = cpl_frameset_new();
110 for (iext = 1; iext <= next; iext++) {
112 cpl_propertylist *hext = cpl_propertylist_load(iname, iext);
115 const char *xtension = cpl_propertylist_get_string(hext,
"XTENSION"),
118 fprintf(stderr,
"Broken FITS extension (missing XTENSION, extension " 120 cpl_propertylist_delete(hext);
132 } exttype = IS_OTHER;
133 if (!strncmp(xtension,
"BINTABLE", 8)) {
134 exttype = IS_BINTABLE;
135 }
else if (!strncmp(xtension,
"IMAGE", 8)) {
136 char *chan = cpl_sprintf(
"CHAN%02hhu", ifu),
137 *chandata = cpl_sprintf(
"CHAN%02hhu.DATA", ifu),
138 *chandq = cpl_sprintf(
"CHAN%02hhu.DQ", ifu),
139 *chanstat = cpl_sprintf(
"CHAN%02hhu.STAT", ifu);
140 if (extname && !strncmp(extname, chan, strlen(chan) + 1)) {
142 }
else if (extname && !strncmp(extname, chandata, strlen(chandata) + 1)) {
143 exttype = IS_MUSE_IMAGE_DATA;
144 }
else if (extname && !strncmp(extname, chandq, strlen(chandq) + 1)) {
145 exttype = IS_MUSE_IMAGE_DQ;
146 }
else if (extname && !strncmp(extname, chanstat, strlen(chanstat) + 1)) {
147 exttype = IS_MUSE_IMAGE_STAT;
148 }
else if (extname &&
149 !strncmp(extname, chan, strlen(chan)) &&
151 exttype = IS_CHANNEL_CUBE;
162 char *basefn = cpl_strdup(iname),
163 *end = strstr(basefn,
".fits");
167 char *outfn = cpl_sprintf(
"%s-%02hhu.fits", basefn, ifu);
173 printf(
"\tbinary table (XTENSION=\'%s\', EXTNAME=\'%s\')\n", xtension,
176 cpl_table *table = cpl_table_load(iname, iext, 1);
177 cpl_propertylist *hout = cpl_propertylist_duplicate(header);
178 cpl_propertylist_append(hout, hext);
179 if (strlen(extname) == 6) {
181 cpl_table_save(table, hout, NULL, outfn, CPL_IO_CREATE);
183 cpl_propertylist *hextout = cpl_propertylist_new();
185 char *extnew = strchr(extname,
'.');
188 cpl_propertylist_append_string(hextout,
"EXTNAME", extnew);
190 cpl_table_save(table, hout, hextout, outfn, CPL_IO_CREATE);
191 cpl_propertylist_delete(hextout);
193 cpl_table_delete(table);
194 cpl_propertylist_delete(hout);
198 printf(
"\tstandard image(XTENSION=\'%s\', EXTNAME=\'%s\')\n", xtension,
201 cpl_image *image = cpl_image_load(iname, CPL_TYPE_UNSPECIFIED, 0, iext);
202 cpl_propertylist *hout = cpl_propertylist_duplicate(header);
203 cpl_propertylist_append(hout, hext);
204 cpl_image_save(image, outfn, CPL_TYPE_UNSPECIFIED, hout, CPL_IO_CREATE);
205 cpl_image_delete(image);
206 cpl_propertylist_delete(hout);
209 case IS_CHANNEL_CUBE: {
210 printf(
"\tchannel cube (XTENSION=\'%s\', EXTNAME=\'%s\')\n", xtension,
213 cpl_imagelist *list = cpl_imagelist_load(iname, CPL_TYPE_UNSPECIFIED, iext);
214 cpl_propertylist *hout = cpl_propertylist_duplicate(header);
217 char extnamerest[KEYWORD_LENGTH];
218 sscanf(extname,
"CHAN%02hhu.%s", &dummy, extnamerest);
220 printf(
"%s -> %02hhu and %s\n", extname, dummy, extnamerest);
222 cpl_propertylist_update_string(hext,
"EXTNAME", extnamerest);
224 char *chan = cpl_sprintf(
"CHAN%02hhu", ifu);
225 cpl_propertylist_update_string(hout,
"EXTNAME", chan);
227 cpl_propertylist_copy_property_regexp(hout, hext,
"^ESO ", 0);
228 cpl_propertylist_save(hout, outfn, CPL_IO_CREATE);
229 cpl_propertylist_erase_regexp(hext,
"^ESO ", 0);
230 cpl_imagelist_save(list, outfn, CPL_TYPE_UNSPECIFIED, hext, CPL_IO_EXTEND);
231 cpl_imagelist_delete(list);
232 cpl_propertylist_delete(hout);
235 case IS_MUSE_IMAGE_DATA: {
236 printf(
"\tMUSE image (XTENSION=\'%s\', EXTNAME=\'%s\')\n", xtension,
244 case IS_MUSE_IMAGE_DQ:
245 case IS_MUSE_IMAGE_STAT:
247 printf(
"MUSE OTHER (%s %s)\n", xtension, extname);
249 cpl_propertylist_delete(hext);
253 fprintf(stderr,
"\tUnsupported FITS extension (XTENSION=\'%s\', " 254 "extension %d)\n", xtension, iext);
255 cpl_propertylist_delete(hext);
259 cpl_propertylist_delete(hext);
262 cpl_frame *frame = cpl_frame_new();
263 cpl_frame_set_filename(frame, outfn);
265 cpl_frame_set_tag(frame, tag);
266 cpl_frame_set_group(frame, CPL_FRAME_GROUP_PRODUCT);
268 cpl_frame_set_type(frame, CPL_FRAME_TYPE_NONE);
269 cpl_frame_set_level(frame, CPL_FRAME_LEVEL_NONE);
272 cpl_frame_dump(frame, stdout);
275 cpl_frameset_insert(fset, frame);
277 cpl_propertylist_delete(header);
279 int nout = cpl_frameset_get_size(fset);
281 printf(
"Signing %d output product%s...\n", nout, nout == 0 ?
"" :
"s");
282 cpl_dfs_sign_products(fset, CPL_DFS_SIGNATURE_DATAMD5 | CPL_DFS_SIGNATURE_CHECKSUM);
285 printf(
"Deleting input file \"%s\"...\n", iname);
289 printf(
"Split output product%s:\n", nout == 0 ?
"" :
"s");
290 for (i = 0; i < nout; i++) {
291 const cpl_frame *frame = cpl_frameset_get_position_const(fset, i);
292 const char *fn = cpl_frame_get_filename(frame);
293 next = cpl_fits_count_extensions(fn);
294 printf(
"\t\"%s\" (%d FITS extensions)\n", fn, next);
296 cpl_frameset_delete(fset);
299 if (!cpl_errorstate_is_equal(state)) {
void muse_image_delete(muse_image *aImage)
Deallocate memory associated to a muse_image object.
const char * muse_pfits_get_extname(const cpl_propertylist *aHeaders)
find out the extension name
unsigned char muse_utils_get_ifu(const cpl_propertylist *aHeaders)
Find out the IFU/channel from which this header originated.
cpl_size muse_pfits_get_naxis(const cpl_propertylist *aHeaders, unsigned int aAxis)
find out the size of a given axis
Structure definition of MUSE three extension FITS file.
void muse_cplerrorstate_dump_some(unsigned aCurrent, unsigned aFirst, unsigned aLast)
Dump some CPL errors.
cpl_error_code muse_image_save(muse_image *aImage, const char *aFilename)
Save the three image extensions and the FITS headers of a MUSE image to a file.
const char * muse_pfits_get_pro_catg(const cpl_propertylist *aHeaders)
find out the PRO category
muse_image * muse_image_load_from_extensions(const char *aFilename, unsigned char aIFU)
Load the three extensions and the FITS headers of a MUSE image from extensions of a merged file...
void muse_processing_recipeinfo(cpl_plugin *)
Output main pipeline configuration, inputs, and parameters.