diff --git a/contrib/Chaco/Makefile b/contrib/Chaco/Makefile
index 2c50e7a829cfcc64d0a2d499a9144e19b1d26b5f..5dc3c1a411bafbc50c031049ca201ab20d36035a 100644
--- a/contrib/Chaco/Makefile
+++ b/contrib/Chaco/Makefile
@@ -1,11 +1,14 @@
-DEST_DIR = 	../exec
-DEST=		${DEST_DIR}/chaco
-CC = 		gcc
-IFLAG =		-Imain
-CFLAGS =	-O2
-OFLAGS =	-O2
 
-FILES.c=	main/user_params.c main/interface.c main/main.c \
+include ../../variables
+
+LIB = ../../lib/libGmshChaco${LIBEXT}
+
+INC = ${DASH}Imain
+
+CFLAGS  = ${OPTIM} ${FLAGS} ${INC} ${SYSINCLUDE}
+
+SRCX	 =	main/Gmsh_printf.cpp main/Gmsh_exit.cpp
+SRC =		main/user_params.c main/interface.c \
 		submain/balance.c submain/divide.c submain/submain.c \
 		input/input_assign.c \
 		input/check_input.c input/input.c input/input_geom.c \
@@ -87,20 +90,30 @@ FILES.c=	main/user_params.c main/interface.c main/main.c \
 		util/update.c  util/vecout.c util/vecran.c \
                 util/vecscale.c 
 
-FILES.o=	$(FILES.c:.c=.o) 
+OBJ = ${SRC:.c=${OBJEXT}}
+OBJX = ${SRCX:.cpp=${OBJEXT}}
 
+.SUFFIXES: ${OBJEXT} .c .cpp
 
-${DEST}:	${FILES.o} Makefile
-		${CC} ${OFLAGS} ${FILES.o} -lm -o ${DEST}
+${LIB}: ${OBJ} ${OBJX}
+	${AR} ${ARFLAGS}${LIB} ${OBJ} ${OBJX} 
+	${RANLIB} ${LIB}
 
-lint:
-		lint ${IFLAG} ${FILES.c} -lm
+.c${OBJEXT}:
+	${CC} ${CFLAGS} ${DASH}c $< ${DASH}o ${<:.c=${OBJEXT}}
 
-alint:
-		alint ${IFLAG} ${FILES.c} -lm
+.cpp${OBJEXT}:
+	${CXX} ${CFLAGS} ${DASH}c $< ${DASH}o ${<:.cpp=${OBJEXT}}
 
 clean:
-		rm -f */*.o ${DEST_DIR}/core
+	rm -f */*.o */*.obj
+
+depend:
+	(sed '/^# DO NOT DELETE THIS LINE/q' Makefile && \
+	${CXX} -MM ${CFLAGS} ${SRC} \
+	) >Makefile.new
+	cp Makefile Makefile.bak
+	cp Makefile.new Makefile
+	rm -f Makefile.new
 
-.c.o:
-		${CC} -c ${IFLAG} ${CFLAGS} -o $*.o $*.c
+# DO NOT DELETE THIS LINE
diff --git a/contrib/Chaco/README b/contrib/Chaco/README
index 1b09eb26ba35935d21cd23619ebf13c10d754c76..ec51fb0cbabe0f007e1b0ecbc04e6c0cbea5b0d5 100644
--- a/contrib/Chaco/README
+++ b/contrib/Chaco/README
@@ -1,15 +1,22 @@
-This directory contains all the necessary source code files
-for Chaco.  Simply type "make", and the code will be compiled
-and the executable image placed in "../exec/chaco".  
-
-The default values for the user accessible parameters discussed 
-in the user's guide "doc/User_guide.ps" can be modified by 
-editing the file "main/user_params.c".  You must recompile for 
-these changes to take affect. 
-
-You can also change the code parameters at run time (i.e. without 
-recompiling) by including a file "User_Params" in whichever 
-directory you are running the code from (so in the file 
-"exec/User_Params" in our orignal set-up). Parameter changes 
-can be specified in a natural way in this file using the rules 
-described in the user's guide.
+Chaco version 2.2
+
+This software was developed by Bruce Hendrickson and Robert Leland
+at Sandia National Laboratories under US Department of Energy
+contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation.
+
+--------------------------------------------------------------------------------
+
+Chaco has been slightly modified for integration into the Gmsh program.  Most
+changes are to 'main/interface.c'.  Elsewhere, the 'printf' routine has been
+defined as Gmsh_printf to write through a Gmsh Msg::Info.  All other
+modifications are tagged by 'Gmsh' and 'Gmsh - end'
+
+Parameters explicitly set to false
+FREE_GRAPH
+
+Parameters that are read through Gmsh and overwrite the parameters file
+REFINE_PARTITION
+INTERNAL_VERTICES
+REFINE_MAP
+TERMINAL_PROPOGATION
+
diff --git a/contrib/Chaco/assign/assign.c b/contrib/Chaco/assign/assign.c
index 6c1e97f7911766f892427c83d6958b3cabce2dec..d70d2727bad97185a5f856c22b7f84a9c93f0275 100644
--- a/contrib/Chaco/assign/assign.c
+++ b/contrib/Chaco/assign/assign.c
@@ -3,6 +3,7 @@
  * contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation. */
 
 #include	<stdio.h>
+#include        "Gmsh_printf.h"
 #include	"defs.h"
 #include	"structs.h"
 
diff --git a/contrib/Chaco/bpmatch/checkbp.c b/contrib/Chaco/bpmatch/checkbp.c
index d3ff61968c306f6e500a512406cd46fe53c20674..486e67a428df6c6295c1e1502062b8a91426b52d 100644
--- a/contrib/Chaco/bpmatch/checkbp.c
+++ b/contrib/Chaco/bpmatch/checkbp.c
@@ -4,6 +4,7 @@
 
 #include	<stdio.h>
 #include	<math.h>
+#include        "Gmsh_printf.h"
 #include	"structs.h"
 #include	"params.h"
 #include	"defs.h"
diff --git a/contrib/Chaco/bpmatch/map2d.c b/contrib/Chaco/bpmatch/map2d.c
index 7d70aee2c5263d4c81628ec456635686c323f0a6..5723106ef5581e04d187050983acceb30ae8ca9e 100644
--- a/contrib/Chaco/bpmatch/map2d.c
+++ b/contrib/Chaco/bpmatch/map2d.c
@@ -3,6 +3,7 @@
  * contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation. */
 
 #include	<stdio.h>
+#include        "Gmsh_printf.h"
 #include	"defs.h"
 #include	"params.h"
 #include	"structs.h"
diff --git a/contrib/Chaco/bpmatch/map3d.c b/contrib/Chaco/bpmatch/map3d.c
index 3354f864afeacee2e79717694b8e954605b8a4a9..b06fe807835ba6649fcd835b3ec327bea0d8e662 100644
--- a/contrib/Chaco/bpmatch/map3d.c
+++ b/contrib/Chaco/bpmatch/map3d.c
@@ -3,6 +3,7 @@
  * contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation. */
 
 #include	<stdio.h>
+#include        "Gmsh_printf.h"
 #include	"defs.h"
 #include	"params.h"
 #include	"structs.h"
diff --git a/contrib/Chaco/coarsen/coarsen.c b/contrib/Chaco/coarsen/coarsen.c
index d9088af32ee588e748f1f1b2bbcba0f90de29f65..92d845ec22586881f110df0f02992a232860a48e 100644
--- a/contrib/Chaco/coarsen/coarsen.c
+++ b/contrib/Chaco/coarsen/coarsen.c
@@ -4,6 +4,7 @@
 
 #include <stdio.h>
 #include <math.h>
+#include "Gmsh_printf.h"
 #include "params.h"
 #include "defs.h"
 #include "structs.h"
diff --git a/contrib/Chaco/coarsen/makecgraph.c b/contrib/Chaco/coarsen/makecgraph.c
index a2f3971f9e8621ed6f4c4db99e4a59cbf584a970..d3ae894880471360f13e24808806089fd9ce0bd9 100644
--- a/contrib/Chaco/coarsen/makecgraph.c
+++ b/contrib/Chaco/coarsen/makecgraph.c
@@ -3,6 +3,7 @@
  * contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation. */
 
 #include <stdio.h>
+#include "Gmsh_printf.h"
 #include "defs.h"
 #include "structs.h"
 
diff --git a/contrib/Chaco/coarsen/makecgraph2.c b/contrib/Chaco/coarsen/makecgraph2.c
index e66128b9ccccea903964ed306bb44c489bac90fc..65e6d7fc727bfc1cca191ff4fc55819105a3ff2f 100644
--- a/contrib/Chaco/coarsen/makecgraph2.c
+++ b/contrib/Chaco/coarsen/makecgraph2.c
@@ -3,6 +3,7 @@
  * contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation. */
 
 #include <stdio.h>
+#include "Gmsh_printf.h"
 #include "defs.h"
 #include "structs.h"
 
diff --git a/contrib/Chaco/coarsen/makefgraph.c b/contrib/Chaco/coarsen/makefgraph.c
index d557ab087b5a1a1540af9c62e105604e4b19918f..7ae25d95f40526cfa50b5f8acfb108232f19aaf3 100644
--- a/contrib/Chaco/coarsen/makefgraph.c
+++ b/contrib/Chaco/coarsen/makefgraph.c
@@ -3,6 +3,7 @@
  * contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation. */
 
 #include <stdio.h>
+#include "Gmsh_printf.h"
 #include "defs.h"
 #include "structs.h"
 
diff --git a/contrib/Chaco/coarsen/maxmatch.c b/contrib/Chaco/coarsen/maxmatch.c
index 3daaedc66863dc967023bd1972e828d1e7a59060..9822c9d830941cc5a43301ad1bf0e14b8e2c7f1b 100644
--- a/contrib/Chaco/coarsen/maxmatch.c
+++ b/contrib/Chaco/coarsen/maxmatch.c
@@ -3,6 +3,7 @@
  * contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation. */
 
 #include <stdio.h>
+#include "Gmsh_printf.h"
 #include "defs.h"
 #include "structs.h"
 
diff --git a/contrib/Chaco/connect/connected.c b/contrib/Chaco/connect/connected.c
index 0e0301e1afce69da3dedfd6073d75aee9a17cc6a..0eed3ee717245e1122b0e0181896fbce15f964b6 100644
--- a/contrib/Chaco/connect/connected.c
+++ b/contrib/Chaco/connect/connected.c
@@ -3,6 +3,7 @@
  * contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation. */
 
 #include	<stdio.h>
+#include        "Gmsh_printf.h"
 #include	"defs.h"
 #include	"structs.h"
 
diff --git a/contrib/Chaco/eigen/bisect.c b/contrib/Chaco/eigen/bisect.c
index 8cb5033c036f539883c5181430e09961d2dc2fe0..885a142b203ea391a92a4e158a066a573a4bfa96 100644
--- a/contrib/Chaco/eigen/bisect.c
+++ b/contrib/Chaco/eigen/bisect.c
@@ -3,6 +3,7 @@
  * contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation. */
 
 #include <stdio.h>
+#include "Gmsh_printf.h"
 #include "defs.h"
 
 /* Finds selected eigenvalues of T using Sturm sequence bisection. Based 
diff --git a/contrib/Chaco/eigen/checkeig_ext.c b/contrib/Chaco/eigen/checkeig_ext.c
index c706b8a7dd4bd8c0084fa87aa5c5519a6890082a..25c95656f5468460bea357dca500799354ece43f 100644
--- a/contrib/Chaco/eigen/checkeig_ext.c
+++ b/contrib/Chaco/eigen/checkeig_ext.c
@@ -3,6 +3,7 @@
  * contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation. */
 
 #include <stdio.h>
+#include "Gmsh_printf.h"
 #include "defs.h"
 #include "structs.h"
 
diff --git a/contrib/Chaco/eigen/checkorth.c b/contrib/Chaco/eigen/checkorth.c
index d162ba46f28cb6c64ef05898e358c7c1d9f84942..8d4f875bfb61ae02288e014f63525760e167998b 100644
--- a/contrib/Chaco/eigen/checkorth.c
+++ b/contrib/Chaco/eigen/checkorth.c
@@ -4,6 +4,7 @@
 
 #include <stdio.h>
 #include <math.h>
+#include "Gmsh_printf.h"
 #include "defs.h"
 #include "structs.h"
 
diff --git a/contrib/Chaco/eigen/eigensolve.c b/contrib/Chaco/eigen/eigensolve.c
index 8f8fa9c1ce59a98f3ae464e9c8bb027b6f878fd5..5a9754565a9e604e73e5e51e4957f30a7d1b76fa 100644
--- a/contrib/Chaco/eigen/eigensolve.c
+++ b/contrib/Chaco/eigen/eigensolve.c
@@ -4,6 +4,7 @@
 
 #include <stdio.h>
 #include <math.h>
+#include "Gmsh_printf.h"
 #include "params.h"
 #include "defs.h"
 #include "structs.h"
diff --git a/contrib/Chaco/eigen/get_extval.c b/contrib/Chaco/eigen/get_extval.c
index 85b9429b9da31081c8e06a139c55aeb0a6796ff1..0d3f63988dd4a2f23af3bdf17f4153ce223d8055 100644
--- a/contrib/Chaco/eigen/get_extval.c
+++ b/contrib/Chaco/eigen/get_extval.c
@@ -4,6 +4,7 @@
 
 #include <math.h>
 #include <stdio.h>
+#include "Gmsh_printf.h"
 
 /* Finds first extended eigenpair of system corresponding to
    tridiagonal T using using Rafael's bisection technique. */
diff --git a/contrib/Chaco/eigen/get_ritzvals.c b/contrib/Chaco/eigen/get_ritzvals.c
index 50932822580b8ff2846f9b95456443af034afe75..4251fe8e526f6af0fcd038119e8267fbdd952b33 100644
--- a/contrib/Chaco/eigen/get_ritzvals.c
+++ b/contrib/Chaco/eigen/get_ritzvals.c
@@ -4,6 +4,7 @@
 
 #include <math.h>
 #include <stdio.h>
+#include "Gmsh_printf.h"
 #include "defs.h"
 
 /* Finds needed eigenvalues of tridiagonal T using either the QL algorithm 
diff --git a/contrib/Chaco/eigen/lanczos_FO.c b/contrib/Chaco/eigen/lanczos_FO.c
index 73af15bf0f57496688586761c5e2dec54eda3998..00d0a2adb34a5be9153b66764056b855e974e2bb 100644
--- a/contrib/Chaco/eigen/lanczos_FO.c
+++ b/contrib/Chaco/eigen/lanczos_FO.c
@@ -3,6 +3,7 @@
  * contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation. */
 
 #include <stdio.h>
+#include "Gmsh_printf.h"
 #include "structs.h"
 #include "defs.h"
 
diff --git a/contrib/Chaco/eigen/lanczos_SO.c b/contrib/Chaco/eigen/lanczos_SO.c
index 718aa26d974b2fdb8aa5300b872f9e1af8931d07..d652eb432dd765df983ed7a90b15ec617744aa13 100644
--- a/contrib/Chaco/eigen/lanczos_SO.c
+++ b/contrib/Chaco/eigen/lanczos_SO.c
@@ -4,6 +4,7 @@
 
 #include <stdio.h>
 #include <math.h>
+#include "Gmsh_printf.h"
 #include "structs.h"
 #include "defs.h"
 #include "params.h"
diff --git a/contrib/Chaco/eigen/lanczos_SO_float.c b/contrib/Chaco/eigen/lanczos_SO_float.c
index f74a2c3673badc3ec6839886e7e0d18e578d52a4..9c75dc46b03c2fccf0b67500ec5b840c7e62d127 100644
--- a/contrib/Chaco/eigen/lanczos_SO_float.c
+++ b/contrib/Chaco/eigen/lanczos_SO_float.c
@@ -4,6 +4,7 @@
 
 #include <stdio.h>
 #include <math.h>
+#include "Gmsh_printf.h"
 #include "structs.h"
 #include "defs.h"
 #include "params.h"
diff --git a/contrib/Chaco/eigen/lanczos_ext.c b/contrib/Chaco/eigen/lanczos_ext.c
index fa3c68941a21939cfd696c99b7685c262e0920ac..113c1f7b9c56c373286af36ecb040435b772c0b0 100644
--- a/contrib/Chaco/eigen/lanczos_ext.c
+++ b/contrib/Chaco/eigen/lanczos_ext.c
@@ -4,6 +4,7 @@
 
 #include <stdio.h>
 #include <math.h>
+#include "Gmsh_printf.h"
 #include "../main/structs.h"
 #include "../main/defs.h"
 
diff --git a/contrib/Chaco/eigen/lanczos_ext_float.c b/contrib/Chaco/eigen/lanczos_ext_float.c
index 1d4c257c85dd9c6c2897618d0934d6852de503b6..2fd1cd96d2e6c7df0cf6ca2b6b5f8eff757435c0 100644
--- a/contrib/Chaco/eigen/lanczos_ext_float.c
+++ b/contrib/Chaco/eigen/lanczos_ext_float.c
@@ -4,6 +4,7 @@
 
 #include <stdio.h>
 #include <math.h>
+#include "Gmsh_printf.h"
 #include "structs.h"
 #include "defs.h"
 
diff --git a/contrib/Chaco/eigen/lanpause.c b/contrib/Chaco/eigen/lanpause.c
index e865885fcd1763cec4178c4479e8acef5d32fcf9..130d2e142be79800fab5f1c0660ed6241c2b5a5b 100644
--- a/contrib/Chaco/eigen/lanpause.c
+++ b/contrib/Chaco/eigen/lanpause.c
@@ -3,6 +3,7 @@
  * contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation. */
 
 #include <stdio.h>
+#include "Gmsh_printf.h"
 #include "defs.h"
 #include "structs.h"
 
diff --git a/contrib/Chaco/eigen/rqi.c b/contrib/Chaco/eigen/rqi.c
index 3147edcbdd0ba0c49c82952c3ec92977ac88d575..4eff28e291526dea84d2e3774037d54789a421a0 100644
--- a/contrib/Chaco/eigen/rqi.c
+++ b/contrib/Chaco/eigen/rqi.c
@@ -4,6 +4,7 @@
 
 #include	<stdio.h>
 #include	<math.h>
+#include        "Gmsh_printf.h"
 #include	"defs.h"
 #include	"structs.h"
 
diff --git a/contrib/Chaco/eigen/solistout.c b/contrib/Chaco/eigen/solistout.c
index c2cf1c5ebcf043a6413644e96c3610e191203a18..3a3a57615653a158ac4889eff431eae65d30beaa 100644
--- a/contrib/Chaco/eigen/solistout.c
+++ b/contrib/Chaco/eigen/solistout.c
@@ -3,6 +3,7 @@
  * contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation. */
 
 #include <stdio.h>
+#include "Gmsh_printf.h"
 #include "defs.h"
 #include "structs.h"
 
diff --git a/contrib/Chaco/eigen/tri_solve.c b/contrib/Chaco/eigen/tri_solve.c
index 031e33693fb44df8a6dd6f320335e551c0b3bb9b..e0dae712fe5b1e9b42af090bf29c8aa7bedb766c 100644
--- a/contrib/Chaco/eigen/tri_solve.c
+++ b/contrib/Chaco/eigen/tri_solve.c
@@ -4,6 +4,7 @@
 
 #include <stdio.h>
 #include <math.h>
+#include "Gmsh_printf.h"
 #include "defs.h"
 
 /* Solve the shifted, symmetric tridiagonal linear system (T - lambda*I)v = b
diff --git a/contrib/Chaco/graph/check_graph.c b/contrib/Chaco/graph/check_graph.c
index 29c79e3d87aa7e8ca7033528d5b940c4fea42913..f8698fc3d4ed5661d0c2538e3b60c19d96db57d8 100644
--- a/contrib/Chaco/graph/check_graph.c
+++ b/contrib/Chaco/graph/check_graph.c
@@ -4,6 +4,7 @@
 
 #include <stdio.h>
 #include <math.h>
+#include "Gmsh_printf.h"
 #include "defs.h"
 #include "structs.h"
 
diff --git a/contrib/Chaco/graph/reformat.c b/contrib/Chaco/graph/reformat.c
index 0e672085971c90f7d959af86b6327c047014fb34..ff7aa1baa9546ce0506e4936323b1e39eb4d4b39 100644
--- a/contrib/Chaco/graph/reformat.c
+++ b/contrib/Chaco/graph/reformat.c
@@ -3,6 +3,7 @@
  * contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation. */
 
 #include <stdio.h>
+#include "Gmsh_printf.h"
 #include "defs.h"
 #include "structs.h"
 
diff --git a/contrib/Chaco/inertial/inertial.c b/contrib/Chaco/inertial/inertial.c
index e40e98974cc7a4379d4abb16736c9d1e63b138b8..803c4433cb746d18e0d62777cf7bec5407ba2c55 100644
--- a/contrib/Chaco/inertial/inertial.c
+++ b/contrib/Chaco/inertial/inertial.c
@@ -4,6 +4,7 @@
 
 #include <math.h>
 #include <stdio.h>
+#include "Gmsh_printf.h"
 #include "structs.h"
 #include "defs.h"
 
diff --git a/contrib/Chaco/inertial/inertial2d.c b/contrib/Chaco/inertial/inertial2d.c
index 2869856d0f7026ba024ce2f24a190bd376bd34da..2c31699aebe703a8dce82582e1e849575a77a07d 100644
--- a/contrib/Chaco/inertial/inertial2d.c
+++ b/contrib/Chaco/inertial/inertial2d.c
@@ -4,6 +4,7 @@
 
 #include <math.h>
 #include <stdio.h>
+#include "Gmsh_printf.h"
 #include "structs.h"
 #include "defs.h"
 
diff --git a/contrib/Chaco/inertial/inertial3d.c b/contrib/Chaco/inertial/inertial3d.c
index f94752b538240dcb1ce0f1c4c84408d531dfdab1..2d894c382c1ac5c7f67d632341f4f1b03326ef69 100644
--- a/contrib/Chaco/inertial/inertial3d.c
+++ b/contrib/Chaco/inertial/inertial3d.c
@@ -4,6 +4,7 @@
 
 #include <math.h>
 #include <stdio.h>
+#include "Gmsh_printf.h"
 #include "structs.h"
 #include "defs.h"
 
diff --git a/contrib/Chaco/input/check_input.c b/contrib/Chaco/input/check_input.c
index ba79a82daa252375d317ab8e5b62ad9d656324ff..bbb8d357586053a335c66c94b4794481682b7bd8 100644
--- a/contrib/Chaco/input/check_input.c
+++ b/contrib/Chaco/input/check_input.c
@@ -4,6 +4,7 @@
 
 #include <stdio.h>
 #include <math.h>
+#include "Gmsh_printf.h"
 #include "params.h"
 #include "defs.h"
 #include "structs.h"
diff --git a/contrib/Chaco/input/input.c b/contrib/Chaco/input/input.c
index 6ab75177956ecd42b9ec87b92ee427f76c49b749..23db3260fb3f7a1adc14ba63b637abc15e4c8702 100644
--- a/contrib/Chaco/input/input.c
+++ b/contrib/Chaco/input/input.c
@@ -4,6 +4,7 @@
 
 #include	<stdio.h>
 #include	<string.h>
+#include        "Gmsh_printf.h"
 #include	"defs.h"
 #include	"params.h"
 
diff --git a/contrib/Chaco/input/input_assign.c b/contrib/Chaco/input/input_assign.c
index 57eea91f21f8b74f296efff120e629e0bda4723c..0dbb14130dfa781aac6ed51093d57f5b70caf170 100644
--- a/contrib/Chaco/input/input_assign.c
+++ b/contrib/Chaco/input/input_assign.c
@@ -4,6 +4,7 @@
 
 #include	<stdio.h>
 #include        <string.h>
+#include        "Gmsh_printf.h"
 #include        "defs.h"
 
 static int input_assign_normal(), input_assign_inv();
diff --git a/contrib/Chaco/input/input_geom.c b/contrib/Chaco/input/input_geom.c
index 6dbcda0dd8dbc9c2710a706db64818a37ba55aea..f0b19304409b15aa7bde65f90fbbbe9804c37d54 100644
--- a/contrib/Chaco/input/input_geom.c
+++ b/contrib/Chaco/input/input_geom.c
@@ -4,6 +4,7 @@
 
 #include	<stdio.h>
 #include	<string.h>
+#include        "Gmsh_printf.h"
 #include	"defs.h"
 #include	"params.h"
 
diff --git a/contrib/Chaco/input/input_graph.c b/contrib/Chaco/input/input_graph.c
index ef97167c768c06f591ac0bef82d51f352a77ec30..4a3e161bbd0644ad75b1edf90b7204a31450a309 100644
--- a/contrib/Chaco/input/input_graph.c
+++ b/contrib/Chaco/input/input_graph.c
@@ -4,6 +4,7 @@
 
 #include	<stdio.h>
 #include	<string.h>
+#include        "Gmsh_printf.h"
 #include	"defs.h"
 
 
diff --git a/contrib/Chaco/input/input_graph_normal.c b/contrib/Chaco/input/input_graph_normal.c
index ef97167c768c06f591ac0bef82d51f352a77ec30..4a3e161bbd0644ad75b1edf90b7204a31450a309 100644
--- a/contrib/Chaco/input/input_graph_normal.c
+++ b/contrib/Chaco/input/input_graph_normal.c
@@ -4,6 +4,7 @@
 
 #include	<stdio.h>
 #include	<string.h>
+#include        "Gmsh_printf.h"
 #include	"defs.h"
 
 
diff --git a/contrib/Chaco/input/input_graph_scotch.c b/contrib/Chaco/input/input_graph_scotch.c
index 8a9543bc84767b2f5b229bf16fd99d19cf73e0d3..dc95cbfaace9fe276fef342aaeda74d52c51167c 100644
--- a/contrib/Chaco/input/input_graph_scotch.c
+++ b/contrib/Chaco/input/input_graph_scotch.c
@@ -4,6 +4,7 @@
 
 #include	<stdio.h>
 #include	<string.h>
+#include        "Gmsh_printf.h"
 #include	"defs.h"
 
 
diff --git a/contrib/Chaco/input/input_graph_vis.c b/contrib/Chaco/input/input_graph_vis.c
index 760c3769b0578f5b2585fc8f81da476e9da5769d..394085f34d20b3b77c2b1f5cccdc40e9e2c4c37e 100644
--- a/contrib/Chaco/input/input_graph_vis.c
+++ b/contrib/Chaco/input/input_graph_vis.c
@@ -4,6 +4,7 @@
 
 #include	<stdio.h>
 #include	<string.h>
+#include        "Gmsh_printf.h"
 #include	"defs.h"
 
 
diff --git a/contrib/Chaco/input/read_params.c b/contrib/Chaco/input/read_params.c
index 9b0d4fe424a78aa68ae6b2d1d2b99a838effda63..8be8b4243212e2f11901875aee259264ba02512a 100644
--- a/contrib/Chaco/input/read_params.c
+++ b/contrib/Chaco/input/read_params.c
@@ -5,6 +5,7 @@
 #include <stdio.h>
 #include <ctype.h>
 #include <string.h>
+#include "Gmsh_printf.h"
 #include "defs.h"
 #include "params.h"
 
diff --git a/contrib/Chaco/input/reflect_input.c b/contrib/Chaco/input/reflect_input.c
index 3c1bc1f0871aa7f7f2d5a3c6bb4b8a129fe956b2..414fb74b445b612c7da6a56c2d3363a3ec9b532c 100644
--- a/contrib/Chaco/input/reflect_input.c
+++ b/contrib/Chaco/input/reflect_input.c
@@ -4,6 +4,7 @@
 
 #include <stdio.h>
 #include <math.h>
+#include "Gmsh_printf.h"
 #include "params.h"
 #include "defs.h"
 
diff --git a/contrib/Chaco/internal/check_internal.c b/contrib/Chaco/internal/check_internal.c
index 3a088c68834cdb85257a333d78691f4167cf0e55..3c5488d661206ec6c2c3b3ffeaa131e830c52d9f 100644
--- a/contrib/Chaco/internal/check_internal.c
+++ b/contrib/Chaco/internal/check_internal.c
@@ -3,6 +3,7 @@
  * contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation. */
 
 #include	<stdio.h>
+#include        "Gmsh_printf.h"
 #include	"structs.h"
 #include	"defs.h"
 #include	"internal.h"
diff --git a/contrib/Chaco/internal/force_internal.c b/contrib/Chaco/internal/force_internal.c
index 9734011e351a592b1ee770c4d70ae27c8c85ccbe..3e919277cc9ab8e817e8f24aa52adc7dbd78aadb 100644
--- a/contrib/Chaco/internal/force_internal.c
+++ b/contrib/Chaco/internal/force_internal.c
@@ -3,6 +3,7 @@
  * contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation. */
 
 #include	<stdio.h>
+#include        "Gmsh_printf.h"
 #include	"structs.h"
 #include	"defs.h"
 #include	"internal.h"
diff --git a/contrib/Chaco/klspiff/coarsen_kl.c b/contrib/Chaco/klspiff/coarsen_kl.c
index ce3887b50676f58d192a62a98114475620e6cb8b..3292bffc919eaa7cbf511dc2fcf7ccd4c6099a1d 100644
--- a/contrib/Chaco/klspiff/coarsen_kl.c
+++ b/contrib/Chaco/klspiff/coarsen_kl.c
@@ -3,6 +3,7 @@
  * contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation. */
 
 #include <stdio.h>
+#include "Gmsh_printf.h"
 #include "params.h"
 #include "defs.h"
 #include "structs.h"
diff --git a/contrib/Chaco/klspiff/compress_ewgts.c b/contrib/Chaco/klspiff/compress_ewgts.c
index 00efc0f77d25996bb6ad7c38b2c647355bc07b78..0aa9417eece35b3c4f102606c87bafd81937ac0f 100644
--- a/contrib/Chaco/klspiff/compress_ewgts.c
+++ b/contrib/Chaco/klspiff/compress_ewgts.c
@@ -3,6 +3,7 @@
  * contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation. */
 
 #include	<stdio.h>
+#include        "Gmsh_printf.h"
 #include	"structs.h"
 #include	"params.h"
 #include	"defs.h"
diff --git a/contrib/Chaco/klspiff/kl_output.c b/contrib/Chaco/klspiff/kl_output.c
index f3abe6025d7aebf347e39111d93944a2344ed9cf..b86690d8fcde06438f271286f612a7b7b2433f34 100644
--- a/contrib/Chaco/klspiff/kl_output.c
+++ b/contrib/Chaco/klspiff/kl_output.c
@@ -3,6 +3,7 @@
  * contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation. */
 
 #include	<stdio.h>
+#include        "Gmsh_printf.h"
 #include	"structs.h"
 #include	"defs.h"
 
diff --git a/contrib/Chaco/klspiff/klspiff.c b/contrib/Chaco/klspiff/klspiff.c
index 4492cdc2e9ace31025fec9be4febc75274950470..a4be0ff500fed85c0b6935219c835f09f0907f2b 100644
--- a/contrib/Chaco/klspiff/klspiff.c
+++ b/contrib/Chaco/klspiff/klspiff.c
@@ -3,6 +3,7 @@
  * contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation. */
 
 #include	<stdio.h>
+#include        "Gmsh_printf.h"
 #include	"structs.h"
 #include	"params.h"
 #include	"defs.h"
diff --git a/contrib/Chaco/klspiff/nway_kl.c b/contrib/Chaco/klspiff/nway_kl.c
index 483feb1d7f50d86a330804a351c5712538efbc62..450b0eaf690f22fde9993e28e9265da9d6fa4d6a 100644
--- a/contrib/Chaco/klspiff/nway_kl.c
+++ b/contrib/Chaco/klspiff/nway_kl.c
@@ -4,6 +4,7 @@
 
 #include	<stdio.h>
 #include	<math.h>
+#include        "Gmsh_printf.h"
 #include	"structs.h"
 #include	"params.h"
 #include	"defs.h"
diff --git a/contrib/Chaco/klvspiff/bpm_improve.c b/contrib/Chaco/klvspiff/bpm_improve.c
index 3fec1de59a6f9df6289f7d1486053a52c0e3d439..8a4a024c98481073c6e1cf7fd31aec3c6aa5f9c8 100644
--- a/contrib/Chaco/klvspiff/bpm_improve.c
+++ b/contrib/Chaco/klvspiff/bpm_improve.c
@@ -3,6 +3,7 @@
  * contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation. */
 
 #include	<stdio.h>
+#include        "Gmsh_printf.h"
 #include	"structs.h"
 #include	"defs.h"
 
diff --git a/contrib/Chaco/klvspiff/coarsen_klv.c b/contrib/Chaco/klvspiff/coarsen_klv.c
index 7d59ad0fbafc16129c0c08d92d8313633a483459..15d79e1e57ca746a89d6c5fd5159bcb8ba512586 100644
--- a/contrib/Chaco/klvspiff/coarsen_klv.c
+++ b/contrib/Chaco/klvspiff/coarsen_klv.c
@@ -3,6 +3,7 @@
  * contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation. */
 
 #include <stdio.h>
+#include "Gmsh_printf.h"
 #include "params.h"
 #include "defs.h"
 #include "structs.h"
diff --git a/contrib/Chaco/klvspiff/countup_vtx_sep.c b/contrib/Chaco/klvspiff/countup_vtx_sep.c
index be0a6f529073615d12f9fa327dbafe62a8b3c852..b83d709ee132f31bcdb20e269509829f9d622022 100644
--- a/contrib/Chaco/klvspiff/countup_vtx_sep.c
+++ b/contrib/Chaco/klvspiff/countup_vtx_sep.c
@@ -3,6 +3,7 @@
  * contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation. */
 
 #include	<stdio.h>
+#include        "Gmsh_printf.h"
 #include	"structs.h"
 #include	"params.h"
 #include	"defs.h"
diff --git a/contrib/Chaco/klvspiff/flow.c b/contrib/Chaco/klvspiff/flow.c
index 64816485e83fc6fccf9829580db30e3c6adc3f9a..bc9baa14c5164c2c3d59c262a928e3dd10f513ee 100644
--- a/contrib/Chaco/klvspiff/flow.c
+++ b/contrib/Chaco/klvspiff/flow.c
@@ -4,6 +4,7 @@
 
 
 #include <stdio.h>
+#include "Gmsh_printf.h"
 #include "defs.h"
 
 /* STATUS:
diff --git a/contrib/Chaco/klvspiff/klvspiff.c b/contrib/Chaco/klvspiff/klvspiff.c
index ebf7604c70d86f19a1416191dd71b451f5864fa1..f1d560adaf5973c87d57fdfa022c315375377f07 100644
--- a/contrib/Chaco/klvspiff/klvspiff.c
+++ b/contrib/Chaco/klvspiff/klvspiff.c
@@ -3,6 +3,7 @@
  * contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation. */
 
 #include	<stdio.h>
+#include        "Gmsh_printf.h"
 #include	"structs.h"
 #include	"params.h"
 #include	"defs.h"
diff --git a/contrib/Chaco/klvspiff/make_bpgraph.c b/contrib/Chaco/klvspiff/make_bpgraph.c
index 41c8c4cd2555cb5e5f70406aeb5d7d5268afbfc8..d8b046d9b3797e035028a712adb1db5695e57f1b 100644
--- a/contrib/Chaco/klvspiff/make_bpgraph.c
+++ b/contrib/Chaco/klvspiff/make_bpgraph.c
@@ -3,6 +3,7 @@
  * contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation. */
 
 #include	<stdio.h>
+#include        "Gmsh_printf.h"
 #include	"structs.h"
 #include	"defs.h"
 
diff --git a/contrib/Chaco/klvspiff/matching.c b/contrib/Chaco/klvspiff/matching.c
index c7c5972bd613d773be72fff18293e184a82d20fc..aad56c9dcec91ca534f8e3c9e715c31e02198a82 100644
--- a/contrib/Chaco/klvspiff/matching.c
+++ b/contrib/Chaco/klvspiff/matching.c
@@ -6,6 +6,7 @@
    code provided by Ed Rothberg at SGI. */
 
 #include <stdio.h>
+#include "Gmsh_printf.h"
 
 #define  TRUE  1
 #define  FALSE 0
diff --git a/contrib/Chaco/klvspiff/nway_klv.c b/contrib/Chaco/klvspiff/nway_klv.c
index 9b60e2cf989f76972e080031aedc16af5442b271..8f7c938259d107ea708eb5193aad0a4ec9cd2ca3 100644
--- a/contrib/Chaco/klvspiff/nway_klv.c
+++ b/contrib/Chaco/klvspiff/nway_klv.c
@@ -4,6 +4,7 @@
 
 #include	<stdio.h>
 #include	<math.h>
+#include        "Gmsh_printf.h"
 #include	"structs.h"
 #include	"defs.h"
 
diff --git a/contrib/Chaco/main/interface.c b/contrib/Chaco/main/interface.c
index 8b7125c271be623867f463ffb03628a6cbdb160a..6f6cac7f6a837b0ff8d42ade67148662a7cf2a44 100644
--- a/contrib/Chaco/main/interface.c
+++ b/contrib/Chaco/main/interface.c
@@ -3,6 +3,7 @@
  * contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation. */
 
 #include <stdio.h>
+#include "Gmsh_printf.h"
 #include "defs.h"
 #include "structs.h"
 
@@ -13,7 +14,12 @@ int       interface(nvtxs, start, adjacency, vwgts, ewgts, x, y, z,
 		              assignment,
 		              architecture, ndims_tot, mesh_dims, goal,
 		              global_method, local_method, rqi_flag, vmax, ndims,
-		              eigtol, seed)
+		              eigtol, seed
+/* Gmsh - extra parameters in the interface */
+                    , refine_partition, internal_vertices, refine_map,
+                    terminal_propogation
+/* Gmsh - end */
+                                          )
 int       nvtxs;		/* number of vertices in full graph */
 int      *start;		/* start of edge list for each vertex */
 int      *adjacency;		/* edge list data */
@@ -34,6 +40,13 @@ int       vmax;			/* how many vertices to coarsen down to? */
 int       ndims;		/* number of eigenvectors (2^d sets) */
 double    eigtol;		/* tolerance on eigenvectors */
 long      seed;			/* for random graph mutations */
+/* Gmsh - get some extra parameters through the interface.  These are identical
+ * to those in the parameters file */
+int       refine_partition;
+int       internal_vertices;
+int       refine_map;
+int       terminal_propogation;
+/* Gmsh - end */
 {
     extern char *PARAMS_FILENAME;	/* name of file with parameter updates */
     extern int MAKE_VWGTS;	/* make vertex weights equal to degrees? */
@@ -41,6 +54,10 @@ long      seed;			/* for random graph mutations */
     extern int FREE_GRAPH;	/* free graph data structure after reformat? */
     extern int DEBUG_PARAMS;	/* debug flag for reading parameters */
     extern int DEBUG_TRACE;	/* trace main execution path */
+    extern int REFINE_PARTITION;  /* # passes post-processing KL */
+    extern int INTERNAL_VERTICES; /* post-process to increase internal nodes */
+    extern int REFINE_MAP;	  /* greedy post-processing to reduce hops? */
+    extern int TERM_PROP;	  /* perform terminal propagation */
     extern double start_time;	/* time routine is entered */
     extern double reformat_time;/* time spent reformatting graph */
     FILE     *params_file;	/* file for reading new parameters */
@@ -70,15 +87,25 @@ long      seed;			/* for random graph mutations */
     graph = NULL;
     coords = NULL;
 
-    if (!Using_Main) {		/* If not using main, need to read parameters file. */
-	start_time = seconds();
-	params_file = fopen(PARAMS_FILENAME, "r");
-	if (params_file == NULL && DEBUG_PARAMS > 1) {
-	    printf("Parameter file `%s' not found; using default parameters.\n",
-		   PARAMS_FILENAME);
-	}
-	read_params(params_file);
-    }
+/* Gmsh - disable this for now.  It would be interesting to let someone include
+ * it though */
+/*     if (!Using_Main) {		/\* If not using main, need to read parameters file. *\/ */
+/* 	start_time = seconds(); */
+/* 	params_file = fopen(PARAMS_FILENAME, "r"); */
+/* 	if (params_file == NULL && DEBUG_PARAMS > 1) { */
+/* 	    printf("Parameter file `%s' not found; using default parameters.\n", */
+/* 		   PARAMS_FILENAME); */
+/* 	} */
+/* 	read_params(params_file); */
+/*     } */
+/* Gmsh - end */
+/* Gmsh - override some parameters */
+    FREE_GRAPH = 0;
+    REFINE_PARTITION = refine_partition;
+    INTERNAL_VERTICES = internal_vertices;
+    REFINE_MAP = refine_map;
+    TERM_PROP = terminal_propogation;
+/* Gmsh - end */
 
     if (goal == NULL) {	/* If not passed in, default goals have equal set sizes. */
 	default_goal = TRUE;
diff --git a/contrib/Chaco/misc/count.c b/contrib/Chaco/misc/count.c
index 92f5c05892802389c96bcd4ff54cf1b572a4eaa8..d80269d2fe2ca6ec614697d438541ad2174866a6 100644
--- a/contrib/Chaco/misc/count.c
+++ b/contrib/Chaco/misc/count.c
@@ -3,6 +3,7 @@
  * contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation. */
 
 #include	<stdio.h>
+#include        "Gmsh_printf.h"
 #include	"params.h"
 #include	"structs.h"
 #include	"defs.h"
diff --git a/contrib/Chaco/misc/countup_cube.c b/contrib/Chaco/misc/countup_cube.c
index 4998c8d707a58a1ccc927866d497c357007348dd..4148c1f3cc961d46098ac82aeb99fcc92a2c719f 100644
--- a/contrib/Chaco/misc/countup_cube.c
+++ b/contrib/Chaco/misc/countup_cube.c
@@ -3,6 +3,7 @@
  * contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation. */
 
 #include <stdio.h>
+#include "Gmsh_printf.h"
 #include "defs.h"
 #include "structs.h"
 
diff --git a/contrib/Chaco/misc/countup_mesh.c b/contrib/Chaco/misc/countup_mesh.c
index 9eb656256fcf1109b7d3ee5dae9bc1f79cb0de78..5d1ae7171ae11618b59833384a4e2f12e1723a8b 100644
--- a/contrib/Chaco/misc/countup_mesh.c
+++ b/contrib/Chaco/misc/countup_mesh.c
@@ -3,6 +3,7 @@
  * contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation. */
 
 #include <stdio.h>
+#include "Gmsh_printf.h"
 #include "defs.h"
 #include "structs.h"
 
diff --git a/contrib/Chaco/misc/sequence.c b/contrib/Chaco/misc/sequence.c
index 9e63c1c314d774dcf9f1f3656f79655467e5a126..cb2dae3903ef05871d3a62f1b8d61704224d6473 100644
--- a/contrib/Chaco/misc/sequence.c
+++ b/contrib/Chaco/misc/sequence.c
@@ -4,6 +4,7 @@
 
 #include <stdio.h>
 #include <string.h>
+#include "Gmsh_printf.h"
 #include "params.h"
 #include "defs.h"
 #include "structs.h"
diff --git a/contrib/Chaco/misc/simple_part.c b/contrib/Chaco/misc/simple_part.c
index 12479e39bd664a05384357059df0dd4945063da4..264a35a1500e87eba5b0a761d43d6299355b4463 100644
--- a/contrib/Chaco/misc/simple_part.c
+++ b/contrib/Chaco/misc/simple_part.c
@@ -3,6 +3,7 @@
  * contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation. */
 
 #include	<stdio.h>
+#include        "Gmsh_printf.h"
 #include	"structs.h"
 #include	"defs.h"
 #include	"params.h"
diff --git a/contrib/Chaco/misc/time_kernels.c b/contrib/Chaco/misc/time_kernels.c
index 4713ee42ff7f53e6f44b3a9a4e174f6814d0ec78..cd176963ca0cb95ffb73f766ec183ee50fee7ee7 100644
--- a/contrib/Chaco/misc/time_kernels.c
+++ b/contrib/Chaco/misc/time_kernels.c
@@ -4,6 +4,7 @@
 
 #include	<stdio.h>
 #include	<math.h>
+#include        "Gmsh_printf.h"
 #include	"defs.h"
 #include	"structs.h"
 
diff --git a/contrib/Chaco/optimize/opt2d.c b/contrib/Chaco/optimize/opt2d.c
index b1d829af052ecaefe98a4ea05dbbb453c1bf995d..1de8c0937b2ba116ed1653d4778bd52351c79bf1 100644
--- a/contrib/Chaco/optimize/opt2d.c
+++ b/contrib/Chaco/optimize/opt2d.c
@@ -4,6 +4,7 @@
 
 #include	<stdio.h>
 #include	<math.h>
+#include        "Gmsh_printf.h"
 #include	"defs.h"
 #include	"structs.h"
 
diff --git a/contrib/Chaco/optimize/opt3d.c b/contrib/Chaco/optimize/opt3d.c
index 41f25b901987c561fa9c72a8a40aa9ffe7450f85..eff8d7efed7ee0355693921f28c34a5dcc5c6598 100644
--- a/contrib/Chaco/optimize/opt3d.c
+++ b/contrib/Chaco/optimize/opt3d.c
@@ -4,6 +4,7 @@
 
 #include	<stdio.h>
 #include	<math.h>
+#include        "Gmsh_printf.h"
 #include	"structs.h"
 #include	"defs.h"
 
diff --git a/contrib/Chaco/submain/balance.c b/contrib/Chaco/submain/balance.c
index dad4fe0904d622f245e5687fca33e93e0a284fea..20d2f6ff014819460c357c69907b9a856bc71885 100644
--- a/contrib/Chaco/submain/balance.c
+++ b/contrib/Chaco/submain/balance.c
@@ -3,6 +3,7 @@
  * contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation. */
 
 #include <stdio.h>
+#include "Gmsh_printf.h"
 #include "params.h"
 #include "defs.h"
 #include "structs.h"
diff --git a/contrib/Chaco/submain/divide.c b/contrib/Chaco/submain/divide.c
index 95adc1a06248bb3e315b4ca435c2d74dd2a5d5af..732fd08b77b73eee9430edaba14defca2b91f7ac 100644
--- a/contrib/Chaco/submain/divide.c
+++ b/contrib/Chaco/submain/divide.c
@@ -3,6 +3,7 @@
  * contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation. */
 
 #include <stdio.h>
+#include "Gmsh_printf.h"
 #include "params.h"
 #include "defs.h"
 #include "structs.h"
diff --git a/contrib/Chaco/submain/submain.c b/contrib/Chaco/submain/submain.c
index d9d2ece0a83b42a17ade35242776f0b61deea190..24d9155c0008e9a9f68173b77c589f308f5c6973 100644
--- a/contrib/Chaco/submain/submain.c
+++ b/contrib/Chaco/submain/submain.c
@@ -5,6 +5,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <math.h>
+#include "Gmsh_printf.h"
 #include "defs.h"
 #include "params.h"
 #include "structs.h"
diff --git a/contrib/Chaco/util/affirm.c b/contrib/Chaco/util/affirm.c
index bd5f4173ed83372c6e6155bcb226c81e6078307e..c1b802ce29e6f7c530f434eedb0732e670359fbb 100644
--- a/contrib/Chaco/util/affirm.c
+++ b/contrib/Chaco/util/affirm.c
@@ -5,6 +5,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <ctype.h>
+#include "Gmsh_printf.h"
 #include "defs.h"
 
 /* Record a return TRUE if answer is yes, FALSE if no. */
diff --git a/contrib/Chaco/util/bail.c b/contrib/Chaco/util/bail.c
index 2e27443144c440e089b493401d49b5b49b7a6294..42dab7911f6281997417addcb878193dc0d69402 100644
--- a/contrib/Chaco/util/bail.c
+++ b/contrib/Chaco/util/bail.c
@@ -4,6 +4,8 @@
 
 #include	<stdio.h>
 #include	<string.h>
+#include        "Gmsh_printf.h"
+#include        "Gmsh_exit.h"
 
 /* Wrapper for exit() - print message and exit with status code. Exit code
    of 0 indicates normal termination. Exit code of 1 indicates early 
@@ -22,5 +24,6 @@ int       status;
             fprintf(Output_File, "%s\n", msg);
 	}
     }
-    exit(status);
+/*     exit(status); */
+    Gmsh_exit();
 }
diff --git a/contrib/Chaco/util/checkpnt.c b/contrib/Chaco/util/checkpnt.c
index 5b7a08f1c12fdad2fadd9d12acf70a4786d0bccb..60fb5683bb792cc5fedc40769f933af716a5dd89 100644
--- a/contrib/Chaco/util/checkpnt.c
+++ b/contrib/Chaco/util/checkpnt.c
@@ -4,6 +4,7 @@
 
 #include	<stdio.h>
 #include	<string.h>
+#include        "Gmsh_printf.h"
 
 /* Debug break point. */
 void      checkpnt(tag)
diff --git a/contrib/Chaco/util/doubleout.c b/contrib/Chaco/util/doubleout.c
index ef94d9a668ecd2e87afd6eb3df174e987704f2ba..dd1b6d1a66d56b18cd0ffc7383dcdd96c001d89a 100644
--- a/contrib/Chaco/util/doubleout.c
+++ b/contrib/Chaco/util/doubleout.c
@@ -3,6 +3,7 @@
  * contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation. */
 
 #include  <stdio.h>
+#include  "Gmsh_printf.h"
 
 /* Print a double precision number with filtering format to screen. */
 void      doubleout(number, mode)
diff --git a/contrib/Chaco/util/mergesort.c b/contrib/Chaco/util/mergesort.c
index 11690259c86410b6851a1231e5d9403d7fd6c765..1ecef03747ec755bd34783c40676de2c8cd58dc9 100644
--- a/contrib/Chaco/util/mergesort.c
+++ b/contrib/Chaco/util/mergesort.c
@@ -3,6 +3,7 @@
  * contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation. */
 
 #include	<stdio.h>
+#include        "Gmsh_printf.h"
 #include	"defs.h"
 
 
diff --git a/contrib/Chaco/util/smalloc.c b/contrib/Chaco/util/smalloc.c
index 3edc1fb1bfd331f3bb3dc5ff8c2555b53aacd511..3d146a0aac6dc0bd8a3b452445ddf38a55a7c89d 100644
--- a/contrib/Chaco/util/smalloc.c
+++ b/contrib/Chaco/util/smalloc.c
@@ -4,6 +4,7 @@
 
 #include <stdio.h>
 #include <malloc.h>
+#include "Gmsh_printf.h"
 
 static int nmalloc = 0;		/* number of calls to malloc */
 static int nfree = 0;		/* number of calls to free */
diff --git a/contrib/Chaco/util/strout.c b/contrib/Chaco/util/strout.c
index 10ea5a400172e20823f430e4721abd582a4d4ee0..70665c13d718e8ac400119b5d5d96ca107eb5e24 100644
--- a/contrib/Chaco/util/strout.c
+++ b/contrib/Chaco/util/strout.c
@@ -4,6 +4,7 @@
 
 #include	<stdio.h>
 #include	<string.h>
+#include        "Gmsh_printf.h"
 
 /* Wrapper for a printf statement with a string as only arg.
    Prints to screen and to output file if there is one. */