+// Copyright (C) 2007-2008 OPEN CASCADE, CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// ---
+//
+// File : ghs3dprl_mesh_wrap.cxx
+// Author : Christian VAN WAMBEKE (CEA) (from Hexotic plugin Lioka RAZAFINDRAZAKA)
+//
+// ---
+
+#include "ghs3dprl_mesh_wrap.h"
#include <string>
#include <iostream>
#include <sstream>
#include <fstream>
-#include <qstring.h>
-#include <qfile.h>
-#include "ghs3dprl_mesh_wrap.h"
-using namespace std;
+#include <QFile>
+#include <QRegExp>
+
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;
+ //std::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;
+ //std::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 ok;
+ //std::cout<<" destructor CVWtab *** "<<this->filename<<std::endl;
+ ok = CVWtab_deallocate();
+ //remove temporary file
+ if (filename!="_NO_FILE")
+ {
+ QFile::remove(filename);
+ //std::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;
+ //std::cout<<" deallocate CVWtab*** "<<size<<std::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;
+ //std::cout<<"is_equal tab1 tab2 type="<<this->type<<" size="<<this->size<<" "<<tab2->size<<std::endl;
+ //if (this->type==1) std::cout<<"med_int tab1[0]="<<this->tmint[0]<<std::endl;
+ //if (this->type==2) std::cout<<"med_float tab1[0]="<<this->tmflo[0]<<std::endl;
+ if (this->size!=tab2->size) return false;
+ if (this->type!=tab2->type) return false;
+ if (this->type==1)
+ {
+ if (!this->tmint)
+ { std::cout<<"***is_equal*** pb pointer NULL with tmint size="<<this->size<<std::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)
+ { std::cout<<"***is_equal*** pb pointer NULL with tmflo size="<<this->size<<std::endl;
+ return false;
+ }
+ for (long i=0; i < this->size; i++)
+ if (this->tmflo[i]!=tab2->tmflo[i]) return false;
+ }
+ return true;
}
//************************************
//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;
+ //std::cout<<"is_equal_vertice size="<<tab1->size<<" "<<tab2->size<<std::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)
+ {
+ std::cerr<<"BadIndice tab1 in is_equal_vertices "<<
+ di1<<" not in "<<tab1->size<<std::endl;
+ return false;
+ }
+ if (di2<0 || di2>=tab2->size)
+ {
+ std::cerr<<"BadIndice tab2 in is_equal_vertices "<<
+ di2<<" not in "<<tab2->size<<std::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)
+bool CVW_FindString(const std::string &str, std::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))
+ std::string line;
+ do
+ {
+ if (getline(Ff,line))
+ {
+ if (line[0]==str[0]) //faster
{
- 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;
- }
- }
+ if (line.find(str)==0)
+ {
+ QString tmp=line.c_str();
+ 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;
+ }
+ else
+ {
+ std::cerr<<"Problem line '"<<str<<"' not found in file\n"<<std::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;
+ QString tmp;
+ std::fstream Ff(FileName.toLatin1().constData(),std::ios_base::in);
+ std::string line;
+ long count;
+ bool ok;
+
+ if (!Ff.is_open())
+ {
+ std::cerr<<"Problem File '"<<FileName.toLatin1().constData()<<"' not open\n"<<std::endl;
+ return false;
+ }
+
+ //Lit les données :
+ if (!CVW_FindString("<vertices count=",Ff,count)) return false;
+ if (this->verbose>2) std::cout<<"VerticesCount="<<count<<std::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) std::cout<<"Elements "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[count-1]<<std::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) std::cout<<"EdgesCount="<<count<<std::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) std::cout<<"Elements "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[count-1]<<std::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) std::cout<<"FacesCount="<<count<<std::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) std::cout<<"Elements "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[count-1]<<std::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) std::cout<<"ElementsCount="<<count<<std::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) std::cout<<"Elements "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[count-1]<<std::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;
+ QString tmp;
+ std::fstream Ff(FileName.toLatin1().constData(),std::ios_base::in);
+ std::string line;
+ long nbelem,ntype;
+ bool ok;
+
+ if (!Ff.is_open())
+ {
+ std::cerr<<"Problem File '"<<FileName.toLatin1().constData()<<"' not open\n"<<std::endl;
+ return false;
+ }
+
+ //Lit les données :
+ //Replace le pointeur de fichier au début :f.seekg(0);
+ if (getline(Ff,line))
+ {
+ tmp=line.c_str();
+ nbelem=tmp.section(' ',0,0).toLong(&ok);
+ }
+ else
+ {
+ std::cerr<<"Problem on first line of file"<<std::endl;
+ return false;
+ }
+ if (this->verbose>2) std::cout<<"NumberOfElements="<<nbelem<<std::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
+ {
+ std::cerr<<"Problem on ntype != 3"<<std::endl;
+ return false;
+ }
+ for (int j=0; j<7; j++) Ff>>tmint[i+j];
+ //for (int j=0; j<7; j++) std::cout<<tmint[i+j]<<' '; std::cout<<std::endl;
+ }
+ if (this->verbose>4) std::cout<<"Elements "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[nbelem*7-1]<<std::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;
}
//************************************
//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;
+ QString tmp;
+ std::fstream Ff(FileName.toLatin1().constData(),std::ios_base::in);
+ long ne,np,npfixe,subnumber,reste;
+ bool ok;
+
+ if (!Ff.is_open())
+ {
+ std::cerr<<"Problem File '"<<FileName.toLatin1().constData()<<"' not open\n"<<std::endl;
+ return false;
+ }
+
+ //lit les données :
+ Ff>>ne>>np>>npfixe;
+ if (this->verbose>2)
+ {
+ std::cout<<"NumberOfElements="<<ne<<std::endl;
+ std::cout<<"NumberOfVertices="<<np<<std::endl;
+ std::cout<<"NumberOfSpecifiedPoints="<<npfixe<<std::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) std::cout<<"Elements "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[ne*4-1]<<std::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) std::cout<<"Vertices "<<tmflo[0]<<" "<<tmflo[1]<<"... "<<tmflo[np*3-1]<<std::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) std::cout<<"NumberOfSubdomains="<<subnumber<<std::endl;
+ tmint=new med_int[subnumber*3];
+ for (int i=0; i<subnumber*3; i++) Ff>>tmint[i];
+ if (this->verbose>4) std::cout<<"Subdomains "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[subnumber*3-1]<<std::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;
}
//************************************
//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 ok;
+
+ std::cerr<<"Problem function ReadFileNOBOITEB\n"
+ <<"(no FORTRAN binary format files in tepal)\n\n";
+
+ QString tmp;
+ //file binary
+ FILE *Ff=fopen(FileName.toLatin1().constData(),"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)
+ {
+ std::cerr<<"Problem File '"<<FileName.toLatin1().constData()<<"' not open\n"<<std::endl;
+ return false;
+ }
+
+ //read datas :
+ fread(&r1,sizeof(long),17+2,Ff);
+ for (long i=1; i<18; i++) std::cout<<"R1("<<i<<")="<<r1[i]<<std::endl;
+
+ if (r1[0]!=68)
+ {
+ std::cerr<<"First FORTRAN record of File '"<<FileName.toLatin1().constData()<<"' not length 17*long"<<std::endl;
+ return false;
+ }
+ ne=r1[1];
+ np=r1[2];
+ npfixe=r1[3];
+ if (this->verbose>2)
+ {
+ std::cout<<"NumberOfElements="<<ne<<std::endl;
+ std::cout<<"NumberOfVertices="<<np<<std::endl;
+ std::cout<<"NumberOfSpecifiedPoints="<<npfixe<<std::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) std::cout<<"Elements "<<tmint[0]<<" "<<tmint[1]<<"... "<<tmint[ne*4-1]<<std::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);
+ //std::cout<<"info "<<reste<<" "<<np*3<<" "<<sizeof(med_float)<<std::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) std::cout<<"NumberOfSubdomains="<<subnumber<<std::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);
+ QString tmp;
+ long nb;
+ long maxlen=128;
+ bool ok=true;
+
+ //Lit les données :
+ QFile Ff(FileName);
+ //NOT Raw because Raw=non-buffered file access
+ ok=Ff.open(QIODevice::ReadOnly|QIODevice::Text);
+ if (!ok)
+ {
+ std::cerr<<"Problem File '"<<FileName.toLatin1().constData()<<"' not open\n"<<std::endl;
+ return false;
+ }
+
+ tmp=Ff.readLine(maxlen);
+ tmp=tmp.simplified();
+ nb=tmp.toLong(&ok);
+ if (!ok)
+ {
+ std::cerr<<"Problem conversion File '"<<FileName.toLatin1().constData()<<"\n"<<std::endl;
+ return false;
+ }
+ if (this->verbose>2) std::cout<<"NumberOfVertices="<<nb<<std::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++ )
+ {
+ tmp=Ff.readLine(maxlen);
+ tmp=tmp.simplified();
+ for ( int j=0; j<3; j++ )
+ {
+ tmflo[il3]=tmp.section(' ',j,j).toDouble(&ok);
+ //std::cout<<"cv '"<<tmflo[il3]<<"' "<<il3<<std::endl;
+ il3++;
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;
+ {
+ std::cerr<<"Problem conversion File '"<<FileName.toLatin1().constData()<<"\n"<<std::endl;
+ return false;
+ }
+ }
+ //nrs is vertex attribute
+ tmint[il]=tmp.section(' ',3,3).toLong(&ok);
+ if (!ok)
+ {
+ std::cerr<<"Problem conversion File '"<<FileName.toLatin1().constData()<<"\n"<<std::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;
+ QHashIterator<QString,CVWtab*> it( this->mestab);
+ while ( it.hasNext() )
+ {
+ it.next();
+ QString nom = it.key().leftJustified(20,' ');
+ std::cout<<nom.toLatin1().constData()<<"-> size="<<it.value()->size<<std::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 nb=this->remove_key_mesh_wrap(QRegExp("."));
+ 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;
+ long nbremove=0;
+ QMutableHashIterator<QString,CVWtab*> it(this->mestab);
+ while ( it.hasNext() )
+ {
+ it.next();
+ if (it.key().contains(rxp)) {
+ nbremove++;
+ if (this->verbose>4) std::cout<<"remove key "<<it.key().toLatin1().constData()<<std::endl;
+ delete it.value();
+ it.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;
+ //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.toLatin1().constData(),"wb");
+ long taille;
+ taille=tab->size;
+ fwrite(&taille,sizeof(taille),1,fichier);
+ if (tab->tmint)
+ {
+ if (verbose>3)
+ std::cout<<"SwapOnFile in binary file "<<tab->filename.toLatin1().constData()<<
+ " number of elements "<<taille<<
+ " size_element med_int "<<sizeof(med_int)<<
+ " total_size_binary " <<taille*sizeof(med_int)<<std::endl;
+ fwrite(tab->tmint,sizeof(med_int),taille,fichier);
+ //fread(&gagnants,sizeof(gagnants),1,fichier);
+ }
+ if (tab->tmflo)
+ {
+ if (verbose>3)
+ std::cout<<"SwapOnFile in binary file "<<tab->filename.toLatin1().constData()<<
+ " number of elements "<<taille<<
+ " size_element med_float "<<sizeof(med_float)<<
+ " total_size_binary " <<taille*sizeof(med_float)<<std::endl;
+ fwrite(tab->tmflo,sizeof(med_float),taille,fichier);
+ }
+ fclose(fichier);
+ }
+ else
+ {
+ if (verbose>3) std::cout<<"SwapOnFile in binary file done yet "<<tab->filename.toLatin1().constData()<<std::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;
+ long nb=0;
+ bool ok;
+ QHashIterator<QString,CVWtab*> it(this->mestab);
+ while ( it.hasNext() )
+ {
+ it.next();
+ if (it.key().contains(rxp))
+ {
+ nb++;
+ if (it.value()->size>0)
+ ok=SwapOnFile(it.key(),this->path,it.value(),this->verbose); //free memory
+ //if (this->verbose) std::cout<<"SwapOutOfMemory key "<<it.currentKey()<<std::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;
+ CVWtab *montab=this->mestab[key];
+ if (montab)
+ {
+ //std::cout<<"key "<<key<<"trouvee -> size="<<montab->size<<std::endl;
+ if (montab->type==1)
+ for ( long i=0; i<montab->size; i++ )
+ std::cout<<montab->tmint[i]<<" ";
+ if (montab->type==2)
+ for ( long i=0; i<montab->size; i++ )
+ std::cout<<montab->tmflo[i]<<" ";
+ std::cout<<std::endl;
+ }
+ else
+ std::cout<<"key "<<key.toLatin1().constData()<<" not found"<<std::endl;
+ return true;
}
//************************************
//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;
+ bool ok;
+ if (this->verbose>4)
+ std::cout<<"InsertKey "<<key.toLatin1().constData()<<" size="<<tab->size<<std::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)
//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;
+ CVWtab *tab=NULL;
+ tab=this->mestab[key];
+ /*if (tab) std::cout<<" -> size in proc "<<tab->size<<std::endl;
+ else std::cout<<" -> tab NULL\n";*/
+ if (!tab) //it is NOT a problem
+ {
+ if (this->verbose>6) std::cout<<"restore_key key not found "<<key.toLatin1().constData()<<std::endl;
+ return NULL;
+ }
+ if (tab->size > 0)
+ {
+ if (this->verbose>5) std::cout<<"restore_key direct from memory "<<key.toLatin1().constData()<<" size="<<tab->size<<std::endl;
+ return tab;
+ }
+ //restore from binary file
+ if ((tab->type<1)||(tab->type>2))
+ {
+ std::cerr<<"Problem restore_key from binary file "<<tab->filename.toLatin1().constData()<<
+ " type unexpexted "<<tab->type<<std::endl;
+ return NULL;
+ }
+ //std::cout<<"restore_key from binary file "<<tab->filename<<std::endl;
+
+ //swap disque binaire
+ FILE *fichier=fopen(tab->filename.toLatin1().constData(),"rb");
+ long taille;
+ fread(&taille,sizeof(long),1,fichier);
+ if (taille!=-tab->size)
+ {
+ std::cerr<<"Problem restore_key from binary file "<<tab->filename.toLatin1().constData()<<
+ " size unexpexted "<<taille<<" expected "<<-tab->size<<std::endl;
+ fclose(fichier);
+ return NULL;
+ }
+ if (tab->type==1)
+ {
+ if (this->verbose>5)
+ std::cout<<"restore_key from binary file "<<tab->filename.toLatin1().constData()<<
+ " number of elements "<<taille<<
+ " size_element med_float "<<sizeof(med_float)<<
+ " total_size_binary " <<taille*sizeof(med_float)<<std::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)
+ std::cout<<"restore_key from binary file "<<tab->filename.toLatin1().constData()<<
+ " number of elements "<<taille<<
+ " size_element med_float "<<sizeof(med_float)<<
+ " total_size_binary " <<taille*sizeof(med_float)<<std::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++) std::cout<<tab->tmflo[i]<<"/";
+ std::cout<<std::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
+ 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.count(' ',Qt::CaseSensitive) + 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 (!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;
- }
+ 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";
+ //std::cout<<"key "<<key1<<" et key "<<key2<<std::endl;
+ tab1=this->restore_key(key1);
+ //tab1=this->mestab[key1];
+ tab2=this->restore_key(key2);
+ //tab2=this->mestab[key2];
+ //std::cout<<"sortie key "<<key1<<" et key "<<key2<<std::endl;
+ if (!tab1 && !tab2) continue; //case not neighbours
+ if (!tab1)
+ {
+ std::cout<<"key "<<key1.toLatin1().constData()<<" inexistante avec key "<<key2.toLatin1().constData()<<" existante"<<std::endl;
+ ok=false;
+ }
+ else
+ {
+ if (!tab2)
+ {
+ std::cout<<"key "<<key2.toLatin1().constData()<<" inexistante avec key "<<key1.toLatin1().constData()<<" existante"<<std::endl;
+ ok=false;
+ }
+ else if (!tab1->is_equal(tab2))
+ {
+ std::cout<<"key "<<key1.toLatin1().constData()<<" et key "<<key2.toLatin1().constData()<<" de contenu differents"<<std::endl;
+ ok=false;
+ }
+ }
+ /*else
+ printf("key '%s' et key '%s' identiques \n",
+ (const char *)key2,(const char *)key1);*/
}
- /*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
+ }
+ }
+
+ //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 (!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;
- }
+ 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)
+ {
+ std::cout<<"key "<<key1.toLatin1().constData()<<" inexistante avec key "<<key2.toLatin1().constData()<<" existante"<<std::endl;
+ ok=false;
+ }
+ else
+ {
+ if (!tab2)
+ {
+ std::cout<<"key "<<key2.toLatin1().constData()<<" inexistante avec key "<<key1.toLatin1().constData()<<" existante"<<std::endl;
+ ok=false;
+ }
+ else if ((tab1->type!=tab2->type)||(tab1->size!=tab2->size))
+ {
+ std::cout<<"key "<<key1.toLatin1().constData()<<" et key "<<key2.toLatin1().constData()<<" de type ou tailles differents"<<std::endl;
+ ok=false;
+ }
+ }
}
- }
- return ok;
+ }
+ }
+ 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--)
- {
+ 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);
if (!tab1 && !tab2) continue; //cas non voisins
if (!tab1)
{
- cerr<<"TestEqualityCoordinates key "<<key1<<" NOT existing but key "<<key2<<" existing"<<endl;
- ok=FALSE; continue;
+ std::cerr<<"TestEqualityCoordinates key "<<key1.toLatin1().constData()<<" NOT existing but key "<<key2.toLatin1().constData()<<" existing"<<std::endl;
+ ok=false; continue;
}
if (!tab2)
{
- cerr<<"TestEqualityCoordinates key "<<key2<<" NOT existing but key "<<key1<<" existing"<<endl;
- ok=FALSE; continue;
+ std::cerr<<"TestEqualityCoordinates key "<<key2.toLatin1().constData()<<" NOT existing but key "<<key1.toLatin1().constData()<<" existing"<<std::endl;
+ ok=false; continue;
}
if (tab1->size!=tab2->size)
{
- cerr<<"TestEqualityCoordinates key "<<key1<<" and key "<<key2<<" NOT same size"<<endl;
- ok=FALSE; continue;
+ std::cerr<<"TestEqualityCoordinates key "<<key1.toLatin1().constData()<<" and key "<<key2.toLatin1().constData()<<" NOT same size"<<std::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 if no use
+ if ((key11old!=key11)&&(key11old!=key22))
+ this->SwapOutOfMemory_key_mesh_wrap(QRegExp(key11old));
+ if ((key22old!=key11)&&(key22old!=key22))
+ this->SwapOutOfMemory_key_mesh_wrap(QRegExp(key22old));
+
+ 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))
+ {
+ std::cerr<<j<<" Vertice "<<i1<<" != Vertice "<<i2<<"\n"<<std::endl;
+ ok=false; ok1=false;
+ }
+ }
+ if ((this->verbose>2)&&(ok1))
+ std::cout<<"TestEqualityCoordinates "<<tab1->size<<
+ " Vertices "<<key1.toLatin1().constData()<<" and "<<key2.toLatin1().constData()<<" ok"<<std::endl;
+ if (!ok1)
+ std::cerr<<"TestEqualityCoordinates "<<tab1->size<<
+ " Vertices "<<key1.toLatin1().constData()<<" and "<<key2.toLatin1().constData()<<" NO_OK"<<std::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;
+ }
+ }
+ //Swap out of memory (supposed no use?)
+ //NO because NB1&NB2 VC supposed future use
+ //YES precaution
+ this->SwapOutOfMemory_key_mesh_wrap(QRegExp(key11old));
+ this->SwapOutOfMemory_key_mesh_wrap(QRegExp(key22old));
+ 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;
- long nbtetrastotal=0;
- file<<nbdomains<<" "<<endl;
+ 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)
+ {
+ std::cerr<<"CaseNameMed truncated (no more 20 characters)"<<std::endl;
+ this->casename.truncate(20);
+ }
+ filename=this->path+this->casename;
+ std::ofstream file(filename.toLatin1().constData()); //master file
+ file<<"#MED Fichier V 2.3"<<" "<<std::endl;
+ file<<"# NumbersOfSubDomains"<<" "<<std::endl;
+ int nbdomains=this->nbfiles;
+ long nbtetrastotal=0;
+ file<<nbdomains<<" "<<std::endl;
+
+ //loop on the domains
+ for (int idom=1; idom<=nbdomains; idom++)
+ {
+ oklocal=true;
+ std::ostringstream suffix;
+ suffix<<filename.toLatin1().constData()<<"_"<<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) std::cout<<std::endl;
+ std::cout<<"CreateMEDFile "<<idom<<" "<<distfilename<<std::endl;
+ }
+
+ med_idt fid=MEDouvrir(distfilename,MED_CREATION);
+ if (fid<0) std::cerr<<"Problem MEDouvrir "<<distfilename<<std::endl;
+
+ //updating the ascii master description file
+ tmp=tmp.sprintf(QString(this->casename+"_%d").toLatin1().constData(),idom);
+ file<<this->casename.toLatin1().constData()<<" "<<idom<<" "<<
+ tmp.toLatin1().constData()<<" "<<"localhost "<<distfilename<<" "<<std::endl;
+
+ //create mesh
+ strcpy(namelocal,tmp.toLatin1().constData());
+ tmp=tmp.sprintf("domain %d among %d",idom,nbdomains);
+ strcpy(description,tmp.toLatin1().constData());
+ if (this->verbose>4) std::cout<<"File "<<distfilename<<" : "<<description<<std::endl;
+ //std::cout<<namelocal<<":"<<description<<std::endl
+ err=MEDmaaCr(fid,namelocal,3,MED_NON_STRUCTURE,description);
+ if (err<0) std::cerr<<"Problem MEDmaaCr"<<std::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) std::cerr<<"Problem MEDcoordEcr"<<std::endl;
+ if (this->verbose>4)std::cout<<"NumberOfNodes="<<nbnodes<<std::endl;
+ this->SwapOutOfMemory_key_mesh_wrap(QRegExp(key1));
+
+ //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) std::cerr<<"Problem MEDnumEcr of nodes"<<std::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) std::cout<<"NumberOfTrianglesOfWrap="<<nbfaces<<std::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) std::cerr<<"Problem MEDconnEcr for triangles connectivity"<<std::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) std::cerr<<"Problem MEDnumEcr of triangles"<<std::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) std::cerr<<"Problem MEDfamCr of "<<nomfam<<std::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) std::cerr<<"Problem MEDfamEcr faces of wrap"<<std::endl;
+ delete[] arrayi;*/
- //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)
+ //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;
+ nbtetrastotal=nbtetrastotal + nbtetras;
+ std::cout<<"NumberOfTetraedes="<<nbtetras<<std::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) std::cerr<<"Problem MEDconnEcr for tetra connectivity"<<std::endl;
+ //delete[] arrayi;
+ this->SwapOutOfMemory_key_mesh_wrap(QRegExp(key1));
+
+ //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) std::cerr<<"Problem MEDnumEcr of tetraedes"<<std::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 (this->verbose>2) cout<<endl;
- cout<<"CreateMEDFile "<<idom<<" "<<distfilename<<endl;
+ if (imess==0)
+ {
+ std::cerr<<"Problem for domain "<<idom<<" nrs="<<itest<<
+ " shoud be in [0;97] forced 98"<<std::endl;
+ imess=1; //message only once
+ }
+ itest=98; //0<=nrs<=97 precaution 98=family garbage
}
-
- 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[i]=-numfam_ini_nodes-itest;
+ i2=0;
+ while (1)
{
- arrayi[ii]=tab1->tmint[i]; ii++;
- arrayi[ii]=tab1->tmint[i+1]; ii++;
- arrayi[ii]=tab1->tmint[i+2]; ii++;
- i=i+7;
+ if (i2==imax)
+ {
+ ifam[imax]=itest ; imax++ ; break;
+ }
+ if (itest==ifam[i2]) break;
+ i2++;
+ if (i2>=30) break;
}
- 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;
+ if (imax>=30) {
+ std::cerr<<"Problem more than 30 families of nodes"<<std::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.toLatin1().constData());
+ if (this->verbose>2) std::cout<<"CreateFamilyOfNodes_"<<nomfam<<std::endl;
+ strcpy(gro,tmp.toLatin1().constData());
+ 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.toLatin1().constData());
+ numfam=-numfam_ini_nodes-ifam[i];
+ //attide=1;
+ attval=numfam;
+ //natt=1;
+ ngro=1;
+ if (this->verbose>4) std::cout<<"MEDfamCr (nodes) of "<<nomfam<<" / "<<attdes<<" / FamilyNumber="<<numfam<<std::endl;
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;
- nbtetrastotal=nbtetrastotal + nbtetras;
- 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;
+ if (err<0) std::cerr<<"Problem MEDfamCr of "<<nomfam<<std::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) std::cerr<<"Problem MEDfamEcr nodes"<<std::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)
+ std::cout<<"CreateMEDglobalNumerotation_Nodes "<<key1.toLatin1().constData()<<" "<<tab1->size<<std::endl;
+ if (nbnodes<=0) std::cerr<<"Problem MEDglobalNumEcr not in memory"<<std::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;
+ //std::cout<<"MED_POINT1="<<toto<<" medgeoele0="<<medgeoele0<<std::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) std::cerr<<"Problem MEDglobalNumEcr nodes"<<std::endl;
+ //std::cout<<"MEDglobalNumEcr vertices size="<<nbnodes<<std::endl;
+ //delete[] arrayi;
+ this->SwapOutOfMemory_key_mesh_wrap(QRegExp(key1));
+
+ //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)
+ std::cout<<"CreateMEDglobalNumerotation_Faces "<<key1.toLatin1().constData()<<" "<<tab1->size<<std::endl;
+ err=MEDglobalNumEcr(fid,namelocal,tab1->tmint,nbfaces,MED_FACE,MED_TRIA3);
+ if (err<0) std::cerr<<"Problem MEDglobalNumEcr faces"<<std::endl;
+ //std::cout<<"MEDglobalNumEcr faces size="<<nbfaces<<std::endl;
+ //delete[] arrayi;
+ this->SwapOutOfMemory_key_mesh_wrap(QRegExp(key1));
+
+ //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)
+ std::cerr<<"Problem incorrect size of tetraedes global numbering"<<std::endl;
+ //arrayi=new med_int[nbtetrasglo];
+ //for (int i=0; i<tab1->size ; i++) arrayi[i]=tab1->tmint[i];
+ if (this->verbose>2)
+ std::cout<<"CreateMEDglobalNumerotation_Tetraedes "<<key1.toLatin1().constData()<<" "<<tab1->size<<std::endl;
+ err=MEDglobalNumEcr(fid,namelocal,tab1->tmint,nbtetrasglo,MED_MAILLE,MED_TETRA4);
+ if (err<0) std::cerr<<"Problem MEDglobalNumEcr tetraedes"<<std::endl;
+ //std::cout<<"MEDglobalNumEcr tetraedes size="<<nbtetrasglo<<std::endl;
+ //delete[] arrayi;
+ this->SwapOutOfMemory_key_mesh_wrap(QRegExp(key1));
+
+ //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) std::cerr<<"Problem nodes joint <send> with no <receive> in file .msg"<<std::endl;
+ nbnodes=tab1->size;
+
+ if (this->verbose>4)
+ std::cout<<"NumberOfNodesOfJoint_"<<ineig<<"="<<nbnodes<<std::endl;
+ strcpy(namejnt,tmp.sprintf("joint_%d",ineig).toLatin1().constData());
+ tmp=tmp.sprintf("joint_%d among %d domains of ",ineig,nbdomains)+namelocal;
+ strcpy(descjnt,tmp.toLatin1().constData());
+ //std::cout<<descjnt<<std::endl;
+ strcpy(namedist,tmp.sprintf("joint_%d",idom).toLatin1().constData()); //or this->casename+"_%d",ineig));
+ err=MEDjointCr(fid,namelocal,namejnt,descjnt,ineig,namedist);
+ if (err<0) std::cerr<<"Problem MEDjointCr"<<std::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) std::cerr<<"Problem MEDjointEcr nodes"<<std::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
+
+ //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];
- 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++)
+ if (!tab1)
{
- 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;
- }
+ if (this->verbose>4)
+ std::cout<<"NumberOfTrianglesOfJoint_"<<ineig<<"="<<0<<std::endl;
+ continue; //case (ifile,ineig) are not neighbours=>no joints
}
- for (int i=0 ; i<imax ; i++)
+ 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) std::cerr<<"Problem triangles joint send with no receive"<<std::endl;
+ med_int nbtriangles=tab1->size;
+
+ if (this->verbose>4)
+ std::cout<<"NumberOfTrianglesOfJoint_"<<ineig<<"="<<nbtriangles<<std::endl;
+ arrayi=new med_int[nbtriangles*2];
+ ii=0;
+ for (int i=0; i<nbtriangles ; 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;
+ //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++;
+ //std::cout<<arrayi[ii-1]<<"="<<arrayi[ii-2]<<std::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;
+ err=MEDjointEcr(fid,namelocal,namejnt,arrayi,nbtriangles,MED_FACE,MED_TRIA3,MED_FACE,MED_TRIA3);
+ if (err<0) std::cerr<<"Problem MEDjointEcr triangles"<<std::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;
+
+ tmp=tmp.sprintf("JOINT_%d",ineig);
+ strcpy(nomfam,tmp.toLatin1().constData());
+
+ //err=MEDnumEcr(fid,nomfam,arrayi,nbtriangles,MED_FACE,MED_TRIA3);
+ //if (err<0) std::cerr<<"Problem MEDnumEcr of triangles of "<<nomfam<<std::endl;
+
+ //char gro[MED_TAILLE_LNOM+1]="PART_OF_GLOBAL_WRAP_PLUS_JOINTS";
+ strcpy(gro,tmp.toLatin1().constData());
+ /*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.toLatin1().constData());
+ numfam=-numfam_ini_wrap-ineig;
+ //attide=1;
+ attval=numfam;
+ //natt=1;
+ ngro=1;
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));
+ std::cout<<"CreateFamilyOfFaces_"<<nomfam<<std::endl;
+ if (this->verbose>4) std::cout<<"MEDfamCr (faces) of "<<nomfam<<" / "<<attdes<<" / FamilyNumber="<<numfam<<std::endl;
- //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
- }
- cout<<"\nTotalNumberOfTetraedes="<<nbtetrastotal<<endl;
- return ok;
+ err=MEDfamCr(fid,namelocal,nomfam,numfam,&attide,&attval,attdes,natt,gro,ngro);
+ if (err<0) std::cerr<<"Problem MEDfamCr of "<<nomfam<<std::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) std::cerr<<"Problem MEDfamEcr faces of all joints"<<std::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
+ }
+ std::cout<<"\nTotalNumberOfTetraedes="<<nbtetrastotal<<std::endl;
+ return ok;
}
+// Copyright (C) 2007-2008 OPEN CASCADE, CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// ---
+//
+// File : tepal2med.cxx
+// Author : Christian VAN WAMBEKE (CEA) (from Hexotic plugin Lioka RAZAFINDRAZAKA)
+//
+// ---
+
/*
** prog principal de test de ghs3dprl
*/
#include <cstring>
#include <iostream>
#include <fstream>
-#include "ghs3dprl_msg_parser.h"
-#include <qtextstream.h>
#include <qstring.h>
-#include <qxml.h>
-#include <qwindowdefs.h>
-
+#include <QXmlSimpleReader>
+#include <QXmlInputSource>
+#include <QApplication>
-#include <qapplication.h>
+#include "ghs3dprl_msg_parser.h"
#include "dlg_ghs3dmain.h"
-using namespace std;
using namespace med_2_2;
//************************************
int main(int argc, char **argv)
{
- bool ok,is_test,is_menu,is_launchtepal;
- int nbfiles,nbelem_limit_swap,verbose;
- QString casename,casenamemed,tmp,cmd,format;
- QString version="V0.2 beta";
-
-
- if ((argc > 11)||(argc < 2))
- {
- cerr<<"tepal2med "<<version<<endl;
- cerr<<"Usage: "<<argv[0]<<" CaseNameTepal NumberOfFiles [LimitSwap] [Verbose[0->6]] [Test|noTest] [Menu|noMenu] [LaunchTepal|noLaunchTepal] CaseNameMed\n";
- return 1;
- }
- casename=argv[1];
- tmp=argv[2];
- nbfiles=tmp.toLong(&ok,10);
- if (!ok)
- {
- cerr<<"NumberOfFiles: an integer is expected\n\n";
+ bool ok,is_test,is_menu,is_launchtepal;
+ int nbfiles,nbelem_limit_swap,verbose;
+ QString casename,casenamemed,tmp,cmd,format;
+ QString version="V0.2 beta";
+
+ if ((argc > 11)||(argc < 2))
+ {
+ std::cerr<<"tepal2med "<<version.toLatin1().constData()<<std::endl;
+ std::cerr<<"Usage: "<<argv[0]<<" CaseNameTepal NumberOfFiles [LimitSwap] [Verbose[0->6]] [Test|noTest] [Menu|noMenu] [LaunchTepal|noLaunchTepal] CaseNameMed\n";
+ return 1;
+ }
+ casename=argv[1];
+ tmp=argv[2];
+ nbfiles=tmp.toLong(&ok,10);
+ if (!ok)
+ {
+ std::cerr<<"NumberOfFiles: an integer is expected\n\n";
+ return 1;
+ }
+ if (nbfiles<=0)
+ {
+ std::cerr<<"NumberOfFiles: a positive integer is expected\n\n";
+ return 1;
+ }
+ if (nbfiles>512) //delirium in 2007
+ {
+ std::cerr<<"NumberOfFiles: a positive integer <= 512 is expected\n\n";
+ return 1;
+ }
+
+ //default 1GOctet/8(for double)/10(for arrays in memory at the same time)
+ nbelem_limit_swap=1000000000/8/10;
+ if (argc > 3)
+ {
+ tmp=argv[3];
+ nbelem_limit_swap=tmp.toLong(&ok,10);
+ if (!ok)
+ {
+ std::cerr<<"LimitSwap: an integer is expected\n\n";
return 1;
- }
- if (nbfiles<=0)
- {
- cerr<<"NumberOfFiles: a positive integer is expected\n\n";
+ }
+ if (nbelem_limit_swap<=0)
+ {
+ std::cerr<<"LimitSwap: a positive integer is expected\n\n";
return 1;
- }
- if (nbfiles>512) //delirium in 2007
- {
- cerr<<"NumberOfFiles: a positive integer <= 512 is expected\n\n";
+ }
+ }
+
+ verbose=1; //default
+ if (argc > 4)
+ {
+ tmp=argv[4];
+ verbose=tmp.toLong(&ok,10);
+ if (!ok)
+ {
+ std::cerr<<"Verbose: an integer is expected\n\n";
return 1;
- }
-
- //default 1GOctet/8(for double)/10(for arrays in memory at the same time)
- nbelem_limit_swap=1000000000/8/10;
- if (argc > 3)
- {
- tmp=argv[3];
- nbelem_limit_swap=tmp.toLong(&ok,10);
- if (!ok)
- {
- cerr<<"LimitSwap: an integer is expected\n\n";
- return 1;
- }
- if (nbelem_limit_swap<=0)
- {
- cerr<<"LimitSwap: a positive integer is expected\n\n";
- return 1;
- }
- }
-
- verbose=1; //default
- if (argc > 4)
- {
- tmp=argv[4];
- verbose=tmp.toLong(&ok,10);
- if (!ok)
- {
- cerr<<"Verbose: an integer is expected\n\n";
- return 1;
- }
- if (verbose<0)
- {
- cerr<<"Verbose: a positive integer is expected\n\n";
- return 1;
- }
- }
-
- is_test=FALSE; //default
- if (argc > 5)
- {
- tmp=argv[5];
- if (tmp=="Test") is_test=TRUE;
- }
-
- is_menu=FALSE; //default
- if (argc > 6)
- {
- tmp=argv[6];
- if (tmp=="Menu") is_menu=TRUE;
- }
-
- is_launchtepal=FALSE; //default
- if (argc > 7)
- {
- tmp=argv[7];
- if (tmp=="LaunchTepal") is_launchtepal=TRUE;
- }
-
- casenamemed=casename;
- if (argc > 8)
- {
- casenamemed=argv[8];
- }
-
- // We must always have an application
- if (is_menu)
- {
- QApplication a(argc,argv);
- dlg_ghs3dmain *m = new dlg_ghs3dmain();
- a.setMainWidget(m); // It is our main widget
- m->setCaption("tepal2med "+version);
- m->show(); // Show it...
- a.exec(); // And run!
- cout<<"parameters "<<m->value_KeepFiles<<" "<<m->value_NbPart<<endl;
- //cancel if close widget without Ok button
- if (!m->value_Ok) return 1;
- nbfiles=m->value_NbPart;
- }
-
- QString path;
- int n=casenamemed.contains('/');
- if (n>0)
- path=casenamemed.section('/',-n-1,-2)+"/";
- else
- path="./";
- casenamemed=casenamemed.section('/',-1);
- if (casenamemed.length()>20)
- {
- cerr<<"CaseNameMed truncated (no more 20 characters)"<<endl;
- casenamemed.truncate(20);
- }
-
- /*cout<<"CaseNameMed="<<casenamemed<<endl;
- cout<<"PathMed="<<path<<endl;*/
-
- //verbose=5;
- if (verbose>0)
- cout<<"tepal2med parameters:"<<
- "\n CaseNameTepal="<<casename<<
- "\n NumberOfFiles="<<nbfiles<<
- "\n LimitSwap="<<nbelem_limit_swap<<
- "\n Verbose="<<verbose<<
- "\n Test="<<is_test<<
- "\n Menu="<<is_menu<<
- "\n LaunchTepal="<<is_launchtepal<<
- "\n CaseNameMed="<<path+casenamemed<<
- "\n";
-
- //"tepal -f exemple1 -n 4"
- if (is_launchtepal)
- {
- cmd="tepal -f "+casename+" -n "+cmd.sprintf("%d",nbfiles)+" > "+path+"tepal.log";
- cout<<"\nLaunchTepal Command = "<<cmd<<endl;
- system( (const char *) cmd ); // run
- //sometimes it is better to wait flushing files on slow filesystem...
- system( "sleep 3" );
- }
-
- ghs3dprl_mesh_wrap *mymailw=new ghs3dprl_mesh_wrap;
- //no constructor, later maybe
- mymailw->nbfiles=0;
- mymailw->nbelem_limit_swap=nbelem_limit_swap; //for huge cases big array swap in huge binary files
- mymailw->verbose=verbose;
- mymailw->casename=casenamemed;
- mymailw->path=path;
-
- ghs3dprl_msg_parser handler;
- //constructor later maybe
- //handler.verbose=TRUE;
- handler.mailw=mymailw;
-
- QXmlSimpleReader reader;
- reader.setContentHandler(&handler);
- format=format.sprintf("%d",nbfiles);
- int nbf=format.length();
- format=format.sprintf(".%%.%dd.%%.%dd",nbf,nbf);
- //read files .msg
- for (int i=1; i<=nbfiles; i++)
- {
- mymailw->nofile=i;
- //tmp=casename+tmp.sprintf(".%d.%d.msg",nbfiles,i);
- tmp=casename+tmp.sprintf(format,nbfiles,i)+".msg";
- if (verbose>0) cout<<"FileName="<<tmp<<endl;
- QFile File(tmp);
- QXmlInputSource source(&File);
- reader.parse(source);
- File.close();
- }
- if (verbose>0)
- cout<<"NumberOfFilesMSGAcquired="<<mymailw->nbfiles<<"\n";
- if (mymailw->nbfiles != nbfiles)
- {
- cerr<<"NumberOfFiles != NumberOfFilesAcquired is unexpected\n";
+ }
+ if (verbose<0)
+ {
+ std::cerr<<"Verbose: a positive integer is expected\n\n";
return 1;
- }
-
- if (is_test)
- {
- ok=mymailw->test_msg_wrap();
- if (ok)
- {
- if (verbose>0) cout<<"\nResult_test_msg_wrap=ok\n\n";
- }
- else
- {
- cerr<<"\nResult_test_msg_wrap=NO_OK!\n\n";
- return 1;
- }
- }
-
- //after verification remove unusued data
- //"NE0 FI" for/from <version>1.0</version>
- //after verification remove duplicates data
- //for debug but don't do that because reliability
- // and locality of datas files
- //" RE " for duplicates <receive>
- //int nb=mymailw->remove_key_mesh_wrap(QRegExp("( NE0 | RE)",TRUE,FALSE));
-
- //because <send> equals <receive>
- int nb=0;
- nb=mymailw->remove_key_mesh_wrap(QRegExp("RE",TRUE,FALSE));
- if (verbose>3) cout<<"NumberOfKeysRemoved="<<nb<<endl;
- if (verbose>3) ok=mymailw->list_keys_mesh_wrap();
-
- //test read files .noboiteb
- //tmp=casename+".noboiteb";
- //ok=mymailw->ReadFileNOBOITEB(tmp);
-
- //read files .noboite
- //supposed big files
- mymailw->nbfiles=0;
- for (int i=1; i<=nbfiles; i++)
- {
- mymailw->nofile=i;
- tmp=casename+tmp.sprintf(format,nbfiles,i)+".noboite";
- if (verbose>0) cout<<"FileName="<<tmp<<endl;
- ok=mymailw->ReadFileNOBOITE(tmp);
- //mymailw->SwapOutOfMemory_key_mesh_wrap(QRegExp("NB",TRUE,FALSE));
- }
- if (verbose>0)
- cout<<"NumberOfFilesNOBOITEAcquired="<<mymailw->nbfiles<<"\n";
- if (mymailw->nbfiles != nbfiles)
- {
- cerr<<"NumberOfFiles != NumberOfFilesAcquired is unexpected\n";
+ }
+ }
+
+ is_test=false; //default
+ if (argc > 5)
+ {
+ tmp=argv[5];
+ if (tmp=="Test") is_test=true;
+ }
+
+ is_menu=false; //default
+ if (argc > 6)
+ {
+ tmp=argv[6];
+ if (tmp=="Menu") is_menu=true;
+ }
+
+ is_launchtepal=false; //default
+ if (argc > 7)
+ {
+ tmp=argv[7];
+ if (tmp=="LaunchTepal") is_launchtepal=true;
+ }
+
+ casenamemed=casename;
+ if (argc > 8)
+ {
+ casenamemed=argv[8];
+ }
+
+ // We must always have an application
+ if (is_menu)
+ {
+ QApplication a(argc,argv);
+ dlg_ghs3dmain *m = new dlg_ghs3dmain();
+ m->setWindowTitle("tepal2med 2.1");
+ m->show();
+ a.exec();
+ if ( m->result() == QDialog::Accepted ) {
+ std::cout<<"parameters "<<m->KeepFiles()<<" "<<m->NbPart()<<std::endl;
+ nbfiles=m->NbPart();
+ }
+ else {
return 1;
- }
-
- if (is_test)
- {
- ok=mymailw->test_vertices_wrap();
- if (ok)
- {
- if (verbose>0) cout<<"\nResult_test_vertices_wrap=ok\n\n";
- }
- else
- {
- cerr<<"\nResult_test_vertices_wrap=NO_OK!\n\n";
- return 1;
- }
- }
-
- //read files .faces
- mymailw->nbfiles=0;
- for (int i=1; i<=nbfiles; i++)
- {
- mymailw->nofile=i;
- tmp=casename+tmp.sprintf(format,nbfiles,i)+".faces";
- if (verbose>0) cout<<"FileName="<<tmp<<endl;
- ok=mymailw->ReadFileFACES(tmp);
- }
- if (verbose>0)
- cout<<"NumberOfFilesFACESAcquired="<<mymailw->nbfiles<<"\n\n";
- if (mymailw->nbfiles != nbfiles)
- {
- cerr<<"NumberOfFiles != NumberOfFilesAcquired is unexpected\n\n";
+ }
+ delete m;
+ }
+
+ QString path;
+ int n=casenamemed.count('/');
+ if (n>0)
+ path=casenamemed.section('/',-n-1,-2)+"/";
+ else
+ path="./";
+ casenamemed=casenamemed.section('/',-1);
+ if (casenamemed.length()>20)
+ {
+ std::cerr<<"CaseNameMed truncated (no more 20 characters)"<<std::endl;
+ casenamemed.truncate(20);
+ }
+
+ /*std::cout<<"CaseNameMed="<<casenamemed<<std::endl;
+ std::cout<<"PathMed="<<path<<std::endl;*/
+
+ //verbose=5;
+ if (verbose>0)
+ std::cout<<"tepal2med parameters:"<<
+ "\n CaseNameTepal="<<casename.toLatin1().constData()<<
+ "\n NumberOfFiles="<<nbfiles<<
+ "\n LimitSwap="<<nbelem_limit_swap<<
+ "\n Verbose="<<verbose<<
+ "\n Test="<<is_test<<
+ "\n Menu="<<is_menu<<
+ "\n LaunchTepal="<<is_launchtepal<<
+ "\n CaseNameMed="<<path.toLatin1().constData()<<casenamemed.toLatin1().constData()<<
+ "\n";
+
+ //"tepal -f exemple1 -n 4"
+ if (is_launchtepal)
+ {
+ cmd="tepal -f "+casename+" -n "+cmd.sprintf("%d",nbfiles)+" > "+path+"tepal.log";
+ std::cout<<"\nLaunchTepal Command = "<<cmd.toLatin1().constData()<<std::endl;
+ system( cmd.toLatin1().constData() ); // run
+ //sometimes it is better to wait flushing files on slow filesystem...
+ system( "sleep 3" );
+ }
+
+ ghs3dprl_mesh_wrap *mymailw=new ghs3dprl_mesh_wrap;
+ //no constructor, later maybe
+ mymailw->nbfiles=0;
+ mymailw->nbelem_limit_swap=nbelem_limit_swap; //for huge cases big array swap in huge binary files
+ mymailw->verbose=verbose;
+ mymailw->casename=casenamemed;
+ mymailw->path=path;
+
+ ghs3dprl_msg_parser handler;
+ //constructor later maybe
+ //handler.verbose=true;
+ handler.mailw=mymailw;
+
+ QXmlSimpleReader reader;
+ reader.setContentHandler(&handler);
+ format=format.sprintf("%d",nbfiles);
+ int nbf=format.length();
+ format=format.sprintf(".%%.%dd.%%.%dd",nbf,nbf);
+ //read files .msg
+ for (int i=1; i<=nbfiles; i++)
+ {
+ mymailw->nofile=i;
+ //tmp=casename+tmp.sprintf(".%d.%d.msg",nbfiles,i);
+ tmp=casename+tmp.sprintf(format.toLatin1().constData(),nbfiles,i)+".msg";
+ if (verbose>0) std::cout<<"FileName="<<tmp.toLatin1().constData()<<std::endl;
+ QFile File(tmp);
+ QXmlInputSource source(&File);
+ reader.parse(source);
+ File.close();
+ }
+ if (verbose>0)
+ std::cout<<"NumberOfFilesMSGAcquired="<<mymailw->nbfiles<<"\n";
+ if (mymailw->nbfiles != nbfiles)
+ {
+ std::cerr<<"NumberOfFiles != NumberOfFilesAcquired is unexpected\n";
+ return 1;
+ }
+
+ if (is_test)
+ {
+ ok=mymailw->test_msg_wrap();
+ if (ok)
+ {
+ if (verbose>0) std::cout<<"\nResult_test_msg_wrap=ok\n\n";
+ }
+ else
+ {
+ std::cerr<<"\nResult_test_msg_wrap=NO_OK!\n\n";
return 1;
- }
-
- //read files .points
- mymailw->nbfiles=0;
- for (int i=1; i<=nbfiles; i++)
- {
- mymailw->nofile=i;
- tmp=casename+tmp.sprintf(format,nbfiles,i)+".points";
- if (verbose>0) cout<<"FileName="<<tmp<<endl;
- ok=mymailw->ReadFilePOINTS(tmp);
- }
- if (verbose>0)
- cout<<"NumberOfFilesPOINTSAcquired="<<mymailw->nbfiles<<"\n\n";
- if (mymailw->nbfiles != nbfiles)
- {
- cerr<<"NumberOfFiles != NumberOfFilesAcquired is unexpected\n\n";
+ }
+ }
+
+ //after verification remove unusued data
+ //"NE0 FI" for/from <version>1.0</version>
+ //after verification remove duplicates data
+ //for debug but don't do that because reliability
+ // and locality of datas files
+ //" RE " for duplicates <receive>
+ //int nb=mymailw->remove_key_mesh_wrap(QRegExp("( NE0 | RE)",true,false));
+
+ //because <send> equals <receive>
+ int nb=0;
+ nb=mymailw->remove_key_mesh_wrap(QRegExp("RE"));
+ if (verbose>3) std::cout<<"NumberOfKeysRemoved="<<nb<<std::endl;
+ if (verbose>3) ok=mymailw->list_keys_mesh_wrap();
+
+ //test read files .noboiteb
+ //tmp=casename+".noboiteb";
+ //ok=mymailw->ReadFileNOBOITEB(tmp);
+
+ //read files .noboite
+ //supposed big files
+ mymailw->nbfiles=0;
+ for (int i=1; i<=nbfiles; i++)
+ {
+ mymailw->nofile=i;
+ tmp=casename+tmp.sprintf(format.toLatin1().constData(),nbfiles,i)+".noboite";
+ if (verbose>0) std::cout<<"FileName="<<tmp.toLatin1().constData()<<std::endl;
+ ok=mymailw->ReadFileNOBOITE(tmp);
+ //mymailw->SwapOutOfMemory_key_mesh_wrap(QRegExp("NB",true,false));
+ }
+ if (verbose>0)
+ std::cout<<"NumberOfFilesNOBOITEAcquired="<<mymailw->nbfiles<<"\n";
+ if (mymailw->nbfiles != nbfiles)
+ {
+ std::cerr<<"NumberOfFiles != NumberOfFilesAcquired is unexpected\n";
+ return 1;
+ }
+
+ if (is_test)
+ {
+ ok=mymailw->test_vertices_wrap();
+ if (ok)
+ {
+ if (verbose>0) std::cout<<"\nResult_test_vertices_wrap=ok\n\n";
+ }
+ else
+ {
+ std::cerr<<"\nResult_test_vertices_wrap=NO_OK!\n\n";
return 1;
- }
-
- //read files .glo
- //supposed big files big arrays so don't read with parser
- mymailw->nbfiles=0;
- for (int i=1; i<=nbfiles; i++)
- {
- mymailw->nofile=i;
- tmp=casename+tmp.sprintf(format,nbfiles,i)+".glo";
- if (verbose>0) cout<<"FileName="<<tmp<<endl;
- ok=mymailw->ReadFileGLO(tmp);
- //mymailw->SwapOutOfMemory_key_mesh_wrap(QRegExp("GL",TRUE,FALSE));
- }
- if (verbose>0)
- cout<<"NumberOfFilesGLOAcquired="<<mymailw->nbfiles<<"\n\n";
- if (mymailw->nbfiles != nbfiles)
- {
- cerr<<"NumberOfFiles != NumberOfFilesAcquired is unexpected\n\n";
+ }
+ }
+
+ //read files .faces
+ mymailw->nbfiles=0;
+ for (int i=1; i<=nbfiles; i++)
+ {
+ mymailw->nofile=i;
+ tmp=casename+tmp.sprintf(format.toLatin1().constData(),nbfiles,i)+".faces";
+ if (verbose>0) std::cout<<"FileName="<<tmp.toLatin1().constData()<<std::endl;
+ ok=mymailw->ReadFileFACES(tmp);
+ }
+ if (verbose>0)
+ std::cout<<"NumberOfFilesFACESAcquired="<<mymailw->nbfiles<<"\n\n";
+ if (mymailw->nbfiles != nbfiles)
+ {
+ std::cerr<<"NumberOfFiles != NumberOfFilesAcquired is unexpected\n\n";
+ return 1;
+ }
+
+ //read files .points
+ mymailw->nbfiles=0;
+ for (int i=1; i<=nbfiles; i++)
+ {
+ mymailw->nofile=i;
+ tmp=casename+tmp.sprintf(format.toLatin1().constData(),nbfiles,i)+".points";
+ if (verbose>0) std::cout<<"FileName="<<tmp.toLatin1().constData()<<std::endl;
+ ok=mymailw->ReadFilePOINTS(tmp);
+ }
+ if (verbose>0)
+ std::cout<<"NumberOfFilesPOINTSAcquired="<<mymailw->nbfiles<<"\n\n";
+ if (mymailw->nbfiles != nbfiles)
+ {
+ std::cerr<<"NumberOfFiles != NumberOfFilesAcquired is unexpected\n\n";
+ return 1;
+ }
+
+ //read files .glo
+ //supposed big files big arrays so don't read with parser
+ mymailw->nbfiles=0;
+ for (int i=1; i<=nbfiles; i++)
+ {
+ mymailw->nofile=i;
+ tmp=casename+tmp.sprintf(format.toLatin1().constData(),nbfiles,i)+".glo";
+ if (verbose>0) std::cout<<"FileName="<<tmp.toLatin1().constData()<<std::endl;
+ ok=mymailw->ReadFileGLO(tmp);
+ //mymailw->SwapOutOfMemory_key_mesh_wrap(QRegExp("GL",true,false));
+ }
+ if (verbose>0)
+ std::cout<<"NumberOfFilesGLOAcquired="<<mymailw->nbfiles<<"\n\n";
+ if (mymailw->nbfiles != nbfiles)
+ {
+ std::cerr<<"NumberOfFiles != NumberOfFilesAcquired is unexpected\n\n";
return 1;
- }
-
- /*exemples
- ok=mymailw->list_keys_mesh_wrap();
- tmp="FA RE NE4 FI1";
- ok=mymailw->list_onekey_mesh_wrap(tmp);
- tmp="FA SE NE4 FI1";
- ok=mymailw->list_onekey_mesh_wrap(tmp);
- tmp="FA RE NE1 FI4";
- ok=mymailw->list_onekey_mesh_wrap(tmp);
- tmp="FA SE NE1 FI4";
- ok=mymailw->list_onekey_mesh_wrap(tmp);
-
- tmp="FA RE NE4 FI1";
- ok=mymailw->list_onekey_mesh_wrap(tmp);*/
-
- //test remove points (type 3)
- //nb=mymailw->remove_key_mesh_wrap(QRegExp("PO",TRUE,FALSE));
- //cout<<"***remove_key_mesh_wrap*** remove nb="<<nb<<endl;
- //ok=mymailw->list_keys_mesh_wrap();
-
- ok=mymailw->Write_MEDfiles();
- //int nb=mymailw->remove_key_mesh_wrap(QRegExp(".",TRUE,FALSE));
- nb=mymailw->remove_all_keys_mesh_wrap();
- if (verbose>3)
- cout<<"***remove_all_key_mesh_wrap*** "<<nb<<" keys removed\n";
- cout<<endl<<"===end of "<<argv[0]<<"==="<<endl;
- return 0; //ok
+ }
+
+ /*exemples
+ ok=mymailw->list_keys_mesh_wrap();
+ tmp="FA RE NE4 FI1";
+ ok=mymailw->list_onekey_mesh_wrap(tmp);
+ tmp="FA SE NE4 FI1";
+ ok=mymailw->list_onekey_mesh_wrap(tmp);
+ tmp="FA RE NE1 FI4";
+ ok=mymailw->list_onekey_mesh_wrap(tmp);
+ tmp="FA SE NE1 FI4";
+ ok=mymailw->list_onekey_mesh_wrap(tmp);
+
+ tmp="FA RE NE4 FI1";
+ ok=mymailw->list_onekey_mesh_wrap(tmp);*/
+
+ //test remove points (type 3)
+ //nb=mymailw->remove_key_mesh_wrap(QRegExp("PO",true,false));
+ //std::cout<<"***remove_key_mesh_wrap*** remove nb="<<nb<<std::endl;
+ //ok=mymailw->list_keys_mesh_wrap();
+
+ ok=mymailw->Write_MEDfiles();
+ //int nb=mymailw->remove_key_mesh_wrap(QRegExp(".",true,false));
+ nb=mymailw->remove_all_keys_mesh_wrap();
+ if (verbose>3)
+ std::cout<<"***remove_all_key_mesh_wrap*** "<<nb<<" keys removed\n";
+ std::cout<<std::endl<<"===end of "<<argv[0]<<"==="<<std::endl;
+
+ return 0; //ok
}