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 "sofi_utils.h"
00043 #include "sofi_pfits.h"
00044 #include "sofi_dfs.h"
00045
00046
00047
00048
00049
00050 static int sofi_util_stdstars_create(cpl_plugin *) ;
00051 static int sofi_util_stdstars_exec(cpl_plugin *) ;
00052 static int sofi_util_stdstars_destroy(cpl_plugin *) ;
00053 static int sofi_util_stdstars(cpl_frameset *) ;
00054 static cpl_table * sofi_util_stdstars_convert(const char *) ;
00055
00056
00057
00058
00059
00060 static char sofi_util_stdstars_description[] =
00061 "sofi_util_stdstars -- SOFI standard stars catalog creation.\n"
00062 "The files listed in the Set Of Frames (sof-file) must be tagged:\n"
00063 "raw-file.fits "SOFI_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 SOFI_BINARY_VERSION,
00086 CPL_PLUGIN_TYPE_RECIPE,
00087 "sofi_util_stdstars",
00088 "Standard stars catalog creation",
00089 sofi_util_stdstars_description,
00090 "Yves Jung",
00091 "yjung@eso.org",
00092 sofi_get_license(),
00093 sofi_util_stdstars_create,
00094 sofi_util_stdstars_exec,
00095 sofi_util_stdstars_destroy) ;
00096
00097 cpl_pluginlist_append(list, plugin) ;
00098
00099 return 0;
00100 }
00101
00102
00111
00112 static int sofi_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 sofi_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 sofi_util_stdstars(recipe->frames) ;
00145 }
00146
00147
00153
00154 static int sofi_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 sofi_util_stdstars(
00175 cpl_frameset * framelist)
00176 {
00177 cpl_frameset * rawframes ;
00178
00179
00180 if (sofi_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 = sofi_extract_frameset(framelist,
00187 SOFI_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 "sofi_util_stdstars",
00196 SOFI_UTIL_STDSTARS_RES,
00197 NULL,
00198 PACKAGE "/" PACKAGE_VERSION,
00199 "SOFI",
00200 sofi_util_stdstars_convert)) {
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 * sofi_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) {
00247 return NULL;
00248 (void)cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT);
00249 }
00250
00251
00252 nfilters = 8 ;
00253 filters[0] = "J" ;
00254 filters[1] = "H" ;
00255 filters[2] = "K" ;
00256 filters[3] = "Ks" ;
00257 filters[4] = "L" ;
00258 filters[5] = "M" ;
00259 filters[6] = "Lp" ;
00260 filters[7] = "Mp" ;
00261
00262
00263 nbentries = 0 ;
00264 if ((in = fopen(filename, "r")) == NULL) {
00265 (void)cpl_error_set(cpl_func, CPL_ERROR_FILE_IO);
00266 return NULL ;
00267 }
00268 while (fgets(line, 1024, in) != NULL) {
00269 if (line[0] != '#') nbentries ++ ;
00270 }
00271 rewind(in);
00272
00273
00274 out = cpl_table_new(nbentries);
00275 cpl_table_new_column(out, IRPLIB_STDSTAR_STAR_COL, CPL_TYPE_STRING);
00276 cpl_table_new_column(out, IRPLIB_STDSTAR_TYPE_COL, CPL_TYPE_STRING);
00277 cpl_table_new_column(out, IRPLIB_STDSTAR_RA_COL, CPL_TYPE_DOUBLE);
00278 cpl_table_new_column(out, IRPLIB_STDSTAR_DEC_COL, CPL_TYPE_DOUBLE);
00279 for (i=0 ; i<nfilters ; i++)
00280 cpl_table_new_column(out, filters[i], CPL_TYPE_DOUBLE);
00281
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 fclose(in);
00291 cpl_table_delete(out) ;
00292 (void)cpl_error_set(cpl_func, CPL_ERROR_BAD_FILE_FORMAT);
00293 return NULL ;
00294 }
00295 cpl_table_set_string(out, IRPLIB_STDSTAR_STAR_COL, nbentries,sname);
00296 cpl_table_set_string(out, IRPLIB_STDSTAR_TYPE_COL, nbentries,stype);
00297 cpl_table_set_double(out, IRPLIB_STDSTAR_RA_COL, nbentries, ra);
00298 cpl_table_set_double(out, IRPLIB_STDSTAR_DEC_COL, nbentries, dec);
00299 for (i=0 ; i<nfilters ; i++)
00300 cpl_table_set_double(out, filters[i], nbentries, mags[i]);
00301 nbentries ++ ;
00302 }
00303 }
00304 fclose(in) ;
00305
00306 if (cpl_table_get_nrow(out) == 0) {
00307 cpl_table_delete(out);
00308 (void)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
00309 "Empty catalogue in '%s'", filename);
00310 return NULL ;
00311 }
00312
00313 return out ;
00314 }
00315