isaac_spc_wlmodel.c

00001 /* $Id: isaac_spc_wlmodel.c,v 1.6 2012/01/12 11:57:51 llundin 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: llundin $
00023  * $Date: 2012/01/12 11:57:51 $
00024  * $Revision: 1.6 $
00025  * $Name: isaac-6_1_0 $
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 "isaac_physicalmodel.h"
00040 #include "isaac_utils.h"
00041 
00042 /*-----------------------------------------------------------------------------
00043                             Functions prototypes
00044  -----------------------------------------------------------------------------*/
00045 
00046 static int isaac_spc_wlmodel_create(cpl_plugin *);
00047 static int isaac_spc_wlmodel_exec(cpl_plugin *);
00048 static int isaac_spc_wlmodel_destroy(cpl_plugin *);
00049 static int isaac_spc_wlmodel(cpl_parameterlist *);
00050  
00051 /*-----------------------------------------------------------------------------
00052                             Static variables
00053  -----------------------------------------------------------------------------*/
00054 
00055 static char isaac_spc_wlmodel_description[] = 
00056 "isaac_spc_wlmodel -- ISAAC spectro wavelength model\n";
00057 
00058 /*-----------------------------------------------------------------------------
00059                                 Functions code
00060  -----------------------------------------------------------------------------*/
00061 
00062 /*----------------------------------------------------------------------------*/
00070 /*----------------------------------------------------------------------------*/
00071 int cpl_plugin_get_info(cpl_pluginlist * list)
00072 {
00073     cpl_recipe  *   recipe = cpl_calloc(1, sizeof(*recipe));
00074     cpl_plugin  *   plugin = &recipe->interface;
00075 
00076     cpl_plugin_init(plugin,
00077                     CPL_PLUGIN_API,
00078                     ISAAC_BINARY_VERSION,
00079                     CPL_PLUGIN_TYPE_RECIPE,
00080                     "isaac_spc_wlmodel",
00081                     "Spectro wavelength model recipe",
00082                     isaac_spc_wlmodel_description,
00083                     "Lars Lundin",
00084                     PACKAGE_BUGREPORT,
00085                     isaac_get_license(),
00086                     isaac_spc_wlmodel_create,
00087                     isaac_spc_wlmodel_exec,
00088                     isaac_spc_wlmodel_destroy);
00089 
00090     cpl_pluginlist_append(list, plugin);
00091     
00092     return 0;
00093 }
00094 
00095 /*----------------------------------------------------------------------------*/
00104 /*----------------------------------------------------------------------------*/
00105 static int isaac_spc_wlmodel_create(cpl_plugin * plugin)
00106 {
00107     cpl_recipe      * recipe;
00108     cpl_parameter   * p;
00109 
00110     /* Get the recipe out of the plugin */
00111     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00112         recipe = (cpl_recipe *)plugin;
00113     else return -1;
00114 
00115     /* Create the parameters list in the cpl_recipe object */
00116     recipe->parameters = cpl_parameterlist_new();
00117 
00118     /* Fill the parameters list */
00119     /* --wcen */
00120     p = cpl_parameter_new_value("isaac.isaac_spc_wlmodel.wcen",CPL_TYPE_DOUBLE,
00121             "the central wavelength in angstroms", "isaac.isaac_spc_wlmodel", 
00122             22000.0);
00123     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "wcen");
00124     cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
00125     cpl_parameterlist_append(recipe->parameters, p);
00126 
00127     /* --obj */
00128     p = cpl_parameter_new_value("isaac.isaac_spc_wlmodel.obj",
00129             CPL_TYPE_STRING, "objective (S1/S2/L1/L2/L3)", 
00130             "isaac.isaac_spc_wlmodel", "S2");
00131     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "obj");
00132     cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
00133     cpl_parameterlist_append(recipe->parameters, p);
00134 
00135     /* --res */
00136     p = cpl_parameter_new_value("isaac.isaac_spc_wlmodel.res",
00137             CPL_TYPE_STRING, "resolution (LR/MR)", 
00138             "isaac.isaac_spc_wlmodel", "MR");
00139     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "res");
00140     cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
00141     cpl_parameterlist_append(recipe->parameters, p);
00142 
00143     return 0;
00144 }
00145 
00146 /*----------------------------------------------------------------------------*/
00152 /*----------------------------------------------------------------------------*/
00153 static int isaac_spc_wlmodel_exec(cpl_plugin * plugin)
00154 {
00155     cpl_recipe  *   recipe;
00156 
00157     /* Get the recipe out of the plugin */
00158     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00159         recipe = (cpl_recipe *)plugin;
00160     else return -1;
00161 
00162     return isaac_spc_wlmodel(recipe->parameters);
00163 }
00164 
00165 /*----------------------------------------------------------------------------*/
00171 /*----------------------------------------------------------------------------*/
00172 static int isaac_spc_wlmodel_destroy(cpl_plugin * plugin)
00173 {
00174     cpl_recipe  *   recipe;
00175 
00176     /* Get the recipe out of the plugin */
00177     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00178         recipe = (cpl_recipe *)plugin;
00179     else return -1;
00180 
00181     cpl_parameterlist_delete(recipe->parameters);
00182     return 0;
00183 }
00184 
00185 /*----------------------------------------------------------------------------*/
00192 /*----------------------------------------------------------------------------*/
00193 static int isaac_spc_wlmodel(cpl_parameterlist * parlist)
00194 {
00195     cpl_parameter       *   par;
00196     double              *   wlcal;
00197     double                  wcen;
00198     const char          *   obj;
00199     const char          *   res;
00200     FILE                *   fp;
00201     int                     i;
00202     
00203     /* Initialise */
00204     par = NULL;
00205 
00206     /* Retrieve input parameters */
00207     /* --wcen */
00208     par = cpl_parameterlist_find(parlist, "isaac.isaac_spc_wlmodel.wcen");
00209     wcen = cpl_parameter_get_double(par);
00210 
00211     /* --obj */
00212     par = cpl_parameterlist_find(parlist, "isaac.isaac_spc_wlmodel.obj");
00213     obj = cpl_parameter_get_string(par);
00214 
00215     /* --res */
00216     par = cpl_parameterlist_find(parlist, "isaac.isaac_spc_wlmodel.res");
00217     res = cpl_parameter_get_string(par);
00218 
00219     /* Physical model */
00220     wlcal = isaac_physical_model(wcen, obj, res, 1024);
00221     if (wlcal == NULL) {
00222         cpl_msg_error(cpl_func, "Cannot compute the physical model");
00223         return -1;
00224     } 
00225             
00226     /* Save results */
00227     if ((fp = fopen("wavecal.txt", "w")) == NULL) {
00228         cpl_msg_error(cpl_func, "Cannot open the output file");
00229         cpl_free(wlcal);
00230         return -1;
00231     } 
00232     for (i=0; i<1024; i++) fprintf(fp, "%d\t\t%g\n", i+1, wlcal[i]);
00233     fclose(fp);
00234     cpl_free(wlcal);
00235     return 0;
00236 }
00237 

Generated on Mon Feb 6 14:44:02 2012 for ISAAC Pipeline Reference Manual by  doxygen 1.5.8