- Timestamp:
- Jan 15, 2009, 3:32:36 PM (12 years ago)
- Location:
- trunk/yat/regression
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/yat/regression/GSLInterpolation.cc
r1655 r1724 2 2 3 3 /* 4 Copyright (C) 2008 Jari Häkkinen4 Copyright (C) 2008, 2009 Jari Häkkinen 5 5 6 6 This file is part of the yat library, http://dev.thep.lu.se/yat … … 22 22 #include "GSLInterpolation.h" 23 23 24 #include "yat/utility/Exception.h" 24 25 #include "yat/utility/VectorBase.h" 25 26 26 27 #include <cassert> 28 #include <sstream> 27 29 28 30 namespace theplu { … … 34 36 const utility::VectorBase& x, 35 37 const utility::VectorBase& y) 36 : evaluation_(0.0) , gsl_status_(0)38 : evaluation_(0.0) 37 39 { 38 40 assert(x.size()==y.size()); … … 45 47 } 46 48 interpolator_ = gsl_interp_alloc(interpolator_type, size); 47 gsl_status_=gsl_interp_init(interpolator_, x_, y_, size); 49 if (int status=gsl_interp_init(interpolator_, x_, y_, size)) { 50 std::stringstream ss("GSLInterpolation::GSLInterpolation "); 51 ss << " GSL error code " << status; 52 // clean up 53 gsl_interp_free(interpolator_); 54 throw utility::GSL_error(ss.str()); 55 } 48 56 accelerator_ = gsl_interp_accel_alloc(); 49 57 } … … 52 60 GSLInterpolation::~GSLInterpolation(void) 53 61 { 62 gsl_interp_accel_free(accelerator_); 54 63 gsl_interp_free(interpolator_); 55 gsl_interp_accel_free(accelerator_);56 64 delete x_; 57 65 delete y_; … … 59 67 60 68 61 int GSLInterpolation::error_status(void) const62 {63 return gsl_status_;64 }65 66 67 69 double GSLInterpolation::evaluate(double x) 68 70 { 69 gsl_status_=gsl_interp_eval_e(interpolator_, x_, y_, x, accelerator_, 70 &evaluation_); 71 if (int status=gsl_interp_eval_e(interpolator_, x_, y_, x, accelerator_, 72 &evaluation_)) { 73 std::stringstream ss("GSLInterpolation::evaluate "); 74 ss << " GSL error code " << status; 75 throw utility::GSL_error(ss.str()); 76 } 71 77 return evaluation_; 72 78 } … … 75 81 double GSLInterpolation::evaluate_derivative(double x) 76 82 { 77 gsl_status_=gsl_interp_eval_deriv_e(interpolator_, x_, y_, x, accelerator_, 78 &evaluation_); 83 if (int status=gsl_interp_eval_deriv_e(interpolator_, x_, y_, x, 84 accelerator_, &evaluation_)) { 85 std::stringstream ss("GSLInterpolation::evaluate_derivative "); 86 ss << " GSL error code " << status; 87 throw utility::GSL_error(ss.str()); 88 } 79 89 return evaluation_; 80 90 } … … 83 93 double GSLInterpolation::evaluate_derivative2(double x) 84 94 { 85 gsl_status_=gsl_interp_eval_deriv2_e(interpolator_, x_, y_, x, accelerator_, 86 &evaluation_); 95 if (int status=gsl_interp_eval_deriv2_e(interpolator_, x_, y_, x, 96 accelerator_, &evaluation_)) { 97 std::stringstream ss("GSLInterpolation::evaluate_derivative2 "); 98 ss << " GSL error code " << status; 99 throw utility::GSL_error(ss.str()); 100 } 87 101 return evaluation_; 88 102 } … … 91 105 double GSLInterpolation::evaluate_integral(double a, double b) 92 106 { 93 gsl_status_=gsl_interp_eval_integ_e(interpolator_, x_, y_, a, b, 94 accelerator_, &evaluation_); 107 if (int status=gsl_interp_eval_integ_e(interpolator_, x_, y_, a, b, 108 accelerator_, &evaluation_)) { 109 std::stringstream ss("GSLInterpolation::evaluate_integral "); 110 ss << " GSL error code " << status; 111 throw utility::GSL_error(ss.str()); 112 } 95 113 return evaluation_; 96 114 } -
trunk/yat/regression/GSLInterpolation.h
r1722 r1724 52 52 determined by the type of interpolation used. 53 53 54 Some underlying GSL functions return GSL error codes. The error 55 code is stored internally and should be checked for by the caller 56 using GSLInterpolation::error_status(void). Refer to the 57 gsl_errno.h for the error code listing. 54 When underlying GSL functions return GSL error an GSL_error is 55 thrown. Refer to the gsl_errno.h for the error code listing. 58 56 59 57 \since New in yat 0.5 … … 73 71 not defined. 74 72 75 Some underlying GSL functions return GSL error codes. The error 76 code is stored internally and should be checked for by the 77 caller. Refer to the gsl_errno.h for the error code listing. 78 79 \see error_status(void) 73 \throw GSL_error if some underlying GSL functions return GSL 74 error. Refer to gsl_errno.h for the error code listing. 80 75 */ 81 76 GSLInterpolation(const gsl_interp_type*, const utility::VectorBase& x, … … 88 83 89 84 /** 90 \brief Check the error status91 92 Some underlying GSL functions return GSL error codes. The error93 code is stored internally and should be checked for by the94 caller. Refer to the gsl_errno.h for the error code listing.95 96 \return The current error status. A zero return values97 indicates no errors where encountered.98 */99 int error_status(void) const;100 101 /**102 85 \brief Calculate the interpolated value for \a x. 103 104 GSL error status is set if evaluation is requested outside the105 range defined by the interpolation algorithm. Use function106 error_status to check for errors.107 86 108 87 \return The interpolated value of \f$ y \f$ for a given point 109 88 \a x. 110 89 111 \see error_status(void) 90 \throw GSL_error if evaluation is requested outside the range 91 defined by the interpolation algorithm. 112 92 */ 113 93 double evaluate(double x); … … 117 97 \a x. 118 98 119 GSL error status is set if evaluation is requested outside the120 range defined by the interpolation algorithm. Use function121 error_status to check for errors.122 123 99 \return The derivative. 124 100 125 \see error_status(void) 101 \throw GSL_error if evaluation is requested outside the range 102 defined by the interpolation algorithm. 126 103 */ 127 104 double evaluate_derivative(double x); … … 131 108 function at \a x. 132 109 133 GSL error status is set if evaluation is requested outside the134 range defined by the interpolation algorithm. Use function135 error_status to check for errors.136 137 110 \return The 2nd derivative. 138 111 139 \see error_status(void) 112 \throw GSL_error if evaluation is requested outside the range 113 defined by the interpolation algorithm. 140 114 */ 141 115 double evaluate_derivative2(double x); … … 145 119 function over the range \f$ [a,b] \f$. 146 120 147 GSL error status is set if evaluation is requested outside the148 range defined by the interpolation algorithm. Use function149 error_status to check for errors.150 151 121 \return The integral. 152 122 153 \see error_status(void) 123 \throw GSL_error if evaluation is requested outside the range 124 defined by the interpolation algorithm. 154 125 */ 155 126 double evaluate_integral(double a, double b); … … 185 156 double evaluation_; 186 157 gsl_interp* interpolator_; 187 int gsl_status_;188 158 double* x_; 189 159 double* y_;
Note: See TracChangeset
for help on using the changeset viewer.