uves_error.h

00001 /*
00002  * This file is part of the ESO UVES Pipeline
00003  * Copyright (C) 2004,2005 European Southern Observatory
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
00018  */
00019 
00020 /*
00021  * $Author: amodigli $
00022  * $Date: 2010/09/24 09:32:03 $
00023  * $Revision: 1.58 $
00024  * $Name: uves-4_9_1 $
00025  * $Log: uves_error.h,v $
00026  * Revision 1.58  2010/09/24 09:32:03  amodigli
00027  * put back QFITS dependency to fix problem spot by NRI on FIBER mode (with MIDAS calibs) data
00028  *
00029  * Revision 1.56  2007/08/21 11:08:10  jmlarsen
00030  * Readded checks for pre-existing error which was provided by irplib_error_assure but not by cpl_error_ensure
00031  *
00032  * Revision 1.55  2007/08/13 12:15:58  amodigli
00033  * support of CPL4
00034  *
00035  * Revision 1.54  2007/06/06 08:17:33  amodigli
00036  * replace tab with 4 spaces
00037  *
00038  * Revision 1.53  2007/01/08 16:58:52  amodigli
00039  * added ck0 and cknull
00040  *
00041  * Revision 1.52  2006/11/06 15:19:41  jmlarsen
00042  * Removed unused include directives
00043  *
00044  * Revision 1.51  2006/08/17 13:56:52  jmlarsen
00045  * Reduced max line length
00046  *
00047  * Revision 1.50  2006/06/01 14:43:17  jmlarsen
00048  * Added missing documentation
00049  *
00050  * Revision 1.49  2006/05/05 13:54:11  jmlarsen
00051  * Added assure_mem
00052  *
00053  * Revision 1.48  2006/04/24 09:19:25  jmlarsen
00054  * Minor message change
00055  *
00056  * Revision 1.47  2006/04/06 08:31:52  jmlarsen
00057  * Dump trace on CPL_MSG_ERROR level
00058  *
00059  * Revision 1.46  2006/03/09 10:57:57  jmlarsen
00060  * Added check_nomsg macro
00061  *
00062  * Revision 1.45  2006/03/03 13:54:11  jmlarsen
00063  * Changed syntax of check macro
00064  *
00065  * Revision 1.44  2006/02/28 09:15:22  jmlarsen
00066  * Minor update
00067  *
00068  * Revision 1.43  2006/02/23 16:07:59  jmlarsen
00069  * Using irplib_assert_msg
00070  *
00071  * Revision 1.42  2006/02/21 14:26:54  jmlarsen
00072  * Minor changes
00073  *
00074  * Revision 1.41  2006/02/08 07:52:16  jmlarsen
00075  * Added function returning library version
00076  *
00077  * Revision 1.40  2006/02/03 07:46:30  jmlarsen
00078  * Moved recipe implementations to ./uves directory
00079  *
00080  * Revision 1.39  2006/01/24 07:49:31  jmlarsen
00081  * Removed spaces between backslash and newline
00082  *
00083  * Revision 1.38  2006/01/23 08:08:53  jmlarsen
00084  * Updated documentation
00085  *
00086  * Revision 1.37  2005/12/19 16:17:56  jmlarsen
00087  * Replaced bool -> int
00088  *
00089  */
00090 
00091 #ifndef UVES_ERROR_H
00092 #define UVES_ERROR_H
00093 
00094 /*----------------------------------------------------------------------------*/
00098 /*----------------------------------------------------------------------------*/
00101 /*-----------------------------------------------------------------------------
00102                     Includes
00103  -----------------------------------------------------------------------------*/
00104 #include <uves_utils.h>
00105 #include <uves_msg.h>
00106 
00107 #if defined CPL_VERSION_CODE && CPL_VERSION_CODE < CPL_VERSION(4, 0, 0)
00108 #include <irplib_error.h>
00109 #endif
00110 
00111 #include <cpl_error.h>
00112 
00113 /*-----------------------------------------------------------------------------
00114                              Defines
00115  -----------------------------------------------------------------------------*/
00116 /* To save some key-strokes, use the irplib error handling macros
00117    under different (shorter) names.
00118    Additionally, irplib macros require the VA_ARGS to be enclosed in (),
00119 */
00120 
00121 #if defined CPL_VERSION_CODE && CPL_VERSION_CODE >= CPL_VERSION(4, 0, 0)
00122 
00125 #define assure(BOOL, CODE, ...) \
00126 do {                                                              \
00127     cpl_error_ensure(cpl_error_get_code() == CPL_ERROR_NONE,      \
00128                      cpl_error_get_code(), goto cleanup,          \
00129                      "An error occurred that was not caught: %s", \
00130                      cpl_error_get_where() );                     \
00131     cpl_error_ensure(BOOL, CODE, goto cleanup, __VA_ARGS__);      \
00132 } while (0)
00133 
00135 #define assure_nomsg(BOOL, CODE) \
00136     assure(BOOL, CODE, " ")
00137 
00139 #define assure_mem(PTR) \
00140     assure((PTR) != NULL, CPL_ERROR_ILLEGAL_OUTPUT, "Memory allocation failure!")
00141 
00142 #define ck0(IEXP, ...) \
00143     assure((IEXP) == 0, CPL_ERROR_UNSPECIFIED, __VA_ARGS__)
00144 
00145 #define ck0_nomsg(IEXP) ck0(IEXP, " ")
00146 
00147 #define cknull(NULLEXP, ...)  \
00148     assure((NULLEXP) != NULL, CPL_ERROR_UNSPECIFIED, __VA_ARGS__)
00149 
00150 #define cknull_nomsg(NULLEXP) cknull(NULLEXP, " ")
00151 
00152 
00154 #define  check(CMD, ...) \
00155     assure((uves_msg_softer(), (CMD), uves_msg_louder(),  \
00156             cpl_error_get_code() == CPL_ERROR_NONE),      \
00157             cpl_error_get_code(), __VA_ARGS__)
00158 
00160 #define  check_nomsg(CMD) check(CMD, " ")
00161 
00163 #define passure(BOOL, ...) \
00164     assure(BOOL, CPL_ERROR_UNSPECIFIED, \
00165            "Internal error. Please report to " PACKAGE_BUGREPORT " " __VA_ARGS__ )
00166            /*  Assumes that PACKAGE_BUGREPORT
00167                contains no formatting special characters  */
00168 
00170 #define uves_error_reset() cpl_error_reset()
00171 
00172 
00173 #else // if we still test CPL31
00174 
00175 
00176 #define assure(BOOL, CODE, ...) \
00177   irplib_error_assure(BOOL, CODE, (__VA_ARGS__), goto cleanup)
00178 
00180 #define assure_nomsg(BOOL, CODE) \
00181   irplib_error_assure(BOOL, CODE, (" "), goto cleanup)
00182 
00184 #define assure_mem(PTR) \
00185   irplib_error_assure((PTR) != NULL, CPL_ERROR_ILLEGAL_OUTPUT, \
00186   ("Memory allocation failure!"), goto cleanup)
00187 #define ck0(IEXP, ...) \
00188   irplib_error_assure(IEXP == 0, CPL_ERROR_UNSPECIFIED, \
00189   (__VA_ARGS__), goto cleanup)
00190 
00191 #define ck0_nomsg(IEXP) ck0(IEXP," ")
00192 
00193 #define cknull(NULLEXP, ...) \
00194   irplib_error_assure((NULLEXP) != NULL, \
00195   CPL_ERROR_UNSPECIFIED, (__VA_ARGS__), goto cleanup)
00196 
00197 #define cknull_nomsg(NULLEXP) cknull(NULLEXP," ")
00198 
00199 
00201 #define  check(CMD, ...)                                                 \
00202   irplib_error_assure((uves_msg_softer(), (CMD), uves_msg_louder(),      \
00203               cpl_error_get_code() == CPL_ERROR_NONE),       \
00204                        cpl_error_get_code(), (__VA_ARGS__), goto cleanup)
00205 
00207 #define  check_nomsg(CMD) check(CMD, " ")
00208 
00210 #define passure(BOOL, ...)                                               \
00211   irplib_error_assure(BOOL, CPL_ERROR_UNSPECIFIED,                       \
00212                      ("Internal error. Please report to "                \
00213                       PACKAGE_BUGREPORT " " __VA_ARGS__), goto cleanup)
00214                        /*  Assumes that PACKAGE_BUGREPORT
00215                contains no formatting special characters  */
00216 
00218 #define uves_error_reset()   \
00219       irplib_error_reset()
00220 
00222 #define uves_error_dump()  \
00223       irplib_error_dump(CPL_MSG_ERROR, CPL_MSG_ERROR)
00224 
00225 #endif //end check on CPL version
00226 
00235 /*----------------------------------------------------------------------------*/
00502 /*----------------------------------------------------------------------------*/
00503 
00504 #endif
00505 
00506 
00507 
00508 
00509 
00510 
00511 
00512 
00513 
00514 
00515 
00516 
00517 
00518 
00519 
00520 
00521 
00522 
00523 
00524 
00525 
00526 
00527 

Generated on 8 Mar 2011 for UVES Pipeline Reference Manual by  doxygen 1.6.1