MEDnomEcr.c

Aller à la documentation de ce fichier.
00001 /*  This file is part of MED.
00002  *
00003  *  COPYRIGHT (C) 1999 - 2015  EDF R&D, CEA/DEN
00004  *  MED is free software: you can redistribute it and/or modify
00005  *  it under the terms of the GNU Lesser General Public License as published by
00006  *  the Free Software Foundation, either version 3 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  MED is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU Lesser General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU Lesser General Public License
00015  *  along with MED.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 
00019 #include <med.h>
00020 #include <med_config.h>
00021 #include <med_outils.h>
00022 
00023 #include <stdlib.h>
00024 #include <string.h>
00025 
00026 med_err 
00027 MEDnomEcr(med_idt fid,char *maa, char *nom, med_int n,
00028           med_entite_maillage type_ent,med_geometrie_element type_geo)
00029 {
00030   med_idt root, maaid, entid, geoid, dataset;
00031   med_err ret;
00032   med_size dimd[1];
00033   char chemin[MED_TAILLE_MAA+MED_TAILLE_NOM+1];
00034   char nom_ent[MED_TAILLE_NOM_ENTITE+1];
00035   char nom_geo[MED_TAILLE_NOM_ENTITE+1];
00036   med_entite_maillage _type_ent=type_ent;
00037 
00038   if ( type_ent == MED_NOEUD_MAILLE ) _type_ent=MED_NOEUD ;
00039 
00040   /*
00041    * On inhibe le gestionnaire d'erreur HDF 5
00042    */
00043   _MEDmodeErreurVerrouiller();
00044 if (MEDcheckVersion(fid) < 0) return -1;
00045 
00046 
00047   /*
00048    * Si le maillage n'existe pas => erreur
00049    */
00050   strcpy(chemin,MED_MAA);
00051   strcat(chemin,maa);
00052   if ((maaid = _MEDdatagroupOuvrir(fid,chemin)) < 0)
00053       return -1;
00054 
00055   /*
00056    * On met a jour le nom du Data Group representant
00057    * le type des entites
00058    */
00059    if ((ret = _MEDnomEntite(nom_ent,_type_ent)) < 0)
00060      return -1;
00061 
00062    /*
00063     * Si le Data Group des entites n'existe pas on le cree
00064     */
00065    if ((entid = _MEDdatagroupOuvrir(maaid,nom_ent)) < 0)
00066      if ((entid = _MEDdatagroupCreer(maaid,nom_ent)) < 0)
00067        return -1;
00068 
00069    /*
00070     * Pour les mailles, les faces et le aretes, on cree
00071     * s'il n'existe pas le Data Group du type geometrique
00072     */
00073    if ((_type_ent==MED_MAILLE)||(_type_ent==MED_FACE)||(_type_ent==MED_ARETE))
00074      {
00075        if ((ret = _MEDnomGeometrie(nom_geo,type_geo)) < 0)
00076          return -1;
00077 
00078        if ((geoid = _MEDdatagroupOuvrir(entid,nom_geo)) < 0)
00079          if ((geoid = _MEDdatagroupCreer(entid,nom_geo)) < 0)
00080            return -1;
00081      }
00082    else
00083      geoid = -1;
00084 
00085    /*
00086     * Creation du Data Set "NOM" 
00087     */
00088    if (geoid == -1)
00089      root = entid;
00090    else
00091      root = geoid;
00092    dimd[0] = n*MED_TAILLE_PNOM+1;
00093    if ((ret = _MEDdatasetStringEcrire(root,MED_NOM_NOM,dimd,nom)) < 0)
00094      return -1;
00095 
00096   /*
00097    * Attribut NBR (nombre de noeuds)
00098    */
00099    if ((dataset = _MEDdatasetOuvrir(root,MED_NOM_NOM)) < 0)
00100      return -1;
00101    if ((ret = _MEDattrEntierEcrire(dataset,MED_NOM_NBR,&n)) < 0)
00102      return -1;
00103 
00104    /*
00105     * On ferme tout
00106     */
00107    if ((ret = _MEDdatasetFermer(dataset)) < 0)
00108      return -1;
00109    if (geoid > 0)
00110      if ((ret = _MEDdatagroupFermer(geoid)) < 0)
00111        return -1;
00112    if ((ret = _MEDdatagroupFermer(entid)) < 0)
00113      return -1;
00114    if ((ret = _MEDdatagroupFermer(maaid)) < 0)
00115      return -1;
00116 
00117   return 0; 
00118 }

Généré le Thu Oct 8 14:26:16 2015 pour MED fichier par  doxygen 1.6.1