Back to index

salome-med  6.5.0
MEDfamCr.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 #include "med.hxx"
00020 #include "med_outils.hxx"
00021 
00022 #include <string.h>
00023 #include <stdlib.h>
00024 
00025 namespace med_2_1{
00026 
00027 med_err 
00028 MEDfamCr(med_idt fid,char* maa,char *famille,med_int numero, 
00029          med_int *attr_ident, med_int *attr_val, char *attr_desc, 
00030          med_int n_attr,char *groupe, med_int n_groupe)
00031 {
00032   med_idt root, datagroup, famid;
00033   med_err ret;
00034   med_size dimd[1];
00035   char chemin[MED_TAILLE_MAA+MED_TAILLE_FAS+MED_TAILLE_NOM+1];
00036   char tmp[MED_TAILLE_FAS+1];
00037 
00038   /*
00039    * On inhibe le gestionnaire d'erreur HDF 5
00040    */
00041   _MEDmodeErreurVerrouiller();
00042 
00043   /* 
00044    * Si le Data Group FAS n'existe pas, on le cree
00045    */
00046   strcpy(chemin,MED_MAA);
00047   strcat(chemin,maa);
00048   strncpy(tmp,MED_FAS,MED_TAILLE_FAS-1);
00049   tmp[MED_TAILLE_FAS-1] = '\0';
00050   strcat(chemin,tmp);
00051   if ((root = _MEDdatagroupOuvrir(fid,chemin)) < 0)
00052     if ((root = _MEDdatagroupCreer(fid,chemin)) < 0)
00053       return -1;
00054     
00055   /*
00056    * Si le Data Group de meme nom que famille existe => erreur
00057    * Sinon on le cree
00058    */
00059   if ((famid = _MEDdatagroupOuvrir(root,famille)) >= 0)
00060     return -1;
00061   if ((famid = _MEDdatagroupCreer(root,famille)) < 0)
00062     return -1;
00063 
00064   /*
00065    * L'attribut NUM
00066    */
00067   if ((ret = _MEDattrEntierEcrire(famid,MED_NOM_NUM,&numero,MED_REMP)) < 0)
00068     return -1;
00069 
00070   /*
00071    * Le Data Group "GRO"
00072    */
00073   if (n_groupe > 0)
00074     {
00075       /*
00076        * On cree le Data Group 
00077        */
00078       if ((datagroup = _MEDdatagroupCreer(famid,MED_NOM_GRO)) < 0)
00079         return -1;
00080 
00081       /*
00082        * L'attribut "NBR"
00083        */
00084       if ((ret = _MEDattrEntierEcrire(datagroup,MED_NOM_NBR,&n_groupe,MED_REMP)) < 0)
00085         return -1;
00086       
00087       /* 
00088        * Data Set des noms des groupes "NOM"
00089        */
00090       dimd[0] = n_groupe*MED_TAILLE_LNOM+1;
00091       if ((ret = _MEDdatasetStringEcrire(datagroup,MED_NOM_NOM,dimd,groupe,
00092                                       MED_REMP))<0)
00093         return -1;
00094 
00095       /* 
00096        * On ferme le Data Group
00097        */
00098       if ((ret = _MEDdatagroupFermer(datagroup)) < 0)
00099         return -1;
00100     }
00101 
00102   /*
00103    * Le Data Group "ATT"
00104    */
00105   
00106   if (n_attr > 0)
00107     {
00108       if ((datagroup = _MEDdatagroupCreer(famid,MED_NOM_ATT)) < 0)
00109         return -1;
00110 
00111       /*
00112        * L'attribut "NBR"
00113        */
00114       if ((ret = _MEDattrEntierEcrire(datagroup,MED_NOM_NBR,&n_attr,MED_REMP)) < 0)
00115         return -1;
00116       
00117       /*
00118        * Le Data Set "IDE"
00119        */
00120       dimd[0] = n_attr;
00121 #if defined(HAVE_F77INT64)
00122       if ((ret = _MEDdatasetNumEcrire(datagroup,MED_NOM_IDE,MED_INT64,MED_NO_INTERLACE,MED_DIM1,MED_ALL,MED_NOPF,0,MED_NOPG,dimd,
00123                                    (unsigned char *)attr_ident,MED_REMP)) < 0)
00124         return -1;    
00125 #else
00126       if ((ret = _MEDdatasetNumEcrire(datagroup,MED_NOM_IDE,MED_INT32,MED_NO_INTERLACE,MED_DIM1,MED_ALL,MED_NOPF,0,MED_NOPG,dimd,
00127                                    (unsigned char *)attr_ident,MED_REMP)) < 0)
00128         return -1;      
00129 #endif
00130 
00131       /*
00132        * Le Data Set "VAL"
00133        */
00134       dimd[0] = n_attr;
00135 #if defined(HAVE_F77INT64)
00136       if ((ret = _MEDdatasetNumEcrire(datagroup,MED_NOM_VAL,MED_INT64,MED_NO_INTERLACE,MED_DIM1,MED_ALL,MED_NOPF,0,MED_NOPG,dimd,
00137                                    (unsigned char*)attr_val,MED_REMP)) < 0)
00138         return -1;
00139 #else
00140       if ((ret = _MEDdatasetNumEcrire(datagroup,MED_NOM_VAL,MED_INT32,MED_NO_INTERLACE,MED_DIM1,MED_ALL,MED_NOPF,0,MED_NOPG,dimd,
00141                                    (unsigned char*)attr_val,MED_REMP)) < 0)
00142         return -1;
00143 #endif
00144 
00145       /*
00146        * Le Data Set "DES"
00147        */
00148       dimd[0] = n_attr*MED_TAILLE_DESC+1;
00149       if ((ret = _MEDdatasetStringEcrire(datagroup,MED_NOM_DES,dimd,attr_desc,
00150                                       MED_REMP)) < 0)
00151         return -1;
00152 
00153       /* 
00154        * On ferme le Data Group
00155        */
00156       if ((ret = _MEDdatagroupFermer(datagroup)) < 0)
00157         return -1;
00158     }
00159 
00160   /* 
00161    * On ferme tout
00162    */ 
00163   if ((ret = _MEDdatagroupFermer(famid)) < 0)
00164     return -1;
00165   if ((ret = _MEDdatagroupFermer(root)) < 0)
00166     return -1;
00167 
00168   return 0; 
00169 }
00170 
00171 }