-
Notifications
You must be signed in to change notification settings - Fork 0
/
CompareSnowModel.h
66 lines (52 loc) · 2.03 KB
/
CompareSnowModel.h
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
#ifndef COMPARE_SNOW_MODEL
#define COMPARE_SNOW_MODEL
#include "BackupSnowModel.h"
#include <datastr/ConstantGeographicMap.h>
using namespace std;
namespace openworld {
class CompareSnowModel : public SnowModel {
protected:
BackupSnowModel& backup;
DividedRange backuptime;
int lastindex;
SnowModel& compare;
string outfile;
public:
CompareSnowModel(BackupSnowModel& backup, SnowModel& compare, DividedRange backuptime, string outfile)
: SnowModel(backup.getTimes()), backup(backup), backuptime(backuptime), compare(compare) {
this->lastindex = -1;
this->outfile = outfile;
}
virtual SnowModel* clone() {
CompareSnowModel* clone = new CompareSnowModel(*((BackupSnowModel*) backup.clone()), *compare.clone(), backuptime, outfile);
clone->lastindex = lastindex;
return clone;
}
// returns the snowcover
virtual GeographicMap<double>& operator[](Measure tt) {
GeographicMap<double>& result = backup[tt];
int index = backuptime.inRange(tt);
if (index >= 0 && index != lastindex) {
GeographicMap<double>& comparison = compare[tt];
cout << "SNOW COMPARE" << endl;
fstream fs;
fs.open(outfile.c_str(), fstream::out | fstream::app);
for (unsigned rr = 0; rr < comparison.getLatitudes().count(); rr++)
for (unsigned cc = 0; cc < comparison.getLongitudes().count(); cc++) {
Measure latitude(Inds::lat), longitude(Inds::lon);
comparison.calcLatitudeLongitude(rr, cc, latitude, longitude);
if (result.validLocation(latitude, longitude))
fs << rr << "\t" << cc << "\t" << result.getDouble(latitude, longitude) << "\t" << comparison.getCellConst(rr, cc) << endl;
}
fs.close();
lastindex = backuptime.inRange(tt);
}
return result;
}
virtual void inform(GeographicMap<double>& newMeltVolume, GeographicMap<double>& newSnowVolume) {
if (lastindex >= 0)
compare.inform(newMeltVolume, newSnowVolume);
}
};
}
#endif