Back to index

salome-kernel  6.5.0
test3.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 //  SALOME HDFPersist : implementation of HDF persitent ( save/ restore )
00024 //  File   : test3.cxx
00025 //  Module : SALOME
00026 //
00027 #include <iostream.h>
00028 #include "HDFOI.hxx"
00029 #include <stdlib.h>
00030 
00031 
00032 int main()
00033 {
00034   HDFfile *hdf_file;
00035   HDFgroup *hdf_group;
00036   HDFdataset *hdf_dataset;
00037   HDFdataset *hdf_dataset2;
00038   HDFattribute *hdf_attribute;
00039   hdf_size size[1];
00040   hdf_float64 coordinates[3] = {5.,-6.9,4.2};
00041   hdf_int32 unit[3] = {0,0,0};
00042   char message[HDF_NAME_MAX_LEN+1] = "MESSAGE";
00043   hdf_int32 attribute = 3;
00044   HDFexplorer *explorer;
00045   HDFinternalObject *object;
00046 
00047   system("rm file_test3.hdf");
00048 
00049   try
00050     {
00051       // a new HDFfile object
00052       hdf_file = new HDFfile("file_test3.hdf");
00053       MESSAGE( ">> A HDFfile object is created" );
00054       
00055       hdf_file->CreateOnDisk();
00056       MESSAGE( ">> The HDF file is created on Disk " );
00057 
00058       // Inside the HDF file 
00059 
00060       // A new HDF group object
00061       hdf_group = new HDFgroup("MESH",hdf_file);
00062       MESSAGE( ">> A HDFgroup object 'MESH' is created" );
00063 
00064       hdf_group->CreateOnDisk();
00065       MESSAGE( ">> The HDF group is created on Disk " );
00066 
00067       // Inside the HDF group  
00068       
00069       // A new HDF dataset object
00070       // size of each dimension, only one in the example
00071       size[0] = 3;
00072       hdf_dataset = new HDFdataset("COORDINATES",hdf_group,HDF_FLOAT64,size,1);
00073       MESSAGE( ">> A HDFdataset object 'COORDINATES' is created" );
00074 
00075       hdf_dataset->CreateOnDisk();
00076       MESSAGE( ">> The HDF dataset is created on Disk " );
00077 
00078       // a HDFattribute object inside the dataset
00079       hdf_attribute = new HDFattribute("ATTRIBUTE",hdf_dataset,HDF_INT32);
00080       MESSAGE( ">> A HDF attribute  object is created for the dataset " );
00081 
00082       hdf_dataset->WriteOnDisk(coordinates);
00083       MESSAGE( ">> The HDF dataset is written on Disk " );
00084 
00085       hdf_attribute->CreateOnDisk();
00086       MESSAGE( ">> The HDF attribute is created on Disk " );
00087 
00088       hdf_attribute->WriteOnDisk(&attribute); 
00089       MESSAGE( ">> The HDF attribute is written on Disk " );
00090       
00091       hdf_attribute->CloseOnDisk();
00092       MESSAGE( ">> The HDF attribute closed on Disk " );  
00093 
00094       hdf_dataset->CloseOnDisk();
00095       MESSAGE( ">> The HDF dataset is closed on Disk " );
00096 
00097       // A new dataset is created
00098       size[0] = 3;
00099       hdf_dataset2 = new HDFdataset("UNIT",hdf_group,HDF_INT32,size,1);
00100       MESSAGE( ">> A second HDFdataset object 'UNIT' is created" );
00101 
00102       hdf_dataset2->CreateOnDisk();
00103       MESSAGE( ">> The HDF dataset is created on Disk " );
00104 
00105       hdf_dataset2->WriteOnDisk(unit);
00106       MESSAGE( ">> The HDF dataset is written on Disk " );
00107 
00108       hdf_dataset2->CloseOnDisk();
00109       MESSAGE( ">> The HDF dataset is closed on Disk " );
00110 
00111       // The HDF group is built, it can be closed
00112       hdf_group->CloseOnDisk();
00113       MESSAGE( ">> The HDF group is closed on Disk " );
00114 
00115       // The HDF file is built, it can be closed
00116       hdf_file->CloseOnDisk();
00117       MESSAGE( ">> The HDF file is closed on disk" );
00118 
00119       // Explorer
00120       explorer = new HDFexplorer(hdf_file);
00121       MESSAGE( ">> A HDF explorer object is created" );
00122 
00123       MESSAGE( ">> File Exploration " );
00124       for (explorer->Init();explorer->More();explorer->Next())
00125         {
00126           object = explorer->Value();
00127           MESSAGE( "--> Name of the object : " << object->GetName() );
00128           switch (object->GetObjectType())
00129             {
00130             case HDF_FILE :
00131               MESSAGE( "--> Type of the object : HDF_FILE : " );
00132               break;
00133 
00134             case HDF_GROUP :
00135               MESSAGE( "--> Type of the object : HDF_GROUP : " );
00136               break;
00137 
00138             case HDF_DATASET :
00139               MESSAGE( "--> Type of the object : HDF_DATASET : " );
00140               break;
00141 
00142             default :
00143               MESSAGE( "--> PANIC !!! : " ); 
00144             }
00145         }
00146       
00147       MESSAGE( ">> Group exploration" );
00148       explorer->Reset(hdf_group); 
00149       for (explorer->Init();explorer->More();explorer->Next())
00150         {
00151           object = explorer->Value();
00152           MESSAGE( "--> Name of the object : " << object->GetName() );
00153           switch (object->GetObjectType())
00154             {
00155             case HDF_FILE :
00156               MESSAGE( "--> Type of the object : HDF_FILE : " );
00157               break;
00158 
00159             case HDF_GROUP :
00160               MESSAGE( "--> Type of the object : HDF_GROUP : " );
00161               break;
00162 
00163             case HDF_DATASET :
00164               MESSAGE( "--> Type of the object : HDF_DATASET : " );
00165               break;
00166 
00167             default :
00168               MESSAGE( "--> !!! PANIC !!! : " );
00169             }
00170         }      
00171       
00172       // memory clean
00173       MESSAGE( ">> MEMORY CLEAN " );
00174       delete explorer;
00175       MESSAGE( ">> The HDF eplorer object is deleted" );
00176       delete hdf_attribute;
00177       MESSAGE( ">> The HDF attribute object is deleted" );     
00178       delete hdf_dataset;
00179       MESSAGE( ">> The first HDF dataset object is deleted" );
00180       delete hdf_dataset2;
00181       MESSAGE( ">> The second HDF dataset object is deleted" );
00182       delete hdf_group;
00183       MESSAGE( ">> The HDF group object is deleted" ); 
00184       delete hdf_file;
00185       MESSAGE( ">> The HDF file object is deleted" );
00186     }
00187   catch (HDFexception)
00188     {
00189       MESSAGE( "!!!! HDFexception" )
00190     }
00191 
00192   return 0;
00193 }