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_ACC_RDWR
00031 #elif DEF_LECT_AJOUT
00032 #define MODE_ACCES MED_ACC_RDEXT
00033 #else
00034 #define MODE_ACCES MED_ACC_CREAT
00035 #endif
00036 
00037 int afficheCorres(med_idt fid, char *maa, char *jnt,
00038                  med_entity_type typ_ent_local,   med_geometry_type typ_geo_local,
00039                  med_entity_type typ_ent_distant, med_geometry_type 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_NAME_SIZE+1],maa_dist[MED_NAME_SIZE+1];
00049   med_int mdim,sdim;
00050   med_int njnt,ncor,ndom,nc;
00051   char jnt[MED_NAME_SIZE+1],corr[MED_NAME_SIZE+1];
00052   char des[MED_COMMENT_SIZE+1];
00053   char dtunit[MED_SNAME_SIZE+1]="";
00054   char nomcoo[3*MED_SNAME_SIZE+1];
00055   char unicoo[3*MED_SNAME_SIZE+1];
00056   med_axis_type rep;
00057   med_mesh_type type;
00058   med_sorting_type sort;
00059   med_int nstep=0,njstep=0,nodtitncor=0,nentity=0;
00060   med_entity_type typ_ent_local,typ_ent_distant;
00061   med_geometry_type typ_geo_local,typ_geo_distant;
00062   int i,j,k;
00063 
00064   if (argc != 2) {
00065     MESSAGE("Il faut passer un fichier MED en paramètre");
00066     return -1;
00067   }
00068 
00069   /* Ouverture du fichier passe en argument en lecture seule */
00070   if ((fid = MEDfileOpen(argv[1],MED_ACC_RDONLY)) < 0) {
00071     MESSAGE("Erreur à l'ouverture du fichier : "); SSCRUTE(argv[1]);
00072     return -1;
00073   }
00074 
00075   if ((sdim=MEDmeshnAxis(fid, 1)) <0) {
00076     MESSAGE("Erreur à la lecture de la dimension de l'espace du maillage :");
00077     SSCRUTE(maa);
00078     return -1;
00079   }
00080 
00081   /* Lecture des infos concernant le premier maillage */
00082   if ( MEDmeshInfo( fid, 1,  maa, &sdim, &mdim, &type, des, dtunit, &sort,
00083                     &nstep,  &rep, nomcoo,unicoo) < 0 ) {
00084     MESSAGE("Erreur a la lecture des informations sur le maillage : ");SSCRUTE(maa);
00085     return -1;
00086   } else {
00087     printf("Maillage de nom : |%s| , de dimension : "IFORMAT" , et de type %d\n",maa,mdim,type);
00088     printf("\t -Dimension de l'espace : "IFORMAT"\n",sdim);
00089     printf("\t -Description du maillage : |%s|\n",des);
00090     printf("\t -Noms des axes : |%s|\n",nomcoo);
00091     printf("\t -Unités des axes : |%s|\n",unicoo);
00092     printf("\t -Type de repère : %d\n",rep);
00093     printf("\t -Nombre d'étapes de calcul : "IFORMAT"\n",nstep);
00094     printf("\t -Unité des dates : |%s|\n\n",dtunit);
00095   }
00096 
00097   /* Lecture du nombre de joints */
00098   if ((njnt = MEDnSubdomainJoint(fid,maa)) < 0) {
00099     MESSAGE("Erreur a la lecture du nombre de joints");
00100     return -1;
00101   }
00102   printf("Nombre de joints : "IFORMAT" \n",njnt);
00103 
00104   /* Lecture de tous les joints du maillage */
00105   for (i = 0;i<njnt;i++) {
00106     printf("Joint numero : %d \n",i+1);
00107 
00108     /* Lecture des infos sur le joints */
00109     if (MEDsubdomainJointInfo(fid,maa,i+1,jnt,des,&ndom,maa_dist,&njstep,&nodtitncor) < 0) {
00110       MESSAGE("Erreur a la lecture du joint d'indice");
00111       ISCRUTE_int(i+1);
00112       return -1;
00113     }
00114     printf("Nom du joint: |%s| \n",jnt);
00115     printf("Description du joint      : |%s| \n",des);
00116     printf("Domaine en regard         : "IFORMAT" \n",ndom);
00117     printf("Maillage distant          : |%s| \n",maa_dist);
00118     printf("Nombre d'étapes de calcul : "IFORMAT" \n",njstep);
00119     printf("Nombre de correspondance pour (NO_DT,NO_IT) : "IFORMAT" \n",nodtitncor);
00120 
00121 
00122 
00123     /* lecture des correspondances une par une
00124        en connaissant leur type a priori */
00125 
00126     /* Lecture de la correspondance Noeud Noeud */
00127     afficheCorres(fid,maa,jnt,MED_NODE,0,MED_NODE,0,"noeud/noeud");
00128 
00129     /* Lecture de la correspondance Noeud Maille */
00130     afficheCorres(fid,maa,jnt,MED_NODE,0,MED_CELL,MED_TRIA3,"noeud/TRIA3");
00131 
00132 
00133     /* lecture des correspondances une par une
00134        sans connaitre leur type a priori
00135        -> utilisation de la fonction MEDjointTypeCorres */
00136 
00137     ncor=1;
00138 
00139     while ( ncor <= nodtitncor ) {
00140       ISCRUTE(ncor);
00141       if ( MEDsubdomainCorrespondenceSizeInfo(fid,maa,jnt,MED_NO_DT,MED_NO_IT,ncor,
00142                                            &typ_ent_local,&typ_geo_local,&typ_ent_distant,&typ_geo_distant,
00143                                               &nentity) < 0 ) {
00144         MESSAGE("Erreur a la lecture des infos sur le nombre d'entite en regard");
00145         return -1;
00146       }
00147 
00148       /* Lecture de la correspondance Noeud Noeud */
00149       afficheCorres(fid,maa,jnt,typ_ent_local,typ_geo_local,typ_ent_distant,typ_geo_distant,"------");
00150 
00151       ncor++;
00152     }
00153 
00154   }
00155 
00156   /* Fermeture du fichier */
00157   if (MEDfileClose(fid) < 0) {
00158     MESSAGE("Erreur a la fermeture du fichier ");
00159     return -1;
00160   }
00161 
00162   return ret;
00163 }
00164 
00165 
00166 
00167 
00168 int afficheCorres(med_idt fid, char *maa, char *jnt,
00169                  med_entity_type typ_ent_local,   med_geometry_type typ_geo_local,
00170                  med_entity_type typ_ent_distant, med_geometry_type typ_geo_distant,
00171                  char *type)
00172 {
00173   med_int nc;
00174   med_int *cortab;
00175   int k,ncor,ret=0;
00176 
00177   ISCRUTE_int(typ_ent_local);ISCRUTE_int(typ_geo_local);
00178   ISCRUTE_int(typ_ent_distant);ISCRUTE_int(typ_geo_distant);
00179   if ( MEDsubdomainCorrespondenceSize(fid,maa,jnt,MED_NO_DT,MED_NO_IT,
00180                                       typ_ent_local,typ_geo_local,typ_ent_distant,typ_geo_distant,
00181                                       &nc) < 0) {
00182     MESSAGE("Erreur a la lecture des infos sur le nombre d'entite en regard de type");
00183     SSCRUTE(type);
00184     return -1;
00185   }
00186 
00187   printf("nb de couples d'entites en regard |%s|: "IFORMAT" \n",type,nc);
00188 
00189   if (nc > 0) {
00190     cortab = (med_int*) malloc(sizeof(med_int)*nc*2);
00191     if ((ret=MEDsubdomainCorrespondenceRd(fid,maa,jnt,MED_NO_DT,MED_NO_IT,
00192                                           typ_ent_local,typ_geo_local,typ_ent_distant,typ_geo_distant,
00193                                           cortab)) < 0) {
00194       MESSAGE("Erreur a la lecture des correspondances sur ");
00195       SSCRUTE(type);
00196       ret = -1;
00197     }
00198     if (ret == 0)
00199       for (k=0;k<nc;k++)
00200         printf("Correspondance %d : "IFORMAT" et "IFORMAT" \n",k+1,*(cortab+2*k),
00201                *(cortab+2*k+1));
00202     free(cortab);
00203   }
00204   return ret;
00205 }
00206 

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