-
Notifications
You must be signed in to change notification settings - Fork 0
/
eaInput.go
154 lines (131 loc) · 3.01 KB
/
eaInput.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package RefET
import (
"errors"
"strings"
)
// EA has several methods in ASCE Standarized, we support many but not all
// Methods supported:
// 1 - Ea directly measured by station
// 2 - measured or computed dew point
// 5 - max, min relative humidity (add RHmax, RHmin this struct, add temp in struct as well)
// 6 - daily maximum relative humidty (put in Value, add Tmin)
// 7 - daily minimum relative humidty (put in Value, add Tmax)
type EaInput struct {
Input
Method int
RHmax interface{}
RHmin interface{}
Tmax Input
Tmin Input
}
// ea is a method to return the ea that can be used in the various parts of the app
func (e EaInput) Ea() (ea float64, err error) {
switch e.Method {
case 1:
ea, err = e.convertEA()
if err != nil {
return 0.0, err
}
case 2:
ea, err = e.convertFromTdew()
if err != nil {
return 0.0, err
}
case 5:
ea, err = e.convertMinMaxRH()
if err != nil {
return 0.0, err
}
case 6:
ea, err = e.convertRHmax()
if err != nil {
return 0.0, err
}
case 7:
ea, err = e.convertRHmin()
if err != nil {
return 0.0, err
}
}
return ea, nil
}
// convertET is an input methodd to convert vapor pressure from pascals to kilopascals
func (e EaInput) convertEA() (v float64, err error) {
iU := strings.ToLower(e.Units)
if iU[0] == 'p' {
v, err = PaToKpa(e.Value)
if err != nil {
return 0.0, err
}
return v, nil
}
v, err = MakeFloat(e.Value)
if err != nil {
return 0.0, err
}
return v, nil
}
func (e EaInput) convertFromTdew() (ea float64, err error) {
v, err := e.Input.convertTemp()
if err != nil {
return 0.0, err
}
ea = eo(v) // Eq. 8
return ea, nil
}
func (e EaInput) convertMinMaxRH() (ea float64, err error) {
TmaxV, err := e.Tmax.convertTemp()
if err != nil {
return 0.0, errors.New("RH must have valid Tmax")
}
TminV, err := e.Tmin.convertTemp()
if err != nil {
return 0.0, errors.New("RH must have valid Tmin")
}
rhMax, err := MakeFloat(e.RHmax)
if err != nil {
return 0.0, errors.New("RHmax must have valid value")
}
rhMin, err := MakeFloat(e.RHmin)
if err != nil {
return 0.0, errors.New("RHmin must have valid value")
}
if rhMax > 1 {
rhMax = rhMax / 100
}
if rhMin > 1 {
rhMin = rhMin / 100
}
ea = ((eo(TminV) * rhMax) + (eo(TmaxV) * rhMin)) / 2 // Eq. 11
return ea, nil
}
func (e EaInput) convertRHmax() (ea float64, err error) {
TminV, err := e.Tmin.convertTemp()
if err != nil {
return 0.0, errors.New("RHmax must have valid Tmin")
}
rhMax, err := MakeFloat(e.RHmax)
if err != nil {
return 0.0, errors.New("RHmax must have valid value")
}
if rhMax > 1 {
rhMax = rhMax / 100
}
ea = eo(TminV) * rhMax // Eq. 12
return ea, nil
}
func (e EaInput) convertRHmin() (ea float64, err error) {
TmaxV, err := e.Tmax.convertTemp()
if err != nil {
return 0.0, errors.New("RHmin must have valid Tmax")
}
rhMin, err := MakeFloat(e.RHmin)
if err != nil {
return 0.0, errors.New("RHmin must have valid value")
}
if rhMin > 1 {
rhMin = rhMin / 100
}
ea = eo(TmaxV) * rhMin // Eq. 13
return ea, nil
}