129 lines
4.0 KiB
C++
129 lines
4.0 KiB
C++
|
#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;
|
||
|
}
|