From 94008d0f9741938458a70722056188b2c8aea526 Mon Sep 17 00:00:00 2001 From: gdd Date: Thu, 14 Apr 2011 09:43:31 +0000 Subject: [PATCH] Porting to MED3 --- doc/conf.py | 4 +- src/HOMARDGUI/HomardQtCommun.cxx | 256 +++++++++++++++++-------------- src/HOMARDGUI/HomardQtCommun.h | 4 - src/HOMARD_I/HomardMedCommun.cxx | 252 ++++++++++++++++++------------ src/HOMARD_I/HomardMedCommun.h | 5 - 5 files changed, 301 insertions(+), 220 deletions(-) diff --git a/doc/conf.py b/doc/conf.py index 2b658f9b..ad1c1f46 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -45,9 +45,9 @@ copyright = u'1996, 2011, EDF R&D, G. Nicolas, T. Fouquet, P. Noyret' # built documents. # # The short X.Y version. -version = '9.9' +version = '10.1' # The full version, including alpha/beta/rc tags. -release = '9.9' +release = '10.1' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/src/HOMARDGUI/HomardQtCommun.cxx b/src/HOMARDGUI/HomardQtCommun.cxx index 79746df4..b96dfea7 100644 --- a/src/HOMARDGUI/HomardQtCommun.cxx +++ b/src/HOMARDGUI/HomardQtCommun.cxx @@ -178,21 +178,21 @@ int HOMARD_QT_COMMUN::OuvrirFichier(QString aFile) // ======================================================================= // renvoie le medId associe au fichier Med apres ouverture { - int MedIdt = MEDouvrir(const_cast(aFile.toStdString().c_str()),MED_LECTURE); - if (MedIdt <0) + med_int medIdt = MEDfileOpen(aFile.toStdString().c_str(),MED_ACC_RDONLY); + if (medIdt <0) { QMessageBox::critical( 0, QObject::tr("HOM_ERROR"), QObject::tr("HOM_MED_FILE_1") ); } - return MedIdt; + return (int) medIdt; } // ====================================================== QString HOMARD_QT_COMMUN::LireNomMaillage(QString aFile) // ======================================================== { - int MedIdt = HOMARD_QT_COMMUN::OuvrirFichier(aFile); - int numberOfMeshes = MEDnMaa(MedIdt) ; + med_int medIdt = HOMARD_QT_COMMUN::OuvrirFichier(aFile); + med_int numberOfMeshes = MEDnMesh(medIdt) ; if (numberOfMeshes == 0 ) { QMessageBox::critical( 0, QObject::tr("HOM_ERROR"), @@ -204,30 +204,50 @@ QString HOMARD_QT_COMMUN::LireNomMaillage(QString aFile) QObject::tr("HOM_MED_FILE_3") ); } - QString nomMaillage= HOMARD_QT_COMMUN::LireNomMaillage(MedIdt,1); - MEDfermer(MedIdt); + QString nomMaillage= HOMARD_QT_COMMUN::LireNomMaillage(medIdt,1); + MEDfileClose(medIdt); return nomMaillage; } // ======================================================================= -QString HOMARD_QT_COMMUN::LireNomMaillage(int MedIdt ,int MeshId) +QString HOMARD_QT_COMMUN::LireNomMaillage(int medIdt ,int meshId) // ======================================================================= { - QString NomMaillage=QString::null; - char maa[MED_TAILLE_NOM+1]; - char desc[MED_TAILLE_DESC+1]; - med_int mdim; - med_maillage type; - - if ( MEDmaaInfo(MedIdt,MeshId,maa,&mdim,&type,desc) < 0 ) - { - QMessageBox::critical( 0, QObject::tr("HOM_ERROR"), - QObject::tr("HOM_MED_FILE_4") ); - } - else - { - NomMaillage=QString(maa); - } - return NomMaillage; + QString NomMaillage=QString::null; + char meshname[MED_NAME_SIZE+1]; + med_int spacedim,meshdim; + med_mesh_type meshtype; + char descriptionription[MED_COMMENT_SIZE+1]; + char dtunit[MED_SNAME_SIZE+1]; + med_sorting_type sortingtype; + med_int nstep; + med_axis_type axistype; + int naxis = MEDmeshnAxis(medIdt,1); + char *axisname=new char[naxis*MED_SNAME_SIZE+1]; + char *axisunit=new char[naxis*MED_SNAME_SIZE+1]; + med_err aRet = MEDmeshInfo(medIdt, + meshId, + meshname, + &spacedim, + &meshdim, + &meshtype, + descriptionription, + dtunit, + &sortingtype, + &nstep, + &axistype, + axisname, + axisunit); + + if ( aRet < 0 ) + { + QMessageBox::critical( 0, QObject::tr("HOM_ERROR"), + QObject::tr("HOM_MED_FILE_4") ); + } + else + { + NomMaillage=QString(meshname); + } + return NomMaillage; } @@ -237,111 +257,121 @@ std::list HOMARD_QT_COMMUN::GetListeChamps(QString aFile) { // Il faut voir si plusieurs maillages - MESSAGE("HOMARD_QT_COMMUN::GetListeChamps"); - std::list ListeChamp; + MESSAGE("HOMARD_QT_COMMUN::GetListeChamps"); + std::list ListeChamp; - char *comp, *unit; - char nomcha [MED_TAILLE_NOM+1]; - med_type_champ typcha; - med_int ncomp; + char *comp, *unit; + char nomcha [MED_NAME_SIZE+1]; + char meshname[MED_NAME_SIZE+1]; + med_field_type typcha; + med_int ncomp; + med_bool local; + med_int nbofcstp; - SCRUTE(aFile.toStdString()); - int MedIdt = HOMARD_QT_COMMUN::OuvrirFichier(aFile); - if ( MedIdt < 0 ) { return ListeChamp; } + SCRUTE(aFile.toStdString()); + med_int medIdt = HOMARD_QT_COMMUN::OuvrirFichier(aFile); + if ( medIdt < 0 ) { return ListeChamp; } - // Le fichier Med est lisible - // Lecture du maillage + // Le fichier Med est lisible + // Lecture du maillage - // Lecture du nombre de champs - med_int ncha = MEDnChamp(MedIdt, 0) ; - if (ncha < 1 ) - { + // Lecture du nombre de champs + med_int ncha = MEDnField(medIdt) ; + if (ncha < 1 ) + { QMessageBox::critical( 0, QObject::tr("HOM_ERROR"), - QObject::tr("HOM_MED_FILE_5") ); - MEDfermer(MedIdt); - return ListeChamp; - } - - for (int i=0; i< ncha; i++) - { - /* Lecture du type du champ, des noms des composantes et du nom de l'unite*/ - ncomp = MEDnChamp(MedIdt,i+1); - comp = (char*) malloc(ncomp*MED_TAILLE_PNOM+1); - unit = (char*) malloc(ncomp*MED_TAILLE_PNOM+1); - if ( MEDchampInfo(MedIdt,i+1,nomcha,&typcha,comp,unit,ncomp) < 0 ) - { - QMessageBox::critical( 0, QObject::tr("HOM_ERROR"), - QObject::tr("HOM_MED_FILE_6") ); - MEDfermer(MedIdt); - return ListeChamp; - } + QObject::tr("HOM_MED_FILE_5") ); + MEDfileClose(medIdt); + return ListeChamp; + } - ListeChamp.push_back(QString(nomcha)); - free(comp); - free(unit); - } - MEDfermer(MedIdt); - return ListeChamp; + for (int i=0; i< ncha; i++) + { + /* Lecture du type du champ, des noms des composantes et du nom de l'unite*/ + ncomp = MEDfieldnComponent(medIdt,i+1); + comp = (char*) malloc(ncomp*MED_SNAME_SIZE+1); + unit = (char*) malloc(ncomp*MED_SNAME_SIZE+1); + char dtunit[MED_SNAME_SIZE+1]; + if ( MEDfieldInfo(medIdt,i+1,nomcha,meshname,&local,&typcha,comp,unit,dtunit,&nbofcstp) < 0 ) + { + QMessageBox::critical( 0, QObject::tr("HOM_ERROR"), + QObject::tr("HOM_MED_FILE_6") ); + MEDfileClose(medIdt); + return ListeChamp; + } + + ListeChamp.push_back(QString(nomcha)); + free(comp); + free(unit); + } + MEDfileClose(medIdt); + return ListeChamp; } // ====================================================================================== std::list HOMARD_QT_COMMUN::GetListeComposants(QString aFile, QString aChamp) // ====================================================================================== { - MESSAGE ( "GetListeComposants pour le fichier " << aFile.toStdString().c_str()); - MESSAGE ( "GetListeComposants pour le champ " << aChamp.toStdString().c_str()); + MESSAGE ( "GetListeComposants pour le fichier " << aFile.toStdString().c_str()); + MESSAGE ( "GetListeComposants pour le champ " << aChamp.toStdString().c_str()); - std::list ListeComposants; + std::list ListeComposants; - char *comp, *unit; - char nomcha [MED_TAILLE_NOM+1]; - med_type_champ typcha; - med_int ncomp; + char *comp, *unit; + char nomcha [MED_NAME_SIZE+1]; + char meshname[MED_NAME_SIZE+1]; + med_field_type typcha; + med_int ncomp; + med_bool local; + med_int nbofcstp; - int MedIdt = HOMARD_QT_COMMUN::OuvrirFichier(aFile); - if ( MedIdt < 0 ) { return ListeComposants; } + int medIdt = HOMARD_QT_COMMUN::OuvrirFichier(aFile); + if ( medIdt < 0 ) { return ListeComposants; } - // Lecture du nombre de champs - med_int ncha = MEDnChamp(MedIdt, 0) ; - if (ncha < 1 ) - { + // Lecture du nombre de champs + med_int ncha = MEDnField(medIdt) ; + if (ncha < 1 ) + { QMessageBox::critical( 0, QObject::tr("HOM_ERROR"), - QObject::tr("HOM_MED_FILE_5") ); - MEDfermer(MedIdt); - return ListeComposants; - } - - for (int i=0; i< ncha; i++) - { - /* Lecture du type du champ, des noms des composantes et du nom de l'unite*/ - ncomp = MEDnChamp(MedIdt,i+1); - comp = (char*) malloc(ncomp*MED_TAILLE_PNOM+1); - unit = (char*) malloc(ncomp*MED_TAILLE_PNOM+1); - - if ( MEDchampInfo(MedIdt,i+1,nomcha,&typcha,comp,unit,ncomp) < 0 ) - { - QMessageBox::critical( 0, QObject::tr("HOM_ERROR"), - QObject::tr("HOM_MED_FILE_6") ); - MEDfermer(MedIdt); - return ListeComposants; - } - if ( QString(nomcha) != aChamp ) { - free(comp); - free (unit); - continue;} - - for (int j = 0; j #include #include -extern "C" -{ -#include -} class QComboBox; diff --git a/src/HOMARD_I/HomardMedCommun.cxx b/src/HOMARD_I/HomardMedCommun.cxx index bacc234a..e99d676e 100644 --- a/src/HOMARD_I/HomardMedCommun.cxx +++ b/src/HOMARD_I/HomardMedCommun.cxx @@ -1,9 +1,10 @@ #include "HomardMedCommun.h" -using namespace std; + #include #include #include #include +#include extern "C" { @@ -15,69 +16,98 @@ extern "C" std::set GetListeGroupesInMedFile(const char * aFile) // ======================================================================= { - std::set ListeGroupes; - int MedIdt = MEDouvrir(const_cast(aFile),MED_LECTURE); - if ( MedIdt < 0 ) { return ListeGroupes; }; - - char maa[MED_TAILLE_NOM+1]; - char desc[MED_TAILLE_DESC+1]; - char nomfam[MED_TAILLE_NOM+1]; - med_int numfam; + std::set ListeGroupes; + med_idt medIdt = MEDfileOpen(aFile,MED_ACC_RDONLY); + if ( medIdt < 0 ) { return ListeGroupes; }; - med_int mdim; - med_maillage type; - med_int numMaillage=1; - if ( MEDmaaInfo(MedIdt,numMaillage,maa,&mdim,&type,desc) < 0 ) { return ListeGroupes; }; + char meshname[MED_NAME_SIZE+1]; + med_int spacedim,meshdim; + med_mesh_type meshtype; + char descriptionription[MED_COMMENT_SIZE+1]; + char dtunit[MED_SNAME_SIZE+1]; + med_sorting_type sortingtype; + med_int nstep; + med_axis_type axistype; + int naxis = MEDmeshnAxis(medIdt,1); + char *axisname=new char[naxis*MED_SNAME_SIZE+1]; + char *axisunit=new char[naxis*MED_SNAME_SIZE+1]; + med_err aRet = MEDmeshInfo(medIdt, + 1, + meshname, + &spacedim, + &meshdim, + &meshtype, + descriptionription, + dtunit, + &sortingtype, + &nstep, + &axistype, + axisname, + axisunit); + if ( aRet < 0 ) { return ListeGroupes; }; + med_int nfam, ngro, natt; - if ((nfam = MEDnFam(MedIdt,maa)) < 0) { return ListeGroupes; }; - for (int i=0;i 0) { continue;} // On ne garde que les familles d elts + if ((natt = MEDnFamily23Attribute(medIdt,meshname,i+1)) < 0) + { + // GERALD -- QMESSAGE BOX + std::cerr << " Error : Families are unreadable" << std::endl; + std::cerr << "Pb avec la famille : " << i+1 << std::endl; + break; + } - for (int j=0;j 0) { continue;} // On ne garde que les familles d elts - } - free(gro); - } - MEDfermer(MedIdt); - return ListeGroupes; + for (int j=0;j GetBoundingBoxInMedFile(const char * aFile) std::vector LesExtremes; - // Ouverture du Fichier Med - int MedIdt = MEDouvrir(const_cast(aFile),MED_LECTURE); - if (MedIdt <0) + // Ouverture du Fichier Med + med_idt medIdt = MEDfileOpen(aFile,MED_ACC_RDONLY); + if (medIdt <0) { // GERALD -- QMESSAGE BOX std::cerr << "Error : mesh is unreadable" << std::endl; @@ -102,8 +132,8 @@ std::vector GetBoundingBoxInMedFile(const char * aFile) } // Le fichier Med est lisible - // Boucle sur les noms de maillage - int numberOfMeshes = MEDnMaa(MedIdt) ; + // Boucle sur les noms de maillage + med_int numberOfMeshes = MEDnMesh(medIdt) ; if (numberOfMeshes != 1 ) { // GERALD -- QMESSAGE BOX @@ -111,40 +141,70 @@ std::vector GetBoundingBoxInMedFile(const char * aFile) return LesExtremes; } - char maa[MED_TAILLE_NOM+1]; - char desc[MED_TAILLE_DESC+1]; - char nomcoo[3*MED_TAILLE_PNOM+1]; - char unicoo[3*MED_TAILLE_PNOM+1]; - med_maillage type; - med_repere rep; - med_booleen inonoe,inunoe; - - med_int dim; - med_int numMaillage=1; + char meshname[MED_NAME_SIZE+1]; + med_int spacedim,meshdim; + med_mesh_type meshtype; + char descriptionription[MED_COMMENT_SIZE+1]; + char dtunit[MED_SNAME_SIZE+1]; + med_sorting_type sortingtype; + med_int nstep; + med_axis_type axistype; + int naxis = MEDmeshnAxis(medIdt,1); + char *axisname=new char[naxis*MED_SNAME_SIZE+1]; + char *axisunit=new char[naxis*MED_SNAME_SIZE+1]; + med_err aRet = MEDmeshInfo(medIdt, + 1, + meshname, + &spacedim, + &meshdim, + &meshtype, + descriptionription, + dtunit, + &sortingtype, + &nstep, + &axistype, + axisname, + axisunit); - if (MEDmaaInfo(MedIdt,numMaillage,maa,&dim,&type,desc) < 0) + if (aRet < 0) { // GERALD -- QMESSAGE BOX - std::cerr << "Error : mesh " << numMaillage << " is unreadable" << std::endl; + std::cerr << "Error : mesh is unreadable" << std::endl; return LesExtremes; } - med_int nnoe = MEDnEntMaa(MedIdt,maa,MED_COOR,MED_NOEUD,(med_geometrie_element)0,(med_connectivite)0); + med_bool chgt,trsf; + med_int nnoe = MEDmeshnEntity(medIdt, + meshname, + MED_NO_DT, + MED_NO_IT, + MED_NODE, + MED_NO_GEOTYPE, + MED_COORDINATE, + MED_NO_CMODE, + &chgt, + &trsf); if ( nnoe < 0) { // GERALD -- QMESSAGE BOX - std::cerr << "Error : mesh " << numMaillage << " is unreadable" << std::endl; + std::cerr << "Error : mesh is unreadable" << std::endl; return LesExtremes; } - med_float* coo = (med_float*) malloc(sizeof(med_float)*nnoe*dim); - med_int* numnoe = (med_int*) malloc(sizeof(med_int)*nnoe); - med_int* nufano = (med_int*) malloc(sizeof(med_int)*nnoe); - char * nomnoe = (char*) malloc(MED_TAILLE_PNOM*nnoe+1); + med_float* coo = (med_float*) malloc(sizeof(med_float)*nnoe*spacedim); - MEDnoeudsLire(MedIdt,maa,dim,coo,MED_NO_INTERLACE,&rep, - nomcoo,unicoo,nomnoe,&inonoe,numnoe,&inunoe, - nufano,nnoe); + aRet = MEDmeshNodeCoordinateRd(medIdt, + meshname, + MED_NO_DT, + MED_NO_IT, + MED_NO_INTERLACE, + coo); + if ( aRet < 0) + { + // GERALD -- QMESSAGE BOX + std::cerr << "Error : mesh coordinates are unreadable" << std::endl; + return LesExtremes; + } med_float xmin,xmax,ymin,ymax,zmin,zmax; @@ -152,17 +212,17 @@ std::vector GetBoundingBoxInMedFile(const char * aFile) xmax=coo[0]; for (int i=1;i 1) + if (spacedim > 1) { ymin=coo[nnoe]; ymax=coo[nnoe]; for (int i=nnoe+1;i<2*nnoe;i++) { - ymin = min(ymin,coo[i]); - ymax = max(ymax,coo[i]); + ymin = std::min(ymin,coo[i]); + ymax = std::max(ymax,coo[i]); } } else @@ -173,13 +233,13 @@ std::vector GetBoundingBoxInMedFile(const char * aFile) zmax=0; } // - if (dim > 2) + if (spacedim > 2) { zmin=coo[2*nnoe]; zmax=coo[2*nnoe]; for (int i=2*nnoe+1;i<3*nnoe;i++) { - zmin = min(zmin,coo[i]); - zmax = max(zmax,coo[i]); + zmin = std::min(zmin,coo[i]); + zmax = std::max(zmax,coo[i]); } } else @@ -187,7 +247,7 @@ std::vector GetBoundingBoxInMedFile(const char * aFile) zmin=0; zmax=0; } - MEDfermer(MedIdt); + MEDfileClose(medIdt); MESSAGE( "_______________________________________"); MESSAGE( "xmin : " << xmin << " xmax : " << xmax ); @@ -206,8 +266,8 @@ std::vector GetBoundingBoxInMedFile(const char * aFile) LesExtremes.push_back(0); - double max1=max ( LesExtremes[1] - LesExtremes[0] , LesExtremes[4] - LesExtremes[3] ) ; - double max2=max ( max1 , LesExtremes[7] - LesExtremes[6] ) ; + double max1=std::max ( LesExtremes[1] - LesExtremes[0] , LesExtremes[4] - LesExtremes[3] ) ; + double max2=std::max ( max1 , LesExtremes[7] - LesExtremes[6] ) ; LesExtremes.push_back(max2); // LesExtremes[0] = Xmini du maillage diff --git a/src/HOMARD_I/HomardMedCommun.h b/src/HOMARD_I/HomardMedCommun.h index 9f9c65df..2978e715 100644 --- a/src/HOMARD_I/HomardMedCommun.h +++ b/src/HOMARD_I/HomardMedCommun.h @@ -5,11 +5,6 @@ #include #include -extern "C" -{ -#include -} - std::vector GetBoundingBoxInMedFile( const char * aFile); std::set GetListeGroupesInMedFile(const char * aFile); -- 2.30.2