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 "hawki_utils.h"
00043 #include "hawki_load.h"
00044 #include "hawki_pfits.h"
00045 #include "hawki_dfs.h"
00046
00047
00048
00049
00050
00051 static int hawki_util_stdstars_create(cpl_plugin *) ;
00052 static int hawki_util_stdstars_exec(cpl_plugin *) ;
00053 static int hawki_util_stdstars_destroy(cpl_plugin *) ;
00054 static int hawki_util_stdstars(cpl_frameset *) ;
00055 static cpl_table * hawki_util_stdstars_convert(const char *) ;
00056
00057
00058
00059
00060
00061 static char hawki_util_stdstars_description[] =
00062 "hawki_util_stdstars -- HAWK-I standard stars catalog creation.\n"
00063 "The files listed in the Set Of Frames (sof-file) must be tagged:\n"
00064 "raw-file.txt "HAWKI_UTIL_STDSTARS_RAW"\n" ;
00065
00066
00067
00068
00069
00070
00078
00079 int cpl_plugin_get_info(cpl_pluginlist * list)
00080 {
00081 cpl_recipe * recipe = cpl_calloc(1, sizeof(*recipe)) ;
00082 cpl_plugin * plugin = &recipe->interface ;
00083
00084 cpl_plugin_init(plugin,
00085 CPL_PLUGIN_API,
00086 HAWKI_BINARY_VERSION,
00087 CPL_PLUGIN_TYPE_RECIPE,
00088 "hawki_util_stdstars",
00089 "Standard stars catalog creation",
00090 hawki_util_stdstars_description,
00091 "Yves Jung",
00092 PACKAGE_BUGREPORT,
00093 hawki_get_license(),
00094 hawki_util_stdstars_create,
00095 hawki_util_stdstars_exec,
00096 hawki_util_stdstars_destroy) ;
00097
00098 cpl_pluginlist_append(list, plugin) ;
00099
00100 return 0;
00101 }
00102
00103
00112
00113 static int hawki_util_stdstars_create(cpl_plugin * plugin)
00114 {
00115 cpl_recipe * recipe ;
00116
00117
00118 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00119 recipe = (cpl_recipe *)plugin ;
00120 else return -1 ;
00121
00122
00123 recipe->parameters = cpl_parameterlist_new() ;
00124
00125
00126 return 0;
00127 }
00128
00129
00135
00136 static int hawki_util_stdstars_exec(cpl_plugin * plugin)
00137 {
00138 cpl_recipe * recipe ;
00139
00140
00141 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00142 recipe = (cpl_recipe *)plugin ;
00143 else return -1 ;
00144
00145
00146 hawki_print_banner();
00147
00148 return hawki_util_stdstars(recipe->frames) ;
00149 }
00150
00151
00157
00158 static int hawki_util_stdstars_destroy(cpl_plugin * plugin)
00159 {
00160 cpl_recipe * recipe ;
00161
00162
00163 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00164 recipe = (cpl_recipe *)plugin ;
00165 else return -1 ;
00166
00167 cpl_parameterlist_delete(recipe->parameters) ;
00168 return 0 ;
00169 }
00170
00171
00177
00178 static int hawki_util_stdstars(
00179 cpl_frameset * framelist)
00180 {
00181 cpl_frameset * rawframes ;
00182 const char * recipe_name = "hawki_util_stdstars" ;
00183
00184
00185
00186 if (hawki_dfs_set_groups(framelist)) {
00187 cpl_msg_error(__func__, "Cannot identify RAW and CALIB frames") ;
00188 return -1 ;
00189 }
00190
00191
00192 if ((rawframes = hawki_extract_frameset(framelist,
00193 HAWKI_UTIL_STDSTARS_RAW)) == NULL) {
00194 cpl_msg_error(__func__, "Cannot find raw frames in the input list") ;
00195 return -1 ;
00196 }
00197
00198
00199 if (irplib_stdstar_write_catalogs(framelist,
00200 rawframes,
00201 recipe_name,
00202 HAWKI_CALPRO_STDSTARS,
00203 HAWKI_PROTYPE_STDSTARS,
00204 PACKAGE "/" PACKAGE_VERSION,
00205 "HAWKI",
00206 hawki_util_stdstars_convert) == -1) {
00207 cpl_msg_error(__func__, "Cannot write the catalogs") ;
00208 cpl_frameset_delete(rawframes) ;
00209 return -1 ;
00210 }
00211 cpl_frameset_delete(rawframes) ;
00212
00213
00214 if (cpl_error_get_code()) return -1 ;
00215 else return 0 ;
00216 }
00217
00218
00239
00240 static cpl_table * hawki_util_stdstars_convert(const char * filename)
00241 {
00242 cpl_table * out ;
00243 int nfilters ;
00244 const char * filters[4];
00245 double mags[4] ;
00246 int nbentries ;
00247 FILE * in ;
00248 char line[1024];
00249 double ra, dec ;
00250 char sname[512];
00251 char stype[512];
00252 int i ;
00253
00254
00255 if (filename == NULL) return NULL ;
00256
00257
00258 nfilters = 4 ;
00259 filters[0] = hawki_std_band_name(HAWKI_BAND_J) ;
00260 filters[1] = hawki_std_band_name(HAWKI_BAND_H) ;
00261 filters[2] = hawki_std_band_name(HAWKI_BAND_K) ;
00262 filters[3] = hawki_std_band_name(HAWKI_BAND_Y) ;
00263
00264
00265 nbentries = 0 ;
00266 if ((in = fopen(filename, "r")) == NULL) {
00267 return NULL ;
00268 }
00269 while (fgets(line, 1024, in) != NULL) {
00270 if (line[0] != '#') nbentries ++ ;
00271 }
00272 fclose(in) ;
00273
00274
00275 out = cpl_table_new(nbentries);
00276 cpl_table_new_column(out, IRPLIB_STDSTAR_STAR_COL, CPL_TYPE_STRING);
00277 cpl_table_new_column(out, IRPLIB_STDSTAR_TYPE_COL, CPL_TYPE_STRING);
00278 cpl_table_new_column(out, IRPLIB_STDSTAR_RA_COL, CPL_TYPE_DOUBLE);
00279 cpl_table_new_column(out, IRPLIB_STDSTAR_DEC_COL, CPL_TYPE_DOUBLE);
00280 for (i=0 ; i<nfilters ; i++)
00281 cpl_table_new_column(out, filters[i], CPL_TYPE_DOUBLE);
00282
00283
00284 if ((in = fopen(filename, "r")) == NULL) {
00285 cpl_table_delete(out) ;
00286 return NULL ;
00287 }
00288 nbentries = 0 ;
00289 while (fgets(line, 1024, in) != NULL) {
00290 if (line[0] != '#') {
00291 if (sscanf(line, "%s %lg %lg %s %lg %lg %lg %lg",
00292 sname, &ra, &dec, stype, &(mags[0]), &(mags[1]),
00293 &(mags[2]), &(mags[3])) != 8) {
00294 cpl_table_delete(out) ;
00295 return NULL ;
00296 }
00297 cpl_table_set_string(out, IRPLIB_STDSTAR_STAR_COL,nbentries, sname);
00298 cpl_table_set_string(out, IRPLIB_STDSTAR_TYPE_COL,nbentries, stype);
00299 cpl_table_set_double(out, IRPLIB_STDSTAR_RA_COL, nbentries, ra);
00300 cpl_table_set_double(out, IRPLIB_STDSTAR_DEC_COL, nbentries, dec);
00301 for (i=0 ; i<nfilters ; i++)
00302 cpl_table_set_double(out, filters[i], nbentries, mags[i]);
00303 nbentries ++ ;
00304 }
00305 }
00306 fclose(in) ;
00307
00308 return out ;
00309 }
00310