test20.c

Aller à la documentation de ce fichier.
00001 /*  This file is part of MED.
00002  *
00003  *  COPYRIGHT (C) 1999 - 2012  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_ACC_RDWR
00031 #elif DEF_LECT_AJOUT
00032 #define MODE_ACCES MED_ACC_RDEXT
00033 #else
00034 #define MODE_ACCES MED_ACC_CREAT
00035 #endif
00036 
00037 int main (int argc, char **argv)
00038 
00039 
00040 {
00041   med_idt        fid,mid,mid2;
00042   med_int        ncha, ncomp, nmaa;
00043   med_field_type type;
00044   char           comp[3*MED_SNAME_SIZE+1]="",unit[3*MED_SNAME_SIZE+1]="";
00045   char           nom       [MED_NAME_SIZE+1] ="";
00046   char           _meshname [MED_NAME_SIZE+1] ="";
00047   char           _dtunit   [MED_SNAME_SIZE+1]="";
00048   med_int        _ncstp=0;
00049   med_bool       _local;
00050   int i;
00051 
00052   /* Ouverture du fichier test20-0.med en mode lecture et ajout */
00053   if ((fid = MEDfileOpen("test20-0.med",MED_ACC_RDEXT)) < 0) {
00054     MESSAGE("Erreur a l'ouverture du fichier test20-0.med");
00055     return -1;
00056   }
00057   printf("On ouvre le fichier test20-0.med \n");
00058 
00059   /* Lecture du nombre de champs */
00060   if ((ncha = MEDnField(fid)) < 0) {
00061     MESSAGE("Erreur a la lecture du nombre de champs");
00062     return -1;
00063   }
00064   printf("Nombre de champs dans test20-0.med :"IFORMAT" \n",ncha);
00065 
00066   /* On fait le montage dans test20-0.med de tous les champs de test10.med */
00067   mid = MEDfileObjectsMount(fid,"test10.med",MED_FIELD);
00068   if (mid < 0) {
00069     MESSAGE("Echec du montage des champs de test10.med");
00070     return -1;
00071   }
00072   printf("On monte les champs du fichier test10.med dans le fichier test20-0.med \n");
00073 
00074   /* Combien de champs dans le fichier "test20-0.med" apres le montage */
00075   if ((ncha = MEDnField(fid)) < 0) {
00076     MESSAGE("Erreur a la lecture du nombre de champ");
00077     return -1;
00078   }
00079   printf("Nombre de champs dans test20-0.med apres montage : "IFORMAT" \n",ncha);
00080 
00081   /* On s'assure que les champs sont bien accessibles */
00082   for (i=1;i<=ncha;i++) {
00083 
00084     /* Combien de composantes dans le champ */
00085     if ((ncomp = MEDfieldnComponent(fid,i)) < 0) {
00086       MESSAGE("Erreur a lecture du nombre de composante du champ");
00087       return -1;
00088     }
00089 
00090     /* Lecture des infos sur le champ */
00091     if (MEDfieldInfo(fid,i,nom,_meshname,&_local,&type,comp,unit,_dtunit,&_ncstp) < 0) {
00092       MESSAGE("Erreur a la lecture des informations sur le champ");
00093       return -1;
00094     }
00095 
00096     printf("Nom du champ : |%s| de type %d\n",nom,type);
00097     printf("Nom des composantes : |%s|\n",comp);
00098     printf("Unites des composantes : |%s| \n",unit);
00099     printf("Unites des dates  : |%s| \n",_dtunit);
00100     printf("Le maillage associé est |%s|\n",_meshname);
00101 
00102   }
00103 
00104   /* On demonte le fichier */
00105   if (MEDfileObjectsUnmount(fid,mid,MED_FIELD) < 0) {
00106     MESSAGE("Echec du demontage de test10.med");
00107     return -1;
00108   }
00109   printf("On demonte le fichier test10.med dans test20-0.med\n");
00110 
00111   /* Combien de champs dans le fichier "test20-0.med" apres le demontage */
00112   if ((ncha = MEDnField(fid)) < 0) {
00113     MESSAGE("Erreur a la lecture du nombre de champ");
00114     return -1;
00115   }
00116   printf("Nombre de champs dans test20-0.med apres demontage: "IFORMAT" \n",ncha);
00117 
00118   /* On ferme le fichier test20-0.med */
00119   if (MEDfileClose(fid) < 0) {
00120     MESSAGE("Erreur lors de la fermeture du fichier");
00121     return -1;
00122   }
00123   printf("On ferme le fichier test20-0.med \n");
00124 
00125   /* Creation du fichier test20.med */
00126   if ((fid = MEDfileOpen("test20.med",MODE_ACCES))  < 0) {
00127     MESSAGE("Erreur a la creation du fichier test20.med");
00128     return -1;
00129   }
00130   printf("On cree le fichier test20.med \n");
00131 
00132   /* Montage dans test20.med de tous les maillages de test20-0.med */
00133   mid2 = MEDfileObjectsMount(fid,"test20-0.med",MED_MESH);
00134   if (mid2 < 0) {
00135     MESSAGE("Echec du montage de test20-0.med");
00136     return -1;
00137   }
00138   printf("On monte les maillages du fichier test20-0.med dans le fichier test20.med \n");
00139 
00140   /* Lecture du nombre de maillages */
00141   nmaa = MEDnMesh(fid);
00142   if (nmaa < 0) {
00143     MESSAGE("Erreur lors de la lecture du nombre de maillage");
00144     return -1;
00145   }
00146   printf("Nombre de maillages apres montage de test20-0.med : "IFORMAT"\n",nmaa);
00147 
00148   /* Montage dans test20.med de tous les champs de test10.med */
00149   mid = MEDfileObjectsMount(fid,"test10.med",MED_FIELD);
00150   if (mid < 0) {
00151     MESSAGE("Echec du montage de test10.med");
00152     return -1;
00153   }
00154   printf("On monte les champs du fichier test10.med dans le fichier test20.med \n");
00155 
00156   /* Combien de champs dans le fichier "test20.med" apres le montage */
00157   if ((ncha = MEDnField(fid)) < 0) {
00158     MESSAGE("Erreur lors de la lecture du nombre de champ");
00159     return -1;
00160   }
00161   printf("Nombre de champs dans test20.med apres montage : "IFORMAT" \n",ncha);
00162 
00163   /* Demontage du fichier test10.med */
00164   if (MEDfileObjectsUnmount(fid,mid,MED_FIELD) < 0) {
00165     MESSAGE("Echec du demontage de test10.med");
00166     return -1;
00167   }
00168   printf("On demonte le fichier test10.med dans test20.med \n");
00169 
00170   /* Demontage du fichier test20-0.med */
00171   if (MEDfileObjectsUnmount(fid,mid2,MED_MESH) < 0) {
00172     MESSAGE("Echec du demontage de test20-0.med");
00173     return -1;
00174   }
00175   printf("On demonte le fichier test20-0.med dans test20.med\n");
00176 
00177   /* Fermeture du fichier test20.med */
00178   if (MEDfileClose(fid) < 0) {
00179     MESSAGE("Erreur de la fermeture du fichier");
00180     return -1;
00181   }
00182   printf("On ferme le fichier test20.med \n");
00183   
00184   return 0;
00185 }

Généré le Mon Nov 19 15:43:35 2012 pour MED fichier par  doxygen 1.6.1