GIRAFFE Pipeline Reference Manual

irplib_utils.c

00001 /* $Id: irplib_utils.c,v 1.2.2.1 2008/06/10 14:09:33 rpalsa Exp $
00002  *
00003  * This file is part of the irplib package 
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: rpalsa $
00023  * $Date: 2008/06/10 14:09:33 $
00024  * $Revision: 1.2.2.1 $
00025  * $Name: giraffe-2_5_2 $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031 
00032 /*-----------------------------------------------------------------------------
00033                                    Includes
00034  -----------------------------------------------------------------------------*/
00035 
00036 #include <math.h>
00037 
00038 #include <string.h>
00039 #include <assert.h>
00040 
00041 #include <cpl.h>
00042 
00043 #include "irplib_utils.h"
00044 
00045 /*-----------------------------------------------------------------------------
00046                            Missing Function Prototypes
00047  -----------------------------------------------------------------------------*/
00048 
00049 #if defined HAVE_ISNAN && HAVE_ISNAN != 0
00050 #if !defined isnan && defined HAVE_DECL_ISNAN && HAVE_DECL_ISNAN == 0
00051 /* HP-UX and Solaris may have isnan() available at link-time
00052    without the prototype */
00053 int isnan(double);
00054 #endif
00055 #endif
00056 
00057 /*----------------------------------------------------------------------------*/
00061 /*----------------------------------------------------------------------------*/
00064 /*----------------------------------------------------------------------------*/
00076 /*----------------------------------------------------------------------------*/
00077 void irplib_reset(void)
00078 {
00079     return;
00080 }
00081 
00082 /*----------------------------------------------------------------------------*/
00089 /*----------------------------------------------------------------------------*/
00090 int irplib_compare_tags(
00091         cpl_frame   *   frame1,
00092         cpl_frame   *   frame2)
00093 {
00094     char            *   v1 ;
00095     char            *   v2 ;
00096 
00097     /* Test entries */
00098     if (frame1==NULL || frame2==NULL) return -1 ;
00099 
00100     /* Get the tags */
00101     if ((v1 = (char*)cpl_frame_get_tag(frame1)) == NULL) return -1 ;
00102     if ((v2 = (char*)cpl_frame_get_tag(frame2)) == NULL) return -1 ;
00103 
00104     /* Compare the tags */
00105     if (strcmp(v1, v2)) return 0 ;
00106     else return 1 ;
00107 }
00108 
00109 /*----------------------------------------------------------------------------*/
00125 /*----------------------------------------------------------------------------*/
00126 const char * irplib_frameset_find_file(const cpl_frameset * self,
00127                                       const char * tag)
00128 {
00129     const cpl_frame * frame = cpl_frameset_find_const(self, tag);
00130 
00131 
00132     cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), NULL);
00133 
00134     if (frame == NULL) return NULL;
00135 
00136     if (cpl_frameset_find_const(self, NULL))
00137         cpl_msg_warning(cpl_func,
00138             "Frameset has more than one file with tag: %s",
00139                         tag);
00140 
00141     return cpl_frame_get_filename(frame);
00142 
00143 }
00144 
00145 /*----------------------------------------------------------------------------*/
00155 /*----------------------------------------------------------------------------*/
00156 cpl_frame * irplib_frameset_get_first_from_group(
00157         const cpl_frameset  *   self,
00158         cpl_frame_group         group)
00159 {
00160     const cpl_frame * frame;
00161     cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
00162 
00163     for (frame = cpl_frameset_get_first_const(self); frame != NULL ;
00164          frame = cpl_frameset_get_next_const(self)) {
00165         if (cpl_frame_get_group(frame) == group) break;
00166     }
00167     return (cpl_frame*)frame;
00168 }
00169 
00170 /*----------------------------------------------------------------------------*/
00189 /*----------------------------------------------------------------------------*/
00190 cpl_error_code irplib_apertures_find_max_flux(const cpl_apertures * self,
00191                                               int * ind, int nfind)
00192 {
00193     const int    nsize = cpl_apertures_get_size(self);
00194     int          ifind;
00195 
00196 
00197     cpl_ensure_code(nsize > 0,      cpl_error_get_code());
00198     cpl_ensure_code(ind,          CPL_ERROR_NULL_INPUT);
00199     cpl_ensure_code(nfind > 0,      CPL_ERROR_ILLEGAL_INPUT);
00200     cpl_ensure_code(nfind <= nsize, CPL_ERROR_ILLEGAL_INPUT);
00201 
00202     for (ifind=0; ifind < nfind; ifind++) {
00203         double maxflux = -1;
00204         int maxind = -1;
00205         int i;
00206         for (i=1; i <= nsize; i++) {
00207             int k;
00208 
00209             /* The flux has to be the highest among those not already found */
00210             for (k=0; k < ifind; k++) if (ind[k] == i) break;
00211 
00212             if (k == ifind) {
00213                 /* i has not been inserted into ind */
00214                 const double flux = cpl_apertures_get_flux(self, i);
00215 
00216                 if (maxind < 0 || flux > maxflux) {
00217                     maxind = i;
00218                     maxflux = flux;
00219                 }
00220             }
00221         }
00222         ind[ifind] = maxind;
00223     }
00224 
00225     return CPL_ERROR_NONE;
00226 
00227 }
00228 
00229 /*----------------------------------------------------------------------------*/
00233 /*----------------------------------------------------------------------------*/
00234 int irplib_isinf(double value)
00235 {
00236 #if defined HAVE_ISINF && HAVE_ISINF
00237     return isinf(value);
00238 #else
00239     return value != 0 && value == 2 * value;
00240 #endif
00241 }
00242 
00243 /*----------------------------------------------------------------------------*/
00247 /*----------------------------------------------------------------------------*/
00248 int irplib_isnan(double value)
00249 {
00250 #if defined HAVE_ISNAN && HAVE_ISNAN
00251     return isnan(value);
00252 #else
00253     return value != value;
00254 #endif
00255 }
00256 
00257 
00258 
00259 /*----------------------------------------------------------------------------*/
00270 /*----------------------------------------------------------------------------*/
00271 void irplib_errorstate_warning(unsigned self, unsigned first, unsigned last)
00272 {
00273 
00274     const cpl_boolean is_reverse = first > last ? CPL_TRUE : CPL_FALSE;
00275     const unsigned    newest     = is_reverse ? first : last;
00276     const unsigned    oldest     = is_reverse ? last : first;
00277     const char      * revmsg     = is_reverse ? " in reverse order" : "";
00278 
00279 
00280     assert( oldest <= self );
00281     assert( newest >= self );
00282 
00283     if (newest == 0) {
00284         cpl_msg_info(cpl_func, "No error(s) to dump");
00285         assert( oldest == 0);
00286     } else {
00287         assert( oldest > 0);
00288         assert( newest >= oldest);
00289         if (self == first) {
00290             if (oldest == 1) {
00291                 cpl_msg_warning(cpl_func, "Dumping all %u error(s)%s:", newest,
00292                               revmsg);
00293             } else {
00294                 cpl_msg_warning(cpl_func, "Dumping the %u most recent error(s) "
00295                               "out of a total of %u errors%s:",
00296                               newest - oldest + 1, newest, revmsg);
00297             }
00298             cpl_msg_indent_more();
00299         }
00300 
00301         cpl_msg_warning(cpl_func, "[%u/%u] '%s' (%u) at %s", self, newest,
00302                       cpl_error_get_message(), cpl_error_get_code(),
00303                       cpl_error_get_where());
00304 
00305         if (self == last) cpl_msg_indent_less();
00306     }
00307 }
00308 
00309 

This file is part of the GIRAFFE Pipeline Reference Manual 2.5.2.
Documentation copyright © 2002-2006 European Southern Observatory.
Generated on Fri Jun 13 14:36:26 2008 by doxygen 1.4.6 written by Dimitri van Heesch, © 1997-2004