| MESH toolbox 0.1 Matlab/Octave mesh utils

- Main Page
- Related Pages
- Modules
- Files

- File List
- File Members

All Files Functions Groups Pages
GetMeshOpt.m
Go to the documentation of this file.
1 function Mesh=GetMeshOpt(cFileName)
2 % function Mesh=GetMeshOpt(cFileName)
3 % Initialization of the Mesh structure from a FreeFEM++ mesh file
4 %
5 % Parameters:
6 % cFileName: file name (string)
7 %
8 % Return values:
9 % Mesh: mesh structure (see report)
10 %
11 % Generated fields of Mesh:
12 % q:
13 % me:
14 %
15 % Usage: Th=GetMesh('carre.msh')
16 [fid,message]=fopen(cFileName,'r');
17 if ( fid == -1 )
18 error([message,' : ',cFileName]);
19 end
20 if isOctave()
21 [n]=fscanf(fid,'%d %d %d',3);
22
23 R=fscanf(fid,'%f %f %d',[3,n(1)]);
24 q=R([1 2],:);
25 ql=R(3,:);
26 R=fscanf(fid,'%d %d %d %d',[4,n(2)]);
27
28 me=R([1:3],:);
29 mel=R(4,:);
30 R=fscanf(fid,'%d %d %d',[3,n(3)]);
31
32 be=R([1 2],:);
33 bel=R(3,:);
34 else % Matlab
35 n=textscan(fid,'%d %d %d',1); % n(1) -> number of vertices
36 % n(2) -> number of triangles
37 % n(3) -> number of boundary edges
38
39 R=textscan(fid,'%f %f %d',n{1});
40 q=[R{1},R{2}]';
41 ql=R{3}';
42 R=textscan(fid,'%d %d %d %d',n{2});
43 me=[R{1},R{2},R{3}]';
44 mel=R{4}';
45
46 R=textscan(fid,'%d %d %d',n{3});
47 be=[R{1},R{2}]';
48 bel=R{3}';
49 end
50 fclose(fid);
51
52 Mesh=struct('q',q,'me',me,'ql',ql,'mel',mel,'be',be,'bel',bel, ...
53 'nq',size(q,2), ...
54 'nme',size(me,2), ...
55 'nbe',size(be,2), ...
56 'areas',ComputeAreaOpt(q,me),...
57 'lbe',EdgeLengthOpt(be,q));
58