1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
---|
2 | "http://www.w3.org/TR/REC-html40/loose.dtd"> |
---|
3 | <html> |
---|
4 | <head> |
---|
5 | <title>Description of find_field_indices</title> |
---|
6 | <meta name="keywords" content="find_field_indices"> |
---|
7 | <meta name="description" content="'find_file_indices': group the variables of a nc-formated Matlab structure into 'fields' with common dimensions"> |
---|
8 | <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> |
---|
9 | <meta name="generator" content="m2html © 2003 Guillaume Flandin"> |
---|
10 | <meta name="robots" content="index, follow"> |
---|
11 | <link type="text/css" rel="stylesheet" href="../m2html.css"> |
---|
12 | </head> |
---|
13 | <body> |
---|
14 | <a name="_top"></a> |
---|
15 | <div><a href="../index.html">Home</a> > <a href="index.html">.</a> > find_field_indices.m</div> |
---|
16 | |
---|
17 | <!--<table width="100%"><tr><td align="left"><a href="../index.html"><img alt="<" border="0" src="../left.png"> Master index</a></td> |
---|
18 | <td align="right"><a href="index.html">Index for . <img alt=">" border="0" src="../right.png"></a></td></tr></table>--> |
---|
19 | |
---|
20 | <h1>find_field_indices |
---|
21 | </h1> |
---|
22 | |
---|
23 | <h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> |
---|
24 | <div class="box"><strong>'find_file_indices': group the variables of a nc-formated Matlab structure into 'fields' with common dimensions</strong></div> |
---|
25 | |
---|
26 | <h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> |
---|
27 | <div class="box"><strong>function [CellVarIndex,NbDim,VarType,errormsg]=find_field_indices(Data) </strong></div> |
---|
28 | |
---|
29 | <h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> |
---|
30 | <div class="fragment"><pre class="comment">'find_file_indices': group the variables of a nc-formated Matlab structure into 'fields' with common dimensions |
---|
31 | ---------------------------------------------------------------------- |
---|
32 | function [DimVarIndex,CellVarIndex,NbDim,VarType]=find_field_indices(Data) |
---|
33 | |
---|
34 | OUTPUT: |
---|
35 | CellVaxIndex: cell whose elements are arrays of indices in the list data.ListVarName |
---|
36 | CellvarIndex{i} represents a set of variables with the same dimensions |
---|
37 | NbDim: array with the length of CellVarIndex, giving its space dimension |
---|
38 | VarType: cell array of structures with fields |
---|
39 | .coord_x, y, z: indices (in .ListVarname) of variables representing unstructured coordinates x, y, z |
---|
40 | .vector_x,_y,_z: indices of variables giving the vector components x, y, z |
---|
41 | .warnflag: index of warnflag |
---|
42 | .errorflag: index of error flag |
---|
43 | .ancillary: indices of ancillary variables |
---|
44 | .image : B/W image, (behaves like scalar) |
---|
45 | .color : color image, the last index, which is not a coordinate variable, represent the color components |
---|
46 | .scalar: scalar field</pre></div> |
---|
47 | |
---|
48 | <!-- crossreference --> |
---|
49 | <h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> |
---|
50 | This function calls: |
---|
51 | <ul style="list-style-image:url(../matlabicon.gif)"> |
---|
52 | </ul> |
---|
53 | This function is called by: |
---|
54 | <ul style="list-style-image:url(../matlabicon.gif)"> |
---|
55 | <li><a href="get_field.html" class="code" title="function varargout = get_field(varargin)">get_field</a> 'get_field': display variables and attributes from a Netcdf file, and plot selected fields</li><li><a href="plot_field.html" class="code" title="function [PlotType,PlotParamOut,haxes]= plot_field(Data,haxes,PlotParam,KeepLim,PosColorbar)">plot_field</a> 'plot_field': plot any field with the structure defined in the uvmat package</li><li><a href="proj_field.html" class="code" title="function [ProjData,errormsg]=proj_field(FieldData,ObjectData,IndexObj)">proj_field</a> 'proj_field': projects the field on a projection object</li><li><a href="series.html" class="code" title="function varargout = series(varargin)">series</a> 'series': master function associated to the GUI series.m for analysis field series</li><li><a href="uvmat.html" class="code" title="function varargout = uvmat(varargin)">uvmat</a> 'uvmat': function associated with the GUI 'uvmat.fig' for images and data field visualization</li></ul> |
---|
56 | <!-- crossreference --> |
---|
57 | |
---|
58 | |
---|
59 | <h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> |
---|
60 | <div class="fragment"><pre>0001 <span class="comment">%'find_file_indices': group the variables of a nc-formated Matlab structure into 'fields' with common dimensions</span> |
---|
61 | 0002 <span class="comment">%----------------------------------------------------------------------</span> |
---|
62 | 0003 <span class="comment">% function [DimVarIndex,CellVarIndex,NbDim,VarType]=find_field_indices(Data)</span> |
---|
63 | 0004 <span class="comment">%</span> |
---|
64 | 0005 <span class="comment">%OUTPUT:</span> |
---|
65 | 0006 <span class="comment">% CellVaxIndex: cell whose elements are arrays of indices in the list data.ListVarName</span> |
---|
66 | 0007 <span class="comment">% CellvarIndex{i} represents a set of variables with the same dimensions</span> |
---|
67 | 0008 <span class="comment">% NbDim: array with the length of CellVarIndex, giving its space dimension</span> |
---|
68 | 0009 <span class="comment">% VarType: cell array of structures with fields</span> |
---|
69 | 0010 <span class="comment">% .coord_x, y, z: indices (in .ListVarname) of variables representing unstructured coordinates x, y, z</span> |
---|
70 | 0011 <span class="comment">% .vector_x,_y,_z: indices of variables giving the vector components x, y, z</span> |
---|
71 | 0012 <span class="comment">% .warnflag: index of warnflag</span> |
---|
72 | 0013 <span class="comment">% .errorflag: index of error flag</span> |
---|
73 | 0014 <span class="comment">% .ancillary: indices of ancillary variables</span> |
---|
74 | 0015 <span class="comment">% .image : B/W image, (behaves like scalar)</span> |
---|
75 | 0016 <span class="comment">% .color : color image, the last index, which is not a coordinate variable, represent the color components</span> |
---|
76 | 0017 <span class="comment">% .scalar: scalar field</span> |
---|
77 | 0018 |
---|
78 | 0019 <span class="comment">%</span> |
---|
79 | 0020 <span class="comment">%INPUT:</span> |
---|
80 | 0021 <span class="comment">% Data: structure representing fields, output of check_field_structure</span> |
---|
81 | 0022 <span class="comment">% .ListDimName: cell listing the names of the array dimensions</span> |
---|
82 | 0023 <span class="comment">% .ListVarName: cell listing the names of the variables</span> |
---|
83 | 0024 <span class="comment">% .VarDimIndex: cell containing the set of dimension indices (in list .ListDimName) for each variable of .ListVarName</span> |
---|
84 | 0025 <span class="comment">%</span> |
---|
85 | 0026 <span class="comment">% HELP:</span> |
---|
86 | 0027 <span class="comment">% to get the dimensions of arrays common to the field #icell</span> |
---|
87 | 0028 <span class="comment">% VarIndex=CellVarIndex{icell}; % list of variable indices</span> |
---|
88 | 0029 <span class="comment">% DimIndex=Data.VarDimIndex{VarIndex(1)} % list of dimensions for each variable in the cell #icell</span> |
---|
89 | 0030 <span class="comment">%</span> |
---|
90 | 0031 <span class="comment">%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA</span> |
---|
91 | 0032 <span class="comment">% Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.</span> |
---|
92 | 0033 <span class="comment">%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA</span> |
---|
93 | 0034 <span class="comment">% This file is part of the toolbox UVMAT.</span> |
---|
94 | 0035 <span class="comment">%</span> |
---|
95 | 0036 <span class="comment">% UVMAT is free software; you can redistribute it and/or modify</span> |
---|
96 | 0037 <span class="comment">% it under the terms of the GNU General Public License as published by</span> |
---|
97 | 0038 <span class="comment">% the Free Software Foundation; either version 2 of the License, or</span> |
---|
98 | 0039 <span class="comment">% (at your option) any later version.</span> |
---|
99 | 0040 <span class="comment">%</span> |
---|
100 | 0041 <span class="comment">% UVMAT is distributed in the hope that it will be useful,</span> |
---|
101 | 0042 <span class="comment">% but WITHOUT ANY WARRANTY; without even the implied warranty of</span> |
---|
102 | 0043 <span class="comment">% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span> |
---|
103 | 0044 <span class="comment">% GNU General Public License (file UVMAT/COPYING.txt) for more details.</span> |
---|
104 | 0045 <span class="comment">%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA</span> |
---|
105 | 0046 |
---|
106 | 0047 <a name="_sub0" href="#_subfunctions" class="code">function [CellVarIndex,NbDim,VarType,errormsg]=find_field_indices(Data)</a> |
---|
107 | 0048 CellVarIndex={}; |
---|
108 | 0049 NbDim=[]; |
---|
109 | 0050 VarType=[]; |
---|
110 | 0051 errormsg=[]; |
---|
111 | 0052 nbvar=numel(Data.ListVarName);<span class="comment">%number of field variables</span> |
---|
112 | 0053 icell=0; |
---|
113 | 0054 ivardim=0; |
---|
114 | 0055 VarDimIndex=[]; |
---|
115 | 0056 VarDimName={}; |
---|
116 | 0057 |
---|
117 | 0058 <span class="keyword">if</span> ~isfield(Data,<span class="string">'VarDimName'</span>) |
---|
118 | 0059 errormsg=<span class="string">'missing .VarDimName'</span>; |
---|
119 | 0060 <span class="keyword">return</span> |
---|
120 | 0061 <span class="keyword">end</span> |
---|
121 | 0062 |
---|
122 | 0063 <span class="comment">%loop on the list of variables</span> |
---|
123 | 0064 <span class="keyword">for</span> ivar=1:nbvar |
---|
124 | 0065 DimCell=Data.VarDimName{ivar}; <span class="comment">%dimensions associated with the variable #ivar</span> |
---|
125 | 0066 <span class="keyword">if</span> ischar(DimCell) |
---|
126 | 0067 DimCell={DimCell}; |
---|
127 | 0068 Data.VarDimName{ivar}={Data.VarDimName{ivar}};<span class="comment">%transform char chain into cell</span> |
---|
128 | 0069 <span class="keyword">end</span> |
---|
129 | 0070 testnewcell=1; |
---|
130 | 0071 <span class="keyword">for</span> icell_prev=1:numel(CellVarIndex)<span class="comment">%detect whether the dimensions of ivar fit with an existing cell</span> |
---|
131 | 0072 PrevVarIndex=CellVarIndex{icell_prev}; |
---|
132 | 0073 PrevDimName=Data.VarDimName{PrevVarIndex(1)}; |
---|
133 | 0074 <span class="keyword">if</span> isequal(PrevDimName,DimCell) |
---|
134 | 0075 CellVarIndex{icell_prev}=[CellVarIndex{icell_prev} ivar];<span class="comment">% add variable index #ivar to the cell #icell_prev</span> |
---|
135 | 0076 testnewcell=0; <span class="comment">%existing cell detected</span> |
---|
136 | 0077 <span class="keyword">break</span> |
---|
137 | 0078 <span class="keyword">end</span> |
---|
138 | 0079 <span class="keyword">end</span> |
---|
139 | 0080 <span class="keyword">if</span> testnewcell |
---|
140 | 0081 icell=icell+1; |
---|
141 | 0082 CellVarIndex{icell}=ivar;<span class="comment">%put the current variabl index in the new cell</span> |
---|
142 | 0083 <span class="keyword">end</span> |
---|
143 | 0084 |
---|
144 | 0085 <span class="comment">%look for dimension variables</span> |
---|
145 | 0086 <span class="keyword">if</span> numel(DimCell)==1<span class="comment">% if the variable has a single dimension</span> |
---|
146 | 0087 Role=<span class="string">''</span>; |
---|
147 | 0088 <span class="keyword">if</span> isfield(Data,<span class="string">'VarAttribute'</span>) && length(Data.VarAttribute)>=ivar && isfield(Data.VarAttribute{ivar},<span class="string">'Role'</span>) |
---|
148 | 0089 Role=Data.VarAttribute{ivar}.Role; |
---|
149 | 0090 <span class="keyword">end</span> |
---|
150 | 0091 <span class="keyword">if</span> strcmp(DimCell{1},Data.ListVarName{ivar}) || strcmp(Role,<span class="string">'dimvar'</span>) |
---|
151 | 0092 ivardim=ivardim+1; |
---|
152 | 0093 VarDimIndex(ivardim)=ivar;<span class="comment">%index of the variable</span> |
---|
153 | 0094 VarDimName{ivardim}=DimCell{1};<span class="comment">%name of the dimension</span> |
---|
154 | 0095 <span class="keyword">end</span> |
---|
155 | 0096 <span class="keyword">end</span> |
---|
156 | 0097 <span class="keyword">end</span> |
---|
157 | 0098 |
---|
158 | 0099 <span class="comment">% find the spatial dimensions and vector components</span> |
---|
159 | 0100 ListRole={<span class="string">'coord_x'</span>,<span class="string">'coord_y'</span>,<span class="string">'coord_z'</span>,<span class="string">'vector_x'</span>,<span class="string">'vector_y'</span>,<span class="string">'vector_z'</span>,<span class="string">'warnflag'</span>,<span class="string">'errorflag'</span>,<span class="keyword">...</span> |
---|
160 | 0101 <span class="string">'ancillary'</span>,<span class="string">'image'</span>,<span class="string">'color'</span>,<span class="string">'discrete'</span>,<span class="string">'scalar'</span>}; |
---|
161 | 0102 <span class="keyword">for</span> icell=1:length(CellVarIndex) |
---|
162 | 0103 <span class="keyword">for</span> ilist=1:numel(ListRole) |
---|
163 | 0104 eval([<span class="string">'ivar_'</span> ListRole{ilist} <span class="string">'=[];'</span>]) |
---|
164 | 0105 <span class="keyword">end</span> |
---|
165 | 0106 VarIndex=CellVarIndex{icell};<span class="comment">%set of variable indices with the same dim</span> |
---|
166 | 0107 DimCell=Data.VarDimName{VarIndex(1)};<span class="comment">% list of dimensions for each variable in the cell #icell</span> |
---|
167 | 0108 <span class="keyword">if</span> isfield(Data,<span class="string">'VarAttribute'</span>); |
---|
168 | 0109 VarAttribute=Data.VarAttribute; |
---|
169 | 0110 <span class="keyword">else</span> |
---|
170 | 0111 VarAttribute={}; |
---|
171 | 0112 <span class="keyword">end</span> |
---|
172 | 0113 test_2D=0; |
---|
173 | 0114 <span class="keyword">for</span> ivar=VarIndex |
---|
174 | 0115 <span class="keyword">if</span> length(VarAttribute)>=ivar |
---|
175 | 0116 <span class="keyword">if</span> isfield(VarAttribute{ivar},<span class="string">'Role'</span>) |
---|
176 | 0117 role=VarAttribute{ivar}.Role; |
---|
177 | 0118 <span class="keyword">switch</span> role |
---|
178 | 0119 <span class="keyword">case</span> ListRole |
---|
179 | 0120 eval([<span class="string">'ivar_'</span> role <span class="string">'=[ivar_'</span> role <span class="string">' ivar];'</span>]) |
---|
180 | 0121 <span class="keyword">otherwise</span> |
---|
181 | 0122 ivar_scalar=[ivar_scalar ivar]; |
---|
182 | 0123 <span class="keyword">end</span> |
---|
183 | 0124 <span class="keyword">else</span> |
---|
184 | 0125 ivar_scalar=[ivar_scalar ivar];<span class="comment">% variable considered as scalar in the absence of Role attribute</span> |
---|
185 | 0126 <span class="keyword">end</span> |
---|
186 | 0127 <span class="keyword">if</span> isfield(VarAttribute{ivar},<span class="string">'Coord_2'</span>) |
---|
187 | 0128 test_2D=1; <span class="comment">%obsolete convention</span> |
---|
188 | 0129 <span class="keyword">end</span> |
---|
189 | 0130 <span class="keyword">else</span> |
---|
190 | 0131 ivar_scalar=[ivar_scalar ivar];<span class="comment">% variable considered as scalar in the absence of variable a attribute</span> |
---|
191 | 0132 <span class="keyword">end</span> |
---|
192 | 0133 <span class="keyword">end</span> |
---|
193 | 0134 <span class="keyword">for</span> ilist=1:numel(ListRole) |
---|
194 | 0135 eval([<span class="string">'VarType{icell}.'</span> ListRole{ilist} <span class="string">'=ivar_'</span> ListRole{ilist} <span class="string">';'</span>]) |
---|
195 | 0136 <span class="keyword">end</span> |
---|
196 | 0137 <span class="keyword">if</span> numel(ivar_coord_x)>1 || numel(ivar_coord_y)>1 || numel(ivar_coord_z)>1 |
---|
197 | 0138 errormsg=<span class="string">'multiply defined coordinates in the same cell'</span>; |
---|
198 | 0139 <span class="keyword">return</span> |
---|
199 | 0140 <span class="keyword">end</span> |
---|
200 | 0141 <span class="keyword">if</span> numel(ivar_vector_x)>1 || numel(ivar_vector_y)>1 || numel(ivar_vector_z)>1 |
---|
201 | 0142 errormsg=<span class="string">'more than one vector fields in the same cell'</span>; |
---|
202 | 0143 <span class="keyword">return</span> |
---|
203 | 0144 <span class="keyword">end</span> |
---|
204 | 0145 NbDim(icell)=0;<span class="comment">% nbre of space dimensions</span> |
---|
205 | 0146 <span class="keyword">if</span> ~isempty(ivar_coord_z) |
---|
206 | 0147 NbDim(icell)=3; |
---|
207 | 0148 <span class="keyword">elseif</span> ~isempty(ivar_coord_y) |
---|
208 | 0149 NbDim(icell)=2; |
---|
209 | 0150 <span class="keyword">elseif</span> ~isempty(ivar_coord_x) |
---|
210 | 0151 NbDim(icell)=1; |
---|
211 | 0152 <span class="keyword">end</span> |
---|
212 | 0153 |
---|
213 | 0154 <span class="comment">% look at coordinates variables</span> |
---|
214 | 0155 coord=zeros(1,numel(DimCell));<span class="comment">%default</span> |
---|
215 | 0156 <span class="keyword">if</span> NbDim(icell)==0 && ~isempty(VarDimName)<span class="comment">% no unstructured coordinate found</span> |
---|
216 | 0157 <span class="keyword">for</span> idim=1:numel(DimCell) <span class="comment">%loop on the dimensions of the variables in cell #icell</span> |
---|
217 | 0158 <span class="keyword">for</span> ivardim=1:numel(VarDimName) |
---|
218 | 0159 <span class="keyword">if</span> strcmp(VarDimName{ivardim},DimCell{idim}) |
---|
219 | 0160 coord(idim)=VarDimIndex(ivardim); |
---|
220 | 0161 <span class="keyword">break</span> |
---|
221 | 0162 <span class="keyword">end</span> |
---|
222 | 0163 <span class="keyword">end</span> |
---|
223 | 0164 <span class="keyword">end</span> |
---|
224 | 0165 NbDim(icell)=numel(find(coord)); |
---|
225 | 0166 <span class="keyword">end</span> |
---|
226 | 0167 VarType{icell}.coord=coord; |
---|
227 | 0168 <span class="keyword">if</span> NbDim(icell)==0 && test_2D <span class="comment">%look at attributes Coord_1, coord_2 (obsolete convention)</span> |
---|
228 | 0169 NbDim(icell)=2; |
---|
229 | 0170 <span class="keyword">end</span> |
---|
230 | 0171 <span class="keyword">end</span></pre></div> |
---|
231 | <hr><address>Generated on Fri 13-Nov-2009 11:17:03 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> © 2003</address> |
---|
232 | </body> |
---|
233 | </html> |
---|