source: trunk/src/find_field_bounds.m @ 667

Last change on this file since 667 was 667, checked in by sommeria, 11 years ago

a few bugs corrected.
multimask introduced in series
displ_uvmat transformed into disp_uvmat

File size: 3.4 KB
Line 
1%'find_field_bounds': % find the boounds and typical meshs of coordinates
2%-----------------------------------------------------------------------
3%function  FieldOut=find_field_bounds(Field)
4%-----------------------------------------------------------------------
5%OUTPUT
6%FieldOut copy of the input Field with the additional items:
7%  .XMin,.XMax,.YMin,.YMax,bounds for x and y
8%  .CoordMesh: typical mesh needed for automatic grids
9
10%INPUT
11% Field
12
13function FieldOut=find_field_bounds(Field)
14
15FieldOut=Field;%default
16%% analyse input field
17[CellInfo,NbDimArray,errormsg]=find_field_cells(Field);% analyse  the input field structure
18if ~isempty(errormsg)
19    errormsg=['uvmat /refresh_field / find_field_cells / ' errormsg];% display error
20    return
21end
22
23NbDim=max(NbDimArray);% spatial dimension of the input field
24imax=find(NbDimArray==NbDim);% indices of field cells to consider
25if isfield(Field,'NbDim')
26    NbDim=double(Field.NbDim);% deal with plane fields containing z coordinates
27end
28FieldOut.NbDim=NbDim;
29if  NbDim<=1; return; end% stop here for 1D fields
30
31%% get bounds and mesh (needed  to propose default options for projection objects)
32% if NbDim>1
33CoordMax=zeros(numel(imax),NbDim);
34CoordMin=zeros(numel(imax),NbDim);
35Mesh=zeros(1,numel(imax));
36for ind=1:numel(imax)
37    if strcmp(CellInfo{imax(ind)}.CoordType,'tps')
38        CoordName=Field.ListVarName{CellInfo{imax(ind)}.CoordIndex};% X,Y coordinates in a single variable
39        CoordMax(ind,NbDim)=max(max(Field.(CoordName)(1:end-3,1,:),[],1),[],3);% max of x component (2D case)
40        CoordMax(ind,NbDim-1)=max(max(Field.(CoordName)(1:end-3,2,:),[],1),[],3);% max of y component (2D case)
41        CoordMin(ind,NbDim)=min(min(Field.(CoordName)(1:end-3,1,:),[],1),[],3);
42        CoordMin(ind,NbDim-1)=min(min(Field.(CoordName)(1:end-3,2,:),[],1),[],3);% min of y component (2D case)
43    else
44        XName=Field.ListVarName{CellInfo{imax(ind)}.CoordIndex(end)};
45        YName=Field.ListVarName{CellInfo{imax(ind)}.CoordIndex(end-1)};
46        CoordMax(ind,NbDim)=max(max(Field.(XName)));
47        CoordMin(ind,NbDim)=min(min(Field.(XName)));
48        CoordMax(ind,NbDim-1)=max(max(Field.(YName)));
49        CoordMin(ind,NbDim-1)=min(min(Field.(YName)));
50        %         test_x=1;%test for unstructured coordinates
51        if NbDim==3
52            ZName=Field.ListVarName{CellInfo{imax(ind)}.CoordIndex(1)};
53            CoordMax(imax(ind),1)=max(max(Field.(ZName)));
54            CoordMin(ind,1)=min(min(Field.(ZName)));
55        end
56    end
57    switch CellInfo{imax(ind)}.CoordType
58       
59        case {'scattered','tps'} %unstructured coordinates
60            NbPoints=CellInfo{imax(ind)}.CoordSize;% total nbre of points
61            Mesh(ind)=(prod(CoordMax(ind,:)-CoordMin(ind,:))/NbPoints)^(1/NbDim); %(volume or area per point)^(1/NbDim)
62        case 'grid'%structured coordinate
63            NbPoints=CellInfo{imax(ind)}.CoordSize;% nbre of points in each direction
64            Mesh(ind)=min((CoordMax(ind,:)-CoordMin(ind,:))./(NbPoints-1));
65    end
66end
67Mesh=min(Mesh);
68FieldOut.XMax=max(CoordMax(:,end));
69FieldOut.XMin=min(CoordMin(:,end));
70FieldOut.YMax=max(CoordMax(:,end-1));
71FieldOut.YMin=min(CoordMin(:,end-1));
72if NbDim==3
73    FieldOut.ZMax=max(CoordMax(ind,1));
74    FieldOut.ZMin=max(CoordMin(ind,1));
75end
76% adjust the mesh to a value 1, 2 , 5 *10^n
77ord=10^(floor(log10(Mesh)));%order of magnitude
78if Mesh/ord>=5
79    FieldOut.CoordMesh=5*ord;
80elseif Mesh/ord>=2
81    FieldOut.CoordMesh=2*ord;
82else
83    FieldOut.CoordMesh=ord;
84end
Note: See TracBrowser for help on using the repository browser.