87 lines
3.0 KiB
C++
87 lines
3.0 KiB
C++
|
#include "trackLine.h"
|
||
|
|
||
|
void disp_help()
|
||
|
{
|
||
|
cout << "trackline - v1.1 extract data along a line from a group of 2-D data points" << endl
|
||
|
<< "Author: zhangyi.cugwuhan@gmail.com" << endl << endl
|
||
|
<< "usage: trackline -i<input-file>[+d<x-col>,<y-col>,<z-col>] -o<output-file> \n\t -l<input-file>[+d<x-col>,<y-col>]|<p1-x>/<p1-y>/<p2-x>/<p2-y>/<spacing> \n\t [-b<grid-x>/<grid-y>] [-h]" << endl
|
||
|
<< "\t-i\tinput data table. a +d option could be attached to the filename to select data columns of the input data, the default is 0,1,2. Note that any line starts with '#' will be skipped" << endl
|
||
|
<< "\t-o\toutput data table, every line contains a x-coordinate of a point on the line and 2-D coordinates of the point, and the point's value" << endl
|
||
|
<< "\t-l\tline parameters, you can either specify where the line starts and ends, plus interval of data points on the line. Or you can give point locations via a file, a +d option could be attached to the filename to select data columns of the input data, the default is 0,1. Note that any line starts with '#' will be skipped" << endl
|
||
|
<< "\t-b\tgriding parameters, the program will automatically using the mean area-size of input points to estimate a griding size if no -b option has been set" << endl
|
||
|
<< "\t-h\tshow this info" << endl;
|
||
|
}
|
||
|
|
||
|
int main(int argc, char** argv)
|
||
|
{
|
||
|
trackLine tl;
|
||
|
char infilename[1024] = "NULL";
|
||
|
char outfilename[1024] = "NULL";
|
||
|
char boxpara[1024] = "NULL";
|
||
|
char linepara[1024] = "NULL";
|
||
|
|
||
|
opterr = 0; //内置参数 若不为0则会在发生遭遇错误时输出一条信息到屏幕
|
||
|
|
||
|
int curr;
|
||
|
/*循环拾取参数 最后一个参数为-1 需要变量的参数后跟一个冒号 可有可无参数跟两个冒号*/
|
||
|
while((curr = getopt(argc,argv,"hi:o:l:b:")) != -1)
|
||
|
{
|
||
|
/*匹配命令*/
|
||
|
switch (curr)
|
||
|
{
|
||
|
case 'h': //显示帮助信息
|
||
|
disp_help();
|
||
|
break;
|
||
|
case 'i':
|
||
|
if (1!=sscanf(optarg,"%s",infilename))
|
||
|
{
|
||
|
cout << "error ==> wrong format of " << optarg << endl;
|
||
|
}
|
||
|
break;
|
||
|
case 'o':
|
||
|
if (1!=sscanf(optarg,"%s",outfilename))
|
||
|
{
|
||
|
cout << "error ==> wrong format of " << optarg << endl;
|
||
|
}
|
||
|
break;
|
||
|
case 'l':
|
||
|
if (1!=sscanf(optarg,"%s",linepara))
|
||
|
{
|
||
|
cout << "error ==> wrong format of " << optarg << endl;
|
||
|
}
|
||
|
break;
|
||
|
case 'b':
|
||
|
if (1!=sscanf(optarg,"%s",boxpara))
|
||
|
{
|
||
|
cout << "error ==> wrong format of " << optarg << endl;
|
||
|
}
|
||
|
break;
|
||
|
case '?': //处理未定义或错误参数
|
||
|
if (optopt == 'i' || optopt == 'o' || optopt == 'l' || optopt == 'b')
|
||
|
{
|
||
|
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 (tl.getInputNode(infilename)) return 0;
|
||
|
tl.initBox(boxpara);
|
||
|
if (tl.initLine(linepara)) return 0;
|
||
|
tl.interLine();
|
||
|
tl.outLine(outfilename);
|
||
|
return 0;
|
||
|
}
|