Back to index

salome-med  6.5.0
MEDattrNumEcrire.cxx
Go to the documentation of this file.
00001 /*************************************************************************
00002 * COPYRIGHT (C) 1999 - 2002  EDF R&D
00003 * THIS LIBRARY IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
00004 * IT UNDER THE TERMS OF THE GNU LESSER GENERAL PUBLIC LICENSE 
00005 * AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION; 
00006 * EITHER VERSION 2.1 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.
00007 *  
00008 * THIS LIBRARY IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT
00009 * WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
00010 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU
00011 * LESSER GENERAL PUBLIC LICENSE FOR MORE DETAILS.
00012 *
00013 * YOU SHOULD HAVE RECEIVED A COPY OF THE GNU LESSER GENERAL PUBLIC LICENSE
00014 * ALONG WITH THIS LIBRARY; IF NOT, WRITE TO THE FREE SOFTWARE FOUNDATION,
00015 * INC., 59 TEMPLE PLACE, SUITE 330, BOSTON, MA 02111-1307 USA
00016 *
00017 *************************************************************************/
00018 
00019 
00020 #include "med.hxx"
00021 #include "med_outils.hxx"
00022 
00023 /*
00024  * - Nom de la fonction : _MEDattrNumEcrire
00025  * - Description : ecriture d'un attribut entier
00026  * - Parametres :
00027  *     - pere (IN) : l'ID de l'objet HDF pere ou placer l'attribut
00028  *     - type (IN) : le type du champ {MED_REEL64,MED_INT}
00029  *     - nom  (IN) : le nom de l'attribut
00030  *     - val  (IN) : la valeur de l'attribut
00031  * - Resultat : 0 en cas de succes, -1 sinon
00032  */
00033 
00034 namespace med_2_1{
00035 
00036 med_err 
00037 _MEDattrNumEcrire(med_idt pere,med_type_champ type,char *nom,unsigned char *val, 
00038                   med_mode_acces mode)
00039 {
00040   med_idt aid,attr;
00041   med_err ret;
00042   int type_hdf;
00043 
00044   switch(type)
00045     {
00046     case MED_REEL64 :
00047       /* 1) IA32 is LE but due to an (?HDF convertion BUG?) when using H5T_NATIVE_DOUBLE/MED_REEL64? under PCLINUX
00048          the file read under SGI is incorrect
00049          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
00050          REM  : Be careful of compatibility between MED files when changing this (med2.2)    
00051                 */
00052 #if defined(PCLINUX) || defined(PPRO_NT) || defined(PCLINUX64) || defined(PCLINUX64_32) || defined(OSF1)
00053       type_hdf = H5T_IEEE_F64BE;
00054 #else 
00055       type_hdf = H5T_IEEE_F64LE;
00056 #endif
00057       break;
00058       
00059     case MED_INT :
00060 #if defined(HAVE_F77INT64)
00061       type_hdf = H5T_NATIVE_LONG;
00062 #elif defined(PCLINUX) || defined(PCLINUX64_32)
00063       /* This explicit convertion avoid a core dump between in HDF&ASTER when reading on SGI
00064          a file written under a PCLINUX system (in founction H5Tconvert),
00065          we don't know yet if it is an HDF bug or an ASTER one */
00066       /* The problem seems to be in convertion process between INT32LE->INT32BE ? */
00067       type_hdf = H5T_STD_I32BE;
00068       if ((H5Tconvert(H5T_NATIVE_INT,H5T_STD_I32BE,1,(void *)val,NULL,0)) < 0) 
00069           return -1;
00070 #else
00071       type_hdf = H5T_NATIVE_INT;
00072 #endif
00073       break;
00074 
00075     default :
00076       return -1;
00077     }
00078 
00079   if ((aid = H5Screate(H5S_SCALAR)) < 0)
00080     return -1;
00081 
00082   if ( ((attr = H5Aopen_name(pere,nom)) > 0) && (mode != MED_REMP) )
00083     return -1;
00084   else
00085     if ( attr < 0)
00086       if ((attr = H5Acreate(pere,nom,type_hdf,aid,H5P_DEFAULT)) < 0) return -1;  
00087 
00088   if ((ret = H5Awrite(attr,type_hdf,val)) < 0)
00089     return -1;
00090 
00091 
00092   if ((ret = H5Sclose(aid)) < 0)
00093     return -1;
00094   if ((ret = H5Aclose(attr)) < 0)
00095     return -1;
00096 
00097 #if defined(PCLINUX) || defined(PCLINUX64_32)
00098   /* This explicit convertion cancel the previous on which avoid a mysterious bug between HDF&ASTER when reading
00099      a file written under a PCLINUX system, we don't know yet if it is an HDF bug or an ASTER one */  
00100   if (type == MED_INT) 
00101     if ((H5Tconvert(H5T_STD_I32BE,H5T_NATIVE_INT,1,(void *)val,NULL,0)) < 0) 
00102       return -1;
00103 #endif
00104 
00105   return 0;
00106 }
00107 
00108 }