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