Cain.hh 5.06 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:   Cain.hh
 * Author: hacene
 *
 * Created on September 6, 2021, 11:41 AM
 */

#ifndef CAIN_HH
#define CAIN_HH


#include "Parameter.hh"
#include "ParamData.hh"
#include "DataTypeMath.hh"
#include "Operation.hh"
#include "SpiceKernelMgr.hh"
#include <vector>
#include <c++/4.8.2/bits/basic_string.h>
#include "cainWarpper.hh"

#define RM  3396.2  //RADIUS_MARS 


namespace AMDA {
    namespace Parameters {
        namespace Cain {

            using namespace std;

            template<typename DataType, class TOutputParamData>
            class Cain : public Operation {
            public:

                Cain(Process& pProcess, ParamDataSpec<vector<DataType> >&paramInput) : Operation(pProcess),
                _paramInput(paramInput), _paramOutput(new TOutputParamData()) {
                    _paramDataOutput = _paramOutput;
                }

                virtual ~Cain() {
                }

                /**
                 * @overload Operation::write(ParamDataIndexInfo &pParamDataIndexInfo)
                 */
                void write(ParamDataIndexInfo &pParamDataIndexInfo) {
                    double dlat, dlong, alt;
                    double B= 0.0;
                    double Bx = 0.0, By = 0.0, Bz = 0.0;
                    double Btt = 0.0, Bpp = 0.0, Brr = 0.0;
                    int ifail = -1;
                    for (unsigned int _index = pParamDataIndexInfo._startIndex;
                            _index < pParamDataIndexInfo._startIndex + pParamDataIndexInfo._nbDataToProcess;
                            ++_index) {
                        std::vector<DataType> xyz_MSO = _paramInput.getDataList()[_index];
                        dlat = (double) xyz_MSO[0];
                        dlong = (double) xyz_MSO[1];
                        alt = (double) xyz_MSO[2]*RM;
                        double crtTime = _paramInput.getTime(_index);                        
                        cainWarpper::getCain(
                                dlat, dlong,    alt,
                                Btt, Bpp, Brr,
                                Bx, By, Bz,
                                B, ifail);
                        std::vector<double> outputBrtp;
                        outputBrtp.resize(3);
                        outputBrtp[0] = Btt;
                        outputBrtp[1] = Bpp;
                        outputBrtp[2] = Brr;

                        vector<double>outputBxyz;
                        outputBxyz.resize(3);
                        outputBxyz[0] = Bx;
                        outputBxyz[1] = By;
                        outputBxyz[2] = Bz;
                        // writing data 
                        _paramOutput->pushTime(crtTime);
                        pushResult(outputBrtp, B, outputBxyz);

                    }
                }

                virtual void pushResult(std::vector<double>& fieldSph, double& magnitude_, std::vector<double> &fieldCoor) = 0;
            protected:
                ParamDataSpec<std::vector<DataType> >& _paramInput;
                TOutputParamData* _paramOutput;
            };

        template<typename DataType, class TOutputParamData>
        class CainMag : public Cain<DataType, TOutputParamData >{
            public:
                CainMag(Process& pProcess, ParamDataSpec<vector<DataType> >& paramInput) :
                Cain<DataType, TOutputParamData>(pProcess, paramInput) {
                }
                
                void pushResult(std::vector<double>& /*fieldSph*/, double& magnitude_, std::vector<double>& /*fieldCoor*/){
                    Cain<DataType, TOutputParamData> ::_paramOutput->getDataList().push_back(magnitude_);
                }
        };
        
      template<typename DataType, class TOutputParamData>
        class CainCart : public Cain<DataType, TOutputParamData >{
            public:
                CainCart(Process& pProcess, ParamDataSpec<vector<DataType> >& paramInput) :
                Cain<DataType, TOutputParamData>(pProcess, paramInput) {
                }
                
                void pushResult(std::vector<double>& /*fieldSph*/, double& /*magnitude_*/, std::vector<double>& fieldCoor){
                    Cain<DataType, TOutputParamData> ::_paramOutput->getDataList().push_back(fieldCoor);
                }
        };
        
        template<typename DataType, class TOutputParamData>
        class CainSphr : public Cain<DataType, TOutputParamData >{
            public:
                CainSphr(Process& pProcess, ParamDataSpec<vector<DataType> >& paramInput) :
                Cain<DataType, TOutputParamData>(pProcess, paramInput) {
                }
                
                void pushResult(std::vector<double>& fieldSph, double& /*magnitude_*/, std::vector<double>& /*fieldCoor*/){
                    Cain<DataType, TOutputParamData> ::_paramOutput->getDataList().push_back(fieldSph);
                }
        };
        
        }
    }
}

#endif /* CAIN2003_HH */