diff --git a/Box/Main.cpp b/Box/Main.cpp
index 31f2592d50d29ece68e9fe023f6bb66fdbdcd2f6..4f9bacbb32df186ee0878eb9b8abaec50f7c9872 100644
--- a/Box/Main.cpp
+++ b/Box/Main.cpp
@@ -1,4 +1,4 @@
-// $Id: Main.cpp,v 1.3 2001-04-08 20:36:49 geuzaine Exp $
+// $Id: Main.cpp,v 1.4 2001-05-22 08:30:26 geuzaine Exp $
 
 #include <signal.h>
 
@@ -87,7 +87,7 @@ int main(int argc, char *argv[]){
     }
     if(CTX.batch > 0){
       mai3d(THEM, CTX.batch);
-      Print_Mesh(THEM,NULL,CTX.mesh.format);
+      Print_Mesh(THEM,CTX.output_filename,CTX.mesh.format);
     }
     exit(1);
   }    
diff --git a/Common/Context.h b/Common/Context.h
index 213669b51698b5c6b6bca1ad6c4e3b6eda26ee55..b033ce1ac4c406483fe11c532d304f52a1e4df38 100644
--- a/Common/Context.h
+++ b/Common/Context.h
@@ -27,15 +27,17 @@ public :
 
   // general options
   char filename[NAME_STR_L];  // the name of the currently opened file
-  char basefilename[NAME_STR_L]; // the same without the extension
+  char base_filename[NAME_STR_L]; // the same without the extension
+  char *output_filename;      // output file specified with command line option '-o'
   char *default_filename;     // the name of the default file
   char *tmp_filename;         // the name of the temp file
   char *session_filename, sessionrc_filename[NAME_STR_L];
                               // the name of the sessionrc configuration file
   char *options_filename, optionsrc_filename[NAME_STR_L]; 
                               // the name of the optionrc configuration file
-  int session_save, options_save; // save session/option file on exit
   char *error_filename;       // the name of the error file
+
+  int session_save, options_save; // save session/option file on exit
   char *display;              // forced display host:0.0 under X11 
   int  terminal;              // show we print to the terminal console?
   char *editor;               // text editor command (with included '%s')
diff --git a/Common/GetOptions.cpp b/Common/GetOptions.cpp
index e41129b0c6f57cc4b409f62a3ca08149951a380d..9450992f4ccb9e2cd74506206e787a89e8b34e3a 100644
--- a/Common/GetOptions.cpp
+++ b/Common/GetOptions.cpp
@@ -1,4 +1,4 @@
-// $Id: GetOptions.cpp,v 1.21 2001-05-21 08:56:35 geuzaine Exp $
+// $Id: GetOptions.cpp,v 1.22 2001-05-22 08:30:26 geuzaine Exp $
 
 #include "Gmsh.h"
 #include "GmshUI.h"
@@ -33,6 +33,7 @@ void Print_Usage(char *name){
   Msg(DIRECT, "  -0                    parse input files, output flattened geometry, and exit");
   Msg(DIRECT, "Mesh options:");
   Msg(DIRECT, "  -1, -2, -3            perform batch 1D, 2D and 3D mesh generation");
+  Msg(DIRECT, "  -o file               specify output file name");
   Msg(DIRECT, "  -format msh|unv|gref  set output mesh format (default: msh)");
   Msg(DIRECT, "  -algo iso|aniso       select 2D mesh algorithm (default: iso)");
   Msg(DIRECT, "  -smooth int           set mesh smoothing (default: 0)");
@@ -121,6 +122,14 @@ void Get_Options (int argc, char *argv[], int *nbfiles) {
       else if(!strcmp(argv[i]+1, "3")){ 
         CTX.batch = 3; i++;
       }
+      else if(!strcmp(argv[i]+1, "o")){ 
+        i++;
+        if(argv[i] != NULL) CTX.output_filename = argv[i++];
+        else {    
+          fprintf(stderr, ERROR_STR "Missing file name\n");
+          exit(1);
+        }
+      }
       else if(!strcmp(argv[i]+1, "bgm")){ 
         i++;
         if(argv[i] != NULL) TheBgmFileName = argv[i++];
diff --git a/Common/Options.cpp b/Common/Options.cpp
index 2c04b8a4137e95ffacfe163257b56db49bf14541..13381fcffb1be25f58639d74f0545428b879a56d 100644
--- a/Common/Options.cpp
+++ b/Common/Options.cpp
@@ -1,4 +1,4 @@
-// $Id: Options.cpp,v 1.21 2001-05-21 13:19:05 geuzaine Exp $
+// $Id: Options.cpp,v 1.22 2001-05-22 08:30:26 geuzaine Exp $
 
 #include "Gmsh.h"
 #include "GmshUI.h"
@@ -73,6 +73,7 @@ void Init_Options(int num){
 
   // The following defaults cannot be set by the user 
   CTX.batch = 0 ;
+  CTX.output_filename = NULL ;
   CTX.expose = 0 ;
   CTX.stream = TO_SCREEN ;
   CTX.gl_fontheight = 12;
diff --git a/Fltk/Callbacks.cpp b/Fltk/Callbacks.cpp
index 4157bee84c9711168cf03552481b97850bb29624..b9e82fa82d9e6db7bd6a613ce2bae273890cb24b 100644
--- a/Fltk/Callbacks.cpp
+++ b/Fltk/Callbacks.cpp
@@ -1,4 +1,4 @@
-// $Id: Callbacks.cpp,v 1.56 2001-05-20 19:24:53 geuzaine Exp $
+// $Id: Callbacks.cpp,v 1.57 2001-05-22 08:30:26 geuzaine Exp $
 
 #include <sys/types.h>
 #include <signal.h>
@@ -1093,7 +1093,7 @@ void geometry_physical_add_volume_cb (CALLBACK_ARGS){
 // Dynamic Mesh Menus
 
 void mesh_save_cb(CALLBACK_ARGS) {
-  Print_Mesh(&M, NULL, CTX.mesh.format);
+  Print_Mesh(&M, CTX.output_filename, CTX.mesh.format);
 }
 void mesh_define_cb(CALLBACK_ARGS){
   WID->set_context(menu_mesh_define, 0);
@@ -1319,7 +1319,7 @@ void getdp_cb(CALLBACK_ARGS){
   static int first=1;
   if(first){
     first = 0;
-    strcpy(file,CTX.basefilename);
+    strcpy(file,CTX.base_filename);
     strcat(file,".pro");
     WID->getdp_input[0]->value(file);
   }
diff --git a/Fltk/Main.cpp b/Fltk/Main.cpp
index 3e360ef2f8abb14db39256d9cf03023ff4384c47..1947f019b36686210161bd3524190cfa93d58a3c 100644
--- a/Fltk/Main.cpp
+++ b/Fltk/Main.cpp
@@ -1,4 +1,4 @@
-// $Id: Main.cpp,v 1.25 2001-05-21 13:01:13 geuzaine Exp $
+// $Id: Main.cpp,v 1.26 2001-05-22 08:30:26 geuzaine Exp $
 
 #include <signal.h>
 
@@ -87,10 +87,10 @@ int main(int argc, char *argv[]){
       }
       if(CTX.batch > 0){
         mai3d(THEM, CTX.batch);
-        Print_Mesh(THEM,NULL,CTX.mesh.format);
+        Print_Mesh(THEM, CTX.output_filename, CTX.mesh.format);
       }
       else
-        Print_Geo(THEM, NULL);
+        Print_Geo(THEM, CTX.output_filename);
       exit(1);
     }    
   }
diff --git a/Graphics/CreateFile.cpp b/Graphics/CreateFile.cpp
index 4a0efade287f4c4006e95d1777dfb8f1583f139e..d40e815e324e8b6d3264acbbc72739153bc4e0b3 100644
--- a/Graphics/CreateFile.cpp
+++ b/Graphics/CreateFile.cpp
@@ -1,4 +1,4 @@
-// $Id: CreateFile.cpp,v 1.17 2001-04-08 20:36:49 geuzaine Exp $
+// $Id: CreateFile.cpp,v 1.18 2001-05-22 08:30:26 geuzaine Exp $
 
 #include "Gmsh.h"
 #include "GmshUI.h"
@@ -204,7 +204,7 @@ void CreateOutputFile (char *name, int format) {
       res = GL2PS_OVERFLOW ;
       while(res == GL2PS_OVERFLOW){
 	size3d += 2048*2048 ;
-	gl2psBeginPage(CTX.basefilename, "Gmsh", 
+	gl2psBeginPage(CTX.base_filename, "Gmsh", 
 		       (CTX.print.eps_quality == 1 ? GL2PS_SIMPLE_SORT : GL2PS_BSP_SORT),
 		       GL2PS_SIMPLE_LINE_OFFSET | GL2PS_DRAW_BACKGROUND,
 		       GL_RGBA, 0, NULL, size3d, fp);
diff --git a/Motif/Main.cpp b/Motif/Main.cpp
index 3ec5335b9c9252c75de594deca2f13e6c2f566c1..8c99e0b1f2a4cdd44c14a1e34dbfe185e29cc295 100644
--- a/Motif/Main.cpp
+++ b/Motif/Main.cpp
@@ -1,4 +1,4 @@
-// $Id: Main.cpp,v 1.10 2001-02-20 18:32:58 geuzaine Exp $
+// $Id: Main.cpp,v 1.11 2001-05-22 08:30:26 geuzaine Exp $
 
 #include <signal.h>
 
@@ -95,10 +95,10 @@ int main(int argc, char *argv[]){
       }
       if(CTX.batch > 0){
         mai3d(THEM, CTX.batch);
-        Print_Mesh(THEM,NULL,CTX.mesh.format);
+        Print_Mesh(THEM,CTX.output_filename,CTX.mesh.format);
       }
       else
-        Print_Geo(THEM, NULL);
+        Print_Geo(THEM,CTX.output_filename);
       exit(1);
     }    
   }
diff --git a/Parser/OpenFile.cpp b/Parser/OpenFile.cpp
index 312ac0628210dae6399129baae4605c4c63f7582..055a82d6110b7d24571f21616f9ab7f49b5669bf 100644
--- a/Parser/OpenFile.cpp
+++ b/Parser/OpenFile.cpp
@@ -1,4 +1,4 @@
-// $Id: OpenFile.cpp,v 1.15 2001-05-20 19:24:53 geuzaine Exp $
+// $Id: OpenFile.cpp,v 1.16 2001-05-22 08:30:26 geuzaine Exp $
 #include "Gmsh.h"
 #include "Const.h"
 #include "Context.h"
@@ -98,7 +98,7 @@ void OpenProblem(char *name){
   Init_Mesh(&M, 1);
 
   strncpy(CTX.filename,name,NAME_STR_L);
-  strncpy(CTX.basefilename,name,NAME_STR_L);
+  strncpy(CTX.base_filename,name,NAME_STR_L);
 
   strcpy(ext,name+(strlen(name)-4));
   if(!strcmp(ext,".geo") || !strcmp(ext,".GEO") ||
@@ -106,19 +106,19 @@ void OpenProblem(char *name){
      !strcmp(ext,".stl") || !strcmp(ext,".STL") ||
      !strcmp(ext,".sms") || !strcmp(ext,".SMS") ||
      !strcmp(ext,".pos") || !strcmp(ext,".POS")){
-    CTX.basefilename[strlen(name)-4] = '\0';
+    CTX.base_filename[strlen(name)-4] = '\0';
   }
   else{
     strcat(CTX.filename,".geo");
   }
 
-  strncpy(THEM->name, CTX.basefilename,NAME_STR_L);
+  strncpy(THEM->name, CTX.base_filename,NAME_STR_L);
 
   if(!CTX.batch){
 #if _XMOTIF
     XtVaSetValues(WID.G.shell,
                   XmNtitle, CTX.filename,
-                  XmNiconName, CTX.basefilename,
+                  XmNiconName, CTX.base_filename,
                   NULL);
 #elif _FLTK
     WID->set_title(CTX.filename);