source: trunk/src/read_civdata.m @ 516

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

various bug corrections

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