2.3.6/test20.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 : test20.c
00020  *
00021  * - Description : montage/demontage de fichiers MED 
00022  *
00023  *****************************************************************************/
00024 
00025 #include <med.h>
00026 #define MESGERR 1
00027 #include <med_utils.h>
00028 
00029 #ifdef DEF_LECT_ECR
00030 #define MODE_ACCES MED_LECTURE_ECRITURE
00031 #elif DEF_LECT_AJOUT
00032 #define MODE_ACCES MED_LECTURE_AJOUT
00033 #else
00034 #define MODE_ACCES MED_CREATION
00035 #endif
00036 
00037 int main (int argc, char **argv)
00038 
00039 
00040 {
00041   int i;
00042   med_idt fid,mid,mid2;
00043   med_int ncha, ncomp, nmaa;
00044   med_type_champ type;
00045   char comp[3*MED_TAILLE_PNOM+1],unit[3*MED_TAILLE_PNOM+1];
00046   char nom[MED_TAILLE_NOM+1];
00047 
00048   /* Ouverture du fichier test20-0.med en mode lecture et ajout */
00049   if ((fid = MEDouvrir("test20-0.med",MED_LECTURE_AJOUT)) < 0) {
00050     MESSAGE("Erreur a l'ouverture du fichier test20-0.med");
00051     return -1;
00052   }
00053   printf("On ouvre le fichier test20-0.med \n");
00054 
00055   /* Lecture du nombre de champs */
00056   if ((ncha = MEDnChamp(fid,0)) < 0) {
00057     MESSAGE("Erreur a la lecture du nombre de champs");
00058     return -1;
00059   }
00060   printf("Nombre de champs dans test20-0.med :"IFORMAT" \n",ncha);
00061 
00062   /* On fait le montage dans test20-0.med de tous les champs de test10.med */
00063   mid = MEDmonter(fid,"test10.med",MED_CHAMP);
00064   if (mid < 0) {
00065     MESSAGE("Echec du montage des champs de test10.med");
00066     return -1;
00067   }
00068   printf("On monte les champs du fichier test10.med dans le fichier test20-0.med \n");
00069 
00070   /* Combien de champs dans le fichier "test20-0.med" apres le montage */
00071   if ((ncha = MEDnChamp(fid,0)) < 0) {
00072     MESSAGE("Erreur a la lecture du nombre de champ");
00073     return -1;
00074   }
00075   printf("Nombre de champs dans test20-0.med apres montage : "IFORMAT" \n",ncha);
00076 
00077   /* On s'assure que les champs sont bien accessibles */
00078   for (i=1;i<=ncha;i++) {
00079 
00080     /* Combien de composantes dans le champ */
00081     if ((ncomp = MEDnChamp(fid,i)) < 0) {
00082       MESSAGE("Erreur a lecture du nombre de composante du champ");
00083       return -1;
00084     }
00085 
00086     /* Lecture des infos sur le champ */
00087     if (MEDchampInfo(fid,i,nom,&type,comp,unit,ncomp) < 0) {
00088       MESSAGE("Erreur a la lecture des informations sur le champ");
00089       return -1;
00090     }
00091 
00092     printf("Champ de nom [%s] de type %d et avec "IFORMAT" composantes \n",nom,type,ncomp);
00093   }
00094 
00095   /* On demonte le fichier */
00096   if (MEDdemonter(fid,mid,MED_CHAMP) < 0) {
00097     MESSAGE("Echec du demontage de test10.med");
00098     return -1;
00099   }
00100   printf("On demonte le fichier test10.med dans test20-0.med\n");
00101 
00102   /* Combien de champs dans le fichier "test20-0.med" apres le demontage */
00103   if ((ncha = MEDnChamp(fid,0)) < 0) {
00104     MESSAGE("Erreur a la lecture du nombre de champ");
00105     return -1;
00106   }
00107   printf("Nombre de champs dans test20-0.med apres demontage: "IFORMAT" \n",ncha);
00108 
00109   /* On ferme le fichier test20-0.med */
00110   if (MEDfermer(fid) < 0) {
00111     MESSAGE("Erreur lors de la fermeture du fichier");
00112     return -1;
00113   }
00114   printf("On ferme le fichier test20-0.med \n");
00115 
00116   /* Creation du fichier test20.med */
00117   if ((fid = MEDouvrir("test20.med",MODE_ACCES))  < 0) {
00118     MESSAGE("Erreur a la creation du fichier test20.med");
00119     return -1;
00120   }
00121   printf("On cree le fichier test20.med \n");
00122 
00123   /* Montage dans test20.med de tous les maillages de test20-0.med */
00124   mid2 = MEDmonter(fid,"test20-0.med",MED_MAILLAGE);
00125   if (mid2 < 0) {
00126     MESSAGE("Echec du montage de test20-0.med");
00127     return -1;
00128   }
00129   printf("On monte les maillages du fichier test20-0.med dans le fichier test20.med \n");
00130 
00131   /* Lecture du nombre de maillages */
00132   nmaa = MEDnMaa(fid);
00133   if (nmaa < 0) {
00134     MESSAGE("Erreur lors de la lecture du nombre de maillage");
00135     return -1;
00136   }
00137   printf("Nombre de maillages apres montage de test20-0.med : "IFORMAT"\n",nmaa);
00138 
00139   /* Montage dans test20.med de tous les champs de test10.med */
00140   mid = MEDmonter(fid,"test10.med",MED_CHAMP);
00141   if (mid < 0) {
00142     MESSAGE("Echec du montage de test10.med");
00143     return -1;
00144   }
00145   printf("On monte les champs du fichier test10.med dans le fichier test20.med \n");
00146 
00147   /* Combien de champs dans le fichier "test20.med" apres le montage */
00148   if ((ncha = MEDnChamp(fid,0)) < 0) {
00149     MESSAGE("Erreur lors de la lecture du nombre de champ");
00150     return -1;
00151   }
00152   printf("Nombre de champs dans test20.med apres montage : "IFORMAT" \n",ncha);
00153 
00154   /* Demontage du fichier test10.med */
00155   if (MEDdemonter(fid,mid,MED_CHAMP) < 0) {
00156     MESSAGE("Echec du demontage de test10.med");
00157     return -1;
00158   }
00159   printf("On demonte le fichier test10.med dans test20.med \n");
00160 
00161   /* Demontage du fichier test20-0.med */
00162   if (MEDdemonter(fid,mid2,MED_MAILLAGE) < 0) {
00163     MESSAGE("Echec du demontage de test20-0.med");
00164     return -1;
00165   }
00166   printf("On demonte le fichier test20-0.med dans test20.med\n");
00167 
00168   /* Fermeture du fichier test20.med */
00169   if (MEDfermer(fid) < 0) {
00170     MESSAGE("Erreur de la fermeture du fichier");
00171     return -1;
00172   }
00173   printf("On ferme le fichier test20.med \n");
00174   
00175   return 0;
00176 }

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