-
Notifications
You must be signed in to change notification settings - Fork 1
/
Cumulus.cs
174 lines (143 loc) · 5.6 KB
/
Cumulus.cs
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
using CumulusMX;
using System;
namespace CreateRecords
{
class Cumulus
{
public string RecordsBeganDate;
public int RolloverHour;
public bool Use10amInSummer;
public double RainDayThreshold;
public string TempFormat;
public string WindFormat;
public string WindAvgFormat;
public string RainFormat;
public string PressFormat;
public string UVFormat;
public string SunFormat;
public string ETFormat;
public string WindRunFormat;
public string TempTrendFormat;
public double NOAAheatingthreshold;
public double NOAAcoolingthreshold;
public const double DefaultHiVal = -9999;
public const double DefaultLoVal = 9999;
private readonly StationOptions StationOptions = new StationOptions();
internal StationUnits Units = new StationUnits();
private readonly int[] WindDPlaceDefaults = { 1, 0, 0, 0 }; // m/s, mph, km/h, knots
private readonly int[] TempDPlaceDefaults = { 1, 1 };
private readonly int[] PressDPlaceDefaults = { 1, 1, 2 };
private readonly int[] RainDPlaceDefaults = { 1, 2 };
public Cumulus()
{
// Get all the stuff we need from Cumulus.ini
ReadIniFile();
TempFormat = "F" + Units.TempDPlaces;
WindFormat = "F" + Units.WindDPlaces;
WindAvgFormat = "F" + Units.WindAvgDPlaces;
RainFormat = "F" + Units.RainDPlaces;
PressFormat = "F" + Units.PressDPlaces;
UVFormat = "F" + Units.UVDPlaces;
SunFormat = "F" + Units.SunshineDPlaces;
ETFormat = "F" + (Units.RainDPlaces + 1);
WindRunFormat = "F" + Units.WindRunDPlaces;
TempTrendFormat = "+0.0;-0.0;0";
}
private void ReadIniFile()
{
if (!System.IO.File.Exists("Cumulus.ini"))
{
Program.LogMessage("Failed to find Cumulus.ini file!");
Console.WriteLine("Failed to find Cumulus.ini file!");
Environment.Exit(1);
}
Program.LogMessage("Reading Cumulus.ini file");
IniFile ini = new IniFile("Cumulus.ini");
var StationType = ini.GetValue("Station", "Type", -1);
var IncrementPressureDP = ini.GetValue("Station", "DavisIncrementPressureDP", false);
RecordsBeganDate = ini.GetValue("Station", "StartDate", DateTime.Now.ToLongDateString());
if ((StationType == 0) || (StationType == 1))
{
Units.UVDPlaces = 1;
}
else
{
Units.UVDPlaces = 0;
}
RolloverHour = ini.GetValue("Station", "RolloverHour", 0);
Use10amInSummer = ini.GetValue("Station", "Use10amInSummer", true);
Units.Wind = ini.GetValue("Station", "WindUnit", 0);
Units.Press = ini.GetValue("Station", "PressureUnit", 0);
Units.Rain = ini.GetValue("Station", "RainUnit", 0);
Units.Temp = ini.GetValue("Station", "TempUnit", 0);
var RoundWindSpeed = ini.GetValue("Station", "RoundWindSpeed", false);
RainDayThreshold = ini.GetValue("Station", "RainDayThreshold", -1.0);
// Unit decimals
Units.RainDPlaces = RainDPlaceDefaults[Units.Rain];
Units.TempDPlaces = TempDPlaceDefaults[Units.Temp];
Units.PressDPlaces = PressDPlaceDefaults[Units.Press];
Units.WindDPlaces = RoundWindSpeed ? 0 : WindDPlaceDefaults[Units.Wind];
Units.WindAvgDPlaces = Units.WindDPlaces;
// Unit decimal overrides
Units.WindDPlaces = ini.GetValue("Station", "WindSpeedDecimals", Units.WindDPlaces);
Units.WindAvgDPlaces = ini.GetValue("Station", "WindSpeedAvgDecimals", Units.WindAvgDPlaces);
Units.WindRunDPlaces = ini.GetValue("Station", "WindRunDecimals", Units.WindRunDPlaces);
Units.SunshineDPlaces = ini.GetValue("Station", "SunshineHrsDecimals", 1);
if ((StationType == 0 || StationType == 1) && IncrementPressureDP)
{
// Use one more DP for Davis stations
++Units.PressDPlaces;
}
Units.PressDPlaces = ini.GetValue("Station", "PressDecimals", Units.PressDPlaces);
Units.RainDPlaces = ini.GetValue("Station", "RainDecimals", Units.RainDPlaces);
Units.TempDPlaces = ini.GetValue("Station", "TempDecimals", Units.TempDPlaces);
Units.UVDPlaces = ini.GetValue("Station", "UVDecimals", Units.UVDPlaces);
StationOptions.UseZeroBearing = ini.GetValue("Station", "UseZeroBearing", false);
NOAAheatingthreshold = ini.GetValue("NOAA", "HeatingThreshold", -1000.0);
if (NOAAheatingthreshold < -99 || NOAAheatingthreshold > 150)
{
NOAAheatingthreshold = Units.Temp == 0 ? 18.3 : 65;
}
NOAAcoolingthreshold = ini.GetValue("NOAA", "CoolingThreshold", -1000.0);
if (NOAAcoolingthreshold < -99 || NOAAcoolingthreshold > 150)
{
NOAAcoolingthreshold = Units.Temp == 0 ? 18.3 : 65;
}
}
}
internal class StationUnits
{
public int Wind { get; set; }
public int Press { get; set; }
public int Rain { get; set; }
public int Temp { get; set; }
public int WindDPlaces { get; set; }
public int PressDPlaces { get; set; }
public int RainDPlaces { get; set; }
public int TempDPlaces { get; set; }
public int WindAvgDPlaces { get; set; }
public int WindRunDPlaces { get; set; }
public int SunshineDPlaces { get; set; }
public int UVDPlaces { get; set; }
}
public class StationOptions
{
public bool UseZeroBearing { get; set; }
public bool UseWind10MinAve { get; set; }
public bool UseSpeedForAvgCalc { get; set; }
public bool Humidity98Fix { get; set; }
public bool CalculatedDP { get; set; }
public bool CalculatedWC { get; set; }
public bool SyncTime { get; set; }
public int ClockSettingHour { get; set; }
public bool UseCumulusPresstrendstr { get; set; }
public bool LogExtraSensors { get; set; }
public bool WS2300IgnoreStationClock { get; set; }
public bool RoundWindSpeed { get; set; }
public int PrimaryAqSensor { get; set; }
public bool NoSensorCheck { get; set; }
public int AvgBearingMinutes { get; set; }
public int AvgSpeedMinutes { get; set; }
public int PeakGustMinutes { get; set; }
}
}