Back to index

salome-med  6.5.0
test_porflow_driver.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 #include "MEDMEM_PorflowMeshDriver.hxx"
00023 #include "MEDMEM_Mesh.hxx"
00024 
00025 using namespace std;
00026 using namespace MEDMEM;
00027 using namespace MED_EN;
00028 
00029 int main (int argc, char ** argv)
00030 {
00031     /* process the arguments */
00032     if (argc != 2) 
00033     {
00034         cerr << "Usage : " << argv[0] 
00035         << " Porflowfilename" << endl << endl
00036         << "-> lit le fichier Porflowfilename ,crée 2 fichiers : MED et VTK" << endl;
00037         exit(-1);
00038     }
00039 
00040     string porflowfilename  = argv[1];
00041 
00042     // Construction des noms de fichier
00043     const string ext=".inp";
00044     string::size_type pos=porflowfilename.find(ext,0);
00045     string basename (porflowfilename, 0, pos); // nom sans extension
00046     string medfile=basename+".med"; // nom fichier med à creer
00047     string vtkfile=basename+".vtk"; // nom fichier vtk à creer
00048     string::size_type pos1=porflowfilename.rfind('/');
00049     string meshName (porflowfilename,pos1+1,pos-pos1-1); //get rid of directory & extension
00050     cout << meshName << endl;
00051 
00052     // lecture du fichier porflow
00053     MESH * myMesh= new MESH; 
00054     PORFLOW_MESH_RDONLY_DRIVER myPorflowMeshDriver(porflowfilename, myMesh) ;
00055     myPorflowMeshDriver.open() ;
00056     myPorflowMeshDriver.read() ;
00057     myPorflowMeshDriver.close() ;
00058     
00059     cout << "Impression de MESH : " << endl;
00060     cout << *myMesh;
00061 
00062     // creation d'un fichier med
00063     cout << "creation d'un fichier med : " << endl;
00064     int idMed = myMesh->addDriver(MED_DRIVER, medfile, meshName);
00065     myMesh->write(idMed) ;
00066 
00067     // creation d'un fichier vtk
00068     cout << "creation d'un fichier vtk : " << endl;
00069     int idVtk = myMesh->addDriver(VTK_DRIVER, vtkfile, meshName);
00070     myMesh->write(idVtk) ;
00071 
00072 
00073     int SpaceDimension = myMesh->getSpaceDimension() ;
00074     int MeshDimension  = myMesh->getMeshDimension() ;
00075     int NumberOfNodes  = myMesh->getNumberOfNodes() ;
00076 
00077     cout << "Space Dimension : " << SpaceDimension << endl << endl ; 
00078 
00079     cout << "Mesh Dimension : " << MeshDimension << endl << endl ; 
00080 
00081     const double * Coordinates = myMesh->getCoordinates(MED_FULL_INTERLACE) ;
00082 
00083     cout << "Show Nodes Coordinates : " << endl ;
00084 
00085     cout << "Name :" << endl ;
00086     const string * CoordinatesNames = myMesh->getCoordinatesNames() ;
00087     for(int i=0; i<SpaceDimension ; i++) {
00088       cout << " - " << CoordinatesNames[i] << endl ;
00089     }
00090     cout << "Unit :" << endl ;
00091     const string * CoordinatesUnits = myMesh->getCoordinatesUnits() ;
00092     for(int i=0; i<SpaceDimension ; i++) {
00093       cout << " - " << CoordinatesUnits[i] << endl ;
00094     }
00095     for(int i=0; i<NumberOfNodes ; i++) {
00096       cout << "Nodes " << i+1 << " : " ;
00097       for (int j=0; j<SpaceDimension ; j++)
00098         cout << Coordinates[i*SpaceDimension+j] << " " ;
00099       cout << endl ;
00100     }
00101 
00102     cout << "The END" << endl;
00103     myMesh->removeReference();
00104 
00105     // remontée du fichier med en mémoire
00106     myMesh= new MESH(MED_DRIVER,medfile,meshName);
00107     myMesh->removeReference();
00108 
00109 }