source: trunk/src/read_civdata.m @ 923

Last change on this file since 923 was 908, checked in by g7moreau, 10 years ago
  • Update Copyright to 2015
File size: 10.7 KB
RevLine 
[237]1%'read_civdata': reads new civ data from netcdf files
2%------------------------------------------------------------------
3%
[613]4% function [Field,VelTypeOut]=read_civdata(FileName,FieldNames,VelType)
[237]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)
[515]12%                    .Dt: time interval for the corresponding image pair
[237]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:
[613]32% FileName: file name (string).
[237]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)
[809]41%
[237]42% FUNCTIONS called:
43% 'varcivx_generator':, sets the names of vaiables to read in the netcdf file
44% 'nc2struct': reads a netcdf file
45
[809]46%=======================================================================
[908]47% Copyright 2008-2015, LEGI UMR 5519 / CNRS UJF G-INP, Grenoble, France
[809]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
[613]64function [Field,VelTypeOut,errormsg]=read_civdata(FileName,FieldNames,VelType)
[406]65
[237]66%% default input
67if ~exist('VelType','var')
[246]68    VelType='';
[237]69end
70if isequal(VelType,'*')
[246]71    VelType='';
[237]72end
[246]73if isempty(VelType)
74    VelType='';
75end
[237]76if ~exist('FieldNames','var')
77    FieldNames=[]; %default
78end
[613]79Field=[];
80VelTypeOut=VelType;
[406]81errormsg='';
[613]82if ~exist(FileName,'file')
83    errormsg=['input file ' FileName ' does not exist'];
84    return
85end
[515]86if ischar(FieldNames), FieldNames={FieldNames}; end;
[581]87ProjModeRequest='';
[515]88for ilist=1:length(FieldNames)
89    if ~isempty(FieldNames{ilist})
90        switch FieldNames{ilist}
91            case{'U','V','norm(U,V)'}
[654]92                if ~strcmp(FieldNames{1},'vec(U,V)')% if the scalar is not used as color of vectors
[581]93                ProjModeRequest='interp_lin';
[654]94                end
[515]95            case {'curl(U,V)','div(U,V)','strain(U,V)'}
[581]96                ProjModeRequest='interp_tps';
[515]97        end
98    end
99end
[237]100
101%% reading data
[613]102Data=nc2struct(FileName,'ListGlobalAttribute','CivStage');
[612]103if isfield(Data,'Txt')
104     erromsg=['error in read_civdata: ' Data.Txt];
105    return
106end
[822]107% set the list of variables to read and their role
[581]108[varlist,role,VelTypeOut]=varcivx_generator(ProjModeRequest,VelType,Data.CivStage);
[406]109if isempty(varlist)
110    erromsg=['error in read_civdata: unknow velocity type ' VelType];
111    return
112else
[613]113    [Field,vardetect]=nc2struct(FileName,varlist);%read the variables in the netcdf file
[406]114end
[237]115if isfield(Field,'Txt')
116    errormsg=Field.Txt;
117    return
118end
119if vardetect(1)==0
[613]120     errormsg=[ 'requested field not available in ' FileName '/' VelType ': need to run patch'];
[237]121     return
122end
[380]123switch VelTypeOut
[494]124    case{'civ1','filter1'}
125        if isfield(Field,'Patch1_SubDomain')
126            Field.SubDomain=Field.Patch1_SubDomain;
127            Field.ListGlobalAttribute=[Field.ListGlobalAttribute {'SubDomain'}];
[822]128        end
[594]129        if isfield(Field,'Civ1_Dt')
[822]130            Field.Dt=Field.Civ1_Dt;
[594]131        end
132        if isfield(Field,'Civ1_Time')
[822]133            Field.Time=Field.Civ1_Time;
[594]134        end
[494]135    case{'civ2','filter2'}
136        if isfield(Field,'Patch2_SubDomain')
137            Field.SubDomain=Field.Patch2_SubDomain;
138            Field.ListGlobalAttribute=[Field.ListGlobalAttribute {'SubDomain'}];
139        end
[594]140        if isfield(Field,'Civ2_Dt')
[380]141        Field.Dt=Field.Civ2_Dt;
[594]142        end
143        if isfield(Field,'Civ2_Time')
[494]144        Field.Time=Field.Civ2_Time;
[594]145        end
[372]146end
[494]147Field.ListGlobalAttribute=[Field.ListGlobalAttribute {'Dt','Time'}];
[515]148ivar_U_tps=[];
[581]149ivar_V_tps=[];
[237]150var_ind=find(vardetect);
[389]151for ivar=1:numel(var_ind)
[237]152    Field.VarAttribute{ivar}.Role=role{var_ind(ivar)};
[871]153    %Field.VarAttribute{ivar}.Mesh=0.025;%typical mesh for histograms O.025 pixel (used in series)
[674]154    Field.VarAttribute{ivar}.ProjModeRequest=ProjModeRequest;
[515]155    if strcmp(role{var_ind(ivar)},'vector_x')
[576]156        Field.VarAttribute{ivar}.FieldName=FieldNames;
[515]157        ivar_U=ivar;
158    end
159    if strcmp(role{var_ind(ivar)},'vector_x_tps')
[576]160        Field.VarAttribute{ivar}.FieldName=FieldNames;
[515]161        ivar_U_tps=ivar;
162    end
[581]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
[237]171end
[515]172if ~isempty(ivar_U_tps)
173    Field.VarAttribute{ivar_U}.VarIndex_tps=ivar_U_tps;
174end
[581]175if ~isempty(ivar_V_tps)
176    Field.VarAttribute{ivar_V}.VarIndex_tps=ivar_V_tps;
177end
[515]178
[581]179%% update list of global attributes
[237]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'...)
[380]195%            if vel_type=[] or'*', a  priority choice is done, civ2 considered better than civ1 )
[237]196
[581]197function [var,role,vel_type_out,errormsg]=varcivx_generator(ProjModeRequest,vel_type,CivStage)
[237]198
199%% default input values
[246]200if ~exist('vel_type','var'),vel_type='';end;
[237]201if iscell(vel_type),vel_type=vel_type{1}; end;%transform cell to string if needed
[406]202errormsg='';
[237]203
204%% select the priority order for automatic vel_type selection
[581]205if strcmp(vel_type,'civ2') && strcmp(ProjModeRequest,'derivatives')
[492]206    vel_type='filter2';
[581]207elseif strcmp(vel_type,'civ1') && strcmp(ProjModeRequest,'derivatives')
[492]208    vel_type='filter1';
209end
[406]210if isempty(vel_type)||strcmp(vel_type,'*')
[851]211    vel_type='filter2';% case CivStage >=6
[380]212    switch CivStage
213        case {4,5}% civ2 available but not filter2
[581]214            if strcmp(ProjModeRequest,'derivatives')% derivatives needed
[492]215                vel_type='filter1';
[380]216            else
217                vel_type='civ2';
218            end
[492]219        case 3
220            vel_type='filter1';
221        case {1,2}% civ1 available but not filter1
[380]222            vel_type='civ1';
223    end
224end
[492]225
[406]226var={};
[246]227switch vel_type
[389]228    case 'civ1'
[492]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'};
[515]232    %    units={'pixel','pixel','pixel','pixel','pixel','pixel','','',''};
[389]233    case 'filter1'
[651]234        var={'X','Y','Z','U','V','W','C','F','FF','Coord_tps','U_tps','V_tps','W_tps','SubRange','NbCentre','NbCentre','NbCentre';...
[389]235            'Civ1_X','Civ1_Y','Civ1_Z','Civ1_U_smooth','Civ1_V_smooth','Civ1_W','Civ1_C','Civ1_F','Civ1_FF',...
[651]236            'Civ1_Coord_tps','Civ1_U_tps','Civ1_V_tps','Civ1_W_tps','Civ1_SubRange','Civ1_NbCentre','Civ1_NbCentres','Civ1_NbSites'};
[497]237        role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag','coord_tps','vector_x_tps',...
[651]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
[389]240    case 'civ2'
[492]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'};
[389]244    case 'filter2'
[651]245        var={'X','Y','Z','U','V','W','C','F','FF','Coord_tps','U_tps','V_tps','W_tps','SubRange','NbCentre','NbCentre','NbCentre';...
[389]246            'Civ2_X','Civ2_Y','Civ2_Z','Civ2_U_smooth','Civ2_V_smooth','Civ2_W','Civ2_C','Civ2_F','Civ2_FF',...
[651]247            'Civ2_Coord_tps','Civ2_U_tps','Civ2_V_tps','','Civ2_SubRange','Civ2_NbCentre','Civ2_NbCentres','Civ2_NbSites'};
[497]248        role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag','coord_tps','vector_x_tps',...
[651]249            'vector_y_tps','vector_z_tps','ancillary','ancillary','ancillary','ancillary'};
[246]250end
[581]251if ~strcmp(ProjModeRequest,'interp_tps')
[515]252    var=var(:,1:9);%suppress tps if not needed
253end
[380]254vel_type_out=vel_type;
[237]255
256
257
[246]258
259
Note: See TracBrowser for help on using the repository browser.