Back to index

salome-kernel  6.5.0
test1.c
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 /*----------------------------------------------------------------------------
00024 SALOME HDFPersist : implementation of HDF persitent ( save/ restore )
00025   File   : test1.c
00026   Module : SALOME
00027 ----------------------------------------------------------------------------*/
00028 
00029 #include"hdfi.h"
00030 #include<stdlib.h>
00031 
00032 #define MESSAGE(msg) printf(msg);
00033 //__FILE__,":[",__LINE__,"]: ",
00034 
00035 int main() {
00036   hdf_idt fid,gid,did,atid;
00037   hdf_err ret;
00038   hdf_size size[1];
00039   hdf_int32 data[10] = { 1,2,3,4,5,6,7,8,9,10};
00040   hdf_int32 attr_val = 2; 
00041   
00042   system("rm titi.HDF");
00043 
00044   HDFerrorModeLock();
00045   
00046   if  ((fid = HDFfileCreate("titi.HDF")) < 0)
00047     return -1;
00048   MESSAGE("Creation du fichier")
00049 
00050   if ((gid = HDFgroupCreate(fid,"GROUP")) < 0)
00051     return -1;
00052   MESSAGE("Creation d'un groupe")
00053 
00054   if ((atid = HDFattrCreate(gid,"ATTR",HDF_INT32))< 0)
00055     return -1;
00056   MESSAGE("Creation d'un attribut")
00057 
00058   if ((ret = HDFattrWrite(atid,&attr_val)) < 0)
00059     return -1;
00060   MESSAGE("Ecriture de l'attribut")
00061  
00062   if ((ret = HDFattrClose(atid))  < 0)
00063     return -1;
00064   MESSAGE("Fermeture de l'attribut")
00065 
00066   size[0] = 10;
00067   if ((did = HDFdatasetCreate(gid,"DATASET",HDF_INT32,size)) < 0)
00068     return -1;
00069   MESSAGE("Creation d'un dataset")
00070 
00071   if ((ret = HDFdatasetWrite(did,data)) < 0)
00072     return -1;
00073   MESSAGE("Ecriture du dataset")
00074 
00075   if ((ret = HDFdatasetClose(did)) < 0)
00076     return -1;
00077   MESSAGE("Fermeture du datset")
00078 
00079   if ((ret = HDFgroupClose(gid)) < 0)
00080     return -1;
00081   MESSAGE("Fermeture du groupe")
00082 
00083   if ((ret = HDFfileClose(fid)) < 0)
00084     return ret; 
00085   MESSAGE("Fermeture du fichier")
00086 
00087   if  ((fid = HDFfileCreate("toto.HDF")) < 0)
00088     return -1;
00089   MESSAGE("Creation du fichier")
00090 
00091   if ((ret = HDFfileClose(fid)) < 0)
00092     return ret; 
00093   MESSAGE("Fermeture du fichier")
00094   
00095   
00096   return 0;
00097 }