source: trunk/src/read_civdata.m @ 378

Last change on this file since 378 was 372, checked in by sommeria, 13 years ago

many bugs repaired.

File size: 11.4 KB
Line 
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
49function [Field,VelTypeOut,errormsg]=read_civdata(filename,FieldNames,VelType,XI,YI)
50errormsg='';
51VelTypeOut=VelType;%default
52%% default input
53if ~exist('VelType','var')
54    VelType='';
55end
56if isequal(VelType,'*')
57    VelType='';
58end
59if isempty(VelType)
60    VelType='';
61end
62if ~exist('FieldNames','var')
63    FieldNames=[]; %default
64end
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
69if isfield(Field,'Txt')
70    errormsg=Field.Txt;
71    return
72end
73if vardetect(1)==0
74     errormsg=[ 'requested field not available in ' filename '/' VelType];
75     return
76end
77switch vel_type_out_cell{ichoice}
78    case{'civ1','fix1','patch1'}
79        Field.dt=Field.Civ1_Dt;
80    case{'civ2','fix2','patch2'}
81        Field.dt=Field.Civ2_Dt;
82end
83Field.ListGlobalAttribute=[Field.ListGlobalAttribute {'dt'}];
84var_ind=find(vardetect);
85for ivar=1:min(numel(var_ind),numel(Field.VarAttribute))
86    Field.VarAttribute{ivar}.Role=role{var_ind(ivar)};
87    Field.VarAttribute{ivar}.Unit=units{var_ind(ivar)};
88    Field.VarAttribute{ivar}.Mesh=0.1;%typical mesh for histograms O.1 pixel
89end
90if ~isempty(ichoice)
91    VelTypeOut=vel_type_out_cell{ichoice};
92end
93
94
95%% renaming for standard conventions
96%Field.NbCoord=Field.nb_coord;
97%Field.NbDim=2;%Field.nb_dim;
98
99%% CivStage
100% if isfield(Field,'patch2')&& isequal(Field.patch2,1)
101%     Field.CivStage=6;
102% elseif isfield(Field,'fix2')&& isequal(Field.fix2,1)
103%     Field.CivStage=5;
104% elseif isfield(Field,'civ2')&& isequal(Field.civ2,1)
105%     Field.CivStage=4;
106% elseif isfield(Field,'patch')&& isequal(Field.patch,1)
107%     Field.CivStage=3;
108% elseif isfield(Field,'fix')&& isequal(Field.fix,1)
109%     Field.CivStage=2;
110% else
111%     Field.CivStage=1;
112% end
113Field.ListGlobalAttribute=[Field.ListGlobalAttribute {'NbCoord','NbDim','TimeUnit','CoordUnit'}];
114% %determine the appropriate constant for time and dt for the PIV pair
115% test_civ1=isequal(VelTypeOut,'civ1')||isequal(VelTypeOut,'interp1')||isequal(VelTypeOut,'filter1');
116% test_civ2=isequal(VelTypeOut,'civ2')||isequal(VelTypeOut,'interp2')||isequal(VelTypeOut,'filter2');
117% Field.Time=0; %default
118% Field.TimeUnit='s';
119% if test_civ1
120%     if isfield(Field,'absolut_time_T0')
121%         Field.Time=double(Field.absolut_time_T0);
122%         Field.dt=double(Field.dt);
123%     else
124%        Field.Txt='the input file is not civx';
125%        Field.CivStage=0;
126%        Field.dt=0;
127%     end
128% elseif test_civ2
129%     Field.Time=double(Field.absolut_time_T0_2);
130%     Field.dt=double(Field.dt2);
131% else
132%     Field.Txt='the input file is not civx';
133%     Field.CivStage=0;
134%     Field.dt=0;
135% end
136%
137%
138%
139% %% update list of global attributes
140% List=Field.ListGlobalAttribute;
141% ind_remove=[];
142% for ilist=1:length(List)
143%     switch(List{ilist})
144%         case {'patch2','fix2','civ2','patch','fix','dt2','absolut_time_T0','absolut_time_T0_2','nb_coord','nb_dim','pixcmx','pixcmy'}
145%             ind_remove=[ind_remove ilist];
146%             Field=rmfield(Field,List{ilist});
147%     end
148% end
149% List(ind_remove)=[];
150% Field.ListGlobalAttribute=[{'NbCoord'},{'NbDim'} List {'Time','TimeUnit','CivStage','CoordUnit'}];
151Field.NbCoord=2;
152Field.NbDim=2;
153Field.TimeUnit='s';
154Field.CoordUnit='pixel';
155
156
157
158%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
159% TAKEN FROM read_civxdata NOT USED
160% [var,role,units,vel_type_out]=varcivx_generator(FieldNames,vel_type)
161%INPUT:
162% FieldNames =cell of field names to get, which can contain the strings:
163%             'ima_cor': image correlation, vec_c or vec2_C
164%             'vort','div','strain': requires velocity derivatives DUDX...
165%             'error': error estimate (vec_E or vec2_E)
166%             
167% vel_type: character string indicating the types of velocity fields to read ('civ1','civ2'...)
168%            if vel_type=[] or'*', a  priority choice, given by vel_type_out{1,2}, is done depending
169%            if vel_type='filter'; a structured field is sought (filter2 in priority, then filter1)
170
171function [var,role,units,vel_type_out]=varcivx_generator(FieldNames,vel_type)
172
173%% default input values
174if ~exist('vel_type','var'),vel_type='';end;
175if iscell(vel_type),vel_type=vel_type{1}; end;%transform cell to string if needed
176if ~exist('FieldNames','var'),FieldNames={'ima_cor'};end;%default scalar
177if ischar(FieldNames), FieldNames={FieldNames}; end;
178
179%% select the priority order for automatic vel_type selection
180testder=0;
181testpatch=0;
182for ilist=1:length(FieldNames)
183    if ~isempty(FieldNames{ilist})
184    switch FieldNames{ilist}
185        case{'u','v'}
186            testpatch=1;
187        case {'vort','div','strain'}
188            testder=1;
189    end
190    end
191end   
192switch vel_type
193    case 'civ1'
194        var={'X','Y','Z','U','V','W','C','F','FF';...
195            'Civ1_X','Civ1_Y','Civ1_Z','Civ1_U','Civ1_V','Civ1_W','Civ1_C','Civ1_F','Civ1_FF'};
196        role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag'};
197        units={'pixel','pixel','pixel','pixel','pixel','pixel',[],[],[]};
198    case 'interp1'
199        var={'X','Y','Z','U','V','W','FF';...
200            'Civ1_X','Civ1_Y','','Civ1_U_Diff','Civ1_V_Diff','','Civ1_FF'};
201        role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','errorflag'};
202        units={'pixel','pixel','pixel','pixel','pixel','pixel',[]};
203    case 'filter1'
204        var={'X_tps','Y_tps','Z_tps','U_tps','V_tps','W_tps','X_SubRange','Y_SubRange','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    case 'civ2'
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        role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag'};
212        units={'pixel','pixel','pixel','pixel','pixel','pixel',[],[],[]};
213    case 'interp2'
214        var={'X','Y','Z','U','V','W','FF';...
215            'Civ2_X','Civ2_Y','','Civ2_U_Diff','Civ2_V_Diff','','Civ2_FF'};
216        role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','errorflag'};
217        units={'pixel','pixel','pixel','pixel','pixel','pixel',[]};
218    case 'filter2'
219        var={'X_tps','Y_tps','Z_tps','U_tps','V_tps','W_tps','X_SubRange','Y_SubRange','NbSites';...
220            'Civ2_X_tps','Civ2_Y_tps','','Civ2_U_tps','Civ2_V_tps','','Civ2_X_SubRange','Civ2_Y_SubRange','Civ2_NbSites'};
221        role={'','','','','','','','',''};
222        units={'pixel','pixel','pixel','pixel','pixel','pixel','pixel','pixel',''};
223    otherwise % if VelType=[], choose the best field, civ in priority, or patch2 for derivatives
224        if testpatch
225            var={'X_tps','Y_tps','Z_tps','U_tps','V_tps','W_tps','X_SubRange','Y_SubRange','NbSites';...
226                'Civ2_X_tps','Civ2_Y_tps','','Civ2_U_tps','Civ2_V_tps','','Civ2_X_SubRange','Civ2_Y_SubRange','Civ2_NbSites';...
227                'Civ1_X_tps','Civ1_Y_tps','','Civ1_U_tps','Civ1_V_tps','','Civ1_X_SubRange','Civ1_Y_SubRange','Civ1_NbSites'};
228            role={'','','','','','','',''};
229            units={'pixel','pixel','pixel','pixel','pixel','pixel','pixel','pixel'};
230        else
231            var={'X','Y','Z','U','V','W','C','F','FF';...
232                'Civ2_X','Civ2_Y','Civ2_Z','Civ2_U','Civ2_V','Civ2_W','Civ2_C','Civ2_F','Civ2_FF';...
233                'Civ1_X','Civ1_Y','Civ1_Z','Civ1_U','Civ1_V','Civ1_W','Civ1_C','Civ1_F','Civ1_FF'};
234            role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag'};
235            units={'pixel','pixel','pixel','pixel','pixel','pixel',[],[],[]};
236        end
237end
238if isempty(vel_type) || isequal(vel_type,'*') %undefined velocity type (civ1,civ2...)
239    if testder
240         vel_type_out{1}='filter2'; %priority to filter2 for scalar reading, filter1 as second
241        vel_type_out{2}='filter1';
242    else
243        vel_type_out{1}='civ2'; %priority to civ2 for vector reading, civ1 as second priority     
244        vel_type_out{2}='civ1';
245    end
246elseif isequal(vel_type,'filter')
247        vel_type_out{1}='filter2'; %priority to filter2 for scalar reading, filter1 as second
248        vel_type_out{2}='filter1';
249        if ~testder
250            vel_type_out{3}='civ1';%civ1 as third priority if derivatives are not needed
251        end
252elseif testder
253    test_civ1=isequal(vel_type,'civ1')||isequal(vel_type,'interp1')||isequal(vel_type,'filter1');
254    if test_civ1
255        vel_type_out{1}='filter1'; %switch to filter for reading spatial derivatives
256    else
257        vel_type_out{1}='filter2';
258    end
259else   
260    vel_type_out{1}=vel_type;%imposed velocity field
261end
262vel_type_out=vel_type_out';
263
264
265
266
267
268
Note: See TracBrowser for help on using the repository browser.