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 <math.h>
00037 #include <cpl.h>
00038
00039 #include "irplib_utils.h"
00040 #include "irplib_stdstar.h"
00041
00042 #include "isaac_utils.h"
00043 #include "isaac_pfits.h"
00044 #include "isaac_dfs.h"
00045
00046
00047
00048
00049
00050 static int isaac_util_stdstars_create(cpl_plugin *);
00051 static int isaac_util_stdstars_exec(cpl_plugin *);
00052 static int isaac_util_stdstars_destroy(cpl_plugin *);
00053 static int isaac_util_stdstars(cpl_frameset *);
00054 static cpl_table * isaac_util_stdstars_convert(const char *);
00055
00056
00057
00058
00059
00060 static char isaac_util_stdstars_description[] =
00061 "isaac_util_stdstars -- ISAAC standard stars catalog creation.\n"
00062 "The files listed in the Set Of Frames (sof-file) must be tagged:\n"
00063 "raw-file.fits "ISAAC_UTIL_STDSTARS_RAW"\n";
00064
00065
00066
00067
00068
00069
00077
00078 int cpl_plugin_get_info(cpl_pluginlist * list)
00079 {
00080 cpl_recipe * recipe = cpl_calloc(1, sizeof(*recipe));
00081 cpl_plugin * plugin = &recipe->interface;
00082
00083 cpl_plugin_init(plugin,
00084 CPL_PLUGIN_API,
00085 ISAAC_BINARY_VERSION,
00086 CPL_PLUGIN_TYPE_RECIPE,
00087 "isaac_util_stdstars",
00088 "Standard stars catalog creation",
00089 isaac_util_stdstars_description,
00090 "Lars Lundin",
00091 PACKAGE_BUGREPORT,
00092 isaac_get_license(),
00093 isaac_util_stdstars_create,
00094 isaac_util_stdstars_exec,
00095 isaac_util_stdstars_destroy);
00096
00097 cpl_pluginlist_append(list, plugin);
00098
00099 return 0;
00100 }
00101
00102
00111
00112 static int isaac_util_stdstars_create(cpl_plugin * plugin)
00113 {
00114 cpl_recipe * recipe;
00115
00116
00117 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00118 recipe = (cpl_recipe *)plugin;
00119 else return -1;
00120
00121
00122 recipe->parameters = cpl_parameterlist_new();
00123
00124
00125 return 0;
00126 }
00127
00128
00134
00135 static int isaac_util_stdstars_exec(cpl_plugin * plugin)
00136 {
00137 cpl_recipe * recipe;
00138
00139
00140 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00141 recipe = (cpl_recipe *)plugin;
00142 else return -1;
00143
00144 return isaac_util_stdstars(recipe->frames);
00145 }
00146
00147
00153
00154 static int isaac_util_stdstars_destroy(cpl_plugin * plugin)
00155 {
00156 cpl_recipe * recipe;
00157
00158
00159 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00160 recipe = (cpl_recipe *)plugin;
00161 else return -1;
00162
00163 cpl_parameterlist_delete(recipe->parameters);
00164 return 0;
00165 }
00166
00167
00173
00174 static int isaac_util_stdstars(
00175 cpl_frameset * framelist)
00176 {
00177 cpl_frameset * rawframes;
00178
00179
00180 if (isaac_dfs_set_groups(framelist)) {
00181 cpl_msg_error(cpl_func, "Cannot identify RAW and CALIB frames");
00182 return -1;
00183 }
00184
00185
00186 if ((rawframes = isaac_extract_frameset(framelist,
00187 ISAAC_UTIL_STDSTARS_RAW)) == NULL) {
00188 cpl_msg_error(cpl_func, "Cannot find raw frames in the input list");
00189 return -1;
00190 }
00191
00192
00193 if (irplib_stdstar_write_catalogs(framelist,
00194 rawframes,
00195 "isaac_util_stdstars",
00196 ISAAC_UTIL_STDSTARS_RES,
00197 NULL,
00198 PACKAGE "/" PACKAGE_VERSION,
00199 "ISAAC",
00200 isaac_util_stdstars_convert) == -1) {
00201 cpl_msg_error(cpl_func, "Cannot write the catalogs");
00202 cpl_frameset_delete(rawframes);
00203 return -1;
00204 }
00205 cpl_frameset_delete(rawframes);
00206 return 0;
00207 }
00208
00209
00230
00231 static cpl_table * isaac_util_stdstars_convert(const char * filename)
00232 {
00233 cpl_table * out;
00234 int nfilters;
00235 const char * filters[8];
00236 double mags[8];
00237 int nbentries;
00238 FILE * in;
00239 char line[1024];
00240 double ra, dec;
00241 char sname[512];
00242 char stype[512];
00243 int i;
00244
00245
00246 if (filename == NULL) return NULL;
00247
00248
00249 nfilters = 8;
00250 filters[0] = "J";
00251 filters[1] = "H";
00252 filters[2] = "K";
00253 filters[3] = "Ks";
00254 filters[4] = "L";
00255 filters[5] = "M";
00256 filters[6] = "Lp";
00257 filters[7] = "Mp";
00258
00259
00260 nbentries = 0;
00261 if ((in = fopen(filename, "r")) == NULL) {
00262 return NULL;
00263 }
00264 while (fgets(line, 1024, in) != NULL) {
00265 if (line[0] != '#') nbentries ++;
00266 }
00267 fclose(in);
00268
00269
00270 out = cpl_table_new(nbentries);
00271 cpl_table_new_column(out, IRPLIB_STDSTAR_STAR_COL, CPL_TYPE_STRING);
00272 cpl_table_new_column(out, IRPLIB_STDSTAR_TYPE_COL, CPL_TYPE_STRING);
00273 cpl_table_new_column(out, IRPLIB_STDSTAR_RA_COL, CPL_TYPE_DOUBLE);
00274 cpl_table_new_column(out, IRPLIB_STDSTAR_DEC_COL, CPL_TYPE_DOUBLE);
00275 for (i=0; i<nfilters; i++)
00276 cpl_table_new_column(out, filters[i], CPL_TYPE_DOUBLE);
00277
00278
00279 if ((in = fopen(filename, "r")) == NULL) {
00280 cpl_table_delete(out);
00281 return NULL;
00282 }
00283 nbentries = 0;
00284 while (fgets(line, 1024, in) != NULL) {
00285 if (line[0] != '#') {
00286 if (sscanf(line, "%s %lg %lg %s %lg %lg %lg %lg %lg %lg %lg %lg",
00287 sname, &ra, &dec, stype, &(mags[0]), &(mags[1]),
00288 &(mags[2]), &(mags[3]), &(mags[4]), &(mags[5]),
00289 &(mags[6]), &(mags[7])) != 12) {
00290 cpl_table_delete(out);
00291 return NULL;
00292 }
00293 cpl_table_set_string(out, IRPLIB_STDSTAR_STAR_COL,nbentries, sname);
00294 cpl_table_set_string(out, IRPLIB_STDSTAR_TYPE_COL,nbentries, stype);
00295 cpl_table_set_double(out, IRPLIB_STDSTAR_RA_COL, nbentries, ra);
00296 cpl_table_set_double(out, IRPLIB_STDSTAR_DEC_COL, nbentries, dec);
00297 for (i=0; i<nfilters; i++)
00298 cpl_table_set_double(out, filters[i], nbentries, mags[i]);
00299 nbentries ++;
00300 }
00301 }
00302 fclose(in);
00303
00304 return out;
00305 }
00306