#ifndef _DRTP_H
#define _DRTP_H
#include "gctl/core.h"
#include "gctl/utility.h"
#include "gctl/io.h"
#include "gctl/algorithm.h"
#include "complex"
#include "fftw3.h"
#include "stdlib.h"

#define GRIDIN     "input-grid"
#define GRIDOUT    "output-grid"
#define GRIDPARA   "grid-para"
#define GEOMAGEXE  "geomag-exe"
#define GEOMAGPARA "geomag-para"
#define GEOMAGOUT  "geomag-output"
#define IGRFMODEL  "IGRF"
#define CALLGEOMAG "call-geomag"
#define USEMEAN    "mean-geomag"
#define TAYLOR     "taylor-order"


class DRTP
{
public:
	DRTP()
	{
		netcdf_lon_name_ = "x";
		netcdf_lat_name_ = "y";
		netcdf_data_name_ = "z";

		taylor_order_ = 2;
	}
	virtual ~DRTP(){}

	void ReadConfig(std::string filename); // 读入参数
	void ReadGrid(); // 读入磁异常总强度异常网格文件（Netcdf）
	void ReadGEOMAG(); // 读入geomag输出文件中的倾角与偏角
	void SaveGrid(); // 保存计算结果文件
	void CalNormalField(); // 计算网格节点位置的正常场的磁倾角与磁偏角
	void RTP(double inc, double dec); // 普通化极 倾角与偏角的单位为度
	void DiffRTP(int order); // 差分化极
	void Process(); // 执行化极流程

	double cosd(double deg){return cos(deg*GCTL_Pi/180.0);}
	double sind(double deg){return sin(deg*GCTL_Pi/180.0);}
protected:
	unsigned int taylor_order_;

	int rsize_, csize_;
	double mean_inc_, mean_dec_;
	double dlon_, dlat_;

	gctl::array<double> in_lon_, in_lat_;
	gctl::matrix<double> grid_;
	gctl::matrix<double> rtp_;
	gctl::matrix<double> geomag_inc_;
	gctl::matrix<double> geomag_dec_;

	std::string ingrid_name_, outgrid_name_;
	std::string netcdf_data_name_, netcdf_lon_name_, netcdf_lat_name_;

	// 从文件读入参数列表
	gctl::getoption gopt_;
};
#endif //_DRTP_H