test10.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 #define _a 0.446948490915965
00018 #define _b 0.091576213509771
00019 #define _p1 0.11169079483905
00020 #define _p2 0.0549758718227661
00021 
00022 /******************************************************************************
00023  * - Nom du fichier : test10.c
00024  *
00025  * - Description : ecriture de champs de resultats MED 
00026  *
00027  *****************************************************************************/
00028 
00029 #include <med.h>
00030 #define MESGERR 1
00031 #include "med_utils.h"
00032 #include <string.h>
00033 
00034 #ifdef DEF_LECT_ECR
00035 #define MODE_ACCES MED_ACC_RDWR
00036 #elif DEF_LECT_AJOUT
00037 #define MODE_ACCES MED_ACC_RDEXT
00038 #else
00039 #define MODE_ACCES MED_ACC_CREAT
00040 #endif
00041 
00042 #ifndef USER_INTERLACE
00043 #define USER_INTERLACE MED_FULL_INTERLACE
00044 #endif
00045 
00046 #define USER_MODE MED_COMPACT_PFLMODE
00047 
00048 int main (int argc, char **argv)
00049 
00050 
00051 {
00052   med_err ret=0;
00053   med_idt fid;
00054 
00055 
00056 
00057   /* Maillage support aux champs*/
00058   /* Ces maillages sont vides*/
00059   char maa1[MED_NAME_SIZE+1]= "maa1";
00060   char maa2[MED_NAME_SIZE+1]= "maa2";
00061   char * lien_maa2 = "./testfoo.med";
00062   char maa3[MED_NAME_SIZE+1]= "maa3";
00063 
00064 
00065   /* Caract�ristiques du champ n� 1 sur TRIA6 */
00066   char nomcha1[MED_NAME_SIZE+1]  = "champ reel";
00067   char comp1[2*MED_SNAME_SIZE+1] = "comp1           comp2           ";
00068                                    /*12345678901234561234567890123456*/
00069   char unit1[2*MED_SNAME_SIZE+1] = "unit1           unit2           ";
00070   med_int ncomp1  = 2;
00071   /* Caract�ristiques du model n� 1 de localisation des points de gauss pour le champ n�1*/
00072   med_int ngauss1_1 = 6;
00073   char gauss1_1[MED_NAME_SIZE+1]  = "Model n1";
00074   med_float refcoo1[12] = { -1.0,1.0, -1.0,-1.0, 1.0,-1.0, -1.0,0.0, 0.0,-1.0, 0.0,0.0 };
00075 
00076   /* Constantes */
00077 
00078   med_float gscoo1_1[12] = { 2*_b-1, 1-4*_b, 2*_b-1, 2*_b-1, 1-4*_b,
00079                              2*_b-1, 1-4*_a, 2*_a-1, 2*_a-1, 1-4*_a, 2*_a-1, 2*_a-1 };
00080   med_float wg1_1[6] = { 4*_p2, 4*_p2, 4*_p2, 4*_p1, 4*_p1, 4*_p1 };
00081 
00082   med_int   nval1_1= 1*6; /*1 valeurs et 6 points de gauss par valeur */
00083   med_int   _nent1_1= 1; /*1 valeurs et 6 points de gauss par valeur */
00084   med_float valr1_1[1*6*2]  = {0.0,1.0, 2.0,3.0, 10.0,11.0, 12.0,13.0, 20.0,21.0, 22.0,23.0};  /* 2 composantes*/
00085   /* Caract�ristiques du model n� 2 de localisation des points de gauss pour le champ n�1*/
00086   med_int ngauss1_2 = 3;
00087   char gauss1_2[MED_NAME_SIZE+1]  = "Model n2";
00088   med_float gscoo1_2[6] = { -2.0/3,1.0/3, -2.0/3,-2.0/3, 1.0/3,-2.0/3  };
00089   med_float wg1_2[3] = { 2.0/3, 2.0/3, 2.0/3 };
00090   med_int   nval1_2= 2*3; /*2 valeurs et 3 points de gauss par valeur */
00091   med_int   _nent1_2= 2; /*2 valeurs et 3 points de gauss par valeur */
00092   med_float valr1_2[2*3*2]  = {0.0,1.0, 2.0,3.0, 10.0,11.0,   12.0,13.0, 20.0,21.0, 22.0,23.0};  /* 2 composantes*/
00093   med_float valr1_2p[2*3*2]  = {                              12.0,13.0, 20.0,21.0, 22.0,23.0};  /* 2 composantes*/
00094  /* Caract�ristiques du model n� 3 sans points de gauss pour le champ n�1*/
00095   med_int   nval1_3= 6; /*6 valeurs et pas de points de gauss */
00096   med_int   _nent1_3= 6; /*6 valeurs et pas de points de gauss */
00097   med_float valr1_3[2*3*2]  = {0.0,1.0, 2.0,3.0, 10.0,11.0, 12.0,13.0, 20.0,21.0, 22.0,23.0};  /* 2 composantes*/
00098   med_float valr1_3p[2*2*2] = {         2.0,3.0, 10.0,11.0                                 };  /* 2 composantes profil1 */
00099 
00100   /* Caract�ristiques du champ n� 2 */
00101   char nomcha2[MED_NAME_SIZE+1]  = "champ entier";
00102   char comp2[3*MED_SNAME_SIZE+1] = "comp1           comp2           comp3           ";
00103                                    /*123456789012345612345678901234561234567890123456*/
00104   char unit2[3*MED_SNAME_SIZE+1] = "unit1           unit2           unit3           ";
00105   med_int ncomp2  = 3; 
00106   med_int nval2 = 5;   /*5 valeurs */
00107   med_int   valr2[5*3  ]  = {0,1,2, 10,11,12, 20,21,22, 30,31,32, 40,41,42};              /* 3 composantes*/
00108   med_int   valr2p[3*3  ] = {0,1,2,           20,21,22,           40,41,42};              /* 3 composantes*/
00109 
00110   /* Profils utilis�s */
00111   char nomprofil1[MED_NAME_SIZE+1]  = "PROFIL(champ(1))";
00112   char nomprofil1b[MED_NAME_SIZE+1] = "PROFIL(champ(1b))";
00113   char nomprofil2[MED_NAME_SIZE+1]  = "PROFIL(champ2)";
00114   med_int profil1[2] = { 2, 3 };
00115   med_int profil2[3] = { 1, 3, 5 };
00116 
00117 
00118   /* Caract�ristiques du champ n� 3 */
00119   char nomcha3[MED_NAME_SIZE+1]  = "champ entier 3";
00120   char comp3[3*MED_SNAME_SIZE+1] = "comp1           comp2           ";
00121                                    /*123456789012345612345678901234561234567890123456*/
00122   char unit3[3*MED_SNAME_SIZE+1] = "unit1           unit2           ";
00123   char dtunit[MED_SNAME_SIZE+1] = "s";
00124   med_int ncomp3  = 2;
00125   med_int nval3 = 5*4;     /*5 valeurs et 4 noeuds par element*/
00126   med_int _nent3 = 5;     /*5 valeurs et 4 noeuds par element*/
00127   med_int valr3[5*4*2]   = {0,1, 10,11, 20,21, 30,31,
00128                             40,41, 50,51, 60,61, 70,71,
00129                             80,81, 90,91, 100,101, 110,111,
00130                             120,121, 130,131, 140,141, 150,151,
00131                             160,161, 170,171, 180,181, 190,191};    /* 2 composantes*/
00132   med_int valr3p[3*4*2]  = {0,1, 10,11, 20,21, 30,31,
00133                             80,81, 90,91, 100,101, 110,111,
00134                             160,161, 170,171, 180,181, 190,191};    /* 2 composantes*/
00135 
00136 
00137   char nomcoo[3*MED_SNAME_SIZE+1] = "x               y               z               ";
00138   char unicoo[3*MED_SNAME_SIZE+1] = "cm              cm              cm              ";
00139 
00140 
00141 
00142 
00143   /* ouverture du fichier */
00144   if ((fid = MEDfileOpen("test10.med",MODE_ACCES)) < 0){
00145     MESSAGE("Erreur à l'ouverture du fichier : ");
00146     return -1;
00147   }
00148 
00149   /* creation de maa1 de dimension 3*/
00150   if (MEDmeshCr( fid, maa1, 3, 3, MED_UNSTRUCTURED_MESH,
00151                  "Maillage vide","s", MED_SORT_DTIT,
00152                  MED_CARTESIAN, nomcoo, unicoo) < 0) {
00153     MESSAGE("Erreur a la creation du maillage : "); SSCRUTE(maa1);
00154     ret = -1;
00155   }
00156 
00157 
00158   /* creation de maa3 de dimension 3*/
00159   if (MEDmeshCr( fid, maa3, 3, 3, MED_UNSTRUCTURED_MESH,
00160                  "Maillage vide","s", MED_SORT_DTIT,
00161                  MED_CARTESIAN, nomcoo, unicoo) < 0) {
00162     MESSAGE("Erreur a la creation du maillage : "); SSCRUTE(maa3);
00163     ret = -1;
00164   }
00165 
00166 
00167   /* creation du champ r�el n�1 */
00168   if ( MEDfieldCr(fid,nomcha1,MED_FLOAT64,ncomp1,comp1,unit1,dtunit,maa1 ) < 0) {
00169     MESSAGE("Erreur à la création du champ : ");SSCRUTE(nomcha1);
00170     ret = -1;
00171   };
00172 
00173   /* creation du champ entier n�2 */
00174   if ( MEDfieldCr(fid,nomcha2,MED_INT32,ncomp2,comp2,unit2,dtunit,maa2 ) < 0) {
00175     MESSAGE("Erreur à la création du champ : ");SSCRUTE(nomcha2);
00176     ret = -1;
00177   };
00178 
00179   /* creation du lien au fichier distant contenant maa2 */
00180   if (MEDlinkWr(fid,maa2,lien_maa2) < 0) {
00181     MESSAGE("Erreur à la création du lien : ");SSCRUTE(lien_maa2);
00182     ret = -1;
00183   };
00184 
00185   /* creation de la localisation des points de Gauss mod�le n�1 */
00186   if (MEDlocalizationWr(fid, gauss1_1, MED_TRIA6, MED_TRIA6/100, refcoo1, USER_INTERLACE,
00187                         ngauss1_1, gscoo1_1, wg1_1,
00188                         MED_NO_INTERPOLATION, MED_NO_MESH_SUPPORT ) < 0) {
00189     MESSAGE("Erreur à la création du mod�le n�1 : ");SSCRUTE(gauss1_1);
00190     ret = -1;
00191   };
00192 
00193    /* creation de la localisation des points de Gauss mod�le n�2 */
00194   if (MEDlocalizationWr(fid, gauss1_2, MED_TRIA6, MED_TRIA6/100, refcoo1, USER_INTERLACE,
00195                         ngauss1_2, gscoo1_2, wg1_2,
00196                         MED_NO_INTERPOLATION, MED_NO_MESH_SUPPORT) < 0) {
00197     MESSAGE("Erreur à la création du mod�le n�1 : ");SSCRUTE(gauss1_2);
00198     ret = -1;
00199   };
00200  
00201   /* ecriture du champ n�1*/
00202   /* enregistre uniquement les composantes n�2 de valr1_1, et n'utilise ni pas de temps ni n� d'ordre*/
00203 
00204   if ( MEDfieldValueWithProfileWr(fid, nomcha1,MED_NO_DT,MED_NO_IT,0.0,MED_CELL,MED_TRIA6,USER_MODE,MED_ALLENTITIES_PROFILE,
00205                        gauss1_1,USER_INTERLACE, 2, _nent1_1, (unsigned char*)valr1_1 ) < 0) {
00206     MESSAGE("Erreur à l'écriture du champ : ");
00207     SSCRUTE(nomcha1);ISCRUTE_int(MED_NO_DT);ISCRUTE_int(MED_NO_IT);SSCRUTE(MED_NO_PROFILE);
00208     SSCRUTE(maa1);
00209     ret = -1;
00210   };
00211 
00212   
00213 
00214   /* enregistre uniquement les composantes n�1 de valr1_1, et n'utilise ni pas de temps ni n� d'ordre */
00215 
00216   if ( MEDfieldValueWithProfileWr(fid, nomcha1,MED_NO_DT,MED_NO_IT,0.0,MED_CELL,MED_TRIA6,USER_MODE,MED_ALLENTITIES_PROFILE,
00217                        gauss1_1,USER_INTERLACE, 1, _nent1_1, (unsigned char*)valr1_1 ) < 0) {
00218     MESSAGE("Erreur à l'écriture du champ : ");
00219     SSCRUTE(nomcha1);ISCRUTE_int(MED_NO_DT);ISCRUTE_int(MED_NO_IT);SSCRUTE(MED_NO_PROFILE);
00220     SSCRUTE(maa1);
00221     ret = -1;
00222   };
00223 
00224   /* enregistre uniquement les composantes n�1 de valr1_2, au pas de temps n�1(5.5), n'utilise pas de n�d'ordre*/
00225   /* ce champ repose sur le maillage maa2 qui est distant */
00226 
00227   if ( MEDfieldValueWithProfileWr(fid, nomcha1,1,MED_NO_IT,5.5,MED_CELL,MED_TRIA6,USER_MODE,MED_ALLENTITIES_PROFILE,
00228                        gauss1_2,USER_INTERLACE, 1, _nent1_2, (unsigned char*)valr1_2 ) < 0) {
00229     MESSAGE("Erreur à l'écriture du champ : ");
00230     SSCRUTE(nomcha1);ISCRUTE_int(MED_NO_IT);SSCRUTE(MED_NO_PROFILE);
00231     SSCRUTE(maa1);
00232     ret = -1;
00233   };
00234 
00235 /*Ce test utilise un deuxi�me maillag epour un m�me champ, ceci n'existe plus en 3.0*/
00236   /* enregistre uniquement les composantes n�2 de valr1_2, au pas de temps n�1(5.5), n'utilise pas de n�d'ordre*/
00237   /* ce champ repose sur le maillage maa1 qui est local */
00238 
00239   /*Ce test utilise un deuxi�me maillag epour un m�me champ, ceci n'existe plus en 3.0*/
00240   if ( MEDfieldValueWithProfileWr(fid, nomcha1,1,1,5.5,MED_CELL,MED_TRIA6,USER_MODE,MED_ALLENTITIES_PROFILE,
00241                        gauss1_1,USER_INTERLACE, 2, _nent1_1, (unsigned char*)valr1_1 ) < 0) {
00242     MESSAGE("Erreur à l'écriture du champ : ");
00243     SSCRUTE(nomcha1);ISCRUTE_int(MED_NO_DT);ISCRUTE_int(MED_NO_IT);SSCRUTE(MED_NO_PROFILE);
00244     SSCRUTE(maa1);
00245     ret = -1;
00246   };
00247 
00248 
00249     /* enregistre uniquement les composantes n�1 de valr1_1, au pas de temps n�1(5.5), et n�d'it�ration n�2*/
00250     /* ce champ repose sur le maillage maa3 qui est local */
00251 
00252   if ( MEDfieldValueWithProfileWr(fid, nomcha1,1,2,5.5,MED_CELL,MED_TRIA6,USER_MODE,MED_ALLENTITIES_PROFILE,
00253                        gauss1_2,USER_INTERLACE, 1, _nent1_2, (unsigned char*)valr1_2 ) < 0) {
00254     MESSAGE("Erreur à l'écriture du champ : ");
00255     SSCRUTE(nomcha1);SSCRUTE(MED_NO_PROFILE);
00256     SSCRUTE(maa1);
00257     ret = -1;
00258   };
00259 
00260   /* Creation d'un profil (selection  du deuxieme �l�ment de valr1_1) */
00261   /* On n'utilise que la premi�re valeur (2) du profil */
00262   if ( MEDprofileWr(fid,nomprofil1,1,profil1) < 0) {
00263     MESSAGE("Erreur à l'écriture du profil : ");
00264     SSCRUTE(nomprofil1);
00265     ret = -1;
00266   };
00267 
00268 
00269   if ( MEDprofileWr(fid,nomprofil1b,1,profil1) < 0) {
00270     MESSAGE("Erreur à l'écriture du profil : ");
00271     SSCRUTE(nomprofil1b);
00272     ret = -1;
00273   };
00274 
00275 
00276 
00277 
00278   /* enregistre toutes les composantes du deuxi�me �l�ment de valr1_1 (premier �l�ment en stockage compact de valr1p),
00279      au pas de temps n�2(5.6), et n�d'it�ration n�2*/
00280   if ( MEDfieldValueWithProfileWr(fid, nomcha1,2,2,5.6,MED_CELL,MED_TRIA6,USER_MODE,nomprofil1,
00281                        MED_NO_LOCALIZATION,USER_INTERLACE, MED_ALL_CONSTITUENT, nval1_3, (unsigned char*)valr1_3p ) < 0) {
00282     MESSAGE("Erreur à l'écriture du champ : ");
00283     SSCRUTE(nomcha1);SSCRUTE(MED_NO_PROFILE);
00284     SSCRUTE(maa1);
00285     ret = -1;
00286   };
00287 
00288   /* enregistre toutes les composantes du deuxi�me �l�ment de valr1_1 (premier �l�ment en stockage compact de valr1p),
00289      au pas de temps n�2(5.6), et n�d'it�ration n�2 */
00290 
00291   if ( MEDfieldValueWithProfileWr(fid, nomcha1,2,2,5.6,MED_CELL,MED_TRIA6,USER_MODE,nomprofil1b,
00292                        gauss1_2,USER_INTERLACE, MED_ALL_CONSTITUENT, _nent1_2, (unsigned char*)valr1_2p ) < 0) {
00293     MESSAGE("Erreur à l'écriture du champ : ");
00294     SSCRUTE(nomcha1);SSCRUTE(MED_NO_PROFILE);
00295     SSCRUTE(maa1);
00296     ret = -1;
00297   };
00298 
00299 
00300   if ( MEDfieldValueWithProfileWr(fid, nomcha1,3,2,5.7,MED_CELL,MED_TRIA6,USER_MODE,nomprofil1,
00301                        MED_NO_LOCALIZATION,USER_INTERLACE, 2, _nent1_3, (unsigned char*)valr1_3p ) < 0) {
00302     MESSAGE("Erreur à l'écriture du champ : ");
00303     SSCRUTE(nomcha1);SSCRUTE(MED_NO_PROFILE);
00304     SSCRUTE(maa1);
00305     ret = -1;
00306   };
00307 
00308 
00309   /* Ecriture du champ n� 2 */
00310     
00311 
00312   if ( MEDfieldValueWr(fid, nomcha2,MED_NO_DT,MED_NO_IT,0,
00313                                   MED_DESCENDING_EDGE,MED_SEG2,
00314                                   USER_INTERLACE, 1, nval2, (unsigned char*)valr2 ) < 0) {
00315     MESSAGE("Erreur à l'écriture du champ : ");
00316     SSCRUTE(nomcha1);ISCRUTE_int(MED_NO_DT);ISCRUTE_int(MED_NO_IT);SSCRUTE(MED_NO_PROFILE);
00317     SSCRUTE(maa1);
00318     ret = -1;
00319   };
00320 
00321 
00322   if ( MEDfieldValueWr(fid, nomcha2,MED_NO_DT,MED_NO_IT,0,MED_NODE,MED_NONE,
00323                                   USER_INTERLACE, 2, nval2, (unsigned char*)valr2 ) < 0) {
00324     MESSAGE("Erreur à l'écriture du champ : ");
00325     SSCRUTE(nomcha1);ISCRUTE_int(MED_NO_DT);ISCRUTE_int(MED_NO_IT);SSCRUTE(MED_NO_PROFILE);
00326     SSCRUTE(maa1);
00327     ret = -1;
00328   };
00329 
00330 
00331   if ( MEDfieldValueWr(fid, nomcha2,MED_NO_DT,MED_NO_IT,0,MED_DESCENDING_FACE,MED_TRIA6,
00332                                   USER_INTERLACE, 3, nval2, (unsigned char*)valr2 ) < 0) {
00333     MESSAGE("Erreur à l'écriture du champ : ");
00334     SSCRUTE(nomcha1);ISCRUTE_int(MED_NO_DT);ISCRUTE_int(MED_NO_IT);SSCRUTE(MED_NO_PROFILE);
00335     SSCRUTE(maa1);
00336     ret = -1;
00337   };
00338 
00339   /* Creation d'un profil (selection  des �l�ments 1,3,5 de valr2) */
00340   /* On utilise les trois valeurs du profil */
00341   if ( MEDprofileWr(fid,nomprofil2,3,profil2) < 0) {
00342     MESSAGE("Erreur à l'écriture du profil : ");
00343     SSCRUTE(nomprofil2);
00344     ret = -1;
00345   };
00346 
00347 
00348   if ( MEDfieldValueWithProfileWr(fid, nomcha2,MED_NO_DT,MED_NO_IT,0,MED_CELL,MED_TRIA6,USER_MODE,nomprofil2,
00349                        MED_NO_LOCALIZATION,USER_INTERLACE, 3, nval2, (unsigned char*)valr2p ) < 0) {
00350     MESSAGE("Erreur à l'écriture du champ : ");
00351     SSCRUTE(nomcha1);ISCRUTE_int(MED_NO_DT);ISCRUTE_int(MED_NO_IT);SSCRUTE(MED_NO_PROFILE);
00352     SSCRUTE(maa1);
00353     ret = -1;
00354   };
00355 
00356   /* creation du champ entier n�3 */
00357   if ( MEDfieldCr(fid,nomcha3,MED_INT32,ncomp3,comp3,unit3,dtunit,maa1) < 0) {
00358     MESSAGE("Erreur à la création du champ : ");SSCRUTE(nomcha3);
00359     ret = -1;
00360   };
00361   
00362   /* Ecriture du champ n� 3 */
00363 
00364   if ( MEDfieldValueWr(fid, nomcha3,MED_NO_DT,MED_NO_IT,0,MED_CELL,MED_QUAD4,
00365                                   USER_INTERLACE, 1, nval3, (unsigned char*)valr3 ) < 0) {
00366     MESSAGE("Erreur à l'écriture du champ : ");
00367     SSCRUTE(nomcha1);ISCRUTE_int(MED_NO_DT);ISCRUTE_int(MED_NO_IT);SSCRUTE(MED_NO_PROFILE);
00368     SSCRUTE(maa1);
00369     ret = -1;
00370   };
00371 
00372   if ( MEDfieldValueWr(fid, nomcha3,MED_NO_DT,MED_NO_IT,0,MED_NODE_ELEMENT,MED_QUAD4,
00373                                   USER_INTERLACE, MED_ALL_CONSTITUENT, _nent3, (unsigned char*)valr3 ) < 0) {
00374     MESSAGE("Erreur à l'écriture du champ : ");
00375     SSCRUTE(nomcha1);ISCRUTE_int(MED_NO_DT);ISCRUTE_int(MED_NO_IT);SSCRUTE(MED_NO_PROFILE);
00376     SSCRUTE(maa1);
00377     ret = -1;
00378   };
00379 
00380   if ( MEDfieldValueWithProfileWr(fid, nomcha3,MED_NO_DT,MED_NO_IT,0,MED_NODE_ELEMENT,MED_QUAD4,USER_MODE,nomprofil2,
00381                        MED_NO_LOCALIZATION,USER_INTERLACE, MED_ALL_CONSTITUENT, _nent3, (unsigned char*)valr3p ) < 0) {
00382     MESSAGE("Erreur à l'écriture du champ : ");
00383     SSCRUTE(nomcha1);ISCRUTE_int(MED_NO_DT);ISCRUTE_int(MED_NO_IT);SSCRUTE(MED_NO_PROFILE);
00384     SSCRUTE(maa1);
00385     ret = -1;
00386   };
00387 
00388 
00389   /* fermeture du fichier */
00390   if ( MEDfileClose(fid) < 0 ) ret=-1;
00391 
00392   return ret;
00393 }
00394 
00395 
00396 
00397 

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