# UsesCase_MEDfield_15.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 15 : write a field in a MED file with
    00020  * values defined on struct elements
    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=0,mfid=0;
    00032   const char meshname[MED_NAME_SIZE+1] = "COMPUT_MESH";
    00033   const char fieldname[MED_NAME_SIZE+1] = "SPEED";
    00034   const med_int ncomponent = 3;
    00035   /*                                              123456789012345612345678901234561234567890123456 */
    00036   const char componentname[3*MED_SNAME_SIZE+1] = "Vx              Vy              Vz";
    00037   const char componentunit[3*MED_SNAME_SIZE+1] = "m/s             m/s             m/s";
    00038   med_geometry_type geotype=MED_NONE;
    00039   const med_int npart = 3;
    00040   char structelementname[MED_NAME_SIZE+1]="";
    00041   const med_float part_speed1[3*3] = { 1.1, 2.2, 3.3,
    00042                                  4.4, 5.5, 6.6,
    00043                                  7.7, 8.8, 9.9 };
    00044   int ret=-1;
    00045
    00046
    00047   /* File creation to write the field */
    00048   fid = MEDfileOpen("UsesCase_MEDfield_15.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_MEDstructElement_1.med") < 0) {
    00056     MESSAGE("ERROR : create mesh link ...");
    00057     goto ERROR;
    00058   }
    00059
    00060   /*
    00061    * Read struct element geometric type
    00062    */
    00063   if (( mfid=MEDfileObjectsMount(fid,  "UsesCase_MEDstructElement_1.med",MED_ELSTRUCT)) < 0 ) {
    00064     MESSAGE("ERROR : file mounting ...");
    00065     goto ERROR;
    00066   }
    00067
    00068   strcpy(structelementname,MED_PARTICLE_NAME);
    00069   geotype = MEDstructElementGeotype(fid,structelementname);
    00070
    00071
    00072   /*
    00073    * Speed field  creation for particles :
    00074    * - 3 component
    00075    * - component unit : m/s
    00076    * - mesh is the 3D computation mesh of UsesCase_MEDstructElement_1 use case.
    00077    * - computation step unit in 'ms'
    00078    */
    00079   if (MEDfieldCr(fid, fieldname, MED_FLOAT64,
    00080                  ncomponent, componentname, componentunit,
    00081                  "ms", meshname) < 0) {
    00082     MESSAGE("ERROR : create field");
    00083     goto ERROR;
    00084   }
    00085
    00086   if (MEDfieldValueWithProfileWr(fid, fieldname, MED_NO_DT, MED_NO_IT, MED_UNDEF_DT, MED_STRUCT_ELEMENT, geotype,
    00087                                  MED_COMPACT_PFLMODE, MED_NO_PROFILE, MED_NO_LOCALIZATION,
    00088                                  MED_FULL_INTERLACE, MED_ALL_CONSTITUENT,
    00089                                  npart, (unsigned char*) part_speed1) < 0) {
    00090     MESSAGE("ERROR : write field values on MED_PARTICLE ");
    00091     goto ERROR;
    00092   }
    00093
    00094   if ( MEDfileObjectsUnmount(fid, mfid, MED_ELSTRUCT) < 0 ) {
    00095     MESSAGE("ERROR : file unmounting ...");
    00096     goto ERROR;
    00097   }
    00098
    00099   ret=0;
    00100  ERROR:
    00101
    00102   /* close file */
    00103   if (MEDfileClose(fid) < 0) {
    00104     MESSAGE("ERROR : close file ...");
    00105     ret=-1;
    00106   }
    00107
    00108   return ret;
    00109 }
    00110