test22.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 : test22.c
00021  *
00022  * - Description : lecture de valeurs scalaires numeriques crees dans test21.
00023  *
00024  *****************************************************************************/
00025 
00026 #include <med.h>
00027 #define MESGERR 1
00028 #include <med_utils.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 {
00042   med_idt fid;
00043   char nom_scalaire[MED_NAME_SIZE+1];
00044   char description[MED_COMMENT_SIZE+1];
00045   med_int vali;
00046   med_float valr;
00047   med_int i,n,npdt,j;
00048   med_field_type type;
00049   med_int numdt,numo;
00050   med_float dt;
00051   char dt_unit[MED_SNAME_SIZE+1];
00052 
00053   /* Ouverture du fichier test21.med en lecture seule */
00054   if ((fid = MEDfileOpen("test21.med",MED_ACC_RDONLY)) < 0) {
00055     MESSAGE("Erreur a l'ouverture du fichier test21.med");
00056     return -1;
00057   }
00058 
00059   /* Lecture du nombre de variable scalaire */
00060   n = MEDnParameter(fid);
00061   if (n < 0) {
00062     MESSAGE("Erreur a la lecture du nombre de variable scalaire");
00063     return -1;
00064   }
00065   printf("Nombre de variables scalaires dans test21.med = "IFORMAT"\n",n);
00066 
00067   /* Lecture des infos sur les variables (type,description) */
00068   for (i=1;i<=n;i++) {
00069 
00070     if (MEDparameterInfo(fid, i, nom_scalaire, &type, description, dt_unit, &npdt) < 0) {
00071       MESSAGE("Erreur a la lecture des infos sur la variable d'indice : ");
00072       ISCRUTE(i);
00073       return -1;
00074     }
00075     printf("- Scalaire n°"IFORMAT" de nom %s \n",i,nom_scalaire);
00076     if (type == MED_FLOAT64)
00077       printf("  Type flottant. \n");
00078     else
00079       printf("  Type entier. \n");
00080     printf("  Description associee : [%s] \n",description);
00081     printf("  Nombre de pas de temps : "IFORMAT" \n",npdt);
00082 
00083     for (j=1;j<=npdt;j++) {
00084 
00085       if (MEDparameterComputationStepInfo(fid,nom_scalaire,j,&numdt,&numo,&dt) < 0) {
00086         MESSAGE("Erreur a la lecture des informations sur le pas de temps d'indice :");
00087         ISCRUTE(j);
00088         return -1;
00089       }
00090 
00091       printf("   Valeur n°"IFORMAT" : \n",j);
00092       if (numdt == MED_NO_DT)
00093         printf("   - Aucun de pas de temps \n");
00094       else
00095         printf("   - Pas de de temps de numero "IFORMAT" de valeur %f [%s] \n",numdt,dt,dt_unit);
00096       if (numo == MED_NO_IT)
00097         printf("   - Aucun numero d'ordre \n");
00098       else
00099         printf("   - Numero d'ordre : "IFORMAT" \n",numo);
00100 
00101       /* Lecture de la valeur flottante associee au pas de temps */
00102       if (type == MED_FLOAT64) {
00103         if (MEDparameterValueRd(fid,nom_scalaire,numdt,numo,(unsigned char *) &valr) < 0) {
00104           MESSAGE("Erreur a la lecture de la valeur flottante : ");
00105           SSCRUTE(nom_scalaire); ISCRUTE(numdt);ISCRUTE(numo);
00106           return -1;
00107         }
00108         printf("    - Valeur : %f \n",valr);
00109       } else {
00110         /* Lecture de la valeur scalaire associee au pas de temps */
00111         if (MEDparameterValueRd(fid,nom_scalaire,numdt,numo,(unsigned char *) &vali) < 0) {
00112           MESSAGE("Erreur a la lecture de la valeur entiere : ");
00113           SSCRUTE(nom_scalaire); ISCRUTE(numdt);ISCRUTE(numo);
00114           return -1;
00115         }
00116         printf("    - Valeur : "IFORMAT" \n",vali);
00117       }
00118     }
00119 
00120   }
00121 
00122   /* Fermeture du fichier */
00123   if (MEDfileClose(fid) < 0) {
00124     MESSAGE("Erreur a la fermeture du fichier ");
00125     return -1;
00126   }
00127 
00128   return 0;
00129 }

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