| 1 | function Struct=expread(filename,whole);
|
|---|
| 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,whole)
|
|---|
| 13 | %
|
|---|
| 14 | % Example:
|
|---|
| 15 | % Struct=expread('domainoutline.exp')
|
|---|
| 16 | % Struct=expread('domainoutline.exp',1)
|
|---|
| 17 | %
|
|---|
| 18 | % See also EXPDOC, EXPWRITEASVERTICES
|
|---|
| 19 |
|
|---|
| 20 | %some checks
|
|---|
| 21 | if ~exist(filename),
|
|---|
| 22 | error(['expread error message: file ' filename ' not found!']);
|
|---|
| 23 | end
|
|---|
| 24 | if nargin<2,
|
|---|
| 25 | whole=1;
|
|---|
| 26 | end
|
|---|
| 27 |
|
|---|
| 28 | %initialize number of profile
|
|---|
| 29 | count=0;
|
|---|
| 30 |
|
|---|
| 31 | %open file
|
|---|
| 32 | fid=fopen(filename,'r');
|
|---|
| 33 |
|
|---|
| 34 | %loop over the number of profiles
|
|---|
| 35 | while (~feof(fid)),
|
|---|
| 36 |
|
|---|
| 37 | %update number of profiles
|
|---|
| 38 | count=count+1;
|
|---|
| 39 |
|
|---|
| 40 | %Get file name
|
|---|
| 41 | A=fscanf(fid,'%s %s',2);
|
|---|
| 42 | if ~strncmp(A,'##Name:',7), break; end
|
|---|
| 43 | if length(A)>7,
|
|---|
| 44 | Struct(count).name=A(8:end);
|
|---|
| 45 | else
|
|---|
| 46 | Struct(count).name='';
|
|---|
| 47 | end
|
|---|
| 48 |
|
|---|
| 49 | %Get Icon
|
|---|
| 50 | A=fscanf(fid,'%s %s',2);
|
|---|
| 51 | if ~strncmp(A,'##Icon:',6), break; end
|
|---|
| 52 |
|
|---|
| 53 | %Get Info
|
|---|
| 54 | A=fscanf(fid,'%s %s %s %s',4);
|
|---|
| 55 | if ~strncmp(A,'#Points',7), break; end
|
|---|
| 56 |
|
|---|
| 57 | %Get number of nods and density
|
|---|
| 58 | A=fscanf(fid,'%f %f',[1 2]);
|
|---|
| 59 | Struct(count).nods=A(1);
|
|---|
| 60 | Struct(count).density=A(2);
|
|---|
| 61 |
|
|---|
| 62 | %Get Info
|
|---|
| 63 | A=fscanf(fid,'%s %s %s %s',5);
|
|---|
| 64 | if ~strncmp(A,'#XposYpos',9), break; end
|
|---|
| 65 |
|
|---|
| 66 | %Get Coordinates
|
|---|
| 67 | A=fscanf(fid,'%f %f',[2 Struct(count).nods]);
|
|---|
| 68 | Struct(count).x=A(1,:)';
|
|---|
| 69 | Struct(count).y=A(2,:)';
|
|---|
| 70 |
|
|---|
| 71 | if(Struct(count).nods~=length(Struct(count).x))error(['Profile ' num2str(count) ' reports incorrect length']); end;
|
|---|
| 72 |
|
|---|
| 73 | %Check if closed
|
|---|
| 74 | if (Struct(count).nods > 1) && ...
|
|---|
| 75 | (Struct(count).x(end) == Struct(count).x(1)) && ...
|
|---|
| 76 | (Struct(count).y(end) == Struct(count).y(1))
|
|---|
| 77 | Struct(count).closed=true;
|
|---|
| 78 | %skip last coordinate if whole=0,
|
|---|
| 79 | if whole==0
|
|---|
| 80 | Struct(count).nods=Struct(count).nods-1;
|
|---|
| 81 | Struct(count).x =Struct(count).x(1:end-1,1);
|
|---|
| 82 | Struct(count).y =Struct(count).y(1:end-1,1);
|
|---|
| 83 | end
|
|---|
| 84 | else
|
|---|
| 85 | Struct(count).closed=false;
|
|---|
| 86 | end
|
|---|
| 87 |
|
|---|
| 88 | end
|
|---|
| 89 |
|
|---|
| 90 | %close file
|
|---|
| 91 | fclose(fid);
|
|---|