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
|
#pragma once
#include <windows.h>
#include "ReadStrikesCSV.h"
#include "WindSite.h"
#include <string>
#include <iostream>
#include <sstream>
#include "AppendText.h"
#include <tchar.h>
using std::ios;
using std::string;
using std::endl;
#include <fstream>
using std::ifstream;
using std::ofstream;
#include <sstream>
#include <stdlib.h>
void ReadStrikesCSV::ReadFile(string file, WindSite sites[], const HWND &hwnd)
{
string line;
LatLong point;
ifstream inFile(file, ios::in);
bool fileexists = true;
string TimeofStrike;
// get edit control from dialog
if (!inFile)
{
TCHAR temp = StringtoTCHAR("Strikes file does not exist");
AppendText(hwnd, temp);
fileexists = false;
}
std::string tempstring[17];
inFile.ignore('\n'); //ignore the first line as it is headers
while(std::getline(inFile,line))
{
std::stringstream lineStream(line);
std::string cell;
int j = 0;
while(std::getline(lineStream,cell,','))
{
tempstring[j] = cell;
j++;
}
TimeofStrike = tempstring[0];
point.SetLat((atof(tempstring[1].c_str())));
point.SetLong((atof(tempstring[2].c_str())));
CheckPointSites(sites, point, hwnd, TimeofStrike);
}
if (!inFile && fileexists) //if file exists but there is no more data to be read.
{
TCHAR temp = StringtoTCHAR("\r\nFinished reading strikes file.\r\n");
AppendText(hwnd, temp);
}
}
void ReadStrikesCSV::CheckPointSites(WindSite sites[], LatLong point, const HWND &OUTPUT, string TimeofStrike) // check point against N,E,S,W before checking against turbines. Pass array of WindSites to check
{
//check point is inside box
for (int j=0; j < 27; j++) //We have 27 sites, need to make that a variable, probably fixed when sites turned into vector.
{
if ((point.GetLat() >= ((sites[j].GetNorth()) - 0.01)) && (point.GetLat() <= ((sites[j].GetSouth()) + 0.01)) && (point.GetLong() >= (sites[j].GetWest() - 0.01) && (point.GetLong() <= (sites[j].GetEast() + 0.01))))
{
CheckPointWTGs(sites[j].GetFirstTurbine(), point, sites[j].getName(), OUTPUT, TimeofStrike);
}
}
}
void ReadStrikesCSV::CheckPointWTGs(Turbine *WTG, LatLong StrikePoint, string site, const HWND &OUTPUT , string TimeofStrike)//// check point if it is inside box for site, pass it the pointer for the first turbine of the site from WindSite to check.
{
// read a point from strikes file.
LatLong WTGpoint;
bool run = true; //variable for the while loop, set to true so that it runs at least once.
ofstream outLog("Log.txt", ios::app);
while (run == true)
{
WTGpoint = WTG->GetLatLong();
if (WTGpoint.InRange(StrikePoint, 0.01))
{
string output;
output.append(WTG->GetName()); //placed WTG name
output.append(" at ");
output.append(site); //placed site name
output.append(" might have had a lightning strike at ");
output.append(TimeofStrike); //placed time of lightning strike
TCHAR temp = StringtoTCHAR(output);
AppendText(OUTPUT, temp);
outLog << site << " " << WTG->GetName() << " might have a lightning strike" << endl;
}
if (WTG->GetnextPtr() != NULL)//if more WTGs to check
WTG = WTG->GetnextPtr(); //get next WTG
else
run = false;
}
}
|