# UsesCase_MEDfield_13.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 13 : write a field on nodes elements in a MED file
    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_int nquad4 = 4;
    00037   const med_float quad4values_step1[4*4] = { 10000.,  20000.,  30000.,  40000.,
    00038                                              50000.,  60000.,  70000.,  80000.,
    00039                                              90000., 100000., 110000., 120000.,
    00040                                              130000., 140000., 150000., 160000. };
    00041   const med_float quad4values_step2[4*4] = { 100.,  200.,  300.,  400.,
    00042                                              500.,  600.,  700.,  800.,
    00043                                              900., 1000., 1100., 1200.,
    00044                                              1300., 1400., 1500., 1600. };
    00045   int ret=-1;
    00046
    00047   /* file creation */
    00048   fid = MEDfileOpen("UsesCase_MEDfield_13.med",MED_ACC_CREAT);
    00049   if (fid < 0) {
    00050     MESSAGE("ERROR : file creation ...");
    00051     goto ERROR;
    00052   }
    00053
    00054   /* create mesh link */
    00055   if (MEDlinkWr(fid,meshname,"./UsesCase_MEDmesh_1.med") < 0) {
    00056     MESSAGE("ERROR : create mesh link ...");
    00057     goto ERROR;
    00058   }
    00059
    00060   /*
    00061    * Temperature field  creation :
    00062    * - 1 component
    00063    * - component unit : celsius degree
    00064    * - mesh is the 2D unstructured mesh of UsecaseMEDmesh_1.c use case.
    00065    * - computation step unit in 'ms'
    00066    */
    00067   if (MEDfieldCr(fid, fieldname, MED_FLOAT64,
    00068                  ncomponent, componentname, componentunit,
    00069                  "ms", meshname) < 0) {
    00070     MESSAGE("ERROR : create field");
    00071     goto ERROR;
    00072   }
    00073
    00074   /* two computation steps */
    00075   /* write values at nodes elements : 4 MED_QUAD4 */
    00076
    00077   /* STEP 1 : dt1 = 5.5, it = 1*/
    00078   /* MED_QUAD4  : with no profile */
    00079   if (MEDfieldValueWithProfileWr(fid, fieldname, 1, 1, 5.5, MED_NODE_ELEMENT, MED_QUAD4,
    00080                                  MED_COMPACT_PFLMODE, MED_NO_PROFILE, MED_NO_LOCALIZATION,
    00081                                  MED_FULL_INTERLACE, MED_ALL_CONSTITUENT,
    00082                                  nquad4, (unsigned char*) quad4values_step1) < 0) {
    00083     MESSAGE("ERROR : write field values on MED_QUAD4 ");
    00084     goto ERROR;
    00085   }
    00086
    00087   /* STEP 2 : dt2 = 8.9, it = 1*/
    00088   /* MED_QUAD4 : with no profile */
    00089   if (MEDfieldValueWithProfileWr(fid, fieldname, 2, 1, 8.9, MED_NODE_ELEMENT, MED_QUAD4,
    00090                                  MED_COMPACT_PFLMODE, MED_NO_PROFILE, MED_NO_LOCALIZATION,
    00091                                  MED_FULL_INTERLACE, MED_ALL_CONSTITUENT,
    00092                                  nquad4, (unsigned char*) quad4values_step2) < 0) {
    00093     MESSAGE("ERROR : write field values on MED_QUAD4 ... ");
    00094     goto ERROR;
    00095   }
    00096
    00097   ret=0;
    00098  ERROR:
    00099
    00100   /* close file */
    00101   if (MEDfileClose(fid) < 0) {
    00102     MESSAGE("ERROR : close file ...");
    00103     ret=-1;
    00104   }
    00105
    00106   return ret;
    00107 }
    00108