| 1 |
/* @(#)ratint.c 19.1 (ES0-DMD) 02/25/03 13:43:14 */ |
| 2 |
/*=========================================================================== |
| 3 |
Copyright (C) 1995 European Southern Observatory (ESO) |
| 4 |
|
| 5 |
This program is free software; you can redistribute it and/or |
| 6 |
modify it under the terms of the GNU General Public License as |
| 7 |
published by the Free Software Foundation; either version 2 of |
| 8 |
the License, or (at your option) any later version. |
| 9 |
|
| 10 |
This program is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
GNU General Public License for more details. |
| 14 |
|
| 15 |
You should have received a copy of the GNU General Public |
| 16 |
License along with this program; if not, write to the Free |
| 17 |
Software Foundation, Inc., 675 Massachusetss Ave, Cambridge, |
| 18 |
MA 02139, USA. |
| 19 |
|
| 20 |
Corresponding concerning ESO-MIDAS should be addressed as follows: |
| 21 |
Internet e-mail: [email protected] |
| 22 |
Postal address: European Southern Observatory |
| 23 |
Data Management Division |
| 24 |
Karl-Schwarzschild-Strasse 2 |
| 25 |
D 85748 Garching bei Muenchen |
| 26 |
GERMANY |
| 27 |
===========================================================================*/ |
| 28 |
|
| 29 |
#include <math.h> |
| 30 |
|
| 31 |
#define TINY 1.0e-25 |
| 32 |
#define FREERETURN {free_vector(d,1,n);free_vector(c,1,n);return;} |
| 33 |
|
| 34 |
void ratint(xa,ya,n,x,y,dy) |
| 35 |
float xa[],ya[],x,*y,*dy; |
| 36 |
int n; |
| 37 |
{ |
| 38 |
int m,i,ns=1; |
| 39 |
float w,t,hh,h,dd,*c,*d,*vector(); |
| 40 |
void nrerror(),free_vector(); |
| 41 |
c=vector(1,n); |
| 42 |
d=vector(1,n); |
| 43 |
hh=fabs(x-xa[1]); |
| 44 |
for (i=1;i<=n;i++) { |
| 45 |
h=fabs(x-xa[i]); |
| 46 |
if (h == 0.0) { |
| 47 |
*y=ya[i]; |
| 48 |
*dy=0.0; |
| 49 |
FREERETURN |
| 50 |
} else if (h < hh) { |
| 51 |
ns=i; |
| 52 |
hh=h; |
| 53 |
} |
| 54 |
c[i]=ya[i]; |
| 55 |
d[i]=ya[i]+TINY; |
| 56 |
} |
| 57 |
*y=ya[ns--]; |
| 58 |
for (m=1;m<n;m++) { |
| 59 |
for (i=1;i<=n-m;i++) { |
| 60 |
w=c[i+1]-d[i]; |
| 61 |
h=xa[i+m]-x; |
| 62 |
t=(xa[i]-x)*d[i]/h; |
| 63 |
dd=t-c[i+1]; |
| 64 |
if (dd == 0.0) nrerror("Error in routine RATINT"); |
| 65 |
dd=w/dd; |
| 66 |
d[i]=c[i+1]*dd; |
| 67 |
c[i]=t*dd; |
| 68 |
} |
| 69 |
*y += (*dy=(2*ns < (n-m) ? c[ns+1] : d[ns--])); |
| 70 |
} |
| 71 |
FREERETURN |
| 72 |
} |
| 73 |
|
| 74 |
#undef TINY |
| 75 |
#undef FREERETURN |