Back to index

salome-med  6.5.0
test_copie_field_.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 /* Programme de test du constructeur de copies de la classe FIELD_ de MEDMEM
00023    jroy - 12/12/2002 */
00024 
00025 #include "MEDMEM_Exception.hxx"
00026 #include "MEDMEM_Mesh.hxx"
00027 #include "MEDMEM_Family.hxx"
00028 #include "MEDMEM_Group.hxx"
00029 
00030 #include "MEDMEM_MedMeshDriver.hxx"
00031 #include "MEDMEM_MedFieldDriver.hxx"
00032 #include "MEDMEM_Support.hxx"
00033 #include "MEDMEM_Field.hxx"
00034 #include "MEDMEM_define.hxx"
00035 
00036 #include<string>
00037 
00038 #include <math.h>
00039 #include <stdlib.h>
00040 
00041 
00042 using namespace MEDMEM;
00043 using namespace MED_EN;
00044 
00045 
00046 static void affiche_field(FIELD_ * myField, const SUPPORT * mySupport)
00047 {
00048   cout << "Field "<< myField->getName() << " : " <<myField->getDescription() <<  endl ;
00049   int NumberOfComponents = myField->getNumberOfComponents() ;
00050   cout << "- Nombre de composantes : "<< NumberOfComponents << endl ;
00051   for (int i=1; i<NumberOfComponents+1; i++)
00052     {
00053       cout << "  - composante "<<i<<" :"<<endl ;
00054       cout << "      - nom         : "<<myField->getComponentName(i)<< endl;
00055       cout << "      - description : "<<myField->getComponentDescription(i) << endl;
00056       cout << "      - units       : "<<myField->getMEDComponentUnit(i) << endl;
00057     }
00058   cout << "- iteration :" << endl ;
00059   cout << "    - numero : " << myField->getIterationNumber()<< endl  ;
00060   cout << "    - ordre  : " << myField->getOrderNumber()<< endl  ;
00061   cout << "    - temps  : " << myField->getTime()<< endl  ;
00062 
00063   cout << "- Type : " << myField->getValueType()<< endl;
00064   /*
00065     cout << "- Valeurs :"<<endl;
00066     int NumberOf = mySupport->getNumberOfElements(MED_ALL_ELEMENTS);
00067 
00068     for (int i=1; i<NumberOf+1; i++) 
00069     {
00070     double * value = myField->getValueI(MED_FULL_INTERLACE,i) ;
00071     for (int j=0; j<NumberOfComponents; j++)
00072     cout << value[j]<< " ";
00073     cout<<endl;
00074     }
00075   */
00076   cout << "- Adresse support : " << mySupport << endl;
00077 }
00078 
00079 
00080 int main (int argc, char ** argv)
00081 {
00082   if ((argc !=3) && (argc != 4))
00083     {
00084       cerr << "Usage : " << argv[0] 
00085            << " filename meshname fieldname" << endl << endl;
00086       exit(-1);
00087     }
00088 
00089   string filename = argv[1] ;
00090   string meshname = argv[2] ;
00091 
00092   MESH * myMesh= new MESH(MED_DRIVER,filename,meshname) ;
00093 
00094   // read field :
00095 
00096   if (argc != 4) exit(0) ;
00097   // else we have a field !
00098 
00099   string fieldname = argv[3];
00100 
00101 
00102   const SUPPORT * mySupport = myMesh->getSupportOnAll(MED_EN::MED_CELL);
00103   FIELD<double> * myField = new FIELD<double>() ;
00104 
00105   myField->setName(fieldname);
00106   myField->setSupport(mySupport);
00107   MED_FIELD_RDONLY_DRIVER<double> myFieldDriver(filename,myField) ;
00108   myFieldDriver.setFieldName(fieldname);
00109   myFieldDriver.open() ;
00110 
00111   try
00112     {
00113       myFieldDriver.read() ;
00114     }
00115   catch (...)
00116     {
00117       myField->setSupport(0);
00118       mySupport = myMesh->getSupportOnAll(MED_EN::MED_NODE);
00119       myField->setSupport(mySupport);
00120       try
00121         {
00122           myFieldDriver.read() ;
00123         }
00124       catch (...)
00125         {
00126           cout << "Field " << fieldname << " not found !!!" << endl ;
00127           exit (-1) ;
00128         }
00129     }
00130 
00131   myFieldDriver.close() ;
00132 
00133   FIELD_ * pt_field_ = myField;
00134   affiche_field(pt_field_, mySupport);
00135   FIELD_ * pt_field_2 = new FIELD_(* pt_field_);
00136   myField->removeReference();
00137   affiche_field(pt_field_2, pt_field_2->getSupport());
00138 
00139   pt_field_2->removeReference();
00140   myMesh->removeReference() ;
00141 
00142   return 0;
00143 }