UsesCase_MEDinterp_3.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 1 : read an interpolation family with a generic access by an iterator.
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   char              interpname[MED_NAME_SIZE+1]="";
00033   med_int           ninterp                    =0;
00034   int               it                         =0;
00035   med_geometry_type geotype                    =MED_NONE;
00036   med_bool          cellnodes                  =MED_FALSE;
00037   med_int           nbasisfunc              =0;
00038   med_int           nvariable               =0;
00039   med_int           maxdegree                  =0;
00040   med_int           nmaxcoefficient            =0;
00041   int               basisfuncit                =0;
00042   int               powerit                    =0;
00043   med_int           ncoefficient            =0;
00044   med_int*          power                      =NULL;
00045   med_float*        coefficient                =NULL;
00046   int               coefficientit              =0;
00047   int ret=-1;
00048 
00049 
00050   /* file creation */
00051   fid = MEDfileOpen("UsesCase_MEDinterp_1.med",MED_ACC_RDONLY);
00052   if (fid < 0) {
00053     MESSAGE("ERROR : file creation ...");
00054     goto ERROR;
00055   }
00056  
00057   /* how many interpolation family in the file ? */
00058   if ((ninterp = MEDnInterp(fid)) < 0) {
00059     MESSAGE("ERROR : read number of interpolation ...");
00060     goto ERROR;
00061   }
00062 
00063   /* read each interpolation family */
00064   /* with an access by an iterator */
00065   for (it=1; it<= ninterp; it++) {
00066 
00067     if (MEDinterpInfo(fid,it,interpname,&geotype,&cellnodes,&nbasisfunc,
00068                       &nvariable,&maxdegree,&nmaxcoefficient) < 0) {
00069       MESSAGE("ERROR : interpolation function information ...");
00070       goto ERROR;
00071     }
00072 
00073     /* read each basis function */
00074     for ( basisfuncit=1; basisfuncit<= nbasisfunc; ++basisfuncit) {
00075       if ((ncoefficient = MEDinterpBaseFunctionCoefSize(fid,interpname,basisfuncit) ) <0 ) {
00076         MESSAGE("ERROR : read number of coefficient in the base function ...");
00077         goto ERROR;
00078       }
00079       
00080       coefficient = (med_float*) calloc(sizeof(med_float),ncoefficient);
00081       power       = (med_int*)   calloc(sizeof(med_int),nvariable*ncoefficient);
00082       
00083       if (MEDinterpBaseFunctionRd(fid,interpname,basisfuncit,&ncoefficient,power,coefficient) < 0) {
00084         MESSAGE("ERROR : read base function ...");
00085         free(coefficient); free(power);
00086         goto ERROR;
00087       }
00088 
00089       free(coefficient);
00090       free(power);
00091     }
00092 
00093   }
00094 
00095   ret=0;
00096  ERROR:
00097   
00098   /* close file */
00099   if (MEDfileClose(fid) < 0) {
00100     MESSAGE("ERROR : close file ...");             
00101     ret=-1; 
00102   } 
00103   
00104   return ret;
00105 }

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