[474] | 1 | %'merge_proj': project and concatene fields |
---|
| 2 | % can be used as a template for applying an operation (here projection and concatenation) on each field of an input series |
---|
[457] | 3 | %------------------------------------------------------------------------ |
---|
[464] | 4 | % function ParamOut=merge_proj(Param) |
---|
[457] | 5 | %------------------------------------------------------------------------ |
---|
[222] | 6 | |
---|
[457] | 7 | %%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
[169] | 8 | % |
---|
[457] | 9 | % This function is used in four modes by the GUI series: |
---|
| 10 | % 1) config GUI: with no input argument, the function determine the suitable GUI configuration |
---|
| 11 | % 2) interactive input: the function is used to interactively introduce input parameters, and then stops |
---|
| 12 | % 3) RUN: the function itself runs, when an appropriate input structure Param has been introduced. |
---|
| 13 | % 4) BATCH: the function itself proceeds in BATCH mode, using an xml file 'Param' as input. |
---|
| 14 | % |
---|
| 15 | % This function is used in four modes by the GUI series: |
---|
| 16 | % 1) config GUI: with no input argument, the function determine the suitable GUI configuration |
---|
| 17 | % 2) interactive input: the function is used to interactively introduce input parameters, and then stops |
---|
| 18 | % 3) RUN: the function itself runs, when an appropriate input structure Param has been introduced. |
---|
| 19 | % 4) BATCH: the function itself proceeds in BATCH mode, using an xml file 'Param' as input. |
---|
| 20 | % |
---|
[169] | 21 | %OUTPUT |
---|
| 22 | % GUI_input=list of options in the GUI series.fig needed for the function |
---|
| 23 | % |
---|
| 24 | %INPUT: |
---|
[457] | 25 | % In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series. |
---|
| 26 | % In batch mode, Param is the name of the corresponding xml file containing the same information |
---|
| 27 | % In the absence of input (as activated when the current Action is selected |
---|
| 28 | % in series), the function ouput GUI_input set the activation of the needed GUI elements |
---|
[169] | 29 | % |
---|
[457] | 30 | % Param contains the elements:(use the menu bar command 'export/GUI config' in series to see the current structure Param) |
---|
| 31 | % .InputTable: cell of input file names, (several lines for multiple input) |
---|
| 32 | % each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension} |
---|
| 33 | % .OutputSubDir: name of the subdirectory for data outputs |
---|
[474] | 34 | % .OutputDirExt: directory extension for data outputs |
---|
[457] | 35 | % .Action: .ActionName: name of the current activated function |
---|
| 36 | % .ActionPath: path of the current activated function |
---|
| 37 | % .IndexRange: set the file or frame indices on which the action must be performed |
---|
| 38 | % .FieldTransform: .TransformName: name of the selected transform function |
---|
| 39 | % .TransformPath: path of the selected transform function |
---|
| 40 | % .TransformHandle: corresponding function handle |
---|
| 41 | % .InputFields: sub structure describing the input fields withfields |
---|
| 42 | % .FieldName: name of the field |
---|
| 43 | % .VelType: velocity type |
---|
| 44 | % .FieldName_1: name of the second field in case of two input series |
---|
| 45 | % .VelType_1: velocity type of the second field in case of two input series |
---|
| 46 | % .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object) |
---|
| 47 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 48 | |
---|
[462] | 49 | function ParamOut=merge_proj(Param) |
---|
[29] | 50 | |
---|
[457] | 51 | %% set the input elements needed on the GUI series when the action is selected in the menu ActionName |
---|
| 52 | if ~exist('Param','var') % case with no input parameter |
---|
[474] | 53 | ParamOut={'AllowInputSort';'off';...% allow alphabetic sorting of the list of input files (options 'off'/'on', 'off' by default) |
---|
[462] | 54 | 'WholeIndexRange';'off';...% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default) |
---|
[29] | 55 | 'NbSlice';'on'; ...%nbre of slices ('off' by default) |
---|
[462] | 56 | 'VelType';'one';...% menu for selecting the velocity type (options 'off'/'one'/'two', 'off' by default) |
---|
| 57 | 'FieldName';'one';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default) |
---|
[457] | 58 | 'FieldTransform'; 'on';...%can use a transform function |
---|
| 59 | 'ProjObject';'on';...%can use projection object(option 'off'/'on', |
---|
[462] | 60 | 'Mask';'off';...%can use mask option (option 'off'/'on', 'off' by default) |
---|
| 61 | 'OutputDirExt';'.mproj';...%set the output dir extension |
---|
[29] | 62 | ''}; |
---|
[457] | 63 | return |
---|
[29] | 64 | end |
---|
| 65 | |
---|
[457] | 66 | %%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%% |
---|
| 67 | %% select different modes, RUN, parameter input, BATCH |
---|
| 68 | % BATCH case: read the xml file for batch case |
---|
| 69 | if ischar(Param) |
---|
| 70 | Param=xml2struct(Param); |
---|
| 71 | checkrun=0; |
---|
| 72 | % RUN case: parameters introduced as the input structure Param |
---|
| 73 | else |
---|
[374] | 74 | hseries=guidata(Param.hseries);%handles of the GUI series |
---|
[462] | 75 | if isfield(Param,'Specific')&& strcmp(Param.Specific,'?') |
---|
| 76 | checkrun=1;% will only search interactive input parameters (preparation of BATCH mode) |
---|
| 77 | else |
---|
| 78 | checkrun=2; % indicate the RUN option is used |
---|
| 79 | end |
---|
[374] | 80 | end |
---|
[462] | 81 | ParamOut=Param; %default output |
---|
[550] | 82 | if ~isfield(Param,'InputFields') |
---|
| 83 | Param.InputFields.FieldName=''; |
---|
| 84 | end |
---|
[474] | 85 | OutputSubDir=[Param.OutputSubDir Param.OutputDirExt]; |
---|
[457] | 86 | |
---|
| 87 | %% root input file(s) and type |
---|
| 88 | RootPath=Param.InputTable(:,1); |
---|
| 89 | RootFile=Param.InputTable(:,3); |
---|
| 90 | SubDir=Param.InputTable(:,2); |
---|
| 91 | NomType=Param.InputTable(:,4); |
---|
| 92 | FileExt=Param.InputTable(:,5); |
---|
[374] | 93 | [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param); |
---|
[474] | 94 | %%%%%%%%%%%% |
---|
| 95 | % The cell array filecell is the list of input file names, while |
---|
| 96 | % filecell{iview,fileindex}: |
---|
[457] | 97 | % iview: line in the table corresponding to a given file series |
---|
| 98 | % fileindex: file index within the file series, |
---|
| 99 | % i1_series(iview,ref_j,ref_i)... are the corresponding arrays of indices i1,i2,j1,j2, depending on the input line iview and the two reference indices ref_i,ref_j |
---|
| 100 | % i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices |
---|
[474] | 101 | %%%%%%%%%%%% |
---|
[457] | 102 | NbSlice=1;%default |
---|
[462] | 103 | if isfield(Param.IndexRange,'NbSlice')&&~isempty(Param.IndexRange.NbSlice) |
---|
[457] | 104 | NbSlice=Param.IndexRange.NbSlice; |
---|
| 105 | end |
---|
| 106 | nbview=numel(i1_series);%number of input file series (lines in InputTable) |
---|
| 107 | nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices) |
---|
| 108 | nbfield_i=size(i1_series{1},2); %nb of fields for the i index |
---|
| 109 | nbfield=nbfield_j*nbfield_i; %total number of fields |
---|
| 110 | nbfield_i=floor(nbfield/NbSlice);%total number of indexes in a slice (adjusted to an integer number of slices) |
---|
| 111 | nbfield=nbfield_i*NbSlice; %total number of fields after adjustement |
---|
| 112 | |
---|
| 113 | %determine the file type on each line from the first input file |
---|
[462] | 114 | ImageTypeOptions={'image','multimage','mmreader','video'}; |
---|
| 115 | NcTypeOptions={'netcdf','civx','civdata'}; |
---|
| 116 | for iview=1:nbview |
---|
| 117 | if ~exist(filecell{iview,1}','file') |
---|
[474] | 118 | displ_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist'],checkrun) |
---|
[462] | 119 | return |
---|
| 120 | end |
---|
| 121 | [FileType{iview},FileInfo{iview},MovieObject{iview}]=get_file_type(filecell{iview,1}); |
---|
| 122 | CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images |
---|
| 123 | CheckNc{iview}=~isempty(find(strcmp(FileType{iview},NcTypeOptions)));% =1 for netcdf files |
---|
| 124 | if ~isempty(j1_series{iview}) |
---|
| 125 | frame_index{iview}=j1_series{iview}; |
---|
| 126 | else |
---|
| 127 | frame_index{iview}=i1_series{iview}; |
---|
| 128 | end |
---|
[457] | 129 | end |
---|
| 130 | |
---|
[470] | 131 | |
---|
[457] | 132 | %% calibration data and timing: read the ImaDoc files |
---|
[470] | 133 | [XmlData,NbSlice_calib,time,errormsg]=read_multimadoc(RootPath,SubDir,RootFile,FileExt,i1_series,i2_series,j1_series,j2_series); |
---|
| 134 | if size(time,1)>1 |
---|
[457] | 135 | diff_time=max(max(diff(time))); |
---|
[474] | 136 | if diff_time>0 |
---|
| 137 | displ_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)],checkrun) |
---|
[457] | 138 | end |
---|
| 139 | end |
---|
| 140 | |
---|
[409] | 141 | %% coordinate transform or other user defined transform |
---|
[374] | 142 | transform_fct='';%default |
---|
[478] | 143 | if isfield(Param,'FieldTransform')&&~isempty(Param.FieldTransform.TransformName) |
---|
[474] | 144 | addpath(Param.FieldTransform.TransformPath) |
---|
| 145 | transform_fct=str2func(Param.FieldTransform.TransformName); |
---|
| 146 | rmpath(Param.FieldTransform.TransformPath) |
---|
[374] | 147 | end |
---|
[474] | 148 | |
---|
[457] | 149 | %%%%%%%%%%%% END STANDARD PART %%%%%%%%%%%% |
---|
| 150 | % EDIT FROM HERE |
---|
[116] | 151 | |
---|
[457] | 152 | %% check the validity of input file types |
---|
| 153 | if CheckImage{1} |
---|
| 154 | FileExtOut='.png'; % write result as .png images for image inputs |
---|
| 155 | elseif CheckNc{1} |
---|
| 156 | FileExtOut='.nc';% write result as .nc files for netcdf inputs |
---|
[474] | 157 | else |
---|
| 158 | displ_uvmat('ERROR',['invalid file type input ' FileType{1}],checkrun) |
---|
[457] | 159 | return |
---|
| 160 | end |
---|
[462] | 161 | for iview=1:nbview |
---|
| 162 | if ~isequal(CheckImage{iview},CheckImage{1})||~isequal(CheckNc{iview},CheckNc{1}) |
---|
[474] | 163 | displ_uvmat('ERROR','input set of input series: need either netcdf either image series',checkrun) |
---|
[457] | 164 | return |
---|
[464] | 165 | end |
---|
[457] | 166 | end |
---|
[462] | 167 | NomTypeOut=NomType;% output file index will indicate the first and last ref index in the series |
---|
[474] | 168 | if checkrun==1 |
---|
| 169 | ParamOut.Specific=[];%no specific parameter |
---|
| 170 | return %stop here for interactive input (option Param.Specific='?') |
---|
| 171 | end |
---|
[457] | 172 | |
---|
| 173 | %% Set field names and velocity types |
---|
[462] | 174 | %use Param.InputFields for all views |
---|
[457] | 175 | |
---|
| 176 | %% MAIN LOOP ON SLICES |
---|
| 177 | %%%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%% |
---|
| 178 | for i_slice=1:NbSlice |
---|
| 179 | index_slice=i_slice:NbSlice:nbfield;% select file indices of the slice |
---|
| 180 | nbfiles=0; |
---|
| 181 | nbmissing=0; |
---|
[474] | 182 | |
---|
[457] | 183 | %%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%% |
---|
| 184 | for index=index_slice |
---|
[470] | 185 | |
---|
[457] | 186 | if checkrun |
---|
[478] | 187 | update_waitbar(hseries.Waitbar,index/(nbfield)) |
---|
[457] | 188 | stopstate=get(hseries.RUN,'BusyAction'); |
---|
| 189 | else |
---|
| 190 | stopstate='queue'; |
---|
| 191 | end |
---|
[462] | 192 | |
---|
| 193 | %%%%%%%%%%%%%%%% loop on views (input lines) %%%%%%%%%%%%%%%% |
---|
| 194 | Data=cell(1,nbview);%initiate the set Data |
---|
[464] | 195 | nbtime=0; |
---|
[29] | 196 | for iview=1:nbview |
---|
[462] | 197 | % reading input file(s) |
---|
[464] | 198 | [Data{iview},tild,errormsg] = read_field(filecell{iview,index},FileType{iview},Param.InputFields,frame_index{iview}(index)); |
---|
[462] | 199 | if ~isempty(errormsg) |
---|
[474] | 200 | errormsg=['merge_proj/read_field/' errormsg]; |
---|
| 201 | display(errormsg) |
---|
[29] | 202 | break |
---|
| 203 | end |
---|
[464] | 204 | timeread(iview)=0; |
---|
| 205 | if isfield(Data{iview},'Time') |
---|
[470] | 206 | timeread(iview)=Data{iview}.Time; |
---|
[464] | 207 | nbtime=nbtime+1; |
---|
| 208 | end |
---|
[29] | 209 | if ~isempty(NbSlice_calib) |
---|
[462] | 210 | Data{iview}.ZIndex=mod(i1_series{iview}(index)-1,NbSlice_calib{iview})+1;%Zindex for phys transform |
---|
[29] | 211 | end |
---|
[494] | 212 | |
---|
[464] | 213 | %transform the input field (e.g; phys) if requested |
---|
[41] | 214 | if ~isempty(transform_fct) |
---|
[550] | 215 | switch nargin(transform_fct) |
---|
| 216 | case {2,3,4} |
---|
| 217 | Data{iview}=transform_fct(Data{iview},XmlData{iview}); |
---|
| 218 | case 1 |
---|
| 219 | Data{iview}=transform_fct(Data{iview}); |
---|
| 220 | end |
---|
[29] | 221 | end |
---|
[494] | 222 | |
---|
| 223 | %% check whether tps is needed, then calculate tps coefficients if needed |
---|
| 224 | check_tps=0; |
---|
| 225 | if ischar(Param.InputFields.FieldName) |
---|
| 226 | Param.InputFields.FieldName={Param.InputFields.FieldName}; |
---|
| 227 | end |
---|
| 228 | for ilist=1:numel(Param.InputFields.FieldName) |
---|
| 229 | switch Param.InputFields.FieldName{ilist} |
---|
| 230 | case {'vort','div','strain'} |
---|
| 231 | check_tps=1; |
---|
| 232 | end |
---|
| 233 | end |
---|
[522] | 234 | |
---|
| 235 | %% calculate tps coeff if needed |
---|
| 236 | check_proj_tps= ~isempty(Param.ProjObject)&& strcmp(Param.ProjObject.ProjMode,'filter')&&~isfield(Data{iview},'Coord_tps'); |
---|
| 237 | Data{iview}=calc_tps(Data{iview},check_proj_tps); |
---|
| 238 | |
---|
| 239 | % % field calculation (vort, div...) |
---|
| 240 | % if strcmp(FileType{iview},'civx')||strcmp(FileType{iview},'civdata') |
---|
| 241 | % if isfield(Data{iview},'Coord_tps') |
---|
| 242 | % Data{iview}.FieldList=Param.InputFields.FieldName; |
---|
| 243 | % else |
---|
| 244 | % Data{iview}=calc_field(Param.InputFields.FieldName,Data{iview});%calculate field (vort..) |
---|
| 245 | % end |
---|
| 246 | % end |
---|
[464] | 247 | |
---|
| 248 | %projection on object (gridded plane) |
---|
| 249 | if Param.CheckObject |
---|
| 250 | [Data{iview},errormsg]=proj_field(Data{iview},Param.ProjObject); |
---|
[409] | 251 | if ~isempty(errormsg) |
---|
[474] | 252 | displ_uvmat('ERROR',['error in merge_proge/proj_field: ' errormsg],checkrun) |
---|
[409] | 253 | return |
---|
| 254 | end |
---|
[29] | 255 | end |
---|
[464] | 256 | end |
---|
[222] | 257 | %----------END LOOP ON VIEWS---------------------- |
---|
[464] | 258 | |
---|
[222] | 259 | %% merge the nbview fields |
---|
[462] | 260 | MergeData=merge_field(Data); |
---|
[29] | 261 | if isfield(MergeData,'Txt') |
---|
[474] | 262 | displ_uvmat('ERROR',MergeData.Txt,checkrun) |
---|
[29] | 263 | return |
---|
[464] | 264 | end |
---|
[470] | 265 | |
---|
| 266 | % time of the merged field: |
---|
| 267 | if ~isempty(time)% time defined from ImaDoc |
---|
| 268 | timeread=time(:,index); |
---|
[29] | 269 | end |
---|
[470] | 270 | timeread=mean(timeread); |
---|
| 271 | |
---|
[464] | 272 | % generating the name of the merged field |
---|
| 273 | i1=i1_series{iview}(index); |
---|
| 274 | if ~isempty(i2_series{iview}) |
---|
| 275 | i2=i2_series{iview}(index); |
---|
| 276 | else |
---|
| 277 | i2=i1; |
---|
| 278 | end |
---|
| 279 | j1=1; |
---|
| 280 | j2=1; |
---|
| 281 | if ~isempty(j1_series{iview}) |
---|
| 282 | j1=j1_series{iview}(index); |
---|
| 283 | if ~isempty(j2_series{iview}) |
---|
| 284 | j2=j2_series{iview}(index); |
---|
| 285 | else |
---|
| 286 | j2=j1; |
---|
| 287 | end |
---|
| 288 | end |
---|
[474] | 289 | OutputFile=fullfile_uvmat(RootPath{1},OutputSubDir,RootFile{1},FileExtOut,NomType{1},i1,i2,j1,j2); |
---|
[29] | 290 | |
---|
[464] | 291 | % recording the merged field |
---|
| 292 | if CheckImage{1} %in case of input images an image is produced |
---|
[29] | 293 | if isa(MergeData.A,'uint8') |
---|
| 294 | bitdepth=8; |
---|
| 295 | elseif isa(MergeData.A,'uint16') |
---|
| 296 | bitdepth=16; |
---|
| 297 | end |
---|
[464] | 298 | imwrite(MergeData.A,OutputFile,'BitDepth',bitdepth); |
---|
[29] | 299 | %write xml calibration file |
---|
| 300 | siz=size(MergeData.A); |
---|
| 301 | npy=siz(1); |
---|
| 302 | npx=siz(2); |
---|
| 303 | if isfield(MergeData,'VarAttribute')&&isfield(MergeData.VarAttribute{1},'Coord_2')&&isfield(MergeData.VarAttribute{1},'Coord_1') |
---|
| 304 | Rangx=MergeData.VarAttribute{1}.Coord_2; |
---|
| 305 | Rangy=MergeData.VarAttribute{1}.Coord_1; |
---|
| 306 | elseif isfield(MergeData,'AX')&& isfield(MergeData,'AY') |
---|
| 307 | Rangx=[MergeData.AX(1) MergeData.AX(end)]; |
---|
| 308 | Rangy=[MergeData.AY(1) MergeData.AY(end)]; |
---|
| 309 | else |
---|
| 310 | Rangx=[0.5 npx-0.5]; |
---|
| 311 | Rangy=[npy-0.5 0.5];%default |
---|
| 312 | end |
---|
| 313 | pxcmx=(npx-1)/(Rangx(2)-Rangx(1)); |
---|
| 314 | pxcmy=(npy-1)/(Rangy(1)-Rangy(2)); |
---|
| 315 | T_x=-pxcmx*Rangx(1)+0.5; |
---|
| 316 | T_y=-pxcmy*Rangy(2)+0.5; |
---|
| 317 | GeometryCal.focal=1; |
---|
| 318 | GeometryCal.R=[pxcmx,0,0;0,pxcmy,0;0,0,1]; |
---|
| 319 | GeometryCal.Tx_Ty_Tz=[T_x T_y 1]; |
---|
| 320 | ImaDoc.GeometryCalib=GeometryCal; |
---|
[550] | 321 | % t=struct2xml(ImaDoc); |
---|
| 322 | % t=set(t,1,'name','ImaDoc'); |
---|
| 323 | % save(t,[filebase_merge '.xml']) |
---|
| 324 | % display([filebase_merge '.xml saved']) |
---|
[29] | 325 | else |
---|
[464] | 326 | MergeData.ListGlobalAttribute={'Conventions','Project','InputFile_1','InputFile_end','nb_coord','nb_dim','dt','Time','civ'}; |
---|
[422] | 327 | MergeData.Conventions='uvmat'; |
---|
[29] | 328 | MergeData.nb_coord=2; |
---|
| 329 | MergeData.nb_dim=2; |
---|
[93] | 330 | dt=[]; |
---|
[462] | 331 | if isfield(Data{1},'dt')&& isnumeric(Data{1}.dt) |
---|
| 332 | dt=Data{1}.dt; |
---|
[93] | 333 | end |
---|
[462] | 334 | for iview =2:numel(Data) |
---|
| 335 | if ~(isfield(Data{iview},'dt')&& isequal(Data{iview}.dt,dt)) |
---|
[93] | 336 | dt=[];%dt not the same for all fields |
---|
| 337 | end |
---|
| 338 | end |
---|
| 339 | if isempty(dt) |
---|
| 340 | MergeData.ListGlobalAttribute(6)=[]; |
---|
| 341 | else |
---|
[464] | 342 | MergeData.dt=dt; |
---|
[93] | 343 | end |
---|
[470] | 344 | MergeData.Time=timeread; |
---|
[462] | 345 | error=struct2nc(OutputFile,MergeData);%save result file |
---|
[29] | 346 | if isempty(error) |
---|
[462] | 347 | display(['output file ' OutputFile ' written']) |
---|
[29] | 348 | else |
---|
| 349 | display(error) |
---|
| 350 | end |
---|
| 351 | end |
---|
| 352 | end |
---|
| 353 | end |
---|
| 354 | |
---|
[222] | 355 | %'merge_field': concatene fields |
---|
| 356 | %------------------------------------------------------------------------ |
---|
[29] | 357 | function MergeData=merge_field(Data) |
---|
[222] | 358 | %% default output |
---|
[29] | 359 | if isempty(Data)||~iscell(Data) |
---|
| 360 | MergeData=[]; |
---|
| 361 | return |
---|
| 362 | end |
---|
| 363 | MergeData=Data{1};%default |
---|
| 364 | error=0; |
---|
| 365 | nbview=length(Data); |
---|
| 366 | if nbview==1 |
---|
| 367 | return |
---|
| 368 | end |
---|
[222] | 369 | |
---|
[522] | 370 | %% group the variables (fields of 'Data') in cells of variables with the same dimensions |
---|
| 371 | [CellVarIndex,NbDim,VarTypeCell]=find_field_cells(Data{1}); |
---|
[89] | 372 | %LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS |
---|
| 373 | % CellVarIndex=cells of variable index arrays |
---|
| 374 | for icell=1:length(CellVarIndex) |
---|
| 375 | if NbDim(icell)==1 |
---|
| 376 | continue |
---|
| 377 | end |
---|
| 378 | VarIndex=CellVarIndex{icell};% indices of the selected variables in the list FieldData.ListVarName |
---|
| 379 | VarType=VarTypeCell{icell}; |
---|
| 380 | ivar_X=VarType.coord_x; |
---|
| 381 | ivar_Y=VarType.coord_y; |
---|
| 382 | ivar_FF=VarType.errorflag; |
---|
| 383 | if isempty(ivar_X) |
---|
| 384 | test_grid=1;%test for input data on regular grid (e.g. image)coordinates |
---|
| 385 | else |
---|
| 386 | if length(ivar_Y)~=1 |
---|
[474] | 387 | displ_uvmat('ERROR','y coordinate missing in proj_field.m',checkrun) |
---|
[89] | 388 | return |
---|
| 389 | end |
---|
| 390 | test_grid=0; |
---|
| 391 | end |
---|
| 392 | %case of input fields with unstructured coordinates |
---|
| 393 | if ~test_grid |
---|
| 394 | for ivar=VarIndex |
---|
| 395 | VarName=MergeData.ListVarName{ivar}; |
---|
| 396 | for iview=1:nbview |
---|
[522] | 397 | MergeData.(VarName)=[MergeData.(VarName); Data{iview}.(VarName)]; |
---|
[89] | 398 | end |
---|
| 399 | end |
---|
| 400 | %case of fields defined on a structured grid |
---|
| 401 | else |
---|
| 402 | testFF=0; |
---|
| 403 | for iview=2:nbview |
---|
| 404 | for ivar=VarIndex |
---|
| 405 | VarName=MergeData.ListVarName{ivar}; |
---|
| 406 | if isfield(MergeData,'VarAttribute') |
---|
| 407 | if length(MergeData.VarAttribute)>=ivar && isfield(MergeData.VarAttribute{ivar},'Role') && isequal(MergeData.VarAttribute{ivar}.Role,'errorflag') |
---|
| 408 | testFF=1; |
---|
| 409 | end |
---|
| 410 | end |
---|
[522] | 411 | MergeData.(VarName)=MergeData.(VarName) + Data{iview}.(VarName); |
---|
[89] | 412 | end |
---|
| 413 | end |
---|
| 414 | if testFF |
---|
| 415 | nbaver=nbview-MergeData.FF; |
---|
| 416 | indgood=find(nbaver>0); |
---|
| 417 | for ivar=VarIndex |
---|
| 418 | VarName=MergeData.ListVarName{ivar}; |
---|
[522] | 419 | MergeData.(VarName)(indgood)=double(MergeData.(VarName)(indgood))./nbaver(indgood); |
---|
[89] | 420 | end |
---|
| 421 | else |
---|
| 422 | for ivar=VarIndex |
---|
| 423 | VarName=MergeData.ListVarName{ivar}; |
---|
[522] | 424 | MergeData.(VarName)=double(MergeData.(VarName))./nbview; |
---|
[89] | 425 | end |
---|
| 426 | end |
---|
| 427 | end |
---|
| 428 | end |
---|
[222] | 429 | |
---|
[89] | 430 | |
---|