2.3.6/test30.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  * - Nom du fichier : test30.c
00020  *
00021  * - Description : lecture des joints d'un maillage MED.
00022  *
00023  *****************************************************************************/
00024 
00025 #include <med.h>
00026 #define MESGERR 1
00027 #include <med_utils.h>
00028 
00029 #ifdef DEF_LECT_ECR
00030 #define MODE_ACCES MED_LECTURE_ECRITURE
00031 #elif DEF_LECT_AJOUT
00032 #define MODE_ACCES MED_LECTURE_AJOUT
00033 #else
00034 #define MODE_ACCES MED_CREATION
00035 #endif
00036 
00037 int afficheCorres(med_idt fid, char *maa, char *jnt,
00038                  med_entite_maillage typ_ent_local,   med_geometrie_element typ_geo_local,
00039                  med_entite_maillage typ_ent_distant, med_geometrie_element typ_geo_distant,
00040                  char *type);
00041 
00042 int main (int argc, char **argv)
00043 
00044 
00045 {
00046   med_err ret = 0;
00047   med_idt fid;
00048   char maa[MED_TAILLE_NOM+1],maa_dist[MED_TAILLE_NOM+1];
00049   med_int mdim;
00050   med_int njnt,ncor,ndom,nc;
00051   char jnt[MED_TAILLE_NOM+1],corr[MED_TAILLE_NOM+1];
00052   char des[MED_TAILLE_DESC+1];
00053   med_entite_maillage typ_ent_local,typ_ent_distant;
00054   med_geometrie_element typ_geo_local,typ_geo_distant;
00055 
00056   int i,j,k;
00057   med_maillage type;
00058 
00059   if (argc != 2) {
00060     MESSAGE("Il faut passer un fichier MED en paramètre");
00061     return -1;
00062   }
00063 
00064   /* Ouverture du fichier passe en argument en lecture seule */
00065   if ((fid = MEDouvrir(argv[1],MED_LECTURE)) < 0) {
00066     MESSAGE("Erreur a l'ouverture du fichier : "); SSCRUTE(argv[1]);
00067     return -1;
00068   }
00069   
00070   /* Lecture des infos sur le premier maillage */
00071   if (MEDmaaInfo(fid,1,maa,&mdim,&type,des) < 0) {
00072     MESSAGE("Erreur a lecture des infos sur le 1er maillage"); 
00073     return -1;
00074   }
00075   printf("Maillage de nom %s et de dimension "IFORMAT" \n",maa,mdim);
00076 
00077   /* Lecture du nombre de joints */
00078   if ((njnt = MEDnJoint(fid,maa)) < 0) {
00079     MESSAGE("Erreur a la lecture du nombre de joints"); 
00080     return -1;
00081   }
00082   printf("Nombre de joints : "IFORMAT" \n",njnt);
00083 
00084   /* Lecture de tous les joints du maillage */
00085   if (njnt > 0)
00086     for (i = 0;i<njnt;i++) {
00087       printf("Joint numero : %d \n",i+1);
00088 
00089       /* Lecture des infos sur le joints */
00090       if (MEDjointInfo(fid,maa,i+1,jnt,des,&ndom,maa_dist) < 0) {
00091         MESSAGE("Erreur a la lecture du joint d'indice");
00092         ISCRUTE_int(i+1);
00093         return -1;
00094       }
00095       printf("Nom du joint: %s \n",jnt);
00096       printf("Description du joint      : %s \n",des);
00097       printf("Domaine en regard         : "IFORMAT" \n",ndom);
00098       printf("Maillage distant          : %s \n",maa_dist);
00099 
00100 
00101 
00102       /* lecture des correspondances une par une 
00103          en connaissant leur type a priori */
00104 
00105       /* Lecture de la correspondance Noeud Noeud */
00106       afficheCorres(fid,maa,jnt,MED_NOEUD,0,MED_NOEUD,0,"noeud/noeud");
00107   
00108       /* Lecture de la correspondance Noeud Maille */
00109       afficheCorres(fid,maa,jnt,MED_NOEUD,0,MED_MAILLE,MED_TRIA3,"noeud/TRIA3");
00110 
00111 
00112       /* lecture des correspondances une par une 
00113          sans connaitre leur type a priori 
00114          -> utilisation de la fonction MEDjointTypeCorres */
00115 
00116       ncor=1;
00117 
00118       while (MEDjointTypeCorres(fid,maa,jnt,ncor,
00119                                 &typ_ent_local,&typ_geo_local,&typ_ent_distant,&typ_geo_distant)>=0) {
00120 
00121         /* Lecture de la correspondance Noeud Noeud */
00122         afficheCorres(fid,maa,jnt,typ_ent_local,typ_geo_local,typ_ent_distant,typ_geo_distant,"noeud/noeud");
00123         
00124         ncor++;
00125       }
00126 
00127 
00128             
00129     }                       
00130 
00131   /* Fermeture du fichier */
00132   if (MEDfermer(fid) < 0) {
00133     MESSAGE("Erreur a la fermeture du fichier ");
00134     return -1;
00135   }
00136 
00137   return ret;
00138 }
00139 
00140 
00141 
00142 
00143 int afficheCorres(med_idt fid, char *maa, char *jnt,
00144                  med_entite_maillage typ_ent_local,   med_geometrie_element typ_geo_local,
00145                  med_entite_maillage typ_ent_distant, med_geometrie_element typ_geo_distant,
00146                  char *type)
00147 {
00148   med_int nc;
00149   med_int *cortab;
00150   int k,ncor,ret=0;
00151 
00152   if ((nc = MEDjointnCorres(fid,maa,jnt,typ_ent_local,typ_geo_local,typ_ent_distant,typ_geo_distant)) < 0) {
00153     MESSAGE("Erreur a la lecture des infos sur le nombre d'entite en regard de type");
00154     SSCRUTE(type);
00155     return -1;
00156   }
00157         
00158   printf("nb de couples d'entites en regard %s: "IFORMAT" \n",type,nc);
00159   
00160   if (nc > 0) {
00161     cortab = (med_int*) malloc(sizeof(med_int)*nc*2);
00162     if ((ret=MEDjointLire(fid,maa,jnt,cortab,nc*2,
00163                           typ_ent_local,typ_geo_local,typ_ent_distant,typ_geo_distant)) < 0) {
00164       MESSAGE("Erreur a la lecture des correspondances sur ");
00165       SSCRUTE(type);
00166       ret = -1;
00167     }
00168     if (ret == 0)
00169       for (k=0;k<nc;k++)
00170         printf("Correspondance %d : "IFORMAT" et "IFORMAT" \n",k+1,*(cortab+2*k),
00171                *(cortab+2*k+1));
00172     free(cortab);
00173   }
00174   return ret;
00175 }
00176 

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