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