Index: /issm/trunk-jpl/src/m/mesh/planet/gmsh/gmshplanet.m
===================================================================
--- /issm/trunk-jpl/src/m/mesh/planet/gmsh/gmshplanet.m	(revision 26353)
+++ /issm/trunk-jpl/src/m/mesh/planet/gmsh/gmshplanet.m	(revision 26354)
@@ -39,10 +39,13 @@
 	fid=fopen('sphere.geo','w');
 
-	fprintf(fid,'Mesh.Algorithm = 1;\n');
+	fprintf(fid,'Mesh.Algorithm = 1;\n'); % MeshAdapt
+	fprintf(fid,'Mesh.RandomFactor = 1e-10;\n');
 	if  exist(options,'refine'),
-		fprintf(fid,'Mesh.Algorithm = 7;\n');
-		fprintf(fid,'Mesh.CharacteristicLengthFromPoints= 0;\n');
-		fprintf(fid,'Mesh.SmoothRatio= 3;\n');
-		fprintf(fid,'Mesh.RemeshAlgorithm= 1;\n');
+		fprintf(fid,'Mesh.Algorithm = 7;\n'); % BAMG
+		fprintf(fid,'Mesh.CharacteristicLengthFromPoints = 0;\n');
+		fprintf(fid,'Mesh.SmoothRatio = 3;\n');
+		if gmshmajorversion == 3,
+			fprintf(fid,'Mesh.RemeshAlgorithm = 1;\n');
+		end
 	end
 	fprintf(fid,'resolution=%g;\n',resolution);
Index: /issm/trunk-jpl/src/m/mesh/planet/gmsh/gmshplanet.py
===================================================================
--- /issm/trunk-jpl/src/m/mesh/planet/gmsh/gmshplanet.py	(revision 26353)
+++ /issm/trunk-jpl/src/m/mesh/planet/gmsh/gmshplanet.py	(revision 26354)
@@ -25,12 +25,12 @@
 
     # Get Gmsh version
-    subproc_args = "gmsh -info 2>&1 | command grep 'Version' | sed -e 's/Version[[:blank:]]*:[[:blank:]]//' | cut -d '.' -f1"
+    subproc_args = 'gmsh -info 2>&1 | command grep \'Version\' | sed -e \'s/Version[[:blank:]]*:[[:blank:]]//\' | cut -d \'.\' -f1'
     subproc = subprocess.Popen(subproc_args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     outs, errs = subproc.communicate()
     if errs != '':
-        raise Exception("gmshplanet: call to gmsh failed: {}".format(errs))
+        raise Exception('gmshplanet: call to gmsh failed: {}'.format(errs))
     gmshmajorversion = int(outs)
     if gmshmajorversion not in [3, 4]:
-        raise RuntimeError("gmshplanet: Gmsh major version {} not supported!".format(gmshmajorversion))
+        raise RuntimeError('gmshplanet: Gmsh major version {} not supported!'.format(gmshmajorversion))
 
     # Process options
@@ -47,10 +47,12 @@
     fid = open('sphere.geo', 'w')
 
-    fid.write('Mesh.Algorithm = 1;\n')
+    fid.write('Mesh.Algorithm = 1;\n') # MeshAdapt
+    fid.write('Mesh.RandomFactor = 1e-10;\n')
     if options.exist('refine'):
-        fid.write('Mesh.Algorithm = 7;\n')
+        fid.write('Mesh.Algorithm = 7;\n') # BAMG
         fid.write('Mesh.CharacteristicLengthFromPoints = 0;\n')
         fid.write('Mesh.SmoothRatio = 3;\n')
-        fid.write('Mesh.RemeshAlgorithm = 1;\n')
+        if gmshmajorversion == 3:
+            fid.write('Mesh.RemeshAlgorithm = 1;\n')
     fid.write('resolution = %g;\n' % resolution)
     fid.write('radius = %g;\n' % radius)
