th7/thermocouple/j_type.go
2022-11-12 14:20:29 +00:00

96 lines
1.6 KiB
Go

package thermocouple
import (
"th7/data/thermocouple"
)
const (
J_MAX_C = 1200.0
J_MIN_C = -210.0
J_MAX_UV = 69553.0
J_MIN_UV = -8095.0
)
func j_c_to_uv(c float64) (float64, error) {
if c < J_MIN_C || c > J_MAX_C {
return 0, thermocouple.ErrC
}
var c0, c1, c2, c3, c4, c5, c6, c7, c8, E float64
if c < 760.0 {
c0 = 0.0
c1 = 5.0381187815e1
c2 = 3.0475836930e-2
c3 = -8.5681065720e-5
c4 = 1.3228195295e-7
c5 = -1.7052958337e-10
c6 = 2.0948090697e-13
c7 = -1.2538395336e-16
c8 = 1.5631725697e-20
} else { // 760.0 - 1200.0
c0 = 2.9645625681e5
c1 = -1.4976127786e3
c2 = 3.1787103924
c3 = -3.1847686701e-3
c4 = 1.5720819004e-6
c5 = -3.0691369056e-10
c6 = 0.0
c7 = 0.0
c8 = 0.0
}
E = c0 + c*(c1+c*(c2+c*(c3+c*(c4+c*(c5+c*(c6+c*(c7+c*(c8))))))))
return E, nil
}
func j_uv_to_c(uv float64) (float64, error) {
if uv < J_MIN_UV || uv > J_MAX_UV {
return 0, thermocouple.ErrUV
}
var c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, T float64
if uv < 0.0 {
c0 = 0.0
c1 = 3.8436847e-2
c2 = 1.1010485e-6
c3 = 5.2229312e-9
c4 = 7.2060525e-12
c5 = 5.8488586e-15
c6 = 2.7754916e-18
c7 = 7.7075166e-22
c8 = 1.1582665e-25
c9 = 7.3138868e-30
} else if uv < 20613.0 {
c0 = 0.0
c1 = 3.86896e-2
c2 = -1.08267e-6
c3 = 4.70205e-11
c4 = -2.12169e-18
c5 = -1.17272e-19
c6 = 5.39280e-24
c7 = -7.98156e-29
c8 = 0.0
c9 = 0.0
} else {
c0 = 1.972485e1
c1 = 3.300943e-2
c2 = -3.915159e-7
c3 = 9.855391e-12
c4 = -1.274371e-16
c5 = 7.767022e-22
c6 = 0.0
c7 = 0.0
c8 = 0.0
c9 = 0.0
}
T = c0 + uv*(c1+uv*(c2+uv*(c3+uv*(c4+uv*(c5+uv*(c6+uv*(c7+uv*(c8+uv*(c9)))))))))
return T, nil
}