From 4eaef45594efea783acccbc8410caa3f8a48f812 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Wed, 21 Apr 2004 23:14:47 +0000
Subject: [PATCH] "gmsh -convert file file" now also translates meshes into the
 newest format (in addition to parsed->binary post-processing views)

---
 Common/CommandLine.cpp        | 16 +++++++++++++---
 Fltk/Main.cpp                 | 30 +++++++++++++++---------------
 doc/texinfo/command_line.texi |  2 +-
 3 files changed, 29 insertions(+), 19 deletions(-)

diff --git a/Common/CommandLine.cpp b/Common/CommandLine.cpp
index 2e448ecee8..a9a5a9316f 100644
--- a/Common/CommandLine.cpp
+++ b/Common/CommandLine.cpp
@@ -1,4 +1,4 @@
-// $Id: CommandLine.cpp,v 1.31 2004-04-18 03:07:44 geuzaine Exp $
+// $Id: CommandLine.cpp,v 1.32 2004-04-21 23:14:47 geuzaine Exp $
 //
 // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle
 //
@@ -41,6 +41,7 @@
 #endif
 
 extern Context_T CTX;
+extern Mesh *THEM;
 
 char *TheFileNameTab[MAX_OPEN_FILES];
 char *TheBgmFileName = NULL, *TheOptString = NULL;
@@ -93,7 +94,7 @@ void Print_Usage(char *name){
   Msg(DIRECT, "  -link int             select link mode between views (default: 0)");
   Msg(DIRECT, "  -smoothview           smooth views");
   Msg(DIRECT, "  -combine              combine input views into multi time step ones");
-  Msg(DIRECT, "  -convert file file    convert all views in a file into binary views");
+  Msg(DIRECT, "  -convert file file    perform batch conversion of view(s)/mesh into new file formats");
   Msg(DIRECT, "Display options:");    
   Msg(DIRECT, "  -nodb                 disable double buffering");
   Msg(DIRECT, "  -fontsize int         specify the font size for the GUI (default: 12)");
@@ -263,11 +264,20 @@ void Get_Options(int argc, char *argv[], int *nbfiles)
       else if(!strcmp(argv[i] + 1, "convert")) {
         i++;
         CTX.terminal = 1;
+        CTX.batch = 1;
         if(argv[i] && argv[i + 1]) {
-          MergeProblem(argv[i]);
+          OpenProblem(argv[i]);
+	  // convert post-processing views to latest (binary) format
           for(int j = 0; j < List_Nbr(CTX.post.list); j++)
             WriteView((Post_View *) List_Pointer(CTX.post.list, j),
                       argv[i + 1], 1, j ? 1 : 0);
+	  // convert any mesh to the latest format
+	  if(THEM){
+	    if(Tree_Nbr(THEM->Vertices)){
+	      CTX.mesh.msh_file_version = 2.0;
+	      Print_Mesh(THEM, argv[i + 1], FORMAT_MSH);
+	    }
+	  }
         }
         else
           fprintf(stderr, "Usage: %s -convert file file\n", argv[0]);
diff --git a/Fltk/Main.cpp b/Fltk/Main.cpp
index 70bd51f3b2..06b52f8325 100644
--- a/Fltk/Main.cpp
+++ b/Fltk/Main.cpp
@@ -1,4 +1,4 @@
-// $Id: Main.cpp,v 1.61 2004-04-19 07:42:24 geuzaine Exp $
+// $Id: Main.cpp,v 1.62 2004-04-21 23:14:47 geuzaine Exp $
 //
 // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle
 //
@@ -80,6 +80,20 @@ int main(int argc, char *argv[])
     exit(0);
   }
 
+  // Initialize the static Mesh
+
+  M.Vertices = NULL;
+  M.Simplexes = NULL;
+  M.Points = NULL;
+  M.Curves = NULL;
+  M.SurfaceLoops = NULL;
+  M.EdgeLoops = NULL;
+  M.Surfaces = NULL;
+  M.Volumes = NULL;
+  M.PhysicalGroups = NULL;
+  M.Partitions = NULL;
+  M.Metric = NULL;
+
   // Configuration files and command line options
 
   Get_Options(argc, argv, &nbf);
@@ -102,20 +116,6 @@ int main(int argc, char *argv[])
   if(CTX.default_plugins)
     GMSH_PluginManager::instance()->registerDefaultPlugins();
 
-  // Initialize the static Mesh
-
-  M.Vertices = NULL;
-  M.Simplexes = NULL;
-  M.Points = NULL;
-  M.Curves = NULL;
-  M.SurfaceLoops = NULL;
-  M.EdgeLoops = NULL;
-  M.Surfaces = NULL;
-  M.Volumes = NULL;
-  M.PhysicalGroups = NULL;
-  M.Partitions = NULL;
-  M.Metric = NULL;
-
   // Signal handling
 
   signal(SIGINT, Signal);
diff --git a/doc/texinfo/command_line.texi b/doc/texinfo/command_line.texi
index 7dff55efe7..a4d3dcaed9 100644
--- a/doc/texinfo/command_line.texi
+++ b/doc/texinfo/command_line.texi
@@ -62,7 +62,7 @@ smooth views
 @item -combine
 combine input views into multi time step ones
 @item -convert file file
-convert all views in a file into binary views
+perform batch conversion of view(s)/mesh into new file formats
 @end ftable
 
 @sp 1 
-- 
GitLab