Ignore:
Timestamp:
Jan 15, 2009, 3:32:36 PM (12 years ago)
Author:
Jari Häkkinen
Message:

Fixes #466. GSL_error is now thrown on GSL errors. Last thing in this ticket.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/regression/GSLInterpolation.cc

    r1655 r1724  
    22
    33/*
    4   Copyright (C) 2008 Jari Häkkinen
     4  Copyright (C) 2008, 2009 Jari Häkkinen
    55
    66  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    2222#include "GSLInterpolation.h"
    2323
     24#include "yat/utility/Exception.h"
    2425#include "yat/utility/VectorBase.h"
    2526
    2627#include <cassert>
     28#include <sstream>
    2729
    2830namespace theplu {
     
    3436                                     const utility::VectorBase& x,
    3537                                     const utility::VectorBase& y)
    36     : evaluation_(0.0), gsl_status_(0)
     38    : evaluation_(0.0)
    3739  {
    3840    assert(x.size()==y.size());
     
    4547    }
    4648    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    }
    4856    accelerator_ = gsl_interp_accel_alloc();
    4957  }
     
    5260  GSLInterpolation::~GSLInterpolation(void)
    5361  {
     62    gsl_interp_accel_free(accelerator_);
    5463    gsl_interp_free(interpolator_);
    55     gsl_interp_accel_free(accelerator_);
    5664    delete x_;
    5765    delete y_;
     
    5967
    6068
    61   int GSLInterpolation::error_status(void) const
    62   {
    63     return gsl_status_;
    64   }
    65 
    66 
    6769  double GSLInterpolation::evaluate(double x)
    6870  {
    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    }
    7177    return evaluation_;
    7278  }
     
    7581  double GSLInterpolation::evaluate_derivative(double x)
    7682  {
    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    }
    7989    return evaluation_;
    8090  }
     
    8393  double GSLInterpolation::evaluate_derivative2(double x)
    8494  {
    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    }
    87101    return evaluation_;
    88102  }
     
    91105  double GSLInterpolation::evaluate_integral(double a, double b)
    92106  {
    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    }
    95113    return evaluation_;
    96114  }
Note: See TracChangeset for help on using the changeset viewer.