Test_MEDmeshNodeCoordinateTrsfRd.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 /******************************************************************************
00020  * - Nom du fichier : Test_MEDmeshNodeCoordinateTrsfRd.c
00021  *
00022  * - Description : lecture des noeuds d'un maillage MED.
00023  *
00024  *****************************************************************************/
00025 
00026 #include <med.h>
00027 #define MESGERR 1
00028 #include "med_utils.h"
00029 #include <string.h>
00030 
00031 #ifdef DEF_LECT_ECR
00032 #define MODE_ACCES MED_ACC_RDWR
00033 #elif DEF_LECT_AJOUT
00034 #define MODE_ACCES MED_ACC_RDEXT
00035 #else
00036 #define MODE_ACCES MED_ACC_CREAT
00037 #endif
00038 
00039 int main (int argc, char **argv)
00040 
00041 
00042 {
00043   med_err ret = 0;
00044   med_idt fid=0;
00045   med_int mdim=0,sdim=0;
00046   char    maa[MED_NAME_SIZE+1]="";
00047   med_int nnoe = 0;
00048   med_int ntrsf = 0;
00049   med_float *coo1;
00050   med_float mtrsf[7]={ 0, 0, 0, 0, 0, 0, 0};
00051   /* tables des noms et des unites des coordonnees
00052      flt : (dimension*MED_SNAME_SIZE+1) */
00053   char nomcoo[2*MED_SNAME_SIZE+1];
00054   char unicoo[2*MED_SNAME_SIZE+1];
00055   /* tables des noms, numeros, numeros de familles des noeuds
00056      autant d'elements que de noeuds - les noms ont pout longueur
00057      MED_SNAME_SIZE */
00058   char *nomnoe;
00059   med_int *numnoe, *nufano;
00060   med_axis_type rep;
00061   med_int  nnomnoe=0,nnumnoe=0,nnufano=0;
00062   med_bool inonoe=MED_FALSE,inunoe=MED_FALSE,inufano=MED_FALSE;
00063   med_bool chgt=MED_FALSE,trsf=MED_FALSE;
00064   med_bool chgtco=MED_FALSE,trsfdataset=MED_FALSE;
00065   char desc[MED_COMMENT_SIZE+1]="";
00066   char dtunit[MED_SNAME_SIZE+1]="";
00067   char str[MED_SNAME_SIZE+1]="";
00068   med_mesh_type type;
00069   med_sorting_type sort;
00070   med_int nstep=0,i=0;
00071   med_int numit=MED_NO_IT,numdt=MED_NO_DT;
00072   med_float dt=0.0;
00073   int csit=0;
00074 
00075   /* Ouverture du fichier en lecture seule */
00076   fid = MEDfileOpen("Test_MEDmeshNodeCoordinateTrsfWr.med",MED_ACC_RDONLY);
00077   if (fid < 0) {
00078     MESSAGE("Erreur a l'ouverture du fichier Test_MEDmeshNodeCoordinateTrsfWr.med");
00079     return -1;
00080   }
00081 
00082   if ((sdim=MEDmeshnAxis(fid, 1)) <0) {
00083     MESSAGE("Erreur a la lecture de la dimension de l'espace du maillage :");
00084     SSCRUTE(maa);
00085     ret = -1;
00086   }
00087 
00088   /* Lecture des infos concernant le premier maillage */
00089   if ( MEDmeshInfo( fid, 1,  maa,  &sdim, &mdim, &type, desc, dtunit, &sort,
00090                     &nstep,  &rep, nomcoo,unicoo) < 0 ) {
00091     MESSAGE("Erreur a la lecture des informations sur le maillage : ");SSCRUTE(maa);
00092     return -1;
00093   } else {
00094     printf("Maillage de nom : |%s| , de dimension : %d , et de type %d\n",maa,mdim,type);
00095     printf("\t -Dimension de l'espace : %d\n",sdim);
00096     printf("\t -Description du maillage : %s\n",desc);
00097     printf("\t -Noms des axes : %s\n",nomcoo);
00098     printf("\t -Unités des axes : %s\n",unicoo);
00099     printf("\t -Type de repère : %d\n",rep);
00100     printf("\t -Nombre d'étape de calcul : %d\n",nstep);
00101     printf("\t -Unité des dates : %s\n",dtunit);
00102   }
00103 
00104   for (csit=0; csit <nstep; ++csit) {
00105 
00106     if ( MEDmeshComputationStepInfo(fid, maa, csit+1, &numdt, &numit, &dt ) < 0) {
00107       MESSAGE("Erreur a la lecture des informations sur le maillage : ");SSCRUTE(maa);
00108       ret = -1;
00109       continue;
00110     }
00111     if (sort == MED_SORT_DTIT )
00112       printf("\n -Etape de calcul n° %d : (%d,%d) avec dt=%f %s\n\n",csit+1,numdt,numit,dt,dtunit);
00113     else
00114       printf("\n -Etape de calcul n° %d : (%d,%d) avec dt=%f %s\n\n",csit+1,numit,numdt,dt,dtunit);
00115 
00116     /* Combien de noeuds a lire ? */
00117     nnoe = MEDmeshnEntity(fid,maa,numdt,numit,
00118                           MED_NODE,MED_NONE,MED_COORDINATE,MED_NODAL, &chgt,&trsf);
00119     if (nnoe < 0) {
00120       MESSAGE("Erreur a la lecture du nombre de noeuds.");
00121       ret = -1;
00122     } else
00123       printf("Nombre de noeuds : "IFORMAT", (chgt,trsf) : (%1d,%1d) \n",nnoe,chgt,trsf);
00124 
00125     if ( !chgt )
00126       printf("Aucun changement par rapport à la séquence de calcul précédente.\n");
00127 
00128     if ( chgt && trsf ) {
00129       printf("Seules les coordonnées sont modifiées par rapport à la séquence de calcul précédente.\n");
00130       chgtco=MED_TRUE;
00131     } else {
00132       chgtco=MED_FALSE;
00133     }
00134     trsfdataset=MED_FALSE;
00135     if ( chgt && !trsf ) {
00136 
00137       printf("Des modifications ont eu lieu depuis la séquence de calcul précédente.\n");
00138       ntrsf = MEDmeshnEntity(fid,maa,numdt,numit,
00139                              MED_NODE,MED_NONE,MED_COORDINATE_TRSF,MED_NODAL, &chgtco, &trsfdataset);
00140       if (ntrsf < 0)  {
00141         MESSAGE("Erreur a la lecture de la présence d'une transformation géométrique : ");
00142         ret=-1;
00143       }
00144       if (chgtco)
00145         printf("Les coordonnées sont modifiées par rapport à la séquence de calcul précédente.\n");
00146       else
00147         printf("Les coordonnées ne sont pas modifiées par rapport à la séquence de calcul précédente.\n");
00148 
00149       if (trsfdataset)
00150         printf("Une modification de la matrice de transformation a eu lieu par rapport à la séquence de calcul précédente.\n");
00151     }
00152 
00153     /* Lecture des coordonnees des noeuds */
00154     if (nnoe > 0) {
00155       if (chgtco) {
00156         coo1 = (med_float*) calloc(nnoe*sdim,sizeof(med_float));
00157         if ( MEDmeshNodeCoordinateRd(fid, maa, numdt, numit,MED_FULL_INTERLACE, coo1) < 0 ) {
00158           MESSAGE("Erreur a la lecture des coordonnees des noeuds");
00159           ret = -1;
00160         }
00161       }
00162 
00163     /* Lecture des noms des noeuds (optionnel dans un maillage MED) */
00164       nnomnoe = MEDmeshnEntity(fid,maa,numdt,numit,
00165                                MED_NODE,MED_NONE,MED_NAME,MED_NODAL, &chgtco, &inonoe);
00166       if ( (nnomnoe>0) && inonoe) {
00167         nomnoe = (char*) malloc(MED_SNAME_SIZE*nnomnoe+1);
00168         if (MEDmeshEntityNameRd(fid,maa, numdt, numit, MED_NODE,MED_NONE,nomnoe) < 0) {
00169           MESSAGE("Erreur a la lecture des noms des noeuds");
00170           ret = -1;
00171         }
00172       }
00173 
00174     /* Lecture des numeros des noeuds (optionnel dans un maillage MED) */
00175       nnumnoe = MEDmeshnEntity(fid,maa,numdt,numit,
00176                                MED_NODE,MED_NONE,MED_NUMBER,MED_NODAL, &chgtco, &inunoe);
00177       if ( (nnumnoe>0) && inunoe) {
00178         numnoe = (med_int*) malloc(sizeof(med_int)*nnumnoe);
00179         if (MEDmeshEntityNumberRd(fid,maa, numdt, numit, MED_NODE,MED_NONE,numnoe) < 0) {
00180           MESSAGE("Erreur a la lecture des numéros des noeuds");
00181           ret = -1;
00182         }
00183       }
00184 
00185     /* Lecture des numeros de familles des noeuds */
00186       nnufano = MEDmeshnEntity(fid,maa,numdt,numit,
00187                                MED_NODE,MED_NONE,MED_FAMILY_NUMBER,MED_NODAL, &chgtco, &inufano);
00188       if ( (nnufano>0) && inufano) {
00189         nufano = (med_int*) malloc(sizeof(med_int)*nnufano);
00190         if (MEDmeshEntityFamilyNumberRd(fid,maa, numdt, numit,MED_NODE,MED_NONE,nufano ) < 0) {
00191           MESSAGE("Erreur a la lecture des numeros de famille des noeuds");
00192           ret = -1;
00193         }
00194       }
00195     }
00196 
00197     /* Affichage des resulats */
00198     if (ret == 0 && nnoe > 0) {
00199 
00200       if (chgtco) {
00201         printf("\n\tCoordonnees des noeuds : \n\t");
00202         for (i=0;i<nnoe*sdim;i++)
00203           printf("%f ",*(coo1+i));
00204       }
00205 
00206       if (trsfdataset)
00207         if ( MEDmeshNodeCoordinateTrsfRd(fid, maa, numdt, numit, mtrsf) < 0 ) {
00208           MESSAGE("Erreur a la lecture de la matrice de transformation");
00209           ret = -1;
00210         } else {
00211           printf("Valeur de la matrice de transformation : ");
00212           for (i=0;i<7;i++)
00213             printf("%4.2f ",mtrsf[i]);
00214           printf("\n\n");
00215         }
00216 
00217       if (inonoe) {
00218         printf("\n\tNoms des noeuds : \n\t");
00219         for (i=0;i<nnoe;i++) {
00220           strncpy(str,nomnoe+i*MED_SNAME_SIZE,MED_SNAME_SIZE);
00221           str[MED_SNAME_SIZE] = '\0';
00222           printf("|%s|",str);
00223         }
00224       }
00225       if (inunoe) {
00226         printf("\n\tNumeros des noeuds : \n\t");
00227         for (i=0;i<nnoe;i++)
00228           printf(IFORMAT" ",*(numnoe+i));
00229       }
00230       if (inufano) {
00231         printf("\n\tNumeros des familles des noeuds : \n\t");
00232         for (i=0;i<nnoe;i++)
00233           printf(IFORMAT" ",*(nufano+i));
00234         printf("\n");
00235       }
00236     }
00237 
00238     /* liberation memoire */
00239     if (nnoe > 0) {
00240       if (chgtco)  free(coo1);
00241       if (inonoe)  free(nomnoe);
00242       if (inunoe)  free(numnoe);
00243       if (inufano) free(nufano);
00244     }
00245   }
00246 
00247   /* Fermeture du fichier */
00248   if (MEDfileClose(fid) < 0){
00249     MESSAGE("Erreur a la fermeture du fichier");
00250     ret = -1;
00251   }
00252 
00253   return ret;
00254 }
00255 
00256 
00257 
00258 

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