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