initial upload
This commit is contained in:
104
archive/mshinterpolate/main.cpp
Normal file
104
archive/mshinterpolate/main.cpp
Normal file
@@ -0,0 +1,104 @@
|
||||
#include "mshInterpolate.h"
|
||||
|
||||
void disp_help()
|
||||
{
|
||||
cout << "mshInterpolate - v0.1 msh file interpolation" << endl
|
||||
<< "Author: zhangyi.cugwuhan@gmail.com" << endl << endl
|
||||
<< "usage: mshInterpolate -i<input-msh> -d<data-name> -l<list-file> [-t<type>] [-s<refr>/<refR>] [-h] > out-file" << endl
|
||||
<< "-i\tinput Gmsh file." << endl
|
||||
<< "-d\tnode data name for interpolation." << endl
|
||||
<< "-l\tlist table generated by the stt program" << endl
|
||||
<< "-s\treference system, this must be set for topography interpolation" << endl
|
||||
<< "-t\tinterpolation type, 'linear' for linear interpolation (default) and 'topo' for topography" << endl
|
||||
<< "-h\tshow this info" << endl;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
char infilename[1024] = "NULL";
|
||||
char nodename[1024] = "NULL";
|
||||
char listname[1024] = "NULL";
|
||||
char referSystem[1024] = "NULL";
|
||||
char calType[1024] = "linear";
|
||||
|
||||
opterr = 0; //内置参数 若不为0则会在发生遭遇错误时输出一条信息到屏幕
|
||||
|
||||
int curr;
|
||||
/*循环拾取参数 最后一个参数为-1 需要变量的参数后跟一个冒号 可有可无参数跟两个冒号*/
|
||||
while((curr = getopt(argc,argv,"hi:d:l:s:t:")) != -1)
|
||||
{
|
||||
/*匹配命令*/
|
||||
switch (curr)
|
||||
{
|
||||
case 'h': //显示帮助信息
|
||||
disp_help();
|
||||
break;
|
||||
case 'i':
|
||||
if (1!=sscanf(optarg,"%[^\0]",infilename))
|
||||
{
|
||||
cout << "error ==> wrong format of " << optarg << endl;
|
||||
}
|
||||
break;
|
||||
case 'd':
|
||||
if (1!=sscanf(optarg,"%[^\0]",nodename))
|
||||
{
|
||||
cout << "error ==> wrong format of " << optarg << endl;
|
||||
}
|
||||
break;
|
||||
case 'l':
|
||||
if (1!=sscanf(optarg,"%[^\0]",listname))
|
||||
{
|
||||
cout << "error ==> wrong format of " << optarg << endl;
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
if (1!=sscanf(optarg,"%[^\0]",referSystem))
|
||||
{
|
||||
cout << "error ==> wrong format of " << optarg << endl;
|
||||
}
|
||||
break;
|
||||
case 't':
|
||||
if (1!=sscanf(optarg,"%[^\0]",calType))
|
||||
{
|
||||
cout << "error ==> wrong format of " << optarg << endl;
|
||||
}
|
||||
break;
|
||||
case '?': //处理未定义或错误参数
|
||||
if (optopt == 'i' || optopt == 'd' || optopt == 'l' || optopt == 's' || optopt == 't')
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
mshInterpolate mi;
|
||||
if (mi.readMsh(infilename,nodename)) return -1;
|
||||
if (mi.readList(listname)) return -1;
|
||||
if (!strcmp(calType,"linear"))
|
||||
mi.interpolate_linear();
|
||||
else if (!strcmp(calType,"topo"))
|
||||
{
|
||||
if (mi.initRef(referSystem)) return -1;
|
||||
mi.interpolate_topo();
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "error ==> wrong interpolation type: " << calType << endl;
|
||||
}
|
||||
mi.outList();
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user