00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031
00032
00033
00034
00035
00036 #include "irplib_utils.h"
00037
00038 #include "isaac_utils.h"
00039 #include "isaac_pfits.h"
00040 #include "isaac_dfs.h"
00041
00042 #include <string.h>
00043 #include <math.h>
00044
00045
00046
00047
00048
00049 #define RECIPE_NAME "isaac_util_seds"
00050
00051
00052
00053
00054
00055 CPL_RECIPE_DEFINE(isaac_util_seds, ISAAC_BINARY_VERSION, recipe ? 0 : 1,
00056 "Lars Lundin", PACKAGE_BUGREPORT, "2008",
00057 "ISAAC SEDS table creation",
00058 RECIPE_NAME " -- ISAAC SEDS table creation.\n"
00059 "The files listed in the Set Of Frames (sof-file) "
00060 "must be tagged:\n"
00061 "ASCII-SEDS.txt " ISAAC_UTIL_SEDS_RAW "\n"
00062 "The first three characters of the input file names must be "
00063 "unique. Lines starting with a '#' are ignored. The other "
00064 "lines must have (at least) two columns, the first with a "
00065 "wavelength, the second with an SED. All files must have "
00066 "an identical number of non-comment rows and all files are "
00067 "assumed to contain identical sequences of wavelengths.\n");
00068
00069 static
00070 cpl_error_code isaac_util_seds_save(cpl_frameset *, const cpl_table *,
00071 const cpl_parameterlist *);
00072
00073
00074
00075
00076
00077
00085
00086 static int isaac_util_seds(cpl_frameset * framelist,
00087 const cpl_parameterlist * parlist)
00088 {
00089 cpl_frameset * rawframes = NULL;
00090 cpl_table * out = NULL;
00091 cpl_bivector * seds = NULL;
00092 cpl_vector * sedsx = NULL;
00093 cpl_vector * sedsx1 = NULL;
00094 cpl_vector * sedsy = NULL;
00095 int nframes = 0;
00096 int nlines = 0;
00097 int i;
00098
00099
00100 skip_if (isaac_dfs_set_groups(framelist));
00101
00102
00103 rawframes = isaac_extract_frameset(framelist, ISAAC_UTIL_SEDS_RAW);
00104 irplib_ensure(rawframes != NULL, CPL_ERROR_DATA_NOT_FOUND,
00105 "Could not find raw frames in the input list");
00106
00107 nframes = cpl_frameset_get_size(rawframes);
00108 irplib_ensure(nframes > 0, CPL_ERROR_DATA_NOT_FOUND,
00109 "Could not find raw frames in the input list");
00110
00111
00112 for (i = 0; i < nframes; i++) {
00113 const cpl_frame * rawframe = cpl_frameset_get_frame_const(rawframes, i);
00114
00115
00116 char name[4];
00117 const char * rawfile = cpl_frame_get_filename(rawframe);
00118
00119 const char * cat_name = strrchr(rawfile, '/');
00120
00121 cat_name = cat_name ? 1+cat_name : rawfile;
00122 bug_if(cat_name == NULL);
00123 (void)strncpy(name, cat_name, 3);
00124 name[3] = '\0';
00125
00126
00127 seds = cpl_bivector_read(cpl_frame_get_filename(rawframe));
00128 irplib_ensure(seds != NULL, cpl_error_get_code(),
00129 "Could not load SED no. %d of %d", i+1, nframes);
00130 sedsx = cpl_bivector_get_x(seds);
00131 sedsy = cpl_bivector_get_y(seds);
00132 cpl_bivector_unwrap_vectors(seds);
00133 seds = NULL;
00134
00135 if (i == 0) {
00136 nlines = cpl_vector_get_size(sedsx);
00137
00138
00139 out = cpl_table_new(nlines);
00140
00141 bug_if(cpl_table_wrap_double(out, cpl_vector_get_data(sedsx),
00142 "Wavelength"));
00143 sedsx1 = sedsx;
00144 sedsx = NULL;
00145 } else {
00146
00147 const int ilines = cpl_vector_get_size(sedsx);
00148 double dmin, dmax;
00149
00150 irplib_ensure(ilines == nlines, CPL_ERROR_INCOMPATIBLE_INPUT,
00151 "Number of lines in SED no. %d and %d differ: "
00152 "%d <=> %d", 1, i+1, nlines, ilines);
00153
00154
00155 bug_if(cpl_vector_subtract(sedsx, sedsx1));
00156
00157 dmin = cpl_vector_get_min(sedsx);
00158 dmax = cpl_vector_get_max(sedsx);
00159
00160 if (dmin != 0.0 || dmax != 0.0) {
00161 cpl_msg_warning(cpl_func, "Wavelengths in SED no. %d differ "
00162 "from those in no. 1 (min, max): %g %g",
00163 i+1, dmin, dmax);
00164 }
00165
00166 cpl_vector_delete(sedsx);
00167 sedsx = NULL;
00168 }
00169
00170
00171 skip_if(cpl_table_wrap_double(out, cpl_vector_get_data(sedsy), name));
00172 (void)cpl_vector_unwrap(sedsy);
00173 sedsy = NULL;
00174 }
00175
00176
00177 skip_if (isaac_util_seds_save(framelist, out, parlist));
00178
00179 end_skip;
00180
00181 cpl_bivector_unwrap_vectors(seds);
00182 (void)cpl_vector_unwrap(sedsx1);
00183 cpl_vector_delete(sedsx);
00184 cpl_vector_delete(sedsy);
00185 cpl_frameset_delete(rawframes);
00186 cpl_table_delete(out);
00187
00188 return cpl_error_get_code();
00189 }
00190
00191
00200
00201 static
00202 cpl_error_code isaac_util_seds_save(cpl_frameset * set,
00203 const cpl_table * sed,
00204 const cpl_parameterlist * parlist)
00205 {
00206 cpl_propertylist * plist = cpl_propertylist_new();
00207
00208 bug_if(cpl_propertylist_append_string(plist, "INSTRUME", "ISAAC"));
00209
00210
00211 skip_if(irplib_dfs_save_table(set,
00212 parlist,
00213 set,
00214 sed,
00215 NULL,
00216 RECIPE_NAME,
00217 ISAAC_UTIL_SEDS_RES,
00218 plist,
00219 NULL,
00220 PACKAGE "/" PACKAGE_VERSION,
00221 RECIPE_NAME CPL_DFS_FITS));
00222
00223 end_skip;
00224
00225 cpl_propertylist_delete(plist);
00226
00227 return cpl_error_get_code();
00228 }
00229
00230