WSL/SLF GitLab Repository

MeteoProcessor.cc 4.12 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/***********************************************************************************/
/*  Copyright 2009 WSL Institute for Snow and Avalanche Research    SLF-DAVOS      */
/***********************************************************************************/
/* This file is part of MeteoIO.
    MeteoIO is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    MeteoIO is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with MeteoIO.  If not, see <http://www.gnu.org/licenses/>.
*/
#include <meteoio/MeteoProcessor.h>

using namespace std;

namespace mio {

24
MeteoProcessor::MeteoProcessor(const Config& cfg) : mi1d(cfg), processing_stack()
25
26
27
{
	//Parse [Filters] section, create processing stack for each configured parameter
	set<string> set_of_used_parameters;
28
	getParameters(cfg, set_of_used_parameters);
29

30
	for (set<string>::const_iterator it = set_of_used_parameters.begin(); it != set_of_used_parameters.end(); ++it){
31
32
33
34
35
36
37
38
		ProcessingStack* tmp = new ProcessingStack(cfg, *it);
		processing_stack[*it] = tmp;
	}
}

MeteoProcessor::~MeteoProcessor()
{
	//clean up heap memory
39
	for (map<string, ProcessingStack*>::const_iterator it=processing_stack.begin(); it != processing_stack.end(); ++it)
40
41
42
		delete it->second;
}

43
void MeteoProcessor::getParameters(const Config& cfg, std::set<std::string>& set_parameters)
44
45
{
	std::vector<std::string> vec_keys;
46
	cfg.findKeys(vec_keys, std::string(), "Filters");
47

Mathias Bavay's avatar
Mathias Bavay committed
48
	for (size_t ii=0; ii<vec_keys.size(); ++ii){
49
		const size_t found = vec_keys[ii].find_first_of(":");
50
		if (found != std::string::npos){
51
			const string tmp = vec_keys[ii].substr(0,found);
52
53
54
55
56
			set_parameters.insert(tmp);
		}
	}
}

57
void MeteoProcessor::getWindowSize(ProcessingProperties& o_properties) const
58
59
60
{
	ProcessingProperties tmp;

61
	for (map<string, ProcessingStack*>::const_iterator it=processing_stack.begin(); it != processing_stack.end(); ++it){
62
63
64
65
66
67
68
69
70
		(*(it->second)).getWindowSize(tmp);
		compareProperties(tmp, o_properties);
	}

	//Also take the Meteo1DInterpolator into account:
	mi1d.getWindowSize(tmp);
	compareProperties(tmp, o_properties);
}

71
void MeteoProcessor::compareProperties(const ProcessingProperties& newprop, ProcessingProperties& current)
72
73
74
{
	current.points_before = MAX(current.points_before, newprop.points_before);
	current.points_after = MAX(current.points_after, newprop.points_after);
75

76
77
	if (newprop.time_before > current.time_before)
		current.time_before = newprop.time_before;
78

79
80
81
82
	if (newprop.time_after > current.time_after)
		current.time_after = newprop.time_after;
}

83
void MeteoProcessor::process(const std::vector< std::vector<MeteoData> >& ivec,
84
85
86
                             std::vector< std::vector<MeteoData> >& ovec, const bool& second_pass)
{
	//call the different processing stacks
87
	std::vector< std::vector<MeteoData> > vec_tmp;
88

89
	for (map<string, ProcessingStack*>::const_iterator it=processing_stack.begin(); it != processing_stack.end(); ++it){
90
91
92
93
94
		if (it==processing_stack.begin()){
			(*(it->second)).process(ivec, ovec, second_pass);
		} else {
			(*(it->second)).process(vec_tmp, ovec, second_pass);
		}
95
96
97
		vec_tmp = ovec;
	}

98
	if (processing_stack.empty())
99
100
		ovec = ivec;
}
101

102
bool MeteoProcessor::resample(const Date& date, const std::vector<MeteoData>& ivec, MeteoData& md)
103
{
104
	return mi1d.resampleData(date, ivec, md);
105
106
}

107
const std::string MeteoProcessor::toString() const {
108
	std::ostringstream os;
109
	os << "<MeteoProcessor>\n";
110
	os << mi1d.toString();
111
	os << "Processing stacks:\n";
112
113
114
115
	map<string, ProcessingStack*>::const_iterator it;
	for (it=processing_stack.begin(); it != processing_stack.end(); ++it){
		//os << setw(10) << it->first.toString() << "::"; //the processing stack already contains it
		os << (*it->second).toString();
116
	}
117
	os << "</MeteoProcessor>\n";
118
	return os.str();
119
120
}

121
} //namespace