Salome HOME
ef2aa54e297d76cfbca8875c0f9d8db85b6ef428
[plugins/ghs3dprlplugin.git] / src / tepal2med / ghs3dprl_mesh_wrap.cxx
1 // Copyright (C) 2007-2020  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // ---
21 // File   : ghs3dprl_mesh_wrap.cxx
22 // Author : Christian VAN WAMBEKE (CEA) 
23 // ---
24 //
25 #include "ghs3dprl_mesh_wrap.h"
26
27 #include <string>
28 #include <iostream>
29 #include <sstream>
30 #include <fstream>
31 #ifndef WIN32
32 #include <unistd.h>
33 #endif
34
35 #include <libxml/tree.h>
36 #include <libxml/parser.h>
37 #include <libxml/xpath.h>
38 #include <libxml/xpathInternals.h>
39 #ifdef WIN32
40 #include <io.h>
41 #include <windows.h>
42 #include <time.h>
43 #define F_OK 0
44 #undef max
45 #undef min
46 #endif
47
48 #include <QFile>
49 #include <QRegExp>
50 #include <limits>
51
52 #include <med.h>
53 //#include <med_config.h>
54 //#include <med_utils.h>
55 //#include <med_misc.h>
56
57 //utils procedures
58
59 //************************************
60 std::string i2a(const int &v)
61 {
62    std::ostringstream ss;
63    ss<<v;
64    return ss.str();
65 }
66
67 //************************************
68 QString endspace(QString deb,int lg)
69 //better fill by spaces for char unicoo[3*MED_TAILLE_PNOM+1]; etc...
70 {
71    QString fin,spa;
72    //spa.fill(' ',lg);
73    //fin=deb+spa;
74    //fin.truncate(lg);
75    fin=deb.leftJustified(lg,' ',true);
76    return fin;
77 }
78
79 //************************************
80 void charendnull(char *p, QString deb, int lg)
81 {
82    QString fin;
83    fin=deb;
84    fin.truncate(lg-1);
85    strcpy(p,fin.toLatin1().constData()); // 0 at end
86    for (int i=fin.length();i<lg-1;i++){
87        p[i]='\0';
88    }
89 }
90
91 //class familles
92 //************************************
93    void familles::newfam(QString nom){
94       //std::cout<<"newfam "<<nom<<std::endl;
95       if (fam.find(nom)!=fam.end()){
96          std::cout<<"***newfam*** "<<nom.toLatin1().constData()<<" deja present\n";
97          return;
98       }
99       fend gb;
100       fam[nom]=gb;
101    }
102
103 //************************************
104    void familles::newgro(QString nom){
105       //std::cout<<"newgro "<<nom<<std::endl;
106       if (gro.find(nom)!=gro.end()){
107          std::cout<<"***newgro*** "<<nom.toLatin1().constData()<<" deja present\n";
108          return;
109       }
110       fend gb;
111       gro[nom]=gb;
112    }
113    
114 //************************************
115    void familles::write(){
116       fend gb;
117       fagr::iterator it1;
118       fend::iterator it2;
119       int nbf=0,nbg=0;
120       for (it1=fam.begin(); it1!=fam.end(); ++it1){
121          nbf++;
122          std::cout<<"Family=<"<<(*it1).first.toLatin1().constData()<<">\tGroups=";
123          gb=(*it1).second;
124          for (it2=gb.begin(); it2!=gb.end(); ++it2){
125             std::cout<<"<"<<(*it2).first.toLatin1().constData()<<"> ";
126          }
127          std::cout<<std::endl;
128       }
129       if (nbf==0) std::cout<<"no families"<<std::endl;
130       for (it1=gro.begin(); it1!=gro.end(); ++it1){
131          nbg++;
132          std::cout<<"Group=<"<<(*it1).first.toLatin1().constData()<<">\tFamilies=";
133          gb=(*it1).second;
134          for (it2=gb.begin(); it2!=gb.end(); ++it2){
135             std::cout<<"<"<<(*it2).first.toLatin1().constData()<<"> ";
136          }
137          std::cout<<std::endl;
138       }
139       if (nbg==0) std::cout<<"no groups"<<std::endl;
140    }
141
142 //************************************
143    xmlNodePtr familles::xml_groups(){
144       fend gb;
145       fagr::iterator it1;
146       fend::iterator it2;
147       int nb=0,nbf;
148       std::string ss;
149       xmlNodePtr res,node;
150       res=xmlNewNode(NULL, BAD_CAST "groups");
151       for (it1=gro.begin(); it1!=gro.end(); ++it1){
152          node = xmlNewChild(res, 0, BAD_CAST "group",0);
153          ss=(*it1).first.toLatin1().constData();
154          xmlNewProp(node, BAD_CAST "name", BAD_CAST ss.c_str());
155          nb++;
156          gb=(*it1).second;
157          nbf=0; ss="";
158          for (it2=gb.begin(); it2!=gb.end(); ++it2){
159             ss=ss+" "+(*it2).first.toLatin1().constData();
160             nbf++;
161          }
162          xmlNewProp(node, BAD_CAST "families_number", BAD_CAST i2a(nbf).c_str());
163          xmlNewProp(node, BAD_CAST "families", BAD_CAST ss.substr(1).c_str());
164          //std::cout<<std::endl;
165       }
166       xmlNewProp(res, BAD_CAST "number", BAD_CAST i2a(nb).c_str());
167       return res;
168    }
169
170 //************************************
171    void familles::add(QString nomfam, QString nomgro)
172    {
173       //std::cout<<"add family <"<<nomfam<<">\t<"<<nomgro<<">\n";
174       fagr::iterator it;
175       it=fam.find(nomfam);
176       if (it==fam.end()){
177          //std::cout<<"add new family <"<<nomfam<<">\t<"<<nomgro<<">\n";
178          newfam(nomfam);
179          it=fam.find(nomfam);
180       }
181       if (nomgro=="") return; //no group
182       (*it).second[nomgro]=0;
183       it=gro.find(nomgro);
184       if (it==gro.end()){
185          //std::cout<<"***new*** "<<nomgro<<" non present\n";
186          newgro(nomgro);
187          it=gro.find(nomgro);
188       }
189       (*it).second[nomfam]=0;
190
191    }
192
193
194 //************************************
195 bool familles::get_number_of_new_family(int sign, med_int *ires, QString *tmp)
196 //if sign < 0 families faces or tria3 etc...
197 //if sign >= 0 family zero and family nodes
198 //outputs in *ires and *tmp
199 {
200    int pas,i,ii;
201    QString nomfam;
202    fagr::iterator it;
203    if (sign>=0) pas=1; else pas=-1;
204    *tmp="0"; *ires=0;
205    ii=pas;
206    for (i=0;i<10000;i++) { //mefiance
207       nomfam=nomfam.sprintf("%d",ii);
208       it=fam.find(nomfam);
209       if (it==fam.end()) {
210          *tmp=nomfam; *ires=ii;
211          //std::cout<<"NewFamily Found<"<<*ires<<"><"<<*tmp<<">\n";
212          return true;
213       }
214       ii=ii+pas;
215    }
216    std::cerr<<"***get_number_of_new_family*** Problem new family not found"<<std::endl;
217    return false;
218 }
219
220 //************************************
221    med_int familles::find_family_on_groups(med_int fam1, med_int fam2)
222    {
223       med_int ires=0;
224       if (fam1==fam2) {ires=fam1; return ires;}
225       //find one family whith groups of fam1 and groups of fam2
226       fend gb=fuse_goups(fam1,fam2);
227       //find if one family have theses groups
228       fagr::iterator it1;
229       fend::iterator it2;
230       for (it1=fam.begin(); it1!=fam.end(); ++it1){
231          if (gb==(*it1).second){
232             ires=(*it1).first.toLong();
233             //std::cout<<"find_family_on_groups old <"<<ires<<"> from <"<<
234             //       fam1<<"><"<<fam2<<">\n";
235             return ires;
236          }
237       }
238       //std::cout<<"no family found!!! - groups of "<<fam1<<" and "<<fam2<<std::endl;
239       QString tmp;
240       //fam1 positive for nodes negative faces & mailles
241       bool oktmp=get_number_of_new_family(fam1,&ires,&tmp);
242       fend::iterator it;
243       for (it=gb.begin(); it!=gb.end(); ++it){
244           this->add(tmp,(*it).first);
245       }
246       //std::cout<<"new family <"<<ires<<"> intersection of <"<<fam1<<"><"<<fam2<<">\n";
247       return ires;
248    }
249    
250 //************************************
251    fend familles::fuse_goups(med_int fam1, med_int fam2)
252    //concatenation/fusion deux map groupes
253    {
254       QString nom1,nom2;
255       fagr::iterator it1,it2;
256       nom1=nom1.sprintf("%d",fam1);
257       it1=fam.find(nom1);
258       nom2=nom2.sprintf("%d",fam2);
259       it2=fam.find(nom2);
260       if ( (it1==fam.end())||(it2==fam.end()) ) {
261          std::cerr<<"***fuse_goups*** non existing family "<<fam1<<" or "<<fam2<<std::endl;
262          fend gb;
263          return gb; //empty
264       }
265       fend gb=(*it1).second; //firt groups
266       gb.insert((*it2).second.begin(),(*it2).second.end()); //other groups
267       return gb;
268       //for debug
269       std::cout<<"fuse_goups "<<fam1<<" "<<fam2<<" ";
270       fend::iterator it;
271       for (it=gb.begin(); it!=gb.end(); ++it){
272             std::cout<<"<"<<(*it).first.toLatin1().constData()<<"> ";
273       }
274       std::cout<<std::endl;
275       return gb;
276    }
277
278 long CVWtab::memoryuse=0; //static
279 long CVWtab::memorymax=1000*1000000; //static
280
281 //************************************
282 CVWtab::CVWtab(long nb, med_int *pmint)
283 //constructor with pmint allocated yet with new
284 {
285    //std::cout"***constructor med_int CVWtab***\n";
286    size=nb;
287    type=1;  //only tmint valide
288    tmint=pmint;
289    tmflo=NULL;
290    memoryuse=memoryuse+sizeof(med_int)*nb;
291    //std::cout<<"memoryuse int "<<sizeof(med_int)<<" "<<nb<<" "<<memoryuse<<" "<<memorymax<<std::endl;
292    if (memoryuse>memorymax) {
293       std::cout<<"***WARNING*** memory max reached "<<memorymax<<std::endl;
294       //std::cout<<"memoryuse int "<<sizeof(med_int)<<" "<<nb<<" "<<memoryuse<<std::endl;
295    }
296 }
297
298 //************************************
299 CVWtab::CVWtab(long nb, med_float *pmflo)
300 //constructor with pmflo allocated yet with new
301 {
302    //std::cout<<"***constructor med_float CVWtab***\n";
303    size=nb;
304    type=2;   //only tmflo valide
305    tmint=NULL;
306    tmflo=pmflo;
307    memoryuse=memoryuse+sizeof(med_float)*nb;
308    //std::cout<<"memoryuse float "<<sizeof(med_float)<<" "<<nb<<" "<<memoryuse<<" "<<memorymax<<std::endl;
309    if (memoryuse>memorymax) {
310       std::cout<<"***WARNING*** memory max reached "<<memorymax<<std::endl;
311       //std::cout<<"memoryuse float "<<sizeof(med_float)<<" "<<nb<<" "<<memoryuse<<std::endl;
312    }
313 }
314
315 //************************************
316 CVWtab::~CVWtab()
317 {
318    bool ok;
319    //std::cout<<"   destructor CVWtab *** "<<this->filename<<std::endl;
320    ok=this->CVWtab_deallocate();
321    //remove temporary file
322    if (this->filename!="_NO_FILE")
323    {
324       remove(this->filename.toLatin1().constData()); //#include <stdio.h>
325       //std::cout<<this->filename<<" successfully deleted\n";
326    }
327
328 }
329
330 //************************************
331 bool CVWtab::CVWtab_deallocate()
332 {
333    //std::cout<<"   deallocate CVWtab*** "<<size<<std::endl;
334    if (size <= 0) return false;
335    if (tmint)
336    {
337       delete[] tmint;
338       memoryuse=memoryuse-sizeof(med_int)*size;
339       size=-size; //precaution
340    }
341    if (tmflo)
342    {
343       delete[] tmflo;
344       memoryuse=memoryuse-sizeof(med_float)*size;
345       size=-size; //precaution
346    }
347    if (memoryuse<0) std::cout<<"ERROR: on arrays deallocate memory use < 0 "<<memoryuse<<std::endl;
348    if (memoryuse==0) std::cout<<"WARNING: on arrays deallocate memory use = 0 "<<std::endl;
349    return true;
350 }
351
352 //************************************
353 bool CVWtab::is_equal(CVWtab *tab2)
354 {
355    //std::cout<<"is_equal tab1 tab2 type="<<this->type<<"  size="<<this->size<<" "<<tab2->size<<std::endl;
356    //if (this->type==1) std::cout<<"med_int tab1[0]="<<this->tmint[0]<<std::endl;
357    //if (this->type==2) std::cout<<"med_float tab1[0]="<<this->tmflo[0]<<std::endl;
358    if (this->size!=tab2->size) return false;
359    if (this->type!=tab2->type) return false;
360    if (this->type==1)
361    {
362       if (!this->tmint)
363       {  std::cout<<"***is_equal*** pb pointer NULL with tmint size="<<this->size<<std::endl;
364          return false;
365       }
366       for (long i=0; i < this->size; i++)
367          if (this->tmint[i]!=tab2->tmint[i]) return false;
368    }
369    if (this->type==2)
370    {
371       if (!this->tmflo)
372       {  std::cout<<"***is_equal*** pb pointer NULL with tmflo size="<<this->size<<std::endl;
373          return false;
374       }
375       for (long i=0; i < this->size; i++)
376          if (this->tmflo[i]!=tab2->tmflo[i]) return false;
377    }
378    return true;
379 }
380
381 //************************************
382 bool CVW_is_equal_vertices(CVWtab *tab1, long i1,
383                        CVWtab *tab2, long i2, int verbose)
384 //verbose 0 for no prints
385 //verbose 1 for print vertices not equals
386 //verbose 2 for print also vertices equals (debug)
387 {
388    //std::cout<<"is_equal_vertice size="<<tab1->size<<" "<<tab2->size<<std::endl;
389    bool ok=false;
390    med_float *p1,*p2;
391    //vertices indices from 1 not 0!
392    long di1=(i1-1)*3, di2=(i2-1)*3;
393    if (di1<0 || di1>=tab1->size)
394    {
395       std::cerr<<"BadIndice tab1 in is_equal_vertices "<<
396             di1<<" not in "<<tab1->size<<std::endl;
397       return false;
398    }
399    if (di2<0 || di2>=tab2->size)
400    {
401       std::cerr<<"BadIndice tab2 in is_equal_vertices "<<
402             di2<<" not in "<<tab2->size<<std::endl;
403       return false;
404    }
405    p1=(tab1->tmflo+di1);
406    p2=(tab2->tmflo+di2);
407    if (p1[0]==p2[0] && p1[1]==p2[1] && p1[2]==p2[2]) ok=true ;
408    if (!ok && verbose>0) printf(
409       "Vertices differents (%.16g %.16g %.16g) (%.16g %.16g %.16g)\n",
410       p1[0],p1[1],p1[2],p2[0],p2[1],p2[2]);
411    else
412       if (verbose>1) printf(
413       "Vertices equals     (%.16g %.16g %.16g)\n",
414       p1[0],p1[1],p1[2]);
415    return ok;
416 }
417
418 //************************************
419 bool CVW_FindString(const std::string &str,std::fstream &Ff, long &count)
420 //find in file first line with string str in first position of line
421 //converts count value expected after "='" in line found
422 {
423    std::string line;
424    QString tmp;
425    do
426    {
427       if (getline(Ff,line))
428       {
429          if (line[0]==str[0]) //faster
430          {
431             if (line.find(str)==0)
432             {
433             tmp=line.c_str();
434             bool ok;
435             count=tmp.section('\'',1,1).toLong(&ok);
436             return ok;
437             }
438          }
439       }
440       else
441       {
442          std::cerr<<"Problem line '"<<str<<"' not found in file\n"<<std::endl;
443          return false;
444       }
445    } while (1);
446    return true;
447 }
448
449 //************************************
450 bool CVW_FindStringInFirstLines(const std::string &str,std::fstream &Ff, long &maxline)
451 //find in file maximum maxline first lines with string str in first position of line
452 //converts count value expected after " " in line found
453 {
454    std::string line;
455    long nbLine=0;
456    do
457    {
458       if (getline(Ff,line))
459       {
460          nbLine++;
461          if (line[0]==str[0]) //faster
462          {
463             if (line.find(str)==0)
464             {
465             return true;
466             }
467          }
468          if (nbLine>=maxline)
469          {
470             std::cerr<<"Problem line '"<<str<<"' not found in first "<<maxline<<" lines of file\n"<<std::endl;
471             return false;
472          }
473       }
474       else
475       {
476          std::cerr<<"Problem line '"<<str<<"' not found in all file\n"<<std::endl;
477          return false;
478       }
479    } while (1);
480    return true;
481 }
482
483 //************************************
484 bool ghs3dprl_mesh_wrap::ReadFileMSGnew(const QString FileName)
485 //read file .glo with no parser xml because big file (volume)
486 //no read of <receive> for speed (and so no test)
487 {
488    QString tmp;
489    std::fstream Ff(FileName.toLatin1().constData(),std::ios_base::in);
490    std::string line;
491    long i,count,nbneighbour,ineighbour;
492    bool ok;
493
494    if (!Ff.is_open())
495    {
496       std::cerr<<"Problem File '"<<FileName.toLatin1().constData()<<"' not open\n"<<std::endl;
497       return false;
498    }
499
500    //Lit les donnees :
501    if (!CVW_FindString("<neighbours count=",Ff,nbneighbour)) return false;
502    if (verbose>2) std::cout<<"NeighboursCountDomain_"<<this->nofile<<"="<<nbneighbour<<std::endl;
503    for (i=1; i<=nbneighbour; i++)
504    {
505       if (!CVW_FindString("<neighbour indice=",Ff,ineighbour)) return false;
506       if (!CVW_FindString("<vertices count=",Ff,count)) return false;
507       if (count>0){
508          med_int *tmint=new med_int[count];
509          for (int i=0; i<count; i++) Ff>>tmint[i];
510          if (verbose>4) std::cout<<"Vertices "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[count-1]<<std::endl;
511
512          CVWtab *montab=new CVWtab(count,tmint);
513          tmp=tmp.sprintf("MS%ld NE%ld VE SE",this->nofile,ineighbour);
514          ok=this->insert_key(tmp,montab);
515       }
516       if (!CVW_FindString("<edges count=",Ff,count)) return false;
517       if (count>0){
518          med_int *tmint=new med_int[count];
519          for (int i=0; i<count; i++) Ff>>tmint[i];
520          if (verbose>4) std::cout<<"Edges "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[count-1]<<std::endl;
521
522          CVWtab *montab=new CVWtab(count,tmint);
523          tmp=tmp.sprintf("MS%ld NE%ld ED SE",this->nofile,ineighbour);
524          ok=this->insert_key(tmp,montab);
525       }
526       if (!CVW_FindString("<faces count=",Ff,count)) return false;
527       if (count>0){
528          med_int *tmint=new med_int[count];
529          for (int i=0; i<count; i++) Ff>>tmint[i];
530          if (verbose>4) std::cout<<"Faces "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[count-1]<<std::endl;
531
532          CVWtab *montab=new CVWtab(count,tmint);
533          tmp=tmp.sprintf("MS%ld NE%ld FA SE",this->nofile,ineighbour);
534          ok=this->insert_key(tmp,montab);
535       }
536       if (!CVW_FindString("<elements count=",Ff,count)) return false;
537       if (count>0){
538          med_int *tmint=new med_int[count];
539          for (int i=0; i<count; i++) Ff>>tmint[i];
540          if (verbose>4) std::cout<<"Elements "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[count-1]<<std::endl;
541
542          CVWtab *montab=new CVWtab(count,tmint);
543          tmp=tmp.sprintf("MS%ld NE%ld EL SE",this->nofile,ineighbour);
544          ok=this->insert_key(tmp,montab);
545       }
546    }
547
548    //Ferme le fichier :
549    Ff.close();
550    this->nbfiles++;
551    return true;
552 }
553
554 //************************************
555 bool ghs3dprl_mesh_wrap::TestExistingFileMESHnew(const QString FileName)
556 //read file .glo with no parser xml because big file (volume)
557 //no read of <receive> for speed (and so no test)
558 {
559    QString tmp;
560    std::fstream Ff(FileName.toLatin1().constData(),std::ios_base::in);
561    std::string line;
562    long i,count,meshversion,maxline;
563    bool ok;
564
565    if (!Ff.is_open())
566    {
567       std::cerr<<"Problem File '"<<FileName.toLatin1().constData()<<"' not open\n"<<std::endl;
568       return false;
569    }
570
571    //Lit les donnees au debut du fichier, 1 lignes maxi:
572    maxline=1;
573    if (!CVW_FindStringInFirstLines("MeshVersionFormatted",Ff,maxline)) return false;
574    if (verbose>2) std::cout<<"MeshVersionFormatted_"<<this->nofile<<" ok"<<std::endl;
575
576    //Ferme le fichier :
577    Ff.close();
578    this->nbfiles++;
579    return true;
580 }
581
582 ///************************************
583 bool ghs3dprl_mesh_wrap::ReadFileGLO(const QString FileName)
584 //read file .glo with no parser xml because big file (volume)
585 {
586    QString tmp;
587    std::fstream Ff(FileName.toLatin1().constData(),std::ios_base::in);
588    std::string line;
589    long count;
590    bool ok;
591
592    if (!Ff.is_open())
593    {
594       std::cerr<<"Problem File '"<<FileName.toLatin1().constData()<<"' not open\n"<<std::endl;
595       return false;
596    }
597
598    //Lit les donnees :
599    if (!CVW_FindString("<vertices count=",Ff,count)) return false;
600    if (verbose>3) std::cout<<"GloVerticesCount="<<count<<std::endl;
601    if (count>0)
602    {
603       med_int *tmint=new med_int[count];
604       for (int i=0; i<count; i++) Ff>>tmint[i];
605       if (verbose>4) std::cout<<"Elements "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[count-1]<<std::endl;
606
607       CVWtab *montab=new CVWtab(count,tmint);
608       tmp=tmp.sprintf("GL%ld VE",this->nofile);
609       ok=this->insert_key(tmp,montab);
610    }
611
612    if (!CVW_FindString("<edges count=",Ff,count)) return false;
613    if (verbose>3) std::cout<<"GloEdgesCount="<<count<<std::endl;
614    if (count>0)
615    {
616       med_int *tmint=new med_int[count];
617       for (int i=0; i<count; i++) Ff>>tmint[i];
618       if (verbose>4) std::cout<<"Elements "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[count-1]<<std::endl;
619
620       CVWtab *montab=new CVWtab(count,tmint);
621       tmp=tmp.sprintf("GL%ld ED",this->nofile);
622       ok=this->insert_key(tmp,montab);
623    }
624
625    if (!CVW_FindString("<faces count=",Ff,count)) return false;
626    if (verbose>3) std::cout<<"GloFacesCount="<<count<<std::endl;
627    if (count>0)
628    {
629       med_int *tmint=new med_int[count];
630       for (int i=0; i<count; i++) Ff>>tmint[i];
631       if (verbose>4) std::cout<<"Elements "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[count-1]<<std::endl;
632
633       CVWtab *montab=new CVWtab(count,tmint);
634       tmp=tmp.sprintf("GL%ld FA",this->nofile);
635       ok=this->insert_key(tmp,montab);
636    }
637
638    if (!CVW_FindString("<elements count=",Ff,count)) return false;
639    if (verbose>3) std::cout<<"GloElementsCount="<<count<<std::endl;
640    if (count>0)
641    {
642       med_int *tmint=new med_int[count];
643       for (int i=0; i<count; i++) Ff>>tmint[i];
644       if (verbose>4) std::cout<<"Elements "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[count-1]<<std::endl;
645
646       CVWtab *montab=new CVWtab(count,tmint);
647       tmp=tmp.sprintf("GL%ld EL",this->nofile);
648       ok=this->insert_key(tmp,montab);
649    }
650    //Ferme le fichier :
651    Ff.close();
652    this->nbfiles++;
653    return true;
654 }
655
656 ///************************************
657 bool ghs3dprl_mesh_wrap::ReadFileGLOBAL(const QString FileName)
658 //read file .global ascii (no xml)
659 //first line: Vertices Edges Triangles Tetrahedra
660 {
661    std::string line("                                            ");
662    QString tmp;
663    std::fstream Ff(FileName.toLatin1().constData(),std::ios_base::in);
664    long vert=0,edge=0,tria=0,tetr=0,count=0;
665    med_int *tmint;
666    CVWtab *montab;
667    bool ok;
668    
669    if (verbose>=6) std::cout<<"Read file '"<<FileName.toLatin1().constData()<<std::endl;
670    if (!Ff.is_open())
671    {
672       std::cerr<<"Problem file '"<<FileName.toLatin1().constData()<<"' not open"<<std::endl;
673       // std::cout<<"Default global numerotation nb verts "<<vert<<" nb edges "<<edge<<" nb trias "<<tria<<" nb tetras "<<tetr<<std::endl;
674       return false;
675    }
676    else
677    {
678      //Lit les donnees :
679      Ff>>vert>>edge>>tria>>tetr;
680      std::cout<<"Global numerotation nb verts "<<vert<<" nb edges "<<edge<<" nb trias "<<tria<<" nb tetras "<<tetr<<std::endl;
681    }
682    
683    if (vert<0)
684    {
685       std::cerr<<"Problem Vertices: a positive integer is expected"<<std::endl;
686       return false;
687    }
688
689    if (edge<0)
690    {
691       std::cerr<<"Problem Edges: a positive integer is expected"<<std::endl;
692       return false;
693    }
694
695    if (tria<0)
696    {
697       std::cerr<<"Problem Triangles: a positive integer is expected"<<std::endl;
698       return false;
699    }
700
701    if (tetr<0)
702    {
703       std::cerr<<"Problem Tetrahedra: a positive integer is expected"<<std::endl;
704       return false;
705    }
706
707    count=vert;
708    tmint=new med_int[count];
709    for (long i=0; i<count; i++) Ff>>tmint[i];
710    if (verbose>4) std::cout<<"Vertices ("<<count<<") "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[count-1]<<std::endl;
711
712    montab=new CVWtab(count,tmint);
713    tmp=tmp.sprintf("GL%ld VE",this->nofile);
714    ok=this->insert_key(tmp,montab);
715
716    count=edge;
717    tmint=new med_int[count];
718    for (long i=0; i<count; i++) Ff>>tmint[i];
719    if (verbose>4) std::cout<<"Edges ("<<count<<") "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[count-1]<<std::endl;
720
721    montab=new CVWtab(count,tmint);
722    tmp=tmp.sprintf("GL%ld ED",this->nofile);
723    ok=this->insert_key(tmp,montab);
724
725    count=tria;
726    tmint=new med_int[count];
727    for (long i=0; i<count; i++) Ff>>tmint[i];
728    if (verbose>4) std::cout<<"Triangles ("<<count<<") "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[count-1]<<std::endl;
729
730    montab=new CVWtab(count,tmint);
731    tmp=tmp.sprintf("GL%ld FA",this->nofile);
732    ok=this->insert_key(tmp,montab);
733
734    count=tetr;
735    tmint=new med_int[count];
736    for (long i=0; i<count; i++) Ff>>tmint[i];
737    if (verbose>4) std::cout<<"Tetrahedra ("<<count<<") "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[count-1]<<std::endl;
738
739    montab=new CVWtab(count,tmint);
740    tmp=tmp.sprintf("GL%ld EL",this->nofile);
741    ok=this->insert_key(tmp,montab);
742
743    //Ferme le fichier :
744    Ff.close();
745    this->nbfiles++;
746    return true;
747 }
748
749 ///************************************
750 bool ghs3dprl_mesh_wrap::ReadFileDefaultGLOBAL(long vert, long edge, long tria, long tetr)
751 //default like read file .global ascii (no xml) when inexisting when multithread
752 {
753    QString tmp;
754    long count=0;
755    med_int *tmint;
756    CVWtab *montab;
757    bool ok;
758    
759    //Simule les donnees :
760    std::cout<<"Default Global numerotation nb verts "<<vert<<" nb edges "<<edge<<" nb trias "<<tria<<" nb tetras "<<tetr<<std::endl;
761    
762    count=vert;
763    tmint=new med_int[count];
764    for (long i=0; i<count; i++) tmint[i] = i+1;
765    if (verbose>4) std::cout<<"Default Vertices ("<<count<<") "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[count-1]<<std::endl;
766
767    montab=new CVWtab(count,tmint);
768    tmp=tmp.sprintf("GL%ld VE",this->nofile);
769    ok=this->insert_key(tmp,montab);
770
771    count=edge;
772    tmint=new med_int[count];
773    for (long i=0; i<count; i++) tmint[i] = i+1;
774    if (verbose>4) std::cout<<"Default Edges ("<<count<<") "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[count-1]<<std::endl;
775
776    montab=new CVWtab(count,tmint);
777    tmp=tmp.sprintf("GL%ld ED",this->nofile);
778    ok=this->insert_key(tmp,montab);
779
780    count=tria;
781    tmint=new med_int[count];
782    for (long i=0; i<count; i++) tmint[i] = i+1;
783    if (verbose>4) std::cout<<"Default Triangles ("<<count<<") "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[count-1]<<std::endl;
784
785    montab=new CVWtab(count,tmint);
786    tmp=tmp.sprintf("GL%ld FA",this->nofile);
787    ok=this->insert_key(tmp,montab);
788
789    count=tetr;
790    tmint=new med_int[count];
791    for (long i=0; i<count; i++) tmint[i] = i+1;
792    if (verbose>4) std::cout<<"Default Tetrahedra ("<<count<<") "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[count-1]<<std::endl;
793
794    montab=new CVWtab(count,tmint);
795    tmp=tmp.sprintf("GL%ld EL",this->nofile);
796    ok=this->insert_key(tmp,montab);
797
798    return true;
799 }
800
801 //************************************
802 bool ghs3dprl_mesh_wrap::ReadFileFACES(const QString FileName)
803 //read file .faces (wrap)
804 {
805    QString tmp;
806    std::fstream Ff(FileName.toLatin1().constData(),std::ios_base::in);
807    std::string line;
808    long nbelem,ntype;
809    bool ok;
810
811    if (!Ff.is_open())
812    {
813       std::cerr<<"Problem File '"<<FileName.toLatin1().constData()<<"' not open\n"<<std::endl;
814       return false;
815    }
816
817    //Lit les donnees :
818    //Replace le pointeur de fichier au debut :f.seekg(0);
819    if (getline(Ff,line))
820    {
821       tmp=line.c_str();
822       nbelem=tmp.section(' ',0,0).toLong(&ok);
823    }
824    else
825    {
826       std::cerr<<"Problem on first line of file"<<std::endl;
827       return false;
828    }
829    if (verbose>3) std::cout<<"FacesNumberOfElements="<<nbelem<<std::endl;
830    med_int *tmint=new med_int[nbelem*7];
831    for (int i=0; i<nbelem*7; i=i+7)
832    {
833       Ff>>ntype;
834       if (ntype!=3) //only triangles
835       {
836          std::cerr<<"Problem on ntype != 3"<<std::endl;
837          return false;
838       }
839       for (int j=0; j<7; j++) Ff>>tmint[i+j];
840       //for (int j=0; j<7; j++) std::cout<<tmint[i+j]<<' '; std::cout<<std::endl;
841    }
842    if (verbose>4) std::cout<<"Elements "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[nbelem*7-1]<<std::endl;
843
844    CVWtab *montab=new CVWtab(nbelem*7,tmint);
845    tmp=tmp.sprintf("FC%ld",this->nofile);
846    ok=this->insert_key(tmp,montab);
847
848    Ff.close();
849    this->nbfiles++;
850    return true;
851 }
852
853 //************************************
854 bool ghs3dprl_mesh_wrap::ReadFileMESH(const QString FileName)
855 //read file .mesh from tetra_hpc (with volume)
856 {
857    std::string line("                                            ");
858    QString tmp;
859    std::fstream Ff(FileName.toLatin1().constData(),std::ios_base::in);
860    long Mversion=0,Mdim=0,Mvert=0,Mtria=0,Medge=0,Mtetra=0,count=0;
861    med_int garbage;
862    med_int *tmint;
863    bool ok;
864    
865    if (verbose>=6)std::cout<<"Read file '"<<FileName.toLatin1().constData()<<std::endl;
866    if (!Ff.is_open()){
867       std::cerr<<"Problem file '"<<FileName.toLatin1().constData()<<"' not open\n"<<std::endl;
868       return false;
869    }
870
871    //lit les données :
872    if (getline(Ff,line) && (line.find("MeshVersionFormatted")==0))
873    {
874       tmp=line.c_str();
875       Mversion=tmp.section(' ',1,1).toLong(&ok);
876    }
877    else
878    {
879       std::cerr<<"Problem on line 1 of file: 'MeshVersionFormatted' expected"<<std::endl;
880       return false;
881    }
882    
883    getline(Ff,line);
884
885    if (getline(Ff,line) && (line.find("Dimension 3")==0))
886    {
887       tmp=line.c_str();
888       Mdim=tmp.section(' ',1,1).toLong(&ok);
889    }
890    else
891    {
892       std::cerr<<"Problem on line 3 of file: Dimension 3 expected"<<std::endl;
893       return false;
894    }
895    
896    getline(Ff,line);
897
898    if (!(getline(Ff,line) && (line.find("Vertices")==0)))
899    {
900       std::cerr<<"Problem on line 5 of file: 'Vertices' expected"<<std::endl;
901       return false;
902    }
903    if (getline(Ff,line))
904    {
905       tmp=line.c_str();
906       Mvert=tmp.toLong(&ok);
907    }
908    else
909    {
910       std::cerr<<"Problem Vertices: a positive integer is expected"<<std::endl;
911       return false;
912    }
913    if (Mvert<=0)
914    {
915       std::cerr<<"Problem Vertices: a positive integer is expected"<<std::endl;
916       return false;
917    }
918
919    count=Mvert;
920    med_float *tmflo=new med_float[count*3];
921    for (int i=0; i<count*3; i=i+3) Ff>>tmflo[i]>>tmflo[i+1]>>tmflo[i+2]>>garbage;
922    if (verbose>4) std::cout<<"Vertices ("<<count<<") "<<tmflo[0]<<" "<<tmflo[1]<<"... "<<tmflo[count*3-1]<<std::endl;
923
924    CVWtab *montab=new CVWtab(count*3,tmflo);
925    tmp=tmp.sprintf("NB%ld VC",this->nofile);
926    ok=this->insert_key(tmp,montab);
927
928    getline(Ff,line);
929    getline(Ff,line);
930   
931    getline(Ff,line); // get Edges or Triangle, because sometimes Edges absent
932    
933    if (!line.find("Edges")==0)
934    {
935       std::cerr<<"absent line 'Edges' of file '"<<FileName.toLatin1().constData()<<"' :found '"<<line<<"' instead"<<std::endl;
936    }
937    else 
938    {
939      if (getline(Ff,line))
940      {
941         tmp=line.c_str();
942         Medge=tmp.toLong(&ok);
943      }
944      else
945      {
946         std::cerr<<"Problem on line 'Edges' of file: a positive integer is expected"<<std::endl;
947         return false;
948      }
949      if (Medge<=0)
950      {
951         std::cerr<<"Problem on line 'Edges' of file: a positive integer is expected"<<std::endl;
952         return false;
953      }
954
955      count=Medge;
956      tmint=new med_int[count*2]; //*3
957      for (int i=0; i<count*2; i=i+2) {
958        Ff>>tmint[i]>>tmint[i+1]>>garbage;
959      }
960      if (verbose>4) std::cout<<"Edges ("<<count<<") "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[count*2-1]<<std::endl;
961      montab=new CVWtab(count*2,tmint);
962      tmp=tmp.sprintf("NB%ld ED",this->nofile); //TODO see if it could serve
963      ok=this->insert_key(tmp,montab);
964      
965      getline(Ff,line);
966      getline(Ff,line);
967      getline(Ff,line);
968    }
969
970    if (!line.find("Triangles")==0)
971    {
972       std::cerr<<"Problem on line 'Triangles' of file '"<<FileName.toLatin1().constData()<<"' :found '"<<line<<"' instead"<<std::endl;
973       return false;
974    }
975    if (getline(Ff,line))
976    {
977       tmp=line.c_str();
978       Mtria=tmp.toLong(&ok);
979    }
980    else
981    {
982       std::cerr<<"Problem on line 'Triangles' of file: a positive integer is expected"<<std::endl;
983       return false;
984    }
985    if (Mtria<=0)
986    {
987       std::cerr<<"Problem on line 'Triangles' of file: a positive integer is expected"<<std::endl;
988       return false;
989    }
990
991    count=Mtria;
992    tmint=new med_int[count*3]; //*7 as older files .faces, obsolete
993    for (int i=0; i<count*3; i=i+3) {
994      Ff>>tmint[i]>>tmint[i+1]>>tmint[i+2]>>garbage;
995    }
996    if (verbose>4) std::cout<<"Triangles ("<<count<<") "<<tmint[0]<<" "<<tmint[1]<<"... "<<
997        tmint[count*3-5]<<" "<<tmint[count*3-4]<<" "<<tmint[count*3-3]<<" "<<
998        tmint[count*3-2]<<" "<<tmint[count*3-1]<<std::endl;
999
1000    montab=new CVWtab(count*3,tmint);
1001    tmp=tmp.sprintf("FC%ld",this->nofile);
1002    ok=this->insert_key(tmp,montab);
1003    
1004    getline(Ff,line);
1005    getline(Ff,line);
1006
1007    if (!(getline(Ff,line) && (line.find("Tetrahedra")==0)))
1008    {
1009       std::cerr<<"Problem on line 'Tetrahedra' of file: not found"<<std::endl;
1010       return false;
1011    }
1012    if (getline(Ff,line))
1013    {
1014       tmp=line.c_str();
1015       Mtetra=tmp.toLong(&ok);
1016    }
1017    else
1018    {
1019       std::cerr<<"Problem on line 'Tetrahedra' of file: a positive integer is expected"<<std::endl;
1020       return false;
1021    }
1022    if (Mtetra<=0)
1023    {
1024       std::cerr<<"Problem on line 'Tetrahedra' of file: a positive integer is expected"<<std::endl;
1025       return false;
1026    }
1027
1028    if (verbose>=2)
1029    {
1030       std::cout<<"MeshVersionFormatted="<<Mversion<<std::endl;
1031       std::cout<<"MeshDimension="<<Mdim<<std::endl;
1032       std::cout<<"MeshNumberOfVertices="<<Mvert<<std::endl;
1033       std::cout<<"MeshNumberOfEdges="<<Medge<<std::endl;
1034       std::cout<<"MeshNumberOfTriangles="<<Mtria<<std::endl;
1035       std::cout<<"MeshNumberOfTetrahedra="<<Mtetra<<std::endl;
1036    }
1037
1038    this->nbvert=Mvert; // for current idom
1039    this->nbedge=Medge; 
1040    this->nbtria=Mtria; 
1041    this->nbtetr=Mtetra; 
1042
1043    count=Mtetra;
1044    tmint=new med_int[count*4];
1045    for (int i=0; i<count*4; i=i+4) Ff>>tmint[i]>>tmint[i+1]>>tmint[i+2]>>tmint[i+3]>>garbage;
1046    if (verbose>4) std::cout<<"Tetrahedra ("<<count<<") "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[count*4-1]<<std::endl;
1047
1048    montab=new CVWtab(count*4,tmint);
1049    tmp=tmp.sprintf("NB%ld EV",this->nofile);
1050    ok=this->insert_key(tmp,montab);
1051
1052    //swap on file if too big for memory in one cpu
1053    //default 1GOctet/8(for double)/10(for arrays in memory at the same time)
1054    if (Mvert*3>this->nbelem_limit_swap)
1055      this->SwapOutOfMemory_key_mesh_wrap(QRegExp("NB",Qt::CaseSensitive,QRegExp::RegExp));
1056    //beware record 6 lenght 1
1057    //ferme le fichier :
1058    Ff.close();
1059    this->nbfiles++;
1060    return true;
1061 }
1062
1063 //************************************
1064 bool ghs3dprl_mesh_wrap::ReadFileNOBOITE(const QString FileName)
1065 //read file .noboite (volume)
1066 //for huge files it could be better use ReadFileNOBOITEB (B=binary format)
1067 //(parameter option of ghs3d but NOT tepal)
1068 {
1069    QString tmp;
1070    std::fstream Ff(FileName.toLatin1().constData(),std::ios_base::in);
1071    long ne,np,npfixe,subnumber,reste;
1072    bool ok;
1073
1074    if (!Ff.is_open()){
1075       std::cerr<<"Problem File '"<<FileName.toLatin1().constData()<<"' not open\n"<<std::endl;
1076       return false;
1077    }
1078
1079    //lit les donnees :
1080    Ff>>ne>>np>>npfixe;
1081    if (verbose>3){
1082       std::cout<<"NoboiteNumberOfElements="<<ne<<std::endl;
1083       std::cout<<"NoboiteNumberOfVertices="<<np<<std::endl;
1084       std::cout<<"NoboiteNumberOfSpecifiedPoints="<<npfixe<<std::endl;
1085    }
1086
1087    for (int i=1; i<=17-3; i++) Ff>>reste;
1088    //printf("reste %ld\n",reste);
1089    med_int *tmint=new med_int[ne*4];
1090    for (int i=0; i<ne*4; i++) Ff>>tmint[i];
1091    if (verbose>4) std::cout<<"Elements "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[ne*4-1]<<std::endl;
1092
1093    CVWtab *montab=new CVWtab(ne*4,tmint);
1094    tmp=tmp.sprintf("NB%ld EV",this->nofile);
1095    ok=this->insert_key(tmp,montab);
1096
1097    med_float *tmflo=new med_float[np*3];
1098    for (int i=0; i<np*3; i++) Ff>>tmflo[i];
1099    if (verbose>4) std::cout<<"Vertices "<<tmflo[0]<<" "<<tmflo[1]<<"... "<<tmflo[np*3-1]<<std::endl;
1100
1101    montab=new CVWtab(np*3,tmflo);
1102    tmp=tmp.sprintf("NB%ld VC",this->nofile);
1103    ok=this->insert_key(tmp,montab);
1104
1105    Ff>>subnumber;
1106    if (verbose>2) std::cout<<"NumberOfSubdomains="<<subnumber<<std::endl;
1107    //tmint=new med_int[subnumber*3];
1108    tmint=new  med_int[subnumber*3];
1109    long onelong,maxint;
1110    maxint=std::numeric_limits<int>::max();
1111    //pb from tepalv2
1112    bool isproblem=true;
1113    for (int i=0; i<subnumber*3; i++) {
1114      Ff>>onelong;
1115      //pb from tepalv2
1116      if (onelong<0) {
1117       if (isproblem && verbose>1) std::cout<<"There is one or more negative med_int value in NumberOfSubdomains "<<onelong<<std::endl;
1118       isproblem=false;
1119       onelong=-1;
1120       }
1121      if (onelong>maxint) {
1122       if (isproblem && verbose>1) std::cout<<"There is one or more truncated med_int value in NumberOfSubdomains "<<onelong<<std::endl;
1123       isproblem=false;
1124       onelong=-2;
1125       }
1126      tmint[i]=(int)onelong;
1127      }
1128    if (verbose>4) std::cout<<"Subdomains "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[subnumber*3-1]<<std::endl;
1129
1130    montab=new CVWtab(subnumber*3,tmint);
1131    tmp=tmp.sprintf("NB%ld SN",this->nofile);
1132    ok=this->insert_key(tmp,montab);
1133
1134    //swap on file if too big for memory in one cpu
1135    //default 1GOctet/8(for double)/10(for arrays in memory at the same time)
1136    if (np*3>this->nbelem_limit_swap)
1137      this->SwapOutOfMemory_key_mesh_wrap(QRegExp("NB",Qt::CaseSensitive,QRegExp::RegExp));
1138    //beware record 6 lenght 1
1139    //ferme le fichier :
1140    Ff.close();
1141    this->nbfiles++;
1142    return true;
1143 }
1144
1145 //************************************
1146 bool ghs3dprl_mesh_wrap::ReadFileNOBOITEB(const QString FileName)
1147 //read file .noboiteb (volume)
1148 //for huge files it could be better use ReadFileNOBOITEB (B=binary format)
1149 //but NOT parameter option of tepal
1150 //idem ReadFileNOBOITE with read unformatted
1151 {
1152    bool ok;
1153    QString tmp;
1154    std::cerr<<"Problem function ReadFileNOBOITEB\n"
1155        <<"(no FORTRAN binary format files in tepal)\n\n";
1156    //file binary
1157    FILE *Ff=fopen(FileName.toLatin1().constData(),"rb");
1158    long ne,np,npfixe,reste,subnumber;
1159
1160    //http://www.math.utah.edu/software/c-with-fortran.html
1161    //record 1 from format FORTRAN begins and ends with lengh of record
1162    //=> 2*long(68)     (68=17*4octets)
1163    long r1[17+2];
1164    if (!Ff){
1165       std::cerr<<"Problem File '"<<FileName.toLatin1().constData()<<"' not open\n"<<std::endl;
1166       return false;
1167    }
1168    //read datas :
1169    fread(&r1,sizeof(long),17+2,Ff);
1170    for (long i=1; i<18; i++) std::cout<<"R1("<<i<<")="<<r1[i]<<std::endl;
1171
1172    if (r1[0]!=68){
1173       std::cerr<<"First FORTRAN record of File '"<<FileName.toLatin1().constData()<<"' not length 17*long"<<std::endl;
1174       return false;
1175    }
1176    ne=r1[1];
1177    np=r1[2];
1178    npfixe=r1[3];
1179    if (verbose>3){
1180       std::cout<<"NoboitebNumberOfElements="<<ne<<std::endl;
1181       std::cout<<"NoboitebNumberOfVertices="<<np<<std::endl;
1182       std::cout<<"NoboitebNumberOfSpecifiedPoints="<<npfixe<<std::endl;
1183    }
1184    //etc...could be done if necessary not debugged
1185    fread(&reste,sizeof(long),1,Ff);
1186    long *tlong=new long[ne*4];
1187    med_int *tmint=new med_int[ne*4];
1188    fread(tlong,sizeof(long),ne*4,Ff);
1189    fread(&reste,sizeof(long),1,Ff);
1190    for (long i=0; i<ne*4; i++) tmint[i]=tlong[i];
1191    delete tlong;
1192    if (verbose>4) std::cout<<"Elements "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[ne*4-1]<<std::endl;
1193
1194    CVWtab *montab=new CVWtab(ne*4,tmint);
1195    tmp=tmp.sprintf("NB%ld EV",this->nofile);
1196    ok=this->insert_key(tmp,montab);
1197
1198    fread(&reste,sizeof(long),1,Ff);
1199    //std::cout<<"info "<<reste<<" "<<np*3<<" "<<sizeof(med_float)<<std::endl;
1200    float *tfloat=new float[np*3];
1201    med_float *tmflo=new med_float[np*3];
1202    fread(tfloat,sizeof(float),np*3,Ff);
1203    fread(&reste,sizeof(long),1,Ff);
1204    for (long i=0; i<np*3; i++) tmflo[i]=tfloat[i];
1205    delete tfloat;
1206    if (verbose>4) printf("Vertices %g %g ... %g \n",tmflo[0],tmflo[1],tmflo[np*3-1]);
1207
1208    montab=new CVWtab(np*3,tmflo);
1209    tmp=tmp.sprintf("NB%ld VC",this->nofile);
1210    ok=this->insert_key(tmp,montab);
1211
1212    fread(&reste,sizeof(long),1,Ff);
1213    fread(&subnumber,sizeof(long),1,Ff);
1214    fread(&reste,sizeof(long),1,Ff);
1215    if (verbose>2) std::cout<<"NumberOfSubdomains="<<subnumber<<std::endl;
1216    fread(&reste,sizeof(long),1,Ff);
1217    tlong=new long[subnumber*3];
1218    fread(tlong,sizeof(long),subnumber*3,Ff);
1219    fread(&reste,sizeof(long),1,Ff);
1220    if (verbose>4) printf("Subdomains %ld %ld ... %ld \n",tlong[0],tlong[1],tlong[subnumber*3-1]);
1221
1222    tmint=new med_int[subnumber*3];
1223    for (long i=0; i<subnumber*3; i++) tmint[i]=tlong[i];
1224    delete tlong;
1225    montab=new CVWtab(subnumber*3,tmint);
1226    tmp=tmp.sprintf("NB%ld SN",this->nofile);
1227    ok=this->insert_key(tmp,montab);
1228
1229    //swap on file if too big for memory in one cpu
1230    //default 1GOctet/8(for double)/10(for arrays in memory at the same time)
1231    if (np*3>this->nbelem_limit_swap)
1232      this->SwapOutOfMemory_key_mesh_wrap(QRegExp("NB",Qt::CaseSensitive,QRegExp::RegExp));
1233
1234    //beware record 6 lenght 1
1235    //ferme le fichier :
1236    fclose(Ff);
1237    this->nbfiles++;
1238    return true;
1239 }
1240
1241 //************************************
1242 bool ghs3dprl_mesh_wrap::ReadFilePOINTS(const QString FileName)
1243 //read file .points (wrap)
1244 {
1245    QString tmp;
1246    long nb;
1247    long maxlen=128;
1248    bool ok=true;
1249
1250    //Lit les donnees :
1251    QFile Ff(FileName);
1252    //NOT Raw because Raw=non-buffered file access
1253    //qt3 ok=Ff.open(IO_ReadOnly|IO_Translate);
1254    ok=Ff.open(QIODevice::ReadOnly|QIODevice::Text);
1255    if (!ok){
1256       std::cerr<<"Problem File '"<<FileName.toLatin1().constData()<<"' not open\n"<<std::endl;
1257       return false;
1258    }
1259    tmp=Ff.readLine(maxlen);
1260    tmp=tmp.simplified();
1261    nb=tmp.toLong(&ok);
1262    if (!ok){
1263       std::cerr<<"Problem conversion File '"<<FileName.toLatin1().constData()<<"\n"<<std::endl;
1264       return false;
1265    }
1266    if (verbose>2) std::cout<<"NumberOfVertices="<<nb<<std::endl;
1267    med_float *tmflo=new med_float[3*nb]; //coordinates
1268    med_int *tmint=new med_int[nb];         //nrs (attribute of point)
1269    long il3=0;
1270    for ( long il=0; il<nb; il++ ){
1271       tmp=Ff.readLine(maxlen);
1272       tmp=tmp.simplified();
1273       for ( int j=0; j<3; j++ ){
1274          tmflo[il3]=tmp.section(' ',j,j).toDouble(&ok);
1275          //std::cout<<"cv '"<<tmflo[il3]<<"' "<<il3<<std::endl;
1276          il3++;
1277          if (!ok){
1278             std::cerr<<"Problem conversion File '"<<FileName.toLatin1().constData()<<"\n"<<std::endl;
1279             return false;
1280          }
1281       }
1282       //nrs is vertex attribute
1283       tmint[il]=tmp.section(' ',3,3).toLong(&ok);
1284       if (!ok){
1285          std::cerr<<"Problem conversion File '"<<FileName.toLatin1().constData()<<"\n"<<std::endl;
1286          return false;
1287       }
1288    }
1289    //beware no examples with each specified points (if any) here
1290    CVWtab *montab=new CVWtab(nb,tmint); //init montab->tmint nrs
1291    tmp=tmp.sprintf("PO%ld NRS",this->nofile);
1292    ok=this->insert_key(tmp,montab);
1293
1294    montab=new CVWtab(nb,tmflo); //init montab->tmflo xyz
1295    tmp=tmp.sprintf("PO%ld XYZ",this->nofile);
1296    ok=this->insert_key(tmp,montab);
1297
1298    //Ferme le fichier :
1299    Ff.close();
1300    this->nbfiles++;
1301    return true;
1302 }
1303
1304 //************************************
1305 bool ghs3dprl_mesh_wrap::list_keys_mesh_wrap()
1306 {
1307    QHashIterator<QString,CVWtab*> it( this->mestab);
1308    while ( it.hasNext() ) {
1309      it.next();
1310      QString nom = it.key().leftJustified(32,' ');
1311      std::cout<<nom.toLatin1().constData()<<"-> size="<<it.value()->size<<std::endl;
1312    }
1313    return true;
1314 }
1315
1316 //************************************
1317 long ghs3dprl_mesh_wrap::remove_all_keys_mesh_wrap()
1318 {
1319    long nb=this->remove_key_mesh_wrap(QRegExp(".",Qt::CaseSensitive,QRegExp::RegExp));
1320    return nb;
1321 }
1322
1323 //************************************
1324 long ghs3dprl_mesh_wrap::remove_key_mesh_wrap(const QRegExp &rxp)
1325 {
1326    long nbremove=0;
1327    QMutableHashIterator<QString,CVWtab*> it(this->mestab);
1328    while ( it.hasNext() ){
1329      it.next();
1330      if (it.key().contains(rxp)) {
1331         nbremove++;
1332         if (this->verbose>6) std::cout<<"remove key "<<it.key().toLatin1().constData()<<std::endl;
1333         delete it.value();
1334         it.remove();
1335      }
1336    }
1337    return nbremove;
1338 }
1339
1340 //************************************
1341 long ghs3dprl_mesh_wrap::nb_key_mesh_wrap(const QRegExp &rxp)
1342 {
1343    long nbremove=0;
1344    //std::cout<<"nb_key_mesh_wrap on "<<std::endl;
1345    QMutableHashIterator<QString,CVWtab*> it(this->mestab);
1346    while ( it.hasNext() ){
1347      it.next();
1348      if (it.key().contains(rxp)) nbremove++;
1349    }
1350    //std::cout<<"nb_key_mesh_wrap found "<<nbremove<<std::endl;
1351    return nbremove;
1352 }
1353
1354 //************************************
1355 bool SwapOnFile(const QString &key,const QString &path,CVWtab *tab,int verbose)
1356 //
1357 {
1358    //return true;
1359    if (tab->filename=="_NO_FILE"){
1360       tab->filename=path+key+".tmp";
1361       tab->filename.replace(" ","_"); //replace " " by "_"
1362
1363       //swap disque binaire
1364       //montab->tmint=new long[10]; //for test
1365       //for (int i=0; i<10; i++) montab->tmint[i]=i*2;
1366       FILE *fichier=fopen(tab->filename.toLatin1().constData(),"wb");
1367       long taille;
1368       taille=tab->size;
1369       fwrite(&taille,sizeof(taille),1,fichier);
1370       if (tab->tmint){
1371          if (verbose>3)
1372          std::cout<<"SwapOnFile_binary "<<tab->filename.toLatin1().constData()<<
1373          " NbElements "<<taille<<
1374          " SizeElement_med_int   "<<sizeof(med_int)<<
1375          " TotalSizeBinary " <<taille*sizeof(med_int)<<std::endl;
1376          fwrite(tab->tmint,sizeof(med_int),taille,fichier);
1377          //fread(&gagnants,sizeof(gagnants),1,fichier);
1378       }
1379       if (tab->tmflo){
1380          if (verbose>3)
1381          std::cout<<"SwapOnFile_binary "<<tab->filename.toLatin1().constData()<<
1382          " NbElements "<<taille<<
1383          " SizeElement_med_float "<<sizeof(med_float)<<
1384          " TotalSizeBinary " <<taille*sizeof(med_float)<<std::endl;
1385          fwrite(tab->tmflo,sizeof(med_float),taille,fichier);
1386       }
1387       fclose(fichier);
1388    }
1389    else{
1390       if (verbose>3) std::cout<<"SwapOnFile in binary file done yet "<<
1391          tab->filename.toLatin1().constData()<<std::endl;
1392    }
1393    //deallocate because swap disk binary mode
1394    tab->CVWtab_deallocate(); //free memory
1395    return true;
1396 }
1397
1398 //************************************
1399 long ghs3dprl_mesh_wrap::SwapOutOfMemory_key_mesh_wrap(const QRegExp &rxp,
1400                                                        long ifgreaterthan)
1401 //swap on file if not yet and if size greater than ifgreaterthan
1402 {
1403    long nb=0;
1404    bool ok;
1405    QHashIterator<QString,CVWtab*> it(this->mestab);
1406    while ( it.hasNext() ) {
1407      it.next();
1408      if (it.key().contains(rxp)) {
1409         nb++;
1410         if ((it.value()->size>0)&&(it.value()->size>ifgreaterthan)){
1411            if (verbose>3)
1412               std::cout<<"SwapOutOfMemory_key_mesh_wrap on demand "<<
1413                    it.key().toLatin1().constData()<<
1414                    " size "<<it.value()->size<<">"<<ifgreaterthan<<std::endl;
1415            //free memory
1416            ok=SwapOnFile(it.key(),this->path,it.value(),this->verbose);
1417        }
1418      }
1419    }
1420    return nb;
1421 }
1422 //************************************
1423 bool ghs3dprl_mesh_wrap::list_onekey_mesh_wrap(const QString &key)
1424 {
1425    CVWtab *montab=this->mestab[key];
1426    if (montab){
1427       //std::cout<<"key "<<key<<"trouvee -> size="<<montab->size<<std::endl;
1428       if (montab->type==1)
1429          for ( long i=0; i<montab->size; i++ )
1430             std::cout<<montab->tmint[i]<<" ";
1431       if (montab->type==2)
1432          for ( long i=0; i<montab->size; i++ )
1433             std::cout<<montab->tmflo[i]<<" ";
1434       std::cout<<std::endl;
1435    }
1436    else
1437       std::cout<<"key "<<key.toLatin1().constData()<<" not found"<<std::endl;
1438    return true;
1439 }
1440
1441 //************************************
1442 bool ghs3dprl_mesh_wrap::insert_key(const QString &key,CVWtab *tab)
1443 //insertion conditionnee par limite this->nbelem_limit_swap
1444 //si tableaux contenus on dimension superieure
1445 //alors swap disque dans getenv(tmp) fichier temporaire binaire
1446 {
1447    bool ok;
1448    if (verbose>4)
1449       std::cout<<"insert key "<<key.toLatin1().constData()<<
1450             " size="<<tab->size<<std::endl;
1451    tab->filename="_NO_FILE";
1452    if (this->nbelem_limit_swap<tab->size) {
1453       if (verbose>3) std::cout<<"insert key automatic SwapOnFile "<<
1454                            key.toLatin1().constData()<<std::endl;
1455       ok=SwapOnFile(key,this->path,tab,this->verbose);
1456    }
1457    this->mestab.insert(key,tab);
1458    return true;
1459 }
1460 //************************************
1461 CVWtab* ghs3dprl_mesh_wrap::restore_key(const QString &key)
1462 //retauration conditionnee par limite nbelem
1463 //si tableaux contenus on dimension superieure a nbelem
1464 //alors swap disque dans getenv(tmp) fichier temporaire
1465 //alors lecture du fichier (et reallocate memory)
1466 {
1467    CVWtab *tab=NULL;
1468    tab=this->mestab[key];
1469    /*if (tab) std::cout<<" -> size in proc "<<tab->size<<std::endl;
1470    else std::cout<<" -> tab NULL\n";*/
1471    if (!tab) //it is NOT a problem
1472    {
1473       if (verbose>6) std::cout<<"restore key not found "<<key.toLatin1().constData()<<std::endl;
1474       return NULL;
1475    }
1476    if (tab->size > 0){
1477       if (verbose>5) std::cout<<"restore key direct from memory "<<key.toLatin1().constData()<<" size="<<tab->size<<std::endl;
1478       return tab;
1479    }
1480    //restore from binary file
1481    if ((tab->type<1)||(tab->type>2)){
1482       std::cerr<<"Problem restore key from binary file "<<tab->filename.toLatin1().constData()<<
1483                " type unexpexted "<<tab->type<<std::endl;
1484       return NULL;
1485    }
1486    //std::cout<<"restore_key from binary file "<<tab->filename<<std::endl;
1487
1488    //swap disque binaire
1489    FILE *fichier=fopen(tab->filename.toLatin1().constData(),"rb");
1490    long taille;
1491    fread(&taille,sizeof(long),1,fichier);
1492    if (taille!=-tab->size){
1493       std::cerr<<"Problem restore_key from binary file "<<tab->filename.toLatin1().constData()<<
1494             " size unexpexted "<<taille<<" expected "<<-tab->size<<std::endl;
1495       fclose(fichier);
1496       return NULL;
1497    }
1498    if (tab->type==1){
1499       if (verbose>5)
1500       std::cout<<"restore key from binary file "<<tab->filename.toLatin1().constData()<<
1501             " number of elements "<<taille<<
1502             " size_element med_float "<<sizeof(med_float)<<
1503             " total_size_binary " <<taille*sizeof(med_float)<<std::endl;
1504
1505       //allocate because swap disque binaire
1506       tab->tmint=new med_int[taille]; //allocate memory
1507       fread(tab->tmint,sizeof(med_int),taille,fichier);
1508    }
1509    if (tab->type==2){
1510       if (verbose>5)
1511       std::cout<<"restore key from binary file "<<tab->filename.toLatin1().constData()<<
1512             " number of elements "<<taille<<
1513             " size_element med_float "<<sizeof(med_float)<<
1514             " total_size_binary " <<taille*sizeof(med_float)<<std::endl;
1515       //allocate because swap disque binaire
1516       tab->tmflo=new med_float[taille]; //allocate memory
1517       for (int i=0; i<taille ; i++) tab->tmflo[i]=-1e0;
1518       fread(tab->tmflo,sizeof(med_float),taille,fichier);
1519       /*for (int i=0; i<taille ; i++) std::cout<<tab->tmflo[i]<<"/";
1520       std::cout<<std::endl;*/
1521    }
1522    fclose(fichier);
1523    tab->size=-tab->size;
1524    return tab;
1525 }
1526
1527 //************************************
1528 bool ghs3dprl_mesh_wrap::test_msg_wrap()
1529 //tests sur resultats fichiers msg
1530 {
1531    QString key1,key2,typ="FA VE ED EL"; //pour faces vertice edges elements
1532    CVWtab *tab1,*tab2;
1533    bool ok=true;
1534    //test send=receive
1535    //numerotations locales sont identiques
1536    long nb=typ.count(' ',Qt::CaseSensitive) + 1; //nb chiffres detectes
1537    for (long i=0; i < nb; i++)
1538    for (long ifile=1; ifile <= this->nbfiles; ifile++)
1539    for (long ineig=1; ineig <= this->nbfiles; ineig++)
1540    {
1541       if (ifile==ineig) continue; //impossible
1542       key1=key1.sprintf("MS%ld NE%ld ",ifile,ineig)+typ.section(' ',i,i)+" SE";
1543       key2=key2.sprintf("MS%ld NE%ld ",ifile,ineig)+typ.section(' ',i,i)+" RE";
1544       //std::cout<<"key "<<key1<<" et key "<<key2<<std::endl;
1545       tab1=this->restore_key(key1);
1546       //tab1=this->mestab[key1];
1547       tab2=this->restore_key(key2);
1548       //tab2=this->mestab[key2];
1549       //std::cout<<"sortie key "<<key1<<" et key "<<key2<<std::endl;
1550       if (!tab1 && !tab2) continue; //case not neighbours
1551       if (!tab1)
1552       {  std::cout<<"key "<<key1.toLatin1().constData()<<" inexistante avec key "<<key2.toLatin1().constData()<<" existante"<<std::endl;
1553          ok=false;
1554       }
1555       else
1556       {
1557        if (!tab2)
1558        {  std::cout<<"key "<<key2.toLatin1().constData()<<" inexistante avec key "<<key1.toLatin1().constData()<<" existante"<<std::endl;
1559           ok=false;
1560        }
1561        else
1562         if (!tab1->is_equal(tab2))
1563         {  std::cout<<"key "<<key1.toLatin1().constData()<<" et key "<<key2.toLatin1().constData()<<" de contenu differents"<<std::endl;
1564            ok=false;
1565         }
1566       }
1567       /*else
1568          printf("key '%s' et key '%s' identiques \n",
1569                            (const char *)key2,(const char *)key1);*/
1570    }
1571
1572    //test size neighbourg=ifile
1573    //numerotations locales sont differentes mais de tailles identiques
1574    //pas besoin de verifier " RE " car deja fait au dessus
1575    for (long i=0; i < nb; i++)
1576    for (long ifile=1; ifile <= this->nbfiles; ifile++)
1577    for (long ineig=ifile+1; ineig <= this->nbfiles; ineig++)
1578    {
1579       if (ifile==ineig) continue; //cas impossible
1580       key1=key1.sprintf("MS%ld NE%ld ",ifile,ineig)+typ.section(' ',i,i)+" SE";
1581       tab1=this->restore_key(key1); //tab1=this->mestab[key1];
1582       key2=key2.sprintf("MS%ld NE%ld ",ineig,ifile)+typ.section(' ',i,i)+" SE";
1583       tab2=this->restore_key(key2); //tab2=this->mestab[key2];
1584       if (!tab1 && !tab2) continue; //case not neighbours
1585       if (!tab1)
1586       {  std::cout<<"key "<<key1.toLatin1().constData()<<" inexistante avec key "<<key2.toLatin1().constData()<<" existante"<<std::endl;
1587          ok=false;
1588       }
1589       else
1590       {
1591        if (!tab2)
1592        {  std::cout<<"key "<<key2.toLatin1().constData()<<" inexistante avec key "<<key1.toLatin1().constData()<<" existante"<<std::endl;
1593           ok=false;
1594        }
1595        else
1596         if ((tab1->type!=tab2->type)||(tab1->size!=tab2->size))
1597         {  std::cout<<"key "<<key1.toLatin1().constData()<<" et key "<<key2.toLatin1().constData()<<" de type ou tailles differents"<<std::endl;
1598            ok=false;
1599         }
1600       }
1601    }
1602    return ok;
1603 }
1604
1605 //************************************
1606 bool ghs3dprl_mesh_wrap::test_vertices_wrap()
1607 //tests sur vertices
1608 {
1609    QString key1,key2,key11,key22,key11old,key22old;
1610    CVWtab *tab1,*tab2,*tab11,*tab22;
1611    bool ok=true;
1612    key11old="_NO_KEY";key22old="_NO_KEY";
1613    //test size neighbourg=ifile
1614    //numerotations locales sont differentes mais de tailles identiques
1615    //pas besoin de verifier " RE " car deja fait au dessus
1616    //for (int ifile=1; ifile <= this->nbfiles; ifile++)
1617    //for (int ineig=ifile+1; ineig <= this->nbfiles; ineig++)
1618    bool swap=false;
1619    if (verbose>4)std::cout<<"test_vertices_wrap on nb files "<<this->nbfiles<<std::endl;
1620    for (int ifile=this->nbfiles; ifile >= 1; ifile--)
1621    for (int ineig=this->nbfiles; ineig >= ifile+1; ineig--)
1622    {
1623       if (ifile==ineig) continue; //cas impossible
1624       key1=key1.sprintf("MS%d NE%d VE SE",ifile,ineig);
1625       key11=key11.sprintf("NB%d VC",ifile);
1626       tab1=this->restore_key(key1); //tab1=this->mestab[key1];
1627       key2=key2.sprintf("MS%d NE%d VE SE",ineig,ifile);
1628       key22=key22.sprintf("NB%d VC",ineig);
1629       tab2=this->restore_key(key2); //tab2=this->mestab[key2];
1630       if (!tab1 && !tab2) continue; //cas non voisins
1631       if (!tab1)
1632       {
1633          std::cerr<<"TestEqualityCoordinates key "<<key1.toLatin1().constData()<<
1634                " NOT existing but key "<<key2.toLatin1().constData()<<" existing"<<std::endl;
1635          ok=false; continue;
1636       }
1637       if (!tab2)
1638       {
1639          std::cerr<<"TestEqualityCoordinates key "<<key2.toLatin1().constData()<<
1640                " NOT existing but key "<<key1.toLatin1().constData()<<" existing"<<std::endl;
1641          ok=false; continue;
1642       }
1643       if (tab1->size!=tab2->size)
1644       {
1645          std::cerr<<"TestEqualityCoordinates key "<<key1.toLatin1().constData()<<
1646                " and key "<<key2.toLatin1().constData()<<" NOT same size"<<std::endl;
1647          ok=false; continue;
1648       }
1649       if (ok)
1650       {
1651          if (swap) {
1652             //Swap out of memory if no use
1653             if ((key11old!=key11)&&(key11old!=key22))
1654                this->SwapOutOfMemory_key_mesh_wrap(QRegExp(key11old,Qt::CaseSensitive,QRegExp::RegExp));
1655             if ((key22old!=key11)&&(key22old!=key22))
1656                this->SwapOutOfMemory_key_mesh_wrap(QRegExp(key22old,Qt::CaseSensitive,QRegExp::RegExp));
1657          }
1658          tab11=this->restore_key(key11); //tab11=this->mestab[key11];
1659          tab22=this->restore_key(key22); //tab22=this->mestab[key22];
1660          if (tab11->size>this->nbelem_limit_swap ||
1661              tab22->size>this->nbelem_limit_swap) swap=true ;
1662          long i1,i2;
1663          bool ok1=true;
1664          //test on equality of xyz_coordinates of commons vertices
1665          for  (long j=0; j < tab1->size-1; j++)
1666          {
1667             i1=tab1->tmint[j];
1668             i2=tab2->tmint[j];
1669             //1 for print vertices not equals
1670             if (!CVW_is_equal_vertices(tab11,i1,tab22,i2,1))
1671             {
1672                std::cerr<<j<<" Vertice "<<i1<<" != Vertice "<<i2<<"\n"<<std::endl;
1673                ok=false; ok1=false;
1674             }
1675          }
1676          if ((verbose>2)&&(ok1))
1677             std::cout<<"TestEqualityCoordinates "<<tab1->size<<
1678                   " Vertices "<<key1.toLatin1().constData()<<" and "<<key2.toLatin1().constData()<<" ok"<<std::endl;
1679          if (!ok1)
1680             std::cerr<<"TestEqualityCoordinates "<<tab1->size<<
1681                   " Vertices "<<key1.toLatin1().constData()<<" and "<<key2.toLatin1().constData()<<" NO_OK"<<std::endl;
1682          key11old=key11; key22old=key22;
1683       }
1684    }
1685    //Swap out of memory (supposed no use?)
1686    //NO because NB1&NB2 VC supposed future use
1687    //YES precaution
1688    if (swap) {
1689       this->SwapOutOfMemory_key_mesh_wrap(QRegExp(key11old,Qt::CaseSensitive,QRegExp::RegExp));
1690       this->SwapOutOfMemory_key_mesh_wrap(QRegExp(key22old,Qt::CaseSensitive,QRegExp::RegExp));
1691    }
1692    return ok;
1693 }
1694
1695 //************************************
1696 bool ghs3dprl_mesh_wrap::Find_VerticesDomainToVerticesSkin()
1697 //initialise correspondances vertice skin et vertices locaux pour chaque domaine
1698 //calcule un med_int new tab[nb_vertices_of_domain]
1699 //avec nieme vertice of skin=tab[ieme vertice de domain]
1700 //apres verification tepal garde bien dans la global numbering "GLi VE"
1701 //les indices initiaux des noeuds (attention: de 1 a nbNodes) 
1702 {
1703    QString key1,key2,tmp;
1704    CVWtab *cooskin,*coodom,*glodom,*montab;
1705    bool ok=true;
1706    med_float *p1,*p2;
1707    med_int i,nb,jd,js;
1708
1709    cooskin=this->restore_key(QString("SKIN_VERTICES_COORDINATES"));
1710    if (!cooskin) return false;
1711    if (verbose>4)std::cout<<"NumberVerticesSKIN="<<cooskin->size/3<<std::endl;
1712    //ici pourrait creer BBtree sur skin
1713    for (int ifile=1; ifile<=this->nbfiles; ifile++)
1714    {
1715       key1=key1.sprintf("NB%ld VC",ifile);
1716       coodom=this->restore_key(key1);
1717       if (!coodom) continue; //Problem
1718       key2=key2.sprintf("GL%ld VE",ifile);
1719       glodom=this->restore_key(key2);
1720       if (verbose>4)
1721          std::cout<<"NumberVerticesDOMAIN_"<<ifile<<"="<<glodom->size<<std::endl;
1722       if (coodom->size!=glodom->size*3)
1723       {
1724          std::cerr<<"Find_VerticesDomainToVerticesSkin key "<<key1.toLatin1().constData()<<
1725                " and key "<<key2.toLatin1().constData()<<" NOT coherent sizes"<<std::endl;
1726          ok=false; continue;
1727       }
1728       //test on equality of xyz_coordinates of commons vertices
1729       med_int *tab=new med_int[glodom->size];
1730       i=0;
1731       nb=0; //nb equals vertices
1732     if (verbose>8){
1733       std::cout<<"\nglobal numbering nodes: no iglo\n";
1734       for  (jd=0; jd < glodom->size; jd++) 
1735            std::cout<<"\t"<<jd<<"\t"<<glodom->tmint[jd]<<std::endl;
1736       std::cout<<"\nresults: no i js iglo\n";
1737       for  (jd=0; jd < coodom->size; jd=jd+3)
1738       {
1739          p2=(coodom->tmflo+jd);
1740          tab[i]=0;
1741          //ici pourrait utiliser BBtree
1742          for  (js=0; js < cooskin->size; js=js+3)
1743          {
1744             p1=(cooskin->tmflo+js);
1745             if (p1[0]==p2[0] && p1[1]==p2[1] && p1[2]==p2[2]) 
1746             {
1747                std::cout<<"\t"<<nb<<"\t"<<i<<"\t"<<js/3<<"\t"<<glodom->tmint[i]-1<<
1748                  key2.sprintf("\t%13.5e%13.5e%13.5e",p1[0],p1[1],p1[2]).toLatin1().constData()<<std::endl;
1749                tab[i]=js/3; nb++; continue;
1750             }
1751          }
1752          i++;
1753       }
1754       montab=new CVWtab(glodom->size,tab);
1755       tmp=tmp.sprintf("NB%ld GL_SKIN",ifile);
1756       ok=this->insert_key(tmp,montab);
1757       if (verbose>4){
1758          std::cout<<"NumberOfEqualsVerticesDOMAIN_"<<ifile<<"="<<nb<<std::endl;
1759       }
1760     }
1761    }
1762    return ok;
1763 }
1764
1765 //fin utils procedures
1766
1767 //************************************
1768 bool ghs3dprl_mesh_wrap::Write_masterxmlMEDfile()
1769 {
1770    QString tmp;
1771
1772    //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!first call create xml doc node
1773    if (idom==1)
1774    {
1775    //define master file (.xml) in memory
1776    tmp=path+medname+".xml";
1777    filemaster=tmp.toLatin1().constData();
1778    domainname=medname.toLatin1().constData();
1779    char buff[256];
1780
1781    //Creating the XML document
1782    master_doc = xmlNewDoc(BAD_CAST "1.0");
1783    root_node = xmlNewNode(0, BAD_CAST "root");
1784    xmlDocSetRootElement(master_doc,root_node);
1785
1786    //Creating child nodes
1787    //Version tag
1788    med_int majeur,mineur,release;
1789    //Quelle version de MED est utilisee
1790    MEDlibraryNumVersion(&majeur,&mineur,&release);
1791    if (verbose>0) fprintf(stdout,"File write %s with MED V%d.%d.%d\n",filemaster.c_str(),majeur,mineur,release);
1792    node = xmlNewChild(root_node, 0, BAD_CAST "version",0);
1793    //xmlNewProp(node, BAD_CAST "maj", BAD_CAST int2string2(majeur).c_str());
1794    xmlNewProp(node, BAD_CAST "maj", BAD_CAST i2a(majeur).c_str());
1795    xmlNewProp(node, BAD_CAST "min", BAD_CAST i2a(mineur).c_str());
1796    xmlNewProp(node, BAD_CAST "ver", BAD_CAST i2a(release).c_str());
1797
1798    //Description tag
1799    node = xmlNewChild(root_node,0, BAD_CAST "description",0);
1800    // .../INSTALL/MeshGems/include/meshgems/meshgems.h:11:#define MESHGEMS_VERSION_LONG "2.9-6"
1801    xmlNewProp(node, BAD_CAST "what", BAD_CAST "tetrahedral mesh by MeshGems-Tetra-hpc 2.9-6 2019");
1802 #ifdef WIN32
1803   SYSTEMTIME  present;
1804   GetLocalTime ( &present );
1805   sprintf(buff,"%04d/%02d/%02d %02dh%02dm",
1806           present.wYear,present.wMonth,present.wDay,
1807           present.wHour,present.wMinute);
1808 #else
1809    time_t present;
1810    time(&present);
1811    struct tm *time_asc = localtime(&present);
1812    sprintf(buff,"%04d/%02d/%02d %02dh%02dm",
1813            time_asc->tm_year+1900,time_asc->tm_mon+1,time_asc->tm_mday,
1814            time_asc->tm_hour,time_asc->tm_min);
1815 #endif
1816    xmlNewProp(node, BAD_CAST "when", BAD_CAST buff);
1817    xmlNewProp(node, BAD_CAST "from", BAD_CAST "tepal2med");
1818
1819    //Content tag
1820    node =xmlNewChild(root_node,0, BAD_CAST "content",0);
1821    node2 = xmlNewChild(node, 0, BAD_CAST "mesh",0);
1822    xmlNewProp(node2, BAD_CAST "name", BAD_CAST domainname.c_str());
1823    info_node = xmlNewChild(node, 0, BAD_CAST "tepal2med_info",0);
1824
1825    //Splitting tag
1826    node=xmlNewChild(root_node,0,BAD_CAST "splitting",0);
1827    node2=xmlNewChild(node,0,BAD_CAST "subdomain",0);
1828    xmlNewProp(node2, BAD_CAST "number", BAD_CAST i2a(nbfilestot).c_str());
1829    node2=xmlNewChild(node,0,BAD_CAST "global_numbering",0);
1830    xmlNewProp(node2, BAD_CAST "present", BAD_CAST "yes");
1831
1832    //Files tag
1833    files_node=xmlNewChild(root_node,0,BAD_CAST "files",0);
1834
1835    //Mapping tag
1836    node = xmlNewChild(root_node,0,BAD_CAST "mapping",0);
1837    mesh_node = xmlNewChild(node, 0, BAD_CAST "mesh",0);
1838    xmlNewProp(mesh_node, BAD_CAST "name", BAD_CAST domainname.c_str());
1839    }
1840
1841    //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!all calls add xml idom node
1842    {
1843    fprintf(stdout,"Xml node write %s idom %d\n",filemaster.c_str(), idom);
1844    char *hostname = getenv("HOSTNAME");
1845    node = xmlNewChild(files_node,0,BAD_CAST "subfile",0);
1846    xmlNewProp(node, BAD_CAST "id", BAD_CAST i2a(idom).c_str());
1847    node2 = xmlNewChild(node, 0, BAD_CAST "name", BAD_CAST distfilename);
1848    
1849    if (hostname == NULL)
1850       node2 = xmlNewChild(node, 0, BAD_CAST "machine",BAD_CAST "localhost");
1851    else
1852       node2 = xmlNewChild(node, 0, BAD_CAST "machine",BAD_CAST hostname);
1853
1854    node = xmlNewChild(mesh_node,0,BAD_CAST "chunk",0);
1855    xmlNewProp(node, BAD_CAST "subdomain", BAD_CAST i2a(idom).c_str());
1856    node2 = xmlNewChild(node, 0, BAD_CAST "name", BAD_CAST nomfinal);
1857
1858    //tepal2med_info
1859    node = xmlNewChild(info_node, 0, BAD_CAST "chunk",0);
1860    xmlNewProp(node, BAD_CAST "subdomain", BAD_CAST i2a(idom).c_str());
1861    xmlNewProp(node, BAD_CAST "nodes_number", BAD_CAST i2a(nbnodes).c_str());
1862    xmlNewProp(node, BAD_CAST "faces_number", BAD_CAST i2a(nbtria3).c_str());
1863    xmlNewProp(node, BAD_CAST "tetrahedra_number", BAD_CAST i2a(nbtetra4).c_str());
1864    //node2 = xmlNewChild(node, 0, BAD_CAST "name", BAD_CAST nomfinal);
1865
1866    //node2 = xmlNewChild(node, 0, BAD_CAST "nodes", 0);
1867    //xmlNewProp(node2, BAD_CAST "number", BAD_CAST i2a(nbnodes).c_str());
1868    //node2 = xmlNewChild(node, 0, BAD_CAST "faces", 0);
1869    //xmlNewProp(node2, BAD_CAST "number", BAD_CAST i2a(nbtria3).c_str());
1870    //node2 = xmlNewChild(node, 0, BAD_CAST "tetrahedra", 0);
1871    //xmlNewProp(node2, BAD_CAST "number", BAD_CAST i2a(nbtetra4).c_str());
1872
1873    //tepal2med_info about joints of one subdomain
1874    fprintf(stdout,"MeshGems 2.9-6 tetra-hpc joints are not implemented\n");  //MeshGems 2.9-6 Salome 9.5.0 jan 2020
1875    // not implemented ... empty joints ... does NOT work ... xmlAddChild(node,joints_node);
1876    //tepal2med_info about groups and families of one subdomain
1877    xmlAddChild(node,families.xml_groups());
1878    }
1879
1880    //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!last call
1881    fprintf(stdout,"xml node idom %d/%d nb tetras total %d\n", idom, nbfilestot, nbtetrastotal);
1882    if (idom==nbfilestot)
1883    {
1884    fprintf(stdout,"File write %s as last idom nb tetras total %d\n",filemaster.c_str(), nbtetrastotal);
1885    node2 = xmlNewChild(info_node, 0, BAD_CAST "global",0);
1886    xmlNewProp(node2, BAD_CAST "tetrahedra_number", BAD_CAST i2a(nbtetrastotal).c_str());
1887    //save masterfile
1888    xmlSaveFormatFileEnc(filemaster.c_str(), master_doc, "UTF-8", 1);
1889    xmlFreeDoc(master_doc);
1890    xmlCleanupParser();
1891    }
1892    return true;
1893 }
1894
1895
1896 //************************************
1897 bool ghs3dprl_mesh_wrap::Write_MEDfiles_v2(bool deletekeys)
1898 //deletekeys=true to delete non utils keys and arrays "au fur et a mesure"
1899 {
1900    bool ok=true,oktmp;
1901    QString tmp,cmd;
1902    char description[MED_COMMENT_SIZE];
1903    char dtunit[MED_SNAME_SIZE+1]="_NO_UNIT";
1904    char axisname[MED_SNAME_SIZE*3+1]="x               y               z               ";
1905    char axisunit[MED_SNAME_SIZE*3+1]="_NO_UNIT        _NO_UNIT        _NO_UNIT        ";
1906    med_int nb;
1907    
1908    //remove path
1909    //precaution because casename->med_nomfinal no more 32 character
1910    //if path, in this->path.
1911    //20 preserve for add postfixes "_idom" etc...
1912    if (verbose>0)std::cout<<"\nWrite_MEDfiles_v2\n";
1913    if (verbose>6){std::cout<<"\nInitialFamilies\n"; families.write();}
1914
1915    medname=medname.section('/',-1);
1916    if (medname.length()>20) {
1917       std::cerr<<"CaseNameMed truncated (no more 20 characters)"<<std::endl;
1918       medname.truncate(20);
1919    }
1920
1921    //create file resume DOMAIN.joints.med of all joints for quick display (...may be...)
1922    tmp=path+medname+tmp.sprintf("_joints.med",idom);
1923    charendnull(distfilename,tmp,MED_COMMENT_SIZE);
1924    fidjoint=MEDfileOpen(distfilename,MED_ACC_CREAT);
1925    if (fidjoint<0) std::cerr<<"Problem MEDfileOpen "<<distfilename<<std::endl;
1926    if (verbose>0) std::cout<<"CreateMEDFile for all joints <"<<distfilename<<">\n";
1927
1928    //copy file source/GHS3DPRL_skin.med as destination/DOMAIN.skin.med
1929    tmp=path+medname+"_skin.med";
1930    cmd=pathini+casename+"_skin.med";
1931    int ret = access(cmd.toLatin1().constData(),F_OK); //on regarde si le fichier existe
1932    if (ret >= 0) {
1933 #ifdef WIN32
1934       cmd="copy ";
1935 #else 
1936       cmd="cp ";
1937 #endif
1938       cmd = cmd+pathini+casename+"_skin.med "+tmp;
1939       //std::cout<<"Copy skin.med Command = "<<cmd<<std::endl;
1940       system(cmd.toLatin1().constData()); 
1941       if (verbose>0) std::cout<<"CreateMEDFile for initial skin <"<<tmp.toLatin1().constData()<<">\n"; }
1942    else {
1943       if (verbose>0) std::cout<<"No CreateMEDFile <"<<tmp.toLatin1().constData()<<"> for initial skin because <"<<
1944                                                 cmd.toLatin1().constData()<<"> does not exist\n"; }
1945
1946    //define family 0 if not existing, no groups
1947    //La famille FAMILLE_ZERO n'a pas Ã©té trouvée, elle est obligatoire
1948    families.add("0","FAMILLE_ZERO");
1949    //define family Group_of_New_Nodes (which not exists before tetrahedra)
1950    famallnodes=0;
1951    if (QString("All_Nodes").contains(deletegroups)==0){
1952       oktmp=families.get_number_of_new_family(1,&famallnodes,&tmp);
1953       families.add(tmp,"All_Nodes");
1954    }
1955    else if (verbose>3) std::cout<<"--deletegroups matches \"All_Nodes\"\n";
1956    
1957    famalltria3=0;
1958    if (QString("All_Faces").contains(deletegroups)==0){
1959       oktmp=families.get_number_of_new_family(-1,&famalltria3,&tmp);
1960       families.add(tmp,"All_Faces");
1961    }
1962    else if (verbose>3) std::cout<<"--deletegroups matches \"All_Faces\"\n";
1963
1964    famalltetra4=0;
1965    if (QString("All_Tetrahedra").contains(deletegroups)==0){
1966       oktmp=families.get_number_of_new_family(-1,&famalltetra4,&tmp);
1967       families.add(tmp,"All_Tetrahedra");
1968    }
1969    else if (verbose>3) std::cout<<"--deletegroups matches \"All_Tetrahedra\"\n";
1970
1971    famnewnodes=0;
1972    if (QString("New_Nodes").contains(deletegroups)==0){
1973       oktmp=families.get_number_of_new_family(1,&famnewnodes,&tmp);
1974       families.add(tmp,"New_Nodes");
1975    }
1976    else if (verbose>3) std::cout<<"--deletegroups matches \"New_Nodes\"\n";
1977    
1978    famnewtria3=0;
1979    if (QString("New_Faces").contains(deletegroups)==0){
1980       oktmp=families.get_number_of_new_family(-1,&famnewtria3,&tmp);
1981       families.add(tmp,"New_Faces");
1982    }
1983    else if (verbose>3) std::cout<<"--deletegroups matches \"New_Faces\"\n";
1984    
1985    famnewtetra4=0;
1986    if (QString("New_Tetrahedra").contains(deletegroups)==0){
1987       oktmp=families.get_number_of_new_family(-1,&famnewtetra4,&tmp);
1988       families.add(tmp,"New_Tetrahedra");
1989    }
1990    else if (verbose>3) std::cout<<"--deletegroups matches \"New_Tetrahedra\"\n";
1991
1992    if (verbose>6){std::cout<<"\nIntermediatesFamilies\n"; families.write();}
1993    //if (verbose>6) std::cout<<"\nNumber0fFiles="<<nbfilestot<<std::endl;
1994    familles intermediatesfamilies=families;
1995    //initialisations on all domains
1996    nbtetrastotal=0;
1997
1998    //loop on the domains
1999    //for (idom=1; idom<=nbfilestot; idom++) {
2000    if (for_multithread) {
2001      nbfilestot=1;
2002      std::cout<<"\nset NumberOfFiles only one domain file as multithread="<<nbfilestot<<std::endl;
2003    }
2004
2005    // if (verbose>6) 
2006    std::cout<<"\nNumberOfFiles="<<nbfilestot<<std::endl;
2007
2008    for (idom=1; idom<=nbfilestot; idom++) {
2009    
2010       this->nbvert=0;  // will be set for current loop idom
2011       this->nbedge=0;
2012       this->nbtria=0;
2013       this->nbtetr=0;
2014
2015       this->nofile=idom;
2016       //restore initial context of families
2017       if (idom>1) families=intermediatesfamilies;
2018       //if (idom>1) continue;
2019       tmp=path+medname+tmp.sprintf("_%d.med",idom);
2020       charendnull(distfilename,tmp,MED_COMMENT_SIZE);
2021
2022       //std::cout<<"<"<<distfilename<<">"<<std::endl;
2023       fid=MEDfileOpen(distfilename,MED_ACC_CREAT);
2024       if (fid<0) {std::cerr<<"Problem MEDfileOpen "<<distfilename<<std::endl; goto erreur;}
2025       if (verbose>2) {
2026          std::cout<<std::endl;
2027          std::cout<<"CreateMEDFile "<<idom<<" <"<<distfilename<<">\n";
2028       }
2029  
2030       //create mesh
2031       tmp=medname+tmp.sprintf("_%d",idom);
2032       charendnull(nomfinal,tmp,MED_NAME_SIZE);
2033       tmp=tmp.sprintf("domain %d among %d",idom,nbfilestot);
2034       charendnull(description,tmp,MED_COMMENT_SIZE);
2035
2036       if (verbose>4) std::cout<<"Description : "<<description<<std::endl;
2037       err=MEDmeshCr(fid,nomfinal,3,3,MED_UNSTRUCTURED_MESH,description,dtunit,MED_SORT_DTIT,MED_CARTESIAN,axisname,axisunit);
2038       if (err<0) {std::cerr<<"Problem MEDmeshCr"<<nomfinal<<std::endl; goto erreur;}
2039
2040       if (!idom_nodes()) {std::cerr<<"Problem on Nodes"<<std::endl; goto erreur;}
2041       if (verbose>4) std::cout<<"\nEnd of Nodes ***\n"<<std::endl;
2042       if (!idom_edges()) {std::cerr<<"Problem on Edges"<<std::endl; goto erreur;}
2043       if (verbose>4) std::cout<<"\nEnd of Edges ***\n"<<std::endl;
2044       if (!idom_faces()) {std::cerr<<"Problem on Faces"<<std::endl; goto erreur;}
2045       if (verbose>4) std::cout<<"\nEnd of Faces ***\n"<<std::endl;
2046       if (!idom_tetras()) {std::cerr<<"Problem on tetrahedra"<<std::endl; goto erreur;}
2047       if (verbose>4) std::cout<<"\nEnd of Tetrahedra ***\n"<<std::endl;
2048       
2049       //non existing files msg mh-tetra_hpc v2.1.11
2050       //if (!idom_joints()) {std::cerr<<"Problem on Joints"<<std::endl; goto erreur;}
2051
2052       // if (!for_multithread) 
2053       {
2054         if (verbose>6){std::cout<<"\nFinalsFamilies\n"; families.write();}
2055         //for nodes families
2056         nb=create_families(fid,1);
2057         if (verbose>5)std::cout<<"NumberOfFamiliesNodes="<<nb<<" name "<<nomfinal<<std::endl;
2058
2059         if (verbose>8)
2060           std::cout<<"MEDmeshEntityFamilyNumberWr nodes "<<nbnodes<<":"<<
2061                 famnodes[0]<<"..."<<famnodes[nbnodes-1]<<" "<<std::endl;
2062
2063         err=MEDmeshEntityFamilyNumberWr(fid,nomfinal,MED_NO_DT,MED_NO_IT,MED_NODE,MED_UNDEF_GEOMETRY_TYPE,nbnodes,famnodes);
2064         delete[] famnodes;
2065         
2066         if (err<0) std::cerr<<"Problem MEDmeshEntityFamilyNumberWr nodes"<<std::endl;
2067
2068         //for others families
2069         nb=create_families(fid,-1);
2070         if (verbose>5)std::cout<<"NumberOfFamiliesFacesAndEdgesEtc="<<nb<<std::endl;
2071
2072         err=MEDmeshEntityFamilyNumberWr(fid,nomfinal,MED_NO_DT,MED_NO_IT,MED_CELL,MED_TRIA3,nbtria3,famtria3);
2073         if (verbose>8)
2074           std::cout<<"MEDmeshEntityFamilyNumberWr tria3 "<<nbtria3<<":"<<
2075                 famtria3[0]<<"..."<<famtria3[nbtria3-1]<<" "<<std::endl;
2076         delete[] famtria3;
2077         if (err<0) std::cerr<<"Problem MEDmeshEntityFamilyNumberWr tria3"<<std::endl;
2078
2079         err=MEDmeshEntityFamilyNumberWr(fid,nomfinal,MED_NO_DT,MED_NO_IT,MED_CELL,MED_TETRA4,nbtetra4,famtetra4);
2080         if (verbose>8)
2081           std::cout<<"MEDmeshEntityFamilyNumberWr tetra4 "<<nbtetra4<<":"<<
2082                 famtetra4[0]<<"..."<<famtetra4[nbtria3-1]<<" "<<std::endl;
2083         delete[] famtetra4;
2084         if (err<0) std::cerr<<"Problem MEDmeshEntityFamilyNumberWr tria3"<<std::endl;
2085       }
2086     
2087       MEDfileClose(fid); //no error
2088       //master.xml writings
2089       oktmp=Write_masterxmlMEDfile();
2090       continue;       //and loop on others domains
2091
2092       erreur:         //error
2093       ok=false;
2094       MEDfileClose(fid); //but loop on others domains
2095
2096    }
2097    
2098    MEDfileClose(fidjoint); //no error
2099    if (verbose>0)std::cout<<"\nTotalNumberOftetrahedra="<<nbtetrastotal<<std::endl;
2100    ok = true;
2101    
2102    return ok;
2103 }
2104
2105 //************************************
2106 bool ghs3dprl_mesh_wrap::idom_nodes()
2107 {
2108    bool ok=true;
2109    QString tmp,key,key1,key2,key3;
2110    CVWtab *tab,*tab1,*tab2,*tab3;
2111    med_int i,j,*arrayi;
2112    int xx;
2113
2114       //writing node(vertices) coordinates
2115       //NBx VC=files.NoBoite Vertex Coordinates
2116       key=key.sprintf("NB%d VC",idom); //files.NoBoite Vertex Coordinates
2117       tab=this->restore_key(key); //tab1=this->mestab[key1];
2118       if (!tab) {
2119          if (!for_tetrahpc) {
2120             tmp=pathini+casename+tmp.sprintf(format.toLatin1().constData(),nbfilestot,idom)+".noboite";
2121             ok=this->ReadFileNOBOITE(tmp);
2122          }
2123          if (for_tetrahpc) {
2124             tmp=pathini+casename+"_out"+tmp.sprintf(format_tetra.toLatin1().constData(),idom)+".mesh";
2125             ok=this->ReadFileMESH(tmp);
2126             if (for_multithread) { // inexisting file GHS3DPRL_out.000001.global
2127                this->ReadFileDefaultGLOBAL(this->nbvert, this->nbedge, this->nbtria, this->nbtetr);
2128             }
2129          }
2130          tab=this->restore_key(key); //tab1=this->mestab[key1];
2131          if (!tab) return false;
2132       }
2133       tmp=tmp.sprintf("NB%d SN",idom);
2134       //qt3 xx=this->remove_key_mesh_wrap(QRegExp(tmp,true,true));
2135       xx=this->remove_key_mesh_wrap(QRegExp(tmp,Qt::CaseSensitive,QRegExp::RegExp));
2136       nbnodes=this->nbvert; // for current idom
2137       
2138       err=MEDmeshNodeCoordinateWr(fid,nomfinal,MED_NO_DT,MED_NO_IT,0.,MED_FULL_INTERLACE,nbnodes,tab->tmflo);
2139       if (err<0) {std::cerr<<"Problem MEDmeshNodeCoordinateWr"<<std::endl; return false;}
2140       if (verbose>4) std::cout<<"NumberOfNodes="<<nbnodes<<std::endl;
2141
2142       //writing indices of nodes
2143       arrayi=new med_int[nbnodes];
2144       for (i=0; i<nbnodes ; i++) arrayi[i]=i+1;
2145       err=MEDmeshEntityNumberWr(fid,nomfinal,MED_NO_DT,MED_NO_IT,MED_NODE,MED_UNDEF_GEOMETRY_TYPE,nbnodes,arrayi);
2146       delete[] arrayi;
2147       if (err<0) {std::cerr<<"Problem MEDmeshEntityNumberWr of nodes"<<std::endl; return false;}
2148
2149     // if (!for_multithread) 
2150     {
2151       key1=key1.sprintf("GL%d VE",idom); //global numerotation 
2152       tab1=this->restore_key(key1); //tab1=this->mestab[key1];
2153       if (!tab1) {
2154          if (!for_tetrahpc) {
2155             tmp=pathini+casename+tmp.sprintf(format.toLatin1().constData(),nbfilestot,idom)+".glo";
2156             ok=this->ReadFileGLO(tmp);
2157          }
2158          if (for_tetrahpc) {
2159             tmp=pathini+casename+"_out"+tmp.sprintf(format_tetra.toLatin1().constData(),idom)+".global";
2160             ok=this->ReadFileGLOBAL(tmp);
2161          }
2162          if (!ok) {std::cerr<<"Problem file "<<tmp.toLatin1().constData()<<std::endl; return false;}
2163          tab1=this->restore_key(key1); //tab1=this->mestab[key1];
2164          if (!tab1) return false;
2165       }
2166       if (nbnodes!=tab1->size){std::cerr<<"Problem size GLi VE!=nbnodes!"<<std::endl; return false;}
2167
2168       key2=key2.sprintf("SKIN_VERTICES_FAMILIES",idom); //on global numerotation 
2169       tab2=this->restore_key(key2); //tab1=this->mestab[key1];
2170       med_int nbskin=0; 
2171       if (tab2) med_int nbskin=tab2->size;
2172       //for (i=0; i<nbskin; i++) std::cout<<i<<" "<<tab2->tmint[i]<<std::endl;
2173
2174       //set families of nodes existing in GHS3DPRL_skin.med
2175       med_int nb=nbnodes;
2176       famnodes=new med_int[nb];
2177       for (i=0; i<nb ; i++) famnodes[i]=famallnodes;
2178       med_int * fammore=new med_int[nb];
2179       for (i=0; i<nb ; i++) fammore[i]=famnewnodes;
2180
2181       //set families of nodes of skin
2182       for (i=0; i<nb ; i++){
2183          j=tab1->tmint[i]-1; //
2184          if (j<nbskin){
2185             fammore[i]=tab2->tmint[j];
2186          }
2187       }
2188       ok=set_one_more_family(famnodes,fammore,nb);
2189       delete[] fammore;
2190
2191       //std::cout<<"nodes loc "<<i<<" = gl "<<j<<"\t << "<<tab2->tmint[j]<<
2192       //      tmp.sprintf("\t%23.15e%23.15e%23.15e",tab3->tmflo[i*3],
2193       //      tab3->tmflo[i*3+1],tab3->tmflo[i*3+2])<<std::endl;
2194
2195       //writing nodes(vertices) global numbering
2196       err=MEDmeshGlobalNumberWr(fid,nomfinal,MED_NO_DT,MED_NO_IT,MED_NODE,MED_UNDEF_GEOMETRY_TYPE,nbnodes,tab1->tmint);
2197       if (err<0){std::cerr<<"Problem MEDmeshGlobalNumberWr nodes"<<std::endl; return false;}
2198     }
2199     
2200    return ok;
2201 }
2202
2203 /*
2204 //************************************
2205 bool ghs3dprl_mesh_wrap::set_one_more_family_old(med_int *fami, med_int *more, med_int nb)
2206 //fuse array of med_int families more et fami as kind of groups 
2207 //because there are possibilities of intersections
2208 {
2209    QString tmp;
2210    med_int i,newfam,morfam,oldfam;
2211    for (i=0; i<nb ; i++) {
2212       if (more[i]==0) continue;
2213       if (fami[i]==0) {
2214          fami[i]=more[i];
2215          //std::cout<<"sur "<<i<<" en plus "<<more[i]<<std::endl;
2216       }
2217       else { //intersection
2218          if (fami[i]==more[i]) continue; //same families
2219          oldfam=fami[i];
2220          morfam=more[i];
2221          //create new family intersection if needed
2222          newfam=families.find_family_on_groups(oldfam,morfam);
2223          //std::cout<<"oldfam "<<oldfam<<" morfam "<<morfam<<" -> newfam "<<newfam<<std::endl;
2224          fami[i]=newfam;
2225       }
2226    }
2227    return true;
2228 }*/
2229
2230 //************************************
2231 bool ghs3dprl_mesh_wrap::set_one_more_family(med_int *fami, med_int *more, med_int nb)
2232 //fuse array of med_int families more et fami as kind of groups 
2233 //because there are possibilities of intersections
2234 {
2235    QString tmp;
2236    med_int i,ii,j,newfam,morfam,oldfam,morfami,oldfami,i_zero,nb_fam,nb_max,nb_tot,nb_mess;
2237    med_int *newfami;
2238
2239    nb_fam=families.fam.size(); //on families negative and positive
2240    //std::cout<<"size families "<<nb_fam<<std::endl;
2241    if (nb_fam<=0) nb_fam=5;    //precaution
2242    i_zero=nb_fam*2;            //offset for negative indices of families
2243    nb_max=nb_fam*4;
2244    if (nb_fam>300) std::cout<<
2245       "***set_one_more_family*** warning many initial families could decrease speed "<<nb_fam<<std::endl;
2246    nb_tot=nb_max*nb_max;       //max oversizing *2 on families
2247    //newfami is for speed (avoid calls find_family_on_groups)
2248    //it is an array[nb_fam*4][nb_fam*4] implemented on vector[nb_max]
2249    //to memorize newfam in array[oldfam][morfam]
2250    newfami=new med_int[nb_tot];
2251    for (i=0; i<nb_tot ; i++) newfami[i]=0; //not yet met!
2252
2253    nb_mess=0;
2254    for (i=0; i<nb ; i++) {
2255       if (more[i]==0) continue;
2256       if (fami[i]==0) {
2257          fami[i]=more[i];
2258          //std::cout<<"sur "<<i<<" en plus "<<more[i]<<std::endl;
2259       }
2260       else { //intersection
2261          if (fami[i]==more[i]) continue; //same families
2262          oldfam=fami[i]; oldfami=oldfam+i_zero;
2263          morfam=more[i]; morfami=morfam+i_zero;
2264          //not yet met?
2265          ii=oldfami+morfami*nb_max; //array 2d on vector
2266          if ((ii>=0)&&(ii<nb_tot)) {
2267             newfam=newfami[ii];
2268          }
2269          else {
2270             if (nb_mess<3) {
2271                nb_mess++;
2272                std::cout<<"***set_one_more_family*** warning many new families decrease speed "<<nb_fam<<std::endl;
2273             }
2274             ii=-1;
2275             newfam=0;
2276          }
2277          if (newfam==0) {
2278             //create new family intersection if needed
2279             newfam=families.find_family_on_groups(oldfam,morfam);
2280             //std::cout<<"new oldfam "<<oldfam<<" morfam "<<morfam<<" -> newfam "<<newfam<<std::endl;
2281             if (ii>=0) newfami[ii]=newfam;
2282          }
2283          /*else {
2284             std::cout<<"!!! oldfam "<<oldfam<<" morfam "<<morfam<<" -> newfam "<<newfam<<std::endl;
2285          }*/
2286          fami[i]=newfam;
2287       }
2288    }
2289    delete[] newfami;
2290    return true;
2291 }
2292
2293 //************************************
2294 bool ghs3dprl_mesh_wrap::idom_edges()
2295 {
2296    bool ok=true;
2297    QString tmp;
2298    nbseg2=0;
2299    this->nbedge=0;
2300    return ok;
2301 }
2302
2303 //************************************
2304 bool ghs3dprl_mesh_wrap::idom_faces()
2305 {
2306    bool ok=true;
2307    QString tmp,key,key1,key2,key3;
2308    CVWtab *tab,*tab1,*tab2,*tab3;
2309    med_int ii,i,j,*arrayi;
2310    int xx;
2311
2312       //writing connectivity of faces triangles of wrap by nodes
2313       key1=key1.sprintf("FC%d",idom); //files.FaCes faces (wrap and triangles only)
2314       tab1=this->restore_key(key1); //tab1=this->mestab[key1];
2315       if (!tab1) {
2316          tmp=pathini+casename+tmp.sprintf(format.toLatin1().constData(),nbfilestot,idom)+".faces";
2317          ok=this->ReadFileFACES(tmp);
2318          tab1=this->restore_key(key1);
2319          if (!tab1) return false;
2320       }
2321       nbtria3=tab1->size/3;
2322       this->nbtria=nbtria3; // for current idom
2323
2324       if (verbose>4) std::cout<<"NumberOfTriangles="<<nbtria3<<std::endl;
2325       //arrayi=new med_int[nbtria3*3];
2326       //ii=0,i=0 ;
2327       //for (j=0; j<nbtria3 ; j++){
2328       //   arrayi[ii]=tab1->tmint[i]; ii++;
2329       //   arrayi[ii]=tab1->tmint[i+1]; ii++;
2330       //   arrayi[ii]=tab1->tmint[i+2]; ii++;
2331       //   i=i+7;
2332       //}
2333       //err=MEDmeshElementConnectivityWr(fid,nomfinal,MED_NO_DT,MED_NO_IT,0.,MED_CELL,MED_TRIA3,MED_NODAL,MED_FULL_INTERLACE,nbtria3,arrayi);
2334       err=MEDmeshElementConnectivityWr(fid,nomfinal,MED_NO_DT,MED_NO_IT,0.,MED_CELL,MED_TRIA3,MED_NODAL,MED_FULL_INTERLACE,nbtria3,tab1->tmint);
2335       //delete[] arrayi; //need immediately more little array
2336       if (err<0){std::cerr<<"Problem MEDmeshElementConnectivityWr for triangles connectivity"<<std::endl; return false;}
2337       
2338       //writing indices of faces triangles of wrap
2339       //caution!
2340       //generate "overlapping of numbers of elements" in "import med file" in salome
2341       //if not in "//writing indices of tetrahedra" -> arrayi[i]=!NBFACES!+i+1
2342       arrayi=new med_int[nbtria3]; 
2343       for (i=0; i<nbtria3 ; i++) arrayi[i]=nbseg2+i+1;
2344       err=MEDmeshEntityNumberWr(fid,nomfinal,MED_NO_DT,MED_NO_IT,MED_CELL,MED_TRIA3,nbtria3,arrayi);
2345       delete[] arrayi;
2346       if (err<0){std::cerr<<"Problem MEDmeshEntityNumberWr of triangles"<<std::endl; return false;}
2347
2348       //GLx FA=files.GLo FAces
2349       // if (!for_multithread) 
2350       {
2351         key1=key1.sprintf("GL%d FA",idom);
2352         tab1=this->restore_key(key1); //tab1=this->mestab[key1];
2353         if (nbtria3!=tab1->size){std::cerr<<"Problem size GLi FA!=nbtria3!"<<std::endl; return false;}
2354       
2355       
2356         key2=key2.sprintf("SKIN_TRIA3_FAMILIES",idom); //on global numerotation 
2357         tab2=this->restore_key(key2); //tab1=this->mestab[key1];
2358         med_int nbskin=0; 
2359         if (tab2) nbskin=tab2->size;
2360         
2361         //set families of faces existing in GHS3DPRL_skin.med
2362         med_int nb=nbtria3;
2363         famtria3=new med_int[nb];
2364         for (i=0; i<nb ; i++) famtria3[i]=famalltria3;
2365         med_int * fammore=new med_int[nb];
2366         for (i=0; i<nb ; i++) fammore[i]=famnewtria3;
2367
2368         //set families of faces of skin
2369         for (i=0; i<nb ; i++){
2370           j=tab1->tmint[i]-1; //
2371           if (j<nbskin){
2372               fammore[i]=tab2->tmint[j];
2373           }
2374         }
2375         ok=set_one_more_family(famtria3,fammore,nb);
2376         delete[] fammore;
2377         
2378         //writing faces(triangles) global numbering
2379         if (verbose>2)
2380           std::cout<<"CreateMEDglobalNumerotation_Faces "<<key1.toLatin1().constData()<<" "<<tab1->size<<std::endl;
2381         err=MEDmeshGlobalNumberWr(fid,nomfinal,MED_NO_DT,MED_NO_IT,MED_CELL,MED_TRIA3,tab1->size,tab1->tmint);
2382         if (err<0){std::cerr<<"Problem MEDmeshGlobalNumberWr faces"<<std::endl; return false;}
2383
2384         //xx=this->remove_key_mesh_wrap(QRegExp("FC*",true,true));
2385         tmp=tmp.sprintf("GL%d FA",idom);
2386         //qt3 xx=this->remove_key_mesh_wrap(QRegExp(tmp,true,true));
2387         xx=this->remove_key_mesh_wrap(QRegExp(tmp,Qt::CaseSensitive,QRegExp::RegExp));
2388         tmp=tmp.sprintf("GL%d VE",idom);
2389         //qt3 xx=this->remove_key_mesh_wrap(QRegExp(tmp,true,true));
2390         xx=this->remove_key_mesh_wrap(QRegExp(tmp,Qt::CaseSensitive,QRegExp::RegExp));
2391       }
2392
2393    return ok;
2394 }
2395
2396 //************************************
2397 bool ghs3dprl_mesh_wrap::idom_joints()
2398 {
2399    bool ok=true;
2400    QString tmp,namejoint,key,key1,key2;
2401    CVWtab *tab,*tab1,*tab2;
2402    med_int ineig,ii,jj,i,j,k,*arrayi,nb,famjoint,*fammore,*inodes,*arrayfaces;
2403    med_float *arraynodes;
2404    char namejnt[MED_NAME_SIZE+1];  //no more 32
2405    char namedist[MED_NAME_SIZE+1];
2406    char descjnt[MED_COMMENT_SIZE+1];
2407    med_int numfam_ini_wrap=100;
2408    joints_node=xmlNewNode(NULL, BAD_CAST "joints");  //masterfile.xml
2409    med_int nbjoints=0,nbnodesneig,nbtria3neig;
2410    std::string sjoints=""; //which domains are neighbourg
2411    int xx;
2412    char dtunit[MED_SNAME_SIZE+1]="_NO_UNIT";
2413    char axisname[MED_SNAME_SIZE*3+1]="x               y               z               ";
2414    char axisunit[MED_SNAME_SIZE*3+1]="_NO_UNIT        _NO_UNIT        _NO_UNIT        ";
2415
2416       tmp=tmp.sprintf("MS%d *",idom);
2417       //read file .msg if not done
2418       //qt3 if (this->nb_key_mesh_wrap(QRegExp(tmp,true,true))<=0) {
2419       if (this->nb_key_mesh_wrap(QRegExp(tmp,Qt::CaseSensitive,QRegExp::RegExp))<=0) {
2420          this->nofile=idom;
2421          
2422          if (!for_tetrahpc) {
2423             tmp=pathini+casename+tmp.sprintf(format.toLatin1().constData(),nbfilestot,idom)+".msg";
2424          }
2425          if (for_tetrahpc) {
2426             tmp=pathini+casename+tmp.sprintf(format_tetra.toLatin1().constData(),idom)+".msg";
2427          }
2428
2429          ok=this->ReadFileMSGnew(tmp);
2430          if (!ok) {
2431             std::cerr<<"Problem in file "<<tmp.toLatin1().constData()<<std::endl;
2432             return false;
2433          }
2434       }
2435
2436       //writing joints
2437       for (ineig=1; ineig <= nbfilestot; ineig++) {
2438          if (idom==ineig) continue; //impossible
2439
2440          //!*************nodes
2441          //std::cout<<"\n    nodes joints\n";
2442          key1=key1.sprintf("MS%d NE%d VE SE",idom,ineig); //SE or RE identicals
2443          tab1=restore_key(key1);
2444          if (!tab1) continue; //case (ifile,ineig) are not neighbours=>no joints
2445          key1=key1.sprintf("MS%d NE%d VE SE",ineig,idom); //SE or RE identicals
2446          tab2=this->restore_key(key1);
2447          //if not yet loaded (first time) try to load necessary file msg of neighbourg
2448          if (!tab2) {
2449             
2450             if (!for_tetrahpc) {
2451                tmp=pathini+casename+tmp.sprintf(format.toLatin1().constData(),nbfilestot,ineig)+".msg";
2452             }
2453             if (for_tetrahpc) {
2454                tmp=pathini+casename+tmp.sprintf(format_tetra.toLatin1().constData(),ineig)+".msg";
2455             }
2456             
2457             this->nofile=ineig; //neighbourg file
2458             ok=this->ReadFileMSGnew(tmp);
2459             this->nofile=idom;  //restaure initial domain
2460             if (!ok) {
2461                std::cerr<<"Problem in file "<<tmp.toLatin1().constData()<<std::endl;
2462                continue;
2463             }
2464             tab2=this->restore_key(key1);
2465          }
2466          if (!tab2) std::cerr<<"Problem existing nodes joint in domain "<<idom<<
2467                           " with none in neighbourg "<<ineig<<" files .msg"<<std::endl;
2468          nb=tab1->size; nbnodesneig=tab2->size;
2469          if (nb!=nbnodesneig) {
2470             std::cerr<<"Problem in file "<<tmp.toLatin1().constData()<<
2471                   " number of nodes of joint "<<idom<<"<->"<<ineig<<" not equals"<<std::endl;
2472             continue;
2473          }
2474
2475          nbjoints++; //one more joint for this domain
2476          sjoints=sjoints+" "+i2a(ineig);
2477          if (verbose>4)
2478             std::cout<<"NumberOfNodesOfJoint_"<<idom<<"_"<<ineig<<"="<<nb<<std::endl;
2479          namejoint=namejoint.sprintf("JOINT_%d_%d_Nodes",idom,ineig);
2480          strcpy(namejnt,namejoint.toLatin1().constData());
2481          tmp=tmp.sprintf("JOINT_%d_%d among %d domains of ",idom,ineig,nbfilestot)+nomfinal;
2482          strcpy(descjnt,tmp.toLatin1().constData());
2483          tmp=medname+tmp.sprintf("_%d",ineig);
2484          strcpy(namedist,tmp.toLatin1().constData());
2485          err=MEDsubdomainJointCr(fid,nomfinal,namejnt,descjnt,ineig,namedist);
2486          if (err<0) std::cerr<<"Problem MEDsubdomainJointCr"<<std::endl;
2487
2488          famjoint=0;
2489          if (namejoint.contains(deletegroups)==0){
2490             ok=families.get_number_of_new_family(1,&famjoint,&tmp);
2491             families.add(tmp,namejoint);
2492          }
2493
2494          key=key.sprintf("NB%d VC",idom); //files.NoBoite Vertex Coordinates
2495          tab=this->restore_key(key); //tab1=this->mestab[key1];
2496          nbnodes=tab->size/3;
2497
2498          //writing correspondence nodes-nodes
2499          //two indices for one correspondence
2500          arrayi=new med_int[nb*2];
2501          arraynodes=new med_float[nbnodesneig*3];  //for file DOMAIN_join.med
2502          inodes=new med_int[nbnodes];              //for file DOMAIN_join.med
2503          med_int * fammore=new med_int[nbnodes];
2504          for (i=0; i<nbnodes ; i++) {fammore[i]=0; inodes[i]=-2;}  //precautions
2505          ii=0; jj=0; k=1;
2506          for (i=0; i<nb ; i++){
2507             //no need because <send> equals <receive> tab1->tmint[i]==tab2->tmint[i]
2508             j=tab1->tmint[i]-1; //contents of tab1 1->nb, j 0->nb-1
2509             inodes[j]=k; k++;   //contents of inodes 1->n ,nodes of joint from nodes of domain
2510             arraynodes[jj]=tab->tmflo[j*3]; jj++;
2511             arraynodes[jj]=tab->tmflo[j*3+1]; jj++;
2512             arraynodes[jj]=tab->tmflo[j*3+2]; jj++;
2513
2514             fammore[j]=famjoint;
2515             arrayi[ii]=tab1->tmint[i]; ii++;
2516             arrayi[ii]=tab2->tmint[i]; ii++;
2517          }
2518          if (namejoint.contains(deletegroups)==0){
2519             ok=set_one_more_family(famnodes,fammore,nbnodes);
2520          }
2521          delete[] fammore;
2522
2523          err=MEDsubdomainCorrespondenceWr(fid,nomfinal,namejnt,MED_NO_DT,MED_NO_IT,
2524                  MED_NODE,MED_UNDEF_GEOMETRY_TYPE,MED_NODE,MED_UNDEF_GEOMETRY_TYPE,nb,arrayi);
2525          if (err<0) std::cerr<<"Problem MEDsubdomainCorrespondenceWr nodes"<<std::endl;
2526          delete[] arrayi;
2527
2528          //!*************TRIA3
2529          //writing correspondence triangles-triangles
2530          //std::cout<<"\n    faces joints\n";
2531          nbtria3neig=0;
2532          key1=key1.sprintf("MS%d NE%d FA SE",idom,ineig); //SE or RE identicals
2533          tab1=this->restore_key(key1); //tab1=this->mestab[key1];
2534          if (!tab1){
2535             if (verbose>4)
2536                std::cout<<"NumberOfTrianglesOfJoint_"<<idom<<"_"<<ineig<<"=0"<<std::endl;
2537             //continue; //case (ifile,ineig) are not neighbours=>no joints
2538          }
2539          else //have to set xml may be no faces but nodes in a joint!
2540          {
2541          key1=key1.sprintf("MS%d NE%d FA SE",ineig,idom); //SE or RE identicals
2542          tab2=this->restore_key(key1);
2543          if (!tab2) std::cerr<<"Problem existing triangles of joint in domain "<<idom<<
2544                                " with none in neighbourg "<<ineig<<" files .msg"<<std::endl;
2545          nb=tab1->size; nbtria3neig=tab2->size;
2546          if (nb!=nbtria3neig) {
2547             std::cerr<<"Problem in file "<<tmp.toLatin1().constData()<<
2548                   " number of triangles of joint "<<idom<<"<->"<<ineig<<" not equals"<<std::endl;
2549             continue;
2550          }
2551          namejoint=namejoint.sprintf("JOINT_%d_%d_Faces",idom,ineig);
2552          
2553          famjoint=0;
2554          if (namejoint.contains(deletegroups)==0){
2555             ok=families.get_number_of_new_family(-1,&famjoint,&tmp);
2556             families.add(tmp,namejoint);
2557          }
2558
2559          key=key.sprintf("FC%d",idom); //files.FaCes faces (wrap and triangles only)
2560          tab=this->restore_key(key); //tab1=this->mestab[key1];
2561
2562          med_int nb=tab1->size; nbtria3neig=nb;
2563          //if (verbose>=0) std::cout<<"NumberOfTrianglesOfJoint_"<<idom<<"_"<<ineig<<"="<<nb<<std::endl;
2564          arrayi=new med_int[nb*2]; //correspondance indices triangles in 2 domains
2565          arrayfaces=new med_int[nbtria3neig*3];  //for file DOMAIN_join.med
2566          for (i=0; i<nbtria3neig*3 ; i++) arrayfaces[i]=-1; //precaution
2567          fammore=new med_int[nbtria3];
2568          for (i=0; i<nbtria3 ; i++) fammore[i]=0;
2569          ii=0; jj=0;
2570          for (i=0; i<nb ; i++){
2571             arrayi[ii]=tab1->tmint[i]; ii++;
2572             arrayi[ii]=tab2->tmint[i]; ii++; //correspondance indices triangles in 2 domains
2573        
2574             fammore[tab1->tmint[i]-1]=famjoint;
2575             //famtria3[tab1->tmint[i]-1]=famjoint;
2576             
2577             k=tab1->tmint[i]-1; //indice of node connectivity
2578             //std::cout<<"k="<<k<<std::endl;
2579             k=k*7; //indice of node connectivity in tab of triangles
2580             
2581             arrayfaces[jj]=inodes[tab->tmint[k]-1]; jj++;
2582             arrayfaces[jj]=inodes[tab->tmint[k+1]-1]; jj++;
2583             arrayfaces[jj]=inodes[tab->tmint[k+2]-1]; jj++;
2584          }
2585          int happens=0;
2586          for (i=0; i<nbtria3neig*3 ; i++) {
2587            if (arrayfaces[i]<=0) {
2588              std::cerr<<"Problem file X_joints.med unknown node in joint "<<idom<<"_"<<ineig<<" face "<<i/3+1<<std::endl; //precaution
2589              happens=1;
2590            }
2591          }
2592          /*TODO DEBUG may be bug distene?
2593          if (happens==1) {
2594             std::cout<<"\nNumberOfTrianglesOfJoint_"<<idom<<"_"<<ineig<<"="<<nb<<std::endl;
2595             for (i=0; i<nbnodes ; i++) std::cout<<"inode i "<<i+1<<" "<<inodes[i]<<std::endl;
2596             for (i=0; i<tab1->size ; i++) std::cout<<"triangle i "<<i+1<<" "<<tab1->tmint[i]<<std::endl;
2597             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;
2598          }
2599          */
2600          if (namejoint.contains(deletegroups)==0){
2601             ok=set_one_more_family(famtria3,fammore,nbtria3);
2602          }
2603          delete[] fammore;
2604
2605          err=MEDsubdomainCorrespondenceWr(fid,nomfinal,namejnt,MED_NO_DT,MED_NO_IT,
2606                  MED_CELL,MED_TRIA3,MED_CELL,MED_TRIA3,nb,arrayi);
2607          if (err<0) std::cerr<<"Problem MEDsubdomainCorrespondenceWr triangles"<<std::endl;
2608          delete[] arrayi;
2609          }
2610
2611          //!write in file resume DOMAIN.joints.med of all joints for quick display (...may be...)
2612          if (idom<=ineig) { //no duplicate joint_1_2 and joint_2_1
2613           //create mesh
2614           namejoint=namejoint.sprintf("JOINT_%d_%d",idom,ineig);
2615           charendnull(namejnt,namejoint,MED_NAME_SIZE);
2616           tmp=tmp.sprintf("joint between %d and %d",idom,ineig);
2617           charendnull(descjnt,tmp,MED_COMMENT_SIZE);
2618           err=MEDmeshCr(fidjoint,namejnt,3,3,MED_UNSTRUCTURED_MESH,descjnt,dtunit,MED_SORT_DTIT,MED_CARTESIAN,axisname,axisunit);
2619           if (err<0) std::cerr<<"Problem MEDmeshCr "<<namejnt<<std::endl;
2620           //write nodes
2621           err=MEDmeshNodeCoordinateWr(fidjoint,namejnt,MED_NO_DT,MED_NO_IT,0.,MED_FULL_INTERLACE,nbnodesneig,arraynodes);
2622           if (err<0) std::cerr<<"Problem MEDmeshNodeCoordinateWr "<<namejnt<<std::endl;
2623           arrayi=new med_int[nbnodesneig];
2624           for (i=0; i<nbnodesneig ; i++) arrayi[i]=i+1;
2625           err=MEDmeshEntityNumberWr(fidjoint,namejnt,MED_NO_DT,MED_NO_IT,MED_NODE,MED_UNDEF_GEOMETRY_TYPE,nbnodesneig,arrayi);
2626           delete[] arrayi;
2627           if (err<0) std::cerr<<"Problem MEDmeshEntityNumberWr of nodes "<<namejnt<<std::endl;
2628           //families zero in file fidjoint ???
2629           //La famille FAMILLE_ZERO n'a pas Ã©té trouvée, elle est obligatoire
2630           nb=create_family_zero(fidjoint,namejnt);
2631           
2632           //write tria3
2633           if (nbtria3neig>0) {
2634            //for (i=0; i<nbtria3neig ; i++) std::cout<<i+1<<" "<<
2635            //    arrayfaces[i*3]<<" "<<arrayfaces[i*3+1]<<" "<<arrayfaces[i*3+2]<<std::endl;
2636            err=MEDmeshElementConnectivityWr(fidjoint,namejnt,MED_NO_DT,MED_NO_IT,0.,
2637                    MED_CELL,MED_TRIA3,MED_NODAL,MED_FULL_INTERLACE,nbtria3neig,arrayfaces);
2638            if (err<0) std::cerr<<"Problem MEDmeshElementConnectivityWr for triangles connectivity "<<namejnt<<std::endl;
2639            //writing indices of faces triangles of joint
2640            arrayi=new med_int[nbtria3neig]; 
2641            for (i=0; i<nbtria3neig ; i++) arrayi[i]=i+1;
2642            err=MEDmeshEntityNumberWr(fidjoint,namejnt,MED_NO_DT,MED_NO_IT,MED_CELL,MED_TRIA3,nbtria3neig,arrayi);
2643            delete[] arrayi;
2644            if (err<0) std::cerr<<"Problem MEDmeshEntityNumberWr of triangles "<<namejnt<<std::endl;
2645           }
2646          }
2647
2648          delete[] arraynodes;
2649          if (nbtria3neig>0) delete[] arrayfaces;
2650          delete[] inodes;
2651
2652          //!masterfile.xml
2653          node=xmlNewChild(joints_node, 0, BAD_CAST "joint", 0);
2654          xmlNewProp(node, BAD_CAST "id", BAD_CAST i2a(ineig).c_str());
2655          xmlNewProp(node, BAD_CAST "nodes_number", BAD_CAST i2a(nbnodesneig).c_str());
2656          xmlNewProp(node, BAD_CAST "faces_number", BAD_CAST i2a(nbtria3neig).c_str());
2657          //node2 = xmlNewChild(node, 0, BAD_CAST "nodes", 0);
2658          //xmlNewProp(node2, BAD_CAST "number", BAD_CAST i2a(nbnodesneig).c_str());
2659          //node2 = xmlNewChild(node, 0, BAD_CAST "faces", 0);
2660          //xmlNewProp(node2, BAD_CAST "number", BAD_CAST i2a(nbtria3neig).c_str());
2661       }
2662
2663    //masterfile.xml
2664    xmlNewProp(joints_node, BAD_CAST "number", BAD_CAST i2a(nbjoints).c_str());
2665    xmlNewChild(joints_node, 0, BAD_CAST "id_neighbours", BAD_CAST sjoints.substr(1).c_str());
2666    
2667    tmp=tmp.sprintf("NB%d VC",idom);
2668    //qt3 xx=this->remove_key_mesh_wrap(QRegExp(tmp,true,true));
2669    xx=this->remove_key_mesh_wrap(QRegExp(tmp,Qt::CaseSensitive,QRegExp::RegExp));
2670    //tmp=tmp.sprintf("MS%d NE*",idom);
2671    //qt3 xx=this->remove_key_mesh_wrap(QRegExp(tmp,true,true));
2672    //xx=this->remove_key_mesh_wrap(QRegExp(tmp,Qt::CaseSensitive,QRegExp::RegExp));
2673    tmp=tmp.sprintf("FC%d",idom);
2674    //qt3 xx=this->remove_key_mesh_wrap(QRegExp(tmp,true,true));
2675    xx=this->remove_key_mesh_wrap(QRegExp(tmp,Qt::CaseSensitive,QRegExp::RegExp));
2676    tmp=tmp.sprintf("GL%d *",idom);
2677    //qt3 xx=this->remove_key_mesh_wrap(QRegExp(tmp,true,true));
2678    xx=this->remove_key_mesh_wrap(QRegExp(tmp,Qt::CaseSensitive,QRegExp::RegExp));
2679    return ok;
2680 }
2681
2682 //************************************
2683 bool ghs3dprl_mesh_wrap::idom_tetras()
2684 {
2685    bool ok=true;
2686    QString tmp,key1;
2687    CVWtab *tab1;
2688    med_int i,*arrayi;
2689    int xx;
2690
2691       //writing connectivity of tetrahedra by nodes
2692       key1=key1.sprintf("NB%d EV",idom); //files.NoBoite Elements Vertices (tetra only)
2693       tab1=this->restore_key(key1); //tab1=this->mestab[key1];
2694       nbtetra4=tab1->size/4;
2695       this->nbtetr=nbtetra4; // for current idom
2696
2697       nbtetrastotal=nbtetrastotal + nbtetra4;
2698       if (verbose>5)std::cout<<"NumberOftetrahedra="<<nbtetra4<<std::endl;
2699       err=MEDmeshElementConnectivityWr(fid,nomfinal,MED_NO_DT,MED_NO_IT,0.,MED_CELL,MED_TETRA4,MED_NODAL,MED_FULL_INTERLACE,nbtetra4,tab1->tmint);
2700       if (err<0){std::cerr<<"Problem MEDmeshElementConnectivityWr for tetra connectivity"<<std::endl; return false;}
2701
2702       //writing indices of tetrahedra
2703       arrayi=new med_int[nbtetra4];
2704       for (i=0; i<nbtetra4 ; i++) arrayi[i]=nbseg2+nbtria3+i+1;
2705       //for (i=0; i<nbtria3 ; i++) std::cout<<i<<" "<<arrayi[i]<<std::endl;
2706       err=MEDmeshEntityNumberWr(fid,nomfinal,MED_NO_DT,MED_NO_IT,MED_CELL,MED_TETRA4,nbtetra4,arrayi);
2707       delete[] arrayi;
2708       if (err<0){std::cerr<<"Problem MEDmeshEntityNumberWr of tetrahedra"<<std::endl; return false;}
2709
2710       famtetra4=new med_int[nbtetra4];
2711       for (i=0; i<nbtetra4 ; i++) famtetra4[i]=famnewtetra4;
2712
2713       // if (!for_multithread) 
2714       {
2715         //writing tetrahedra global numbering
2716         //GLx EL=files.GLo ELements
2717         key1=key1.sprintf("GL%d EL",idom);
2718         tab1=this->restore_key(key1); //tab1=this->mestab[key1];
2719         if (!tab1) {
2720           //tmp=pathini+casename+tmp.sprintf(format.toLatin1().constData(),nbfilestot,idom)+".glo";
2721           //ok=this->ReadFileGLO(tmp);
2722           //tab1=this->restore_key(key1);
2723           //if (!tab1) return false;
2724
2725           if (!for_tetrahpc) {
2726               tmp=pathini+casename+tmp.sprintf(format.toLatin1().constData(),nbfilestot,idom)+".glo";
2727               ok=this->ReadFileGLO(tmp);
2728           }
2729           if (for_tetrahpc) {
2730               tmp=pathini+casename+"_out"+tmp.sprintf(format_tetra.toLatin1().constData(),idom)+".global";
2731               ok=this->ReadFileGLOBAL(tmp);
2732           }
2733           tab1=this->restore_key(key1);
2734           if (!tab1) return false;
2735
2736         }
2737
2738         if (tab1->size!=nbtetra4){
2739           std::cerr<<"Problem incorrect size of tetrahedra global numbering"<<std::endl; return false;}
2740         if (verbose>2)
2741           std::cout<<"CreateMEDglobalNumerotation_tetrahedra "<<key1.toLatin1().constData()<<" "<<tab1->size<<std::endl;
2742         err=MEDmeshGlobalNumberWr(fid,nomfinal,MED_NO_DT,MED_NO_IT,MED_CELL,MED_TETRA4,tab1->size,tab1->tmint);
2743         if (err<0){std::cerr<<"Problem MEDmeshGlobalNumberWr tetrahedra"<<std::endl; return false;}
2744       }
2745
2746       tmp=tmp.sprintf("NB%d EV",idom);
2747       //qt3 xx=this->remove_key_mesh_wrap(QRegExp(tmp,true,true));
2748       xx=this->remove_key_mesh_wrap(QRegExp(tmp,Qt::CaseSensitive,QRegExp::RegExp));
2749    return ok;
2750 }
2751
2752 //************************************
2753 med_int ghs3dprl_mesh_wrap::create_families(med_idt fid, int sign)
2754 //if sign < 0 families faces or tria3 etc...
2755 //if sign >= 0 family zero and family nodes
2756 {
2757    med_int pas,ires;
2758    char nomfam[MED_NAME_SIZE+1];  //it.current()->name;
2759    char attdes[MED_COMMENT_SIZE+1]="_NO_DESCRIPTION";
2760    char *gro;
2761    med_int i,attide=1,attval=1,natt=1,num,ngro;
2762    
2763    if (sign>=0) pas=1; else pas=-1;
2764    ires=0;
2765    fend gb;
2766    fagr::iterator it1;
2767    fend::iterator it2;
2768    for (it1=families.fam.begin(); it1!=families.fam.end(); ++it1){
2769       num=(*it1).first.toLong();
2770       if ((pas==-1) && (num>=0)) continue; //not good families
2771       if ((pas== 1) && (num< 0)) continue; //not good families
2772       charendnull(nomfam,(*it1).first,MED_NAME_SIZE);
2773       ires++;
2774       //med_int natt=0;
2775       ngro=(*it1).second.size();
2776       if (verbose>5) 
2777          std::cout<<"CreateFamilyInMEDFile <"<<nomfam<<">\tNbGroups="<<ngro;
2778       gro=new char[MED_LNAME_SIZE*ngro+2];
2779       gb=(*it1).second;
2780       i=0;
2781       for (it2=gb.begin(); it2!=gb.end(); ++it2){
2782          charendnull(&gro[i*MED_LNAME_SIZE],(*it2).first,MED_LNAME_SIZE);
2783          if (verbose>5)std::cout<<" <"<<&gro[i*MED_LNAME_SIZE]<<"> ";
2784          i++;
2785       }
2786       if (verbose>5)std::cout<<std::endl;
2787       err=MEDfamilyCr(fid,nomfinal,nomfam,num,ngro,gro);
2788       delete[] gro;
2789       if (err<0) std::cerr<<"Problem MEDfamilyCr of "<<nomfam<<std::endl;
2790    }
2791    return ires;
2792 }
2793
2794 med_int ghs3dprl_mesh_wrap::create_family_zero(med_idt fid, QString nameMesh)
2795 {
2796    med_int pas,ires;
2797    ires=0;
2798    char nomfam[MED_NAME_SIZE+1]="FAMILLE_ZERO";  //it.current()->name;
2799    char attdes[MED_COMMENT_SIZE+1]="_NO_DESCRIPTION";
2800    
2801    char *gro;
2802    med_int i,attide=1,attval=1,natt=1,num=0,ngro=0;
2803    
2804    gro=new char[MED_LNAME_SIZE*ngro+2];
2805    if (verbose>3)std::cout<<"\ncreate_family_ZERO "<<nameMesh.toLatin1().constData()<<std::endl;
2806    err=MEDfamilyCr(fid,nameMesh.toLatin1().constData(),nomfam,num,ngro,gro);
2807    if (err<0) std::cerr<<"Problem MEDfamilyCr FAMILLE_ZERO of "<<nameMesh.toLatin1().constData()<<std::endl;
2808    delete[] gro;
2809    return ires;
2810 }
2811
2812
2813