Back to index

salome-med  6.5.0
MEDnumEcr.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 <stdlib.h>
00023 #include <string.h>
00024 
00025 namespace med_2_1{
00026 
00027 med_err 
00028 MEDnumEcr(med_idt fid,char *maa, med_int *num, med_int n, med_mode_acces mode,
00029           med_entite_maillage type_ent,med_geometrie_element type_geo)
00030 {
00031   med_idt root, maaid, entid, geoid, dataset;
00032   med_err ret;
00033   med_size dimd[1];
00034   char chemin[MED_TAILLE_MAA+MED_TAILLE_NOM+1];
00035   char nom_ent[MED_TAILLE_NOM_ENTITE+1];
00036   char nom_geo[MED_TAILLE_NOM_ENTITE+1];
00037 
00038   /*
00039    * On inhibe le gestionnaire d'erreur HDF 5
00040    */
00041   _MEDmodeErreurVerrouiller(); 
00042 
00043   /*
00044    * Si le maillage n'existe pas => erreur
00045    */
00046   strcpy(chemin,MED_MAA);
00047   strcat(chemin,maa);
00048   if ((maaid = _MEDdatagroupOuvrir(fid,chemin)) < 0)
00049       return -1;
00050 
00051   /*
00052    * On met a jour le nom du Data Group representant
00053    * le type des entites
00054    */
00055    if ((ret = _MEDnomEntite(nom_ent,type_ent)) < 0)
00056      return -1;
00057 
00058    /*
00059     * Si le Data Group des entites n'existe pas on le cree
00060     */
00061    if ((entid = _MEDdatagroupOuvrir(maaid,nom_ent)) < 0)
00062      if ((root = _MEDdatagroupCreer(maaid,nom_ent)) < 0)
00063        return -1;
00064 
00065    /*
00066     * Pour les mailles, les faces et le aretes, on cree
00067     * s'il n'existe pas le Data Group du type geometrique
00068     */
00069    if ((type_ent==MED_MAILLE)||(type_ent==MED_FACE)||(type_ent==MED_ARETE))
00070      {
00071        if ((ret = _MEDnomGeometrie(nom_geo,type_geo)) < 0)
00072          return -1;
00073 
00074        if ((geoid = _MEDdatagroupOuvrir(entid,nom_geo)) < 0)
00075          if ((geoid = _MEDdatagroupCreer(entid,nom_geo)) < 0)
00076            return -1;
00077      }
00078    else 
00079      geoid = -1;
00080 
00081    /*
00082     * Creation du Data Set "NUM" 
00083     */
00084    if (geoid == -1)
00085      root = entid;
00086    else
00087      root = geoid;
00088    dimd[0] = n;
00089 #if defined(HAVE_F77INT64)
00090    if ((ret = _MEDdatasetNumEcrire(root,MED_NOM_NUM,MED_INT64,MED_NO_INTERLACE,MED_DIM1,MED_ALL,MED_NOPF,0,MED_NOPG,dimd,
00091                                 (unsigned char*) num,mode)) < 0)
00092      return -1;
00093 #else
00094    if ((ret = _MEDdatasetNumEcrire(root,MED_NOM_NUM,MED_INT32,MED_NO_INTERLACE,MED_DIM1,MED_ALL,MED_NOPF,0,MED_NOPG,dimd,
00095                                 (unsigned char*) num,mode)) < 0)
00096      return -1;
00097 #endif
00098 
00099   /*
00100    * Attribut NBR (nombre de noeuds)
00101    */
00102    if ((dataset = _MEDdatasetOuvrir(root,MED_NOM_NUM)) < 0)
00103      return -1;
00104    if ((ret = _MEDattrEntierEcrire(dataset,MED_NOM_NBR,&n,mode)) < 0)
00105      return -1;
00106 
00107    /*
00108     * On ferme tout
00109     */
00110    if ((ret = _MEDdatasetFermer(dataset)) < 0)
00111      return -1;
00112    if (geoid != -1)
00113      if ((ret = _MEDdatagroupFermer(geoid)) < 0)
00114        return -1;
00115    if ((ret = _MEDdatagroupFermer(entid)) < 0)
00116      return -1;
00117    if ((ret = _MEDdatagroupFermer(maaid)) < 0)
00118      return -1; 
00119 
00120   return 0; 
00121 }
00122 
00123 }