MEDgaussEcr.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 #include <med.h>
00019 #include <med_config.h>
00020 #include <med_outils.h>
00021 
00022 #include <string.h>
00023 #include <stdlib.h>
00024 
00025 med_err
00026 MEDgaussEcr(med_idt fid, med_geometrie_element type_geo, med_float *refcoo, med_mode_switch mode_coo,
00027             med_int ngauss, med_float *gscoo, med_float * wg, char * locname )
00028 {
00029   med_idt gid=0, chid=0;
00030   med_size dimd[1];
00031   med_err ret = -1;
00032   med_int typegeo = -1;
00033   char chemin[MED_TAILLE_GAUSS+1]="";
00034   med_mode_acces MED_MODE_ACCES;
00035 
00036   /*
00037    * On inhibe le gestionnaire d'erreur HDF 5
00038    */
00039   _MEDmodeErreurVerrouiller();
00040 if (MEDcheckVersion(fid) < 0) return -1;
00041 
00042 
00043   if ( (MED_MODE_ACCES = _MEDmodeAcces(fid) ) == MED_UNDEF_MODE_ACCES ) {
00044     MESSAGE("Impossible de déterminer le mode d'acces au fichier ");
00045     goto ERROR;
00046   }
00047 
00048   /*
00049    * MED_GAUSS_ELNO est un mot cle reserve
00050    */
00051   if (! strcmp(locname,MED_GAUSS_ELNO)) {
00052     MESSAGE("MED_GAUSS_ELNO est un mot cle reserve : points Gauss sur les noeuds de l'element");
00053     goto ERROR;   
00054    }
00055 
00056   /* 
00057    * Si le groupe "GAUSS" n'existe pas, on le cree
00058    */
00059   strncpy(chemin,MED_GAUSS,MED_TAILLE_GAUSS-1);
00060   chemin[MED_TAILLE_GAUSS-1] = '\0';
00061   if ((gid = _MEDdatagroupOuvrir(fid,chemin)) < 0)
00062     if ((gid = _MEDdatagroupCreer(fid,chemin)) < 0) {
00063       MESSAGE("Impossible de creer le groupe MED_GAUSS : ");
00064       SSCRUTE(chemin); goto ERROR;
00065     }
00066   
00067   /* 
00068    * Si le groupe <locname> n'existe pas, on le cree
00069    * Sinon => erreur
00070    */
00071   NOFINALBLANK(locname,ERROR);
00072 
00073   if ((chid = _MEDdatagroupOuvrir(gid,locname)) >= 0) {
00074     if ( MED_MODE_ACCES != MED_LECTURE_ECRITURE ) {
00075       MESSAGE("Le nom de localisation existe déjà : ");
00076       SSCRUTE(locname); goto ERROR;
00077     }
00078   } else
00079     if ((chid = _MEDdatagroupCreer(gid,locname)) < 0)
00080       goto ERROR;
00081 
00082   /*
00083    * On stocke <ngauss> sous forme d'attribut
00084    */
00085   if (_MEDattrEntierEcrire(chid,MED_NOM_NBR,&ngauss) < 0) {
00086     MESSAGE("Erreur à l'écriture de l'attribut MED_NOM_NBR : ");
00087     ISCRUTE(ngauss);goto ERROR;
00088   };
00089 
00090   /*
00091    * On stocke <type_geo> sous forme d'attribut
00092    */
00093   typegeo = (med_int) type_geo; 
00094   /* sizeof(enum) tjrs = sizeof(int) en C, or
00095      sur machines 64 bits par défaut med_int==long,
00096      du coup sur  machines 64 bits _MEDattrEntierEcrire utilise 
00097      le type hdf NATIVE_LONG, ce qui pose un problème qd on passe
00098      un enum.
00099   */
00100   if (_MEDattrEntierEcrire(chid,MED_NOM_GEO,&typegeo) < 0) {
00101     MESSAGE("Erreur à l'écriture de l'attribut MED_NOM_GEO : ");
00102     ISCRUTE(type_geo);goto ERROR;
00103   };
00104 
00105 
00106   /*
00107    * On stocke les coordonnées de référence dans un dataset
00108    */
00109 
00110   dimd[0] = (type_geo%100)*(type_geo/100);
00111   if ( _MEDdatasetNumEcrire(chid,MED_NOM_COO,MED_FLOAT64,mode_coo,(type_geo/100),MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,0,MED_NOPG,dimd,
00112                             (unsigned char*) refcoo)  < 0 ) {
00113     MESSAGE("Impossible d'ecrire le dataset : ");SSCRUTE(MED_NOM_COO);
00114     ISCRUTE_size(dimd[0]); goto ERROR;
00115   }
00116 
00117   /*
00118    * On stocke les points d'intégration dans un dataset
00119    */
00120    
00121   dimd[0] = ngauss*(type_geo/100);
00122   if ( _MEDdatasetNumEcrire(chid,MED_NOM_GAU,MED_FLOAT64,mode_coo,(type_geo/100),MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,0,MED_NOPG,dimd,
00123                             (unsigned char*) gscoo)  < 0 ) {
00124     MESSAGE("Impossible d'ecrire le dataset : ");SSCRUTE(MED_NOM_GAU);
00125     ISCRUTE_size(dimd[0]); goto ERROR;
00126   }
00127   
00128   /*
00129    * On stocke les poids dans un dataset
00130    */
00131    
00132   dimd[0] = ngauss; 
00133   if ( _MEDdatasetNumEcrire(chid,MED_NOM_VAL,MED_FLOAT64,mode_coo,1,MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,0,MED_NOPG,dimd,
00134                             (unsigned char*) wg)  < 0 ) {
00135     MESSAGE("Impossible d'ecrire le dataset : ");SSCRUTE(MED_NOM_VAL);
00136     ISCRUTE_size(dimd[0]); goto ERROR;
00137   }
00138 
00139 
00140   ret = 0;
00141 
00142  ERROR:
00143   
00144   /*
00145    * On ferme tout
00146    */
00147   
00148   if (chid>0)     if (_MEDdatagroupFermer(chid) < 0) {
00149     MESSAGE("Impossible de fermer le datagroup : ");
00150     ISCRUTE_id(chid); ret = -1; 
00151   }
00152 
00153   if (gid>0)     if (_MEDdatagroupFermer(gid) < 0) {
00154     MESSAGE("Impossible de fermer le datagroup : ");
00155     ISCRUTE_id(gid); ret = -1; 
00156   }
00157   
00158   return ret;
00159 }
00160 

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