| 1 |
/* This file is part of MED. |
| 2 |
* |
| 3 |
* COPYRIGHT (C) 1999 - 2020 EDF R&D, CEA/DEN |
| 4 |
* MED is free software: you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU Lesser General Public License as published by |
| 6 |
* the Free Software Foundation, either version 3 of the License, or |
| 7 |
* (at your option) any later version. |
| 8 |
* |
| 9 |
* MED is distributed in the hope that it will be useful, |
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
* GNU Lesser General Public License for more details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU Lesser General Public License |
| 15 |
* along with MED. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
*/ |
| 17 |
|
| 18 |
#include <med.h> |
| 19 |
#define MESGERR 1 |
| 20 |
#include <med_utils.h> |
| 21 |
#include <string.h> |
| 22 |
|
| 23 |
#ifdef DEF_LECT_ECR |
| 24 |
#define MODE_ACCES MED_ACC_RDWR |
| 25 |
#elif DEF_LECT_AJOUT |
| 26 |
#define MODE_ACCES MED_ACC_RDEXT |
| 27 |
#else |
| 28 |
#define MODE_ACCES MED_ACC_CREAT |
| 29 |
#endif |
| 30 |
|
| 31 |
int main (int argc, char **argv) |
| 32 |
|
| 33 |
{ |
| 34 |
med_err _ret=-1; |
| 35 |
med_idt _fid=0; |
| 36 |
|
| 37 |
char _meshname1[MED_NAME_SIZE+1] = "meshname1"; |
| 38 |
char _axisname[3*MED_SNAME_SIZE+1] = "x y z "; |
| 39 |
char _unitname[3*MED_SNAME_SIZE+1] = "cm cm cm "; |
| 40 |
|
| 41 |
char _fieldname1[MED_NAME_SIZE+1] = "champ reel"; |
| 42 |
char _componentname1[2*MED_SNAME_SIZE+1] = "comp1 comp2 "; |
| 43 |
/*12345678901234561234567890123456*/ |
| 44 |
char _unitname1[2*MED_SNAME_SIZE+1] = "unit1 unit2 "; |
| 45 |
char _dtunit[MED_SNAME_SIZE+1] = "s"; |
| 46 |
med_int _ncomponentname1 = 2; |
| 47 |
|
| 48 |
|
| 49 |
/*Exemple 1 : |
| 50 |
|
| 51 |
- Elément de référence de type géométrique MED_TRIA3 |
| 52 |
- Point X(X1,X2) quelconque dans le plan de l'élément de référence |
| 53 |
- Fonctions de base : P1(X)=1-X1-X2 ; P2(X)=X1; P3(X)=X2; |
| 54 |
(issu du choix de la base polynomiale (1,X1,X2) |
| 55 |
et des trois noeuds de la maille de référence pour |
| 56 |
construire l'interpolation) |
| 57 |
*/ |
| 58 |
const char _interpname1[] ="interpname1"; |
| 59 |
med_geometry_type _geotype1 =MED_TRIA3; |
| 60 |
|
| 61 |
|
| 62 |
/* Ouverture en mode creation du fichier "current.med" */ |
| 63 |
_fid = MEDfileOpen("current.med",MODE_ACCES); |
| 64 |
if (_fid < 0) { |
| 65 |
MESSAGE("Erreur a la creation du fichier current.med"); |
| 66 |
return -1; |
| 67 |
} |
| 68 |
|
| 69 |
/* Creation de _meshname1 de dimension 2 dans un espace de dimension 3*/ |
| 70 |
if (MEDmeshCr( _fid, _meshname1, 3, 2, MED_UNSTRUCTURED_MESH, |
| 71 |
"Maillage vide","s", MED_SORT_DTIT, |
| 72 |
MED_CARTESIAN, _axisname, _unitname) < 0) { |
| 73 |
MESSAGE("Erreur a la creation du maillage : "); SSCRUTE(_meshname1); |
| 74 |
goto ERROR; |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
/* Creation du champ réel n°1 */ |
| 79 |
if ( MEDfieldCr(_fid,_fieldname1,MED_FLOAT64, |
| 80 |
_ncomponentname1,_componentname1,_unitname1,_dtunit,_meshname1 ) < 0) { |
| 81 |
MESSAGE("Erreur à la création du champ : ");SSCRUTE(_fieldname1); |
| 82 |
goto ERROR; |
| 83 |
}; |
| 84 |
|
| 85 |
|
| 86 |
if ( (_ret = MEDfieldInterpWr(_fid, |
| 87 |
_fieldname1, |
| 88 |
_interpname1) <0) ) { |
| 89 |
MESSAGE("Erreur à l'écriture de la fonction d'interpolation n°1 sur le champ : ");SSCRUTE(_fieldname1); |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
ERROR: |
| 94 |
if (MEDfileClose(_fid) < 0) { |
| 95 |
MESSAGE("ERROR : file closing"); |
| 96 |
return -1; |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
return _ret; |
| 101 |
|
| 102 |
} |
| 103 |
|