UsesCase_MEDfield_15b.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 15 : write a field in a MED file with 
00020  * values defined on struct elements
00021  */
00022 
00023 #include <med.h>
00024 
00025 #include "med_hdfi.h"
00026 #define MESGERR 1
00027 #include <med_utils.h>
00028 
00029 #include <string.h>
00030 
00031 
00032 int main (int argc, char **argv) {
00033   med_idt fid2=0,oid=0;
00034   med_idt fid=0,mfid=0;
00035   const char meshname[MED_NAME_SIZE+1] = "COMPUT_MESH";
00036   const char fieldname[MED_NAME_SIZE+1] = "SPEED";
00037   const med_int ncomponent = 3;
00038   /*                                              123456789012345612345678901234561234567890123456 */   
00039   const char componentname[3*MED_SNAME_SIZE+1] = "Vx              Vy              Vz";
00040   const char componentunit[3*MED_SNAME_SIZE+1] = "m/s             m/s             m/s";
00041   med_geometry_type geotype=MED_NONE;
00042   const med_int npart = 3;
00043   char structelementname[MED_NAME_SIZE+1]="";
00044   const med_float part_speed1[3*3] = { 1.1, 2.2, 3.3,
00045                                  4.4, 5.5, 6.6,
00046                                  7.7, 8.8, 9.9 };
00047   int ret=-1;
00048 
00049 
00050   /* File creation to write the field */
00051   fid = MEDfileOpen("UsesCase_MEDfield_15b.med",MED_ACC_CREAT);
00052   if (fid < 0) {
00053     MESSAGE("ERROR : file creation ...");
00054     goto ERROR;
00055   }
00056 
00057   /* Create mesh link */
00058   if (MEDlinkWr(fid,meshname,"./UsesCase_MEDstructElement_1.med") < 0) {
00059     MESSAGE("ERROR : create mesh link ...");
00060     goto ERROR;
00061   }
00062 
00063   /*
00064    * Read struct element geometric type
00065    *
00066    * UsesCase_MEDstructElement_1_byid.med 
00067    */
00068   fid2 = MEDfileOpen(argv[1],MED_ACC_RDONLY);
00069   if (fid2 < 0) {
00070     MESSAGE("Erreur � l'ouverture du fichier UsesCase_MEDstructElement_1_byid.med");
00071     goto ERROR;
00072   }
00073 
00074 
00075   if (( mfid=MEDfileObjectsMountById(fid,fid2,"/byid",MED_ELSTRUCT)) < 0 ) {
00076     MESSAGE("ERROR : file mounting ...");
00077     goto ERROR;
00078   }
00079 
00080   strcpy(structelementname,MED_PARTICLE_NAME);
00081   geotype = MEDstructElementGeotype(fid,structelementname);
00082 
00083 
00084   /*
00085    * Speed field  creation for particles :
00086    * - 3 component
00087    * - component unit : m/s
00088    * - mesh is the 3D computation mesh of UsesCase_MEDstructElement_1 use case.
00089    * - computation step unit in 'ms'
00090    */
00091   if (MEDfieldCr(fid, fieldname, MED_FLOAT64,
00092                  ncomponent, componentname, componentunit,
00093                  "ms", meshname) < 0) {
00094     MESSAGE("ERROR : create field");
00095     goto ERROR;
00096   }
00097 
00098   if (MEDfieldValueWithProfileWr(fid, fieldname, MED_NO_DT, MED_NO_IT, MED_UNDEF_DT, MED_STRUCT_ELEMENT, geotype, 
00099                                  MED_COMPACT_PFLMODE, MED_NO_PROFILE, MED_NO_LOCALIZATION,
00100                                  MED_FULL_INTERLACE, MED_ALL_CONSTITUENT,
00101                                  npart, (unsigned char*) part_speed1) < 0) {
00102     MESSAGE("ERROR : write field values on MED_PARTICLE ");
00103     goto ERROR;
00104   }
00105 
00106   if ( MEDfileObjectsUnmount(fid, mfid, MED_ELSTRUCT) < 0 ) {
00107     MESSAGE("ERROR : file unmounting ...");
00108     goto ERROR;
00109   }
00110 
00111   ret=0;
00112  ERROR:
00113 
00114   if (MEDfileClose(fid) < 0) {
00115     MESSAGE("ERROR : close file ...");
00116     ret=-1;
00117   }
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