naco_utils.c

00001 /* $Id: naco_utils.c,v 1.32 2009/10/13 08:05:57 llundin Exp $
00002  *
00003  * This file is part of the NACO 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., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
00019  */
00020 
00021 /*
00022  * $Author: llundin $
00023  * $Date: 2009/10/13 08:05:57 $
00024  * $Revision: 1.32 $
00025  * $Name: naco-4_3_3 $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031 
00032 /*-----------------------------------------------------------------------------
00033                                    Includes
00034  -----------------------------------------------------------------------------*/
00035 
00036 #include <string.h>
00037 #include <math.h>
00038 #include <cpl.h>
00039 
00040 #include "naco_utils.h"
00041 #include "naco_pfits.h"
00042 
00043 /*----------------------------------------------------------------------------*/
00047 /*----------------------------------------------------------------------------*/
00048 
00051 /*----------------------------------------------------------------------------*/
00060 /*----------------------------------------------------------------------------*/
00061 cpl_error_code naco_get_filter_infos(const char * f, double * lam,
00062                                      double * dlam)
00063 {
00064 
00065     bug_if(cpl_error_get_code());
00066     bug_if( f    == NULL);
00067     bug_if( lam  == NULL);
00068     bug_if( dlam == NULL);
00069 
00070     if (!strncmp(f, "J", IRPLIB_FITS_STRLEN))        {
00071          *lam = 1.265; *dlam = 0.250;
00072     } else if (!strncmp(f, "Jc", IRPLIB_FITS_STRLEN))       {
00073          *lam = 1.265; *dlam = 0.250;
00074     } else if (!strncmp(f, "H", IRPLIB_FITS_STRLEN))        {
00075          *lam = 1.660; *dlam = 0.330;
00076     } else if (!strncmp(f, "K", IRPLIB_FITS_STRLEN))        {
00077          *lam = 2.230; *dlam = 0.390;
00078     } else if (!strncmp(f, "Ks", IRPLIB_FITS_STRLEN))       {
00079          *lam = 2.180; *dlam = 0.350;
00080     } else if (!strncmp(f, "L", IRPLIB_FITS_STRLEN))        {
00081          *lam = 3.500; *dlam = 0.610;
00082     } else if (!strncmp(f, "L_prime", IRPLIB_FITS_STRLEN))  {
00083          *lam = 3.800; *dlam = 0.620;
00084     } else if (!strncmp(f, "M_prime", IRPLIB_FITS_STRLEN))  {
00085          *lam = 4.780; *dlam = 0.590;
00086     } else if (!strncmp(f, "SJ", IRPLIB_FITS_STRLEN))       {
00087          *lam = 1.160; *dlam = 0.470;
00088     } else if (!strncmp(f, "SH", IRPLIB_FITS_STRLEN))       {
00089          *lam = 1.630; *dlam = 0.430;
00090     } else if (!strncmp(f, "SK", IRPLIB_FITS_STRLEN))       {
00091          *lam = 2.270; *dlam = 0.760;
00092     } else if (!strncmp(f, "NB_1.04", IRPLIB_FITS_STRLEN))  {
00093          *lam = 1.040; *dlam = 0.015;
00094     } else if (!strncmp(f, "NB_1.08", IRPLIB_FITS_STRLEN))  {
00095          *lam = 1.083; *dlam = 0.015;
00096     } else if (!strncmp(f, "NB_1.09", IRPLIB_FITS_STRLEN))  {
00097          *lam = 1.094; *dlam = 0.015;
00098     } else if (!strncmp(f, "NB_1.24", IRPLIB_FITS_STRLEN))  {
00099          *lam = 1.237; *dlam = 0.015;
00100     } else if (!strncmp(f, "NB_1.26", IRPLIB_FITS_STRLEN))  {
00101          *lam = 1.257; *dlam = 0.014;
00102     } else if (!strncmp(f, "NB_1.28", IRPLIB_FITS_STRLEN))  {
00103          *lam = 1.282; *dlam = 0.014;
00104     } else if (!strncmp(f, "NB_1.64", IRPLIB_FITS_STRLEN))  {
00105          *lam = 1.644; *dlam = 0.018;
00106     } else if (!strncmp(f, "NB_1.75", IRPLIB_FITS_STRLEN))  {
00107          *lam = 1.748; *dlam = 0.026;
00108     } else if (!strncmp(f, "NB_3.74", IRPLIB_FITS_STRLEN))  {
00109          *lam = 3.740; *dlam = 0.020;
00110     } else if (!strncmp(f, "IB_2.00", IRPLIB_FITS_STRLEN))  {
00111          *lam = 2.000; *dlam = 0.060;
00112     } else if (!strncmp(f, "IB_2.03", IRPLIB_FITS_STRLEN))  {
00113          *lam = 2.030; *dlam = 0.060;
00114     } else if (!strncmp(f, "IB_2.06", IRPLIB_FITS_STRLEN))  {
00115          *lam = 2.060; *dlam = 0.060;
00116     } else if (!strncmp(f, "IB_2.09", IRPLIB_FITS_STRLEN))  {
00117          *lam = 2.090; *dlam = 0.060;
00118     } else if (!strncmp(f, "IB_2.12", IRPLIB_FITS_STRLEN))  {
00119          *lam = 2.120; *dlam = 0.060;
00120     } else if (!strncmp(f, "NB_2.12", IRPLIB_FITS_STRLEN))  {
00121          *lam = 2.122; *dlam = 0.022;
00122     } else if (!strncmp(f, "IB_2.15", IRPLIB_FITS_STRLEN))  {
00123          *lam = 2.150; *dlam = 0.060;
00124     } else if (!strncmp(f, "NB_2.17", IRPLIB_FITS_STRLEN))  {
00125          *lam = 2.166; *dlam = 0.023;
00126     } else if (!strncmp(f, "IB_2.18", IRPLIB_FITS_STRLEN))  {
00127          *lam = 2.180; *dlam = 0.060;
00128     } else if (!strncmp(f, "IB_2.21", IRPLIB_FITS_STRLEN))  {
00129          *lam = 2.210; *dlam = 0.060;
00130     } else if (!strncmp(f, "IB_2.24", IRPLIB_FITS_STRLEN))  {
00131          *lam = 2.240; *dlam = 0.060;
00132     } else if (!strncmp(f, "IB_2.27", IRPLIB_FITS_STRLEN))  {
00133          *lam = 2.270; *dlam = 0.060;
00134     } else if (!strncmp(f, "IB_2.30", IRPLIB_FITS_STRLEN))  {
00135          *lam = 2.300; *dlam = 0.060;
00136     } else if (!strncmp(f, "IB_2.33", IRPLIB_FITS_STRLEN))  {
00137          *lam = 2.330; *dlam = 0.060;
00138     } else if (!strncmp(f, "IB_2.36", IRPLIB_FITS_STRLEN))  {
00139          *lam = 2.360; *dlam = 0.060;
00140     } else if (!strncmp(f, "IB_2.39", IRPLIB_FITS_STRLEN))  {
00141          *lam = 2.390; *dlam = 0.060;
00142     } else if (!strncmp(f, "IB_2.42", IRPLIB_FITS_STRLEN))  {
00143          *lam = 2.420; *dlam = 0.060;
00144     } else if (!strncmp(f, "IB_2.45", IRPLIB_FITS_STRLEN))  {
00145          *lam = 2.450; *dlam = 0.060;
00146     } else if (!strncmp(f, "IB_2.48", IRPLIB_FITS_STRLEN))  {
00147          *lam = 2.480; *dlam = 0.060;
00148     } else if (!strncmp(f, "NB_4.05", IRPLIB_FITS_STRLEN))  {
00149          *lam = 4.051; *dlam = 0.020;
00150     } else if (!strncmp(f, "IB_4.05", IRPLIB_FITS_STRLEN))  {
00151         /* As per email 2009-10-13 from epompei@eso.org */
00152          *lam = 4.05; *dlam = 0.100;
00153     } else
00154         irplib_ensure(0, CPL_ERROR_DATA_NOT_FOUND, "Unknown filter: %s", f);
00155 
00156     end_skip;
00157 
00158     return cpl_error_get_code();
00159 }
00160 
00161 /*----------------------------------------------------------------------------*/
00175 /*----------------------------------------------------------------------------*/
00176 const char ** naco_framelist_set_tag(irplib_framelist * self,
00177                                      char * (*pftag)(const cpl_frame *,
00178                                                      const cpl_propertylist *,
00179                                                      int),
00180                                      int *pntags)
00181 {
00182 
00183     const char ** taglist = NULL; /* Must be initialized due to realloc call */
00184     int iframe, size;
00185 
00186     cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), NULL);
00187     cpl_ensure(self   != NULL, CPL_ERROR_NULL_INPUT, NULL);
00188     cpl_ensure(pftag  != NULL, CPL_ERROR_NULL_INPUT, NULL);
00189     cpl_ensure(pntags != NULL, CPL_ERROR_NULL_INPUT, NULL);
00190 
00191     size = irplib_framelist_get_size(self);
00192 
00193     cpl_ensure(size > 0, CPL_ERROR_DATA_NOT_FOUND, NULL);
00194 
00195     *pntags = 0;
00196 
00197     for (iframe = 0; iframe < size ; iframe++) {
00198         cpl_frame  * frame = irplib_framelist_get(self, iframe);
00199         const cpl_propertylist * plist
00200             = irplib_framelist_get_propertylist_const(self, iframe);
00201         char       * tag;
00202         const char * newtag;
00203         int          i;
00204 
00205 
00206         /* This should really be an assert() */
00207         cpl_ensure(frame != NULL, CPL_ERROR_ILLEGAL_INPUT, NULL);
00208         cpl_ensure(plist != NULL, CPL_ERROR_ILLEGAL_INPUT, NULL);
00209 
00210         tag = (*pftag)(frame, plist, iframe);
00211 
00212         cpl_ensure(tag != NULL, cpl_error_get_code(), NULL);
00213 
00214         /* From this point on failures should not really happen */
00215 
00216         (void)cpl_frame_set_tag(frame, tag);
00217         cpl_free(tag);
00218 
00219         newtag = cpl_frame_get_tag(frame);
00220 
00221         cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), NULL);
00222 
00223         /* Compare the new tags with those of previous frames */
00224         for (i=0; i < *pntags; i++)
00225             if (strcmp(newtag, taglist[i]) == 0) break;
00226 
00227         if (i == *pntags) {
00228             /* The new tag is different from the previous ones
00229                - add it to the list */
00230             (*pntags)++;
00231             taglist = (const char **)cpl_realloc(taglist, *pntags *
00232                                                  sizeof(const char *));
00233             taglist[i] = newtag;
00234         }
00235 
00236     }
00237 
00238     return taglist;
00239 
00240 }
00241 

Generated on Tue Mar 12 15:19:53 2013 for NACO Pipeline Reference Manual by  doxygen 1.4.7