[573] | 1 | %'merge_proj': concatene several fields from series, can project them on a regular grid in phys coordinates |
---|
[457] | 2 | %------------------------------------------------------------------------ |
---|
[464] | 3 | % function ParamOut=merge_proj(Param) |
---|
[457] | 4 | %------------------------------------------------------------------------ |
---|
| 5 | %%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
[169] | 6 | % |
---|
| 7 | %OUTPUT |
---|
[596] | 8 | % ParamOut: sets options in the GUI series.fig needed for the function |
---|
[169] | 9 | % |
---|
| 10 | %INPUT: |
---|
[457] | 11 | % In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series. |
---|
| 12 | % In batch mode, Param is the name of the corresponding xml file containing the same information |
---|
[596] | 13 | % when Param.Action.RUN=0 (as activated when the current Action is selected |
---|
| 14 | % in series), the function ouput paramOut set the activation of the needed GUI elements |
---|
[169] | 15 | % |
---|
[596] | 16 | % Param contains the elements:(use the menu bar command 'export/GUI config' in series to |
---|
| 17 | % see the current structure Param) |
---|
[457] | 18 | % .InputTable: cell of input file names, (several lines for multiple input) |
---|
| 19 | % each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension} |
---|
| 20 | % .OutputSubDir: name of the subdirectory for data outputs |
---|
[474] | 21 | % .OutputDirExt: directory extension for data outputs |
---|
[457] | 22 | % .Action: .ActionName: name of the current activated function |
---|
| 23 | % .ActionPath: path of the current activated function |
---|
[596] | 24 | % .ActionExt: fct extension ('.m', Matlab fct, '.sh', compiled Matlab fct |
---|
| 25 | % .RUN =0 for GUI input, =1 for function activation |
---|
| 26 | % .RunMode='local','background', 'cluster': type of function use |
---|
| 27 | % |
---|
[457] | 28 | % .IndexRange: set the file or frame indices on which the action must be performed |
---|
| 29 | % .FieldTransform: .TransformName: name of the selected transform function |
---|
| 30 | % .TransformPath: path of the selected transform function |
---|
| 31 | % .InputFields: sub structure describing the input fields withfields |
---|
[596] | 32 | % .FieldName: name(s) of the field |
---|
[457] | 33 | % .VelType: velocity type |
---|
| 34 | % .FieldName_1: name of the second field in case of two input series |
---|
| 35 | % .VelType_1: velocity type of the second field in case of two input series |
---|
[596] | 36 | % .Coord_y: name of y coordinate variable |
---|
| 37 | % .Coord_x: name of x coordinate variable |
---|
[457] | 38 | % .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object) |
---|
| 39 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 40 | |
---|
[462] | 41 | function ParamOut=merge_proj(Param) |
---|
[29] | 42 | |
---|
[606] | 43 | %% set the input elements needed on the GUI series when the function is selected in the menu ActionName or InputTable refreshed |
---|
[592] | 44 | if isstruct(Param) && isequal(Param.Action.RUN,0) |
---|
[606] | 45 | ParamOut.AllowInputSort='off';% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default) |
---|
[632] | 46 | ParamOut.WholeIndexRange='off';% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default) |
---|
[606] | 47 | ParamOut.NbSlice='off'; %nbre of slices ('off' by default) |
---|
| 48 | ParamOut.VelType='one';% menu for selecting the velocity type (options 'off'/'one'/'two', 'off' by default) |
---|
| 49 | ParamOut.FieldName='one';% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default) |
---|
| 50 | ParamOut.FieldTransform = 'on';%can use a transform function |
---|
| 51 | ParamOut.TransformPath=fullfile(fileparts(which('uvmat')),'transform_field');% path to transform functions (needed for compilation only) |
---|
| 52 | ParamOut.ProjObject='on';%can use projection object(option 'off'/'on', |
---|
[635] | 53 | ParamOut.Mask='on';%can use mask option (option 'off'/'on', 'off' by default) |
---|
[592] | 54 | ParamOut.OutputDirExt='.mproj';%set the output dir extension |
---|
[605] | 55 | ParamOut.OutputFileMode='NbInput';% '=NbInput': 1 output file per input file index, '=NbInput_i': 1 file per input file index i, '=NbSlice': 1 file per slice |
---|
| 56 | filecell=get_file_series(Param);%check existence of the first input file |
---|
| 57 | if ~exist(filecell{1,1},'file') |
---|
| 58 | msgbox_uvmat('WARNING','the first input file does not exist') |
---|
| 59 | elseif isequal(size(Param.InputTable,1),1) && ~isfield(Param,'ProjObject') |
---|
[635] | 60 | msgbox_uvmat('WARNING','You may need a projection object of type plane for merge_proj') |
---|
[605] | 61 | end |
---|
[606] | 62 | return |
---|
[29] | 63 | end |
---|
| 64 | |
---|
[457] | 65 | %%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%% |
---|
[632] | 66 | ParamOut=[]; %default output |
---|
[592] | 67 | %% read input parameters from an xml file if input is a file name (batch mode) |
---|
| 68 | checkrun=1; |
---|
[457] | 69 | if ischar(Param) |
---|
[592] | 70 | Param=xml2struct(Param);% read Param as input file (batch case) |
---|
| 71 | checkrun=0; |
---|
[374] | 72 | end |
---|
[624] | 73 | hseries=findobj(allchild(0),'Tag','series'); |
---|
| 74 | RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series |
---|
| 75 | WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series |
---|
[592] | 76 | |
---|
[624] | 77 | %% define the directory for result file (with path=RootPath{1}) |
---|
| 78 | OutputDir=[Param.OutputSubDir Param.OutputDirExt];% subdirectory for output files |
---|
| 79 | |
---|
[550] | 80 | if ~isfield(Param,'InputFields') |
---|
| 81 | Param.InputFields.FieldName=''; |
---|
| 82 | end |
---|
[457] | 83 | |
---|
[577] | 84 | %% root input file type |
---|
[457] | 85 | RootPath=Param.InputTable(:,1); |
---|
| 86 | RootFile=Param.InputTable(:,3); |
---|
| 87 | SubDir=Param.InputTable(:,2); |
---|
| 88 | NomType=Param.InputTable(:,4); |
---|
| 89 | FileExt=Param.InputTable(:,5); |
---|
[374] | 90 | [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param); |
---|
[474] | 91 | %%%%%%%%%%%% |
---|
| 92 | % The cell array filecell is the list of input file names, while |
---|
| 93 | % filecell{iview,fileindex}: |
---|
[457] | 94 | % iview: line in the table corresponding to a given file series |
---|
| 95 | % fileindex: file index within the file series, |
---|
| 96 | % 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 |
---|
| 97 | % i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices |
---|
[474] | 98 | %%%%%%%%%%%% |
---|
[606] | 99 | % NbSlice=1;%default |
---|
| 100 | % if isfield(Param.IndexRange,'NbSlice')&&~isempty(Param.IndexRange.NbSlice) |
---|
| 101 | % NbSlice=Param.IndexRange.NbSlice; |
---|
| 102 | % end |
---|
| 103 | NbView=numel(i1_series);%number of input file series (lines in InputTable) |
---|
| 104 | NbField_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices) |
---|
| 105 | NbField_i=size(i1_series{1},2); %nb of fields for the i index |
---|
| 106 | NbField=NbField_j*NbField_i; %total number of fields |
---|
[457] | 107 | |
---|
[673] | 108 | %% determine the file type on each line from the first input file |
---|
[462] | 109 | ImageTypeOptions={'image','multimage','mmreader','video'}; |
---|
| 110 | NcTypeOptions={'netcdf','civx','civdata'}; |
---|
[606] | 111 | for iview=1:NbView |
---|
[462] | 112 | if ~exist(filecell{iview,1}','file') |
---|
[668] | 113 | disp_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist'],checkrun) |
---|
[462] | 114 | return |
---|
| 115 | end |
---|
| 116 | [FileType{iview},FileInfo{iview},MovieObject{iview}]=get_file_type(filecell{iview,1}); |
---|
| 117 | CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images |
---|
| 118 | CheckNc{iview}=~isempty(find(strcmp(FileType{iview},NcTypeOptions)));% =1 for netcdf files |
---|
| 119 | if ~isempty(j1_series{iview}) |
---|
| 120 | frame_index{iview}=j1_series{iview}; |
---|
| 121 | else |
---|
| 122 | frame_index{iview}=i1_series{iview}; |
---|
| 123 | end |
---|
[457] | 124 | end |
---|
| 125 | |
---|
| 126 | %% calibration data and timing: read the ImaDoc files |
---|
[470] | 127 | [XmlData,NbSlice_calib,time,errormsg]=read_multimadoc(RootPath,SubDir,RootFile,FileExt,i1_series,i2_series,j1_series,j2_series); |
---|
| 128 | if size(time,1)>1 |
---|
[457] | 129 | diff_time=max(max(diff(time))); |
---|
[474] | 130 | if diff_time>0 |
---|
[670] | 131 | disp_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time) ': time of first series chosen in result'],checkrun) |
---|
[457] | 132 | end |
---|
| 133 | end |
---|
| 134 | |
---|
[409] | 135 | %% coordinate transform or other user defined transform |
---|
[606] | 136 | transform_fct='';%default fct handle |
---|
[478] | 137 | if isfield(Param,'FieldTransform')&&~isempty(Param.FieldTransform.TransformName) |
---|
[606] | 138 | currentdir=pwd; |
---|
| 139 | cd(Param.FieldTransform.TransformPath) |
---|
| 140 | transform_fct=str2func(Param.FieldTransform.TransformName); |
---|
| 141 | cd (currentdir) |
---|
[374] | 142 | end |
---|
[457] | 143 | %%%%%%%%%%%% END STANDARD PART %%%%%%%%%%%% |
---|
| 144 | % EDIT FROM HERE |
---|
[116] | 145 | |
---|
[457] | 146 | %% check the validity of input file types |
---|
[606] | 147 | for iview=1:NbView |
---|
[673] | 148 | if ~isequal(CheckImage{iview},1)&&~isequal(CheckNc{iview},1) |
---|
[668] | 149 | disp_uvmat('ERROR','input set of input series: need either netcdf either image series',checkrun) |
---|
[632] | 150 | return |
---|
[464] | 151 | end |
---|
[457] | 152 | end |
---|
[673] | 153 | |
---|
| 154 | %% output file type |
---|
| 155 | if min(cell2mat(CheckImage))==1 && (~Param.CheckObject || strcmp(Param.ProjObject.Type,'plane')) |
---|
| 156 | FileExtOut='.png'; %image output (input and proj result = image) |
---|
| 157 | for iview=1:NbView |
---|
| 158 | BitDepth(iview)=FileInfo{iview}.BitDepth; |
---|
| 159 | end |
---|
| 160 | BitDepth=max(BitDepth); |
---|
| 161 | else |
---|
| 162 | FileExtOut='.nc'; %netcdf output |
---|
| 163 | end |
---|
[462] | 164 | NomTypeOut=NomType;% output file index will indicate the first and last ref index in the series |
---|
[673] | 165 | RootFileOut=RootFile{1}; |
---|
| 166 | for iview=2:NbView |
---|
| 167 | if ~strcmp(RootFile{iview},RootFile{1}) |
---|
| 168 | RootFileOut='mproj'; |
---|
| 169 | break |
---|
| 170 | end |
---|
| 171 | end |
---|
[457] | 172 | |
---|
[642] | 173 | %% mask (TODO: case of multilevels) |
---|
[668] | 174 | MaskData=cell(NbView,1); |
---|
[642] | 175 | if Param.CheckMask |
---|
[668] | 176 | for iview=1:numel(Param.MaskTable) |
---|
[673] | 177 | if exist(Param.MaskTable{iview},'file') |
---|
| 178 | [MaskData{iview},tild,errormsg] = read_field(Param.MaskTable{iview},'image'); |
---|
| 179 | if ~isempty(transform_fct) && nargin(transform_fct)>=2 |
---|
| 180 | MaskData{iview}=transform_fct(MaskData{iview},XmlData{iview}); |
---|
| 181 | end |
---|
[642] | 182 | end |
---|
| 183 | end |
---|
| 184 | end |
---|
| 185 | |
---|
[457] | 186 | %% Set field names and velocity types |
---|
[462] | 187 | %use Param.InputFields for all views |
---|
[457] | 188 | |
---|
[640] | 189 | %% MAIN LOOP ON FIELDS |
---|
[457] | 190 | %%%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%% |
---|
[606] | 191 | % for i_slice=1:NbSlice |
---|
| 192 | % index_slice=i_slice:NbSlice:NbField;% select file indices of the slice |
---|
| 193 | % NbFiles=0; |
---|
| 194 | % nbmissing=0; |
---|
[474] | 195 | |
---|
[457] | 196 | %%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%% |
---|
[606] | 197 | for index=1:NbField |
---|
[626] | 198 | update_waitbar(WaitbarHandle,index/NbField) |
---|
[642] | 199 | if ~isempty(RUNHandle) && ~strcmp(get(RUNHandle,'BusyAction'),'queue') |
---|
[624] | 200 | disp('program stopped by user') |
---|
[606] | 201 | return |
---|
| 202 | end |
---|
[673] | 203 | |
---|
[606] | 204 | %%%%%%%%%%%%%%%% loop on views (input lines) %%%%%%%%%%%%%%%% |
---|
| 205 | Data=cell(1,NbView);%initiate the set Data |
---|
| 206 | nbtime=0; |
---|
| 207 | for iview=1:NbView |
---|
| 208 | %% reading input file(s) |
---|
| 209 | [Data{iview},tild,errormsg] = read_field(filecell{iview,index},FileType{iview},Param.InputFields,frame_index{iview}(index)); |
---|
| 210 | if ~isempty(errormsg) |
---|
[614] | 211 | disp(['ERROR in merge_proj/read_field/' errormsg]) |
---|
| 212 | return |
---|
[457] | 213 | end |
---|
[606] | 214 | timeread(iview)=0; |
---|
| 215 | if isfield(Data{iview},'Time') |
---|
| 216 | timeread(iview)=Data{iview}.Time; |
---|
| 217 | nbtime=nbtime+1; |
---|
[595] | 218 | end |
---|
[606] | 219 | if ~isempty(NbSlice_calib) |
---|
| 220 | Data{iview}.ZIndex=mod(i1_series{iview}(index)-1,NbSlice_calib{iview})+1;%Zindex for phys transform |
---|
| 221 | end |
---|
[642] | 222 | |
---|
[632] | 223 | %% transform the input field (e.g; phys) if requested (no transform involving two input fields) |
---|
[606] | 224 | if ~isempty(transform_fct) |
---|
| 225 | if nargin(transform_fct)>=2 |
---|
| 226 | Data{iview}=transform_fct(Data{iview},XmlData{iview}); |
---|
| 227 | else |
---|
| 228 | Data{iview}=transform_fct(Data{iview}); |
---|
[29] | 229 | end |
---|
[606] | 230 | end |
---|
[632] | 231 | |
---|
[642] | 232 | %% calculate tps coefficients if needed |
---|
[614] | 233 | check_proj_tps= isfield(Param,'ProjObject')&&~isempty(Param.ProjObject)&& strcmp(Param.ProjObject.ProjMode,'interp_tps')&&~isfield(Data{iview},'Coord_tps'); |
---|
[606] | 234 | Data{iview}=tps_coeff_field(Data{iview},check_proj_tps); |
---|
[642] | 235 | |
---|
[606] | 236 | %% projection on object (gridded plane) |
---|
| 237 | if Param.CheckObject |
---|
| 238 | [Data{iview},errormsg]=proj_field(Data{iview},Param.ProjObject); |
---|
| 239 | if ~isempty(errormsg) |
---|
[614] | 240 | disp(['ERROR in merge_proge/proj_field: ' errormsg]) |
---|
[606] | 241 | return |
---|
[29] | 242 | end |
---|
[464] | 243 | end |
---|
[640] | 244 | |
---|
| 245 | %% mask |
---|
[642] | 246 | if Param.CheckMask && ~isempty(MaskData{iview}) |
---|
| 247 | [Data{iview},errormsg]=mask_proj(Data{iview},MaskData{iview}); |
---|
[640] | 248 | end |
---|
[606] | 249 | end |
---|
[673] | 250 | %%%%%%%%%%%%%%%% END LOOP ON VIEWS %%%%%%%%%%%%%%%% |
---|
[606] | 251 | |
---|
| 252 | %% merge the NbView fields |
---|
| 253 | MergeData=merge_field(Data); |
---|
| 254 | if isfield(MergeData,'Txt') |
---|
[614] | 255 | disp(MergeData.Txt); |
---|
[606] | 256 | return |
---|
| 257 | end |
---|
| 258 | |
---|
[673] | 259 | %% time of the merged field: take the average of the different views |
---|
[606] | 260 | if ~isempty(time)% time defined from ImaDoc |
---|
| 261 | timeread=time(:,index); |
---|
| 262 | end |
---|
| 263 | timeread=mean(timeread); |
---|
| 264 | |
---|
[673] | 265 | %% generating the name of the merged field |
---|
| 266 | i1=i1_series{1}(index); |
---|
| 267 | if ~isempty(i2_series{end}) |
---|
| 268 | i2=i2_series{end}(index); |
---|
[606] | 269 | else |
---|
| 270 | i2=i1; |
---|
| 271 | end |
---|
| 272 | j1=1; |
---|
| 273 | j2=1; |
---|
[673] | 274 | if ~isempty(j1_series{1}) |
---|
| 275 | j1=j1_series{1}(index); |
---|
| 276 | if ~isempty(j2_series{end}) |
---|
| 277 | j2=j2_series{end}(index); |
---|
[606] | 278 | else |
---|
| 279 | j2=j1; |
---|
[464] | 280 | end |
---|
[606] | 281 | end |
---|
[673] | 282 | OutputFile=fullfile_uvmat(RootPath{1},OutputDir,RootFileOut,FileExtOut,NomType{1},i1,i2,j1,j2); |
---|
[606] | 283 | |
---|
[673] | 284 | %% recording the merged field |
---|
| 285 | if strcmp(FileExtOut,'.png') %output as image |
---|
| 286 | if BitDepth==8 |
---|
| 287 | imwrite(uint8(MergeData.A),OutputFile,'BitDepth',8) |
---|
[464] | 288 | else |
---|
[673] | 289 | imwrite(uint16(MergeData.A),OutputFile,'BitDepth',16) |
---|
[464] | 290 | end |
---|
[673] | 291 | if index==1 |
---|
| 292 | %write xml calibration file, using the first file |
---|
| 293 | siz=size(MergeData.A); |
---|
| 294 | npy=siz(1); |
---|
| 295 | npx=siz(2); |
---|
| 296 | if isfield(MergeData,'coord_x') && isfield(MergeData,'coord_y') |
---|
| 297 | Rangx=MergeData.coord_x; |
---|
| 298 | Rangy=MergeData.coord_y; |
---|
| 299 | elseif isfield(MergeData,'AX')&& isfield(MergeData,'AY') |
---|
| 300 | Rangx=[MergeData.AX(1) MergeData.AX(end)]; |
---|
| 301 | Rangy=[MergeData.AY(1) MergeData.AY(end)]; |
---|
| 302 | else |
---|
| 303 | Rangx=[0.5 npx-0.5]; |
---|
| 304 | Rangy=[npy-0.5 0.5];%default |
---|
| 305 | end |
---|
| 306 | pxcmx=(npx-1)/(Rangx(2)-Rangx(1)); |
---|
| 307 | pxcmy=(npy-1)/(Rangy(1)-Rangy(2)); |
---|
| 308 | T_x=-pxcmx*Rangx(1)+0.5; |
---|
| 309 | T_y=-pxcmy*Rangy(2)+0.5; |
---|
| 310 | GeometryCal.CalibrationType='rescale'; |
---|
| 311 | GeometryCal.CoordUnit=MergeData.CoordUnit; |
---|
| 312 | GeometryCal.focal=1; |
---|
| 313 | GeometryCal.R=[pxcmx,0,0;0,pxcmy,0;0,0,1]; |
---|
| 314 | GeometryCal.Tx_Ty_Tz=[T_x T_y 1]; |
---|
| 315 | ImaDoc.GeometryCalib=GeometryCal; |
---|
| 316 | t=struct2xml(ImaDoc); |
---|
| 317 | t=set(t,1,'name','ImaDoc'); |
---|
| 318 | save(t,[fileparts(OutputFile) '.xml']) |
---|
| 319 | end |
---|
| 320 | |
---|
[606] | 321 | else |
---|
| 322 | MergeData.ListGlobalAttribute={'Conventions','Project','InputFile_1','InputFile_end','nb_coord','nb_dim','dt','Time','civ'}; |
---|
| 323 | MergeData.Conventions='uvmat'; |
---|
| 324 | MergeData.nb_coord=2; |
---|
| 325 | MergeData.nb_dim=2; |
---|
| 326 | dt=[]; |
---|
| 327 | if isfield(Data{1},'dt')&& isnumeric(Data{1}.dt) |
---|
| 328 | dt=Data{1}.dt; |
---|
| 329 | end |
---|
| 330 | for iview =2:numel(Data) |
---|
| 331 | if ~(isfield(Data{iview},'dt')&& isequal(Data{iview}.dt,dt)) |
---|
| 332 | dt=[];%dt not the same for all fields |
---|
[464] | 333 | end |
---|
| 334 | end |
---|
[606] | 335 | if isempty(dt) |
---|
| 336 | MergeData.ListGlobalAttribute(6)=[]; |
---|
[29] | 337 | else |
---|
[606] | 338 | MergeData.dt=dt; |
---|
[29] | 339 | end |
---|
[606] | 340 | MergeData.Time=timeread; |
---|
| 341 | error=struct2nc(OutputFile,MergeData);%save result file |
---|
| 342 | if isempty(error) |
---|
| 343 | display(['output file ' OutputFile ' written']) |
---|
| 344 | else |
---|
| 345 | display(error) |
---|
| 346 | end |
---|
[29] | 347 | end |
---|
| 348 | end |
---|
| 349 | |
---|
[606] | 350 | |
---|
[222] | 351 | %'merge_field': concatene fields |
---|
| 352 | %------------------------------------------------------------------------ |
---|
[29] | 353 | function MergeData=merge_field(Data) |
---|
[222] | 354 | %% default output |
---|
[29] | 355 | if isempty(Data)||~iscell(Data) |
---|
| 356 | MergeData=[]; |
---|
| 357 | return |
---|
| 358 | end |
---|
| 359 | error=0; |
---|
[673] | 360 | MergeData=Data{1};% merged field= first field by default, reproduces the glabal attributes of the first field |
---|
[606] | 361 | NbView=length(Data); |
---|
| 362 | if NbView==1 |
---|
[29] | 363 | return |
---|
| 364 | end |
---|
[222] | 365 | |
---|
[522] | 366 | %% group the variables (fields of 'Data') in cells of variables with the same dimensions |
---|
[668] | 367 | [CellInfo,NbDim,errormsg]=find_field_cells(Data{1}); |
---|
[670] | 368 | |
---|
[89] | 369 | %LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS |
---|
[668] | 370 | for icell=1:length(CellInfo) |
---|
[670] | 371 | if NbDim(icell)~=1 % skip field cells which are of dim 1 |
---|
| 372 | switch CellInfo{icell}.CoordType |
---|
| 373 | case 'scattered' %case of input fields with unstructured coordinates: just concacene data |
---|
| 374 | for ivar=CellInfo{icell}.VarIndex % indices of the selected variables in the list FieldData.ListVarName |
---|
| 375 | VarName=Data{1}.ListVarName{ivar}; |
---|
| 376 | %MergeData=Data{1};% merged field= first field by default, reproduces the glabal attributes of the first field |
---|
| 377 | for iview=2:NbView |
---|
| 378 | MergeData.(VarName)=[MergeData.(VarName); Data{iview}.(VarName)]; |
---|
[89] | 379 | end |
---|
| 380 | end |
---|
[670] | 381 | case 'grid' %case of fields defined on a structured grid |
---|
| 382 | FFName=''; |
---|
| 383 | if ~isempty(CellInfo{icell}.VarIndex_errorflag) |
---|
| 384 | FFName=Data{1}.ListVarName{CellInfo{icell}.VarIndex_errorflag};% name of errorflag variable |
---|
| 385 | end |
---|
| 386 | % select good data on each view |
---|
| 387 | for ivar=CellInfo{icell}.VarIndex % indices of the selected variables in the list FieldData.ListVarName |
---|
| 388 | VarName=Data{1}.ListVarName{ivar}; |
---|
| 389 | for iview=1:NbView |
---|
| 390 | if isempty(FFName) |
---|
| 391 | check_bad=isnan(Data{iview}.(VarName));%=0 for NaN data values, 1 else |
---|
| 392 | else |
---|
| 393 | check_bad=isnan(Data{iview}.(VarName)) | Data{iview}.(FFName)~=0;%=0 for NaN or error flagged data values, 1 else |
---|
| 394 | end |
---|
| 395 | Data{iview}.(VarName)(check_bad)=0; %set to zero NaN or masked data |
---|
| 396 | if iview==1 |
---|
| 397 | MergeData.(VarName)=Data{1}.(VarName);% correct the field of MergeData |
---|
| 398 | NbAver=~check_bad;% initiate NbAver: the nbre of good data for each point |
---|
| 399 | else |
---|
| 400 | MergeData.(VarName)=MergeData.(VarName) + Data{iview}.(VarName);%add data |
---|
| 401 | NbAver=NbAver + ~check_bad;% add 1 for good data, 0 else |
---|
| 402 | end |
---|
| 403 | end |
---|
| 404 | MergeData.(VarName)(NbAver~=0)=MergeData.(VarName)(NbAver~=0)./NbAver(NbAver~=0);% take average of defined data at each point |
---|
| 405 | end |
---|
[89] | 406 | end |
---|
[670] | 407 | if isempty(FFName) |
---|
| 408 | FFName='FF'; |
---|
[89] | 409 | end |
---|
[670] | 410 | MergeData.(FFName)(NbAver~=0)=0;% flag to 1 undefined summed data |
---|
| 411 | MergeData.(FFName)(NbAver==0)=1;% flag to 1 undefined summed data |
---|
[89] | 412 | end |
---|
| 413 | end |
---|
[222] | 414 | |
---|
[670] | 415 | |
---|
[89] | 416 | |
---|