/// <summary>
/// Write the cell information to a data file in CSV format.
/// </summary>
/// <returns>0 if successful; -ve for error code</returns>
protected int WriteCellInfo()
{
OpenTemp.WriteLine(string.Format("Writing the cell info file '{0}'...", _outputCellFile)); // Open the file
StreamWriter sw;
try
{
sw = new StreamWriter(_outputCellFile, false); // Overwrite (do not append)
OpenTemp.WriteLine(" File opened for writing");
}
catch (Exception ex)
{
OpenTemp.WriteLine(string.Format(" Exception thrown when opening file: {0}", ex.ToString()));
return -1;
}
if (sw == null)
{
OpenTemp.WriteLine(" Failed to open file (check that it exists and the path is correct)");
return -2;
}
// Write header
sw.WriteLine("LATITUDE, LONGITUDE, AREA");
// Write one line for each cell
foreach (Cell cell in _cells)
{
sw.WriteLine(string.Format("{0:F2}, {1:F2}, {2:F3}", cell.Latitude, cell.Longitude, cell.Area));
}
// Done
sw.Close();
// Done
OpenTemp.WriteLine(string.Format(" Writing finished: {0} cells written", _cells.Count));
return 0;
}