naco_utils.c

00001 /* $Id: naco_utils.c,v 1.30 2008/04/15 17:04:21 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: 2008/04/15 17:04:21 $
00024  * $Revision: 1.30 $
00025  * $Name: naco-4_1_2 $
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
00151         irplib_ensure(0, CPL_ERROR_DATA_NOT_FOUND, "Unknown filter: %s", f);
00152 
00153     end_skip;
00154 
00155     return cpl_error_get_code();
00156 }
00157 
00158 /*----------------------------------------------------------------------------*/
00172 /*----------------------------------------------------------------------------*/
00173 const char ** naco_framelist_set_tag(irplib_framelist * self,
00174                                      char * (*pftag)(const cpl_frame *,
00175                                                      const cpl_propertylist *,
00176                                                      int),
00177                                      int *pntags)
00178 {
00179 
00180     const char ** taglist = NULL; /* Must be initialized due to realloc call */
00181     int iframe, size;
00182 
00183     cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), NULL);
00184     cpl_ensure(self   != NULL, CPL_ERROR_NULL_INPUT, NULL);
00185     cpl_ensure(pftag  != NULL, CPL_ERROR_NULL_INPUT, NULL);
00186     cpl_ensure(pntags != NULL, CPL_ERROR_NULL_INPUT, NULL);
00187 
00188     size = irplib_framelist_get_size(self);
00189 
00190     cpl_ensure(size > 0, CPL_ERROR_DATA_NOT_FOUND, NULL);
00191 
00192     *pntags = 0;
00193 
00194     for (iframe = 0; iframe < size ; iframe++) {
00195         cpl_frame  * frame = irplib_framelist_get(self, iframe);
00196         const cpl_propertylist * plist
00197             = irplib_framelist_get_propertylist_const(self, iframe);
00198         char       * tag;
00199         const char * newtag;
00200         int          i;
00201 
00202 
00203         /* This should really be an assert() */
00204         cpl_ensure(frame != NULL, CPL_ERROR_ILLEGAL_INPUT, NULL);
00205         cpl_ensure(plist != NULL, CPL_ERROR_ILLEGAL_INPUT, NULL);
00206 
00207         tag = (*pftag)(frame, plist, iframe);
00208 
00209         cpl_ensure(tag != NULL, cpl_error_get_code(), NULL);
00210 
00211         /* From this point on failures should not really happen */
00212 
00213         (void)cpl_frame_set_tag(frame, tag);
00214         cpl_free(tag);
00215 
00216         newtag = cpl_frame_get_tag(frame);
00217 
00218         cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), NULL);
00219 
00220         /* Compare the new tags with those of previous frames */
00221         for (i=0; i < *pntags; i++)
00222             if (strcmp(newtag, taglist[i]) == 0) break;
00223 
00224         if (i == *pntags) {
00225             /* The new tag is different from the previous ones
00226                - add it to the list */
00227             (*pntags)++;
00228             taglist = (const char **)cpl_realloc(taglist, *pntags *
00229                                                  sizeof(const char *));
00230             taglist[i] = newtag;
00231         }
00232 
00233     }
00234 
00235     return taglist;
00236 
00237 }
00238 

Generated on Fri Jul 3 11:23:59 2009 for NACO Pipeline Reference Manual by  doxygen 1.5.8