PLUTO
|
Miscellaneous functions for handling 2D tables. More...
#include "pluto.h"
Go to the source code of this file.
Macros | |
#define | LOG_INTERPOLATION NO |
Functions | |
void | PlotCubic (double a, double b, double c, double d) |
void | InitializeTable2D (Table2D *tab, double xmin, double xmax, int nx, double ymin, double ymax, int ny) |
void | FinalizeTable2D (Table2D *tab) |
int | LocateIndex (double *yarr, int beg, int end, double y) |
int | InverseLookupTable2D (Table2D *tab, double y, double f, double *x) |
int | Table2DInterpolate (Table2D *tab, double x, double y, double *f) |
void | WriteBinaryTable2D (char *fname, Table2D *tab) |
Miscellaneous functions for handling 2D tables.
Definition in file math_table2D.c.
#define LOG_INTERPOLATION NO |
Definition at line 194 of file math_table2D.c.
void FinalizeTable2D | ( | Table2D * | tab | ) |
void InitializeTable2D | ( | Table2D * | tab, |
double | xmin, | ||
double | xmax, | ||
int | nx, | ||
double | ymin, | ||
double | ymax, | ||
int | ny | ||
) |
Allocate memory for the arrays contained in the *tab
structure and generate a uniformly spaced grid in log10(x), log10(y) within the range provided by xmin
, xmax
, ymin
, ymax
. On output, the function initializes the following structure members:
nx, ny
lnxmin, lnxmax, lnymin, lnymax
lnx[], lny[]
dlnx, dlny
dlnx_1, dlny_1
x[], y[]
dx[], dy[]
[in,out] | tab | pointer to a Table2D structure |
[in] | xmin | lower column limit. |
[in] | xmax | upper column limit. |
[in] | nx | number of equally-spaced column bins (in log space) |
[in] | ymin | lower row limit. |
[in] | ymax | upper row limit. |
[in] | ny | number of equally-spaced row bins (in log space) |
Definition at line 15 of file math_table2D.c.
int InverseLookupTable2D | ( | Table2D * | tab, |
double | y, | ||
double | f, | ||
double * | x | ||
) |
Perform inverse lookup table interpolation: given a 2D table f(i,j)=f(x(i), y(j))
and the value of y
, find the value of x
. The algorithm proceeds by a combination of 1D lookup table algorithms:
j
such that y[j]<y<y[j+1]
;j
and j+1
where the value of y
is given.ib
and ie
at j
and j+1
using 1D lookup table.i
and invert the bilinear interpolant by solving
and
y
.[in] | tab | a pointer to a Table2D structure |
[in] | y | the ordinata |
[in] | f | the value of the function |
[out] | *x | the value of the abscissa. |
y
is below range;y
is above range. Definition at line 196 of file math_table2D.c.
int LocateIndex | ( | double * | yarr, |
int | beg, | ||
int | end, | ||
double | y | ||
) |
Given an array yarr
[beg..end] and a given value y
, returns the array index i
such that yarr[i] < y < yarr[i+1]
(for increasing arrays) or yarr[i+1] < y < yarr[i]
(for decreasing arrays). yarr
must be monotonically increasing or monotonically decreasing.
[in] | yarr | the 1D array |
[in] | beg | initial index of the array |
[in] | end | final index of the array |
[in] | y | the value to be searched for |
Reference
Definition at line 144 of file math_table2D.c.
void PlotCubic | ( | double | a, |
double | b, | ||
double | c, | ||
double | d | ||
) |
int Table2DInterpolate | ( | Table2D * | tab, |
double | x, | ||
double | y, | ||
double * | f | ||
) |
Use bilinear interpolation to find the function f(x,y) from the 2D table *tab
. Since the grid is equally spaced in log(x)
and log(y)
, the (i,j) indices such that x[i] <= x < x[i+1]
and y[j] <= y < y[j+1]
are found by a simple division. Then bilinear interpolation can be done in either log or linear coordinates. The latter is expected to be slightly faster since it avoids one pow()
operation.
[in] | *tab | a pointer to a Table2D structure |
[in] | x | the abscissa where interpolation is needed. |
[in] | y | the ordinata where interpolation is needed. |
[out] | *f | the interpolated value |
x
is below column range;x
is above column range;y
is below row range;y
is above row range. Definition at line 430 of file math_table2D.c.
void WriteBinaryTable2D | ( | char * | fname, |
Table2D * | tab | ||
) |
The binary table is a compact format used to write a 2D array together with simple structured coordinates. The file consists of the following information:
nx ny <x[0]..x[nx-1]> <y[0]..y[ny-1]> <q[0][0]..q[0][nx-1] q[1][0]..q[1][nx-1] ....... q[ny-1][0]..q[ny-1][nx-1]>
All fields are written in binary format using double precision arithmetic.
Definition at line 528 of file math_table2D.c.