sinfo_utilities.h

00001 /* $Id: sinfo_utilities.h,v 1.2 2006/12/05 15:01:41 amodigli Exp $
00002  *
00003  * This file is part of the SINFONI 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: 2006/12/05 15:01:41 $
00024  * $Revision: 1.2 $
00025  * $Name:  $
00026  */
00027 #ifndef SINFO_UTILITIES_H
00028 #define SINFO_UTILITIES_H
00029 
00030 #ifdef HAVE_CONFIG_H
00031 #  include <config.h>
00032 #endif
00033 
00034 /*
00035   This recipe implements error handling cleanly using a pair of macros called
00036   skip_if() and end_skip.
00037 
00038   skip_if() takes one argument, which is a logical expression. 
00039   If the logical expression is false skip_if() takes no action and
00040   program execution continues.
00041   If the logical expression is true this indicates an error. In this case
00042   skip_if() will set the location of the error to the point where it
00043   was invoked in the recipe code (unless the error location is already in the
00044   recipe code). If no error code had been set, then skip_if() will set one.
00045   Finally, skip_if() causes program execution to skip to the macro 'end_skip'.
00046   The macro end_skip is located towards the end of the function, after
00047   which all resource deallocation and the function return is located. 
00048 
00049   The use of skip_if() assumes the following coding practice:
00050   1) Pointers used for dynamically allocated memory that they "own" shall 
00051      always
00052      point to either NULL or to allocated memory (including CPL-objects).
00053   2) Such pointers may not be reused to point to memory whose deallocation
00054      requires calls to different functions.
00055   3) Pointers of type FILE should be set NULL when not pointing to an open
00056      stream and their closing calls (fclose(), freopen(), etc.) following the
00057      'end_skip' should be guarded against such NULL pointers.
00058 
00059   Error checking with skip_if() is encouraged due to the following advantages:
00060   1) It ensures that a CPL-error code is set.
00061   2) It ensures that the location of the error in the _recipe_ code is noted.
00062   3) The error checking may be confined to a single concise line.
00063   4) It is not necessary to replicate memory deallocation for every error
00064      condition.
00065   5) If more extensive error reporting/handling is required it is not precluded
00066      by the use of skip_if().
00067   6) It allows for a single point of function return.
00068   7) It allows for optional, uniformly formatted debugging/tracing information
00069      at each macro invocation.
00070 
00071   The implementation of skip_if() uses a goto/label construction.
00072   According to Kerningham & Ritchie, The C Programming Language, 2nd edition,
00073   Section 3.8:
00074   "This organization is handy if the error-handling code is non-trivial,
00075   and if errors can occur in several places."
00076 
00077   The use of goto for any other purpose should be avoided.
00078 
00079 */
00080 
00081 #define skip_if(CONDITION) \
00082   do if (CONDITION) { \
00083     if (cpl_error_get_code()) { \
00084         cpl_msg_debug("", "Skip in %s line %d due to '%s' with error '%s' " \
00085                       "at %s", __FILE__, __LINE__, #CONDITION, \
00086                       cpl_error_get_message(), cpl_error_get_where());  \
00087         if (strstr(cpl_error_get_where(), "visir") == NULL) \
00088             cpl_error_set_where(""); \
00089     } else { \
00090         cpl_msg_debug("", "Skip in %s line %d due to '%s'", \
00091                         __FILE__, __LINE__, #CONDITION);  \
00092         cpl_error_set("", CPL_ERROR_UNSPECIFIED); \
00093     } \
00094     goto cleanup; \
00095   } else { \
00096     if (cpl_error_get_code()) \
00097         cpl_msg_debug("", "No skip in %s line %d due to '%s' with error '%s' " \
00098                       "at %s", __FILE__, __LINE__, #CONDITION, \
00099                       cpl_error_get_message(), cpl_error_get_where()); \
00100     else \
00101         cpl_msg_debug("", "No skip in %s line %d due to '%s'", \
00102                       __FILE__, __LINE__, #CONDITION);  \
00103   } while (0)
00104 
00105 
00106 #define end_skip \
00107     do { \
00108         cleanup: \
00109         if (cpl_error_get_code()) \
00110             cpl_msg_debug("", "Cleanup in %s line %d with error '%s' at %s", \
00111                            __FILE__, __LINE__, \
00112                           cpl_error_get_message(), cpl_error_get_where()); \
00113         else \
00114             cpl_msg_debug("", "Cleanup in %s line %d", \
00115                           __FILE__, __LINE__);  \
00116     } while (0)
00117 
00118 
00119 #include <cpl.h>
00120 #include <sinfo_image_ops.h> 
00121 #include "sinfo_globals.h"
00122 CPL_BEGIN_DECLS
00123 int
00124 sinfo_table_column_dump(cpl_table* t, const char* name, cpl_type type);
00125 
00126 cpl_table*
00127 sinfo_table_shift_column_spline3(cpl_table* t, 
00128                                  const char* col, 
00129                                  const double s);
00130 
00131 cpl_table*
00132 sinfo_table_shift_column_poly(cpl_table* t, 
00133                               const char* col, 
00134                               const double s,
00135                               const int order);
00136 
00137 cpl_table*
00138 sinfo_table_shift_column_int(const cpl_table* t, 
00139                              const char* col, 
00140                              const double s,
00141                                    double* r);
00142 
00143 
00144 void sinfo_new_array_set_value( float * array, float value, int i ); 
00145 float sinfo_new_array_get_value( float * array, int i );
00146 void sinfo_new_destroy_array(float ** array);
00147 void sinfo_new_destroy_stringarray(char ** array, int size_x);
00148 void sinfo_new_intarray_set_value( int * array, int value, int i );
00149 void sinfo_new_array2D_set_value( float ** array, float value, int x, int y );
00150 void sinfo_new_destroy_2Dintarray(int *** array, int size_x);
00151 void sinfo_new_destroy_2Dfloatarray(float *** array, int size_x);
00152 void sinfo_new_destroy_2Ddoublearray(double *** array, int size_x);
00153 void sinfo_new_destroy_intarray(int ** array);
00154 void sinfo_new_destroy_doublearray(double * array);
00155 void sinfo_new_doublearray_set_value( double * array, double value, int i );
00156 int sinfo_new_intarray_get_value( int * array, int i );
00157 int * sinfo_new_intarray( int size);
00158 int ** sinfo_new_2Dintarray( int size_x, int size_y);
00159 double ** sinfo_new_2Ddoublearray( int size_x, int size_y);
00160 char * sinfo_new_get_rootname(const char * filename);
00161 char * sinfo_new_get_basename(const char *filename);
00162 float sinfo_new_Stats_get_cleanstdev(Stats * stats);
00163 float sinfo_new_Stats_get_cleanmean(Stats * stats);
00164 float sinfo_new_array2D_get_value( float ** array, int x, int y );
00165 float * sinfo_new_floatarray( int size);
00166 float ** sinfo_new_2Dfloatarray( int size_x, int size_y);
00167 double   sinfo_new_doublearray_get_value( double * array, int i );
00168 
00169 double * sinfo_new_doublearray( int size);
00170 /*
00171 FitParams ** sinfo_new_fit_params( int n_params ) ;
00172 */
00173 cpl_imagelist * sinfo_new_frameset_to_iset(cpl_frameset *) ;
00174 cpl_imagelist * 
00175 sinfo_new_imagelist_load_frameset(const cpl_frameset * frameset,cpl_type type, 
00176                                             int pnum,int extnum);
00177 
00178 char ** sinfo_new_frameset_to_filenames(cpl_frameset *set, int *nfiles);
00179 char ** new_frameset_to_tags(cpl_frameset *set, int *ntags);
00180 
00181 CPL_END_DECLS
00182 
00183 #endif

Generated on Wed Jan 17 08:33:44 2007 for SINFONI Pipeline Reference Manual by  doxygen 1.4.4