PageRenderTime 46ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/Common/CommandLine.cpp

https://bitbucket.org/lge/gmsh
C++ | 826 lines | 796 code | 15 blank | 15 comment | 308 complexity | 8d18c362b367536d0eb7e94cf0ccb286 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, BSD-3-Clause
  1. // Gmsh - Copyright (C) 1997-2012 C. Geuzaine, J.-F. Remacle
  2. //
  3. // See the LICENSE.txt file for license information. Please report all
  4. // bugs and problems to <gmsh@geuz.org>.
  5. #include <string>
  6. #include <string.h>
  7. #include <stdlib.h>
  8. #include "GmshConfig.h"
  9. #include "GmshDefines.h"
  10. #include "GmshVersion.h"
  11. #include "GmshMessage.h"
  12. #include "OpenFile.h"
  13. #include "CommandLine.h"
  14. #include "Context.h"
  15. #include "Options.h"
  16. #include "GModel.h"
  17. #include "CreateFile.h"
  18. #include "OS.h"
  19. #if defined(HAVE_FLTK)
  20. #include <FL/Fl.H>
  21. #if (FL_MAJOR_VERSION == 1) && (FL_MINOR_VERSION >= 3)
  22. // OK
  23. #else
  24. #error "Gmsh requires FLTK >= 1.3"
  25. #endif
  26. #endif
  27. #if defined(HAVE_POST)
  28. #include "PView.h"
  29. #endif
  30. int GetGmshMajorVersion(){ return GMSH_MAJOR_VERSION; }
  31. int GetGmshMinorVersion(){ return GMSH_MINOR_VERSION; }
  32. int GetGmshPatchVersion(){ return GMSH_PATCH_VERSION; }
  33. const char *GetGmshExtraVersion(){ return GMSH_EXTRA_VERSION; }
  34. const char *GetGmshVersion(){ return GMSH_VERSION; }
  35. const char *GetGmshBuildDate(){ return GMSH_DATE; }
  36. const char *GetGmshBuildHost(){ return GMSH_HOST; }
  37. const char *GetGmshPackager(){ return GMSH_PACKAGER; }
  38. const char *GetGmshBuildOS(){ return GMSH_OS; }
  39. const char *GetGmshShortLicense(){ return GMSH_SHORT_LICENSE; }
  40. const char *GetGmshBuildOptions(){ return GMSH_CONFIG_OPTIONS; }
  41. void PrintUsage(const char *name)
  42. {
  43. // If you make changes in this routine, please also change the texinfo
  44. // documentation (doc/texinfo/gmsh.texi) and the man page (doc/gmsh.1)
  45. Msg::Direct("Usage: %s [options] [files]", name);
  46. Msg::Direct("Geometry options:");
  47. Msg::Direct(" -0 Output unrolled geometry, then exit");
  48. Msg::Direct(" -tol float Set geometrical tolerance");
  49. Msg::Direct(" -match Match geometries and meshes");
  50. Msg::Direct("Mesh options:");
  51. Msg::Direct(" -1, -2, -3 Perform 1D, 2D or 3D mesh generation, then exit");
  52. Msg::Direct(" -format string Select output mesh format (auto (default), msh, msh1, msh2,");
  53. Msg::Direct(" unv, vrml, ply2, stl, mesh, bdf, cgns, p3d, diff, med, ...)");
  54. Msg::Direct(" -refine Perform uniform mesh refinement, then exit");
  55. Msg::Direct(" -part int Partition after batch mesh generation");
  56. Msg::Direct(" -partWeight <tri|quad|tet|prism|hex> int");
  57. Msg::Direct(" Weight of a triangle/quad/etc. during partitioning");
  58. Msg::Direct(" -renumber Renumber the mesh elements after batch mesh generation");
  59. Msg::Direct(" -saveall Save all elements (discard physical group definitions)");
  60. Msg::Direct(" -o file Specify output file name");
  61. Msg::Direct(" -bin Use binary format when available");
  62. Msg::Direct(" -parametric Save vertices with their parametric coordinates");
  63. Msg::Direct(" -numsubedges Set the number of subdivisions when displaying high order elements");
  64. Msg::Direct(" -algo string Select mesh algorithm (meshadapt, del2d, front2d, delquad, ");
  65. Msg::Direct(" del3d, front3d, mmg3d)");
  66. Msg::Direct(" -smooth int Set number of mesh smoothing steps");
  67. Msg::Direct(" -order int Set mesh order (1, ..., 5)");
  68. Msg::Direct(" -hoOptimize Optimize high order meshes");
  69. Msg::Direct(" -hoMindisto float Minimum quality for high-order elements before optimization (0.0->1.0)");
  70. Msg::Direct(" -hoNLayers int Number of high order element layers to optimize");
  71. Msg::Direct(" -hoElasticity float Poisson ration for the elasticity analogy (-1.0 < nu < 0.5)");
  72. Msg::Direct(" -optimize[_netgen] Optimize quality of tetrahedral elements");
  73. Msg::Direct(" -optimize_lloyd Optimize 2D meshes using Lloyd algorithm");
  74. Msg::Direct(" -clscale float Set global mesh element size scaling factor");
  75. Msg::Direct(" -clmin float Set minimum mesh element size");
  76. Msg::Direct(" -clmax float Set maximum mesh element size");
  77. Msg::Direct(" -anisoMax float Set maximum anisotropy (only used in bamg for now)");
  78. Msg::Direct(" -smoothRatio float Set smoothing ration between mesh sizes at nodes of a same edge");
  79. Msg::Direct(" (only used in bamg)");
  80. Msg::Direct(" -clcurv Automatically compute element sizes from curvatures");
  81. Msg::Direct(" -epslc1d Set the accuracy of the evaluation of the LCFIELD for 1D mesh");
  82. Msg::Direct(" -swapangle Set the threshold angle (in degree) between two adjacent faces");
  83. Msg::Direct(" below which a swap is allowed");
  84. Msg::Direct(" -rand float Set random perturbation factor");
  85. Msg::Direct(" -bgm file Load background mesh from file");
  86. Msg::Direct(" -check Perform various consistency checks on mesh");
  87. Msg::Direct(" -mpass int Do several passes on the mesh for complex backround fields");
  88. Msg::Direct(" -ignorePartBound Ignore partitions boundaries");
  89. #if defined(HAVE_FLTK)
  90. Msg::Direct("Post-processing options:");
  91. Msg::Direct(" -link int Select link mode between views (0, 1, 2, 3, 4)");
  92. Msg::Direct(" -combine Combine views having identical names into multi-time-step views");
  93. Msg::Direct("Display options:");
  94. Msg::Direct(" -n Hide all meshes and post-processing views on startup");
  95. Msg::Direct(" -nodb Disable double buffering");
  96. Msg::Direct(" -fontsize int Specify the font size for the GUI");
  97. Msg::Direct(" -theme string Specify FLTK GUI theme");
  98. Msg::Direct(" -display string Specify display");
  99. #endif
  100. Msg::Direct("Other options:");
  101. Msg::Direct(" - Parse input files, then exit");
  102. #if defined(HAVE_FLTK)
  103. Msg::Direct(" -a, -g, -m, -s, -p Start in automatic, geometry, mesh, solver or post-processing mode");
  104. #endif
  105. Msg::Direct(" -pid Print process id on stdout");
  106. Msg::Direct(" -listen Always listen to incoming connection requests");
  107. Msg::Direct(" -watch pattern Pattern of files to merge as they become available");
  108. Msg::Direct(" -v int Set verbosity level");
  109. Msg::Direct(" -nopopup Don't popup dialog windows in scripts");
  110. Msg::Direct(" -string \"string\" Parse option string at startup");
  111. Msg::Direct(" -option file Parse option file at startup");
  112. Msg::Direct(" -convert files Convert files into latest binary formats, then exit");
  113. Msg::Direct(" -vmsh float Select msh file version");
  114. Msg::Direct(" -version Show version number");
  115. Msg::Direct(" -info Show detailed version information");
  116. Msg::Direct(" -help Show this message");
  117. }
  118. void GetOptions(int argc, char *argv[])
  119. {
  120. // print messages on terminal
  121. int terminal = CTX::instance()->terminal;
  122. CTX::instance()->terminal = 1;
  123. #if defined(HAVE_PARSER)
  124. if(argc && argv){
  125. // parse session and option file (if argc/argv is not provided skip this
  126. // step: this is usually what is expected when using Gmsh as a library)
  127. ParseFile(CTX::instance()->homeDir + CTX::instance()->sessionFileName, true);
  128. ParseFile(CTX::instance()->homeDir + CTX::instance()->optionsFileName, true);
  129. }
  130. #endif
  131. if(argc) Msg::SetExecutableName(argv[0]);
  132. // get command line options
  133. int i = 1;
  134. while(i < argc) {
  135. if(argv[i][0] == '-') {
  136. if(!strcmp(argv[i] + 1, "")) {
  137. CTX::instance()->batch = -99;
  138. i++;
  139. }
  140. else if(!strcmp(argv[i] + 1, "onelab")) {
  141. i++;
  142. if(argv[i] && argv[i + 1] && argv[i + 1][0] != '-'){
  143. Msg::InitializeOnelab(argv[i], argv[i + 1]);
  144. i += 2;
  145. }
  146. else if(argv[i]){
  147. Msg::InitializeOnelab(argv[i]);
  148. i += 1;
  149. }
  150. else
  151. Msg::Fatal("Missing client name and/or address of OneLab server");
  152. }
  153. else if(!strcmp(argv[i] + 1, "lol")) {
  154. i++;
  155. if(argv[i] && argv[i + 1] && argv[i + 1][0] != '-'){
  156. Msg::LoadOnelabClient(argv[i], argv[i + 1]);
  157. i += 2;
  158. }
  159. else
  160. Msg::Fatal("Missing client name and/or address of OneLab server");
  161. }
  162. else if(!strcmp(argv[i] + 1, "socket")) {
  163. i++;
  164. if(argv[i])
  165. Msg::InitializeOnelab("GmshRemote", argv[i++]);
  166. else
  167. Msg::Fatal("Missing string");
  168. CTX::instance()->batch = -3;
  169. }
  170. else if(!strcmp(argv[i] + 1, "check")) {
  171. CTX::instance()->batch = -2;
  172. i++;
  173. }
  174. else if(!strcmp(argv[i] + 1, "0")) {
  175. CTX::instance()->batch = -1;
  176. i++;
  177. }
  178. else if(!strcmp(argv[i] + 1, "1")) {
  179. CTX::instance()->batch = 1;
  180. i++;
  181. }
  182. else if(!strcmp(argv[i] + 1, "2")) {
  183. CTX::instance()->batch = 2;
  184. i++;
  185. }
  186. else if(!strcmp(argv[i] + 1, "3")) {
  187. CTX::instance()->batch = 3;
  188. i++;
  189. }
  190. else if(!strcmp(argv[i] + 1, "4")) {
  191. CTX::instance()->batch = 4;
  192. i++;
  193. }
  194. else if(!strcmp(argv[i] + 1, "refine")) {
  195. CTX::instance()->batch = 5;
  196. i++;
  197. }
  198. else if(!strcmp(argv[i] + 1, "renumber")) {
  199. CTX::instance()->batchAfterMesh = 1;
  200. CTX::instance()->partitionOptions.renumber = 1;
  201. i++;
  202. }
  203. else if(!strcmp(argv[i] + 1, "part")) {
  204. i++;
  205. if(argv[i]){
  206. CTX::instance()->batchAfterMesh = 1 ;
  207. opt_mesh_partition_num(0, GMSH_SET, atoi(argv[i++]));
  208. }
  209. else
  210. Msg::Fatal("Missing number");
  211. }
  212. else if (!strcmp(argv[i] + 1,"partWeight")) {
  213. i++;
  214. bool check = true;
  215. opt_mesh_partition_partitioner(0, GMSH_SET, 2); // Metis partitioner
  216. opt_mesh_partition_metis_algorithm(0, GMSH_SET, 3); // partGraphKWay w/ weights
  217. while (check) {
  218. if (argv[i]) {
  219. if (!strcmp(argv[i],"triangle")) {
  220. i++;
  221. opt_mesh_partition_tri_weight(0,GMSH_SET,atoi(argv[i]));
  222. }
  223. else if (!strcmp(argv[i],"quad")) {
  224. i++;
  225. opt_mesh_partition_qua_weight(0,GMSH_SET,atoi(argv[i]));
  226. }
  227. else if (!strcmp(argv[i],"tet")) {
  228. i++;
  229. opt_mesh_partition_tet_weight(0,GMSH_SET,atoi(argv[i]));
  230. }
  231. else if (!strcmp(argv[i],"prism")) {
  232. i++;
  233. opt_mesh_partition_pri_weight(0,GMSH_SET,atoi(argv[i]));
  234. }
  235. else if (!strcmp(argv[i],"pyramid")) {
  236. i++;
  237. opt_mesh_partition_pyr_weight(0,GMSH_SET,atoi(argv[i]));
  238. }
  239. else if (!strcmp(argv[i],"hex")) {
  240. i++;
  241. opt_mesh_partition_hex_weight(0,GMSH_SET,atoi(argv[i]));
  242. }
  243. else check = false;
  244. i++;
  245. }
  246. else check = false;
  247. }
  248. }
  249. else if(!strcmp(argv[i] + 1, "new")) {
  250. CTX::instance()->files.push_back("-new");
  251. i++;
  252. }
  253. else if(!strcmp(argv[i] + 1, "pid")) {
  254. fprintf(stdout, "%d\n", GetProcessId());
  255. fflush(stdout);
  256. i++;
  257. }
  258. else if(!strcmp(argv[i] + 1, "a")) {
  259. CTX::instance()->initialContext = 0;
  260. i++;
  261. }
  262. else if(!strcmp(argv[i] + 1, "g")) {
  263. CTX::instance()->initialContext = 1;
  264. i++;
  265. }
  266. else if(!strcmp(argv[i] + 1, "m")) {
  267. CTX::instance()->initialContext = 2;
  268. i++;
  269. }
  270. else if(!strcmp(argv[i] + 1, "s")) {
  271. CTX::instance()->initialContext = 3;
  272. i++;
  273. }
  274. else if(!strcmp(argv[i] + 1, "p")) {
  275. CTX::instance()->initialContext = 4;
  276. i++;
  277. }
  278. else if(!strcmp(argv[i] + 1, "saveall")) {
  279. CTX::instance()->mesh.saveAll = 1;
  280. i++;
  281. }
  282. else if(!strcmp(argv[i] + 1, "switch_tags")) {
  283. CTX::instance()->mesh.switchElementTags = 1;
  284. i++;
  285. }
  286. else if(!strcmp(argv[i] + 1, "optimize")) {
  287. CTX::instance()->mesh.optimize = 1;
  288. i++;
  289. }
  290. else if(!strcmp(argv[i] + 1, "bunin")) {
  291. i++;
  292. if(argv[i])
  293. CTX::instance()->mesh.bunin = atoi(argv[i++]);
  294. else
  295. Msg::Fatal("Missing cavity size in bunin optimization");
  296. }
  297. else if(!strcmp(argv[i] + 1, "optimize_netgen")) {
  298. CTX::instance()->mesh.optimizeNetgen = 1;
  299. i++;
  300. }
  301. else if(!strcmp(argv[i] + 1, "hoOptimize")) {
  302. i++;
  303. opt_mesh_smooth_internal_edges(0, GMSH_SET, 1);
  304. }
  305. else if(!strcmp(argv[i] + 1, "hoMindisto")) {
  306. i++;
  307. if(argv[i])
  308. opt_mesh_ho_mindisto(0, GMSH_SET, atof(argv[i++]));
  309. else
  310. Msg::Fatal("Missing number");
  311. }
  312. else if(!strcmp(argv[i] + 1, "hoElasticity")) {
  313. i++;
  314. if(argv[i])
  315. opt_mesh_ho_poisson(0, GMSH_SET, atof(argv[i++]));
  316. else
  317. Msg::Fatal("Missing number");
  318. }
  319. else if(!strcmp(argv[i] + 1, "hoNlayers")) {
  320. i++;
  321. if(argv[i])
  322. opt_mesh_ho_nlayers(0, GMSH_SET, atoi(argv[i++]));
  323. else
  324. Msg::Fatal("Missing number");
  325. }
  326. else if(!strcmp(argv[i] + 1, "optimize_lloyd")) {
  327. i++;
  328. if(argv[i])
  329. CTX::instance()->mesh.optimizeLloyd = atoi(argv[i++]);
  330. else
  331. Msg::Fatal("Missing number of lloyd iterations");
  332. }
  333. else if(!strcmp(argv[i] + 1, "nopopup")) {
  334. CTX::instance()->noPopup = 1;
  335. i++;
  336. }
  337. else if(!strcmp(argv[i] + 1, "watch")) {
  338. i++;
  339. if(argv[i]){
  340. std::string tmp = argv[i++];
  341. if(tmp.size() > 2 && tmp[0] == '"' && tmp[tmp.size() - 1] == '"')
  342. CTX::instance()->watchFilePattern = tmp.substr(1, tmp.size() - 2);
  343. else
  344. CTX::instance()->watchFilePattern = tmp;
  345. }
  346. else
  347. Msg::Fatal("Missing string");
  348. }
  349. else if(!strcmp(argv[i] + 1, "string")) {
  350. i++;
  351. if(argv[i])
  352. ParseString(argv[i++]);
  353. else
  354. Msg::Fatal("Missing string");
  355. }
  356. else if(!strcmp(argv[i] + 1, "option")) {
  357. i++;
  358. if(argv[i])
  359. ParseFile(argv[i++], true);
  360. else
  361. Msg::Fatal("Missing file name");
  362. }
  363. else if(!strcmp(argv[i] + 1, "o")) {
  364. i++;
  365. if(argv[i])
  366. CTX::instance()->outputFileName = argv[i++];
  367. else
  368. Msg::Fatal("Missing file name");
  369. }
  370. else if(!strcmp(argv[i] + 1, "anisoMax")) {
  371. i++;
  372. if(argv[i])
  373. CTX::instance()->mesh.anisoMax = atof(argv[i++]);
  374. else
  375. Msg::Fatal("Missing anisotropy ratio");
  376. }
  377. else if(!strcmp(argv[i] + 1, "smoothRatio")) {
  378. i++;
  379. if(argv[i])
  380. CTX::instance()->mesh.smoothRatio = atof(argv[i++]);
  381. else
  382. Msg::Fatal("Missing smooth ratio");
  383. }
  384. else if(!strcmp(argv[i] + 1, "bgm")) {
  385. i++;
  386. if(argv[i])
  387. CTX::instance()->bgmFileName = argv[i++];
  388. else
  389. Msg::Fatal("Missing file name");
  390. }
  391. else if(!strcmp(argv[i] + 1, "nw")) {
  392. i++;
  393. if(argv[i])
  394. CTX::instance()->numWindows = atoi(argv[i++]);
  395. else
  396. Msg::Fatal("Missing number");
  397. }
  398. else if(!strcmp(argv[i] + 1, "nt")) {
  399. i++;
  400. if(argv[i])
  401. CTX::instance()->numTiles = atoi(argv[i++]);
  402. else
  403. Msg::Fatal("Missing number");
  404. }
  405. else if(!strcmp(argv[i] + 1, "vmsh")) {
  406. i++;
  407. if(argv[i]){
  408. CTX::instance()->mesh.mshFileVersion = atof(argv[i++]);
  409. }
  410. else
  411. Msg::Fatal("Missing number");
  412. }
  413. else if(!strcmp(argv[i] + 1, "convert")) {
  414. i++;
  415. CTX::instance()->batch = 1;
  416. while(i < argc) {
  417. std::string fileName = std::string(argv[i]) + "_new";
  418. #if defined(HAVE_POST)
  419. unsigned int n = PView::list.size();
  420. #endif
  421. OpenProject(argv[i]);
  422. #if defined(HAVE_POST)
  423. // convert post-processing views to latest binary format
  424. for(unsigned int j = n; j < PView::list.size(); j++)
  425. PView::list[j]->write(fileName, 1, (j == n) ? false : true);
  426. #endif
  427. // convert mesh to latest binary format
  428. if(GModel::current()->getMeshStatus() > 0){
  429. CTX::instance()->mesh.mshFileVersion = 2.0;
  430. CTX::instance()->mesh.binary = 1;
  431. CreateOutputFile(fileName, FORMAT_MSH);
  432. }
  433. i++;
  434. }
  435. Msg::Exit(0);
  436. }
  437. else if(!strcmp(argv[i] + 1, "tol")) {
  438. i++;
  439. if(argv[i])
  440. CTX::instance()->geom.tolerance = atof(argv[i++]);
  441. else
  442. Msg::Fatal("Missing number");
  443. }
  444. else if(!strcmp(argv[i] + 1, "match")) {
  445. i++;
  446. CTX::instance()->geom.matchGeomAndMesh = 1;
  447. }
  448. else if(!strcmp(argv[i] + 1, "scale")) {
  449. i++;
  450. if(argv[i])
  451. CTX::instance()->geom.scalingFactor = atof(argv[i++]);
  452. else
  453. Msg::Fatal("Missing number");
  454. }
  455. else if(!strcmp(argv[i] + 1, "meshscale")) {
  456. i++;
  457. if(argv[i])
  458. CTX::instance()->mesh.scalingFactor = atof(argv[i++]);
  459. else
  460. Msg::Fatal("Missing number");
  461. }
  462. else if(!strcmp(argv[i] + 1, "rand")) {
  463. i++;
  464. if(argv[i])
  465. CTX::instance()->mesh.randFactor = atof(argv[i++]);
  466. else
  467. Msg::Fatal("Missing number");
  468. }
  469. else if(!strcmp(argv[i] + 1, "clscale")) {
  470. i++;
  471. if(argv[i]) {
  472. CTX::instance()->mesh.lcFactor = atof(argv[i++]);
  473. if(CTX::instance()->mesh.lcFactor <= 0.0)
  474. Msg::Fatal("Mesh element size factor must be > 0");
  475. }
  476. else
  477. Msg::Fatal("Missing number");
  478. }
  479. else if(!strcmp(argv[i] + 1, "clmin")) {
  480. i++;
  481. if(argv[i]) {
  482. CTX::instance()->mesh.lcMin = atof(argv[i++]);
  483. if(CTX::instance()->mesh.lcMin <= 0.0)
  484. Msg::Fatal("Minimum length size must be > 0");
  485. }
  486. else
  487. Msg::Fatal("Missing number");
  488. }
  489. else if(!strcmp(argv[i] + 1, "clmax")) {
  490. i++;
  491. if(argv[i]) {
  492. CTX::instance()->mesh.lcMax = atof(argv[i++]);
  493. if(CTX::instance()->mesh.lcMax <= 0.0)
  494. Msg::Fatal("Maximum length size must be > 0");
  495. }
  496. else
  497. Msg::Fatal("Missing number");
  498. }
  499. else if(!strcmp(argv[i] + 1, "mpass")) {
  500. i++;
  501. if(argv[i]) {
  502. CTX::instance()->mesh.multiplePasses = atoi(argv[i++]);
  503. if(CTX::instance()->mesh.multiplePasses <= 0)
  504. Msg::Fatal("Number of Mesh Passes must be > 0");
  505. }
  506. else
  507. Msg::Fatal("Missing number");
  508. }
  509. else if(!strcmp(argv[i] + 1, "ignorePartBound")) {
  510. i++;
  511. opt_mesh_ignore_part_bound(0, GMSH_SET, 1);
  512. }
  513. else if(!strcmp(argv[i] + 1, "edgelmin")) {
  514. i++;
  515. if(argv[i]) {
  516. CTX::instance()->mesh.toleranceEdgeLength = atof(argv[i++]);
  517. if(CTX::instance()->mesh.toleranceEdgeLength <= 0.0)
  518. Msg::Fatal("Tolerance for model edge length must be > 0 (here %g)",
  519. CTX::instance()->mesh.toleranceEdgeLength);
  520. }
  521. else
  522. Msg::Fatal("Missing number");
  523. }
  524. else if(!strcmp(argv[i] + 1, "epslc1d")) {
  525. i++;
  526. if(argv[i]) {
  527. CTX::instance()->mesh.lcIntegrationPrecision = atof(argv[i++]);
  528. if(CTX::instance()->mesh.lcIntegrationPrecision <= 0.0)
  529. Msg::Fatal("Integration accuracy must be > 0");
  530. }
  531. else
  532. Msg::Fatal("Missing number");
  533. }
  534. else if(!strcmp(argv[i] + 1, "swapangle")) {
  535. i++;
  536. if(argv[i]) {
  537. CTX::instance()->mesh.allowSwapEdgeAngle = atof(argv[i++]);
  538. if(CTX::instance()->mesh.allowSwapEdgeAngle <= 0.0)
  539. Msg::Fatal("Threshold angle for edge swap must be > 0");
  540. }
  541. else
  542. Msg::Fatal("Missing number");
  543. }
  544. else if(!strcmp(argv[i] + 1, "clcurv")) {
  545. CTX::instance()->mesh.lcFromCurvature = 1;
  546. i++;
  547. }
  548. else if(!strcmp(argv[i] + 1, "clcurviso")) {
  549. CTX::instance()->mesh.lcFromCurvature = 2;
  550. i++;
  551. }
  552. else if(!strcmp(argv[i] + 1, "smooth")) {
  553. i++;
  554. if(argv[i])
  555. CTX::instance()->mesh.nbSmoothing = atoi(argv[i++]);
  556. else
  557. Msg::Fatal("Missing number");
  558. }
  559. else if(!strcmp(argv[i] + 1, "order") || !strcmp(argv[i] + 1, "degree")) {
  560. i++;
  561. if(argv[i])
  562. opt_mesh_order(0, GMSH_SET, atof(argv[i++]));
  563. else
  564. Msg::Fatal("Missing number");
  565. }
  566. else if(!strcmp(argv[i] + 1, "numsubedges")) {
  567. i++;
  568. if(argv[i])
  569. opt_mesh_num_sub_edges(0, GMSH_SET, atof(argv[i++]));
  570. else
  571. Msg::Fatal("Missing number");
  572. }
  573. else if(!strcmp(argv[i] + 1, "statreport")) {
  574. i++;
  575. CTX::instance()->createAppendMeshStatReport = 1;
  576. if(argv[i])
  577. CTX::instance()->meshStatReportFileName = argv[i++];
  578. else
  579. Msg::Fatal("Missing argument");
  580. }
  581. else if(!strcmp(argv[i] + 1, "append_statreport")) {
  582. i++;
  583. CTX::instance()->createAppendMeshStatReport = 2;
  584. if(argv[i])
  585. CTX::instance()->meshStatReportFileName = argv[i++];
  586. else
  587. Msg::Fatal("Missing argument");
  588. }
  589. else if(!strcmp(argv[i] + 1, "bin")) {
  590. i++;
  591. CTX::instance()->mesh.binary = 1;
  592. }
  593. else if(!strcmp(argv[i] + 1, "parametric")) {
  594. i++;
  595. CTX::instance()->mesh.saveParametric = 1;
  596. }
  597. else if(!strcmp(argv[i] + 1, "algo")) {
  598. i++;
  599. if(argv[i]) {
  600. if(!strncmp(argv[i], "auto", 4))
  601. CTX::instance()->mesh.algo2d = ALGO_2D_AUTO;
  602. else if(!strncmp(argv[i], "meshadapt", 9) || !strncmp(argv[i], "iso", 3))
  603. CTX::instance()->mesh.algo2d = ALGO_2D_MESHADAPT;
  604. else if(!strncmp(argv[i], "bds", 3))
  605. CTX::instance()->mesh.algo2d = ALGO_2D_MESHADAPT_OLD;
  606. else if(!strncmp(argv[i], "del2d", 5) || !strncmp(argv[i], "tri", 3))
  607. CTX::instance()->mesh.algo2d = ALGO_2D_DELAUNAY;
  608. else if(!strncmp(argv[i], "delquad", 5) || !strncmp(argv[i], "tri", 3))
  609. CTX::instance()->mesh.algo2d = ALGO_2D_FRONTAL_QUAD;
  610. else if(!strncmp(argv[i], "front2d", 7) || !strncmp(argv[i], "frontal", 7))
  611. CTX::instance()->mesh.algo2d = ALGO_2D_FRONTAL;
  612. else if(!strncmp(argv[i], "bamg",4))
  613. CTX::instance()->mesh.algo2d = ALGO_2D_BAMG;
  614. else if(!strncmp(argv[i], "del3d", 5) || !strncmp(argv[i], "tetgen", 6))
  615. CTX::instance()->mesh.algo3d = ALGO_3D_DELAUNAY;
  616. else if(!strncmp(argv[i], "front3d", 7) || !strncmp(argv[i], "netgen", 6))
  617. CTX::instance()->mesh.algo3d = ALGO_3D_FRONTAL;
  618. else if(!strncmp(argv[i], "mmg3d", 5))
  619. CTX::instance()->mesh.algo3d = ALGO_3D_MMG3D;
  620. else if(!strncmp(argv[i], "delfr3d", 7))
  621. CTX::instance()->mesh.algo3d = ALGO_3D_FRONTAL_DEL;
  622. else if(!strncmp(argv[i], "delhex3d", 8))
  623. CTX::instance()->mesh.algo3d = ALGO_3D_FRONTAL_HEX;
  624. else if(!strncmp(argv[i], "rtree3d", 9))
  625. CTX::instance()->mesh.algo3d = ALGO_3D_RTREE;
  626. else
  627. Msg::Fatal("Unknown mesh algorithm");
  628. i++;
  629. }
  630. else
  631. Msg::Fatal("Missing algorithm");
  632. }
  633. else if(!strcmp(argv[i] + 1, "format") || !strcmp(argv[i] + 1, "f")) {
  634. i++;
  635. if(argv[i]) {
  636. if(!strcmp(argv[i], "auto")){
  637. CTX::instance()->mesh.fileFormat = FORMAT_AUTO;
  638. }
  639. else if(!strcmp(argv[i], "msh1")){
  640. CTX::instance()->mesh.fileFormat = FORMAT_MSH;
  641. CTX::instance()->mesh.mshFileVersion = 1.0;
  642. }
  643. else if(!strcmp(argv[i], "msh2")){
  644. CTX::instance()->mesh.fileFormat = FORMAT_MSH;
  645. CTX::instance()->mesh.mshFileVersion = 2.0;
  646. }
  647. else{
  648. int format = GetFileFormatFromExtension(std::string(".") + argv[i]);
  649. if(format < 0){
  650. Msg::Error("Unknown mesh format `%s', using `msh' instead", argv[i]);
  651. format = FORMAT_MSH;
  652. }
  653. CTX::instance()->mesh.fileFormat = format;
  654. }
  655. i++;
  656. }
  657. else
  658. Msg::Fatal("Missing format");
  659. }
  660. else if(!strcmp(argv[i] + 1, "listen")) {
  661. CTX::instance()->solver.listen = 1;
  662. i++;
  663. }
  664. else if(!strcmp(argv[i] + 1, "version") || !strcmp(argv[i] + 1, "-version")) {
  665. fprintf(stderr, "%s\n", GMSH_VERSION);
  666. Msg::Exit(0);
  667. }
  668. else if(!strcmp(argv[i] + 1, "info") || !strcmp(argv[i] + 1, "-info")) {
  669. fprintf(stderr, "Version : %s\n", GMSH_VERSION);
  670. #if defined(HAVE_FLTK)
  671. fprintf(stderr, "GUI toolkit : FLTK %d.%d.%d\n", FL_MAJOR_VERSION,
  672. FL_MINOR_VERSION, FL_PATCH_VERSION);
  673. #else
  674. fprintf(stderr, "GUI toolkit : none\n");
  675. #endif
  676. fprintf(stderr, "License : %s\n", GMSH_SHORT_LICENSE);
  677. fprintf(stderr, "Build OS : %s\n", GMSH_OS);
  678. fprintf(stderr, "Build options :%s\n", GMSH_CONFIG_OPTIONS);
  679. fprintf(stderr, "Build date : %s\n", GMSH_DATE);
  680. fprintf(stderr, "Build host : %s\n", GMSH_HOST);
  681. fprintf(stderr, "Packager : %s\n", GMSH_PACKAGER);
  682. fprintf(stderr, "Web site : http://www.geuz.org/gmsh/\n");
  683. fprintf(stderr, "Mailing list : gmsh@geuz.org\n");
  684. Msg::Exit(0);
  685. }
  686. else if(!strcmp(argv[i] + 1, "help") || !strcmp(argv[i] + 1, "-help")) {
  687. fprintf(stderr, "Gmsh, a 3D mesh generator with pre- and post-processing facilities\n");
  688. fprintf(stderr, "Copyright (C) 1997-2012 Christophe Geuzaine and Jean-Francois Remacle\n");
  689. PrintUsage(argv[0]);
  690. Msg::Exit(0);
  691. }
  692. else if(!strcmp(argv[i] + 1, "v") || !strcmp(argv[i] + 1, "verbose")) {
  693. i++;
  694. if(argv[i])
  695. Msg::SetVerbosity(atoi(argv[i++]));
  696. else
  697. Msg::Fatal("Missing number");
  698. }
  699. #if defined(HAVE_FLTK)
  700. else if(!strcmp(argv[i] + 1, "term")) {
  701. terminal = 1;
  702. i++;
  703. }
  704. else if(!strcmp(argv[i] + 1, "dual")) {
  705. CTX::instance()->mesh.dual = 1;
  706. i++;
  707. }
  708. else if(!strcmp(argv[i] + 1, "voronoi")) {
  709. CTX::instance()->mesh.voronoi = 1;
  710. i++;
  711. }
  712. else if(!strcmp(argv[i] + 1, "noview")) {
  713. opt_view_visible(0, GMSH_SET, 0);
  714. i++;
  715. }
  716. else if(!strcmp(argv[i] + 1, "nomesh")) {
  717. opt_mesh_points(0, GMSH_SET, 0.);
  718. opt_mesh_lines(0, GMSH_SET, 0.);
  719. opt_mesh_surfaces_edges(0, GMSH_SET, 0.);
  720. opt_mesh_surfaces_faces(0, GMSH_SET, 0.);
  721. opt_mesh_volumes_edges(0, GMSH_SET, 0.);
  722. opt_mesh_volumes_faces(0, GMSH_SET, 0.);
  723. i++;
  724. }
  725. else if(!strcmp(argv[i] + 1, "n")) {
  726. opt_view_visible(0, GMSH_SET, 0);
  727. opt_mesh_points(0, GMSH_SET, 0.);
  728. opt_mesh_lines(0, GMSH_SET, 0.);
  729. opt_mesh_surfaces_edges(0, GMSH_SET, 0.);
  730. opt_mesh_surfaces_faces(0, GMSH_SET, 0.);
  731. opt_mesh_volumes_edges(0, GMSH_SET, 0.);
  732. opt_mesh_volumes_faces(0, GMSH_SET, 0.);
  733. i++;
  734. }
  735. else if(!strcmp(argv[i] + 1, "link")) {
  736. i++;
  737. if(argv[i])
  738. CTX::instance()->post.link = atoi(argv[i++]);
  739. else
  740. Msg::Fatal("Missing number");
  741. }
  742. else if(!strcmp(argv[i] + 1, "smoothview")) {
  743. CTX::instance()->post.smooth = 1;
  744. i++;
  745. }
  746. else if(!strcmp(argv[i] + 1, "combine")) {
  747. CTX::instance()->post.combineTime = 1;
  748. i++;
  749. }
  750. else if(!strcmp(argv[i] + 1, "nodb")) {
  751. CTX::instance()->db = 0;
  752. i++;
  753. }
  754. else if(!strcmp(argv[i] + 1, "fontsize")) {
  755. i++;
  756. if(argv[i])
  757. CTX::instance()->fontSize = atoi(argv[i++]);
  758. else
  759. Msg::Fatal("Missing number");
  760. }
  761. else if(!strcmp(argv[i] + 1, "deltafontsize")) {
  762. i++;
  763. if(argv[i])
  764. CTX::instance()->deltaFontSize = atoi(argv[i++]);
  765. else
  766. Msg::Fatal("Missing number");
  767. }
  768. else if(!strcmp(argv[i] + 1, "theme") || !strcmp(argv[i] + 1, "scheme")) {
  769. i++;
  770. if(argv[i])
  771. CTX::instance()->guiTheme = argv[i++];
  772. else
  773. Msg::Fatal("Missing argument");
  774. }
  775. else if(!strcmp(argv[i] + 1, "display")) {
  776. i++;
  777. if(argv[i])
  778. CTX::instance()->display = argv[i++];
  779. else
  780. Msg::Fatal("Missing argument");
  781. }
  782. else if(!strcmp(argv[i] + 1, "showCompounds")) {
  783. CTX::instance()->geom.hideCompounds = 0;
  784. i++;
  785. }
  786. #endif
  787. #if defined(__APPLE__)
  788. else if(!strncmp(argv[i] + 1, "psn", 3)) {
  789. // the Mac Finder launches programs with a special command line argument
  790. // of the form -psn_XXX: just ignore it silently (and don't exit!)
  791. i++;
  792. }
  793. #endif
  794. else {
  795. Msg::Error("Unknown option '%s'", argv[i]);
  796. PrintUsage(argv[0]);
  797. Msg::Exit(1);
  798. }
  799. }
  800. else {
  801. CTX::instance()->files.push_back(argv[i++]);
  802. }
  803. }
  804. if(CTX::instance()->files.empty()){
  805. std::string base = (getenv("PWD") ? "" : CTX::instance()->homeDir);
  806. GModel::current()->setFileName(base + CTX::instance()->defaultFileName);
  807. }
  808. else
  809. GModel::current()->setFileName(CTX::instance()->files[0]);
  810. CTX::instance()->terminal = terminal;
  811. }