# UsesCase_MEDfield_1.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  * Field use case 1 : write a field on mesh vertices and elements
    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 verticesvalues[15] = {  0.,   100., 200.,  300.,  400.,
    00037                                           500.,   600., 700.,  800.,  900,
    00038                                           1000., 1100, 1200., 1300., 1500. };
    00039   const med_int nnodes = 15;
    00040   const med_float tria3values[8] = {1000., 2000., 3000., 4000.,
    00041                                     5000., 6000., 7000., 8000.};
    00042   const med_int ntria3 = 8;
    00043   const med_float quad4values[4] = {10000., 20000., 30000., 4000.};
    00044   const med_int nquad4 = 4;
    00045   int ret=-1;
    00046
    00047   /* file creation */
    00048   fid = MEDfileOpen("UsesCase_MEDfield_1.med",MED_ACC_CREAT);
    00049   if (fid < 0) {
    00050     MESSAGE("ERROR : file creation ...");
    00051     goto ERROR;
    00052   }
    00053
    00054   /* field creation : temperature field  : 1 component in celsius degree
    00055    *                  the mesh is the 2D unstructured mesh of UsecaseMEDmesh_1.c
    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   if (MEDfieldCr(fid, fieldname, MED_FLOAT64,
    00065                  ncomponent, componentname, componentunit,"",
    00066                  meshname) < 0) {
    00067     MESSAGE("ERROR : create field");
    00068     goto ERROR;
    00069   }
    00070
    00071   /* write field values at vertices */
    00072   if (MEDfieldValueWr(fid, fieldname, MED_NO_DT, MED_NO_IT, 0.0, MED_NODE,
    00073                       MED_NONE, MED_FULL_INTERLACE, MED_ALL_CONSTITUENT,
    00074                       nnodes,(unsigned char*) verticesvalues) < 0) {
    00075     MESSAGE("ERROR : write field values on vertices");
    00076     goto ERROR;
    00077   }
    00078
    00079   /* write values at cell centers : 8 MED_TRIA3 and 4 MED_QUAD4 */
    00080   /* MED_TRIA3 */
    00081   if (MEDfieldValueWr(fid, fieldname, MED_NO_DT, MED_NO_IT, 0.0, MED_CELL,
    00082                       MED_TRIA3, MED_FULL_INTERLACE, MED_ALL_CONSTITUENT,
    00083                       ntria3, (unsigned char*) tria3values) < 0) {
    00084     MESSAGE("ERROR : write field values on MED_TRIA3");
    00085     goto ERROR;
    00086   }
    00087   /* MED_QUAD4 */
    00088   if (MEDfieldValueWr(fid, fieldname, MED_NO_DT, MED_NO_IT, 0.0, MED_CELL,
    00089                       MED_QUAD4, MED_FULL_INTERLACE, MED_ALL_CONSTITUENT,
    00090                       nquad4, (unsigned char*) quad4values) < 0) {
    00091     MESSAGE("ERROR : write field values on MED_QUAD4 ");
    00092     goto ERROR;
    00093   }
    00094
    00095   ret=0;
    00096  ERROR :
    00097
    00098   /* close file */
    00099   if (MEDfileClose(fid) < 0) {
    00100     MESSAGE("ERROR : close file ...");
    00101     ret = -1;
    00102   }
    00103
    00104   return ret;
    00105 }
    00106