si_step_distortion.c

00001 /* $Id: si_step_distortion.c,v 1.18 2005/10/08 10:34:50 amodigli Exp $
00002  *
00003  * This file is part of the CPL (Common Pipeline Library)
00004  * Copyright (C) 2002 European Southern Observatory
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library 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 GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; 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: 2005/10/08 10:34:50 $
00024  * $Revision: 1.18 $
00025  * $Name:  $
00026  */
00027 
00028  /****************************************************************
00029   *          Distortion Frames Data Reduction                          *
00030   ****************************************************************/
00031 #include <strings.h>
00032 #include <string.h>
00033 
00034 #include <stdio.h>
00035 
00036 #ifdef HAVE_CONFIG_H
00037 #include <config.h>          
00038 #endif
00039 
00040 #include <cxmacros.h>
00041 #include <cxtypes.h>
00042 #include <cxmessages.h>     
00043 #include <qfits.h>      
00044 #include <cpl.h>      
00045 
00046 
00047 #include <sinfoni_key_names.h>
00048 #include <sinfoni_globals.h>
00049 #include <sinfoni_pro_types.h>
00050 #include <sinfoni_prepare_stacked_frames_config.h>
00051 #include <sinfoni_north_south_test_config.h>
00052 
00053 #include <prepare_stacked_frames.h>
00054 #include <sinfoni_distortion_config.h>
00055 #include <find_distortions.h>
00056 #include <nst.h>
00057 #include <sinfoni_hidden.h>
00058 #include <sinfoni_tpl_dfs.h>
00059 #include <sinfoni_globals.h>
00060 #include <sinfoni_functions.h>
00061 #include <sinfoni_memory.h>
00062 
00063 static cxint si_step_distortion(cpl_parameterlist *, cpl_frameset *);
00064 const char * sinfoni_get_licence(void);
00065 cxint si_step_distortion_create(cpl_plugin *plugin);
00066 cxint si_step_distortion_exec(cpl_plugin *plugin);
00067 cxint si_step_distortion_destroy(cpl_plugin *plugin);
00068 static cxint si_step_distortion(cpl_parameterlist *config, cpl_frameset *set);
00069 int cpl_plugin_get_info(cpl_pluginlist *list);
00070 void sinfoni_find_distortion_config_add(cpl_parameterlist *); 
00071 
00072 const char * sinfoni_get_licence(void)
00073 {
00074   return "bla bla";
00075 
00076 } 
00077 
00078  /*
00079   *
00080   * Create the recipe instance, i.e. setup the parameter list for this
00081   * recipe and make it available to the application using the interface.
00082   *
00083   */
00084 
00085 
00086 cxint
00087 si_step_distortion_create(cpl_plugin *plugin)
00088 {
00089 
00090   /*
00091    * We have to provide the option we accept to the application.
00092    * We need to setup our parameter list and hook it into the recipe
00093    * interface.
00094    */
00095   cpl_recipe *recipe = (cpl_recipe *)plugin;
00096   recipe->parameters = cpl_parameterlist_new();
00097   if(recipe->parameters == NULL) {
00098     return 1;
00099   }
00100 
00101   /*
00102    * Fill the parameter list.
00103    */
00104   sinfoni_prepare_stacked_frames_config_add(recipe->parameters);
00105   sinfoni_distortion_config_add(recipe->parameters);
00106   sinfoni_north_south_test_config_add(recipe->parameters);
00107 
00108   return 0;
00109 
00110 }
00111 
00112 cxint
00113 si_step_distortion_exec(cpl_plugin *plugin)
00114 {
00115 
00116   cpl_recipe *recipe = (cpl_recipe *) plugin;
00117   if(recipe->parameters == NULL) {
00118     return 1;
00119   }
00120   if(recipe->frames == NULL) {
00121     return 1;
00122   }
00123 
00124   cpl_error_reset();
00125   return si_step_distortion(recipe->parameters, recipe->frames);
00126 
00127 }
00128 
00129 cxint
00130 si_step_distortion_destroy(cpl_plugin *plugin)
00131 {
00132 
00133   cpl_recipe *recipe = (cpl_recipe *) plugin;
00134   /*
00135    * We just destroy what was created during the plugin initializzation phase
00136    * i.e. the parameter list. The frame set is managed by the application which
00137    * called us, so that we must not touch it.
00138    */
00139 
00140   cpl_parameterlist_delete(recipe->parameters);
00141 
00142   return 0;
00143 
00144 }
00145 
00146 int
00147 cpl_plugin_get_info(cpl_pluginlist *list)
00148 {
00149 
00150   cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
00151   cpl_plugin *plugin = &recipe->interface;
00152 
00153 
00154   cpl_plugin_init(plugin,
00155           CPL_PLUGIN_API,
00156           SINFONI_BINARY_VERSION,
00157           CPL_PLUGIN_TYPE_RECIPE,
00158           "si_step_distortion",
00159           "Find Distortions in frames",
00160           "TBD",
00161           "A. Modigliani",
00162           "amodigli@eso.org",
00163           "No license",
00164           si_step_distortion_create,
00165           si_step_distortion_exec,
00166           si_step_distortion_destroy);
00167 
00168   cpl_pluginlist_append(list, plugin);
00169 
00170   return 0;
00171 
00172 }
00173 
00174 
00175 /*
00176  * The actual recipe actually start here.
00177  */
00178 
00179 static cxint
00180 si_step_distortion(cpl_parameterlist *config, cpl_frameset *set)
00181 {
00182  
00183   const char *_id = "si_step_distortion";
00184  
00185   int  ind =0;
00186 
00187   cpl_frame* frame=NULL;
00188   char file_name[FILE_NAME_SZ];
00189   cpl_propertylist* plist=NULL;
00190 
00191   cpl_image* ima=NULL;
00192   fake* fk=fake_new();
00193 
00194    if(sinfoni_dfs_set_groups(set)) {
00195        cpl_msg_error(_id, "Cannot indentify RAW and CALIB frames") ;
00196        return -1;
00197     }
00198 
00199 
00200 
00201     /* 
00202        ---------------------------------------------------------
00203                 DISTORTIONS 
00204        ---------------------------------------------------------
00205      */
00206    
00207 
00208     {
00209       
00210     cpl_msg_info(_id,"COMPUTE DISTORTIONS\n") ; 
00211          if ( -1 == (ind = find_distortions(_id,config, set ) ) )
00212         {
00213         cpl_msg_error(_id,"step_distortion(), no: %d\n", ind) ;
00214             fake_delete(fk);
00215         return -1 ;
00216     }
00217    
00218         if(NULL != cpl_frameset_find(set,PRO_FIBRE_NS_STACKED)) {
00219             frame = cpl_frameset_find(set,PRO_FIBRE_NS_STACKED);
00220             strcpy(file_name,cpl_frame_get_filename(frame));
00221         } else {
00222             cpl_msg_error(_id,"Frame %s not found!", PRO_FIBRE_NS_STACKED);
00223             fake_delete(fk);
00224             return -1;
00225     }
00226         ima=cpl_image_load(file_name,CPL_TYPE_FLOAT,0,0);
00227 
00228         if ((cpl_error_code)((plist = cpl_propertylist_load(file_name, 0)) == NULL)) {
00229            cpl_msg_error(_id, "getting header from reference ima frame %s",file_name);
00230            cpl_propertylist_delete(plist) ;
00231             fake_delete(fk);
00232            return -1 ;
00233     }
00234 
00235         if (cpl_propertylist_contains(plist, KEY_NAME_LAMP_HALO)) {
00236             cpl_propertylist_set_bool(plist, KEY_NAME_LAMP_HALO, LAMP_ON);
00237         } else {
00238             cpl_propertylist_append_bool(plist, KEY_NAME_LAMP_HALO,LAMP_ON) ;
00239         }
00240      
00241 
00242 
00243         /* Save the file */
00244     /*
00245         if (cpl_image_save(ima, file_name, CPL_BPP_DEFAULT, plist,CPL_IO_DEFAULT)!=CPL_ERROR_NONE) {
00246            cpl_msg_error(_id, "Cannot save the product %s",file_name);
00247            cpl_propertylist_delete(plist) ;
00248           return -1 ;
00249     }
00250     */
00251      
00252         cpl_propertylist_delete(plist);
00253     cpl_msg_info(_id,"SUCCESS: COMPUTED DISTORTIONS\n") ; 
00254     }
00255    cpl_image_delete(ima);
00256    sinfoni_memory_status();
00257     /* 
00258        ---------------------------------------------------------
00259        4th iteration: distort fake frame
00260        ---------------------------------------------------------
00261      */
00262 
00263   
00264      {
00265     cpl_msg_info (_id,"DISTORT FAKE FRAME\n") ; 
00266 
00267         strcpy(fk->pro_class,PRO_FIBRE_NS_STACKED);
00268         fk->frm_switch=1;
00269         fk->mask_index=1;
00270         fk->ind_index=1;
00271         fk->flat_index=0;
00272         fk->wfix_index=1;
00273         fk->low_rej=0.0;
00274         fk->hig_rej=0.0;
00275 
00276 
00277         if ( -1 == (ind = prepare_stacked_frames(_id,config, set, PRO_FIBRE_NS_STACKED_DIST, 0,fk) ) )
00278         {
00279         cpl_msg_error(_id," no: %d\n", ind) ;
00280             fake_delete(fk);
00281         return -1 ;
00282     }
00283     cpl_msg_info (_id,"SUCCESS: DISTORTED FAKE FRAME\n") ; 
00284         fake_delete(fk);
00285     
00286 
00287         if(NULL != cpl_frameset_find(set,PRO_FIBRE_NS_STACKED_DIST)) {
00288             frame = cpl_frameset_find(set,PRO_FIBRE_NS_STACKED_DIST);
00289             strcpy(file_name,cpl_frame_get_filename(frame));
00290         } else {
00291             cpl_msg_error(_id,"Frame %s not found!", PRO_FIBRE_NS_STACKED_DIST);
00292             return -1;
00293     }
00294         ima=cpl_image_load(file_name,CPL_TYPE_FLOAT,0,0);
00295 
00296 
00297     
00298         if ((cpl_error_code)((plist = cpl_propertylist_load(file_name, 0)) == NULL)) {
00299            cpl_msg_error(_id, "getting header from reference ima frame %s",file_name);
00300            cpl_propertylist_delete(plist) ;
00301            return -1 ;
00302     }
00303 
00304         if (cpl_propertylist_contains(plist, KEY_NAME_LAMP_HALO)) {
00305             cpl_propertylist_set_bool(plist, KEY_NAME_LAMP_HALO, LAMP_ON);
00306         } else {
00307             cpl_propertylist_append_bool(plist, KEY_NAME_LAMP_HALO,LAMP_ON) ;
00308         }
00309   
00310 
00311         /* Save the file */
00312     /*
00313         if (cpl_image_save(ima, file_name, CPL_BPP_DEFAULT, plist,CPL_IO_DEFAULT)!=CPL_ERROR_NONE) {
00314            cpl_msg_error(_id, "Cannot save the product %s",file_name);
00315            cpl_propertylist_delete(plist) ;
00316           return -1 ;
00317     }
00318     */
00319   
00320         cpl_propertylist_delete(plist);
00321         cpl_image_delete(ima);
00322 
00323     cpl_msg_info(_id,"SUCCESS: COMPUTED DISTORTIONS\n") ; 
00324      }
00325     sinfoni_memory_status(); 
00326   
00327     /* 
00328        ---------------------------------------------------------
00329                                NST 
00330        ---------------------------------------------------------
00331      */
00332 
00333     {
00334     cpl_msg_info (_id,"RUN NORD SUD TEST\n") ; 
00335         if ( -1 == (ind = nst(_id,config, set ) ) )
00336         {
00337         cpl_msg_error(_id,"no: %d\n", ind) ;
00338         return -1 ;
00339     }
00340      
00341     cpl_msg_info (_id,"SUCCESS: RUNNED NORD SUD TEST\n") ; 
00342 
00343     }    
00344     cpl_msg_info (_id,"SUCCESS: RECIPE\n") ;
00345     sinfoni_memory_status(); 
00346 
00347     return 0 ;
00348 
00349 }
00350 

Generated on Wed Oct 26 13:08:54 2005 for SINFONI Pipeline Reference Manual by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001