Salome HOME
Updated copyright comment
[plugins/ghs3dprlplugin.git] / src / tepal2med / ghs3dprl_mesh_wrap.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 1ed2e55..bb4731f
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2024  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 #include <QRegExp>
 #include <limits>
 
-extern "C" {
 #include <med.h>
 //#include <med_config.h>
 //#include <med_utils.h>
 //#include <med_misc.h>
-}
 
 //utils procedures
 
@@ -240,7 +238,7 @@ bool familles::get_number_of_new_family(int sign, med_int *ires, QString *tmp)
       //std::cout<<"no family found!!! - groups of "<<fam1<<" and "<<fam2<<std::endl;
       QString tmp;
       //fam1 positive for nodes negative faces & mailles
-      bool oktmp=get_number_of_new_family(fam1,&ires,&tmp);
+      /*bool oktmp=*/get_number_of_new_family(fam1,&ires,&tmp);
       fend::iterator it;
       for (it=gb.begin(); it!=gb.end(); ++it){
           this->add(tmp,(*it).first);
@@ -255,9 +253,9 @@ bool familles::get_number_of_new_family(int sign, med_int *ires, QString *tmp)
    {
       QString nom1,nom2;
       fagr::iterator it1,it2;
-      nom1=nom1.sprintf("%d",fam1);
+      nom1=nom1.sprintf("%d",(int)fam1);
       it1=fam.find(nom1);
-      nom2=nom2.sprintf("%d",fam2);
+      nom2=nom2.sprintf("%d",(int)fam2);
       it2=fam.find(nom2);
       if ( (it1==fam.end())||(it2==fam.end()) ) {
          std::cerr<<"***fuse_goups*** non existing family "<<fam1<<" or "<<fam2<<std::endl;
@@ -317,9 +315,9 @@ CVWtab::CVWtab(long nb, med_float *pmflo)
 //************************************
 CVWtab::~CVWtab()
 {
-   bool ok;
+   //bool ok;
    //std::cout<<"   destructor CVWtab *** "<<this->filename<<std::endl;
-   ok=this->CVWtab_deallocate();
+   /*ok=*/this->CVWtab_deallocate();
    //remove temporary file
    if (this->filename!="_NO_FILE")
    {
@@ -346,8 +344,8 @@ bool CVWtab::CVWtab_deallocate()
       memoryuse=memoryuse-sizeof(med_float)*size;
       size=-size; //precaution
    }
-   if (memoryuse<0) std::cout<<"***WARNING*** memoryuse <0 "<<memoryuse<<std::endl;
-   if (memoryuse==0) std::cout<<"***CVWtab_deallocate*** memoryuse=0 "<<std::endl;
+   if (memoryuse<0) std::cout<<"ERROR: on arrays deallocate memory use < 0 "<<memoryuse<<std::endl;
+   if (memoryuse==0) std::cout<<"WARNING: on arrays deallocate memory use = 0 "<<std::endl;
    return true;
 }
 
@@ -448,6 +446,40 @@ bool CVW_FindString(const std::string &str,std::fstream &Ff, long &count)
    return true;
 }
 
+//************************************
+bool CVW_FindStringInFirstLines(const std::string &str,std::fstream &Ff, long &maxline)
+//find in file maximum maxline first lines with string str in first position of line
+//converts count value expected after " " in line found
+{
+   std::string line;
+   long nbLine=0;
+   do
+   {
+      if (getline(Ff,line))
+      {
+         nbLine++;
+         if (line[0]==str[0]) //faster
+         {
+            if (line.find(str)==0)
+            {
+            return true;
+            }
+         }
+         if (nbLine>=maxline)
+         {
+            std::cerr<<"Problem line '"<<str<<"' not found in first "<<maxline<<" lines of file\n"<<std::endl;
+            return false;
+         }
+      }
+      else
+      {
+         std::cerr<<"Problem line '"<<str<<"' not found in all file\n"<<std::endl;
+         return false;
+      }
+   } while (1);
+   return true;
+}
+
 //************************************
 bool ghs3dprl_mesh_wrap::ReadFileMSGnew(const QString FileName)
 //read file .glo with no parser xml because big file (volume)
@@ -457,7 +489,7 @@ bool ghs3dprl_mesh_wrap::ReadFileMSGnew(const QString FileName)
    std::fstream Ff(FileName.toLatin1().constData(),std::ios_base::in);
    std::string line;
    long i,count,nbneighbour,ineighbour;
-   bool ok;
+   //bool ok;
 
    if (!Ff.is_open())
    {
@@ -465,7 +497,7 @@ bool ghs3dprl_mesh_wrap::ReadFileMSGnew(const QString FileName)
       return false;
    }
 
-   //Lit les donns :
+   //Lit les donnees :
    if (!CVW_FindString("<neighbours count=",Ff,nbneighbour)) return false;
    if (verbose>2) std::cout<<"NeighboursCountDomain_"<<this->nofile<<"="<<nbneighbour<<std::endl;
    for (i=1; i<=nbneighbour; i++)
@@ -479,7 +511,7 @@ bool ghs3dprl_mesh_wrap::ReadFileMSGnew(const QString FileName)
 
          CVWtab *montab=new CVWtab(count,tmint);
          tmp=tmp.sprintf("MS%ld NE%ld VE SE",this->nofile,ineighbour);
-         ok=this->insert_key(tmp,montab);
+         /*ok=*/this->insert_key(tmp,montab);
       }
       if (!CVW_FindString("<edges count=",Ff,count)) return false;
       if (count>0){
@@ -489,7 +521,7 @@ bool ghs3dprl_mesh_wrap::ReadFileMSGnew(const QString FileName)
 
          CVWtab *montab=new CVWtab(count,tmint);
          tmp=tmp.sprintf("MS%ld NE%ld ED SE",this->nofile,ineighbour);
-         ok=this->insert_key(tmp,montab);
+         /*ok=*/this->insert_key(tmp,montab);
       }
       if (!CVW_FindString("<faces count=",Ff,count)) return false;
       if (count>0){
@@ -499,7 +531,7 @@ bool ghs3dprl_mesh_wrap::ReadFileMSGnew(const QString FileName)
 
          CVWtab *montab=new CVWtab(count,tmint);
          tmp=tmp.sprintf("MS%ld NE%ld FA SE",this->nofile,ineighbour);
-         ok=this->insert_key(tmp,montab);
+         /*ok=*/this->insert_key(tmp,montab);
       }
       if (!CVW_FindString("<elements count=",Ff,count)) return false;
       if (count>0){
@@ -509,7 +541,7 @@ bool ghs3dprl_mesh_wrap::ReadFileMSGnew(const QString FileName)
 
          CVWtab *montab=new CVWtab(count,tmint);
          tmp=tmp.sprintf("MS%ld NE%ld EL SE",this->nofile,ineighbour);
-         ok=this->insert_key(tmp,montab);
+         /*ok=*/this->insert_key(tmp,montab);
       }
    }
 
@@ -519,6 +551,33 @@ bool ghs3dprl_mesh_wrap::ReadFileMSGnew(const QString FileName)
    return true;
 }
 
+//************************************
+bool ghs3dprl_mesh_wrap::TestExistingFileMESHnew(const QString FileName)
+//read file .glo with no parser xml because big file (volume)
+//no read of <receive> for speed (and so no test)
+{
+   QString tmp;
+   std::fstream Ff(FileName.toLatin1().constData(),std::ios_base::in);
+   std::string line;
+   long maxline;
+
+   if (!Ff.is_open())
+   {
+      std::cerr<<"Problem File '"<<FileName.toLatin1().constData()<<"' not open\n"<<std::endl;
+      return false;
+   }
+
+   //Lit les donnees au debut du fichier, 1 lignes maxi:
+   maxline=1;
+   if (!CVW_FindStringInFirstLines("MeshVersionFormatted",Ff,maxline)) return false;
+   if (verbose>2) std::cout<<"MeshVersionFormatted_"<<this->nofile<<" ok"<<std::endl;
+
+   //Ferme le fichier :
+   Ff.close();
+   this->nbfiles++;
+   return true;
+}
+
 ///************************************
 bool ghs3dprl_mesh_wrap::ReadFileGLO(const QString FileName)
 //read file .glo with no parser xml because big file (volume)
@@ -527,7 +586,7 @@ bool ghs3dprl_mesh_wrap::ReadFileGLO(const QString FileName)
    std::fstream Ff(FileName.toLatin1().constData(),std::ios_base::in);
    std::string line;
    long count;
-   bool ok;
+   //bool ok;
 
    if (!Ff.is_open())
    {
@@ -535,7 +594,7 @@ bool ghs3dprl_mesh_wrap::ReadFileGLO(const QString FileName)
       return false;
    }
 
-   //Lit les donns :
+   //Lit les donnees :
    if (!CVW_FindString("<vertices count=",Ff,count)) return false;
    if (verbose>3) std::cout<<"GloVerticesCount="<<count<<std::endl;
    if (count>0)
@@ -546,7 +605,7 @@ bool ghs3dprl_mesh_wrap::ReadFileGLO(const QString FileName)
 
       CVWtab *montab=new CVWtab(count,tmint);
       tmp=tmp.sprintf("GL%ld VE",this->nofile);
-      ok=this->insert_key(tmp,montab);
+      /*ok=*/this->insert_key(tmp,montab);
    }
 
    if (!CVW_FindString("<edges count=",Ff,count)) return false;
@@ -559,7 +618,7 @@ bool ghs3dprl_mesh_wrap::ReadFileGLO(const QString FileName)
 
       CVWtab *montab=new CVWtab(count,tmint);
       tmp=tmp.sprintf("GL%ld ED",this->nofile);
-      ok=this->insert_key(tmp,montab);
+      /*ok=*/this->insert_key(tmp,montab);
    }
 
    if (!CVW_FindString("<faces count=",Ff,count)) return false;
@@ -572,7 +631,7 @@ bool ghs3dprl_mesh_wrap::ReadFileGLO(const QString FileName)
 
       CVWtab *montab=new CVWtab(count,tmint);
       tmp=tmp.sprintf("GL%ld FA",this->nofile);
-      ok=this->insert_key(tmp,montab);
+      /*ok=*/this->insert_key(tmp,montab);
    }
 
    if (!CVW_FindString("<elements count=",Ff,count)) return false;
@@ -585,14 +644,159 @@ bool ghs3dprl_mesh_wrap::ReadFileGLO(const QString FileName)
 
       CVWtab *montab=new CVWtab(count,tmint);
       tmp=tmp.sprintf("GL%ld EL",this->nofile);
-      ok=this->insert_key(tmp,montab);
+      /*ok=*/this->insert_key(tmp,montab);
+   }
+   //Ferme le fichier :
+   Ff.close();
+   this->nbfiles++;
+   return true;
+}
+
+///************************************
+bool ghs3dprl_mesh_wrap::ReadFileGLOBAL(const QString FileName)
+//read file .global ascii (no xml)
+//first line: Vertices Edges Triangles Tetrahedra
+{
+   std::string line("                                            ");
+   QString tmp;
+   std::fstream Ff(FileName.toLatin1().constData(),std::ios_base::in);
+   long vert=0,edge=0,tria=0,tetr=0,count=0;
+   med_int *tmint;
+   CVWtab *montab;
+   //bool ok;
+   
+   if (verbose>=6) std::cout<<"Read file '"<<FileName.toLatin1().constData()<<std::endl;
+   if (!Ff.is_open())
+   {
+      std::cerr<<"Problem file '"<<FileName.toLatin1().constData()<<"' not open"<<std::endl;
+      // std::cout<<"Default global numerotation nb verts "<<vert<<" nb edges "<<edge<<" nb trias "<<tria<<" nb tetras "<<tetr<<std::endl;
+      return false;
+   }
+   else
+   {
+     //Lit les donnees :
+     Ff>>vert>>edge>>tria>>tetr;
+     std::cout<<"Global numerotation nb verts "<<vert<<" nb edges "<<edge<<" nb trias "<<tria<<" nb tetras "<<tetr<<std::endl;
+   }
+   
+   if (vert<0)
+   {
+      std::cerr<<"Problem Vertices: a positive integer is expected"<<std::endl;
+      return false;
+   }
+
+   if (edge<0)
+   {
+      std::cerr<<"Problem Edges: a positive integer is expected"<<std::endl;
+      return false;
+   }
+
+   if (tria<0)
+   {
+      std::cerr<<"Problem Triangles: a positive integer is expected"<<std::endl;
+      return false;
+   }
+
+   if (tetr<0)
+   {
+      std::cerr<<"Problem Tetrahedra: a positive integer is expected"<<std::endl;
+      return false;
    }
+
+   count=vert;
+   tmint=new med_int[count];
+   for (long i=0; i<count; i++) Ff>>tmint[i];
+   if (verbose>4) std::cout<<"Vertices ("<<count<<") "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[count-1]<<std::endl;
+
+   montab=new CVWtab(count,tmint);
+   tmp=tmp.sprintf("GL%ld VE",this->nofile);
+   /*ok=*/this->insert_key(tmp,montab);
+
+   count=edge;
+   tmint=new med_int[count];
+   for (long i=0; i<count; i++) Ff>>tmint[i];
+   if (verbose>4) std::cout<<"Edges ("<<count<<") "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[count-1]<<std::endl;
+
+   montab=new CVWtab(count,tmint);
+   tmp=tmp.sprintf("GL%ld ED",this->nofile);
+   /*ok=*/this->insert_key(tmp,montab);
+
+   count=tria;
+   tmint=new med_int[count];
+   for (long i=0; i<count; i++) Ff>>tmint[i];
+   if (verbose>4) std::cout<<"Triangles ("<<count<<") "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[count-1]<<std::endl;
+
+   montab=new CVWtab(count,tmint);
+   tmp=tmp.sprintf("GL%ld FA",this->nofile);
+   /*ok=*/this->insert_key(tmp,montab);
+
+   count=tetr;
+   tmint=new med_int[count];
+   for (long i=0; i<count; i++) Ff>>tmint[i];
+   if (verbose>4) std::cout<<"Tetrahedra ("<<count<<") "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[count-1]<<std::endl;
+
+   montab=new CVWtab(count,tmint);
+   tmp=tmp.sprintf("GL%ld EL",this->nofile);
+   /*ok=*/this->insert_key(tmp,montab);
+
    //Ferme le fichier :
    Ff.close();
    this->nbfiles++;
    return true;
 }
 
+///************************************
+bool ghs3dprl_mesh_wrap::ReadFileDefaultGLOBAL(long vert, long edge, long tria, long tetr)
+//default like read file .global ascii (no xml) when inexisting when multithread
+{
+   QString tmp;
+   long count=0;
+   med_int *tmint;
+   CVWtab *montab;
+   //bool ok;
+   
+   //Simule les donnees :
+   std::cout<<"Default Global numerotation nb verts "<<vert<<" nb edges "<<edge<<" nb trias "<<tria<<" nb tetras "<<tetr<<std::endl;
+   
+   count=vert;
+   tmint=new med_int[count];
+   for (long i=0; i<count; i++) tmint[i] = i+1;
+   if (verbose>4) std::cout<<"Default Vertices ("<<count<<") "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[count-1]<<std::endl;
+
+   montab=new CVWtab(count,tmint);
+   tmp=tmp.sprintf("GL%ld VE",this->nofile);
+   /*ok=*/this->insert_key(tmp,montab);
+
+   count=edge;
+   tmint=new med_int[count];
+   for (long i=0; i<count; i++) tmint[i] = i+1;
+   if (verbose>4) std::cout<<"Default Edges ("<<count<<") "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[count-1]<<std::endl;
+
+   montab=new CVWtab(count,tmint);
+   tmp=tmp.sprintf("GL%ld ED",this->nofile);
+   /*ok=*/this->insert_key(tmp,montab);
+
+   count=tria;
+   tmint=new med_int[count];
+   for (long i=0; i<count; i++) tmint[i] = i+1;
+   if (verbose>4) std::cout<<"Default Triangles ("<<count<<") "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[count-1]<<std::endl;
+
+   montab=new CVWtab(count,tmint);
+   tmp=tmp.sprintf("GL%ld FA",this->nofile);
+   /*ok=*/this->insert_key(tmp,montab);
+
+   count=tetr;
+   tmint=new med_int[count];
+   for (long i=0; i<count; i++) tmint[i] = i+1;
+   if (verbose>4) std::cout<<"Default Tetrahedra ("<<count<<") "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[count-1]<<std::endl;
+
+   montab=new CVWtab(count,tmint);
+   tmp=tmp.sprintf("GL%ld EL",this->nofile);
+   /*ok=*/this->insert_key(tmp,montab);
+
+   return true;
+}
+
 //************************************
 bool ghs3dprl_mesh_wrap::ReadFileFACES(const QString FileName)
 //read file .faces (wrap)
@@ -609,8 +813,8 @@ bool ghs3dprl_mesh_wrap::ReadFileFACES(const QString FileName)
       return false;
    }
 
-   //Lit les donns :
-   //Replace le pointeur de fichier au dut :f.seekg(0);
+   //Lit les donnees :
+   //Replace le pointeur de fichier au debut :f.seekg(0);
    if (getline(Ff,line))
    {
       tmp=line.c_str();
@@ -645,6 +849,216 @@ bool ghs3dprl_mesh_wrap::ReadFileFACES(const QString FileName)
    return true;
 }
 
+//************************************
+bool ghs3dprl_mesh_wrap::ReadFileMESH(const QString FileName)
+//read file .mesh from tetra_hpc (with volume)
+{
+   std::string line("                                            ");
+   QString tmp;
+   std::fstream Ff(FileName.toLatin1().constData(),std::ios_base::in);
+   long Mversion=0,Mdim=0,Mvert=0,Mtria=0,Medge=0,Mtetra=0,count=0;
+   med_int garbage;
+   med_int *tmint;
+   bool ok;
+   
+   if (verbose>=6)std::cout<<"Read file '"<<FileName.toLatin1().constData()<<std::endl;
+   if (!Ff.is_open()){
+      std::cerr<<"Problem file '"<<FileName.toLatin1().constData()<<"' not open\n"<<std::endl;
+      return false;
+   }
+
+   //lit les données :
+   if (getline(Ff,line) && (line.find("MeshVersionFormatted")==0))
+   {
+      tmp=line.c_str();
+      Mversion=tmp.section(' ',1,1).toLong(&ok);
+   }
+   else
+   {
+      std::cerr<<"Problem on line 1 of file: 'MeshVersionFormatted' expected"<<std::endl;
+      return false;
+   }
+   
+   getline(Ff,line);
+
+   if (getline(Ff,line) && (line.find("Dimension 3")==0))
+   {
+      tmp=line.c_str();
+      Mdim=tmp.section(' ',1,1).toLong(&ok);
+   }
+   else
+   {
+      std::cerr<<"Problem on line 3 of file: Dimension 3 expected"<<std::endl;
+      return false;
+   }
+   
+   getline(Ff,line);
+
+   if (!(getline(Ff,line) && (line.find("Vertices")==0)))
+   {
+      std::cerr<<"Problem on line 5 of file: 'Vertices' expected"<<std::endl;
+      return false;
+   }
+   if (getline(Ff,line))
+   {
+      tmp=line.c_str();
+      Mvert=tmp.toLong(&ok);
+   }
+   else
+   {
+      std::cerr<<"Problem Vertices: a positive integer is expected"<<std::endl;
+      return false;
+   }
+   if (Mvert<=0)
+   {
+      std::cerr<<"Problem Vertices: a positive integer is expected"<<std::endl;
+      return false;
+   }
+
+   count=Mvert;
+   med_float *tmflo=new med_float[count*3];
+   for (int i=0; i<count*3; i=i+3) Ff>>tmflo[i]>>tmflo[i+1]>>tmflo[i+2]>>garbage;
+   if (verbose>4) std::cout<<"Vertices ("<<count<<") "<<tmflo[0]<<" "<<tmflo[1]<<"... "<<tmflo[count*3-1]<<std::endl;
+
+   CVWtab *montab=new CVWtab(count*3,tmflo);
+   tmp=tmp.sprintf("NB%ld VC",this->nofile);
+   ok=this->insert_key(tmp,montab);
+
+   getline(Ff,line);
+   getline(Ff,line);
+  
+   getline(Ff,line); // get Edges or Triangle, because sometimes Edges absent
+   
+   if (!line.find("Edges")==0)
+   {
+      std::cerr<<"absent line 'Edges' of file '"<<FileName.toLatin1().constData()<<"' :found '"<<line<<"' instead"<<std::endl;
+   }
+   else 
+   {
+     if (getline(Ff,line))
+     {
+        tmp=line.c_str();
+        Medge=tmp.toLong(&ok);
+     }
+     else
+     {
+        std::cerr<<"Problem on line 'Edges' of file: a positive integer is expected"<<std::endl;
+        return false;
+     }
+     if (Medge<=0)
+     {
+        std::cerr<<"Problem on line 'Edges' of file: a positive integer is expected"<<std::endl;
+        return false;
+     }
+
+     count=Medge;
+     tmint=new med_int[count*2]; //*3
+     for (int i=0; i<count*2; i=i+2) {
+       Ff>>tmint[i]>>tmint[i+1]>>garbage;
+     }
+     if (verbose>4) std::cout<<"Edges ("<<count<<") "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[count*2-1]<<std::endl;
+     montab=new CVWtab(count*2,tmint);
+     tmp=tmp.sprintf("NB%ld ED",this->nofile); //TODO see if it could serve
+     ok=this->insert_key(tmp,montab);
+     
+     getline(Ff,line);
+     getline(Ff,line);
+     getline(Ff,line);
+   }
+
+   if (!line.find("Triangles")==0)
+   {
+      std::cerr<<"Problem on line 'Triangles' of file '"<<FileName.toLatin1().constData()<<"' :found '"<<line<<"' instead"<<std::endl;
+      return false;
+   }
+   if (getline(Ff,line))
+   {
+      tmp=line.c_str();
+      Mtria=tmp.toLong(&ok);
+   }
+   else
+   {
+      std::cerr<<"Problem on line 'Triangles' of file: a positive integer is expected"<<std::endl;
+      return false;
+   }
+   if (Mtria<=0)
+   {
+      std::cerr<<"Problem on line 'Triangles' of file: a positive integer is expected"<<std::endl;
+      return false;
+   }
+
+   count=Mtria;
+   tmint=new med_int[count*3]; //*7 as older files .faces, obsolete
+   for (int i=0; i<count*3; i=i+3) {
+     Ff>>tmint[i]>>tmint[i+1]>>tmint[i+2]>>garbage;
+   }
+   if (verbose>4) std::cout<<"Triangles ("<<count<<") "<<tmint[0]<<" "<<tmint[1]<<"... "<<
+       tmint[count*3-5]<<" "<<tmint[count*3-4]<<" "<<tmint[count*3-3]<<" "<<
+       tmint[count*3-2]<<" "<<tmint[count*3-1]<<std::endl;
+
+   montab=new CVWtab(count*3,tmint);
+   tmp=tmp.sprintf("FC%ld",this->nofile);
+   ok=this->insert_key(tmp,montab);
+   
+   getline(Ff,line);
+   getline(Ff,line);
+
+   if (!(getline(Ff,line) && (line.find("Tetrahedra")==0)))
+   {
+      std::cerr<<"Problem on line 'Tetrahedra' of file: not found"<<std::endl;
+      return false;
+   }
+   if (getline(Ff,line))
+   {
+      tmp=line.c_str();
+      Mtetra=tmp.toLong(&ok);
+   }
+   else
+   {
+      std::cerr<<"Problem on line 'Tetrahedra' of file: a positive integer is expected"<<std::endl;
+      return false;
+   }
+   if (Mtetra<=0)
+   {
+      std::cerr<<"Problem on line 'Tetrahedra' of file: a positive integer is expected"<<std::endl;
+      return false;
+   }
+
+   if (verbose>=2)
+   {
+      std::cout<<"MeshVersionFormatted="<<Mversion<<std::endl;
+      std::cout<<"MeshDimension="<<Mdim<<std::endl;
+      std::cout<<"MeshNumberOfVertices="<<Mvert<<std::endl;
+      std::cout<<"MeshNumberOfEdges="<<Medge<<std::endl;
+      std::cout<<"MeshNumberOfTriangles="<<Mtria<<std::endl;
+      std::cout<<"MeshNumberOfTetrahedra="<<Mtetra<<std::endl;
+   }
+
+   this->nbvert=Mvert; // for current idom
+   this->nbedge=Medge; 
+   this->nbtria=Mtria; 
+   this->nbtetr=Mtetra; 
+
+   count=Mtetra;
+   tmint=new med_int[count*4];
+   for (int i=0; i<count*4; i=i+4) Ff>>tmint[i]>>tmint[i+1]>>tmint[i+2]>>tmint[i+3]>>garbage;
+   if (verbose>4) std::cout<<"Tetrahedra ("<<count<<") "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[count*4-1]<<std::endl;
+
+   montab=new CVWtab(count*4,tmint);
+   tmp=tmp.sprintf("NB%ld EV",this->nofile);
+   ok=this->insert_key(tmp,montab);
+
+   //swap on file if too big for memory in one cpu
+   //default 1GOctet/8(for double)/10(for arrays in memory at the same time)
+   if (Mvert*3>this->nbelem_limit_swap)
+     this->SwapOutOfMemory_key_mesh_wrap(QRegExp("NB",Qt::CaseSensitive,QRegExp::RegExp));
+   //beware record 6 lenght 1
+   //ferme le fichier :
+   Ff.close();
+   this->nbfiles++;
+   return true;
+}
+
 //************************************
 bool ghs3dprl_mesh_wrap::ReadFileNOBOITE(const QString FileName)
 //read file .noboite (volume)
@@ -654,14 +1068,14 @@ bool ghs3dprl_mesh_wrap::ReadFileNOBOITE(const QString FileName)
    QString tmp;
    std::fstream Ff(FileName.toLatin1().constData(),std::ios_base::in);
    long ne,np,npfixe,subnumber,reste;
-   bool ok;
+   //bool ok;
 
    if (!Ff.is_open()){
       std::cerr<<"Problem File '"<<FileName.toLatin1().constData()<<"' not open\n"<<std::endl;
       return false;
    }
 
-   //lit les donns :
+   //lit les donnees :
    Ff>>ne>>np>>npfixe;
    if (verbose>3){
       std::cout<<"NoboiteNumberOfElements="<<ne<<std::endl;
@@ -677,7 +1091,7 @@ bool ghs3dprl_mesh_wrap::ReadFileNOBOITE(const QString FileName)
 
    CVWtab *montab=new CVWtab(ne*4,tmint);
    tmp=tmp.sprintf("NB%ld EV",this->nofile);
-   ok=this->insert_key(tmp,montab);
+   /*ok=*/this->insert_key(tmp,montab);
 
    med_float *tmflo=new med_float[np*3];
    for (int i=0; i<np*3; i++) Ff>>tmflo[i];
@@ -685,7 +1099,7 @@ bool ghs3dprl_mesh_wrap::ReadFileNOBOITE(const QString FileName)
 
    montab=new CVWtab(np*3,tmflo);
    tmp=tmp.sprintf("NB%ld VC",this->nofile);
-   ok=this->insert_key(tmp,montab);
+   /*ok=*/this->insert_key(tmp,montab);
 
    Ff>>subnumber;
    if (verbose>2) std::cout<<"NumberOfSubdomains="<<subnumber<<std::endl;
@@ -714,7 +1128,7 @@ bool ghs3dprl_mesh_wrap::ReadFileNOBOITE(const QString FileName)
 
    montab=new CVWtab(subnumber*3,tmint);
    tmp=tmp.sprintf("NB%ld SN",this->nofile);
-   ok=this->insert_key(tmp,montab);
+   /*ok=*/this->insert_key(tmp,montab);
 
    //swap on file if too big for memory in one cpu
    //default 1GOctet/8(for double)/10(for arrays in memory at the same time)
@@ -734,7 +1148,7 @@ bool ghs3dprl_mesh_wrap::ReadFileNOBOITEB(const QString FileName)
 //but NOT parameter option of tepal
 //idem ReadFileNOBOITE with read unformatted
 {
-   bool ok;
+   //bool ok;
    QString tmp;
    std::cerr<<"Problem function ReadFileNOBOITEB\n"
        <<"(no FORTRAN binary format files in tepal)\n\n";
@@ -778,7 +1192,7 @@ bool ghs3dprl_mesh_wrap::ReadFileNOBOITEB(const QString FileName)
 
    CVWtab *montab=new CVWtab(ne*4,tmint);
    tmp=tmp.sprintf("NB%ld EV",this->nofile);
-   ok=this->insert_key(tmp,montab);
+   /*ok=*/this->insert_key(tmp,montab);
 
    fread(&reste,sizeof(long),1,Ff);
    //std::cout<<"info "<<reste<<" "<<np*3<<" "<<sizeof(med_float)<<std::endl;
@@ -792,7 +1206,7 @@ bool ghs3dprl_mesh_wrap::ReadFileNOBOITEB(const QString FileName)
 
    montab=new CVWtab(np*3,tmflo);
    tmp=tmp.sprintf("NB%ld VC",this->nofile);
-   ok=this->insert_key(tmp,montab);
+   /*ok=*/this->insert_key(tmp,montab);
 
    fread(&reste,sizeof(long),1,Ff);
    fread(&subnumber,sizeof(long),1,Ff);
@@ -809,7 +1223,7 @@ bool ghs3dprl_mesh_wrap::ReadFileNOBOITEB(const QString FileName)
    delete tlong;
    montab=new CVWtab(subnumber*3,tmint);
    tmp=tmp.sprintf("NB%ld SN",this->nofile);
-   ok=this->insert_key(tmp,montab);
+   /*ok=*/this->insert_key(tmp,montab);
 
    //swap on file if too big for memory in one cpu
    //default 1GOctet/8(for double)/10(for arrays in memory at the same time)
@@ -832,7 +1246,7 @@ bool ghs3dprl_mesh_wrap::ReadFilePOINTS(const QString FileName)
    long maxlen=128;
    bool ok=true;
 
-   //Lit les donns :
+   //Lit les donnees :
    QFile Ff(FileName);
    //NOT Raw because Raw=non-buffered file access
    //qt3 ok=Ff.open(IO_ReadOnly|IO_Translate);
@@ -986,7 +1400,7 @@ long ghs3dprl_mesh_wrap::SwapOutOfMemory_key_mesh_wrap(const QRegExp &rxp,
 //swap on file if not yet and if size greater than ifgreaterthan
 {
    long nb=0;
-   bool ok;
+   //bool ok;
    QHashIterator<QString,CVWtab*> it(this->mestab);
    while ( it.hasNext() ) {
      it.next();
@@ -998,7 +1412,7 @@ long ghs3dprl_mesh_wrap::SwapOutOfMemory_key_mesh_wrap(const QRegExp &rxp,
                    it.key().toLatin1().constData()<<
                    " size "<<it.value()->size<<">"<<ifgreaterthan<<std::endl;
            //free memory
-           ok=SwapOnFile(it.key(),this->path,it.value(),this->verbose);
+           /*ok=*/SwapOnFile(it.key(),this->path,it.value(),this->verbose);
        }
      }
    }
@@ -1025,11 +1439,11 @@ bool ghs3dprl_mesh_wrap::list_onekey_mesh_wrap(const QString &key)
 
 //************************************
 bool ghs3dprl_mesh_wrap::insert_key(const QString &key,CVWtab *tab)
-//insertion conditionn par limite this->nbelem_limit_swap
+//insertion conditionnee par limite this->nbelem_limit_swap
 //si tableaux contenus on dimension superieure
 //alors swap disque dans getenv(tmp) fichier temporaire binaire
 {
-   bool ok;
+   //bool ok;
    if (verbose>4)
       std::cout<<"insert key "<<key.toLatin1().constData()<<
             " size="<<tab->size<<std::endl;
@@ -1037,14 +1451,14 @@ bool ghs3dprl_mesh_wrap::insert_key(const QString &key,CVWtab *tab)
    if (this->nbelem_limit_swap<tab->size) {
       if (verbose>3) std::cout<<"insert key automatic SwapOnFile "<<
                            key.toLatin1().constData()<<std::endl;
-      ok=SwapOnFile(key,this->path,tab,this->verbose);
+      /*ok=*/SwapOnFile(key,this->path,tab,this->verbose);
    }
    this->mestab.insert(key,tab);
    return true;
 }
 //************************************
 CVWtab* ghs3dprl_mesh_wrap::restore_key(const QString &key)
-//retauration conditionn par limite nbelem
+//retauration conditionnee par limite nbelem
 //si tableaux contenus on dimension superieure a nbelem
 //alors swap disque dans getenv(tmp) fichier temporaire
 //alors lecture du fichier (et reallocate memory)
@@ -1201,6 +1615,7 @@ bool ghs3dprl_mesh_wrap::test_vertices_wrap()
    //for (int ifile=1; ifile <= this->nbfiles; ifile++)
    //for (int ineig=ifile+1; ineig <= this->nbfiles; ineig++)
    bool swap=false;
+   if (verbose>4)std::cout<<"test_vertices_wrap on nb files "<<this->nbfiles<<std::endl;
    for (int ifile=this->nbfiles; ifile >= 1; ifile--)
    for (int ineig=this->nbfiles; ineig >= ifile+1; ineig--)
    {
@@ -1294,7 +1709,7 @@ bool ghs3dprl_mesh_wrap::Find_VerticesDomainToVerticesSkin()
    if (!cooskin) return false;
    if (verbose>4)std::cout<<"NumberVerticesSKIN="<<cooskin->size/3<<std::endl;
    //ici pourrait creer BBtree sur skin
-   for (int ifile=1; ifile<=this->nbfiles; ifile++)
+   for (long ifile=1; ifile<=this->nbfiles; ifile++)
    {
       key1=key1.sprintf("NB%ld VC",ifile);
       coodom=this->restore_key(key1);
@@ -1353,7 +1768,7 @@ bool ghs3dprl_mesh_wrap::Write_masterxmlMEDfile()
 {
    QString tmp;
 
-   //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!first call
+   //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!first call create xml doc node
    if (idom==1)
    {
    //define master file (.xml) in memory
@@ -1370,9 +1785,9 @@ bool ghs3dprl_mesh_wrap::Write_masterxmlMEDfile()
    //Creating child nodes
    //Version tag
    med_int majeur,mineur,release;
-   //Quelle version de MED est utilis
+   //Quelle version de MED est utilisee
    MEDlibraryNumVersion(&majeur,&mineur,&release);
-   if (verbose>0) fprintf(stdout,"Files write with MED V%d.%d.%d\n",majeur,mineur,release);
+   if (verbose>0) fprintf(stdout,"File write %s with MED V%d.%d.%d\n",filemaster.c_str(),(int)majeur,(int)mineur,(int)release);
    node = xmlNewChild(root_node, 0, BAD_CAST "version",0);
    //xmlNewProp(node, BAD_CAST "maj", BAD_CAST int2string2(majeur).c_str());
    xmlNewProp(node, BAD_CAST "maj", BAD_CAST i2a(majeur).c_str());
@@ -1381,7 +1796,8 @@ bool ghs3dprl_mesh_wrap::Write_masterxmlMEDfile()
 
    //Description tag
    node = xmlNewChild(root_node,0, BAD_CAST "description",0);
-   xmlNewProp(node, BAD_CAST "what", BAD_CAST "tetrahedral mesh by tepal");
+   // .../INSTALL/MeshGems/include/meshgems/meshgems.h:11:#define MESHGEMS_VERSION_LONG "2.9-6"
+   xmlNewProp(node, BAD_CAST "what", BAD_CAST "tetrahedral mesh by MeshGems-Tetra-hpc 2.9-6 2019");
 #ifdef WIN32
   SYSTEMTIME  present;
   GetLocalTime ( &present );
@@ -1421,12 +1837,14 @@ bool ghs3dprl_mesh_wrap::Write_masterxmlMEDfile()
    xmlNewProp(mesh_node, BAD_CAST "name", BAD_CAST domainname.c_str());
    }
 
-   //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!all calls
+   //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!all calls add xml idom node
    {
+   fprintf(stdout,"Xml node write %s idom %d\n",filemaster.c_str(), (int)idom);
    char *hostname = getenv("HOSTNAME");
    node = xmlNewChild(files_node,0,BAD_CAST "subfile",0);
    xmlNewProp(node, BAD_CAST "id", BAD_CAST i2a(idom).c_str());
    node2 = xmlNewChild(node, 0, BAD_CAST "name", BAD_CAST distfilename);
+   
    if (hostname == NULL)
       node2 = xmlNewChild(node, 0, BAD_CAST "machine",BAD_CAST "localhost");
    else
@@ -1452,14 +1870,17 @@ bool ghs3dprl_mesh_wrap::Write_masterxmlMEDfile()
    //xmlNewProp(node2, BAD_CAST "number", BAD_CAST i2a(nbtetra4).c_str());
 
    //tepal2med_info about joints of one subdomain
-   xmlAddChild(node,joints_node);
+   fprintf(stdout,"MeshGems 2.9-6 tetra-hpc joints are not implemented\n");  //MeshGems 2.9-6 Salome 9.5.0 jan 2020
+   // not implemented ... empty joints ... does NOT work ... xmlAddChild(node,joints_node);
    //tepal2med_info about groups and families of one subdomain
    xmlAddChild(node,families.xml_groups());
    }
 
    //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!last call
+   fprintf(stdout,"xml node idom %d/%ld nb tetras total %ld\n", (int)idom, nbfilestot, nbtetrastotal);
    if (idom==nbfilestot)
    {
+   fprintf(stdout,"File write %s as last idom nb tetras total %ld\n",filemaster.c_str(), nbtetrastotal);
    node2 = xmlNewChild(info_node, 0, BAD_CAST "global",0);
    xmlNewProp(node2, BAD_CAST "tetrahedra_number", BAD_CAST i2a(nbtetrastotal).c_str());
    //save masterfile
@@ -1472,10 +1893,10 @@ bool ghs3dprl_mesh_wrap::Write_masterxmlMEDfile()
 
 
 //************************************
-bool ghs3dprl_mesh_wrap::Write_MEDfiles_v2(bool deletekeys)
+bool ghs3dprl_mesh_wrap::Write_MEDfiles_v2(bool /*deletekeys*/)
 //deletekeys=true to delete non utils keys and arrays "au fur et a mesure"
 {
-   bool ok=true,oktmp;
+   bool ok=true/*,oktmp*/;
    QString tmp,cmd;
    char description[MED_COMMENT_SIZE];
    char dtunit[MED_SNAME_SIZE+1]="_NO_UNIT";
@@ -1497,11 +1918,14 @@ bool ghs3dprl_mesh_wrap::Write_MEDfiles_v2(bool deletekeys)
    }
 
    //create file resume DOMAIN.joints.med of all joints for quick display (...may be...)
-   tmp=path+medname+tmp.sprintf("_joints.med",idom);
-   charendnull(distfilename,tmp,MED_COMMENT_SIZE);
-   fidjoint=MEDfileOpen(distfilename,MED_ACC_CREAT);
-   if (fidjoint<0) std::cerr<<"Problem MEDfileOpen "<<distfilename<<std::endl;
-   if (verbose>0) std::cout<<"CreateMEDFile for all joints <"<<distfilename<<">\n";
+   if (! for_multithread)
+   {
+    tmp=path+medname+tmp.sprintf("_joints.med");
+    charendnull(distfilename,tmp,MED_COMMENT_SIZE);
+    fidjoint=MEDfileOpen(distfilename,MED_ACC_CREAT);
+    if (fidjoint<0) std::cerr<<"Problem MEDfileOpen "<<distfilename<<std::endl;
+    if (verbose>0) std::cout<<"CreateMEDFile for all joints <"<<distfilename<<">\n";
+   }
 
    //copy file source/GHS3DPRL_skin.med as destination/DOMAIN.skin.med
    tmp=path+medname+"_skin.med";
@@ -1522,79 +1946,93 @@ bool ghs3dprl_mesh_wrap::Write_MEDfiles_v2(bool deletekeys)
                                                 cmd.toLatin1().constData()<<"> does not exist\n"; }
 
    //define family 0 if not existing, no groups
-   families.add("0","");
+   //La famille FAMILLE_ZERO n'a pas été trouvée, elle est obligatoire
+   families.add("0","FAMILLE_ZERO");
    //define family Group_of_New_Nodes (which not exists before tetrahedra)
    famallnodes=0;
    if (QString("All_Nodes").contains(deletegroups)==0){
-      oktmp=families.get_number_of_new_family(1,&famallnodes,&tmp);
+      /*oktmp=*/families.get_number_of_new_family(1,&famallnodes,&tmp);
       families.add(tmp,"All_Nodes");
    }
    else if (verbose>3) std::cout<<"--deletegroups matches \"All_Nodes\"\n";
    
    famalltria3=0;
    if (QString("All_Faces").contains(deletegroups)==0){
-      oktmp=families.get_number_of_new_family(-1,&famalltria3,&tmp);
+      /*oktmp=*/families.get_number_of_new_family(-1,&famalltria3,&tmp);
       families.add(tmp,"All_Faces");
    }
    else if (verbose>3) std::cout<<"--deletegroups matches \"All_Faces\"\n";
 
    famalltetra4=0;
    if (QString("All_Tetrahedra").contains(deletegroups)==0){
-      oktmp=families.get_number_of_new_family(-1,&famalltetra4,&tmp);
+      /*oktmp=*/families.get_number_of_new_family(-1,&famalltetra4,&tmp);
       families.add(tmp,"All_Tetrahedra");
    }
    else if (verbose>3) std::cout<<"--deletegroups matches \"All_Tetrahedra\"\n";
 
    famnewnodes=0;
    if (QString("New_Nodes").contains(deletegroups)==0){
-      oktmp=families.get_number_of_new_family(1,&famnewnodes,&tmp);
+      /*oktmp=*/families.get_number_of_new_family(1,&famnewnodes,&tmp);
       families.add(tmp,"New_Nodes");
    }
    else if (verbose>3) std::cout<<"--deletegroups matches \"New_Nodes\"\n";
    
    famnewtria3=0;
    if (QString("New_Faces").contains(deletegroups)==0){
-      oktmp=families.get_number_of_new_family(-1,&famnewtria3,&tmp);
+      /*oktmp=*/families.get_number_of_new_family(-1,&famnewtria3,&tmp);
       families.add(tmp,"New_Faces");
    }
    else if (verbose>3) std::cout<<"--deletegroups matches \"New_Faces\"\n";
    
    famnewtetra4=0;
    if (QString("New_Tetrahedra").contains(deletegroups)==0){
-      oktmp=families.get_number_of_new_family(-1,&famnewtetra4,&tmp);
+      /*oktmp=*/families.get_number_of_new_family(-1,&famnewtetra4,&tmp);
       families.add(tmp,"New_Tetrahedra");
    }
    else if (verbose>3) std::cout<<"--deletegroups matches \"New_Tetrahedra\"\n";
 
    if (verbose>6){std::cout<<"\nIntermediatesFamilies\n"; families.write();}
-   if (verbose>6) std::cout<<"\nNumber0fFiles="<<nbfilestot<<std::endl;
+   //if (verbose>6) std::cout<<"\nNumber0fFiles="<<nbfilestot<<std::endl;
    familles intermediatesfamilies=families;
    //initialisations on all domains
    nbtetrastotal=0;
 
    //loop on the domains
    //for (idom=1; idom<=nbfilestot; idom++) {
+   if (for_multithread) {
+     nbfilestot=1;
+     std::cout<<"\nset NumberOfFiles only one domain file as multithread="<<nbfilestot<<std::endl;
+   }
+
+   // if (verbose>6) 
+   std::cout<<"\nNumberOfFiles="<<nbfilestot<<std::endl;
+
    for (idom=1; idom<=nbfilestot; idom++) {
    
+      this->nbvert=0;  // will be set for current loop idom
+      this->nbedge=0;
+      this->nbtria=0;
+      this->nbtetr=0;
+
       this->nofile=idom;
       //restore initial context of families
       if (idom>1) families=intermediatesfamilies;
       //if (idom>1) continue;
-      tmp=path+medname+tmp.sprintf("_%d.med",idom);
+      tmp=path+medname+tmp.sprintf("_%d.med",(int)idom);
       charendnull(distfilename,tmp,MED_COMMENT_SIZE);
 
       //std::cout<<"<"<<distfilename<<">"<<std::endl;
       fid=MEDfileOpen(distfilename,MED_ACC_CREAT);
       if (fid<0) {std::cerr<<"Problem MEDfileOpen "<<distfilename<<std::endl; goto erreur;}
-      if (verbose>0){
-         if (verbose>2) std::cout<<std::endl;
+      if (verbose>2) {
+         std::cout<<std::endl;
          std::cout<<"CreateMEDFile "<<idom<<" <"<<distfilename<<">\n";
       }
  
       //create mesh
-      tmp=medname+tmp.sprintf("_%d",idom);
+      tmp=medname+tmp.sprintf("_%d",(int)idom);
       charendnull(nomfinal,tmp,MED_NAME_SIZE);
-      tmp=tmp.sprintf("domain %d among %d",idom,nbfilestot);
+      tmp=tmp.sprintf("domain %d among %ld",(int)idom,nbfilestot);
       charendnull(description,tmp,MED_COMMENT_SIZE);
 
       if (verbose>4) std::cout<<"Description : "<<description<<std::endl;
@@ -1602,44 +2040,56 @@ bool ghs3dprl_mesh_wrap::Write_MEDfiles_v2(bool deletekeys)
       if (err<0) {std::cerr<<"Problem MEDmeshCr"<<nomfinal<<std::endl; goto erreur;}
 
       if (!idom_nodes()) {std::cerr<<"Problem on Nodes"<<std::endl; goto erreur;}
+      if (verbose>4) std::cout<<"\nEnd of Nodes ***\n"<<std::endl;
       if (!idom_edges()) {std::cerr<<"Problem on Edges"<<std::endl; goto erreur;}
+      if (verbose>4) std::cout<<"\nEnd of Edges ***\n"<<std::endl;
       if (!idom_faces()) {std::cerr<<"Problem on Faces"<<std::endl; goto erreur;}
+      if (verbose>4) std::cout<<"\nEnd of Faces ***\n"<<std::endl;
       if (!idom_tetras()) {std::cerr<<"Problem on tetrahedra"<<std::endl; goto erreur;}
-      if (!idom_joints()) {std::cerr<<"Problem on Joints"<<std::endl; goto erreur;}
-
-      if (verbose>6){std::cout<<"\nFinalsFamilies\n"; families.write();}
-      //for nodes families
-      nb=create_families(fid,1);
-      if (verbose>5)std::cout<<"NumberOfFamiliesNodes="<<nb<<std::endl;
-
-      err=MEDmeshEntityFamilyNumberWr(fid,nomfinal,MED_NO_DT,MED_NO_IT,MED_NODE,MED_UNDEF_GEOMETRY_TYPE,nbnodes,famnodes);
-      if (verbose>8)
-         std::cout<<"MEDmeshEntityFamilyNumberWr nodes "<<nbnodes<<":"<<
-               famnodes[0]<<"..."<<famnodes[nbnodes-1]<<" "<<std::endl;
-      delete[] famnodes;
-      if (err<0) std::cerr<<"Problem MEDmeshEntityFamilyNumberWr nodes"<<std::endl;
-
-      //for others families
-      nb=create_families(fid,-1);
-      if (verbose>5)std::cout<<"NumberOfFamiliesFacesAndEdgesEtc="<<nb<<std::endl;
-
-      err=MEDmeshEntityFamilyNumberWr(fid,nomfinal,MED_NO_DT,MED_NO_IT,MED_CELL,MED_TRIA3,nbtria3,famtria3);
-      if (verbose>8)
-         std::cout<<"MEDmeshEntityFamilyNumberWr tria3 "<<nbtria3<<":"<<
-               famtria3[0]<<"..."<<famtria3[nbtria3-1]<<" "<<std::endl;
-      delete[] famtria3;
-      if (err<0) std::cerr<<"Problem MEDmeshEntityFamilyNumberWr tria3"<<std::endl;
-
-      err=MEDmeshEntityFamilyNumberWr(fid,nomfinal,MED_NO_DT,MED_NO_IT,MED_CELL,MED_TETRA4,nbtetra4,famtetra4);
-      if (verbose>8)
-         std::cout<<"MEDmeshEntityFamilyNumberWr tetra4 "<<nbtetra4<<":"<<
-               famtetra4[0]<<"..."<<famtetra4[nbtria3-1]<<" "<<std::endl;
-      delete[] famtetra4;
-      if (err<0) std::cerr<<"Problem MEDmeshEntityFamilyNumberWr tria3"<<std::endl;
+      if (verbose>4) std::cout<<"\nEnd of Tetrahedra ***\n"<<std::endl;
+      
+      //non existing files msg mh-tetra_hpc v2.1.11
+      //if (!idom_joints()) {std::cerr<<"Problem on Joints"<<std::endl; goto erreur;}
 
+      // if (!for_multithread) 
+      {
+        if (verbose>6){std::cout<<"\nFinalsFamilies\n"; families.write();}
+        //for nodes families
+        nb=create_families(fid,1);
+        if (verbose>5)std::cout<<"NumberOfFamiliesNodes="<<nb<<" name "<<nomfinal<<std::endl;
+
+        if (verbose>8)
+          std::cout<<"MEDmeshEntityFamilyNumberWr nodes "<<nbnodes<<":"<<
+                famnodes[0]<<"..."<<famnodes[nbnodes-1]<<" "<<std::endl;
+
+        err=MEDmeshEntityFamilyNumberWr(fid,nomfinal,MED_NO_DT,MED_NO_IT,MED_NODE,MED_UNDEF_GEOMETRY_TYPE,nbnodes,famnodes);
+        delete[] famnodes;
+        
+        if (err<0) std::cerr<<"Problem MEDmeshEntityFamilyNumberWr nodes"<<std::endl;
+
+        //for others families
+        nb=create_families(fid,-1);
+        if (verbose>5)std::cout<<"NumberOfFamiliesFacesAndEdgesEtc="<<nb<<std::endl;
+
+        err=MEDmeshEntityFamilyNumberWr(fid,nomfinal,MED_NO_DT,MED_NO_IT,MED_CELL,MED_TRIA3,nbtria3,famtria3);
+        if (verbose>8)
+          std::cout<<"MEDmeshEntityFamilyNumberWr tria3 "<<nbtria3<<":"<<
+                famtria3[0]<<"..."<<famtria3[nbtria3-1]<<" "<<std::endl;
+        delete[] famtria3;
+        if (err<0) std::cerr<<"Problem MEDmeshEntityFamilyNumberWr tria3"<<std::endl;
+
+        err=MEDmeshEntityFamilyNumberWr(fid,nomfinal,MED_NO_DT,MED_NO_IT,MED_CELL,MED_TETRA4,nbtetra4,famtetra4);
+        if (verbose>8)
+          std::cout<<"MEDmeshEntityFamilyNumberWr tetra4 "<<nbtetra4<<":"<<
+                famtetra4[0]<<"..."<<famtetra4[nbtria3-1]<<" "<<std::endl;
+        delete[] famtetra4;
+        if (err<0) std::cerr<<"Problem MEDmeshEntityFamilyNumberWr tria3"<<std::endl;
+      }
+    
       MEDfileClose(fid); //no error
-      //master.xml writings
-      oktmp=Write_masterxmlMEDfile();
+      //master.xml writings if mpi mode
+      if (!for_multithread)
+        /*oktmp=*/Write_masterxmlMEDfile();
       continue;       //and loop on others domains
 
       erreur:         //error
@@ -1647,9 +2097,12 @@ bool ghs3dprl_mesh_wrap::Write_MEDfiles_v2(bool deletekeys)
       MEDfileClose(fid); //but loop on others domains
 
    }
-   MEDfileClose(fidjoint); //no error
+   
+   if (! for_multithread)
+     MEDfileClose(fidjoint); //no error
    if (verbose>0)std::cout<<"\nTotalNumberOftetrahedra="<<nbtetrastotal<<std::endl;
-
+   ok = true;
+   
    return ok;
 }
 
@@ -1658,27 +2111,37 @@ bool ghs3dprl_mesh_wrap::idom_nodes()
 {
    bool ok=true;
    QString tmp,key,key1,key2,key3;
-   CVWtab *tab,*tab1,*tab2,*tab3;
+   CVWtab *tab,*tab1,*tab2/*,*tab3*/;
    med_int i,j,*arrayi;
-   int xx;
+   //int xx;
 
       //writing node(vertices) coordinates
       //NBx VC=files.NoBoite Vertex Coordinates
-      key=key.sprintf("NB%d VC",idom); //files.NoBoite Vertex Coordinates
+      key=key.sprintf("NB%d VC",(int)idom); //files.NoBoite Vertex Coordinates
       tab=this->restore_key(key); //tab1=this->mestab[key1];
       if (!tab) {
-         tmp=pathini+casename+tmp.sprintf(format.toLatin1().constData(),nbfilestot,idom)+".noboite";
-         ok=this->ReadFileNOBOITE(tmp);
+         if (!for_tetrahpc) {
+            tmp=pathini+casename+tmp.sprintf(format.toLatin1().constData(),nbfilestot,idom)+".noboite";
+            ok=this->ReadFileNOBOITE(tmp);
+         }
+         if (for_tetrahpc) {
+            tmp=pathini+casename+"_out"+tmp.sprintf(format_tetra.toLatin1().constData(),idom)+".mesh";
+            ok=this->ReadFileMESH(tmp);
+            if (for_multithread) { // inexisting file GHS3DPRL_out.000001.global
+               this->ReadFileDefaultGLOBAL(this->nbvert, this->nbedge, this->nbtria, this->nbtetr);
+            }
+         }
          tab=this->restore_key(key); //tab1=this->mestab[key1];
          if (!tab) return false;
       }
-      tmp=tmp.sprintf("NB%d SN",idom);
+      tmp=tmp.sprintf("NB%d SN",(int)idom);
       //qt3 xx=this->remove_key_mesh_wrap(QRegExp(tmp,true,true));
-      xx=this->remove_key_mesh_wrap(QRegExp(tmp,Qt::CaseSensitive,QRegExp::RegExp));
-      nbnodes=tab->size/3;
+      /*xx=*/this->remove_key_mesh_wrap(QRegExp(tmp,Qt::CaseSensitive,QRegExp::RegExp));
+      nbnodes=this->nbvert; // for current idom
+      
       err=MEDmeshNodeCoordinateWr(fid,nomfinal,MED_NO_DT,MED_NO_IT,0.,MED_FULL_INTERLACE,nbnodes,tab->tmflo);
       if (err<0) {std::cerr<<"Problem MEDmeshNodeCoordinateWr"<<std::endl; return false;}
-      if (verbose>4)std::cout<<"NumberOfNodes="<<nbnodes<<std::endl;
+      if (verbose>4) std::cout<<"NumberOfNodes="<<nbnodes<<std::endl;
 
       //writing indices of nodes
       arrayi=new med_int[nbnodes];
@@ -1687,21 +2150,29 @@ bool ghs3dprl_mesh_wrap::idom_nodes()
       delete[] arrayi;
       if (err<0) {std::cerr<<"Problem MEDmeshEntityNumberWr of nodes"<<std::endl; return false;}
 
-      key1=key1.sprintf("GL%d VE",idom); //global numerotation 
+    // if (!for_multithread) 
+    {
+      key1=key1.sprintf("GL%d VE",(int)idom); //global numerotation 
       tab1=this->restore_key(key1); //tab1=this->mestab[key1];
       if (!tab1) {
-         tmp=pathini+casename+tmp.sprintf(format.toLatin1().constData(),nbfilestot,idom)+".glo";
-         ok=this->ReadFileGLO(tmp);
+         if (!for_tetrahpc) {
+            tmp=pathini+casename+tmp.sprintf(format.toLatin1().constData(),nbfilestot,idom)+".glo";
+            ok=this->ReadFileGLO(tmp);
+         }
+         if (for_tetrahpc) {
+            tmp=pathini+casename+"_out"+tmp.sprintf(format_tetra.toLatin1().constData(),idom)+".global";
+            ok=this->ReadFileGLOBAL(tmp);
+         }
          if (!ok) {std::cerr<<"Problem file "<<tmp.toLatin1().constData()<<std::endl; return false;}
          tab1=this->restore_key(key1); //tab1=this->mestab[key1];
          if (!tab1) return false;
       }
       if (nbnodes!=tab1->size){std::cerr<<"Problem size GLi VE!=nbnodes!"<<std::endl; return false;}
 
-      key2=key2.sprintf("SKIN_VERTICES_FAMILIES",idom); //on global numerotation 
+      key2=key2.sprintf("SKIN_VERTICES_FAMILIES"); //on global numerotation 
       tab2=this->restore_key(key2); //tab1=this->mestab[key1];
       med_int nbskin=0; 
-      if (tab2) med_int nbskin=tab2->size;
+      if (tab2) nbskin=tab2->size;
       //for (i=0; i<nbskin; i++) std::cout<<i<<" "<<tab2->tmint[i]<<std::endl;
 
       //set families of nodes existing in GHS3DPRL_skin.med
@@ -1728,12 +2199,13 @@ bool ghs3dprl_mesh_wrap::idom_nodes()
       //writing nodes(vertices) global numbering
       err=MEDmeshGlobalNumberWr(fid,nomfinal,MED_NO_DT,MED_NO_IT,MED_NODE,MED_UNDEF_GEOMETRY_TYPE,nbnodes,tab1->tmint);
       if (err<0){std::cerr<<"Problem MEDmeshGlobalNumberWr nodes"<<std::endl; return false;}
-
+    }
+    
    return ok;
 }
 
-/*
 //************************************
+/*
 bool ghs3dprl_mesh_wrap::set_one_more_family_old(med_int *fami, med_int *more, med_int nb)
 //fuse array of med_int families more et fami as kind of groups 
 //because there are possibilities of intersections
@@ -1765,7 +2237,7 @@ bool ghs3dprl_mesh_wrap::set_one_more_family(med_int *fami, med_int *more, med_i
 //because there are possibilities of intersections
 {
    QString tmp;
-   med_int i,ii,j,newfam,morfam,oldfam,morfami,oldfami,i_zero,nb_fam,nb_max,nb_tot,nb_mess;
+   med_int i,ii,newfam,morfam,oldfam,morfami,oldfami,i_zero,nb_fam,nb_max,nb_tot,nb_mess;
    med_int *newfami;
 
    nb_fam=families.fam.size(); //on families negative and positive
@@ -1828,6 +2300,7 @@ bool ghs3dprl_mesh_wrap::idom_edges()
    bool ok=true;
    QString tmp;
    nbseg2=0;
+   this->nbedge=0;
    return ok;
 }
 
@@ -1836,12 +2309,12 @@ bool ghs3dprl_mesh_wrap::idom_faces()
 {
    bool ok=true;
    QString tmp,key,key1,key2,key3;
-   CVWtab *tab,*tab1,*tab2,*tab3;
-   med_int ii,i,j,*arrayi;
-   int xx;
+   CVWtab *tab1,*tab2;
+   med_int /*ii,*/i,j,*arrayi;
+   //int xx;
 
       //writing connectivity of faces triangles of wrap by nodes
-      key1=key1.sprintf("FC%d",idom); //files.FaCes faces (wrap and triangles only)
+   key1=key1.sprintf("FC%d",(int)idom); //files.FaCes faces (wrap and triangles only)
       tab1=this->restore_key(key1); //tab1=this->mestab[key1];
       if (!tab1) {
          tmp=pathini+casename+tmp.sprintf(format.toLatin1().constData(),nbfilestot,idom)+".faces";
@@ -1849,18 +2322,21 @@ bool ghs3dprl_mesh_wrap::idom_faces()
          tab1=this->restore_key(key1);
          if (!tab1) return false;
       }
-      nbtria3=tab1->size/7;
+      nbtria3=tab1->size/3;
+      this->nbtria=nbtria3; // for current idom
+
       if (verbose>4) std::cout<<"NumberOfTriangles="<<nbtria3<<std::endl;
-      arrayi=new med_int[nbtria3*3];
-      ii=0,i=0 ;
-      for (j=0; j<nbtria3 ; j++){
-         arrayi[ii]=tab1->tmint[i]; ii++;
-         arrayi[ii]=tab1->tmint[i+1]; ii++;
-         arrayi[ii]=tab1->tmint[i+2]; ii++;
-         i=i+7;
-      }
-      err=MEDmeshElementConnectivityWr(fid,nomfinal,MED_NO_DT,MED_NO_IT,0.,MED_CELL,MED_TRIA3,MED_NODAL,MED_FULL_INTERLACE,nbtria3,arrayi);
-      delete[] arrayi; //need immediately more little array
+      //arrayi=new med_int[nbtria3*3];
+      //ii=0,i=0 ;
+      //for (j=0; j<nbtria3 ; j++){
+      //   arrayi[ii]=tab1->tmint[i]; ii++;
+      //   arrayi[ii]=tab1->tmint[i+1]; ii++;
+      //   arrayi[ii]=tab1->tmint[i+2]; ii++;
+      //   i=i+7;
+      //}
+      //err=MEDmeshElementConnectivityWr(fid,nomfinal,MED_NO_DT,MED_NO_IT,0.,MED_CELL,MED_TRIA3,MED_NODAL,MED_FULL_INTERLACE,nbtria3,arrayi);
+      err=MEDmeshElementConnectivityWr(fid,nomfinal,MED_NO_DT,MED_NO_IT,0.,MED_CELL,MED_TRIA3,MED_NODAL,MED_FULL_INTERLACE,nbtria3,tab1->tmint);
+      //delete[] arrayi; //need immediately more little array
       if (err<0){std::cerr<<"Problem MEDmeshElementConnectivityWr for triangles connectivity"<<std::endl; return false;}
       
       //writing indices of faces triangles of wrap
@@ -1874,45 +2350,49 @@ bool ghs3dprl_mesh_wrap::idom_faces()
       if (err<0){std::cerr<<"Problem MEDmeshEntityNumberWr of triangles"<<std::endl; return false;}
 
       //GLx FA=files.GLo FAces
-      key1=key1.sprintf("GL%d FA",idom);
-      tab1=this->restore_key(key1); //tab1=this->mestab[key1];
-      if (nbtria3!=tab1->size){std::cerr<<"Problem size GLi FA!=nbtria3!"<<std::endl; return false;}
-
-      key2=key2.sprintf("SKIN_TRIA3_FAMILIES",idom); //on global numerotation 
-      tab2=this->restore_key(key2); //tab1=this->mestab[key1];
-      med_int nbskin=0; 
-      if (tab2) nbskin=tab2->size;
+      // if (!for_multithread) 
+      {
+        key1=key1.sprintf("GL%d FA",(int)idom);
+        tab1=this->restore_key(key1); //tab1=this->mestab[key1];
+        if (nbtria3!=tab1->size){std::cerr<<"Problem size GLi FA!=nbtria3!"<<std::endl; return false;}
       
-      //set families of faces existing in GHS3DPRL_skin.med
-      med_int nb=nbtria3;
-      famtria3=new med_int[nb];
-      for (i=0; i<nb ; i++) famtria3[i]=famalltria3;
-      med_int * fammore=new med_int[nb];
-      for (i=0; i<nb ; i++) fammore[i]=famnewtria3;
-
-      //set families of faces of skin
-      for (i=0; i<nb ; i++){
-         j=tab1->tmint[i]-1; //
-         if (j<nbskin){
-            fammore[i]=tab2->tmint[j];
-         }
-      }
-      ok=set_one_more_family(famtria3,fammore,nb);
-      delete[] fammore;
       
-      //writing faces(triangles) global numbering
-      if (verbose>2)
-         std::cout<<"CreateMEDglobalNumerotation_Faces "<<key1.toLatin1().constData()<<" "<<tab1->size<<std::endl;
-      err=MEDmeshGlobalNumberWr(fid,nomfinal,MED_NO_DT,MED_NO_IT,MED_CELL,MED_TRIA3,tab1->size,tab1->tmint);
-      if (err<0){std::cerr<<"Problem MEDmeshGlobalNumberWr faces"<<std::endl; return false;}
-
-      //xx=this->remove_key_mesh_wrap(QRegExp("FC*",true,true));
-      tmp=tmp.sprintf("GL%d FA",idom);
-      //qt3 xx=this->remove_key_mesh_wrap(QRegExp(tmp,true,true));
-      xx=this->remove_key_mesh_wrap(QRegExp(tmp,Qt::CaseSensitive,QRegExp::RegExp));
-      tmp=tmp.sprintf("GL%d VE",idom);
-      //qt3 xx=this->remove_key_mesh_wrap(QRegExp(tmp,true,true));
-      xx=this->remove_key_mesh_wrap(QRegExp(tmp,Qt::CaseSensitive,QRegExp::RegExp));
+        key2=key2.sprintf("SKIN_TRIA3_FAMILIES"); //on global numerotation 
+        tab2=this->restore_key(key2); //tab1=this->mestab[key1];
+        med_int nbskin=0; 
+        if (tab2) nbskin=tab2->size;
+        
+        //set families of faces existing in GHS3DPRL_skin.med
+        med_int nb=nbtria3;
+        famtria3=new med_int[nb];
+        for (i=0; i<nb ; i++) famtria3[i]=famalltria3;
+        med_int * fammore=new med_int[nb];
+        for (i=0; i<nb ; i++) fammore[i]=famnewtria3;
+
+        //set families of faces of skin
+        for (i=0; i<nb ; i++){
+          j=tab1->tmint[i]-1; //
+          if (j<nbskin){
+              fammore[i]=tab2->tmint[j];
+          }
+        }
+        ok=set_one_more_family(famtria3,fammore,nb);
+        delete[] fammore;
+        
+        //writing faces(triangles) global numbering
+        if (verbose>2)
+          std::cout<<"CreateMEDglobalNumerotation_Faces "<<key1.toLatin1().constData()<<" "<<tab1->size<<std::endl;
+        err=MEDmeshGlobalNumberWr(fid,nomfinal,MED_NO_DT,MED_NO_IT,MED_CELL,MED_TRIA3,tab1->size,tab1->tmint);
+        if (err<0){std::cerr<<"Problem MEDmeshGlobalNumberWr faces"<<std::endl; return false;}
+
+        ///*xx=*/this->remove_key_mesh_wrap(QRegExp("FC*",true,true));
+        tmp=tmp.sprintf("GL%d FA",(int)idom);
+        //qt3 /*xx=*/this->remove_key_mesh_wrap(QRegExp(tmp,true,true));
+        /*xx=*/this->remove_key_mesh_wrap(QRegExp(tmp,Qt::CaseSensitive,QRegExp::RegExp));
+        tmp=tmp.sprintf("GL%d VE",(int)idom);
+        //qt3 /*xx=*/this->remove_key_mesh_wrap(QRegExp(tmp,true,true));
+        /*xx=*/this->remove_key_mesh_wrap(QRegExp(tmp,Qt::CaseSensitive,QRegExp::RegExp));
+      }
 
    return ok;
 }
@@ -1923,36 +2403,33 @@ bool ghs3dprl_mesh_wrap::idom_joints()
    bool ok=true;
    QString tmp,namejoint,key,key1,key2;
    CVWtab *tab,*tab1,*tab2;
-   med_int ineig,ii,jj,i,j,k,*arrayi,nb,famjoint,*fammore,*inodes,*arrayfaces;
+   med_int ineig,ii,jj,i,j,k,*arrayi,nb,famjoint,*inodes,*arrayfaces;
    med_float *arraynodes;
    char namejnt[MED_NAME_SIZE+1];  //no more 32
    char namedist[MED_NAME_SIZE+1];
    char descjnt[MED_COMMENT_SIZE+1];
-   med_int numfam_ini_wrap=100;
+   //med_int numfam_ini_wrap=100;
    joints_node=xmlNewNode(NULL, BAD_CAST "joints");  //masterfile.xml
    med_int nbjoints=0,nbnodesneig,nbtria3neig;
    std::string sjoints=""; //which domains are neighbourg
-   int xx;
+   //int xx;
    char dtunit[MED_SNAME_SIZE+1]="_NO_UNIT";
    char axisname[MED_SNAME_SIZE*3+1]="x               y               z               ";
    char axisunit[MED_SNAME_SIZE*3+1]="_NO_UNIT        _NO_UNIT        _NO_UNIT        ";
 
-      tmp=tmp.sprintf("MS%d *",idom);
+      tmp=tmp.sprintf("MS%d *",(int)idom);
       //read file .msg if not done
       //qt3 if (this->nb_key_mesh_wrap(QRegExp(tmp,true,true))<=0) {
       if (this->nb_key_mesh_wrap(QRegExp(tmp,Qt::CaseSensitive,QRegExp::RegExp))<=0) {
          this->nofile=idom;
-         /*old version with xml parser too slow
-         ghs3dprl_msg_parser handler;
-         handler.mailw=this;
-         QXmlSimpleReader reader;
-         reader.setContentHandler(&handler);
-         tmp=pathini+casename+tmp.sprintf(format,nbfilestot,idom)+".msg";
-         QFile File(tmp);
-         QXmlInputSource source(&File);
-         reader.parse(source);
-         File.close();*/
-         tmp=pathini+casename+tmp.sprintf(format.toLatin1().constData(),nbfilestot,idom)+".msg";
+         
+         if (!for_tetrahpc) {
+            tmp=pathini+casename+tmp.sprintf(format.toLatin1().constData(),nbfilestot,idom)+".msg";
+         }
+         if (for_tetrahpc) {
+            tmp=pathini+casename+tmp.sprintf(format_tetra.toLatin1().constData(),idom)+".msg";
+         }
+
          ok=this->ReadFileMSGnew(tmp);
          if (!ok) {
             std::cerr<<"Problem in file "<<tmp.toLatin1().constData()<<std::endl;
@@ -1966,14 +2443,21 @@ bool ghs3dprl_mesh_wrap::idom_joints()
 
          //!*************nodes
          //std::cout<<"\n    nodes joints\n";
-         key1=key1.sprintf("MS%d NE%d VE SE",idom,ineig); //SE or RE identicals
+         key1=key1.sprintf("MS%d NE%d VE SE",(int)idom,(int)ineig); //SE or RE identicals
          tab1=restore_key(key1);
          if (!tab1) continue; //case (ifile,ineig) are not neighbours=>no joints
-         key1=key1.sprintf("MS%d NE%d VE SE",ineig,idom); //SE or RE identicals
+         key1=key1.sprintf("MS%d NE%d VE SE",(int)ineig,(int)idom); //SE or RE identicals
          tab2=this->restore_key(key1);
          //if not yet loaded (first time) try to load necessary file msg of neighbourg
          if (!tab2) {
-            tmp=pathini+casename+tmp.sprintf(format.toLatin1().constData(),nbfilestot,ineig)+".msg";
+            
+            if (!for_tetrahpc) {
+               tmp=pathini+casename+tmp.sprintf(format.toLatin1().constData(),nbfilestot,ineig)+".msg";
+            }
+            if (for_tetrahpc) {
+               tmp=pathini+casename+tmp.sprintf(format_tetra.toLatin1().constData(),ineig)+".msg";
+            }
+            
             this->nofile=ineig; //neighbourg file
             ok=this->ReadFileMSGnew(tmp);
             this->nofile=idom;  //restaure initial domain
@@ -1996,11 +2480,11 @@ bool ghs3dprl_mesh_wrap::idom_joints()
          sjoints=sjoints+" "+i2a(ineig);
          if (verbose>4)
             std::cout<<"NumberOfNodesOfJoint_"<<idom<<"_"<<ineig<<"="<<nb<<std::endl;
-         namejoint=namejoint.sprintf("JOINT_%d_%d_Nodes",idom,ineig);
+         namejoint=namejoint.sprintf("JOINT_%d_%d_Nodes",(int)idom,(int)ineig);
          strcpy(namejnt,namejoint.toLatin1().constData());
-         tmp=tmp.sprintf("JOINT_%d_%d among %d domains of ",idom,ineig,nbfilestot)+nomfinal;
+         tmp=tmp.sprintf("JOINT_%d_%d among %ld domains of ",(int)idom,(int)ineig,nbfilestot)+nomfinal;
          strcpy(descjnt,tmp.toLatin1().constData());
-         tmp=medname+tmp.sprintf("_%d",ineig);
+         tmp=medname+tmp.sprintf("_%d",(int)ineig);
          strcpy(namedist,tmp.toLatin1().constData());
          err=MEDsubdomainJointCr(fid,nomfinal,namejnt,descjnt,ineig,namedist);
          if (err<0) std::cerr<<"Problem MEDsubdomainJointCr"<<std::endl;
@@ -2011,22 +2495,22 @@ bool ghs3dprl_mesh_wrap::idom_joints()
             families.add(tmp,namejoint);
          }
 
-         key=key.sprintf("NB%d VC",idom); //files.NoBoite Vertex Coordinates
+         key=key.sprintf("NB%d VC",(int)idom); //files.NoBoite Vertex Coordinates
          tab=this->restore_key(key); //tab1=this->mestab[key1];
-         //nbnodes=tab->size/3;
+         nbnodes=tab->size/3;
 
          //writing correspondence nodes-nodes
          //two indices for one correspondence
          arrayi=new med_int[nb*2];
          arraynodes=new med_float[nbnodesneig*3];  //for file DOMAIN_join.med
-         inodes=new med_int[nbnodes];            //for file DOMAIN_join.med
+         inodes=new med_int[nbnodes];              //for file DOMAIN_join.med
          med_int * fammore=new med_int[nbnodes];
-         for (i=0; i<nbnodes ; i++) {fammore[i]=0; inodes[i]=-1;}
-         ii=0; jj=0; k=0;
+         for (i=0; i<nbnodes ; i++) {fammore[i]=0; inodes[i]=-2;}  //precautions
+         ii=0; jj=0; k=1;
          for (i=0; i<nb ; i++){
             //no need because <send> equals <receive> tab1->tmint[i]==tab2->tmint[i]
-            j=tab1->tmint[i]-1; //contents of tab1 1 to nb
-            inodes[j]=k; k++;   //indices 0->n-1 of nodes of joint from nodes of domain
+            j=tab1->tmint[i]-1; //contents of tab1 1->nb, j 0->nb-1
+            inodes[j]=k; k++;   //contents of inodes 1->n ,nodes of joint from nodes of domain
             arraynodes[jj]=tab->tmflo[j*3]; jj++;
             arraynodes[jj]=tab->tmflo[j*3+1]; jj++;
             arraynodes[jj]=tab->tmflo[j*3+2]; jj++;
@@ -2049,7 +2533,7 @@ bool ghs3dprl_mesh_wrap::idom_joints()
          //writing correspondence triangles-triangles
          //std::cout<<"\n    faces joints\n";
          nbtria3neig=0;
-         key1=key1.sprintf("MS%d NE%d FA SE",idom,ineig); //SE or RE identicals
+         key1=key1.sprintf("MS%d NE%d FA SE",(int)idom,(int)ineig); //SE or RE identicals
          tab1=this->restore_key(key1); //tab1=this->mestab[key1];
          if (!tab1){
             if (verbose>4)
@@ -2058,17 +2542,17 @@ bool ghs3dprl_mesh_wrap::idom_joints()
          }
          else //have to set xml may be no faces but nodes in a joint!
          {
-         key1=key1.sprintf("MS%d NE%d FA SE",ineig,idom); //SE or RE identicals
+         key1=key1.sprintf("MS%d NE%d FA SE",(int)ineig,(int)idom); //SE or RE identicals
          tab2=this->restore_key(key1);
          if (!tab2) std::cerr<<"Problem existing triangles of joint in domain "<<idom<<
-                          " with none in neighbourg "<<ineig<<" files .msg"<<std::endl;
+                               " with none in neighbourg "<<ineig<<" files .msg"<<std::endl;
          nb=tab1->size; nbtria3neig=tab2->size;
          if (nb!=nbtria3neig) {
             std::cerr<<"Problem in file "<<tmp.toLatin1().constData()<<
                   " number of triangles of joint "<<idom<<"<->"<<ineig<<" not equals"<<std::endl;
             continue;
          }
-         namejoint=namejoint.sprintf("JOINT_%d_%d_Faces",idom,ineig);
+         namejoint=namejoint.sprintf("JOINT_%d_%d_Faces",(int)idom,(int)ineig);
          
          famjoint=0;
          if (namejoint.contains(deletegroups)==0){
@@ -2076,28 +2560,47 @@ bool ghs3dprl_mesh_wrap::idom_joints()
             families.add(tmp,namejoint);
          }
 
-         key=key.sprintf("FC%d",idom); //files.FaCes faces (wrap and triangles only)
+         key=key.sprintf("FC%d",(int)idom); //files.FaCes faces (wrap and triangles only)
          tab=this->restore_key(key); //tab1=this->mestab[key1];
 
          med_int nb=tab1->size; nbtria3neig=nb;
-         if (verbose>4)
-            std::cout<<"NumberOfTrianglesOfJoint_"<<idom<<"_"<<ineig<<"="<<nb<<std::endl;
-         arrayi=new med_int[nb*2];
+         //if (verbose>=0) std::cout<<"NumberOfTrianglesOfJoint_"<<idom<<"_"<<ineig<<"="<<nb<<std::endl;
+         arrayi=new med_int[nb*2]; //correspondance indices triangles in 2 domains
          arrayfaces=new med_int[nbtria3neig*3];  //for file DOMAIN_join.med
+         for (i=0; i<nbtria3neig*3 ; i++) arrayfaces[i]=-1; //precaution
          fammore=new med_int[nbtria3];
          for (i=0; i<nbtria3 ; i++) fammore[i]=0;
          ii=0; jj=0;
          for (i=0; i<nb ; i++){
             arrayi[ii]=tab1->tmint[i]; ii++;
+            arrayi[ii]=tab2->tmint[i]; ii++; //correspondance indices triangles in 2 domains
+       
             fammore[tab1->tmint[i]-1]=famjoint;
             //famtria3[tab1->tmint[i]-1]=famjoint;
-            arrayi[ii]=tab2->tmint[i]; ii++;
-            //std::cout<<arrayi[ii-1]<<"="<<arrayi[ii-2]<<std::endl;
-            k=(tab1->tmint[i]-1)*7; //indice of node connectivity
-            arrayfaces[jj]=inodes[tab->tmint[k]-1]+1; jj++;
-            arrayfaces[jj]=inodes[tab->tmint[k+1]-1]+1; jj++;
-            arrayfaces[jj]=inodes[tab->tmint[k+2]-1]+1; jj++;
+            
+            k=tab1->tmint[i]-1; //indice of node connectivity
+            //std::cout<<"k="<<k<<std::endl;
+            k=k*7; //indice of node connectivity in tab of triangles
+            
+            arrayfaces[jj]=inodes[tab->tmint[k]-1]; jj++;
+            arrayfaces[jj]=inodes[tab->tmint[k+1]-1]; jj++;
+            arrayfaces[jj]=inodes[tab->tmint[k+2]-1]; jj++;
+         }
+         //int happens=0;
+         for (i=0; i<nbtria3neig*3 ; i++) {
+           if (arrayfaces[i]<=0) {
+             std::cerr<<"Problem file X_joints.med unknown node in joint "<<idom<<"_"<<ineig<<" face "<<i/3+1<<std::endl; //precaution
+             //happens=1;
+           }
+         }
+         /*TODO DEBUG may be bug distene?
+         if (happens==1) {
+            std::cout<<"\nNumberOfTrianglesOfJoint_"<<idom<<"_"<<ineig<<"="<<nb<<std::endl;
+            for (i=0; i<nbnodes ; i++) std::cout<<"inode i "<<i+1<<" "<<inodes[i]<<std::endl;
+            for (i=0; i<tab1->size ; i++) std::cout<<"triangle i "<<i+1<<" "<<tab1->tmint[i]<<std::endl;
+            for (i=0; i<tab->size ; i=i+7) std::cout<<"conn i "<<i/7+1<<" : "<<tab->tmint[i]<<" "<<tab->tmint[i+1]<<" "<<tab->tmint[i+2]<<std::endl;
          }
+         */
          if (namejoint.contains(deletegroups)==0){
             ok=set_one_more_family(famtria3,fammore,nbtria3);
          }
@@ -2112,9 +2615,9 @@ bool ghs3dprl_mesh_wrap::idom_joints()
          //!write in file resume DOMAIN.joints.med of all joints for quick display (...may be...)
          if (idom<=ineig) { //no duplicate joint_1_2 and joint_2_1
           //create mesh
-          namejoint=namejoint.sprintf("JOINT_%d_%d",idom,ineig);
+          namejoint=namejoint.sprintf("JOINT_%d_%d",(int)idom,(int)ineig);
           charendnull(namejnt,namejoint,MED_NAME_SIZE);
-          tmp=tmp.sprintf("joint between %d and %d",idom,ineig);
+          tmp=tmp.sprintf("joint between %d and %d",(int)idom,(int)ineig);
           charendnull(descjnt,tmp,MED_COMMENT_SIZE);
           err=MEDmeshCr(fidjoint,namejnt,3,3,MED_UNSTRUCTURED_MESH,descjnt,dtunit,MED_SORT_DTIT,MED_CARTESIAN,axisname,axisunit);
           if (err<0) std::cerr<<"Problem MEDmeshCr "<<namejnt<<std::endl;
@@ -2126,13 +2629,16 @@ bool ghs3dprl_mesh_wrap::idom_joints()
           err=MEDmeshEntityNumberWr(fidjoint,namejnt,MED_NO_DT,MED_NO_IT,MED_NODE,MED_UNDEF_GEOMETRY_TYPE,nbnodesneig,arrayi);
           delete[] arrayi;
           if (err<0) std::cerr<<"Problem MEDmeshEntityNumberWr of nodes "<<namejnt<<std::endl;
-
+          //families zero in file fidjoint ???
+          //La famille FAMILLE_ZERO n'a pas été trouvée, elle est obligatoire
+          nb=create_family_zero(fidjoint,namejnt);
+          
           //write tria3
           if (nbtria3neig>0) {
            //for (i=0; i<nbtria3neig ; i++) std::cout<<i+1<<" "<<
            //    arrayfaces[i*3]<<" "<<arrayfaces[i*3+1]<<" "<<arrayfaces[i*3+2]<<std::endl;
            err=MEDmeshElementConnectivityWr(fidjoint,namejnt,MED_NO_DT,MED_NO_IT,0.,
-                   MED_CELL,MED_TRIA3,MED_NODAL,MED_FULL_INTERLACE,nbtria3neig,arrayfaces);
+                   MED_CELL,MED_TRIA3,MED_NODAL,MED_FULL_INTERLACE,nbtria3neig,arrayfaces); // todo: arrayfaces may be used uninitialized
            if (err<0) std::cerr<<"Problem MEDmeshElementConnectivityWr for triangles connectivity "<<namejnt<<std::endl;
            //writing indices of faces triangles of joint
            arrayi=new med_int[nbtria3neig]; 
@@ -2144,7 +2650,7 @@ bool ghs3dprl_mesh_wrap::idom_joints()
          }
 
          delete[] arraynodes;
-         if (nbtria3neig>0) delete[] arrayfaces;
+         if (nbtria3neig>0) delete[] arrayfaces; // todo: arrayfaces may be used uninitialized
          delete[] inodes;
 
          //!masterfile.xml
@@ -2162,18 +2668,18 @@ bool ghs3dprl_mesh_wrap::idom_joints()
    xmlNewProp(joints_node, BAD_CAST "number", BAD_CAST i2a(nbjoints).c_str());
    xmlNewChild(joints_node, 0, BAD_CAST "id_neighbours", BAD_CAST sjoints.substr(1).c_str());
    
-   tmp=tmp.sprintf("NB%d VC",idom);
+   tmp=tmp.sprintf("NB%d VC",(int)idom);
    //qt3 xx=this->remove_key_mesh_wrap(QRegExp(tmp,true,true));
-   xx=this->remove_key_mesh_wrap(QRegExp(tmp,Qt::CaseSensitive,QRegExp::RegExp));
+   /*xx=*/this->remove_key_mesh_wrap(QRegExp(tmp,Qt::CaseSensitive,QRegExp::RegExp));
    //tmp=tmp.sprintf("MS%d NE*",idom);
    //qt3 xx=this->remove_key_mesh_wrap(QRegExp(tmp,true,true));
-   //xx=this->remove_key_mesh_wrap(QRegExp(tmp,Qt::CaseSensitive,QRegExp::RegExp));
-   tmp=tmp.sprintf("FC%d",idom);
+   ///*xx=*/this->remove_key_mesh_wrap(QRegExp(tmp,Qt::CaseSensitive,QRegExp::RegExp));
+   tmp=tmp.sprintf("FC%d",(int)idom);
    //qt3 xx=this->remove_key_mesh_wrap(QRegExp(tmp,true,true));
-   xx=this->remove_key_mesh_wrap(QRegExp(tmp,Qt::CaseSensitive,QRegExp::RegExp));
-   tmp=tmp.sprintf("GL%d *",idom);
+   /*xx=*/this->remove_key_mesh_wrap(QRegExp(tmp,Qt::CaseSensitive,QRegExp::RegExp));
+   tmp=tmp.sprintf("GL%d *",(int)idom);
    //qt3 xx=this->remove_key_mesh_wrap(QRegExp(tmp,true,true));
-   xx=this->remove_key_mesh_wrap(QRegExp(tmp,Qt::CaseSensitive,QRegExp::RegExp));
+   /*xx=*/this->remove_key_mesh_wrap(QRegExp(tmp,Qt::CaseSensitive,QRegExp::RegExp));
    return ok;
 }
 
@@ -2184,12 +2690,14 @@ bool ghs3dprl_mesh_wrap::idom_tetras()
    QString tmp,key1;
    CVWtab *tab1;
    med_int i,*arrayi;
-   int xx;
+   //int xx;
 
       //writing connectivity of tetrahedra by nodes
-      key1=key1.sprintf("NB%d EV",idom); //files.NoBoite Elements Vertices (tetra only)
+      key1=key1.sprintf("NB%d EV",(int)idom); //files.NoBoite Elements Vertices (tetra only)
       tab1=this->restore_key(key1); //tab1=this->mestab[key1];
       nbtetra4=tab1->size/4;
+      this->nbtetr=nbtetra4; // for current idom
+
       nbtetrastotal=nbtetrastotal + nbtetra4;
       if (verbose>5)std::cout<<"NumberOftetrahedra="<<nbtetra4<<std::endl;
       err=MEDmeshElementConnectivityWr(fid,nomfinal,MED_NO_DT,MED_NO_IT,0.,MED_CELL,MED_TETRA4,MED_NODAL,MED_FULL_INTERLACE,nbtetra4,tab1->tmint);
@@ -2206,27 +2714,42 @@ bool ghs3dprl_mesh_wrap::idom_tetras()
       famtetra4=new med_int[nbtetra4];
       for (i=0; i<nbtetra4 ; i++) famtetra4[i]=famnewtetra4;
 
-      //writing tetrahedra global numbering
-      //GLx EL=files.GLo ELements
-      key1=key1.sprintf("GL%d EL",idom);
-      tab1=this->restore_key(key1); //tab1=this->mestab[key1];
-      if (!tab1) {
-         tmp=pathini+casename+tmp.sprintf(format.toLatin1().constData(),nbfilestot,idom)+".glo";
-         ok=this->ReadFileGLO(tmp);
-         tab1=this->restore_key(key1);
-         if (!tab1) return false;
-      }
+      // if (!for_multithread) 
+      {
+        //writing tetrahedra global numbering
+        //GLx EL=files.GLo ELements
+        key1=key1.sprintf("GL%d EL",(int)idom);
+        tab1=this->restore_key(key1); //tab1=this->mestab[key1];
+        if (!tab1) {
+          //tmp=pathini+casename+tmp.sprintf(format.toLatin1().constData(),nbfilestot,idom)+".glo";
+          //ok=this->ReadFileGLO(tmp);
+          //tab1=this->restore_key(key1);
+          //if (!tab1) return false;
+
+          if (!for_tetrahpc) {
+              tmp=pathini+casename+tmp.sprintf(format.toLatin1().constData(),nbfilestot,idom)+".glo";
+              ok=this->ReadFileGLO(tmp);
+          }
+          if (for_tetrahpc) {
+              tmp=pathini+casename+"_out"+tmp.sprintf(format_tetra.toLatin1().constData(),idom)+".global";
+              ok=this->ReadFileGLOBAL(tmp);
+          }
+          tab1=this->restore_key(key1);
+          if (!tab1) return false;
 
-      if (tab1->size!=nbtetra4){
-         std::cerr<<"Problem incorrect size of tetrahedra global numbering"<<std::endl; return false;}
-      if (verbose>2)
-         std::cout<<"CreateMEDglobalNumerotation_tetrahedra "<<key1.toLatin1().constData()<<" "<<tab1->size<<std::endl;
-      err=MEDmeshGlobalNumberWr(fid,nomfinal,MED_NO_DT,MED_NO_IT,MED_CELL,MED_TETRA4,tab1->size,tab1->tmint);
-      if (err<0){std::cerr<<"Problem MEDmeshGlobalNumberWr tetrahedra"<<std::endl; return false;}
+        }
 
-      tmp=tmp.sprintf("NB%d EV",idom);
+        if (tab1->size!=nbtetra4){
+          std::cerr<<"Problem incorrect size of tetrahedra global numbering"<<std::endl; return false;}
+        if (verbose>2)
+          std::cout<<"CreateMEDglobalNumerotation_tetrahedra "<<key1.toLatin1().constData()<<" "<<tab1->size<<std::endl;
+        err=MEDmeshGlobalNumberWr(fid,nomfinal,MED_NO_DT,MED_NO_IT,MED_CELL,MED_TETRA4,tab1->size,tab1->tmint);
+        if (err<0){std::cerr<<"Problem MEDmeshGlobalNumberWr tetrahedra"<<std::endl; return false;}
+      }
+
+      tmp=tmp.sprintf("NB%d EV", (int)idom);
       //qt3 xx=this->remove_key_mesh_wrap(QRegExp(tmp,true,true));
-      xx=this->remove_key_mesh_wrap(QRegExp(tmp,Qt::CaseSensitive,QRegExp::RegExp));
+      /*xx=*/this->remove_key_mesh_wrap(QRegExp(tmp,Qt::CaseSensitive,QRegExp::RegExp));
    return ok;
 }
 
@@ -2237,9 +2760,9 @@ med_int ghs3dprl_mesh_wrap::create_families(med_idt fid, int sign)
 {
    med_int pas,ires;
    char nomfam[MED_NAME_SIZE+1];  //it.current()->name;
-   char attdes[MED_COMMENT_SIZE+1]="_NO_DESCRIPTION";
+   //char attdes[MED_COMMENT_SIZE+1]="_NO_DESCRIPTION";
    char *gro;
-   med_int i,attide=1,attval=1,natt=1,num,ngro;
+   med_int i,/*attide=1,*//*attval=1,*//*natt=1,*/num,ngro;
    
    if (sign>=0) pas=1; else pas=-1;
    ires=0;
@@ -2266,10 +2789,29 @@ med_int ghs3dprl_mesh_wrap::create_families(med_idt fid, int sign)
       }
       if (verbose>5)std::cout<<std::endl;
       err=MEDfamilyCr(fid,nomfinal,nomfam,num,ngro,gro);
-      if (err<0) std::cerr<<"Problem MEDfamilyCr"<<std::endl;
       delete[] gro;
       if (err<0) std::cerr<<"Problem MEDfamilyCr of "<<nomfam<<std::endl;
    }
    return ires;
 }
 
+med_int ghs3dprl_mesh_wrap::create_family_zero(med_idt fid, QString nameMesh)
+{
+   med_int /*pas,*/ires;
+   ires=0;
+   char nomfam[MED_NAME_SIZE+1]="FAMILLE_ZERO";  //it.current()->name;
+   //char attdes[MED_COMMENT_SIZE+1]="_NO_DESCRIPTION";
+   
+   char *gro;
+   med_int /*attide=1,*//*attval=1,*//*natt=1,*/num=0,ngro=0;
+   
+   gro=new char[MED_LNAME_SIZE*ngro+2];
+   if (verbose>3)std::cout<<"\ncreate_family_ZERO "<<nameMesh.toLatin1().constData()<<std::endl;
+   err=MEDfamilyCr(fid,nameMesh.toLatin1().constData(),nomfam,num,ngro,gro);
+   if (err<0) std::cerr<<"Problem MEDfamilyCr FAMILLE_ZERO of "<<nameMesh.toLatin1().constData()<<std::endl;
+   delete[] gro;
+   return ires;
+}
+
+
+