WSL/SLF GitLab Repository

data_converter.cc 2.08 KB
Newer Older
1
#include <iostream>
2
#include <meteoio/MeteoIO.h>
3
4
5

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

6
7
8
9
//This example takes two ISO-formatted dates on the command line
//for example ./data_converter 2008-12-01T00:00:00 2008-12-31T23:00
//It will retrieve the data for this time interval and write it out as specified
//in the io.ini configuration
10
11

void real_main(int argc, char** argv) {
12
	if(argc!=3) {
13
		std::cout << "Invalid number of arguments! Please provide a date range!\n";
14
15
		exit(0);
	}
16

17
	Config cfg("io.ini");
18
	Date d1, d2;
19
	const double TZ = cfg.get("TIME_ZONE", "Input");
20
	const double Tstep = 1./24.; //sampling rate = 1/24 day = 1 hour
21
22
	IOUtils::convertString(d1,argv[1], TZ);
	IOUtils::convertString(d2,argv[2], TZ);
23

24
	std::vector< std::vector<MeteoData> > vecMeteo;
25
	IOManager io(cfg);
26
	//io.setProcessingLevel(IOManager::raw);
27
28
29
	std::cout << "Reading input data" << std::endl;

	//Very basic conversion: get the whole data set at once, with its original sampling rate
30
	//io.getMeteoData(d1, d2, vecMeteo);
31

32
33
	Timer timer;
	timer.start();
34
35
36
	//More elaborate conversion: sample the data to a specific rate
	//by looping over the time and calling readMeteoData for each timestep
	std::vector<MeteoData> Meteo; //we need some intermediate storage, for storing data sets for 1 timestep
37
	io.getMeteoData(d1, Meteo); //we need to know how many stations will be available
38
	vecMeteo.insert(vecMeteo.begin(), Meteo.size(), std::vector<MeteoData>()); //allocation for the vectors
39
	for(; d1<=d2; d1+=Tstep) { //time loop
40
		io.getMeteoData(d1, Meteo); //read 1 timestep at once, forcing resampling to the timestep
41
		for(size_t ii=0; ii<Meteo.size(); ii++) {
42
43
44
45
			vecMeteo.at(ii).push_back(Meteo[ii]); //fill the data manually into the vector of vectors
		}
	}

46
	timer.stop();
47
48
	//In both case, we write the data out
	std::cout << "Writing output data" << std::endl;
49
	io.writeMeteoData(vecMeteo);
50

51
	std::cout << "Done!! in " << timer.getElapsed() << " s" << std::endl;
52
53
54
55
56
57
58
59
60
}

int main(int argc, char** argv) {
	try {
		real_main(argc, argv);
	} catch(const std::exception &e) {
		std::cerr << e.what();
		exit(1);
	}
61
62
	return 0;
}