test27.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 : test27.c
00021  *
00022  * - Description : creation de maillages structures (grille cartesienne |
00023  *                 grille standard ) dans le fichier test27.med
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 int main (int argc, char **argv)
00041 
00042 /*TODO : Tester l'écriture des attributs famille,numéros optionnels, noms optionnels*/
00043 {
00044   med_idt   fid=0;
00045   med_int   mdim=2,axe=0,nind=0;
00046   med_float indiceX[4] = {1.0,1.1,1.2,1.3};
00047   med_float indiceY[4] = {2.0,2.1,2.2,2.3};
00048   med_float coo[8]     = {0.0,0.0,1.0,0.0,0.0,1.0,1.0,1.0};
00049   med_int   nnoeuds    = 4;
00050   med_int   structure_grille[2] = {2,2};
00051   char      maa [MED_NAME_SIZE+1]= "grille_cartesian";
00052   char      maa2[MED_NAME_SIZE+1]= "grille_curvilinear";
00053   /* composantes et unites */
00054   /*                               12345678901234561234567890123456 */
00055   char comp[2*MED_SNAME_SIZE+1] = "X               Y               ";
00056   char unit[2*MED_SNAME_SIZE+1] = "cm              cm              ";
00057 
00058   /* Creation du fichier test27.med */
00059   fid = MEDfileOpen("test27.med",MODE_ACCES);
00060   if (fid < 0) {
00061     MESSAGE("Erreur a la creation du fichier test27.med");
00062     return -1;
00063   }
00064   printf("Creation du fichier test27.med \n");
00065 
00066   /* Creation du maillage "maa" de type MED_NON_STRUCURE  et de dimension 2 */
00067   if (MEDmeshCr( fid, "maillage vide",2, 2, MED_UNSTRUCTURED_MESH,
00068                  "un maillage vide","s", MED_SORT_DTIT,
00069                  MED_CARTESIAN, comp, unit) < 0) {
00070     MESSAGE("Erreur a la creation du maillage MED_UNSTRUCTURED_MESH : "); SSCRUTE(maa);
00071     return -1;
00072   }
00073   /* creation d'une grille cartesienne de dimension 2 */
00074   /* on commence par definir un maillage MED_STRUCTURED_MESH
00075      de dimension 2 */
00076   if (MEDmeshCr( fid, maa,mdim, mdim, MED_STRUCTURED_MESH,
00077                  "un exemple de grille cartesienne","s", MED_SORT_DTIT,
00078                  MED_CARTESIAN, comp, unit) < 0) {
00079     MESSAGE("Erreur a la creation de la grille");
00080     return -1;
00081   }
00082   printf("Creation d'un maillage structure MED_STRUCTURED_MESH \n");
00083 
00084   /* On specifie la nature du maillage structure : MED_GRILLE_CARTESIENNE */
00085   if (MEDmeshGridTypeWr(fid,maa, MED_CARTESIAN_GRID) < 0) {
00086     MESSAGE("Erreur a l'ecriture de la nature de la grille");
00087     return -1;
00088   }
00089 
00090   printf("On definit la nature du maillage structure : MED_GRILLE_CARTESIENNE \n");
00091 
00092   /* on definit les indices des coordonnees de la grille selon chaque dimension  */
00093   /* axe des "X" */
00094   nind = 4;
00095   axe = 1;
00096   if (MEDmeshGridIndexCoordinateWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_UNDEF_DT,
00097                                    axe,nind,indiceX) < 0) {
00098     MESSAGE("Erreur a l'ecriture de l'axe X");
00099     return -1;
00100   }
00101   printf("Ecriture des indices des coordonnees selon l'axe des X \n");
00102 
00103   /* axe des "Y" */
00104   nind = 4;
00105   axe = 2;
00106   if (MEDmeshGridIndexCoordinateWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_UNDEF_DT,
00107                                    axe,nind,indiceY) < 0) {
00108     MESSAGE("Erreur a l'ecriture de l'axe Y");
00109     return -1;
00110   }
00111   printf("Ecriture des indices des coordonnees selon l'axe des Y \n");
00112 
00113   /* Creation d'une grille MED_CURVILINEAR_GRID de dimension 2 */
00114   /* on commence par definir un maillage MED_STRUCTURED_MESH
00115      de dimension 2 */
00116   if (MEDmeshCr( fid, maa2,mdim, mdim, MED_STRUCTURED_MESH,
00117                  "un exemple de grille standard","s", MED_SORT_DTIT,
00118                  MED_CARTESIAN, comp, unit) < 0) {
00119     MESSAGE("Erreur a la creation de la 2e grille");
00120     return -1;
00121   }
00122   printf("Creation d'un maillage structure MED_STRUCTURED_MESH \n");
00123 
00124  /* On specifie la nature du maillage structure : MED_CURVILINEAR_GRID */
00125   if (MEDmeshGridTypeWr(fid,maa2, MED_CURVILINEAR_GRID) < 0) {
00126     MESSAGE("Erreur a l'ecriture de la nature de la grille");
00127     return -1;
00128   }
00129   printf("On definit la nature du maillage structure : MED_CURVILINEAR_GRID \n");
00130 
00131 
00132   if (MEDmeshNodeCoordinateWr(fid,maa2,MED_NO_DT,MED_NO_IT,MED_UNDEF_DT,
00133                               MED_FULL_INTERLACE,nnoeuds, coo) < 0) {
00134     MESSAGE("Erreur a l'ecriture des noeuds de la grille MED_CURVILINEAR_GRID");
00135     return -1;
00136   }
00137   printf("Ecriture des coordonnees des noeuds \n");
00138 
00139   /* On definit la structure de la grille */
00140   if ( MEDmeshGridStructWr(fid,maa2,MED_NO_DT,MED_NO_IT, MED_UNDEF_DT, structure_grille ) < 0) {
00141     MESSAGE("Erreur a l'ecriture de la structure de la grille");
00142     return -1;
00143   }
00144   printf("Ecriture de la structure de la grille : / 2,2 / \n");
00145 
00146   /* On ferme le fichier */
00147   if (MEDfileClose(fid) < 0) {
00148     MESSAGE("Erreur a la fermeture du fichier");
00149     return -1;
00150   }
00151   printf("Fermeture du fichier \n");
00152 
00153   return 0;
00154 }

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