1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SALOME HDFPersist : implementation of HDF persitent ( save/ restore )
36 HDFdataset *hdf_dataset1;
42 system("rm ascii_hdf.txt");
46 // a new HDFfile object
47 hdf_file = new HDFfile("file_ascii.hdf");
48 MESSAGE( ">> A HDFfile object is created" );
50 hdf_file->OpenOnDisk(HDF_RDONLY);
51 MESSAGE( ">> The HDF file is opened on Disk with HDF_RDONLY access mode" )
53 hdf_group = new HDFgroup("ASCII GROUP",hdf_file);
54 MESSAGE(">> A new HDF group object ASCII GROUP" << " is created in memory")
56 hdf_group->OpenOnDisk();
57 MESSAGE( ">> The group ASCII GROUP is opened on disk" );
59 // The dataset object 'ASCII DATASET'
60 hdf_dataset1 = new HDFdataset("ASCII DATASET",hdf_group);
61 MESSAGE( ">> The dataset object 'ASCII DATASET' is created in memory " );
63 hdf_dataset1->OpenOnDisk();
64 MESSAGE( ">> The dataset object 'ASCII DATASET' is opened on disk " );
66 size = (size_t) hdf_dataset1->GetSize();
68 // Open the target file
70 if ( (fd = open("ascii_hdf.txt",O_RDWR|O_CREAT,00666)) <0) {
71 perror("open : test9");
75 // if ( (pos = lseek(fd,(off_t) size-3,SEEK_SET)) <0) {
76 // perror("lseek : test9");
80 // if ( write(fd,"END",3) <0) {
81 // perror("write : test9");
85 #ifdef _POSIX_MAPPED_FILES
86 // Map le fichier en mémoire
87 // if ((buffer = (char *) mmap(0,size,PROT_WRITE,MAP_SHARED,fd,0)) == MAP_FAILED ) {
88 // perror("mmap : test9");
91 buffer = new char[size];
93 // Sort de la compilation
94 #error Necessite l''utilisation de la primitive mmap
97 // Transfert les informations dans le fichier destination
98 hdf_dataset1->ReadFromDisk(buffer);
100 if ( write(fd,buffer,size) <0) {
101 perror("write : test9");
105 // Desalloue le mapping
106 // if (munmap(buffer,size) < 0 ) {
107 // perror("munmap : test9");
111 // Close the target file
113 perror("close : test9");
117 hdf_dataset1->CloseOnDisk();
118 MESSAGE( ">> The dataset is closed on disk " );
120 hdf_group->CloseOnDisk();
121 MESSAGE( ">> The group is closed on file" );
123 hdf_file->CloseOnDisk();
124 MESSAGE( ">> The HDF file is closed on Disk" )
131 MESSAGE( ">> MEMORY CLEAN : all HDF objects have been deleted" );
134 catch (HDFexception) {
136 MESSAGE( "!!! HDFexception !!! " )