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 "sinfo_raw_types.h"
00043 #include "sinfo_pro_types.h"
00044 #include "sinfo_tpl_utils.h"
00045 #include "sinfo_tpl_dfs.h"
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 static int sinfo_utl_stdstars_create(cpl_plugin *) ;
00058 static int sinfo_utl_stdstars_exec(cpl_plugin *) ;
00059 static int sinfo_utl_stdstars_destroy(cpl_plugin *) ;
00060 static int sinfo_utl_stdstars(cpl_frameset *) ;
00061 static cpl_table * sinfo_utl_stdstars_convert(const char *) ;
00062
00063
00064
00065
00066
00067 static char sinfo_utl_stdstars_description[] =
00068 "sinfo_utl_stdstars -- SINFONI standard stars catalog creation.\n"
00069 "The files listed in the Set Of Frames (sof-file) must be tagged:\n"
00070 "raw-file.fits "SINFO_UTL_STDSTARS_RAW"\n" ;
00071
00072
00073
00074
00075
00076
00077
00081
00082
00083
00091
00092 int cpl_plugin_get_info(cpl_pluginlist * list)
00093 {
00094 cpl_recipe * recipe = cpl_calloc(1, sizeof(*recipe)) ;
00095 cpl_plugin * plugin = &recipe->interface ;
00096
00097 cpl_plugin_init(plugin,
00098 CPL_PLUGIN_API,
00099 SINFONI_BINARY_VERSION,
00100 CPL_PLUGIN_TYPE_RECIPE,
00101 "sinfo_utl_stdstars",
00102 "Standard stars catalog creation",
00103 sinfo_utl_stdstars_description,
00104 "Andrea Modigliani",
00105 "amodigli@eso.org",
00106 sinfo_get_license(),
00107 sinfo_utl_stdstars_create,
00108 sinfo_utl_stdstars_exec,
00109 sinfo_utl_stdstars_destroy) ;
00110
00111 cpl_pluginlist_append(list, plugin) ;
00112
00113 return 0;
00114 }
00115
00116
00125
00126 static int sinfo_utl_stdstars_create(cpl_plugin * plugin)
00127 {
00128 cpl_recipe * recipe ;
00129
00130
00131 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00132 recipe = (cpl_recipe *)plugin ;
00133 else return -1 ;
00134
00135
00136 recipe->parameters = cpl_parameterlist_new() ;
00137
00138
00139 return 0;
00140 }
00141
00142
00148
00149 static int sinfo_utl_stdstars_exec(cpl_plugin * plugin)
00150 {
00151 cpl_recipe * recipe ;
00152
00153
00154 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00155 recipe = (cpl_recipe *)plugin ;
00156 else return -1 ;
00157
00158 return sinfo_utl_stdstars(recipe->frames) ;
00159 }
00160
00161
00167
00168 static int sinfo_utl_stdstars_destroy(cpl_plugin * plugin)
00169 {
00170 cpl_recipe * recipe ;
00171
00172
00173 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00174 recipe = (cpl_recipe *)plugin ;
00175 else return -1 ;
00176
00177 cpl_parameterlist_delete(recipe->parameters) ;
00178 return 0 ;
00179 }
00180
00181
00187
00188 static int sinfo_utl_stdstars(
00189 cpl_frameset * framelist)
00190 {
00191 cpl_frameset * rawframes ;
00192
00193
00194 if (sinfo_dfs_set_groups(framelist)) {
00195 cpl_msg_error(__func__, "Cannot identify RAW and CALIB frames") ;
00196 return -1 ;
00197 }
00198
00199
00200 if ((rawframes = sinfo_extract_frameset(framelist,
00201 SINFO_UTL_STDSTARS_RAW)) == NULL) {
00202 cpl_msg_error(__func__, "Cannot find raw frames in the input list") ;
00203 return -1 ;
00204 }
00205
00206
00207 if (irplib_stdstar_write_catalogs(framelist,
00208 rawframes,
00209 "sinfo_utl_stdstars",
00210 SINFO_UTL_STDSTARS_RES, NULL,
00211 PACKAGE "/" PACKAGE_VERSION,
00212 "SINFONI",
00213 sinfo_utl_stdstars_convert) == -1) {
00214 cpl_msg_error(__func__, "Cannot write the catalogs") ;
00215 cpl_frameset_delete(rawframes) ;
00216 return -1 ;
00217 }
00218 cpl_frameset_delete(rawframes) ;
00219 return 0 ;
00220 }
00221
00222
00243
00244 static cpl_table * sinfo_utl_stdstars_convert(const char * filename)
00245 {
00246 cpl_table * out ;
00247 int nfilters ;
00248 const char * filters[8];
00249 double mags[8] ;
00250 int nbentries ;
00251 FILE * in ;
00252 char line[1024];
00253 double ra, dec ;
00254 char sname[512];
00255 char stype[512];
00256 int i ;
00257
00258
00259 if (filename == NULL) return NULL ;
00260
00261
00262 nfilters = 8 ;
00263 filters[0] = "J" ;
00264 filters[1] = "H" ;
00265 filters[2] = "K" ;
00266 filters[3] = "Ks" ;
00267 filters[4] = "L" ;
00268 filters[5] = "M" ;
00269 filters[6] = "Lp" ;
00270 filters[7] = "Mp" ;
00271
00272
00273 nbentries = 0 ;
00274 if ((in = fopen(filename, "r")) == NULL) {
00275 return NULL ;
00276 }
00277 while (fgets(line, 1024, in) != NULL) {
00278 if (line[0] != '#') nbentries ++ ;
00279 }
00280 fclose(in) ;
00281
00282
00283 out = cpl_table_new(nbentries);
00284 cpl_table_new_column(out, IRPLIB_STDSTAR_STAR_COL, CPL_TYPE_STRING);
00285 cpl_table_new_column(out, IRPLIB_STDSTAR_TYPE_COL, CPL_TYPE_STRING);
00286 cpl_table_new_column(out, IRPLIB_STDSTAR_RA_COL, CPL_TYPE_DOUBLE);
00287 cpl_table_new_column(out, IRPLIB_STDSTAR_DEC_COL, CPL_TYPE_DOUBLE);
00288 for (i=0 ; i<nfilters ; i++)
00289 cpl_table_new_column(out, filters[i], CPL_TYPE_DOUBLE);
00290
00291
00292 if ((in = fopen(filename, "r")) == NULL) {
00293 cpl_table_delete(out) ;
00294 return NULL ;
00295 }
00296 nbentries = 0 ;
00297 while (fgets(line, 1024, in) != NULL) {
00298 if (line[0] != '#') {
00299 if (sscanf(line, "%s %lg %lg %s %lg %lg %lg %lg %lg %lg %lg %lg",
00300 sname, &ra, &dec, stype, &(mags[0]), &(mags[1]),
00301 &(mags[2]), &(mags[3]), &(mags[4]), &(mags[5]),
00302 &(mags[6]), &(mags[7])) != 12) {
00303 cpl_table_delete(out) ;
00304 return NULL ;
00305 }
00306 cpl_table_set_string(out, IRPLIB_STDSTAR_STAR_COL,nbentries, sname);
00307 cpl_table_set_string(out, IRPLIB_STDSTAR_TYPE_COL,nbentries, stype);
00308 cpl_table_set_double(out, IRPLIB_STDSTAR_RA_COL, nbentries, ra);
00309 cpl_table_set_double(out, IRPLIB_STDSTAR_DEC_COL, nbentries, dec);
00310 for (i=0 ; i<nfilters ; i++)
00311 cpl_table_set_double(out, filters[i], nbentries, mags[i]);
00312 nbentries ++ ;
00313 }
00314 }
00315 fclose(in) ;
00316
00317 return out ;
00318 }
00319