#include "xyz2shc.h" void disp_help() { cout << "xyz2shc - v0.1 calculate table data to spherical harmonic coefficients" << endl << "Author: zhangyi.cugwuhan@gmail.com" << endl << endl << "usage: xyz2shc -i+d,,[,] -o -f [-d] [-t] [-h]" << endl << "-i\tinput table name, use +d to specify the input columns." << endl << "-o\toutput shc filename." << endl << "-f\tspherical harmonic coefficients order." << endl << "-d\testimated data accuracy. default value is 1e-3." << endl << "-t\titeration times. default value is 300." << endl << "-h\tshow this info" << endl; } int main(int argc, char* argv[]){ char infilename[1024] = "NULL"; char outfilename[1024] = "NULL"; int shcorder = 0, itertimes = 300; double datadev = 1e-3; opterr = 0; //内置参数 若不为0则会在发生遭遇错误时输出一条信息到屏幕 int curr; /*循环拾取参数 最后一个参数为-1 需要变量的参数后跟一个冒号 可有可无参数跟两个冒号*/ while((curr = getopt(argc,argv,"hi:o:f:d:t:")) != -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 'f': if (1!=sscanf(optarg,"%d",&shcorder)) { cout << "error ==> wrong format of " << optarg << endl; } break; case 'd': if (1!=sscanf(optarg,"%lf",&datadev)) { cout << "error ==> wrong format of " << optarg << endl; } break; case 't': if (1!=sscanf(optarg,"%d",&itertimes)) { cout << "error ==> wrong format of " << optarg << endl; } break; case '?': //处理未定义或错误参数 if (optopt == 'i' || optopt == 'o' || optopt == 'f' || optopt == 'd' || 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(); } } XYZ2SHC instance; if (instance.ReadXyz(infilename,datadev)) return 0; if (instance.InitShc(shcorder)) return 0; instance.CalCKernel(); instance.CalWd(); instance.CalPartB(); instance.Optimize_CG(); if (instance.OutShc(outfilename)) return 0; return 0; }