1 : |
agomez |
1 |
#include "areatime.h" |
2 : |
|
|
#include "readfunc.h" |
3 : |
|
|
#include "errorhandler.h" |
4 : |
|
|
#include "gadget.h" |
5 : |
|
|
#include "global.h" |
6 : |
|
|
|
7 : |
|
|
AreaClass::AreaClass(CommentStream& infile,
|
8 : |
|
|
Keeper* const keeper, const TimeClass* const TimeInfo) {
|
9 : |
|
|
|
10 : |
|
|
int i, tmpint = 0;
|
11 : |
|
|
char text[MaxStrLength];
|
12 : |
|
|
strncpy(text, "", MaxStrLength);
|
13 : |
|
|
|
14 : |
|
|
infile >> text >> ws;
|
15 : |
|
|
if (strcasecmp(text, "areas") != 0)
|
16 : |
|
|
handle.logFileUnexpected(LOGFAIL, "areas", text);
|
17 : |
|
|
|
18 : |
|
|
while (isdigit(infile.peek()) && !infile.eof()) {
|
19 : |
|
|
infile >> tmpint >> ws;
|
20 : |
|
|
modelAreas.resize(1, tmpint);
|
21 : |
|
|
}
|
22 : |
|
|
|
23 : |
|
|
keeper->addString("area");
|
24 : |
|
|
infile >> text >> ws;
|
25 : |
|
|
if (strcasecmp(text, "size") != 0)
|
26 : |
|
|
handle.logFileUnexpected(LOGFAIL, "size", text);
|
27 : |
|
|
|
28 : |
|
|
size.resize(modelAreas.Size(), keeper);
|
29 : |
|
|
for (i = 0; i < modelAreas.Size(); i++)
|
30 : |
|
|
if (!(infile >> size[i]))
|
31 : |
|
|
handle.logFileMessage(LOGFAIL, "invalid format for area size vector");
|
32 : |
|
|
size.Inform(keeper);
|
33 : |
|
|
keeper->clearLast();
|
34 : |
|
|
|
35 : |
|
|
infile >> text >> ws;
|
36 : |
|
|
if (strcasecmp(text, "temperature") != 0)
|
37 : |
|
|
handle.logFileUnexpected(LOGFAIL, "temperature", text);
|
38 : |
|
|
|
39 : |
|
|
//Now the data which is in the following format: year step area temperature.
|
40 : |
|
|
temperature.AddRows(TimeInfo->numTotalSteps() + 1, modelAreas.Size(), 0.0);
|
41 : |
|
|
IntVector Years, Steps;
|
42 : |
|
|
int timeid, areaid, keepdata, year, step, area, count, reject;
|
43 : |
|
|
double tmp;
|
44 : |
|
|
|
45 : |
|
|
//Check the number of columns in the inputfile
|
46 : |
|
|
if (countColumns(infile) != 4)
|
47 : |
|
|
handle.logFileMessage(LOGFAIL, "wrong number of columns in inputfile - should be 4");
|
48 : |
|
|
|
49 : |
|
|
year = step = area = count = reject = 0;
|
50 : |
|
|
while (!infile.eof()) {
|
51 : |
|
|
keepdata = 1;
|
52 : |
|
|
infile >> year >> step >> area >> tmp >> ws;
|
53 : |
|
|
|
54 : |
|
|
//check if the year and step are in the simulation
|
55 : |
|
|
timeid = -1;
|
56 : |
|
|
if (TimeInfo->isWithinPeriod(year, step)) {
|
57 : |
|
|
for (i = 0; i < Years.Size(); i++)
|
58 : |
|
|
if ((Years[i] == year) && (Steps[i] == step))
|
59 : |
|
|
timeid = i;
|
60 : |
|
|
|
61 : |
|
|
if (timeid == -1) {
|
62 : |
|
|
Years.resize(1, year);
|
63 : |
|
|
Steps.resize(1, step);
|
64 : |
|
|
timeid = Years.Size(); //time=0 isnt in the simulation
|
65 : |
|
|
}
|
66 : |
|
|
|
67 : |
|
|
} else
|
68 : |
|
|
keepdata = 0; //dont keep data
|
69 : |
|
|
|
70 : |
|
|
//if area is in modelAreas find areaid, else dont keep the data
|
71 : |
|
|
areaid = -1;
|
72 : |
|
|
for (i = 0; i < modelAreas.Size(); i++)
|
73 : |
|
|
if (area == modelAreas[i])
|
74 : |
|
|
areaid = i;
|
75 : |
|
|
|
76 : |
|
|
if (areaid == -1)
|
77 : |
|
|
keepdata = 0;
|
78 : |
|
|
|
79 : |
|
|
if (keepdata == 1) {
|
80 : |
|
|
//temperature data is required, so store it
|
81 : |
|
|
temperature[timeid][areaid] = tmp;
|
82 : |
|
|
count++;
|
83 : |
|
|
} else
|
84 : |
|
|
reject++; //count number of rejected data points read from file
|
85 : |
|
|
}
|
86 : |
|
|
|
87 : |
|
|
if (count == 0)
|
88 : |
|
|
handle.logMessage(LOGWARN, "Warning in area - found no temperature data");
|
89 : |
|
|
if (count != (temperature.Nrow() - 1) * modelAreas.Size())
|
90 : |
|
|
handle.logMessage(LOGWARN, "Warning in area - temperature data doesnt span time range");
|
91 : |
|
|
if (reject != 0)
|
92 : |
|
|
handle.logMessage(LOGMESSAGE, "Discarded invalid temperature data - number of invalid entries", reject);
|
93 : |
|
|
handle.logMessage(LOGMESSAGE, "Read temperature data - number of entries", count);
|
94 : |
|
|
handle.logMessage(LOGMESSAGE, "Read area file - number of areas", modelAreas.Size());
|
95 : |
|
|
}
|
96 : |
|
|
|
97 : |
|
|
int AreaClass::getInnerArea(int area) const {
|
98 : |
|
|
int i, innerarea = -1;
|
99 : |
|
|
for (i = 0; i < modelAreas.Size(); i++)
|
100 : |
|
|
if (area == modelAreas[i])
|
101 : |
|
|
innerarea = i;
|
102 : |
|
|
|
103 : |
|
|
if (innerarea == -1)
|
104 : |
|
|
handle.logMessage(LOGWARN, "Warning in area - failed to match area", area);
|
105 : |
|
|
return innerarea;
|
106 : |
|
|
}
|