]> SALOME platform Git repositories - modules/med.git/blob - src/MEDWrapper/V2_1/Core/MEDattrNumEcrire.cxx
Salome HOME
Mantis issue 0021668: [CEA 564] MED2.1 to MED2.3
[modules/med.git] / src / MEDWrapper / V2_1 / Core / MEDattrNumEcrire.cxx
1 /*************************************************************************
2 * COPYRIGHT (C) 1999 - 2002  EDF R&D
3 * THIS LIBRARY IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
4 * IT UNDER THE TERMS OF THE GNU LESSER GENERAL PUBLIC LICENSE 
5 * AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION; 
6 * EITHER VERSION 2.1 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.
7 *  
8 * THIS LIBRARY IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT
9 * WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU
11 * LESSER GENERAL PUBLIC LICENSE FOR MORE DETAILS.
12 *
13 * YOU SHOULD HAVE RECEIVED A COPY OF THE GNU LESSER GENERAL PUBLIC LICENSE
14 * ALONG WITH THIS LIBRARY; IF NOT, WRITE TO THE FREE SOFTWARE FOUNDATION,
15 * INC., 59 TEMPLE PLACE, SUITE 330, BOSTON, MA 02111-1307 USA
16 *
17 *************************************************************************/
18
19
20 #include "med.hxx"
21 #include "med_outils.hxx"
22
23 /*
24  * - Nom de la fonction : _MEDattrNumEcrire
25  * - Description : ecriture d'un attribut entier
26  * - Parametres :
27  *     - pere (IN) : l'ID de l'objet HDF pere ou placer l'attribut
28  *     - type (IN) : le type du champ {MED_REEL64,MED_INT}
29  *     - nom  (IN) : le nom de l'attribut
30  *     - val  (IN) : la valeur de l'attribut
31  * - Resultat : 0 en cas de succes, -1 sinon
32  */
33
34 namespace med_2_1{
35
36 med_err 
37 _MEDattrNumEcrire(med_idt pere,med_type_champ type,char *nom,unsigned char *val, 
38                   med_mode_acces mode)
39 {
40   med_idt aid,attr;
41   med_err ret;
42   int type_hdf;
43
44   switch(type)
45     {
46     case MED_REEL64 :
47       /* 1) IA32 is LE but due to an (?HDF convertion BUG?) when using H5T_NATIVE_DOUBLE/MED_REEL64? under PCLINUX
48          the file read under SGI is incorrect
49          2) Compaq OSF/1 is LE, since we force SGI64,SUN4SOL2,HP to write double in LE even if they are BE, mips OSF/1 must be BE
50          REM  : Be careful of compatibility between MED files when changing this (med2.2)    
51                 */
52 #if defined(PCLINUX) || defined(PPRO_NT) || defined(PCLINUX64) || defined(PCLINUX64_32) || defined(OSF1)
53       type_hdf = H5T_IEEE_F64BE;
54 #else 
55       type_hdf = H5T_IEEE_F64LE;
56 #endif
57       break;
58       
59     case MED_INT :
60 #if defined(HAVE_F77INT64)
61       type_hdf = H5T_NATIVE_LONG;
62 #elif defined(PCLINUX) || defined(PCLINUX64_32)
63       /* This explicit convertion avoid a core dump between in HDF&ASTER when reading on SGI
64          a file written under a PCLINUX system (in founction H5Tconvert),
65          we don't know yet if it is an HDF bug or an ASTER one */
66       /* The problem seems to be in convertion process between INT32LE->INT32BE ? */
67       type_hdf = H5T_STD_I32BE;
68       if ((H5Tconvert(H5T_NATIVE_INT,H5T_STD_I32BE,1,(void *)val,NULL,0)) < 0) 
69           return -1;
70 #else
71       type_hdf = H5T_NATIVE_INT;
72 #endif
73       break;
74
75     default :
76       return -1;
77     }
78
79   if ((aid = H5Screate(H5S_SCALAR)) < 0)
80     return -1;
81
82   if ( ((attr = H5Aopen_name(pere,nom)) > 0) && (mode != MED_REMP) )
83     return -1;
84   else
85     if ( attr < 0)
86       if ((attr = H5Acreate(pere,nom,type_hdf,aid,H5P_DEFAULT)) < 0) return -1;  
87
88   if ((ret = H5Awrite(attr,type_hdf,val)) < 0)
89     return -1;
90
91
92   if ((ret = H5Sclose(aid)) < 0)
93     return -1;
94   if ((ret = H5Aclose(attr)) < 0)
95     return -1;
96
97 #if defined(PCLINUX) || defined(PCLINUX64_32)
98   /* This explicit convertion cancel the previous on which avoid a mysterious bug between HDF&ASTER when reading
99      a file written under a PCLINUX system, we don't know yet if it is an HDF bug or an ASTER one */  
100   if (type == MED_INT) 
101     if ((H5Tconvert(H5T_STD_I32BE,H5T_NATIVE_INT,1,(void *)val,NULL,0)) < 0) 
102       return -1;
103 #endif
104
105   return 0;
106 }
107
108 }