1 /*  This file is part of MED.
2  *
3  *  COPYRIGHT (C) 1999 - 2019  EDF R&D, CEA/DEN
4  *  MED is free software: you can redistribute it and/or modify
5  *  it under the terms of the GNU Lesser General Public License as published by
6  *  the Free Software Foundation, either version 3 of the License, or
7  *  (at your option) any later version.
8  *
9  *  MED is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU Lesser General Public License for more details.
13  *
14  *  You should have received a copy of the GNU Lesser General Public License
15  *  along with MED.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 
19 #include <med.h>
20 #include <med_config.h>
21 #include <med_outils.h>
22 #include <hdf5.h>
23 
24 
25 /* 	  herr_t (*func)( hid_t g_id, const char *name, const H5L_info_t *info, void *op_data) ) */
26 
27 med_err
_MEDvisit(const med_idt fid,const char * const srcpath,const char * const dstpath,herr_t (* func)())28 _MEDvisit(const med_idt fid, const char * const srcpath, const char * const dstpath,
29 	  herr_t (*func)() )
30 {
31 
32   med_err    _ret=-1;
33   med_idt    _gid1=0,_gid2=0;
34   med_size   _n;
35 
36   visitordatas _data;
37 
38   med_access_mode MED_ACCESS_MODE;
39 
40   _data.srcpath=(char*)srcpath;
41   _data.dstpath=(char*)dstpath;
42 
43   if ( (MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
44     MESSAGE("Impossible de déterminer le mode d'acces au fichier ");
45     return -1;
46   }
47 
48   /*TESTER LE MODE D'ACCES: A T'ON LE DROIT D'ECRIRE*/
49 
50 
51   if ( (_gid1 = H5Gopen(fid,srcpath)) < 0 ) {
52     MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,srcpath);
53     goto ERROR;
54   }
55   _data.gid1=_gid1;
56 
57   if ( (_gid2 = H5Gopen(fid,dstpath)) < 0 ) {
58     MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,dstpath);
59     goto ERROR;
60   }
61   _data.gid2=_gid2;
62 
63 
64   if ( H5Lvisit( _gid1,H5_INDEX_NAME, H5_ITER_NATIVE, func, &_data ) < 0 ) {
65     MED_ERR_(_ret,MED_ERR_VISIT,MED_ERR_DATAGROUP,srcpath);
66     goto ERROR;
67   }
68 
69 
70   _ret = 0;
71 
72  ERROR:
73 
74   if (_gid1>0)            if ( H5Gclose(_gid1) < 0) {
75     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,srcpath);
76     ISCRUTE_id(_gid1);
77   }
78 
79   if (_gid2>0)            if ( H5Gclose(_gid2) < 0) {
80     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,dstpath);
81     ISCRUTE_id(_gid2);
82   }
83 
84   return _ret;
85 }
86