source: trunk/src/read_civdata.m @ 237

Last change on this file since 237 was 237, checked in by sommeria, 14 years ago

function read_civdata to read new PIV files (Conventions:uvmat/civdata)

File size: 11.0 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)
50errormsg='';
51VelTypeOut=VelType;%default
52%% default input
53if ~exist('VelType','var')
54    VelType=[];
55end
56if isequal(VelType,'*')
57    VelType=[];
58end
59if ~exist('FieldNames','var')
60    FieldNames=[]; %default
61end
62
63%% reading data
64%[var,role,units,vel_type_out_cell]=varcivx_generator(FieldNames,VelType);%determine the names of constants and variables to read
65% if isempty(VelType)
66%     VelType='civ1';
67% end
68% if isequal(VelType,'civ1')
69%     varlist=[{'X','Y','U','V','C','F','FF'};... %output names
70%         {'Civ1_X','Civ1_Y','Civ1_U','Civ1_V','Civ1_C','Civ1_F','Civ1_FF'}];%names in file
71%     role={'coord_x','coord_y','vector_x','vector_y','ancillary','warnflag','errorflag'};
72%     units={'pixel','pixel','pixel','pixel','','',''};
73% elseif isequal(VelType,'interp1')|| isequal(VelType,'filter1')% read diff between spline and initial data (change name interp1 -> splinediff
74%     varlist=[{'X','Y','U','V'};... %output names
75%         {'Civ1_X','Civ1_Y','Patch1_U','Patch1_V'}];
76%     role = {'coord_x','coord_y','vector_x','vector_y'};
77%     units={'pixel','pixel','pixel','pixel'};
78% end
79[varlist,role,units,vel_type_out_cell]=varcivx_generator(FieldNames,VelType);
80[Field,vardetect,ichoice]=nc2struct(filename,varlist);%read the variables in the netcdf file
81if isfield(Field,'Txt')
82    errormsg=Field.Txt;
83    return
84end
85if vardetect(1)==0
86     errormsg=[ 'requested field not available in ' filename '/' VelType];
87     return
88end
89var_ind=find(vardetect);
90for ivar=1:length(var_ind)
91    Field.VarAttribute{ivar}.Role=role{var_ind(ivar)};
92    Field.VarAttribute{ivar}.Unit=units{var_ind(ivar)};
93    Field.VarAttribute{ivar}.Mesh=0.1;%typical mesh for histograms O.1 pixel
94end
95
96if ~isempty(ichoice)
97    VelTypeOut=vel_type_out_cell{ichoice};
98end
99%  Field.CivStage=3;%for patch, to generalise
100% return
101
102%% renaming for standard conventions
103%Field.NbCoord=Field.nb_coord;
104%Field.NbDim=2;%Field.nb_dim;
105
106%% CivStage
107% if isfield(Field,'patch2')&& isequal(Field.patch2,1)
108%     Field.CivStage=6;
109% elseif isfield(Field,'fix2')&& isequal(Field.fix2,1)
110%     Field.CivStage=5;
111% elseif isfield(Field,'civ2')&& isequal(Field.civ2,1)
112%     Field.CivStage=4;
113% elseif isfield(Field,'patch')&& isequal(Field.patch,1)
114%     Field.CivStage=3;
115% elseif isfield(Field,'fix')&& isequal(Field.fix,1)
116%     Field.CivStage=2;
117% else
118%     Field.CivStage=1;
119% end
120Field.ListGlobalAttribute=[Field.ListGlobalAttribute {'NbCoord','NbDim','TimeUnit','CoordUnit'}];
121% %determine the appropriate constant for time and dt for the PIV pair
122% test_civ1=isequal(VelTypeOut,'civ1')||isequal(VelTypeOut,'interp1')||isequal(VelTypeOut,'filter1');
123% test_civ2=isequal(VelTypeOut,'civ2')||isequal(VelTypeOut,'interp2')||isequal(VelTypeOut,'filter2');
124% Field.Time=0; %default
125% Field.TimeUnit='s';
126% if test_civ1
127%     if isfield(Field,'absolut_time_T0')
128%         Field.Time=double(Field.absolut_time_T0);
129%         Field.dt=double(Field.dt);
130%     else
131%        Field.Txt='the input file is not civx';
132%        Field.CivStage=0;
133%        Field.dt=0;
134%     end
135% elseif test_civ2
136%     Field.Time=double(Field.absolut_time_T0_2);
137%     Field.dt=double(Field.dt2);
138% else
139%     Field.Txt='the input file is not civx';
140%     Field.CivStage=0;
141%     Field.dt=0;
142% end
143%
144%
145%
146% %% update list of global attributes
147% List=Field.ListGlobalAttribute;
148% ind_remove=[];
149% for ilist=1:length(List)
150%     switch(List{ilist})
151%         case {'patch2','fix2','civ2','patch','fix','dt2','absolut_time_T0','absolut_time_T0_2','nb_coord','nb_dim','pixcmx','pixcmy'}
152%             ind_remove=[ind_remove ilist];
153%             Field=rmfield(Field,List{ilist});
154%     end
155% end
156% List(ind_remove)=[];
157% Field.ListGlobalAttribute=[{'NbCoord'},{'NbDim'} List {'Time','TimeUnit','CivStage','CoordUnit'}];
158Field.NbCoord=2;
159Field.NbDim=2;
160Field.TimeUnit='s';
161Field.CoordUnit='pixel';
162
163
164%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
165% TAKEN FROM read_civxdata NOT USED
166% [var,role,units,vel_type_out]=varcivx_generator(FieldNames,vel_type)
167%INPUT:
168% FieldNames =cell of field names to get, which can contain the strings:
169%             'ima_cor': image correlation, vec_c or vec2_C
170%             'vort','div','strain': requires velocity derivatives DUDX...
171%             'error': error estimate (vec_E or vec2_E)
172%             
173% vel_type: character string indicating the types of velocity fields to read ('civ1','civ2'...)
174%            if vel_type=[] or'*', a  priority choice, given by vel_type_out{1,2}, is done depending
175%            if vel_type='filter'; a structured field is sought (filter2 in priority, then filter1)
176
177function [var,role,units,vel_type_out]=varcivx_generator(FieldNames,vel_type)
178
179%% default input values
180if ~exist('vel_type','var'),vel_type=[];end;
181if iscell(vel_type),vel_type=vel_type{1}; end;%transform cell to string if needed
182if ~exist('FieldNames','var'),FieldNames={'ima_cor'};end;%default scalar
183if ischar(FieldNames), FieldNames={FieldNames}; end;
184
185%% select the priority order for automatic vel_type selection
186testder=0;
187for ilist=1:length(FieldNames)
188    if ~isempty(FieldNames{ilist})
189    switch FieldNames{ilist}
190        case {'vort','div','strain'}
191            testder=1;
192    end
193    end
194end     
195if isempty(vel_type) || isequal(vel_type,'*') %undefined velocity type (civ1,civ2...)
196    if testder
197         vel_type_out{1}='filter2'; %priority to filter2 for scalar reading, filter1 as second
198        vel_type_out{2}='filter1';
199    else
200        vel_type_out{1}='civ2'; %priority to civ2 for vector reading, civ1 as second priority     
201        vel_type_out{2}='civ1';
202    end
203elseif isequal(vel_type,'filter')
204        vel_type_out{1}='filter2'; %priority to filter2 for scalar reading, filter1 as second
205        vel_type_out{2}='filter1';
206        if ~testder
207            vel_type_out{3}='civ1';%civ1 as third priority if derivatives are not needed
208        end
209elseif testder
210    test_civ1=isequal(vel_type,'civ1')||isequal(vel_type,'interp1')||isequal(vel_type,'filter1');
211    if test_civ1
212        vel_type_out{1}='filter1'; %switch to filter for reading spatial derivatives
213    else
214        vel_type_out{1}='filter2';
215    end
216else   
217    vel_type_out{1}=vel_type;%imposed velocity field
218end
219vel_type_out=vel_type_out';
220
221%% determine names of netcdf variables to read
222var={'X','Y','Z','U','V','W','C','F','FF'};
223role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag'};
224units={'pixel','pixel','pixel','pixel','pixel','pixel',[],[],[]};
225if testder
226    var=[var {'DjUi(:,1,1)','DjUi(:,1,2)','DjUi(:,2,1)','DjUi(:,2,2)'}];
227    role=[role {'tensor','tensor','tensor','tensor'}];
228    units=[units {'pixel','pixel','pixel','pixel'}];
229end
230for ilist=1:length(vel_type_out)
231    var=[var;varname1(vel_type_out{ilist},FieldNames)];
232end
233
234%------------------------------------------------------------------------ 
235% TAKEN FROM read_civxdata NOT USED
236%--- determine  var names to read
237
238function varin=varname1(vel_type,FieldNames)
239%------------------------------------------------------------------------
240testder=0;
241C1='';
242C2='';
243for ilist=1:length(FieldNames)
244    if ~isempty(FieldNames{ilist})
245    switch FieldNames{ilist}
246        case 'ima_cor' %image correlation corresponding to a vel vector
247            C1='vec_C';
248            C2='vec2_C';
249        case 'error'
250            C1='vec_E';
251            C2='vec2_E';
252        case {'vort','div','strain'}
253            testder=1;
254    end
255    end
256end     
257switch vel_type
258    case 'civ1'
259        varin={'Civ1_X','Civ1_Y','Civ1_Z','Civ1_U','Civ1_V','Civ1_W','Civ1_C','Civ1_F','Civ1_FF'};
260    case 'interp1'
261        varin={'','','','','','','','',''};
262    case 'filter1'
263        varin={'Civ1_X','Civ1_Y','','Civ1_U_Spline','Civ1_V_Spline','','','',''};
264    case 'civ2'
265        varin={'vec2_X','vec2_Y','vec2_Z','vec2_U','vec2_V','vec2_W',C2,'vec2_F','vec2_FixFlag'};
266    case 'interp2'
267        varin={'vec2_patch_X','vec2_patch_Y','vec2_patch_Z','vec2_patch0_U','vec2_patch0_V','vec2_patch0_W','','',''};
268    case 'filter2'
269        varin={'vec2_patch_X','vec2_patch_Y','vec2_patch_Z','vec2_patch_U','vec2_patch_V','vec2_patch0_W','','',''};
270end
271if testder
272     switch vel_type
273        case 'filter1'
274            varin=[varin {'vec_patch_DUDX','vec_patch_DVDX','vec_patch_DUDY','vec_patch_DVDY'}];
275        case 'filter2'
276            varin=[varin {'vec2_patch_DUDX','vec2_patch_DVDX','vec2_patch_DUDY','vec2_patch_DVDY'}];
277    end   
278end
Note: See TracBrowser for help on using the repository browser.