skymap.c

00001 /* $Id: skymap.c,v 1.1 2005/03/13 17:43:08 amodigli Exp $
00002  *
00003  * This file is part of the IIINSTRUMENT 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: 2005/03/13 17:43:08 $
00024  * $Revision: 1.1 $
00025  * $Name:  $
00026  */
00027 
00028 
00029 /*-----------------------------------------------------------------------------
00030                                 Includes
00031  -----------------------------------------------------------------------------*/
00032 
00033  
00034 #include "eclipse.h" 
00035 #include "fitshead.h"
00036 #include "cube_ops.h"
00037 #include "skymap.h"
00038 
00039 /*-----------------------------------------------------------------------------
00040                             Functions prototypes
00041  -----------------------------------------------------------------------------*/
00042 
00043 
00044 /*-----------------------------------------------------------------------------
00045                             Static variables
00046  -----------------------------------------------------------------------------*/
00047 
00048 /*-----------------------------------------------------------------------------
00049                                 Functions code
00050  -----------------------------------------------------------------------------*/
00051 
00052 
00053 /*----------------------------------------------------------------------------*/
00060 /*----------------------------------------------------------------------------*/
00061 int si_skymap(
00062         cpl_parameterlist   *   parlist, 
00063         cpl_frameset        *   framelist)
00064 {
00065     const char          *   fctid = "si_skymap" ;
00066     cpl_parameter       *   param =NULL ;
00067     const char          *   name_i =NULL;
00068     const char          *   name_o =NULL;
00069     const char          *   method =NULL;
00070 
00071     double                  ws=0 ;
00072     double                  we=0 ;
00073     double                  wc=0 ;
00074     float                   disp=0 ;
00075 
00076 
00077     cpl_frame           *   frm_cub=NULL ;
00078  
00079     cpl_propertylist    *   plist=NULL ;
00080     cpl_image           *   image=NULL ;
00081     cpl_frame           *   product_frame=NULL;
00082 
00083     OneCube * cube=NULL;
00084     OneImage * img=NULL;
00085     fits_header * header=NULL;
00086 
00087     /* HOW TO RETRIEVE INPUT PARAMETERS */
00088     /* --stropt */
00089     param = cpl_parameterlist_find(parlist, "sinfoni.si_skymap.method");
00090     method = cpl_parameter_get_string(param);
00091 
00092     /* --stropt */
00093     param = cpl_parameterlist_find(parlist, "sinfoni.si_skymap.out_filename");
00094     name_o = cpl_parameter_get_string(param);
00095 
00096     /* --doubleopt */
00097     param = cpl_parameterlist_find(parlist,"sinfoni.si_skymap.ws");
00098     ws = cpl_parameter_get_double(param) ;
00099 
00100     /* --doubleopt */
00101     param = cpl_parameterlist_find(parlist,"sinfoni.si_skymap.we");
00102     we = cpl_parameter_get_double(param) ;
00103 
00104     /* --doubleopt */
00105     param = cpl_parameterlist_find(parlist,"sinfoni.si_skymap.wc");
00106     wc = cpl_parameter_get_double(param) ;
00107  
00108 
00109     /* Identify the RAW and CALIB frames in the input frameset */
00110     if (sinfoni_dfs_set_groups(framelist)) {
00111         cpl_msg_error(fctid, "Cannot identify RAW and CALIB frames") ;
00112         return -1 ;
00113     }
00114  
00115     /* HOW TO ACCESS INPUT DATA */
00116     if ((frm_cub = cpl_frameset_find(framelist, SI_SKYMAP_CUBE))==NULL) {
00117         cpl_msg_error(fctid, "SOF does not have a file tagged as %s",SI_SKYMAP_CUBE);
00118         return -1 ;
00119     }
00120 
00121     name_i = cpl_frame_get_filename(frm_cub);
00122     /* recipe's algorithm */
00123     cube   = load_cube((char*)name_i);
00124     header = fits_read_header((char*)name_i);
00125 
00126     wc   = spiffi_get_cenLambda((char*)name_i);  
00127     disp = spiffi_get_dispersion((char*)name_i);  
00128     img  = averageCubeToImageBetweenWaves(cube,disp,wc,ws,we);       
00129 
00130 
00131     fits_header_del(header, "CTYPE3");
00132     fits_header_del(header, "CRPIX3");
00133     fits_header_del(header, "CRVAL3");
00134     fits_header_del(header, "CDELT3");
00135     fits_header_del(header, "CUNIT3");
00136     /*save_image_to_fits_hdr_dump(img,(char*)name_o, header, -32 ); */   
00137     image=cpl_image_wrap_float(img->lx,img->ly,img->data);
00138 
00139     destroy_cube(cube);
00140     destroy_image(img);
00141     fits_header_destroy(header);
00142 
00143     
00144     /* HOW TO SAVE A PRODUCT ON DISK  */
00145 
00146     /* Create product frame */
00147     product_frame = cpl_frame_new();
00148     cpl_frame_set_filename(product_frame, name_o) ;
00149     cpl_frame_set_tag(product_frame, SI_SKYMAP_PROIMA) ;
00150     cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE) ;
00151     cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT) ;
00152     cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL) ;
00153     if (cpl_error_get_code()) {
00154         cpl_msg_error(fctid, "Error while initialising the product frame") ;
00155         cpl_propertylist_delete(plist) ;
00156         cpl_frame_delete(product_frame) ;
00157         cpl_image_delete(image) ;
00158         return -1 ;
00159     }
00160     
00161     /* Add DataFlow keywords */
00162     /*
00163     if (cpl_dfs_setup_product_header(plist, product_frame, framelist, parlist,
00164             "si_skymap", "SINFONI", "?Dictionary?") != CPL_ERROR_NONE) {
00165         cpl_msg_error(fctid, "Problem in the product DFS-compliance") ;
00166         cpl_propertylist_delete(plist) ;
00167         cpl_frame_delete(product_frame) ;
00168         cpl_image_delete(image) ;
00169         return -1 ;
00170     }
00171     */
00172     /* Save the file */
00173     if (cpl_image_save(image, name_o, CPL_BPP_DEFAULT, plist,
00174                        CPL_IO_DEFAULT) != CPL_ERROR_NONE) {
00175         cpl_msg_error(fctid, "Could not save product");
00176         cpl_propertylist_delete(plist) ;
00177         cpl_frame_delete(product_frame) ;
00178         cpl_image_delete(image) ;
00179         return -1 ;
00180     }
00181     cpl_propertylist_delete(plist) ;
00182     cpl_image_delete(image);
00183  
00184     /* Log the saved file in the input frameset */
00185     cpl_frameset_insert(framelist, product_frame) ;
00186     
00187     /* Return */
00188     if (cpl_error_get_code()) 
00189         return -1 ;
00190     else 
00191         return 0 ;
00192 }

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