1 // SALOME HDFPersist : implementation of HDF persitent ( save/ restore )
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
37 HDFdataset *hdf_dataset1;
43 system("rm ascii_hdf.txt");
47 // a new HDFfile object
48 hdf_file = new HDFfile("file_ascii.hdf");
49 MESSAGE( ">> A HDFfile object is created" );
51 hdf_file->OpenOnDisk(HDF_RDONLY);
52 MESSAGE( ">> The HDF file is opened on Disk with HDF_RDONLY access mode" )
54 hdf_group = new HDFgroup("ASCII GROUP",hdf_file);
55 MESSAGE(">> A new HDF group object ASCII GROUP" << " is created in memory")
57 hdf_group->OpenOnDisk();
58 MESSAGE( ">> The group ASCII GROUP is opened on disk" );
60 // The dataset object 'ASCII DATASET'
61 hdf_dataset1 = new HDFdataset("ASCII DATASET",hdf_group);
62 MESSAGE( ">> The dataset object 'ASCII DATASET' is created in memory " );
64 hdf_dataset1->OpenOnDisk();
65 MESSAGE( ">> The dataset object 'ASCII DATASET' is opened on disk " );
67 size = (size_t) hdf_dataset1->GetSize();
69 // Open the target file
71 if ( (fd = open("ascii_hdf.txt",O_RDWR|O_CREAT,00666)) <0) {
72 perror("open : test9");
76 // if ( (pos = lseek(fd,(off_t) size-3,SEEK_SET)) <0) {
77 // perror("lseek : test9");
81 // if ( write(fd,"END",3) <0) {
82 // perror("write : test9");
86 #ifdef _POSIX_MAPPED_FILES
87 // Map le fichier en mémoire
88 // if ((buffer = (char *) mmap(0,size,PROT_WRITE,MAP_SHARED,fd,0)) == MAP_FAILED ) {
89 // perror("mmap : test9");
92 buffer = new char[size];
94 // Sort de la compilation
95 #error Necessite l''utilisation de la primitive mmap
98 // Transfert les informations dans le fichier destination
99 hdf_dataset1->ReadFromDisk(buffer);
101 if ( write(fd,buffer,size) <0) {
102 perror("write : test9");
106 // Desalloue le mapping
107 // if (munmap(buffer,size) < 0 ) {
108 // perror("munmap : test9");
112 // Close the target file
114 perror("close : test9");
118 hdf_dataset1->CloseOnDisk();
119 MESSAGE( ">> The dataset is closed on disk " );
121 hdf_group->CloseOnDisk();
122 MESSAGE( ">> The group is closed on file" );
124 hdf_file->CloseOnDisk();
125 MESSAGE( ">> The HDF file is closed on Disk" )
132 MESSAGE( ">> MEMORY CLEAN : all HDF objects have been deleted" );
135 catch (HDFexception) {
137 MESSAGE( "!!! HDFexception !!! " )