WSL/SLF GitLab Repository

2D_interpolations.cc 3.27 KB
Newer Older
1
2
3
4
5
6
#include <iostream>
#include <meteoio/MeteoIO.h>

using namespace mio; //The MeteoIO namespace is called mio
using namespace std;

7
const double epsilon = 1e-3; //1e-4 is still too tight because of truncated results when writing data out for the ref.
8
const bool gen_ref = false; //wether to generate ref files or to test
9

10
11
12
13
14
15
16
17
18
19
20
21
22
23
int main(int /*argc*/, char** argv) {
	Date d1;

	//initializing the io handlers according to the config file
	Config cfg("io.ini");
	IOManager io(cfg);

	//reading the dem (necessary for several spatial interpolations algoritms)
	DEMObject dem;
	io.readDEM(dem);

	//we assume that the time given on the command line is in TZ=+1
	IOUtils::convertString(d1,argv[1], 1.);

24
25
26
	std::string date_str = d1.toString(Date::ISO);
	std::replace( date_str.begin(), date_str.end(), ':', '.');

27
	//performing spatial interpolations
28
	Grid2DObject param, ref;
29

30
	io.interpolate(d1, dem, MeteoData::TA, param);
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
	if(gen_ref) io.write2DGrid(param, MeteoGrids::TA, d1);
	else {
		io.read2DGrid(ref, date_str+"_TA_ref.asc");
		if(ref.grid2D.checkEpsilonEquality(param.grid2D, epsilon)==false) {
			cout << "TA grids don't match!\n"; return EXIT_FAILURE;
		}
	}

	io.interpolate(d1, dem, MeteoData::TSS, param);
	if(gen_ref) io.write2DGrid(param, MeteoGrids::TSS, d1);
	else {
		io.read2DGrid(ref, date_str+"_TSS_ref.asc");
		if(ref.grid2D.checkEpsilonEquality(param.grid2D, epsilon)==false) {
			cout << "TSS grids don't match!\n"; return EXIT_FAILURE;
		}
	}

	io.interpolate(d1, dem, MeteoData::TSG, param);
	if(gen_ref) io.write2DGrid(param, MeteoGrids::TSG, d1);
	else {
		io.read2DGrid(ref, date_str+"_TSG_ref.asc");
		if(ref.grid2D.checkEpsilonEquality(param.grid2D, epsilon)==false) {
			cout << "TSG grids don't match!\n"; return EXIT_FAILURE;
		}
55
56
	}

57
	io.interpolate(d1, dem, MeteoData::HNW, param);
58
59
60
61
62
63
	if(gen_ref) io.write2DGrid(param, MeteoGrids::HNW, d1);
	else {
		io.read2DGrid(ref, date_str+"_HNW_ref.asc");
		if(ref.grid2D.checkEpsilonEquality(param.grid2D, epsilon)==false) {
			cout << "HNW grids don't match!\n"; return EXIT_FAILURE;
		}
64
65
	}

66
	io.interpolate(d1, dem, MeteoData::RH, param);
67
68
69
70
71
72
	if(gen_ref) io.write2DGrid(param, MeteoGrids::RH, d1);
	else {
		io.read2DGrid(ref, date_str+"_RH_ref.asc");
		if(ref.grid2D.checkEpsilonEquality(param.grid2D, epsilon)==false) {
			cout << "RH grids don't match!\n"; return EXIT_FAILURE;
		}
73
	}
74
75
76
77
78
79
80
81
82
83

	io.interpolate(d1, dem, MeteoData::VW, param);
	if(gen_ref) io.write2DGrid(param, MeteoGrids::VW, d1);
	else {
		io.read2DGrid(ref, date_str+"_VW_ref.asc");
		if(ref.grid2D.checkEpsilonEquality(param.grid2D, epsilon)==false) {
			cout << "VW grids don't match!\n"; return EXIT_FAILURE;
		}
	}

84
	io.interpolate(d1, dem, MeteoData::RSWR, param);
85
86
87
88
89
90
	if(gen_ref) io.write2DGrid(param, MeteoGrids::RSWR, d1);
	else {
		io.read2DGrid(ref, date_str+"_RSWR_ref.asc");
		if(ref.grid2D.checkEpsilonEquality(param.grid2D, epsilon)==false) {
			cout << "RSWR grids don't match!\n"; return EXIT_FAILURE;
		}
91
92
	}

93
94
95
96
97
98
99
100
101
102
103
	io.interpolate(d1, dem, MeteoData::P, param);
	if(gen_ref) io.write2DGrid(param, MeteoGrids::P, d1);
	else {
		io.read2DGrid(ref, date_str+"_P_ref.asc");
		if(ref.grid2D.checkEpsilonEquality(param.grid2D, epsilon)==false) {
			cout << "P grids don't match!\n"; return EXIT_FAILURE;
		}
	}


	if(!gen_ref) io.write2DGrid(param, MeteoGrids::P, d1); //trying to write one grid out
104
105
106

	return 0;
}