# UsesCase_MEDfield_7.c

Aller à la documentation de ce fichier.

    00001 /*  This file is part of MED.
    00002  *
    00003  *  COPYRIGHT (C) 1999 - 2011  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  * Field use case 7 : write a field with computing steps and profiles
    00020  */
    00021
    00022 #include <med.h>
    00023 #define MESGERR 1
    00024 #include <med_utils.h>
    00025
    00026 #include <string.h>
    00027
    00028
    00029 int main (int argc, char **argv) {
    00030   med_idt fid;
    00031   const char meshname[MED_NAME_SIZE+1] = "2D unstructured mesh";
    00032   const char fieldname[MED_NAME_SIZE+1] = "TEMPERATURE_FIELD";
    00033   const med_int ncomponent = 1;
    00034   const char componentname[MED_SNAME_SIZE+1] = "TEMPERATURE";
    00035   const char componentunit[MED_SNAME_SIZE+1] = "C";
    00036   const med_float tria3values_step1_profile1[3] = {1000.,               4000.,                      8000.};
    00037   const med_float tria3values_step2_profile1[8] = {1500.,    0.,    0., 4500.,    0.,    0.,    0., 8500.};
    00038   const med_float tria3values_step2_profile2[8] = {   0., 2500., 3500.,    0., 5500., 6500., 7500.,   0.};
    00039   const med_float quad4values_step1[4] = {10000., 20000., 30000., 40000.};
    00040   const med_float quad4values_step2[4] = {15000., 25000., 35000., 45000.};
    00041   const char profile1name[MED_NAME_SIZE+1] = "MED_TRIA3_PROFILE1";
    00042   const med_int profile1[3] = {1, 4, 8};
    00043   const med_int profile1size = 3;
    00044   const char profile2name[MED_NAME_SIZE+1] = "MED_TRIA3_PROFILE2";
    00045   const med_int profile2[5] = {2, 3, 5, 6, 7};
    00046   const med_int profile2size = 5;
    00047   const med_int ntria3 = 8;
    00048   const med_int nquad4 = 4;
    00049   int ret=-1;
    00050
    00051   /* file creation */
    00052   fid = MEDfileOpen("UsesCase_MEDfield_7.med",MED_ACC_CREAT);
    00053   if (fid < 0) {
    00054     MESSAGE("ERROR : file creation ...");
    00055     goto ERROR;
    00056   }
    00057
    00058   /* create mesh link */
    00059   if (MEDlinkWr(fid,meshname,"./UsesCase_MEDmesh_1.med") < 0) {
    00060     MESSAGE("ERROR : create mesh link ...");
    00061     goto ERROR;
    00062   }
    00063
    00064   /* create the profiles in the file */
    00065   if (MEDprofileWr(fid, profile1name, profile1size, profile1 ) < 0) {
    00066     MESSAGE("ERROR : create profile ...");
    00067     goto ERROR;
    00068   }
    00069
    00070   if (MEDprofileWr(fid, profile2name, profile2size, profile2 ) < 0) {
    00071     MESSAGE("ERROR : create profile ...");
    00072     goto ERROR;
    00073   }
    00074
    00075   /* field creation : temperature field  : 1 component in celsius degree
    00076    *                  the mesh is the 2D unstructured mesh of UsecaseMEDmesh_1.c
    00077    *                  use case.
    00078    *                  Computation step unit in 'ms'
    00079    */
    00080   if (MEDfieldCr(fid, fieldname, MED_FLOAT64, ncomponent,
    00081                  componentname, componentunit,"ms", meshname) < 0) {
    00082     MESSAGE("ERROR : create field");
    00083     goto ERROR;
    00084   }
    00085
    00086   /* two computation steps */
    00087   /* write values at cell centers : 8 MED_TRIA3 and 4 MED_QUAD4 */
    00088
    00089   /* STEP 1 : dt1 = 5.5, it = 1*/
    00090   /* MED_TRIA3 : with a profile of 3 values in compact memory storage mode */
    00091   if (MEDfieldValueWithProfileWr(fid, fieldname, 1, 1, 5.5, MED_CELL,MED_TRIA3,
    00092                                  MED_COMPACT_PFLMODE, profile1name, MED_NO_LOCALIZATION,
    00093                                  MED_FULL_INTERLACE, MED_ALL_CONSTITUENT, ntria3,
    00094                                  (unsigned char*) tria3values_step1_profile1) < 0) {
    00095     MESSAGE("ERROR : write field values on MED_TRIA3");
    00096     goto ERROR;
    00097   }
    00098    /* MED_QUAD4  : with no profile */
    00099   if (MEDfieldValueWithProfileWr(fid, fieldname, 1, 1, 5.5, MED_CELL, MED_QUAD4,
    00100                                  MED_COMPACT_PFLMODE, MED_NO_PROFILE, MED_NO_LOCALIZATION,
    00101                                  MED_FULL_INTERLACE, MED_ALL_CONSTITUENT, nquad4,
    00102                                  (unsigned char*) quad4values_step1) < 0) {
    00103     MESSAGE("ERROR : write field values on MED_QUAD4 ");
    00104     goto ERROR;
    00105   }
    00106
    00107   /* STEP 2 : dt2 = 8.9, it = 1*/
    00108   /* MED_TRIA3 : with a profile of 3 values then a profile of 5 values in global memory storage mode */
    00109   if (MEDfieldValueWithProfileWr(fid, fieldname, 2 , 1 , 8.9 , MED_CELL, MED_TRIA3,
    00110                                  MED_GLOBAL_PFLMODE, profile1name, MED_NO_LOCALIZATION,
    00111                                  MED_FULL_INTERLACE, MED_ALL_CONSTITUENT, ntria3,
    00112                                  (unsigned char*) tria3values_step2_profile1) < 0) {
    00113     MESSAGE("ERROR : write field values on MED_TRIA3 ...");
    00114     goto ERROR;
    00115   }
    00116   if (MEDfieldValueWithProfileWr(fid, fieldname, 2 , 1 , 8.9 , MED_CELL, MED_TRIA3,
    00117                                  MED_GLOBAL_PFLMODE, profile2name, MED_NO_LOCALIZATION,
    00118                                  MED_FULL_INTERLACE, MED_ALL_CONSTITUENT, ntria3,
    00119                                  (unsigned char*) tria3values_step2_profile2) < 0) {
    00120     MESSAGE("ERROR : write field values on MED_TRIA3 ...");
    00121     goto ERROR;
    00122   }
    00123
    00124   /* MED_QUAD4 : with no profile */
    00125   if (MEDfieldValueWithProfileWr(fid, fieldname, 2, 1, 8.9, MED_CELL, MED_QUAD4,
    00126                       MED_COMPACT_PFLMODE, MED_NO_PROFILE, MED_NO_LOCALIZATION,
    00127                       MED_FULL_INTERLACE, MED_ALL_CONSTITUENT, nquad4,
    00128                       (unsigned char*) quad4values_step2) < 0) {
    00129     MESSAGE("ERROR : write field values on MED_QUAD4 ... ");
    00130     goto ERROR;
    00131   }
    00132
    00133   ret=0;
    00134  ERROR:
    00135
    00136   /* close file */
    00137   if (MEDfileClose(fid) < 0) {
    00138     MESSAGE("ERROR : close file ...");
    00139     ret=-1;
    00140   }
    00141
    00142   return ret;
    00143 }
    00144