SINFONI Pipeline Reference Manual  2.5.2
sinfo_utilities.h
1 /* $Id: sinfo_utilities.h,v 1.13 2011-12-09 07:47:42 amodigli Exp $
2  *
3  * This file is part of the SINFONI Pipeline
4  * Copyright (C) 2002,2003 European Southern Observatory
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 
21 /*
22  * $Author: amodigli $
23  * $Date: 2011-12-09 07:47:42 $
24  * $Revision: 1.13 $
25  * $Name: not supported by cvs2svn $
26  */
27 #ifndef SINFO_UTILITIES_H
28 #define SINFO_UTILITIES_H
29 
30 #ifdef HAVE_CONFIG_H
31 # include <config.h>
32 #endif
33 #include <sinfo_cpl_size.h>
34 
35 /*
36  This recipe implements error handling cleanly using a pair of macros called
37  sinfo_skip_if() and sinfo_end_skip.
38 
39  sinfo_skip_if() takes one argument, which is a logical expression.
40  If the logical expression is false sinfo_skip_if() takes no action and
41  program execution continues.
42  If the logical expression is true this indicates an error. In this case
43  sinfo_skip_if() will set the location of the error to the point where it
44  was invoked in the recipe code (unless the error location is already in the
45  recipe code). If no error code had been set, then sinfo_skip_if() will set
46  one. Finally, sinfo_skip_if() causes program execution to skip to the
47  macro 'sinfo_end_skip'.
48  The macro sinfo_end_skip is located towards the end of the function, after
49  which all resource deallocation and the function return is located.
50 
51  The use of sinfo_skip_if() assumes the following coding practice:
52  1) Pointers used for dynamically allocated memory that they "own" shall
53  always
54  point to either NULL or to allocated memory (including CPL-objects).
55  2) Such pointers may not be reused to point to memory whose deallocation
56  requires calls to different functions.
57  3) Pointers of type FILE should be set NULL when not pointing to an open
58  stream and their closing calls (fclose(), freopen(), etc.) following the
59  'sinfo_end_skip' should be guarded against such NULL pointers.
60 
61  Error checking with sinfo_skip_if() is encouraged due to the following
62  advantages:
63  1) It ensures that a CPL-error code is set.
64  2) It ensures that the location of the error in the _recipe_ code is noted.
65  3) The error checking may be confined to a single concise line.
66  4) It is not necessary to replicate memory deallocation for every error
67  condition.
68  5) If more extensive error reporting/handling is required it is not precluded
69  by the use of sinfo_skip_if().
70  6) It allows for a single point of function return.
71  7) It allows for optional, uniformly formatted debugging/tracing information
72  at each macro invocation.
73 
74  The implementation of sinfo_skip_if() uses a goto/label construction.
75  According to Kerningham & Ritchie, The C Programming Language, 2nd edition,
76  Section 3.8:
77  "This organization is handy if the error-handling code is non-trivial,
78  and if errors can occur in several places."
79 
80  The use of goto for any other purpose should be avoided.
81 
82 */
83 
84 #define sinfo_skip_if(CONDITION) \
85  do if (CONDITION) { \
86  if (cpl_error_get_code()) { \
87  cpl_msg_debug("", "Skip in %s line %d due to '%s' with error '%s' " \
88  "at %s", __FILE__, __LINE__, #CONDITION, \
89  cpl_error_get_message(), cpl_error_get_where()); \
90  if (strstr(cpl_error_get_where(), "visir") == NULL) \
91  cpl_error_set_where(""); \
92  } else { \
93  cpl_msg_debug("", "Skip in %s line %d due to '%s'", \
94  __FILE__, __LINE__, #CONDITION); \
95  cpl_error_set("", CPL_ERROR_UNSPECIFIED); \
96  } \
97  goto cleanup; \
98  } else { \
99  if (cpl_error_get_code()) \
100  cpl_msg_debug("", "No skip in %s line %d due to '%s' with error '%s' " \
101  "at %s", __FILE__, __LINE__, #CONDITION, \
102  cpl_error_get_message(), cpl_error_get_where()); \
103  else \
104  cpl_msg_debug("", "No skip in %s line %d due to '%s'", \
105  __FILE__, __LINE__, #CONDITION); \
106  } while (0)
107 
108 
109 #define sinfo_end_skip \
110  do { \
111  cleanup: \
112  if (cpl_error_get_code()) \
113  cpl_msg_debug("", "Cleanup in %s line %d with error '%s' at %s", \
114  __FILE__, __LINE__, \
115  cpl_error_get_message(), cpl_error_get_where()); \
116  else \
117  cpl_msg_debug("", "Cleanup in %s line %d", \
118  __FILE__, __LINE__); \
119  } while (0)
120 
121 
122 #include <cpl.h>
123 #include <sinfo_image_ops.h>
124 #include "sinfo_globals.h"
125 CPL_BEGIN_DECLS
126 
127 
128 cpl_image*
129 sinfo_vector_to_image(const cpl_vector* vector,cpl_type type);
130 
131 int
132 sinfo_table_column_dump(cpl_table* t, const char* name, cpl_type type);
133 
134 cpl_table*
135 sinfo_table_shift_column_spline3(cpl_table* t,
136  const char* col,
137  const double s);
138 
139 cpl_table*
140 sinfo_table_shift_column_poly(cpl_table* t,
141  const char* col,
142  const double s,
143  const int order);
144 
145 cpl_table*
146 sinfo_table_shift_column_int(const cpl_table* t,
147  const char* col,
148  const double s,
149  double* r);
150 
151 cpl_error_code
152 sinfo_ima_line_cor(cpl_parameterlist * parlist, cpl_frameset* in);
153 
154 
155 void sinfo_new_array_set_value( float * array, float value, int i );
156 float sinfo_new_array_get_value( float * array, int i );
157 void sinfo_new_destroy_array(float ** array);
158 void sinfo_new_destroy_stringarray(char ** array, int size_x);
159 void sinfo_new_intarray_set_value( int * array, int value, int i );
160 void sinfo_new_array2D_set_value( float ** array, float value, int x, int y );
161 void sinfo_new_destroy_2Dintarray(int *** array, int size_x);
162 void sinfo_new_destroy_2Dfloatarray(float *** array, int size_x);
163 void sinfo_new_destroy_2Ddoublearray(double *** array, int size_x);
164 void sinfo_new_destroy_intarray(int ** array);
165 void sinfo_new_destroy_doublearray(double * array);
166 void sinfo_new_doublearray_set_value( double * array, double value, int i );
167 int sinfo_new_intarray_get_value( int * array, int i );
168 int * sinfo_new_intarray( int size);
169 int ** sinfo_new_2Dintarray( int size_x, int size_y);
170 double ** sinfo_new_2Ddoublearray( int size_x, int size_y);
171 char * sinfo_new_get_rootname(const char * filename);
172 char * sinfo_new_get_basename(const char *filename);
173 float sinfo_new_Stats_get_cleanstdev(Stats * stats);
174 float sinfo_new_Stats_get_cleanmean(Stats * stats);
175 float sinfo_new_array2D_get_value( float ** array, int x, int y );
176 float * sinfo_new_floatarray( int size);
177 float ** sinfo_new_2Dfloatarray( int size_x, int size_y);
178 double sinfo_new_doublearray_get_value( double * array, int i );
179 
180 double * sinfo_new_doublearray( int size);
181 /*
182 FitParams ** sinfo_new_fit_params( int n_params ) ;
183 */
184 cpl_imagelist * sinfo_new_frameset_to_iset(cpl_frameset *) ;
185 cpl_imagelist *
186 sinfo_new_imagelist_load_frameset(const cpl_frameset * frameset,cpl_type type,
187  int pnum,int extnum);
188 
189 char ** sinfo_new_frameset_to_filenames(cpl_frameset *set, int *nfiles);
190 char ** new_frameset_to_tags(cpl_frameset *set, int *ntags);
191 double sinfo_spline_hermite(double xp,
192  const double *x,
193  const double *y,
194  int n,
195  int *istart );
196 
197 cpl_error_code update_bad_pixel_map(cpl_image* im);
198 /* replacement of deprecated functions */
199 cpl_polynomial * sinfo_polynomial_fit_2d_create(cpl_bivector * xy_pos,
200  cpl_vector * values,
201  cpl_size degree,
202  double * mse);
203 cpl_polynomial * sinfo_polynomial_fit_1d_create(
204  const cpl_vector * x_pos,
205  const cpl_vector * values,
206  int degree,
207  double * mse
208  );
209 cpl_image * sinfo_image_filter_median(const cpl_image *, const cpl_matrix *);
210 cpl_image * sinfo_image_filter_linear(const cpl_image *, const cpl_matrix *);
211 cpl_image * sinfo_image_filter_linear2(const cpl_image *, const cpl_matrix *);
212 CPL_END_DECLS
213 
214 #endif