Files
separation-of-potential-data/src/head_func.h

181 lines
6.0 KiB
C
Raw Normal View History

2022-02-08 17:29:12 +08:00
#ifndef _HEAD_FUNC_H
#define _HEAD_FUNC_H
#include "iostream"
#include "fstream"
#include "sstream"
#include "string.h"
#include "cmath"
#include "iomanip"
#include "stdio.h"
#include "stdlib.h"
#include "unistd.h"
#include "vector"
#include "map"
#include "algorithm"
#include "ctime"
#include "omp.h"
#include "random"
using namespace std;
//数学常量
#define BDL_MAX 1e+30 ///< 定义变量的最大值
#define BDL_MIN -1e+30 ///< 定义变量的最小值
#define ZERO 1e-20 ///< 定义零值
//物理常量
#define Pi (4.0*atan(1.0)) ///< 圆周率
#define G0 6.67408e-3 ///< 万有引力常数。注意这里的量级本来应该是e-11考虑到单位转换取维度单位为m密度单位为g/cm^3乘以G0则重力单位即为mGal
#define T0 5e+4 ///< 地磁场平均强度
//宏函数
#define MAX(a,b) (a>b?a:b) ///< 返回a与b的最大值
#define MIN(a,b) (a<b?a:b) ///< 返回a与b的最小值
#define SetToBox(a,b,in) (MAX(a,MIN(b,in))) ///< 返回a与b之间的一个值若in在a与b之间则直接返回否则返回较近的边界值
//终端显示控制符
#define BOLDRED "\033[1m\033[31m" ///< 设置后续字符字体为红色加粗
#define BOLDGREEN "\033[1m\033[32m" ///< 设置后续字符字体为绿色加粗
#define BOLDYELLOW "\033[1m\033[33m" ///< 设置后续字符字体为黄色加粗
#define BOLDBLUE "\033[1m\033[34m" ///< 设置后续字符字体为蓝色加粗
#define UNDERLINE "\033[1m\033[4m" ///< 设置后续字符为添加下划线
#define RESET "\033[0m" ///< 重置字符设置
#define MOVEUP(x) printf("\033[%dA", (x)) ///< 将光标向上挪x行
#define MOVEDOWN(x) printf("\033[%dB", (x)) ///< 将光标向下娜x行
#define MOVELEFT(x) printf("\033[%dD", (x)) ///< 将光标向左娜x字符
#define MOVERIGHT(x) printf("\033[%dC", (x)) ///< 将光标向右娜x字符
#define MOVETO(y,x) printf("\033[%d;%dH", (y), (x)) ///< 将光标向右娜动y字符,向上挪动x字符
#define CLEARLINE "\033[K" ///< 清除本行
#define CLEARALL "\033[2J" ///< 清除终端满屏
//数据结构
typedef vector<int> _1iArray; ///< 整形一维向量
typedef vector<double> _1dArray; ///< 双精度浮点一维向量
typedef vector<string> _1sArray; ///< 字符串一维向量
typedef vector<vector<int> > _2iArray; ///< 整形浮点二维向量
typedef vector<vector<double> > _2dArray; ///< 双精度浮点二维向量
typedef map<int,int> int2intMap; ///< 整型到整形的映射
/**
* @brief
*
*
*/
struct cpoint{
int id = -1; ///< 点的索引值。初始值为-1一般从0开始标号。
double x = BDL_MAX; ///< 点的x坐标值。
double y = BDL_MAX; ///< 点的y坐标值。
double z = BDL_MAX; ///< 点的z坐标值。
};
/**
*@brief cpoint结构体的向量
*/
typedef vector<cpoint> cpointArray;
/**
* @brief
*
* cpoint继承而来val与不确定度dev
*/
struct obspoint : cpoint{
double val = BDL_MAX; ///< 标量观测值初始值为BDL_MAX。
double dev = BDL_MAX; ///< 观测值的不确定度初始值为BDL_MAX。
};
/**
* @brief obspoint结构体的向量
*/
typedef vector<obspoint> obspointArray;
/**
* @brief
*
*
*/
struct block{
int id = -1; ///< 块体的索引。初始值为-1一般从0开始编号。
int phy_group = -1; ///< 块体所属的物理组编号。初始值为-1。
int vert[4] = {-1,-1,-1,-1}; ///< 块体的四个角点的索引值。初始值均为-1。
double xmin = BDL_MAX; ///< 块体在x坐标轴的最小值。
double xmax = BDL_MIN; ///< 块体在x坐标轴的最大值。
double ymin = BDL_MAX; ///< 块体在y坐标轴的最小值。
double ymax = BDL_MIN; ///< 块体在y坐标轴的最大值。
double zmin = BDL_MAX; ///< 块体在z坐标轴的最小值。
double zmax = BDL_MIN; ///< 块体在z坐标轴的最大值。
};
/**
* @brief block结构体的向量
*/
typedef vector<block> blockArray;
/*************************矢量函数********************************/
/**
* @brief
*
* @param[in] <unnamed>
* @param[in] <unnamed>
*
* @return
*/
cpoint operator -(cpoint,cpoint);
/**
* @brief
*
* @param[in] <unnamed>
* @param[in] <unnamed>
*
* @return
*/
cpoint operator *(double,cpoint);
/**
* @brief
*
* @param[in] <unnamed>
*
* @return
*/
double modCpoint(cpoint);
/**
* @brief
*
* @param[in] <unnamed>
* @param[in] <unnamed>
*
* @return
*/
double angCpoint(cpoint,cpoint);
/*************************全局函数********************************/
/**
* @brief
*
* @param[in] <unnamed> double类型的浮点值
*
* @return double类型的浮点值
*/
double arctg(double);
/**
* @brief string转换为stringstream
*
* @param[in] <unnamed>
*
* @return CString类型字符串
*/
stringstream str2ss(string);
/**
* @brief
*
* @param <unnamed> ifstream对象
* @param <unnamed>
*
* @return 0-1
*/
int open_infile(ifstream&, const char*);
/**
* @brief
*
* @param <unnamed> ofstream对象
* @param <unnamed>
*
* @return 0-1
*/
int open_outfile(ofstream&, const char*);
/**
* @brief
*
* @param[in] <unnamed>
*
* @return
*/
double cube_interpolate(double, double, double, double, double, double, double, double, double, double); //四方块内的双线性插值
#endif