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