OPERA
1.0
Open source echelle spectrograph reduction pipeline
|
00001 #ifndef OPERAERROR_H 00002 #define OPERAERROR_H 00003 00004 #include <stdio.h> 00005 #include <stdarg.h> 00006 #include <string.h> 00007 #include <limits.h> 00008 #include <errno.h> 00009 00010 #define MAXERRSTRINGSIZE 4096 00011 typedef int operaErrorCode; 00012 00013 /* 00014 * errno uses 1-131 00015 * do not use those ranges 00016 */ 00017 00018 /* 00019 * Standard opera error codes. 00020 */ 00021 00022 #define operaErrorCodeOK 0 00023 00024 00025 #define operaErrorIsInf 32759 00026 #define operaErrorIsNaN 32760 00027 #define operaErrorHeaderProblem 32761 00028 #define operaErrorNoBadPixelMask 32762 00029 #define operaErrorPickOutofRange 32763 00030 #define operaErrorNoInput 32764 00031 #define operaErrorNoOutput 32765 00032 #define operaErrorCodeNOTIMPLEMENTED 32766 00033 #define operaErrorCodeNULL 32767 00034 #define operaErrorCodeNULLString 32768 00035 00036 /* 00037 * opera libraries. 00038 */ 00039 00040 #define operaErrorCodeEnvironmentnotset 701 00041 #define operaErrorCodeDatatypeNotSupported 702 00042 #define operaErrorCodeNoFilename 703 00043 #define operaErrorCodeTileError 704 00044 #define operaErrorCodeBracketingError 705 00045 00046 /* 00047 * operaReductionSet 800-820 00048 */ 00049 #define operaErrorReductionSetEtypeNotDefined 800 00050 #define operaErrorReductionSetQualiKeyNotDefined 801 00051 #define operaErrorReductionSetQualiValNotDefined 802 00052 #define operaErrorReductionSetObstypeKeyNotDefined 803 00053 #define operaErrorReductionSetEtypeFailed 804 00054 #define operaErrorReductionSetInputNotFound 805 00055 00056 /* 00057 * modules 900 - 1000 00058 */ 00059 00060 /* 00061 * cfitsio uses 101-159, 201-264, 301-264, 401-436, 501-599 00062 * do not use those ranges 00063 */ 00064 00065 // defined by libraries that just want the error codes 00066 // and not these routines 00067 #include "fitsio.h" 00068 00069 #ifndef OPERAERRRORCODESONLY 00070 00071 #ifdef __cplusplus 00072 #include <string> 00073 using namespace std; 00082 static string operaErrorString = ""; 00083 static string operaStrError(const operaErrorCode errcode) { 00084 if (errcode <= 100) { 00085 operaErrorString = strerror(errcode); 00086 } else if (errcode < 600) { 00087 char fitserrbuff[80]; 00088 fits_get_errstatus(errcode, fitserrbuff); 00089 operaErrorString = string(fitserrbuff); 00090 } else switch (errcode) { 00091 case 0: 00092 operaErrorString = string(""); 00093 break; 00094 00095 /* Generic */ 00096 case operaErrorCodeNULL: 00097 operaErrorString = string("NULL value"); 00098 break; 00099 case operaErrorCodeNOTIMPLEMENTED: 00100 operaErrorString = string("not implemented"); 00101 break; 00102 case operaErrorCodeNULLString: 00103 operaErrorString = string("NULL string"); 00104 break; 00105 case operaErrorPickOutofRange: 00106 operaErrorString = string("pick out of range"); 00107 break; 00108 case operaErrorNoInput: 00109 operaErrorString = string("no inputs specified"); 00110 break; 00111 case operaErrorNoOutput: 00112 operaErrorString = string("no output specified"); 00113 break; 00114 case operaErrorHeaderProblem: 00115 operaErrorString = string("header problem"); 00116 break; 00117 case operaErrorIsNaN: 00118 operaErrorString = string("Invalid floating point number (NaN)"); 00119 break; 00120 case operaErrorIsInf: 00121 operaErrorString = string("Invalid floating point number (Inf)"); 00122 break; 00123 00124 /* Libraries */ 00125 case operaErrorCodeEnvironmentnotset: 00126 operaErrorString = string("environment variable \"opera\" not set"); 00127 break; 00128 case operaErrorCodeDatatypeNotSupported: 00129 operaErrorString = string("datatype not supported"); 00130 break; 00131 case operaErrorCodeNoFilename: 00132 operaErrorString = string("no filename"); 00133 break; 00134 case operaErrorCodeTileError: 00135 operaErrorString = string("tiling error"); 00136 break; 00137 case operaErrorCodeBracketingError: 00138 operaErrorString = string("improper bracketing of operands, got a bool, need an operaFITSImage*"); 00139 break; 00140 00141 00142 /* reductionset */ 00143 case operaErrorReductionSetEtypeNotDefined: 00144 operaErrorString = string("Error: ETYPE option is not defined in config file"); 00145 break; 00146 case operaErrorReductionSetQualiKeyNotDefined: 00147 operaErrorString = string("Error: QUALIFIER_HEADERKEY is not defined in config file"); 00148 break; 00149 case operaErrorReductionSetQualiValNotDefined: 00150 operaErrorString = string("Error: QUALIFIER_HEADERVALUE is not defined in config file"); 00151 break; 00152 case operaErrorReductionSetObstypeKeyNotDefined: 00153 operaErrorString = string("Error: OBSTYPE_HEADERKEY is not defined in config file"); 00154 break; 00155 case operaErrorReductionSetEtypeFailed: 00156 operaErrorString = string("Error: Failed to read ETYPE_HEADERVALUE"); 00157 break; 00158 case operaErrorReductionSetInputNotFound: 00159 operaErrorString = string("Error: Failed to access input file"); 00160 break; 00161 00162 default: 00163 break; 00164 } 00165 return operaErrorString; 00166 } 00175 static void operaPError(string prefix, const operaErrorCode errcode) { 00176 cerr << prefix << ": " << operaStrError(errcode) << '\n'; 00177 } 00178 00179 #else 00180 00188 static char operaErrorString[MAXERRSTRINGSIZE]; 00189 static char *operaStrError(const operaErrorCode errcode) { 00190 if (errcode <= 100) { 00191 strncpy(operaErrorString, strerror(errcode), sizeof(operaErrorString)); 00192 } else if (errcode < 600) { 00193 fits_get_errstatus(errcode, operaErrorString); 00194 } else switch (errcode) { 00195 case 0: 00196 operaErrorString[0] = '\0'; 00197 break; 00198 00199 /* generic */ 00200 case operaErrorCodeNULL: 00201 strncpy(operaErrorString, "NULL value", sizeof(operaErrorString)); 00202 break; 00203 case operaErrorCodeNULLString: 00204 strncpy(operaErrorString, "NULL string", sizeof(operaErrorString)); 00205 break; 00206 case operaErrorPickOutofRange: 00207 strncpy(operaErrorString, "pick out of range", sizeof(operaErrorString)); 00208 break; 00209 case operaErrorNoInput: 00210 strncpy(operaErrorString, "no inputs specified", sizeof(operaErrorString)); 00211 break; 00212 case operaErrorNoOutput: 00213 strncpy(operaErrorString, "no output specified", sizeof(operaErrorString)); 00214 break; 00215 case operaErrorHeaderProblem: 00216 strncpy(operaErrorString, "header problem", sizeof(operaErrorString)); 00217 break; 00218 case operaErrorIsNaN: 00219 strncpy(operaErrorString, "Invalid floating point number (NaN)", sizeof(operaErrorString)); 00220 break; 00221 case operaErrorIsInf: 00222 strncpy(operaErrorString, "Invalid floating point number (Inf)", sizeof(operaErrorString)); 00223 break; 00224 00225 /* Libraries */ 00226 case operaErrorCodeEnvironmentnotset: 00227 strncpy(operaErrorString, "environment variable \"opera\" not set", sizeof(operaErrorString)); 00228 break; 00229 case operaErrorCodeDatatypeNotSupported: 00230 strncpy(operaErrorString, "datatype not supported", sizeof(operaErrorString)); 00231 break; 00232 case operaErrorCodeNoFilename: 00233 strncpy(operaErrorString, "no filename", sizeof(operaErrorString)); 00234 break; 00235 case operaErrorCodeTileError: 00236 strncpy(operaErrorString, "tiling error", sizeof(operaErrorString)); 00237 break; 00238 case operaErrorCodeBracketingError: 00239 strncpy(operaErrorString, "improper bracketing of operands, got a bool, need an operaFITSImage*", sizeof(operaErrorString)); 00240 break; 00241 00242 /* reductionset */ 00243 case operaErrorReductionSetEtypeNotDefined: 00244 strncpy(operaErrorString, "Error: ETYPE option is not defined in config file", sizeof(operaErrorString)); 00245 break; 00246 case operaErrorReductionSetQualiKeyNotDefined: 00247 strncpy(operaErrorString, "Error: QUALIFIER_HEADERKEY is not defined in config file", sizeof(operaErrorString)); 00248 break; 00249 case operaErrorReductionSetQualiValNotDefined: 00250 strncpy(operaErrorString, "Error: QUALIFIER_HEADERVALUE is not defined in config file", sizeof(operaErrorString)); 00251 break; 00252 case operaErrorReductionSetObstypeKeyNotDefined: 00253 strncpy(operaErrorString, "Error: OBSTYPE_HEADERKEY is not defined in config file", sizeof(operaErrorString)); 00254 break; 00255 case operaErrorReductionSetEtypeFailed: 00256 strncpy(operaErrorString, "Error: Failed to read ETYPE_HEADERVALUE", sizeof(operaErrorString)); 00257 break; 00258 case operaErrorReductionSetInputNotFound: 00259 break; 00260 00261 default: 00262 break; 00263 } 00264 return operaErrorString; 00265 } 00274 static void operaPError(const char *prefix, const operaErrorCode errcode) { 00275 if (prefix == NULL) { 00276 fprintf(stderr, "%s\n", operaStrError(errcode)); 00277 } else { 00278 fprintf(stderr, "%s: %s\n", prefix, operaStrError(errcode)); 00279 } 00280 } 00281 00282 #endif // __cplusplus 00283 #endif // OPERAERRRORCODESONLY 00284 #endif // OPERAERROR_H