ssa
1package pchip2
3import (4"math"5)
6
7func Pchip2(lgl, x []float64) []float64 {8
9del := make([]float64, len(lgl))10
11slopes := make([]float64, len(lgl))12var d float6413for k := 0; k < len(del)-1; k++ {14del[k] = x[k+1] - x[k]15}16
17for k := 0; k < len(slopes)-1; k++ {18slopes[k+1] = 0.019if del[k] < 0.0 {20d = del[k+1]21if d <= del[k] {22slopes[k+1] = del[k] / (0.5*(del[k]/d) + 0.5)23} else {24if d < 0.0 {25slopes[k+1] = d / (0.5 + 0.5*(d/del[k]))26}27}28} else {29if del[k] > 0.0 {30d = del[k+1]31if d >= del[k] {32slopes[k+1] = del[k] / (0.5*(del[k]/del[k+1]) + 0.5)33} else {34if d > 0.0 {35slopes[k+1] = del[k+1] / (0.5 + 0.5*(del[k+1]/del[k]))36}37}38}39}40}41
42slopes[0] = exteriorSlope2(del[0], del[1], 1.0, 1.0)43slopes[len(del)-1] = exteriorSlope2(del[len(del)-1], del[len(del)-2], 1.0, 1.0)44return slopes45}
46
47/* Function Definitions */
48func exteriorSlope2(d1, d2, h1, h2 float64) float64 {49var s float6450var signd1 float6451var signs float6452s = ((2.0*h1+h2)*d1 - h1*d2) / (h1 + h2)53signd1 = d154if d1 < 0.0 {55signd1 = -1.056} else if d1 > 0.0 {57signd1 = 1.058} else {59if d1 == 0.0 {60signd1 = 0.061}62}63
64signs = s65if s < 0.0 {66signs = -1.067} else if s > 0.0 {68signs = 1.069} else {70if s == 0.0 {71signs = 0.072}73}74
75if signs != signd1 {76s = 0.077} else {78signs = d279if d2 < 0.0 {80signs = -1.081} else if d2 > 0.0 {82signs = 1.083} else {84if d2 == 0.0 {85signs = 0.086}87}88
89if (signd1 != signs) && (math.Abs(s) > math.Abs(3.0*d1)) {90s = 3.0 * d191}92}93
94return s95}
96