65 #define PRINT_USAGE(rc) \ 66 fprintf(stderr, "Usage: %s [ -f ] [ -s SOFFILE ] OFFSET_LIST " \ 67 "[ FILE [ FILE [ ... ] ] ] \n", argv[0]); \ 68 cpl_end(); return (rc); 70 int main(
int argc,
char **argv)
72 const char *idstring =
"muse_offset_list_create";
73 cpl_init(CPL_INIT_DEFAULT);
74 cpl_msg_set_time_on();
76 cpl_msg_set_level(CPL_MSG_DEBUG);
77 cpl_msg_set_component_on();
78 cpl_errorstate state = cpl_errorstate_get();
86 cpl_array *files = NULL,
88 cpl_boolean overwrite = CPL_FALSE;
92 for (i = 1; i < argc; i++) {
93 if (strncmp(argv[i],
"-s", 3) == 0) {
97 FILE *fp = fopen(argv[i],
"r");
102 soffiles = cpl_array_new(0, CPL_TYPE_STRING);
106 while (fscanf(fp,
"%4095s %49s", fn, tag) != EOF) {
107 if (!strncmp(tag,
"PIXTABLE_", 9)) {
109 cpl_msg_debug(idstring,
"IS a pixel table: \"%s\" is %s", fn, tag);
112 cpl_array_set_size(soffiles, cpl_array_get_size(soffiles) + 1);
114 cpl_array_set_string(soffiles, cpl_array_get_size(soffiles) - 1, fn);
117 cpl_msg_debug(idstring,
"not a pixel table: \"%s\" is %s", fn, tag);
125 }
else if (strncmp(argv[i],
"-f", 3) == 0) {
126 overwrite = CPL_TRUE;
127 }
else if (strncmp(argv[i],
"-", 1) == 0) {
133 files = cpl_array_new(1, CPL_TYPE_STRING);
135 cpl_array_set_string(files, 0, argv[i]);
137 cpl_array_set_size(files, cpl_array_get_size(files) + 1);
139 cpl_array_set_string(files, cpl_array_get_size(files) - 1, argv[i]);
146 cpl_array_dump(files, 0, cpl_array_get_size(files), stdout);
147 printf(
"from .sof:\n");
148 cpl_array_dump(soffiles, 0, cpl_array_get_size(soffiles), stdout);
156 if (cpl_array_get_size(soffiles) > 0) {
157 cpl_array_insert(files, soffiles, cpl_array_get_size(files));
159 cpl_array_delete(soffiles);
166 cpl_array_delete(files);
169 if (!access(oname, F_OK) && !overwrite) {
170 cpl_array_delete(files);
175 cpl_propertylist *pheader = cpl_propertylist_new();
176 cpl_propertylist_append_string(pheader,
"INSTRUME",
"MUSE");
177 cpl_propertylist_append_string(pheader,
"ESO PRO CATG", MUSE_TAG_OFFSET_LIST);
178 cpl_table *olist = NULL;
181 cpl_msg_debug(idstring,
"No MUSE exposures given on input, creating empty " 182 "table with 10 rows");
184 cpl_propertylist_append_string(pheader,
"FILES",
"no files given");
186 nfiles = cpl_array_get_size(files);
187 cpl_msg_debug(idstring,
"%d MUSE exposures given on input, creating table " 188 "for these", nfiles);
195 cpl_recipe *recipe = NULL;
202 for (i = 0; i < nfiles; i++) {
203 const char *fn = cpl_array_get_string(files, i);
204 cpl_propertylist *header = cpl_propertylist_load(fn, 0);
206 cpl_msg_warning(idstring,
"Could not load primary header from \"%s\"!",
210 cpl_table_set_string(olist, MUSE_OFFSETS_DATEOBS, i,
212 cpl_table_set_double(olist, MUSE_OFFSETS_MJDOBS, i,
214 cpl_propertylist_delete(header);
215 char *kw = cpl_sprintf(
"FILE%d", i+1),
216 *p = strrchr(fn,
'/');
222 cpl_propertylist_append_string(pheader, kw, p);
227 cpl_error_code rc = cpl_table_save(olist, pheader, NULL, oname, CPL_IO_CREATE);
228 cpl_array_delete(files);
229 cpl_table_delete(olist);
230 cpl_propertylist_delete(pheader);
234 cpl_msg_info(idstring,
"Saved %s as \"%s\"", MUSE_TAG_OFFSET_LIST, oname);
236 case CPL_ERROR_FILE_NOT_CREATED:
237 cpl_msg_error(idstring,
"Could not create output file \"%s\"", oname);
242 cpl_msg_error(idstring,
"An unknown error occurred: %s",
243 cpl_error_get_message());
246 if (!cpl_errorstate_is_equal(state)) {
void muse_processing_delete(muse_processing *aProcessing)
Free the muse_processing structure.
const char * muse_pfits_get_dateobs(const cpl_propertylist *aHeaders)
find out the date of observations
muse_processing * muse_processing_new(const char *aName, cpl_recipe *aRecipe)
Create a new processing structure.
cpl_table * muse_cpltable_new(const muse_cpltable_def *aDef, cpl_size aLength)
Create an empty table according to the specified definition.
void muse_cplerrorstate_dump_some(unsigned aCurrent, unsigned aFirst, unsigned aLast)
Dump some CPL errors.
double muse_pfits_get_mjdobs(const cpl_propertylist *aHeaders)
find out the Julian Date of the observation
cpl_table * muse_processing_sort_exposures(muse_processing *aProcessing)
Sort input frames (containing lists of pixel table filenames) into different exposures.
void muse_processing_recipeinfo(cpl_plugin *)
Output main pipeline configuration, inputs, and parameters.