MEDfamLire.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 MEDfamLire(med_idt fid,char *maa, med_int *fam, med_int n, 
00028            med_entite_maillage type_ent,med_geometrie_element type_geo)
00029 {
00030   med_idt root;
00031   med_idt maaid = 0;
00032   med_idt entid = 0;
00033   med_idt geoid = 0;
00034   med_err ret =  -1;
00035   char chemin[MED_TAILLE_MAA+MED_TAILLE_NOM+1];
00036   char nom_ent[MED_TAILLE_NOM_ENTITE+1];
00037   char nom_geo[MED_TAILLE_NOM_ENTITE+1];
00038   med_int i;
00039   med_entite_maillage _type_ent=type_ent;
00040 
00041   if ( type_ent == MED_NOEUD_MAILLE ) _type_ent=MED_NOEUD ;
00042 
00043   /*
00044    * On inhibe le gestionnaire d'erreur HDF 5
00045    */
00046   _MEDmodeErreurVerrouiller();
00047 if (MEDcheckVersion(fid) < 0) return -1;
00048 
00049 
00050   /*
00051    * Si le maillage n'existe pas => erreur
00052    */
00053   strcpy(chemin,MED_MAA);
00054   strcat(chemin,maa);
00055   if ((maaid = _MEDdatagroupOuvrir(fid,chemin)) < 0) {
00056     MESSAGE("Impossible d'acceder au maillage");
00057     SSCRUTE(chemin);
00058     goto ERREUR;
00059   }
00060 
00061   /*
00062    * On met a jour le nom du Data Group representant
00063    * le type des entites
00064    */
00065    if (_MEDnomEntite(nom_ent,_type_ent) < 0) {
00066     MESSAGE("L'entité demandée n'est pas une entité <med_entite_maillage> : ");
00067     SSCRUTE(nom_ent); 
00068     ISCRUTE(_type_ent);
00069     goto ERREUR;
00070   }
00071 
00072    /*
00073     * Si le "Data Group" des entites n'existe pas => erreur
00074     */
00075    if ((entid = _MEDdatagroupOuvrir(maaid,nom_ent)) < 0) { 
00076      MESSAGE("Impossible d'accéder au groupe des entités : ");
00077      SSCRUTE(nom_ent); 
00078      ISCRUTE(_type_ent);
00079      goto ERREUR;
00080    }
00081 
00082 
00083    /*
00084     * Pour les mailles, les faces et le aretes, on cree
00085     * si le "Data Group" du type geometrique => erreur
00086     */
00087    if ((_type_ent==MED_MAILLE)||(_type_ent==MED_FACE)||(_type_ent==MED_ARETE))
00088      {
00089        if (_MEDnomGeometrie30(nom_geo,type_geo) < 0) {
00090          MESSAGE("L'entité demandée n'est pas un élément <med_geometrie_element> : ");
00091          SSCRUTE(nom_geo); 
00092          ISCRUTE(type_geo);
00093          goto ERREUR;
00094        }
00095        if ((geoid = _MEDdatagroupOuvrir(entid,nom_geo)) < 0) {
00096          MESSAGE("Impossible d'accéder au groupe des éléments géométriques : ");
00097          SSCRUTE(nom_geo); 
00098          ISCRUTE(type_geo);
00099          goto ERREUR;
00100        }
00101         
00102      }
00103    else 
00104      geoid = -1;
00105 
00106    /*
00107     * lecture du Data Set "FAM" 
00108     * - En cas d'erreur, pas de message car la presence des 
00109     *   numeros est optionnelle dans un fichier MED (à partir de la V2.2)
00110     *   Dans ce cas de figure, on considère que tous les numéros sont à 0
00111     */
00112    if (geoid == -1)
00113      root = entid;
00114    else
00115      root = geoid;
00116 #if defined(HAVE_F77INT64)
00117    if (_MEDdatasetNumLire(root,MED_NOM_FAM,MED_INT64,
00118                           MED_NO_INTERLACE,1,MED_ALL,
00119                           MED_NOPF,MED_NO_PFLMOD,MED_PFL_NON_COMPACT,0,MED_NOPG,0,
00120                           (unsigned char *)fam) < 0)
00121      for (i=0; i<n; i++)
00122        *(fam+i) = 0;
00123 #else
00124    if (_MEDdatasetNumLire(root,MED_NOM_FAM,MED_INT32,
00125                           MED_NO_INTERLACE,1,MED_ALL,
00126                           MED_NOPF,MED_NO_PFLMOD,MED_PFL_NON_COMPACT,0,MED_NOPG,0,
00127                           (unsigned char *)fam) < 0)
00128      for (i=0; i<n; i++)
00129        *(fam+i) = 0;
00130 #endif
00131 
00132    /*
00133     * Tout s'est bien passé si on est parvenu jusqu'ici
00134     */
00135    ret = 0;
00136 
00137    /*
00138     * On ferme tout
00139     */
00140  ERREUR:
00141    if (geoid > 0)
00142      if (_MEDdatagroupFermer(geoid) < 0)
00143        return -1;
00144    if (entid > 0)
00145      if (_MEDdatagroupFermer(entid) < 0)
00146        return -1;
00147    if (maaid > 0)
00148      if (_MEDdatagroupFermer(maaid) < 0)
00149        return -1; 
00150 
00151    /* Code retour : 
00152     *   - ret == 0 en cas de succès
00153     *   - ret == -1 en cas d'échec 
00154     */
00155    return (ret); 
00156 }

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