sinfo_utilities.h

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

Generated on 3 Mar 2013 for SINFONI Pipeline Reference Manual by  doxygen 1.6.1