UsesCase_MEDinterp_2.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  * Interp use case 2 : read an interpolation family with a direct access by name
00020  * In this example, the interpolation family can be used with
00021  * the TEMPERATURE field of UsesCase_MEDfield_10 use case
00022  */
00023 
00024 #include <med.h>
00025 #define MESGERR 1
00026 #include <med_utils.h>
00027 
00028 #include <string.h>
00029 
00030 int main (int argc, char **argv) {
00031   med_idt fid;
00032   const char interpname[MED_NAME_SIZE+1] = "MED_TRIA3 interpolation family";
00033   med_geometry_type geotype                    =MED_NONE;
00034   med_bool          cellnodes                  =MED_FALSE;
00035   med_int           nbasisfunc              =0;
00036   med_int           nvariable               =0;
00037   med_int           maxdegree                  =0;
00038   med_int           nmaxcoefficient            =0;
00039   int               basisfuncit                =0;
00040   int               powerit                    =0;
00041   med_int           ncoefficient            =0;
00042   med_int*          power                      =NULL;
00043   med_float*        coefficient                =NULL;
00044   int               coefficientit              =0;
00045   int ret=-1;
00046 
00047 
00048   /* file creation */
00049   fid = MEDfileOpen("UsesCase_MEDinterp_1.med",MED_ACC_RDONLY);
00050   if (fid < 0) {
00051     MESSAGE("ERROR : file creation ...");
00052     goto ERROR;
00053   }
00054  
00055   /* with direct access by the family name */
00056   if (MEDinterpInfoByName(fid,interpname,&geotype,&cellnodes,&nbasisfunc,
00057                           &nvariable,&maxdegree,&nmaxcoefficient) < 0) {
00058     MESSAGE("ERROR : interpolation function information ...");
00059     goto ERROR;
00060   }
00061 
00062   /* read each basis function */
00063   for ( basisfuncit=1; basisfuncit<= nbasisfunc; ++basisfuncit) {
00064 
00065     if ((ncoefficient = MEDinterpBaseFunctionCoefSize(fid,interpname,basisfuncit) ) <0 ) {
00066       MESSAGE("ERROR : read number of coefficient in the base function ...");
00067       goto ERROR;
00068     }
00069 
00070     coefficient = (med_float*) calloc(sizeof(med_float),ncoefficient);
00071     power       = (med_int*)   calloc(sizeof(med_int),nvariable*ncoefficient);
00072     
00073     if (MEDinterpBaseFunctionRd(fid,interpname,basisfuncit,&ncoefficient,power,coefficient) < 0) {
00074       MESSAGE("ERROR : read base function ...");
00075       free(coefficient); free(power);
00076       goto ERROR;
00077     }
00078 
00079     free(coefficient);
00080     free(power);
00081   }
00082 
00083   ret=0;
00084  ERROR:
00085   
00086   
00087   /* close file */
00088   if (MEDfileClose(fid) < 0) {
00089     MESSAGE("ERROR : close file ...");             
00090     ret=-1; 
00091   } 
00092   
00093   return ret;
00094 }

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