sinfo_utl_stdstars.c

00001 /* $Id: sinfo_utl_stdstars.c,v 1.4 2008/02/12 14:56:50 amodigli Exp $
00002  *
00003  * This file is part of the ISAAC Pipeline
00004  * Copyright (C) 2002,2003 European Southern Observatory
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 /*
00022  * $Author: amodigli $
00023  * $Date: 2008/02/12 14:56:50 $
00024  * $Revision: 1.4 $
00025  * $Name: sinfo-2_2_5 $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031 
00032 /*-----------------------------------------------------------------------------
00033                                 Includes
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 #include "isaac_utils.h"
00049 #include "isaac_pfits.h"
00050 #include "isaac_dfs.h"
00051 */
00052 
00053 /*-----------------------------------------------------------------------------
00054                             Functions prototypes
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                             Static variables
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                                 Functions code
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     /* Get the recipe out of the plugin */
00131     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00132         recipe = (cpl_recipe *)plugin ;
00133     else return -1 ;
00134 
00135     /* Create the parameters list in the cpl_recipe object */
00136     recipe->parameters = cpl_parameterlist_new() ;
00137 
00138     /* Return */
00139     return 0;
00140 }
00141 
00142 /*----------------------------------------------------------------------------*/
00148 /*----------------------------------------------------------------------------*/
00149 static int sinfo_utl_stdstars_exec(cpl_plugin * plugin)
00150 {
00151     cpl_recipe  *   recipe ;
00152 
00153     /* Get the recipe out of the plugin */
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     /* Get the recipe out of the plugin */
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     /* Identify the RAW and CALIB frames in the input frameset */
00194     if (sinfo_dfs_set_groups(framelist)) {
00195         cpl_msg_error(__func__, "Cannot identify RAW and CALIB frames") ;
00196         return -1 ;
00197     }
00198 
00199     /* Retrieve raw frames */
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     /* Write the catalog */
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     /* Check entries */
00259     if (filename == NULL) return NULL ;
00260 
00261     /* Initialise */
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     /* Get the number of lines */
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    /* Create the table */
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     /* Parse the file */
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 

Generated on 8 Mar 2011 for SINFONI Pipeline Reference Manual by  doxygen 1.6.1