Shue98.hh 5.85 KB
/*
 * 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:   Shue98.hh
 * Author: hacene
 *
 * Created on December 14, 2020, 11:42 AM
 */

#ifndef SHUE98_HH
#define SHUE98_HH
#include "Parameter.hh"
#include "ParamData.hh"
#include "DataTypeMath.hh"
#include "Operation.hh"
#include "GeopackWrapper.hh"
#include "Tsyganenko96.hh"

#include <iterator>

namespace AMDA {
    namespace Parameters {
        namespace Shue98 {

            template <typename ElemType, typename TOutputParamData>
            class Shue98Base : public Tsyganenko96Base {
            public:

                /**
                 * @brief Constructor.
                 * @details Create the ParamData type of the input ParamData.
                 */
                Shue98Base(Process& pProcess, ParamDataSpec<std::vector<ElemType> >& paramInput, ParamData& paramImfInput, ParamData& paramPswInput, bool inGSE)
                : Tsyganenko96Base(pProcess, paramImfInput, paramPswInput),
                _paramInput(paramInput),
                _paramOutput(new TOutputParamData), _inGSE(inGSE) {
                    _paramDataOutput = _paramOutput;
                }

                virtual ~Shue98Base() {
                }

                /**
                 * @overload Operation::write(ParamDataIndexInfo &pParamDataIndexInfo)
                 */

                void write(ParamDataIndexInfo &pParamDataIndexInfo) {
                    for (unsigned int _index = pParamDataIndexInfo._startIndex;
                            _index < pParamDataIndexInfo._startIndex + pParamDataIndexInfo._nbDataToProcess;
                            ++_index) {
                        double crtTime = _paramInput.getTime(_index);

                        float b_x_gse, b_y_gse, b_z_gse;
                        getImfData(crtTime, b_x_gse, b_y_gse, b_z_gse);

                        float p_sw;
                        getPswData(crtTime, p_sw);
                        if (isNAN(p_sw)) {
                            p_sw = DEFAULT_PSW;
                        }


                        std::vector<ElemType> inputElt = _paramInput.get(_index);

                        time_t timestamp = crtTime;
                        struct tm *tmp;
                        tmp = gmtime(&timestamp);

                        std::vector<ElemType> ouputElt;
                        ouputElt.resize(3);
                        ouputElt << NotANumber();

                        //Init geopack with GSM frame
                        geopack::GeopackWrapper::initInGSM(1900 + tmp->tm_year, 1 + tmp->tm_yday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec);

                        //Compute magnetic field
                        float X_GSW, Y_GSW, Z_GSW;
                        float dst;
                        int pos_id;
                        bool computed = false;
                        computed = geopack::GeopackWrapper::shue98(p_sw, b_z_gsm, sat_pos_X_GSM, sat_pos_Y_GSM, sat_pos_Z_GSM,
                                X_GSW, Y_GSW, Z_GSW, dst, pos_id);
                        if (computed) {
                            ouputElt[0] = B_X_RES;
                            ouputElt[1] = B_Y_RES;
                            ouputElt[2] = B_Z_RES;
                        }


                        _paramOutput->pushTime(crtTime);
                        pushData(ouputElt, dst, pos_id);
                    }
                }

                void pushData(std::vector<ElemType> std::vector<ElemType>ouputElt, ElemType dst, int pos_id) = 0;

            protected:
                ParamDataSpec<std::vector<ElemType> >& _paramInput;

                TOutputParamData* _paramOutput;

                bool _inGSE;
            };

            template <typename ElemType>
            class Shue98Dst : public Shue98Base {

                Shue98Dst(Process& pProcess, ParamDataSpec<std::vector<ElemType> >& paramInput, ParamData& paramImfInput, ParamData& paramPswInput, bool inGSE)
                : Shue98Base<ElemType, ParamDataSpec<ElemType>>(pProcess, paramInput, paramImfInput, paramPswInput, inGSE) {

                }

                virtual ~Shue98Dst() {
                }

                pushData(std::vector<ElemType>/*ouputElt*/, ElemType dst, int /*pos_id*/) {
                    Shue98Base<ElemType,ParamDataSpec<ElemType>>::_paramOutput->getDataList().push_back(dst);
                }

            };

            template <typename ElemType>
            class Shue98Pos_Id : public Shue98Base {

                Shue98Pos_Id(Process& pProcess, ParamDataSpec<std::vector<ElemType> >& paramInput, ParamData& paramImfInput, ParamData& paramPswInput, bool inGSE)
                : Shue98Base<ElemType, ParamDataSpec<int>>(pProcess, paramInput, paramImfInput, paramPswInput, inGSE) {

                }

                virtual ~Shue98Pos_Id() {
                }

                pushData(std::vector<ElemType>/*ouputElt*/, ElemType /*dst*/, int pos_id) {
                    Shue98Base<ElemType, ParamDataSpec<int>>::_paramOutput->getDataList().push_back(pos_id);
                }

            };

            template <typename ElemType>
            class Shue98Pos : public Shue98Base {

                Shue98Pos(Process& pProcess, ParamDataSpec<std::vector<ElemType> >& paramInput, ParamData& paramImfInput, ParamData& paramPswInput, bool inGSE)
                : Shue98Base<ElemType,ParamDataSpec<std::vector<ElemType>>>(pProcess, paramInput, paramImfInput, paramPswInput, inGSE) {

                }

                virtual ~Shue98Pos() {
                }

                pushData(std::vector<ElemType> ouputElt, ElemType /*dst*/, int /*pos_id*/) {
                    Shue98Base<ElemType, ParamDataSpec<std::vector<ElemType>>>::_paramOutput->getDataList().push_back(ouputElt);
                }

            };

        }
    }





#endif /* SHUE98_HH */