source: issm/branches/trunk-jpl-damage/src/m/utils/Exp/readwrite/expread.m@ 12004

Last change on this file since 12004 was 12004, checked in by cborstad, 13 years ago

merged trunk-jpl into trunk-jpl-damage through revision 11990

File size: 2.0 KB
Line 
1function Struct=expread(filename);
2%EXPREAD - read a file exp and build a Structure
3%
4% This routine reads a file .exp and build a Structure containing the
5% fields x and y corresponding to the coordinates, one for the filename of
6% the exp file, for the density, for the nodes, and a field closed to
7% indicate if the domain is closed.
8% The first argument is the .exp file to be read and the second one (optional)
9% indicate if the last point shall be read (1 to read it, 0 not to).
10%
11% Usage:
12% Struct=expread(filename)
13%
14% Example:
15% Struct=expread('domainoutline.exp')
16% Struct=expread('domainoutline.exp')
17%
18% See also EXPDOC, EXPWRITEASVERTICES
19
20%some checks
21if ~exist(filename),
22 error(['expread error message: file ' filename ' not found!']);
23end
24
25%initialize number of profile
26count=0;
27
28%open file
29fid=fopen(filename,'r');
30
31%loop over the number of profiles
32while (~feof(fid)),
33
34 %update number of profiles
35 count=count+1;
36
37 %Get file name
38 A=fscanf(fid,'%s %s',2);
39 if ~strncmp(A,'##Name:',7), break; end
40 if length(A)>7,
41 Struct(count).name=A(8:end);
42 else
43 Struct(count).name='';
44 end
45
46 %Get Icon
47 A=fscanf(fid,'%s %s',2);
48 if ~strncmp(A,'##Icon:',6), break; end
49
50 %Get Info
51 A=fscanf(fid,'%s %s %s %s',4);
52 if ~strncmp(A,'#Points',7), break; end
53
54 %Get number of nods and density
55 A=fscanf(fid,'%f %f',[1 2]);
56 Struct(count).nods=A(1);
57 Struct(count).density=A(2);
58
59 %Get Info
60 A=fscanf(fid,'%s %s %s %s',5);
61 if ~strncmp(A,'#XposYpos',9), break; end
62
63 %Get Coordinates
64 A=fscanf(fid,'%f %f',[2 Struct(count).nods]);
65 Struct(count).x=A(1,:)';
66 Struct(count).y=A(2,:)';
67
68 if(Struct(count).nods~=length(Struct(count).x))error(['Profile ' num2str(count) ' reports incorrect length']); end;
69
70 %Check if closed
71 if (Struct(count).nods > 1) && ...
72 (Struct(count).x(end) == Struct(count).x(1)) && ...
73 (Struct(count).y(end) == Struct(count).y(1))
74 Struct(count).closed=true;
75 else
76 Struct(count).closed=false;
77 end
78end
79
80%close file
81fclose(fid);
Note: See TracBrowser for help on using the repository browser.