• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

dsplint.c

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2009 Alan W. Irwin
00003 //
00004 // This file is part of PLplot.
00005 //
00006 // PLplot is free software; you can redistribute it and/or modify
00007 // it under the terms of the GNU Library General Public License as published
00008 // by the Free Software Foundation; either version 2 of the License, or
00009 // (at your option) any later version.
00010 //
00011 // PLplot is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU Library General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Library General Public License
00017 // along with PLplot; if not, write to the Free Software
00018 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019 //
00020 // Provenance: This code was originally developed under the GPL as part of
00021 // the FreeEOS project (revision 121).  This code has been converted from
00022 // Fortran to C with the aid of f2c and relicensed for PLplot under the LGPL
00023 // with the permission of the FreeEOS copyright holder (Alan W. Irwin).
00024 //
00025 # define MAX( a, b )    ( ( ( a ) > ( b ) ) ? ( a ) : ( b ) )
00026 # define MIN( a, b )    ( ( ( a ) < ( b ) ) ? ( a ) : ( b ) )
00027 
00028 //int dsplint(double *xa, double *ya, double *y2a,
00029 //          int n, double x, double *y, double *dy, double *d2y)
00030 int dsplint( double *xa, double *ya, double *y2a,
00031              int n, double x, double *y )
00032 {
00033     // Initialized data
00034 
00035     static int nsave = 0, khi, klo;
00036 
00037     int        i__1, i__2, k;
00038     double     a, b, h__;
00039 
00040 //      evaluate spline = y and its derivatives dy and d2y at x given
00041 //      xa, ya, y2a from dspline.
00042     // Parameter adjustments
00043     --y2a;
00044     --ya;
00045     --xa;
00046 
00047     // Function Body
00048     if ( n != nsave )
00049     {
00050 //        if call with different n value, then redo range
00051         nsave = n;
00052         klo   = 1;
00053         khi   = n;
00054         if ( xa[klo] > x )
00055         {
00056             return 1;
00057         }
00058         if ( xa[khi] < x )
00059         {
00060             return 2;
00061         }
00062     }
00063     else
00064     {
00065 //        optimize range assuming continuous (ascending or
00066 //        descending x calls.
00067         if ( xa[klo] > x )
00068         {
00069 //          x is descending so try next range.
00070             khi = MAX( 2, klo );
00071             klo = khi - 1;
00072 //          if x smaller than next range try lower limit.
00073             if ( xa[klo] > x )
00074             {
00075                 klo = 1;
00076             }
00077             if ( xa[klo] > x )
00078             {
00079                 return 1;
00080             }
00081         }
00082         else if ( xa[khi] <= x )
00083         {
00084 //          x is ascending so try next range.
00085 // Computing MIN
00086             i__1 = khi, i__2 = n - 1;
00087             klo  = MIN( i__1, i__2 );
00088             khi  = klo + 1;
00089 //          if x larger than next range try upper limit.
00090             if ( xa[khi] <= x )
00091             {
00092                 khi = n;
00093             }
00094             if ( xa[khi] < x )
00095             {
00096                 return 2;
00097             }
00098         }
00099     }
00100     while ( khi - klo > 1 )
00101     {
00102         k = ( khi + klo ) / 2;
00103         if ( xa[k] > x )
00104         {
00105             khi = k;
00106         }
00107         else
00108         {
00109             klo = k;
00110         }
00111     }
00112     h__ = xa[khi] - xa[klo];
00113     if ( h__ <= 0. )
00114     {
00115         return 3;
00116     }
00117     a  = ( xa[khi] - x ) / h__;
00118     b  = ( x - xa[klo] ) / h__;
00119     *y = a * ya[klo] + b * ya[khi] + ( a * ( a * a - 1. ) * y2a[klo] + b * ( b *
00120                                                                              b - 1. ) * y2a[khi] ) * ( h__ * h__ ) / 6.;
00121 //    *dy = (-ya[klo] + ya[khi] + (-(a * 3. * a - 1.) * y2a[klo] + (b * 3. * b
00122 //          - 1.) * y2a[khi]) * (h__ * h__) / 6.) / h__;
00123 //d2y = a * y2a[klo] + b * y2a[khi];
00124     return 0;
00125 }
00126 

Generated on Wed Oct 12 2011 20:42:21 for PLplot by  doxygen 1.7.1