source: trunk/src/read_civdata.m @ 364

Last change on this file since 364 was 364, checked in by sommeria, 12 years ago

civ2, fix2, patch2 introduced under Matlab (no interpolation and rotation done yet)
small corrections in plot_field and read_civdata

File size: 11.2 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
77var_ind=find(vardetect);
78for 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
82end
83if ~isempty(ichoice)
84    VelTypeOut=vel_type_out_cell{ichoice};
85end
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
106Field.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'}];
144Field.NbCoord=2;
145Field.NbDim=2;
146Field.TimeUnit='s';
147Field.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
164function [var,role,units,vel_type_out]=varcivx_generator(FieldNames,vel_type)
165
166%% default input values
167if ~exist('vel_type','var'),vel_type='';end;
168if iscell(vel_type),vel_type=vel_type{1}; end;%transform cell to string if needed
169if ~exist('FieldNames','var'),FieldNames={'ima_cor'};end;%default scalar
170if ischar(FieldNames), FieldNames={FieldNames}; end;
171
172%% select the priority order for automatic vel_type selection
173testder=0;
174testpatch=0;
175for 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
184end   
185switch 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    case 'civ2'
202        var={'X','Y','Z','U','V','W','C','F','FF';...
203            'Civ2_X','Civ2_Y','Civ2_Z','Civ2_U','Civ2_V','Civ2_W','Civ2_C','Civ2_F','Civ2_FF'};
204        role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag'};
205        units={'pixel','pixel','pixel','pixel','pixel','pixel',[],[],[]};
206    case 'interp2'
207        var={'X','Y','Z','U','V','W','FF';...
208            'Civ2_X','Civ2_Y','','Civ2_U_Diff','Civ2_V_Diff','','Civ2_FF'};
209        role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','errorflag'};
210        units={'pixel','pixel','pixel','pixel','pixel','pixel',[]};
211    case 'filter2'
212        var={'X_tps','Y_tps','Z_tps','U_tps','V_tps','W_tps','X_SubRange','Y_SubRange','NbSites';...
213            'Civ2_X_tps','Civ2_Y_tps','','Civ2_U_tps','Civ2_V_tps','','Civ2_X_SubRange','Civ2_Y_SubRange','Civ2_NbSites'};
214        role={'','','','','','','','',''};
215        units={'pixel','pixel','pixel','pixel','pixel','pixel','pixel','pixel',''};
216    otherwise % if VelType=[], choose the best field, civ in priority, or patch2 for derivatives
217        if testpatch
218            var={'X_tps','Y_tps','Z_tps','U_tps','V_tps','W_tps','X_SubRange','Y_SubRange','NbSites';...
219                'Civ2_X_tps','Civ2_Y_tps','','Civ2_U_tps','Civ2_V_tps','','Civ2_X_SubRange','Civ2_Y_SubRange','Civ2_NbSites';...
220                'Civ1_X_tps','Civ1_Y_tps','','Civ1_U_tps','Civ1_V_tps','','Civ1_X_SubRange','Civ1_Y_SubRange','Civ1_NbSites'};
221            role={'','','','','','','',''};
222            units={'pixel','pixel','pixel','pixel','pixel','pixel','pixel','pixel'};
223        else
224            var={'X','Y','Z','U','V','W','C','F','FF';...
225                'Civ2_X','Civ2_Y','Civ2_Z','Civ2_U','Civ2_V','Civ2_W','Civ2_C','Civ2_F','Civ2_FF';...
226                'Civ1_X','Civ1_Y','Civ1_Z','Civ1_U','Civ1_V','Civ1_W','Civ1_C','Civ1_F','Civ1_FF'};
227            role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag'};
228            units={'pixel','pixel','pixel','pixel','pixel','pixel',[],[],[]};
229        end
230end
231if isempty(vel_type) || isequal(vel_type,'*') %undefined velocity type (civ1,civ2...)
232    if testder
233         vel_type_out{1}='filter2'; %priority to filter2 for scalar reading, filter1 as second
234        vel_type_out{2}='filter1';
235    else
236        vel_type_out{1}='civ2'; %priority to civ2 for vector reading, civ1 as second priority     
237        vel_type_out{2}='civ1';
238    end
239elseif isequal(vel_type,'filter')
240        vel_type_out{1}='filter2'; %priority to filter2 for scalar reading, filter1 as second
241        vel_type_out{2}='filter1';
242        if ~testder
243            vel_type_out{3}='civ1';%civ1 as third priority if derivatives are not needed
244        end
245elseif testder
246    test_civ1=isequal(vel_type,'civ1')||isequal(vel_type,'interp1')||isequal(vel_type,'filter1');
247    if test_civ1
248        vel_type_out{1}='filter1'; %switch to filter for reading spatial derivatives
249    else
250        vel_type_out{1}='filter2';
251    end
252else   
253    vel_type_out{1}=vel_type;%imposed velocity field
254end
255vel_type_out=vel_type_out';
256
257
258
259
260
261
Note: See TracBrowser for help on using the repository browser.