source: trunk/src/read_civdata.m @ 809

Last change on this file since 809 was 809, checked in by g7moreau, 10 years ago
  • Add license
File size: 10.9 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%=======================================================================
47% Copyright 2008-2014, 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
[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
[581]107[varlist,role,VelTypeOut]=varcivx_generator(ProjModeRequest,VelType,Data.CivStage);
[406]108if isempty(varlist)
109    erromsg=['error in read_civdata: unknow velocity type ' VelType];
110    return
111else
[613]112    [Field,vardetect]=nc2struct(FileName,varlist);%read the variables in the netcdf file
[406]113end
[237]114if isfield(Field,'Txt')
115    errormsg=Field.Txt;
116    return
117end
118if vardetect(1)==0
[613]119     errormsg=[ 'requested field not available in ' FileName '/' VelType ': need to run patch'];
[237]120     return
121end
[380]122switch VelTypeOut
[494]123    case{'civ1','filter1'}
124        if isfield(Field,'Patch1_SubDomain')
125            Field.SubDomain=Field.Patch1_SubDomain;
126            Field.ListGlobalAttribute=[Field.ListGlobalAttribute {'SubDomain'}];
[594]127        end
128        if isfield(Field,'Civ1_Dt')
[380]129        Field.Dt=Field.Civ1_Dt;
[594]130        end
131        if isfield(Field,'Civ1_Time')
[494]132        Field.Time=Field.Civ1_Time;
[594]133        end
[494]134    case{'civ2','filter2'}
135        if isfield(Field,'Patch2_SubDomain')
136            Field.SubDomain=Field.Patch2_SubDomain;
137            Field.ListGlobalAttribute=[Field.ListGlobalAttribute {'SubDomain'}];
138        end
[594]139        if isfield(Field,'Civ2_Dt')
[380]140        Field.Dt=Field.Civ2_Dt;
[594]141        end
142        if isfield(Field,'Civ2_Time')
[494]143        Field.Time=Field.Civ2_Time;
[594]144        end
[372]145end
[494]146Field.ListGlobalAttribute=[Field.ListGlobalAttribute {'Dt','Time'}];
[515]147ivar_U_tps=[];
[581]148ivar_V_tps=[];
[237]149var_ind=find(vardetect);
[389]150for ivar=1:numel(var_ind)
[237]151    Field.VarAttribute{ivar}.Role=role{var_ind(ivar)};
[674]152    Field.VarAttribute{ivar}.Mesh=0.1;%typical mesh for histograms O.1 pixel
153    Field.VarAttribute{ivar}.ProjModeRequest=ProjModeRequest;
[515]154    if strcmp(role{var_ind(ivar)},'vector_x')
[576]155        Field.VarAttribute{ivar}.FieldName=FieldNames;
[674]156%         Field.VarAttribute{ivar}.ProjModeRequest=ProjModeRequest;
[515]157        ivar_U=ivar;
158    end
159    if strcmp(role{var_ind(ivar)},'vector_x_tps')
[576]160        Field.VarAttribute{ivar}.FieldName=FieldNames;
[674]161%         Field.VarAttribute{ivar}.ProjModeRequest=ProjModeRequest;
[515]162        ivar_U_tps=ivar;
163    end
[581]164    if strcmp(role{var_ind(ivar)},'vector_y')
165        Field.VarAttribute{ivar}.FieldName=FieldNames;
[674]166%         Field.VarAttribute{ivar}.ProjModeRequest=ProjModeRequest;
[581]167        ivar_V=ivar;
168    end
169    if strcmp(role{var_ind(ivar)},'vector_y_tps')
170        Field.VarAttribute{ivar}.FieldName=FieldNames;
[674]171%         Field.VarAttribute{ivar}.ProjModeRequest=ProjModeRequest;
[581]172        ivar_V_tps=ivar;
173    end
[237]174end
[515]175if ~isempty(ivar_U_tps)
176    Field.VarAttribute{ivar_U}.VarIndex_tps=ivar_U_tps;
177end
[581]178if ~isempty(ivar_V_tps)
179    Field.VarAttribute{ivar_V}.VarIndex_tps=ivar_V_tps;
180end
[515]181
[581]182%% update list of global attributes
[237]183Field.ListGlobalAttribute=[Field.ListGlobalAttribute {'NbCoord','NbDim','TimeUnit','CoordUnit'}];
184Field.NbCoord=2;
185Field.NbDim=2;
186Field.TimeUnit='s';
187Field.CoordUnit='pixel';
188
189%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
190% [var,role,units,vel_type_out]=varcivx_generator(FieldNames,vel_type)
191%INPUT:
192% FieldNames =cell of field names to get, which can contain the strings:
193%             'ima_cor': image correlation, vec_c or vec2_C
194%             'vort','div','strain': requires velocity derivatives DUDX...
195%             'error': error estimate (vec_E or vec2_E)
196%             
197% vel_type: character string indicating the types of velocity fields to read ('civ1','civ2'...)
[380]198%            if vel_type=[] or'*', a  priority choice is done, civ2 considered better than civ1 )
[237]199
[581]200function [var,role,vel_type_out,errormsg]=varcivx_generator(ProjModeRequest,vel_type,CivStage)
[237]201
202%% default input values
[246]203if ~exist('vel_type','var'),vel_type='';end;
[237]204if iscell(vel_type),vel_type=vel_type{1}; end;%transform cell to string if needed
[406]205errormsg='';
[237]206
207%% select the priority order for automatic vel_type selection
[581]208if strcmp(vel_type,'civ2') && strcmp(ProjModeRequest,'derivatives')
[492]209    vel_type='filter2';
[581]210elseif strcmp(vel_type,'civ1') && strcmp(ProjModeRequest,'derivatives')
[492]211    vel_type='filter1';
212end
[406]213if isempty(vel_type)||strcmp(vel_type,'*')
[380]214    switch CivStage
215        case {6} %filter2 available
[492]216            vel_type='filter2';
[380]217        case {4,5}% civ2 available but not filter2
[581]218            if strcmp(ProjModeRequest,'derivatives')% derivatives needed
[492]219                vel_type='filter1';
[380]220            else
221                vel_type='civ2';
222            end
[492]223        case 3
224            vel_type='filter1';
225        case {1,2}% civ1 available but not filter1
[380]226            vel_type='civ1';
227    end
228end
[492]229
[406]230var={};
[246]231switch vel_type
[389]232    case 'civ1'
[492]233        var={'X','Y','Z','U','V','W','C','F','FF';...
234            'Civ1_X','Civ1_Y','Civ1_Z','Civ1_U','Civ1_V','Civ1_W','Civ1_C','Civ1_F','Civ1_FF'};
235        role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag'};
[515]236    %    units={'pixel','pixel','pixel','pixel','pixel','pixel','','',''};
[389]237    case 'filter1'
[651]238        var={'X','Y','Z','U','V','W','C','F','FF','Coord_tps','U_tps','V_tps','W_tps','SubRange','NbCentre','NbCentre','NbCentre';...
[389]239            'Civ1_X','Civ1_Y','Civ1_Z','Civ1_U_smooth','Civ1_V_smooth','Civ1_W','Civ1_C','Civ1_F','Civ1_FF',...
[651]240            'Civ1_Coord_tps','Civ1_U_tps','Civ1_V_tps','Civ1_W_tps','Civ1_SubRange','Civ1_NbCentre','Civ1_NbCentres','Civ1_NbSites'};
[497]241        role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag','coord_tps','vector_x_tps',...
[651]242            'vector_y_tps','vector_z_tps','ancillary','ancillary','ancillary','ancillary'};
243     %  rmq: NbCentres and NbSites obsolete replaced by NbCentre, kept for consistency with previous data
[389]244    case 'civ2'
[492]245        var={'X','Y','Z','U','V','W','C','F','FF';...
246            'Civ2_X','Civ2_Y','Civ2_Z','Civ2_U','Civ2_V','Civ2_W','Civ2_C','Civ2_F','Civ2_FF'};
247        role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag'};
[389]248    case 'filter2'
[651]249        var={'X','Y','Z','U','V','W','C','F','FF','Coord_tps','U_tps','V_tps','W_tps','SubRange','NbCentre','NbCentre','NbCentre';...
[389]250            'Civ2_X','Civ2_Y','Civ2_Z','Civ2_U_smooth','Civ2_V_smooth','Civ2_W','Civ2_C','Civ2_F','Civ2_FF',...
[651]251            'Civ2_Coord_tps','Civ2_U_tps','Civ2_V_tps','','Civ2_SubRange','Civ2_NbCentre','Civ2_NbCentres','Civ2_NbSites'};
[497]252        role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag','coord_tps','vector_x_tps',...
[651]253            'vector_y_tps','vector_z_tps','ancillary','ancillary','ancillary','ancillary'};
[246]254end
[581]255if ~strcmp(ProjModeRequest,'interp_tps')
[515]256    var=var(:,1:9);%suppress tps if not needed
257end
[380]258vel_type_out=vel_type;
[237]259
260
261
[246]262
263
Note: See TracBrowser for help on using the repository browser.