00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 #include <med.h>
00027 #define MESGERR 1
00028 #include "med_utils.h"
00029 #include <string.h>
00030 
00031 #ifdef DEF_LECT_ECR
00032 #define MODE_ACCES MED_LECTURE_ECRITURE
00033 #elif DEF_LECT_AJOUT
00034 #define MODE_ACCES MED_LECTURE_AJOUT
00035 #else
00036 #define MODE_ACCES MED_CREATION
00037 #endif
00038 
00039 int main (int argc, char **argv)
00040 
00041 
00042 {
00043   med_err ret = 0;
00044   med_idt fid;
00045   
00046   med_int mdim;
00047   
00048   char maa[MED_TAILLE_NOM+1];
00049   
00050   med_int nnoe = 0;
00051   
00052   med_float *coo1,*coo2;
00053   
00054 
00055   char nomcoo[2*MED_TAILLE_PNOM+1];
00056   char unicoo[2*MED_TAILLE_PNOM+1];
00057   
00058 
00059 
00060   char *nomnoe;
00061   med_int *numnoe;
00062   med_int *nufano; 
00063   med_repere rep;
00064   med_booleen inonoe,inunoe;
00065   char str[MED_TAILLE_PNOM+1];
00066   med_int i;
00067   med_int profil[2] = { 2, 3 };
00068   char desc[MED_TAILLE_DESC+1];
00069   med_maillage type;
00070 
00071   
00072   fid = MEDouvrir("test4.med",MED_LECTURE);
00073   if (fid < 0) {
00074     MESSAGE("Erreur a l'ouverture du fichier test4.med");
00075     return -1;
00076   }
00077 
00078   
00079   if (MEDmaaInfo(fid,1,maa,&mdim,&type,desc) < 0) {
00080     MESSAGE("Erreur a la lecture des informations sur le maillage : ");SSCRUTE(maa);
00081     return -1;
00082   } else
00083     printf("Maillage de nom : %s et de dimension : %d \n",maa,mdim);
00084 
00085   
00086   nnoe = MEDnEntMaa(fid,maa,MED_COOR,MED_NOEUD,0,0);
00087   if (nnoe < 0) {
00088     MESSAGE("Erreur a la lecture du nombre de noeuds dans : ");
00089     ret = -1;
00090   } else
00091     printf("Nombre de noeuds : "IFORMAT" \n",nnoe);
00092 
00093   
00094   if (nnoe > 0) {
00095     
00096 
00097     coo1 = (med_float*) calloc(nnoe*mdim,sizeof(med_float));
00098     coo2 = (med_float*) calloc(nnoe*mdim,sizeof(med_float));
00099     
00100 
00101     numnoe = (med_int*) malloc(sizeof(med_int)*nnoe);
00102     nufano = (med_int*) malloc(sizeof(med_int)*nnoe);
00103     
00104 
00105     nomnoe = (char*) malloc(MED_TAILLE_PNOM*nnoe+1);
00106   }
00107 
00108   
00109   if (nnoe > 0) {
00110     if (MEDcoordLire(fid,maa,mdim,coo1,MED_FULL_INTERLACE,2,NULL,0,
00111                      &rep,nomcoo,unicoo) < 0) {
00112       MESSAGE("Erreur a la lecture des coordonnees des noeuds");
00113       ret = -1;
00114     } else {
00115       printf("Valeur de coo1 : ");
00116       for (i=0;i<nnoe*mdim;i++)
00117         printf("%4.2f ",coo1[i]);
00118       printf("\n");
00119     }
00120   }
00121 
00122   
00123   if (nnoe > 0) {
00124     if (MEDcoordLire(fid,maa,mdim,coo1,MED_FULL_INTERLACE,1,NULL,0,
00125                        &rep,nomcoo,unicoo) < 0) {
00126     MESSAGE("Erreur a la lecture des coordonnees des noeuds");
00127     ret = -1;
00128     } else {
00129       printf("Valeur de coo1 : ");
00130       for (i=0;i<nnoe*mdim;i++)
00131         printf("%4.2f ",coo1[i]);
00132       printf("\n");
00133     }
00134   }
00135 
00136   
00137   if (nnoe > 0) { 
00138     if (MEDcoordLire(fid,maa,mdim,coo2,MED_FULL_INTERLACE,2,profil,2,
00139                        &rep,nomcoo,unicoo) < 0) {
00140       MESSAGE("Erreur a la lecture des coordonnees des noeuds");
00141       ret = -1;
00142     } else {
00143       printf("Valeur de coo2 : ");
00144       for (i=0;i<nnoe*mdim;i++)
00145         printf("%4.2f ",coo2[i]);
00146       printf("\n");
00147     }
00148   }
00149 
00150   
00151   if (nnoe > 0) {
00152     if (MEDcoordLire(fid,maa,mdim,coo2,MED_FULL_INTERLACE,1,profil,2,
00153                        &rep,nomcoo,unicoo) < 0) {
00154       MESSAGE("Erreur a la lecture des coordonnees des noeuds");
00155       ret = -1;
00156     } else {
00157       printf("Valeur de coo2 : ");
00158       for (i=0;i<nnoe*mdim;i++) {
00159         printf("%4.2f ",coo2[i]);
00160         coo2[i] = 0.0;
00161       }
00162       printf("\n");
00163     }
00164   }
00165 
00166   
00167   if (nnoe > 0) {
00168     if (MEDcoordLire(fid,maa,mdim,coo2,MED_FULL_INTERLACE,MED_ALL,profil,2,
00169                        &rep,nomcoo,unicoo) < 0) {
00170       MESSAGE("Erreur a la lecture des coordonnees des noeuds");
00171       ret = -1;
00172     } else {
00173       printf("Valeur de coo2 : ");
00174       for (i=0;i<nnoe*mdim;i++) {
00175         printf("%4.2f ",coo2[i]);
00176         coo2[i] = 0.0;
00177       }
00178       printf("\n");
00179     }
00180   }
00181 
00182   
00183   if (nnoe > 0) {
00184     if (MEDcoordLire(fid,maa,mdim,coo2,MED_FULL_INTERLACE,MED_ALL,NULL,0,
00185                        &rep,nomcoo,unicoo) < 0) {
00186       MESSAGE("Erreur a la lecture des coordonnees des noeuds");
00187       ret = -1;
00188     } else {
00189       printf("Valeur de coo2 : ");
00190       for (i=0;i<nnoe*mdim;i++)
00191         printf("%4.2f ",coo2[i]);
00192       printf("\n");
00193     }
00194   }
00195 
00196   
00197   if ((nnoe > 0)) {
00198     if (MEDnomLire(fid,maa,nomnoe,nnoe,MED_NOEUD,0) < 0)
00199       inonoe = MED_FAUX;
00200     else
00201       inonoe = MED_VRAI;
00202   }
00203 
00204   
00205   if ((nnoe > 0)) {
00206     if (MEDnumLire(fid,maa,numnoe,nnoe,MED_NOEUD,0) < 0)
00207       inunoe = MED_FAUX;
00208     else
00209       inunoe = MED_VRAI;
00210   }
00211 
00212               
00213   if ((nnoe > 0))
00214     if (MEDfamLire(fid,maa,nufano,nnoe,MED_NOEUD,0) < 0) {
00215       MESSAGE("Erreur a la lecture des numeros de famille des noeuds");
00216       ret = -1;
00217     } 
00218 
00219   
00220   if (MEDfermer(fid) < 0){
00221       MESSAGE("Erreur a la fermeture du fichier");
00222       ret = -1;
00223     } 
00224 
00225   
00226   if (ret == 0 && nnoe > 0)
00227     {
00228       printf("Type de repere : %d \n",rep);
00229       printf("Nom des coordonnees : \n");
00230       for (i=0;i<mdim;i++)
00231         {
00232           strncpy(str,nomcoo+i*MED_TAILLE_PNOM,MED_TAILLE_PNOM);
00233           str[MED_TAILLE_PNOM] = '\0';
00234           printf("%s ",str);
00235         }
00236       printf("\nUnites des coordonnees : \n");
00237       for (i=0;i<mdim;i++)
00238         {
00239           strncpy(str,unicoo+i*MED_TAILLE_PNOM,MED_TAILLE_PNOM);
00240           str[MED_TAILLE_PNOM] = '\0';
00241           printf("%s ",str);
00242         }     
00243       printf("\nCoordonnees des noeuds : \n");
00244       for (i=0;i<nnoe*mdim;i++)
00245         printf("%f ",*(coo2+i));
00246       if (inonoe)
00247         {
00248           printf("\nNoms des noeuds : \n");
00249           for (i=0;i<nnoe;i++)
00250             {
00251               strncpy(str,nomnoe+i*MED_TAILLE_PNOM,MED_TAILLE_PNOM);
00252               str[MED_TAILLE_PNOM] = '\0';
00253               printf(" %s ",str);
00254             }
00255         }
00256       if (inunoe)
00257         {
00258           printf("\nNumeros des noeuds : \n");
00259           for (i=0;i<nnoe;i++)
00260               printf(IFORMAT" ",*(numnoe+i));
00261         }
00262       printf("\nNumeros des familles des noeuds : \n");
00263       for (i=0;i<nnoe;i++)
00264         printf(IFORMAT" ",*(nufano+i));
00265       printf("\n");
00266     }
00267 
00268   
00269   if (nnoe > 0) {
00270     free(coo1);
00271     free(coo2);
00272     free(nomnoe);
00273     free(numnoe);
00274     free(nufano);
00275   }
00276 
00277   return ret;
00278 }
00279 
00280 
00281 
00282