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