Back to index

salome-med  6.5.0
testAnalFile.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 
00023 #include <string>
00024 #include <deque>
00025 #include <iostream>
00026 #include "MEDMEM_MedFileBrowser.hxx"
00027 #include "MEDMEM_MedMeshDriver.hxx"
00028 #include "MEDMEM_Mesh.hxx"
00029 #include "MEDMEM_Field.hxx"
00030 #include "MEDMEM_DriverFactory.hxx"
00031 
00032 using namespace std;
00033 using namespace MEDMEM;
00034 using namespace MED_EN;
00035 
00036 int main(int argc, char *argv[])
00037 {
00038   if (argc !=2)
00039     {
00040       cerr << "Usage : " << argv[0] 
00041            << " fileName.med where fileName.med should be a med file" << endl;
00042       cerr << "        It will then generate med file fileNameAnal.med" << endl << endl;
00043       exit(-1);
00044     }
00045 
00046   int i;
00047   // This test program is more or less designed to work with file TimeStamps.med
00048   // If you want to use it for other Med files, you have to alter the mounting in memory of the fields f1 and f2
00049   //string fileIn="/export/home/geay32/SALOME225/KERNEL_SRC/examples/TimeStamps.med";
00050 
00051   string fileIn = argv[1] ;
00052   const string ext=".med";
00053   string::size_type pos=fileIn.find(ext,0);
00054   string baseName (fileIn, 0, pos); // nom sans extension
00055   string fileOut=baseName + "Anal_V22.med";
00056 
00057   MEDFILEBROWSER *myMed=new MEDFILEBROWSER(fileIn);
00058   int nbOfMeshes=myMed->getNumberOfMeshes();
00059   int nbOfFields=myMed->getNumberOfFields();
00060   cout << nbOfMeshes << " --- " << nbOfFields << endl;
00061   vector<string> names=myMed->getMeshNames();
00062   for(i=0;i<nbOfMeshes;i++)
00063     cout << names[i] << endl;
00064   cout << "************* " << endl;
00065   vector<string> names2=myMed->getFieldNames();
00066   for(i=0;i<nbOfFields;i++)
00067     cout << names2[i] << endl;
00068   MESH *mesh=new MESH(MED_DRIVER,fileIn,names[0]);
00069   vector<DT_IT_> iterations=myMed->getFieldIteration(names2[2]);
00070   cout << iterations.size() << endl;
00071   FIELD<double> *f1s=new FIELD<double>(MED_DRIVER,fileIn,names2[2],
00072                                        iterations[0].dt,iterations[0].it,mesh);
00073   FIELD<double> *f2s=new FIELD<double>(MED_DRIVER,fileIn,names2[2],
00074                                        iterations[1].dt,iterations[1].it,mesh);
00075   int id=mesh->addDriver(MED_DRIVER,fileOut,mesh->getName());
00076   mesh->write(id);
00077   id=f1s->addDriver(MED_DRIVER, fileOut, f1s->getName());
00078   f1s->write(id);
00079   id=f2s->addDriver(MED_DRIVER, fileOut, f2s->getName());
00080   f2s->write(id);
00081 
00082   f1s->removeReference();
00083   f2s->removeReference();
00084   mesh->removeReference();
00085   delete myMed;
00086   return 0;
00087 }
00088