Blame view

src/amdaParameterInfo/Main.cc 3.45 KB
ad920fd6   Benjamin Renard   First implementat...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/**
 * Main.cc
 *  Created on: 18 mar. 2016
 *      Author: AKKA IS
 */

#include <iostream>

#include <boost/program_options.hpp>

#include "AMDA-Kernel_Config.hh"
#include <Application.hh>

// Parameters module include
#include "ParameterManager.hh"
#include "Parameter.hh"
#include "Process.hh"
#include "ParameterInfo.hh"
#include "ServicesServer.hh"
b03f2eca   Benjamin Renard   Improve amdaParam...
20
#include "TimeUtil.hh"
ad920fd6   Benjamin Renard   First implementat...
21
22
23
24
25
26
27

using namespace std;
namespace po = boost::program_options;
using namespace log4cxx;
using namespace log4cxx::helpers;
using namespace AMDA::Parameters;

b03f2eca   Benjamin Renard   Improve amdaParam...
28
#define MAX_YEAR 2040
ad920fd6   Benjamin Renard   First implementat...
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

/**
 * Main function
 */
int main(int argc, char *argv[]) {
	int result = AMDA_EXIT_OK;

	/// Parse command line parameters
	po::options_description desc("Allowed options");

	desc.add_options()
		("help,h", "Produce help message")
		("version,v", "Program version")
		("parameter,p", po::value< vector<string> >(), "Parameter(s) name")
	;

	po::positional_options_description p;
	p.add("parameter", -1);

	po::variables_map vm;
	po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
	po::notify(vm);

	if (vm.count("help")) {
		cout << desc << "\n";
		return result;
	}
	if (vm.count("version")) {
		cout << "Version: " << AMDA_Kernel_VERSION << "\n";
		return result;
	}

	if (!vm.count("parameter")) {
		return result;
	}

	AMDA::Common::Application lMain;

d6c7a344   RENARD Benjamin   Fix some warning ...
67
	return lMain.main(argc,argv,[&](int , char **, AMDA::helpers::Properties& lProperties) -> int {
ad920fd6   Benjamin Renard   First implementat...
68
69
70
71
72
73

			vector<string> lParameterList = vm["parameter"].as< vector<string> >();

			///Create ParameterManager and configuration
			ParameterManager parameterManager;
			std::string emptyStr;
b03f2eca   Benjamin Renard   Improve amdaParam...
74
75
76
77
78
			std::stringstream ss;
			char startTimeIso[24];
			char stopTimeIso[24];
			memset(startTimeIso, 0, 24*sizeof(char));
			memset(stopTimeIso, 0, 24*sizeof(char));
266c1fa7   Benjamin Renard   Optimize amdaPara...
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
			double startTime = 0.;
			double stopTime = 0.;

			std::vector<std::string> gran;
			gran.push_back("-01-01T00:01:00.000");
			gran.push_back("-01-01T01:00:00.000");
			gran.push_back("-01-02T00:00:00.000");
			gran.push_back("-02-01T00:00:00.000");
			gran.push_back("-12-31T00:00:00.000");
			

			for (std::vector<std::string>::iterator itGran = gran.begin(); itGran != gran.end(); ++itGran) {
				for (int y = 1970; y < MAX_YEAR; ++y) {
					ss.str("");
					ss << std::setfill('0') << y << "-01-01T00:00:00.000";
					memcpy(startTimeIso, ss.str().c_str(), 24*sizeof(char));
					startTime = AMDA::TimeUtil::readTimeInIso(startTimeIso);
					ss.str("");
					ss << std::setfill('0') << y << (*itGran);
					memcpy(stopTimeIso, ss.str().c_str(), 24*sizeof(char));
					stopTime = AMDA::TimeUtil::readTimeInIso(stopTimeIso);
					parameterManager.addInputInterval(startTime, stopTime, 0, emptyStr, emptyStr, 0);
				}
b03f2eca   Benjamin Renard   Improve amdaParam...
102
			}
ad920fd6   Benjamin Renard   First implementat...
103
104
105

			if (!lProperties["app.param.gapthreshold"].empty())
			{
c6a67968   Benjamin Renard   Fix some violatio...
106
				double defaultGapThreshold = atof(lProperties["app.param.gapthreshold"].c_str());
ad920fd6   Benjamin Renard   First implementat...
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
				if (defaultGapThreshold > 0.)
					parameterManager.setDefaultGapThreshold(defaultGapThreshold);
			}

			for (auto lParamName : lParameterList) {
				try {
					///Create Parameter
					parameterManager.createParameter(lParamName);

					///Generate Output
					AMDA::Parameters::ParameterInfo* lParameterInfo =
							new AMDA::Parameters::ParameterInfo(parameterManager);
					ParamOutputSPtr lParamOutput(lParameterInfo);
					lParameterInfo->setParamName(lParamName);
					parameterManager.getParamOutputList().push_back( lParamOutput);
				} catch (...) {
				}
			}
			/// launch request
			parameterManager.execute("");

			return result;
});

}