source: trunk/src/find_field_bounds.m @ 662

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

various bugs corrected

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