MEDpolygoneConnEcr.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 <string.h>
00024 #include <stdlib.h>
00025 
00026 med_err
00027 MEDpolygoneConnEcr(med_idt fid, char *maa, med_int *index, med_int ni, 
00028                    med_int *con, med_entite_maillage type_ent, 
00029                    med_connectivite type_conn)
00030 {
00031   med_err ret;
00032   med_idt maaid, entid, geoid, dataset;
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   char nom_dataset1[MED_TAILLE_NOM_ENTITE+1], nom_dataset2[MED_TAILLE_NOM_ENTITE+1];
00037   med_geometrie_element type_geo = MED_POLYGONE;
00038   med_int n;
00039   med_size dimd[1];
00040   med_entite_maillage _type_ent=type_ent;
00041 
00042   if ( type_ent == MED_NOEUD_MAILLE ) _type_ent=MED_NOEUD ;
00043 
00044   /*
00045    * On inhibe le gestionnaire d'erreur HDF 5
00046    */
00047   _MEDmodeErreurVerrouiller();
00048 if (MEDcheckVersion(fid) < 0) return -1;
00049 
00050 
00051   /*
00052    * Si le maillage n'existe pas => erreur
00053    */
00054   strcpy(chemin,MED_MAA);
00055   strcat(chemin,maa);
00056   if ((maaid = _MEDdatagroupOuvrir(fid,chemin)) < 0)
00057       return -1;
00058 
00059   /*
00060    * On met a jour le nom du groupe HDF representant
00061    * le type des entites
00062    */
00063    if ((ret = _MEDnomEntite(nom_ent,_type_ent)) < 0)
00064      return -1;
00065 
00066    /*
00067     * Si le groupe HDF  des entites n'existe pas on le cree
00068     */
00069    if ((entid = _MEDdatagroupOuvrir(maaid,nom_ent)) < 0)
00070      if ((entid = _MEDdatagroupCreer(maaid,nom_ent)) < 0)
00071        return -1;
00072 
00073    /*
00074     * On cree s'il n'existe pas le groupe HDF du type geometrique
00075     */
00076   if ((ret = _MEDnomGeometrie(nom_geo,type_geo)) < 0)
00077      return -1;
00078    if ((geoid = _MEDdatagroupOuvrir(entid,nom_geo)) < 0)
00079      if ((geoid = _MEDdatagroupCreer(entid,nom_geo)) < 0)
00080        return -1;
00081 
00082    /*
00083     * On regarde si le dataset HDF existe et on le cree sinon
00084     */
00085    switch(type_conn)
00086      {
00087      case MED_NOD :
00088        strcpy(nom_dataset1,MED_NOM_INN);
00089        strcpy(nom_dataset2,MED_NOM_NOD);
00090        break;
00091 
00092      case MED_DESC :
00093        strcpy(nom_dataset1,MED_NOM_IND);
00094        strcpy(nom_dataset2,MED_NOM_DES);
00095        break;
00096        
00097      default :
00098        return -1;
00099      }
00100 
00101 #if defined(HAVE_F77INT64)
00102    dimd[0] = ni;
00103    if ((ret = _MEDdatasetNumEcrire(geoid,nom_dataset1,MED_INT64,MED_NO_INTERLACE,1,MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,0,MED_NOPG,dimd,
00104                                    (unsigned char*) index)) < 0)
00105      return -1;
00106    dimd[0] = index[ni-1] - index[0] ;
00107    if ((ret = _MEDdatasetNumEcrire(geoid,nom_dataset2,MED_INT64,MED_NO_INTERLACE,1,MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,0,MED_NOPG,dimd,
00108                                    (unsigned char*) con)) < 0)
00109      return -1;
00110 #else
00111    dimd[0] = ni;
00112    if ((ret = _MEDdatasetNumEcrire(geoid,nom_dataset1,MED_INT32,MED_NO_INTERLACE,1,MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,0,MED_NOPG,dimd,
00113                                    (unsigned char*) index)) < 0)
00114      return -1;
00115    dimd[0] = index[ni-1] - index[0] ;
00116    if ((ret = _MEDdatasetNumEcrire(geoid,nom_dataset2,MED_INT32,MED_NO_INTERLACE,1,MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,0,MED_NOPG,dimd,
00117                                    (unsigned char*) con)) < 0)
00118      return -1;
00119 #endif
00120 
00121   /*
00122    * On stocke le nombre d'elements du tableau "con" 
00123    * et le nombre de polygones
00124    */
00125    n = ni - 1;
00126    if ((dataset = _MEDdatasetOuvrir(geoid,nom_dataset2)) < 0)
00127      return -1;
00128    if ((ret = _MEDattrEntierEcrire(dataset,MED_NOM_NBR,&n)) < 0)
00129      return -1;
00130    if ((ret = _MEDdatasetFermer(dataset)) < 0)
00131      return -1;
00132 
00133    n = index[ni-1] - index[0] ;
00134    if ((dataset = _MEDdatasetOuvrir(geoid,nom_dataset2)) < 0)
00135      return -1;
00136    if ((ret = _MEDattrEntierEcrire(dataset,MED_NOM_TAI,&n)) < 0)
00137      return -1;
00138    if ((ret = _MEDdatasetFermer(dataset)) < 0)
00139      return -1;
00140 
00141    /*
00142     * On ferme tout 
00143     */
00144    if ((ret = _MEDdatagroupFermer(geoid)) < 0)
00145      return -1;
00146    if ((ret = _MEDdatagroupFermer(entid)) < 0)
00147      return -1;
00148    if ((ret = _MEDdatagroupFermer(maaid)) < 0)
00149      return -1;
00150 
00151   return ret;
00152 }

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