| 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 |
|
| 19 |
#include <med.h> |
| 20 |
#define MESGERR 1 |
| 21 |
#include <med_utils.h> |
| 22 |
#include <string.h> |
| 23 |
|
| 24 |
#ifdef DEF_LECT_ECR |
| 25 |
#define MODE_ACCES MED_ACC_RDWR |
| 26 |
#elif DEF_LECT_AJOUT |
| 27 |
#define MODE_ACCES MED_ACC_RDEXT |
| 28 |
#else |
| 29 |
#define MODE_ACCES MED_ACC_CREAT |
| 30 |
#endif |
| 31 |
|
| 32 |
int main (int argc, char **argv) |
| 33 |
|
| 34 |
{ |
| 35 |
|
| 36 |
int _i = 0; |
| 37 |
int _j = 0; |
| 38 |
med_idt _fid = 0; |
| 39 |
med_int _meshdim = 3; |
| 40 |
med_int _rmeshdim = 0; |
| 41 |
med_int _rspacedim = 0; |
| 42 |
med_int _n = 0; |
| 43 |
med_int _rnnoe = 0; |
| 44 |
med_int _rnse2 = 0; |
| 45 |
med_int _rnaxis = 0; |
| 46 |
|
| 47 |
const med_int _nnoe = 5; |
| 48 |
|
| 49 |
/* table des coordonnees |
| 50 |
(dimension * nombre de noeuds) */ |
| 51 |
med_float coo[5*3] = {0.0, 0.0, 0.0, 0.1 , 0.0, 0.0, |
| 52 |
1.0, 0.0, 0.0, 1.1 , 0.0, 0.0, |
| 53 |
2.0, 0.0, 0.0 }; |
| 54 |
med_float * _rcoo=NULL; |
| 55 |
|
| 56 |
med_int nse2 = 4; |
| 57 |
med_int se2[10] = {1,2, 2,3, 3,4, 4,5}; |
| 58 |
med_int * _rse2=NULL; |
| 59 |
|
| 60 |
const char _supportmeshname[]="SUPPORT_POUTRE"; |
| 61 |
char _axisname[3*MED_SNAME_SIZE+1]=""; |
| 62 |
char _axisunit[3*MED_SNAME_SIZE+1]=""; |
| 63 |
|
| 64 |
char _rsupportmeshname[MED_NAME_SIZE+1]=""; |
| 65 |
char _raxisname[3*MED_SNAME_SIZE+1]=""; |
| 66 |
char _raxisunit[3*MED_SNAME_SIZE+1]=""; |
| 67 |
char _rdescription[MED_COMMENT_SIZE+1]=""; |
| 68 |
med_axis_type _raxistype; |
| 69 |
med_bool _chgt=MED_FALSE,_trsf=MED_FALSE; |
| 70 |
|
| 71 |
strcat(_axisname,"x "); |
| 72 |
strcat(_axisname,"y "); |
| 73 |
strcat(_axisname,"z "); |
| 74 |
strcat(_axisunit,"cm "); |
| 75 |
strcat(_axisunit,"cm "); |
| 76 |
strcat(_axisunit,"cm "); |
| 77 |
|
| 78 |
/* ouverture du fichier */ |
| 79 |
if ((_fid = MEDfileOpen("current.med",MODE_ACCES)) < 0) { |
| 80 |
MESSAGE("Impossible de creer le fichier current.med"); |
| 81 |
return -1; |
| 82 |
} |
| 83 |
|
| 84 |
if (MEDsupportMeshCr( _fid, _supportmeshname, _meshdim, _meshdim,"Maillage support ED de type poutre", |
| 85 |
MED_CARTESIAN,_axisname, _axisname) < 0) { |
| 86 |
MESSAGE("Erreur a la creation du maillage support : "); SSCRUTE(_supportmeshname); |
| 87 |
return -1; |
| 88 |
} |
| 89 |
|
| 90 |
/* Ecriture des coordonnees des noeuds en mode MED_FULL_INTERLACE : |
| 91 |
(X1,Y1, X2,Y2, X3,Y3, ...) dans un repere cartesien */ |
| 92 |
if (MEDmeshNodeCoordinateWr(_fid,_supportmeshname,MED_NO_DT,MED_NO_IT,MED_UNDEF_DT, |
| 93 |
MED_FULL_INTERLACE, _nnoe, coo) < 0) { |
| 94 |
MESSAGE("Erreur a l'écriture des coordonnees des noeuds du maillage support"); |
| 95 |
return -1; |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
/* ecriture des connectivites des segments */ |
| 100 |
if ( MEDmeshElementConnectivityWr(_fid,_supportmeshname, MED_NO_DT, MED_NO_IT, MED_UNDEF_DT, |
| 101 |
MED_CELL, MED_SEG2, MED_NODAL, |
| 102 |
MED_FULL_INTERLACE, nse2, se2) < 0 ) { |
| 103 |
MESSAGE("Impossible d'ecrire la connectivité des segments du maillage support : "); |
| 104 |
return -1; |
| 105 |
} |
| 106 |
|
| 107 |
if (MEDsupportMeshCr( _fid, "MED_BILLE_SUPPORT", _meshdim, _meshdim,"Maillage support ED de type bille", |
| 108 |
MED_CARTESIAN,_axisname, _axisname) < 0) { |
| 109 |
MESSAGE("Erreur a la creation du maillage support : "); SSCRUTE(_supportmeshname); |
| 110 |
return -1; |
| 111 |
} |
| 112 |
|
| 113 |
/* Ecriture des coordonnees des noeuds en mode MED_FULL_INTERLACE : |
| 114 |
(X1,Y1, X2,Y2, X3,Y3, ...) dans un repere cartesien */ |
| 115 |
if (MEDmeshNodeCoordinateWr(_fid,"MED_BILLE_SUPPORT",MED_NO_DT,MED_NO_IT,MED_UNDEF_DT, |
| 116 |
MED_FULL_INTERLACE, 1, coo) < 0) { |
| 117 |
MESSAGE("Erreur a l'écriture des coordonnees des noeuds du maillage support : MED_BILLE_SUPPORT."); |
| 118 |
return -1; |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
if ( (_n =MEDnSupportMesh(_fid)) < 0 ) { |
| 123 |
MESSAGE("Erreur à la lecture du nombre de maillages supports : "); |
| 124 |
return -1; |
| 125 |
} |
| 126 |
|
| 127 |
for (_i=1; _i <= _n; ++_i) { |
| 128 |
|
| 129 |
if ( (_rnaxis = MEDsupportMeshnAxis(_fid, _i)) < 0) { |
| 130 |
MESSAGE("Erreur à la lecture du nombre d'axe du repère d'un maillage support : "); |
| 131 |
return -1; |
| 132 |
} |
| 133 |
printf("\t -Dimension de l'espace : %d\n",_rnaxis); |
| 134 |
|
| 135 |
if ( MEDsupportMeshInfo(_fid, _i , |
| 136 |
_rsupportmeshname, &_rspacedim, &_rmeshdim, _rdescription, |
| 137 |
&_raxistype, _raxisname, _raxisunit) < 0 ) { |
| 138 |
MESSAGE("Erreur à la lecture des informations sur le maillage support : "); SSCRUTE(_supportmeshname); |
| 139 |
return -1; |
| 140 |
} |
| 141 |
|
| 142 |
printf("Maillage support de nom : |%s| , de dimension : %d.\n",_rsupportmeshname, _rmeshdim); |
| 143 |
printf("\t -Dimension de l'espace : %d\n",_rspacedim); |
| 144 |
printf("\t -Description du maillage : %s\n",_rdescription); |
| 145 |
printf("\t -Noms des axes : %s\n",_raxisname); |
| 146 |
printf("\t -Unités des axes : %s\n",_raxisunit); |
| 147 |
|
| 148 |
/* Combien de noeuds a lire ? */ |
| 149 |
_rnnoe = MEDmeshnEntity(_fid,_rsupportmeshname,MED_NO_DT,MED_NO_IT, |
| 150 |
MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE, |
| 151 |
&_chgt,&_trsf); |
| 152 |
if (_rnnoe < 0) { |
| 153 |
MESSAGE("Erreur a la lecture du nombre de noeuds. "); |
| 154 |
return -1; |
| 155 |
} else |
| 156 |
printf("Nombre de noeuds du maillage support: "IFORMAT" \n",_rnnoe); |
| 157 |
|
| 158 |
/* Allocations memoires */ |
| 159 |
if (_rnnoe > 0) { |
| 160 |
/* table des coordonnees (dimension * nombre de noeuds ) */ |
| 161 |
_rcoo = (med_float*) calloc(_rnnoe*_rspacedim,sizeof(med_float)); |
| 162 |
|
| 163 |
if ( MEDmeshNodeCoordinateRd(_fid, _rsupportmeshname, MED_NO_DT, MED_NO_IT,MED_FULL_INTERLACE, _rcoo) < 0 ) { |
| 164 |
MESSAGE("Erreur a la lecture des coordonnees des noeuds"); |
| 165 |
return -1; |
| 166 |
} else { |
| 167 |
printf("Valeur de _rcoo : "); |
| 168 |
for (_j=0;_j<_rnnoe*_rspacedim;_j++) printf("%4.2f ",_rcoo[_j]); |
| 169 |
printf("\n"); |
| 170 |
} |
| 171 |
|
| 172 |
free(_rcoo); |
| 173 |
} |
| 174 |
|
| 175 |
/* Combien de segments à lire ? */ |
| 176 |
_rnse2 = MEDmeshnEntity(_fid,_rsupportmeshname,MED_NO_DT,MED_NO_IT, |
| 177 |
MED_CELL,MED_SEG2,MED_CONNECTIVITY,MED_NODAL, |
| 178 |
&_chgt,&_trsf); |
| 179 |
|
| 180 |
if (_rnse2 < 0) { |
| 181 |
MESSAGE("Erreur a la lecture du nombre de segments."); |
| 182 |
return -1; |
| 183 |
} else |
| 184 |
printf("Nombre de segments du maillage support: "IFORMAT" \n",_rnse2); |
| 185 |
|
| 186 |
if (_rnse2 > 0) { |
| 187 |
/* table des connectivités (_rnse2 * nombre de noeuds ds un MED_SE2) */ |
| 188 |
_rse2 = (med_int*) calloc(_rnse2*2,sizeof(med_int)); |
| 189 |
|
| 190 |
if ( MEDmeshElementConnectivityRd(_fid, _rsupportmeshname, MED_NO_DT, MED_NO_IT, |
| 191 |
MED_CELL,MED_SEG2,MED_NODAL,MED_FULL_INTERLACE, _rse2) < 0 ) { |
| 192 |
MESSAGE("Erreur a la lecture des connectivités des segments"); |
| 193 |
return -1; |
| 194 |
} else { |
| 195 |
printf("Valeur de _rse2 : "); |
| 196 |
for (_j=0;_j<_rnse2*2;_j++) printf("%d ",_rse2[_j]); |
| 197 |
printf("\n"); |
| 198 |
} |
| 199 |
|
| 200 |
free(_rse2); |
| 201 |
} |
| 202 |
|
| 203 |
} |
| 204 |
|
| 205 |
return 0; |
| 206 |
} |