initial upload
This commit is contained in:
33
archive/linearmap/.gitignore
vendored
Normal file
33
archive/linearmap/.gitignore
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
|
||||
# Fortran module files
|
||||
*.mod
|
||||
*.smod
|
||||
|
||||
# Compiled Static libraries
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
*.ex
|
1
archive/linearmap/README.md
Normal file
1
archive/linearmap/README.md
Normal file
@@ -0,0 +1 @@
|
||||
# 线性特征提取
|
273
archive/linearmap/linearmap.h
Normal file
273
archive/linearmap/linearmap.h
Normal file
@@ -0,0 +1,273 @@
|
||||
#include "iostream"
|
||||
#include "fstream"
|
||||
#include "iomanip"
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "unistd.h"
|
||||
#include "cmath"
|
||||
#include "string.h"
|
||||
#include "sstream"
|
||||
#include "vector"
|
||||
#include "string.h"
|
||||
|
||||
#define pi (atan(1.0)*4.0)
|
||||
#define BOLDRED "\033[1m\033[31m"
|
||||
#define RESET "\033[0m"
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct dpoint
|
||||
{
|
||||
double x,y,val;
|
||||
dpoint()
|
||||
{
|
||||
x = y = val = 0.0;
|
||||
}
|
||||
};
|
||||
typedef vector<dpoint> _dpointArray;
|
||||
|
||||
typedef vector<double> _1dArray;
|
||||
|
||||
int open_infile(ifstream &infile,char* filename)
|
||||
{
|
||||
infile.open(filename);
|
||||
if (!infile)
|
||||
{
|
||||
cout << BOLDRED << "error ==> " << RESET << "file not found: " << filename << endl;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int open_outfile(ofstream &outfile,char* filename)
|
||||
{
|
||||
outfile.open(filename);
|
||||
if (!outfile)
|
||||
{
|
||||
cout << BOLDRED << "error ==> " << RESET << "fail to create the file: " << filename << endl;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
class linearmap
|
||||
{
|
||||
public:
|
||||
linearmap(){}
|
||||
~linearmap(){}
|
||||
_dpointArray readxyz(char*,char*,char*,char*);
|
||||
int outRes(char*);
|
||||
int thetaMap(char*,char*,char*,char*,char*,char*);
|
||||
int THDR(char*,char*,char*,char*,char*,char*);
|
||||
int ASA(char*,char*,char*,char*,char*,char*,char*);
|
||||
int TAHG(char*,char*,char*,char*,char*,char*,char*);
|
||||
private:
|
||||
_dpointArray gradx;
|
||||
_dpointArray grady;
|
||||
_dpointArray gradz;
|
||||
_dpointArray res;
|
||||
};
|
||||
|
||||
_dpointArray linearmap::readxyz(char* filename,char* range,char* interval,char* order)
|
||||
{
|
||||
_dpointArray input_data;
|
||||
_1dArray tempRow;
|
||||
double x,y,data,temp_d;
|
||||
double xmin,xmax,ymin,ymax;
|
||||
double dx,dy;
|
||||
int xnum,ynum;
|
||||
int orders[3];
|
||||
int data_index;
|
||||
string temp_str;
|
||||
stringstream temp_ss;
|
||||
|
||||
//解析数据范围
|
||||
if (4 != sscanf(range,"%lf/%lf/%lf/%lf",&xmin,&xmax,&ymin,&ymax))
|
||||
{
|
||||
cout << BOLDRED << "error ==> " << RESET << "wrong range parameters for the file: " << filename << endl;
|
||||
return input_data;
|
||||
}
|
||||
else if (2 != sscanf(interval,"%lf/%lf",&dx,&dy))
|
||||
{
|
||||
cout << BOLDRED << "error ==> " << RESET << "wrong interval parameters for the file: " << filename << endl;
|
||||
return input_data;
|
||||
}
|
||||
else if (3 != sscanf(order,"%d,%d,%d",&orders[0],&orders[1],&orders[2]))
|
||||
{
|
||||
cout << BOLDRED << "error ==> " << RESET << "wrong order parameters for the file: " << filename << endl;
|
||||
return input_data;
|
||||
}
|
||||
|
||||
//打开文件
|
||||
ifstream datain;
|
||||
if (open_infile(datain,filename)) return input_data;
|
||||
|
||||
//设置input_data大小
|
||||
xnum = round((xmax-xmin)/dx)+1;
|
||||
ynum = round((ymax-ymin)/dy)+1;
|
||||
input_data.resize(xnum*ynum);
|
||||
|
||||
//读入数据
|
||||
while (getline(datain,temp_str))
|
||||
{
|
||||
if (*(temp_str.begin()) == '#') continue;
|
||||
else
|
||||
{
|
||||
//读入行
|
||||
temp_ss.str("");
|
||||
temp_ss.clear();
|
||||
temp_ss.str(temp_str);
|
||||
//解析数据行
|
||||
if(!tempRow.empty()) tempRow.clear();
|
||||
while (temp_ss >> temp_d)
|
||||
{
|
||||
tempRow.push_back(temp_d);
|
||||
}
|
||||
//读入指定位置的数据
|
||||
x = tempRow.at(orders[0]);
|
||||
y = tempRow.at(orders[1]);
|
||||
data = tempRow.at(orders[2]);
|
||||
//存入input_data 从左下到右上
|
||||
data_index = round((x-xmin)/dx) + round((y-ymin)/dy)*xnum;
|
||||
input_data.at(data_index).x = x;
|
||||
input_data.at(data_index).y = y;
|
||||
input_data.at(data_index).val = data;
|
||||
}
|
||||
}
|
||||
|
||||
datain.close();
|
||||
return input_data;
|
||||
}
|
||||
|
||||
int linearmap::outRes(char* filename)
|
||||
{
|
||||
ofstream outfile;
|
||||
if (open_outfile(outfile,filename)) return -1;
|
||||
|
||||
for (int i = 0; i < res.size(); i++)
|
||||
{
|
||||
outfile << res.at(i).x << " " << res.at(i).y << " " << setprecision(16) << res.at(i).val << endl;
|
||||
}
|
||||
outfile.close();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int linearmap::thetaMap(char* xfile,char* zfile,char* ofile,char* ran,char* inter,char* col)
|
||||
{
|
||||
gradx = readxyz(xfile,ran,inter,col);
|
||||
if (gradx.empty()) return -1;
|
||||
|
||||
gradz = readxyz(zfile,ran,inter,col);
|
||||
if (gradz.empty()) return -1;
|
||||
|
||||
if (gradx.size() != gradz.size())
|
||||
{
|
||||
cout << BOLDRED << "error ==> " << RESET << "data amount does not match for thetaMap" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
res.resize(gradx.size());
|
||||
for (int i = 0; i < res.size(); i++)
|
||||
{
|
||||
res.at(i).x = gradx.at(i).x;
|
||||
res.at(i).y = gradx.at(i).y;
|
||||
if (fabs(gradx.at(i).val) < 1e-20 && gradz.at(i).val > 0)
|
||||
{
|
||||
res.at(i).val = 0.5*pi;
|
||||
}
|
||||
else if (fabs(gradx.at(i).val) < 1e-20 && gradz.at(i).val < 0)
|
||||
{
|
||||
res.at(i).val = -0.5*pi;
|
||||
}
|
||||
else res.at(i).val = atan(gradz.at(i).val/gradx.at(i).val);
|
||||
//转换为度
|
||||
res.at(i).val = res.at(i).val*180.0/pi;
|
||||
}
|
||||
|
||||
if (outRes(ofile)) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int linearmap::THDR(char* xfile,char* yfile,char* ofile,char* ran,char* inter,char* col)
|
||||
{
|
||||
gradx = readxyz(xfile,ran,inter,col);
|
||||
if (gradx.empty()) return -1;
|
||||
|
||||
grady = readxyz(yfile,ran,inter,col);
|
||||
if (grady.empty()) return -1;
|
||||
|
||||
if (gradx.size() != grady.size())
|
||||
{
|
||||
cout << BOLDRED << "error ==> " << RESET << "data amount does not match for thetaMap" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
res.resize(gradx.size());
|
||||
for (int i = 0; i < res.size(); i++)
|
||||
{
|
||||
res.at(i).x = gradx.at(i).x;
|
||||
res.at(i).y = gradx.at(i).y;
|
||||
res.at(i).val = sqrt(grady.at(i).val*grady.at(i).val + gradx.at(i).val*gradx.at(i).val);
|
||||
}
|
||||
|
||||
if (outRes(ofile)) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int linearmap::ASA(char* xfile,char* yfile,char* zfile,char* ofile,char* ran,char* inter,char* col)
|
||||
{
|
||||
gradx = readxyz(xfile,ran,inter,col);
|
||||
if (gradx.empty()) return -1;
|
||||
|
||||
grady = readxyz(yfile,ran,inter,col);
|
||||
if (grady.empty()) return -1;
|
||||
|
||||
gradz = readxyz(zfile,ran,inter,col);
|
||||
if (gradz.empty()) return -1;
|
||||
|
||||
if (gradx.size() != grady.size() || gradx.size() != gradz.size() || grady.size() != gradz.size())
|
||||
{
|
||||
cout << BOLDRED << "error ==> " << RESET << "data amount does not match for thetaMap" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
res.resize(gradx.size());
|
||||
for (int i = 0; i < res.size(); i++)
|
||||
{
|
||||
res.at(i).x = gradx.at(i).x;
|
||||
res.at(i).y = gradx.at(i).y;
|
||||
res.at(i).val = sqrt(grady.at(i).val*grady.at(i).val + gradx.at(i).val*gradx.at(i).val + gradz.at(i).val*gradz.at(i).val);
|
||||
}
|
||||
|
||||
if (outRes(ofile)) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int linearmap::TAHG(char* xfile,char* yfile,char* zfile,char* ofile,char* ran,char* inter,char* col)
|
||||
{
|
||||
gradx = readxyz(xfile,ran,inter,col);
|
||||
if (gradx.empty()) return -1;
|
||||
|
||||
grady = readxyz(yfile,ran,inter,col);
|
||||
if (grady.empty()) return -1;
|
||||
|
||||
gradz = readxyz(zfile,ran,inter,col);
|
||||
if (gradz.empty()) return -1;
|
||||
|
||||
if (gradx.size() != grady.size() || gradx.size() != gradz.size() || grady.size() != gradz.size())
|
||||
{
|
||||
cout << BOLDRED << "error ==> " << RESET << "data amount does not match for thetaMap" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
res.resize(gradx.size());
|
||||
for (int i = 0; i < res.size(); i++)
|
||||
{
|
||||
res.at(i).x = gradx.at(i).x;
|
||||
res.at(i).y = gradx.at(i).y;
|
||||
res.at(i).val = sqrt(gradz.at(i).val/sqrt(grady.at(i).val*grady.at(i).val + gradx.at(i).val*gradx.at(i).val));
|
||||
}
|
||||
|
||||
if (outRes(ofile)) return -1;
|
||||
return 0;
|
||||
}
|
129
archive/linearmap/main.cpp
Normal file
129
archive/linearmap/main.cpp
Normal file
@@ -0,0 +1,129 @@
|
||||
#include "linearmap.h"
|
||||
|
||||
void disp_help()
|
||||
{
|
||||
cout << "linearmap - v0.1 plot linear structures using gravity gradient data" << endl
|
||||
<< "Author: zhangyi.cugwuhan@gmail.com" << endl
|
||||
<< "usage: linearmap [-x<grad-x>] [-y<grad-y>] [-z<grad-z>] -o<output-file> -t<type> -r<xmin>/<xmax>/<ymin>/<ymax> -i<interval-x>/<interval-y> [-d<x-col>,<y-col>,<z-col>] [-h]" << endl
|
||||
<< "-x\tgravity gradient data in x-direction" << endl
|
||||
<< "-y\tgravity gradient data in y-direction" << endl
|
||||
<< "-z\tgravity gradient data in z-direction" << endl
|
||||
<< "-o\toutput filename" << endl
|
||||
<< "-t\tcalculation type, available types are shown as bellow" << endl
|
||||
<< "\tthetaMap: Need gravity gradient data in x and z directions" << endl
|
||||
<< "\tTHDR: Need gravity gradient data in x and y directions" << endl
|
||||
<< "\tASA: Need gravity gradient data in x, y and z directions" << endl
|
||||
<< "\tTAHG: Need gradient data of the THDR in x, y and z directions" << endl
|
||||
<< "-r\tdata range of the input data" << endl
|
||||
<< "-i\tdata interval of the input data" << endl
|
||||
<< "-d\tdata columns of the input data, the default is 0,1,2" << endl
|
||||
<< "-h\tshow this info" << endl;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
linearmap lm;
|
||||
char gradxName[1024] = "NULL";
|
||||
char gradyName[1024] = "NULL";
|
||||
char gradzName[1024] = "NULL";
|
||||
char outName[1024] = "untitled.xyz";
|
||||
char runType[1024] = "NULL";
|
||||
char rangeName[1024] = "NULL";
|
||||
char intervalName[1024] = "NULL";
|
||||
char cols[1024] = "0,1,2";
|
||||
|
||||
opterr = 0; //内置参数 若不为0则会在发生遭遇错误时输出一条信息到屏幕
|
||||
|
||||
int curr;
|
||||
/*循环拾取参数 最后一个参数为-1 需要变量的参数后跟一个冒号 可有可无参数跟两个冒号*/
|
||||
while((curr = getopt(argc,argv,"hx:y:z:o:t:r:i:d:")) != -1)
|
||||
{
|
||||
/*匹配命令*/
|
||||
switch (curr)
|
||||
{
|
||||
case 'h': //显示帮助信息
|
||||
disp_help();
|
||||
break;
|
||||
case 'x':
|
||||
if (1!=sscanf(optarg,"%s",gradxName))
|
||||
{
|
||||
cout << "error ==> wrong format of " << optarg << endl;
|
||||
}
|
||||
break;
|
||||
case 'y':
|
||||
if (1!=sscanf(optarg,"%s",gradyName))
|
||||
{
|
||||
cout << "error ==> wrong format of " << optarg << endl;
|
||||
}
|
||||
break;
|
||||
case 'z':
|
||||
if (1!=sscanf(optarg,"%s",gradzName))
|
||||
{
|
||||
cout << "error ==> wrong format of " << optarg << endl;
|
||||
}
|
||||
break;
|
||||
case 'o':
|
||||
if (1!=sscanf(optarg,"%s",outName))
|
||||
{
|
||||
cout << "error ==> wrong format of " << optarg << endl;
|
||||
}
|
||||
break;
|
||||
case 't':
|
||||
if (1!=sscanf(optarg,"%s",runType))
|
||||
{
|
||||
cout << "error ==> wrong format of " << optarg << endl;
|
||||
}
|
||||
break;
|
||||
case 'r':
|
||||
if (1!=sscanf(optarg,"%s",rangeName))
|
||||
{
|
||||
cout << "error ==> wrong format of " << optarg << endl;
|
||||
}
|
||||
break;
|
||||
case 'i':
|
||||
if (1!=sscanf(optarg,"%s",intervalName))
|
||||
{
|
||||
cout << "error ==> wrong format of " << optarg << endl;
|
||||
}
|
||||
break;
|
||||
case 'd':
|
||||
if (1!=sscanf(optarg,"%s",cols))
|
||||
{
|
||||
cout << "error ==> wrong format of " << optarg << endl;
|
||||
}
|
||||
break;
|
||||
case '?': //处理未定义或错误参数
|
||||
if (optopt == 'x' || optopt == 'y' || optopt == 'z' || optopt == 'o'
|
||||
|| optopt == 't' || optopt == 'r' || optopt == 'i' || optopt == 'd')
|
||||
{
|
||||
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
|
||||
return -1;
|
||||
}
|
||||
else if (isprint(optopt))
|
||||
{
|
||||
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (stderr,"Unknown option character `\\x%x'.\n",optopt);
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
if (!strcmp(runType,"thetaMap"))
|
||||
lm.thetaMap(gradxName,gradzName,outName,rangeName,intervalName,cols);
|
||||
else if (!strcmp(runType,"THDR"))
|
||||
lm.THDR(gradxName,gradyName,outName,rangeName,intervalName,cols);
|
||||
else if (!strcmp(runType,"ASA"))
|
||||
lm.ASA(gradxName,gradyName,gradzName,outName,rangeName,intervalName,cols);
|
||||
else if (!strcmp(runType,"TAHG"))
|
||||
lm.TAHG(gradxName,gradyName,gradzName,outName,rangeName,intervalName,cols);
|
||||
else
|
||||
cout << "unknown type: " << runType << endl << "use -h option to see help information" << endl;
|
||||
return 0;
|
||||
}
|
15
archive/linearmap/makefile
Normal file
15
archive/linearmap/makefile
Normal file
@@ -0,0 +1,15 @@
|
||||
CC = g++-9
|
||||
PROM = /usr/local/sbin/linearmap
|
||||
CFLAGS = -I.
|
||||
DEPS = $(shell find . -name "*.h")
|
||||
SRC = $(shell find . -name "*.cpp")
|
||||
OBJ = $(SRC:%.cpp=%.o)
|
||||
|
||||
$(PROM): $(OBJ)
|
||||
$(CC) -o $(PROM) $(OBJ) $(CFLAGS)
|
||||
|
||||
%.o:%.cpp $(DEPS)
|
||||
$(CC) -c $< -o $@ $(CFLAGS)
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJ)
|
Reference in New Issue
Block a user