From 805d20054bf935d13c70ee7df4d1fd090f28d74f Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Sun, 29 Jan 2006 20:32:48 +0000
Subject: [PATCH] better export mesh as post-pro view

---
 Common/ViewsIO.cpp |   4 +-
 Mesh/3D_BGMesh.cpp |  52 ++++++++------
 Mesh/Element.cpp   | 175 ++++++++++++---------------------------------
 Mesh/Element.h     |   4 ++
 Mesh/Mesh.h        |   2 +-
 Mesh/Simplex.cpp   |  74 ++-----------------
 6 files changed, 87 insertions(+), 224 deletions(-)

diff --git a/Common/ViewsIO.cpp b/Common/ViewsIO.cpp
index 94920b2d33..0f68dc940f 100644
--- a/Common/ViewsIO.cpp
+++ b/Common/ViewsIO.cpp
@@ -1,4 +1,4 @@
-// $Id: ViewsIO.cpp,v 1.3 2006-01-28 03:23:15 geuzaine Exp $
+// $Id: ViewsIO.cpp,v 1.4 2006-01-29 20:32:48 geuzaine Exp $
 //
 // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle
 //
@@ -664,7 +664,7 @@ static void print_elm(FILE *file, int num, int nbnod, Nod nod[8],
   d /= (double)nbnod;
 
   // assign val as elementary region number
-  int ele = (int)fabs(d) + 1, phys = 1;
+  int ele = (int)fabs(d), phys = 1;
 
   switch(dim){
   case 0:
diff --git a/Mesh/3D_BGMesh.cpp b/Mesh/3D_BGMesh.cpp
index b68a98a4fa..4700c844f2 100644
--- a/Mesh/3D_BGMesh.cpp
+++ b/Mesh/3D_BGMesh.cpp
@@ -1,4 +1,4 @@
-// $Id: 3D_BGMesh.cpp,v 1.43 2006-01-28 22:57:19 geuzaine Exp $
+// $Id: 3D_BGMesh.cpp,v 1.44 2006-01-29 20:32:48 geuzaine Exp $
 //
 // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle
 //
@@ -103,21 +103,9 @@ void ExportStatistics(void *a, void *b)
   if(statfile) ele->ExportStatistics(statfile);
 }
 
-void ExportMeshStatistics(Mesh * M, char *filename, int volume, int surface)
+void ExportMeshStatistics(Mesh * M, char *filename, 
+			  int volumes, int surfaces, int lines)
 {
-  if(!Tree_Nbr(M->Volumes) && !Tree_Nbr(M->Surfaces)){
-    Msg(GERROR, "No volumes or surfaces to save");
-    return;
-  }
-  else if(volume && !surface && !Tree_Nbr(M->Volumes)){
-    Msg(GERROR, "No volumes to save");
-    return;
-  }
-  else if(!volume && surface && !Tree_Nbr(M->Surfaces)){
-    Msg(GERROR, "No surfaces to save");
-    return;
-  }
-
   statfile = fopen(filename, "w");
 
   if(!statfile) {
@@ -125,11 +113,12 @@ void ExportMeshStatistics(Mesh * M, char *filename, int volume, int surface)
     return;
   }
 
-  if(volume && Tree_Nbr(M->Volumes)){
+  if(volumes && Tree_Nbr(M->Volumes)){
     List_T *l = Tree2List(M->Volumes);
-    fprintf(statfile, "View \"Volume Statistics\" {\n");
-    fprintf(statfile, "T2(1.e5,30,%d){\"Characteristic Length\", \"Gamma\", \"Eta\", "
-	    "\"Rho\", \"Element Number\"};\n", (1<<16)|(4<<8));
+    fprintf(statfile, "View \"Volumes\" {\n");
+    fprintf(statfile, "T2(1.e5,30,%d){\"Elementary Entity\", \"Element Number\", "
+	    "\"Characteristic Length\", \"Gamma\", \"Eta\", \"Rho\"};\n", 
+	    (1<<16)|(4<<8));
     for(int i = 0; i < List_Nbr(l); i++) {
       Volume *vol;
       List_Read(l, i, &vol);
@@ -143,11 +132,12 @@ void ExportMeshStatistics(Mesh * M, char *filename, int volume, int surface)
     fprintf(statfile, "};\n");
   }
   
-  if(surface && Tree_Nbr(M->Surfaces)){
+  if(surfaces && Tree_Nbr(M->Surfaces)){
     List_T *l = Tree2List(M->Surfaces);
-    fprintf(statfile, "View \"Surface Statistics\" {\n");
-    fprintf(statfile, "T2(1.e5,30,%d){\"Characteristic Length\", \"Gamma\", \"Eta\", "
-	    "\"Rho\", \"Element Number\"};\n", (1<<16)|(4<<8));
+    fprintf(statfile, "View \"Surfaces\" {\n");
+    fprintf(statfile, "T2(1.e5,30,%d){\"Elementary Entity\", \"Element Number\", "
+	    "\"Characteristic Length\", \"Gamma\", \"Eta\", \"Rho\"};\n", 
+	    (1<<16)|(4<<8));
     for(int i = 0; i < List_Nbr(l); i++) {
       Surface *surf;
       List_Read(l, i, &surf);
@@ -159,6 +149,22 @@ void ExportMeshStatistics(Mesh * M, char *filename, int volume, int surface)
     fprintf(statfile, "};\n");
   }
 
+  if(lines && Tree_Nbr(M->Curves)){
+    List_T *l = Tree2List(M->Curves);
+    fprintf(statfile, "View \"Lines\" {\n");
+    fprintf(statfile, "T2(1.e5,30,%d){\"Elementary Entity\", \"Element Number\", "
+	    "\"Characteristic Length\", \"Gamma\", \"Eta\", \"Rho\"};\n", 
+	    (1<<16)|(4<<8));
+    for(int i = 0; i < List_Nbr(l); i++) {
+      Curve *lin;
+      List_Read(l, i, &lin);
+      Tree_Action(lin->Simplexes, ExportStatistics);
+      Tree_Action(lin->SimplexesBase, ExportStatistics);
+    }
+    List_Delete(l);
+    fprintf(statfile, "};\n");
+  }
+
   fclose(statfile);
   statfile = NULL;
 }
diff --git a/Mesh/Element.cpp b/Mesh/Element.cpp
index 9129917458..f33ec6533e 100644
--- a/Mesh/Element.cpp
+++ b/Mesh/Element.cpp
@@ -1,4 +1,4 @@
-// $Id: Element.cpp,v 1.10 2006-01-06 00:34:26 geuzaine Exp $
+// $Id: Element.cpp,v 1.11 2006-01-29 20:32:48 geuzaine Exp $
 //
 // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle
 //
@@ -96,39 +96,11 @@ Quadrangle *Create_Quadrangle(Vertex *v1, Vertex *v2, Vertex *v3, Vertex *v4)
 
 void Quadrangle::ExportStatistics(FILE * f)
 {
-  int N;
-
-  if(!VSUP){
-    N = 4;
-    fprintf(f, "SQ(%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g){%g,%g,%g,%g",
-	    V[0]->Pos.X, V[0]->Pos.Y, V[0]->Pos.Z, V[1]->Pos.X, V[1]->Pos.Y,
-	    V[1]->Pos.Z, V[2]->Pos.X, V[2]->Pos.Y, V[2]->Pos.Z, V[3]->Pos.X,
-	    V[3]->Pos.Y, V[3]->Pos.Z, V[0]->lc, V[1]->lc, V[2]->lc, V[3]->lc);
-  }
-  else{
-    N = 9;
-    fprintf(f, "SQ2(%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,"
-	    "%g,%g,%g,%g,%g,%g,%g,%g,%g){%g,%g,%g,%g,%g,%g,%g,%g,%g",
-	    V[0]->Pos.X, V[0]->Pos.Y, V[0]->Pos.Z, V[1]->Pos.X, V[1]->Pos.Y,
-	    V[1]->Pos.Z, V[2]->Pos.X, V[2]->Pos.Y, V[2]->Pos.Z, V[3]->Pos.X,
-	    V[3]->Pos.Y, V[3]->Pos.Z, 
-	    VSUP[0]->Pos.X, VSUP[0]->Pos.Y, VSUP[0]->Pos.Z, VSUP[1]->Pos.X, VSUP[1]->Pos.Y,
-	    VSUP[1]->Pos.Z, VSUP[2]->Pos.X, VSUP[2]->Pos.Y, VSUP[2]->Pos.Z, VSUP[3]->Pos.X,
-	    VSUP[3]->Pos.Y, VSUP[3]->Pos.Z, VSUP[4]->Pos.X, VSUP[4]->Pos.Y, VSUP[4]->Pos.Z, 
-	    V[0]->lc, V[1]->lc, V[2]->lc, V[3]->lc, 
-	    VSUP[0]->lc, VSUP[1]->lc, VSUP[2]->lc, VSUP[3]->lc, VSUP[4]->lc);
-  }
-
+  int N = 4, NSUP = VSUP ? 5 : 0;
   double g = 0.;
   double e = 0.;
   double r = RhoShapeMeasure();
-  double n = Num;
-  for(int i = 0; i < N; i++) fprintf(f, ",%g", g);
-  for(int i = 0; i < N; i++) fprintf(f, ",%g", e);
-  for(int i = 0; i < N; i++) fprintf(f, ",%g", r);
-  for(int i = 0; i < N; i++) fprintf(f, ",%g", n);
-  
-  fprintf(f, "};\n");
+  print_elm_stats(f, Num, iEnt, g, e, r, "SQ", N, V, "SQ2", NSUP, VSUP);
 }
 
 void Free_Quadrangle(void *a, void *b)
@@ -203,43 +175,11 @@ Hexahedron *Create_Hexahedron(Vertex * v1, Vertex * v2, Vertex * v3,
 
 void Hexahedron::ExportStatistics(FILE * f)
 {
-  int N;
-
-  if(!VSUP){
-    N = 8;
-    fprintf(f,"SH(%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,"
-	    "%g,%g,%g,%g,%g,%g){%g,%g,%g,%g,%g,%g,%g,%g\n",
-	    V[0]->Pos.X, V[0]->Pos.Y, V[0]->Pos.Z, V[1]->Pos.X, V[1]->Pos.Y,
-	    V[1]->Pos.Z, V[2]->Pos.X, V[2]->Pos.Y, V[2]->Pos.Z, V[3]->Pos.X, 
-	    V[3]->Pos.Y, V[3]->Pos.Z, V[4]->Pos.X, V[4]->Pos.Y, V[4]->Pos.Z,
-	    V[5]->Pos.X, V[5]->Pos.Y, V[5]->Pos.Z, V[6]->Pos.X, V[6]->Pos.Y, 
-	    V[6]->Pos.Z, V[7]->Pos.X, V[7]->Pos.Y, V[7]->Pos.Z, V[0]->lc, 
-	    V[1]->lc, V[2]->lc, V[3]->lc, V[4]->lc, V[5]->lc, V[6]->lc, V[7]->lc);
-  }
-  else{
-    N = 27;
-    fprintf(f,"SH2(%g,%g,%g", V[0]->Pos.X, V[0]->Pos.Y, V[0]->Pos.Z);
-    for(int i = 1; i < 8; i++) 
-      fprintf(f,",%g,%g,%g", V[i]->Pos.X, V[i]->Pos.Y, V[i]->Pos.Z);
-    for(int i = 0; i < 19; i++) 
-      fprintf(f,",%g,%g,%g", VSUP[i]->Pos.X, VSUP[i]->Pos.Y, VSUP[i]->Pos.Z);
-    fprintf(f,"){%g", V[0]->lc);
-    for(int i = 1; i < 8; i++) 
-      fprintf(f,",%g", V[i]->lc);
-    for(int i = 0; i < 19; i++) 
-      fprintf(f,",%g", VSUP[i]->lc);
-  }
-
+  int N = 8, NSUP = VSUP ? 19 : 0;
   double g = 0.;
   double e = 0.;
   double r = RhoShapeMeasure();
-  double n = Num;
-  for(int i = 0; i < N; i++) fprintf(f, ",%g", g);
-  for(int i = 0; i < N; i++) fprintf(f, ",%g", e);
-  for(int i = 0; i < N; i++) fprintf(f, ",%g", r);
-  for(int i = 0; i < N; i++) fprintf(f, ",%g", n);
-  
-  fprintf(f, "};\n");
+  print_elm_stats(f, Num, iEnt, g, e, r, "SH", N, V, "SH2", NSUP, VSUP);
 }
 
 void Free_Hexahedron(void *a, void *b)
@@ -313,42 +253,11 @@ Prism *Create_Prism(Vertex * v1, Vertex * v2, Vertex * v3,
 
 void Prism::ExportStatistics(FILE * f)
 {
-  int N;
-
-  if(!VSUP){
-    N = 6;
-    fprintf(f,"SI(%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g)"
-	    "{%g,%g,%g,%g,%g,%g",
-	    V[0]->Pos.X, V[0]->Pos.Y, V[0]->Pos.Z, V[1]->Pos.X, V[1]->Pos.Y,
-	    V[1]->Pos.Z, V[2]->Pos.X, V[2]->Pos.Y, V[2]->Pos.Z, V[3]->Pos.X, 
-	    V[3]->Pos.Y, V[3]->Pos.Z, V[4]->Pos.X, V[4]->Pos.Y, V[4]->Pos.Z,
-	    V[5]->Pos.X, V[5]->Pos.Y, V[5]->Pos.Z, V[0]->lc, V[1]->lc, V[2]->lc,
-	    V[3]->lc, V[4]->lc, V[5]->lc);
-  }
-  else{
-    N = 18;
-    fprintf(f,"SI2(%g,%g,%g", V[0]->Pos.X, V[0]->Pos.Y, V[0]->Pos.Z);
-    for(int i = 1; i < 6; i++) 
-      fprintf(f,",%g,%g,%g", V[i]->Pos.X, V[i]->Pos.Y, V[i]->Pos.Z);
-    for(int i = 0; i < 12; i++) 
-      fprintf(f,",%g,%g,%g", VSUP[i]->Pos.X, VSUP[i]->Pos.Y, VSUP[i]->Pos.Z);
-    fprintf(f,"){%g", V[0]->lc);
-    for(int i = 1; i < 6; i++) 
-      fprintf(f,",%g", V[i]->lc);
-    for(int i = 0; i < 12; i++) 
-      fprintf(f,",%g", VSUP[i]->lc);
-  }
-
+  int N = 6, NSUP = VSUP ? 12 : 0;
   double g = 0.;
   double e = 0.;
   double r = RhoShapeMeasure();
-  double n = Num;
-  for(int i = 0; i < N; i++) fprintf(f, ",%g", g);
-  for(int i = 0; i < N; i++) fprintf(f, ",%g", e);
-  for(int i = 0; i < N; i++) fprintf(f, ",%g", r);
-  for(int i = 0; i < N; i++) fprintf(f, ",%g", n);
-  
-  fprintf(f, "};\n");
+  print_elm_stats(f, Num, iEnt, g, e, r, "SI", N, V, "SI2", NSUP, VSUP);
 }
 
 void Free_Prism(void *a, void *b)
@@ -420,41 +329,11 @@ Pyramid *Create_Pyramid(Vertex * v1, Vertex * v2, Vertex * v3,
 
 void Pyramid::ExportStatistics(FILE * f)
 {
-  int N;
-
-  if(!VSUP){
-    N = 5;
-    fprintf(f,"SY(%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g)"
-	    "{%g,%g,%g,%g,%g",
-	    V[0]->Pos.X, V[0]->Pos.Y, V[0]->Pos.Z, V[1]->Pos.X, V[1]->Pos.Y,
-	    V[1]->Pos.Z, V[2]->Pos.X, V[2]->Pos.Y, V[2]->Pos.Z, V[3]->Pos.X, 
-	    V[3]->Pos.Y, V[3]->Pos.Z, V[4]->Pos.X, V[4]->Pos.Y, V[4]->Pos.Z,
-	    V[0]->lc, V[1]->lc, V[2]->lc, V[3]->lc, V[4]->lc);
-  }
-  else{
-    N = 14;
-    fprintf(f,"SY2(%g,%g,%g", V[0]->Pos.X, V[0]->Pos.Y, V[0]->Pos.Z);
-    for(int i = 1; i < 5; i++) 
-      fprintf(f,",%g,%g,%g", V[i]->Pos.X, V[i]->Pos.Y, V[i]->Pos.Z);
-    for(int i = 0; i < 9; i++) 
-      fprintf(f,",%g,%g,%g", VSUP[i]->Pos.X, VSUP[i]->Pos.Y, VSUP[i]->Pos.Z);
-    fprintf(f,"){%g", V[0]->lc);
-    for(int i = 1; i < 5; i++) 
-      fprintf(f,",%g", V[i]->lc);
-    for(int i = 0; i < 9; i++) 
-      fprintf(f,",%g", VSUP[i]->lc);
-  }
-
+  int N = 5, NSUP = VSUP ? 9 : 0;
   double g = 0.;
   double e = 0.;
   double r = RhoShapeMeasure();
-  double n = Num;
-  for(int i = 0; i < N; i++) fprintf(f, ",%g", g);
-  for(int i = 0; i < N; i++) fprintf(f, ",%g", e);
-  for(int i = 0; i < N; i++) fprintf(f, ",%g", r);
-  for(int i = 0; i < N; i++) fprintf(f, ",%g", n);
-  
-  fprintf(f, "};\n");
+  print_elm_stats(f, Num, iEnt, g, e, r, "SY", N, V, "SY2", NSUP, VSUP);
 }
 
 void Free_Pyramid(void *a, void *b)
@@ -472,3 +351,39 @@ int comparePyramid(const void *a, const void *b)
   Pyramid *w = *(Pyramid **) b;
   return (q->Num - w->Num);
 }
+
+// dump an element in a parsed post-processing view
+
+void print_elm_stats(FILE *f, int Num, int Ent, double Gamma, double Eta, double Rho, 
+		     const char *S, int N, Vertex **V, 
+		     const char *SSUP, int NSUP, Vertex **VSUP)
+{
+  fprintf(f, "%s(", NSUP ? SSUP : S);
+  for(int i = 0; i < N; i++){
+    if(i) fprintf(f, ",");
+    fprintf(f, "%g,%g,%g", V[i]->Pos.X, V[i]->Pos.Y, V[i]->Pos.Z);
+  }
+  for(int i = 0; i < NSUP; i++){
+    fprintf(f, ",%g,%g,%g", VSUP[i]->Pos.X, VSUP[i]->Pos.Y, VSUP[i]->Pos.Z);
+  }
+  fprintf(f, "){");
+  for(int i = 0; i < N+NSUP; i++)
+    fprintf(f, "%d,", Ent);
+  for(int i = 0; i < N+NSUP; i++)
+    fprintf(f, "%d,", Num);
+  for(int i = 0; i < N; i++)
+    fprintf(f, "%g,", V[i]->lc);
+  for(int i = 0; i < NSUP; i++)
+    fprintf(f, "%g,", VSUP[i]->lc);
+  for(int i = 0; i < N+NSUP; i++)
+    fprintf(f, "%g,", Gamma);
+  for(int i = 0; i < N+NSUP; i++)
+    fprintf(f, "%g,", Eta);
+  for(int i = 0; i < N+NSUP; i++){
+    if(i == N+NSUP - 1)
+      fprintf(f, "%g", Rho);
+    else
+      fprintf(f, "%g,", Rho);
+  }
+  fprintf(f, "};\n");
+}
diff --git a/Mesh/Element.h b/Mesh/Element.h
index 078a355bd5..56ab1f3706 100644
--- a/Mesh/Element.h
+++ b/Mesh/Element.h
@@ -108,4 +108,8 @@ int compareHexahedron(const void *a, const void *b);
 int comparePrism(const void *a, const void *b);
 int comparePyramid(const void *a, const void *b);
 
+void print_elm_stats(FILE *f, int Num, int Ent, double Gamma, double Eta, double Rho, 
+		     const char *S, int N, Vertex **V, 
+		     const char *SSUP, int NSUP, Vertex **VSUP);
+
 #endif
diff --git a/Mesh/Mesh.h b/Mesh/Mesh.h
index db0309dbe5..487bd5e56c 100644
--- a/Mesh/Mesh.h
+++ b/Mesh/Mesh.h
@@ -501,7 +501,7 @@ int Recombine(Tree_T *TreeAllVert, Tree_T *TreeAllSimp, Tree_T *TreeAllQuad,
 		double a);
 int Recombine_All(Mesh *M);
 void ApplyLcFactor(Mesh *M);
-void ExportMeshStatistics(Mesh *M, char *filename, int volume=1, int surface=1);
+void ExportMeshStatistics(Mesh *M, char *filename, int vol=1, int surf=1, int lin=1);
 
 void Degre1();
 void Degre2(int dim);
diff --git a/Mesh/Simplex.cpp b/Mesh/Simplex.cpp
index 276727ee6c..ab339f4b1b 100644
--- a/Mesh/Simplex.cpp
+++ b/Mesh/Simplex.cpp
@@ -1,4 +1,4 @@
-// $Id: Simplex.cpp,v 1.45 2006-01-06 00:34:26 geuzaine Exp $
+// $Id: Simplex.cpp,v 1.46 2006-01-29 20:32:48 geuzaine Exp $
 //
 // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle
 //
@@ -215,76 +215,14 @@ double SimplexBase::GammaShapeMeasure()
 
 void SimplexBase::ExportStatistics(FILE * f)
 {
-  int N;
-
-  if(!V[2]){
-    if(!VSUP){
-      N = 2;
-      fprintf(f, "SL(%g,%g,%g,%g,%g,%g){%g,%g",
-	      V[0]->Pos.X, V[0]->Pos.Y, V[0]->Pos.Z, V[1]->Pos.X, V[1]->Pos.Y,
-	      V[1]->Pos.Z, V[0]->lc, V[1]->lc);
-    }
-    else{
-      N = 3;
-      fprintf(f, "SL2(%g,%g,%g,%g,%g,%g,%g,%g,%g){%g,%g,%g",
-	      V[0]->Pos.X, V[0]->Pos.Y, V[0]->Pos.Z, V[1]->Pos.X, V[1]->Pos.Y,
-	      V[1]->Pos.Z, VSUP[0]->Pos.X, VSUP[0]->Pos.Y, VSUP[0]->Pos.Z,
-	      V[0]->lc, V[1]->lc, VSUP[0]->lc);
-    }
-  }
-  else if(!V[3]){
-    if(!VSUP){
-      N = 3;
-      fprintf(f, "ST(%g,%g,%g,%g,%g,%g,%g,%g,%g){%g,%g,%g",
-	      V[0]->Pos.X, V[0]->Pos.Y, V[0]->Pos.Z, V[1]->Pos.X, V[1]->Pos.Y,
-	      V[1]->Pos.Z, V[2]->Pos.X, V[2]->Pos.Y, V[2]->Pos.Z, V[0]->lc,
-	      V[1]->lc, V[2]->lc);
-    }
-    else{
-      N = 6;
-      fprintf(f, "ST2(%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g)"
-	      "{%g,%g,%g,%g,%g,%g",
-	      V[0]->Pos.X, V[0]->Pos.Y, V[0]->Pos.Z, V[1]->Pos.X, V[1]->Pos.Y,
-	      V[1]->Pos.Z, V[2]->Pos.X, V[2]->Pos.Y, V[2]->Pos.Z, VSUP[0]->Pos.X, 
-	      VSUP[0]->Pos.Y, VSUP[0]->Pos.Z, VSUP[1]->Pos.X, VSUP[1]->Pos.Y,
-	      VSUP[1]->Pos.Z, VSUP[2]->Pos.X, VSUP[2]->Pos.Y, VSUP[2]->Pos.Z, 
-	      V[0]->lc, V[1]->lc, V[2]->lc, VSUP[0]->lc, VSUP[1]->lc, VSUP[2]->lc);
-    }
-  }
-  else{
-    if(!VSUP){
-      N = 4;
-      fprintf(f, "SS(%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g){%g,%g,%g,%g",
-	      V[0]->Pos.X, V[0]->Pos.Y, V[0]->Pos.Z, V[1]->Pos.X, V[1]->Pos.Y,
-	      V[1]->Pos.Z, V[2]->Pos.X, V[2]->Pos.Y, V[2]->Pos.Z, V[3]->Pos.X,
-	      V[3]->Pos.Y, V[3]->Pos.Z, V[0]->lc, V[1]->lc, V[2]->lc, V[3]->lc);
-    }
-    else{
-      N = 10;
-      fprintf(f, "SS2(%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,"
-	      "%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g){%g,%g,%g,%g,%g,%g,%g,%g,%g,%g",
-	      V[0]->Pos.X, V[0]->Pos.Y, V[0]->Pos.Z, V[1]->Pos.X, V[1]->Pos.Y,
-	      V[1]->Pos.Z, V[2]->Pos.X, V[2]->Pos.Y, V[2]->Pos.Z, V[3]->Pos.X,
-	      V[3]->Pos.Y, V[3]->Pos.Z, VSUP[0]->Pos.X, VSUP[0]->Pos.Y, VSUP[0]->Pos.Z, 
-	      VSUP[1]->Pos.X, VSUP[1]->Pos.Y, VSUP[1]->Pos.Z, VSUP[2]->Pos.X, 
-	      VSUP[2]->Pos.Y, VSUP[2]->Pos.Z, VSUP[3]->Pos.X, VSUP[3]->Pos.Y, 
-	      VSUP[3]->Pos.Z, VSUP[4]->Pos.X, VSUP[4]->Pos.Y, VSUP[4]->Pos.Z, 
-	      VSUP[5]->Pos.X, VSUP[5]->Pos.Y, VSUP[5]->Pos.Z, V[0]->lc, V[1]->lc, 
-	      V[2]->lc, V[3]->lc, VSUP[0]->lc, VSUP[1]->lc, VSUP[2]->lc, VSUP[3]->lc,
-	      VSUP[4]->lc, VSUP[5]->lc);
-    }
-  }
-
+  int N = !V[2] ? 2 : (!V[3] ? 3 : 4);
+  int NSUP = !VSUP ? 0 : (!V[2] ? 1 : (!V[3] ? 3 : 6));
   double g = GammaShapeMeasure();
   double e = EtaShapeMeasure();
   double r = RhoShapeMeasure();
-  double n = Num;
-  for(int i = 0; i < N; i++) fprintf(f, ",%g", g);
-  for(int i = 0; i < N; i++) fprintf(f, ",%g", e);
-  for(int i = 0; i < N; i++) fprintf(f, ",%g", r);
-  for(int i = 0; i < N; i++) fprintf(f, ",%g", n);
-  
-  fprintf(f, "};\n");
+  print_elm_stats(f, Num, iEnt, g, e, r, 
+		  !V[2] ? "SL" : (!V[3] ? "ST" : "SS"), N, V, 
+		  !V[2] ? "SL2" : (!V[3] ? "ST2" : "SS2"), NSUP, VSUP);
 }
 
 SimplexBase *Create_SimplexBase(Vertex * v1, Vertex * v2, Vertex * v3, Vertex * v4)
-- 
GitLab