[169] | 1 | %'time_series': extract a time series, used with series.fig |
---|
| 2 | %------------------------------------------------------------------------ |
---|
| 3 | % function GUI_input=time_series(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: |
---|
[27] | 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) |
---|
[169] | 13 | %Series: Matlab structure containing information set by the series interface |
---|
| 14 | % |
---|
| 15 | function GUI_input=time_series(num_i1,num_i2,num_j1,num_j2,Series) |
---|
[27] | 16 | |
---|
[330] | 17 | %% requests for the visibility of input windows in the GUI series (activated directly by the selection in the menu ACTION) |
---|
[27] | 18 | if ~exist('num_i1','var') |
---|
| 19 | GUI_input={'RootPath';'two';...%nbre of possible input series (options 'on'/'two'/'many', default:'one') |
---|
| 20 | 'SubDir';'on';... % subdirectory of derived files (PIV fields), ('on' by default) |
---|
| 21 | 'RootFile';'on';... %root input file name ('on' by default) |
---|
| 22 | 'FileExt';'on';... %input file extension ('on' by default) |
---|
| 23 | 'NomType';'on';...%type of file indexing ('on' by default) |
---|
| 24 | 'NbSlice';'on'; ...%nbre of slices ('off' by default) |
---|
| 25 | 'VelTypeMenu';'two';...% menu for selecting the velocity type (civ1,..) options 'off'/'one'/'two', 'off' by default) |
---|
| 26 | 'FieldMenu';'two';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default) |
---|
| 27 | 'CoordType';'on';...%can use a transform function 'off' by default |
---|
| 28 | 'GetObject';'on';...%can use projection object ,'off' by default |
---|
| 29 | %'GetMask';'on'...%can use mask option ,'off' by default |
---|
| 30 | %'PARAMETER'; options: name of the user defined parameter',repeat a line for each parameter |
---|
| 31 | ''}; |
---|
| 32 | return %exit the function |
---|
| 33 | end |
---|
| 34 | |
---|
| 35 | %------------------------------------------------------ |
---|
| 36 | hseries=guidata(Series.hseries);%handles in the GUI series |
---|
| 37 | WaitbarPos=get(hseries.waitbar_frame,'Position'); %position of the waitbar frame |
---|
| 38 | |
---|
[190] | 39 | %% projection object |
---|
[27] | 40 | test_object=get(hseries.GetObject,'Value'); |
---|
[41] | 41 | if test_object |
---|
[76] | 42 | hset_object=findobj(allchild(0),'tag','set_object'); |
---|
[41] | 43 | ProjObject=read_set_object(guidata(hset_object)); |
---|
| 44 | answeryes=msgbox_uvmat('INPUT_Y-N',['field series projected on ' ProjObject.Style]); |
---|
[27] | 45 | if ~isequal(answeryes,'Yes') |
---|
| 46 | return |
---|
| 47 | end |
---|
| 48 | else |
---|
| 49 | msgbox_uvmat('ERROR','a projection object is needed'); |
---|
| 50 | return |
---|
| 51 | end |
---|
| 52 | |
---|
[330] | 53 | %% root names: transform input to cell in case of a single input series |
---|
| 54 | if ischar(Series.RootPath) |
---|
| 55 | Series.RootPath={Series.RootPath}; |
---|
| 56 | Series.RootFile={Series.RootFile}; |
---|
| 57 | Series.SubDir={Series.SubDir}; |
---|
| 58 | Series.FileExt={Series.FileExt}; |
---|
| 59 | Series.NomType={Series.NomType}; |
---|
[27] | 60 | num_i1={num_i1}; |
---|
| 61 | num_i2={num_i2}; |
---|
| 62 | num_j1={num_j1}; |
---|
| 63 | num_j2={num_j2}; |
---|
| 64 | end |
---|
[330] | 65 | ext=Series.FileExt{1}; |
---|
| 66 | form=imformats(ext(2:end));%test valid Matlab image formats |
---|
[27] | 67 | nbfield=size(num_i1{1},1)*size(num_i1{1},2); %number of fields in the time series |
---|
| 68 | |
---|
[330] | 69 | %% determine image type |
---|
[27] | 70 | hhh=which('mmreader'); |
---|
[259] | 71 | testnetcdf=0; |
---|
[330] | 72 | nbview=length(Series.RootPath);%Number of input series: this function accepts only one or two input file series (sub_field is used in the latter case) |
---|
[27] | 73 | for iview=1:nbview |
---|
[330] | 74 | if isequal(Series.FileExt{iview},'.nc')||isequal(Series.FileExt{iview},'.cdf') |
---|
[44] | 75 | FileType{iview}='netcdf'; |
---|
[259] | 76 | testnetcdf=1; |
---|
[330] | 77 | elseif isequal(lower(Series.FileExt{iview}),'.avi') |
---|
| 78 | if ~isequal(hhh,'')%&& mmreader.isPlatformSupported() |
---|
| 79 | MovieObject{iview}=mmreader(fullfile(Series.RootPath{iview},[Series.RootFile{iview} Series.FileExt{iview}])); |
---|
[44] | 80 | FileType{iview}='movie'; |
---|
| 81 | else |
---|
| 82 | FileType{iview}='avi'; |
---|
[27] | 83 | end |
---|
[330] | 84 | elseif isequal(lower(Series.FileExt{iview}),'.vol') |
---|
[44] | 85 | FileType{iview}='vol'; |
---|
| 86 | else |
---|
[330] | 87 | form=imformats(Series.FileExt{iview}(2:end)); |
---|
[44] | 88 | if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab |
---|
[330] | 89 | if isequal(Series.NomType{iview},'*'); |
---|
[44] | 90 | FileType{iview}='multimage'; |
---|
| 91 | else |
---|
| 92 | FileType{iview}='image'; |
---|
| 93 | end |
---|
| 94 | end |
---|
| 95 | end |
---|
[27] | 96 | end |
---|
[330] | 97 | filebase{1}=fullfile(Series.RootPath{1},Series.RootFile{1}); |
---|
[27] | 98 | |
---|
[330] | 99 | %% number of slices |
---|
[340] | 100 | NbSlice=Series.NbSlice; |
---|
[27] | 101 | |
---|
[330] | 102 | %% Field and velocity type (the same for the two views) |
---|
[27] | 103 | if isfield(Series,'Field') |
---|
| 104 | FieldName=Series.Field;%the same set of fields for all views |
---|
| 105 | else |
---|
| 106 | FieldName={''}; |
---|
| 107 | end |
---|
[259] | 108 | if isequal(FieldName,{''}) && testnetcdf |
---|
| 109 | msgbox_uvmat('ERROR','A field must be defined as input') |
---|
| 110 | return |
---|
| 111 | end |
---|
[27] | 112 | if isequal(FieldName,{'get_field...'}) |
---|
| 113 | hget_field=findobj(allchild(0),'name','get_field');%find the get_field... GUI |
---|
| 114 | if numel(hget_field)>1 |
---|
| 115 | delete(hget_field(2:end)) % delete multiple occurerence of the GUI get_fioeld |
---|
| 116 | elseif isempty(hget_field) |
---|
[330] | 117 | filename=name_generator(filebase{1},num_i1{1}(1),num_j1{1}(1),Series.FileExt{1},Series.NomType{1},1,num_i2{1}(1),num_j2{1}(1),Series.SubDir{1}); |
---|
[27] | 118 | idetect(iview)=exist(filename,'file'); |
---|
| 119 | hget_field=get_field(filename); |
---|
| 120 | return |
---|
| 121 | end |
---|
[102] | 122 | SubField=read_get_field(hget_field); %read the names of the variables to plot in the get_field GUI |
---|
[27] | 123 | if isempty(SubField) |
---|
| 124 | delete(hget_field) |
---|
[330] | 125 | filename=name_generator(filebase{1},num_i1{1}(1),num_j1{1}(1),Series.FileExt{1},Series.NomType{1},1,num_i2{1}(1),num_j2{1}(1),Series.SubDir{1}); |
---|
[27] | 126 | hget_field=get_field(filename); |
---|
| 127 | SubField=read_get_field(hget_field); %read the names of the variables to plot in the get_field GUI |
---|
| 128 | end |
---|
| 129 | end |
---|
| 130 | |
---|
[330] | 131 | %% detect whether the two files are 'images' or 'netcdf' |
---|
[27] | 132 | testcivx=0; |
---|
[330] | 133 | % FileExt=get(hseries.FileExt,'String'); |
---|
[27] | 134 | if ~isequal(FieldName,{'get_field...'}) |
---|
[44] | 135 | testcivx=isequal(FileType{1},'netcdf'); |
---|
[27] | 136 | end |
---|
| 137 | VelType_str=get(hseries.VelTypeMenu,'String'); |
---|
| 138 | VelType_val=get(hseries.VelTypeMenu,'Value'); |
---|
| 139 | VelType{1}=VelType_str{VelType_val}; |
---|
| 140 | if nbview==2 |
---|
| 141 | VelType_str=get(hseries.VelTypeMenu_1,'String'); |
---|
| 142 | VelType_val=get(hseries.VelTypeMenu_1,'Value'); |
---|
| 143 | VelType{2}=VelType_str{VelType_val}; |
---|
| 144 | end |
---|
| 145 | |
---|
[190] | 146 | %% Calibration data and timing: read the ImaDoc files |
---|
[330] | 147 | % mode=''; %default |
---|
[27] | 148 | timecell={}; |
---|
| 149 | XmlData={}; |
---|
| 150 | itime=0; |
---|
| 151 | NbSlice_calib={}; |
---|
| 152 | for iview=1:nbview%Loop on views |
---|
| 153 | XmlData{iview}=[];%default |
---|
[330] | 154 | filebase{iview}=fullfile(Series.RootPath{iview},Series.RootFile{iview}); |
---|
[27] | 155 | if exist([filebase{iview} '.xml'],'file') |
---|
| 156 | [XmlData{iview},error]=imadoc2struct([filebase{iview} '.xml']); |
---|
| 157 | if isfield(XmlData{iview},'Time') |
---|
| 158 | itime=itime+1; |
---|
| 159 | timecell{itime}=XmlData{iview}.Time; |
---|
| 160 | end |
---|
| 161 | if isfield(XmlData{iview},'GeometryCalib') && isfield(XmlData{iview}.GeometryCalib,'SliceCoord') |
---|
| 162 | NbSlice_calib{iview}=size(XmlData{iview}.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform |
---|
| 163 | if ~isequal(NbSlice_calib{iview},NbSlice_calib{1}) |
---|
| 164 | msgbox_uvmat('WARNING','inconsistent number of Z indices for the field series'); |
---|
| 165 | end |
---|
| 166 | end |
---|
[330] | 167 | elseif exist([filebase{iview} '.civ'],'file')%old convention .civ text file |
---|
[27] | 168 | [error,time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([filebase{iview} '.civ']); |
---|
| 169 | itime=itime+1; |
---|
| 170 | timecell{itime}=time; |
---|
| 171 | XmlData{iview}.Time=time; |
---|
| 172 | GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0]; |
---|
| 173 | GeometryCalib.Tx=0; |
---|
| 174 | GeometryCalib.Ty=0; |
---|
| 175 | GeometryCalib.Tz=1; |
---|
| 176 | GeometryCalib.dpx=1; |
---|
| 177 | GeometryCalib.dpy=1; |
---|
| 178 | GeometryCalib.sx=1; |
---|
| 179 | GeometryCalib.Cx=0; |
---|
| 180 | GeometryCalib.Cy=0; |
---|
| 181 | GeometryCalib.f=1; |
---|
| 182 | GeometryCalib.kappa1=0; |
---|
| 183 | GeometryCalib.CoordUnit='cm'; |
---|
| 184 | XmlData{iview}.GeometryCalib=GeometryCalib; |
---|
| 185 | if error==1 |
---|
| 186 | msgbox_uvmat('WARNING','inconsistent number of fields in the .civ file'); |
---|
| 187 | end |
---|
| 188 | end |
---|
| 189 | end |
---|
[330] | 190 | time=[];%default |
---|
| 191 | if ~isempty(timecell) |
---|
| 192 | if numel(timecell{1})<nbfield |
---|
| 193 | msgbox_uvmat('WARNING','time array from ImaDoc to short') |
---|
| 194 | else |
---|
| 195 | time=timecell{1}; %time defined from ImaDoc file (image series) |
---|
| 196 | end |
---|
| 197 | end |
---|
[27] | 198 | |
---|
[190] | 199 | %% check coincidence in time |
---|
[330] | 200 | if length(timecell)>1 |
---|
| 201 | for icell=2:length(timecell) |
---|
| 202 | if isequal(size(timecell{icell}),size(time)) |
---|
| 203 | diff_time=max(abs(timecell{icell}-time)); |
---|
| 204 | if diff_time>0 |
---|
| 205 | msgbox_uvmat('WARNING',['times of series differ by more than ' num2str(diff_time)]) |
---|
| 206 | break |
---|
| 207 | end |
---|
| 208 | else |
---|
[38] | 209 | msgbox_uvmat('WARNING','inconsistent time array dimensions in ImaDoc fields, the time for the first series is used') |
---|
[27] | 210 | break |
---|
| 211 | end |
---|
| 212 | end |
---|
| 213 | end |
---|
[330] | 214 | if ~isempty(time) |
---|
| 215 | display(['time is read from ' filebase{iview} '.xml']) |
---|
[27] | 216 | end |
---|
| 217 | |
---|
[190] | 218 | %% Root name of output files (TO GENERALISE FOR TWO INPUT SERIES) |
---|
[41] | 219 | subdir_result='time_series'; |
---|
[330] | 220 | pathdir=fullfile(Series.RootPath{1},subdir_result); |
---|
[190] | 221 | while exist(pathdir,'dir') |
---|
[218] | 222 | subdir_result=[subdir_result '.0']; |
---|
[330] | 223 | pathdir=fullfile(Series.RootPath{1},subdir_result); |
---|
[41] | 224 | end |
---|
[190] | 225 | [m1,m2,m3]=mkdir(pathdir); |
---|
| 226 | if ~isequal(m2,'') |
---|
| 227 | msgbox_uvmat('CONFIRMATION',m2);%error message for directory creation |
---|
| 228 | end |
---|
| 229 | [xx,msg2] = fileattrib(pathdir,'+w','g'); %yield writing access (+w) to user group (g) |
---|
| 230 | if ~strcmp(msg2,'') |
---|
[218] | 231 | msgbox_uvmat('ERROR',['pb of permission for ' pathdir ': ' msg2])%error message for directory creation |
---|
[190] | 232 | return |
---|
| 233 | end |
---|
[41] | 234 | filebase_out=filebase{1}; |
---|
[330] | 235 | NomTypeOut=nomtype2pair(Series.NomType{1},num_i2{end}(end)-num_i1{1}(1),num_j2{end}(end)-num_j1{1}(1)); |
---|
[27] | 236 | |
---|
[190] | 237 | %% coordinate transform or other user defined transform |
---|
[41] | 238 | transform_fct=[];%default |
---|
| 239 | if isfield(Series,'transform_fct') |
---|
| 240 | transform_fct=Series.transform_fct; |
---|
| 241 | end |
---|
| 242 | |
---|
[190] | 243 | %% velocity type |
---|
[27] | 244 | VelType_str=get(hseries.VelTypeMenu,'String'); |
---|
| 245 | VelType_val=get(hseries.VelTypeMenu,'Value'); |
---|
| 246 | VelType{1}=VelType_str{VelType_val}; |
---|
| 247 | if nbview==2 |
---|
| 248 | VelType_str=get(hseries.VelTypeMenu_1,'String'); |
---|
| 249 | VelType_val=get(hseries.VelTypeMenu_1,'Value'); |
---|
| 250 | VelType{2}=VelType_str{VelType_val}; |
---|
| 251 | end |
---|
| 252 | |
---|
[190] | 253 | %% LOOP ON SLICES |
---|
[330] | 254 | nbmissing=0; %number of undetected files |
---|
[27] | 255 | for i_slice=1:NbSlice |
---|
[330] | 256 | dt=[]; |
---|
| 257 | %%%%%%%%%%%%%%%%%%%%%%%%%%%% LOOP ON FIELDS WITHIN A SLICE |
---|
| 258 | filecounter=0; |
---|
| 259 | for ifile=i_slice:NbSlice:nbfield |
---|
[27] | 260 | stopstate=get(hseries.RUN,'BusyAction'); |
---|
[330] | 261 | errormsg=''; |
---|
[27] | 262 | if isequal(stopstate,'queue')% enable STOP command |
---|
[330] | 263 | update_waitbar(hseries.waitbar,WaitbarPos,ifile/nbfield) % update the waitbar |
---|
| 264 | % loop on views (in case of multiple input series) |
---|
| 265 | for iview=1:nbview |
---|
| 266 | filename=name_generator(filebase{iview},... |
---|
| 267 | num_i1{iview}(ifile),num_j1{iview}(ifile),Series.FileExt{iview},Series.NomType{iview},1,num_i2{iview}(ifile),num_j2{iview}(ifile),Series.SubDir{iview}); |
---|
| 268 | if exist(filename,'file') |
---|
| 269 | try |
---|
| 270 | Data{iview}=[]; %default |
---|
| 271 | if ~isequal(FileType{iview},'netcdf') |
---|
| 272 | Data{iview}.ListVarName={'A'}; |
---|
| 273 | Data{iview}.AName='image'; |
---|
| 274 | switch FileType{iview} |
---|
| 275 | case 'movie' |
---|
| 276 | A=read(MovieObject{iview},num_i1{iview}(ifile)); |
---|
| 277 | case 'avi' |
---|
| 278 | mov=aviread(filename,num_i1{iview}(ifile)); |
---|
| 279 | A=frame2im(mov(1)); |
---|
| 280 | case 'vol' |
---|
| 281 | A=imread(filename); |
---|
| 282 | case 'multimage' |
---|
| 283 | A=imread(filename,num_i1{iview}(ifile)); |
---|
| 284 | case 'image' |
---|
| 285 | A=imread(filename); |
---|
| 286 | end |
---|
| 287 | Data{iview}.ListVarName={'AY','AX','A'}; % |
---|
| 288 | npy=size(A,1); |
---|
| 289 | npx=size(A,2); |
---|
| 290 | nbcolor=size(A,3); |
---|
| 291 | if nbcolor==3 |
---|
| 292 | Data{iview}.VarDimName={'AY','AX',{'AY','AX','rgb'}}; |
---|
| 293 | else |
---|
| 294 | Data{iview}.VarDimName={'AY','AX',{'AY','AX'}}; |
---|
| 295 | end |
---|
| 296 | Data{iview}.AY=[npy-0.5 0.5]; |
---|
| 297 | Data{iview}.AX=[0.5 npx-0.5]; |
---|
| 298 | Data{iview}.A=double(A); |
---|
| 299 | Data{iview}.CoordUnit='pixel'; |
---|
| 300 | elseif testcivx |
---|
| 301 | [Data{iview},VelTypeOut]=read_civxdata(filename,FieldName,VelType); |
---|
| 302 | if ~isequal(FieldName,{''}) |
---|
| 303 | Data{iview}=calc_field(FieldName,Data{iview});%calculate field (vort..) |
---|
| 304 | end |
---|
| 305 | else |
---|
| 306 | [Data{iview},var_detect]=nc2struct(filename,SubField.ListVarName); %read the corresponding input data |
---|
| 307 | Data{iview}.VarAttribute=SubField.VarAttribute; |
---|
| 308 | end |
---|
| 309 | if ~isempty(NbSlice_calib) % z index |
---|
| 310 | Data{iview}.ZIndex=mod(num_i1{iview}(ifile)-1,NbSlice_calib{1})+1; |
---|
| 311 | end |
---|
| 312 | catch ME |
---|
| 313 | errormsg=ME.message; |
---|
| 314 | end |
---|
[27] | 315 | else |
---|
[330] | 316 | errormsg=[filename ' is missing']; |
---|
[27] | 317 | end |
---|
[330] | 318 | if isempty(errormsg) |
---|
| 319 | % coordinate transform (or other user defined transform) |
---|
| 320 | if ~isempty(transform_fct) |
---|
| 321 | if nbview==2 |
---|
| 322 | [Data{1},Data{2}]=transform_fct(Data{1},XmlData{1},Data{2},XmlData{2}); |
---|
| 323 | if isempty(Data{2}) |
---|
| 324 | Data(2)=[]; |
---|
| 325 | end |
---|
| 326 | else |
---|
| 327 | Data{1}=transform_fct(Data{1},XmlData{1}); |
---|
| 328 | end |
---|
| 329 | end |
---|
| 330 | if length(Data)==2 |
---|
| 331 | [Field,errormsg]=sub_field(Data{1},Data{2}); %substract the two fields |
---|
| 332 | else |
---|
| 333 | Field=Data{1}; |
---|
| 334 | end |
---|
| 335 | if test_object |
---|
| 336 | [Field,errormsg]=proj_field(Field,ProjObject); |
---|
| 337 | end |
---|
[27] | 338 | end |
---|
[330] | 339 | filecounter=filecounter+1; |
---|
| 340 | |
---|
| 341 | % initiate the time series at the first iteration |
---|
| 342 | if filecounter==1 |
---|
| 343 | % stop program if the first field reading is in error |
---|
| 344 | if ~isempty(errormsg) |
---|
| 345 | msgbox_uvmat('ERROR',['error in time_series/sub_field:' errormsg]) |
---|
| 346 | return |
---|
[27] | 347 | end |
---|
| 348 | RecordData=Field;%default |
---|
[330] | 349 | RecordData.NbDim=Field.NbDim+1; %add the time dimension for plots |
---|
[27] | 350 | nbvar=length(Field.ListVarName); |
---|
| 351 | if nbvar==0 |
---|
| 352 | msgbox_uvmat('ERROR','no input variable selected in get_field') |
---|
| 353 | return |
---|
| 354 | end |
---|
| 355 | testsum=2*ones(1,nbvar);%initiate flag for action on each variable |
---|
[330] | 356 | if isfield(Field,'VarAttribute') % look for coordinate and flag variables |
---|
[27] | 357 | for ivar=1:nbvar |
---|
| 358 | if length(Field.VarAttribute)>=ivar && isfield(Field.VarAttribute{ivar},'Role') |
---|
| 359 | var_role=Field.VarAttribute{ivar}.Role;%'role' of the variable |
---|
| 360 | if isequal(var_role,'errorflag') |
---|
| 361 | msgbox_uvmat('ERROR','do not handle error flags in time series') |
---|
[330] | 362 | return |
---|
[27] | 363 | end |
---|
[330] | 364 | if isequal(var_role,'warnflag') |
---|
| 365 | testsum(ivar)=0; % not recorded variable |
---|
[27] | 366 | eval(['RecordData=rmfield(RecordData,''' Field.ListVarName{ivar} ''');']);%remove variable |
---|
[330] | 367 | end |
---|
[27] | 368 | if isequal(var_role,'coord_x')| isequal(var_role,'coord_y')|... |
---|
[330] | 369 | isequal(var_role,'coord_z')|isequal(var_role,'coord') |
---|
[27] | 370 | testsum(ivar)=1; %constant coordinates, record without time evolution |
---|
| 371 | end |
---|
| 372 | end |
---|
[107] | 373 | % check whether the variable ivar is a dimension variable |
---|
| 374 | DimCell=Field.VarDimName{ivar}; |
---|
| 375 | if ischar(DimCell) |
---|
| 376 | DimCell={DimCell}; |
---|
| 377 | end |
---|
| 378 | if numel(DimCell)==1 && isequal(Field.ListVarName{ivar},DimCell{1})%detect dimension variables |
---|
[330] | 379 | testsum(ivar)=1; |
---|
[107] | 380 | end |
---|
[27] | 381 | end |
---|
| 382 | end |
---|
| 383 | for ivar=1:nbvar |
---|
[330] | 384 | if testsum(ivar)==2 |
---|
[27] | 385 | eval(['RecordData.' Field.ListVarName{ivar} '=[];']) |
---|
| 386 | end |
---|
| 387 | end |
---|
| 388 | RecordData.ListVarName=[{'Time'} RecordData.ListVarName]; |
---|
| 389 | end |
---|
[330] | 390 | |
---|
| 391 | % add data to the current field |
---|
[27] | 392 | for ivar=1:length(Field.ListVarName) |
---|
| 393 | VarName=Field.ListVarName{ivar}; |
---|
[330] | 394 | VarVal=Field.(VarName); |
---|
| 395 | if testsum(ivar)==2% test for recorded variable |
---|
| 396 | if isempty(errormsg) |
---|
| 397 | if isequal(ProjObject.ProjMode,'inside')% take the average in the domain for 'inside' mode |
---|
| 398 | if isempty(VarVal) |
---|
| 399 | msgbox_uvmat('ERROR',['empty result at frame index ' num2str(num_i1{iview}(ifile))]) |
---|
| 400 | return |
---|
| 401 | end |
---|
| 402 | VarVal=mean(VarVal,1); |
---|
[27] | 403 | end |
---|
[330] | 404 | VarVal=shiftdim(VarVal,-1); %shift dimension |
---|
| 405 | RecordData.(VarName)=cat(1,RecordData.(VarName),VarVal);%concanete the current field to the time series |
---|
| 406 | else |
---|
| 407 | RecordData.(VarName)=cat(1,RecordData.(VarName),0);% put each variable to 0 in case of input reading error |
---|
[27] | 408 | end |
---|
| 409 | elseif testsum(ivar)==1% variable representing fixed coordinates |
---|
| 410 | eval(['VarInit=RecordData.' VarName ';']); |
---|
[330] | 411 | if isempty(errormsg) && ~isequal(VarVal,VarInit) |
---|
[27] | 412 | msgbox_uvmat('ERROR',['time series requires constant coordinates ' VarName]) |
---|
| 413 | return |
---|
| 414 | end |
---|
[330] | 415 | end |
---|
[27] | 416 | end |
---|
[330] | 417 | |
---|
| 418 | % record the time: |
---|
[27] | 419 | if isempty(time)% time read in ncfiles |
---|
[330] | 420 | if isfield(Field,'Time') |
---|
| 421 | RecordData.Time(filecounter,1)=Field.Time; |
---|
| 422 | else |
---|
| 423 | RecordData.Time(filecounter,1)=ifile;%default |
---|
| 424 | end |
---|
[27] | 425 | else % time from ImaDoc prevails |
---|
[330] | 426 | RecordData.Time(filecounter,1)=(time(1,num_i1{1}(ifile),num_j1{1}(ifile))+time(end,num_i2{end}(ifile),num_j2{end}(ifile)))/2; |
---|
[27] | 427 | end |
---|
[330] | 428 | |
---|
| 429 | % record the number of missing input fields |
---|
| 430 | if ~isempty(errormsg) |
---|
| 431 | nbmissing=nbmissing+1; |
---|
| 432 | display(['ifile=' num2str(ifile) ':' errormsg]) |
---|
| 433 | end |
---|
[27] | 434 | end |
---|
| 435 | end |
---|
| 436 | end |
---|
[330] | 437 | %%%%%%% END OF LOOP WITHIN A SLICE |
---|
| 438 | |
---|
[27] | 439 | %remove time for global attributes if exists |
---|
[330] | 440 | for iattr=1:numel(RecordData.ListGlobalAttribute) |
---|
[27] | 441 | if strcmp(RecordData.ListGlobalAttribute{iattr},'Time') |
---|
| 442 | RecordData.ListGlobalAttribute(iattr)=[]; |
---|
| 443 | break |
---|
| 444 | end |
---|
| 445 | end |
---|
| 446 | for ivar=1:numel(RecordData.ListVarName) |
---|
| 447 | VarName=RecordData.ListVarName{ivar}; |
---|
| 448 | eval(['RecordData.' VarName '=squeeze(RecordData.' VarName ');']) %remove singletons |
---|
| 449 | end |
---|
[330] | 450 | |
---|
| 451 | % add time dimension |
---|
| 452 | for ivar=1:length(Field.ListVarName) |
---|
| 453 | DimCell=Field.VarDimName(ivar); |
---|
| 454 | if testsum(ivar)==2%variable used as time series |
---|
| 455 | RecordData.VarDimName{ivar}=[{'Time'} DimCell]; |
---|
| 456 | elseif testsum(ivar)==1 |
---|
| 457 | RecordData.VarDimName{ivar}=DimCell; |
---|
[27] | 458 | end |
---|
[330] | 459 | end |
---|
[27] | 460 | indexremove=find(~testsum); |
---|
| 461 | if ~isempty(indexremove) |
---|
| 462 | RecordData.ListVarName(1+indexremove)=[]; |
---|
| 463 | RecordData.VarDimName(indexremove)=[]; |
---|
[330] | 464 | if isfield(RecordData,'Role') && ~isempty(RecordData.Role{1})%generaliser aus autres attributs |
---|
[27] | 465 | RecordData.Role(1+indexremove)=[]; |
---|
| 466 | end |
---|
| 467 | end |
---|
[330] | 468 | |
---|
[27] | 469 | %shift variable attributes |
---|
| 470 | if isfield(RecordData,'VarAttribute') |
---|
| 471 | RecordData.VarAttribute=[{[]} RecordData.VarAttribute]; |
---|
[330] | 472 | end |
---|
[27] | 473 | RecordData.VarDimName=[{'Time'} RecordData.VarDimName]; |
---|
| 474 | RecordData.Action=Series.Action;%name of the processing programme |
---|
[330] | 475 | test_time=diff(RecordData.Time)>0;% test that the readed time is increasing (not constant) |
---|
| 476 | if ~test_time |
---|
| 477 | RecordData.Time=[1:filecounter]; |
---|
| 478 | end |
---|
[107] | 479 | |
---|
[330] | 480 | % display nbmissing |
---|
| 481 | if ~isequal(nbmissing,0) |
---|
| 482 | msgbox_uvmat('WARNING',[num2str(nbmissing) ' files skipped: missing files or bad input, see command window display']) |
---|
| 483 | end |
---|
| 484 | |
---|
[27] | 485 | %name of result file |
---|
| 486 | [filemean]=... |
---|
[330] | 487 | name_generator(filebase_out,num_i1{1}(i_slice),num_j1{1}(i_slice),'.nc','_i1-i2_j1-j2',1,num_i2{end}(ifile),num_j2{end}(ifile),subdir_result); |
---|
[27] | 488 | errormsg=struct2nc(filemean,RecordData); %save result file |
---|
| 489 | if isempty(errormsg) |
---|
| 490 | display([filemean ' written']) |
---|
| 491 | else |
---|
[259] | 492 | msgbox_uvmat('ERROR',['error in Series/struct2nc: ' errormsg]) |
---|
[27] | 493 | end |
---|
| 494 | end |
---|
[107] | 495 | |
---|
[330] | 496 | %% plot the time series (the last one in case of multislices) |
---|
[27] | 497 | figure |
---|
| 498 | haxes=axes; |
---|
[330] | 499 | plot_field(RecordData,haxes) |
---|
[27] | 500 | |
---|
[330] | 501 | %% display the result file using the GUI get_field |
---|
[27] | 502 | hget_field=findobj(allchild(0),'name','get_field'); |
---|
| 503 | if ~isempty(hget_field) |
---|
| 504 | delete(hget_field) |
---|
| 505 | end |
---|
| 506 | get_field(filemean,RecordData) |
---|
| 507 | |
---|
[330] | 508 | %------------------------------------------------------------------------ |
---|
[27] | 509 | % --- Executes on selection change in CoordType. |
---|
| 510 | function CoordType_Callback(hObject, eventdata, handles) |
---|
[330] | 511 | %------------------------------------------------------------------------ |
---|
[27] | 512 | menu_str=get(handles.CoordType,'String'); |
---|
| 513 | ind_coord=get(handles.CoordType,'Value'); |
---|
| 514 | coord_option=menu_str{ind_coord}; |
---|
| 515 | if isequal(coord_option,'more...'); |
---|
| 516 | fct_name=''; |
---|
| 517 | if exist('./TMP/current_usr_fct.mat','file')% if a file is found |
---|
| 518 | h=load('./TMP/current_usr_fct.mat'); |
---|
| 519 | if isfield(h,'fct_name'); |
---|
| 520 | fct_name=h.fct_name; |
---|
| 521 | end |
---|
| 522 | end |
---|
| 523 | prompt = {'Enter the name of the transform function'}; |
---|
| 524 | dlg_title = 'user defined transform'; |
---|
| 525 | num_lines= 1; |
---|
| 526 | [FileName, PathName, filterindex] = uigetfile( ... |
---|
| 527 | {'*.m', ' (*.m)'; |
---|
| 528 | '*.m', '.m files '; ... |
---|
| 529 | '*.*', 'All Files (*.*)'}, ... |
---|
| 530 | 'Pick a file', fct_name); |
---|
| 531 | fct_name=fullfile(PathName,FileName); |
---|
| 532 | addpath(PathName);%add the path to the selected fct |
---|
| 533 | [errormsg,date_str]=check_functions;%check whether new functions can oversed the uvmat package A UTILISER |
---|
| 534 | if ~exist(fct_name,'file') |
---|
| 535 | warndlg(['image procesing fct ' fct_name ' not found']) |
---|
| 536 | else |
---|
| 537 | transform=FileName(1:end-2);% |
---|
| 538 | update_menu(handles.CoordType,transform)%add the selected fct to the menu |
---|
| 539 | % set(handles.mouse_coord,'String',menu([1:end-1])')%update the mouse coord menu |
---|
| 540 | %save ('./TMP/current_usr_fct.mat','fct_name'); |
---|
| 541 | end |
---|
| 542 | end |
---|
| 543 | ind_coord=get(handles.CoordType,'Value'); |
---|
| 544 | |
---|
| 545 | %--------------------------------------------------------------------- |
---|
[44] | 546 | % % --- Executes on selection change in ProjObject. |
---|
| 547 | % function ProjObject_Callback(hObject, eventdata, handles) |
---|
| 548 | % |
---|
| 549 | % list_object=get(handles.ProjObject,'String'); |
---|
| 550 | % index=get(handles.ProjObject,'Value'); |
---|
| 551 | % hseries=get(handles.ProjObject,'Parent'); |
---|
| 552 | % SeriesData=get(hseries,'UserData'); |
---|
| 553 | % Obj=SeriesData.ProjObject{index}; |
---|
| 554 | % [SeriesData.hset_object,SeriesData.sethandles]=set_object(SeriesData.ProjObject{index}); |
---|
| 555 | % set(hseries,'UserData',SeriesData); |
---|
[27] | 556 | |
---|