UsesCase_MEDfield_4.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 
00018 /* 
00019  * Field use case 4 : write a field with computing steps
00020  */
00021 
00022 
00023 #include <med.h>
00024 #define MESGERR 1
00025 #include <med_utils.h>
00026 
00027 #include <string.h>
00028 
00029 
00030 int main (int argc, char **argv) {
00031   med_idt fid;
00032   const char meshname[MED_NAME_SIZE+1] = "2D unstructured mesh";
00033   const char fieldname[MED_NAME_SIZE+1] = "TEMPERATURE_FIELD";
00034   const med_int ncomponent = 1;
00035   const char componentname[MED_SNAME_SIZE+1] = "TEMPERATURE";
00036   const char componentunit[MED_SNAME_SIZE+1] = "C";
00037   const med_int ntria3 = 8;
00038   const med_int nquad4 = 4;
00039   const med_float tria3values_step1[8] = {1000., 2000., 3000., 4000., 
00040                                           5000., 6000., 7000., 8000.};
00041   const med_float quad4values_step1[4] = {10000., 20000., 30000., 4000.};
00042   const med_float tria3values_step2[8] = {1500., 2500., 3500., 4500., 
00043                                           5500., 6500., 7500., 8500.};
00044   const med_float quad4values_step2[4] = {15000., 25000., 35000., 45000.};
00045   int ret=-1;
00046 
00047   /* file creation */
00048   fid = MEDfileOpen("UsesCase_MEDfield_4.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   /* field creation : temperature field  : 1 component in celsius degree
00061    *                  the mesh is the 2D unstructured mesh of UsecaseMEDmesh_1.c
00062    *                  use case. Computation step unit in 'ms'
00063    */ 
00064   if (MEDfieldCr(fid, fieldname, MED_FLOAT64, 
00065                  ncomponent, componentname, componentunit,"ms", meshname) < 0) {
00066     MESSAGE("ERROR : create field");
00067     goto ERROR;
00068   }
00069   
00070   /* two computation steps :
00071    *  - first  on meshname MED_NO_DT,MED_NO_IT mesh computation step
00072    *  - second on meshname 1,3 mesh computation step */
00073   /* write values at cell centers : 8 MED_TRIA3 and 4 MED_QUAD4 */
00074 
00075   /* STEP 1 : dt1 = 5.5, it = 1*/
00076   /* MED_TRIA3 */
00077   if (MEDfieldValueWr(fid, fieldname, 1, 1, 5.5, MED_CELL, MED_TRIA3, MED_FULL_INTERLACE, 
00078                       MED_ALL_CONSTITUENT, ntria3, (unsigned char*) tria3values_step1) < 0) {
00079     MESSAGE("ERROR : write field values on MED_TRIA3");
00080     goto ERROR;
00081   }
00082    /* MED_QUAD4 */ 
00083   if (MEDfieldValueWr(fid, fieldname, 1, 1, 5.5, MED_CELL,MED_QUAD4, MED_FULL_INTERLACE, 
00084                       MED_ALL_CONSTITUENT, nquad4, (unsigned char*) quad4values_step1) < 0) {
00085     MESSAGE("ERROR : write field values on MED_QUAD4 ");
00086     goto ERROR;
00087   }
00088 
00089   /* STEP 2 : dt2 = 8.9, it = 1*/
00090   /* MED_TRIA3 */
00091   if (MEDfieldValueWr(fid, fieldname, 2 , 1 , 8.9 , MED_CELL, MED_TRIA3, MED_FULL_INTERLACE, 
00092                       MED_ALL_CONSTITUENT, ntria3,  (unsigned char*)tria3values_step2) < 0) {
00093     MESSAGE("ERROR : write field values on MED_TRIA3");
00094     goto ERROR;
00095   }
00096 
00097   /* MED_QUAD4 */
00098   if (MEDfieldValueWr(fid, fieldname, 2, 1, 8.9, MED_CELL, MED_QUAD4, MED_FULL_INTERLACE, 
00099                       MED_ALL_CONSTITUENT, nquad4, (unsigned char*)quad4values_step2) < 0) {
00100     MESSAGE("ERROR : write field values on MED_QUAD4 ");
00101     goto ERROR;
00102   }
00103 
00104   /* Write associated mesh computation step */
00105   if ( MEDfieldComputingStepMeshWr(fid, fieldname, 2, 1,
00106                                    1, 3 ) < 0 ) {
00107     MESSAGE("ERROR : write field mesh computation step error ");
00108     goto ERROR;
00109   }
00110 
00111   ret=0;
00112  ERROR:
00113 
00114   /* close file */
00115   if (MEDfileClose(fid) < 0) {
00116     MESSAGE("ERROR : close file ...");             
00117     ret=-1; 
00118   } 
00119   
00120   return ret;
00121 }
00122 

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