Back to index

salome-kernel  6.5.0
test4.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   : test4.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_dataset1, *hdf_dataset2;
00037   int n,i;
00038   char name[HDF_NAME_MAX_LEN+1];
00039   hdf_object_type type;
00040   hdf_type data_type;
00041   int ndim, size;
00042   hdf_size *dim;
00043   hdf_float64 *val1;
00044   hdf_int32 *val2;
00045 
00046   try  
00047     {
00048       // a new HDFfile object
00049       hdf_file = new HDFfile("file_test3.hdf");
00050       MESSAGE( ">> A HDFfile object is created" );
00051       
00052       hdf_file->OpenOnDisk(HDF_RDONLY);
00053       MESSAGE(">> The HDF file is opened on Disk with HDF_RDONLY access mode") 
00054       // It is possible to read the name of all (objects) sons in the file
00055       n = hdf_file->nInternalObjects(); 
00056       for (i=0;i<n;i++) 
00057         {
00058           hdf_file->InternalObjectIndentify(i,name);
00059           MESSAGE( "--> First Level Internal Object Name : " << name );
00060         }   
00061 
00062       // Or it is possible to ask if an object is in the file
00063       if (hdf_file->ExistInternalObject("MESH"))
00064           MESSAGE( "--> The object naming 'MESH' is in the file " );
00065 
00066       // it is possible to determine the type of an object
00067       type = hdf_file->InternalObjectType("MESH");
00068       switch (type)
00069         {
00070         case HDF_GROUP :
00071           MESSAGE( "--> Its type is HDF_GROUP" );
00072           break;
00073           
00074         case HDF_DATASET :
00075           MESSAGE( "--> Its type is HDF_DATASET" );
00076           break;
00077           
00078         default :
00079           MESSAGE( "--> !!!! PANIC !!!" );
00080         }
00081 
00082       hdf_group = new HDFgroup(name,hdf_file); 
00083       MESSAGE( ">> A new HDF group object " << name << " is created in memory")
00084 
00085       hdf_group->OpenOnDisk();
00086       MESSAGE( ">> The group " << name << " is opened on disk" );
00087  
00088       // object inside the group ?
00089       n = hdf_group->nInternalObjects();  
00090       MESSAGE( ">> There are " << n << " objects in this group " );
00091       for (i=0;i<n;i++)     
00092         {
00093           hdf_group->InternalObjectIndentify(i,name);
00094           type = hdf_group->InternalObjectType(name);
00095           MESSAGE( "--> First Level Internal Object Name : " << name );
00096           switch (type)
00097             {
00098             case HDF_GROUP :
00099               MESSAGE( "--> Its type is HDF_GROUP" );
00100               break;
00101               
00102             case HDF_DATASET :
00103               MESSAGE( "--> Its type is HDF_DATASET" );
00104               break;
00105               
00106             default :
00107               MESSAGE( "--> !!!! PANIC !!!" );
00108             }
00109         } 
00110 
00111       // The first dataset object 'COORDINATES'
00112       hdf_dataset1 = new HDFdataset("COORDINATES",hdf_group);
00113       MESSAGE( ">> The dataset object 'COORDINATES' is created in memory " );
00114 
00115       hdf_dataset1->OpenOnDisk();
00116       MESSAGE( ">> The dataset object 'COORDINATES' is opened on disk " );
00117 
00118       data_type = hdf_dataset1->GetType();
00119       switch(data_type)
00120         {
00121         case HDF_INT32 :
00122           MESSAGE( "--> Type of data : HDF_INT32 " );
00123           break; 
00124         case HDF_INT64 :
00125           MESSAGE( "--> Type of data : HDF_INT64 " );
00126           break; 
00127         case HDF_FLOAT64 :
00128           MESSAGE( "--> Type of data : HDF_FLOAT64 " );
00129           break;
00130         default :
00131           MESSAGE( "--> Type of data : HDF_STRING " );
00132         }
00133  
00134       ndim = hdf_dataset1->nDim();
00135       MESSAGE( "--> Number of dimensions : " << ndim );
00136 
00137       dim = new hdf_size[ndim];
00138       hdf_dataset1->GetDim(dim);
00139       for (i=0;i<ndim;i++)
00140         MESSAGE( "--> Dimension " << i+1 << " of size : " << dim[i] );
00141       delete dim;
00142 
00143       size = hdf_dataset1->GetSize();
00144       val1 = new hdf_float64[size];
00145       hdf_dataset1->ReadFromDisk(val1);
00146       MESSAGE( "--> The values are : ");
00147       for (i=0;i<size;i++)
00148         MESSAGE( " " << val1[i]);
00149       MESSAGE();
00150       delete val1;
00151 
00152       hdf_dataset1->CloseOnDisk();
00153       MESSAGE( ">> The dataset object 'COORDINATES' is closed on disk " );
00154 
00155       // The second dataset 'UNIT'
00156       hdf_dataset2 = new HDFdataset("UNIT",hdf_group);
00157       MESSAGE( ">> The dataset object 'UNIT' is created in memory " );
00158 
00159       hdf_dataset2->OpenOnDisk();
00160       MESSAGE( ">> The dataset object 'UNIT' is opened on disk " );
00161 
00162       data_type = hdf_dataset2->GetType();
00163       switch(data_type)
00164         {
00165         case HDF_INT32 :
00166           MESSAGE( "--> Type of data : HDF_INT32 " );
00167           break;
00168         case HDF_INT64 :
00169           MESSAGE( "--> Type of data : HDF_INT64 " );
00170           break;
00171         case HDF_FLOAT64 :
00172           MESSAGE( "--> Type of data : HDF_FLOAT64 " );
00173           break;
00174         default :
00175           MESSAGE( "--> Type of data : HDF_STRING " );
00176         }
00177 
00178       ndim = hdf_dataset2->nDim();
00179       MESSAGE( "--> Number of dimensions : " << ndim );
00180 
00181       dim = new hdf_size[ndim];
00182       hdf_dataset2->GetDim(dim);
00183       for (i=0;i<ndim;i++)
00184         MESSAGE( "--> Dimension " << i+1 << " of size : " << dim[i] );
00185       delete dim;
00186 
00187       size = hdf_dataset2->GetSize();
00188       val2 = new hdf_int32[size];
00189       hdf_dataset2->ReadFromDisk(val2);
00190       MESSAGE( "--> The values are : ");
00191       for (i=0;i<size;i++)
00192         MESSAGE( " " << val2[i]);
00193       MESSAGE();
00194       delete val2;
00195 
00196       hdf_dataset2->CloseOnDisk();
00197       MESSAGE( ">> The dataset object 'UNIT' is closed on disk " );
00198       
00199       hdf_group->CloseOnDisk();
00200       MESSAGE( ">> The group is closed on file" );
00201       
00202       hdf_file->CloseOnDisk();
00203       MESSAGE(">> The HDF file is closed on Disk" )      
00204       
00205       // Memory clean
00206       delete hdf_dataset1;
00207       delete hdf_dataset2;
00208       delete hdf_group;
00209       delete hdf_file;
00210       MESSAGE( ">> MEMORY CLEAN : all HDF objects have been deleted" );
00211     }
00212   catch (HDFexception)
00213     {
00214       MESSAGE( "!!! HDFexception !!! " )
00215     }  
00216   
00217   return 0;
00218 }