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 "isaac_physicalmodel.h"
00040 #include "isaac_utils.h"
00041 
00042 
00043 
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 
00053 
00054 
00055 static char isaac_spc_wlmodel_description[] = 
00056 "isaac_spc_wlmodel -- ISAAC spectro wavelength model\n";
00057 
00058 
00059 
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     
00111     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00112         recipe = (cpl_recipe *)plugin;
00113     else return -1;
00114 
00115     
00116     recipe->parameters = cpl_parameterlist_new();
00117 
00118     
00119     
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     
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     
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     
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     
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     
00204     par = NULL;
00205 
00206     
00207     
00208     par = cpl_parameterlist_find(parlist, "isaac.isaac_spc_wlmodel.wcen");
00209     wcen = cpl_parameter_get_double(par);
00210 
00211     
00212     par = cpl_parameterlist_find(parlist, "isaac.isaac_spc_wlmodel.obj");
00213     obj = cpl_parameter_get_string(par);
00214 
00215     
00216     par = cpl_parameterlist_find(parlist, "isaac.isaac_spc_wlmodel.res");
00217     res = cpl_parameter_get_string(par);
00218 
00219     
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     
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