1 | %'read_civdata': reads new civ data from netcdf files
|
---|
2 | %------------------------------------------------------------------
|
---|
3 | %
|
---|
4 | % function [Field,VelTypeOut]=read_civxdata(filename,FieldNames,VelType)
|
---|
5 | %
|
---|
6 | % OUTPUT:
|
---|
7 | % Field: structure representing the selected field, containing
|
---|
8 | % .Txt: (char string) error message if any
|
---|
9 | % .ListGlobalAttribute: list of global attributes containing:
|
---|
10 | % .NbCoord: number of vector components
|
---|
11 | % .NbDim: number of dimensions (=2 or 3)
|
---|
12 | % .dt: time interval for the corresponding image pair
|
---|
13 | % .Time: absolute time (average of the initial image pair)
|
---|
14 | % .CivStage: =0,
|
---|
15 | % =1, civ1 has been performed only
|
---|
16 | % =2, fix1 has been performed
|
---|
17 | % =3, pacth1 has been performed
|
---|
18 | % =4, civ2 has been performed
|
---|
19 | % =5, fix2 has been performed
|
---|
20 | % =6, pacth2 has been performed
|
---|
21 | % .CoordUnit: 'pixel'
|
---|
22 | % .ListVarName: {'X' 'Y' 'U' 'V' 'F' 'FF'}
|
---|
23 | % .X, .Y, .Z: set of vector coordinates
|
---|
24 | % .U,.V,.W: corresponding set of vector components
|
---|
25 | % .F: warning flags
|
---|
26 | % .FF: error flag, =0 for good vectors
|
---|
27 | % .C: scalar associated with velocity (used for vector colors)
|
---|
28 | % .DijU; matrix of spatial derivatives (DijU(1,1,:)=DUDX,
|
---|
29 | % DijU(1,2,:)=DUDY, Dij(2,1,:)=DVDX, DijU(2,2,:)=DVDY
|
---|
30 | %
|
---|
31 | % VelTypeOut: velocity type corresponding to the selected field: ='civ1','interp1','interp2','civ2'....
|
---|
32 | %
|
---|
33 | % INPUT:
|
---|
34 | % filename: file name (string).
|
---|
35 | % FieldNames =cell of field names to get, which can contain the strings:
|
---|
36 | % 'ima_cor': image correlation, vec_c or vec2_C
|
---|
37 | % 'vort','div','strain': requires velocity derivatives DUDX...
|
---|
38 | % 'error': error estimate (vec_E or vec2_E)
|
---|
39 | %
|
---|
40 | % VelType : character string indicating the types of velocity fields to read ('civ1','civ2'...)
|
---|
41 | % if vel_type=[] or'*', a priority choice, given by vel_type_out{1,2}, is done depending
|
---|
42 | % if vel_type='filter'; a structured field is sought (filter2 in priority, then filter1)
|
---|
43 |
|
---|
44 |
|
---|
45 | % FUNCTIONS called:
|
---|
46 | % 'varcivx_generator':, sets the names of vaiables to read in the netcdf file
|
---|
47 | % 'nc2struct': reads a netcdf file
|
---|
48 |
|
---|
49 | function [Field,VelTypeOut,errormsg]=read_civdata(filename,FieldNames,VelType,XI,YI)
|
---|
50 | errormsg='';
|
---|
51 | VelTypeOut=VelType;%default
|
---|
52 | %% default input
|
---|
53 | if ~exist('VelType','var')
|
---|
54 | VelType='';
|
---|
55 | end
|
---|
56 | if isequal(VelType,'*')
|
---|
57 | VelType='';
|
---|
58 | end
|
---|
59 | if isempty(VelType)
|
---|
60 | VelType='';
|
---|
61 | end
|
---|
62 | if ~exist('FieldNames','var')
|
---|
63 | FieldNames=[]; %default
|
---|
64 | end
|
---|
65 |
|
---|
66 | %% reading data
|
---|
67 | [varlist,role,units,vel_type_out_cell]=varcivx_generator(FieldNames,VelType);
|
---|
68 | [Field,vardetect,ichoice]=nc2struct(filename,varlist);%read the variables in the netcdf file
|
---|
69 | if isfield(Field,'Txt')
|
---|
70 | errormsg=Field.Txt;
|
---|
71 | return
|
---|
72 | end
|
---|
73 | if vardetect(1)==0
|
---|
74 | errormsg=[ 'requested field not available in ' filename '/' VelType];
|
---|
75 | return
|
---|
76 | end
|
---|
77 | var_ind=find(vardetect);
|
---|
78 | for ivar=1:min(numel(var_ind),numel(Field.VarAttribute))
|
---|
79 | Field.VarAttribute{ivar}.Role=role{var_ind(ivar)};
|
---|
80 | Field.VarAttribute{ivar}.Unit=units{var_ind(ivar)};
|
---|
81 | Field.VarAttribute{ivar}.Mesh=0.1;%typical mesh for histograms O.1 pixel
|
---|
82 | end
|
---|
83 | if ~isempty(ichoice)
|
---|
84 | VelTypeOut=vel_type_out_cell{ichoice};
|
---|
85 | end
|
---|
86 |
|
---|
87 |
|
---|
88 | %% renaming for standard conventions
|
---|
89 | %Field.NbCoord=Field.nb_coord;
|
---|
90 | %Field.NbDim=2;%Field.nb_dim;
|
---|
91 |
|
---|
92 | %% CivStage
|
---|
93 | % if isfield(Field,'patch2')&& isequal(Field.patch2,1)
|
---|
94 | % Field.CivStage=6;
|
---|
95 | % elseif isfield(Field,'fix2')&& isequal(Field.fix2,1)
|
---|
96 | % Field.CivStage=5;
|
---|
97 | % elseif isfield(Field,'civ2')&& isequal(Field.civ2,1)
|
---|
98 | % Field.CivStage=4;
|
---|
99 | % elseif isfield(Field,'patch')&& isequal(Field.patch,1)
|
---|
100 | % Field.CivStage=3;
|
---|
101 | % elseif isfield(Field,'fix')&& isequal(Field.fix,1)
|
---|
102 | % Field.CivStage=2;
|
---|
103 | % else
|
---|
104 | % Field.CivStage=1;
|
---|
105 | % end
|
---|
106 | Field.ListGlobalAttribute=[Field.ListGlobalAttribute {'NbCoord','NbDim','TimeUnit','CoordUnit'}];
|
---|
107 | % %determine the appropriate constant for time and dt for the PIV pair
|
---|
108 | % test_civ1=isequal(VelTypeOut,'civ1')||isequal(VelTypeOut,'interp1')||isequal(VelTypeOut,'filter1');
|
---|
109 | % test_civ2=isequal(VelTypeOut,'civ2')||isequal(VelTypeOut,'interp2')||isequal(VelTypeOut,'filter2');
|
---|
110 | % Field.Time=0; %default
|
---|
111 | % Field.TimeUnit='s';
|
---|
112 | % if test_civ1
|
---|
113 | % if isfield(Field,'absolut_time_T0')
|
---|
114 | % Field.Time=double(Field.absolut_time_T0);
|
---|
115 | % Field.dt=double(Field.dt);
|
---|
116 | % else
|
---|
117 | % Field.Txt='the input file is not civx';
|
---|
118 | % Field.CivStage=0;
|
---|
119 | % Field.dt=0;
|
---|
120 | % end
|
---|
121 | % elseif test_civ2
|
---|
122 | % Field.Time=double(Field.absolut_time_T0_2);
|
---|
123 | % Field.dt=double(Field.dt2);
|
---|
124 | % else
|
---|
125 | % Field.Txt='the input file is not civx';
|
---|
126 | % Field.CivStage=0;
|
---|
127 | % Field.dt=0;
|
---|
128 | % end
|
---|
129 | %
|
---|
130 | %
|
---|
131 | %
|
---|
132 | % %% update list of global attributes
|
---|
133 | % List=Field.ListGlobalAttribute;
|
---|
134 | % ind_remove=[];
|
---|
135 | % for ilist=1:length(List)
|
---|
136 | % switch(List{ilist})
|
---|
137 | % case {'patch2','fix2','civ2','patch','fix','dt2','absolut_time_T0','absolut_time_T0_2','nb_coord','nb_dim','pixcmx','pixcmy'}
|
---|
138 | % ind_remove=[ind_remove ilist];
|
---|
139 | % Field=rmfield(Field,List{ilist});
|
---|
140 | % end
|
---|
141 | % end
|
---|
142 | % List(ind_remove)=[];
|
---|
143 | % Field.ListGlobalAttribute=[{'NbCoord'},{'NbDim'} List {'Time','TimeUnit','CivStage','CoordUnit'}];
|
---|
144 | Field.NbCoord=2;
|
---|
145 | Field.NbDim=2;
|
---|
146 | Field.TimeUnit='s';
|
---|
147 | Field.CoordUnit='pixel';
|
---|
148 |
|
---|
149 |
|
---|
150 |
|
---|
151 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
152 | % TAKEN FROM read_civxdata NOT USED
|
---|
153 | % [var,role,units,vel_type_out]=varcivx_generator(FieldNames,vel_type)
|
---|
154 | %INPUT:
|
---|
155 | % FieldNames =cell of field names to get, which can contain the strings:
|
---|
156 | % 'ima_cor': image correlation, vec_c or vec2_C
|
---|
157 | % 'vort','div','strain': requires velocity derivatives DUDX...
|
---|
158 | % 'error': error estimate (vec_E or vec2_E)
|
---|
159 | %
|
---|
160 | % vel_type: character string indicating the types of velocity fields to read ('civ1','civ2'...)
|
---|
161 | % if vel_type=[] or'*', a priority choice, given by vel_type_out{1,2}, is done depending
|
---|
162 | % if vel_type='filter'; a structured field is sought (filter2 in priority, then filter1)
|
---|
163 |
|
---|
164 | function [var,role,units,vel_type_out]=varcivx_generator(FieldNames,vel_type)
|
---|
165 |
|
---|
166 | %% default input values
|
---|
167 | if ~exist('vel_type','var'),vel_type='';end;
|
---|
168 | if iscell(vel_type),vel_type=vel_type{1}; end;%transform cell to string if needed
|
---|
169 | if ~exist('FieldNames','var'),FieldNames={'ima_cor'};end;%default scalar
|
---|
170 | if ischar(FieldNames), FieldNames={FieldNames}; end;
|
---|
171 |
|
---|
172 | %% select the priority order for automatic vel_type selection
|
---|
173 | testder=0;
|
---|
174 | testpatch=0;
|
---|
175 | for ilist=1:length(FieldNames)
|
---|
176 | if ~isempty(FieldNames{ilist})
|
---|
177 | switch FieldNames{ilist}
|
---|
178 | case{'u','v'}
|
---|
179 | testpatch=1;
|
---|
180 | case {'vort','div','strain'}
|
---|
181 | testder=1;
|
---|
182 | end
|
---|
183 | end
|
---|
184 | end
|
---|
185 | switch vel_type
|
---|
186 | case 'civ1'
|
---|
187 | var={'X','Y','Z','U','V','W','C','F','FF';...
|
---|
188 | 'Civ1_X','Civ1_Y','Civ1_Z','Civ1_U','Civ1_V','Civ1_W','Civ1_C','Civ1_F','Civ1_FF'};
|
---|
189 | role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag'};
|
---|
190 | units={'pixel','pixel','pixel','pixel','pixel','pixel',[],[],[]};
|
---|
191 | case 'interp1'
|
---|
192 | var={'X','Y','Z','U','V','W','FF';...
|
---|
193 | 'Civ1_X','Civ1_Y','','Civ1_U_Diff','Civ1_V_Diff','','Civ1_FF'};
|
---|
194 | role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','errorflag'};
|
---|
195 | units={'pixel','pixel','pixel','pixel','pixel','pixel',[]};
|
---|
196 | case 'filter1'
|
---|
197 | var={'X_tps','Y_tps','Z_tps','U_tps','V_tps','W_tps','X_SubRange','Y_SubRange','NbSites';...
|
---|
198 | 'Civ1_X_tps','Civ1_Y_tps','','Civ1_U_tps','Civ1_V_tps','','Civ1_X_SubRange','Civ1_Y_SubRange','Civ1_NbSites'};
|
---|
199 | role={'','','','','','','','',''};
|
---|
200 | units={'pixel','pixel','pixel','pixel','pixel','pixel','pixel','pixel',''};
|
---|
201 | otherwise % if VelType=[]
|
---|
202 | if testpatch
|
---|
203 | var={'X_tps','Y_tps','Z_tps','U_tps','V_tps','W_tps','X_SubRange','Y_SubRange','NbSites';...
|
---|
204 | 'Civ2_X_tps','Civ2_Y_tps','','Civ2_U_tps','Civ2_V_tps','','Civ2_X_SubRange','Civ2_Y_SubRange','Civ2_NbSites';...
|
---|
205 | 'Civ1_X_tps','Civ1_Y_tps','','Civ1_U_tps','Civ1_V_tps','','Civ1_X_SubRange','Civ1_Y_SubRange','Civ1_NbSites'};
|
---|
206 | role={'','','','','','','',''};
|
---|
207 | units={'pixel','pixel','pixel','pixel','pixel','pixel','pixel','pixel'};
|
---|
208 | else
|
---|
209 | var={'X','Y','Z','U','V','W','C','F','FF';...
|
---|
210 | 'Civ2_X','Civ2_Y','Civ2_Z','Civ2_U','Civ2_V','Civ2_W','Civ2_C','Civ2_F','Civ2_FF';...
|
---|
211 | 'Civ1_X','Civ1_Y','Civ1_Z','Civ1_U','Civ1_V','Civ1_W','Civ1_C','Civ1_F','Civ1_FF'};
|
---|
212 | role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag'};
|
---|
213 | units={'pixel','pixel','pixel','pixel','pixel','pixel',[],[],[]};
|
---|
214 | end
|
---|
215 | end
|
---|
216 | if isempty(vel_type) || isequal(vel_type,'*') %undefined velocity type (civ1,civ2...)
|
---|
217 | if testder
|
---|
218 | vel_type_out{1}='filter2'; %priority to filter2 for scalar reading, filter1 as second
|
---|
219 | vel_type_out{2}='filter1';
|
---|
220 | else
|
---|
221 | vel_type_out{1}='civ2'; %priority to civ2 for vector reading, civ1 as second priority
|
---|
222 | vel_type_out{2}='civ1';
|
---|
223 | end
|
---|
224 | elseif isequal(vel_type,'filter')
|
---|
225 | vel_type_out{1}='filter2'; %priority to filter2 for scalar reading, filter1 as second
|
---|
226 | vel_type_out{2}='filter1';
|
---|
227 | if ~testder
|
---|
228 | vel_type_out{3}='civ1';%civ1 as third priority if derivatives are not needed
|
---|
229 | end
|
---|
230 | elseif testder
|
---|
231 | test_civ1=isequal(vel_type,'civ1')||isequal(vel_type,'interp1')||isequal(vel_type,'filter1');
|
---|
232 | if test_civ1
|
---|
233 | vel_type_out{1}='filter1'; %switch to filter for reading spatial derivatives
|
---|
234 | else
|
---|
235 | vel_type_out{1}='filter2';
|
---|
236 | end
|
---|
237 | else
|
---|
238 | vel_type_out{1}=vel_type;%imposed velocity field
|
---|
239 | end
|
---|
240 | vel_type_out=vel_type_out';
|
---|
241 |
|
---|
242 |
|
---|
243 |
|
---|
244 |
|
---|
245 |
|
---|
246 |
|
---|