[5024] | 1 | function flag=FlagElements(md,region),
|
---|
| 2 | %FLAGELEMENTS - flag the elements in an region
|
---|
[2967] | 3 | %
|
---|
[5024] | 4 | % The region can be given with an exp file, a list of elements.
|
---|
[2967] | 5 | %
|
---|
| 6 | % Usage:
|
---|
[5024] | 7 | % flag=FlagElements(md,region);
|
---|
[2967] | 8 | %
|
---|
| 9 | % Example:
|
---|
| 10 | % flag=FlagElements(md,'all');
|
---|
| 11 | % flag=FlagElements(md,'');
|
---|
| 12 | % flag=FlagElements(md,'Domain.exp');
|
---|
| 13 | % flag=FlagElements(md,'~Domain.exp');
|
---|
[9641] | 14 | % flag=FlagElements(md,md.mask.elementongroundedice);
|
---|
[2967] | 15 |
|
---|
[5024] | 16 | if ischar(region),
|
---|
| 17 | if isempty(region),
|
---|
[9725] | 18 | flag=zeros(md.mesh.numberofelements,1);
|
---|
[2967] | 19 | invert=0;
|
---|
[5024] | 20 | elseif strcmpi(region,'all')
|
---|
[9725] | 21 | flag=ones(md.mesh.numberofelements,1);
|
---|
[2967] | 22 | invert=0;
|
---|
| 23 | else
|
---|
| 24 | %make sure that we actually don't want the elements outside the domain outline!
|
---|
[5024] | 25 | if strcmpi(region(1),'~'),
|
---|
| 26 | region=region(2:length(region));
|
---|
[2967] | 27 | invert=1;
|
---|
| 28 | else
|
---|
| 29 | invert=0;
|
---|
| 30 | end
|
---|
[2990] | 31 |
|
---|
[5024] | 32 | %does the region domain outline exist or do we have to look for xlim,ylim in basinzoom?
|
---|
| 33 | if ~exist(region,'file'),
|
---|
[11057] | 34 | if (length(region)>3 & ~strcmp(region(end-3),'.exp')),
|
---|
| 35 | error(['Error: File ' region ' not found!']);
|
---|
| 36 | end
|
---|
[7304] | 37 | [xlim,ylim]=basinzoom('basin',region);
|
---|
[9734] | 38 | flag_nodes=double(md.mesh.x<xlim(2) & md.mesh.x>xlim(1) & md.mesh.y<ylim(2) & md.mesh.y>ylim(1));
|
---|
[9733] | 39 | flag=prod(flag_nodes(md.mesh.elements),2);
|
---|
[2990] | 40 | else
|
---|
| 41 | %ok, flag elements
|
---|
[9734] | 42 | flag=ContourToMesh(md.mesh.elements(:,1:3),md.mesh.x,md.mesh.y,region,'element',1);
|
---|
[2990] | 43 | end
|
---|
[2967] | 44 | end
|
---|
| 45 | if invert,
|
---|
| 46 | flag=~flag;
|
---|
| 47 | end
|
---|
[8102] | 48 | elseif isfloat(region) | islogical(region),
|
---|
[9725] | 49 | if size(region,1)~=md.mesh.numberofelements,
|
---|
[3346] | 50 | help FlagElements
|
---|
[5024] | 51 | error('Flaglist for region must be of same size as number of elements in model');
|
---|
[2967] | 52 | end
|
---|
[5024] | 53 | flag=region;
|
---|
[2967] | 54 | else
|
---|
[6818] | 55 | error('Invalid region option');
|
---|
[2967] | 56 | end
|
---|
| 57 | end
|
---|