test4.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 : test4.c
00021  *
00022  * - Description : ecriture des noeuds d'un maillage MED.
00023  *
00024  *****************************************************************************/
00025 
00026 #include <med.h>
00027 #define MESGERR 1
00028 #include <med_utils.h>
00029 
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 
00040 int main (int argc, char **argv)
00041 
00042 
00043 {
00044   med_err ret = 0;
00045   med_idt fid;
00046   /* la dimension du maillage */
00047   med_int mdim = 2;
00048   /* nom du maillage de longueur maxi MED_NAME_SIZE */
00049   char maa[MED_NAME_SIZE+1] = "maa1";
00050   /* le nombre de noeuds */
00051   med_int nnoe = 4;
00052   /* table des coordonnees
00053       (dimension * nombre de noeuds) */
00054   med_float coo[8] = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0};
00055   med_float coo_2[8] = {0.0, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0};
00056   /* tables des noms et des unites des coordonnees
00057       (dimension*MED_SNAME_SIZE+1) */
00058   /*                                  12345678901234561234567890123456*/
00059   char nomcoo[2*MED_SNAME_SIZE+1] = "x               y               ";
00060   char unicoo[2*MED_SNAME_SIZE+1] = "cm              cm              ";
00061   /* tables des noms, numeros, numeros de familles des noeuds
00062      autant d'elements que de noeuds - les noms ont pout longueur
00063      MED_SNAME_SIZE */
00064   /*                                  1234567890123456123456789012345612345678901234561234567890123456*/
00065   char nomnoe[4*MED_SNAME_SIZE+1] = "nom1            nom2            nom3            nom4            ";
00066   med_int numnoe[4] = {1,2,3,4};
00067   med_int nufano[4] = {0,1,2,2};
00068 
00069   /* Creation du fichier "test4.med" */
00070   /* ouverture du fichier */
00071   if ((fid = MEDfileOpen("test4.med",MODE_ACCES)) < 0){
00072     MESSAGE("Erreur à l'ouverture du fichier : ");
00073     return -1;
00074   }
00075 
00076   /* Creation du maillage "maa" de type MED_NON_STRUCURE
00077      et de dimension 2 */
00078   if (MEDmeshCr( fid, maa, mdim, mdim, MED_UNSTRUCTURED_MESH,
00079              "un maillage pour test4","s", MED_SORT_DTIT,
00080                  MED_CARTESIAN, nomcoo, unicoo) < 0) {
00081     MESSAGE("Erreur a la creation du maillage : "); SSCRUTE(maa);
00082     ret = -1;
00083   }
00084 
00085   /* Ecriture des coordonnees des noeuds en mode MED_FULL_INTERLACE :
00086      (X1,Y1, X2,Y2, X3,Y3, ...) dans un repere cartesien */
00087   if (MEDmeshNodeCoordinateWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_UNDEF_DT,
00088                               MED_FULL_INTERLACE,nnoe,  coo) < 0) {
00089     MESSAGE("Erreur a l'ecriture des coordonnees des noeuds");
00090     ret = -1;
00091   }
00092 
00093   /* Ecriture des attributs des noeuds du maillage  */
00094   if (MEDmeshAttributeWr(fid,maa, 0, nnoe, 0) < 0 ) {
00095     MESSAGE("Erreur a l'ecriture des attributs des noeuds du maillage");
00096     ret = -1;
00097   }
00098 
00099   /* Ecriture des noms des noeuds (optionnel dans un maillage MED) */
00100   if (MEDmeshEntityNameWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NODE,MED_NONE,nnoe,nomnoe) < 0) {
00101     MESSAGE("Erreur a l'ecriture des noms des noeuds");
00102     ret = -1;
00103   }
00104 
00105   /* Ecriture des numeros des noeuds (optionnel dans un maillage MED) */
00106   if (MEDmeshEntityNumberWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NODE,MED_NONE,nnoe,numnoe) < 0) {
00107     MESSAGE("Erreur a l'ecriture des numeros des noeuds");
00108     ret = -1;
00109   }
00110 
00111   /* Ecriture des numeros de famille des noeuds */
00112   if (MEDmeshEntityFamilyNumberWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NODE,MED_NONE,nnoe,nufano) < 0) {
00113     MESSAGE("Erreur a l'ecriture des numeros de familles des noeuds");
00114     ret = -1;
00115   }
00116 
00117   /* Ecriture des coordonnees des noeuds en mode MED_FULL_INTERLACE :
00118      (X1,Y1, X2,Y2, X3,Y3, ...) dans un repere cartesien */
00119   if (MEDmeshNodeCoordinateWr(fid,maa,0,5,0.5,
00120                               MED_FULL_INTERLACE,nnoe, coo_2) < 0) {
00121     MESSAGE("Erreur a l'ecriture des coordonnees des noeuds");
00122     ret = -1;
00123   }
00124 
00125   /* Ecriture des coordonnees des noeuds en mode MED_FULL_INTERLACE :
00126      (X1,Y1, X2,Y2, X3,Y3, ...) dans un repere cartesien */
00127   if (MEDmeshNodeCoordinateWr(fid,maa,2,0,2.0,
00128                               MED_FULL_INTERLACE,nnoe,  coo) < 0) {
00129     MESSAGE("Erreur a l'ecriture des coordonnees des noeuds");
00130     ret = -1;
00131   }
00132 
00133   /*TODO : Ecrire un test de comparaison next prev et ordre de découverte itératif */
00134   MEDmeshComputationStepCr(fid,maa,-1,-1,0,2,0.25);
00135 
00136   MEDmeshComputationStepCr(fid,maa,0,2,0,3,0.35);
00137 
00138   /* Fermeture du fichier */
00139   if (MEDfileClose(fid) < 0) {
00140     MESSAGE("Erreur a la fermeture du fichier test4.med");
00141     return -1;
00142   }
00143   return ret;
00144 }
00145 
00146 
00147 
00148 

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