+
+#include <string>
+#include <iostream>
+#include <sstream>
+#include <fstream>
+#include <qstring.h>
+#include <qfile.h>
+#include "ghs3dprl_mesh_wrap.h"
+
+using namespace std;
+using namespace med_2_2;
+
+//************************************
+CVWtab::CVWtab(long nb, med_int *pmint)
+//constructor with pmint allocated yet with new
+{
+ //cout"***constructor med_int CVWtab***\n";
+ size=nb;
+ type=1; //only tmint valide
+ tmint=pmint;
+ tmflo=NULL;
+}
+
+//************************************
+CVWtab::CVWtab(long nb, med_float *pmflo)
+//constructor with pmflo allocated yet with new
+{
+ //cout<<"***constructor med_float CVWtab***\n";
+ size=nb;
+ type=2; //only tmflo valide
+ tmint=NULL;
+ tmflo=pmflo;
+}
+
+//************************************
+CVWtab::~CVWtab()
+{
+ bool ok;
+ //cout<<" destructor CVWtab *** "<<this->filename<<endl;
+ ok=this->CVWtab_deallocate();
+ //remove temporary file
+ if (this->filename!="_NO_FILE")
+ {
+ remove(this->filename); //#include <stdio.h>
+ //cout<<this->filename<<" successfully deleted\n";
+ }
+
+}
+
+//************************************
+bool CVWtab::CVWtab_deallocate()
+{
+ //cout<<" deallocate CVWtab*** "<<size<<endl;
+ if (size <= 0) return FALSE;
+ if (tmint)
+ {
+ delete[] tmint;
+ size=-size; //precaution
+ }
+ if (tmflo)
+ {
+ delete[] tmflo;
+ size=-size; //precaution
+ }
+ return TRUE;
+}
+
+//************************************
+bool CVWtab::is_equal(CVWtab *tab2)
+{
+ //cout<<"is_equal tab1 tab2 type="<<this->type<<" size="<<this->size<<" "<<tab2->size<<endl;
+ //if (this->type==1) cout<<"med_int tab1[0]="<<this->tmint[0]<<endl;
+ //if (this->type==2) cout<<"med_float tab1[0]="<<this->tmflo[0]<<endl;
+ if (this->size!=tab2->size) return FALSE;
+ if (this->type!=tab2->type) return FALSE;
+ if (this->type==1)
+ {
+ if (!this->tmint)
+ { cout<<"***is_equal*** pb pointer NULL with tmint size="<<this->size<<endl;
+ return FALSE;
+ }
+ for (long i=0; i < this->size; i++)
+ if (this->tmint[i]!=tab2->tmint[i]) return FALSE;
+ }
+ if (this->type==2)
+ {
+ if (!this->tmflo)
+ { cout<<"***is_equal*** pb pointer NULL with tmflo size="<<this->size<<endl;
+ return FALSE;
+ }
+ for (long i=0; i < this->size; i++)
+ if (this->tmflo[i]!=tab2->tmflo[i]) return FALSE;
+ }
+ return TRUE;
+}
+
+//************************************
+bool CVW_is_equal_vertices(CVWtab *tab1, long i1,
+ CVWtab *tab2, long i2, int verbose)
+//verbose 0 for no prints
+//verbose 1 for print vertices not equals
+//verbose 2 for print also vertices equals (debug)
+{
+ //cout<<"is_equal_vertice size="<<tab1->size<<" "<<tab2->size<<endl;
+ bool ok=FALSE;
+ med_float *p1,*p2;
+ //vertices indices from 1 not 0!
+ long di1=(i1-1)*3, di2=(i2-1)*3;
+ if (di1<0 || di1>=tab1->size)
+ {
+ cerr<<"BadIndice tab1 in is_equal_vertices "<<
+ di1<<" not in "<<tab1->size<<endl;
+ return FALSE;
+ }
+ if (di2<0 || di2>=tab2->size)
+ {
+ cerr<<"BadIndice tab2 in is_equal_vertices "<<
+ di2<<" not in "<<tab2->size<<endl;
+ return FALSE;
+ }
+ p1=(tab1->tmflo+di1);
+ p2=(tab2->tmflo+di2);
+ if (p1[0]==p2[0] && p1[1]==p2[1] && p1[2]==p2[2]) ok=TRUE ;
+ if (!ok && verbose>0) printf(
+ "Vertices differents (%.16g %.16g %.16g) (%.16g %.16g %.16g)\n",
+ p1[0],p1[1],p1[2],p2[0],p2[1],p2[2]);
+ else
+ if (verbose>1) printf(
+ "Vertices equals (%.16g %.16g %.16g)\n",
+ p1[0],p1[1],p1[2]);
+ return ok;
+}
+
+//************************************
+bool CVW_FindString(const string &str,fstream &Ff, long &count)
+//find in file first line with string str in first position of line
+//converts count value expected after "='" in line found
+{
+ string line;
+ do
+ {
+ if (getline(Ff,line))
+ {
+ if (line[0]==str[0]) //faster
+ {
+ if (line.find(str)==0)
+ {
+ QString tmp=line;
+ bool ok;
+ count=tmp.section('\'',1,1).toLong(&ok);
+ return ok;
+ }
+ }
+ }
+ else
+ {
+ cerr<<"Problem line '"<<str<<"' not found in file\n"<<endl;
+ return FALSE;
+ }
+ } while (1);
+ return TRUE;
+}
+
+//************************************
+bool ghs3dprl_mesh_wrap::ReadFileGLO(const QString FileName)
+//read file .glo with no parser xml because big file (volume)
+{
+ QString tmp;
+ fstream Ff((const char *)FileName,ios_base::in);
+ string line;
+ long count;
+ bool ok;
+
+ if (!Ff.is_open())
+ {
+ cerr<<"Problem File '"<<FileName<<"' not open\n"<<endl;
+ return FALSE;
+ }
+
+ //Lit les données :
+ if (!CVW_FindString("<vertices count=",Ff,count)) return FALSE;
+ if (this->verbose>2) cout<<"VerticesCount="<<count<<endl;
+ if (count>0)
+ {
+ med_int *tmint=new med_int[count];
+ for (int i=0; i<count; i++) Ff>>tmint[i];
+ if (this->verbose>4) cout<<"Elements "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[count-1]<<endl;
+
+ CVWtab *montab=new CVWtab(count,tmint);
+ tmp=tmp.sprintf("GL%ld VE",this->nofile);
+ ok=this->insert_key(tmp,montab);
+ }
+
+ if (!CVW_FindString("<edges count=",Ff,count)) return FALSE;
+ if (this->verbose>2) cout<<"EdgesCount="<<count<<endl;
+ if (count>0)
+ {
+ med_int *tmint=new med_int[count];
+ for (int i=0; i<count; i++) Ff>>tmint[i];
+ if (this->verbose>4) cout<<"Elements "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[count-1]<<endl;
+
+ CVWtab *montab=new CVWtab(count,tmint);
+ tmp=tmp.sprintf("GL%ld ED",this->nofile);
+ ok=this->insert_key(tmp,montab);
+ }
+
+ if (!CVW_FindString("<faces count=",Ff,count)) return FALSE;
+ if (this->verbose>2) cout<<"FacesCount="<<count<<endl;
+ if (count>0)
+ {
+ med_int *tmint=new med_int[count];
+ for (int i=0; i<count; i++) Ff>>tmint[i];
+ if (this->verbose>4) cout<<"Elements "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[count-1]<<endl;
+
+ CVWtab *montab=new CVWtab(count,tmint);
+ tmp=tmp.sprintf("GL%ld FA",this->nofile);
+ ok=this->insert_key(tmp,montab);
+ }
+
+ if (!CVW_FindString("<elements count=",Ff,count)) return FALSE;
+ if (this->verbose>2) cout<<"ElementsCount="<<count<<endl;
+ if (count>0)
+ {
+ med_int *tmint=new med_int[count];
+ for (int i=0; i<count; i++) Ff>>tmint[i];
+ if (this->verbose>4) cout<<"Elements "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[count-1]<<endl;
+
+ CVWtab *montab=new CVWtab(count,tmint);
+ tmp=tmp.sprintf("GL%ld EL",this->nofile);
+ ok=this->insert_key(tmp,montab);
+ }
+ //Ferme le fichier :
+ Ff.close();
+ this->nbfiles++;
+ return TRUE;
+}
+
+//************************************
+bool ghs3dprl_mesh_wrap::ReadFileFACES(const QString FileName)
+//read file .faces (wrap)
+{
+ QString tmp;
+ fstream Ff((const char *)FileName,ios_base::in);
+ string line;
+ long nbelem,ntype;
+ bool ok;
+
+ if (!Ff.is_open())
+ {
+ cerr<<"Problem File '"<<FileName<<"' not open\n"<<endl;
+ return FALSE;
+ }
+
+ //Lit les données :
+ //Replace le pointeur de fichier au début :f.seekg(0);
+ if (getline(Ff,line))
+ {
+ tmp=line;
+ nbelem=tmp.section(' ',0,0).toLong(&ok);
+ }
+ else
+ {
+ cerr<<"Problem on first line of file"<<endl;
+ return FALSE;
+ }
+ if (this->verbose>2) cout<<"NumberOfElements="<<nbelem<<endl;
+ med_int *tmint=new med_int[nbelem*7];
+ for (int i=0; i<nbelem*7; i=i+7)
+ {
+ Ff>>ntype;
+ if (ntype!=3) //only triangles
+ {
+ cerr<<"Problem on ntype != 3"<<endl;
+ return FALSE;
+ }
+ for (int j=0; j<7; j++) Ff>>tmint[i+j];
+ //for (int j=0; j<7; j++) cout<<tmint[i+j]<<' '; cout<<endl;
+ }
+ if (this->verbose>4) cout<<"Elements "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[nbelem*7-1]<<endl;
+
+ CVWtab *montab=new CVWtab(nbelem*7,tmint);
+ tmp=tmp.sprintf("FC%ld",this->nofile);
+ ok=this->insert_key(tmp,montab);
+
+ Ff.close();
+ this->nbfiles++;
+ return TRUE;
+}
+
+//************************************
+bool ghs3dprl_mesh_wrap::ReadFileNOBOITE(const QString FileName)
+//read file .noboite (volume)
+//for huge files it could be better use ReadFileNOBOITEB (B=binary format)
+//(parameter option of ghs3d but NOT tepal)
+{
+ QString tmp;
+ fstream Ff((const char *)FileName,ios_base::in);
+ long ne,np,npfixe,subnumber,reste;
+ bool ok;
+
+ if (!Ff.is_open())
+ {
+ cerr<<"Problem File '"<<FileName<<"' not open\n"<<endl;
+ return FALSE;
+ }
+
+ //lit les données :
+ Ff>>ne>>np>>npfixe;
+ if (this->verbose>2)
+ {
+ cout<<"NumberOfElements="<<ne<<endl;
+ cout<<"NumberOfVertices="<<np<<endl;
+ cout<<"NumberOfSpecifiedPoints="<<npfixe<<endl;
+ }
+ for (int i=1; i<=17-3; i++) Ff>>reste;
+ //printf("reste %ld\n",reste);
+ med_int *tmint=new med_int[ne*4];
+ for (int i=0; i<ne*4; i++) Ff>>tmint[i];
+ if (this->verbose>4) cout<<"Elements "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[ne*4-1]<<endl;
+
+ CVWtab *montab=new CVWtab(ne*4,tmint);
+ tmp=tmp.sprintf("NB%ld EV",this->nofile);
+ ok=this->insert_key(tmp,montab);
+
+ med_float *tmflo=new med_float[np*3];
+ for (int i=0; i<np*3; i++) Ff>>tmflo[i];
+ if (this->verbose>4) cout<<"Vertices "<<tmflo[0]<<" "<<tmflo[1]<<"... "<<tmflo[np*3-1]<<endl;
+
+ montab=new CVWtab(np*3,tmflo);
+ tmp=tmp.sprintf("NB%ld VC",this->nofile);
+ ok=this->insert_key(tmp,montab);
+
+ Ff>>subnumber;
+ if (this->verbose>2) cout<<"NumberOfSubdomains="<<subnumber<<endl;
+ tmint=new med_int[subnumber*3];
+ for (int i=0; i<subnumber*3; i++) Ff>>tmint[i];
+ if (this->verbose>4) cout<<"Subdomains "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[subnumber*3-1]<<endl;
+
+ montab=new CVWtab(subnumber*3,tmint);
+ tmp=tmp.sprintf("NB%ld SN",this->nofile);
+ ok=this->insert_key(tmp,montab);
+
+ //beware record 6 lenght 1
+ //ferme le fichier :
+ Ff.close();
+ this->nbfiles++;
+ return TRUE;
+}
+
+//************************************
+bool ghs3dprl_mesh_wrap::ReadFileNOBOITEB(const QString FileName)
+//read file .noboiteb (volume)
+//for huge files it could be better use ReadFileNOBOITEB (B=binary format)
+//but NOT parameter option of tepal
+//idem ReadFileNOBOITE with read unformatted
+{
+ bool ok;
+
+ cerr<<"Problem function ReadFileNOBOITEB\n"
+ <<"(no FORTRAN binary format files in tepal)\n\n";
+
+ QString tmp;
+ //file binary
+ FILE *Ff=fopen((const char *)FileName,"rb");
+ long ne,np,npfixe,reste,subnumber; /*,cube,npbli,
+ nbele,loele,nbelef,loelef,
+ nbpoi,lopoi,nbpoif,lopoif,
+ nbsub,losub,nbsubf,losubf,reste;*/
+
+ //http://www.math.utah.edu/software/c-with-fortran.html
+ //record 1 from format FORTRAN begins and ends with lengh of record
+ //=> 2*long(68) (68=17*4octets)
+ long r1[17+2];
+
+ if (!Ff)
+ {
+ cerr<<"Problem File '"<<FileName<<"' not open\n"<<endl;
+ return FALSE;
+ }
+
+ //read datas :
+ fread(&r1,sizeof(long),17+2,Ff);
+ for (long i=1; i<18; i++) cout<<"R1("<<i<<")="<<r1[i]<<endl;
+
+ if (r1[0]!=68)
+ {
+ cerr<<"First FORTRAN record of File '"<<FileName<<"' not length 17*long"<<endl;
+ return FALSE;
+ }
+ ne=r1[1];
+ np=r1[2];
+ npfixe=r1[3];
+ if (this->verbose>2)
+ {
+ cout<<"NumberOfElements="<<ne<<endl;
+ cout<<"NumberOfVertices="<<np<<endl;
+ cout<<"NumberOfSpecifiedPoints="<<npfixe<<endl;
+ }
+ ///etc...could be done if necessary not debugged
+ fread(&reste,sizeof(long),1,Ff);
+ long *tlong=new long[ne*4];
+ med_int *tmint=new med_int[ne*4];
+ fread(tlong,sizeof(long),ne*4,Ff);
+ fread(&reste,sizeof(long),1,Ff);
+ for (long i=0; i<ne*4; i++) tmint[i]=tlong[i];
+ delete tlong;
+ if (this->verbose>4) cout<<"Elements "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[ne*4-1]<<endl;
+
+ CVWtab *montab=new CVWtab(ne*4,tmint);
+ tmp=tmp.sprintf("NB%ld EV",this->nofile);
+ ok=this->insert_key(tmp,montab);
+
+ fread(&reste,sizeof(long),1,Ff);
+ //cout<<"info "<<reste<<" "<<np*3<<" "<<sizeof(med_float)<<endl;
+ float *tfloat=new float[np*3];
+ med_float *tmflo=new med_float[np*3];
+ fread(tfloat,sizeof(float),np*3,Ff);
+ fread(&reste,sizeof(long),1,Ff);
+ for (long i=0; i<np*3; i++) tmflo[i]=tfloat[i];
+ delete tfloat;
+ if (this->verbose>4) printf("Vertices %g %g ... %g \n",tmflo[0],tmflo[1],tmflo[np*3-1]);
+
+ montab=new CVWtab(np*3,tmflo);
+ tmp=tmp.sprintf("NB%ld VC",this->nofile);
+ ok=this->insert_key(tmp,montab);
+
+ fread(&reste,sizeof(long),1,Ff);
+ fread(&subnumber,sizeof(long),1,Ff);
+ fread(&reste,sizeof(long),1,Ff);
+ if (this->verbose>2) cout<<"NumberOfSubdomains="<<subnumber<<endl;
+ fread(&reste,sizeof(long),1,Ff);
+ tlong=new long[subnumber*3];
+ fread(tlong,sizeof(long),subnumber*3,Ff);
+ fread(&reste,sizeof(long),1,Ff);
+ if (this->verbose>4) printf("Subdomains %ld %ld ... %ld \n",tlong[0],tlong[1],tlong[subnumber*3-1]);
+
+ tmint=new med_int[subnumber*3];
+ for (long i=0; i<subnumber*3; i++) tmint[i]=tlong[i];
+ delete tlong;
+ montab=new CVWtab(subnumber*3,tmint);
+ tmp=tmp.sprintf("NB%ld SN",this->nofile);
+ ok=this->insert_key(tmp,montab);
+
+ //beware record 6 lenght 1
+ //ferme le fichier :
+ fclose(Ff);
+ this->nbfiles++;
+ return TRUE;
+
+}
+
+//************************************
+bool ghs3dprl_mesh_wrap::ReadFilePOINTS(const QString FileName)
+//read file .points (wrap)
+{
+ QString tmp;
+ long nb;
+ Q_ULONG maxlen=128;
+ Q_LONG lg;
+ bool ok=TRUE;
+
+ //Lit les données :
+ QFile Ff(FileName);
+ //NOT Raw because Raw=non-buffered file access
+ ok=Ff.open(IO_ReadOnly|IO_Translate);
+ if (!ok)
+ {
+ cerr<<"Problem File '"<<FileName<<"' not open\n"<<endl;
+ return FALSE;
+ }
+
+ lg=Ff.readLine(tmp,maxlen);
+ tmp=tmp.simplifyWhiteSpace();
+ nb=tmp.toLong(&ok);
+ if (!ok)
+ {
+ cerr<<"Problem conversion File '"<<FileName<<"\n"<<endl;
+ return FALSE;
+ }
+ if (this->verbose>2) cout<<"NumberOfVertices="<<nb<<endl;
+ med_float *tmflo=new med_float[3*nb]; //coordinates
+ med_int *tmint=new med_int[nb]; //nrs (attribute of point)
+ long il3=0;
+ for ( long il=0; il<nb; il++ )
+ {
+ lg=Ff.readLine(tmp,maxlen);
+ tmp=tmp.simplifyWhiteSpace();
+ //cout<<"lu '"<<tmp<<"'"<<lg<<endl;
+ for ( int j=0; j<3; j++ )
+ {
+ tmflo[il3]=tmp.section(' ',j,j).toDouble(&ok);
+ //cout<<"cv '"<<tmflo[il3]<<"' "<<il3<<endl;
+ il3++;
+ if (!ok)
+ {
+ cerr<<"Problem conversion File '"<<FileName<<"\n"<<endl;
+ return FALSE;
+ }
+ }
+ //nrs is vertex attribute
+ tmint[il]=tmp.section(' ',3,3).toLong(&ok);
+ if (!ok)
+ {
+ cerr<<"Problem conversion File '"<<FileName<<"\n"<<endl;
+ return FALSE;
+ }
+ }
+ //beware no examples with each specified points (if any) here
+
+ {CVWtab *montab=new CVWtab(nb,tmint); //init montab->tmint nrs
+ tmp=tmp.sprintf("PO%ld NRS",this->nofile);
+ ok=this->insert_key(tmp,montab);}
+
+ {CVWtab *montab=new CVWtab(nb,tmflo); //init montab->tmflo xyz
+ tmp=tmp.sprintf("PO%ld XYZ",this->nofile);
+ ok=this->insert_key(tmp,montab);}
+
+ //Ferme le fichier :
+ Ff.close();
+ this->nbfiles++;
+ return TRUE;
+}
+
+//************************************
+bool ghs3dprl_mesh_wrap::list_keys_mesh_wrap()
+{
+ QDictIterator<CVWtab> it( this->mestab);
+ for ( ; it.current(); ++it )
+ {
+ string nom=it.currentKey();
+ nom.resize(20,' ');
+ cout<<nom<<"-> size="<<it.current()->size<<endl;
+ }
+ return TRUE;
+}
+
+//************************************
+long ghs3dprl_mesh_wrap::remove_all_keys_mesh_wrap()
+{
+ long nb=this->remove_key_mesh_wrap(QRegExp(".",TRUE,FALSE));
+ return nb;
+}
+
+//************************************
+long ghs3dprl_mesh_wrap::remove_key_mesh_wrap(const QRegExp &rxp)
+{
+ long nbremove=0;
+ bool remove;
+ QDictIterator<CVWtab> it(this->mestab);
+ for ( ; it.current(); ++it )
+ {
+ do
+ {
+ long i=it.currentKey().contains(rxp);
+ remove=FALSE;
+ if (i>0)
+ {
+ nbremove++;
+ if (this->verbose>4) cout<<"remove key "<<it.currentKey()<<endl;
+ delete it.current();
+ this->mestab.remove(it.currentKey());
+ remove=TRUE;
+ }
+ //All dictionary iterators that refer to the removed item
+ //will be set to point to the next item
+ //in the dictionary's traversal order
+ } while (remove);
+ }
+ return nbremove;
+}
+
+//************************************
+bool SwapOnFile(const QString &key,const QString &path,CVWtab *tab,int verbose)
+//
+{
+ //return TRUE;
+ if (tab->filename=="_NO_FILE")
+ {
+ tab->filename=path+key+".tmp";
+ tab->filename.replace(" ","_"); //replace " " by "_"
+
+ //swap disque binaire
+ //montab->tmint=new long[10]; //for test
+ //for (int i=0; i<10; i++) montab->tmint[i]=i*2;
+ FILE *fichier=fopen(tab->filename,"wb");
+ long taille;
+ taille=tab->size;
+ fwrite(&taille,sizeof(taille),1,fichier);
+ if (tab->tmint)
+ {
+ if (verbose>3)
+ cout<<"SwapOnFile in binary file "<<tab->filename<<
+ " number of elements "<<taille<<
+ " size_element med_int "<<sizeof(med_int)<<
+ " total_size_binary " <<taille*sizeof(med_int)<<endl;
+ fwrite(tab->tmint,sizeof(med_int),taille,fichier);
+ //fread(&gagnants,sizeof(gagnants),1,fichier);
+ }
+ if (tab->tmflo)
+ {
+ if (verbose>3)
+ cout<<"SwapOnFile in binary file "<<tab->filename<<
+ " number of elements "<<taille<<
+ " size_element med_float "<<sizeof(med_float)<<
+ " total_size_binary " <<taille*sizeof(med_float)<<endl;
+ fwrite(tab->tmflo,sizeof(med_float),taille,fichier);
+ }
+ fclose(fichier);
+ }
+ else
+ {
+ if (verbose>3) cout<<"SwapOnFile in binary file done yet "<<tab->filename<<endl;
+ }
+ //deallocate because swap disk binary mode
+ tab->CVWtab_deallocate(); //free memory
+ return TRUE;
+}
+
+//************************************
+long ghs3dprl_mesh_wrap::SwapOutOfMemory_key_mesh_wrap(const QRegExp &rxp)
+//
+{
+ long nb=0;
+ bool ok;
+ QDictIterator<CVWtab> it(this->mestab);
+ for ( ; it.current(); ++it )
+ {
+ long i=it.currentKey().contains(rxp);
+ if (i>0)
+ {
+ nb++;
+ if (it.current()->size>0)
+ ok=SwapOnFile(it.currentKey(),this->path,it.current(),this->verbose); //free memory
+ //if (this->verbose) cout<<"SwapOutOfMemory key "<<it.currentKey()<<endl;
+ }
+ }
+ return nb;
+}
+//************************************
+bool ghs3dprl_mesh_wrap::list_onekey_mesh_wrap(const QString &key)
+{
+ CVWtab *montab=this->mestab[key];
+ if (montab)
+ {
+ //cout<<"key "<<key<<"trouvee -> size="<<montab->size<<endl;
+ if (montab->type==1)
+ for ( long i=0; i<montab->size; i++ )
+ cout<<montab->tmint[i]<<" ";
+ if (montab->type==2)
+ for ( long i=0; i<montab->size; i++ )
+ cout<<montab->tmflo[i]<<" ";
+ cout<<endl;
+ }
+ else
+ cout<<"key "<<key<<" not found"<<endl;
+ return TRUE;
+}
+
+//************************************
+bool ghs3dprl_mesh_wrap::insert_key(const QString &key,CVWtab *tab)
+//insertion conditionnée par limite this->nbelem_limit_swap
+//si tableaux contenus on dimension superieure
+//alors swap disque dans getenv(tmp) fichier temporaire binaire
+{
+ bool ok;
+ if (this->verbose>4)
+ cout<<"InsertKey "<<key<<" size="<<tab->size<<endl;
+ tab->filename="_NO_FILE";
+ if (this->nbelem_limit_swap < tab->size)
+ ok=SwapOnFile(key,this->path,tab,this->verbose);
+ this->mestab.insert(key,tab);
+ return TRUE;
+}
+//************************************
+CVWtab* ghs3dprl_mesh_wrap::restore_key(const QString &key)
+//retauration conditionnée par limite nbelem
+//si tableaux contenus on dimension superieure a nbelem
+//alors swap disque dans getenv(tmp) fichier temporaire
+//alors lecture du fichier (et reallocate memory)
+{
+ CVWtab *tab=NULL;
+ tab=this->mestab[key];
+ /*if (tab) cout<<" -> size in proc "<<tab->size<<endl;
+ else cout<<" -> tab NULL\n";*/
+ if (!tab) //it is NOT a problem
+ {
+ if (this->verbose>6) cout<<"restore_key key not found "<<key<<endl;
+ return NULL;
+ }
+ if (tab->size > 0)
+ {
+ if (this->verbose>5) cout<<"restore_key direct from memory "<<key<<" size="<<tab->size<<endl;
+ return tab;
+ }
+ //restore from binary file
+ if ((tab->type<1)||(tab->type>2))
+ {
+ cerr<<"Problem restore_key from binary file "<<tab->filename<<
+ " type unexpexted "<<tab->type<<endl;
+ return NULL;
+ }
+ //cout<<"restore_key from binary file "<<tab->filename<<endl;
+
+ //swap disque binaire
+ FILE *fichier=fopen(tab->filename,"rb");
+ long taille;
+ fread(&taille,sizeof(long),1,fichier);
+ if (taille!=-tab->size)
+ {
+ cerr<<"Problem restore_key from binary file "<<tab->filename<<
+ " size unexpexted "<<taille<<" expected "<<-tab->size<<endl;
+ fclose(fichier);
+ return NULL;
+ }
+ if (tab->type==1)
+ {
+ if (this->verbose>5)
+ cout<<"restore_key from binary file "<<tab->filename<<
+ " number of elements "<<taille<<
+ " size_element med_float "<<sizeof(med_float)<<
+ " total_size_binary " <<taille*sizeof(med_float)<<endl;
+
+ //allocate because swap disque binaire
+ tab->tmint=new med_int[taille]; //allocate memory
+ fread(tab->tmint,sizeof(med_int),taille,fichier);
+ }
+ if (tab->type==2)
+ {
+ if (this->verbose>5)
+ cout<<"restore_key from binary file "<<tab->filename<<
+ " number of elements "<<taille<<
+ " size_element med_float "<<sizeof(med_float)<<
+ " total_size_binary " <<taille*sizeof(med_float)<<endl;
+ //allocate because swap disque binaire
+ tab->tmflo=new med_float[taille]; //allocate memory
+ for (int i=0; i<taille ; i++) tab->tmflo[i]=-1e0;
+ fread(tab->tmflo,sizeof(med_float),taille,fichier);
+ /*for (int i=0; i<taille ; i++) cout<<tab->tmflo[i]<<"/";
+ cout<<endl;*/
+ }
+ fclose(fichier);
+ tab->size=-tab->size;
+ return tab;
+}
+
+//************************************
+bool ghs3dprl_mesh_wrap::test_msg_wrap()
+//tests sur resultats fichiers msg
+{
+ QString key1,key2,typ="FA VE ED EL"; //pour faces vertice edges elements
+ CVWtab *tab1,*tab2;
+ bool ok=TRUE;
+ //test send=receive
+ //numerotations locales sont identiques
+ long nb=typ.contains(' ',TRUE) + 1; //nb chiffres detectes
+ for (long i=0; i < nb; i++)
+ for (long ifile=1; ifile <= this->nbfiles; ifile++)
+ for (long ineig=1; ineig <= this->nbfiles; ineig++)
+ {
+ if (ifile==ineig) continue; //impossible
+ key1=key1.sprintf("MS%ld NE%ld ",ifile,ineig)+typ.section(' ',i,i)+" SE";
+ key2=key2.sprintf("MS%ld NE%ld ",ifile,ineig)+typ.section(' ',i,i)+" RE";
+ //cout<<"key "<<key1<<" et key "<<key2<<endl;
+ tab1=this->restore_key(key1);
+ //tab1=this->mestab[key1];
+ tab2=this->restore_key(key2);
+ //tab2=this->mestab[key2];
+ //cout<<"sortie key "<<key1<<" et key "<<key2<<endl;
+ if (!tab1 && !tab2) continue; //case not neighbours
+ if (!tab1)
+ { cout<<"key "<<key1<<" inexistante avec key "<<key2<<" existante"<<endl;
+ ok=FALSE;
+ }
+ else
+ {
+ if (!tab2)
+ { cout<<"key "<<key2<<" inexistante avec key "<<key1<<" existante"<<endl;
+ ok=FALSE;
+ }
+ else
+ if (!tab1->is_equal(tab2))
+ { cout<<"key "<<key1<<" et key "<<key2<<" de contenu differents"<<endl;
+ ok=FALSE;
+ }
+ }
+ /*else
+ printf("key '%s' et key '%s' identiques \n",
+ (const char *)key2,(const char *)key1);*/
+ }
+
+ //test size neighbourg=ifile
+ //numerotations locales sont differentes mais de tailles identiques
+ //pas besoin de verifier " RE " car deja fait au dessus
+ for (long i=0; i < nb; i++)
+ for (long ifile=1; ifile <= this->nbfiles; ifile++)
+ for (long ineig=ifile+1; ineig <= this->nbfiles; ineig++)
+ {
+ if (ifile==ineig) continue; //cas impossible
+ key1=key1.sprintf("MS%ld NE%ld ",ifile,ineig)+typ.section(' ',i,i)+" SE";
+ tab1=this->restore_key(key1); //tab1=this->mestab[key1];
+ key2=key2.sprintf("MS%ld NE%ld ",ineig,ifile)+typ.section(' ',i,i)+" SE";
+ tab2=this->restore_key(key2); //tab2=this->mestab[key2];
+ if (!tab1 && !tab2) continue; //case not neighbours
+ if (!tab1)
+ { cout<<"key "<<key1<<" inexistante avec key "<<key2<<" existante"<<endl;
+ ok=FALSE;
+ }
+ else
+ {
+ if (!tab2)
+ { cout<<"key "<<key2<<" inexistante avec key "<<key1<<" existante"<<endl;
+ ok=FALSE;
+ }
+ else
+ if ((tab1->type!=tab2->type)||(tab1->size!=tab2->size))
+ { cout<<"key "<<key1<<" et key "<<key2<<" de type ou tailles differents"<<endl;
+ ok=FALSE;
+ }
+ }
+ }
+ return ok;
+}
+
+//************************************
+bool ghs3dprl_mesh_wrap::test_vertices_wrap()
+//tests sur vertices
+{
+ QString key1,key2,key11,key22,key11old,key22old;
+ CVWtab *tab1,*tab2,*tab11,*tab22;
+ bool ok=TRUE;
+ key11old="_NO_KEY";key22old="_NO_KEY";
+ //test size neighbourg=ifile
+ //numerotations locales sont differentes mais de tailles identiques
+ //pas besoin de verifier " RE " car deja fait au dessus
+ //for (int ifile=1; ifile <= this->nbfiles; ifile++)
+ //for (int ineig=ifile+1; ineig <= this->nbfiles; ineig++)
+ for (int ifile=this->nbfiles; ifile >= 1; ifile--)
+ for (int ineig=this->nbfiles; ineig >= ifile+1; ineig--)
+ {
+ if (ifile==ineig) continue; //cas impossible
+ key1=key1.sprintf("MS%d NE%d VE SE",ifile,ineig);
+ key11=key11.sprintf("NB%d VC",ifile);
+ tab1=this->restore_key(key1); //tab1=this->mestab[key1];
+ key2=key2.sprintf("MS%d NE%d VE SE",ineig,ifile);
+ key22=key22.sprintf("NB%d VC",ineig);
+ tab2=this->restore_key(key2); //tab2=this->mestab[key2];
+ if (!tab1 && !tab2) continue; //cas non voisins
+ if (!tab1)
+ {
+ cerr<<"TestEqualityCoordinates key "<<key1<<" NOT existing but key "<<key2<<" existing"<<endl;
+ ok=FALSE; continue;
+ }
+ if (!tab2)
+ {
+ cerr<<"TestEqualityCoordinates key "<<key2<<" NOT existing but key "<<key1<<" existing"<<endl;
+ ok=FALSE; continue;
+ }
+ if (tab1->size!=tab2->size)
+ {
+ cerr<<"TestEqualityCoordinates key "<<key1<<" and key "<<key2<<" NOT same size"<<endl;
+ ok=FALSE; continue;
+ }
+ if (ok)
+ {
+ //Swap out of memory if no use
+ if ((key11old!=key11)&&(key11old!=key22))
+ this->SwapOutOfMemory_key_mesh_wrap(QRegExp(key11old,TRUE,FALSE));
+ if ((key22old!=key11)&&(key22old!=key22))
+ this->SwapOutOfMemory_key_mesh_wrap(QRegExp(key22old,TRUE,FALSE));
+
+ tab11=this->restore_key(key11); //tab11=this->mestab[key11];
+ tab22=this->restore_key(key22); //tab22=this->mestab[key22];
+ long i1,i2;
+ bool ok1=TRUE;
+ //test on equality of xyz_coordinates of commons vertices
+ for (long j=0; j < tab1->size-1; j++)
+ {
+ i1=tab1->tmint[j];
+ i2=tab2->tmint[j];
+ //1 for print vertices not equals
+ if (!CVW_is_equal_vertices(tab11,i1,tab22,i2,1))
+ {
+ cerr<<j<<" Vertice "<<i1<<" != Vertice "<<i2<<"\n"<<endl;
+ ok=FALSE; ok1=FALSE;
+ }
+ }
+ if ((this->verbose>2)&&(ok1))
+ cout<<"TestEqualityCoordinates "<<tab1->size<<
+ " Vertices "<<key1<<" and "<<key2<<" ok"<<endl;
+ if (!ok1)
+ cerr<<"TestEqualityCoordinates "<<tab1->size<<
+ " Vertices "<<key1<<" and "<<key2<<" NO_OK"<<endl;
+ key11old=key11; key22old=key22;
+ }
+ }
+ //Swap out of memory (supposed no use?)
+ //NO because NB1&NB2 VC supposed future use
+ //YES precaution
+ this->SwapOutOfMemory_key_mesh_wrap(QRegExp(key11old,TRUE,FALSE));
+ this->SwapOutOfMemory_key_mesh_wrap(QRegExp(key22old,TRUE,FALSE));
+ return ok;
+}
+
+//************************************
+bool ghs3dprl_mesh_wrap::Write_MEDfiles()
+{
+ bool ok=FALSE,oklocal;
+ QString key1,tmp,filename;
+ CVWtab *tab1,*tab2;
+ med_err err;
+ char namelocal[MED_TAILLE_NOM+1]; //no more 32
+ char distfilename[MED_TAILLE_DESC+1];
+ char description[MED_TAILLE_DESC+1];
+
+ //remove path
+ //precaution because casename->med_namelocal no more 32 character
+ //if path, in this->path.
+ //20 preserve for add postfixes "_idom" etc...
+ this->casename=this->casename.section('/',-1);
+ if (this->casename.length()>20)
+ {
+ cerr<<"CaseNameMed truncated (no more 20 characters)"<<endl;
+ this->casename.truncate(20);
+ }
+ filename=this->path+this->casename;
+ ofstream file(filename); //master file
+ file<<"#MED Fichier V 2.3"<<" "<<endl;
+ file<<"# NumbersOfSubDomains"<<" "<<endl;
+ int nbdomains=this->nbfiles;
+ file<<nbdomains<<" "<<endl;
+
+ //loop on the domains
+ for (int idom=1; idom<=nbdomains; idom++)
+ {
+ oklocal=TRUE;
+ ostringstream suffix;
+ suffix<<filename<<"_"<<idom<<".med";
+ strcpy(distfilename,suffix.str().c_str());
+ //tmp=filename+tmp.sprintf("_%d.med",idom);
+ //strcpy(distfilename,tmp);
+ if (this->verbose>0)
+ {
+ if (this->verbose>2) cout<<endl;
+ cout<<"CreateMEDFile "<<idom<<" "<<distfilename<<endl;
+ }
+
+ med_idt fid=MEDouvrir(distfilename,MED_CREATION);
+ if (fid<0) cerr<<"Problem MEDouvrir "<<distfilename<<endl;
+
+ //updating the ascii master description file
+ tmp=tmp.sprintf(this->casename+"_%d",idom);
+ file<<this->casename<<" "<<idom<<" "<<
+ tmp<<" "<<"localhost "<<distfilename<<" "<<endl;
+
+ //create mesh
+ strcpy(namelocal,tmp);
+ tmp=tmp.sprintf("domain %d among %d",idom,nbdomains);
+ strcpy(description,tmp);
+ if (this->verbose>4) cout<<"File "<<distfilename<<" : "<<description<<endl;
+ //cout<<namelocal<<":"<<description<<endl
+ err=MEDmaaCr(fid,namelocal,3,MED_NON_STRUCTURE,description);
+ if (err<0) cerr<<"Problem MEDmaaCr"<<endl;
+
+ //writing node(vertices) coordinates
+ //NBx VC=files.NoBoite Vertex Coordinates
+ // 123456789012345612345678901234561234567890123456
+ char nomcoo[3*MED_TAILLE_PNOM+1]="x y z ";
+ char unicoo[3*MED_TAILLE_PNOM+1]="? ? ? ";
+ key1=key1.sprintf("NB%d VC",idom); //files.NoBoite Vertex Coordinates
+ tab1=this->restore_key(key1); //tab1=this->mestab[key1];
+ med_int nbnodes=tab1->size/3;
+
+ /*(med_idt fid, char *maa, med_int mdim, med_float *coo,
+ med_mode_switch mode_switch, med_int n,
+ med_repere type_rep, char *nom, char *unit)*/
+ err=MEDcoordEcr(fid,namelocal,3,tab1->tmflo,MED_FULL_INTERLACE,
+ nbnodes,MED_CART,nomcoo,unicoo);
+ if (err<0) cerr<<"Problem MEDcoordEcr"<<endl;
+ if (this->verbose>4)cout<<"NumberOfNodes="<<nbnodes<<endl;
+ this->SwapOutOfMemory_key_mesh_wrap(QRegExp(key1,TRUE,FALSE));
+
+ //writing indices of nodes
+ med_int *arrayi=new med_int[nbnodes];
+ for (long i=0; i<nbnodes ; i++) arrayi[i]=i+1;
+ med_2_2::med_geometrie_element medgeoele0=(med_2_2::med_geometrie_element) 0;
+ err=MEDnumEcr(fid,namelocal,arrayi,nbnodes,MED_NOEUD,medgeoele0);
+ if (err<0) cerr<<"Problem MEDnumEcr of nodes"<<endl;
+ delete[] arrayi;
+
+ //writing connectivity of faces triangles of wrap by nodes
+ key1=key1.sprintf("FC%d",idom); //files.FaCes faces (wrap and triangles only)
+ tab1=this->restore_key(key1); //tab1=this->mestab[key1];
+ med_int nbfaces=tab1->size/7;
+ if (this->verbose>4) cout<<"NumberOfTrianglesOfWrap="<<nbfaces<<endl;
+ arrayi=new med_int[nbfaces*3];
+ long ii=0,i=0 ;
+ for (long j=0; j<nbfaces ; j++)
+ {
+ arrayi[ii]=tab1->tmint[i]; ii++;
+ arrayi[ii]=tab1->tmint[i+1]; ii++;
+ arrayi[ii]=tab1->tmint[i+2]; ii++;
+ i=i+7;
+ }
+ err=MEDconnEcr(fid,namelocal,3,arrayi,MED_FULL_INTERLACE,nbfaces,MED_FACE,MED_TRIA3,MED_NOD);
+ if (err<0) cerr<<"Problem MEDconnEcr for triangles connectivity"<<endl;
+ delete[] arrayi;
+
+ //writing indices of faces triangles of wrap
+ //caution!
+ //generate "overlapping of numbers of elements" in "import med file" in salome
+ //if not in "//writing indices of tetraedes" -> arrayi[i]=!NBFACES!+i+1
+ arrayi=new med_int[nbfaces];
+ for (long i=0; i<nbfaces ; i++) arrayi[i]=i+1;
+ err=MEDnumEcr(fid,namelocal,arrayi,nbfaces,MED_FACE,MED_TRIA3);
+ if (err<0) cerr<<"Problem MEDnumEcr of triangles"<<endl;
+ delete[] arrayi;
+
+ //create global family wrap default
+ char nomfam[MED_TAILLE_NOM+1]="PART_OF_GLOBAL_WRAP";
+ char attdes[MED_TAILLE_DESC+1]="part of wrap of global volume";
+ char gro[MED_TAILLE_LNOM+1]="PART_OF_GLOBAL_WRAP";
+ med_int numfam,attide,attval,natt,ngro,numfam_ini_wrap=200;
+ //caution numfam_ini_wrap!=numfam_ini_nodes
+ numfam=-numfam_ini_wrap; attide=1; attval=numfam; natt=1; ngro=1;
+ err=MEDfamCr(fid,namelocal,nomfam,numfam,&attide,&attval,attdes,natt,gro,ngro);
+ if (err<0) cerr<<"Problem MEDfamCr of "<<nomfam<<endl;
+
+ //for joints
+ //init default indices of families of faces triangles of wrap = -numfam_ini_wrap
+ //(for faces not in joints=PART_OF_GLOBAL_WRAP, why not!)
+ //others -> -numfam_ini_wrap-indice_of_neighbourg ([1;number_of_neighbourg])
+ //(for existing joints)
+ int sizefamilies=nbfaces;
+ med_int *familiesi=new med_int[sizefamilies];
+ for (int i=0; i<sizefamilies ; i++) familiesi[i]=-numfam_ini_wrap;
+
+ //families known in faces in wrap PART_OF_GLOBAL_WRAP
+ //writing indices of families of faces triangles of wrap = nsd why not?
+ //not implemented yet because subdomain(s) of family PART_OF_GLOBAL_WRAP
+ /*arrayi=new med_int[nbfaces];
+ for (int i=0; i<nbfaces ; i++) arrayi[i]=tab1->tmint[(i*7)+3];
+ err=MEDfamEcr(fid,namelocal,arrayi,nbfaces,MED_FACE,MED_TRIA3);
+ if (err<0) cerr<<"Problem MEDfamEcr faces of wrap"<<endl;
+ delete[] arrayi;*/
+
+ //writing connectivity of tetraedes by nodes
+ key1=key1.sprintf("NB%d EV",idom); //files.NoBoite Elements Vertices (tetra only)
+ tab1=this->restore_key(key1); //tab1=this->mestab[key1];
+ med_int nbtetras=tab1->size/4;
+ if (this->verbose>4) cout<<"NumberOfTetraedes="<<nbtetras<<endl;
+ //arrayi=new med_int[tab1->size];
+ //for (long i=0; i<tab1->size ; i++) arrayi[i]=tab1->tmint[i];
+ err=MEDconnEcr(fid,namelocal,3,tab1->tmint,MED_FULL_INTERLACE,nbtetras,MED_MAILLE,MED_TETRA4,MED_NOD);
+ if (err<0) cerr<<"Problem MEDconnEcr for tetra connectivity"<<endl;
+ //delete[] arrayi;
+ this->SwapOutOfMemory_key_mesh_wrap(QRegExp(key1,TRUE,FALSE));
+
+ //writing indices of tetraedes
+ arrayi=new med_int[nbtetras];
+ for (long i=0; i<nbtetras ; i++) arrayi[i]=nbfaces+i+1;
+ err=MEDnumEcr(fid,namelocal,arrayi,nbtetras,MED_MAILLE,MED_TETRA4);
+ if (err<0) cerr<<"Problem MEDnumEcr of tetraedes"<<endl;
+ delete[] arrayi;
+
+ //writing indices of families of nodes = nrs why not?
+ //before create families of nodes fonction of existing values of nrs of files .points
+ arrayi=new med_int[nbnodes];
+ key1=key1.sprintf("PO%d NRS",idom); //files.POints Vertex of wrap
+ tab1=this->restore_key(key1); //tab1=this->mestab[key1];
+ med_int nbwrap=tab1->size;
+ //families known in points in wrap
+ //more than 30 families is stupid? (too many)?
+ int itest,i2,ifam[30],imax=1,imess=0,numfam_ini_nodes=numfam_ini_wrap-100;
+ //caution numfam_ini_wrap!=numfam_ini_nodes
+ //ifam[:]<-existing values of nrs (in [0,97])
+ //ifam[0]<-first family default=99 for new nodes IN volume (out of wrap)
+ ifam[0]=99;
+ for (int i=0; i<nbwrap ; i++)
+ {
+ itest=tab1->tmint[i];
+ if ((itest<0)||(itest>97))
+ {
+ if (imess==0)
+ {
+ cerr<<"Problem for domain "<<idom<<" nrs="<<itest<<
+ " shoud be in [0;97] forced 98"<<endl;
+ imess=1; //message only once
+ }
+ itest=98; //0<=nrs<=97 precaution 98=family garbage
+ }
+ arrayi[i]=-numfam_ini_nodes-itest;
+ i2=0;
+ while (1)
+ {
+ if (i2==imax)
+ {
+ ifam[imax]=itest ; imax++ ; break;
+ }
+ if (itest==ifam[i2]) break;
+ i2++;
+ if (i2>=30) break;
+ }
+ if (imax>=30) {
+ cerr<<"Problem more than 30 families of nodes"<<endl;
+ break;
+ }
+ }
+ for (int i=0 ; i<imax ; i++)
+ {
+ //create families of nodes as nrs
+ if (i==0)
+ tmp=tmp.sprintf("IN_VOLUME");
+ else
+ tmp=tmp.sprintf("NRS_%d",ifam[i]);
+ strcpy(nomfam,tmp);
+ if (this->verbose>2) cout<<"CreateFamilyOfNodes_"<<nomfam<<endl;
+ strcpy(gro,tmp);
+ if(i==0)
+ tmp=tmp.sprintf("nodes in local volume");
+ else
+ tmp=tmp.sprintf("nodes of nrs_%d on local wrap",ifam[i]);
+ strcpy(attdes,tmp);
+ numfam=-numfam_ini_nodes-ifam[i];
+ //attide=1;
+ attval=numfam;
+ //natt=1;
+ ngro=1;
+ if (this->verbose>4) cout<<"MEDfamCr (nodes) of "<<nomfam<<" / "<<attdes<<" / FamilyNumber="<<numfam<<endl;
+ err=MEDfamCr(fid,namelocal,nomfam,numfam,&attide,&attval,attdes,natt,gro,ngro);
+ if (err<0) cerr<<"Problem MEDfamCr of "<<nomfam<<endl;
+ }
+ //defaults ifam[0] for new points in new volume
+ for (int i=nbwrap; i<nbnodes ; i++) arrayi[i]=-numfam_ini_nodes-ifam[0];
+
+ err=MEDfamEcr(fid,namelocal,arrayi,nbnodes,MED_NOEUD,medgeoele0);
+ if (err<0) cerr<<"Problem MEDfamEcr nodes"<<endl;
+ delete[] arrayi;
+
+/*Le nom du maillage local est une chaîne de MED_TAILLE_NOM (32) caractères.
+ Le tableau des numéros "num" est un tableau à 1 dimension de taille égale à "n".
+ Les numéros globaux sont obligatoirement supérieur à 1
+ Le type de l'entite "typent" est soit MED_NOEUD,MED_MAILLE, MED_FACE ou MED_ARETE.
+ Le type géométrique peut être :
+ Pour les noeuds : 0.
+ Pour les mailles : MED_POINT1, MED_SEG2, MED_SEG3, MED_TRIA3, MED_TRIA6, MED_QUAD4, MED_QUAD8, MED_POLYGONE.
+ Pour les faces : MED_TRIA3, MED_TRIA6, MED_QUAD4, MED_QUAD8, MED_POLYGONE.
+ Pour les arêtes : MED_SEG2 et MED_SEG3.*/
+
+ //writing nodes(vertices) global numbering
+ //GLx VE=files.GLo VErtices
+ key1=key1.sprintf("GL%d VE",idom);
+ tab1=this->restore_key(key1); //tab1=this->mestab[key1];
+ nbnodes=tab1->size;
+ if (this->verbose>2)
+ cout<<"CreateMEDglobalNumerotation_Nodes "<<key1<<" "<<tab1->size<<endl;
+ if (nbnodes<=0) cerr<<"Problem MEDglobalNumEcr not in memory"<<endl;
+ //arrayi=new med_int[nbnodes];
+ //for (int i=0; i<tab1->size ; i++) arrayi[i]=tab1->tmint[i];
+ //med_2_2::med_geometrie_element toto=MED_POINT1;
+ //cout<<"MED_POINT1="<<toto<<" medgeoele0="<<medgeoele0<<endl;
+ /*MEDglobalNumEcr(med_idt fid, char *maa, med_int *num, med_int n,
+ med_entite_maillage type_ent, med_geometrie_element type_geo)*/
+ err=MEDglobalNumEcr(fid,namelocal,tab1->tmint,nbnodes,MED_NOEUD,medgeoele0);
+ if (err<0) cerr<<"Problem MEDglobalNumEcr nodes"<<endl;
+ //cout<<"MEDglobalNumEcr vertices size="<<nbnodes<<endl;
+ //delete[] arrayi;
+ this->SwapOutOfMemory_key_mesh_wrap(QRegExp(key1,TRUE,FALSE));
+
+ //writing faces(triangles) global numbering
+ //GLx FA=files.GLo FAces
+ key1=key1.sprintf("GL%d FA",idom);
+ tab1=this->restore_key(key1); //tab1=this->mestab[key1];
+ nbfaces=tab1->size;
+ //arrayi=new med_int[nbfaces];
+ //for (int i=0; i<tab1->size ; i++) arrayi[i]=tab1->tmint[i];
+ if (this->verbose>2)
+ cout<<"CreateMEDglobalNumerotation_Faces "<<key1<<" "<<tab1->size<<endl;
+ err=MEDglobalNumEcr(fid,namelocal,tab1->tmint,nbfaces,MED_FACE,MED_TRIA3);
+ if (err<0) cerr<<"Problem MEDglobalNumEcr faces"<<endl;
+ //cout<<"MEDglobalNumEcr faces size="<<nbfaces<<endl;
+ //delete[] arrayi;
+ this->SwapOutOfMemory_key_mesh_wrap(QRegExp(key1,TRUE,FALSE));
+
+ //writing tetraedes global numbering
+ //GLx EL=files.GLo ELements
+ key1=key1.sprintf("GL%d EL",idom);
+ tab1=this->restore_key(key1); //tab1=this->mestab[key1];
+ med_int nbtetrasglo=tab1->size;
+ if (nbtetrasglo!=nbtetras)
+ cerr<<"Problem incorrect size of tetraedes global numbering"<<endl;
+ //arrayi=new med_int[nbtetrasglo];
+ //for (int i=0; i<tab1->size ; i++) arrayi[i]=tab1->tmint[i];
+ if (this->verbose>2)
+ cout<<"CreateMEDglobalNumerotation_Tetraedes "<<key1<<" "<<tab1->size<<endl;
+ err=MEDglobalNumEcr(fid,namelocal,tab1->tmint,nbtetrasglo,MED_MAILLE,MED_TETRA4);
+ if (err<0) cerr<<"Problem MEDglobalNumEcr tetraedes"<<endl;
+ //cout<<"MEDglobalNumEcr tetraedes size="<<nbtetrasglo<<endl;
+ //delete[] arrayi;
+ this->SwapOutOfMemory_key_mesh_wrap(QRegExp(key1,TRUE,FALSE));
+
+ //writing joints
+ for (int ineig=1; ineig <= this->nbfiles; ineig++)
+ {
+ char namejnt[MED_TAILLE_NOM+1]; //no more 32
+ char namedist[MED_TAILLE_NOM+1];
+ char descjnt[MED_TAILLE_DESC+1];
+
+ if (idom==ineig) continue; //impossible
+ key1=key1.sprintf("MS%d NE%d VE SE",idom,ineig); //SE or RE?
+ tab1=this->restore_key(key1);
+ if (!tab1) continue; //case (ifile,ineig) are not neighbours=>no joints
+ key1=key1.sprintf("MS%d NE%d VE RE",idom,ineig); //SE or RE
+ tab2=tab1; //tab2=this->restore_key(key1); //no need because <send> equals <receive>
+ if (!tab2) cerr<<"Problem nodes joint <send> with no <receive> in file .msg"<<endl;
+ nbnodes=tab1->size;
+
+ if (this->verbose>4)
+ cout<<"NumberOfNodesOfJoint_"<<ineig<<"="<<nbnodes<<endl;
+ strcpy(namejnt,tmp.sprintf("joint_%d",ineig));
+ tmp=tmp.sprintf("joint_%d among %d domains of ",ineig,nbdomains)+namelocal;
+ strcpy(descjnt,tmp);
+ //cout<<descjnt<<endl;
+ strcpy(namedist,tmp.sprintf("joint_%d",idom)); //or this->casename+"_%d",ineig));
+ err=MEDjointCr(fid,namelocal,namejnt,descjnt,ineig,namedist);
+ if (err<0) cerr<<"Problem MEDjointCr"<<endl;
+
+ //writing correspondence nodes-nodes
+ //two indices for one correspondence
+ arrayi=new med_int[nbnodes*2];
+ ii=0;
+ for (int i=0; i<nbnodes ; i++)
+ {
+ //no need because <send> equals <receive> tab1->tmint[i]==tab2->tmint[i]
+ arrayi[ii]=tab1->tmint[i]; ii++;
+ arrayi[ii]=tab2->tmint[i]; ii++;
+ }
+ err=MEDjointEcr(fid,namelocal,namejnt,arrayi,nbnodes,
+ MED_NOEUD,medgeoele0,MED_NOEUD,medgeoele0);
+ if (err<0) cerr<<"Problem MEDjointEcr nodes"<<endl;
+ delete[] arrayi;
+
+ //writing correspondence triangles-triangles
+ key1=key1.sprintf("MS%d NE%d FA SE",idom,ineig); //SE or RE?
+ tab1=this->restore_key(key1); //tab1=this->mestab[key1];
+ if (!tab1)
+ {
+ if (this->verbose>4)
+ cout<<"NumberOfTrianglesOfJoint_"<<ineig<<"="<<0<<endl;
+ continue; //case (ifile,ineig) are not neighbours=>no joints
+ }
+ key1=key1.sprintf("MS%d NE%d FA RE",idom,ineig); //SE or RE?
+ tab2=tab1; //tab2=this->restore_key(key1); //no need because <send> equals <receive>
+ if (!tab2) cerr<<"Problem triangles joint send with no receive"<<endl;
+ med_int nbtriangles=tab1->size;
+
+ if (this->verbose>4)
+ cout<<"NumberOfTrianglesOfJoint_"<<ineig<<"="<<nbtriangles<<endl;
+ arrayi=new med_int[nbtriangles*2];
+ ii=0;
+ for (int i=0; i<nbtriangles ; i++)
+ {
+ //no need because <send> equals <receive> tab1->tmint[i]==tab2->tmint[i]
+ arrayi[ii]=tab1->tmint[i]; ii++;
+ familiesi[tab1->tmint[i]-1]=-numfam_ini_wrap-ineig;
+ arrayi[ii]=tab2->tmint[i]; ii++;
+ //cout<<arrayi[ii-1]<<"="<<arrayi[ii-2]<<endl;
+ }
+ err=MEDjointEcr(fid,namelocal,namejnt,arrayi,nbtriangles,MED_FACE,MED_TRIA3,MED_FACE,MED_TRIA3);
+ if (err<0) cerr<<"Problem MEDjointEcr triangles"<<endl;
+ delete[] arrayi;
+
+ tmp=tmp.sprintf("JOINT_%d",ineig);
+ strcpy(nomfam,tmp);
+
+ //err=MEDnumEcr(fid,nomfam,arrayi,nbtriangles,MED_FACE,MED_TRIA3);
+ //if (err<0) cerr<<"Problem MEDnumEcr of triangles of "<<nomfam<<endl;
+
+ //char gro[MED_TAILLE_LNOM+1]="PART_OF_GLOBAL_WRAP_PLUS_JOINTS";
+ strcpy(gro,tmp);
+ /*char gro[MED_TAILLE_LNOM*2+1];
+ strcpy(gro,"PART_OF_GLOBAL_WRAP_PLUS_JOINTS ");
+ for (int i=32;i<MED_TAILLE_LNOM;i++) gro[i]=' ';
+ gro[MED_TAILLE_LNOM]='\0';
+ strcat(gro,tmp);
+ //for (i=7;i<MED_TAILLE_LNOM;i++) gro[MED_TAILLE_LNOM+i]=' ';
+ //gro[2*MED_TAILLE_LNOM]='\0';*/
+
+ tmp=tmp.sprintf("joint of neighbourg_%d on local wrap",ineig);
+ strcpy(attdes,tmp);
+ numfam=-numfam_ini_wrap-ineig;
+ //attide=1;
+ attval=numfam;
+ //natt=1;
+ ngro=1;
+ if (this->verbose>2)
+ cout<<"CreateFamilyOfFaces_"<<nomfam<<endl;
+ if (this->verbose>4) cout<<"MEDfamCr (faces) of "<<nomfam<<" / "<<attdes<<" / FamilyNumber="<<numfam<<endl;
+
+ err=MEDfamCr(fid,namelocal,nomfam,numfam,&attide,&attval,attdes,natt,gro,ngro);
+ if (err<0) cerr<<"Problem MEDfamCr of "<<nomfam<<endl;
+
+ }
+ //writing indices of families of faces triangles of wrap = joint<-100 or not=100?
+ //arrayi=new med_int[nbtriangles];
+ //families known in faces in wrap
+ //for (int i=0; i<nbtriangles ; i++) arrayi[i]=-100-ineig; //tab1->tlong[(i*7)+3];
+ err=MEDfamEcr(fid,namelocal,familiesi,sizefamilies,MED_FACE,MED_TRIA3);
+ if (err<0) cerr<<"Problem MEDfamEcr faces of all joints"<<endl;
+ delete[] familiesi;
+
+ MEDfermer(fid);
+
+ //examples of test of med files ( ... for me!)
+ //../Salome_321/med_231_install/bin/medconforme exemple11.med
+ //../Salome_321/hdf5-1.6.3/bin/h5dump exemple11.med
+ //../Salome_321/med_231_install/bin/mdump exemple11.med
+ }
+ return ok;
+}
+