test17.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 : test17.c
00020  *
00021  * - Description : lecture d'elements de maillages MED ecrits par test16
00022  *                 via les routines de niveau 2
00023  *                 - equivalent a test7.c
00024  *
00025  *****************************************************************************/
00026 
00027 #include <med.h>
00028 #define MESGERR 1
00029 #include "med_utils.h"
00030 #include <string.h>
00031 
00032 #ifdef DEF_LECT_ECR
00033 #define MODE_ACCES MED_ACC_RDWR
00034 #elif DEF_LECT_AJOUT
00035 #define MODE_ACCES MED_ACC_RDEXT
00036 #else
00037 #define MODE_ACCES MED_ACC_CREAT
00038 #endif
00039 
00040 
00041 int main (int argc, char **argv)
00042 
00043 
00044 {
00045   med_err ret = 0;
00046   med_idt fid;
00047   med_int nse2;
00048   med_int *se2;
00049   char *nomse2;
00050   med_int *numse2;
00051   med_int *nufase2; 
00052   med_int ntr3;
00053   med_int *tr3;
00054   char *nomtr3;
00055   med_int *numtr3;
00056   med_int *nufatr3;
00057   char maa[MED_NAME_SIZE+1] ="maa1";
00058   med_int mdim=0,sdim=0;
00059   med_bool inoele1,inoele2,inuele1,inuele2,infele1,infele2;
00060   med_int tse2,ttr3;
00061   med_bool   chgt=MED_FALSE, trsf=MED_FALSE;
00062   char str   [MED_SNAME_SIZE+1]  ="";
00063   char desc  [MED_COMMENT_SIZE+1]="";
00064   char dtunit[MED_SNAME_SIZE+1]  ="";
00065   char nomcoo[3*MED_SNAME_SIZE+1]="";
00066   char unicoo[3*MED_SNAME_SIZE+1]="";
00067   med_mesh_type    type;
00068   med_sorting_type sort;
00069   med_axis_type    rep;
00070   med_int          nstep=0;
00071   med_int i;
00072 
00073 
00074   /* Ouverture du fichier en mode lecture seule */
00075   if ((fid = MEDfileOpen("test16.med",MED_ACC_RDONLY)) < 0) {
00076     MESSAGE("Erreur a l'ouverture du fichier test16.med .");
00077     return -1;
00078   }
00079   if ((sdim=MEDmeshnAxis(fid, 1)) <0) {
00080     MESSAGE("Erreur a la lecture de la dimension de l'espace du maillage :");
00081     SSCRUTE(maa);
00082     return -1;
00083   }
00084 
00085   /* Lecture des infos concernant le premier maillage */
00086   if ( MEDmeshInfo( fid, 1,  maa, &sdim, &mdim, &type, desc, dtunit, &sort,
00087                     &nstep,  &rep, nomcoo,unicoo) < 0 ) {
00088     MESSAGE("Erreur a la lecture des informations sur le maillage : ");SSCRUTE(maa);
00089     return -1;
00090   } else {
00091     printf("Maillage de nom : |%s| , de dimension : "IFORMAT" , et de type %d\n",maa,mdim,type);
00092     printf("\t -Dimension de l'espace : "IFORMAT"\n",sdim);
00093     printf("\t -Description du maillage : |%s|\n",desc);
00094     printf("\t -Noms des axes : |%s|\n",nomcoo);
00095     printf("\t -Unités des axes : |%s|\n",unicoo);
00096     printf("\t -Type de repère : %d\n",rep);
00097     printf("\t -Nombre d'étapes de calcul : "IFORMAT"\n",nstep);
00098     printf("\t -Unité des dates : |%s|\n",dtunit);
00099   }
00100 
00101   /* Combien de triangles et de segments */
00102   if ((nse2 = MEDmeshnEntity(fid, maa, MED_NO_DT, MED_NO_IT,
00103                               MED_DESCENDING_EDGE, MED_SEG2,MED_CONNECTIVITY, MED_DESCENDING,
00104                              &chgt, &trsf)) < 0)  {
00105     MESSAGE("Erreur a la lecture du nombre de segments");
00106     return -1;
00107   }
00108 
00109   if ((ntr3 = MEDmeshnEntity(fid, maa, MED_NO_DT, MED_NO_IT,
00110                               MED_CELL, MED_TRIA3,MED_CONNECTIVITY, MED_DESCENDING,
00111                              &chgt, &trsf)) < 0)  {
00112     MESSAGE("Erreur a la lecture du nombre de segments");
00113     return -1;
00114   }
00115   printf("Nombre de MED_SEG2 : "IFORMAT" - nombre de MED_TRIA3 :"IFORMAT"\n",nse2,ntr3);
00116 
00117   /* Allocations memoire */
00118   tse2 = 2;
00119   se2  = (med_int*) malloc(sizeof(med_int)*tse2*nse2);
00120   nomse2 = (char*) malloc(MED_SNAME_SIZE*nse2+1);
00121   numse2 = (med_int*) malloc(sizeof(med_int)*nse2);
00122   nufase2 = (med_int*) calloc(nse2,sizeof(med_int));
00123 
00124   ttr3 = 3;
00125   tr3 = (med_int*) malloc(sizeof(med_int)*ntr3*ttr3);
00126   nomtr3 = (char*) malloc(MED_SNAME_SIZE*ntr3+1);
00127   numtr3 = (med_int*) malloc(sizeof(med_int)*ntr3);
00128   nufatr3 = (med_int*) calloc(ntr3,sizeof(med_int));
00129 
00130   /* Lecture des aretes segments MED_SEG2 :
00131      - Connectivite,
00132      - Noms (optionnel)
00133      - Numeros (optionnel)
00134      - Numeros de familles */
00135   if (MEDmeshElementRd(fid,maa,MED_NO_DT,MED_NO_IT,MED_DESCENDING_EDGE,MED_SEG2,MED_DESCENDING,MED_NO_INTERLACE,
00136                        se2,&inoele1,nomse2,&inuele1,numse2,&infele1,nufase2) < 0) {
00137     MESSAGE("Erreur a la lecture des segments");
00138     ret = -1;
00139   }
00140 
00141   /* Lecture des mailles triangles MED_TRIA3 :
00142      - Connectivite,
00143      - Noms (optionnel)
00144      - Numeros (optionnel)
00145      - Numeros de familles */
00146   if (MEDmeshElementRd(fid,maa,MED_NO_DT,MED_NO_IT,MED_CELL,MED_TRIA3,MED_DESCENDING,MED_NO_INTERLACE,
00147                        tr3,&inoele2,nomtr3,&inuele2,numtr3,&infele2,nufatr3) < 0) {
00148     MESSAGE("Erreur a la lecture des triangles");
00149     ret = -1;
00150   }
00151 
00152   /* Fermeture du fichier */
00153   if (MEDfileClose(fid) < 0) {
00154     MESSAGE("Erreur a la fermeture du fichier");
00155     ret = -1;
00156   }
00157 
00158   /* Affichage */
00159   if (ret == 0) {
00160     if (nse2 > 0) {
00161       printf("Connectivite des segments : \n");
00162       for (i=0;i<nse2*tse2;i++)
00163         printf(IFORMAT" ",*(se2+i));
00164       if (inoele1) {
00165         printf("\nNoms des segments :\n");
00166         for (i=0;i<nse2;i++) {
00167           strncpy(str,nomse2+i*MED_SNAME_SIZE,MED_SNAME_SIZE);
00168           str[MED_SNAME_SIZE] = '\0';
00169           printf("|%s| ",str);
00170         }
00171       }
00172       if (inuele1) {
00173         printf("\nNumeros des segments :\n");
00174         for (i=0;i<nse2;i++)
00175           printf(IFORMAT" ",*(numse2+i));
00176       }
00177       printf("\nPrésence de numeros des familles des segments : %d\n",infele1);
00178       printf("\nNumeros des familles des segments :\n");
00179       for (i=0;i<nse2;i++)
00180         printf(IFORMAT" ",*(nufase2+i));
00181     }
00182 
00183     if (ntr3 > 0) {
00184       printf("\nConnectivite des triangles : \n");
00185       for (i=0;i<ntr3*ttr3;i++)
00186         printf(IFORMAT" ",*(tr3+i));
00187       if (inoele2) {
00188         printf("\nNoms des triangles :\n");
00189         for (i=0;i<ntr3;i++) {
00190           strncpy(str,nomtr3+i*MED_SNAME_SIZE,MED_SNAME_SIZE);
00191           str[MED_SNAME_SIZE] = '\0';
00192           printf("|%s| ",str);
00193         }
00194       }
00195       if (inuele2) {
00196         printf("\nNumeros des triangles :\n");
00197         for (i=0;i<ntr3;i++)
00198           printf(IFORMAT" ",*(numtr3+i));
00199       }
00200       printf("\nPrésence de numeros des familles des triangles : %d\n",infele2);
00201       printf("\nNumeros des familles des triangles :\n");
00202       for (i=0;i<ntr3;i++)
00203         printf(IFORMAT" ",*(nufatr3+i));
00204 
00205       printf("\n");
00206     }
00207   }
00208 
00209   /* Nettoyage memoire */
00210   free(se2);
00211   free(nomse2);
00212   free(numse2);
00213   free(nufase2);
00214 
00215   free(tr3);
00216   free(nomtr3);
00217   free(numtr3);
00218   free(nufatr3);
00219 
00220   return ret;
00221 }
00222 
00223 
00224 
00225 

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