/// <summary>
/// Read the sttaions file and parse into the list of stations.
/// </summary>
/// <remarks>The stations file should be a CSV format with one line per station.
/// Each line should consist of the station ID (including the country code), the latitude, and the longitude.</remarks>
/// <returns>Number of stations if successful; -ve for error code</returns>
protected int ParseStations()
{
OpenTemp.WriteLine(string.Format("Reading the stations file '{0}'...", _stationsFile)); // Open the file
StreamReader sr;
try
{
sr = new StreamReader(_stationsFile, true);
OpenTemp.WriteLine(" File opened for reading");
}
catch (Exception ex)
{
OpenTemp.WriteLine(string.Format(" Exception thrown when opening file: {0}", ex.ToString()));
return -1;
}
if (sr == null)
{
OpenTemp.WriteLine(string.Format(" Failed to open file (check that it exists and the path is correct)"));
return -2;
}
// Parse one line at a time
int nLines = 1;
while (!sr.EndOfStream)
{
nLines++;
string line = sr.ReadLine();
if (line.Length == 0) continue;
string[] entries = line.Split(',');
if (entries.Length != 3)
{
OpenTemp.WriteLine(string.Format(" Line {0}: Wrong number of entries ({1}, expected {2})", nLines, entries.Length, 3));
sr.Dispose();
return -3;
}
string countryStation = entries[0];
if (!_stations.ContainsKey(countryStation))
{
float latitude = float.Parse(entries[1]); // TODO: Add error handling
float longitude = float.Parse(entries[2]); // TODO: Add error handling
_stations.Add(countryStation, new Station(countryStation, longitude, latitude));
}
Station station = _stations[countryStation];
// Increment and continue
if ((nLines % 100) == 0)
{
OpenTemp.WriteLine(string.Format(" {0} stations parsed", nLines));
}
}
// Cleanup
sr.Dispose();
// Done
OpenTemp.WriteLine(string.Format(" Parsing finished: {0} stations parsed", nLines));
return nLines;
}
John V | 20-Sep-07 at 11:47 am | Permalink
Should rename nLines to nStations and increment only if a station was successfully added.
Clayton B. | 04-Nov-07 at 2:05 pm | Permalink
I think the “## statations parsed” returns 1 too many.
John V | 05-Nov-07 at 10:41 am | Permalink
Thanks Clayton B, you’re right.
It’s fixed for the next release (which might be a little while — work got really busy).
Clayton B. | 18-Nov-07 at 3:44 pm | Permalink
Hey JohnV,
With Anthony and crew nearly finishing up California - It’d be interesting to run Opentemp on only California.
In order to to do this, one would need to
a) change the boundary coordinates
b) lower the averaging distance (100km may be ok?)
c) reduce the cell size
Is there anything I’m missing?
John V | 21-Nov-07 at 9:42 am | Permalink
That sounds about right.
You could actually get very close just by reducing the averaging distance using “/r=100″ on the command-line and including only California stations. Cells that are not affected by any stations are excluded from the average temperature and the cells are pretty small (~50km on a side).
TCO | 29-Nov-07 at 4:55 pm | Permalink
practical statistics books:
Check these out from the library (public libraries will do ILL, just ask them):
* Box, Hunter, Hunter: Statistics for Experimenters (first edition is better written and more sharing of intuitions, second edition has more computer stuff)
* Barker: Quality by Experimental Design
Recommend also getting a time series book (not sure which one). Some people like Ross and Steve are heavy on time series but lacking on basic issues like confounding variables, interaction effects, hypothesis testing, type I/II errors, multiple regression, etc. (The same can also be true in reverse of course.) I think you are better off having a good DOE foundation to think about problems before getting wrapped up in autocorrelation and such. (and realize that DOE examines run order, so it is not ignorant of time series implications.)
John V | 30-Nov-07 at 8:09 am | Permalink
Thanks TCO.