test2.c

Aller à la documentation de ce fichier.
00001 /*  This file is part of MED.
00002  *
00003  *  COPYRIGHT (C) 1999 - 2011  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 : test2.c
00020  *
00021  * - Description : exemples de creation de maillages MED.
00022  *
00023  *****************************************************************************/
00024 
00025 #include <med.h>
00026 #define MESGERR 1
00027 #include <med_utils.h>
00028 #include <string.h>
00029 
00030 #ifdef DEF_LECT_ECR
00031 #define MODE_ACCES MED_ACC_RDWR
00032 #elif DEF_LECT_AJOUT
00033 #define MODE_ACCES MED_ACC_RDEXT
00034 #else
00035 #define MODE_ACCES MED_ACC_CREAT
00036 #endif
00037 
00038 int main (int argc, char **argv)
00039 
00040 {
00041   med_err ret=0;
00042   med_idt fid=0;
00043   char des[MED_COMMENT_SIZE+1]="";
00044   med_bool hdfok=MED_FALSE, medok=MED_FALSE;
00045   char axisname[3*MED_SNAME_SIZE+1]="";
00046   char axisunit[3*MED_SNAME_SIZE+1]="";
00047 
00048   strcat(axisname,"x               ");
00049   strcat(axisname,"y               ");
00050   strcat(axisname,"z               ");
00051   strcat(axisunit,"cm              ");
00052   strcat(axisunit,"cm              ");
00053   strcat(axisunit,"cm              ");
00054 
00055   /* Verification de la conformite du format med du fichier test1.med */
00056   ret = MEDfileCompatibility("test1.med",&hdfok,&medok);
00057   if (!hdfok) {
00058     MESSAGE("Format HDF non conforme ou fichier inexistant");
00059     return -1;
00060   }
00061   if (!medok) {
00062     MESSAGE("Format MED non conforme ou fichier inexistant");
00063     return -1;
00064   }
00065 
00066 /*   Ouverture en mode de lecture du fichier "test1.med"  */
00067   fid = MEDfileOpen("test1.med",MED_ACC_RDONLY);
00068   if (fid < 0) {
00069       MESSAGE("Erreur a l'ouverture du fichier test1.med en mode MED_LECTURE");
00070       return -1;
00071   }
00072 
00073 /*    Affiche de l'en-tete du fichier  */
00074   ret = MEDfileCommentRd(fid, des);
00075   if (ret == 0)
00076     printf("En-tete du fichier test1.med : %s\n",des);
00077   else {
00078     MESSAGE("Erreur a la lecture de l'en-tete du fichier test1.med");
00079     ret = -1;
00080   }
00081 
00082 /*   Fermeture du fichier test1.med */
00083   ret = MEDfileClose(fid);
00084   if (ret < 0) {
00085     MESSAGE("Erreur a la fermeture du fichier test1.med");
00086     return -1;
00087   }
00088 
00089   /* Ouverture en mode creation du fichier test2.med */
00090   fid = MEDfileOpen("test2.med",MODE_ACCES);
00091   if (fid < 0) {
00092     MESSAGE("Erreur a la creation du fichier test2.med");
00093     return -1;
00094   }
00095 
00096   /* Creation du maillage "maa1" de type MED_UNSTRUCTURED_MESH
00097      et de dimension 3 */
00098   if (MEDmeshCr(fid,"maa1",3,3,MED_UNSTRUCTURED_MESH,
00099                 "un premier maillage","s",MED_SORT_DTIT,
00100                 MED_CARTESIAN,axisname,axisunit) < 0) {
00101     MESSAGE("Erreur a la creation du maillage maa1");
00102     ret = -1;
00103   }
00104 
00105   /* Ecriture du nom universel pour "maa1" */
00106   if (MEDmeshUniversalNameWr(fid,"maa1") < 0) {
00107     MESSAGE("Erreur a la creation du nom universel de maa1");
00108     ret = -1;
00109   }
00110 
00111   if ( MEDmeshComputationStepCr(fid,"maa1",MED_NO_DT,MED_NO_IT,
00112                               MED_NO_DT,MED_NO_IT,0) < 0) {
00113     MESSAGE("Erreur a la creation du premier pas de temps du maillage maa1");
00114 /*     ret = -1; */
00115   }
00116 
00117  if ( MEDmeshComputationStepCr(fid,"maa1",MED_NO_DT,MED_NO_IT,
00118                               1,3,1.1) < 0) {
00119     MESSAGE("Erreur a la creation du second pas de temps du maillage maa1");
00120 /*     ret = -1; */
00121   }
00122 
00123  if ( MEDmeshComputationStepCr(fid,"maa1",MED_NO_DT,MED_NO_IT,
00124                               0,0,1.1) < 0) {
00125     MESSAGE("Erreur a la creation du second pas de temps du maillage maa1");
00126 /*     ret = -1; */
00127   }
00128 
00129  if ( MEDmeshComputationStepCr(fid,"maa1",MED_NO_DT,MED_NO_IT,
00130                               0,-1,1.1) < 0) {
00131     MESSAGE("Erreur a la creation du second pas de temps du maillage maa1");
00132 /*     ret = -1; */
00133   }
00134 
00135  if ( MEDmeshComputationStepCr(fid,"maa1",MED_NO_DT,MED_NO_IT,
00136                               -1,20,1.1) < 0) {
00137     MESSAGE("Erreur a la creation du second pas de temps du maillage maa1");
00138 /*     ret = -1; */
00139   }
00140 
00141  if ( MEDmeshComputationStepCr(fid,"maa1",MED_NO_DT,MED_NO_IT,
00142                               20,-1,1.1) < 0) {
00143     MESSAGE("Erreur a la creation du second pas de temps du maillage maa1");
00144 /*     ret = -1; */
00145   }
00146 
00147 
00148   /* Creation du maillage "maa2" de type MED_UNSTRUCTURED_MESH
00149      et de dimension 2 dans un espace de dimension 3*/
00150   if (MEDmeshCr(fid,"maa2",3,2,MED_UNSTRUCTURED_MESH,
00151                 "un second maillage","s",MED_SORT_DTIT,
00152                 MED_CARTESIAN,axisname,axisunit) < 0) {
00153     MESSAGE("Erreur a la creation du maillage maa2");
00154     ret = -1;
00155   }
00156 
00157   /* Creation du maillage "maa3" de type MED_STRUCTURED_MESH
00158      et de dimension 1 */
00159   if (MEDmeshCr(fid,"maa3",3,1,MED_UNSTRUCTURED_MESH,
00160                 "un troisieme maillage","s",MED_SORT_DTIT,
00161                 MED_CARTESIAN,axisname,axisunit) < 0) {
00162     MESSAGE("Erreur a la creation du maillage maa3");
00163     ret = -1;
00164   }
00165 
00166   /* Fermeture du fichier */
00167   if ( MEDfileClose(fid)  < 0) {
00168     MESSAGE("Erreur a la fermeture du fichier");
00169     return -1;
00170   }
00171 
00172   return ret;
00173 }
00174 
00175 
00176 
00177 

Généré le Mon May 16 17:10:24 2011 pour MED fichier par  doxygen 1.6.1