GSLInterpolator.cxx

Go to the documentation of this file.
00001 // @(#)root/mathmore:$Id: GSLInterpolator.cxx 32000 2010-01-13 16:06:44Z moneta $
00002 // Authors: L. Moneta, A. Zsenei   08/2005 
00003 
00004  /**********************************************************************
00005   *                                                                    *
00006   * Copyright (c) 2004 ROOT Foundation,  CERN/PH-SFT                   *
00007   *                                                                    *
00008   * This library is free software; you can redistribute it and/or      *
00009   * modify it under the terms of the GNU General Public License        *
00010   * as published by the Free Software Foundation; either version 2     *
00011   * of the License, or (at your option) any later version.             *
00012   *                                                                    *
00013   * This library is distributed in the hope that it will be useful,    *
00014   * but WITHOUT ANY WARRANTY; without even the implied warranty of     *
00015   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   *
00016   * General Public License for more details.                           *
00017   *                                                                    *
00018   * You should have received a copy of the GNU General Public License  *
00019   * along with this library (see file COPYING); if not, write          *
00020   * to the Free Software Foundation, Inc., 59 Temple Place, Suite      *
00021   * 330, Boston, MA 02111-1307 USA, or contact the author.             *
00022   *                                                                    *
00023   **********************************************************************/
00024 
00025 // Implementation file for class GSLInterpolator
00026 // 
00027 // Created by: moneta  at Sun Nov 28 08:54:48 2004
00028 // 
00029 // Last update: Sun Nov 28 08:54:48 2004
00030 // 
00031 
00032 #include "GSLInterpolator.h"
00033 
00034 
00035 #include <cassert>
00036 
00037 namespace ROOT {
00038 namespace Math {
00039 
00040 
00041 GSLInterpolator::GSLInterpolator (unsigned int size, Interpolation::Type type) : 
00042    fAccel(0),
00043    fSpline(0)
00044 { 
00045    // constructor given type and vectors of (x,y) points
00046 
00047    switch ( type )  
00048    {
00049       case ROOT::Math::Interpolation::kLINEAR          : 
00050          fInterpType = gsl_interp_linear; 
00051          break ;
00052       case ROOT::Math::Interpolation::kPOLYNOMIAL       :
00053          fInterpType = gsl_interp_polynomial; 
00054          break ;
00055          // depened on GSL linear algebra
00056       case ROOT::Math::Interpolation::kCSPLINE         :
00057          fInterpType = gsl_interp_cspline ;          
00058          break ;
00059       case ROOT::Math::Interpolation::kCSPLINE_PERIODIC :
00060          fInterpType = gsl_interp_cspline_periodic  ; 
00061          break ;
00062       case ROOT::Math::Interpolation::kAKIMA            :
00063          fInterpType = gsl_interp_akima; 
00064          break ;
00065       case ROOT::Math::Interpolation::kAKIMA_PERIODIC   :
00066          fInterpType = gsl_interp_akima_periodic; 
00067          break ;
00068       default :
00069          // cspline
00070          fInterpType = gsl_interp_cspline;   
00071          break ;
00072    }
00073    // allocate objects
00074    
00075    if (size >= fInterpType->min_size) 
00076       fSpline = gsl_spline_alloc( fInterpType, size); 
00077 
00078 }   
00079 
00080 bool  GSLInterpolator::Init(unsigned int size, const double *x, const double * y) {       
00081    // initialize interpolation object with the given data 
00082    // if given size is different a new interpolator object is created
00083    if (fSpline == 0)   
00084       fSpline = gsl_spline_alloc( fInterpType, size);
00085 
00086    else {
00087       gsl_interp * interp = fSpline->interp; 
00088       if (size != interp->size) { 
00089          //  free and reallocate a new object
00090          gsl_spline_free(fSpline);
00091          fSpline = gsl_spline_alloc( fInterpType, size);
00092          
00093       }
00094    }
00095    if (!fSpline) return false;
00096 
00097    int iret = gsl_spline_init( fSpline , x , y , size );
00098    if (iret != 0) return false; 
00099    
00100    fAccel  = gsl_interp_accel_alloc() ; 
00101    
00102    //  if (fSpline == 0 || fAccel == 0) 
00103    //  throw std::exception();
00104    assert (fSpline != 0); 
00105    assert (fAccel != 0); 
00106    return true;
00107 }
00108 
00109 GSLInterpolator::~GSLInterpolator() 
00110 {
00111    // free gsl objects
00112    if (fSpline != 0) gsl_spline_free(fSpline); 
00113    if (fAccel != 0) gsl_interp_accel_free( fAccel);
00114 }
00115 
00116 GSLInterpolator::GSLInterpolator(const GSLInterpolator &) 
00117 {
00118    // dummy copy ctr
00119 }
00120 
00121 GSLInterpolator & GSLInterpolator::operator = (const GSLInterpolator &rhs) 
00122 {
00123    // dummy assignment operator
00124    if (this == &rhs) return *this;  // time saving self-test
00125    
00126    return *this;
00127 }
00128 
00129 
00130 } // namespace Math
00131 } // namespace ROOT

Generated on Tue Jul 5 14:34:56 2011 for ROOT_528-00b_version by  doxygen 1.5.1