Changeset 380 for trunk/src/read_civdata.m
- Timestamp:
- Jan 29, 2012, 2:31:56 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/read_civdata.m
r379 r380 47 47 % 'nc2struct': reads a netcdf file 48 48 49 function [Field,VelTypeOut,errormsg]=read_civdata(filename,FieldNames,VelType, XI,YI)49 function [Field,VelTypeOut,errormsg]=read_civdata(filename,FieldNames,VelType,CivStage) 50 50 errormsg=''; 51 51 VelTypeOut=VelType;%default … … 65 65 66 66 %% reading data 67 [varlist,role,units, vel_type_out_cell]=varcivx_generator(FieldNames,VelType);68 [Field,vardetect ,ichoice]=nc2struct(filename,varlist);%read the variables in the netcdf file67 [varlist,role,units,VelTypeOut]=varcivx_generator(FieldNames,VelType,CivStage); 68 [Field,vardetect]=nc2struct(filename,varlist);%read the variables in the netcdf file 69 69 if isfield(Field,'Txt') 70 70 errormsg=Field.Txt; … … 75 75 return 76 76 end 77 switch vel_type_out_cell{ichoice}78 case{'civ1',' fix1','patch1'}79 Field. dt=Field.Civ1_Dt;80 case{'civ2',' fix2','patch2'}81 Field. dt=Field.Civ2_Dt;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; 82 82 end 83 Field.ListGlobalAttribute=[Field.ListGlobalAttribute {' dt'}];83 Field.ListGlobalAttribute=[Field.ListGlobalAttribute {'Dt'}]; 84 84 var_ind=find(vardetect); 85 85 for ivar=1:min(numel(var_ind),numel(Field.VarAttribute)) … … 88 88 Field.VarAttribute{ivar}.Mesh=0.1;%typical mesh for histograms O.1 pixel 89 89 end 90 if ~isempty(ichoice)91 VelTypeOut=vel_type_out_cell{ichoice};92 end93 90 94 95 %% renaming for standard conventions96 %Field.NbCoord=Field.nb_coord;97 %Field.NbDim=2;%Field.nb_dim;98 99 %% CivStage100 % if isfield(Field,'patch2')&& isequal(Field.patch2,1)101 % Field.CivStage=6;102 % elseif isfield(Field,'fix2')&& isequal(Field.fix2,1)103 % Field.CivStage=5;104 % elseif isfield(Field,'civ2')&& isequal(Field.civ2,1)105 % Field.CivStage=4;106 % elseif isfield(Field,'patch')&& isequal(Field.patch,1)107 % Field.CivStage=3;108 % elseif isfield(Field,'fix')&& isequal(Field.fix,1)109 % Field.CivStage=2;110 % else111 % Field.CivStage=1;112 % end113 91 Field.ListGlobalAttribute=[Field.ListGlobalAttribute {'NbCoord','NbDim','TimeUnit','CoordUnit'}]; 114 % %determine the appropriate constant for time and dt for the PIV pair115 % test_civ1=isequal(VelTypeOut,'civ1')||isequal(VelTypeOut,'interp1')||isequal(VelTypeOut,'filter1');116 % test_civ2=isequal(VelTypeOut,'civ2')||isequal(VelTypeOut,'interp2')||isequal(VelTypeOut,'filter2');117 % Field.Time=0; %default118 % Field.TimeUnit='s';119 % if test_civ1120 % if isfield(Field,'absolut_time_T0')121 % Field.Time=double(Field.absolut_time_T0);122 % Field.dt=double(Field.dt);123 % else124 % Field.Txt='the input file is not civx';125 % Field.CivStage=0;126 % Field.dt=0;127 % end128 % elseif test_civ2129 % Field.Time=double(Field.absolut_time_T0_2);130 % Field.dt=double(Field.dt2);131 % else132 % Field.Txt='the input file is not civx';133 % Field.CivStage=0;134 % Field.dt=0;135 % end136 %137 %138 %139 92 % %% update list of global attributes 140 % List=Field.ListGlobalAttribute;141 % ind_remove=[];142 % for ilist=1:length(List)143 % switch(List{ilist})144 % case {'patch2','fix2','civ2','patch','fix','dt2','absolut_time_T0','absolut_time_T0_2','nb_coord','nb_dim','pixcmx','pixcmy'}145 % ind_remove=[ind_remove ilist];146 % Field=rmfield(Field,List{ilist});147 % end148 % end149 % List(ind_remove)=[];150 % Field.ListGlobalAttribute=[{'NbCoord'},{'NbDim'} List {'Time','TimeUnit','CivStage','CoordUnit'}];151 93 Field.NbCoord=2; 152 94 Field.NbDim=2; … … 157 99 158 100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 159 % TAKEN FROM read_civxdata NOT USED160 101 % [var,role,units,vel_type_out]=varcivx_generator(FieldNames,vel_type) 161 102 %INPUT: … … 166 107 % 167 108 % vel_type: character string indicating the types of velocity fields to read ('civ1','civ2'...) 168 % if vel_type=[] or'*', a priority choice, given by vel_type_out{1,2}, is done depending 169 % if vel_type='filter'; a structured field is sought (filter2 in priority, then filter1) 109 % if vel_type=[] or'*', a priority choice is done, civ2 considered better than civ1 ) 170 110 171 function [var,role,units,vel_type_out]=varcivx_generator(FieldNames,vel_type )111 function [var,role,units,vel_type_out]=varcivx_generator(FieldNames,vel_type,CivStage) 172 112 173 113 %% default input values … … 187 127 case {'vort','div','strain'} 188 128 testder=1; 129 189 130 end 190 131 end 191 132 end 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 192 154 switch vel_type 193 case 'civ1' 194 var={'X','Y','Z','U','V','W','C','F','FF';... 195 'Civ1_X','Civ1_Y','Civ1_Z','Civ1_U','Civ1_V','Civ1_W','Civ1_C','Civ1_F','Civ1_FF'}; 196 role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag'}; 197 units={'pixel','pixel','pixel','pixel','pixel','pixel',[],[],[]}; 198 case 'interp1' 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' 199 162 var={'X','Y','Z','U','V','W','FF';... 200 163 'Civ1_X','Civ1_Y','','Civ1_U_Diff','Civ1_V_Diff','','Civ1_FF'}; … … 207 170 units={'pixel','pixel','pixel','pixel','pixel','pixel','pixel','pixel',''}; 208 171 case 'civ2' 209 var={'X','Y','Z','U','V','W','C','F','FF';... 210 'Civ2_X','Civ2_Y','Civ2_Z','Civ2_U','Civ2_V','Civ2_W','Civ2_C','Civ2_F','Civ2_FF'}; 211 role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag'}; 212 units={'pixel','pixel','pixel','pixel','pixel','pixel',[],[],[]}; 213 case 'interp2' 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' 214 182 var={'X','Y','Z','U','V','W','FF';... 215 183 'Civ2_X','Civ2_Y','','Civ2_U_Diff','Civ2_V_Diff','','Civ2_FF'}; … … 221 189 role={'','','','','','','','',''}; 222 190 units={'pixel','pixel','pixel','pixel','pixel','pixel','pixel','pixel',''}; 223 otherwise % if VelType=[], choose the best field, civ in priority, or patch2 for derivatives224 if testpatch225 var={'X_tps','Y_tps','Z_tps','U_tps','V_tps','W_tps','X_SubRange','Y_SubRange','NbSites';...226 'Civ2_X_tps','Civ2_Y_tps','','Civ2_U_tps','Civ2_V_tps','','Civ2_X_SubRange','Civ2_Y_SubRange','Civ2_NbSites';...227 'Civ1_X_tps','Civ1_Y_tps','','Civ1_U_tps','Civ1_V_tps','','Civ1_X_SubRange','Civ1_Y_SubRange','Civ1_NbSites'};228 role={'','','','','','','',''};229 units={'pixel','pixel','pixel','pixel','pixel','pixel','pixel','pixel'};230 else231 var={'X','Y','Z','U','V','W','C','F','FF';...232 'Civ2_X','Civ2_Y','Civ2_Z','Civ2_U','Civ2_V','Civ2_W','Civ2_C','Civ2_F','Civ2_FF';...233 'Civ1_X','Civ1_Y','Civ1_Z','Civ1_U','Civ1_V','Civ1_W','Civ1_C','Civ1_F','Civ1_FF'};234 role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag'};235 units={'pixel','pixel','pixel','pixel','pixel','pixel',[],[],[]};236 end237 191 end 238 if isempty(vel_type) || isequal(vel_type,'*') %undefined velocity type (civ1,civ2...) 239 if testder 240 vel_type_out{1}='filter2'; %priority to filter2 for scalar reading, filter1 as second 241 vel_type_out{2}='filter1'; 242 else 243 vel_type_out{1}='civ2'; %priority to civ2 for vector reading, civ1 as second priority 244 vel_type_out{2}='civ1'; 245 end 246 elseif isequal(vel_type,'filter') 247 vel_type_out{1}='filter2'; %priority to filter2 for scalar reading, filter1 as second 248 vel_type_out{2}='filter1'; 249 if ~testder 250 vel_type_out{3}='civ1';%civ1 as third priority if derivatives are not needed 251 end 252 elseif testder 253 test_civ1=isequal(vel_type,'civ1')||isequal(vel_type,'interp1')||isequal(vel_type,'filter1'); 254 if test_civ1 255 vel_type_out{1}='filter1'; %switch to filter for reading spatial derivatives 256 else 257 vel_type_out{1}='filter2'; 258 end 259 else 260 vel_type_out{1}=vel_type;%imposed velocity field 261 end 262 vel_type_out=vel_type_out'; 192 vel_type_out=vel_type; 263 193 264 194 … … 266 196 267 197 268
Note: See TracChangeset
for help on using the changeset viewer.