Changeset 1724 for trunk/yat/regression/GSLInterpolation.cc
 Timestamp:
 Jan 15, 2009, 3:32:36 PM (12 years ago)
 File:

 1 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 }
Note: See TracChangeset
for help on using the changeset viewer.