sinfo_utl_line_oh_select.c

00001 /* $Id: sinfo_utl_line_oh_select.c,v 1.2 2012/08/10 07:55:03 amodigli Exp $
00002  *
00003  * This file is part of the SINFONI 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: 2012/08/10 07:55:03 $
00024  * $Revision: 1.2 $
00025  * $Name: HEAD $
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 <sinfo_utils_wrappers.h>
00041 #include <sinfo_msg.h>
00042 
00043 #include "sinfo_raw_types.h"
00044 #include "sinfo_pro_types.h"
00045 #include "sinfo_tpl_utils.h"
00046 #include "sinfo_tpl_dfs.h"
00047 
00048 
00049 /*-----------------------------------------------------------------------------
00050                             Functions prototypes
00051  -----------------------------------------------------------------------------*/
00052 
00053 static int sinfo_utl_line_oh_select_create(cpl_plugin *) ;
00054 static int sinfo_utl_line_oh_select_exec(cpl_plugin *) ;
00055 static int sinfo_utl_line_oh_select_destroy(cpl_plugin *) ;
00056 static int sinfo_utl_line_oh_select(cpl_parameterlist *, cpl_frameset *) ;
00057 
00058 /*-----------------------------------------------------------------------------
00059                             Static variables
00060  -----------------------------------------------------------------------------*/
00061 
00062 static char sinfo_utl_line_oh_select_description[] = 
00063 "sinfo_utl_line_oh_select -- SINFONI OH LINE table creation.\n"
00064 "The files listed in the Set Of Frames (sof-file) must be tagged:\n"
00065 "raw-file.fits REF_LINE_OH \n" ;
00066 
00067 /*-----------------------------------------------------------------------------
00068                                 Functions code
00069  -----------------------------------------------------------------------------*/
00070 
00071 /*----------------------------------------------------------------------------*/
00079 /*----------------------------------------------------------------------------*/
00080 int cpl_plugin_get_info(cpl_pluginlist * list)
00081 {
00082     cpl_recipe  *   recipe = cpl_calloc(1, sizeof(*recipe)) ;
00083     cpl_plugin  *   plugin = &recipe->interface ;
00084 
00085     cpl_plugin_init(plugin,
00086                     CPL_PLUGIN_API,
00087                     SINFONI_BINARY_VERSION,
00088                     CPL_PLUGIN_TYPE_RECIPE,
00089                     "sinfo_utl_line_oh_select",
00090                     "OH line table creation",
00091                     sinfo_utl_line_oh_select_description,
00092                     "Andrea Modigliani",
00093                     "amodigli@eso.org",
00094                     sinfo_get_license(),
00095                     sinfo_utl_line_oh_select_create,
00096                     sinfo_utl_line_oh_select_exec,
00097                     sinfo_utl_line_oh_select_destroy) ;
00098 
00099     cpl_pluginlist_append(list, plugin) ;
00100     
00101     return 0;
00102 }
00103 
00104 /*----------------------------------------------------------------------------*/
00113 /*----------------------------------------------------------------------------*/
00114 static int sinfo_utl_line_oh_select_create(cpl_plugin * plugin)
00115 {
00116     cpl_recipe      * recipe ;
00117     cpl_parameter* p=NULL;
00118 
00119     /* Get the recipe out of the plugin */
00120     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00121         recipe = (cpl_recipe *)plugin ;
00122     else return -1 ;
00123 
00124     /* Create the parameters list in the cpl_recipe object */
00125     recipe->parameters = cpl_parameterlist_new() ;
00126   
00127     /* --doubleopt */
00128     p = cpl_parameter_new_range("sinfoni.sinfo_utl_line_oh_select.wmin", 
00129                                 CPL_TYPE_DOUBLE, "wmin", 
00130                                "sinfoni.sinfo_utl_line_oh_select", 
00131                                 1040.,1000.,2500.) ;
00132     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "wmin") ;
00133     cpl_parameterlist_append(recipe->parameters, p) ;
00134 
00135 
00136     p = cpl_parameter_new_range("sinfoni.sinfo_utl_line_oh_select.wmax", 
00137                                 CPL_TYPE_DOUBLE, "wmax", 
00138                                "sinfoni.sinfo_utl_line_oh_select", 
00139                                 1880.,1000.,2500.) ;
00140     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "wmax") ;
00141     cpl_parameterlist_append(recipe->parameters, p) ;
00142 
00143     p = cpl_parameter_new_value("sinfoni.sinfo_utl_line_oh_select.intnorm", 
00144                                 CPL_TYPE_DOUBLE, "intnorm", 
00145                                "sinfoni.sinfo_utl_line_oh_select", 
00146                                 4.) ;
00147     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "intnorm") ;
00148     cpl_parameterlist_append(recipe->parameters, p) ;
00149 
00150     p = cpl_parameter_new_value("sinfoni.sinfo_utl_line_oh_select.intlimit", 
00151                                 CPL_TYPE_DOUBLE, "intlimit", 
00152                                "sinfoni.sinfo_utl_line_oh_select", 
00153                                 50.) ;
00154     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "intlimit") ;
00155     cpl_parameterlist_append(recipe->parameters, p) ;
00156 
00157 
00158 
00159 
00160     /* Return */
00161     return 0;
00162 }
00163 
00164 /*----------------------------------------------------------------------------*/
00170 /*----------------------------------------------------------------------------*/
00171 static int sinfo_utl_line_oh_select_exec(cpl_plugin * plugin)
00172 {
00173     cpl_recipe  *   recipe ;
00174 
00175     /* Get the recipe out of the plugin */
00176     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00177         recipe = (cpl_recipe *)plugin ;
00178     else return -1 ;
00179 
00180     return sinfo_utl_line_oh_select(recipe->parameters, recipe->frames) ;
00181 }
00182 
00183 /*----------------------------------------------------------------------------*/
00189 /*----------------------------------------------------------------------------*/
00190 static int sinfo_utl_line_oh_select_destroy(cpl_plugin * plugin)
00191 {
00192     cpl_recipe  *   recipe ;
00193 
00194     /* Get the recipe out of the plugin */
00195     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00196         recipe = (cpl_recipe *)plugin ;
00197     else return -1 ;
00198 
00199     cpl_parameterlist_delete(recipe->parameters) ;
00200     return 0 ;
00201 }
00202 
00203 /*----------------------------------------------------------------------------*/
00210 /*----------------------------------------------------------------------------*/
00211 static int sinfo_utl_line_oh_select(
00212         cpl_parameterlist   *   parlist, 
00213         cpl_frameset        *   framelist)
00214 {
00215    cpl_parameter* p=NULL;
00216    cpl_frame* frame=NULL;
00217 
00218     cpl_frameset    *   rawframes ;
00219     int                 nframes;
00220     cpl_propertylist* phead=NULL;
00221     cpl_table       *   tab_in ;
00222     cpl_table       *   tab_ou ;
00223 
00224     int nm2AA=10.;
00225 
00226   
00227     double wmin=0;
00228     double wmax=0;
00229     double intnorm=0;
00230     double intlimit=0;
00231     int next=0;
00232     int nrow=0;
00233     /* Identify the RAW and CALIB frames in the input frameset */
00234     if (sinfo_dfs_set_groups(framelist)) {
00235         cpl_msg_error(__func__, "Cannot identify RAW and CALIB frames") ;
00236         return -1 ;
00237     }
00238 
00239     /* Retrieve raw frames */
00240     if ((rawframes = sinfo_extract_frameset(framelist,
00241                     "REF_LINE_OH")) == NULL) {
00242         cpl_msg_error(__func__, "Cannot find raw frames in the input list") ;
00243         return -1 ;
00244     }
00245 
00246     p=cpl_parameterlist_find(parlist, "sinfoni.sinfo_utl_line_oh_select.wmin");
00247     wmin = cpl_parameter_get_double(p);
00248 
00249     p=cpl_parameterlist_find(parlist, "sinfoni.sinfo_utl_line_oh_select.wmax");
00250     wmax = cpl_parameter_get_double(p);
00251 
00252     p=cpl_parameterlist_find(parlist, "sinfoni.sinfo_utl_line_oh_select.intnorm");
00253     intnorm = cpl_parameter_get_double(p);
00254     p=cpl_parameterlist_find(parlist, "sinfoni.sinfo_utl_line_oh_select.intlimit");
00255     intlimit = cpl_parameter_get_double(p);
00256 
00257     nframes = cpl_frameset_get_size(rawframes) ;
00258  
00259     /* Load */
00260     if(nframes > 0) {
00261        frame=cpl_frameset_get_frame(rawframes,0);
00262     }
00263     tab_in=cpl_table_load(cpl_frame_get_filename(frame),1,0);
00264     nrow=cpl_table_get_nrow(tab_in);
00265 
00266     cpl_table_divide_scalar(tab_in,"wave",nm2AA);
00267     cpl_table_divide_scalar(tab_in,"int",intnorm);
00268     sinfo_msg("wmin=%g wmax=%g",wmin,wmax);
00269     sinfo_msg("nrow=%d",nrow);
00270     cpl_table_dump(tab_in,1,2,stdout);
00271     cpl_table_dump(tab_in,nrow-10,2,stdout);
00272     next=cpl_table_and_selected_double(tab_in,"wave",CPL_GREATER_THAN,wmin);
00273     sinfo_msg("next=%d",next);
00274     next=cpl_table_and_selected_double(tab_in,"wave",CPL_LESS_THAN,wmax);
00275     sinfo_msg("next=%d",next);
00276     next=cpl_table_and_selected_double(tab_in,"int",CPL_GREATER_THAN,intlimit);
00277     sinfo_msg("next=%d",next);
00278     tab_ou=cpl_table_extract_selected(tab_in);
00279 
00280     cpl_table_save(tab_ou,phead,NULL,"oh_selected.fits",CPL_IO_DEFAULT);
00281     
00282     /* Free and return */
00283     sinfo_free_table(&tab_in);
00284     sinfo_free_table(&tab_ou);
00285     sinfo_free_propertylist(&phead);
00286 
00287 
00288     return 0 ;
00289 }
00290 
00291 
00292 

Generated on 3 Mar 2013 for SINFONI Pipeline Reference Manual by  doxygen 1.6.1