Back to index

salome-med  6.5.0
readCoordinate.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 //  File   : readCoordinate.cxx
00021 //  Module : MED
00022 //
00023 #include<string>
00024 #include "MEDMEM_Exception.hxx"
00025 #include "MEDMEM_define.hxx"
00026 #include "MEDMEM_Mesh.hxx"
00027 #include "MEDMEM_MedMeshDriver.hxx"
00028 
00029 using namespace std;
00030 using namespace MEDMEM;
00031 
00032 #define MED_TAILLE_PNOM  16
00033 
00034 static void usage(char * name)
00035 {
00036   cout << "    " << name <<" <file name>"<< " <mesh name> " << " <interlace mode>" << endl;
00037   cout << "    " << "displays all Nodes Coordinates in mdump mode" << endl;
00038   cout << endl;
00039   cout << "    " << "mesh name is mandatory. Try mdump if necessary" << endl;
00040   cout << "    " << "values for interlace mode are  : " << endl;
00041   cout << "    " << "MED_FULL_INTERLACE (default value) or MED_NO_INTERLACE" << endl;
00042   exit(-1);
00043 }
00044 
00045 int main (int argc, char ** argv) {
00046   
00047   if (argc < 3) usage(argv[0]);
00048   if (argc > 4) usage(argv[0]);
00049 
00050   string fileName = argv[1];
00051   string meshName = argv[2];
00052 
00053   MED_EN::medModeSwitch Mode = MED_EN::MED_FULL_INTERLACE;
00054   if (argc==4)
00055   {
00056         string comp=argv[3];
00057         if ( comp == "MED_NO_INTERLACE" ) Mode = MED_EN::MED_NO_INTERLACE;
00058         else if ( comp != "MED_FULL_INTERLACE") usage(argv[0]);
00059   }
00060 
00061 
00062   MESH * myMesh= new MESH;
00063   myMesh->setName(meshName);
00064   MED_MESH_RDONLY_DRIVER myMeshDriver(fileName,myMesh);
00065   try
00066   {
00067        myMeshDriver.setMeshName(meshName);
00068        myMeshDriver.open();
00069   }
00070   catch (const exception & ex)
00071   {
00072          MESSAGE_MED("Catch Exception : ");
00073          SCRUTE_MED(ex.what());
00074   };
00075   MESSAGE_MED("Open done");
00076 
00077   try
00078   {
00079        myMeshDriver.read();
00080   }
00081   catch (const exception & ex)
00082   {
00083          MESSAGE_MED("Catch Exception : ");
00084          SCRUTE_MED(ex.what());
00085   };
00086   MESSAGE_MED("Read done");
00087   
00088   int SpaceDimension = myMesh->getSpaceDimension() ;
00089   int NumberOfNodes  = myMesh->getNumberOfNodes() ;
00090 
00091   cout << "(************************)"<<endl;
00092   cout << "(* NOEUDS DU MAILLAGE : *)"<<endl;
00093   cout << "(************************)"<<endl;
00094 
00095   string typeRepere  = myMesh->getCoordinatesSystem();
00096   if ( typeRepere.size() == 0 ) typeRepere ="0";
00097   cout << "- Type de repere des coordonnees : " << typeRepere << endl;
00098 
00099   string chainevide(MED_TAILLE_PNOM+2,' ');
00100   cout << "- Nom des coordonnees : " << endl ;
00101   const string * CoordinatesNames = myMesh->getCoordinatesNames() ;
00102   for (int i=0; i < SpaceDimension ; i++) 
00103   {
00104         string bonnelongueur=chainevide;
00105         bonnelongueur.replace(1,CoordinatesNames[i].size(),CoordinatesNames[i]);
00106         cout << bonnelongueur;
00107   }
00108   cout <<endl;
00109 
00110   cout << "- Unites des coordonnees : " << endl ;
00111   const string * CoordinatesUnits = myMesh->getCoordinatesUnits() ;
00112   for ( int i=0; i < SpaceDimension ; i++) 
00113   {
00114         string bonnelongueur=chainevide;
00115         bonnelongueur.replace(1,CoordinatesUnits[i].size(),CoordinatesUnits[i]);
00116         cout << bonnelongueur;
00117   }
00118   cout <<endl;
00119 
00120   const double * Coordinates = myMesh->getCoordinates(Mode) ;
00121   cout << "- Coordonnees des noeuds : " << endl;
00122   for (int i=0; i < SpaceDimension*NumberOfNodes; i++)
00123   {
00124         fprintf(stdout," %f ",Coordinates[i]);
00125   }
00126   cout <<endl;
00127 
00128   myMesh->removeReference();
00129 
00130 }