source: trunk/src/read_civdata.m @ 920

Last change on this file since 920 was 908, checked in by g7moreau, 9 years ago
  • Update Copyright to 2015
File size: 10.7 KB
Line 
1%'read_civdata': reads new civ data from netcdf files
2%------------------------------------------------------------------
3%
4% function [Field,VelTypeOut]=read_civdata(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%
29% VelTypeOut: velocity type corresponding to the selected field: ='civ1','interp1','interp2','civ2'....
30%
31% INPUT:
32% FileName: file name (string).
33% FieldNames =cell of field names to get, which can contain the strings:
34%             'ima_cor': image correlation, vec_c or vec2_C
35%             'vort','div','strain': requires velocity derivatives DUDX...
36%             'error': error estimate (vec_E or vec2_E)
37%             
38% VelType : character string indicating the types of velocity fields to read ('civ1','civ2'...)
39%            if vel_type=[] or'*', a  priority choice, given by vel_type_out{1,2}, is done depending
40%            if vel_type='filter'; a structured field is sought (filter2 in priority, then filter1)
41%
42% FUNCTIONS called:
43% 'varcivx_generator':, sets the names of vaiables to read in the netcdf file
44% 'nc2struct': reads a netcdf file
45
46%=======================================================================
47% Copyright 2008-2015, LEGI UMR 5519 / CNRS UJF G-INP, Grenoble, France
48%   http://www.legi.grenoble-inp.fr
49%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
50%
51%     This file is part of the toolbox UVMAT.
52%
53%     UVMAT is free software; you can redistribute it and/or modify
54%     it under the terms of the GNU General Public License as published
55%     by the Free Software Foundation; either version 2 of the license,
56%     or (at your option) any later version.
57%
58%     UVMAT is distributed in the hope that it will be useful,
59%     but WITHOUT ANY WARRANTY; without even the implied warranty of
60%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
61%     GNU General Public License (see LICENSE.txt) for more details.
62%=======================================================================
63
64function [Field,VelTypeOut,errormsg]=read_civdata(FileName,FieldNames,VelType)
65
66%% default input
67if ~exist('VelType','var')
68    VelType='';
69end
70if isequal(VelType,'*')
71    VelType='';
72end
73if isempty(VelType)
74    VelType='';
75end
76if ~exist('FieldNames','var')
77    FieldNames=[]; %default
78end
79Field=[];
80VelTypeOut=VelType;
81errormsg='';
82if ~exist(FileName,'file')
83    errormsg=['input file ' FileName ' does not exist'];
84    return
85end
86if ischar(FieldNames), FieldNames={FieldNames}; end;
87ProjModeRequest='';
88for ilist=1:length(FieldNames)
89    if ~isempty(FieldNames{ilist})
90        switch FieldNames{ilist}
91            case{'U','V','norm(U,V)'}
92                if ~strcmp(FieldNames{1},'vec(U,V)')% if the scalar is not used as color of vectors
93                ProjModeRequest='interp_lin';
94                end
95            case {'curl(U,V)','div(U,V)','strain(U,V)'}
96                ProjModeRequest='interp_tps';
97        end
98    end
99end
100
101%% reading data
102Data=nc2struct(FileName,'ListGlobalAttribute','CivStage');
103if isfield(Data,'Txt')
104     erromsg=['error in read_civdata: ' Data.Txt];
105    return
106end
107% set the list of variables to read and their role
108[varlist,role,VelTypeOut]=varcivx_generator(ProjModeRequest,VelType,Data.CivStage);
109if isempty(varlist)
110    erromsg=['error in read_civdata: unknow velocity type ' VelType];
111    return
112else
113    [Field,vardetect]=nc2struct(FileName,varlist);%read the variables in the netcdf file
114end
115if isfield(Field,'Txt')
116    errormsg=Field.Txt;
117    return
118end
119if vardetect(1)==0
120     errormsg=[ 'requested field not available in ' FileName '/' VelType ': need to run patch'];
121     return
122end
123switch VelTypeOut
124    case{'civ1','filter1'}
125        if isfield(Field,'Patch1_SubDomain')
126            Field.SubDomain=Field.Patch1_SubDomain;
127            Field.ListGlobalAttribute=[Field.ListGlobalAttribute {'SubDomain'}];
128        end
129        if isfield(Field,'Civ1_Dt')
130            Field.Dt=Field.Civ1_Dt;
131        end
132        if isfield(Field,'Civ1_Time')
133            Field.Time=Field.Civ1_Time;
134        end
135    case{'civ2','filter2'}
136        if isfield(Field,'Patch2_SubDomain')
137            Field.SubDomain=Field.Patch2_SubDomain;
138            Field.ListGlobalAttribute=[Field.ListGlobalAttribute {'SubDomain'}];
139        end
140        if isfield(Field,'Civ2_Dt')
141        Field.Dt=Field.Civ2_Dt;
142        end
143        if isfield(Field,'Civ2_Time')
144        Field.Time=Field.Civ2_Time;
145        end
146end
147Field.ListGlobalAttribute=[Field.ListGlobalAttribute {'Dt','Time'}];
148ivar_U_tps=[];
149ivar_V_tps=[];
150var_ind=find(vardetect);
151for ivar=1:numel(var_ind)
152    Field.VarAttribute{ivar}.Role=role{var_ind(ivar)};
153    %Field.VarAttribute{ivar}.Mesh=0.025;%typical mesh for histograms O.025 pixel (used in series)
154    Field.VarAttribute{ivar}.ProjModeRequest=ProjModeRequest;
155    if strcmp(role{var_ind(ivar)},'vector_x')
156        Field.VarAttribute{ivar}.FieldName=FieldNames;
157        ivar_U=ivar;
158    end
159    if strcmp(role{var_ind(ivar)},'vector_x_tps')
160        Field.VarAttribute{ivar}.FieldName=FieldNames;
161        ivar_U_tps=ivar;
162    end
163    if strcmp(role{var_ind(ivar)},'vector_y')
164        Field.VarAttribute{ivar}.FieldName=FieldNames;
165        ivar_V=ivar;
166    end
167    if strcmp(role{var_ind(ivar)},'vector_y_tps')
168        Field.VarAttribute{ivar}.FieldName=FieldNames;
169        ivar_V_tps=ivar;
170    end
171end
172if ~isempty(ivar_U_tps)
173    Field.VarAttribute{ivar_U}.VarIndex_tps=ivar_U_tps;
174end
175if ~isempty(ivar_V_tps)
176    Field.VarAttribute{ivar_V}.VarIndex_tps=ivar_V_tps;
177end
178
179%% update list of global attributes
180Field.ListGlobalAttribute=[Field.ListGlobalAttribute {'NbCoord','NbDim','TimeUnit','CoordUnit'}];
181Field.NbCoord=2;
182Field.NbDim=2;
183Field.TimeUnit='s';
184Field.CoordUnit='pixel';
185
186%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
187% [var,role,units,vel_type_out]=varcivx_generator(FieldNames,vel_type)
188%INPUT:
189% FieldNames =cell of field names to get, which can contain the strings:
190%             'ima_cor': image correlation, vec_c or vec2_C
191%             'vort','div','strain': requires velocity derivatives DUDX...
192%             'error': error estimate (vec_E or vec2_E)
193%             
194% vel_type: character string indicating the types of velocity fields to read ('civ1','civ2'...)
195%            if vel_type=[] or'*', a  priority choice is done, civ2 considered better than civ1 )
196
197function [var,role,vel_type_out,errormsg]=varcivx_generator(ProjModeRequest,vel_type,CivStage)
198
199%% default input values
200if ~exist('vel_type','var'),vel_type='';end;
201if iscell(vel_type),vel_type=vel_type{1}; end;%transform cell to string if needed
202errormsg='';
203
204%% select the priority order for automatic vel_type selection
205if strcmp(vel_type,'civ2') && strcmp(ProjModeRequest,'derivatives')
206    vel_type='filter2';
207elseif strcmp(vel_type,'civ1') && strcmp(ProjModeRequest,'derivatives')
208    vel_type='filter1';
209end
210if isempty(vel_type)||strcmp(vel_type,'*')
211    vel_type='filter2';% case CivStage >=6
212    switch CivStage
213        case {4,5}% civ2 available but not filter2
214            if strcmp(ProjModeRequest,'derivatives')% derivatives needed
215                vel_type='filter1';
216            else
217                vel_type='civ2';
218            end
219        case 3
220            vel_type='filter1';
221        case {1,2}% civ1 available but not filter1
222            vel_type='civ1';
223    end
224end
225
226var={};
227switch vel_type
228    case 'civ1'
229        var={'X','Y','Z','U','V','W','C','F','FF';...
230            'Civ1_X','Civ1_Y','Civ1_Z','Civ1_U','Civ1_V','Civ1_W','Civ1_C','Civ1_F','Civ1_FF'};
231        role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag'};
232    %    units={'pixel','pixel','pixel','pixel','pixel','pixel','','',''};
233    case 'filter1'
234        var={'X','Y','Z','U','V','W','C','F','FF','Coord_tps','U_tps','V_tps','W_tps','SubRange','NbCentre','NbCentre','NbCentre';...
235            'Civ1_X','Civ1_Y','Civ1_Z','Civ1_U_smooth','Civ1_V_smooth','Civ1_W','Civ1_C','Civ1_F','Civ1_FF',...
236            'Civ1_Coord_tps','Civ1_U_tps','Civ1_V_tps','Civ1_W_tps','Civ1_SubRange','Civ1_NbCentre','Civ1_NbCentres','Civ1_NbSites'};
237        role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag','coord_tps','vector_x_tps',...
238            'vector_y_tps','vector_z_tps','ancillary','ancillary','ancillary','ancillary'};
239     %  rmq: NbCentres and NbSites obsolete replaced by NbCentre, kept for consistency with previous data
240    case 'civ2'
241        var={'X','Y','Z','U','V','W','C','F','FF';...
242            'Civ2_X','Civ2_Y','Civ2_Z','Civ2_U','Civ2_V','Civ2_W','Civ2_C','Civ2_F','Civ2_FF'};
243        role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag'};
244    case 'filter2'
245        var={'X','Y','Z','U','V','W','C','F','FF','Coord_tps','U_tps','V_tps','W_tps','SubRange','NbCentre','NbCentre','NbCentre';...
246            'Civ2_X','Civ2_Y','Civ2_Z','Civ2_U_smooth','Civ2_V_smooth','Civ2_W','Civ2_C','Civ2_F','Civ2_FF',...
247            'Civ2_Coord_tps','Civ2_U_tps','Civ2_V_tps','','Civ2_SubRange','Civ2_NbCentre','Civ2_NbCentres','Civ2_NbSites'};
248        role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag','coord_tps','vector_x_tps',...
249            'vector_y_tps','vector_z_tps','ancillary','ancillary','ancillary','ancillary'};
250end
251if ~strcmp(ProjModeRequest,'interp_tps')
252    var=var(:,1:9);%suppress tps if not needed
253end
254vel_type_out=vel_type;
255
256
257
258
259
Note: See TracBrowser for help on using the repository browser.