Mar 31, 2014 at 11:14am UTC
I have a text file that contains values as follows:
2013 05 27 15 52 02.049824 231.401 0.022 49.738
2013 05 27 15 52 02.668822 229.814 0.019 49.738
2013 05 27 15 52 03.283705 228.528 2.599 49.726
2013 05 27 15 52 03.898469 230.140 2.576 49.751
Column1=date, Column2=Month, Column3=Day, Column4=Hour, Column5=Minute, Column6=Seconds, Column7=Voltage(Vrms), Column8=Current(Irms), Column9=Frequency(Hz).
I have to develop a program that will analyse these time-sampled voltage and current measurements over 24 hours and find the total energy used, mean and peak power consumption and Energy used over each hour of the 24 hour period.
How do I go about doing this?
The file data contains over 50 thousand lines in the format mentioned above.
Mar 31, 2014 at 3:04pm UTC
Is this on the right track?
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class DataTable
{
public:
int year;
int month;
int day;
int hour;
int minute;
double seconds;
double voltage;
double current;
double frequency;
};
int main()
{
DataTable Data;
ifstream DataFile("Data.txt");
if (!DataFile)
cout << "Unable to open" << endl;
int year1, month1, day1, hour1, minute1;
double seconds1, voltage1, current1, frequency1;
while(DataFile >> year1 >> month1 >> day1 >> hour1 >> minute1 >> seconds1 >> voltage1 >> current1 >> frequency1)
{
Data.year = year1;
Data.month = month1;
Data.day = day1;
Data.hour = hour1;
Data.minute = minute1;
Data.seconds = seconds1;
Data.voltage = voltage1;
Data.current = current1;
Data.frequency = frequency1;
}
return 0;
}
Mar 31, 2014 at 3:36pm UTC
kind of yea.
then you need to add that Data object to some kind of array or vector (inside the while loop), so when the while loop finishes (i.e. just above your 'return 0;') you will have a collection of Data objects that you can iterate over to do your calculations.
Mar 31, 2014 at 5:24pm UTC
How's this?
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
class DataTable{
public:
int year;
int month;
int day;
int hour;
int minute;
double seconds;
double voltage;
double current;
double frequency;
};
int main(){
ifstream DataFile("Data.txt");
if (!DataFile)
{
cout << "Unable to open" << endl;
return -1;
}
int year1, month1, day1, hour1, minute1;
double seconds1, voltage1, current1, frequency1;
vector<DataTable> records;
while(DataFile >> year1 >> month1 >> day1 >> hour1 >> minute1 >> seconds1 >> voltage1 >> current1 >> frequency1)
{
DataTable Data;
Data.year = year1;
Data.month = month1;
Data.day = day1;
Data.hour = hour1;
Data.minute = minute1;
Data.seconds = seconds1;
Data.voltage = voltage1;
Data.current = current1;
Data.frequency = frequency1;
records.push_back(Data);
}
// Do something with records
return 0;
}