36 #include "irplib_utils.h"
38 #include "isaac_utils.h"
39 #include "isaac_pfits.h"
40 #include "isaac_dfs.h"
49 #define RECIPE_NAME "isaac_util_seds"
55 cpl_recipe_define(isaac_util_seds, ISAAC_BINARY_VERSION,
56 "Lars Lundin", PACKAGE_BUGREPORT,
"2008",
57 "ISAAC SEDS table creation",
58 RECIPE_NAME
" -- ISAAC SEDS table creation.\n"
59 "The files listed in the Set Of Frames (sof-file) "
61 "ASCII-SEDS.txt " ISAAC_UTIL_SEDS_RAW
"\n"
62 "The first three characters of the input file names must be "
63 "unique. Lines starting with a '#' are ignored. The other "
64 "lines must have (at least) two columns, the first with a "
65 "wavelength, the second with an SED. All files must have "
66 "an identical number of non-comment rows and all files are "
67 "assumed to contain identical sequences of wavelengths.\n");
70 cpl_error_code isaac_util_seds_save(cpl_frameset *,
const cpl_table *,
71 const cpl_parameterlist *);
87 cpl_error_code isaac_util_seds_fill_parameterlist(cpl_parameterlist *
self) {
89 return self != NULL ? CPL_ERROR_NONE
90 : cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT);
102 static int isaac_util_seds(cpl_frameset * framelist,
103 const cpl_parameterlist * parlist)
105 cpl_frameset * rawframes = NULL;
106 cpl_table * out = NULL;
107 cpl_bivector * seds = NULL;
108 cpl_vector * sedsx = NULL;
109 cpl_vector * sedsx1 = NULL;
110 cpl_vector * sedsy = NULL;
120 irplib_ensure(rawframes != NULL, CPL_ERROR_DATA_NOT_FOUND,
121 "Could not find raw frames in the input list");
123 nframes = cpl_frameset_get_size(rawframes);
124 irplib_ensure(nframes > 0, CPL_ERROR_DATA_NOT_FOUND,
125 "Could not find raw frames in the input list");
128 for (i = 0; i < nframes; i++) {
129 const cpl_frame * rawframe = cpl_frameset_get_position_const(rawframes, i);
133 const char * rawfile = cpl_frame_get_filename(rawframe);
135 const char * cat_name = strrchr(rawfile,
'/');
137 cat_name = cat_name ? 1+cat_name : rawfile;
138 bug_if(cat_name == NULL);
139 (void)strncpy(name, cat_name, 3);
143 seds = cpl_bivector_read(cpl_frame_get_filename(rawframe));
144 irplib_ensure(seds != NULL, cpl_error_get_code(),
145 "Could not load SED no. %d of %d", i+1, nframes);
146 sedsx = cpl_bivector_get_x(seds);
147 sedsy = cpl_bivector_get_y(seds);
148 cpl_bivector_unwrap_vectors(seds);
152 nlines = cpl_vector_get_size(sedsx);
155 out = cpl_table_new(nlines);
157 bug_if(cpl_table_wrap_double(out, cpl_vector_get_data(sedsx),
163 const int ilines = cpl_vector_get_size(sedsx);
166 irplib_ensure(ilines == nlines, CPL_ERROR_INCOMPATIBLE_INPUT,
167 "Number of lines in SED no. %d and %d differ: "
168 "%d <=> %d", 1, i+1, nlines, ilines);
171 bug_if(cpl_vector_subtract(sedsx, sedsx1));
173 dmin = cpl_vector_get_min(sedsx);
174 dmax = cpl_vector_get_max(sedsx);
176 if (dmin != 0.0 || dmax != 0.0) {
177 cpl_msg_warning(cpl_func,
"Wavelengths in SED no. %d differ "
178 "from those in no. 1 (min, max): %g %g",
182 cpl_vector_delete(sedsx);
187 skip_if(cpl_table_wrap_double(out, cpl_vector_get_data(sedsy), name));
188 (void)cpl_vector_unwrap(sedsy);
193 skip_if (isaac_util_seds_save(framelist, out, parlist));
197 cpl_bivector_unwrap_vectors(seds);
198 (void)cpl_vector_unwrap(sedsx1);
199 cpl_vector_delete(sedsx);
200 cpl_vector_delete(sedsy);
201 cpl_frameset_delete(rawframes);
202 cpl_table_delete(out);
204 return cpl_error_get_code();
218 cpl_error_code isaac_util_seds_save(cpl_frameset * set,
219 const cpl_table * sed,
220 const cpl_parameterlist * parlist)
222 cpl_propertylist * plist = cpl_propertylist_new();
224 bug_if(cpl_propertylist_append_string(plist,
"INSTRUME",
"ISAAC"));
227 skip_if(irplib_dfs_save_table(set,
236 PACKAGE
"/" PACKAGE_VERSION,
237 RECIPE_NAME CPL_DFS_FITS));
241 cpl_propertylist_delete(plist);
243 return cpl_error_get_code();
int isaac_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
cpl_frameset * isaac_extract_frameset(const cpl_frameset *self, const char *tag)
Extract the frames with the given tag from a frameset.