Main.cc 5.99 KB
/****
 * Main.cc
 *  Created on: 15 oct. 2012
 *      Author: AKKA IS
 ****/
/*!
 * @mainpage AMDA-Kernel
 * @image html Logo_CDPP-AMDA_little.png
 * @image latex Logo_CDPP-AMDA_little.png "" height=0cm
 * @section Introduction
 * This document describe the AMDA-Kernel conception:
 * 	- Version 1.0.0 written by AKKA IS exposes:
 * 		-# main component Parameters used to retrieve/store data in parameter. See AMDA::Parameters and  AMDA::Parameters::Parameter.
 * 		-# EvalFormule component which is detailed by only one class:  AMDA::Parameters::ProcessStandard
 * 		-# Download component used to store data in ASCII file which is detailed in namespace AMDA::ParamOutputImpl::Download
 * 		-# DD server Interface component used to open connection and sending data request to server. See AMDA::DDServerInterface
 * 	- Version 2.0.0 written by CS exposes:
 * 		-# TimeTable component used to read/write data from/to file. See timetable. It supports following format:
 * 			- internal XML
 * 			- VO
 * 			- ASCII
 * 		-# Updates of Download component to take into account possibilities of timetable
 * 		-# DataMining component used to store logical state of an equation in file. See AMDA::ParamOutputImpl::DataMining
 * 		-# Plot component used to draw graphics and based on plplot tools. See plot.
 *  - Version 3.0.0 written by AKKA exposes :
 *		-# Components Info used to describe parameters, datasets, instruments and missions
 *      -# Additional functionnalities in the Plot component :
 *      	- Definition of a label
 *      	- Definition of a horizontal or vetical line
 *      	- Draw spectro for a timePlot
 *      	- Muti-Axes Y support
 *      	- Definition of a min or a max value for a plot
 *      	- Definition of a temporal indication along a serie
 *      	- Fill space between a line and a serie
 *      	- Fill space between two series
 *      	- Now the component apply a reampling in a parameter only if it's really needed
 *      	- Definition of vertical layout and auto layout
 *      	- Possibility to make a plot request in a TimeTable
 *      	- Multi-Panel support in a page
 *      	- Possibility to apply a post processing in a plot request result
 *			- Definition of a legend that's described all plotted series
 *			- Definition of an additionnal text in a panel
 *			- Definition of additionals curves
 *			- Use the Info component to show real parameters info in a plot
 *			- Definition of plot 'instantPlot'
 *			- Use the definition of physical gaps for a parameter in a plot
 *			- Possibility to define a colored parameter along a serie
 *			- Possibility to define an orbit plot with a projection
 *			- Possibility to add an error bars along a serie
 *			- Possibility to plot the new Tab2D ParamData
 *			- Possibility to plot a Tab2D for an instant cut time
 *			- Definition of the new plot "statusBar"
 *			- Definition of the new plot "epochPlot"
 *			- Possibility to superpose all time intervals in a same page of plot
 *      -# Additional functionnalities in the Download component :
 *      	- CDF format support
 *      	- JSON format support
 *      	- VOTable format support
 *      	- Use the Info component to show real parameters info in output files
 *      	- New outputStructure "one-file-per-parameter-per-interval"
 *      	- New output structures to resample parameters in the time list of a reference parameters (the first one defined in the request)
 *      	- Creation of a catalog file for "too small time intervals" with the means of all parameters for each time intervals
 *      -# Add new Tab2D ParamData types
 *      -# Module TimeTable is replaced by the module TimeTableCatalog and support the load and the write of catalog files
 *      -# New ParamOutput module StatisticOutput to compute some statistics result
 *      -# New ParamGet module to get data from local files
 *      	- CDF format support
 *      	- ASCII format support
 *      	- VOTable format support
 *
 *@section References
 *@version 3.4.0
 *@authors AKKA IS, CS.
 */
#include <iostream>
#include <memory>

#include "Application.hh"

#include "ParseMainArguments.hh"

// Parameters module include
#include "ParameterManager.hh"
#include "Parameter.hh"
#include "Process.hh"
#include "ServicesServer.hh"

// XMLRequest module include
#include "XMLRequestParser.hh"

using namespace AMDA::Parameters;
using namespace AMDA::XMLRequest;
using namespace AMDA::MainRequest;

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

	try {
		//----------------------------
		//argument parsing
		ParseMainArguments parseArg(argc, argv);
		if (parseArg.isStopProcess()) {
			BOOST_THROW_EXCEPTION(AMDA::AMDA_exception());
		}

		if (access("app.properties", F_OK) != 0) {
			BOOST_THROW_EXCEPTION(
					AMDA::AMDA_exception() << AMDA::errno_code(AMDA_FILEPROPERTIES_ERR) << AMDA::ex_msg("Properties file not found"));
		}
		AMDA::helpers::Properties lProperties("app.properties");


		std::unique_ptr<AMDA::XMLRequest::XMLRequestParser> u0Process(new AMDA::XMLRequest::XMLRequestParser(
				lProperties["app.request.xsd"].c_str()));
		ServicesServer::getInstance()->addService(u0Process.get());

		AMDA::Common::Application lMain;
		result = lMain.main(argc, argv,
				[&](int argc, char *argv[], AMDA::helpers::Properties& lProperties) -> int {
			std::unique_ptr<AMDA::XMLRequest::XMLRequestParser> u1Process = std::move(u0Process);
					//----------------------------
					//Start process
					AMDA::Parameters::ParameterManager lParameterManager;

					if (!lProperties["app.param.gapthreshold"].empty())
					{
						double defaultGapThreshold = 0.;
						defaultGapThreshold = atof(lProperties["app.param.gapthreshold"].c_str());
						if (defaultGapThreshold > 0.)
							lParameterManager.setDefaultGapThreshold(defaultGapThreshold);
					}

					(*u1Process)( lParameterManager, parseArg.getRequesteFile());

					lParameterManager.execute(parseArg.getWorkPath());


					return AMDA_EXIT_OK;
				});
	} catch (AMDA::AMDA_exception & e) {
		std::cerr <<
				"Error resume: " << AMDA::traitException(result,e) << std::endl;
	}

	return result;
}