source: trunk/src/read_civdata.m @ 412

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

bugs corrected in civ_matlab and object projection

File size: 8.5 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,CivStage)
50
51%% default input
52if ~exist('VelType','var')
53    VelType='';
54end
55if isequal(VelType,'*')
56    VelType='';
57end
58if isempty(VelType)
59    VelType='';
60end
61if ~exist('FieldNames','var')
62    FieldNames=[]; %default
63end
64errormsg='';
65
66%% reading data
67[varlist,role,units,VelTypeOut]=varcivx_generator(FieldNames,VelType,CivStage);
68if isempty(varlist)
69    erromsg=['error in read_civdata: unknow velocity type ' VelType];
70    return
71else
72    [Field,vardetect]=nc2struct(filename,varlist);%read the variables in the netcdf file
73end
74if isfield(Field,'Txt')
75    errormsg=Field.Txt;
76    return
77end
78if vardetect(1)==0
79     errormsg=[ 'requested field not available in ' filename '/' VelType ': need to run patch'];
80     return
81end
82switch VelTypeOut
83    case{'civ1','civ-filter1','filter1'}
84        Field.Dt=Field.Civ1_Dt;
85    case{'civ2','civ-filter2','filter2'}
86        Field.Dt=Field.Civ2_Dt;
87end
88Field.ListGlobalAttribute=[Field.ListGlobalAttribute {'Dt'}];
89var_ind=find(vardetect);
90for ivar=1:numel(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
96Field.ListGlobalAttribute=[Field.ListGlobalAttribute {'NbCoord','NbDim','TimeUnit','CoordUnit'}];
97% %% update list of global attributes
98Field.NbCoord=2;
99Field.NbDim=2;
100Field.TimeUnit='s';
101Field.CoordUnit='pixel';
102
103%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104% [var,role,units,vel_type_out]=varcivx_generator(FieldNames,vel_type)
105%INPUT:
106% FieldNames =cell of field names to get, which can contain the strings:
107%             'ima_cor': image correlation, vec_c or vec2_C
108%             'vort','div','strain': requires velocity derivatives DUDX...
109%             'error': error estimate (vec_E or vec2_E)
110%             
111% vel_type: character string indicating the types of velocity fields to read ('civ1','civ2'...)
112%            if vel_type=[] or'*', a  priority choice is done, civ2 considered better than civ1 )
113
114function [var,role,units,vel_type_out,errormsg]=varcivx_generator(FieldNames,vel_type,CivStage)
115
116%% default input values
117if ~exist('vel_type','var'),vel_type='';end;
118if iscell(vel_type),vel_type=vel_type{1}; end;%transform cell to string if needed
119if ~exist('FieldNames','var'),FieldNames={'ima_cor'};end;%default scalar
120if ischar(FieldNames), FieldNames={FieldNames}; end;
121errormsg='';
122
123%% select the priority order for automatic vel_type selection
124testder=0;
125testpatch=0;
126for ilist=1:length(FieldNames)
127    if ~isempty(FieldNames{ilist})
128        switch FieldNames{ilist}
129            case{'u','v'}
130                testpatch=1;
131            case {'vort','div','strain'}
132                testder=1;
133        end
134    end
135end
136if isempty(vel_type)||strcmp(vel_type,'*')
137    switch CivStage
138        case {6} %filter2 available
139            vel_type='civ2';
140        case {4,5}% civ2 available but not filter2
141            if testder% derivatives needed
142                vel_type='civ1';
143            else
144                vel_type='civ2';
145            end
146        case {1,2,3}% civ1 available but not civ2
147            vel_type='civ1';
148    end
149end
150if strcmp(vel_type,'civ2') && testder
151    vel_type='filter2';
152elseif strcmp(vel_type,'civ1') && testder
153    vel_type='filter1';
154end
155var={};
156switch vel_type
157    case 'civ1'
158        var={'X','Y','Z','U','V','W','C','F','FF','Coord_tps','U_tps','V_tps','W_tps','SubRange','NbSites';...
159            'Civ1_X','Civ1_Y','Civ1_Z','Civ1_U','Civ1_V','Civ1_W','Civ1_C','Civ1_F','Civ1_FF',...
160            'Civ1_Coord_tps','Civ1_U_tps','Civ1_V_tps','Civ1_W_tps','Civ1_SubRange','Civ1_NbSites'};
161        role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag','coord_tps','vector_x_tps',...
162            'vector_y_tps','vector_z_tps','ancillary','ancillary'};
163        units={'pixel','pixel','pixel','pixel','pixel','pixel','','','','pixel','pixel','pixel','pixel','pixel',''};
164    case 'filter1'
165        var={'X','Y','Z','U','V','W','C','F','FF','Coord_tps','U_tps','V_tps','W_tps','SubRange','NbSites';...
166            'Civ1_X','Civ1_Y','Civ1_Z','Civ1_U_smooth','Civ1_V_smooth','Civ1_W','Civ1_C','Civ1_F','Civ1_FF',...
167            'Civ1_Coord_tps','Civ1_U_tps','Civ1_V_tps','Civ1_W_tps','Civ1_SubRange','Civ1_NbSites'};
168        role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag','coord_tps','vector_x_tps',...
169            'vector_y_tps','vector_z_tps','ancillary','ancillary'};
170        units={'pixel','pixel','pixel','pixel','pixel','pixel','','','','pixel','pixel','pixel','pixel','pixel',''};
171    case 'civ2'
172        var={'X','Y','Z','U','V','W','C','F','FF','Coord_tps','U_tps','V_tps','W_tps','SubRange','NbSites';...
173            'Civ2_X','Civ2_Y','Civ2_Z','Civ2_U','Civ2_V','Civ2_W','Civ2_C','Civ2_F','Civ2_FF',...
174            'Civ2_Coord_tps','Civ2_U_tps','Civ2_V_tps','','Civ2_SubRange','Civ2_NbSites'};
175        role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag','coord_tps','vector_x_tps',...
176            'vector_y_tps','vector_z_tps','ancillary','ancillary'};
177        units={'pixel','pixel','pixel','pixel','pixel','pixel','','','','pixel','pixel','pixel','pixel','pixel',''};
178    case 'filter2'
179        var={'X','Y','Z','U','V','W','C','F','FF','Coord_tps','U_tps','V_tps','W_tps','SubRange','NbSites';...
180            'Civ2_X','Civ2_Y','Civ2_Z','Civ2_U_smooth','Civ2_V_smooth','Civ2_W','Civ2_C','Civ2_F','Civ2_FF',...
181            'Civ2_Coord_tps','Civ2_U_tps','Civ2_V_tps','','Civ2_SubRange','Civ2_NbSites'};
182        role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag','coord_tps','vector_x_tps',...
183            'vector_y_tps','vector_z_tps','ancillary','ancillary'};
184        units={'pixel','pixel','pixel','pixel','pixel','pixel','','','','pixel','pixel','pixel','pixel','pixel',''};
185end
186vel_type_out=vel_type;
187
188
189
190
191
Note: See TracBrowser for help on using the repository browser.