diff --git a/Common/CommandLine.cpp b/Common/CommandLine.cpp
index 5ce79b517c0840b015ecb56056e2bc22cb262d02..ab2f4e83dac45fb97914c9f9bf7f4c0fc7d67b3f 100644
--- a/Common/CommandLine.cpp
+++ b/Common/CommandLine.cpp
@@ -1,4 +1,4 @@
-// $Id: CommandLine.cpp,v 1.102 2007-08-21 19:05:38 geuzaine Exp $
+// $Id: CommandLine.cpp,v 1.103 2007-09-04 13:47:00 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
@@ -90,6 +90,7 @@ void Print_Usage(char *name){
   Msg(DIRECT, "  -optimize_hom         Optimize higher order meshes (in 2D)");
   Msg(DIRECT, "  -clscale float        Set characteristic length scaling factor");
   Msg(DIRECT, "  -clcurv               Compute characteristic lengths from curvatures");
+  Msg(DIRECT, "  -epslc1d              Set the accuracy of the evaluation of the LCFIELD for 1D mesh");
   Msg(DIRECT, "  -rand float           Set random perturbation factor");
   Msg(DIRECT, "  -bgm file             Load background mesh from file");
   Msg(DIRECT, "  -constrain            Constrain background mesh with characteristic lengths");
@@ -355,6 +356,21 @@ void Get_Options(int argc, char *argv[])
           exit(1);
         }
       }
+      else if(!strcmp(argv[i] + 1, "epslc1d")) {
+        i++;
+        if(argv[i] != NULL) {
+          CTX.mesh.lc_integration_precision = atof(argv[i++]);
+          if(CTX.mesh.lc_integration_precision <= 0.0) {
+            fprintf(stderr, ERROR_STR
+                    "Integration Accuraci for evaluation of 1D LC FIELD must be > 0\n");
+            exit(1);
+          }
+        }
+        else {
+          fprintf(stderr, ERROR_STR "Missing number\n");
+          exit(1);
+        }
+      }
       else if(!strcmp(argv[i] + 1, "clcurv")) {
         CTX.mesh.lc_from_curvature = 1;
         i++;
diff --git a/Common/Context.cpp b/Common/Context.cpp
index 558f53ac1ea350c1b451a9e64fc572a1f4333496..e2f5bc2d737530851adeade4ec6f631b9dede393 100644
--- a/Common/Context.cpp
+++ b/Common/Context.cpp
@@ -1,4 +1,4 @@
-// $Id: Context.cpp,v 1.58 2006-11-27 22:22:07 geuzaine Exp $
+// $Id: Context.cpp,v 1.59 2007-09-04 13:47:00 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/Common/Context.h b/Common/Context.h
index 97e0d304ac09df8a3a770700d574568a70e9609f..563164d13fde3eed33a593fd798a99911fdbdc4f 100644
--- a/Common/Context.h
+++ b/Common/Context.h
@@ -175,7 +175,7 @@ public :
     int optimize;
     int quality_type, label_type;
     double quality_inf, quality_sup, radius_inf, radius_sup;
-    double scaling_factor, lc_factor, rand_factor;
+    double scaling_factor, lc_factor, rand_factor, lc_integration_precision;
     int dual;
     int light, light_two_side, light_lines;
     int format, nb_smoothing, algo2d, algo3d, algo_recombine;
diff --git a/Common/DefaultOptions.h b/Common/DefaultOptions.h
index 20ec21abbc071d022b08b46e62ba903defecf802..56bdd366965c124408bc7bca8fa87824f97cc9ce 100644
--- a/Common/DefaultOptions.h
+++ b/Common/DefaultOptions.h
@@ -1023,6 +1023,8 @@ StringXNumber MeshOptions_Number[] = {
     "Create incomplete second order elements? (8-node quads, 20-node hexas, etc.)" },
   { F|O, "SecondOrderLinear" , opt_mesh_second_order_linear , 0. ,
     "Should second order vertices simply be created by linear interpolation?" },
+  { F|O, "LcIntegrationPrecision" , opt_mesh_lc_integration_precision, 1.e-9 ,
+    "Accuracy of evaluation of the LC field for 1D mesh generation" },
   { F|O, "Smoothing" , opt_mesh_nb_smoothing , 1. ,
     "Number of smoothing steps applied to the final mesh" },
   { F|O, "SmoothNormals" , opt_mesh_smooth_normals , 0. , 
diff --git a/Common/License.cpp b/Common/License.cpp
index c1c22f0f32bc6f1cdf5b820b0c92cb3f5d59a481..8a0ec8553e8eeea33e64d042bccb74ef4244f680 100644
--- a/Common/License.cpp
+++ b/Common/License.cpp
@@ -1,4 +1,4 @@
-// $Id: License.cpp,v 1.9 2007-01-28 17:26:53 geuzaine Exp $
+// $Id: License.cpp,v 1.10 2007-09-04 13:47:00 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/Common/Makefile b/Common/Makefile
index c8f9f6631d198c1e528c0997d88ca621d76c7073..e328f1649ef26ea076a54ef7f2ec64d4031e8c58 100644
--- a/Common/Makefile
+++ b/Common/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.137 2007-08-27 13:46:21 geuzaine Exp $
+# $Id: Makefile,v 1.138 2007-09-04 13:47:00 remacle Exp $
 #
 # Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 #
@@ -67,7 +67,41 @@ Context.o: Context.cpp Gmsh.h Message.h ../DataStr/Malloc.h \
   DefaultOptions.h GmshDefines.h Options.h ../Post/Views.h \
   ../Post/ColorTable.h ../Common/VertexArray.h ../Geo/SVector3.h \
   ../Geo/SPoint3.h ../Common/SmoothData.h ../Post/AdaptiveViews.h \
-  ../Common/GmshMatrix.h Trackball.h
+  ../Common/GmshMatrix.h /sw/include/gsl/gsl_linalg.h \
+  /sw/include/gsl/gsl_mode.h /sw/include/gsl/gsl_permutation.h \
+  /sw/include/gsl/gsl_types.h /sw/include/gsl/gsl_errno.h \
+  /sw/include/gsl/gsl_check_range.h /sw/include/gsl/gsl_vector.h \
+  /sw/include/gsl/gsl_vector_complex_long_double.h \
+  /sw/include/gsl/gsl_complex.h /sw/include/gsl/gsl_vector_long_double.h \
+  /sw/include/gsl/gsl_block_long_double.h \
+  /sw/include/gsl/gsl_vector_complex.h \
+  /sw/include/gsl/gsl_block_complex_long_double.h \
+  /sw/include/gsl/gsl_vector_complex_double.h \
+  /sw/include/gsl/gsl_vector_double.h /sw/include/gsl/gsl_block_double.h \
+  /sw/include/gsl/gsl_block_complex_double.h \
+  /sw/include/gsl/gsl_vector_complex_float.h \
+  /sw/include/gsl/gsl_vector_float.h /sw/include/gsl/gsl_block_float.h \
+  /sw/include/gsl/gsl_block_complex_float.h \
+  /sw/include/gsl/gsl_vector_ulong.h /sw/include/gsl/gsl_block_ulong.h \
+  /sw/include/gsl/gsl_vector_long.h /sw/include/gsl/gsl_block_long.h \
+  /sw/include/gsl/gsl_vector_uint.h /sw/include/gsl/gsl_block_uint.h \
+  /sw/include/gsl/gsl_vector_int.h /sw/include/gsl/gsl_block_int.h \
+  /sw/include/gsl/gsl_vector_ushort.h /sw/include/gsl/gsl_block_ushort.h \
+  /sw/include/gsl/gsl_vector_short.h /sw/include/gsl/gsl_block_short.h \
+  /sw/include/gsl/gsl_vector_uchar.h /sw/include/gsl/gsl_block_uchar.h \
+  /sw/include/gsl/gsl_vector_char.h /sw/include/gsl/gsl_block_char.h \
+  /sw/include/gsl/gsl_matrix.h \
+  /sw/include/gsl/gsl_matrix_complex_long_double.h \
+  /sw/include/gsl/gsl_matrix_complex_double.h \
+  /sw/include/gsl/gsl_matrix_complex_float.h \
+  /sw/include/gsl/gsl_matrix_long_double.h \
+  /sw/include/gsl/gsl_matrix_double.h /sw/include/gsl/gsl_matrix_float.h \
+  /sw/include/gsl/gsl_matrix_ulong.h /sw/include/gsl/gsl_matrix_long.h \
+  /sw/include/gsl/gsl_matrix_uint.h /sw/include/gsl/gsl_matrix_int.h \
+  /sw/include/gsl/gsl_matrix_ushort.h /sw/include/gsl/gsl_matrix_short.h \
+  /sw/include/gsl/gsl_matrix_uchar.h /sw/include/gsl/gsl_matrix_char.h \
+  /sw/include/gsl/gsl_blas.h /sw/include/gsl/gsl_blas_types.h \
+  /sw/include/gsl/gsl_cblas.h Trackball.h
 Octree.o: Octree.cpp Octree.h OctreeInternals.h
 OctreeInternals.o: OctreeInternals.cpp Message.h OctreeInternals.h
 Options.o: Options.cpp Gmsh.h Message.h ../DataStr/Malloc.h \
@@ -79,7 +113,41 @@ Options.o: Options.cpp Gmsh.h Message.h ../DataStr/Malloc.h \
   ../Common/Message.h ../Post/Views.h ../Post/ColorTable.h \
   ../Common/VertexArray.h ../Geo/SVector3.h ../Geo/SPoint3.h \
   ../Common/SmoothData.h ../Numeric/Numeric.h ../Post/AdaptiveViews.h \
-  ../Common/GmshMatrix.h ../Fltk/Solvers.h ../Fltk/GUI.h \
+  ../Common/GmshMatrix.h /sw/include/gsl/gsl_linalg.h \
+  /sw/include/gsl/gsl_mode.h /sw/include/gsl/gsl_permutation.h \
+  /sw/include/gsl/gsl_types.h /sw/include/gsl/gsl_errno.h \
+  /sw/include/gsl/gsl_check_range.h /sw/include/gsl/gsl_vector.h \
+  /sw/include/gsl/gsl_vector_complex_long_double.h \
+  /sw/include/gsl/gsl_complex.h /sw/include/gsl/gsl_vector_long_double.h \
+  /sw/include/gsl/gsl_block_long_double.h \
+  /sw/include/gsl/gsl_vector_complex.h \
+  /sw/include/gsl/gsl_block_complex_long_double.h \
+  /sw/include/gsl/gsl_vector_complex_double.h \
+  /sw/include/gsl/gsl_vector_double.h /sw/include/gsl/gsl_block_double.h \
+  /sw/include/gsl/gsl_block_complex_double.h \
+  /sw/include/gsl/gsl_vector_complex_float.h \
+  /sw/include/gsl/gsl_vector_float.h /sw/include/gsl/gsl_block_float.h \
+  /sw/include/gsl/gsl_block_complex_float.h \
+  /sw/include/gsl/gsl_vector_ulong.h /sw/include/gsl/gsl_block_ulong.h \
+  /sw/include/gsl/gsl_vector_long.h /sw/include/gsl/gsl_block_long.h \
+  /sw/include/gsl/gsl_vector_uint.h /sw/include/gsl/gsl_block_uint.h \
+  /sw/include/gsl/gsl_vector_int.h /sw/include/gsl/gsl_block_int.h \
+  /sw/include/gsl/gsl_vector_ushort.h /sw/include/gsl/gsl_block_ushort.h \
+  /sw/include/gsl/gsl_vector_short.h /sw/include/gsl/gsl_block_short.h \
+  /sw/include/gsl/gsl_vector_uchar.h /sw/include/gsl/gsl_block_uchar.h \
+  /sw/include/gsl/gsl_vector_char.h /sw/include/gsl/gsl_block_char.h \
+  /sw/include/gsl/gsl_matrix.h \
+  /sw/include/gsl/gsl_matrix_complex_long_double.h \
+  /sw/include/gsl/gsl_matrix_complex_double.h \
+  /sw/include/gsl/gsl_matrix_complex_float.h \
+  /sw/include/gsl/gsl_matrix_long_double.h \
+  /sw/include/gsl/gsl_matrix_double.h /sw/include/gsl/gsl_matrix_float.h \
+  /sw/include/gsl/gsl_matrix_ulong.h /sw/include/gsl/gsl_matrix_long.h \
+  /sw/include/gsl/gsl_matrix_uint.h /sw/include/gsl/gsl_matrix_int.h \
+  /sw/include/gsl/gsl_matrix_ushort.h /sw/include/gsl/gsl_matrix_short.h \
+  /sw/include/gsl/gsl_matrix_uchar.h /sw/include/gsl/gsl_matrix_char.h \
+  /sw/include/gsl/gsl_blas.h /sw/include/gsl/gsl_blas_types.h \
+  /sw/include/gsl/gsl_cblas.h ../Fltk/Solvers.h ../Fltk/GUI.h \
   ../Fltk/Opengl_Window.h ../Fltk/Colorbar_Window.h ../Common/GmshUI.h \
   ../Fltk/Popup_Button.h ../Fltk/SpherePosition_Widget.h
 CommandLine.o: CommandLine.cpp Gmsh.h Message.h ../DataStr/Malloc.h \
@@ -91,19 +159,54 @@ CommandLine.o: CommandLine.cpp Gmsh.h Message.h ../DataStr/Malloc.h \
   ../Geo/SPoint3.h ../Geo/SBoundingBox3d.h ../Geo/SPoint3.h \
   ../Geo/SPoint2.h ../Geo/ExtrudeParams.h ../Common/SmoothData.h \
   ../Post/Views.h ../Post/ColorTable.h ../Common/VertexArray.h \
-  ../Post/AdaptiveViews.h ../Common/GmshMatrix.h ../Parser/OpenFile.h \
-  ../Parser/CreateFile.h ../Parser/Parser.h ../Geo/GModel.h \
-  ../Geo/GVertex.h ../Geo/GEntity.h ../Geo/Range.h ../Geo/SPoint3.h \
-  ../Geo/SBoundingBox3d.h ../Geo/MVertex.h ../Geo/SPoint3.h \
-  ../Geo/GPoint.h ../Geo/SPoint2.h ../Geo/GEdge.h ../Geo/GEntity.h \
-  ../Geo/GVertex.h ../Geo/SVector3.h ../Geo/SPoint3.h ../Geo/SPoint2.h \
-  ../Geo/MElement.h ../Geo/MVertex.h ../Geo/MEdge.h ../Geo/MVertex.h \
-  ../Geo/SVector3.h ../Common/Hash.h ../Geo/MFace.h ../Geo/MVertex.h \
-  ../Geo/SVector3.h ../Common/Context.h ../Geo/ExtrudeParams.h \
-  ../Geo/GFace.h ../Geo/GPoint.h ../Geo/GEntity.h ../Geo/GEdgeLoop.h \
-  ../Geo/GEdge.h ../Geo/MElement.h ../Geo/SPoint2.h ../Geo/SVector3.h \
-  ../Geo/Pair.h ../Geo/ExtrudeParams.h ../Geo/GRegion.h ../Geo/GEntity.h \
-  ../Geo/MElement.h ../Geo/ExtrudeParams.h ../Geo/SBoundingBox3d.h OS.h
+  ../Post/AdaptiveViews.h ../Common/GmshMatrix.h \
+  /sw/include/gsl/gsl_linalg.h /sw/include/gsl/gsl_mode.h \
+  /sw/include/gsl/gsl_permutation.h /sw/include/gsl/gsl_types.h \
+  /sw/include/gsl/gsl_errno.h /sw/include/gsl/gsl_check_range.h \
+  /sw/include/gsl/gsl_vector.h \
+  /sw/include/gsl/gsl_vector_complex_long_double.h \
+  /sw/include/gsl/gsl_complex.h /sw/include/gsl/gsl_vector_long_double.h \
+  /sw/include/gsl/gsl_block_long_double.h \
+  /sw/include/gsl/gsl_vector_complex.h \
+  /sw/include/gsl/gsl_block_complex_long_double.h \
+  /sw/include/gsl/gsl_vector_complex_double.h \
+  /sw/include/gsl/gsl_vector_double.h /sw/include/gsl/gsl_block_double.h \
+  /sw/include/gsl/gsl_block_complex_double.h \
+  /sw/include/gsl/gsl_vector_complex_float.h \
+  /sw/include/gsl/gsl_vector_float.h /sw/include/gsl/gsl_block_float.h \
+  /sw/include/gsl/gsl_block_complex_float.h \
+  /sw/include/gsl/gsl_vector_ulong.h /sw/include/gsl/gsl_block_ulong.h \
+  /sw/include/gsl/gsl_vector_long.h /sw/include/gsl/gsl_block_long.h \
+  /sw/include/gsl/gsl_vector_uint.h /sw/include/gsl/gsl_block_uint.h \
+  /sw/include/gsl/gsl_vector_int.h /sw/include/gsl/gsl_block_int.h \
+  /sw/include/gsl/gsl_vector_ushort.h /sw/include/gsl/gsl_block_ushort.h \
+  /sw/include/gsl/gsl_vector_short.h /sw/include/gsl/gsl_block_short.h \
+  /sw/include/gsl/gsl_vector_uchar.h /sw/include/gsl/gsl_block_uchar.h \
+  /sw/include/gsl/gsl_vector_char.h /sw/include/gsl/gsl_block_char.h \
+  /sw/include/gsl/gsl_matrix.h \
+  /sw/include/gsl/gsl_matrix_complex_long_double.h \
+  /sw/include/gsl/gsl_matrix_complex_double.h \
+  /sw/include/gsl/gsl_matrix_complex_float.h \
+  /sw/include/gsl/gsl_matrix_long_double.h \
+  /sw/include/gsl/gsl_matrix_double.h /sw/include/gsl/gsl_matrix_float.h \
+  /sw/include/gsl/gsl_matrix_ulong.h /sw/include/gsl/gsl_matrix_long.h \
+  /sw/include/gsl/gsl_matrix_uint.h /sw/include/gsl/gsl_matrix_int.h \
+  /sw/include/gsl/gsl_matrix_ushort.h /sw/include/gsl/gsl_matrix_short.h \
+  /sw/include/gsl/gsl_matrix_uchar.h /sw/include/gsl/gsl_matrix_char.h \
+  /sw/include/gsl/gsl_blas.h /sw/include/gsl/gsl_blas_types.h \
+  /sw/include/gsl/gsl_cblas.h ../Parser/OpenFile.h ../Parser/CreateFile.h \
+  ../Parser/Parser.h ../Geo/GModel.h ../Geo/GVertex.h ../Geo/GEntity.h \
+  ../Geo/Range.h ../Geo/SPoint3.h ../Geo/SBoundingBox3d.h \
+  ../Geo/MVertex.h ../Geo/SPoint3.h ../Geo/GPoint.h ../Geo/SPoint2.h \
+  ../Geo/GEdge.h ../Geo/GEntity.h ../Geo/GVertex.h ../Geo/SVector3.h \
+  ../Geo/SPoint3.h ../Geo/SPoint2.h ../Geo/MElement.h ../Geo/MVertex.h \
+  ../Geo/MEdge.h ../Geo/MVertex.h ../Geo/SVector3.h ../Common/Hash.h \
+  ../Geo/MFace.h ../Geo/MVertex.h ../Geo/SVector3.h ../Common/Context.h \
+  ../Geo/ExtrudeParams.h ../Geo/GFace.h ../Geo/GPoint.h ../Geo/GEntity.h \
+  ../Geo/GEdgeLoop.h ../Geo/GEdge.h ../Geo/MElement.h ../Geo/SPoint2.h \
+  ../Geo/SVector3.h ../Geo/Pair.h ../Geo/ExtrudeParams.h ../Geo/GRegion.h \
+  ../Geo/GEntity.h ../Geo/MElement.h ../Geo/ExtrudeParams.h \
+  ../Geo/SBoundingBox3d.h OS.h
 OS.o: OS.cpp Message.h
 Visibility.o: Visibility.cpp Visibility.h GmshDefines.h ../Geo/GVertex.h \
   ../Geo/GEntity.h ../Geo/Range.h ../Geo/SPoint3.h \
diff --git a/Common/OS.cpp b/Common/OS.cpp
index e6ad140aa973de7223820ca7b6af336116912056..410bae79ef24ee48b835bb22290f492154b4915c 100644
--- a/Common/OS.cpp
+++ b/Common/OS.cpp
@@ -1,4 +1,4 @@
-// $Id: OS.cpp,v 1.8 2007-05-23 15:35:33 geuzaine Exp $
+// $Id: OS.cpp,v 1.9 2007-09-04 13:47:00 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/Common/Octree.cpp b/Common/Octree.cpp
index b14d033a716840c494c9ef9fcbb06394b919704d..630dc3be1d33063cee45fdd58b772c146843f18c 100644
--- a/Common/Octree.cpp
+++ b/Common/Octree.cpp
@@ -1,4 +1,4 @@
-// $Id: Octree.cpp,v 1.2 2006-11-27 22:22:07 geuzaine Exp $
+// $Id: Octree.cpp,v 1.3 2007-09-04 13:47:00 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/Common/OctreeInternals.cpp b/Common/OctreeInternals.cpp
index 1916e2437d9d9d8a6159bbbb275e835a638437ae..b731415ce707d0a355b9513a3d3284d323460b2d 100644
--- a/Common/OctreeInternals.cpp
+++ b/Common/OctreeInternals.cpp
@@ -1,4 +1,4 @@
-// $Id: OctreeInternals.cpp,v 1.2 2006-11-27 22:22:07 geuzaine Exp $
+// $Id: OctreeInternals.cpp,v 1.3 2007-09-04 13:47:00 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/Common/Options.cpp b/Common/Options.cpp
index 3601f2247c024b9225ac6c031a2d97cbfa320cd8..308cd4739bd6210d1968bb6ec88cf6c8ca2f5499 100644
--- a/Common/Options.cpp
+++ b/Common/Options.cpp
@@ -1,4 +1,4 @@
-// $Id: Options.cpp,v 1.351 2007-09-03 20:09:13 geuzaine Exp $
+// $Id: Options.cpp,v 1.352 2007-09-04 13:47:00 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
@@ -4762,6 +4762,17 @@ double opt_mesh_nb_smoothing(OPT_ARGS_NUM)
   return CTX.mesh.nb_smoothing;
 }
 
+double opt_mesh_lc_integration_precision(OPT_ARGS_NUM)
+{
+  if(action & GMSH_SET)
+    CTX.mesh.lc_integration_precision = val;
+#if defined(HAVE_FLTK)
+  //  if(WID && (action & GMSH_GUI))
+  //    WID->mesh_value[0]->value(CTX.mesh.nb_smoothing);
+#endif
+  return CTX.mesh.lc_integration_precision;
+}
+
 double opt_mesh_algo2d(OPT_ARGS_NUM)
 {
   if(action & GMSH_SET){
diff --git a/Common/Options.h b/Common/Options.h
index 729ad253bbfc27046e9bf0abc67a88ed4c6a91b3..ba52ec6eb4035d054521a9bbc27a6b9c169eae25 100644
--- a/Common/Options.h
+++ b/Common/Options.h
@@ -471,6 +471,7 @@ double opt_mesh_bdf_field_format(OPT_ARGS_NUM);
 double opt_mesh_nb_smoothing(OPT_ARGS_NUM);
 double opt_mesh_algo2d(OPT_ARGS_NUM);
 double opt_mesh_algo3d(OPT_ARGS_NUM);
+double opt_mesh_lc_integration_precision(OPT_ARGS_NUM);
 double opt_mesh_recombine_algo(OPT_ARGS_NUM);
 double opt_mesh_min_circ_points(OPT_ARGS_NUM);
 double opt_mesh_constrained_bgmesh(OPT_ARGS_NUM);
diff --git a/DataStr/List.cpp b/DataStr/List.cpp
index e06fff256173e7b57ad9fd05f76050d6d6607f3d..93142b6f39f93cc7e5fc8c976a80744d0dc6775f 100644
--- a/DataStr/List.cpp
+++ b/DataStr/List.cpp
@@ -1,4 +1,4 @@
-// $Id: List.cpp,v 1.39 2006-11-27 22:22:08 geuzaine Exp $
+// $Id: List.cpp,v 1.40 2007-09-04 13:47:00 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/DataStr/Malloc.cpp b/DataStr/Malloc.cpp
index 30189fbb64a8925abba8852bd3f61c9edcd0ecf9..1051e3e2c8a74e60e9d29bae8a9283b6838a1140 100644
--- a/DataStr/Malloc.cpp
+++ b/DataStr/Malloc.cpp
@@ -1,4 +1,4 @@
-// $Id: Malloc.cpp,v 1.20 2006-11-27 22:22:08 geuzaine Exp $
+// $Id: Malloc.cpp,v 1.21 2007-09-04 13:47:00 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/DataStr/SafeIO.cpp b/DataStr/SafeIO.cpp
index 28761f218af0aee6729e1985d1ed0ac3f5ff2b48..38146c2980102bf70e20287444d69c6201823ffb 100644
--- a/DataStr/SafeIO.cpp
+++ b/DataStr/SafeIO.cpp
@@ -1,4 +1,4 @@
-// $Id: SafeIO.cpp,v 1.9 2006-11-27 22:22:08 geuzaine Exp $
+// $Id: SafeIO.cpp,v 1.10 2007-09-04 13:47:00 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/DataStr/Tools.cpp b/DataStr/Tools.cpp
index eb39a9bd7c78ba5bf87e9ac181e5587e2acda3b7..7825d0bcb9c615c9c4a5844bd0a381a3c52f2681 100644
--- a/DataStr/Tools.cpp
+++ b/DataStr/Tools.cpp
@@ -1,4 +1,4 @@
-// $Id: Tools.cpp,v 1.16 2006-11-27 22:22:08 geuzaine Exp $
+// $Id: Tools.cpp,v 1.17 2007-09-04 13:47:00 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/DataStr/Tree.cpp b/DataStr/Tree.cpp
index dfc01911dcdbab0693291a69f75e1c7653349253..acb770d517df41ed2581fb8d2333e230dbf0af77 100644
--- a/DataStr/Tree.cpp
+++ b/DataStr/Tree.cpp
@@ -1,4 +1,4 @@
-// $Id: Tree.cpp,v 1.21 2006-11-27 22:22:08 geuzaine Exp $
+// $Id: Tree.cpp,v 1.22 2007-09-04 13:47:00 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/Fltk/Callbacks.cpp b/Fltk/Callbacks.cpp
index 09c8d33a0909ce1169db98ba077d379c568ecdfc..3bb3ca6abc0011815c188369ef3ef22c3ccca865 100644
--- a/Fltk/Callbacks.cpp
+++ b/Fltk/Callbacks.cpp
@@ -1,4 +1,4 @@
-// $Id: Callbacks.cpp,v 1.540 2007-09-03 20:09:13 geuzaine Exp $
+// $Id: Callbacks.cpp,v 1.541 2007-09-04 13:47:01 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
@@ -3904,6 +3904,7 @@ void mesh_optimize_cb(CALLBACK_ARGS)
   Msg(STATUS2N, " ");
 }
 
+
 void mesh_define_length_cb(CALLBACK_ARGS)
 {
   _action_point_line_surface_volume(8, 0, "Point");
diff --git a/Fltk/Callbacks.h b/Fltk/Callbacks.h
index c68d6600afefb0716c2f43c87f61c66cc097aedb..63f56af92535af01087875d1a88fa1af4edcebf4 100644
--- a/Fltk/Callbacks.h
+++ b/Fltk/Callbacks.h
@@ -282,6 +282,7 @@ void mesh_update_edges_cb(CALLBACK_ARGS);
 void mesh_parameterize_cb(CALLBACK_ARGS);
 void mesh_degree_cb(CALLBACK_ARGS); 
 void mesh_optimize_cb(CALLBACK_ARGS); 
+void mesh_classify_cb(CALLBACK_ARGS); 
 void mesh_define_length_cb (CALLBACK_ARGS);
 void mesh_define_recombine_cb (CALLBACK_ARGS);
 void mesh_define_transfinite_cb (CALLBACK_ARGS); 
diff --git a/Fltk/GUI.cpp b/Fltk/GUI.cpp
index f94966fe45bb0a279eded5bfa8646f5c9ca1d247..3b7aa3e95eb50a977591c3e19651912871c7d7fd 100644
--- a/Fltk/GUI.cpp
+++ b/Fltk/GUI.cpp
@@ -1,4 +1,4 @@
-// $Id: GUI.cpp,v 1.634 2007-09-03 20:09:14 geuzaine Exp $
+// $Id: GUI.cpp,v 1.635 2007-09-04 13:47:01 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
@@ -293,6 +293,7 @@ Context_Item menu_mesh[] = {
 #if defined(HAVE_FOURIER_MODEL)
   {"Reparameterize",   (Fl_Callback *)mesh_parameterize_cb} , 
 #endif
+  {"Reclassify",   (Fl_Callback *)mesh_classify_cb} , 
   {"Save",         (Fl_Callback *)mesh_save_cb} ,
   {0} 
 };  
diff --git a/Fltk/GUI_Classifier.cpp b/Fltk/GUI_Classifier.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..57e170d2490c6817c04e91daa24051e78ccddca8
--- /dev/null
+++ b/Fltk/GUI_Classifier.cpp
@@ -0,0 +1,519 @@
+#include "GUI_Classifier.h"
+#include "Geo.h"
+#include "Gmsh.h"
+#include "Draw.h"
+#include "Options.h"
+#include "Context.h"
+#include "SelectBuffer.h"
+#include "GUI_Projection.h"
+#include "GUI_Extras.h"
+#include "Message.h"
+#include "meshGFaceDelaunayInsertion.h"
+#include "meshGFaceOptimize.h"
+#include "gmshEdge.h"
+#include "gmshFace.h"
+
+extern Mesh *THEM;
+extern Context_T CTX;
+
+void buildListOfEdgeAngle ( e2t_cont adj,std::vector<edge_angle> &edges_detected,std::vector<edge_angle> &edges_lonly);
+
+int maxEdgeNum ()
+{
+  GModel::eiter it =  GModel::current()->firstEdge();
+  GModel::eiter ite = GModel::current()->lastEdge();
+  int MAXX = 0;
+  while (it != ite)
+    {
+      MAXX = std::max (MAXX, (*it)->tag());
+      ++it;
+    }
+  return MAXX;
+}
+
+int maxFaceNum ()
+{
+  GModel::fiter it =  GModel::current()->firstFace();
+  GModel::fiter ite = GModel::current()->lastFace();
+  int MAXX = 0;
+  while (it != ite)
+    {
+      MAXX = std::max (MAXX, (*it)->tag());
+      ++it;
+    }
+  return MAXX;
+}
+
+
+struct compareMLinePtr 
+{
+  bool operator () ( MLine *l1 , MLine *l2) const
+  {
+    static Less_Edge le;
+    return le(l1->getEdge(0),l2->getEdge(0)); 
+  }
+};
+
+ 
+void recurClassify ( MTri3 *t , 
+		     std::vector<MTriangle *> &triangles,
+		     std::map<MLine*, GEdge*, compareMLinePtr> &lines,
+		     std::set<GEdge*> &closure)
+{
+  if (!t->isDeleted())
+    {
+      triangles.push_back(t->tri());
+      t->setDeleted ( true );
+      
+      for (int i=0;i<3;i++)
+	{
+	  MTri3 *tn = t->getNeigh(i);
+	  if (tn)
+	    {
+	      edgeXface exf ( t, i);
+	      MLine ml (exf.v[0],exf.v[1]);	  
+	      std::map<MLine*, GEdge*, compareMLinePtr>::iterator it = lines.find(&ml);
+	      if (it==lines.end())
+		recurClassify (tn, triangles,lines, closure);
+	      else
+		closure.insert(it->second);
+	    }
+	}  
+    }
+}
+
+
+
+void class_color_cb(Fl_Widget* w, void* data)
+{
+  classificationEditor *e = (classificationEditor*)data;
+  std::map<MLine*, GEdge*, compareMLinePtr> lines;
+  {
+    GModel::eiter it =  GModel::current()->firstEdge();
+    GModel::eiter ite = GModel::current()->lastEdge();
+    for( ;it!=ite;++it)
+      {
+	for (int i=0;i<(*it)->lines.size();i++)lines[(*it)->lines[i] ] = *it;
+      }
+  }
+
+
+  std::list<MTri3*> tris;
+  {
+    std::set<GFace*>::iterator it = e->_faces.begin();
+    while (it != e->_faces.end())
+      {
+	GFace *gf = *it;
+	for (int i=0;i<gf->triangles.size();i++)
+	  {
+	    tris.push_back (new MTri3 ( gf->triangles [i] , 0 ) );
+	  }
+	gf->triangles.clear();
+	++it;
+      }
+  }
+
+
+  connectTriangles (tris);
+
+  {
+    std::list<MTri3*> ::iterator it = tris.begin();
+    while (it != tris.end())
+      {
+	if (!(*it)->isDeleted())
+	  {
+	    std::set<GEdge*> closure;
+	    std::vector<MTriangle*> triangles;
+	    gmshFace *temporary = new gmshFace ( GModel::current(), maxFaceNum() + 1);
+	    recurClassify ( *it , temporary->triangles,lines, closure); 
+	    GModel::current()->add (temporary);
+	    e->tempFaces.push_back(temporary);	    	    
+	  }
+	++it;
+      }
+
+    it = tris.begin();
+    while (it != tris.end())
+      {
+	delete *it;
+	++it;
+      }
+  }
+
+  CTX.mesh.changed = ENT_ALL;
+  Draw();  
+  Msg(ONSCREEN, "");
+
+}
+
+void updateedges_cb(Fl_Widget* w, void* data)
+{
+  classificationEditor *e = (classificationEditor*)data;
+ 
+  //  printf("%d edges detected\n",e->edges_detected.size());
+
+  for (int i=0;i<e->temporary->lines.size();i++)
+    {
+      delete e->temporary->lines[i];
+    }
+  e->temporary->lines.clear();
+
+  for ( int i=0 ; i<e->edges_detected.size();i++)
+    {
+      edge_angle ea =  e->edges_detected[i];
+      //      printf("angle = %g\n",ea.angle);
+      if ( ea.angle  <= e -> _inputs[CLASSVALUE_ANGLE] ->value() / 180 * M_PI) 
+	break;
+      e->temporary->lines.push_back(new MLine(ea.v1, ea.v2));            
+    } 
+  CTX.mesh.changed = ENT_ALL;
+  Draw();   
+}
+
+edge_angle::  edge_angle ( MVertex *_v1, MVertex *_v2, MTriangle *t1, MTriangle *t2)
+  : v1(_v1), v2(_v2)
+{
+  if (!t2) angle = 0;
+  else
+    {
+      double c1[3];
+      double c2[3];
+      double c3[3];
+      {
+	MVertex *p1 = t1->getVertex(0);
+	MVertex *p2 = t1->getVertex(1);
+	MVertex *p3 = t1->getVertex(2);
+	double a[3] = { p1->x() - p2->x(), p1->y() - p2->y(), p1->z() - p2->z() };
+	double b[3] = { p1->x() - p3->x(), p1->y() - p3->y(), p1->z() - p3->z() };
+	c1[2] = a[0] * b[1] - a[1] * b[0];
+	c1[1] = -a[0] * b[2] + a[2] * b[0];
+	c1[0] = a[1] * b[2] - a[2] * b[1];
+      }
+      {
+	MVertex *p1 = t2->getVertex(0);
+	MVertex *p2 = t2->getVertex(1);
+	MVertex *p3 = t2->getVertex(2);
+	double a[3] = { p1->x() - p2->x(), p1->y() - p2->y(), p1->z() - p2->z() };
+	double b[3] = { p1->x() - p3->x(), p1->y() - p3->y(), p1->z() - p3->z() };
+	c2[2] = a[0] * b[1] - a[1] * b[0];
+	c2[1] = -a[0] * b[2] + a[2] * b[0];
+	c2[0] = a[1] * b[2] - a[2] * b[1];
+      }
+      norme(c1);
+      norme(c2);
+      prodve(c1,c2,c3);
+      double cosa ; prosca(c1,c2,&cosa);
+      double sina = norme (c3);
+      angle = atan2(sina,cosa);
+    }
+  
+}
+void buildListOfEdgeAngle ( e2t_cont adj,std::vector<edge_angle> &edges_detected,std::vector<edge_angle> &edges_lonly)
+{
+  e2t_cont::iterator it = adj.begin();
+  for ( ; it!=adj.end();++it )
+    {
+      if ( it->second.second ) edges_detected.push_back ( edge_angle ( it->first.getVertex (0) ,it->first.getVertex (1) , 
+								       it->second.first,it->second.second) );
+      else edges_lonly.push_back ( edge_angle ( it->first.getVertex (0) ,it->first.getVertex (1) , 
+						it->second.first,it->second.second) );	
+    }
+  std::sort ( edges_detected .begin() ,  edges_detected .end() );
+}
+
+
+classificationEditor::classificationEditor() 
+{
+
+  // construct GUI in terms of standard sizes
+  const int BH = 2 * GetFontSize() + 1, BB = 12 * GetFontSize(), WB = 7;
+  const int width = (int)(3.5 * BB), height = 10 * BH;
+
+  _window = new Dialog_Window(width, height, "Classify");
+  
+  Fl_Tabs *o = new Fl_Tabs(WB, WB, width - 2 * WB, height - 2 * WB);
+  {
+    Fl_Group *o = new Fl_Group(WB, WB + BH, width - 2 * WB, height - 2 * WB - BH, "Edge Detection");
+    //    o->hide();
+    // create all widgets (we construct this once, we never deallocate!)
+    
+    _buttons[CLASSBUTTON_SELECT] = 
+      new Fl_Button       (2*WB, 2*WB+1*BH, BB, BH, "Select Elements");
+    _buttons[CLASSBUTTON_SELECT]->callback(class_select_cb, this);
+    
+    _togbuttons[CLASSTOGBUTTON_HIDE] = 
+      new Fl_Toggle_Button(3*WB+BB, 2*WB+1*BH, BB, BH, "Hide Unselected");
+    _togbuttons[CLASSTOGBUTTON_HIDE]->callback(hide_cb,this);
+    
+    _inputs[CLASSVALUE_ANGLE] = 
+      new Fl_Value_Input(2*WB, 3*WB+2*BH, BB, BH, "Treshold Angle");
+    _inputs[CLASSVALUE_ANGLE]->value(40);
+    _inputs [CLASSVALUE_ANGLE]->maximum(90);
+    _inputs[CLASSVALUE_ANGLE]->minimum(0);
+    _inputs[CLASSVALUE_ANGLE]->align(FL_ALIGN_RIGHT);
+    _inputs[CLASSVALUE_ANGLE]->step(1);
+    _inputs[CLASSVALUE_ANGLE]->when(FL_WHEN_RELEASE);  
+    _inputs[CLASSVALUE_ANGLE]->callback(updateedges_cb,this);
+
+    _buttons[CLASSBUTTON_DEL] = 
+      new Fl_Button       (2*WB, 5*WB+4*BH, BB, BH, "Delete Edge");
+    _buttons[CLASSBUTTON_DEL]->callback(class_deleteedge_cb, this);    
+    _buttons[CLASSBUTTON_ADD] = 
+      new Fl_Button       (2*WB, 6*WB+5*BH, BB, BH, "Save Selection");
+    _buttons[CLASSBUTTON_ADD]->callback(class_save_cb, this);    
+    _buttons[CLASSBUTTON_CLEAR] = 
+      new Fl_Button       (2*WB, 7*WB+6*BH, BB, BH, "Clear All");
+    _buttons[CLASSBUTTON_CLEAR]->callback(class_clear_cb, this);    
+    o->end();
+  }
+  {
+    Fl_Group *o = new Fl_Group(WB, WB + BH, width - 2 * WB, height - 2 * WB - BH, "Face Colouring");
+    o->hide();
+    _buttons[CLASSBUTTON_SELFAC] = 
+      new Fl_Button       (2*WB, 2*WB+1*BH, BB, BH, "Select Model Face");
+    _buttons[CLASSBUTTON_SELFAC]->callback(class_selectgface_cb, this);
+    _buttons[CLASSBUTTON_COLOR] = 
+      new Fl_Button       (2*WB, 3*WB+2*BH, BB, BH, "Classify Mesh Faces");
+    _buttons[CLASSBUTTON_COLOR]->callback(class_color_cb, this);
+    o->end();
+  }
+
+  // allocate detected edges
+  // temporary for the selection
+  // saved for the ones that have been saved by the user
+  // and that will be used for next step
+
+  temporary = new gmshEdge ( GModel::current(), maxEdgeNum() + 1 );
+  GModel::current()->add (temporary);
+  saved = new gmshEdge ( GModel::current(), maxEdgeNum() + 1 );
+  GModel::current()->add (saved);
+  
+  _window->end();
+  _window->hotspot(_window);
+  _window->size_range(width, (int)(0.85 * height));    
+}
+
+
+void class_select_cb(Fl_Widget *w, void *data)
+{
+  classificationEditor *e = (classificationEditor*)data;
+  std::vector<GVertex*> vertices;
+  std::vector<GEdge*> edges;
+  std::vector<GFace*> faces;
+  std::vector<GRegion*> regions;
+  std::vector<MElement*> elements;
+  std::vector<MTriangle*> &ele(e->getElements());
+
+  CTX.pick_elements = 1;
+
+  while(1) {
+    CTX.mesh.changed = ENT_ALL;
+    Draw();
+
+    Msg(ONSCREEN, "Select Elements\n"
+	"[Press 'e' to end selection or 'q' to abort]");
+    
+    char ib = SelectEntity(ENT_ALL, vertices, edges, faces, regions, elements);
+    if(ib == 'l') {
+      if(CTX.pick_elements){
+	for(unsigned int i = 0; i < elements.size(); i++){
+	  if(elements[i]->getNumEdges() == 3 && elements[i]->getVisibility() != 2){
+	    elements[i]->setVisibility(2); ele.push_back((MTriangle*)elements[i]);
+	  }
+	}
+      }
+    }
+    if(ib == 'r') {
+      for(unsigned int i = 0; i < elements.size(); i++)
+	elements[i]->setVisibility(1);
+    }
+    // ok, we compute edges !
+    if(ib == 'e') {
+      ZeroHighlight();
+      e2t_cont adj;
+      buildEdgeToTriangle (ele , adj );      
+      buildListOfEdgeAngle ( adj,e->edges_detected,e->edges_lonly);
+      break;
+    }
+    // do nothing
+    if(ib == 'q') {
+      ZeroHighlight();
+      ele.clear();
+      break;
+    }
+  }
+  
+  updateedges_cb(0, data);
+
+  CTX.mesh.changed = ENT_ALL;
+  CTX.pick_elements = 0;
+  Draw();  
+  Msg(ONSCREEN, "");
+}
+
+
+void class_selectgface_cb(Fl_Widget *w, void *data)
+{
+  classificationEditor *e = (classificationEditor*)data;
+  std::vector<GVertex*> vertices;
+  std::vector<GEdge*> edges;
+  std::vector<GFace*> faces;
+  std::vector<GFace*> temp;
+  std::vector<GRegion*> regions;
+  std::vector<MElement*> elements;
+
+  opt_geometry_surfaces(0, GMSH_SET | GMSH_GUI, 1);
+
+  while(1) {
+    CTX.mesh.changed = ENT_ALL;
+    Draw();
+
+    Msg(ONSCREEN, "Select Model Face\n"
+	"[Press 'e' to end selection or 'q' to abort]");
+    
+    char ib = SelectEntity(ENT_SURFACE, vertices, edges, faces, regions, elements);
+    if(ib == 'l') {
+      for(unsigned int i = 0; i < faces.size(); i++){
+	HighlightEntity(faces[i]);	
+	temp.push_back(faces[i]);
+      }
+    }
+    // ok store the list of gfaces !
+    if(ib == 'e') {
+      ZeroHighlight();
+      for(unsigned int i = 0; i < temp.size(); i++){
+	e->_faces.insert (temp[i]);
+      }
+      break;
+    }
+    // do nothing
+    if(ib == 'q') {
+      ZeroHighlight();
+      break;
+    }
+  } 
+  CTX.mesh.changed = ENT_ALL;
+  Draw();  
+  Msg(ONSCREEN, "");
+}
+
+
+void class_deleteedge_cb(Fl_Widget *w, void *data)
+{
+  classificationEditor *e = (classificationEditor*)data;
+  std::vector<GVertex*> vertices;
+  std::vector<GEdge*> edges;
+  std::vector<GFace*> faces;
+  std::vector<GRegion*> regions;
+  std::vector<MElement*> elements;
+  std::vector<MLine*> ele;
+  
+  CTX.pick_elements = 1;
+  
+  while(1) {
+    CTX.mesh.changed = ENT_ALL;
+    Draw();
+
+    Msg(ONSCREEN, "Select Elements\n"
+	"[Press 'e' to end selection or 'q' to abort]");
+    
+    char ib = SelectEntity(ENT_ALL, vertices, edges, faces, regions, elements);
+    if(ib == 'l') {
+      if(CTX.pick_elements){
+	for(unsigned int i = 0; i < elements.size(); i++){
+	  if(elements[i]->getNumEdges() == 1 && elements[i]->getVisibility() != 2){
+	    elements[i]->setVisibility(2); ele.push_back((MLine*)elements[i]);
+	  }
+	}
+      }
+    }
+    if(ib == 'r') {
+      for(unsigned int i = 0; i < elements.size(); i++)
+	elements[i]->setVisibility(1);
+    }
+    // ok, we compute edges !
+    if(ib == 'e') {
+      ZeroHighlight();      
+      break;
+    }
+    // do nothing
+    if(ib == 'q') {
+      ZeroHighlight();
+      ele.clear();
+      break;
+    }
+  }
+
+
+  std::sort (ele.begin(),ele.end());
+  //  look in all temporary edges if a deleted one is present and delete it !
+  std::vector<MLine*> temp = e->temporary->lines;
+  e->temporary->lines.clear();
+       
+  for(int i=0;i<temp.size();i++)
+    {      
+      std::vector<MLine*>::iterator it = std::find (ele.begin(),ele.end(),temp[i]);
+      if (it != ele.end())
+	{
+	  delete temp[i];
+	}
+      else e->temporary->lines.push_back(temp[i]);
+    }
+  
+  CTX.mesh.changed = ENT_ALL;
+  CTX.pick_elements = 0;
+  Draw();  
+  Msg(ONSCREEN, "");
+}
+
+
+void class_save_cb(Fl_Widget *w, void *data)
+{
+  classificationEditor *e = (classificationEditor*)data;
+
+  e->saved->lines.insert (e->saved->lines.end(), e->temporary->lines.begin(), e->temporary->lines.end());
+  e->temporary->lines.clear();
+  e->_elements.clear();
+  e->edges_detected.clear();
+
+  CTX.mesh.changed = ENT_ALL;
+  CTX.pick_elements = 0;
+  Draw();  
+  Msg(ONSCREEN, "");
+}
+
+void class_clear_cb(Fl_Widget *w, void *data)
+{
+  classificationEditor *e = (classificationEditor*)data;
+
+  for (int i=0;i<e->temporary->lines.size();i++)
+    {      
+      delete e->temporary->lines[i];
+    }
+  e->temporary->lines.clear();
+
+  for (int i=0;i<e->saved->lines.size();i++)
+    {      
+      delete e->saved->lines[i];
+    }
+  e->saved->lines.clear();
+
+  CTX.mesh.changed = ENT_ALL;
+  CTX.pick_elements = 0;
+  Draw();  
+  Msg(ONSCREEN, "");
+}
+
+
+
+void mesh_classify_cb(Fl_Widget* w, void* data)
+{
+  // create the (static) editor
+  static classificationEditor *editor = 0;
+  if(!editor){
+    editor = new classificationEditor();
+  }
+  editor->show();
+}
+
+
diff --git a/Fltk/GUI_Classifier.h b/Fltk/GUI_Classifier.h
new file mode 100644
index 0000000000000000000000000000000000000000..dbddae79b31545d1c9fd19f709e3116acc14cafa
--- /dev/null
+++ b/Fltk/GUI_Classifier.h
@@ -0,0 +1,60 @@
+#ifndef _GUI_CLASSIFIER_H_
+#define _GUI_CLASSIFIER_H_
+
+#include "GmshUI.h"
+#include "GModel.h"
+#include "MElement.h"
+#include "GUI.h"
+#include "Shortcut_Window.h"
+#include "ColorTable.h"
+#include <FL/Fl_Toggle_Button.H>
+#include <FL/Fl_Round_Button.H>
+#include <vector>
+
+void class_select_cb(Fl_Widget *w, void *data);
+void class_selectgface_cb(Fl_Widget *w, void *data);
+void class_save_cb(Fl_Widget *w, void *data);
+void class_clear_cb(Fl_Widget *w, void *data);
+void class_deleteedge_cb(Fl_Widget *w, void *data);
+void class_color_cb(Fl_Widget *w, void *data);
+
+#define CLASSBUTTON_SELECT   0
+#define CLASSBUTTON_DEL      1
+#define CLASSBUTTON_ADD      2
+#define CLASSBUTTON_CLEAR    3
+#define CLASSBUTTON_OK       4
+#define CLASSBUTTON_COLOR    5
+#define CLASSBUTTON_SELFAC   6
+#define CLASSTOGBUTTON_HIDE  0
+#define CLASSVALUE_ANGLE     0
+
+class edge_angle
+{
+ public :
+  MVertex *v1, *v2;
+  double angle;
+  edge_angle ( MVertex *_v1, MVertex *_v2, MTriangle *t1, MTriangle *t2);
+  bool operator < (const edge_angle & other) const
+  {
+    return other.angle < angle;
+  }  
+};
+
+class classificationEditor {
+ public:
+  std::vector<MTriangle*> _elements;
+  std::set<GFace*> _faces;
+  Fl_Window *_window;
+  Fl_Button *_buttons[10];
+  Fl_Toggle_Button *_togbuttons[10];
+  Fl_Value_Input *_inputs[10];
+  GEdge *temporary;
+  GEdge *saved;
+  std::list<GFace *> tempFaces;
+  std::vector<edge_angle> edges_detected;
+  std::vector<edge_angle> edges_lonly;
+  classificationEditor();
+  void show(){ _window->show();}
+  std::vector<MTriangle*> &getElements() { return _elements; }
+};
+#endif
diff --git a/Fltk/Makefile b/Fltk/Makefile
index b91319a66f5c771e3904fcb90126889341ac3278..9cd050d5b0991a4f2dcae6ca6b94f112de0197f8 100644
--- a/Fltk/Makefile
+++ b/Fltk/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.144 2007-08-27 13:46:21 geuzaine Exp $
+# $Id: Makefile,v 1.145 2007-09-04 13:47:01 remacle Exp $
 #
 # Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 #
@@ -29,7 +29,7 @@ CFLAGS  = ${OPTIM} ${FLAGS} ${INCLUDE}
 
 SRC = Main.cpp \
       Message.cpp \
-      GUI.cpp GUI_Extras.cpp GUI_Projection.cpp\
+      GUI.cpp GUI_Extras.cpp GUI_Projection.cpp GUI_Classifier.cpp\
       Callbacks.cpp\
       Opengl.cpp\
       Opengl_Window.cpp\
@@ -78,7 +78,41 @@ Main.o: Main.cpp GUI.h Opengl_Window.h Colorbar_Window.h \
   ../Parser/OpenFile.h ../Common/CommandLine.h Solvers.h \
   ../Plugin/PluginManager.h ../Plugin/Plugin.h ../Post/Views.h \
   ../Post/ColorTable.h ../Common/VertexArray.h ../Post/AdaptiveViews.h \
-  ../Common/GmshMatrix.h ../Geo/GModel.h ../Geo/GVertex.h \
+  ../Common/GmshMatrix.h /sw/include/gsl/gsl_linalg.h \
+  /sw/include/gsl/gsl_mode.h /sw/include/gsl/gsl_permutation.h \
+  /sw/include/gsl/gsl_types.h /sw/include/gsl/gsl_errno.h \
+  /sw/include/gsl/gsl_check_range.h /sw/include/gsl/gsl_vector.h \
+  /sw/include/gsl/gsl_vector_complex_long_double.h \
+  /sw/include/gsl/gsl_complex.h /sw/include/gsl/gsl_vector_long_double.h \
+  /sw/include/gsl/gsl_block_long_double.h \
+  /sw/include/gsl/gsl_vector_complex.h \
+  /sw/include/gsl/gsl_block_complex_long_double.h \
+  /sw/include/gsl/gsl_vector_complex_double.h \
+  /sw/include/gsl/gsl_vector_double.h /sw/include/gsl/gsl_block_double.h \
+  /sw/include/gsl/gsl_block_complex_double.h \
+  /sw/include/gsl/gsl_vector_complex_float.h \
+  /sw/include/gsl/gsl_vector_float.h /sw/include/gsl/gsl_block_float.h \
+  /sw/include/gsl/gsl_block_complex_float.h \
+  /sw/include/gsl/gsl_vector_ulong.h /sw/include/gsl/gsl_block_ulong.h \
+  /sw/include/gsl/gsl_vector_long.h /sw/include/gsl/gsl_block_long.h \
+  /sw/include/gsl/gsl_vector_uint.h /sw/include/gsl/gsl_block_uint.h \
+  /sw/include/gsl/gsl_vector_int.h /sw/include/gsl/gsl_block_int.h \
+  /sw/include/gsl/gsl_vector_ushort.h /sw/include/gsl/gsl_block_ushort.h \
+  /sw/include/gsl/gsl_vector_short.h /sw/include/gsl/gsl_block_short.h \
+  /sw/include/gsl/gsl_vector_uchar.h /sw/include/gsl/gsl_block_uchar.h \
+  /sw/include/gsl/gsl_vector_char.h /sw/include/gsl/gsl_block_char.h \
+  /sw/include/gsl/gsl_matrix.h \
+  /sw/include/gsl/gsl_matrix_complex_long_double.h \
+  /sw/include/gsl/gsl_matrix_complex_double.h \
+  /sw/include/gsl/gsl_matrix_complex_float.h \
+  /sw/include/gsl/gsl_matrix_long_double.h \
+  /sw/include/gsl/gsl_matrix_double.h /sw/include/gsl/gsl_matrix_float.h \
+  /sw/include/gsl/gsl_matrix_ulong.h /sw/include/gsl/gsl_matrix_long.h \
+  /sw/include/gsl/gsl_matrix_uint.h /sw/include/gsl/gsl_matrix_int.h \
+  /sw/include/gsl/gsl_matrix_ushort.h /sw/include/gsl/gsl_matrix_short.h \
+  /sw/include/gsl/gsl_matrix_uchar.h /sw/include/gsl/gsl_matrix_char.h \
+  /sw/include/gsl/gsl_blas.h /sw/include/gsl/gsl_blas_types.h \
+  /sw/include/gsl/gsl_cblas.h ../Geo/GModel.h ../Geo/GVertex.h \
   ../Geo/GEntity.h ../Geo/Range.h ../Geo/SPoint3.h \
   ../Geo/SBoundingBox3d.h ../Geo/MVertex.h ../Geo/SPoint3.h \
   ../Geo/GPoint.h ../Geo/SPoint2.h ../Geo/GEdge.h ../Geo/GEntity.h \
@@ -90,9 +124,10 @@ Main.o: Main.cpp GUI.h Opengl_Window.h Colorbar_Window.h \
   ../Geo/SPoint2.h ../Geo/SVector3.h ../Geo/Pair.h ../Geo/ExtrudeParams.h \
   ../Geo/GRegion.h ../Geo/GEntity.h ../Geo/MElement.h \
   ../Geo/ExtrudeParams.h ../Geo/SBoundingBox3d.h ../Mesh/Field.h \
-  ../Post/OctreePost.h ../Common/Octree.h ../Common/OctreeInternals.h \
-  ../Mesh/BackgroundMesh.h ../Post/PView.h ../Post/AdaptiveViews.h \
-  ../Post/PViewData.h ../Post/PViewOptions.h ../Post/ColorTable.h
+  ../contrib/ANN/include/ANN/ANN.h ../Post/OctreePost.h \
+  ../Common/Octree.h ../Common/OctreeInternals.h ../Mesh/BackgroundMesh.h \
+  ../Post/PView.h ../Post/AdaptiveViews.h ../Post/PViewData.h \
+  ../Post/PViewOptions.h ../Post/ColorTable.h
 Message.o: Message.cpp ../Common/Gmsh.h ../Common/Message.h \
   ../DataStr/Malloc.h ../DataStr/List.h ../DataStr/Tree.h \
   ../DataStr/avl.h ../DataStr/Tools.h ../DataStr/List.h ../DataStr/Tree.h \
@@ -111,7 +146,41 @@ GUI.o: GUI.cpp ../Common/Gmsh.h ../Common/Message.h ../DataStr/Malloc.h \
   ../Plugin/Plugin.h ../Post/Views.h ../Post/ColorTable.h \
   ../Common/VertexArray.h ../Geo/SVector3.h ../Geo/SPoint3.h \
   ../Common/SmoothData.h ../Post/AdaptiveViews.h ../Common/GmshMatrix.h \
-  Shortcut_Window.h
+  /sw/include/gsl/gsl_linalg.h /sw/include/gsl/gsl_mode.h \
+  /sw/include/gsl/gsl_permutation.h /sw/include/gsl/gsl_types.h \
+  /sw/include/gsl/gsl_errno.h /sw/include/gsl/gsl_check_range.h \
+  /sw/include/gsl/gsl_vector.h \
+  /sw/include/gsl/gsl_vector_complex_long_double.h \
+  /sw/include/gsl/gsl_complex.h /sw/include/gsl/gsl_vector_long_double.h \
+  /sw/include/gsl/gsl_block_long_double.h \
+  /sw/include/gsl/gsl_vector_complex.h \
+  /sw/include/gsl/gsl_block_complex_long_double.h \
+  /sw/include/gsl/gsl_vector_complex_double.h \
+  /sw/include/gsl/gsl_vector_double.h /sw/include/gsl/gsl_block_double.h \
+  /sw/include/gsl/gsl_block_complex_double.h \
+  /sw/include/gsl/gsl_vector_complex_float.h \
+  /sw/include/gsl/gsl_vector_float.h /sw/include/gsl/gsl_block_float.h \
+  /sw/include/gsl/gsl_block_complex_float.h \
+  /sw/include/gsl/gsl_vector_ulong.h /sw/include/gsl/gsl_block_ulong.h \
+  /sw/include/gsl/gsl_vector_long.h /sw/include/gsl/gsl_block_long.h \
+  /sw/include/gsl/gsl_vector_uint.h /sw/include/gsl/gsl_block_uint.h \
+  /sw/include/gsl/gsl_vector_int.h /sw/include/gsl/gsl_block_int.h \
+  /sw/include/gsl/gsl_vector_ushort.h /sw/include/gsl/gsl_block_ushort.h \
+  /sw/include/gsl/gsl_vector_short.h /sw/include/gsl/gsl_block_short.h \
+  /sw/include/gsl/gsl_vector_uchar.h /sw/include/gsl/gsl_block_uchar.h \
+  /sw/include/gsl/gsl_vector_char.h /sw/include/gsl/gsl_block_char.h \
+  /sw/include/gsl/gsl_matrix.h \
+  /sw/include/gsl/gsl_matrix_complex_long_double.h \
+  /sw/include/gsl/gsl_matrix_complex_double.h \
+  /sw/include/gsl/gsl_matrix_complex_float.h \
+  /sw/include/gsl/gsl_matrix_long_double.h \
+  /sw/include/gsl/gsl_matrix_double.h /sw/include/gsl/gsl_matrix_float.h \
+  /sw/include/gsl/gsl_matrix_ulong.h /sw/include/gsl/gsl_matrix_long.h \
+  /sw/include/gsl/gsl_matrix_uint.h /sw/include/gsl/gsl_matrix_int.h \
+  /sw/include/gsl/gsl_matrix_ushort.h /sw/include/gsl/gsl_matrix_short.h \
+  /sw/include/gsl/gsl_matrix_uchar.h /sw/include/gsl/gsl_matrix_char.h \
+  /sw/include/gsl/gsl_blas.h /sw/include/gsl/gsl_blas_types.h \
+  /sw/include/gsl/gsl_cblas.h Shortcut_Window.h
 GUI_Extras.o: GUI_Extras.cpp ../Common/Gmsh.h ../Common/Message.h \
   ../DataStr/Malloc.h ../DataStr/List.h ../DataStr/Tree.h \
   ../DataStr/avl.h ../DataStr/Tools.h ../DataStr/List.h ../DataStr/Tree.h \
@@ -134,6 +203,8 @@ GUI_Projection.o: GUI_Projection.cpp ../Geo/GModelIO_F.h ../Geo/GModel.h \
   ../Geo/MElement.h ../Geo/SPoint2.h ../Geo/SVector3.h ../Geo/Pair.h \
   ../Geo/ExtrudeParams.h ../Geo/GRegion.h ../Geo/GEntity.h \
   ../Geo/MElement.h ../Geo/ExtrudeParams.h ../Geo/SBoundingBox3d.h \
+  /Users/remacle/SOURCES/FourierModel/FM_Patch.h \
+  /Users/remacle/SOURCES/FourierModel/FM_ProjectionSurface.h \
   ../Graphics/Draw.h ../Common/Options.h ../Parser/OpenFile.h \
   ../Graphics/SelectBuffer.h GUI_Projection.h ../Common/GmshUI.h \
   ../Geo/FProjectionFace.h ../Geo/GModel.h ../Geo/Range.h GUI.h \
@@ -141,7 +212,56 @@ GUI_Projection.o: GUI_Projection.cpp ../Geo/GModelIO_F.h ../Geo/GModel.h \
   SpherePosition_Widget.h Shortcut_Window.h GUI_Extras.h ../Geo/FFace.h \
   ../Geo/GFace.h ../Geo/GModel.h ../Geo/Range.h ../Geo/FEdge.h \
   ../Geo/GEdge.h ../Geo/GModel.h ../Geo/FVertex.h ../Geo/GModel.h \
-  ../Geo/GVertex.h ../Geo/Range.h ../Common/Message.h
+  ../Geo/GVertex.h /Users/remacle/SOURCES/FourierModel/FM_TopoVertex.h \
+  ../Geo/Range.h ../Common/Message.h \
+  /Users/remacle/SOURCES/FourierModel/FM_TopoEdge.h \
+  /Users/remacle/SOURCES/FourierModel/FM_Curve.h \
+  /Users/remacle/SOURCES/FourierModel/FM_TopoVertex.h \
+  /Users/remacle/SOURCES/FourierModel/FM_TopoFace.h \
+  /Users/remacle/SOURCES/FourierModel/FM_Patch.h \
+  /Users/remacle/SOURCES/FourierModel/FM_TopoEdge.h \
+  /Users/remacle/SOURCES/FourierModel/FM_FPatch.h \
+  /Users/remacle/SOURCES/FourierModel/FM_Patch.h \
+  /Users/remacle/SOURCES/FourierModel/FM_PartitionOfUnity.h \
+  /Users/remacle/SOURCES/FourierModel/FM_ProjectionSurface.h \
+  /Users/remacle/SOURCES/FourierModel/FM_WFPatch.h \
+  /Users/remacle/SOURCES/FourierModel/FM_Patch.h \
+  /Users/remacle/SOURCES/FourierModel/FM_PartitionOfUnity.h \
+  /Users/remacle/SOURCES/FourierModel/FM_ProjectionSurface.h \
+  /Users/remacle/SOURCES/FourierModel/FM_PlaneProjectionSurface.h \
+  /Users/remacle/SOURCES/FourierModel/FM_ProjectionSurface.h \
+  /Users/remacle/SOURCES/FourierModel/FM_ParaboloidProjectionSurface.h \
+  /Users/remacle/SOURCES/FourierModel/FM_Utils.h \
+  /Users/remacle/SOURCES/FourierModel/FM_ProjectionSurface.h \
+  /Users/remacle/SOURCES/FourierModel/FM_CylindricalProjectionSurface.h \
+  /Users/remacle/SOURCES/FourierModel/FM_ProjectionSurface.h \
+  /Users/remacle/SOURCES/FourierModel/FM_RevolvedParabolaProjectionSurface.h \
+  /Users/remacle/SOURCES/FourierModel/FM_Utils.h \
+  /Users/remacle/SOURCES/FourierModel/FM_ProjectionSurface.h \
+  /Users/remacle/SOURCES/FourierModel/FM_TranslatedParabolaProjectionSurface.h \
+  /Users/remacle/SOURCES/FourierModel/FM_Utils.h \
+  /Users/remacle/SOURCES/FourierModel/FM_ProjectionSurface.h
+GUI_Classifier.o: GUI_Classifier.cpp GUI_Classifier.h ../Common/GmshUI.h \
+  ../Geo/GModel.h ../Geo/GVertex.h ../Geo/GEntity.h ../Geo/Range.h \
+  ../Geo/SPoint3.h ../Geo/SBoundingBox3d.h ../Geo/SPoint3.h \
+  ../Common/GmshDefines.h ../Geo/MVertex.h ../Geo/SPoint3.h \
+  ../Geo/GPoint.h ../Geo/SPoint2.h ../Geo/GEdge.h ../Geo/GEntity.h \
+  ../Geo/GVertex.h ../Geo/SVector3.h ../Geo/SPoint3.h ../Geo/SPoint3.h \
+  ../Geo/SPoint2.h ../Geo/MElement.h ../Geo/MVertex.h ../Geo/MEdge.h \
+  ../Geo/MVertex.h ../Geo/SVector3.h ../Common/Hash.h ../Geo/MFace.h \
+  ../Geo/MVertex.h ../Geo/SVector3.h ../Numeric/Numeric.h \
+  ../Common/Context.h ../DataStr/List.h ../Geo/ExtrudeParams.h \
+  ../Common/SmoothData.h ../Geo/GFace.h ../Geo/GPoint.h ../Geo/GEntity.h \
+  ../Geo/GEdgeLoop.h ../Geo/GEdge.h ../Geo/MElement.h ../Geo/SPoint2.h \
+  ../Geo/SVector3.h ../Geo/Pair.h ../Geo/ExtrudeParams.h ../Geo/GRegion.h \
+  ../Geo/GEntity.h ../Geo/MElement.h ../Geo/ExtrudeParams.h \
+  ../Geo/SBoundingBox3d.h GUI.h Opengl_Window.h Colorbar_Window.h \
+  ../Post/ColorTable.h Popup_Button.h SpherePosition_Widget.h \
+  Shortcut_Window.h ../Graphics/Draw.h ../Common/Options.h \
+  ../Graphics/SelectBuffer.h GUI_Projection.h ../Geo/FProjectionFace.h \
+  ../Geo/GModel.h ../Geo/Range.h \
+  /Users/remacle/SOURCES/FourierModel/FM_ProjectionSurface.h GUI_Extras.h \
+  ../Common/Message.h
 Callbacks.o: Callbacks.cpp ../Common/Gmsh.h ../Common/Message.h \
   ../DataStr/Malloc.h ../DataStr/List.h ../DataStr/Tree.h \
   ../DataStr/avl.h ../DataStr/Tools.h ../DataStr/List.h ../DataStr/Tree.h \
@@ -165,12 +285,47 @@ Callbacks.o: Callbacks.cpp ../Common/Gmsh.h ../Common/Message.h \
   ../Geo/MElement.h ../Geo/ExtrudeParams.h ../Geo/SBoundingBox3d.h \
   ../Graphics/Draw.h ../Graphics/SelectBuffer.h ../Post/Views.h \
   ../Post/ColorTable.h ../Common/VertexArray.h ../Post/AdaptiveViews.h \
-  ../Common/GmshMatrix.h ../Parser/CreateFile.h ../Parser/OpenFile.h \
+  ../Common/GmshMatrix.h /sw/include/gsl/gsl_linalg.h \
+  /sw/include/gsl/gsl_mode.h /sw/include/gsl/gsl_permutation.h \
+  /sw/include/gsl/gsl_types.h /sw/include/gsl/gsl_errno.h \
+  /sw/include/gsl/gsl_check_range.h /sw/include/gsl/gsl_vector.h \
+  /sw/include/gsl/gsl_vector_complex_long_double.h \
+  /sw/include/gsl/gsl_complex.h /sw/include/gsl/gsl_vector_long_double.h \
+  /sw/include/gsl/gsl_block_long_double.h \
+  /sw/include/gsl/gsl_vector_complex.h \
+  /sw/include/gsl/gsl_block_complex_long_double.h \
+  /sw/include/gsl/gsl_vector_complex_double.h \
+  /sw/include/gsl/gsl_vector_double.h /sw/include/gsl/gsl_block_double.h \
+  /sw/include/gsl/gsl_block_complex_double.h \
+  /sw/include/gsl/gsl_vector_complex_float.h \
+  /sw/include/gsl/gsl_vector_float.h /sw/include/gsl/gsl_block_float.h \
+  /sw/include/gsl/gsl_block_complex_float.h \
+  /sw/include/gsl/gsl_vector_ulong.h /sw/include/gsl/gsl_block_ulong.h \
+  /sw/include/gsl/gsl_vector_long.h /sw/include/gsl/gsl_block_long.h \
+  /sw/include/gsl/gsl_vector_uint.h /sw/include/gsl/gsl_block_uint.h \
+  /sw/include/gsl/gsl_vector_int.h /sw/include/gsl/gsl_block_int.h \
+  /sw/include/gsl/gsl_vector_ushort.h /sw/include/gsl/gsl_block_ushort.h \
+  /sw/include/gsl/gsl_vector_short.h /sw/include/gsl/gsl_block_short.h \
+  /sw/include/gsl/gsl_vector_uchar.h /sw/include/gsl/gsl_block_uchar.h \
+  /sw/include/gsl/gsl_vector_char.h /sw/include/gsl/gsl_block_char.h \
+  /sw/include/gsl/gsl_matrix.h \
+  /sw/include/gsl/gsl_matrix_complex_long_double.h \
+  /sw/include/gsl/gsl_matrix_complex_double.h \
+  /sw/include/gsl/gsl_matrix_complex_float.h \
+  /sw/include/gsl/gsl_matrix_long_double.h \
+  /sw/include/gsl/gsl_matrix_double.h /sw/include/gsl/gsl_matrix_float.h \
+  /sw/include/gsl/gsl_matrix_ulong.h /sw/include/gsl/gsl_matrix_long.h \
+  /sw/include/gsl/gsl_matrix_uint.h /sw/include/gsl/gsl_matrix_int.h \
+  /sw/include/gsl/gsl_matrix_ushort.h /sw/include/gsl/gsl_matrix_short.h \
+  /sw/include/gsl/gsl_matrix_uchar.h /sw/include/gsl/gsl_matrix_char.h \
+  /sw/include/gsl/gsl_blas.h /sw/include/gsl/gsl_blas_types.h \
+  /sw/include/gsl/gsl_cblas.h ../Parser/CreateFile.h ../Parser/OpenFile.h \
   ../Common/CommandLine.h ../Common/Options.h GUI.h Opengl_Window.h \
   Colorbar_Window.h Popup_Button.h SpherePosition_Widget.h GUI_Extras.h \
   Callbacks.h ../Plugin/Plugin.h ../Plugin/PluginManager.h \
   ../Plugin/Plugin.h ../Common/Visibility.h ../Common/GmshDefines.h \
-  Solvers.h ../Common/OS.h ../Mesh/Field.h ../Post/OctreePost.h \
+  Solvers.h ../Common/OS.h ../Mesh/Field.h \
+  ../contrib/ANN/include/ANN/ANN.h ../Post/OctreePost.h \
   ../Common/Octree.h ../Common/OctreeInternals.h ../Mesh/BackgroundMesh.h
 Opengl.o: Opengl.cpp ../Common/Gmsh.h ../Common/Message.h \
   ../DataStr/Malloc.h ../DataStr/List.h ../DataStr/Tree.h \
diff --git a/Fltk/Message.cpp b/Fltk/Message.cpp
index 824c9bb671796005483e4529132c0b5d298794f0..8eeec3e6f857da8510226ccebe922268e8018c0f 100644
--- a/Fltk/Message.cpp
+++ b/Fltk/Message.cpp
@@ -1,4 +1,4 @@
-// $Id: Message.cpp,v 1.80 2007-05-04 14:27:41 geuzaine Exp $
+// $Id: Message.cpp,v 1.81 2007-09-04 13:47:01 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/Geo/GEdgeLoop.cpp b/Geo/GEdgeLoop.cpp
index b9cac08afd8426b0ecd2b31c23566f70a6c056da..53d7388b95d639e6a6bdead9a6551e387829c8cd 100644
--- a/Geo/GEdgeLoop.cpp
+++ b/Geo/GEdgeLoop.cpp
@@ -1,4 +1,4 @@
-// $Id: GEdgeLoop.cpp,v 1.5 2007-01-19 15:34:05 geuzaine Exp $
+// $Id: GEdgeLoop.cpp,v 1.6 2007-09-04 13:47:01 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/Geo/GFace.h b/Geo/GFace.h
index 3e9124e2b4afc54e83fdfde70c317852970d6712..cb1d1847c117ef221f82b03da1a9596d05e7f6cf 100644
--- a/Geo/GFace.h
+++ b/Geo/GFace.h
@@ -105,6 +105,13 @@ class GFace : public GEntity
   virtual GPoint point(double par1, double par2) const = 0;
   virtual GPoint point(const SPoint2 &pt) const { return point(pt.x(), pt.y()); }
 
+  // If the mapping is a conforming mapping, i.e. a mapping that conserves angles,
+  // this function returns the eigenvalue of the metric at a given point
+  // this is a special feature for stereographic mappings of the sphere
+  // that is used in 2D mesh generation !
+
+  virtual double getMetricEigenvalue ( const SPoint2 &) {throw;}
+
   // Return the parmater location on the face given a point in space
   // that is on the face.
   virtual SPoint2 parFromPoint(const SPoint3 &) const;
diff --git a/Geo/GModelIO_Geo.cpp b/Geo/GModelIO_Geo.cpp
index fcf48f119bbed7586894a7fe3134b7b1bdcb769d..7513e85ca1d4a15b450b14e9d5eaeb8004422991 100644
--- a/Geo/GModelIO_Geo.cpp
+++ b/Geo/GModelIO_Geo.cpp
@@ -1,4 +1,4 @@
-// $Id: GModelIO_Geo.cpp,v 1.11 2007-03-18 12:05:16 geuzaine Exp $
+// $Id: GModelIO_Geo.cpp,v 1.12 2007-09-04 13:47:01 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/Geo/GModelIO_OCC.cpp b/Geo/GModelIO_OCC.cpp
index 85e4d0b9c855270addc0aaeec8dc19f15c6d223b..c061d4673f404edc1e6f3ca2a4628e748930d10e 100644
--- a/Geo/GModelIO_OCC.cpp
+++ b/Geo/GModelIO_OCC.cpp
@@ -1,4 +1,4 @@
-// $Id: GModelIO_OCC.cpp,v 1.20 2007-04-23 07:59:25 geuzaine Exp $
+// $Id: GModelIO_OCC.cpp,v 1.21 2007-09-04 13:47:01 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/Geo/GRegion.cpp b/Geo/GRegion.cpp
index cd856b6d4f6f74d11ba1264bd8119d4f24960c91..7d27487930f96a5a852a83399a722f15901c5a60 100644
--- a/Geo/GRegion.cpp
+++ b/Geo/GRegion.cpp
@@ -1,4 +1,4 @@
-// $Id: GRegion.cpp,v 1.16 2007-05-10 22:08:03 geuzaine Exp $
+// $Id: GRegion.cpp,v 1.17 2007-09-04 13:47:01 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/Geo/MElement.cpp b/Geo/MElement.cpp
index cc5245408f247ff455d1126b893393b846cdde8d..d4a88c20a7deb376149c18d9d5e5e90604e736b7 100644
--- a/Geo/MElement.cpp
+++ b/Geo/MElement.cpp
@@ -1,4 +1,4 @@
-// $Id: MElement.cpp,v 1.36 2007-07-26 13:10:48 geuzaine Exp $
+// $Id: MElement.cpp,v 1.37 2007-09-04 13:47:01 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
@@ -22,10 +22,12 @@
 #include <math.h>
 #include "MElement.h"
 #include "GEntity.h"
+#include "GFace.h"
 #include "Numeric.h"
 #include "Message.h"
 #include "Context.h"
 
+
 extern Context_T CTX;
 
 int MElement::_globalNum = 0;
@@ -342,6 +344,53 @@ bool MTriangle::invertmappingXY(double *p, double *uv, double tol)
   return false; 
 }
 
+
+bool MTriangle::invertmappingUV(GFace* gf, double *p, double *uv, double tol)
+{
+  double mat[2][2];
+  double b[2];
+
+  double u0,v0,u1,v1,u2,v2;
+
+  parametricCoordinates ( getVertex(0), gf, u0, v0);
+  parametricCoordinates ( getVertex(1), gf, u1, v1);
+  parametricCoordinates ( getVertex(2), gf, u2, v2);
+  
+  mat[0][0] = u1 - u0;
+  mat[0][1] = u2 - u0;
+  mat[1][0] = v1 - v0;
+  mat[1][1] = v2 - v0;
+
+  b[0] = p[0] - u0;
+  b[1] = p[1] - v0;
+  sys2x2(mat, b, uv);
+
+  if(uv[0] >= -tol && 
+     uv[1] >= -tol && 
+     uv[0] <= 1. + tol && 
+     uv[1] <= 1. + tol && 
+     1. - uv[0] - uv[1] > -tol) {
+    return true;
+  }
+  return false; 
+}
+
+
+double MTriangle::getSurfaceUV(GFace *gf)
+{
+  double u3,v3,u1,v1,u2,v2;
+
+  parametricCoordinates ( getVertex(0), gf, u1, v1);
+  parametricCoordinates ( getVertex(1), gf, u2, v2);
+  parametricCoordinates ( getVertex(2), gf, u3, v3);
+
+  const double vv1 [2] = {u2 - u1, v2 - v1};
+  const double vv2 [2] = {u3 - u1, v3 - v1};
+
+  double s = vv1[0] * vv2[1] - vv1[1] * vv2[0]; 
+  return s * 0.5;
+}
+
 double MTriangle::getSurfaceXY() const
 {
   const double x1 = _v[0]->x();
@@ -373,21 +422,40 @@ void MTriangle::circumcenterXYZ(double *p1, double *p2, double *p3,double *res)
 
   circumcenterXY(p1P, p2P, p3P,resP);
 
-//   double d1 = sqrt((p2P[0] - resP[0]) * (p2P[0] - resP[0]) +
-// 		   (p2P[1] - resP[1]) * (p2P[1] - resP[1]));
-
-//   double d2 = sqrt((p1P[0] - resP[0]) * (p1P[0] - resP[0]) +
-// 		   (p1P[1] - resP[1]) * (p1P[1] - resP[1])) ;
+//    double d1 = sqrt((p2P[0] - resP[0]) * (p2P[0] - resP[0]) +
+//  		   (p2P[1] - resP[1]) * (p2P[1] - resP[1]));
 
-//   double d3 = sqrt((p3P[0] - resP[0]) * (p3P[0] - resP[0]) +
-// 		   (p3P[1] - resP[1]) * (p3P[1] - resP[1]) );
+//    double d2 = sqrt((p1P[0] - resP[0]) * (p1P[0] - resP[0]) +
+//  		   (p1P[1] - resP[1]) * (p1P[1] - resP[1])) ;
 
+//    double d3 = sqrt((p3P[0] - resP[0]) * (p3P[0] - resP[0]) +
+//  		   (p3P[1] - resP[1]) * (p3P[1] - resP[1]) );
 
-  //  printf("%g %g - %g %g -- %g %g %g\n",p2P[0],p2P[1],p3P[0],p3P[1],d1,d2,d3);
 
+//   printf("%g %g - %g %g -- %g %g %g\n",p2P[0],p2P[1],p3P[0],p3P[1],d1,d2,d3);
+  
   res[0] = p1[0] + resP[0] * vx[0] + resP[1] * vy[0];
   res[1] = p1[1] + resP[0] * vx[1] + resP[1] * vy[1];
   res[2] = p1[2] + resP[0] * vx[2] + resP[1] * vy[2];
+  
+  return;
+
+  double d1 = sqrt((p1[0] - res[0]) * (p1[0] - res[0]) +
+  		   (p1[1] - res[1]) * (p1[1] - res[1]) +
+  		   (p1[2] - res[2]) * (p1[2] - res[2]) );
+  double d2 = sqrt((p2[0] - res[0]) * (p2[0] - res[0]) +
+  		   (p2[1] - res[1]) * (p2[1] - res[1]) +
+  		   (p2[2] - res[2]) * (p2[2] - res[2]) );
+  double d3 = sqrt((p3[0] - res[0]) * (p3[0] - res[0]) +
+  		   (p3[1] - res[1]) * (p3[1] - res[1]) +
+  		   (p3[2] - res[2]) * (p3[2] - res[2]) );
+  		   
+
+
+  printf("%g %g %g\n",d1,d2,d3);
+  
+
+
 }
 
 void MTriangle::circumcenterXY(double *p1, double *p2, double *p3, double *res)
@@ -415,6 +483,46 @@ void MTriangle::circumcenterXY(double *p1, double *p2, double *p3, double *res)
   res[1] = (double)((a1 * (x2 - x3) + a2 * (x3 - x1) + a3 * (x1 - x2)) / d);
 }
 
+
+void MTriangle::circumcenterUV(GFace *gf, double *res)
+{
+  double u3,v3,u1,v1,u2,v2;
+
+  parametricCoordinates ( getVertex(0), gf, u1, v1);
+  parametricCoordinates ( getVertex(1), gf, u2, v2);
+  parametricCoordinates ( getVertex(2), gf, u3, v3);
+
+//   Pair<SVector3,SVector3> der = gf->firstDer(SPoint2((u1+u2+u3)/3.,(v1+v2+v3)/3.)) ;
+//   const double a = dot(der.first() ,der.first() );
+//   const double b = dot(der.second(),der.first() );
+//   const double d = dot(der.second(),der.second()); 
+
+//   double sys[2][2];
+//   double rhs[2];
+
+//   sys[0][0] = 2. * a * (u1 - u2) + 2. * b * (v1 - v2);
+//   sys[0][1] = 2. * d * (v1 - v2) + 2. * b * (u1 - u2);
+//   sys[1][0] = 2. * a * (u1 - u3) + 2. * b * (v1 - v3);
+//   sys[1][1] = 2. * d * (v1 - v3) + 2. * b * (u1 - u3);
+
+//   rhs[0] =
+//     a * (u1 * u1 - u2 * u2) + d * (v1 * v1 - v2 * v2) + 2. * b * (u1 * v1 -
+//                                                                   u2 * v2);
+//   rhs[1] =
+//     a * (u1 * u1 - u3 * u3) + d * (v1 * v1 - v3 * v3) + 2. * b * (u1 * v1 -
+//                                                                   u3 * v3);
+//   sys2x2(sys, rhs, res);
+
+//   return;
+   double p1[2] ={u1,v1};
+   double p2[2] ={u2,v2};
+   double p3[2] ={u3,v3};
+  
+//   printf("%g %g vs ",res[0],res[1]);
+  circumcenterXY(p1,p2,p3,res);
+  //  printf("%g %g \n ",res[0],res[1]);
+}
+
 void MTriangle::circumcenterXY(double *res) const
 {
   double p1[2] = {_v[0]->x(),_v[0]->y()};
diff --git a/Geo/MElement.h b/Geo/MElement.h
index 9e9a23bf9d096295a35fff841037c76ebd4988a9..b01ad669f321ec00e790cb69db6685e4749ce706 100644
--- a/Geo/MElement.h
+++ b/Geo/MElement.h
@@ -29,6 +29,8 @@
 #include "MFace.h"
 #include "Numeric.h"
 
+class GFace;
+
 // A mesh element.
 class MElement 
 {
@@ -311,10 +313,13 @@ class MTriangle : public MElement {
     mat[1][1] = _v[2]->y() - _v[0]->y();
   }
   void circumcenterXY(double *res) const; 
+  void circumcenterUV(GFace*,double *res); 
   static void circumcenterXYZ(double *p1, double *p2, double *p3,double *res);
   static void circumcenterXY (double *p1, double *p2, double *p3,double *res);
   double getSurfaceXY() const;
+  double getSurfaceUV(GFace*);
   bool invertmappingXY(double *p, double *uv, double tol = 1.e-8);
+  bool invertmappingUV(GFace*,double *p, double *uv, double tol = 1.e-8);
   virtual int getNumVertices(){ return 3; }
   virtual MVertex *getVertex(int num){ return _v[num]; }
   virtual MVertex *getOtherVertex(MVertex *v1, MVertex *v2){ 
@@ -763,11 +768,8 @@ class MTetrahedron : public MElement {
     }
     return false;
   }
-  inline void circumcenter(double *res)
+  inline static void circumcenter(double X[4],double Y[4],double Z[4],double *res)
   {
-    double X[4] = {_v[0]->x(), _v[1]->x(), _v[2]->x(), _v[3]->x()};
-    double Y[4] = {_v[0]->y(), _v[1]->y(), _v[2]->y(), _v[3]->y()};
-    double Z[4] = {_v[0]->z(), _v[1]->z(), _v[2]->z(), _v[3]->z()};
     double mat[3][3], b[3], dum;    
     b[0] = X[1] * X[1] - X[0] * X[0] +
       Y[1] * Y[1] - Y[0] * Y[0] + Z[1] * Z[1] - Z[0] * Z[0];
@@ -790,6 +792,14 @@ class MTetrahedron : public MElement {
       res[0] = res[1] = res[2] = 10.0e10;
     }
   }
+  inline void circumcenter(double *res)
+  {
+    double X[4] = {_v[0]->x(), _v[1]->x(), _v[2]->x(), _v[3]->x()};
+    double Y[4] = {_v[0]->y(), _v[1]->y(), _v[2]->y(), _v[3]->y()};
+    double Z[4] = {_v[0]->z(), _v[1]->z(), _v[2]->z(), _v[3]->z()};
+
+    MTetrahedron::circumcenter (X,Y,Z,res); 
+  }
 };
 
 class MTetrahedron10 : public MTetrahedron {
diff --git a/Geo/MVertex.cpp b/Geo/MVertex.cpp
index e63b430dda9f0f10d4401ef575d6331690b2dc0e..57e89354bad5813a34ab8282c77bfe1fd3ccf2db 100644
--- a/Geo/MVertex.cpp
+++ b/Geo/MVertex.cpp
@@ -1,4 +1,4 @@
-// $Id: MVertex.cpp,v 1.14 2007-07-31 22:09:11 geuzaine Exp $
+// $Id: MVertex.cpp,v 1.15 2007-09-04 13:47:01 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
@@ -21,6 +21,8 @@
 
 #include <math.h>
 #include "MVertex.h"
+#include "GEdge.h"
+#include "GFace.h"
 
 int MVertex::_globalNum = 0;
 double MVertexLessThanLexicographic::tolerance = 1.e-6;
@@ -154,3 +156,29 @@ MVertex::linearSearch(std::set<MVertex*, MVertexLessThanLexicographic> &pos)
   }
   return pos.end();
 }
+
+void parametricCoordinates ( const MVertex*ver, const GFace *gf, double &u, double &v)
+{
+  GEntity *ge = ver->onWhat();
+  if (ge->dim() == 2)
+    {
+      ver->getParameter ( 0,u);
+      ver->getParameter ( 1,v);	  
+    }
+  else if (ge->dim() == 1)
+    {
+      double t;
+      ver->getParameter ( 0,t);
+      GEdge *ged = dynamic_cast<GEdge*> (ge);
+      SPoint2 p = ged->reparamOnFace ( (GFace*)gf , t , 1);
+      u =p.x(); 
+      v =p.y(); 
+    }
+  else
+    {
+      GVertex *gver = dynamic_cast<GVertex*> (ge);
+      SPoint2 p = gver->reparamOnFace ( (GFace*)gf , 1);
+      u =p.x(); 
+      v =p.y(); 
+    }      
+}
diff --git a/Geo/MVertex.h b/Geo/MVertex.h
index 895e1d12f2e8a73e6e3010eccb8ce514ad039c8c..8fd9a5b5f92b0a025d6204c0ea8c703473ea3f1f 100644
--- a/Geo/MVertex.h
+++ b/Geo/MVertex.h
@@ -25,6 +25,7 @@
 #include "SPoint3.h"
 
 class GEntity;
+class GFace;
 class MVertex;
 
 class MVertexLessThanLexicographic{
@@ -85,7 +86,7 @@ class MVertex{
   inline void setNum(int num) { _num = num; }
 
   // get/set ith parameter
-  virtual bool getParameter(int i, double &par){ return false; }
+  virtual bool getParameter(int i, double &par) const{ return false; }
   virtual bool setParameter(int i, double par){ return false; }
 
   // measure distance to another vertex
@@ -123,7 +124,7 @@ class MEdgeVertex : public MVertex{
   {
   }
   virtual ~MEdgeVertex(){}
-  virtual bool getParameter(int i, double &par){ par = _u; return true; }
+  virtual bool getParameter(int i, double &par) const{ par = _u; return true; }
   virtual bool setParameter(int i, double par){ _u = par; return true; }
 };
 
@@ -136,22 +137,10 @@ class MFaceVertex : public MVertex{
   {
   }
   virtual ~MFaceVertex(){}
-  virtual bool getParameter(int i, double &par){ par = (i ? _v : _u); return true; }
+  virtual bool getParameter(int i, double &par)const { par = (i ? _v : _u); return true; }
   virtual bool setParameter(int i, double par){ if(!i) _u = par; else _v = par; return true; }
 };
 
-template<class T>
-class MDataFaceVertex : public MFaceVertex{
- private:
-  T _data;
- public :
-  MDataFaceVertex(double x, double y, double z, GEntity *ge, double u, double v, T data) 
-    : MFaceVertex(x, y, z, ge, u, v), _data(data)
-  {
-  }
-  virtual ~MDataFaceVertex(){}
-  virtual bool getData(T &data){ data = _data; return true; }
-  virtual void *getData(){ return (void*)&_data; }
-};
+void parametricCoordinates ( const MVertex*ver, const GFace *gf, double &u, double &v);
 
 #endif
diff --git a/Geo/OCCEdge.cpp b/Geo/OCCEdge.cpp
index 6dad6617fd3bed5844815c0ab2248e565821febc..666b20505fc9467b800a3c7dd08fc6ed4efbc392 100644
--- a/Geo/OCCEdge.cpp
+++ b/Geo/OCCEdge.cpp
@@ -1,4 +1,4 @@
-// $Id: OCCEdge.cpp,v 1.21 2007-02-27 17:15:47 remacle Exp $
+// $Id: OCCEdge.cpp,v 1.22 2007-09-04 13:47:01 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/Geo/OCCRegion.cpp b/Geo/OCCRegion.cpp
index d0b82fc46b7fb1344634c2376920bc6521151c2c..e56f8871ac0d0e307f698ee35a5c26a1d9d81b68 100644
--- a/Geo/OCCRegion.cpp
+++ b/Geo/OCCRegion.cpp
@@ -1,4 +1,4 @@
-// $Id: OCCRegion.cpp,v 1.5 2007-01-16 11:31:41 geuzaine Exp $
+// $Id: OCCRegion.cpp,v 1.6 2007-09-04 13:47:01 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/Geo/gmshFace.cpp b/Geo/gmshFace.cpp
index b03c7b8132604b6a576ffaefeba12c611e70b382..a1aca8329f068596371f77870ef2606af2f218c1 100644
--- a/Geo/gmshFace.cpp
+++ b/Geo/gmshFace.cpp
@@ -1,4 +1,4 @@
-// $Id: gmshFace.cpp,v 1.39 2007-02-26 08:25:38 geuzaine Exp $
+// $Id: gmshFace.cpp,v 1.40 2007-09-04 13:47:01 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
@@ -86,6 +86,13 @@ gmshFace::gmshFace(GModel *m, Surface *face)
   resetMeshAttributes();
 }
 
+
+double gmshFace::getMetricEigenvalue ( const SPoint2 &pt) 
+{
+  if(!s->geometry)return 1;
+  return s->geometry->getMetricEigenvalue (pt) ;
+}
+
 gmshFace::gmshFace(GModel *m, int num)
   : GFace(m, num)
 {
diff --git a/Geo/gmshFace.h b/Geo/gmshFace.h
index fad081652ada01da98e5f5b562968ef508507394..acc622367a3a5ffa5e2b94c358dc04169479066b 100644
--- a/Geo/gmshFace.h
+++ b/Geo/gmshFace.h
@@ -41,7 +41,7 @@ class gmshFace : public GFace {
   
   virtual int containsPoint(const SPoint3 &pt) const;  
   virtual int containsParam(const SPoint2 &pt) const; 
-  
+  virtual double getMetricEigenvalue ( const SPoint2 &);  
   virtual SVector3 normal(const SPoint2 &param) const; 
   virtual Pair<SVector3,SVector3> firstDer(const SPoint2 &param) const; 
   
diff --git a/Geo/gmshRegion.cpp b/Geo/gmshRegion.cpp
index 4e8f646c9392616108a4fc29d599cf404b7246d1..9421e0f2aaa1b640774e82697125b93d2a663226 100644
--- a/Geo/gmshRegion.cpp
+++ b/Geo/gmshRegion.cpp
@@ -1,4 +1,4 @@
-// $Id: gmshRegion.cpp,v 1.14 2007-02-12 08:36:11 geuzaine Exp $
+// $Id: gmshRegion.cpp,v 1.15 2007-09-04 13:47:01 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/Geo/gmshSurface.h b/Geo/gmshSurface.h
index 1084acb233cab6b6e5d5378f9c3ad82e394caffa..f09883a6da2013f4ce05fd13e79d5cb5f14c35ac 100644
--- a/Geo/gmshSurface.h
+++ b/Geo/gmshSurface.h
@@ -63,6 +63,7 @@ public:
   virtual SVector3 normal(const SPoint2 &param) const = 0;
   // Return the first derivate of the face at the parameter location.
   virtual Pair<SVector3,SVector3> firstDer(const SPoint2 &param) const = 0;
+  virtual double getMetricEigenvalue ( const SPoint2 &) {throw;}
 };
 
 class gmshSphere : public gmshSurface
@@ -136,6 +137,12 @@ public:
     // 2 be done
     throw;
   }  
+  virtual double getMetricEigenvalue ( const SPoint2 &p)
+  {
+    double l = (4*r*r)/(4*r*r+p.x()*p.x()+p.y()*p.y());
+    return l*l;
+  }
+
 };
 
 
diff --git a/Graphics/ReadImg.cpp b/Graphics/ReadImg.cpp
index 753d35f0b6dbe0de1af3c12ccc7d92295657666a..f0f2f433051e63cdcc59711e990265930e4d3959 100644
--- a/Graphics/ReadImg.cpp
+++ b/Graphics/ReadImg.cpp
@@ -1,4 +1,4 @@
-// $Id: ReadImg.cpp,v 1.17 2006-11-27 22:22:16 geuzaine Exp $
+// $Id: ReadImg.cpp,v 1.18 2007-09-04 13:47:01 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/Graphics/gl2ps.cpp b/Graphics/gl2ps.cpp
index cc3f979285712f2a9d0feb28bc7766e22cd48c2d..77bbf9001ac1338229b954356d12665ba3ec2aa1 100644
--- a/Graphics/gl2ps.cpp
+++ b/Graphics/gl2ps.cpp
@@ -1,4 +1,4 @@
-/* $Id: gl2ps.cpp,v 1.111 2007-01-25 15:50:57 geuzaine Exp $ */
+/* $Id: gl2ps.cpp,v 1.112 2007-09-04 13:47:01 remacle Exp $ */
 /*
  * GL2PS, an OpenGL to PostScript Printing Library
  * Copyright (C) 1999-2006 Christophe Geuzaine <geuz@geuz.org>
diff --git a/Graphics/gl2ps.h b/Graphics/gl2ps.h
index 47dc48a6ed13f78062f15e18af40bc129f5752d5..351692580addc88eae97771972ae3f758a3f0830 100644
--- a/Graphics/gl2ps.h
+++ b/Graphics/gl2ps.h
@@ -1,4 +1,4 @@
-/* $Id: gl2ps.h,v 1.69 2007-01-25 15:50:58 geuzaine Exp $ */
+/* $Id: gl2ps.h,v 1.70 2007-09-04 13:47:02 remacle Exp $ */
 /*
  * GL2PS, an OpenGL to PostScript Printing Library
  * Copyright (C) 1999-2006 Christophe Geuzaine <geuz@geuz.org>
diff --git a/Mesh/BDS.cpp b/Mesh/BDS.cpp
index 485e83ab958c45556ab8d052f7ee873f1cd40dc6..e51a7a7c7756390f827bf11e2868e6e7a4e5cee0 100644
--- a/Mesh/BDS.cpp
+++ b/Mesh/BDS.cpp
@@ -1,4 +1,4 @@
-// $Id: BDS.cpp,v 1.76 2007-04-13 12:49:52 remacle Exp $
+// $Id: BDS.cpp,v 1.77 2007-09-04 13:47:02 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
@@ -206,7 +206,7 @@ int Intersect_Edges_2d(double x1, double y1, double x2, double y2,
   return 0;
 }
 
-BDS_Edge *BDS_Mesh::recover_edge(int num1, int num2)
+BDS_Edge *BDS_Mesh::recover_edge(int num1, int num2,std::set<EdgeToRecover> *e2r)
 {
   BDS_Edge *e = find_edge (num1, num2);
 
@@ -233,11 +233,18 @@ BDS_Edge *BDS_Mesh::recover_edge(int num1, int num2)
 				  e->p2->u, e->p2->v,
 				  p1->u, p1->v,
 				  p2->u, p2->v))
-	      intersected.push_back(e);	  
+	      {
+		if (e2r && e2r->find(EdgeToRecover(e->p1->iD,e->p2->iD,0)) != e2r->end())
+		  {
+		    Msg(GERROR," edge %d %d cannot be recovered because it intersects %d %d",num1,num2,e->p1->iD,e->p2->iD);
+		    return false;
+		  }
+		intersected.push_back(e);	  
+	      }
 	  ++it;
 	}
 
-      if (!intersected.size() || ix > 10000)
+      if (!intersected.size() || ix > 100)
 	{
 	  BDS_Edge *eee = find_edge (num1, num2);
 	  if (!eee)
diff --git a/Mesh/BDS.h b/Mesh/BDS.h
index 67f4a6f8ba399794c1b2775b1c8387dce3255add..a7d1b6d9fda30ac2ab609d6756c6586577f99ea4 100644
--- a/Mesh/BDS.h
+++ b/Mesh/BDS.h
@@ -159,7 +159,10 @@ public:
 
 class BDS_Point 
 {
-  double _lc;
+  // the first size is the one dictated by the Background Mesh
+  // the second one is dictated by charecteristic lengths at points
+  // and is propagated
+  double _lcBGM, _lcPTS;
 public:
   double X,Y,Z; // Real COORDINATES
   double u,v;   // Parametric COORDINATES
@@ -169,8 +172,8 @@ public:
   std::list<BDS_Edge*> edges;
 
   // just a transition
-  double & radius () {return _lc;}
-  double & lc     () {return _lc;}
+  double & lcBGM  () {return _lcBGM;}
+  double & lc     () {return _lcPTS;}
   
   inline bool operator < (const BDS_Point & other) const
   {
@@ -190,7 +193,7 @@ public:
   }
   void getTriangles(std::list<BDS_Face *> &t) const; 	
   BDS_Point(int id, double x=0, double y=0, double z=0)
-    : _lc(1.e22),X(x),Y(y),Z(z),u(0),v(0),config_modified(true),iD(id),g(0)
+    : _lcBGM(1.e22),_lcPTS(1.e22),X(x),Y(y),Z(z),u(0),v(0),config_modified(true),iD(id),g(0)
   {	    
   }
 };
@@ -380,6 +383,32 @@ class BDS_SwapEdgeTestDelaunay : public BDS_SwapEdgeTest
   virtual ~BDS_SwapEdgeTestDelaunay(){}
 };
 
+struct EdgeToRecover 
+{
+  int p1,p2;
+  GEdge *ge;
+  EdgeToRecover ( int  _p1 ,  int  _p2 , GEdge *_ge) : ge(_ge)
+  {
+    if (_p1 < _p2 )
+      {
+	p1 = _p1 ;
+	p2 = _p2 ;
+      }
+    else
+      {
+	p2 = _p1 ;
+	p1 = _p2 ;
+      }
+  }
+  bool operator < ( const EdgeToRecover & other) const
+  {    
+    if ( p1 < other.p1 ) return true;
+    if ( p1 > other.p1 ) return false;
+    if ( p2 < other.p2 ) return true;
+    return false;
+  }
+};
+
 class BDS_Mesh 
 {    
 public:
@@ -418,7 +447,7 @@ public:
   void add_geom(int degree, int tag);
   BDS_GeomEntity *get_geom(int p1, int p2);
   // 2D operators
-  BDS_Edge *recover_edge(int p1, int p2);
+  BDS_Edge *recover_edge(int p1, int p2, std::set<EdgeToRecover> *e2r=0);
   bool swap_edge(BDS_Edge *, const BDS_SwapEdgeTest &theTest);
   bool collapse_edge_parametric(BDS_Edge *, BDS_Point*);
   void snap_point(BDS_Point* , BDS_Mesh *geom = 0);
diff --git a/Mesh/BackgroundMesh.cpp b/Mesh/BackgroundMesh.cpp
index 530e54d4cc655af34b07f5f1f45ec247aaa9cef2..6683773ff9a611cec71cd66146d7f861c61c15e5 100644
--- a/Mesh/BackgroundMesh.cpp
+++ b/Mesh/BackgroundMesh.cpp
@@ -1,4 +1,4 @@
-// $Id: BackgroundMesh.cpp,v 1.22 2007-05-24 14:44:06 remacle Exp $
+// $Id: BackgroundMesh.cpp,v 1.23 2007-09-04 13:47:02 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
@@ -38,7 +38,7 @@ MinField lc_field;
 
 bool BGMExists() 
 {
-  return lc_field.empty();
+  return !lc_field.empty();
 }
 
 void BGMAddField(Field *field)
@@ -56,6 +56,22 @@ void BGMReset()
 // CTX.mesh.min_circ_points tells the minimum number of points per
 // radius of curvature
 
+static double max_edge_curvature(const GVertex *gv)
+{
+  double max_curvature = 0;
+  std::list<GEdge*> l_edges = gv->edges();
+  for (std::list<GEdge*>::const_iterator ite = l_edges.begin(); 
+       ite != l_edges.end(); ++ite){
+    GEdge *_myGEdge = *ite;
+    Range<double> range = _myGEdge->parBounds(0);      
+    double cc;
+    if (gv == _myGEdge->getBeginVertex())cc = _myGEdge->curvature (range.low());
+    else cc = _myGEdge->curvature (range.high());
+    max_curvature = std::max(max_curvature,cc);
+  }
+  return max_curvature;
+}
+
 static double max_surf_curvature(const GVertex *gv)
 {
   double max_curvature = 0;
@@ -100,20 +116,23 @@ double LC_MVertex_CURV(GEntity *ge, double U, double V)
   double Crv = 0;
   switch(ge->dim()){
   case 0:
-    Crv = max_surf_curvature ( (const GVertex *)ge);
+    Crv = max_edge_curvature ( (const GVertex *)ge);
+    Crv = std::max(max_surf_curvature ( (const GVertex *)ge),Crv);
+    //    printf("point %d coucou %g\n",ge->tag(),Crv);
     break;
   case 1:
     {
       GEdge *ged = (GEdge *)ge;
       Crv = ged->curvature(U);
       //      printf("coucou %12.5E %d\n",Crv,CTX.mesh.min_circ_points);
-      //Crv = max_surf_curvature(ged, U);
+      Crv = std::max(Crv,max_surf_curvature(ged, U));
+      
     }
     break;
   case 2:
     {
-      //      GFace *gf = (GFace *)ge;
-      //      Crv = gf->curvature(SPoint2(U, V));
+      GFace *gf = (GFace *)ge;
+      Crv = gf->curvature(SPoint2(U, V));
     }
     break;
   }
@@ -165,16 +184,17 @@ double BGM_MeshSize(GEntity *ge, double U, double V, double X, double Y, double
   double l3 = CTX.lc;
   double l4 = lc_field.empty() ? MAX_LC : lc_field(X, Y, Z);
 
-  if(l4 < MAX_LC && !CTX.mesh.constrained_bgmesh)
-    return l4 * CTX.mesh.lc_factor;
+  if(CTX.mesh.lc_from_curvature && ge->dim() < 3)
+    l1 = LC_MVertex_CURV(ge, U, V);
+
+  if(l4 < MAX_LC && CTX.mesh.constrained_bgmesh)
+    return std::min(l4,l1) * CTX.mesh.lc_factor;
 
   if(ge->dim() < 2) 
     l2 = LC_MVertex_PNTS(ge, U, V);
 
-  if(CTX.mesh.lc_from_curvature && ge->dim() < 3)
-    l1 = LC_MVertex_CURV(ge, U, V);
   
-  //  printf("l1 = %12.5E l2 = %12.5E\n",l1,l2);
+  //  printf("l1 = %12.5E l2 = %12.5E l4 = %12.5E\n",l1,l2,l4);
 
   double lc = std::min(std::min(std::min(l1, l2), l3), l4);
   return lc * CTX.mesh.lc_factor;
diff --git a/Mesh/DivideAndConquer.cpp b/Mesh/DivideAndConquer.cpp
index 6d4c6fe6449cdd6ae4aeabdb5c79c5e476dd3126..09729dd480a5574ddbb9e09c746943aad6c6c43e 100644
--- a/Mesh/DivideAndConquer.cpp
+++ b/Mesh/DivideAndConquer.cpp
@@ -1,4 +1,4 @@
-// $Id: DivideAndConquer.cpp,v 1.9 2007-01-16 11:31:41 geuzaine Exp $
+// $Id: DivideAndConquer.cpp,v 1.10 2007-09-04 13:47:02 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/Mesh/Field.cpp b/Mesh/Field.cpp
index 038673ca95a106d22eb6b425567c1fb795e96186..b7fa28f50222d39a527e3215206afbeeff5a82ef 100644
--- a/Mesh/Field.cpp
+++ b/Mesh/Field.cpp
@@ -1,4 +1,4 @@
-// $Id: Field.cpp,v 1.4 2007-05-24 13:57:59 remacle Exp $
+// $Id: Field.cpp,v 1.5 2007-09-04 13:47:02 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
@@ -26,6 +26,7 @@
 #include "Field.h"
 #include "Context.h"
 #include "GeoInterpolation.h"
+#include "GModel.h"
 #ifdef HAVE_MATH_EVAL
 #include "matheval.h"
 #endif
@@ -321,7 +322,7 @@ double MinField::operator()(double x, double y, double z)
 
 // Attractor Field
 #define maxpts  1
-void AttractorField::addPoint(double X, double Y, double Z, double lc)
+void AttractorField::addPoint(double X, double Y, double Z)
 {
   attractorPoints.push_back(SPoint3(X, Y, Z));
 }
@@ -406,3 +407,59 @@ void AttractorField::addGEdge(GEdge *c, int N)
     addPoint(gp.x(), gp.y(), gp.z());
   }
 }
+
+void addMapLc (std::map<MVertex*,double> &maplc, MVertex *v, double l)
+{
+  std::map<MVertex*,double> :: iterator it = maplc.find(v);
+  if (it == maplc.end())maplc[v] = l;
+  else if (it->second > l) it->second = l;
+}
+
+
+AttractorField_1DMesh::AttractorField_1DMesh (GModel *m, double dmax, double dmin, double lcmax)
+  : _dmax(dmax), _dmin(dmin), _lcmax(lcmax)
+{
+  GModel::eiter it = m->firstEdge();
+
+  std::map<MVertex*,double> maplc;
+
+  while (it != m->lastEdge())
+    {
+      MVertex *first = (*it)->getBeginVertex()->mesh_vertices[0];
+      for (int i=1;i<=(*it)->mesh_vertices.size();++i)
+	{
+	  MVertex *last = i==(*it)->mesh_vertices.size() ? (*it)->getEndVertex()->mesh_vertices[0]:(*it)->mesh_vertices[i];
+	  double l = sqrt((first->x()-last->x())*(first->x()-last->x())+
+			  (first->y()-last->y())*(first->y()-last->y())+
+			  (first->z()-last->z())*(first->z()-last->z()));
+	  addMapLc(maplc,first,l);
+	  addMapLc(maplc,last,l);
+	  first = last;
+	}
+    }      
+
+  std::map<MVertex*,double> :: iterator itm = maplc.begin();
+  
+  while (itm != maplc.end())
+    {
+      addPoint(itm->first->x(),itm->first->y(),itm->first->z());
+      lcs.push_back(itm->second);
+    }  
+}
+
+
+double AttractorField_1DMesh::operator()(double X, double Y, double Z)
+{
+#ifdef HAVE_ANN_
+  double xyz[3] = {X, Y, Z};
+  kdtree->annkSearch(xyz, maxpts, index, dist);
+  double d = sqrt(dist[0]);
+  double lcmin = lcs[index[0]];
+  double r = (d - _dmin) / (_dmax - _dmin);
+  r = std::max(std::min(r, 1.), 0.);
+  double lc = lcmin * (1 - r) + _lcmax * r;
+  return lc;
+#else
+  Msg(GERROR,"GMSH should be compiled with ANN in order to enable attractors");
+#endif
+}
diff --git a/Mesh/Field.h b/Mesh/Field.h
index 4449416ad5f09e9ecd8507f88cb9ea7e314bd1b0..a4c063b9e52048410597933a61951048c1b2a923 100644
--- a/Mesh/Field.h
+++ b/Mesh/Field.h
@@ -20,6 +20,7 @@
 // 
 // Please report all bugs and problems to <gmsh@geuz.org>.
 
+#include <vector>
 #include <map>
 #include <list>
 #include "Views.h"
@@ -127,11 +128,23 @@ protected :
 public :
   AttractorField();
   virtual ~AttractorField();
-  void addPoint(double X, double Y, double Z, double lc = -1.0);
+  void addPoint(double X, double Y, double Z);
   void buildFastSearchStructures() ;
   void addGEdge(GEdge*, int);
   void addCurve(Curve*, int);
-  double operator()(double X, double Y, double Z) ;
+  virtual double operator()(double X, double Y, double Z) ;
 };
 
+class AttractorField_1DMesh : public AttractorField 
+{
+protected:
+  std::vector<double> lcs;
+  double _dmax,_dmin,_lcmax;
+public:
+  AttractorField_1DMesh (GModel *m, double dmax, double dmin, double lcmax);
+  virtual double operator()(double X, double Y, double Z) ;
+};
+
+
+
 #endif
diff --git a/Mesh/Makefile b/Mesh/Makefile
index 8334072528010f613ec7354c4db9454e94cc2cc4..981c8d3a10f5cbc62d90a9ad66a883233c84ab86 100644
--- a/Mesh/Makefile
+++ b/Mesh/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.179 2007-08-24 20:14:18 geuzaine Exp $
+# $Id: Makefile,v 1.180 2007-09-04 13:47:02 remacle Exp $
 #
 # Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 #
@@ -38,6 +38,7 @@ SRC = Generator.cpp \
         meshGFaceTransfinite.cpp \
         meshGFaceExtruded.cpp \
         meshGFaceDelaunayInsertion.cpp \
+        meshGFaceOptimize.cpp \
         meshGRegion.cpp \
         meshGRegionDelaunayInsertion.cpp \
         meshGRegionTransfinite.cpp \
@@ -82,8 +83,42 @@ Generator.o: Generator.cpp ../Common/Gmsh.h ../Common/Message.h \
   ../Numeric/Numeric.h ../Common/Context.h ../Post/Views.h \
   ../Post/ColorTable.h ../Common/VertexArray.h ../Geo/SVector3.h \
   ../Geo/SPoint3.h ../Common/SmoothData.h ../Post/AdaptiveViews.h \
-  ../Common/GmshMatrix.h ../Common/OS.h ../Geo/GModel.h ../Geo/GVertex.h \
-  ../Geo/GEntity.h ../Geo/Range.h ../Geo/SPoint3.h \
+  ../Common/GmshMatrix.h /sw/include/gsl/gsl_linalg.h \
+  /sw/include/gsl/gsl_mode.h /sw/include/gsl/gsl_permutation.h \
+  /sw/include/gsl/gsl_types.h /sw/include/gsl/gsl_errno.h \
+  /sw/include/gsl/gsl_check_range.h /sw/include/gsl/gsl_vector.h \
+  /sw/include/gsl/gsl_vector_complex_long_double.h \
+  /sw/include/gsl/gsl_complex.h /sw/include/gsl/gsl_vector_long_double.h \
+  /sw/include/gsl/gsl_block_long_double.h \
+  /sw/include/gsl/gsl_vector_complex.h \
+  /sw/include/gsl/gsl_block_complex_long_double.h \
+  /sw/include/gsl/gsl_vector_complex_double.h \
+  /sw/include/gsl/gsl_vector_double.h /sw/include/gsl/gsl_block_double.h \
+  /sw/include/gsl/gsl_block_complex_double.h \
+  /sw/include/gsl/gsl_vector_complex_float.h \
+  /sw/include/gsl/gsl_vector_float.h /sw/include/gsl/gsl_block_float.h \
+  /sw/include/gsl/gsl_block_complex_float.h \
+  /sw/include/gsl/gsl_vector_ulong.h /sw/include/gsl/gsl_block_ulong.h \
+  /sw/include/gsl/gsl_vector_long.h /sw/include/gsl/gsl_block_long.h \
+  /sw/include/gsl/gsl_vector_uint.h /sw/include/gsl/gsl_block_uint.h \
+  /sw/include/gsl/gsl_vector_int.h /sw/include/gsl/gsl_block_int.h \
+  /sw/include/gsl/gsl_vector_ushort.h /sw/include/gsl/gsl_block_ushort.h \
+  /sw/include/gsl/gsl_vector_short.h /sw/include/gsl/gsl_block_short.h \
+  /sw/include/gsl/gsl_vector_uchar.h /sw/include/gsl/gsl_block_uchar.h \
+  /sw/include/gsl/gsl_vector_char.h /sw/include/gsl/gsl_block_char.h \
+  /sw/include/gsl/gsl_matrix.h \
+  /sw/include/gsl/gsl_matrix_complex_long_double.h \
+  /sw/include/gsl/gsl_matrix_complex_double.h \
+  /sw/include/gsl/gsl_matrix_complex_float.h \
+  /sw/include/gsl/gsl_matrix_long_double.h \
+  /sw/include/gsl/gsl_matrix_double.h /sw/include/gsl/gsl_matrix_float.h \
+  /sw/include/gsl/gsl_matrix_ulong.h /sw/include/gsl/gsl_matrix_long.h \
+  /sw/include/gsl/gsl_matrix_uint.h /sw/include/gsl/gsl_matrix_int.h \
+  /sw/include/gsl/gsl_matrix_ushort.h /sw/include/gsl/gsl_matrix_short.h \
+  /sw/include/gsl/gsl_matrix_uchar.h /sw/include/gsl/gsl_matrix_char.h \
+  /sw/include/gsl/gsl_blas.h /sw/include/gsl/gsl_blas_types.h \
+  /sw/include/gsl/gsl_cblas.h ../Common/OS.h ../Geo/GModel.h \
+  ../Geo/GVertex.h ../Geo/GEntity.h ../Geo/Range.h ../Geo/SPoint3.h \
   ../Geo/SBoundingBox3d.h ../Geo/SPoint3.h ../Common/GmshDefines.h \
   ../Geo/MVertex.h ../Geo/SPoint3.h ../Geo/GPoint.h ../Geo/SPoint2.h \
   ../Geo/GEdge.h ../Geo/GEntity.h ../Geo/GVertex.h ../Geo/SVector3.h \
@@ -109,14 +144,52 @@ Field.o: Field.cpp ../Mesh/BDS.h ../Geo/GFace.h ../Geo/GPoint.h \
   ../Common/SmoothData.h ../Geo/MElement.h ../Geo/SPoint2.h \
   ../Geo/SVector3.h ../Geo/Pair.h ../Geo/ExtrudeParams.h ../Post/Views.h \
   ../Post/ColorTable.h ../Common/VertexArray.h ../Post/AdaptiveViews.h \
-  ../Common/GmshMatrix.h ../Common/Gmsh.h ../Common/Message.h \
+  ../Common/GmshMatrix.h /sw/include/gsl/gsl_linalg.h \
+  /sw/include/gsl/gsl_mode.h /sw/include/gsl/gsl_permutation.h \
+  /sw/include/gsl/gsl_types.h /sw/include/gsl/gsl_errno.h \
+  /sw/include/gsl/gsl_check_range.h /sw/include/gsl/gsl_vector.h \
+  /sw/include/gsl/gsl_vector_complex_long_double.h \
+  /sw/include/gsl/gsl_complex.h /sw/include/gsl/gsl_vector_long_double.h \
+  /sw/include/gsl/gsl_block_long_double.h \
+  /sw/include/gsl/gsl_vector_complex.h \
+  /sw/include/gsl/gsl_block_complex_long_double.h \
+  /sw/include/gsl/gsl_vector_complex_double.h \
+  /sw/include/gsl/gsl_vector_double.h /sw/include/gsl/gsl_block_double.h \
+  /sw/include/gsl/gsl_block_complex_double.h \
+  /sw/include/gsl/gsl_vector_complex_float.h \
+  /sw/include/gsl/gsl_vector_float.h /sw/include/gsl/gsl_block_float.h \
+  /sw/include/gsl/gsl_block_complex_float.h \
+  /sw/include/gsl/gsl_vector_ulong.h /sw/include/gsl/gsl_block_ulong.h \
+  /sw/include/gsl/gsl_vector_long.h /sw/include/gsl/gsl_block_long.h \
+  /sw/include/gsl/gsl_vector_uint.h /sw/include/gsl/gsl_block_uint.h \
+  /sw/include/gsl/gsl_vector_int.h /sw/include/gsl/gsl_block_int.h \
+  /sw/include/gsl/gsl_vector_ushort.h /sw/include/gsl/gsl_block_ushort.h \
+  /sw/include/gsl/gsl_vector_short.h /sw/include/gsl/gsl_block_short.h \
+  /sw/include/gsl/gsl_vector_uchar.h /sw/include/gsl/gsl_block_uchar.h \
+  /sw/include/gsl/gsl_vector_char.h /sw/include/gsl/gsl_block_char.h \
+  /sw/include/gsl/gsl_matrix.h \
+  /sw/include/gsl/gsl_matrix_complex_long_double.h \
+  /sw/include/gsl/gsl_matrix_complex_double.h \
+  /sw/include/gsl/gsl_matrix_complex_float.h \
+  /sw/include/gsl/gsl_matrix_long_double.h \
+  /sw/include/gsl/gsl_matrix_double.h /sw/include/gsl/gsl_matrix_float.h \
+  /sw/include/gsl/gsl_matrix_ulong.h /sw/include/gsl/gsl_matrix_long.h \
+  /sw/include/gsl/gsl_matrix_uint.h /sw/include/gsl/gsl_matrix_int.h \
+  /sw/include/gsl/gsl_matrix_ushort.h /sw/include/gsl/gsl_matrix_short.h \
+  /sw/include/gsl/gsl_matrix_uchar.h /sw/include/gsl/gsl_matrix_char.h \
+  /sw/include/gsl/gsl_blas.h /sw/include/gsl/gsl_blas_types.h \
+  /sw/include/gsl/gsl_cblas.h ../Common/Gmsh.h ../Common/Message.h \
   ../DataStr/Malloc.h ../DataStr/Tree.h ../DataStr/avl.h \
   ../DataStr/Tools.h ../DataStr/List.h ../DataStr/Tree.h Field.h \
-  ../Geo/Geo.h ../Geo/gmshSurface.h ../Geo/Pair.h ../Geo/Range.h \
-  ../Geo/SPoint2.h ../Geo/SPoint3.h ../Geo/SVector3.h \
-  ../Geo/SBoundingBox3d.h ../Geo/SPoint2.h ../Geo/ExtrudeParams.h \
-  ../Post/OctreePost.h ../Common/Octree.h ../Common/OctreeInternals.h \
-  ../Geo/GeoInterpolation.h ../Geo/Geo.h
+  ../contrib/ANN/include/ANN/ANN.h ../Geo/Geo.h ../Geo/gmshSurface.h \
+  ../Geo/Pair.h ../Geo/Range.h ../Geo/SPoint2.h ../Geo/SPoint3.h \
+  ../Geo/SVector3.h ../Geo/SBoundingBox3d.h ../Geo/SPoint2.h \
+  ../Geo/ExtrudeParams.h ../Post/OctreePost.h ../Common/Octree.h \
+  ../Common/OctreeInternals.h ../Geo/GeoInterpolation.h ../Geo/Geo.h \
+  ../Geo/GModel.h ../Geo/GVertex.h ../Geo/GEdge.h ../Geo/GFace.h \
+  ../Geo/GRegion.h ../Geo/GEntity.h ../Geo/MElement.h \
+  ../Geo/ExtrudeParams.h ../Geo/SBoundingBox3d.h \
+  ../contrib/MathEval/matheval.h
 meshGEdge.o: meshGEdge.cpp ../Common/Gmsh.h ../Common/Message.h \
   ../DataStr/Malloc.h ../DataStr/List.h ../DataStr/Tree.h \
   ../DataStr/avl.h ../DataStr/Tools.h ../DataStr/List.h ../DataStr/Tree.h \
@@ -156,20 +229,55 @@ meshGFace.o: meshGFace.cpp meshGFace.h meshGFaceDelaunayInsertion.h \
   ../Geo/SPoint3.h ../Geo/MEdge.h ../Geo/MVertex.h ../Geo/SVector3.h \
   ../Geo/SPoint3.h ../Common/Hash.h ../Geo/MFace.h ../Geo/MVertex.h \
   ../Geo/SVector3.h ../Numeric/Numeric.h ../Common/Context.h \
-  ../DataStr/List.h DivideAndConquer.h BackgroundMesh.h ../Geo/GVertex.h \
-  ../Geo/GEntity.h ../Geo/Range.h ../Geo/SPoint3.h \
-  ../Geo/SBoundingBox3d.h ../Geo/SPoint3.h ../Geo/MVertex.h \
-  ../Geo/GPoint.h ../Geo/SPoint2.h ../Geo/GEdge.h ../Geo/GEntity.h \
-  ../Geo/GVertex.h ../Geo/SVector3.h ../Geo/SPoint3.h ../Geo/SPoint2.h \
-  ../Geo/MElement.h ../Geo/ExtrudeParams.h ../Common/SmoothData.h \
-  ../Geo/GFace.h ../Geo/GPoint.h ../Geo/GEntity.h ../Geo/GEdgeLoop.h \
-  ../Geo/GEdge.h ../Geo/MElement.h ../Geo/SPoint2.h ../Geo/SVector3.h \
-  ../Geo/Pair.h ../Geo/ExtrudeParams.h ../Geo/MRep.h ../Geo/GEdge.h \
-  ../Geo/GFace.h ../Geo/GRegion.h ../Geo/GEntity.h ../Geo/MElement.h \
-  ../Geo/ExtrudeParams.h ../Geo/MVertex.h ../Geo/MEdge.h \
-  ../Geo/MElement.h ../Common/VertexArray.h ../Common/Message.h \
-  ../Common/OS.h BDS.h ../Post/Views.h ../Post/ColorTable.h \
-  ../Post/AdaptiveViews.h ../Common/GmshMatrix.h
+  ../DataStr/List.h meshGFaceOptimize.h DivideAndConquer.h \
+  BackgroundMesh.h ../Geo/GVertex.h ../Geo/GEntity.h ../Geo/Range.h \
+  ../Geo/SPoint3.h ../Geo/SBoundingBox3d.h ../Geo/SPoint3.h \
+  ../Geo/MVertex.h ../Geo/GPoint.h ../Geo/SPoint2.h ../Geo/GEdge.h \
+  ../Geo/GEntity.h ../Geo/GVertex.h ../Geo/SVector3.h ../Geo/SPoint3.h \
+  ../Geo/SPoint2.h ../Geo/MElement.h ../Geo/ExtrudeParams.h \
+  ../Common/SmoothData.h ../Geo/GFace.h ../Geo/GPoint.h ../Geo/GEntity.h \
+  ../Geo/GEdgeLoop.h ../Geo/GEdge.h ../Geo/MElement.h ../Geo/SPoint2.h \
+  ../Geo/SVector3.h ../Geo/Pair.h ../Geo/ExtrudeParams.h ../Geo/MRep.h \
+  ../Geo/GEdge.h ../Geo/GFace.h ../Geo/GRegion.h ../Geo/GEntity.h \
+  ../Geo/MElement.h ../Geo/ExtrudeParams.h ../Geo/MVertex.h \
+  ../Geo/MEdge.h ../Geo/MElement.h ../Common/VertexArray.h \
+  ../Common/Message.h ../Common/OS.h BDS.h ../Post/Views.h \
+  ../Post/ColorTable.h ../Post/AdaptiveViews.h ../Common/GmshMatrix.h \
+  /sw/include/gsl/gsl_linalg.h /sw/include/gsl/gsl_mode.h \
+  /sw/include/gsl/gsl_permutation.h /sw/include/gsl/gsl_types.h \
+  /sw/include/gsl/gsl_errno.h /sw/include/gsl/gsl_check_range.h \
+  /sw/include/gsl/gsl_vector.h \
+  /sw/include/gsl/gsl_vector_complex_long_double.h \
+  /sw/include/gsl/gsl_complex.h /sw/include/gsl/gsl_vector_long_double.h \
+  /sw/include/gsl/gsl_block_long_double.h \
+  /sw/include/gsl/gsl_vector_complex.h \
+  /sw/include/gsl/gsl_block_complex_long_double.h \
+  /sw/include/gsl/gsl_vector_complex_double.h \
+  /sw/include/gsl/gsl_vector_double.h /sw/include/gsl/gsl_block_double.h \
+  /sw/include/gsl/gsl_block_complex_double.h \
+  /sw/include/gsl/gsl_vector_complex_float.h \
+  /sw/include/gsl/gsl_vector_float.h /sw/include/gsl/gsl_block_float.h \
+  /sw/include/gsl/gsl_block_complex_float.h \
+  /sw/include/gsl/gsl_vector_ulong.h /sw/include/gsl/gsl_block_ulong.h \
+  /sw/include/gsl/gsl_vector_long.h /sw/include/gsl/gsl_block_long.h \
+  /sw/include/gsl/gsl_vector_uint.h /sw/include/gsl/gsl_block_uint.h \
+  /sw/include/gsl/gsl_vector_int.h /sw/include/gsl/gsl_block_int.h \
+  /sw/include/gsl/gsl_vector_ushort.h /sw/include/gsl/gsl_block_ushort.h \
+  /sw/include/gsl/gsl_vector_short.h /sw/include/gsl/gsl_block_short.h \
+  /sw/include/gsl/gsl_vector_uchar.h /sw/include/gsl/gsl_block_uchar.h \
+  /sw/include/gsl/gsl_vector_char.h /sw/include/gsl/gsl_block_char.h \
+  /sw/include/gsl/gsl_matrix.h \
+  /sw/include/gsl/gsl_matrix_complex_long_double.h \
+  /sw/include/gsl/gsl_matrix_complex_double.h \
+  /sw/include/gsl/gsl_matrix_complex_float.h \
+  /sw/include/gsl/gsl_matrix_long_double.h \
+  /sw/include/gsl/gsl_matrix_double.h /sw/include/gsl/gsl_matrix_float.h \
+  /sw/include/gsl/gsl_matrix_ulong.h /sw/include/gsl/gsl_matrix_long.h \
+  /sw/include/gsl/gsl_matrix_uint.h /sw/include/gsl/gsl_matrix_int.h \
+  /sw/include/gsl/gsl_matrix_ushort.h /sw/include/gsl/gsl_matrix_short.h \
+  /sw/include/gsl/gsl_matrix_uchar.h /sw/include/gsl/gsl_matrix_char.h \
+  /sw/include/gsl/gsl_blas.h /sw/include/gsl/gsl_blas_types.h \
+  /sw/include/gsl/gsl_cblas.h
 meshGFaceTransfinite.o: meshGFaceTransfinite.cpp meshGFace.h \
   ../Geo/GVertex.h ../Geo/GEntity.h ../Geo/Range.h ../Geo/SPoint3.h \
   ../Geo/SBoundingBox3d.h ../Geo/SPoint3.h ../Common/GmshDefines.h \
@@ -211,8 +319,56 @@ meshGFaceDelaunayInsertion.o: meshGFaceDelaunayInsertion.cpp BDS.h \
   ../Geo/ExtrudeParams.h ../Common/SmoothData.h ../Geo/MElement.h \
   ../Geo/SPoint2.h ../Geo/SVector3.h ../Geo/Pair.h ../Geo/ExtrudeParams.h \
   ../Post/Views.h ../Post/ColorTable.h ../Common/VertexArray.h \
-  ../Post/AdaptiveViews.h ../Common/GmshMatrix.h BackgroundMesh.h \
-  meshGFaceDelaunayInsertion.h ../Common/Message.h
+  ../Post/AdaptiveViews.h ../Common/GmshMatrix.h \
+  /sw/include/gsl/gsl_linalg.h /sw/include/gsl/gsl_mode.h \
+  /sw/include/gsl/gsl_permutation.h /sw/include/gsl/gsl_types.h \
+  /sw/include/gsl/gsl_errno.h /sw/include/gsl/gsl_check_range.h \
+  /sw/include/gsl/gsl_vector.h \
+  /sw/include/gsl/gsl_vector_complex_long_double.h \
+  /sw/include/gsl/gsl_complex.h /sw/include/gsl/gsl_vector_long_double.h \
+  /sw/include/gsl/gsl_block_long_double.h \
+  /sw/include/gsl/gsl_vector_complex.h \
+  /sw/include/gsl/gsl_block_complex_long_double.h \
+  /sw/include/gsl/gsl_vector_complex_double.h \
+  /sw/include/gsl/gsl_vector_double.h /sw/include/gsl/gsl_block_double.h \
+  /sw/include/gsl/gsl_block_complex_double.h \
+  /sw/include/gsl/gsl_vector_complex_float.h \
+  /sw/include/gsl/gsl_vector_float.h /sw/include/gsl/gsl_block_float.h \
+  /sw/include/gsl/gsl_block_complex_float.h \
+  /sw/include/gsl/gsl_vector_ulong.h /sw/include/gsl/gsl_block_ulong.h \
+  /sw/include/gsl/gsl_vector_long.h /sw/include/gsl/gsl_block_long.h \
+  /sw/include/gsl/gsl_vector_uint.h /sw/include/gsl/gsl_block_uint.h \
+  /sw/include/gsl/gsl_vector_int.h /sw/include/gsl/gsl_block_int.h \
+  /sw/include/gsl/gsl_vector_ushort.h /sw/include/gsl/gsl_block_ushort.h \
+  /sw/include/gsl/gsl_vector_short.h /sw/include/gsl/gsl_block_short.h \
+  /sw/include/gsl/gsl_vector_uchar.h /sw/include/gsl/gsl_block_uchar.h \
+  /sw/include/gsl/gsl_vector_char.h /sw/include/gsl/gsl_block_char.h \
+  /sw/include/gsl/gsl_matrix.h \
+  /sw/include/gsl/gsl_matrix_complex_long_double.h \
+  /sw/include/gsl/gsl_matrix_complex_double.h \
+  /sw/include/gsl/gsl_matrix_complex_float.h \
+  /sw/include/gsl/gsl_matrix_long_double.h \
+  /sw/include/gsl/gsl_matrix_double.h /sw/include/gsl/gsl_matrix_float.h \
+  /sw/include/gsl/gsl_matrix_ulong.h /sw/include/gsl/gsl_matrix_long.h \
+  /sw/include/gsl/gsl_matrix_uint.h /sw/include/gsl/gsl_matrix_int.h \
+  /sw/include/gsl/gsl_matrix_ushort.h /sw/include/gsl/gsl_matrix_short.h \
+  /sw/include/gsl/gsl_matrix_uchar.h /sw/include/gsl/gsl_matrix_char.h \
+  /sw/include/gsl/gsl_blas.h /sw/include/gsl/gsl_blas_types.h \
+  /sw/include/gsl/gsl_cblas.h BackgroundMesh.h \
+  meshGFaceDelaunayInsertion.h meshGFace.h ../Common/Message.h
+meshGFaceOptimize.o: meshGFaceOptimize.cpp meshGFaceOptimize.h \
+  ../Geo/MElement.h ../Common/GmshDefines.h ../Geo/MVertex.h \
+  ../Geo/SPoint3.h ../Geo/MEdge.h ../Geo/MVertex.h ../Geo/SVector3.h \
+  ../Geo/SPoint3.h ../Common/Hash.h ../Geo/MFace.h ../Geo/MVertex.h \
+  ../Geo/SVector3.h ../Numeric/Numeric.h ../Common/Context.h \
+  ../DataStr/List.h ../Geo/GFace.h ../Geo/GPoint.h ../Geo/GEntity.h \
+  ../Geo/Range.h ../Geo/SPoint3.h ../Geo/SBoundingBox3d.h \
+  ../Geo/SPoint3.h ../Geo/GEdgeLoop.h ../Geo/GEdge.h ../Geo/GEntity.h \
+  ../Geo/GVertex.h ../Geo/GEntity.h ../Geo/MVertex.h ../Geo/GPoint.h \
+  ../Geo/SPoint2.h ../Geo/SVector3.h ../Geo/SPoint3.h ../Geo/SPoint2.h \
+  ../Geo/MElement.h ../Geo/ExtrudeParams.h ../Common/SmoothData.h \
+  ../Geo/MElement.h ../Geo/SPoint2.h ../Geo/SVector3.h ../Geo/Pair.h \
+  ../Geo/ExtrudeParams.h
 meshGRegion.o: meshGRegion.cpp meshGRegion.h \
   meshGRegionDelaunayInsertion.h ../Geo/MElement.h \
   ../Common/GmshDefines.h ../Geo/MVertex.h ../Geo/SPoint3.h \
@@ -236,7 +392,44 @@ meshGRegion.o: meshGRegion.cpp meshGRegion.h \
   ../Geo/GFace.h ../Geo/GRegion.h ../Geo/MVertex.h ../Geo/MEdge.h \
   ../Geo/MElement.h ../Common/VertexArray.h ../Common/Message.h \
   ../Common/OS.h BDS.h ../Post/Views.h ../Post/ColorTable.h \
-  ../Post/AdaptiveViews.h ../Common/GmshMatrix.h
+  ../Post/AdaptiveViews.h ../Common/GmshMatrix.h \
+  /sw/include/gsl/gsl_linalg.h /sw/include/gsl/gsl_mode.h \
+  /sw/include/gsl/gsl_permutation.h /sw/include/gsl/gsl_types.h \
+  /sw/include/gsl/gsl_errno.h /sw/include/gsl/gsl_check_range.h \
+  /sw/include/gsl/gsl_vector.h \
+  /sw/include/gsl/gsl_vector_complex_long_double.h \
+  /sw/include/gsl/gsl_complex.h /sw/include/gsl/gsl_vector_long_double.h \
+  /sw/include/gsl/gsl_block_long_double.h \
+  /sw/include/gsl/gsl_vector_complex.h \
+  /sw/include/gsl/gsl_block_complex_long_double.h \
+  /sw/include/gsl/gsl_vector_complex_double.h \
+  /sw/include/gsl/gsl_vector_double.h /sw/include/gsl/gsl_block_double.h \
+  /sw/include/gsl/gsl_block_complex_double.h \
+  /sw/include/gsl/gsl_vector_complex_float.h \
+  /sw/include/gsl/gsl_vector_float.h /sw/include/gsl/gsl_block_float.h \
+  /sw/include/gsl/gsl_block_complex_float.h \
+  /sw/include/gsl/gsl_vector_ulong.h /sw/include/gsl/gsl_block_ulong.h \
+  /sw/include/gsl/gsl_vector_long.h /sw/include/gsl/gsl_block_long.h \
+  /sw/include/gsl/gsl_vector_uint.h /sw/include/gsl/gsl_block_uint.h \
+  /sw/include/gsl/gsl_vector_int.h /sw/include/gsl/gsl_block_int.h \
+  /sw/include/gsl/gsl_vector_ushort.h /sw/include/gsl/gsl_block_ushort.h \
+  /sw/include/gsl/gsl_vector_short.h /sw/include/gsl/gsl_block_short.h \
+  /sw/include/gsl/gsl_vector_uchar.h /sw/include/gsl/gsl_block_uchar.h \
+  /sw/include/gsl/gsl_vector_char.h /sw/include/gsl/gsl_block_char.h \
+  /sw/include/gsl/gsl_matrix.h \
+  /sw/include/gsl/gsl_matrix_complex_long_double.h \
+  /sw/include/gsl/gsl_matrix_complex_double.h \
+  /sw/include/gsl/gsl_matrix_complex_float.h \
+  /sw/include/gsl/gsl_matrix_long_double.h \
+  /sw/include/gsl/gsl_matrix_double.h /sw/include/gsl/gsl_matrix_float.h \
+  /sw/include/gsl/gsl_matrix_ulong.h /sw/include/gsl/gsl_matrix_long.h \
+  /sw/include/gsl/gsl_matrix_uint.h /sw/include/gsl/gsl_matrix_int.h \
+  /sw/include/gsl/gsl_matrix_ushort.h /sw/include/gsl/gsl_matrix_short.h \
+  /sw/include/gsl/gsl_matrix_uchar.h /sw/include/gsl/gsl_matrix_char.h \
+  /sw/include/gsl/gsl_blas.h /sw/include/gsl/gsl_blas_types.h \
+  /sw/include/gsl/gsl_cblas.h ../contrib/Tetgen/tetgen.h \
+  ../contrib/Netgen/libsrc/interface/nglib.h \
+  ../contrib/Netgen/nglib_addon.h
 meshGRegionDelaunayInsertion.o: meshGRegionDelaunayInsertion.cpp \
   BackgroundMesh.h meshGRegionDelaunayInsertion.h ../Geo/MElement.h \
   ../Common/GmshDefines.h ../Geo/MVertex.h ../Geo/SPoint3.h \
@@ -296,7 +489,7 @@ meshGRegionCarveHole.o: meshGRegionCarveHole.cpp ../Geo/GModel.h \
   ../Geo/MElement.h ../Geo/SPoint2.h ../Geo/SVector3.h ../Geo/Pair.h \
   ../Geo/ExtrudeParams.h ../Geo/GRegion.h ../Geo/GEntity.h \
   ../Geo/MElement.h ../Geo/ExtrudeParams.h ../Geo/SBoundingBox3d.h \
-  ../Common/Message.h
+  ../Common/Message.h ../contrib/ANN/include/ANN/ANN.h
 DivideAndConquer.o: DivideAndConquer.cpp ../Common/Gmsh.h \
   ../Common/Message.h ../DataStr/Malloc.h ../DataStr/List.h \
   ../DataStr/Tree.h ../DataStr/avl.h ../DataStr/Tools.h ../DataStr/List.h \
@@ -307,9 +500,43 @@ BackgroundMesh.o: BackgroundMesh.cpp ../Common/Gmsh.h ../Common/Message.h \
   ../Post/Views.h ../Post/ColorTable.h ../Common/VertexArray.h \
   ../Geo/SVector3.h ../Geo/SPoint3.h ../Common/SmoothData.h \
   ../Numeric/Numeric.h ../Post/AdaptiveViews.h ../Common/GmshMatrix.h \
-  BackgroundMesh.h ../Common/Context.h ../Post/OctreePost.h \
-  ../Common/Octree.h ../Common/OctreeInternals.h ../Geo/GVertex.h \
-  ../Geo/GEntity.h ../Geo/Range.h ../Geo/SPoint3.h \
+  /sw/include/gsl/gsl_linalg.h /sw/include/gsl/gsl_mode.h \
+  /sw/include/gsl/gsl_permutation.h /sw/include/gsl/gsl_types.h \
+  /sw/include/gsl/gsl_errno.h /sw/include/gsl/gsl_check_range.h \
+  /sw/include/gsl/gsl_vector.h \
+  /sw/include/gsl/gsl_vector_complex_long_double.h \
+  /sw/include/gsl/gsl_complex.h /sw/include/gsl/gsl_vector_long_double.h \
+  /sw/include/gsl/gsl_block_long_double.h \
+  /sw/include/gsl/gsl_vector_complex.h \
+  /sw/include/gsl/gsl_block_complex_long_double.h \
+  /sw/include/gsl/gsl_vector_complex_double.h \
+  /sw/include/gsl/gsl_vector_double.h /sw/include/gsl/gsl_block_double.h \
+  /sw/include/gsl/gsl_block_complex_double.h \
+  /sw/include/gsl/gsl_vector_complex_float.h \
+  /sw/include/gsl/gsl_vector_float.h /sw/include/gsl/gsl_block_float.h \
+  /sw/include/gsl/gsl_block_complex_float.h \
+  /sw/include/gsl/gsl_vector_ulong.h /sw/include/gsl/gsl_block_ulong.h \
+  /sw/include/gsl/gsl_vector_long.h /sw/include/gsl/gsl_block_long.h \
+  /sw/include/gsl/gsl_vector_uint.h /sw/include/gsl/gsl_block_uint.h \
+  /sw/include/gsl/gsl_vector_int.h /sw/include/gsl/gsl_block_int.h \
+  /sw/include/gsl/gsl_vector_ushort.h /sw/include/gsl/gsl_block_ushort.h \
+  /sw/include/gsl/gsl_vector_short.h /sw/include/gsl/gsl_block_short.h \
+  /sw/include/gsl/gsl_vector_uchar.h /sw/include/gsl/gsl_block_uchar.h \
+  /sw/include/gsl/gsl_vector_char.h /sw/include/gsl/gsl_block_char.h \
+  /sw/include/gsl/gsl_matrix.h \
+  /sw/include/gsl/gsl_matrix_complex_long_double.h \
+  /sw/include/gsl/gsl_matrix_complex_double.h \
+  /sw/include/gsl/gsl_matrix_complex_float.h \
+  /sw/include/gsl/gsl_matrix_long_double.h \
+  /sw/include/gsl/gsl_matrix_double.h /sw/include/gsl/gsl_matrix_float.h \
+  /sw/include/gsl/gsl_matrix_ulong.h /sw/include/gsl/gsl_matrix_long.h \
+  /sw/include/gsl/gsl_matrix_uint.h /sw/include/gsl/gsl_matrix_int.h \
+  /sw/include/gsl/gsl_matrix_ushort.h /sw/include/gsl/gsl_matrix_short.h \
+  /sw/include/gsl/gsl_matrix_uchar.h /sw/include/gsl/gsl_matrix_char.h \
+  /sw/include/gsl/gsl_blas.h /sw/include/gsl/gsl_blas_types.h \
+  /sw/include/gsl/gsl_cblas.h BackgroundMesh.h ../Common/Context.h \
+  ../Post/OctreePost.h ../Common/Octree.h ../Common/OctreeInternals.h \
+  ../Geo/GVertex.h ../Geo/GEntity.h ../Geo/Range.h ../Geo/SPoint3.h \
   ../Geo/SBoundingBox3d.h ../Geo/SPoint3.h ../Common/GmshDefines.h \
   ../Geo/MVertex.h ../Geo/SPoint3.h ../Geo/GPoint.h ../Geo/SPoint2.h \
   ../Geo/GEdge.h ../Geo/GEntity.h ../Geo/GVertex.h ../Geo/SVector3.h \
@@ -321,10 +548,10 @@ BackgroundMesh.o: BackgroundMesh.cpp ../Common/Gmsh.h ../Common/Message.h \
   ../Geo/SVector3.h ../Geo/Pair.h ../Geo/ExtrudeParams.h ../Geo/GModel.h \
   ../Geo/GVertex.h ../Geo/GEdge.h ../Geo/GFace.h ../Geo/GRegion.h \
   ../Geo/GEntity.h ../Geo/MElement.h ../Geo/ExtrudeParams.h \
-  ../Geo/SBoundingBox3d.h Field.h ../Geo/Geo.h ../Geo/gmshSurface.h \
-  ../Geo/Pair.h ../Geo/Range.h ../Geo/SPoint2.h ../Geo/SPoint3.h \
-  ../Geo/SVector3.h ../Geo/SBoundingBox3d.h ../Geo/SPoint2.h \
-  ../Geo/ExtrudeParams.h
+  ../Geo/SBoundingBox3d.h Field.h ../contrib/ANN/include/ANN/ANN.h \
+  ../Geo/Geo.h ../Geo/gmshSurface.h ../Geo/Pair.h ../Geo/Range.h \
+  ../Geo/SPoint2.h ../Geo/SPoint3.h ../Geo/SVector3.h \
+  ../Geo/SBoundingBox3d.h ../Geo/SPoint2.h ../Geo/ExtrudeParams.h
 BoundaryLayer.o: BoundaryLayer.cpp BoundaryLayer.h ../Geo/GModel.h \
   ../Geo/GVertex.h ../Geo/GEntity.h ../Geo/Range.h ../Geo/SPoint3.h \
   ../Geo/SBoundingBox3d.h ../Geo/SPoint3.h ../Common/GmshDefines.h \
@@ -341,21 +568,89 @@ BoundaryLayer.o: BoundaryLayer.cpp BoundaryLayer.h ../Geo/GModel.h \
   ../Geo/MElement.h ../Geo/ExtrudeParams.h ../Geo/SBoundingBox3d.h \
   meshGEdge.h meshGFace.h ../Common/Message.h ../Post/Views.h \
   ../Post/ColorTable.h ../Common/VertexArray.h ../Post/AdaptiveViews.h \
-  ../Common/GmshMatrix.h
-BDS.o: BDS.cpp ../Numeric/Numeric.h ../Common/GmshMatrix.h BDS.h \
-  ../Geo/GFace.h ../Geo/GPoint.h ../Geo/GEntity.h ../Geo/Range.h \
-  ../Geo/SPoint3.h ../Geo/SBoundingBox3d.h ../Geo/SPoint3.h \
-  ../Common/GmshDefines.h ../Geo/GEdgeLoop.h ../Geo/GEdge.h \
-  ../Geo/GEntity.h ../Geo/GVertex.h ../Geo/GEntity.h ../Geo/MVertex.h \
-  ../Geo/SPoint3.h ../Geo/GPoint.h ../Geo/SPoint2.h ../Geo/SVector3.h \
-  ../Geo/SPoint3.h ../Geo/SPoint3.h ../Geo/SPoint2.h ../Geo/MElement.h \
-  ../Geo/MVertex.h ../Geo/MEdge.h ../Geo/MVertex.h ../Geo/SVector3.h \
-  ../Common/Hash.h ../Geo/MFace.h ../Geo/MVertex.h ../Geo/SVector3.h \
-  ../Common/Context.h ../DataStr/List.h ../Geo/ExtrudeParams.h \
-  ../Common/SmoothData.h ../Geo/MElement.h ../Geo/SPoint2.h \
-  ../Geo/SVector3.h ../Geo/Pair.h ../Geo/ExtrudeParams.h ../Post/Views.h \
-  ../Post/ColorTable.h ../Common/VertexArray.h ../Post/AdaptiveViews.h \
-  ../Common/Message.h
+  ../Common/GmshMatrix.h /sw/include/gsl/gsl_linalg.h \
+  /sw/include/gsl/gsl_mode.h /sw/include/gsl/gsl_permutation.h \
+  /sw/include/gsl/gsl_types.h /sw/include/gsl/gsl_errno.h \
+  /sw/include/gsl/gsl_check_range.h /sw/include/gsl/gsl_vector.h \
+  /sw/include/gsl/gsl_vector_complex_long_double.h \
+  /sw/include/gsl/gsl_complex.h /sw/include/gsl/gsl_vector_long_double.h \
+  /sw/include/gsl/gsl_block_long_double.h \
+  /sw/include/gsl/gsl_vector_complex.h \
+  /sw/include/gsl/gsl_block_complex_long_double.h \
+  /sw/include/gsl/gsl_vector_complex_double.h \
+  /sw/include/gsl/gsl_vector_double.h /sw/include/gsl/gsl_block_double.h \
+  /sw/include/gsl/gsl_block_complex_double.h \
+  /sw/include/gsl/gsl_vector_complex_float.h \
+  /sw/include/gsl/gsl_vector_float.h /sw/include/gsl/gsl_block_float.h \
+  /sw/include/gsl/gsl_block_complex_float.h \
+  /sw/include/gsl/gsl_vector_ulong.h /sw/include/gsl/gsl_block_ulong.h \
+  /sw/include/gsl/gsl_vector_long.h /sw/include/gsl/gsl_block_long.h \
+  /sw/include/gsl/gsl_vector_uint.h /sw/include/gsl/gsl_block_uint.h \
+  /sw/include/gsl/gsl_vector_int.h /sw/include/gsl/gsl_block_int.h \
+  /sw/include/gsl/gsl_vector_ushort.h /sw/include/gsl/gsl_block_ushort.h \
+  /sw/include/gsl/gsl_vector_short.h /sw/include/gsl/gsl_block_short.h \
+  /sw/include/gsl/gsl_vector_uchar.h /sw/include/gsl/gsl_block_uchar.h \
+  /sw/include/gsl/gsl_vector_char.h /sw/include/gsl/gsl_block_char.h \
+  /sw/include/gsl/gsl_matrix.h \
+  /sw/include/gsl/gsl_matrix_complex_long_double.h \
+  /sw/include/gsl/gsl_matrix_complex_double.h \
+  /sw/include/gsl/gsl_matrix_complex_float.h \
+  /sw/include/gsl/gsl_matrix_long_double.h \
+  /sw/include/gsl/gsl_matrix_double.h /sw/include/gsl/gsl_matrix_float.h \
+  /sw/include/gsl/gsl_matrix_ulong.h /sw/include/gsl/gsl_matrix_long.h \
+  /sw/include/gsl/gsl_matrix_uint.h /sw/include/gsl/gsl_matrix_int.h \
+  /sw/include/gsl/gsl_matrix_ushort.h /sw/include/gsl/gsl_matrix_short.h \
+  /sw/include/gsl/gsl_matrix_uchar.h /sw/include/gsl/gsl_matrix_char.h \
+  /sw/include/gsl/gsl_blas.h /sw/include/gsl/gsl_blas_types.h \
+  /sw/include/gsl/gsl_cblas.h
+BDS.o: BDS.cpp ../Numeric/Numeric.h ../Common/GmshMatrix.h \
+  /sw/include/gsl/gsl_linalg.h /sw/include/gsl/gsl_mode.h \
+  /sw/include/gsl/gsl_permutation.h /sw/include/gsl/gsl_types.h \
+  /sw/include/gsl/gsl_errno.h /sw/include/gsl/gsl_check_range.h \
+  /sw/include/gsl/gsl_vector.h \
+  /sw/include/gsl/gsl_vector_complex_long_double.h \
+  /sw/include/gsl/gsl_complex.h /sw/include/gsl/gsl_vector_long_double.h \
+  /sw/include/gsl/gsl_block_long_double.h \
+  /sw/include/gsl/gsl_vector_complex.h \
+  /sw/include/gsl/gsl_block_complex_long_double.h \
+  /sw/include/gsl/gsl_vector_complex_double.h \
+  /sw/include/gsl/gsl_vector_double.h /sw/include/gsl/gsl_block_double.h \
+  /sw/include/gsl/gsl_block_complex_double.h \
+  /sw/include/gsl/gsl_vector_complex_float.h \
+  /sw/include/gsl/gsl_vector_float.h /sw/include/gsl/gsl_block_float.h \
+  /sw/include/gsl/gsl_block_complex_float.h \
+  /sw/include/gsl/gsl_vector_ulong.h /sw/include/gsl/gsl_block_ulong.h \
+  /sw/include/gsl/gsl_vector_long.h /sw/include/gsl/gsl_block_long.h \
+  /sw/include/gsl/gsl_vector_uint.h /sw/include/gsl/gsl_block_uint.h \
+  /sw/include/gsl/gsl_vector_int.h /sw/include/gsl/gsl_block_int.h \
+  /sw/include/gsl/gsl_vector_ushort.h /sw/include/gsl/gsl_block_ushort.h \
+  /sw/include/gsl/gsl_vector_short.h /sw/include/gsl/gsl_block_short.h \
+  /sw/include/gsl/gsl_vector_uchar.h /sw/include/gsl/gsl_block_uchar.h \
+  /sw/include/gsl/gsl_vector_char.h /sw/include/gsl/gsl_block_char.h \
+  /sw/include/gsl/gsl_matrix.h \
+  /sw/include/gsl/gsl_matrix_complex_long_double.h \
+  /sw/include/gsl/gsl_matrix_complex_double.h \
+  /sw/include/gsl/gsl_matrix_complex_float.h \
+  /sw/include/gsl/gsl_matrix_long_double.h \
+  /sw/include/gsl/gsl_matrix_double.h /sw/include/gsl/gsl_matrix_float.h \
+  /sw/include/gsl/gsl_matrix_ulong.h /sw/include/gsl/gsl_matrix_long.h \
+  /sw/include/gsl/gsl_matrix_uint.h /sw/include/gsl/gsl_matrix_int.h \
+  /sw/include/gsl/gsl_matrix_ushort.h /sw/include/gsl/gsl_matrix_short.h \
+  /sw/include/gsl/gsl_matrix_uchar.h /sw/include/gsl/gsl_matrix_char.h \
+  /sw/include/gsl/gsl_blas.h /sw/include/gsl/gsl_blas_types.h \
+  /sw/include/gsl/gsl_cblas.h BDS.h ../Geo/GFace.h ../Geo/GPoint.h \
+  ../Geo/GEntity.h ../Geo/Range.h ../Geo/SPoint3.h \
+  ../Geo/SBoundingBox3d.h ../Geo/SPoint3.h ../Common/GmshDefines.h \
+  ../Geo/GEdgeLoop.h ../Geo/GEdge.h ../Geo/GEntity.h ../Geo/GVertex.h \
+  ../Geo/GEntity.h ../Geo/MVertex.h ../Geo/SPoint3.h ../Geo/GPoint.h \
+  ../Geo/SPoint2.h ../Geo/SVector3.h ../Geo/SPoint3.h ../Geo/SPoint3.h \
+  ../Geo/SPoint2.h ../Geo/MElement.h ../Geo/MVertex.h ../Geo/MEdge.h \
+  ../Geo/MVertex.h ../Geo/SVector3.h ../Common/Hash.h ../Geo/MFace.h \
+  ../Geo/MVertex.h ../Geo/SVector3.h ../Common/Context.h \
+  ../DataStr/List.h ../Geo/ExtrudeParams.h ../Common/SmoothData.h \
+  ../Geo/MElement.h ../Geo/SPoint2.h ../Geo/SVector3.h ../Geo/Pair.h \
+  ../Geo/ExtrudeParams.h ../Post/Views.h ../Post/ColorTable.h \
+  ../Common/VertexArray.h ../Post/AdaptiveViews.h ../Common/Message.h
 HighOrder.o: HighOrder.cpp HighOrder.h ../Geo/GModel.h ../Geo/GVertex.h \
   ../Geo/GEntity.h ../Geo/Range.h ../Geo/SPoint3.h \
   ../Geo/SBoundingBox3d.h ../Geo/SPoint3.h ../Common/GmshDefines.h \
diff --git a/Mesh/meshGEdge.cpp b/Mesh/meshGEdge.cpp
index 81c23aa335ced695c78cd8044d1ce3e076d4d090..93e07a95fffd930f306dbe026aac3e04ef112e7c 100644
--- a/Mesh/meshGEdge.cpp
+++ b/Mesh/meshGEdge.cpp
@@ -1,4 +1,4 @@
-// $Id: meshGEdge.cpp,v 1.39 2007-05-12 22:45:14 anand Exp $
+// $Id: meshGEdge.cpp,v 1.40 2007-09-04 13:47:02 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
@@ -27,6 +27,116 @@
 #include "BackgroundMesh.h"
 #include "Message.h"
 
+typedef struct{
+  int Num;
+  double t, lc, p;
+}IntPoint;
+
+
+struct xi2lc
+{
+  double xi,lc;
+  xi2lc (const double &_xi,const double _lc)
+    :xi(_xi),lc(_lc)
+  { }
+  bool operator < ( const xi2lc &other)
+  {
+    return xi < other.xi; 
+  }
+};
+
+std::vector<xi2lc> interpLc;
+
+void smoothInterpLc (bool periodic, int nbSmooth)
+{
+  if (periodic)
+    {
+      for (int i=0 ; i<interpLc.size()*nbSmooth; i++)
+	{	  	  
+	  xi2lc &left  = interpLc[(i-1)%interpLc.size()];
+	  xi2lc &mid   = interpLc[i%interpLc.size()];
+	  xi2lc &right = interpLc[(i+1)%interpLc.size()];
+
+	  if (1./mid.lc > 1.1 * 1./left.lc)mid.lc = left.lc/1.1;
+	  if (1./mid.lc > 1.1 * 1./right.lc)mid.lc = right.lc/1.1;
+	}
+    } 
+  else
+    {
+      for (int j=0 ; j<nbSmooth; j++)
+	{
+	  for (int i=0 ; i<interpLc.size(); i++)
+	    {	  	  
+	      xi2lc &left  = (i==0)?interpLc[0]:interpLc[i-1];
+	      xi2lc &mid   = interpLc[i];
+	      xi2lc &right = (i==interpLc.size()-1)?interpLc[interpLc.size()-1]:interpLc[i+1];
+	      
+	      if (1./mid.lc > 1.1 * 1./left.lc)mid.lc = left.lc/1.1;
+	      if (1./mid.lc > 1.1 * 1./right.lc)mid.lc = right.lc/1.1;
+	    }
+	} 
+    }
+}
+
+void printInterpLc (const char *name)
+{
+  FILE *f = fopen (name,"w");
+  for (int i=0 ; i<interpLc.size(); i++)
+    {	  	  
+      xi2lc &interp  = interpLc[i];
+      fprintf(f,"%12.5E %12.5E\n",interp.xi,1/interp.lc);
+    }
+  fclose(f);
+}
+
+void buildInterpLc (List_T *lcPoints)
+{
+  IntPoint p;
+  interpLc.clear();
+  for (int i=0;i<List_Nbr(lcPoints);i++)
+    {
+      List_Read(lcPoints, i, &p);
+      interpLc.push_back(xi2lc ( p.t,p.lc));
+    }
+  //  printf("interpLc with %d points\n",interpLc.size());
+}
+
+double F_Lc_usingInterpLc(GEdge *ge, double t)
+{
+  std::vector<xi2lc>::iterator it = std::lower_bound (interpLc.begin(),interpLc.end(),xi2lc(t,0));
+  double t1 = it->xi;
+  double l1 = it->lc;
+  it++;
+  SVector3 der = ge->firstDer(t);
+  const double d = norm(der);
+  if (it == interpLc.end())return d*l1;
+  double t2 = it->xi;
+  double l2 = it->lc;
+  double l  = l1 + ((t-t1)/(t2-t1)) * (l2-l1);
+  return d*l;
+}
+
+
+double F_Lc_usingInterpLcBis(GEdge *ge, double t)
+{
+  GPoint p = ge->point(t);
+  double lc_here;
+
+  Range<double> bounds = ge->parBounds(0);
+  double t_begin = bounds.low();
+  double t_end = bounds.high();
+
+  if(t == t_begin)
+    lc_here = BGM_MeshSize(ge->getBeginVertex(), t, 0, p.x(), p.y(), p.z());
+  else if(t == t_end)
+    lc_here = BGM_MeshSize(ge->getEndVertex(), t, 0, p.x(), p.y(), p.z());
+  else
+    lc_here = BGM_MeshSize(ge, t, 0, p.x(), p.y(), p.z());
+
+  return 1 / lc_here;
+}
+
+
 double F_Lc(GEdge *ge, double t)
 {
   GPoint p = ge->point(t);
@@ -112,11 +222,6 @@ double F_One(GEdge *ge, double t)
   return norm(der);
 }
 
-typedef struct{
-  int Num;
-  double t, lc, p;
-}IntPoint;
-
 double trapezoidal(IntPoint * P1, IntPoint * P2)
 {
   return (0.5 * (P1->lc + P2->lc) * (P2->t - P1->t));
@@ -204,6 +309,8 @@ void meshGEdge::operator() (GEdge *ge)
 
   // Create a list of integration points
   List_T *Points = List_Create(10, 10, sizeof(IntPoint));
+  // Create a list of points for interpolating the LC Field
+  List_T *lcPoints = List_Create(10, 10, sizeof(IntPoint));
 
   // compute bounds
   Range<double> bounds = ge->parBounds(0);
@@ -212,6 +319,9 @@ void meshGEdge::operator() (GEdge *ge)
   
   // first compute the length of the curve by integrating one
   double length = Integration(ge, t_begin, t_end, F_One, Points, 1.e-8);
+
+  //  printf("%d points for the length\n",List_Nbr(Points));
+
   ge->setLength(length);
 
   List_Reset(Points);
@@ -224,7 +334,20 @@ void meshGEdge::operator() (GEdge *ge)
     N = ge->meshAttributes.nbPointsTransfinite;
   }
   else{
-    a = Integration(ge, t_begin, t_end, F_Lc, Points, 1.e-8);
+    if (CTX.mesh.lc_integration_precision > 1.e-8)
+      {
+	Integration(ge, t_begin, t_end, F_Lc_usingInterpLcBis, lcPoints, CTX.mesh.lc_integration_precision);
+	buildInterpLc (lcPoints);
+	printInterpLc ("toto1.dat");
+	smoothInterpLc (ge->periodic(),20);
+	printInterpLc ("toto2.dat");
+	a = Integration(ge, t_begin, t_end, F_Lc_usingInterpLc, Points, 1.e-8);
+	//	printf("%d points for LC , %d points for the distribution interpLc %d\n",List_Nbr(lcPoints),List_Nbr(Points),interpLc.size());
+      }
+    else
+      {
+	a = Integration(ge, t_begin, t_end, F_Lc, Points, 1.e-8);
+      }
     N = std::max(ge->minimumMeshSegments() + 1, (int)(a + 1.));
   }
 
@@ -251,6 +374,7 @@ void meshGEdge::operator() (GEdge *ge)
 
   // do not consider the first and the last vertex (those are not
   // classified on this mesh edge)
+
   if(N > 1){
     ge->mesh_vertices.resize(N - 2);
     GPoint last_p = beg_p;
@@ -261,9 +385,9 @@ void meshGEdge::operator() (GEdge *ge)
       if((fabs(P2.p) >= fabs(d)) && (fabs(P1.p) < fabs(d))) {
         double dt = P2.t - P1.t;
         double dp = P2.p - P1.p;
-        double t = P1.t + dt / dp * (d - P1.p);
+        double t  = P1.t + dt / dp * (d - P1.p);
         GPoint V = ge->point(t);
-	if(ge->meshAttributes.Method == TRANSFINI){
+	if(1 || ge->meshAttributes.Method == TRANSFINI){
 	  ge->mesh_vertices[NUMP2 - 1] = new MEdgeVertex(V.x(), V.y(), V.z(), ge, t);
 	  NUMP2++;
 	}
@@ -285,6 +409,7 @@ void meshGEdge::operator() (GEdge *ge)
     ge->mesh_vertices.resize(NUMP2 - 1);
   }
   List_Delete(Points);
+  List_Delete(lcPoints);
 
   for(unsigned int i = 0; i < ge->mesh_vertices.size() + 1; i++){
     MVertex *v0 = (i == 0) ? 
@@ -301,4 +426,6 @@ void meshGEdge::operator() (GEdge *ge)
     v0->y() = beg_p.y();
     v0->z() = beg_p.z();
   }
+
+
 }
diff --git a/Mesh/meshGFace.cpp b/Mesh/meshGFace.cpp
index d0e94805a0f6bf5385fd0f04487c1067180669f7..e5fbb64e0900eb6ac9862c76943123c1aa43b184 100644
--- a/Mesh/meshGFace.cpp
+++ b/Mesh/meshGFace.cpp
@@ -1,4 +1,4 @@
-// $Id: meshGFace.cpp,v 1.83 2007-09-03 20:09:14 geuzaine Exp $
+// $Id: meshGFace.cpp,v 1.84 2007-09-04 13:47:02 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
@@ -21,6 +21,7 @@
 
 #include "meshGFace.h"
 #include "meshGFaceDelaunayInsertion.h"
+#include "meshGFaceOptimize.h"
 #include "DivideAndConquer.h"
 #include "BackgroundMesh.h"
 #include "GVertex.h"
@@ -99,8 +100,7 @@ double F_LC_ANALY(double xx, double yy, double zz)
 
 double NewGetLc(BDS_Point *p)
 {
-  //  double l = Attractor::lc (p->X,p->Y,p->Z);
-  return p->lc();
+  return std::min(p->lc(),p->lcBGM());
 }
 
 inline double computeEdgeLinearLength(BDS_Point *p1, BDS_Point *p2)
@@ -295,13 +295,13 @@ void RefineMesh ( GFace *gf, BDS_Mesh &m , const int NIT)
 {
   int IT =0;
 
-  //printf("lc (1,1) = %g\n",Attractor::lc(1,1,0));
+  //  printf("lc (1,1) = %g\n",Attractor::lc(1,1,0));
 
   int MAXNP = m.MAXPOINTNUMBER;
 
   // computecharacteristic lengths using mesh edge spacing
-  // separate attractors & 
-  if (NIT > 0 && !BGMExists())
+  // those lengths will propagate in the 2D mesh.
+  if (NIT > 0)
     {
       std::set<BDS_Point*,PointLessThan>::iterator itp = m.points.begin();
       while (itp != m.points.end())
@@ -314,7 +314,9 @@ void RefineMesh ( GFace *gf, BDS_Mesh &m , const int NIT)
 	    if (l<L && (*it)->g && (*it)->g->classif_degree == 1)L=l;
 	    ++it;
 	  }
-	  (*itp)->lc() = std::min(L,(*itp)->lc());
+	  if(!CTX.mesh.constrained_bgmesh)
+	    (*itp)->lc() = L;
+	  (*itp)->lcBGM() = L;
 	  ++itp;
 	}
     }
@@ -324,19 +326,8 @@ void RefineMesh ( GFace *gf, BDS_Mesh &m , const int NIT)
   const double MINE_ = 0.7, MAXE_=1.4;
   while (1)
     {
-    //   double stot = 0;
-//       std::list<BDS_Face *>::iterator ittt = m.triangles.begin();
-//       while (ittt!= m.triangles.end())
-// 	{
-// 	  if (!(*ittt)->deleted)
-// 	    {
-// 	      BDS_Point *pts[4];
-// 	      (*ittt)->getNodes(pts);
-// 	      stot += fabs( surface_triangle_param(pts[0], pts[1], pts[2]));
-// 	    }
-// 	  ++ittt;
-// 	}
-      
+      // we count the number of local mesh modifs.
+
       int nb_split=0;
       int nb_smooth=0;
       int nb_collaps=0;
@@ -367,7 +358,6 @@ void RefineMesh ( GFace *gf, BDS_Mesh &m , const int NIT)
       
       if ((minL > MINE_ && maxL < MAXE_) || IT > (abs(NIT)))break;
 
-
       NN1 = m.edges.size();
       NN2 = 0;
       it = m.edges.begin();
@@ -377,27 +367,21 @@ void RefineMesh ( GFace *gf, BDS_Mesh &m , const int NIT)
 	  if (!(*it)->deleted)
 	    {
 	      double lone = NewGetLc ( *it,gf);
-
-	      // take care with seams :
-	      //	      if (lone < 1.e-10 && computeParametricEdgeLength((*it)->p1,(*it)->p2) > 1.e-5) lone = 2;
 	      if ((*it)->numfaces() == 2 && (lone >  MAXE_))
 		{
-
 		  const double coord = 0.5;
-
 		  BDS_Point *mid ;
 		  mid  = m.add_point(++m.MAXPOINTNUMBER,
 				     coord * (*it)->p1->u + (1 - coord) * (*it)->p2->u,
 				     coord * (*it)->p1->v + (1 - coord) * (*it)->p2->v,gf);
   		  double l1;
-		  if (!BGMExists())
-		    l1 = BGM_MeshSize(gf,
-				      (coord * (*it)->p1->u + (1 - coord) * (*it)->p2->u)*m.scalingU,
-				      (coord * (*it)->p1->v + (1 - coord) * (*it)->p2->v)*m.scalingV,
-				      mid->X,mid->Y,mid->Z);
-		  else l1 = 0.5 * ( (*it)->p1->lc() +  (*it)->p2->lc() );
-
-		  mid->lc() = l1;
+		  //		  if (BGMExists())
+		  mid->lcBGM() = BGM_MeshSize(gf,
+					      (coord * (*it)->p1->u + (1 - coord) * (*it)->p2->u)*m.scalingU,
+					      (coord * (*it)->p1->v + (1 - coord) * (*it)->p2->v)*m.scalingV,
+					      mid->X,mid->Y,mid->Z);
+		  //mid->lc() = 2./ ( 1./(*it)->p1->lc() +  1./(*it)->p2->lc() );		  
+		  mid->lc() = 0.5 * ( (*it)->p1->lc() +  (*it)->p2->lc() );		  
 		  m.split_edge ( *it, mid );
 		  nb_split++;
 		} 
@@ -406,7 +390,7 @@ void RefineMesh ( GFace *gf, BDS_Mesh &m , const int NIT)
 	}
 
       // swap edges that provide a better configuration
-//       NN1 = m.edges.size();
+
       NN2 = 0;
       it = m.edges.begin();
       while (1)
@@ -467,138 +451,130 @@ void RefineMesh ( GFace *gf, BDS_Mesh &m , const int NIT)
 	    }
 	}
       // smooth resulting mesh
-      //if (IT % 4 == 0 )
-	{
-	  std::set<BDS_Point*,PointLessThan>::iterator itp = m.points.begin();
-	  while (itp != m.points.end())
-	    {
-
-	      if(m.smooth_point_centroid(*itp,gf))
-		nb_smooth ++;
-	      ++itp;
-	    }
-	}
-	// recompute mesh sizes takin into account curvature , BGMESH & co
-	m.cleanup();  
-	if (0 && IT % 5 == 0)
-	{
-	  std::set<BDS_Point*,PointLessThan>::iterator itp = m.points.begin();
-	  while (itp != m.points.end())
-	    {
-	      BDS_Point *p = *itp;
-	      if(p->g->classif_degree == 2)
-		{
-		  double l2 = BGM_MeshSize(gf,p->u*m.scalingU,p->v*m.scalingV,p->X,p->Y,p->Z);
-		  p->config_modified = true;
-		  p->lc() = std::min(p->lc(),l2);
-		}
-	      ++itp;
-	    }
-	  for (int ITERA = 0;ITERA< 0; ITERA++);
+      {
+	std::set<BDS_Point*,PointLessThan>::iterator itp = m.points.begin();
+	while (itp != m.points.end())
 	  {
-	    it = m.edges.begin();
-	    while (it != m.edges.end())
-	      {
-		BDS_Edge *e = *it;
-		if (!e->deleted)
-		  {
-		    double l1 = e->p1->lc();
-		    double l2 = e->p2->lc();
-		    if (l1 > 1.3 *l2) e->p1->lc() = 1.5*l2;
-		    if (l2 > 1.3 *l1) e->p2->lc() = 1.5*l1;
-		  }
-		++it;
-	      }
+	    
+	    if(m.smooth_point_centroid(*itp,gf))
+	      nb_smooth ++;
+	    ++itp;
 	  }
-	}
-	IT++;
-	Msg(DEBUG1," iter %3d minL %8.3f maxL %8.3f : %6d splits, %6d swaps, %6d collapses, %6d moves",IT,minL,maxL,nb_split,nb_swap,nb_collaps,nb_smooth);
+      }
 
-	if (nb_split==0 && nb_collaps == 0)break;
+      // clean up the mesh
+      m.cleanup();  	
+      IT++;
+      Msg(DEBUG1," iter %3d minL %8.3f maxL %8.3f : %6d splits, %6d swaps, %6d collapses, %6d moves",IT,minL,maxL,nb_split,nb_swap,nb_collaps,nb_smooth);
+      
+      if (nb_split==0 && nb_collaps == 0)break;
     }  
 }
 
 
 
 
-bool recover_medge ( BDS_Mesh *m, GEdge *ge)
+bool recover_medge ( BDS_Mesh *m, GEdge *ge, std::set<EdgeToRecover> *e2r, int pass_)
 {
-
-  m->add_geom (ge->tag(), 1);
-  BDS_GeomEntity *g = m->get_geom(ge->tag(),1);
+  BDS_GeomEntity *g;
+  if (pass_ == 2)
+    {
+      m->add_geom (ge->tag(), 1);
+      g = m->get_geom(ge->tag(),1);
+    }
 
   if (ge->mesh_vertices.size() == 0)
     {
 
       MVertex   *vstart = *(ge->getBeginVertex()->mesh_vertices.begin());
       MVertex   *vend   = *(ge->getEndVertex()->mesh_vertices.begin());
-      BDS_Point *pstart = m->find_point(vstart->getNum());
-      BDS_Point *pend   = m->find_point(vend->getNum());
+      if (pass_ == 1)
+	{
+	  e2r->insert (EdgeToRecover (vstart->getNum(), vend->getNum(),ge));
+	  return true;
+	}
+      else
+	{
+	  BDS_Point *pstart = m->find_point(vstart->getNum());
+	  BDS_Point *pend   = m->find_point(vend->getNum());
+	  
+	  if(!pstart->g)
+	    {
+	      m->add_geom (vstart->getNum(), 0);
+	      BDS_GeomEntity *g0 = m->get_geom(vstart->getNum(), 0);
+	      pstart->g = g0;
+	    }
+	  if(!pend->g)
+	    {
+	      m->add_geom (vend->getNum(), 0);
+	      BDS_GeomEntity *g0 = m->get_geom(vend->getNum(), 0);
+	      pend->g = g0;
+	    }
+	  BDS_Edge * e = m->recover_edge ( vstart->getNum(), vend->getNum(),e2r);
+	  if (e)e->g = g;
+	  else {
+	    Msg(GERROR,"The unrecoverable edge is on model edge %d",ge->tag());
+	    return false;
+	  }
+	  return true;
+	}
+    }
+
+  BDS_Edge * e;
+  MVertex *vstart = *(ge->getBeginVertex()->mesh_vertices.begin());
+  MVertex *vend   = *(ge->mesh_vertices.begin());
 
+  if (pass_ == 1)e2r->insert (EdgeToRecover (vstart->getNum(), vend->getNum(),ge));
+  else 
+    {
+      BDS_Point *pstart = m->find_point(vstart->getNum());
       if(!pstart->g)
 	{
 	  m->add_geom (vstart->getNum(), 0);
 	  BDS_GeomEntity *g0 = m->get_geom(vstart->getNum(), 0);
 	  pstart->g = g0;
 	}
-      if(!pend->g)
-	{
-	  m->add_geom (vend->getNum(), 0);
-	  BDS_GeomEntity *g0 = m->get_geom(vend->getNum(), 0);
-	  pend->g = g0;
-	}
-      BDS_Edge * e = m->recover_edge ( vstart->getNum(), vend->getNum());
+      e = m->recover_edge ( vstart->getNum(), vend->getNum(),e2r);
       if (e)e->g = g;
       else {
-	Msg(GERROR,"Unable to recover an edge %g %g && %g %g (size 0)",vstart->x(),vstart->y(), vend->x(),vend->y());
-	Msg(GERROR,"Mesh with %d triangles",m->triangles.size());
+	Msg(GERROR,"The unrecoverable edge is on model edge %d",ge->tag());
 	return false;
       }
-      return true;
     }
 
-
-  MVertex *vstart = *(ge->getBeginVertex()->mesh_vertices.begin());
-  MVertex *vend   = *(ge->mesh_vertices.begin());
-
-  BDS_Point *pstart = m->find_point(vstart->getNum());
-  if(!pstart->g)
-    {
-      m->add_geom (vstart->getNum(), 0);
-      BDS_GeomEntity *g0 = m->get_geom(vstart->getNum(), 0);
-      pstart->g = g0;
-    }
-
-  BDS_Edge * e = m->recover_edge ( vstart->getNum(), vend->getNum());
-  if (e)e->g = g;
-  else return false;
-
   for (unsigned int i=1;i<ge->mesh_vertices.size();i++)
     {
       vstart = ge->mesh_vertices[i-1];
       vend   = ge->mesh_vertices[i];
-      e = m->recover_edge ( vstart->getNum(), vend->getNum());
-      if (e)e->g = g;
-      else {
-	Msg(GERROR,"Unable to recover an edge %g %g && %g %g (%d/%d)",vstart->x(),vstart->y(), vend->x(),vend->y(),i,ge->mesh_vertices.size());
-	return false;
-      }
+      if (pass_ == 1)e2r->insert (EdgeToRecover (vstart->getNum(), vend->getNum(),ge));
+      else
+	{
+	  e = m->recover_edge ( vstart->getNum(), vend->getNum(),e2r);
+	  if (e)e->g = g;
+	  else {
+	    Msg(GERROR,"Unable to recover an edge %g %g && %g %g (%d/%d)",vstart->x(),vstart->y(), vend->x(),vend->y(),i,ge->mesh_vertices.size());
+	    return false;
+	  }
+	}
     }    
   vstart = vend;
   vend   = *(ge->getEndVertex()->mesh_vertices.begin());
-  e = m->recover_edge ( vstart->getNum(), vend->getNum());
-  if (e)e->g = g;
-  else {
-    Msg(GERROR,"Unable to recover an edge %g %g && %g %g",vstart->x(),vstart->y(), vend->x(),vend->y());
-    return false;
-  }
-
-  BDS_Point *pend = m->find_point(vend->getNum());
-  if(!pend->g)
+  if (pass_ == 1)e2r->insert (EdgeToRecover (vstart->getNum(), vend->getNum(),ge));
+  else
     {
-      m->add_geom (vend->getNum(), 0);
-      BDS_GeomEntity *g0 = m->get_geom(vend->getNum(), 0);
-      pend->g = g0;
+      e = m->recover_edge ( vstart->getNum(), vend->getNum(),e2r);
+      if (e)e->g = g;
+      else {
+	Msg(GERROR,"Unable to recover an edge %g %g && %g %g (%d/%d)",vstart->x(),vstart->y(), vend->x(),vend->y(),ge->mesh_vertices.size(),ge->mesh_vertices.size());
+	return false;
+      }
+      BDS_Point *pend = m->find_point(vend->getNum());
+      if(!pend->g)
+	{
+	  m->add_geom (vend->getNum(), 0);
+	  BDS_GeomEntity *g0 = m->get_geom(vend->getNum(), 0);
+	  pend->g = g0;
+	}
     }
   return true;
 }
@@ -661,13 +637,7 @@ bool gmsh2DMeshGenerator ( GFace *gf , bool debug = true)
     }
     else if(here->onWhat()->dim() == 0){
       GVertex *gv = (GVertex*)here->onWhat();
-      if(gv->edges().size() == 1){
-	GEdge *ge = *(gv->edges().begin());
-	Range<double> bb = ge->parBounds(0);
-	param = ge->reparamOnFace(gf, bb.low(), 1);	  
-      }
-      else
-	param = gv->reparamOnFace(gf,1);
+      param = gv->reparamOnFace(gf,1);      
     }
     else if(here->onWhat()->dim() == 1){
       GEdge *ge = (GEdge*)here->onWhat();
@@ -772,27 +742,22 @@ bool gmsh2DMeshGenerator ( GFace *gf , bool debug = true)
       // to curve interpolation, and straight line interpol does
       // "while(not in bounds) i--" which would take forever to get
       // back into a reasonnable interval)
-      if(num < 0){ // fake bbox points 
-	U = V = 0;
+
+      // JFR : the fix was WRONG, I fixed the fix ;-)
+
+      if(num< 0){ // fake bbox points 
+	U = bb[-1-num]->x();
+	V = bb[-1-num]->y();
       }
-      else{
+      else
+      {
 	U = U_[num];
 	V = V_[num];
       }
 
       BDS_Point *pp = m->add_point ( num, U,V, gf);
-      //      printf("here->onWhat = %p dim = %d\n",here->onWhat(),here->onWhat()->dim());
-
-       if (here->onWhat()->dim() == 1)
- 	{
- 	  double t;
- 	  here->getParameter(0,t);
- 	  pp->lc() = BGM_MeshSize ( here->onWhat(), t, 0, here->x(),here->y(),here->z());
- 	}
-       else
-	 pp->lc() = BGM_MeshSize ( here->onWhat(), U, V, here->x(),here->y(),here->z());
     }
-
+  
   Msg(DEBUG1,"Meshing of the convex hull (%d points) done",all_vertices.size());
 
   for(int i = 0; i < doc.numTriangles; i++) 
@@ -815,14 +780,47 @@ bool gmsh2DMeshGenerator ( GFace *gf , bool debug = true)
   // and compute characteristic lenghts using mesh edge spacing
 
   BDS_GeomEntity CLASS_F (1,2);
+  if (debug)
+    {
+      char name[245];
+      sprintf(name,"surface%d-initial-real.pos",gf->tag());
+      outputScalarField(m->triangles, name,0);
+      sprintf(name,"surface%d-initial-param.pos",gf->tag());
+      outputScalarField(m->triangles, name,1);
+    }
+    
+  Msg(DEBUG1,"Recovering %d model Edges",edges.size());
+  
+  // build a structure with all mesh edges that have to be
+  // recovered. If two of these edges intersect, then the
+  // 1D mesh have to be densified
+
+  std::set<EdgeToRecover> edgesToRecover;
+  it = edges.begin();
+  while(it != edges.end())
+    {
+      if(!(*it)->is_mesh_degenerated())
+	recover_medge ( m, *it, &edgesToRecover,1);
+      ++it;
+    }
+  it = emb_edges.begin();
+  while(it != emb_edges.end())
+    {
+      recover_medge ( m, *it, &edgesToRecover,1);
+      ++it;
+    }
+
+
+  Msg(DEBUG1,"Recovering %d mesh Edges",edgesToRecover.size());
+  // effectively recover the medge
 
   it = edges.begin();
   while(it != edges.end())
     {
       if(!(*it)->is_mesh_degenerated()){
-	if (!recover_medge ( m, *it))
+	if (!recover_medge ( m, *it, &edgesToRecover,2))
 	  {
-	    Msg(GERROR,"Face not meshed");
+	    Msg(GERROR,"Face cannot be not meshed because 1D mesh self intersects !");
 	    return false;
 	  }
       }
@@ -859,10 +857,11 @@ bool gmsh2DMeshGenerator ( GFace *gf , bool debug = true)
   }
 
 
+
   it = emb_edges.begin();
   while(it != emb_edges.end())
     {
-      recover_medge ( m, *it);
+      recover_medge ( m, *it, &edgesToRecover,2);
       ++it;
     }
 
@@ -879,6 +878,18 @@ bool gmsh2DMeshGenerator ( GFace *gf , bool debug = true)
       }
   }
   m->cleanup();
+
+
+  if (debug)
+    {
+      char name[245];
+      sprintf(name,"surface%d-recovered-real.pos",gf->tag());
+      outputScalarField(m->triangles, name,0);
+      sprintf(name,"surface%d-recovered-param.pos",gf->tag());
+      outputScalarField(m->triangles, name,1);
+    }
+
+
   {
     std::list<BDS_Edge*>::iterator ite = m->edges.begin();
     while (ite != m->edges.end())
@@ -904,7 +915,7 @@ bool gmsh2DMeshGenerator ( GFace *gf , bool debug = true)
   m->del_point(m->find_point(-4));
 
   // start mesh generation
-  if (CTX.mesh.algo2d != ALGO_2D_DELAUNAY || gf->geomType() != GEntity::Plane)
+  if (CTX.mesh.algo2d != ALGO_2D_DELAUNAY)
     {
       RefineMesh (gf,*m,10);
       OptimizeMesh(gf, *m, 2);
@@ -964,20 +975,20 @@ bool gmsh2DMeshGenerator ( GFace *gf , bool debug = true)
   // the delaunay algo is based directly on internal gmsh structures
   // BDS mesh is passed in order not to recompute local coordinates
   // of vertices
-  if (CTX.mesh.algo2d == ALGO_2D_DELAUNAY && gf->geomType() == GEntity::Plane)
+  if (CTX.mesh.algo2d == ALGO_2D_DELAUNAY)
      {
        insertVerticesInFace (gf,m) ;
+       for (int i=0;i<5;i++)laplaceSmoothing (gf);
      }
-
-  // delete the mesh
-
-  if (debug){
+  else if (debug){
     char name[256];
     sprintf(name,"real%d.pos",gf->tag());
     outputScalarField(m->triangles, name,0);
     sprintf(name,"param%d.pos",gf->tag());
     outputScalarField(m->triangles, name,1);
   }
+
+  // delete the mesh
   delete m;
 
 
@@ -1176,16 +1187,16 @@ bool buildConsecutiveListOfVertices (  GFace *gf,
 	 V = param.y() / m->scalingV;
 	 BDS_Point *pp;
 	 pp = m->add_point ( count, U,V,gf );
-	 if(ge->dim() == 1)
-	   {
-	     double t;
-	     here->getParameter(0,t);
-	     pp->lc() = BGM_MeshSize(ge,t,-12,here->x(),here->y(),here->z());
-	   }
-	 else
-	   {
-	     pp->lc() = BGM_MeshSize(ge,param.x(),param.y(),here->x(),here->y(),here->z());
-	   }
+// 	 if(ge->dim() == 1)
+// 	   {
+// 	     double t;
+// 	     here->getParameter(0,t);
+// 	     pp->lc() = BGM_MeshSize(ge,t,-12,here->x(),here->y(),here->z());
+// 	   }
+// 	 else
+// 	   {
+// 	     pp->lc() = BGM_MeshSize(ge,param.x(),param.y(),here->x(),here->y(),here->z());
+// 	   }
 
 	 m->add_geom (ge->tag(), ge->dim());
 	 BDS_GeomEntity *g = m->get_geom(ge->tag(),ge->dim());
@@ -1337,6 +1348,18 @@ bool gmsh2DMeshGeneratorPeriodic ( GFace *gf , bool debug = true)
     }
 
 
+  // build a list of edges to recover
+//   std::set<EdgeToRecover> e2r;
+//   for (unsigned int i=0;i<edgeLoops_BDS.size();i++)
+//     {
+//       std::vector<BDS_Point*> &edgeLoop_BDS = edgeLoops_BDS[i];
+//       for (unsigned int j=0;j<edgeLoop_BDS.size();j++)
+// 	{
+// 	  e2r.insert (EdgeToRecover (edgeLoop_BDS[j]->iD,edgeLoop_BDS[(j+1)%edgeLoop_BDS.size()]->iD,ge));
+// 	}
+//     }
+
+
   for (unsigned int i=0;i<edgeLoops_BDS.size();i++)
     {
       std::vector<BDS_Point*> &edgeLoop_BDS = edgeLoops_BDS[i];
@@ -1435,7 +1458,7 @@ bool gmsh2DMeshGeneratorPeriodic ( GFace *gf , bool debug = true)
   // goto hhh;
   // start mesh generation
   
-  //  if (CTX.mesh.algo2d == ALGO_2D_MESHADAPT)
+  if (CTX.mesh.algo2d != ALGO_2D_DELAUNAY)
     {
       RefineMesh (gf,*m,10);
       OptimizeMesh(gf, *m, 2);
@@ -1505,12 +1528,12 @@ bool gmsh2DMeshGeneratorPeriodic ( GFace *gf , bool debug = true)
       outputScalarField(m->triangles, name,1);
     }
 
-//   if (CTX.mesh.algo2d == ALGO_2D_DELAUNAY)
-//     {
-//       insertVerticesInFace (gf,m) ;
-//     }
-
-  
+   if (CTX.mesh.algo2d == ALGO_2D_DELAUNAY)
+     {
+       insertVerticesInFace (gf,m) ;
+       for (int i=0;i<5;i++)laplaceSmoothing (gf);
+     }
+ 
   delete m; 
   SCALINGU = SCALINGV = 1;
   return true;
@@ -1574,7 +1597,7 @@ void meshGFace::operator() (GFace *gf)
   // temp fix until we create MEdgeLoops in gmshFace
   Msg(DEBUG1, "Generating the mesh");
   if(gf->getNativeType() == GEntity::GmshModel || gf->edgeLoops.empty()){
-    gmsh2DMeshGenerator(gf,false);
+    gmsh2DMeshGenerator(gf,true);
   }
   else{
     if(!gmsh2DMeshGeneratorPeriodic(gf,false))
diff --git a/Mesh/meshGFace.h b/Mesh/meshGFace.h
index df7171e49c0baa15f48cf8eee24c89ac014a1296..da6153d134ec4adaf8ba404ae0fd6c894f0ccf46 100644
--- a/Mesh/meshGFace.h
+++ b/Mesh/meshGFace.h
@@ -59,4 +59,5 @@ int MeshTransfiniteSurface(GFace *gf);
 int MeshExtrudedSurface(GFace *gf, 
 			std::set<std::pair<MVertex*, MVertex*> > *constrainedEdges=0);
 
+void fourthPoint (double *p1, double *p2, double *p3, double *p4);
 #endif
diff --git a/Mesh/meshGFaceDelaunayInsertion.cpp b/Mesh/meshGFaceDelaunayInsertion.cpp
index 4970c9e503579ac00b8641762903b7c249723e64..afbbb17937fefd9d785bc278ebed3eafa7df762c 100644
--- a/Mesh/meshGFaceDelaunayInsertion.cpp
+++ b/Mesh/meshGFaceDelaunayInsertion.cpp
@@ -1,4 +1,4 @@
-// $Id: meshGFaceDelaunayInsertion.cpp,v 1.2 2007-05-24 14:44:06 remacle Exp $
+// $Id: meshGFaceDelaunayInsertion.cpp,v 1.3 2007-09-04 13:47:02 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
@@ -22,6 +22,7 @@
 #include "BDS.h"
 #include "BackgroundMesh.h"
 #include "meshGFaceDelaunayInsertion.h"
+#include "meshGFace.h"
 #include "GFace.h"
 #include "Numeric.h"
 #include "Message.h"
@@ -29,40 +30,13 @@
 #include <map>
 #include <algorithm>
 
+int III = 1;
+
 // computes the center of the circum circle in the tangent plane
 // the metric given by a b d is supposed to be constant
 void MTri3::Center_Circum_Aniso(double a, double b, double d, double &x, double &y, double &r) const
 {
-  double sys[2][2], X[2];
-  double rhs[2];
-  double x1, y1, x2, y2, x3, y3;
-
-  x1 = base->getVertex(0)->x();
-  y1 = base->getVertex(0)->y();
-  x2 = base->getVertex(1)->x();
-  y2 = base->getVertex(1)->y();
-  x3 = base->getVertex(2)->x();
-  y3 = base->getVertex(2)->y();
-
-  sys[0][0] = 2. * a * (x1 - x2) + 2. * b * (y1 - y2);
-  sys[0][1] = 2. * d * (y1 - y2) + 2. * b * (x1 - x2);
-  sys[1][0] = 2. * a * (x1 - x3) + 2. * b * (y1 - y3);
-  sys[1][1] = 2. * d * (y1 - y3) + 2. * b * (x1 - x3);
-
-  rhs[0] =
-    a * (x1 * x1 - x2 * x2) + d * (y1 * y1 - y2 * y2) + 2. * b * (x1 * y1 -
-                                                                  x2 * y2);
-  rhs[1] =
-    a * (x1 * x1 - x3 * x3) + d * (y1 * y1 - y3 * y3) + 2. * b * (x1 * y1 -
-                                                                  x3 * y3);
-  sys2x2(sys, rhs, X);
-  
-  x = X[0];
-  y = X[1];
-  
-  r = sqrt((X[0] - x1) * (X[0] - x1) * a
-	   + (X[1] - y1) * (X[1] - y1) * d
-	   + 2. * (X[0] - x1) * (X[1] - y1) * b);
+  throw;
 }
 
 
@@ -70,69 +44,12 @@ void MTri3::Center_Circum_Aniso(double a, double b, double d, double &x, double
 void simultaneousMetricReduction( const gmsh2dMetric &M1,  const gmsh2dMetric &M2,
 				  double & l1,double & l2, double V[2][2]) 
 {
-  double a11=M1.a11,a21=M1.a21,a22=M1.a22;
-  double b11=M2.a11,b21=M2.a21,b22=M2.a22;
-  const double /*c11 = a11*a11,*/ c21= a21*a21;
-  const double /*d11 = b11*b11,*/ d21= b21*b21;
-  const double a=b11*b22 - d21;
-  const double b=-a11*b22-a22*b11+2*a21*b21;
-  const double c=-c21+a11*a22;
-  const double bb = b*b,ac= a*c;
-  const double delta = bb - 4 * ac;
-  if (bb + fabs(ac) < 1.0e-20 || (delta< 1.0E-4 * bb ) )
-    {
-      if (fabs(a) < 1.e-30 )
-	l1 = l2 = 0;
-      else 
-	l1=l2=-b/(2*a); 
-      V[0][0] = 1.;
-      V[1][0] = 0.;
-      V[0][1] = 0.;
-      V[1][1] = 1.;
-    }
-  else {
-    const double delta2 = sqrt(delta);
-    l1= (-b - delta2)/(2*a);
-    l2= (-b + delta2)/(2*a);
-    double v0 = a11-l1*b11, v1 = a21-l1*b21,v2 = a22 - l1*b22;
-    double s0 = v0*v0 + v1*v1, s1 = v1*v1 +v2*v2;
-    double vp1x,vp1y,vp2x,vp2y;   
-    if(s1 < s0)
-      s0=sqrt(s0),vp1x=v1/s0,vp1y=-v0/s0;
-    else
-      s1=sqrt(s1),vp1x=v2/s1,vp1y=-v1/s1;
-    
-    v0 = a11-l2*b11, v1 = a21-l2*b21,v2 = a22 - l2*b22;
-    s0 = v0*v0 + v1*v1, s1 = v1*v1 +v2*v2;
-    if(s1 < s0)
-      s0=sqrt(s0),vp2x=v1/s0,vp2y=-v0/s0;
-    else
-      s1=sqrt(s1),vp2x=v2/s1,vp2y=-v1/s1;
-      V[0][0] = vp1x;
-      V[0][1] = vp2x;
-      V[1][0] = vp1y;
-      V[1][1] = vp2y;
-  }
+  throw;
 }
 
 gmsh2dMetric metricIntersection(const gmsh2dMetric &Ma,const gmsh2dMetric &Mb) 
 {
-  double M[2][2],M1[2][2];
-  double l1,l2;
-  simultaneousMetricReduction(Ma,Mb,l1,l2,M);
-  inv2x2 ( M, M1 );
-  const double M1ev1 = Ma.eval(M[0][0],M[0][1]);
-  const double M1ev2 = Ma.eval(M[0][0],M[0][1]);
-  const double M2ev1 = Mb.eval(M[1][0],M[1][1]);
-  const double M2ev2 = Mb.eval(M[1][0],M[1][1]);
-
-  const double D0 = std::max( M1ev1,M1ev2);
-  const double D1 = std::max( M2ev1,M2ev2);
-
-  return gmsh2dMetric(M1[0][0] * D0 * M1[0][0] + M1[0][1] * D1 * M1[0][1] ,
-		      0.5 * ( M1[0][0] * D0 * M1[1][0] + M1[0][1] * D1 * M1[1][1] +
-			      M1[1][0] * D0 * M1[0][0] + M1[1][1] * D1 * M1[0][1] ), 
-		      M1[1][0] * D0 * M1[1][0] + M1[1][1] * D1 * M1[1][1] );		            
+  throw;
 }
 
 gmsh2dMetric metricInterpolationTriangle(const gmsh2dMetric &M1,
@@ -141,106 +58,47 @@ gmsh2dMetric metricInterpolationTriangle(const gmsh2dMetric &M1,
 					 const double u, 
 					 const double v) 
 {
-  double m1[2][2] = {{M1.a11,0.5*M1.a21},{0.5*M1.a21,M1.a22}};
-  double m2[2][2] = {{M2.a11,0.5*M2.a21},{0.5*M2.a21,M2.a22}};
-  double m3[2][2] = {{M3.a11,0.5*M3.a21},{0.5*M3.a21,M3.a22}};
-  double invm1 [2][2]; inv2x2 ( m1, invm1 );
-  double invm2 [2][2]; inv2x2 ( m2, invm2 );
-  double invm3 [2][2]; inv2x2 ( m3, invm3 ); 
-  double invm [2][2] ;
-  for (int i=0;i<2;i++)
-    for (int j=0;j<2;j++)
-      invm[i][j] = (1.-u-v) * invm1[i][j] + u * invm2[i][j] + v * invm3[i][j];
-  double m [2][2]; inv2x2 ( invm, m );
-  return gmsh2dMetric ( m[0][0] , m[0][1] , m[1][1] );
+  throw;
 }
 
 gmsh2dMetric :: gmsh2dMetric ( double lc )
   : a11 ( 1./(lc*lc) ) ,a21 ( 0.0 ) ,a22 ( 1./(lc*lc) )
 {  
+  throw;
 }
 
 
-MTri3::MTri3 ( MTriangle * t, std::vector<gmsh2dMetric> & sizes) : deleted(false), base (t)
+MTri3::MTri3 ( MTriangle * t, double lc) : deleted(false), base (t)
 {
   neigh[0] = neigh[1] = neigh[2] = 0;
-  // compute the metric at the centroid
-  metric = metricInterpolationTriangle(sizes [base->getVertex(0)->getNum()] , 
-				       sizes [base->getVertex(1)->getNum()] , 
-				       sizes [base->getVertex(2)->getNum()] ,
-				       1./3., 1./3.); 
-  Center_Circum_Aniso(metric.a11,metric.a21,metric.a22, xc, yc, circum_radius);
-  //  printf("metric %g %g %g circum_radius = %g\n",metric.a11,metric.a21,metric.a22,circum_radius);
-}
-
-int inCircumCircle ( MTri3 *t , const double *p , const gmsh2dMetric &metric ) 
-{
-  double xc, yc;
-  double eps, d1, d2, x[2];
-  t->Center_Circum_Aniso(metric.a11,metric.a21,metric.a22,xc, yc, d1);
-
-  x[0] = xc - p[0];
-  x[1] = yc - p[1];
-
-  d2 = sqrt(fabs(metric.eval(x[0],x[1])));
-
-  eps = fabs(d1 - d2) / (d1 + d2);
-  if(eps < 1.e-12) {
-    return 0; 
-  }
-  if(d2 < d1)
-    return 1;
-  return 0;
 
+  // compute the circumradius of the triangle
+  double pa[3] = {base->getVertex(0)->x(),base->getVertex(0)->y(),base->getVertex(0)->z()};
+  double pb[3] = {base->getVertex(1)->x(),base->getVertex(1)->y(),base->getVertex(1)->z()};
+  double pc[3] = {base->getVertex(2)->x(),base->getVertex(2)->y(),base->getVertex(2)->z()};
+  double center[3];
+  base->circumcenterXYZ(pa,pb,pc,center);
+  const double dx = base->getVertex(0)->x() - center[0];
+  const double dy = base->getVertex(0)->y() - center[1];
+  const double dz = base->getVertex(0)->z() - center[2];
+  
+  circum_radius = sqrt ( dx*dx + dy*dy + dz*dz);
+  circum_radius /= lc;
 }
 
+
 int MTri3::inCircumCircle ( const double *p ) const
 {
-
-    double pa[2] = {base->getVertex(0)->x(),base->getVertex(0)->y()};
-    double pb[2] = {base->getVertex(1)->x(),base->getVertex(1)->y()};
-    double pc[2] = {base->getVertex(2)->x(),base->getVertex(2)->y()};
-    double result = gmsh::incircle(pa, pb, pc, (double*)p) * gmsh::orient2d(pa, pb, pc);  
-    return (result > 0) ? 1 : 0;
-
-
-  double eps, d1, d2, x[2];
-
-  x[0] = xc - p[0];
-  x[1] = yc - p[1];
-
-  d1 = circum_radius;
-  d2 = sqrt(fabs(metric.eval(x[0],x[1])));
-
-  eps = fabs(d1 - d2) / (d1 + d2);
-  if(eps < 1.e-12) {
-    return 0; 
-  }
-  if(d2 < d1)
-    return 1;
-  return 0;
+  double pa[3] = {base->getVertex(0)->x(),base->getVertex(0)->y(),base->getVertex(0)->z()};
+  double pb[3] = {base->getVertex(1)->x(),base->getVertex(1)->y(),base->getVertex(1)->z()};
+  double pc[3] = {base->getVertex(2)->x(),base->getVertex(2)->y(),base->getVertex(2)->z()};
+  double fourth[3];
+  fourthPoint ( pa,pb,pc,fourth);
+
+  double result = gmsh::insphere(pa, pb, pc, fourth, (double*)p) * gmsh::orient3d(pa, pb, pc,fourth);  
+  return (result > 0) ? 1 : 0;  
 }
 
-struct edgeXface
-{
-  MVertex *v[2];
-  MTri3 * t1;
-  int i1;
-  edgeXface ( MTri3 *_t, int iFac)
-    : t1(_t),i1(iFac)
-  {
-    v[0] = t1->tri()->getVertex ( iFac == 0 ? 2 : iFac-1 );
-    v[1] = t1->tri()->getVertex ( iFac );
-    std::sort ( v, v+2 );
-  }
-  inline bool operator < ( const edgeXface & other) const
-  {
-    if (v[0] < other.v[0])return true;
-    if (v[0] > other.v[0])return false;
-    if (v[1] < other.v[1])return true;
-    return false;
-  }
-};
 
 template <class ITER>
 void connectTris ( ITER beg, ITER end)
@@ -269,9 +127,12 @@ void connectTris ( ITER beg, ITER end)
   }
 }
 
+void connectTriangles ( std::list<MTri3*> & l)
+{
+  connectTris(l.begin(),l.end());
+}
 
-void recurFindCavity (const gmsh2dMetric &metric, 
-		      std::list<edgeXface> & shell, 
+void recurFindCavity (std::list<edgeXface> & shell, 
 		      std::list<MTri3*> & cavity, 
 		      double *v, 
 		      MTri3 *t)
@@ -288,46 +149,111 @@ void recurFindCavity (const gmsh2dMetric &metric,
 	  shell.push_back ( edgeXface ( t, i ) );
       else  if (!neigh->isDeleted())
 	{
-	  int circ =  inCircumCircle ( neigh, v, metric );
+	  int circ =  neigh->inCircumCircle ( v );
 	  if (circ)
-	    recurFindCavity ( metric,shell, cavity,v , neigh);
+	    recurFindCavity ( shell, cavity,v , neigh);
 	  else
 	    shell.push_back ( edgeXface ( t, i ) );
 	}
     }
 }
 
+bool circUV ( MTriangle   *t , 
+	      std::vector<double> & Us,
+	      std::vector<double> & Vs , double *res)
+{
+  double p1 [2] = {Us[t->getVertex(0)->getNum()],Vs[t->getVertex(0)->getNum()]};
+  double p2 [2] = {Us[t->getVertex(1)->getNum()],Vs[t->getVertex(1)->getNum()]};
+  double p3 [2] = {Us[t->getVertex(2)->getNum()],Vs[t->getVertex(2)->getNum()]};
+  t->circumcenterXY ( p1, p2 , p3, res);
+}
+
+bool invMapUV ( MTriangle   *t , 
+		double *p,
+		std::vector<double> & Us,
+		std::vector<double> & Vs , double *uv, double tol)
+{
+  double mat[2][2];
+  double b[2];
+
+  double u0 = Us[t->getVertex(0)->getNum()];
+  double v0 = Vs[t->getVertex(0)->getNum()];
+  double u1 = Us[t->getVertex(1)->getNum()];
+  double v1 = Vs[t->getVertex(1)->getNum()];
+  double u2 = Us[t->getVertex(2)->getNum()];
+  double v2 = Vs[t->getVertex(2)->getNum()];
+
+  mat[0][0] = u1 - u0;
+  mat[0][1] = u2 - u0;
+  mat[1][0] = v1 - v0;
+  mat[1][1] = v2 - v0;
+
+  b[0] = p[0] - u0;
+  b[1] = p[1] - v0;
+  sys2x2(mat, b, uv);
+
+  if(uv[0] >= -tol && 
+     uv[1] >= -tol && 
+     uv[0] <= 1. + tol && 
+     uv[1] <= 1. + tol && 
+     1. - uv[0] - uv[1] > -tol) {
+    return true;
+  }
+  return false; 
+}
+
+
+double getSurfUV ( MTriangle   *t , 
+		 std::vector<double> & Us,
+		 std::vector<double> & Vs )
+{
+  double u1 = Us[t->getVertex(0)->getNum()];
+  double v1 = Vs[t->getVertex(0)->getNum()];
+  double u2 = Us[t->getVertex(1)->getNum()];
+  double v2 = Vs[t->getVertex(1)->getNum()];
+  double u3 = Us[t->getVertex(2)->getNum()];
+  double v3 = Vs[t->getVertex(2)->getNum()];
+  const double vv1 [2] = {u2 - u1, v2 - v1};
+  const double vv2 [2] = {u3 - u1, v3 - v1};
+  double s = vv1[0] * vv2[1] - vv1[1] * vv2[0]; 
+  return s * 0.5;
+
+}
+
 bool insertVertex (MVertex *v , 
 		   MTri3   *t ,
 		   std::set<MTri3*,compareTri3Ptr> &allTets,
-		   std::vector<gmsh2dMetric> & vSizes,
-		   const gmsh2dMetric &metric)
+		   std::vector<double> & vSizes,
+		   std::vector<double> & vSizesBGM,
+		   std::vector<double> & Us,
+		   std::vector<double> & Vs)
 {
   std::list<edgeXface>  shell;
   std::list<MTri3*>  cavity; 
   std::list<MTri3*>  new_cavity;
 
-  double p[2] = {v->x(),v->y()};
+  double p[3] = {v->x(),v->y(),v->z()};
 
-  recurFindCavity ( metric,shell,  cavity, p , t);  
+  recurFindCavity ( shell,  cavity, p , t);  
 
   // check that volume is conserved
   double newVolume = 0;
   double oldVolume = 0;
 
+
   std::list<MTri3*>::iterator ittet = cavity.begin();
   std::list<MTri3*>::iterator ittete = cavity.end();
   while ( ittet != ittete )
     {
-      oldVolume += fabs((*ittet)->getSurfaceXY());
+      oldVolume += fabs(getSurfUV((*ittet)->tri(),Us,Vs));
       ++ittet;
     }
 
-//    char name[245];
-//    int III = 1;
-//    sprintf(name,"test%d.pos",III);
-//    FILE *ff = fopen (name,"w");
-//    fprintf(ff,"View\"test\"{\n");
+//   fprintf(ff,"};\n");
+//   fclose (ff);
+//   sprintf(name,"test%d.pos",III++);
+//   ff = fopen (name,"w");
+//   fprintf(ff,"View\"test\"{\n");
 
 
   MTri3** newTris = new MTri3*[shell.size()];;
@@ -339,17 +265,25 @@ bool insertVertex (MVertex *v ,
       MTriangle *t = new MTriangle ( it->v[0],
 				     it->v[1],
 				     v);
-      MTri3 *t4 = new MTri3 ( t , vSizes); 
-//       fprintf(ff,"ST(%g,%g,%g,%g,%g,%g,%g,%g,%g) {0,0,0};\n",
-// 	      it->v[0]->x(),
-// 	      it->v[0]->y(),
-// 	      it->v[0]->z(),
-// 	      it->v[1]->x(),
-// 	      it->v[1]->y(),
-// 	      it->v[1]->z(),
-// 	      v->x(),
-// 	      v->y(),
-// 	      v->z());
+
+      double lc    = 0.3333333333*(vSizes [t->getVertex(0)->getNum()]+
+				   vSizes [t->getVertex(1)->getNum()]+
+				   vSizes [t->getVertex(2)->getNum()]);
+      double lcBGM = 0.3333333333*(vSizesBGM [t->getVertex(0)->getNum()]+
+				   vSizesBGM [t->getVertex(1)->getNum()]+
+				   vSizesBGM [t->getVertex(2)->getNum()]);
+      
+      MTri3 *t4 = new MTri3 ( t , std::min(lc,lcBGM)); 
+//        fprintf(ff,"ST(%g,%g,%g,%g,%g,%g,%g,%g,%g) {0,0,0};\n",
+// 	       Us [t->getVertex(0)->getNum()],
+// 	       Vs [t->getVertex(0)->getNum()],
+// 	       0.0,
+// 	       Us [t->getVertex(1)->getNum()],
+// 	       Vs [t->getVertex(1)->getNum()],
+// 	       0.0,
+// 	       Us [t->getVertex(2)->getNum()],
+// 	       Vs [t->getVertex(2)->getNum()],
+// 	       0.0);
       newTris[k++]=t4;
       // all new triangles are pushed front in order to
       // ba able to destroy them if the cavity is not
@@ -360,13 +294,13 @@ bool insertVertex (MVertex *v ,
       if (otherSide)
       	new_cavity.push_back (otherSide);
       //      if (!it->t1->isDeleted())throw;
-      double ss = fabs(t4->getSurfaceXY());
+      double ss = fabs(getSurfUV(t4->tri(),Us,Vs));
       if (ss < 1.e-12)ss = 1256172121;
       newVolume += ss;
       ++it;
     }
-//    fprintf(ff,"};\n");
-//    fclose (ff);
+//     fprintf(ff,"};\n");
+//     fclose (ff);
 //   printf("%d %d newVolume %g oldVolume %g\n",cavity.size(),new_cavity.size(),newVolume,oldVolume);
 //    getchar();
 
@@ -381,6 +315,8 @@ bool insertVertex (MVertex *v ,
   // The cavity is NOT star shaped
   else
     {      
+      printf("the cavity (%d members) is not star shaped %g vs %g\n",shell.size(),oldVolume,newVolume);
+
       for (unsigned int i=0;i<shell.size();i++)delete newTris[i];
       delete [] newTris;      
       ittet = cavity.begin();
@@ -394,19 +330,21 @@ bool insertVertex (MVertex *v ,
     }
 }
 
-static gmsh2dMetric evalMetricTensor ( GFace *gf , MVertex *mv , double lc )
+static void setLcsMax ( MTriangle *t, std::map<MVertex*,double> &vSizes)
 {
-  Pair<SVector3,SVector3> der = gf->firstDer(SPoint2(mv->x(),mv->y())) ;
-  const double oneoverlc2 = 1./(lc*lc);
-  const double a11 = dot(der.first() ,der.first() ) * oneoverlc2; 
-  const double a21 = dot(der.second(),der.first() ) * oneoverlc2; 
-  const double a22 = dot(der.second(),der.second()) * oneoverlc2; 
-
-  //  printf("metric : %g %g %g - %g %g\n",a11,a21,a22,oneoverlc2,lc);
-
-  return gmsh2dMetric ( a11, a21 , a22);
+  for (int i=0;i<3;i++)
+    {
+      for (int j=i+1;j<3;j++)
+	{
+	  MVertex *vi = t->getVertex(i);
+	  MVertex *vj = t->getVertex(j);
+	  vSizes[vi] = 1.e12;
+	  vSizes[vj] = 1.e12;
+	}
+    }
 }
 
+
 static void setLcs ( MTriangle *t, std::map<MVertex*,double> &vSizes)
 {
   for (int i=0;i<3;i++)
@@ -415,14 +353,15 @@ static void setLcs ( MTriangle *t, std::map<MVertex*,double> &vSizes)
 	{
 	  MVertex *vi = t->getVertex(i);
 	  MVertex *vj = t->getVertex(j);
+
 	  double dx = vi->x()-vj->x();
 	  double dy = vi->y()-vj->y();
 	  double dz = vi->z()-vj->z();
 	  double l = sqrt(dx*dx+dy*dy+dz*dz);
 	  std::map<MVertex*,double>::iterator iti = vSizes.find(vi);	  
 	  std::map<MVertex*,double>::iterator itj = vSizes.find(vj);	  
-	  if (iti==vSizes.end() || iti->second > l)vSizes[vi] = l;
-	  if (itj==vSizes.end() || itj->second > l)vSizes[vj] = l;
+	  if (iti->second > l)iti->second = l;
+	  if (itj->second > l)itj->second = l;
 	}
     }
 }
@@ -432,32 +371,31 @@ void insertVerticesInFace (GFace *gf, BDS_Mesh *bds)
 
   std::set<MTri3*,compareTri3Ptr> AllTris;
   std::map<MVertex*,double> vSizesMap;
-  std::map<const BDS_Point*,MVertex*> recoverMap;
-  std::vector<gmsh2dMetric> vMetrics;
-  std::vector<double> vSizes;
+  std::vector<double> vSizes, vSizesBGM,Us,Vs;
 
+  for (unsigned int i=0;i<gf->triangles.size();i++)setLcsMax ( gf->triangles[i] , vSizesMap);
 
   // compute edge sizes on the contour and propagate thos sizes inside the surface
   for (unsigned int i=0;i<gf->triangles.size();i++)setLcs ( gf->triangles[i] , vSizesMap);
 
-  // set vertex positions to local coordinates of the face  
-  // compute metric tensors of the surface
   int NUM=0;
   for (std::map<MVertex*,double>::iterator it = vSizesMap.begin();it!=vSizesMap.end();++it)
     {
-      BDS_Point *p;
-      p = bds->find_point(it->first->getNum());
-      it->first->x() = p->u;
-      it->first->y() = p->v;
-      it->first->z() = 0;
       it->first->setNum(NUM++);      
-      vSizes.push_back(it->second);
-      recoverMap[p]= (it->first);
-      vMetrics.push_back(evalMetricTensor ( gf , it->first, it->second));
+      vSizes.push_back(it->second); 
+      vSizesBGM.push_back(it->second); 
+      double u0,v0;
+      parametricCoordinates ( it->first, gf, u0, v0);
+      Us.push_back(u0);
+      Vs.push_back(v0);
     }
-  
   for (unsigned int i=0;i<gf->triangles.size();i++)
-    AllTris.insert ( new MTri3 ( gf->triangles[i] ,vMetrics ) );
+    {
+      double lc    = 0.3333333333*(vSizes [gf->triangles[i]->getVertex(0)->getNum()]+
+				   vSizes [gf->triangles[i]->getVertex(1)->getNum()]+
+				   vSizes [gf->triangles[i]->getVertex(2)->getNum()]);
+      AllTris.insert ( new MTri3 ( gf->triangles[i] ,lc ) );
+    }
 
   gf->triangles.clear();
   connectTris ( AllTris.begin(), AllTris.end() );      
@@ -483,43 +421,53 @@ void insertVerticesInFace (GFace *gf, BDS_Mesh *bds)
 	{
 	  if(ITER++%5000 ==0)
 	    Msg(DEBUG,"%7d points created -- Worst tri radius is %8.3f",vSizes.size(),worst->getRadius());
-	  if (worst->getRadius() < 0.5 * sqrt(2.0)) break;
 	  double center[2],uv[2];
-	  worst->getCenter(center);
-	  //	  worst->tri()->circumcenterXY(center);
-	  bool inside = worst->tri()->invertmappingXY(center,uv);
-	  if (inside || 1)
+	  if (worst->getRadius() < 0.5 * sqrt(2.0)) break;	  
+	  circUV(worst->tri(),Us,Vs,center);
+	  bool inside = invMapUV(worst->tri(),center,Us,Vs,uv,1.e-8);
+
+	  if (1 || inside)
 	    {
 	      // we use here local coordinates as real coordinates
 	      // x,y and z will be computed hereafter
 	      //	      Msg(INFO,"Point is inside");
-	      MVertex *v = new MFaceVertex (center[0],center[1],0.0,gf,center[0],center[1]);
-	      v->setNum(NUM++);
-	      double lc1 = (1.-uv[0]-uv[1]) * vSizes [worst->tri()->getVertex(0)->getNum()] + 
-		uv[0] * vSizes [worst->tri()->getVertex(1)->getNum()] + 
-		uv[1] * vSizes [worst->tri()->getVertex(2)->getNum()] ; 
 	      GPoint p = gf->point (center[0],center[1]);
-	      double lc = std::min(lc1,BGM_MeshSize(gf,center[0],center[1],p.x(),p.y(),p.z()));
-	      vSizes.push_back(lc);
-	      gmsh2dMetric metr = evalMetricTensor ( gf , v, lc); 
-	      vMetrics.push_back(metr);
+	      MVertex *v = new MFaceVertex (p.x(),p.y(),p.z(),gf,center[0],center[1]);
+	      v->setNum(NUM++);
+	      double lc1 = ((1.-uv[0]-uv[1]) * vSizes [worst->tri()->getVertex(0)->getNum()] + 
+			       uv[0] * vSizes [worst->tri()->getVertex(1)->getNum()] + 
+			       uv[1] * vSizes [worst->tri()->getVertex(2)->getNum()] ); 
+	      //	      double eigMetricSurface = gf->getMetricEigenvalue(SPoint2(center[0],center[1]));
+	      double lc = BGM_MeshSize(gf,center[0],center[1],p.x(),p.y(),p.z());
+	      //	      printf("lc1 %12.5E lc %12.5E\n",lc1,lc);
 	      
-	      // compute mesh spacing there
-	      if (!insertVertex ( v  , worst, AllTris,vMetrics,metr))
+	      vSizesBGM.push_back( lc );
+	      vSizes.push_back   ( lc1);
+	      Us.push_back( center[0] );
+	      Vs.push_back( center[1] );
+	      
+	      if (!insertVertex ( v , worst, AllTris,vSizes,vSizesBGM,Us,Vs))
 		{
+		  Msg(INFO,"cavity is invalid");
 		  AllTris.erase(AllTris.begin());
-		  worst->forceRadius(0);
+		  worst->forceRadius(-1);
 		  AllTris.insert(worst);		  
 		  delete v;
 		}
 	      else 
-		{
-		  gf->mesh_vertices.push_back(v);
-		}
+		gf->mesh_vertices.push_back(v);
 	    }
  	  else
  	    {
- 	      //	      Msg(INFO,"Point is outside");
+	      Msg(INFO,"Point %g %g is outside %g %g - %g %g - %g %g (%g %g)",
+		  center[0],center[1],		  
+		  Us [(worst)->tri()->getVertex(0)->getNum()],
+		  Vs [(worst)->tri()->getVertex(0)->getNum()],
+		  Us [(worst)->tri()->getVertex(1)->getNum()],
+		  Vs [(worst)->tri()->getVertex(1)->getNum()],
+		  Us [(worst)->tri()->getVertex(2)->getNum()],
+		  Vs [(worst)->tri()->getVertex(2)->getNum()],
+		  uv[0],uv[1]);
  	      AllTris.erase(AllTris.begin());
  	      worst->forceRadius(0);
  	      AllTris.insert(worst);		  
@@ -527,30 +475,13 @@ void insertVerticesInFace (GFace *gf, BDS_Mesh *bds)
 	}
     }
 
-  // restore real coordinates of vertices
-  if (1){
-    std::map<const BDS_Point*,MVertex*>::const_iterator itx =  recoverMap.begin();
-    while (itx != recoverMap.end())
-      {
-	MVertex *v = (itx->second);
-	const BDS_Point *p = (itx->first);
-	v->x() = p->X;
-	v->y() = p->Y;
-	v->z() = p->Z;
-	++itx;
-      }
-    for (unsigned int i=0;i<gf->mesh_vertices.size();i++)
-      {
-	double u = gf->mesh_vertices[i]->x();
-	double v = gf->mesh_vertices[i]->y();
-	GPoint p = gf->point(u,v);
-	gf->mesh_vertices[i]->x() = p.x();
-	gf->mesh_vertices[i]->y() = p.y();
-	gf->mesh_vertices[i]->z() = p.z();
-      }
-  }
+  // optimize the mesh
 
   // fill new gmsh structures with triangles
+   char name[245];
+   sprintf(name,"param%d.pos",gf->tag());
+   FILE *ff = fopen (name,"w");
+   fprintf(ff,"View\"test\"{\n");
   while (1)
     {
       if (AllTris.begin() == AllTris.end() ) break;
@@ -562,8 +493,20 @@ void insertVerticesInFace (GFace *gf, BDS_Mesh *bds)
       else
 	{
 	  gf->triangles.push_back(worst->tri());
+	  fprintf(ff,"ST(%g,%g,%g,%g,%g,%g,%g,%g,%g) {0,0,0};\n",
+		  Us [(worst)->tri()->getVertex(0)->getNum()],
+		  Vs [(worst)->tri()->getVertex(0)->getNum()],
+		  0.0,
+		  Us [(worst)->tri()->getVertex(1)->getNum()],
+		  Vs [(worst)->tri()->getVertex(1)->getNum()],
+		  0.0,
+		  Us [(worst)->tri()->getVertex(2)->getNum()],
+		  Vs [(worst)->tri()->getVertex(2)->getNum()],
+		  0.0);
 	}
       delete worst;
       AllTris.erase(AllTris.begin());      
     }
+  fprintf(ff,"};\n");
+  fclose (ff);
 }
diff --git a/Mesh/meshGFaceDelaunayInsertion.h b/Mesh/meshGFaceDelaunayInsertion.h
index 778489ec07721ebc51606ced190dff72e57c6c1f..ae3f8a89c6ef54eceb2c669e54a0560a866367c3 100644
--- a/Mesh/meshGFaceDelaunayInsertion.h
+++ b/Mesh/meshGFaceDelaunayInsertion.h
@@ -46,8 +46,6 @@ struct gmsh2dMetric
 class MTri3
 {
   bool deleted;
-  gmsh2dMetric metric;
-  double xc,yc;
   double circum_radius;
   MTriangle *base;
   MTri3 *neigh[3];
@@ -56,9 +54,8 @@ class MTri3
   bool isDeleted () const {return deleted;}
   void   forceRadius (double r){circum_radius=r;}
   double getRadius ()const {return circum_radius;}
-  inline void getCenter (double c[2]) const {c[0]=xc;c[1]=yc;}
   
-  MTri3 ( MTriangle * t, std::vector<gmsh2dMetric> & sizes);
+  MTri3 ( MTriangle * t, double lc);
   inline MTriangle * tri() const {return base;}
   inline void  setNeigh (int iN , MTri3 *n) {neigh[iN]=n;}
   inline MTri3 *getNeigh (int iN ) const {return neigh[iN];}
@@ -76,6 +73,7 @@ class MTri3
   void Center_Circum_Aniso(double a, double b, double d, double &x, double &y, double &r) const ;
 
   double getSurfaceXY () const { return base -> getSurfaceXY() ; };
+  double getSurfaceUV (GFace* gf) const { return base -> getSurfaceUV(gf) ; };
   inline void setDeleted (bool d)
   {
     deleted = d;
@@ -111,4 +109,28 @@ class compareTri3Ptr
    }
 };
 
+
+struct edgeXface
+{
+  MVertex *v[2];
+  MTri3 * t1;
+  int i1;
+  edgeXface ( MTri3 *_t, int iFac)
+    : t1(_t),i1(iFac)
+  {
+    v[0] = t1->tri()->getVertex ( iFac == 0 ? 2 : iFac-1 );
+    v[1] = t1->tri()->getVertex ( iFac );
+    std::sort ( v, v+2 );
+  }
+  inline bool operator < ( const edgeXface & other) const
+  {
+    if (v[0] < other.v[0])return true;
+    if (v[0] > other.v[0])return false;
+    if (v[1] < other.v[1])return true;
+    return false;
+  }
+};
+
+
+
 #endif
diff --git a/Mesh/meshGFaceOptimize.cpp b/Mesh/meshGFaceOptimize.cpp
index e61e04e7acf7133b0df4a7b0ac664d1cef86b7a5..63beef62bc94496f379b5c2f7fbf8e9a11a6c012 100644
--- a/Mesh/meshGFaceOptimize.cpp
+++ b/Mesh/meshGFaceOptimize.cpp
@@ -4,10 +4,9 @@
 #include "GVertex.h"
 #include "MVertex.h"
 #include "MElement.h"
-#include <map>
-#include <vector>
 
 typedef std::map<MVertex*,std::vector<MTriangle*> > v2t_cont ;
+typedef std::map<MEdge, std::pair<MTriangle*,MTriangle*> , Less_Edge>     e2t_cont ;
 
 void buildVertexToTriangle ( GFace *gf ,  v2t_cont &adj )
 {
@@ -34,33 +33,43 @@ void buildVertexToTriangle ( GFace *gf ,  v2t_cont &adj )
 }
 
 
+void buildEdgeToTriangle ( GFace *gf ,  e2t_cont &adj )
+{
+  buildEdgeToTriangle(gf->triangles,adj);
+}
+
+void buildEdgeToTriangle ( std::vector<MTriangle*> &triangles ,  e2t_cont &adj )
+{
+  adj.clear();
+  for (unsigned int i=0;i<triangles.size();i++)
+    {
+      MTriangle *t = triangles[i];
+      for (unsigned int j=0;j<3;j++)
+	{
+	  MVertex *v1 = t->getVertex(j);
+	  MVertex *v2 = t->getVertex((j+1)%3);
+	  MEdge e(v1,v2);
+	  e2t_cont :: iterator it = adj.find ( e );      
+	  if (it == adj.end())
+	    {
+	      std::pair<MTriangle*,MTriangle*> one = std::make_pair (t,(MTriangle*)0);
+	      adj[e] = one;
+	    }
+	  else
+	    {
+	      it->second.second = t;
+	    }
+	}
+    }
+}
+
+
 void parametricCoordinates ( MTriangle *t , GFace *gf, double u[3], double v[3])
 {
   for (unsigned int j=0;j<3;j++)
     {
       MVertex *ver = t->getVertex(j);
-      GEntity *ge = ver->onWhat();
-      if (ge->dim() == 2)
-	{
-	  ver->getParameter ( 0,u[j]);
-	  ver->getParameter ( 1,v[j]);	  
-	}
-      else if (ge->dim() == 1)
-	{
-	  double t;
-	  ver->getParameter ( 0,t);
-	  GEdge *ged = dynamic_cast<GEdge*> (ge);
-	  SPoint2 p = ged->reparamOnFace ( gf , t , 1);
-	  u[j] =p.x(); 
-	  v[j] =p.y(); 
-	}
-      else
-	{
-	  GVertex *gver = dynamic_cast<GVertex*> (ge);
-	  SPoint2 p = gver->reparamOnFace ( gf , 1);
-	  u[j] =p.x(); 
-	  v[j] =p.y(); 
-	}      
+      parametricCoordinates ( ver , gf, u[j],  v[j]);
     }
 }
 
@@ -102,9 +111,93 @@ void laplaceSmoothing (GFace *gf)
 	  ver->y() = pt.y();
 	  ver->z() = pt.z();
 	}
+      ++it;
+    }  
+}
+
+extern void fourthPoint (double *p1, double *p2, double *p3, double *p4);
+
+bool edgeSwap(e2t_cont &adj, e2t_cont::iterator &it, GFace *gf)
+{  
+  MVertex *v1 = it->first.getVertex(0);
+  MVertex *v2 = it->first.getVertex(1);
+  MVertex *o1,*o2 ;
+  MTriangle *t1 = it->second.first;
+  MTriangle *t2 = it->second.second;
+  for (int i=0;i<3;i++)
+    {
+      if (t1->getVertex(i) != v1 &&
+	  t1->getVertex(i) != v2)o1 = t1->getVertex(i);
+      if (t2->getVertex(i) != v1 &&
+	  t2->getVertex(i) != v2)o1 = t2->getVertex(i);
+    }
+  
+}
+
+
+
+bool edgeSwapTestDelaunay(e2t_cont::iterator &it,GFace *gf)
+{  
+  if(!it->second.second) return false;
+
+  MVertex *v1 = it->first.getVertex(0);
+  MVertex *v2 = it->first.getVertex(1);
+  MVertex *o1,*o2 ;
+  for (int i=0;i<3;i++)
+    {
+      if (it->second.first->getVertex(i) != v1 &&
+	  it->second.first->getVertex(i) != v2)o1 = it->second.first->getVertex(i);
+      if (it->second.second->getVertex(i) != v1 &&
+	  it->second.second->getVertex(i) != v2)o2 = it->second.second->getVertex(i);
     }
+  double p1[2];
+  double p2[2];
+  double op1[2];
+  double op2[2];
+  parametricCoordinates ( v1,gf,p1[0],p1[1] );
+  parametricCoordinates ( v2,gf,p2[0],p2[1] );
+  parametricCoordinates ( o1,gf,op1[0],op1[1] );
+  parametricCoordinates ( o2,gf,op2[0],op2[1] );
   
+  double ori_t1 = gmsh::orient2d(op1, p1, op2);
+  double ori_t2 = gmsh::orient2d(op1,op2, p2);
 
+
+  // the quad is concave in parametric coord, return false
+  if ( ori_t1 * ori_t2 <= 0) return false;
+
+  double p1x[3] =  {v1->x(),v1->y(),v1->z()};
+  double p2x[3] =  {v2->x(),v2->y(),v2->z()};
+  double op1x[3] =  {o1->x(),o1->y(),o1->z()};
+  double op2x[3] =  {o2->x(),o2->y(),o2->z()};
+  double fourth[3];
+  fourthPoint(p1x,p2x,op1x,fourth);
+  double result = gmsh::insphere(p1x, p2x, op1x, fourth, op2x) * gmsh::orient3d(p1x, p2x, op1x, fourth);  
+  return result > 0.;
 }
 
+void edgeSwappingLawson (GFace *gf)
+{
+
+  e2t_cont adj;
+  buildEdgeToTriangle ( gf ,  adj );
+
+  e2t_cont :: iterator it = adj.begin();
+  
+  while (it != adj.end())
+    {
+      
+      bool evalSwapLawson = edgeSwapTestDelaunay(it,gf);
+
+      if ( evalSwapLawson )
+	{
+	  edgeSwap  (adj, it ,gf );
+	  e2t_cont :: iterator itb = it;
+	  ++it;
+	  adj.erase(itb);
+	}
+      else
+	++it;
+    }  
+}
 
diff --git a/Mesh/meshGFaceOptimize.h b/Mesh/meshGFaceOptimize.h
index 3280450f549ea498b3427f57a369fa0f0c8ff5a6..b68331f14c015fea07265b220d4ebc4c271dac6f 100644
--- a/Mesh/meshGFaceOptimize.h
+++ b/Mesh/meshGFaceOptimize.h
@@ -19,7 +19,16 @@
 // USA.
 // 
 // Please report all bugs and problems to <gmsh@geuz.org>.
+#include "MElement.h"
+#include "MEdge.h"
+#include <map>
+#include <vector>
 class GFace;
+class MVertex;
+typedef std::map<MVertex*,std::vector<MTriangle*> > v2t_cont ;
+typedef std::map<MEdge, std::pair<MTriangle*,MTriangle*> , Less_Edge> e2t_cont ;
+void buildVertexToTriangle ( std::vector<MTriangle*> & ,  v2t_cont &adj );
+void buildEdgeToTriangle ( std::vector<MTriangle*> & ,  e2t_cont &adj );
 void laplaceSmoothing   (GFace *gf);
 void edgeSwappingLawson (GFace *gf);
 #endif
diff --git a/Mesh/meshGFaceTransfinite.cpp b/Mesh/meshGFaceTransfinite.cpp
index 1d3ecca0e067282089b48602fa85dc8d5fba8013..1f99c7db86e94ca65aa5bd05898f88deca808b0f 100644
--- a/Mesh/meshGFaceTransfinite.cpp
+++ b/Mesh/meshGFaceTransfinite.cpp
@@ -1,4 +1,4 @@
-// $Id: meshGFaceTransfinite.cpp,v 1.20 2007-05-24 17:34:04 geuzaine Exp $
+// $Id: meshGFaceTransfinite.cpp,v 1.21 2007-09-04 13:47:02 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/Mesh/meshGRegionDelaunayInsertion.cpp b/Mesh/meshGRegionDelaunayInsertion.cpp
index 843fb7e6e5672ad3abb627aad0c290114e59b31c..7018ced6575d705915a8090e5791e083fb86acb3 100644
--- a/Mesh/meshGRegionDelaunayInsertion.cpp
+++ b/Mesh/meshGRegionDelaunayInsertion.cpp
@@ -1,4 +1,4 @@
-// $Id: meshGRegionDelaunayInsertion.cpp,v 1.17 2007-03-23 08:44:41 geuzaine Exp $
+// $Id: meshGRegionDelaunayInsertion.cpp,v 1.18 2007-09-04 13:47:02 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
@@ -137,14 +137,6 @@ bool insertVertex (MVertex *v ,
   std::list<MTet4*>  cavity; 
   std::list<MTet4*>  new_cavity;
 
-//   int NC = 0;
-//   {
-//     for (std::set<MTet4*,compareTet4Ptr>::iterator it = allTets.begin();it!=allTets.end();++it)
-//       {
-// 	if (!((*it)->isDeleted()) && (*it)->inCircumSphere ( v ))NC++;	
-//       }
-//   }
-
   recurFindCavity ( shell,  cavity, v , t);  
 
 //     Msg(INFO,"%d %d",cavity.size(),NC);
@@ -201,7 +193,6 @@ bool insertVertex (MVertex *v ,
   std::list<faceXtet>::iterator it =   shell.begin();
 
 
-
   while (it != shell.end())
     {
       MTetrahedron *tr = new MTetrahedron ( it->v[0],
diff --git a/Numeric/EigSolve.cpp b/Numeric/EigSolve.cpp
index 2cf7b3e42dba675763e726e94cedf22bb14cc477..9e1eab25463ed7d30880151e0e628b31f38a9e9d 100644
--- a/Numeric/EigSolve.cpp
+++ b/Numeric/EigSolve.cpp
@@ -1,4 +1,4 @@
-// $Id: EigSolve.cpp,v 1.7 2006-11-27 22:22:17 geuzaine Exp $
+// $Id: EigSolve.cpp,v 1.8 2007-09-04 13:47:03 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/Numeric/gsl_brent.cpp b/Numeric/gsl_brent.cpp
index 801229dc21564437255b8daefd4eef4812f41b9c..ede3483354585b94b2a6dc452369ac47ffbdd32c 100644
--- a/Numeric/gsl_brent.cpp
+++ b/Numeric/gsl_brent.cpp
@@ -1,4 +1,4 @@
-// $Id: gsl_brent.cpp,v 1.15 2006-11-27 22:22:17 geuzaine Exp $
+// $Id: gsl_brent.cpp,v 1.16 2007-09-04 13:47:03 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/Parallel/ParUtil.cpp b/Parallel/ParUtil.cpp
index b3592bcb5853eaf02cb8cfaaab7f98c9c884cfa2..c9a922a2e1bec7c39c81c8d1d1f884e43401ec3e 100644
--- a/Parallel/ParUtil.cpp
+++ b/Parallel/ParUtil.cpp
@@ -1,4 +1,4 @@
-// $Id: ParUtil.cpp,v 1.17 2006-11-27 22:22:17 geuzaine Exp $
+// $Id: ParUtil.cpp,v 1.18 2007-09-04 13:47:03 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/Parser/FunctionManager.cpp b/Parser/FunctionManager.cpp
index ca81d6904acad7c8f3de3765b29809b1f548be16..6c434d5d3d8a5c3d2b54870c0f526ec35e2eb65d 100644
--- a/Parser/FunctionManager.cpp
+++ b/Parser/FunctionManager.cpp
@@ -1,4 +1,4 @@
-// $Id: FunctionManager.cpp,v 1.25 2006-11-27 22:22:17 geuzaine Exp $
+// $Id: FunctionManager.cpp,v 1.26 2007-09-04 13:47:03 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/Parser/Gmsh.tab.cpp b/Parser/Gmsh.tab.cpp
index dc7829165e91b3997fef3467308481b5baaa53bc..c8d5b63b5c6cc589d11bf6bc1a3686d34b2727cf 100644
--- a/Parser/Gmsh.tab.cpp
+++ b/Parser/Gmsh.tab.cpp
@@ -132,7 +132,7 @@
 
 #line 1 "Gmsh.y"
 
-// $Id: Gmsh.tab.cpp,v 1.327 2007-08-27 19:27:02 geuzaine Exp $
+// $Id: Gmsh.tab.cpp,v 1.328 2007-09-04 13:47:03 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/Parser/Gmsh.yy.cpp b/Parser/Gmsh.yy.cpp
index e7bdfc1c1207f647606500d2211f00f8ab455b75..b16a18e2827764fec62342a30a3ecd759d8dcab8 100644
--- a/Parser/Gmsh.yy.cpp
+++ b/Parser/Gmsh.yy.cpp
@@ -2,7 +2,7 @@
 /* A lexical scanner generated by flex */
 
 /* Scanner skeleton version:
- * $Header: /cvsroot/gmsh/Parser/Gmsh.yy.cpp,v 1.326 2007-08-27 19:27:03 geuzaine Exp $
+ * $Header: /cvsroot/gmsh/Parser/Gmsh.yy.cpp,v 1.327 2007-09-04 13:47:04 remacle Exp $
  */
 
 #define FLEX_SCANNER
@@ -759,7 +759,7 @@ char *yytext;
 #line 1 "Gmsh.l"
 #define INITIAL 0
 #line 2 "Gmsh.l"
-// $Id: Gmsh.yy.cpp,v 1.326 2007-08-27 19:27:03 geuzaine Exp $
+// $Id: Gmsh.yy.cpp,v 1.327 2007-09-04 13:47:04 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/Plugin/FieldView.cpp b/Plugin/FieldView.cpp
index ebc19520c7b5393f75fb77c0c954f484c648e473..2376a455561dab4bba84b59320edd087114e5d4e 100644
--- a/Plugin/FieldView.cpp
+++ b/Plugin/FieldView.cpp
@@ -1,4 +1,4 @@
-// $Id: FieldView.cpp,v 1.1 2007-05-07 07:50:33 remacle Exp $
+// $Id: FieldView.cpp,v 1.2 2007-09-04 13:47:05 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/Plugin/Gradient.cpp b/Plugin/Gradient.cpp
index 85aaafb1ab84c19bfb40907a50bb40c1061ae5c4..e0ffb3b02345b89a5220c702d1f67ace46962329 100644
--- a/Plugin/Gradient.cpp
+++ b/Plugin/Gradient.cpp
@@ -1,4 +1,4 @@
-// $Id: Gradient.cpp,v 1.8 2007-05-04 10:45:09 geuzaine Exp $
+// $Id: Gradient.cpp,v 1.9 2007-09-04 13:47:05 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/Plugin/HarmonicToTime.cpp b/Plugin/HarmonicToTime.cpp
index b613aa48a5f5612b4fddf078261234c5541b7e51..a0bdf82022ae9f6be19813842b8271e4bc22b4dc 100644
--- a/Plugin/HarmonicToTime.cpp
+++ b/Plugin/HarmonicToTime.cpp
@@ -1,4 +1,4 @@
-// $Id: HarmonicToTime.cpp,v 1.10 2007-05-04 10:45:09 geuzaine Exp $
+// $Id: HarmonicToTime.cpp,v 1.11 2007-09-04 13:47:05 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/Plugin/Integrate.cpp b/Plugin/Integrate.cpp
index b30ab74ad59ab77395a5418e88a8f378322c6269..ec065deed6a06fb98c1c622f1bb14e7b556dcb54 100644
--- a/Plugin/Integrate.cpp
+++ b/Plugin/Integrate.cpp
@@ -1,4 +1,4 @@
-// $Id: Integrate.cpp,v 1.20 2007-05-04 10:45:09 geuzaine Exp $
+// $Id: Integrate.cpp,v 1.21 2007-09-04 13:47:05 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/Plugin/Levelset.cpp b/Plugin/Levelset.cpp
index 36b3fc416332c3562d97264d7cabb78e2201a11e..7cefa8e5f3bb21e34bf535bea7e75889881139d2 100644
--- a/Plugin/Levelset.cpp
+++ b/Plugin/Levelset.cpp
@@ -1,4 +1,4 @@
-// $Id: Levelset.cpp,v 1.32 2007-05-04 14:27:41 geuzaine Exp $
+// $Id: Levelset.cpp,v 1.33 2007-09-04 13:47:05 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/Plugin/MakeSimplex.cpp b/Plugin/MakeSimplex.cpp
index 1f01922d526dfa51ea880e8fe00d1612eab99f22..e99ec1f8e78eb2fa1cc7bb2e499d012ee5ba9c01 100644
--- a/Plugin/MakeSimplex.cpp
+++ b/Plugin/MakeSimplex.cpp
@@ -1,4 +1,4 @@
-// $Id: MakeSimplex.cpp,v 1.1 2007-05-04 14:27:41 geuzaine Exp $
+// $Id: MakeSimplex.cpp,v 1.2 2007-09-04 13:47:05 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/Plugin/ModulusPhase.cpp b/Plugin/ModulusPhase.cpp
index 1cb562b41b50dbf039bfb68dc891bf83fed384bf..c13d215b931be433f48269e5e8299e144bec3dbc 100644
--- a/Plugin/ModulusPhase.cpp
+++ b/Plugin/ModulusPhase.cpp
@@ -1,4 +1,4 @@
-// $Id: ModulusPhase.cpp,v 1.5 2007-05-04 10:45:09 geuzaine Exp $
+// $Id: ModulusPhase.cpp,v 1.6 2007-09-04 13:47:05 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/Plugin/Remove.cpp b/Plugin/Remove.cpp
index 575ca1b4ca6e689ce6d4eec903ce14e57e47d4d9..f6e5a4f6cb15f1726e6e0dc44b49a9193bd60127 100644
--- a/Plugin/Remove.cpp
+++ b/Plugin/Remove.cpp
@@ -1,4 +1,4 @@
-// $Id: Remove.cpp,v 1.9 2007-05-04 10:45:09 geuzaine Exp $
+// $Id: Remove.cpp,v 1.10 2007-09-04 13:47:05 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/Plugin/Skin.cpp b/Plugin/Skin.cpp
index 92f5c248c464e0296f3e1d01f55b9e8e8725271f..456660c703b50e6354c3082970aaa27b7ce77551 100644
--- a/Plugin/Skin.cpp
+++ b/Plugin/Skin.cpp
@@ -1,4 +1,4 @@
-// $Id: Skin.cpp,v 1.33 2007-05-04 10:45:09 geuzaine Exp $
+// $Id: Skin.cpp,v 1.34 2007-09-04 13:47:05 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/Plugin/Smooth.cpp b/Plugin/Smooth.cpp
index 959447d99a12ea41eaf0c5912816c7b2f334e69d..35f3cb33a2461a02dbf20b0598bf04b364bbe4f6 100644
--- a/Plugin/Smooth.cpp
+++ b/Plugin/Smooth.cpp
@@ -1,4 +1,4 @@
-// $Id: Smooth.cpp,v 1.24 2007-05-04 10:45:09 geuzaine Exp $
+// $Id: Smooth.cpp,v 1.25 2007-09-04 13:47:05 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/Plugin/Triangulate.cpp b/Plugin/Triangulate.cpp
index 811a9b60c382723cb7735a46afb380a5d1894ef6..34fbc2077e55b20bdf65c159c5701bf9a439066b 100644
--- a/Plugin/Triangulate.cpp
+++ b/Plugin/Triangulate.cpp
@@ -1,4 +1,4 @@
-// $Id: Triangulate.cpp,v 1.35 2007-05-04 10:45:09 geuzaine Exp $
+// $Id: Triangulate.cpp,v 1.36 2007-09-04 13:47:05 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/Plugin/Warp.cpp b/Plugin/Warp.cpp
index e378e22a875961413e4df462f251b5684a0d02dd..116d76f7d464246bf17b6cce61b087e998054120 100644
--- a/Plugin/Warp.cpp
+++ b/Plugin/Warp.cpp
@@ -1,4 +1,4 @@
-// $Id: Warp.cpp,v 1.7 2007-05-04 10:45:09 geuzaine Exp $
+// $Id: Warp.cpp,v 1.8 2007-09-04 13:47:05 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/Post/AdaptiveViews.cpp b/Post/AdaptiveViews.cpp
index f39ed4640e2529f8fe055877f7bbe46bc60cccbf..66485fc6b25a667a0aebaab6002fae1687a5515c 100644
--- a/Post/AdaptiveViews.cpp
+++ b/Post/AdaptiveViews.cpp
@@ -1029,6 +1029,9 @@ void Adaptive_Post_View::initWithLowResolution(Post_View * view)
 
   int nbComp = 1;
 
+  //  printf("%d\n",view->NbST);
+
+
   if (view->NbST){
     myList = view->ST;
     nbelm = view->NbST;
@@ -1074,9 +1077,12 @@ void Adaptive_Post_View::initWithLowResolution(Post_View * view)
     {
       nbnod = _coefsGeom -> size1 ();
       //      printf("THERE IS A GEOMETRY !!!!!!!! nbNod = %d\n",nbnod);
+    }  
+  else
+    {
+      printf("coucouc2\n");
     }
 
-
   minval = VAL_INF;
   maxval = -VAL_INF;
 
@@ -1166,6 +1172,9 @@ Adaptive_Post_View::Adaptive_Post_View(Post_View * view,
 
   if (_cGeom && _polGeom)
     {
+
+      printf("coucou %d \n",List_Nbr (_cGeom));
+
       _coefsGeom = new Double_Matrix ( List_Nbr (_cGeom) , List_Nbr (_cGeom)  );
       _eexpsGeom = new Double_Matrix ( List_Nbr (_cGeom) , 3  );
       for(int i = 0; i < List_Nbr(_cGeom); ++i) {
diff --git a/Post/Makefile b/Post/Makefile
index 1085213fb49a068c9ebf76779b70883d25a93448..be937797451c1258e2ceebb8a018caa837e2fbec 100644
--- a/Post/Makefile
+++ b/Post/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.9 2007-09-02 21:05:20 geuzaine Exp $
+# $Id: Makefile,v 1.10 2007-09-04 13:47:05 remacle Exp $
 #
 # Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 #
@@ -63,9 +63,44 @@ depend:
 # DO NOT DELETE THIS LINE
 PView.o: PView.cpp PView.h ../Common/VertexArray.h ../Geo/SVector3.h \
   ../Geo/SPoint3.h ../Common/SmoothData.h ../Numeric/Numeric.h \
-  AdaptiveViews.h ../DataStr/List.h ../Common/GmshMatrix.h PViewData.h \
-  ../Geo/SBoundingBox3d.h ../Geo/SPoint3.h PViewOptions.h ColorTable.h \
-  PViewDataList.h ../Common/Message.h
+  AdaptiveViews.h ../DataStr/List.h ../Common/GmshMatrix.h \
+  /sw/include/gsl/gsl_linalg.h /sw/include/gsl/gsl_mode.h \
+  /sw/include/gsl/gsl_permutation.h /sw/include/gsl/gsl_types.h \
+  /sw/include/gsl/gsl_errno.h /sw/include/gsl/gsl_check_range.h \
+  /sw/include/gsl/gsl_vector.h \
+  /sw/include/gsl/gsl_vector_complex_long_double.h \
+  /sw/include/gsl/gsl_complex.h /sw/include/gsl/gsl_vector_long_double.h \
+  /sw/include/gsl/gsl_block_long_double.h \
+  /sw/include/gsl/gsl_vector_complex.h \
+  /sw/include/gsl/gsl_block_complex_long_double.h \
+  /sw/include/gsl/gsl_vector_complex_double.h \
+  /sw/include/gsl/gsl_vector_double.h /sw/include/gsl/gsl_block_double.h \
+  /sw/include/gsl/gsl_block_complex_double.h \
+  /sw/include/gsl/gsl_vector_complex_float.h \
+  /sw/include/gsl/gsl_vector_float.h /sw/include/gsl/gsl_block_float.h \
+  /sw/include/gsl/gsl_block_complex_float.h \
+  /sw/include/gsl/gsl_vector_ulong.h /sw/include/gsl/gsl_block_ulong.h \
+  /sw/include/gsl/gsl_vector_long.h /sw/include/gsl/gsl_block_long.h \
+  /sw/include/gsl/gsl_vector_uint.h /sw/include/gsl/gsl_block_uint.h \
+  /sw/include/gsl/gsl_vector_int.h /sw/include/gsl/gsl_block_int.h \
+  /sw/include/gsl/gsl_vector_ushort.h /sw/include/gsl/gsl_block_ushort.h \
+  /sw/include/gsl/gsl_vector_short.h /sw/include/gsl/gsl_block_short.h \
+  /sw/include/gsl/gsl_vector_uchar.h /sw/include/gsl/gsl_block_uchar.h \
+  /sw/include/gsl/gsl_vector_char.h /sw/include/gsl/gsl_block_char.h \
+  /sw/include/gsl/gsl_matrix.h \
+  /sw/include/gsl/gsl_matrix_complex_long_double.h \
+  /sw/include/gsl/gsl_matrix_complex_double.h \
+  /sw/include/gsl/gsl_matrix_complex_float.h \
+  /sw/include/gsl/gsl_matrix_long_double.h \
+  /sw/include/gsl/gsl_matrix_double.h /sw/include/gsl/gsl_matrix_float.h \
+  /sw/include/gsl/gsl_matrix_ulong.h /sw/include/gsl/gsl_matrix_long.h \
+  /sw/include/gsl/gsl_matrix_uint.h /sw/include/gsl/gsl_matrix_int.h \
+  /sw/include/gsl/gsl_matrix_ushort.h /sw/include/gsl/gsl_matrix_short.h \
+  /sw/include/gsl/gsl_matrix_uchar.h /sw/include/gsl/gsl_matrix_char.h \
+  /sw/include/gsl/gsl_blas.h /sw/include/gsl/gsl_blas_types.h \
+  /sw/include/gsl/gsl_cblas.h PViewData.h ../Geo/SBoundingBox3d.h \
+  ../Geo/SPoint3.h PViewOptions.h ColorTable.h PViewDataList.h \
+  ../Common/Message.h
 PViewData.o: PViewData.cpp PViewData.h ../Geo/SBoundingBox3d.h \
   ../Geo/SPoint3.h
 PViewDataList.o: PViewDataList.cpp PViewDataList.h PViewData.h \
@@ -90,22 +125,125 @@ PViewDataGModel.o: PViewDataGModel.cpp PViewDataGModel.h PViewData.h \
   ../Geo/Pair.h ../Geo/ExtrudeParams.h ../Geo/GRegion.h ../Geo/GEntity.h \
   ../Geo/MElement.h ../Geo/ExtrudeParams.h ../Geo/SBoundingBox3d.h
 PViewOptions.o: PViewOptions.cpp PViewOptions.h ColorTable.h \
-  ../Geo/SBoundingBox3d.h ../Geo/SPoint3.h ../Common/Message.h
+  ../Geo/SBoundingBox3d.h ../Geo/SPoint3.h ../Common/Message.h \
+  ../contrib/MathEval/matheval.h
 Views.o: Views.cpp ../Common/Gmsh.h ../Common/Message.h \
   ../DataStr/Malloc.h ../DataStr/List.h ../DataStr/Tree.h \
   ../DataStr/avl.h ../DataStr/Tools.h ../DataStr/List.h ../DataStr/Tree.h \
   ../Numeric/Numeric.h Views.h ColorTable.h ../Common/VertexArray.h \
   ../Geo/SVector3.h ../Geo/SPoint3.h ../Common/SmoothData.h \
-  AdaptiveViews.h ../Common/GmshMatrix.h ../Common/Context.h \
-  ../Common/Options.h ../Mesh/BackgroundMesh.h
+  AdaptiveViews.h ../Common/GmshMatrix.h /sw/include/gsl/gsl_linalg.h \
+  /sw/include/gsl/gsl_mode.h /sw/include/gsl/gsl_permutation.h \
+  /sw/include/gsl/gsl_types.h /sw/include/gsl/gsl_errno.h \
+  /sw/include/gsl/gsl_check_range.h /sw/include/gsl/gsl_vector.h \
+  /sw/include/gsl/gsl_vector_complex_long_double.h \
+  /sw/include/gsl/gsl_complex.h /sw/include/gsl/gsl_vector_long_double.h \
+  /sw/include/gsl/gsl_block_long_double.h \
+  /sw/include/gsl/gsl_vector_complex.h \
+  /sw/include/gsl/gsl_block_complex_long_double.h \
+  /sw/include/gsl/gsl_vector_complex_double.h \
+  /sw/include/gsl/gsl_vector_double.h /sw/include/gsl/gsl_block_double.h \
+  /sw/include/gsl/gsl_block_complex_double.h \
+  /sw/include/gsl/gsl_vector_complex_float.h \
+  /sw/include/gsl/gsl_vector_float.h /sw/include/gsl/gsl_block_float.h \
+  /sw/include/gsl/gsl_block_complex_float.h \
+  /sw/include/gsl/gsl_vector_ulong.h /sw/include/gsl/gsl_block_ulong.h \
+  /sw/include/gsl/gsl_vector_long.h /sw/include/gsl/gsl_block_long.h \
+  /sw/include/gsl/gsl_vector_uint.h /sw/include/gsl/gsl_block_uint.h \
+  /sw/include/gsl/gsl_vector_int.h /sw/include/gsl/gsl_block_int.h \
+  /sw/include/gsl/gsl_vector_ushort.h /sw/include/gsl/gsl_block_ushort.h \
+  /sw/include/gsl/gsl_vector_short.h /sw/include/gsl/gsl_block_short.h \
+  /sw/include/gsl/gsl_vector_uchar.h /sw/include/gsl/gsl_block_uchar.h \
+  /sw/include/gsl/gsl_vector_char.h /sw/include/gsl/gsl_block_char.h \
+  /sw/include/gsl/gsl_matrix.h \
+  /sw/include/gsl/gsl_matrix_complex_long_double.h \
+  /sw/include/gsl/gsl_matrix_complex_double.h \
+  /sw/include/gsl/gsl_matrix_complex_float.h \
+  /sw/include/gsl/gsl_matrix_long_double.h \
+  /sw/include/gsl/gsl_matrix_double.h /sw/include/gsl/gsl_matrix_float.h \
+  /sw/include/gsl/gsl_matrix_ulong.h /sw/include/gsl/gsl_matrix_long.h \
+  /sw/include/gsl/gsl_matrix_uint.h /sw/include/gsl/gsl_matrix_int.h \
+  /sw/include/gsl/gsl_matrix_ushort.h /sw/include/gsl/gsl_matrix_short.h \
+  /sw/include/gsl/gsl_matrix_uchar.h /sw/include/gsl/gsl_matrix_char.h \
+  /sw/include/gsl/gsl_blas.h /sw/include/gsl/gsl_blas_types.h \
+  /sw/include/gsl/gsl_cblas.h ../Common/Context.h ../Common/Options.h \
+  ../Mesh/BackgroundMesh.h ../contrib/MathEval/matheval.h
 ViewsIO.o: ViewsIO.cpp ../Common/Gmsh.h ../Common/Message.h \
   ../DataStr/Malloc.h ../DataStr/List.h ../DataStr/Tree.h \
   ../DataStr/avl.h ../DataStr/Tools.h ../DataStr/List.h ../DataStr/Tree.h \
   ../Numeric/Numeric.h Views.h ColorTable.h ../Common/VertexArray.h \
   ../Geo/SVector3.h ../Geo/SPoint3.h ../Common/SmoothData.h \
-  AdaptiveViews.h ../Common/GmshMatrix.h ../Common/Context.h
+  AdaptiveViews.h ../Common/GmshMatrix.h /sw/include/gsl/gsl_linalg.h \
+  /sw/include/gsl/gsl_mode.h /sw/include/gsl/gsl_permutation.h \
+  /sw/include/gsl/gsl_types.h /sw/include/gsl/gsl_errno.h \
+  /sw/include/gsl/gsl_check_range.h /sw/include/gsl/gsl_vector.h \
+  /sw/include/gsl/gsl_vector_complex_long_double.h \
+  /sw/include/gsl/gsl_complex.h /sw/include/gsl/gsl_vector_long_double.h \
+  /sw/include/gsl/gsl_block_long_double.h \
+  /sw/include/gsl/gsl_vector_complex.h \
+  /sw/include/gsl/gsl_block_complex_long_double.h \
+  /sw/include/gsl/gsl_vector_complex_double.h \
+  /sw/include/gsl/gsl_vector_double.h /sw/include/gsl/gsl_block_double.h \
+  /sw/include/gsl/gsl_block_complex_double.h \
+  /sw/include/gsl/gsl_vector_complex_float.h \
+  /sw/include/gsl/gsl_vector_float.h /sw/include/gsl/gsl_block_float.h \
+  /sw/include/gsl/gsl_block_complex_float.h \
+  /sw/include/gsl/gsl_vector_ulong.h /sw/include/gsl/gsl_block_ulong.h \
+  /sw/include/gsl/gsl_vector_long.h /sw/include/gsl/gsl_block_long.h \
+  /sw/include/gsl/gsl_vector_uint.h /sw/include/gsl/gsl_block_uint.h \
+  /sw/include/gsl/gsl_vector_int.h /sw/include/gsl/gsl_block_int.h \
+  /sw/include/gsl/gsl_vector_ushort.h /sw/include/gsl/gsl_block_ushort.h \
+  /sw/include/gsl/gsl_vector_short.h /sw/include/gsl/gsl_block_short.h \
+  /sw/include/gsl/gsl_vector_uchar.h /sw/include/gsl/gsl_block_uchar.h \
+  /sw/include/gsl/gsl_vector_char.h /sw/include/gsl/gsl_block_char.h \
+  /sw/include/gsl/gsl_matrix.h \
+  /sw/include/gsl/gsl_matrix_complex_long_double.h \
+  /sw/include/gsl/gsl_matrix_complex_double.h \
+  /sw/include/gsl/gsl_matrix_complex_float.h \
+  /sw/include/gsl/gsl_matrix_long_double.h \
+  /sw/include/gsl/gsl_matrix_double.h /sw/include/gsl/gsl_matrix_float.h \
+  /sw/include/gsl/gsl_matrix_ulong.h /sw/include/gsl/gsl_matrix_long.h \
+  /sw/include/gsl/gsl_matrix_uint.h /sw/include/gsl/gsl_matrix_int.h \
+  /sw/include/gsl/gsl_matrix_ushort.h /sw/include/gsl/gsl_matrix_short.h \
+  /sw/include/gsl/gsl_matrix_uchar.h /sw/include/gsl/gsl_matrix_char.h \
+  /sw/include/gsl/gsl_blas.h /sw/include/gsl/gsl_blas_types.h \
+  /sw/include/gsl/gsl_cblas.h ../Common/Context.h
 AdaptiveViews.o: AdaptiveViews.cpp AdaptiveViews.h ../DataStr/List.h \
-  ../Common/GmshMatrix.h ../Plugin/Plugin.h ../Common/Options.h \
+  ../Common/GmshMatrix.h /sw/include/gsl/gsl_linalg.h \
+  /sw/include/gsl/gsl_mode.h /sw/include/gsl/gsl_permutation.h \
+  /sw/include/gsl/gsl_types.h /sw/include/gsl/gsl_errno.h \
+  /sw/include/gsl/gsl_check_range.h /sw/include/gsl/gsl_vector.h \
+  /sw/include/gsl/gsl_vector_complex_long_double.h \
+  /sw/include/gsl/gsl_complex.h /sw/include/gsl/gsl_vector_long_double.h \
+  /sw/include/gsl/gsl_block_long_double.h \
+  /sw/include/gsl/gsl_vector_complex.h \
+  /sw/include/gsl/gsl_block_complex_long_double.h \
+  /sw/include/gsl/gsl_vector_complex_double.h \
+  /sw/include/gsl/gsl_vector_double.h /sw/include/gsl/gsl_block_double.h \
+  /sw/include/gsl/gsl_block_complex_double.h \
+  /sw/include/gsl/gsl_vector_complex_float.h \
+  /sw/include/gsl/gsl_vector_float.h /sw/include/gsl/gsl_block_float.h \
+  /sw/include/gsl/gsl_block_complex_float.h \
+  /sw/include/gsl/gsl_vector_ulong.h /sw/include/gsl/gsl_block_ulong.h \
+  /sw/include/gsl/gsl_vector_long.h /sw/include/gsl/gsl_block_long.h \
+  /sw/include/gsl/gsl_vector_uint.h /sw/include/gsl/gsl_block_uint.h \
+  /sw/include/gsl/gsl_vector_int.h /sw/include/gsl/gsl_block_int.h \
+  /sw/include/gsl/gsl_vector_ushort.h /sw/include/gsl/gsl_block_ushort.h \
+  /sw/include/gsl/gsl_vector_short.h /sw/include/gsl/gsl_block_short.h \
+  /sw/include/gsl/gsl_vector_uchar.h /sw/include/gsl/gsl_block_uchar.h \
+  /sw/include/gsl/gsl_vector_char.h /sw/include/gsl/gsl_block_char.h \
+  /sw/include/gsl/gsl_matrix.h \
+  /sw/include/gsl/gsl_matrix_complex_long_double.h \
+  /sw/include/gsl/gsl_matrix_complex_double.h \
+  /sw/include/gsl/gsl_matrix_complex_float.h \
+  /sw/include/gsl/gsl_matrix_long_double.h \
+  /sw/include/gsl/gsl_matrix_double.h /sw/include/gsl/gsl_matrix_float.h \
+  /sw/include/gsl/gsl_matrix_ulong.h /sw/include/gsl/gsl_matrix_long.h \
+  /sw/include/gsl/gsl_matrix_uint.h /sw/include/gsl/gsl_matrix_int.h \
+  /sw/include/gsl/gsl_matrix_ushort.h /sw/include/gsl/gsl_matrix_short.h \
+  /sw/include/gsl/gsl_matrix_uchar.h /sw/include/gsl/gsl_matrix_char.h \
+  /sw/include/gsl/gsl_blas.h /sw/include/gsl/gsl_blas_types.h \
+  /sw/include/gsl/gsl_cblas.h ../Plugin/Plugin.h ../Common/Options.h \
   ../Common/Message.h ../Post/Views.h ../Post/ColorTable.h \
   ../Common/VertexArray.h ../Geo/SVector3.h ../Geo/SPoint3.h \
   ../Common/SmoothData.h ../Numeric/Numeric.h ../Post/AdaptiveViews.h \
@@ -114,7 +252,42 @@ OctreePost.o: OctreePost.cpp ../Common/Octree.h \
   ../Common/OctreeInternals.h OctreePost.h ../DataStr/List.h Views.h \
   ColorTable.h ../Common/VertexArray.h ../Geo/SVector3.h ../Geo/SPoint3.h \
   ../Common/SmoothData.h ../Numeric/Numeric.h AdaptiveViews.h \
-  ../Common/GmshMatrix.h ../Common/Message.h ../Common/ShapeFunctions.h
+  ../Common/GmshMatrix.h /sw/include/gsl/gsl_linalg.h \
+  /sw/include/gsl/gsl_mode.h /sw/include/gsl/gsl_permutation.h \
+  /sw/include/gsl/gsl_types.h /sw/include/gsl/gsl_errno.h \
+  /sw/include/gsl/gsl_check_range.h /sw/include/gsl/gsl_vector.h \
+  /sw/include/gsl/gsl_vector_complex_long_double.h \
+  /sw/include/gsl/gsl_complex.h /sw/include/gsl/gsl_vector_long_double.h \
+  /sw/include/gsl/gsl_block_long_double.h \
+  /sw/include/gsl/gsl_vector_complex.h \
+  /sw/include/gsl/gsl_block_complex_long_double.h \
+  /sw/include/gsl/gsl_vector_complex_double.h \
+  /sw/include/gsl/gsl_vector_double.h /sw/include/gsl/gsl_block_double.h \
+  /sw/include/gsl/gsl_block_complex_double.h \
+  /sw/include/gsl/gsl_vector_complex_float.h \
+  /sw/include/gsl/gsl_vector_float.h /sw/include/gsl/gsl_block_float.h \
+  /sw/include/gsl/gsl_block_complex_float.h \
+  /sw/include/gsl/gsl_vector_ulong.h /sw/include/gsl/gsl_block_ulong.h \
+  /sw/include/gsl/gsl_vector_long.h /sw/include/gsl/gsl_block_long.h \
+  /sw/include/gsl/gsl_vector_uint.h /sw/include/gsl/gsl_block_uint.h \
+  /sw/include/gsl/gsl_vector_int.h /sw/include/gsl/gsl_block_int.h \
+  /sw/include/gsl/gsl_vector_ushort.h /sw/include/gsl/gsl_block_ushort.h \
+  /sw/include/gsl/gsl_vector_short.h /sw/include/gsl/gsl_block_short.h \
+  /sw/include/gsl/gsl_vector_uchar.h /sw/include/gsl/gsl_block_uchar.h \
+  /sw/include/gsl/gsl_vector_char.h /sw/include/gsl/gsl_block_char.h \
+  /sw/include/gsl/gsl_matrix.h \
+  /sw/include/gsl/gsl_matrix_complex_long_double.h \
+  /sw/include/gsl/gsl_matrix_complex_double.h \
+  /sw/include/gsl/gsl_matrix_complex_float.h \
+  /sw/include/gsl/gsl_matrix_long_double.h \
+  /sw/include/gsl/gsl_matrix_double.h /sw/include/gsl/gsl_matrix_float.h \
+  /sw/include/gsl/gsl_matrix_ulong.h /sw/include/gsl/gsl_matrix_long.h \
+  /sw/include/gsl/gsl_matrix_uint.h /sw/include/gsl/gsl_matrix_int.h \
+  /sw/include/gsl/gsl_matrix_ushort.h /sw/include/gsl/gsl_matrix_short.h \
+  /sw/include/gsl/gsl_matrix_uchar.h /sw/include/gsl/gsl_matrix_char.h \
+  /sw/include/gsl/gsl_blas.h /sw/include/gsl/gsl_blas_types.h \
+  /sw/include/gsl/gsl_cblas.h ../Common/Message.h \
+  ../Common/ShapeFunctions.h
 ColorTable.o: ColorTable.cpp ../Common/Gmsh.h ../Common/Message.h \
   ../DataStr/Malloc.h ../DataStr/List.h ../DataStr/Tree.h \
   ../DataStr/avl.h ../DataStr/Tools.h ../DataStr/List.h ../DataStr/Tree.h \
diff --git a/benchmarks/2d/Square-01.geo b/benchmarks/2d/Square-01.geo
index 72c04246dbca630c5e0c642ebd48b6dabad34709..744b75780fe70211a7a4481d62ae68002207124b 100644
--- a/benchmarks/2d/Square-01.geo
+++ b/benchmarks/2d/Square-01.geo
@@ -1,7 +1,7 @@
 /******************************      
 Square uniformly meshed      
 ******************************/      
-lc = .3;       
+lc = .1;       
 Point(1) = {0.0,0.0,0,lc};       
 Point(2) = {1,0.0,0,lc};       
 Point(3) = {1,1,0,lc};       
diff --git a/benchmarks/2d/naca12_2d.geo b/benchmarks/2d/naca12_2d.geo
index b754796ced51b6d0dcf60c9806078e29331f4706..34085f830aecc63632bdf774f740a9796a6af034 100644
--- a/benchmarks/2d/naca12_2d.geo
+++ b/benchmarks/2d/naca12_2d.geo
@@ -1,6 +1,6 @@
 lc = 0.2;
-lc2 = 0.2;
-lc3 = 0.05;
+lc2 = 1;
+lc3 = 0.2;
 Point(1) =  {1.000000e+00,0.000000e+00,0.000000e+00,lc}; 
 Point(2) =  {9.997533e-01,0.000000e+00,-3.498543e-05,lc}; 
 Point(3) =  {9.990134e-01,0.000000e+00,-1.398841e-04,lc}; 
@@ -223,6 +223,9 @@ Line Loop(9) = {6,7,8,5};
 Line Loop(10) = {2,3,4,1};
 Plane Surface(11) = {9,10};
 
-//Attractor Point{101,200} = {0.04,0.04,2};
+Point(9999) = {0.6,0,0,1};
+
+Attractor Point{9999} = {0.2,0.02,lc3*10,2};
+
 //Attractor Line{1,2,3,4} = {1,.05,3};
-Mesh.Algorithm = 2;
+//Mesh.Algorithm = 2;
diff --git a/benchmarks/2d/wing-splines.geo b/benchmarks/2d/wing-splines.geo
index 02492d17efc6730aa446a76043b5014bf2c46a2c..1f2c8da7d420e81f45b6980ffed8c93c08e2c8ea 100644
--- a/benchmarks/2d/wing-splines.geo
+++ b/benchmarks/2d/wing-splines.geo
@@ -1,6 +1,6 @@
 scale = 1 ;
 
-lc_wing = 0.04 * scale ;
+lc_wing = 0.1 * scale ;
 lc_box = 10 * scale ;
 
 Point(3895) = {1.177410e-02*scale,-2.768003e-03*scale,0,lc_wing};
@@ -592,7 +592,7 @@ Spline(12) = {4221,4251,4299,4335,4337,4267,4294,4269,4233,4234,
 	      4348,4349,4332,4333,4334,4278,4247,4248,4249,4282,
 	      4283,4341,4342,4343,4289,4290,4286,4255,4257,4256,
 	      4346,4288,4287,4260,4259,4258,4262,4261,4264,4264,
-	      4263,4265,4266,4303,4302,4304,4305,4306,4307,4308,
+	      4263,4265,4266,4302,4304,4305,4306,4307,4308,
 	      4309,4345,4344,4254,4253,4285,4284,4340,4339,4338,
 	      4246,4245,4281,4280,4279,4244,4243,4242,4296,4295,
 	      4300,4330,4331,4329,4232,4231,4230,4229,4228,4227,
diff --git a/contrib/Metis/balance.c b/contrib/Metis/balance.c
index 2e9bd5fbbbc2561163d633478ce706aeb327682b..60f61d0faba1a47026222990c0b83bf6a1d48530 100644
--- a/contrib/Metis/balance.c
+++ b/contrib/Metis/balance.c
@@ -9,7 +9,7 @@
  * Started 7/29/97
  * George
  *
- * $Id: balance.c,v 1.1 2005-09-21 17:29:37 geuzaine Exp $
+ * $Id: balance.c,v 1.2 2007-09-04 13:47:06 remacle Exp $
  *
  */
 
diff --git a/contrib/Metis/bucketsort.c b/contrib/Metis/bucketsort.c
index 316d212179e6f7f2499a1e9d198860585980721f..05c21f0f2821be6556e31e88c8c413a558618764 100644
--- a/contrib/Metis/bucketsort.c
+++ b/contrib/Metis/bucketsort.c
@@ -9,7 +9,7 @@
  * Started 7/25/97
  * George
  *
- * $Id: bucketsort.c,v 1.1 2005-09-21 17:29:37 geuzaine Exp $
+ * $Id: bucketsort.c,v 1.2 2007-09-04 13:47:06 remacle Exp $
  *
  */
 
diff --git a/contrib/Metis/ccgraph.c b/contrib/Metis/ccgraph.c
index 549b4267f6e60e9c70a5655a7646b30c3023f667..c8dced53344c78424fbd7424e8e685776f81a9f7 100644
--- a/contrib/Metis/ccgraph.c
+++ b/contrib/Metis/ccgraph.c
@@ -8,7 +8,7 @@
  * Started 8/11/97
  * George
  *
- * $Id: ccgraph.c,v 1.1 2005-09-21 17:29:37 geuzaine Exp $
+ * $Id: ccgraph.c,v 1.2 2007-09-04 13:47:06 remacle Exp $
  *
  */
 
diff --git a/contrib/Metis/coarsen.c b/contrib/Metis/coarsen.c
index 40c25df00e68583e20a47c4402f5a8dcc4e2cbef..456938b2983fe7481fa3f569d2ef662385de1ad6 100644
--- a/contrib/Metis/coarsen.c
+++ b/contrib/Metis/coarsen.c
@@ -6,7 +6,7 @@
  * Started 7/23/97
  * George
  *
- * $Id: coarsen.c,v 1.1 2005-09-21 17:29:37 geuzaine Exp $
+ * $Id: coarsen.c,v 1.2 2007-09-04 13:47:06 remacle Exp $
  *
  */
 
diff --git a/contrib/Metis/compress.c b/contrib/Metis/compress.c
index 9798919a6af06e5d8440edc8270ae1d9d0805a7b..fc2aa8c88d8ab93058396c232827e0bb6a4c9a06 100644
--- a/contrib/Metis/compress.c
+++ b/contrib/Metis/compress.c
@@ -9,7 +9,7 @@
  * Started 9/17/97
  * George
  *
- * $Id: compress.c,v 1.1 2005-09-21 17:29:37 geuzaine Exp $
+ * $Id: compress.c,v 1.2 2007-09-04 13:47:06 remacle Exp $
  */
 
 #include <metis.h>
diff --git a/contrib/Metis/debug.c b/contrib/Metis/debug.c
index 3a30fe9d78cee77b2a47e52e4cf5590dda5f6e2f..43b3e10f97abdf4c040eb68a96ecab1a160cd5de 100644
--- a/contrib/Metis/debug.c
+++ b/contrib/Metis/debug.c
@@ -8,7 +8,7 @@
  * Started 7/24/97
  * George
  *
- * $Id: debug.c,v 1.1 2005-09-21 17:29:37 geuzaine Exp $
+ * $Id: debug.c,v 1.2 2007-09-04 13:47:06 remacle Exp $
  *
  */
 
diff --git a/contrib/Metis/defs.h b/contrib/Metis/defs.h
index 472e2db06a77764169512cc07acd3024cfa112fd..9f69eae825a0569e90fc1e2e4af44bb684d7c042 100644
--- a/contrib/Metis/defs.h
+++ b/contrib/Metis/defs.h
@@ -8,7 +8,7 @@
  * Started 8/27/94
  * George
  *
- * $Id: defs.h,v 1.1 2005-09-21 17:29:37 geuzaine Exp $
+ * $Id: defs.h,v 1.2 2007-09-04 13:47:06 remacle Exp $
  *
  */
 
diff --git a/contrib/Metis/estmem.c b/contrib/Metis/estmem.c
index 852d5ac5e049d920ffbbaf177e5cb4f81259451c..052172ca97afc70cd434fc3a0a1b537659650d1c 100644
--- a/contrib/Metis/estmem.c
+++ b/contrib/Metis/estmem.c
@@ -9,7 +9,7 @@
  * Started 11/4/97
  * George
  *
- * $Id: estmem.c,v 1.1 2005-09-21 17:29:37 geuzaine Exp $
+ * $Id: estmem.c,v 1.2 2007-09-04 13:47:06 remacle Exp $
  *
  */
 
diff --git a/contrib/Metis/fm.c b/contrib/Metis/fm.c
index 79cd74fa1ae49b70cc2d4f7110a464db8f5f1977..d9bf6ae40b156fc313a64f09e5582f05a36f75b2 100644
--- a/contrib/Metis/fm.c
+++ b/contrib/Metis/fm.c
@@ -8,7 +8,7 @@
  * Started 7/23/97
  * George
  *
- * $Id: fm.c,v 1.1 2005-09-21 17:29:37 geuzaine Exp $
+ * $Id: fm.c,v 1.2 2007-09-04 13:47:06 remacle Exp $
  */
 
 #include <metis.h>
diff --git a/contrib/Metis/fortran.c b/contrib/Metis/fortran.c
index a89c65408a03d5f5eaa47de7e6382a1888a2aade..11a1a6be966ddf269c0c53f578aa4b70f7fe6115 100644
--- a/contrib/Metis/fortran.c
+++ b/contrib/Metis/fortran.c
@@ -8,7 +8,7 @@
  * Started 8/19/97
  * George
  *
- * $Id: fortran.c,v 1.1 2005-09-21 17:29:37 geuzaine Exp $
+ * $Id: fortran.c,v 1.2 2007-09-04 13:47:06 remacle Exp $
  *
  */
 
diff --git a/contrib/Metis/frename.c b/contrib/Metis/frename.c
index 0ec34403a0e0f07396ba3f6ac845415e5755af7c..75d73f6366c9e3e73e665202cd5d483eb6d0a569 100644
--- a/contrib/Metis/frename.c
+++ b/contrib/Metis/frename.c
@@ -8,7 +8,7 @@
  * Started 9/15/97
  * George
  *
- * $Id: frename.c,v 1.1 2005-09-21 17:29:37 geuzaine Exp $
+ * $Id: frename.c,v 1.2 2007-09-04 13:47:06 remacle Exp $
  *
  */
 
diff --git a/contrib/Metis/graph.c b/contrib/Metis/graph.c
index 351ce4578c3c8e8f2befdc359f2c042e7f62ab27..9716726c71e48ae1376409b6e8247508c75b5921 100644
--- a/contrib/Metis/graph.c
+++ b/contrib/Metis/graph.c
@@ -9,7 +9,7 @@
  * Started 7/25/97
  * George
  *
- * $Id: graph.c,v 1.1 2005-09-21 17:29:37 geuzaine Exp $
+ * $Id: graph.c,v 1.2 2007-09-04 13:47:06 remacle Exp $
  *
  */
 
diff --git a/contrib/Metis/initpart.c b/contrib/Metis/initpart.c
index 72c5b7be07860ad00a802f425ce01a97fa7109ac..36f645df24b095e0b181f064ee6495138d0e3532 100644
--- a/contrib/Metis/initpart.c
+++ b/contrib/Metis/initpart.c
@@ -9,7 +9,7 @@
  * Started 7/23/97
  * George
  *
- * $Id: initpart.c,v 1.1 2005-09-21 17:29:37 geuzaine Exp $
+ * $Id: initpart.c,v 1.2 2007-09-04 13:47:06 remacle Exp $
  *
  */
 
diff --git a/contrib/Metis/kmetis.c b/contrib/Metis/kmetis.c
index ab702154d60cb1f7503c813fac4b1c77bf6feec4..a4e8dfe106ddc25ab49ad88291bc403767e19ad4 100644
--- a/contrib/Metis/kmetis.c
+++ b/contrib/Metis/kmetis.c
@@ -9,7 +9,7 @@
  * Started 7/28/97
  * George
  *
- * $Id: kmetis.c,v 1.2 2005-09-26 18:11:23 geuzaine Exp $
+ * $Id: kmetis.c,v 1.3 2007-09-04 13:47:06 remacle Exp $
  *
  */
 
diff --git a/contrib/Metis/kvmetis.c b/contrib/Metis/kvmetis.c
index cb077a286a8a902b7fd3a8ca462eb1dd346d2613..8b7ff8b4c9020ec842ea374b23289a27b6c87d83 100644
--- a/contrib/Metis/kvmetis.c
+++ b/contrib/Metis/kvmetis.c
@@ -9,7 +9,7 @@
  * Started 7/28/97
  * George
  *
- * $Id: kvmetis.c,v 1.2 2005-09-26 18:11:23 geuzaine Exp $
+ * $Id: kvmetis.c,v 1.3 2007-09-04 13:47:06 remacle Exp $
  *
  */
 
diff --git a/contrib/Metis/kwayfm.c b/contrib/Metis/kwayfm.c
index 57726049483c3e2fd06f41a6bd6611a20387bcd5..d48b47eb1fd5e5b6cc468f698cbb70667b54d1b9 100644
--- a/contrib/Metis/kwayfm.c
+++ b/contrib/Metis/kwayfm.c
@@ -6,7 +6,7 @@
  * Started 7/28/97
  * George
  *
- * $Id: kwayfm.c,v 1.1 2005-09-21 17:29:37 geuzaine Exp $
+ * $Id: kwayfm.c,v 1.2 2007-09-04 13:47:06 remacle Exp $
  *
  */
 
diff --git a/contrib/Metis/kwayrefine.c b/contrib/Metis/kwayrefine.c
index 2783e6cad4f3b2f0a4b0bfd25330c1e8bc655ca1..10b47f4867728bf940abae10345b1510d816d05c 100644
--- a/contrib/Metis/kwayrefine.c
+++ b/contrib/Metis/kwayrefine.c
@@ -8,7 +8,7 @@
  * Started 7/28/97
  * George
  *
- * $Id: kwayrefine.c,v 1.1 2005-09-21 17:29:37 geuzaine Exp $
+ * $Id: kwayrefine.c,v 1.2 2007-09-04 13:47:06 remacle Exp $
  */
 
 #include <metis.h>
diff --git a/contrib/Metis/kwayvolfm.c b/contrib/Metis/kwayvolfm.c
index 3271571ff1f0357d5159b9ae221484f7982f685d..be13fda184350075ca132e1bcca8b4e68674237c 100644
--- a/contrib/Metis/kwayvolfm.c
+++ b/contrib/Metis/kwayvolfm.c
@@ -6,7 +6,7 @@
  * Started 7/8/98
  * George
  *
- * $Id: kwayvolfm.c,v 1.1 2005-09-21 17:29:37 geuzaine Exp $
+ * $Id: kwayvolfm.c,v 1.2 2007-09-04 13:47:06 remacle Exp $
  *
  */
 
diff --git a/contrib/Metis/kwayvolrefine.c b/contrib/Metis/kwayvolrefine.c
index 4677b6bd1731aaf3a23d4a418336004dc1cbcfdd..65395f50de57047171ec5ea68a3c51befcb6f369 100644
--- a/contrib/Metis/kwayvolrefine.c
+++ b/contrib/Metis/kwayvolrefine.c
@@ -8,7 +8,7 @@
  * Started 7/28/97
  * George
  *
- * $Id: kwayvolrefine.c,v 1.1 2005-09-21 17:29:37 geuzaine Exp $
+ * $Id: kwayvolrefine.c,v 1.2 2007-09-04 13:47:06 remacle Exp $
  */
 
 #include <metis.h>
diff --git a/contrib/Metis/mkmetis.c b/contrib/Metis/mkmetis.c
index 3fdfefe89761051e8777e2a2cb5a367d407c7e50..05636749574cba007f75a5b1cc0ec5f099ee5dd2 100644
--- a/contrib/Metis/mkmetis.c
+++ b/contrib/Metis/mkmetis.c
@@ -9,7 +9,7 @@
  * Started 7/28/97
  * George
  *
- * $Id: mkmetis.c,v 1.2 2005-09-26 18:11:23 geuzaine Exp $
+ * $Id: mkmetis.c,v 1.3 2007-09-04 13:47:06 remacle Exp $
  *
  */
 
diff --git a/contrib/Metis/proto.h b/contrib/Metis/proto.h
index 1b7d7e0e16a11849c4747dfaa5e50cc9b9a2fd47..be7ffb7f622efe39cf55c1d851fb893a3454eb98 100644
--- a/contrib/Metis/proto.h
+++ b/contrib/Metis/proto.h
@@ -8,7 +8,7 @@
  * Started 10/19/95
  * George
  *
- * $Id: proto.h,v 1.2 2005-09-26 18:11:23 geuzaine Exp $
+ * $Id: proto.h,v 1.3 2007-09-04 13:47:06 remacle Exp $
  *
  */
 
diff --git a/contrib/Metis/rename.h b/contrib/Metis/rename.h
index b47b180444a50990817b0c238431805f5e583473..3bce5eab77489ed5bb82baaf89bf9ab42a6be1f2 100644
--- a/contrib/Metis/rename.h
+++ b/contrib/Metis/rename.h
@@ -8,7 +8,7 @@
  * Started 10/2/97
  * George
  *
- * $Id: rename.h,v 1.2 2005-09-26 18:11:23 geuzaine Exp $
+ * $Id: rename.h,v 1.3 2007-09-04 13:47:06 remacle Exp $
  *
  */
 
diff --git a/doc/Makefile b/doc/Makefile
index d2580ce5d38ed59b51799d99408dfba9e89b441f..a5a1ee9dc4324eac5a9ed4b70dc51a958ebc515a 100644
--- a/doc/Makefile
+++ b/doc/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.15 2006-11-27 22:22:33 geuzaine Exp $
+# $Id: Makefile,v 1.16 2007-09-04 13:47:06 remacle Exp $
 #
 # Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 #
diff --git a/doc/VERSIONS b/doc/VERSIONS
index 694749957d54372a7e9774812fed300c74d7f7df..1e7c74e9dd07ed1d138e323f321490e31060c24f 100644
--- a/doc/VERSIONS
+++ b/doc/VERSIONS
@@ -1,5 +1,4 @@
-$Id: VERSIONS,v 1.389 2007-07-31 20:07:39 geuzaine Exp $
-
+$Id: VERSIONS,v 1.390 2007-09-04 13:47:06 remacle Exp $
 2.0.9 (XX): temp fix for 'could not find extruded vertex' bug;
 
 2.0.8 (Jul 13, 2007): unused vertices are not saved in mesh files
diff --git a/doc/gmsh.1 b/doc/gmsh.1
index bdfe0c011b5c5dbc1c8fe286c4b620ae30dc097a..16bda94d3588d132673902910e434a4e746afda9 100644
--- a/doc/gmsh.1
+++ b/doc/gmsh.1
@@ -1,4 +1,4 @@
-.\" $Id: gmsh.1,v 1.80 2007-03-23 08:44:41 geuzaine Exp $
+.\" $Id: gmsh.1,v 1.81 2007-09-04 13:47:06 remacle Exp $
 .TH Gmsh 1 "09 March 2006" "Gmsh 2.0" "Gmsh Manual Pages"
 .UC 4
 .\" ********************************************************************
diff --git a/doc/texinfo/Makefile b/doc/texinfo/Makefile
index db0161b8abb6b5538aee41f8e4c650a5bed8de5d..64be229ad39c024ee969cf8387945935e176fec1 100644
--- a/doc/texinfo/Makefile
+++ b/doc/texinfo/Makefile
@@ -1,4 +1,8 @@
-# $Id: Makefile,v 1.14 2007-07-13 14:32:09 geuzaine Exp $
+<<<<<<< Makefile
+# $Id: Makefile,v 1.15 2007-09-04 13:47:07 remacle Exp $
+=======
+# $Id: Makefile,v 1.15 2007-09-04 13:47:07 remacle Exp $
+>>>>>>> 1.14
 #
 # Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 #
diff --git a/lib/Makefile b/lib/Makefile
index a4911b07a7d8ed3168d57222a8cea3a3aa3f3608..38725871139f358cf14b50eda5c9f5b471e68974 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.10 2006-11-27 22:22:34 geuzaine Exp $
+# $Id: Makefile,v 1.11 2007-09-04 13:47:07 remacle Exp $
 #
 # Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 #
diff --git a/utils/commercial/License.cpp b/utils/commercial/License.cpp
index fa45897e18c7351f11f3949ed5d16ec49dd3cde1..7dbc6d213e330fbf5740b30649790cdaa2eb95e8 100644
--- a/utils/commercial/License.cpp
+++ b/utils/commercial/License.cpp
@@ -1,4 +1,4 @@
-// $Id: License.cpp,v 1.8 2006-11-27 22:22:34 geuzaine Exp $
+// $Id: License.cpp,v 1.9 2007-09-04 13:47:07 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/utils/converters/autocad/dxf2pos.c b/utils/converters/autocad/dxf2pos.c
index b10a03be9f47236f051cbe2e6bff992f33772659..5af66d2f01806f6d33aacdfa5d9690131fef36f0 100644
--- a/utils/converters/autocad/dxf2pos.c
+++ b/utils/converters/autocad/dxf2pos.c
@@ -1,4 +1,4 @@
-/* $Id: dxf2pos.c,v 1.1 2003-05-09 21:58:55 geuzaine Exp $ */
+/* $Id: dxf2pos.c,v 1.2 2007-09-04 13:47:07 remacle Exp $ */
 
 /* 
    AutoCAD DXF to GMSH .pos Data File Converter
diff --git a/utils/misc/Makefile b/utils/misc/Makefile
index e7e5a60f31251d46ee0cd4f58e10884b0ed038e8..b5db970a6789c3361d91eb554826155ba866a60d 100644
--- a/utils/misc/Makefile
+++ b/utils/misc/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.4 2006-11-27 22:22:34 geuzaine Exp $
+# $Id: Makefile,v 1.5 2007-09-04 13:47:07 remacle Exp $
 #
 # Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 #
diff --git a/utils/misc/mshsort.cpp b/utils/misc/mshsort.cpp
index c90453f3fea5ac405b0523ff11cf614fe1c49348..81312780f8bb7df6fbefaa9e4d6fbbedbe47c0cf 100644
--- a/utils/misc/mshsort.cpp
+++ b/utils/misc/mshsort.cpp
@@ -1,4 +1,4 @@
-// $Id: mshsort.cpp,v 1.9 2006-11-27 22:22:34 geuzaine Exp $
+// $Id: mshsort.cpp,v 1.10 2007-09-04 13:47:07 remacle Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
diff --git a/utils/solvers/c++/solver.cpp b/utils/solvers/c++/solver.cpp
index e58952d647e821f7a519553c01c854b1f4caf265..81fa46fb03301f2adcd977f04aed30191412f195 100644
--- a/utils/solvers/c++/solver.cpp
+++ b/utils/solvers/c++/solver.cpp
@@ -1,4 +1,4 @@
-// $Id: solver.cpp,v 1.9 2006-02-25 14:36:53 geuzaine Exp $
+// $Id: solver.cpp,v 1.10 2007-09-04 13:47:08 remacle Exp $
 //
 // Copyright (C) 1997-2005 C. Geuzaine, J.-F. Remacle
 //
diff --git a/utils/solvers/c/GmshClient.c b/utils/solvers/c/GmshClient.c
index 2fc1df385271b2b0bad021d99a15c01008020ceb..e3f46b84739330fb3698cbbbe9a2574e3a230692 100644
--- a/utils/solvers/c/GmshClient.c
+++ b/utils/solvers/c/GmshClient.c
@@ -1,4 +1,4 @@
-/* $Id: GmshClient.c,v 1.7 2006-11-27 22:22:34 geuzaine Exp $ */
+/* $Id: GmshClient.c,v 1.8 2007-09-04 13:47:07 remacle Exp $ */
 /*
  * Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
  *
diff --git a/utils/solvers/perl/GMSH_CLIENT.pm b/utils/solvers/perl/GMSH_CLIENT.pm
index 2be3fb613d7f302e83232cecab3e0b68eb3ba3b7..dcd2a2cb18991054d0cac80554399e524440cfd2 100755
--- a/utils/solvers/perl/GMSH_CLIENT.pm
+++ b/utils/solvers/perl/GMSH_CLIENT.pm
@@ -1,4 +1,4 @@
-# $Id: GMSH_CLIENT.pm,v 1.3 2006-02-23 21:59:09 geuzaine Exp $
+# $Id: GMSH_CLIENT.pm,v 1.4 2007-09-04 13:47:08 remacle Exp $
 #
 # Copyright (c) 2002 Laurent CHAMPANEY <laurent.champaney@meca.uvsq.fr>. 
 # All rights reserved.
diff --git a/utils/solvers/perl/solver.pl b/utils/solvers/perl/solver.pl
index afcdc39cc1710ab0245306c939e6ad3a340c6420..3e139c4ea2610ea5de78c926cc073297fd168a51 100755
--- a/utils/solvers/perl/solver.pl
+++ b/utils/solvers/perl/solver.pl
@@ -1,6 +1,6 @@
 #!/usr/bin/perl
 #
-# $Id: solver.pl,v 1.3 2006-02-23 21:59:09 geuzaine Exp $
+# $Id: solver.pl,v 1.4 2007-09-04 13:47:08 remacle Exp $
 #
 # Copyright (c) 2002 Laurent CHAMPANEY <laurent.champaney@meca.uvsq.fr>. 
 #
diff --git a/variables.in b/variables.in
index c24a5af6b85662403c1f80c64ce0504e72f4206b..b3dc53e4a26fab5be9c552775a6a14b29bde1eac 100644
--- a/variables.in
+++ b/variables.in
@@ -1,4 +1,4 @@
-# $Id: variables.in,v 1.15 2007-02-01 15:46:40 geuzaine Exp $
+# $Id: variables.in,v 1.16 2007-09-04 13:47:00 remacle Exp $
 #
 # Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 #