[169] | 1 | %'aver_stat': calculate field average, used with series.fig |
---|
| 2 | %------------------------------------------------------------------------ |
---|
| 3 | % function GUI_input=aver_stat(num_i1,num_i2,num_j1,num_j2,Series) |
---|
| 4 | % |
---|
| 5 | %OUTPUT |
---|
| 6 | % GUI_input=list of options in the GUI series.fig needed for the function |
---|
| 7 | % |
---|
| 8 | %INPUT: |
---|
| 9 | %num_i1: series of first indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ) |
---|
| 10 | %num_i2: series of second indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ) |
---|
| 11 | %num_j1: series of first indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ ) |
---|
| 12 | %num_j2: series of second indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ) |
---|
| 13 | %Series: Matlab structure containing information set by the series interface |
---|
| 14 | % |
---|
[27] | 15 | function GUI_input=aver_stat(num_i1,num_i2,num_j1,num_j2,Series) |
---|
| 16 | %---------------------------------------------------------------------- |
---|
| 17 | % --- make average on a series of files |
---|
| 18 | %---------------------------------------------------------------------- |
---|
| 19 | %INPUT: |
---|
| 20 | %num_i1: series of first indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ) |
---|
| 21 | %num_i2: series of second indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ) |
---|
| 22 | %num_j1: series of first indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ ) |
---|
| 23 | %num_j2: series of second indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ) |
---|
| 24 | %OTHER INPUTS given by the structure Series |
---|
| 25 | % Series.Time: |
---|
| 26 | % Series.GeometryCalib:%requests for the visibility of input windows in the GUI series (activated directly by the selection in the menu ACTION) |
---|
| 27 | if ~exist('num_i1','var') |
---|
| 28 | GUI_input={'RootPath';'two';...%nbre of possible input series (options 'on'/'two'/'many', default:'one') |
---|
| 29 | 'SubDir';'on';... % subdirectory of derived files (PIV fields), ('on' by default) |
---|
| 30 | 'RootFile';'on';... %root input file name ('on' by default) |
---|
| 31 | 'FileExt';'on';... %input file extension ('on' by default) |
---|
| 32 | 'NomType';'on';...%type of file indexing ('on' by default) |
---|
| 33 | 'NbSlice';'on'; ...%nbre of slices ('off' by default) |
---|
| 34 | 'VelTypeMenu';'two';...% menu for selecting the velocity type (options 'off'/'one'/'two', 'off' by default) |
---|
| 35 | 'FieldMenu';'two';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default) |
---|
| 36 | 'CoordType'; 'on';...%can use a transform function |
---|
| 37 | 'GetObject';'on';...%can use projection object(option 'off'/'one'/'two', |
---|
| 38 | %'GetMask';'on'...%can use mask option |
---|
| 39 | %'PARAMETER'; %options: name of the user defined parameter',repeat a line for each parameter |
---|
| 40 | ''}; |
---|
| 41 | return |
---|
| 42 | end |
---|
| 43 | |
---|
| 44 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 45 | hseries=guidata(Series.hseries);%handles of the GUI series |
---|
| 46 | WaitbarPos=get(hseries.waitbar_frame,'Position'); |
---|
| 47 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
[41] | 48 | |
---|
| 49 | %projection object |
---|
| 50 | test_object=get(hseries.GetObject,'Value'); |
---|
| 51 | if test_object%isfield(Series,'sethandles') |
---|
[76] | 52 | hset_object=findobj(allchild(0),'tag','set_object'); |
---|
[41] | 53 | ProjObject=read_set_object(guidata(hset_object)); |
---|
| 54 | %answeryes=questdlg({['field series projected on ' Series.ProjObject.Style]}); |
---|
| 55 | answeryes=msgbox_uvmat('INPUT_Y-N',['field series projected on ' ProjObject.Style ' before averaging']); |
---|
| 56 | if ~isequal(answeryes,'Yes') |
---|
| 57 | return |
---|
| 58 | end |
---|
| 59 | end |
---|
| 60 | |
---|
[27] | 61 | %root input file and type |
---|
| 62 | if ~iscell(Series.RootPath)% case of a single input field series |
---|
| 63 | num_i1={num_i1};num_j1={num_j1};num_i2={num_i2};num_j2={num_j2}; |
---|
| 64 | RootPath={Series.RootPath}; |
---|
| 65 | RootFile={Series.RootFile}; |
---|
| 66 | SubDir={Series.SubDir}; |
---|
| 67 | FileExt={Series.FileExt}; |
---|
| 68 | NomType={Series.NomType}; |
---|
| 69 | else |
---|
| 70 | RootPath=Series.RootPath; |
---|
| 71 | RootFile=Series.RootFile; |
---|
| 72 | SubDir=Series.SubDir; |
---|
| 73 | NomType=Series.NomType; |
---|
| 74 | FileExt=Series.FileExt; |
---|
| 75 | end |
---|
| 76 | ext=FileExt{1}; |
---|
| 77 | form=imformats(ext([2:end]));%test valid Matlab image formats |
---|
| 78 | testima=0; |
---|
| 79 | if ~isempty(form)||isequal(lower(ext),'.avi')||isequal(lower(ext),'.vol') |
---|
| 80 | testima(1)=1; |
---|
| 81 | end |
---|
| 82 | if length(FileExt)>=2 |
---|
| 83 | ext_1=FileExt{2}; |
---|
| 84 | form=imformats(ext_1([2:end]));%test valid Matlab image formats |
---|
| 85 | if ~isempty(form)||isequal(lower(ext_1),'.avi')||isequal(lower(ext_1),'.vol') |
---|
| 86 | testima(2)=1; |
---|
| 87 | end |
---|
| 88 | if testima(2)~=testima(1) |
---|
| 89 | msgbox_uvmat('ERROR','images and netcdf files cannot be compared') |
---|
| 90 | return |
---|
| 91 | end |
---|
| 92 | end |
---|
| 93 | |
---|
| 94 | %Number of input series: this function accepts two input file series at most (then it operates on the difference of fields) |
---|
| 95 | nbview=length(RootPath); |
---|
| 96 | if nbview>2 |
---|
| 97 | RootPath=RootPath(1:2); |
---|
| 98 | set(hseries.RootPath,'String',RootPath) |
---|
| 99 | SubDir=SubDir(1:2); |
---|
| 100 | set(hseries.SubDir,'String',SubDir) |
---|
| 101 | RootFile=RootFile(1:2); |
---|
| 102 | set(hseries.RootFile,'String',RootFile) |
---|
| 103 | NomType=NomType(1:2); |
---|
| 104 | FileExt=FileExt(1:2); |
---|
| 105 | set(hseries.FileExt,'String',FileExt) |
---|
| 106 | nbview=2; |
---|
| 107 | end |
---|
[43] | 108 | |
---|
| 109 | %determine image type |
---|
[27] | 110 | hhh=which('mmreader'); |
---|
| 111 | for iview=1:nbview |
---|
[43] | 112 | if isequal(FileExt{iview},'.nc')||isequal(FileExt{iview},'.cdf') |
---|
| 113 | FileType{iview}='netcdf'; |
---|
| 114 | elseif isequal(lower(FileExt{iview}),'.avi') |
---|
| 115 | if ~isequal(hhh,'')&& mmreader.isPlatformSupported() |
---|
[27] | 116 | MovieObject{iview}=mmreader(fullfile(RootPath{iview},[RootFile{iview} FileExt{iview}])); |
---|
[43] | 117 | FileType{iview}='movie'; |
---|
| 118 | else |
---|
| 119 | FileType{iview}='avi'; |
---|
[27] | 120 | end |
---|
[43] | 121 | elseif isequal(lower(FileExt{iview}),'.vol') |
---|
| 122 | FileType{iview}='vol'; |
---|
| 123 | else |
---|
| 124 | form=imformats(FileExt{iview}(2:end)); |
---|
| 125 | if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab |
---|
| 126 | if isequal(NomType{iview},'*'); |
---|
| 127 | FileType{iview}='multimage'; |
---|
| 128 | else |
---|
| 129 | FileType{iview}='image'; |
---|
| 130 | end |
---|
| 131 | end |
---|
| 132 | end |
---|
[27] | 133 | end |
---|
| 134 | |
---|
| 135 | % number of slices |
---|
| 136 | NbSlice=str2num(get(hseries.NbSlice,'String')); |
---|
| 137 | if isempty(NbSlice) |
---|
| 138 | NbSlice=1; |
---|
| 139 | end |
---|
| 140 | NbSlice_name=num2str(NbSlice); |
---|
| 141 | |
---|
| 142 | % Field and velocity type (the same for the two views) |
---|
| 143 | Field_str=get(hseries.FieldMenu,'String'); |
---|
| 144 | FieldName=[]; %default |
---|
| 145 | testfield=get(hseries.FieldMenu,'Visible'); |
---|
| 146 | if isequal(testfield,'on') |
---|
| 147 | val=get(hseries.FieldMenu,'Value'); |
---|
| 148 | FieldName=Field_str(val);%the same set of fields for all views |
---|
| 149 | if isequal(FieldName,{'get_field...'}) |
---|
| 150 | hget_field=findobj(allchild(0),'name','get_field');%find the get_field... GUI |
---|
| 151 | if length(hget_field)>1 |
---|
| 152 | delete(hget_field(2:end)) |
---|
| 153 | elseif isempty(hget_field) |
---|
| 154 | filename=... |
---|
| 155 | name_generator(fullfile(RootPath{1},RootFile{1}),num_i1{1}(1),num_j1{1}(1),FileExt{1},NomType{1},1,num_i2{1}(1),num_j2{1}(1),SubDir{1}); |
---|
| 156 | get_field(filename); |
---|
| 157 | return |
---|
| 158 | end |
---|
| 159 | %hhget_field=guidata(hget_field);%handles of GUI elements in get_field |
---|
| 160 | SubField=read_get_field(hget_field); %read the names of the variables to plot in the get_field GUI |
---|
| 161 | end |
---|
| 162 | end |
---|
| 163 | %detect whether the two files are 'images' or 'netcdf' |
---|
[43] | 164 | % testima=0; |
---|
| 165 | % testvol=0; |
---|
[27] | 166 | testcivx=0; |
---|
[43] | 167 | % testnc=0; |
---|
[27] | 168 | FileExt=get(hseries.FileExt,'String'); |
---|
| 169 | % test_movie=0; |
---|
[43] | 170 | % for iview=1:nbview |
---|
| 171 | % ext=FileExt{iview}; |
---|
| 172 | % form=imformats(ext([2:end])); |
---|
| 173 | % if isequal(lower(ext),'.vol') |
---|
| 174 | % testvol=testvol+1; |
---|
| 175 | % elseif ~isempty(form)||isequal(lower(ext),'.avi')% if the extension corresponds to an image format recognized by Matlab |
---|
| 176 | % testima=testima+1; |
---|
| 177 | % elseif isequal(ext,'.nc') |
---|
| 178 | % testnc=testnc+1; |
---|
| 179 | % end |
---|
| 180 | % end |
---|
| 181 | % if testvol |
---|
| 182 | % msgbox_uvmat('ERROR','volume images not implemented yet') |
---|
| 183 | % return |
---|
| 184 | % end |
---|
| 185 | % if testnc~=nbview && testima~=nbview && testvol~=nbview |
---|
| 186 | % msgbox_uvmat('ERROR','compare two image series or two netcdf files with the same fields as input') |
---|
| 187 | % return |
---|
| 188 | % end |
---|
[27] | 189 | if ~isequal(FieldName,{'get_field...'}) |
---|
[43] | 190 | testcivx=isequal(FileType{1},'netcdf'); |
---|
[27] | 191 | end |
---|
[43] | 192 | % if ~isequal(FieldName,{'get_field...'}) |
---|
| 193 | % if isequal(FieldName,{''}) && ~testima |
---|
| 194 | % msgbox_uvmat('ERROR','an input field needs to be selected') |
---|
| 195 | % return |
---|
| 196 | % end |
---|
| 197 | % testcivx=testnc; |
---|
| 198 | % end |
---|
[27] | 199 | |
---|
| 200 | if testcivx |
---|
| 201 | VelType_str=get(hseries.VelTypeMenu,'String'); |
---|
| 202 | VelType_val=get(hseries.VelTypeMenu,'Value'); |
---|
| 203 | VelType{1}=VelType_str{VelType_val}; |
---|
| 204 | if nbview==2 |
---|
| 205 | VelType_str=get(hseries.VelTypeMenu_1,'String'); |
---|
| 206 | VelType_val=get(hseries.VelTypeMenu_1,'Value'); |
---|
| 207 | VelType{2}=VelType_str{VelType_val}; |
---|
| 208 | end |
---|
| 209 | end |
---|
| 210 | |
---|
| 211 | %Calibration data and timing: read the ImaDoc files |
---|
| 212 | mode=''; %default |
---|
| 213 | timecell={}; |
---|
| 214 | itime=0; |
---|
| 215 | NbSlice_calib={}; |
---|
| 216 | for iview=1:nbview%Loop on views |
---|
| 217 | XmlData{iview}=[];%default |
---|
| 218 | filebase{iview}=fullfile(RootPath{iview},RootFile{iview}); |
---|
| 219 | if exist([filebase{iview} '.xml'],'file') |
---|
| 220 | [XmlData{iview},error]=imadoc2struct([filebase{iview} '.xml']); |
---|
| 221 | if isfield(XmlData{iview},'Time') |
---|
| 222 | itime=itime+1; |
---|
| 223 | timecell{itime}=XmlData{iview}.Time; |
---|
| 224 | end |
---|
| 225 | if isfield(XmlData{iview},'GeometryCalib') && isfield(XmlData{iview}.GeometryCalib,'SliceCoord') |
---|
| 226 | NbSlice_calib{iview}=size(XmlData{iview}.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform |
---|
| 227 | if ~isequal(NbSlice_calib{iview},NbSlice_calib{1}) |
---|
| 228 | msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series'); |
---|
| 229 | end |
---|
| 230 | end |
---|
| 231 | elseif exist([filebase{iview} '.civ'],'file') |
---|
| 232 | [error,time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([filebase{iview} '.civ']); |
---|
| 233 | itime=itime+1; |
---|
| 234 | timecell{itime}=time; |
---|
| 235 | XmlData{iview}.Time=time; |
---|
| 236 | GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0]; |
---|
| 237 | GeometryCalib.Tx=0; |
---|
| 238 | GeometryCalib.Ty=0; |
---|
| 239 | GeometryCalib.Tz=1; |
---|
| 240 | GeometryCalib.dpx=1; |
---|
| 241 | GeometryCalib.dpy=1; |
---|
| 242 | GeometryCalib.sx=1; |
---|
| 243 | GeometryCalib.Cx=0; |
---|
| 244 | GeometryCalib.Cy=0; |
---|
| 245 | GeometryCalib.f=1; |
---|
| 246 | GeometryCalib.kappa1=0; |
---|
| 247 | GeometryCalib.CoordUnit='cm'; |
---|
| 248 | XmlData{iview}.GeometryCalib=GeometryCalib; |
---|
| 249 | if error==1 |
---|
| 250 | msgbox_uvmat('WARNING','inconsistent number of fields in the .civ file'); |
---|
| 251 | end |
---|
| 252 | end |
---|
| 253 | end |
---|
| 254 | |
---|
| 255 | %check coincidence in time |
---|
| 256 | multitime=0; |
---|
[55] | 257 | if isempty(timecell) |
---|
[27] | 258 | time=[]; |
---|
| 259 | elseif length(timecell)==1 |
---|
| 260 | time=timecell{1}; |
---|
| 261 | elseif length(timecell)>1 |
---|
| 262 | multitime=1; |
---|
| 263 | for icell=1:length(timecell) |
---|
| 264 | if ~isequal(size(timecell{icell}),size(timecell{1})) |
---|
| 265 | msgbox_uvmat('WARNING','inconsistent time array dimensions in ImaDoc fields, the time for the first series is used') |
---|
| 266 | time=timecell{1}; |
---|
| 267 | multitime=0; |
---|
| 268 | break |
---|
| 269 | end |
---|
| 270 | end |
---|
| 271 | end |
---|
| 272 | if multitime |
---|
| 273 | for icell=1:length(timecell) |
---|
| 274 | time(icell,:,:)=timecell{icell}; |
---|
| 275 | end |
---|
| 276 | diff_time=max(max(diff(time))); |
---|
| 277 | if diff_time>0 |
---|
| 278 | msgbox_uvmat('WARNING',['times of series differ by more than ' num2str(diff_time)]) |
---|
| 279 | end |
---|
| 280 | end |
---|
| 281 | if size(time,2) < num_i2{1}(end) || size(time,3) < num_j2{1}(end)% ime array absent or too short in ImaDoc xml file' |
---|
| 282 | time=[]; |
---|
| 283 | end |
---|
| 284 | |
---|
| 285 | % Root name of output files (TO GENERALISE FOR TWO INPUT SERIES) |
---|
[29] | 286 | subdir_result='aver_stat'; |
---|
| 287 | if ~exist(fullfile(RootPath{1},subdir_result),'dir') |
---|
| 288 | dircur=pwd; %record current working directory |
---|
| 289 | cd(RootPath{1})% goes to the iamge directory |
---|
| 290 | [m1,m2,m3]=mkdir(subdir_result); |
---|
| 291 | if ~isequal(m2,'') |
---|
| 292 | msgbox_uvmat('CONFIRMATION',m2);%error message for directory creation |
---|
[27] | 293 | end |
---|
[128] | 294 | [xx,msg2] = fileattrib(subdir_result,'+w','g'); %yield writing access (+w) to user group (g) |
---|
| 295 | if ~strcmp(msg2,'') |
---|
| 296 | msgbox_uvmat('ERROR',['pb of permission for ' subdir_result ': ' msg2])%error message for directory creation |
---|
| 297 | cd(curdir) |
---|
| 298 | return |
---|
| 299 | end |
---|
[29] | 300 | cd(dircur) %back to the initial working directory |
---|
[27] | 301 | end |
---|
[29] | 302 | filebase_out=filebase{1}; |
---|
[27] | 303 | NomTypeOut=nomtype2pair(NomType{1},num_i2{end}(end)-num_i1{1}(1),num_j2{end}(end)-num_j1{1}(1)); |
---|
| 304 | |
---|
| 305 | % coordinate transform or other user defined transform |
---|
[41] | 306 | transform_fct=[];%default |
---|
| 307 | if isfield(Series,'transform_fct') |
---|
| 308 | transform_fct=Series.transform_fct; |
---|
| 309 | end |
---|
[27] | 310 | |
---|
| 311 | %slice loop |
---|
| 312 | siz=size(num_i1{1}); |
---|
| 313 | lengthtot=siz(1)*siz(2); |
---|
| 314 | nbfield=floor(lengthtot/(siz(1)*NbSlice));%total number of i indexes (adjusted to an integer number of slices) |
---|
| 315 | nbfield_slice=nbfield*siz(1);% number of fields per slice |
---|
| 316 | |
---|
| 317 | for i_slice=1:NbSlice |
---|
| 318 | S=0; %initiate the image sum S |
---|
| 319 | nbfiles=0; |
---|
| 320 | nbmissing=0; |
---|
| 321 | %averaging loop |
---|
| 322 | for ifile=i_slice:NbSlice:lengthtot |
---|
| 323 | stopstate=get(hseries.RUN,'BusyAction'); |
---|
| 324 | if isequal(stopstate,'queue') % enable STOP command |
---|
| 325 | update_waitbar(hseries.waitbar,WaitbarPos,ifile/lengthtot) |
---|
| 326 | for iview=1:nbview |
---|
| 327 | [filename]=... |
---|
| 328 | name_generator(filebase{iview},num_i1{iview}(ifile),num_j1{iview}(ifile),FileExt{iview},NomType{iview},1,num_i2{iview}(ifile),num_j2{iview}(ifile),SubDir{iview}); |
---|
[43] | 329 | if ~isequal(FileType{iview},'netcdf') |
---|
[27] | 330 | Data{iview}.ListVarName={'A'}; |
---|
| 331 | Data{iview}.AName='image'; |
---|
[43] | 332 | switch FileType{iview} |
---|
| 333 | case 'movie' |
---|
| 334 | A=read(MovieObject{iview},num_i1{iview}(ifile)); |
---|
| 335 | case 'avi' |
---|
| 336 | mov=aviread(filename,num_i1{iview}(ifile)); |
---|
| 337 | A=frame2im(mov(1)); |
---|
| 338 | case 'vol' |
---|
| 339 | A=imread(filename); |
---|
| 340 | case 'multimage' |
---|
| 341 | A=imread(filename,num_i1{iview}(ifile)); |
---|
| 342 | case 'image' |
---|
| 343 | A=imread(filename); |
---|
| 344 | end |
---|
[107] | 345 | Data{iview}.ListVarName={'AY','AX','A'}; % |
---|
[43] | 346 | Atype{iview}=class(A); |
---|
| 347 | npy=size(A,1); |
---|
| 348 | npx=size(A,2); |
---|
| 349 | nbcolor=size(A,3); |
---|
| 350 | if nbcolor==3 |
---|
[107] | 351 | Data{iview}.VarDimName={'AY','AX',{'AY','AX','rgb'}}; |
---|
[27] | 352 | else |
---|
[107] | 353 | Data{iview}.VarDimName={'AY','AX',{'AY','AX'}}; |
---|
[43] | 354 | end |
---|
[107] | 355 | Data{iview}.AY=[npy-0.5 0.5]; |
---|
| 356 | Data{iview}.AX=[0.5 npx-0.5]; |
---|
[43] | 357 | Data{iview}.A=double(A); |
---|
[158] | 358 | Data{iview}.CoordUnit='pixel'; |
---|
[27] | 359 | elseif testcivx |
---|
| 360 | [Data{iview},VelTypeOut]=read_civxdata(filename,FieldName,VelType); |
---|
| 361 | else |
---|
| 362 | [Data{iview},var_detect]=nc2struct(filename,SubField.ListVarName); %read the corresponding input data |
---|
| 363 | Data{iview}.VarAttribute=SubField.VarAttribute; |
---|
| 364 | end |
---|
| 365 | if isfield(Data{iview},'Txt') |
---|
| 366 | msgbox_uvmat('ERROR',['error of input reading: ' Data{iview}.Txt]) |
---|
| 367 | return |
---|
| 368 | end |
---|
| 369 | end |
---|
[190] | 370 | |
---|
[27] | 371 | % coordinate transform (or other user defined transform) |
---|
[41] | 372 | if ~isempty(transform_fct) |
---|
[27] | 373 | % z index |
---|
| 374 | if ~isempty(NbSlice_calib) |
---|
| 375 | Data{iview}.ZIndex=mod(num_i1{iview}(ifile)-1,NbSlice_calib{1})+1;%Zindex for phys transform |
---|
| 376 | end |
---|
| 377 | if nbview==2 |
---|
[41] | 378 | [Data{1},Data{2}]=transform_fct(Data{1},XmlData{1},Data{2},XmlData{2}); |
---|
[27] | 379 | if isempty(Data{2}) |
---|
| 380 | Data(2)=[]; |
---|
| 381 | end |
---|
| 382 | else |
---|
[80] | 383 | Data{1}=transform_fct(Data{1},XmlData{1}); |
---|
[27] | 384 | end |
---|
| 385 | end |
---|
| 386 | if testcivx |
---|
| 387 | Data{iview}=calc_field(FieldName,Data{iview});%calculate field (vort..) |
---|
| 388 | end |
---|
| 389 | if length(Data)==2 |
---|
| 390 | [Field,errormsg]=sub_field(Data{1},Data{2}); %substract the two fields |
---|
| 391 | if ~isempty(errormsg) |
---|
| 392 | msgbox_uvmat('ERROR',['error in aver_stat/sub_field:' errormsg]) |
---|
| 393 | return |
---|
| 394 | end |
---|
| 395 | else |
---|
| 396 | Field=Data{1}; |
---|
| 397 | end |
---|
[41] | 398 | if test_object |
---|
| 399 | [Field,errormsg]=proj_field(Field,ProjObject); |
---|
[27] | 400 | if ~isempty(errormsg) |
---|
| 401 | msgbox_uvmat('ERROR',['error in aver_stat/proj_field:' errormsg]) |
---|
| 402 | return |
---|
| 403 | end |
---|
| 404 | end |
---|
| 405 | nbfiles=nbfiles+1; |
---|
| 406 | if nbfiles==1 %first field |
---|
| 407 | time_1=[]; |
---|
| 408 | if isfield(Field,'Time') |
---|
| 409 | time_1=Field.Time(1); |
---|
| 410 | end |
---|
| 411 | DataMean=Field;%default |
---|
| 412 | else |
---|
| 413 | for ivar=1:length(Field.ListVarName) |
---|
| 414 | VarName=Field.ListVarName{ivar}; |
---|
| 415 | eval(['sizmean=size(DataMean.' VarName ');']); |
---|
| 416 | eval(['siz=size(Field.' VarName ');']); |
---|
| 417 | if ~isequal(siz,sizmean) |
---|
[43] | 418 | msgbox_uvmat('ERROR',['unequal size of input field ' VarName ', need to interpolate on a grid']) |
---|
| 419 | return |
---|
[27] | 420 | else |
---|
| 421 | eval(['DataMean.' VarName '=DataMean.' VarName '+ Field.' VarName ';']); % update the sum |
---|
| 422 | end |
---|
| 423 | end |
---|
| 424 | end |
---|
| 425 | end |
---|
| 426 | end %end averaging loop |
---|
| 427 | for ivar=1:length(Field.ListVarName) |
---|
| 428 | VarName=Field.ListVarName{ivar}; |
---|
| 429 | eval(['DataMean.' VarName '=DataMean.' VarName '/nbfiles;']); % normalize the mean |
---|
| 430 | end |
---|
| 431 | if nbmissing~=0 |
---|
| 432 | msgbox_uvmat('WARNING',[num2str(nbmissing) ' input files are missing or skipted']) |
---|
| 433 | end |
---|
| 434 | if isempty(time) % time read from files prevails |
---|
| 435 | time_end=[]; |
---|
| 436 | if isfield(Field,'Time') |
---|
| 437 | time_end=Field.Time(1);%last time read |
---|
| 438 | if ~isempty(time_1) |
---|
| 439 | DataMean.Time=time_1; |
---|
| 440 | DataMean.Time_end=time_end; |
---|
| 441 | end |
---|
| 442 | end |
---|
| 443 | else % time from ImaDoc prevails |
---|
| 444 | DataMean.Time=time(1,num_i1{1}(1),num_j1{1}(1)); |
---|
| 445 | DataMean.Time_end=time(end,num_i1{end}(end),num_j1{end}(end)); |
---|
| 446 | end |
---|
[190] | 447 | |
---|
[27] | 448 | %writing the result file |
---|
| 449 | if testima |
---|
[29] | 450 | [filemean]=name_generator(filebase_out,num_i1{1}(1),num_j1{1}(1),'.png',NomTypeOut,1,num_i2{end}(end),num_j2{end}(end),subdir_result); |
---|
[27] | 451 | if exist(filemean,'file') |
---|
| 452 | backupfile=filemean; |
---|
| 453 | testexist=2; |
---|
| 454 | while testexist==2 |
---|
| 455 | backupfile=[backupfile(1:end-4) '~.png']; |
---|
| 456 | testexist=exist(backupfile,'file'); |
---|
| 457 | end |
---|
| 458 | [success,message]=copyfile(filemean,backupfile);%make backup |
---|
| 459 | if ~isequal(success,1) |
---|
| 460 | msgbox_uvmat('ERROR',['previous file result ' filemean ' already exists, problem in backup']) |
---|
| 461 | return |
---|
| 462 | end |
---|
| 463 | end |
---|
| 464 | if isequal(Atype{1},'uint16') |
---|
| 465 | imwrite(uint16(DataMean.A),filemean,'BitDepth',16); |
---|
| 466 | else |
---|
| 467 | imwrite(uint8(DataMean.A),filemean,'BitDepth',8); |
---|
| 468 | end |
---|
| 469 | display([filemean ' written']); |
---|
[55] | 470 | else %case of netcdf input file , determine global attributes |
---|
[27] | 471 | DataMean.ListGlobalAttribute=[DataMean.ListGlobalAttribute {Series.Action}]; |
---|
| 472 | ActionKey='Action'; |
---|
| 473 | while isfield(DataMean,ActionKey) |
---|
| 474 | ActionKey=[ActionKey '_1']; |
---|
| 475 | end |
---|
| 476 | eval(['DataMean.' ActionKey '=Series.Action;']) |
---|
| 477 | DataMean.ListGlobalAttribute=[DataMean.ListGlobalAttribute {ActionKey}]; |
---|
| 478 | if isfield(DataMean,'Time') |
---|
| 479 | DataMean.ListGlobalAttribute=[DataMean.ListGlobalAttribute {'Time','Time_end'}]; |
---|
| 480 | end |
---|
[190] | 481 | filemean=name_generator(filebase_out,num_i1{1}(1),num_j1{1}(1),'.nc',NomTypeOut,1,num_i2{end}(end),num_j2{end}(end),subdir_result); |
---|
[27] | 482 | if exist(filemean,'file') |
---|
| 483 | backupfile=filemean; |
---|
| 484 | testexist=2; |
---|
| 485 | while testexist==2 |
---|
| 486 | backupfile=[backupfile(1:end-3) '~.nc']; |
---|
| 487 | testexist=exist(backupfile,'file'); |
---|
| 488 | end |
---|
| 489 | [success,message]=copyfile(filemean,backupfile);%make backup |
---|
| 490 | if ~isequal(success,1) |
---|
| 491 | msgbox_uvmat('ERROR',['previous file result ' filemean ' already exists, problem in backup']) |
---|
| 492 | display(['previous file result ' filemean ' already exists, problem in backup']) |
---|
| 493 | return |
---|
| 494 | end |
---|
| 495 | end |
---|
| 496 | errormsg=struct2nc(filemean,DataMean); %save result file |
---|
| 497 | if isempty(errormsg) |
---|
| 498 | display([filemean ' written']); |
---|
| 499 | else |
---|
| 500 | msgbox_uvmat('ERROR',['error in writting result file: ' errormsg]) |
---|
| 501 | display(errormsg) |
---|
| 502 | end |
---|
| 503 | end |
---|
| 504 | end |
---|
[55] | 505 | |
---|
[27] | 506 | hget_field=findobj(allchild(0),'name','get_field');%find the get_field... GUI |
---|
| 507 | delete(hget_field) |
---|
| 508 | uvmat(filemean) |
---|