91 lines
2.8 KiB
C++
91 lines
2.8 KiB
C++
#include "sph2random.h"
|
|
|
|
void disp_help()
|
|
{
|
|
cout << "sph2random - v0.1 data interpolation under the spherical coordinates" << endl
|
|
<< "Author: zhangyi.cugwuhan@gmail.com" << endl << endl
|
|
<< "usage: sph2random -t<grid-table>[+d<x-col>,<y-col>,<val-col>] -l<random-loc>[+d<x-col>,<y-col>[,<z-col>]] -i<dlon>/<dlat> -c<start-corner> [-s] [-h] > output-file" << endl
|
|
<< "-t\tinput grid 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
|
|
<< "-l\tinput spherical locations, 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
|
|
<< "-i\tdata intervals" << endl
|
|
<< "-c\tstart corner of the grid data, 'leftTopo' (default) or 'leftDown'" << endl
|
|
<< "-s\tconvert input coordinates to spherical coordinates" << endl
|
|
<< "-h\tshow this info" << endl;
|
|
}
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
char infilename[1024] = "NULL";
|
|
char infileloc[1024] = "NULL";
|
|
char interval[1024] = "NULL";
|
|
char startPoint[1024] = "leftTopo";
|
|
char use_sc[1024] = "no";
|
|
|
|
opterr = 0; //内置参数 若不为0则会在发生遭遇错误时输出一条信息到屏幕
|
|
|
|
int curr;
|
|
/*循环拾取参数 最后一个参数为-1 需要变量的参数后跟一个冒号 可有可无参数跟两个冒号*/
|
|
while((curr = getopt(argc,argv,"hst:l:i:c:")) != -1)
|
|
{
|
|
/*匹配命令*/
|
|
switch (curr)
|
|
{
|
|
case 'h': //显示帮助信息
|
|
disp_help();
|
|
break;
|
|
case 's':
|
|
strcpy(use_sc,"yes");
|
|
break;
|
|
case 't':
|
|
if (1!=sscanf(optarg,"%[^\0]",infilename))
|
|
{
|
|
cout << "error ==> wrong format of " << optarg << endl;
|
|
}
|
|
break;
|
|
case 'l':
|
|
if (1!=sscanf(optarg,"%[^\0]",infileloc))
|
|
{
|
|
cout << "error ==> wrong format of " << optarg << endl;
|
|
}
|
|
break;
|
|
case 'i':
|
|
if (1!=sscanf(optarg,"%[^\0]",interval))
|
|
{
|
|
cout << "error ==> wrong format of " << optarg << endl;
|
|
}
|
|
break;
|
|
case 'c':
|
|
if (1!=sscanf(optarg,"%[^\0]",startPoint))
|
|
{
|
|
cout << "error ==> wrong format of " << optarg << endl;
|
|
}
|
|
break;
|
|
case '?': //处理未定义或错误参数
|
|
if (optopt == 'i' || optopt == 'l')
|
|
{
|
|
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();
|
|
}
|
|
}
|
|
|
|
sphInterpolate si;
|
|
if (si.readGrid(infilename,interval,use_sc)) return -1;
|
|
if (si.readRandom(infileloc,use_sc)) return -1;
|
|
si.interpolate(startPoint);
|
|
si.outRes();
|
|
return 0;
|
|
} |