amber_lingain.c

00001 /* $Id: amber_lingain.c,v 1.3 2007/11/19 17:50:43 lbilbao Exp $
00002  *
00003  * This file is part of the DETMON 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: lbilbao $
00023  * $Date: 2007/11/19 17:50:43 $
00024  * $Revision: 1.3 $
00025  * $Name: HEAD $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031 
00032 /*----------------------------------------------------------------------------
00033                              Includes and Defines
00034  ----------------------------------------------------------------------------*/
00035 
00036 #include <cpl.h>
00037 
00038 #include "irplib_detmon_lg.h"
00039 #include "irplib_plugin.h"
00040 
00041 #include "amdrs.h"
00042 
00043 /* Define here the DO.CATG keywords */
00044 #define AMBER_LINGAIN_ON_RAW                    "ON_RAW"
00045 #define AMBER_LINGAIN_OFF_RAW           "OFF_RAW"
00046 
00047 #define RECIPE_NAME "amber_lingain"
00048 
00049 /* Copy here instrument specific keywords which need to be in the PAF file */
00050 #define INSTREGEXP   "ESO INS SETUP ID" /* To be defined in AMBER case yet */
00051 
00052 #define PAFREGEXP    "^(" REGEXP "|" INSTREGEXP ")$"
00053 
00054 #define NIR TRUE
00055 
00056 static  amdlibRAW_DATA   rawData;
00057 /*----------------------------------------------------------------------------
00058                  Functions prototypes
00059  ----------------------------------------------------------------------------*/
00060 
00061 IRPLIB_RECIPE_DEFINE(amber_lingain, DETMON_BINARY_VERSION,
00062              /* Replace DETMON_BINARY_VERSION with
00063             corresponding pipeline macro */
00064                      irplib_detmon_lg_fill_parlist_nir_default(recipe->parameters,
00065                                RECIPE_NAME, "amber"),
00066              /* Replace "amber" with PACKAGE_TARNAME
00067             when moved into AMBER */
00068                      "Lander de Bilbao", PACKAGE_BUGREPORT, "2007", 
00069                      "Linearity/Gain recipe for the IR domain",
00070                      irplib_detmon_lg_get_description(RECIPE_NAME, "AMBER",
00071                                                       AMBER_LINGAIN_ON_RAW,
00072                                                       AMBER_LINGAIN_OFF_RAW));
00073 
00074 int
00075 amber_ilist_load_fset(const cpl_frameset *,
00076               cpl_type,
00077                       cpl_imagelist *);
00078 
00079 /*---------------------------------------------------------------------------*/
00080 /*
00081   @brief    Interpret the command line options and execute the data processing
00082   @param    frameset    the frames list
00083   @param    parlist     the parameters list
00084   @return   0 if everything is ok
00085  */
00086 /*---------------------------------------------------------------------------*/
00087 
00088 static int amber_lingain(cpl_frameset            * frameset,
00089              const cpl_parameterlist * parlist)
00090 {
00091     const cpl_error_code error = irplib_detmon_lg(frameset,
00092                                                   parlist,
00093                                                   AMBER_LINGAIN_ON_RAW,
00094                                                   AMBER_LINGAIN_OFF_RAW,
00095                                                   RECIPE_NAME,
00096     /* Replace this string ("amber") with */      "amber",
00097     /* PACKAGE_TARNAME when moved into AMBER */   PAFREGEXP,
00098                                                   "DET_LIN_INFO", "GAIN_INFO",
00099                                               "COEFFS_CUBE", "BP_MAP_NL",
00100                           "AUTOCORR", "DIFF_FLAT",
00101                                                   PACKAGE "/" PACKAGE_VERSION,
00102                                                   NULL,
00103                           amber_ilist_load_fset, NIR);
00104 
00105     /* Propagate the error, if any */
00106     cpl_ensure_code(!error, error);
00107 
00108     return CPL_ERROR_NONE;
00109 }
00110 
00111 int
00112 amber_ilist_load_fset(const cpl_frameset * frameset,
00113               cpl_type             type,
00114                       cpl_imagelist      * ilist)
00115 {
00116     int nframes = cpl_frameset_get_size(frameset);
00117     int i;
00118 
00119     for (i = 0; i < nframes; i++) {
00120     cpl_frame * cur_frame = cpl_frameset_get_frame(frameset, i);
00121     char      * filename  = cpl_frame_get_filename(cur_frame);
00122 
00123     cpl_imagelist * framelist = cpl_imagelist_new();
00124 
00125     amdlibERROR_MSG  errMsg;
00126 
00127 
00128     int iCol, iRow, iRegion;
00129     int iX, iY, iFrame;
00130     int regionHeight, regionWidth, regionSize;
00131     
00132     float * image = NULL;
00133 
00134     int          status = 0;
00135 
00136     int          bitpix = FLOAT_IMG;
00137 
00138     long         naxis = 3;  /* 2-dimensional image */
00139     long         naxes[3] = {0, 0, 0};
00140 
00141     int j;
00142 
00143     /* Load raw frame and store it to amdlib format */
00144     if (amdlibLoadRawData(filename, &rawData, errMsg) != amdlibSUCCESS) {
00145         cpl_msg_error(cpl_func, "Couldn't read AMBER format");
00146     }
00147     
00148     /* Determine the size of the glued image */
00149     for (iCol = 0; iCol < rawData.nbCols; iCol++) {
00150         iRegion = iCol;
00151         naxes[0] += rawData.region[iRegion].dimAxis[0];
00152     }
00153     for (iRow = 0; iRow < rawData.nbRows; iRow++) {
00154         iRegion = iRow *  rawData.nbCols;
00155         naxes[1] += rawData.region[iRegion].dimAxis[1];
00156     }
00157     naxes[2] = rawData.region[0].dimAxis[2];
00158 
00159     /* Allocate memory */
00160     image = cpl_malloc(naxes[0]*naxes[1]*naxes[2]*sizeof(float));
00161     if (image == NULL) {
00162         cpl_msg_error(cpl_func, "Error while allocating memory");
00163     }
00164 
00165     /* Create glued image */
00166     j = 0;
00167     for (iFrame = 0; iFrame < rawData.region[0].dimAxis[2]; iFrame++) {
00168         for (iRow = 0; iRow < rawData.nbRows; iRow++) {
00169         iRegion = iRow * rawData.nbCols;
00170         regionHeight = rawData.region[iRegion].dimAxis[1];
00171         for (iY = 0; iY < regionHeight; iY++) {
00172             for (iCol = 0; iCol < rawData.nbCols; iCol++) {
00173             iRegion = iRow *  rawData.nbCols + iCol;
00174             regionWidth = rawData.region[iRegion].dimAxis[0];
00175             regionSize  = regionWidth * regionHeight;
00176             for (iX = 0; iX < regionWidth; iX++) {
00177                 image[j++] = rawData.region[iRegion].
00178                 data[iFrame * regionSize  +
00179                      iY     * regionWidth +
00180                      iX];
00181             }
00182             }
00183         }
00184         }
00185     }
00186 
00187     for (iFrame = 0; iFrame < rawData.region[0].dimAxis[2]; iFrame ++) {
00188         cpl_image * img = cpl_image_wrap_float(regionHeight,
00189                            regionWidth,
00190                            image + 
00191                            iFrame * regionSize);
00192         cpl_imagelist_set(framelist, img, iFrame);
00193     }
00194     
00195     cpl_image * out = cpl_imagelist_collapse_create(framelist);
00196     if(out == NULL) {
00197         cpl_msg_error(cpl_func, "Error collapsing");
00198         cpl_imagelist_delete(framelist);
00199     }
00200 //  cpl_imagelist_delete(framelist);
00201     cpl_free(image);
00202 
00203     cpl_imagelist_set(ilist, out, i);
00204     } /* End of for(nframes) statement */ 
00205 
00206     return 0;
00207 }

Generated on 1 Mar 2011 for DETMON Pipeline Reference Manual by  doxygen 1.6.1