From afa22fae5d532a6d2590e6fe710533caba97eacb Mon Sep 17 00:00:00 2001 From: Hacene SI HADJ MOHAND Date: Fri, 24 Jul 2020 14:28:18 +0200 Subject: [PATCH] presque --- src/ExternLib/Maglib/AMDAPlugin.cc | 30 ++++++++++++++++++++++++++++++ src/ExternLib/Maglib/CMakeLists.txt | 1 + src/ExternLib/Maglib/MLTProcess.cc | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/ExternLib/Maglib/MLTProcess.hh | 38 ++++++++++++++++++++++++++++++++++++++ src/ExternLib/Maglib/MaglibCreator.hh | 183 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/ExternLib/Maglib/MaglibWarpper.hh | 15 +++++++++------ src/ExternLib/Maglib/Posmag.hh | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------- 7 files changed, 381 insertions(+), 59 deletions(-) create mode 100644 src/ExternLib/Maglib/AMDAPlugin.cc create mode 100644 src/ExternLib/Maglib/MLTProcess.cc create mode 100644 src/ExternLib/Maglib/MLTProcess.hh diff --git a/src/ExternLib/Maglib/AMDAPlugin.cc b/src/ExternLib/Maglib/AMDAPlugin.cc new file mode 100644 index 0000000..f723d6b --- /dev/null +++ b/src/ExternLib/Maglib/AMDAPlugin.cc @@ -0,0 +1,30 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +#include "ServicesServer.hh" +#include "PluginManager.hh" + +#include "MLTProcess.hh" + +using namespace AMDA::Parameters; + +/** + Retrieve the Plugin version we're going to expect +*/ +extern "C" const char* getPluginVersion() +{ + return "(Version)"; +} + +/** + Tells us to register our functionality to an engine kernel +*/ +extern "C" void registerPlugin(AMDA::Plugins::PluginManager & pm) +{ + ProcessFactory factMLTProcess = boost::factory(); + ServicesServer::getInstance()->addProcessFactory("maglib_mlt", factMLTProcess); + ServicesServer::getInstance()->linkProcessWithPlugin("maglib_mlt", pm.getCurrentPluginPath()); +} + diff --git a/src/ExternLib/Maglib/CMakeLists.txt b/src/ExternLib/Maglib/CMakeLists.txt index df17ba4..0d4af7e 100644 --- a/src/ExternLib/Maglib/CMakeLists.txt +++ b/src/ExternLib/Maglib/CMakeLists.txt @@ -29,6 +29,7 @@ ADD_LIBRARY( maglib SHARED ${source_files} ) target_link_libraries( maglib ${LOG4CXX_LIBRARIES} + $(MAGLIBLIBRARIES) Parameters InternLib TimeTableCatalog diff --git a/src/ExternLib/Maglib/MLTProcess.cc b/src/ExternLib/Maglib/MLTProcess.cc new file mode 100644 index 0000000..36b8b64 --- /dev/null +++ b/src/ExternLib/Maglib/MLTProcess.cc @@ -0,0 +1,56 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +/* + * File: MLTProcess.cc + * Author: hacene + * + * Created on July 23, 2020, 4:14 PM + */ +#include +#include + +#include "Operation.hh" +#include "ParameterManager.hh" +#include "ParameterCreatorFromExpression.hh" +#include "MLTProcess.hh" +#include "MaglibCreator.hh" + +namespace AMDA { + namespace Parameters { + + MLTProcess::MLTProcess(Parameter& parameter) : SingleParamProcess_CRTP(parameter) { + } + + MLTProcess::MLTProcess(const MLTProcess& pProcess, Parameter ¶meter) : SingleParamProcess_CRTP(pProcess, parameter) { + } + + TimeStamp MLTProcess::init() { + + TimeStamp timeStamp = _parameterInput->init(this, _timeIntervalList); + Parameter::InfoList lInfoList = _parameterInput->getInfoList(); + _parameter.getInfoList().insert(lInfoList.begin(), lInfoList.end()); + _paramInput = _parameterInput->getParamData(this).get(); + + std::string isatex_str = "0"; + std::string magout_str = "2"; + + if (_attributList.size() == 2) { + isatex_str = _attributList[0]; + magout_str = _attributList[1]; + } + MaglibCreator lCreator(*this, *_paramInput, "mlt", isatex_str, isatex_str); + _operation = lCreator.getOperation(); + _paramData = ParamDataSPtr(_operation->getParamOutput()); + _paramData->setMinSampling(_paramInput->getMinSampling()); + return timeStamp; + } + + MLTProcess::~MLTProcess() { + } + + } +} \ No newline at end of file diff --git a/src/ExternLib/Maglib/MLTProcess.hh b/src/ExternLib/Maglib/MLTProcess.hh new file mode 100644 index 0000000..f445af3 --- /dev/null +++ b/src/ExternLib/Maglib/MLTProcess.hh @@ -0,0 +1,38 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +/* + * File: MLTProcess.hh + * Author: hacene + * + * Created on July 23, 2020, 4:14 PM + */ + +#ifndef MLTPROCESS_HH +#define MLTPROCESS_HH + +#include "SingleParamProcess.hh" + +namespace AMDA { + namespace Parameters { + + class MLTProcess : public AMDA::Parameters::SingleParamProcess_CRTP { + public: + MLTProcess(Parameter ¶meter); + MLTProcess(const MLTProcess& pProcess, Parameter& pParameter); + virtual ~MLTProcess(); + + /** + * @overload DataWriter::init() + */ + TimeStamp init(); + + }; + + } +} +#endif /* MLTPROCESS_HH */ + diff --git a/src/ExternLib/Maglib/MaglibCreator.hh b/src/ExternLib/Maglib/MaglibCreator.hh index eaf0082..f4eb199 100644 --- a/src/ExternLib/Maglib/MaglibCreator.hh +++ b/src/ExternLib/Maglib/MaglibCreator.hh @@ -14,6 +14,189 @@ #ifndef MAGLIBCREATOR_HH #define MAGLIBCREATOR_HH +#include "ParamData.hh" +#include "VisitorOfParamData.hh" +#include "Posmag.hh" + +namespace AMDA { +namespace Parameters { + + class MaglibCreator : public VisitorOfParamData { + public: + + MaglibCreator(Process& pProcess, ParamData& paramInput, std::string output, std::string isatex, std::string magout) : + _process(pProcess), _paramData(paramInput), _operation(NULL), _output(output) { + _paramData.accept(*this); + + if (std::stoi(isatex) == 0 || std::stoi(isatex) == 1) { + _isatex = std::stoi(isatex); + } else { + BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg(" Not handled in the Mablib")); + } + if (std::stoi(magout) >= 0 && std::stoi(magout) <= 3) { + _magout = std::stoi(magout); + } else { + BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg(" Not handled in the Mablib")); + } + } + + /** + * @overload VisitorOfParamData::visit(ParamDataScalaireShort *) + */ + void visit(ParamDataScalaireShort *) { + BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("ParamDataScalaireShort data not supported")); + } + + /** + * @overload VisitorOfParamData::visit(ParamDataScalaireFloat *) + */ + void visit(ParamDataScalaireFloat *) { + BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("ParamDataScalaireFloat data not supported")); + } + + /** + * @overload VisitorOfParamData::visit(ParamDataScalaireDouble *) + */ + void visit(ParamDataScalaireDouble *) { + BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("ParamDataScalaireDouble data not supported")); + } + + /** + * @overload VisitorOfParamData::visit(ParamDataScalaireLongDouble *) + */ + void visit(ParamDataScalaireLongDouble *) { + BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("ParamDataScalaireLongDouble data not supported")); + } + + /** + * @overload VisitorOfParamData::visit(ParamDataScalaireInt *) + */ + void visit(ParamDataScalaireInt *) { + BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("ParamDataScalaireInt data not supported")); + } + + /** + * @overload VisitorOfParamData::visit(ParamDataLogicalData *) + */ + void visit(ParamDataLogicalData *) { + BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("ParamDataLogicalData data not supported")); + } + + /** + * @overload VisitorOfParamData::visit(ParamDataTab1DShort *) + */ + void visit(ParamDataTab1DShort *) { + create(); + } + + /** + * @overload VisitorOfParamData::visit(ParamDataTab1DFloat *) + */ + void visit(ParamDataTab1DFloat *) { + create(); + } + + /** + * @overload VisitorOfParamData::visit(ParamDataTab1DDouble *) + */ + void visit(ParamDataTab1DDouble *) { + create(); + } + + /** + * @overload VisitorOfParamData::visit(ParamDataTab1DLongDouble *) + */ + void visit(ParamDataTab1DLongDouble *) { + create(); + } + + /** + * @overload VisitorOfParamData::visit(ParamDataTab1DInt *) + */ + void visit(ParamDataTab1DInt *) { + create(); + } + + /** + * @overload VisitorOfParamData::visit(ParamDataTab1DLogicalData *) + */ + void visit(ParamDataTab1DLogicalData *) { + BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("ParamDataTab1DLogicalData data not supported")); + } + + /** + * @overload VisitorOfParamData::visit(ParamDataTab2DShort *) + */ + void visit(ParamDataTab2DShort *) { + BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("ParamDataTab2DShort data not supported")); + } + + /** + * @overload VisitorOfParamData::visit(ParamDataTab2DFloat *) + */ + void visit(ParamDataTab2DFloat *) { + BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("ParamDataTab2DFloat data not supported")); + } + + /** + * @overload VisitorOfParamData::visit(ParamDataTab2DDouble *) + */ + void visit(ParamDataTab2DDouble *) { + BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("ParamDataTab2DDouble data not supported")); + } + + /** + * @overload VisitorOfParamData::visit(ParamDataTab2DLongDouble *) + */ + void visit(ParamDataTab2DLongDouble *) { + BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("ParamDataTab2DLongDouble data not supported")); + } + + /** + * @overload VisitorOfParamData::visit(ParamDataTab2DInt *) + */ + void visit(ParamDataTab2DInt *) { + BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("ParamDataTab2DInt data not supported")); + } + + /** + * @overload VisitorOfParamData::visit(ParamDataTab2DLogicalData *) + */ + void visit(ParamDataTab2DLogicalData *) { + BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("ParamDataTab2DLogicalData data not supported")); + } + + /** + * @brief get the TimeShifted parameterized operation. + */ + Operation * getOperation() const { + return _operation; + } + + template + void create() { + + if (_output == "mlt") + _operation = new MLT(_process, dynamic_cast >&> (_paramData), _isatex, _magout); + else if (_output == "invlat") + _operation = new InvLat(_process, dynamic_cast >&> (_paramData), _isatex, _magout); + else if (_output == "lparam") + _operation = new Lparam(_process, dynamic_cast >&> (_paramData), _isatex, _magout); + else + BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg(" output type not supported")); + + } + + private: + Process &_process; + ParamData &_paramData; + Operation *_operation; + std::string _output; + int _isatex; + int _magout; + }; + } +} #endif /* MAGLIBCREATOR_HH */ diff --git a/src/ExternLib/Maglib/MaglibWarpper.hh b/src/ExternLib/Maglib/MaglibWarpper.hh index d16b1d2..1421073 100644 --- a/src/ExternLib/Maglib/MaglibWarpper.hh +++ b/src/ExternLib/Maglib/MaglibWarpper.hh @@ -23,10 +23,9 @@ namespace AMDA { class maglibWarpper { public: - static void getPosmag(int iyear, int imonth, int iday, int ihour, int imin, int isec, float* rrmag, float* thetr, float* phir, - int* isatex, int* magout, float* xgsm, float* ygsm, float* zgsm, float* xgse, float* ygse, float* zgse, float* tgl, - float* flg, float* xlambr, float* tglc, float* hsl, float* clatgmr, float* clongmr, float * iposmg[15], int* ifai) - { + static void getPosmag(int iyear, int imonth, int iday, int ihour, int imin, int isec, float& rrmag, float& thetr, float& phir, + int& isatex, int& magout, float& xgsm, float& ygsm, float& zgsm, float& xgse, float& ygse, float& zgse, float& tgl, + float& flg, float& xlambr, float& tglc, float& hsl, float& clatgmr, float& clongmr, std::vector& iposmg, int& ifai) { /** * * @param iyear enre 2000 et 2015 @@ -44,17 +43,21 @@ i * isatex : 1 = satellite excentrique (apogee > // declaration int ifail; + int iposmg_o [15]; float rig[3][3], rgi[3][3], rgsm[3][3], rsmg[3][3], rggsm[3][3], rgsmg[3][3], rgse[3][3], rseg[3][3]; float rgdip[3][3], rdipg[3][3], rigsm[3][3], rgsmi[3][3]; float alfag, alfas, deltas, tilt, tetdip, phidip, year; - + valfix_(ifail); inigeom_(iyear, imonth, iday, ihour, imin, isec, year, alfag, tetdip, phidip, alfas, deltas, rig, rgi, rgdip, rdipg, rgsm, rsmg, tilt, rggsm, rgsmg, rgse, rseg, rigsm, rgsmi, ifail); posmag_(magout, isatex, year, rrmag, thetr, phir, alfag, alfas, deltas, tilt, rgsm, rggsm, rgsmg, rgdip, rgse, tetdip, - phidip, xgsm, ygsm, zgsm, xgse, ygse, zgse, tgl, flg, xlambr, tglc, hsl, clatgmr, clongmr, iposmg, ifail); + phidip, xgsm, ygsm, zgsm, xgse, ygse, zgse, tgl, flg, xlambr, tglc, hsl, clatgmr, clongmr, iposmg_o, ifail); + + for (int i = 0; i < iposmg_o.size(); i++) + iposmg[i] = iposmg_o[i]; } }; diff --git a/src/ExternLib/Maglib/Posmag.hh b/src/ExternLib/Maglib/Posmag.hh index 6755f1c..ae858f0 100644 --- a/src/ExternLib/Maglib/Posmag.hh +++ b/src/ExternLib/Maglib/Posmag.hh @@ -19,12 +19,13 @@ #include "ParamData.hh" #include "DataTypeMath.hh" #include "Operation.hh" -#include "SpiceKernelMgr.hh" #include namespace AMDA { namespace Parameters { + using namespace std; + template class Posmag : public Operation { public: @@ -68,7 +69,7 @@ namespace AMDA { vector in = _paramInput.getDataList()[_index]; double crtTime = _paramInput.getTime(_index); - ime_t timestamp = crtTime; + time_t timestamp = crtTime; struct tm *tmp; tmp = gmtime(×tamp); float i_rrmag = in[0]; @@ -101,25 +102,32 @@ namespace AMDA { */ float xgsm, ygsm, zgsm, xgse, ygse, zgse, tgl, - flg, xlambr, tglc, hsl, fclatgmr, clongmr, - tgl, flg, xlambr, tglc, hsl, clatgmr, clongmr, xlamb, clatgm, clongm; + flg, xlamb, tglc, hsl, clatgmr, clongmr; + int ifail; - int iposmg[15]; + std::vector iposmg; + iposmg.resize(15); /** - static void getPosmag(int iyear, int imonth, int iday, int ihour, int imin, int isec, float* rrmag, float* thetr, float* phir, - int* isatex, int* magout, float* xgsm, float* ygsm, float* zgsm, float* xgse, float* ygse, float* zgse, float* tgl, - float* flg, float* xlambr, float* tglc, float* hsl, float* clatgmr, float* clongmr, float * iposmg[15], int* ifai) + static void getPosmag(int iyear, int imonth, int iday, int ihour, int imin, int isec, + * float* rrmag, float* thetr, float* phir, + int* isatex, int* magout, float* + * xgsm, float* ygsm, float* zgsm, + * float* xgse, float* ygse, float* zgse, + * float* tgl, float* flg, float* xlambr, float* tglc, float* hsl, float* clatgmr, float* clongmr, float * iposmg[15], int* ifai) */ - maglib::maglibWarpper::getPosmag(1900 + tmp->tm_year, 1 + tmp->tm_yday, tmp->tm_hour, - tmp->tm_min, tmp->tm_sec, i_rrmag, i_thetr, i_phir, _isatex, _magout, xgsm, ygsm, zgsm, xgse, ygse, zgse, tgl, - flg, xlambr, tglc, hsl, fclatgmr, clongmr, iposmg, ifail); - + maglib::maglibWarpper::getPosmag(1900 + tmp->tm_year, 1 + tmp->tm_mon, tmp->tm_mday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec, + i_rrmag, i_thetr, i_phir, + _isatex, _magout, + xgsm, ygsm, zgsm, + xgse, ygse, zgse, + tgl, flg, xlamb, tglc, hsl, clatgmr, clongmr, iposmg, ifail); + DataType tgl_res = (DataType) tgl; DataType xlamb_res = (DataType) xlamb; DataType flg_res = (DataType) flg; - _paramOutput->pushTime(crtTime); + _paramOutput->pushTime(crtTime); pushData(tgl_res, xlamb_res, flg_res); } @@ -128,63 +136,66 @@ namespace AMDA { virtual void pushData(DataType tgl, DataType xlamb, DataType flg) = 0; protected: + ParamDataSpec >& _paramInput; + ParamDataSpec* _paramOutput; int _isatex; int _magout; - private: - ParamDataSpec >& _paramInput; - ParamDataSpec* _paramOutput; + }; - + /** * Ecriture de temps geomagnetique local du satellite (heure fractionnée) */ template - class MLT : public Posmag >{ - - MLT(Process& pProcess, ParamDataSpec >& paramInput, int isatex, int magout): - Posmag > :: Posmag(pProcess, paramInput, isatex, magout){ - } - - void pushData(DataType tgl, DataType /*xlamb*/, DataType /*flg*/){ - - Posmag > :: _paramDataOutput.getDataList().push_back(tgl); - } + class MLT : public Posmag > { + public: + + MLT(Process& pProcess, ParamDataSpec >& paramInput, int isatex, int magout) : + Posmag > ::Posmag(pProcess, paramInput, isatex, magout) { + } + + void pushData(DataType tgl, DataType /*xlamb*/, DataType /*flg*/) { + + Posmag > ::_paramOutput->getDataList().push_back(tgl); + } }; - - /** + + /** * Ecriture de invariant latitude */ template - class InvLat : public Posmag >{ - - InvLat(Process& pProcess, ParamDataSpec >& paramInput, int isatex, int magout): - Posmag > :: Posmag(pProcess, paramInput, isatex, magout){ - } - - void pushData(DataType /*tgl*/, DataType xlamb, DataType /*flg*/){ - - Posmag > :: _paramDataOutput.getDataList().push_back(xlamb); - } + class InvLat : public Posmag > { + public: + + InvLat(Process& pProcess, ParamDataSpec >& paramInput, int isatex, int magout) : + Posmag > ::Posmag(pProcess, paramInput, isatex, magout) { + } + + void pushData(DataType /*tgl*/, DataType xlamb, DataType /*flg*/) { + + Posmag > ::_paramOutput->getDataList().push_back(xlamb); + } }; - - /** + + /** * Ecriture du parametre L */ template - class Lparam : public Posmag >{ - - Lparam(Process& pProcess, ParamDataSpec >& paramInput, int isatex, int magout): - Posmag > :: Posmag(pProcess, paramInput, isatex, magout){ - } - - void pushData(DataType /*tgl*/, DataType /*xlamb*/, DataType flg){ - - Posmag > :: _paramDataOutput.getDataList().push_back(flg); - } + class Lparam : public Posmag > { + public: + + Lparam(Process& pProcess, ParamDataSpec >& paramInput, int isatex, int magout) : + Posmag > ::Posmag(pProcess, paramInput, isatex, magout) { + } + + void pushData(DataType /*tgl*/, DataType /*xlamb*/, DataType flg) { + + Posmag > ::_paramOutput->getDataList().push_back(flg); + } }; - + } - + } -- libgit2 0.21.2