summaryrefslogtreecommitdiffstats
path: root/interp.cc
diff options
context:
space:
mode:
Diffstat (limited to 'interp.cc')
-rw-r--r--interp.cc26
1 files changed, 10 insertions, 16 deletions
diff --git a/interp.cc b/interp.cc
index 12bac0e..95e2cfa 100644
--- a/interp.cc
+++ b/interp.cc
@@ -13,12 +13,8 @@ typedef realvec_t::real_t real_t;
typedef realvec_t::intvec_t intvec_t;
typedef intvec_t::int_t int_t;
-
-
-realvec_t interp(const real_t* array, ptrdiff_t size,
- real_t xmin, real_t xmax,
- realvec_t x)
-{
+realvec_t interp(const real_t *array, ptrdiff_t size, real_t xmin, real_t xmax,
+ realvec_t x) {
assert(size >= 2);
// spacing
real_t dx = (xmax - xmin) / (size - 1);
@@ -29,11 +25,11 @@ realvec_t interp(const real_t* array, ptrdiff_t size,
intvec_t n = convert_int(cell);
// gather values from array
realvec_t x0, x1;
- for (ptrdiff_t i=0; i<realvec_t::size; ++i) {
+ for (ptrdiff_t i = 0; i < realvec_t::size; ++i) {
// ensure location is not out of bounds
- ptrdiff_t j = max(ptrdiff_t(0), min(size-2, ptrdiff_t(n[i])));
+ ptrdiff_t j = max(ptrdiff_t(0), min(size - 2, ptrdiff_t(n[i])));
x0.set_elt(i, array[j]);
- x1.set_elt(i, array[j+1]);
+ x1.set_elt(i, array[j + 1]);
}
// determine interpolation weights
realvec_t offset = scaled - cell;
@@ -44,20 +40,18 @@ realvec_t interp(const real_t* array, ptrdiff_t size,
return y;
}
-
-
-int main(int argc, char** argv)
-{
+int main(int argc, char **argv) {
ptrdiff_t size = 1001;
vector<real_t> array(size);
- for (ptrdiff_t i=0; i<size; ++i) array[i] = real_t(i) / 1000.0;
-
+ for (ptrdiff_t i = 0; i < size; ++i)
+ array[i] = real_t(i) / 1000.0;
+
real_t xmin = 0.0;
real_t xmax = 0.5;
realvec_t x = 0.333;
cout << "x=" << x << "\n";
realvec_t y = interp(&array[0], size, xmin, xmax, x);
cout << "y=" << y << "\n";
-
+
return 0;
}
OpenPOWER on IntegriCloud