source: trunk/src/series.m @ 460

Last change on this file since 460 was 460, checked in by sommeria, 12 years ago

cleaning and bugs corrected

File size: 89.5 KB
RevLine 
[2]1%'series': master function associated to the GUI series.m for analysis field series 
2%------------------------------------------------------------------------
3% function varargout = series(varargin)
4% associated with the GUI series.fig
5%
6%INPUT
7% param: structure with input parameters (link with the GUI uvmat)
[446]8%      .menu_coord_str: string for the TransformName (menu for coordinate transforms)
9%      .menu_coord_val: value for TransformName (menu for coordinate transforms)
[2]10%      .FileName: input file name
11%      .FileName_1: second input file name
12%      .list_field: menu of input fields
13%      .index_fields: chosen index
14%      .civ1=0 or 1, .interp1,  ... : input civ field type
15%
16%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
17%  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
18%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
19%     This file is part of the toolbox UVMAT.
20%
21%     UVMAT is free software; you can redistribute it and/or modify
22%     it under the terms of the GNU General Public License as published by
23%     the Free Software Foundation; either version 2 of the License, or
24%     (at your option) any later version.
25%
26%     UVMAT is distributed in the hope that it will be useful,
27%     but WITHOUT ANY WARRANTY; without even the implied warranty of
28%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29%     GNU General Public License (file UVMAT/COPYING.txt) for more details.
30%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
31
[408]32%------------------------------------------------------------------------
33%------------------------------------------------------------------------
34%  I - MAIN FUNCTION series
35%------------------------------------------------------------------------
36%------------------------------------------------------------------------
[2]37function varargout = series(varargin)
38
39% Begin initialization code - DO NOT EDIT
40gui_Singleton = 1;
41gui_State = struct('gui_Name',       mfilename, ...
42                   'gui_Singleton',  gui_Singleton, ...
43                   'gui_OpeningFcn', @series_OpeningFcn, ...
44                   'gui_OutputFcn',  @series_OutputFcn, ...
45                   'gui_LayoutFcn',  [] , ...
46                   'gui_Callback',   []);
47if nargin && ischar(varargin{1})
48    gui_State.gui_Callback = str2func(varargin{1});
49end
50
51if nargout
52    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
53else
54    gui_mainfcn(gui_State, varargin{:});
55end
56% End initialization code - DO NOT EDIT
57
58%--------------------------------------------------------------------------
59% --- Executes just before series is made visible.
60%--------------------------------------------------------------------------
61function series_OpeningFcn(hObject, eventdata, handles,param)
[205]62global nb_builtin_ACTION nb_builtin_transform
[2]63% Choose default command line output for series
64handles.output = hObject;
65% Update handles structure
66guidata(hObject, handles);
67%default initial parameters
[156]68drawnow
[244]69set(hObject,'Units','pixels')
[408]70set(handles.PairString,'ColumnEditable',logical(0))
71set(handles.PairString,'ColumnFormat',{'char'})
72set(handles.PairString,'ColumnWidth',{60})
73set(handles.PairString,'Data',{''})
[332]74set(hObject,'WindowButtonDownFcn',{'mouse_down'})%allows mouse action with right button (zoom for uicontrol display)
[2]75dir_perso=prefdir;
[205]76test_profil_perso=0;
[2]77profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
78if exist(profil_perso,'file')
79     h=load (profil_perso);
[460]80     if isfield(h,'MenuFile')
81          for ifile=1:min(length(h.MenuFile),5)
82              eval(['set(handles.MenuFile_' num2str(ifile) ',''Label'',h.MenuFile{ifile});'])
83%               eval(['set(handles.MenuFile_' num2str(ifile) '_1,''Label'',h.MenuFile{ifile});'])
84          end
85     end
86%      if isfield(h,'MenuFile')
87%           for ifile=1:min(length(h.MenuFile),5)
88%               eval(['set(handles.MenuFile_' num2str(ifile) ',''Label'',h.MenuFile{ifile});'])
89%                eval(['set(handles.MenuFile_' num2str(ifile) '_1,''Label'',h.MenuFile{ifile});'])
90%           end
91%       end
92     
[205]93     test_profil_perso=1;
[460]94%      if isfield(h,'MenuFile_1') && exist(h.MenuFile_1,'file')
95%           set(handles.MenuFile_1,'Label',h.MenuFile_1);
96%           set(handles.MenuFile_insert_1,'Label',h.MenuFile_1);
97%      end
98%      if isfield(h,'MenuFile_2')&& exist(h.MenuFile_2,'file')
99%           set(handles.MenuFile_2,'Label',h.MenuFile_2);
100%           set(handles.MenuFile_insert_2,'Label',h.MenuFile_2);
101%      end
102%      if isfield(h,'MenuFile_3')&& exist(h.MenuFile_3,'file')
103%           set(handles.MenuFile_3,'Label',h.MenuFile_3);
104%           set(handles.MenuFile_insert_3,'Label',h.MenuFile_3);
105%      end
106%      if isfield(h,'MenuFile_4')&& exist(h.MenuFile_4,'file')
107%           set(handles.MenuFile_4,'Label',h.MenuFile_4);
108%           set(handles.MenuFile_insert_4,'Label',h.MenuFile_4);
109%      end
110%      if isfield(h,'MenuFile_5')&& exist(h.MenuFile_5,'file')
111%           set(handles.MenuFile_5,'Label',h.MenuFile_5);
112%           set(handles.MenuFile_insert_5,'Label',h.MenuFile_5);
113%      end
[2]114end
115
116%check default input data
117if ~exist('param','var')
118    param=[]; %default
119end
120
[376]121%% file name and browser initialisation
[2]122if isfield(param,'menu_coord_str')
[446]123    set(handles.TransformName,'String',param.menu_coord_str)
[2]124end
125if isfield(param,'menu_coord_val')
[446]126    set(handles.TransformName,'Value',param.menu_coord_val);
[2]127else
[446]128     set(handles.TransformName,'Value',1);%default
[2]129end
130if isfield(param,'FileName')
131    if isfield(param,'FileName_1')
[408]132        display_file_name(handles,param.FileName_1,0)
133        display_file_name(handles,param.FileName,1)
[2]134    else
[408]135        display_file_name(handles,param.FileName,0)
[2]136    end
137end 
138
[376]139%% fields input initialisation
[2]140if isfield(param,'list_fields')&& isfield(param,'index_fields') &&~isempty(param.list_fields) &&~isempty(param.index_fields)
[446]141    set(handles.FieldName,'String',param.list_fields);% list menu fields
142    set(handles.FieldName,'Value',param.index_fields);% selected string index
[2]143    FieldCell{1}=param.list_fields{param.index_fields};
144end
[376]145
[446]146%loads the information stored in prefdir to initiate  the list of ActionName functions
[329]147fct_menu={'check_data_files';'aver_stat';'time_series';'merge_proj';'clean_civ_cmx'};
[38]148transform_menu={'';'phys';'px';'phys_polar'};
[205]149nb_builtin_ACTION=numel(fct_menu); %number of functions
[38]150nb_transform=numel(transform_menu);
[26]151[path_series,name,ext]=fileparts(which('series'));
[34]152path_series=fullfile(path_series,'series');%path of the function 'series'
[332]153addpath (path_series) ; %add the path to UVMAT, (useful in case of change of working directory after civ has been s opened in the working directory)
[276]154path_transform=fullfile(path_series,'transform_field');%path to the field transform functions
[38]155for ilist=1:length(fct_menu)
[2]156    fct_path{ilist,1}=path_series;%paths of the fuctions buil-in in 'series.m'
157end
[39]158
[376]159%% TRANSFORM menu: loads the information stored in prefdir to initiate  the list of field transform functions
[39]160menu_str={'';'phys';'px';'phys_polar'};
[205]161nb_builtin_transform=numel(menu_str); %number of functions
[39]162[path_uvmat,name,ext]=fileparts(which('uvmat'));
163addpath(fullfile(path_uvmat,'transform_field'))
164fct_handle{1,1}=[];
165testexist(1)=1;
166for ilist=2:length(menu_str)
167    if exist(menu_str{ilist},'file')
168        fct_handle{ilist,1}=str2func(menu_str{ilist});
169        testexist(ilist)=1;
170    else
171        testexist(ilist)=0;
172    end
[38]173end
[39]174rmpath(fullfile(path_uvmat,'transform_field'))
175
[376]176%% read the list of functions stored in the personal file 'uvmat_perso.mat' in prefdir
[205]177if test_profil_perso
[2]178    if isfield(h,'series_fct') && iscell(h.series_fct)
179         for ilist=1:length(h.series_fct)
180             [path,file]=fileparts(h.series_fct{ilist});
181             fct_path=[fct_path; {path}];%concatene the list of paths
[205]182             fct_menu=[fct_menu; {file}];
[2]183         end
184    end
[38]185    if isfield(h,'transform_fct') && iscell(h.transform_fct)
[39]186        for ilist=1:length(h.transform_fct);
[38]187             [path,file]=fileparts(h.transform_fct{ilist});
[39]188             addpath(path)
189             if exist(file,'file')
190                h_func=str2func(file);
191                testexist=[testexist 1];
192             else
193                h_func=[];
194                testexist=[testexist 0];
195             end
196             fct_handle=[fct_handle; {h_func}];%concatene the list of paths
197             rmpath(path)
198             menu_str=[menu_str; {file}];
199        end
[38]200    end
[2]201end
[38]202fct_menu=[fct_menu;{'more...'}];
[446]203set(handles.ActionName,'String',fct_menu)
204set(handles.ActionName,'UserData',fct_path)% store the list of path in UserData of ACTION
[39]205menu_str=menu_str(find(testexist));
206fct_handle=fct_handle(find(testexist));
207menu_str=[menu_str;{'more...'}];
[446]208set(handles.TransformName,'String',menu_str)
209set(handles.TransformName,'UserData',fct_handle)% store the list of path in UserData of ACTION
[39]210
[446]211% display the GUI for the default actionname 'check_data_files'
212ActionName_Callback(hObject, eventdata, handles)
[2]213
[408]214%------------------------------------------------------------------------
[2]215% --- Outputs from this function are returned to the command line.
216function varargout = series_OutputFcn(hObject, eventdata, handles)
[408]217%------------------------------------------------------------------------
[2]218% varargout  cell array for returning output args (see VARARGOUT);
219% hObject    handle to figure
220% eventdata  reserved - to be defined in a future version of MATLAB
221% handles    structure with handles and user data (see GUIDATA)
222% Get default command line output from handles structure
223varargout{1} = handles.output;
224
[408]225%------------------------------------------------------------------------
226%------------------------------------------------------------------------
227%  II - FUNCTIONS FOR INTRODUCING THE INPUT FILES
228% automatically sets the global properties when the rootfile name is introduced
[446]229% then activate the view-field actionname if selected
[408]230% it is activated either by clicking on the RootPath window or by the
231% browser
232%------------------------------------------------------------------------
233%------------------------------------------------------------------------
[2]234function MenuBrowse_Callback(hObject, eventdata, handles)
[408]235%------------------------------------------------------------------------   
[350]236InputTable=get(handles.InputTable,'Data');
237RootPathCell=InputTable(:,1);
[358]238SubDirCell=InputTable(:,2);
239RootFileCell=InputTable(:,3);
[2]240oldfile=''; %default
[329]241if isempty(RootPathCell)||isequal(RootPathCell,{''})%loads the previously stored file name and set it as default in the file_input box
[2]242     dir_perso=prefdir;
243     profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
244     if exist(profil_perso,'file')
245          h=load (profil_perso);
[329]246         if isfield(h,'filebase')&&ischar(h.filebase)
[2]247                 oldfile=h.filebase;
248         end
[329]249         if isfield(h,'RootPath')&&ischar(h.RootPath)
[2]250                 oldfile=h.RootPath;
251         end
252     end
253 else
254     oldfile=fullfile(RootPathCell{1},SubDirCell{1},RootFileCell{1});
255 end
256[FileName, PathName, filterindex] = uigetfile( ...
257       {'*.xml;*.xls;*.png;*.tif;*.avi;*.AVI;*.nc', ' (*.xml,*.xls, *.png,*.tif, *.avi,*.nc)';
258       '*.xml',  '.xml files '; ...
259        '*.xls',  '.xls files '; ...
260        '*.png','.png image files'; ...
261        '*.tif','.tif image files'; ...
262        '*.avi;*.AVI','.avi movie files'; ...
263        '*.nc','.netcdf files'; ...
264        '*.*',  'All Files (*.*)'}, ...
265        'Pick a file',oldfile);
266fileinput=[PathName FileName];%complete file name
267sizf=size(fileinput);
268if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
269[path,name,ext]=fileparts(fileinput);
270SeriesData=[];%dfault
271if isequal(ext,'.xml')
[460]272     Param=xml2struct(fileinput);
273    fill_GUI(Param,handles);%fill the GUI with the parameters retrieved from the xml file
274    return
[2]275elseif isequal(ext,'.xls')
[408]276    msg_box_uvmat('ERROR','input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
[2]277else
[408]278    display_file_name(handles,fileinput,0)
[2]279     %update list of recent files in the menubar
[446]280%     MenuFile_1=fileinput;
281%     MenuFile_2=get(handles.MenuFile_1,'Label');
282%     MenuFile_3=get(handles.MenuFile_2,'Label');
283%     MenuFile_4=get(handles.MenuFile_3,'Label');
284%     MenuFile_5=get(handles.MenuFile_4,'Label');
285%     set(handles.MenuFile_1,'Label',MenuFile_1)
286%     set(handles.MenuFile_2,'Label',MenuFile_2)
287%     set(handles.MenuFile_3,'Label',MenuFile_3)
288%     set(handles.MenuFile_4,'Label',MenuFile_4)
289%     set(handles.MenuFile_5,'Label',MenuFile_5)
290%     set(handles.MenuFile_insert_1,'Label',MenuFile_1)
291%     set(handles.MenuFile_insert_2,'Label',MenuFile_2)
292%     set(handles.MenuFile_insert_3,'Label',MenuFile_3)
293%     set(handles.MenuFile_insert_4,'Label',MenuFile_4)
294%     set(handles.MenuFile_insert_5,'Label',MenuFile_5)
295%     dir_perso=prefdir;
296%     profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
297%     if exist(profil_perso,'file')
298%         save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-append'); %store the file names for future opening of uvmat
299%     else
300%     txt=ver('MATLAB');
301%     Release=txt.Release;
302%         relnumb=str2num(Release(3:4));
303%         if relnumb >= 14
304%             save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-V6'); %store the file names for future opening of uvmat
305%         else
306%             save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5'); %store the file names for future opening of uvmat
307%         end
308%     end
[2]309end
310
311% --------------------------------------------------------------------
312function MenuFile_1_Callback(hObject, eventdata, handles)
313fileinput=get(handles.MenuFile_1,'Label');
[408]314display_file_name(handles,fileinput,0)
[2]315
316% --------------------------------------------------------------------
317function MenuFile_2_Callback(hObject, eventdata, handles)
318fileinput=get(handles.MenuFile_2,'Label');
[408]319display_file_name(handles,fileinput,0)
[2]320
321% --------------------------------------------------------------------
322function MenuFile_3_Callback(hObject, eventdata, handles)
323fileinput=get(handles.MenuFile_3,'Label');
[408]324display_file_name( handles,fileinput,0)
[2]325
326% --------------------------------------------------------------------
327function MenuFile_4_Callback(hObject, eventdata, handles)
328fileinput=get(handles.MenuFile_4,'Label');
[408]329display_file_name(handles,fileinput,0)
[2]330
331% --------------------------------------------------------------------
332function MenuFile_5_Callback(hObject, eventdata, handles)
333fileinput=get(handles.MenuFile_5,'Label');
[408]334display_file_name(handles,fileinput,0)
[2]335
336% --------------------------------------------------------------------
337function MenuBrowse_insert_Callback(hObject, eventdata, handles)
[350]338InputTable=get(handles.InputTable,'Data');
339RootPathCell=InputTable(:,1);
340SubDirCell=InputTable(:,3);
341RootFileCell=InputTable(:,2);
[2]342oldfile=''; %default
[206]343if isempty(RootPathCell)||isequal(RootPathCell,{''})%loads the previously stored file name and set it as default in the file_input box
[2]344     dir_perso=prefdir;
345     profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
346     if exist(profil_perso,'file')
347          h=load (profil_perso);
348         if isfield(h,'filebase')&ischar(h.filebase)
349                 oldfile=h.filebase;
350         end
351         if isfield(h,'RootPath')&ischar(h.RootPath)
352                 oldfile=h.RootPath;
353         end
354     end
355 else
356     oldfile=fullfile(RootPathCell{1},RootFileCell{1});
357 end
358[FileName, PathName, filterindex] = uigetfile( ...
359       {'*.xml;*.xls;*.png;*.avi;*.AVI;*.nc', ' (*.xml,*.xls, *.png, *.avi,*.nc)';
360       '*.xml',  '.xml files '; ...
361        '*.xls',  '.xls files '; ...
362        '*.png','.png image files'; ...
363        '*.avi;*.AVI','.avi movie files'; ...
364        '*.nc','.netcdf files'; ...
365        '*.*',  'All Files (*.*)'}, ...
366        'Pick a file',oldfile);
367fileinput=[PathName FileName];%complete file name
368sizf=size(fileinput);
369if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
370[path,name,ext]=fileparts(fileinput);
371if isequal(ext,'.xml')
[206]372    msgbox_uvmat('ERROR','input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
[2]373elseif isequal(ext,'.xls')
[206]374    msgbox_uvmat('ERROR','input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
[2]375else
[408]376    display_file_name(handles,fileinput,1)
[2]377end
378
379% --------------------------------------------------------------------
380function MenuFile_insert_1_Callback(hObject, eventdata, handles)
[408]381% --------------------------------------------------------------------   
[2]382fileinput=get(handles.MenuFile_insert_1,'Label');
[408]383display_file_name(handles,fileinput,1)
[2]384
385% --------------------------------------------------------------------
386function MenuFile_insert_2_Callback(hObject, eventdata, handles)
[408]387% --------------------------------------------------------------------   
[2]388fileinput=get(handles.MenuFile_insert_2,'Label');
[408]389display_file_name(handles,fileinput,1)
[2]390
391% --------------------------------------------------------------------
392function MenuFile_insert_3_Callback(hObject, eventdata, handles)
[408]393% --------------------------------------------------------------------   
[2]394fileinput=get(handles.MenuFile_insert_3,'Label');
[408]395display_file_name( handles,fileinput,1)
[2]396
397% --------------------------------------------------------------------
398function MenuFile_insert_4_Callback(hObject, eventdata, handles)
[408]399% --------------------------------------------------------------------   
[2]400fileinput=get(handles.MenuFile_insert_4,'Label');
[408]401display_file_name( handles,fileinput,1)
[2]402
403% --------------------------------------------------------------------
404function MenuFile_insert_5_Callback(hObject, eventdata, handles)
[408]405% --------------------------------------------------------------------   
[2]406fileinput=get(handles.MenuFile_insert_5,'Label');
[408]407display_file_name(handles,fileinput,1)
[2]408
[89]409%------------------------------------------------------------------------
[408]410% --- Executes when entered data in editable cell(s) in InputTable.
411function InputTable_CellEditCallback(hObject, eventdata, handles)
412%------------------------------------------------------------------------
413iview=eventdata.Indices(1);
414InputTable=get(handles.InputTable,'Data');
[446]415fileinput=fullfile(InputTable{iview,1},InputTable{iview,2},[InputTable{iview,3} InputTable{iview,4} InputTable{iview,5}]);
[408]416display_file_name(handles,fileinput,0)
[446]417%update the output dir
418SubDir=sort(InputTable(:,2)); %set of subdirectories sorted in alphabetical order
419SubDirOut=SubDir{1};
420if numel(SubDir)>1
421    for ilist=2:numel(SubDir)
422        SubDirOut=[SubDirOut '-' SubDir{ilist}];
423    end
424end
425set(handles.OutputSubDir,'String',SubDirOut)
[408]426
427%------------------------------------------------------------------------
428% ---  refresh the GUI data after introduction of a new file
[332]429% INPUT:
[408]430% handles: handles of the elements in the GUI series
[332]431% fileinput: name of the input file
[408]432% append: =0 to refresh the list of file series, =1 to append a new series to the list (from the menu bar option 'Open_insert')
433function display_file_name(handles,fileinput,append)
[89]434%------------------------------------------------------------------------ 
[332]435
[408]436%% get the input root name, indices, file extension and nomenclature NomType
437if ~exist(fileinput,'file')
438    msgbox_uvmat('ERROR',['input file ' fileinput  ' does not exist'])
439    return
440end
441
[332]442%% enable other menus and uicontrols
443set(handles.MenuOpen_insert,'Enable','on')
444set(handles.MenuFile_insert_1,'Enable','on')
445set(handles.MenuFile_insert_2,'Enable','on')
446set(handles.MenuFile_insert_3,'Enable','on')
447set(handles.MenuFile_insert_4,'Enable','on')
448set(handles.MenuFile_insert_5,'Enable','on')
449set(handles.RUN, 'Enable','On')
450set(handles.RUN,'BackgroundColor',[1 0 0])% set RUN button to red
[350]451set(handles.InputTable,'BackgroundColor',[1 1 0]) % set RootPath edit box  to yellow
[332]452drawnow
453
[408]454%% detect root name, nomenclature and indices in the input file name:
455[FilePath,FileName,FileExt]=fileparts(fileinput);
456% detect the file type, get the movie object if relevant, and look for the corresponding file series:
457% the root name and indices may be corrected by including the first index i1 if a corresponding xml file exists
458[RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,NomType,FileType,MovieObject,i1,i2,j1,j2]=find_file_series(FilePath,[FileName FileExt]);
459if isempty(RootFile)&&isempty(i1_series)
460    errormsg='no input file in the series';
[29]461    return
462end
[89]463
[376]464%% fill the list of file series
465InputTable=get(handles.InputTable,'Data');
[408]466if append % display the input data as a new line in the table
467     lastview=size(InputTable,1)+1;
468     InputTable(lastview,:)=[{RootPath},{SubDir},{RootFile},{NomType},{FileExt}];
469    set(handles.ListView,'String',[get(handles.ListView,'String');{num2str(lastview)}])
470    set(handles.ListView,'Value',lastview)
[446]471
[376]472else % or re-initialise the list of  input  file series
[408]473    lastview=1;
[376]474    InputTable=[{RootPath},{SubDir},{RootFile},{NomType},{FileExt}];
475    set(handles.TimeTable,'Data',[{[]},{[]},{[]},{[]}])
476    set(handles.MinIndex,'Data',[{[]},{[]}])
477    set(handles.MaxIndex,'Data',[{[]},{[]}])
[408]478    set(handles.ListView,'Value',1)
479    set(handles.ListView,'String',{'1'})
[376]480end
481set(handles.InputTable,'Data',InputTable)
482
[460]483%% display the min and max indices for all the file series
484i_sum=sum(sum(i1_series,2),3);%sum of i1_series on the last index
485MaxIndex_i=max(find(i_sum>0))-1;
486MinIndex_i=min(find(i_sum>0))-1;
487if isequal(MinIndex_i,1) && exist (fullfile_uvmat(RootPath,SubDir,RootFile,FileExt,NomType,0,i2_series(2,2),j1_series(2,2),j2_series(2,2)),'file')
488    MinIndex_i=0;
489end
490j_sum=sum(sum(j1_series,1),3);
491MaxIndex_j=max(find(j_sum>0))-1;
492MinIndex_j=min(find(j_sum>0))-1;
493MinIndex=get(handles.MinIndex,'Data');%retrieve the min indices in the table MinIndex
494MaxIndex=get(handles.MaxIndex,'Data');%retrieve the max indices in the table MaxIndex
495MinIndex{lastview,1}=MinIndex_i;
496MinIndex{lastview,2}=MinIndex_j;
497MaxIndex{lastview,1}=MaxIndex_i;
498MaxIndex{lastview,2}=MaxIndex_j;
499
500set(handles.MinIndex,'Data',MinIndex)%display the min indices in the table MinIndex
501set(handles.MaxIndex,'Data',MaxIndex)%display the max indices in the table MaxIndex
502
503%% adjust the first and last indices if requested by the bounds
504first_i=str2num(get(handles.num_first_i,'String'));
505ref_i=str2num(get(handles.num_ref_i,'String'));
506ref_j=str2num(get(handles.num_ref_j,'String'));
507if isempty(first_i)
508    first_i=ref_i;
509elseif first_i < MinIndex_i
510    first_i=MinIndex_i;
511end
512first_j=str2num(get(handles.num_first_j,'String'));
513if isempty(first_j)
514    first_j=ref_j;
515elseif first_j<MinIndex_j
516    first_j=MinIndex_j;
517end
518last_i=str2num(get(handles.num_last_i,'String'));
519if isempty(last_i)
520    last_i=ref_i;
521elseif last_i > MaxIndex_i
522    last_i=MaxIndex_i;
523end
524last_j=str2num(get(handles.num_first_j,'String'));
525if isempty(last_j)
526    last_j=ref_j;
527elseif last_j>MaxIndex_j
528    last_j=MaxIndex_j;
529end
530set(handles.num_first_i,'String',num2str(first_i));
531set(handles.num_first_j,'String',num2str(first_j));
532set(handles.num_last_i,'String',num2str(last_i));
533set(handles.num_last_j,'String',num2str(last_j));
534
535
536%% update the output dir
[446]537SubDir=sort(InputTable(:,2)); %set of subdirectories sorted in alphabetical order
538SubDirOut=SubDir{1};
539if numel(SubDir)>1
540    for ilist=2:numel(SubDir)
541        SubDirOut=[SubDirOut '-' SubDir{ilist}];
542    end
543end
544set(handles.OutputSubDir,'String',SubDirOut)
[376]545
[408]546%% determine the selected reference field indices for pair display
[2]547ref_i=1; %default ref_i is a reference frame index used to find existing pairs from PIV
[339]548if ~isempty(i1)
549    ref_i=i1;
550    if ~isempty(i2)
551        ref_i=floor((ref_i+i2)/2);% reference image number corresponding to the file
[2]552    end
553end
[408]554set(handles.num_ref_i,'String',num2str(ref_i));
[2]555ref_j=1; %default  ref_j is a reference frame index used to find existing pairs from PIV
[339]556if ~isempty(j1)
557    ref_j=j1;
558    if ~isempty(j2)
559        ref_j=floor((j1+j2)/2);
[2]560    end         
561end
[408]562set(handles.num_ref_j,'String',num2str(ref_j));
[372]563
[446]564%% update the list of recent files in the menubar and save it for future opening
[408]565MenuFile=[{get(handles.MenuFile_1,'Label')};{get(handles.MenuFile_2,'Label')};...
566    {get(handles.MenuFile_3,'Label')};{get(handles.MenuFile_4,'Label')};{get(handles.MenuFile_5,'Label')}];
[446]567str_find=strcmp(fileinput,MenuFile);
[408]568if isempty(find(str_find,1))
[446]569    MenuFile=[{fileinput};MenuFile];%insert the current file if not already in the list
[372]570end
[408]571for ifile=1:min(length(MenuFile),5)
572    eval(['set(handles.MenuFile_' num2str(ifile) ',''Label'',MenuFile{ifile});'])
573    eval(['set(handles.MenuFile_insert_' num2str(ifile) ',''Label'',MenuFile{ifile});'])
574end
[2]575dir_perso=prefdir;
576profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
577if exist(profil_perso,'file')
[408]578    save (profil_perso,'MenuFile','-append'); %store the file names for future opening of uvmat
[2]579else
[408]580    save (profil_perso,'MenuFile','-V6'); %store the file names for future opening of uvmat
[2]581end
[408]582
[350]583set(handles.InputTable,'BackgroundColor',[1 1 1])
[2]584
[408]585%% initiate input file series and refresh the current field view:     
586update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,MovieObject,lastview);
[2]587
[408]588%------------------------------------------------------------------------
589% --- Update information about a new field series (indices to scan, timing,
590%     calibration from an xml file, then refresh current plots
591function update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,VideoObject,iview)
592%------------------------------------------------------------------------
593
594%% enable j index visibility
595if isempty(j1_series)
596    state='off';
597else
598    state='on';
599end
600enable_j(handles,state)
601
602%% read timing and total frame number from the current file (movie files) !! may be overrid by xml file
603InputTable=get(handles.InputTable,'Data');
604FileBase=fullfile(InputTable{iview,1},InputTable{iview,3});
605time=[];%default
606% case of movies
607if strcmp(InputTable{iview,4},'*')
608    if ~isempty(VideoObject)
609        imainfo=get(VideoObject);
610        time=(0:1/imainfo.FrameRate:(imainfo.NumberOfFrames-1)/imainfo.FrameRate)';
611        set(handles.Dt_txt,'String',['Dt=' num2str(1000/imainfo.FrameRate) 'ms']);%display the elementary time interval in millisec
612        ColorType='truecolor';
613    elseif ~isempty(imformats(regexprep(InputTable{iview,5},'^.',''))) || isequal(InputTable{iview,5},'.vol')%&& isequal(NomType,'*')% multi-frame image
614        if ~isempty(InputTable{iview,2})
615            imainfo=imfinfo(fullfile(InputTable{iview,1},InputTable{iview,2},[InputTable{iview,3} InputTable{iview,5}]));
616        else
617            imainfo=imfinfo([FileBase InputTable{iview,5}]);
618        end
619        ColorType=imainfo.ColorType;%='truecolor' for color images
620        if length(imainfo) >1 %case of image with multiple frames
621            nbfield=length(imainfo);
622            nbfield_j=1;
623        end
624    end
625end
626
627%%  read image documentation file  if found%%%%%%%%%%%%%%%%%%%%%%%%%%%
628ext_imadoc='';
629if exist([FileBase '.xml'],'file')
630    ext_imadoc='.xml';
631elseif exist([FileBase '.civ'],'file')
632    ext_imadoc='.civ';
633end
634%read the ImaDoc file
635XmlData=[];
636NbSlice_calib={};
637if isequal(ext_imadoc,'.xml')
638        [XmlData,warntext]=imadoc2struct([FileBase '.xml']);
639        if isfield(XmlData,'Heading') && isfield(XmlData.Heading,'ImageName') && ischar(XmlData.Heading.ImageName)
640            [PP,FF,ext_ima_read]=fileparts(XmlData.Heading.ImageName);
641        end
642        if isfield(XmlData,'Time')
643            time=XmlData.Time;
644        end
645        if isfield(XmlData,'Camera')
646            if isfield(XmlData.Camera,'NbSlice')&& ~isempty(XmlData.Camera.NbSlice)
647                NbSlice_calib{iview}=XmlData.Camera.NbSlice;% Nbre of slices for Zindex in phys transform
648                if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
649                    msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
650                end
651            end
652            if isfield(XmlData.Camera,'TimeUnit')&& ~isempty(XmlData.Camera.TimeUnit)
653                TimeUnit=XmlData.Camera.TimeUnit;
654            end
655        end
656        if ~isempty(warntext)
657            msgbox_uvmat('WARNING',warntext)
658        end 
659elseif isequal(ext_imadoc,'.civ')
660    [error,XmlData.Time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([FileBase '.civ']);
661    time=XmlData.Time;
662    if error==2, warntext=['no file ' FileBase '.civ'];
663    elseif error==1, warntext='inconsistent number of fields in the .civ file';
664    end 
665end
666
667%% update time table
[456]668if ~isempty(time)
[408]669TimeTable=get(handles.TimeTable,'Data');
670if isempty(MinIndex_j)
[456]671    if MinIndex_i>0
[408]672    TimeTable{iview,1}=time(MinIndex_i);
[456]673    end
[408]674    TimeTable{iview,2}=time(first_i);
675    TimeTable{iview,3}=time(last_i);
676    TimeTable{iview,4}=time(MaxIndex_i);
[419]677elseif ~isempty(time)
[456]678    if MinIndex_i>0
[408]679    TimeTable{iview,1}=time(MinIndex_i,MinIndex_j);
[456]680    end
[408]681    TimeTable{iview,2}=time(first_i,first_j);
682    TimeTable{iview,3}=time(last_i,last_j);
683    TimeTable{iview,4}=time(MaxIndex_i,MaxIndex_j);
684end
685set(handles.TimeTable,'Data',TimeTable)
[456]686end
[408]687
688%% number of slices
[460]689NbSlice=1;%default
[408]690if isfield(XmlData,'GeometryCalib') && isfield(XmlData.GeometryCalib,'SliceCoord')
691    siz=size(XmlData.GeometryCalib.SliceCoord);
692    if siz(1)>1
693        NbSlice=siz(1);
694    end
695end
[450]696set(handles.num_NbSlice,'String',num2str(NbSlice))
697   
[408]698%% update pair menus
[441]699set(handles.Pairs,'Visible','on')
700set(handles.PairString,'Visible','on')
[408]701ListView=get(handles.ListView,'String');
702ListView{iview}=num2str(iview);
703set(handles.ListView,'String');
704set(handles.ListView,'Value',iview)
705update_mode(handles,i1_series,i2_series,j1_series,j2_series,time)
706
[441]707
[408]708%% display the set of existing files as an image
709set(handles.waitbar_frame,'Units','pixels')
710pos=get(handles.waitbar_frame,'Position');
711xima=0.5:pos(3)-0.5;% pixel positions on the image representing the existing file indices
712yima=0.5:pos(4)-0.5;
713[XIma,YIma]=meshgrid(xima,yima);
714nb_i=size(i1_series,1);
715nb_j=size(i1_series,2);
716ind_i=(0.5:nb_i-0.5)*pos(3)/nb_i;
717ind_j=(0.5:nb_j-0.5)*pos(4)/nb_j;
718[Ind_i,Ind_j]=meshgrid(ind_i,ind_j);
719CData=zeros([size(XIma) 3]);
720file_ima=double((i1_series(:,:,1)>0)');
721if numel(file_ima)>=2
722if size(file_ima,1)==1
723    CLine=interp1(ind_i,file_ima,xima,'nearest');
724    CData(:,:,2)=ones(size(yima'))*CLine;
725else
726    CData(:,:,2)=interp2(Ind_i,Ind_j,file_ima,XIma,YIma,'nearest');
727end
728set(handles.waitbar_frame,'CData',CData)
729end
730set(handles.waitbar_frame,'Units','normalized')
731
732%% enable field and veltype menus
733SeriesData=get(handles.series,'UserData');
734SeriesData.FileType{iview}=FileType;
735check_civ=0;
736check_netcdf=0;
737for iview=1:length(SeriesData.FileType)
738    switch SeriesData.FileType{iview}
739        case {'civx','civdata'}
740            check_civ=check_civ+1;
741        case 'netcdf'
742            check_netcdf=check_netcdf+1;
743    end
744end
745if check_civ
746    enable='on';
747else
748    enable='off';
749end
[446]750set(handles.VelType,'Visible',enable)
[408]751set(handles.VelType_text,'Visible',enable)
752if check_civ>=2
753    enable='on';
754else
755    enable='off';
756end
[446]757set(handles.VelType_1,'Visible',enable)
[408]758set(handles.VelType_text_1,'Visible',enable)
759if check_civ || check_netcdf
760    enable='on';
761else
762    enable='off';
763end
[446]764set(handles.FieldName,'Visible',enable)
[408]765set(handles.Field_text,'Visible',enable)
766if check_civ+ check_netcdf>=2
767    enable='on';
768else
769    enable='off';
770end
[446]771set(handles.FieldName_1,'Visible',enable)
[408]772set(handles.Field_text_1,'Visible',enable)
773FieldString={''};
774if check_civ
775    FieldString=[calc_field;{'get_field...'}];
776elseif check_netcdf
777    FieldString={'get_field...'};
778end
[446]779set(handles.FieldName,'String',FieldString)
[408]780FieldString={''};
781if check_civ>=2
782    FieldString=[calc_field;{'get_field...'}];
783elseif check_civ+check_netcdf>=2
784    FieldString={'get_field...'};
785end
[446]786set(handles.FieldName_1,'String',{'get_field...'})
[408]787
788
789%% store the series info in 'UserData'
790SeriesData.i1_series{iview}=i1_series;
791SeriesData.i2_series{iview}=i2_series;
792SeriesData.j1_series{iview}=j1_series;
793SeriesData.j2_series{iview}=j2_series;
794SeriesData.FileType{iview}=FileType;
795SeriesData.Time{iview}=time;
796set(handles.series,'UserData',SeriesData)
797
[441]798%% check for pair display
799check_pairs=0;
800for iview=1:numel(SeriesData.i2_series)
801    if ~isempty(SeriesData.i2_series{iview})||~isempty(SeriesData.j2_series{iview})
802        check_pairs=1;
803    end
804end
805if check_pairs
806    set(handles.Pairs,'Visible','on')
807    set(handles.PairString,'Visible','on')
808else
809    set(handles.Pairs,'Visible','off')
810    set(handles.PairString,'Visible','off')
811end
[408]812
[460]813% %% set default options in menu 'Fields'%% TODO: check VelType
814% if ~testima
815%     testcivx=0;
816%     if isfield(UvData,'FieldsString') && isequal(UvData.FieldsString,{'get_field...'})% field menu defined as input (from get_field)
817%         set(handles_Fields,'Value',1)
818%         set(handles_Fields,'String',{'get_field...'})
819%         UvData=rmfield(UvData,'FieldsString');
820%     else
821%         Data=nc2struct(FileName,'ListGlobalAttribute','Conventions','absolut_time_T0','civ');
822%         if strcmp(Data.Conventions,'uvmat/civdata') ||( ~isempty(Data.absolut_time_T0)&& ~isequal(Data.civ,0))%if the new input is Civx
823%             FieldList=calc_field;
824%             set(handles_Fields,'String',[{'image'};FieldList;{'get_field...'}]);%standard menu for civx data
825%             set(handles_Fields,'Value',2) % set menu to 'velocity'
826%             col_vec=FieldList;
827%             col_vec(1)=[];%remove 'velocity' option for vector color (must be a scalar)
828%             testcivx=1;
829%         end
830%         if ~testcivx
831%             set(handles_Fields,'Value',1) % set menu to 'get_field...
832%             set(handles_Fields,'String',{'get_field...'})
833%             col_vec={'get_field...'};
834%         end
835%         set(handles.ColorScalar,'String',col_vec)
836%     end
837% end
838% set(handles.uvmat,'UserData',UvData)
839%
840% %% set index navigation options and refresh plots
841% scan_option='i';%default
842% state_j='off'; %default
843% if index==2
844%     if get(handles.scan_j,'Value')
845%         scan_option='j'; %keep the scan option for the second fiel series
846%     end
847%     if strcmp(get(handles.j1,'Visible'),'on')
848%         state_j='on';
849%     end
850% end
851% if ~isempty(j1_series)
852%         state_j='on';
853%         if isequal(nbfield,1) &&index==1
854%             scan_option='j'; %scan j index by default if nbfield=1               
855%         end
856% end
857% if isequal(scan_option,'i')
858%      set(handles.scan_i,'Value',1)
859%      scan_i_Callback([],[], handles);
860% else
861%      set(handles.scan_j,'Value',1)
862%      scan_j_Callback([],[], handles);
863% end
864% set(handles.scan_j,'Visible',state_j)
865% set(handles.j1,'Visible',state_j)
866% set(handles.j2,'Visible',state_j)
867% set(handles.last_j,'Visible',state_j);
868% set(handles.frame_j,'Visible',state_j);
869% set(handles.j_text,'Visible',state_j);
870% if ~isempty(i2_series)||~isempty(j2_series)
871%     set(handles.CheckFixPair,'Visible','on')
872% elseif index==1
873%     set(handles.CheckFixPair,'Visible','off')
874% end
875%
876%
877% mode_Callback(hObject, eventdata, handles)
878%
879% set(handles.REFRESH_INDICES,'BackgroundColor',[0.7 0.7 0.7])
880% InputTable=get(handles.InputTable,'Data');
881% check_lines=get(handles.REFRESH_INDICES,'UserData');
882%
883% %% check the indices and FileTypes for each series (limited to the new ones to save time)
884% for ind_list=1:length(check_lines)
885%     if  check_lines(ind_list)
886%         InputLine=InputTable(ind_list,:);
887%         detect_idem=strcmp('"',InputLine);% look for '" (repeat of previous data)
888%         detect_idem=detect_idem(detect_idem>0);
889%         if ~isempty (detect_idem)
890%             InputLine(detect_idem)=InputTable(ind_list-1,detect_idem);
891%             set(handles.InputTable,'Data',InputTable)
892%         end
893%         fileinput=fullfile_uvmat(InputLine{1},InputLine{2},InputLine{3},InputLine{5},InputLine{4},1,2,1,2);
894%         %fileinput=name_generator(fullfile(InputLine{1},InputLine{3}),1,1,InputLine{5},InputLine{4},1,2,2,InputLine{2})
895%         %update file series defined by the selected line
896%         [InputTable{ind_list,3},InputTable{(ind_list),4},errormsg]=update_indices(handles,fileinput,ind_list);
897%         if ~isempty(errormsg)
898%                 msgbox_uvmat('ERROR',errormsg)
899%                 return
900%         end
901%     end
902% end
903% set(handles.InputTable,'Data',InputTable)
904% SeriesData=get(handles.series,'UserData');
905%
906% state_j='off';
907% state_Pairs='off';
908% state_InputFields='off';
909% val=get(handles.ListView,'Value');
910% ListViewString={''};
911% if ~isempty(SeriesData)
912% %     ListViewString={};
913%     for iview=1:size(InputTable,1)
914%         if ~isempty(SeriesData.j1_series{iview})
915%             state_j='on';
916%         end
917%         if ~isempty(SeriesData.i2_series{iview})||~isempty(SeriesData.j2_series{iview})
918%             state_Pairs='on';
919%             ListViewString{iview}=num2str(iview);
920%             if check_lines(iview)
921%                 val=iview;%select the last pair if it is a new entry
922%             end
923%         end
924%         if strcmp(SeriesData.FileType{iview},'civx')||strcmp(SeriesData.FileType{iview},'civdata')
925%             state_InputFields='on';
926%         end
927%     end
928% end
929% set(handles.ListView,'Value',val)
930% set(handles.ListView,'String',ListViewString)
931% if strcmp(state_Pairs,'on')
932%     ListView_Callback(hObject,eventdata,handles)
933% end
934% set(handles.PairString,'Visible',state_Pairs)
935% enable_j(handles,state_j)
[408]936
[446]937%------------------------------------------------------------------------
938function num_first_i_Callback(hObject, eventdata, handles)
939%------------------------------------------------------------------------
940num_last_i_Callback(hObject, eventdata, handles)
[408]941
942%------------------------------------------------------------------------
[446]943function num_last_i_Callback(hObject, eventdata, handles)
944%------------------------------------------------------------------------
945SeriesData=get(handles.series,'UserData');
946if ~isfield(SeriesData,'Time')
947    SeriesData.Time{1}=[];
948end
949displ_time(handles);
950
951%------------------------------------------------------------------------
952function num_first_j_Callback(hObject, eventdata, handles)
953%------------------------------------------------------------------------
954 num_last_j_Callback(hObject, eventdata, handles)
955
956%------------------------------------------------------------------------
957function num_last_j_Callback(hObject, eventdata, handles)
958%------------------------------------------------------------------------
959first_j=str2num(get(handles.num_first_j,'String'));
960last_j=str2num(get(handles.num_last_j,'String'));
961ref_j=ceil((first_j+last_j)/2);
962set(handles.num_ref_j,'String', num2str(ref_j))
963num_ref_j_Callback(hObject, eventdata, handles)
964SeriesData=get(handles.series,'UserData');
965if ~isfield(SeriesData,'Time')
966    SeriesData.Time{1}=[];
967end
968displ_time(handles);
969
970%------------------------------------------------------------------------
971% ---- find the times corresponding to the first and last indices of a series
972function displ_time(handles)
973%------------------------------------------------------------------------
974SeriesData=get(handles.series,'UserData');%
975ref_i=[str2num(get(handles.num_first_i,'String')) str2num(get(handles.num_last_i,'String'))];
976ref_j=[str2num(get(handles.num_first_j,'String')) str2num(get(handles.num_last_j,'String'))];
977% last_i=str2num(get(handles.num_last_i,'String'));
978% last_j=str2num(get(handles.num_last_j,'String'));
979TimeTable=get(handles.TimeTable,'Data');
980Pairs=get(handles.PairString,'Data');
981for iview=1:size(TimeTable,1)
982    if size(SeriesData.Time,1)<iview
983        break
984    end
985    i1=ref_i;
986    j1=ref_j;
987    i2=ref_i;
988    j2=ref_j;
989    % case of pairs
990    if ~isempty(Pairs{iview,1})
991        r=regexp(Pairs{iview,1},'(?<mode>(Di=)|(Dj=)) -*(?<num1>\d+)\|(?<num2>\d+)','names');
992        if isempty(r)
993            r=regexp(Pairs{iview,1},'(?<num1>\d+)(?<mode>-)(?<num2>\d+)','names');
994        end
995        switch r.mode
996            case 'Di='  %  case 'series(Di)')
997                i1=ref_i-str2num(r.num1);
998                i2=ref_i+str2num(r.num2);
999            case 'Dj='  %  case 'series(Dj)'
1000                j1=ref_j-str2num(r.num1);
1001                j2=ref_j+str2num(r.num2);
1002            case '-'  % case 'bursts'
1003                j1=str2num(r.num1)*ones(size(ref_i));
1004                j2=str2num(r.num2)*ones(size(ref_i));
1005        end
1006    end
1007    TimeTable{iview,2}=[];
1008    TimeTable{iview,3}=[];
1009    if size(SeriesData.Time{iview},1)>=i2(2)&&size(SeriesData.Time{iview},1)>=j2(2)
1010        if isempty(ref_j)
1011            time_first=(SeriesData.Time{iview}(i1(1))+SeriesData.Time{iview}(i2(1)))/2;
1012            time_last=(SeriesData.Time{iview}(i1(2))+SeriesData.Time{iview}(i2(2)))/2;
1013        else
1014            time_first=(SeriesData.Time{iview}(i1(1),j1(1))+SeriesData.Time{iview}(i2(1),j2(1)))/2;
1015            time_last=(SeriesData.Time{iview}(i1(2),j1(2))+SeriesData.Time{iview}(i2(2),j2(2)))/2;
1016        end
1017        TimeTable{iview,2}=time_first; %TODO: take into account pairs
1018        TimeTable{iview,3}=time_last; %TODO: take into account pairs
1019    end
1020end
1021set(handles.TimeTable,'Data',TimeTable)
1022
1023%------------------------------------------------------------------------
[408]1024% --- Executes when selected cell(s) is changed in PairString.
1025function PairString_CellSelectionCallback(hObject, eventdata, handles)
1026%------------------------------------------------------------------------   
1027set(handles.ListView,'Value',eventdata.Indices(1))% detect the selected raw index
1028ListView_Callback ([],[],handles) % update the list of available pairs
1029
1030%------------------------------------------------------------------------
1031%------------------------------------------------------------------------
1032%  III - FUNCTIONS ASSOCIATED TO THE FRAME SET PAIRS
1033%------------------------------------------------------------------------
1034%------------------------------------------------------------------------
1035% --- Executes on selection change in ListView.
1036function ListView_Callback(hObject, eventdata, handles)
1037%------------------------------------------------------------------------   
1038SeriesData=get(handles.series,'UserData');
1039i2_series=[];
1040j2_series=[];
1041iview=get(handles.ListView,'Value');
1042if ~isempty(SeriesData.i2_series{iview})
1043    i2_series=SeriesData.i2_series{iview};
1044end
1045if ~isempty(SeriesData.j2_series{iview})
1046    j2_series=SeriesData.j2_series{iview};
1047end
1048update_mode(handles,SeriesData.i1_series{iview},SeriesData.i2_series{iview},...
1049    SeriesData.j1_series{iview},SeriesData.j2_series{iview},SeriesData.Time{iview})
1050
1051%------------------------------------------------------------------------
[2]1052% --- Executes on button press in mode.
[376]1053function mode_Callback(hObject, eventdata, handles)
[408]1054%------------------------------------------------------------------------       
[376]1055SeriesData=get(handles.series,'UserData');
[408]1056iview=get(handles.ListView,'Value');
[376]1057mode_list=get(handles.mode,'String');
[408]1058mode=mode_list{get(handles.mode,'Value')};
[376]1059if isequal(mode,'bursts')
1060    enable_i(handles,'On')
1061    enable_j(handles,'Off') %do not display j index scanning in burst mode (j is fixed by the burst choice)
1062else
1063    enable_i(handles,'On')
1064    enable_j(handles,'Off')
1065end
[408]1066fill_ListPair(handles,SeriesData.i1_series{iview},SeriesData.i2_series{iview},...
1067    SeriesData.j1_series{iview},SeriesData.j2_series{iview},SeriesData.Time{iview})
1068ListPairs_Callback([],[],handles)
[339]1069
[408]1070%-------------------------------------------------------------
1071% --- Executes on selection in ListPairs.
1072function ListPairs_Callback(hObject,eventdata,handles)
1073%------------------------------------------------------------
1074list_pair=get(handles.ListPairs,'String');%get the menu of image pairs
[441]1075if isempty(list_pair)
1076    string='';
1077else
1078    string=list_pair{get(handles.ListPairs,'Value')};
1079    string=regexprep(string,',.*','');%removes time indication (after ',')
1080end
[408]1081PairString=get(handles.PairString,'Data');
1082iview=get(handles.ListView,'Value');
1083PairString{iview,1}=string;
1084% report the selected pair string to the table PairString
1085set(handles.PairString,'Data',PairString)
[2]1086
[408]1087%------------------------------------------------------------------------
1088function num_ref_i_Callback(hObject, eventdata, handles)
1089%------------------------------------------------------------------------
1090mode_list=get(handles.mode,'String');
1091mode=mode_list{get(handles.mode,'Value')};
1092SeriesData=get(handles.series,'UserData');
1093iview=get(handles.ListView,'Value');
1094fill_ListPair(handles,SeriesData.i1_series{iview},SeriesData.i2_series{iview},...
[446]1095    SeriesData.j1_series{iview},SeriesData.j2_series{iview},SeriesData.Time{iview});% update the menu of pairs depending on the available netcdf files
[408]1096ListPairs_Callback([],[],handles)
[2]1097
[408]1098%------------------------------------------------------------------------
1099function num_ref_j_Callback(hObject, eventdata, handles)
1100%------------------------------------------------------------------------
1101num_ref_i_Callback(hObject, eventdata, handles)
[2]1102
[408]1103%------------------------------------------------------------------------
1104function update_mode(handles,i1_series,i2_series,j1_series,j2_series,time)
1105%------------------------------------------------------------------------   
[440]1106check_burst=0;
[408]1107if isempty(j2_series)% no pair menu to display
1108    if isempty(i2_series)
1109        set(handles.mode,'String',{''})
1110    else
1111        set(handles.mode,'Value',1)
1112        set(handles.mode,'String',{'series(Di)'})
1113    end
1114else
[419]1115    nbfield=size(j2_series,1);
1116    nbfield2=size(j2_series,2);
[408]1117    set(handles.mode,'String',{'bursts';'series(Dj)'})
1118    if nbfield2>10 || nbfield==1
[440]1119        set(handles.mode,'Value',2);%set mode to series(Dj) if more than 10 j values
[408]1120    else
1121        set(handles.mode,'Value',1);
1122        check_burst=1;
1123    end
1124end
1125if check_burst
1126    enable_i(handles,'On')
1127    enable_j(handles,'Off') %do not display j index scanning in burst mode (j is fixed by the burst choice)
1128else
1129    enable_i(handles,'On')
[456]1130    if isempty(j1_series)
1131         enable_j(handles,'Off')
1132    else
1133        enable_j(handles,'On')
1134    end
[408]1135end
1136fill_ListPair(handles,i1_series,i2_series,j1_series,j2_series,time)
1137ListPairs_Callback([],[],handles)
[2]1138
1139%--------------------------------------------------------------
[408]1140% determine the menu for civ1 pairstring depending on existing netcdf files
1141% with the reference indices num_ref_i and num_ref_j
[2]1142%----------------------------------------------------------------
[408]1143function fill_ListPair(handles,i1_series,i2_series,j1_series,j2_series,time)
1144
[2]1145mode_list=get(handles.mode,'String');
[408]1146mode=mode_list{get(handles.mode,'Value')};
1147ref_i=str2num(get(handles.num_ref_i,'String'));
1148ref_j=str2num(get(handles.num_ref_j,'String'));
1149if isempty(ref_i)
1150    ref_i=1;
1151end
1152if isempty(ref_j)
1153    ref_j=1;
1154end
[2]1155TimeUnit=get(handles.TimeUnit,'String');
1156if length(TimeUnit)>=1
1157    dtunit=['m' TimeUnit];
1158else
1159    dtunit='e-03';
1160end
[339]1161
1162displ_pair={};
[118]1163if strcmp(mode,'series(Di)')
[339]1164    if isempty(i2_series)
1165        msgbox_uvmat('ERROR','no i1-i2 pair available')
1166        return
1167    end
1168    diff_i=i2_series-i1_series;
1169    min_diff=min(diff_i(diff_i>0));
1170    max_diff=max(diff_i(diff_i>0));
1171    for ipair=min_diff:max_diff
1172        if numel(diff_i(diff_i==ipair))>0
[408]1173            pair_string=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ];
1174            if ~isempty(time)
1175                Dt=time(ref_i+ceil(ipair/2),ref_j)-time(ref_i-floor(ipair/2),ref_j);
1176                pair_string=[pair_string ', Dt=' num2str(Dt) ' ' dtunit];
1177            end
1178            displ_pair=[displ_pair;{pair_string}];
[339]1179        end
1180    end
1181    if ~isempty(displ_pair)
1182        displ_pair=[displ_pair;{'Di=*|*'}];
1183    end
1184elseif strcmp(mode,'series(Dj)')
1185    if isempty(j2_series)
1186        msgbox_uvmat('ERROR','no j1-j2 pair available')
1187        return
1188    end
1189    diff_j=j2_series-j1_series;
1190    min_diff=min(diff_j(diff_j>0));
1191    max_diff=max(diff_j(diff_j>0));
1192    for ipair=min_diff:max_diff
1193        if numel(diff_j(diff_j==ipair))>0
[408]1194            pair_string=['Dj= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ];
1195            if ~isempty(time)
1196                Dt=time(ref_i,ref_j+ceil(ipair/2))-time(ref_i,ref_j-floor(ipair/2));
1197                pair_string=[pair_string ', Dt=' num2str(Dt) ' ' dtunit];
1198            end
1199            displ_pair=[displ_pair;{pair_string}];
[339]1200        end
1201    end
1202    if ~isempty(displ_pair)
1203        displ_pair=[displ_pair;{'Dj=*|*'}];
1204    end
1205elseif strcmp(mode,'bursts')
1206    if isempty(j2_series)
1207        msgbox_uvmat('ERROR','no j1-j2 pair available')
1208        return
1209    end
1210    diff_j=j2_series-j1_series;
1211    min_j1=min(j1_series(j1_series>0));
1212    max_j1=max(j1_series(j1_series>0));
1213    min_j2=min(j2_series(j2_series>0));
1214    max_j2=max(j2_series(j2_series>0));
1215    for pair1=min_j1:min(max_j1,min_j1+20)
1216        for pair2=min_j2:min(max_j2,min_j2+20)
1217        if numel(j1_series(j1_series==pair1))>0 && numel(j2_series(j2_series==pair2))>0
1218            displ_pair=[displ_pair;{['j= ' num2str(pair1) '-' num2str(pair2)]}];
1219        end
1220        end
1221    end
1222    if ~isempty(displ_pair)
1223        displ_pair=[displ_pair;{'j=*-*'}];
1224    end
1225end
[408]1226
1227%% display list of pairstring
1228displ_pair_list=get(handles.ListPairs,'String');
[339]1229NewVal=[];
1230if ~isempty(displ_pair_list)
[408]1231Val=get(handles.ListPairs,'Value');
[419]1232NewVal=find(strcmp(displ_pair_list{Val},displ_pair),1);% look at the previous display in the new menu displ_pï¿œir
[339]1233end
1234if ~isempty(NewVal)
[408]1235    set(handles.ListPairs,'Value',NewVal)
[339]1236else
[408]1237    set(handles.ListPairs,'Value',1)
[339]1238end
[408]1239set(handles.ListPairs,'String',displ_pair)
[339]1240
[408]1241%-------------------------------------
1242function enable_i(handles,state)
1243set(handles.i_txt,'Visible',state)
1244set(handles.num_first_i,'Visible',state)
1245set(handles.num_last_i,'Visible',state)
1246set(handles.num_incr_i,'Visible',state)
1247% set(handles.num_MaxIndex_i,'Visible',state)
1248set(handles.num_ref_i,'Visible',state)
1249set(handles.ref_i_text,'Visible',state)
[2]1250
[408]1251%-----------------------------------
1252function enable_j(handles,state)
1253set(handles.j_txt,'Visible',state)
1254% set(handles.num_MinIndex_j,'Visible',state)
1255set(handles.num_first_j,'Visible',state)
1256set(handles.num_last_j,'Visible',state)
1257set(handles.num_incr_j,'Visible',state)
1258% set(handles.num_MaxIndex_j,'Visible',state)
1259set(handles.num_ref_j,'Visible',state)
1260set(handles.ref_j_text,'Visible',state)
[41]1261
[408]1262%-----------------------------------
1263function view_FieldMenu(handles,state)
[446]1264% set(handles.FieldName,'Visible',state)
[408]1265% set(handles.Field_text,'Visible',state)
1266set(handles.InputFields,'Visible',state)
1267
1268%-----------------------------------
1269function view_FieldMenu_1(handles,state)
[446]1270set(handles.FieldName_1,'Visible',state)
[408]1271set(handles.Field_text_1,'Visible',state)
1272
1273
[446]1274%%%%%%%%%%%%%%%%%%%%
1275%%  MAIN ActionName FUNCTIONS
1276%%%%%%%%%%%%%%%%%%%%
[41]1277%------------------------------------------------------------------------
[2]1278% --- Executes on button press in RUN.
1279function RUN_Callback(hObject, eventdata, handles)
[41]1280%------------------------------------------------------------------------
[2]1281set(handles.RUN,'BusyAction','queue');
[332]1282set(0,'CurrentFigure',handles.series)
[446]1283set(handles.RUN, 'Enable','Off')
1284set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784])
[456]1285drawnow
[453]1286[h_fun,Series,filexml,errormsg]=prepare_jobs(handles);
[446]1287if ~isempty(errormsg)
1288    msgbox_uvmat('ERROR',errormsg)
[2]1289else
[456]1290  %Series.Specific=h_fun(Series);   
1291   Series=h_fun(Series); 
[460]1292   if ~isempty(filexml)
[453]1293   t=struct2xml(Series);
1294    t=set(t,1,'name','Series');
1295    save(t,filexml);
[460]1296   end
[456]1297%     h_fun(Series);
[2]1298end
[446]1299set(handles.RUN, 'Enable','On')
1300set(handles.RUN,'BackgroundColor',[1 0 0])
[2]1301
[446]1302%------------------------------------------------------------------------
1303function STOP_Callback(hObject, eventdata, handles)
1304%------------------------------------------------------------------------
1305set(handles.RUN, 'BusyAction','cancel')
1306set(handles.RUN,'BackgroundColor',[1 0 0])
1307set(handles.RUN,'enable','on')
[448]1308set(handles.BATCH,'BackgroundColor',[1 0 0])
1309set(handles.BATCH,'enable','on')
[446]1310
1311%------------------------------------------------------------------------
1312% --- Executes on button press in BATCH.
1313function BATCH_Callback(hObject, eventdata, handles)
1314%------------------------------------------------------------------------   
1315set(handles.BATCH, 'Enable','Off')
1316set(handles.BATCH,'BackgroundColor',[0.831 0.816 0.784])
[453]1317[h_fun,Series,filexml,errormsg]=prepare_jobs(handles);
[448]1318if ~isempty(errormsg)
1319    msgbox_uvmat('ERROR',errormsg)
1320    return
1321end
[453]1322% update the xml file after interactive input with the function
[460]1323Series.Specific='?';
1324Series=h_fun(Series);   
[453]1325t=struct2xml(Series);
1326t=set(t,1,'name','Series');
1327save(t,filexml);
[448]1328path_series=fileparts(which('series'));
1329filename_xml=fullfile(Series.OutputDir,[Series.OutputRootFile '.xml']);
1330filename_bat=fullfile(Series.OutputDir,[Series.OutputRootFile '.bat']);
[446]1331[fid,message]=fopen(filename_bat,'w');
1332if isequal(fid,-1)
[448]1333    msgbox_uvmat('ERROR', ['creation of .bat file: ' message]);
[446]1334    return
1335end
[456]1336path_fct=get(handles.ActionPath,'String');
[446]1337text_matlabscript=[...
1338    '#!/bin/bash \n'...
1339    '. /etc/sysprofile \n'...
1340    'matlab -nodisplay -nosplash -nojvm <<END_MATLAB \n'...
[448]1341    'cd(''' path_series '''); \n'...
[456]1342    'addpath(''' path_fct '''); \n'...
[448]1343    '' Series.Action  '( ''' filename_xml '''); \n'...
[446]1344    'exit \n'...
1345    'END_MATLAB \n'];
1346fprintf(fid,text_matlabscript);
1347fclose(fid);
1348if isunix
[456]1349    system(['chmod +x ' filename_bat]);% set the file to executable
[460]1350    system(['. ' filename_bat ' &']);%execute fct
1351else
1352    system(filename_bat);
[446]1353end
[448]1354set(handles.BATCH, 'Enable','On')
1355set(handles.BATCH,'BackgroundColor',[1 0 0])
[456]1356
[446]1357%------------------------------------------------------------------------
1358% --- Executes on button press in BIN.
1359function BIN_Callback(hObject, eventdata, handles)
1360%------------------------------------------------------------------------
1361    cmd=['#!/bin/bash \n '...
1362        '#$ -cwd \n '...
1363        'hostname && date \n '...
1364        'umask 002 \n'...
1365        Param.xml.CivmBin ' ' Param.xml.RunTime ' ' filename_xml ' ' OutputFile '.nc'];
1366   
1367%------------------------------------------------------------------------
[456]1368% --- Main launch command, called by RUN and BATCH
[453]1369function [h_fun,Series,filexml,errormsg]=prepare_jobs(handles)
[446]1370%------------------------------------------------------------------------
[456]1371filexml='';
[446]1372errormsg='';
1373%% Read parameters from series
1374Series=read_GUI(handles.series);
1375if isfield(Series,'Pairs')
1376Series=rmfield(Series,'Pairs'); %info Pairs not needed for output
1377end
1378
[456]1379%% read index ranges
[446]1380first_i=1;
1381last_i=1;
1382incr_i=1;
1383first_j=1;
1384last_j=1;
1385incr_j=1;
[339]1386if isfield(Series.IndexRange,'first_i')
1387    first_i=Series.IndexRange.first_i;
1388    incr_i=Series.IndexRange.incr_i;
1389    last_i=Series.IndexRange.last_i;
1390end
1391if isfield(Series.IndexRange,'first_j')
1392    first_j=Series.IndexRange.first_j;
1393    incr_j=Series.IndexRange.incr_j;
1394    last_j=Series.IndexRange.last_j;
1395end
1396
1397%% read input file parameters and set menus
[446]1398menu_coord_state=get(handles.TransformName,'Visible');
[2]1399if isequal(menu_coord_state,'on')
[446]1400    menu_index=get(handles.TransformName,'Value');
1401    transform_list=get(handles.TransformName,'UserData');
1402    Series.FieldTransform.TransformHandle=transform_list{menu_index};% transform function handles
[2]1403end
1404
1405if last_i < first_i | last_j < first_j , msgbox_uvmat('ERROR','last field number must be larger than the first one'),...
1406    set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
1407
[446]1408%% projection object
1409if isfield(Series,'CheckObject')
1410    if Series.CheckObject
1411        hset_object=findobj(allchild(0),'tag','set_object');
1412        Series.ProjObject=read_GUI(hset_object);
[458]1413        CheckObject_Callback([], [], handles)
[446]1414    end
1415else
1416    Series.CheckObject=0;
1417end
[2]1418
[446]1419%% get_field GUI
1420if isfield(Series,'InputFields')&&isfield(Series.InputFields,'Field')
1421    if strcmp(Series.InputFields.Field,'get_field...')
1422        hget_field=findobj(allchild(0),'name','get_field');
1423        Series.GetField=read_GUI(hget_field);
1424    end
1425end
[2]1426
[446]1427%% defining the ActionName function handle
1428list_action=get(handles.ActionName,'String');% list menu action
1429index=get(handles.ActionName,'Value');
1430action= list_action{index}; % selected string
1431Series.Action=action;%name of the processing programme
1432Series.hseries=handles.series; % handles to the series GUI
[2]1433path_series=which('series');
[446]1434list_path=get(handles.ActionName,'UserData');
[2]1435fct_path=list_path{index}; %path stored for the function ACTION
1436if ~isequal(fct_path,path_series)
1437    eval(['spath=which(''' action ''');']) %spath = current path of the selected function ACTION
[41]1438    if ~exist(fct_path,'dir')
[446]1439        errormsg=['The prescibed function path ' fct_path ' does not exist'];
[41]1440        return
1441    end
1442    if ~isequal(spath,fct_path)
[2]1443        addpath(fct_path)% add the prescribed path if not the current one
1444    end
1445end
[41]1446eval(['h_fun=@' action ';'])%create a function handle for ACTION
[26]1447if ~isequal(fct_path,path_series)
1448        rmpath(fct_path)% add the prescribed path if not the current one   
1449end
1450
[446]1451%% create the output data directory and write in it the xml file from the GUI config
1452%determine the root file corresponding to the first sub dir
1453if isfield(Series,'OutputSubDir')
1454    SubDirOut=[Series.OutputSubDir Series.OutputDirExt];
1455    SubDirOutNew=SubDirOut;
1456    iview=1;
1457    SeriesData=get(handles.series,'UserData');
1458    if size(Series.InputTable,1)>1 && isfield(SeriesData,'AllowInputSort') && isfield(SeriesData.AllowInputSort)
1459        [tild,iview]=sort(Series.InputTable(:,2)); %subdirectories sorted in alphabetical order
1460        Series.InputTable=Series.InputTable(iview,:);
[421]1461    end
[448]1462    detect=exist(fullfile(Series.InputTable{1,1},SubDirOutNew),'dir');% test if  the dir  already exist
[450]1463    check_create=1; %need to create the result directory by default
[446]1464    while detect
[448]1465        answer=msgbox_uvmat('INPUT_Y-N',['use existing ouput directory: ' fullfile(Series.InputTable{1,1},SubDirOutNew) ', possibly delete previous data']);
1466        if isequal(answer,'Yes')
1467            detect=0;
1468            check_create=0;
1469        else
1470            r=regexp(SubDirOutNew,'(?<root>.*\D)(?<num1>\d+)$','names');%detect whether name ends by a number
1471            if isempty(r)
1472                r(1).root=[SubDirOutNew '_'];
1473                r(1).num1='0';
1474            end
1475            SubDirOutNew=[r(1).root num2str(str2num(r(1).num1)+1)];%increment the index by 1 or put 1
1476            detect=exist(fullfile(Series.InputTable{1,1},SubDirOutNew),'dir');% test if  the dir  already exists   
1477            check_create=1;
[408]1478        end
1479    end
[448]1480    Series.OutputDirExt=regexprep(SubDirOutNew,Series.OutputSubDir,'');
[446]1481    Series.OutputSubDir=SubDirOutNew;
1482    Series.OutputDir=fullfile(Series.InputTable{1,1},Series.OutputSubDir);%directory set for output results
1483    Series.OutputRootFile=Series.InputTable{1,3};% the first sorted RootFile taken for output
[448]1484    set(handles.OutputDirExt,'String',Series.OutputDirExt)
[450]1485    %removes redondant information
1486    Series=rmfield(Series,'OutputDirExt');
1487    Series.IndexRange=rmfield(Series.IndexRange,'TimeTable');
1488    Series.IndexRange=rmfield(Series.IndexRange,'MinIndex');
1489    Series.IndexRange=rmfield(Series.IndexRange,'MaxIndex');
[446]1490    % create output directory
[448]1491    if check_create
[446]1492        [tild,msg1]=mkdir(Series.OutputDir);
1493        if ~strcmp(msg1,'')
1494            errormsg=['cannot create ' Series.OutputDir ': ' msg1];%error message for directory creation
1495            return
[421]1496        end
[408]1497    end
[446]1498    filexml=fullfile(Series.OutputDir,[Series.InputTable{1,3} '.xml']);% name of the parameter xml file set in this directory
[456]1499%     t=struct2xml(Series);
1500%     t=set(t,1,'name','Series');
1501%     save(t,filexml);
[408]1502end
1503
[41]1504%------------------------------------------------------------------------
[446]1505% --- Executes on selection change in ActionName.
1506function ActionName_Callback(hObject, eventdata, handles)
[41]1507%------------------------------------------------------------------------
[205]1508global nb_builtin_ACTION
[446]1509list_ACTION=get(handles.ActionName,'String');% list menu fields
1510index_ACTION=get(handles.ActionName,'Value');% selected string index
[2]1511ACTION= list_ACTION{index_ACTION}; % selected function name
1512path_series=which('series');%path to series.m
[446]1513list_path=get(handles.ActionName,'UserData');%list of recorded paths to functions of the list ACTION
[39]1514default_file=fullfile(list_path{end},ACTION);
[29]1515% add a new function to the menu if the selected item is 'more...'
[2]1516if isequal(ACTION,'more...')
1517    pathfct=fileparts(path_series);
1518    [FileName, PathName, filterindex] = uigetfile( ...
1519       {'*.m', ' (*.m)';
1520        '*.m',  '.m files '; ...
1521        '*.*', 'All Files (*.*)'}, ...
[39]1522        'Pick a file',default_file);
[2]1523    if length(FileName)<2
1524        return
[29]1525    end
1526    [pp,ACTION,ext_fct]=fileparts(FileName);%(end-1:end);
[2]1527    if ~isequal(ext_fct,'.m')
1528        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
1529        return
1530    end
1531   
[446]1532   % insert the choice in the actionname menu
1533   menu_str=update_menu(handles.ActionName,ACTION);%new action menu in which the new item has been appended if needed
1534   index_ACTION=get(handles.ActionName,'Value');% currently selected index in the list
[2]1535   list_path{index_ACTION}=PathName;
[205]1536   if length(menu_str)>nb_builtin_ACTION+5; %nb_builtin=nbre of functions always remaining in the initial menu
1537       nbremove=length(menu_str)-nb_builtin_ACTION-5;
1538       menu_str(nb_builtin_ACTION+1:end-5)=[];
1539       list_path(nb_builtin_ACTION+1:end-4)=[];
[2]1540       index_ACTION=index_ACTION-nbremove;
[446]1541       set(handles.ActionName,'Value',index_ACTION)
1542       set(handles.ActionName,'String',menu_str)
[2]1543   end
1544   list_path{index_ACTION}=PathName;
[446]1545   set(handles.ActionName,'UserData',list_path);
1546   set(handles.ActionPath,'enable','inactive')% indicate that the current path is accessible (not 'off')
[2]1547   
1548   %record the current menu in personal file profil_perso
1549   dir_perso=prefdir;
1550   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
[205]1551   for ilist=nb_builtin_ACTION+1:length(menu_str)-1
1552       series_fct{ilist-nb_builtin_ACTION}=fullfile(list_path{ilist},[menu_str{ilist} '.m']);     
[2]1553   end
[206]1554   if nb_builtin_ACTION+1<=length(menu_str)-1
1555       if exist(profil_perso,'file')% && nb_builtin_ACTION+1>=length(menu_str)-1
1556           save(profil_perso,'series_fct','-append')
1557       else
1558           txt=ver('MATLAB');
1559           Release=txt.Release;
1560           relnumb=str2num(Release(3:4));
1561           if relnumb >= 14%recent relaese of Matlab
1562               save(profil_perso,'series_fct','-V6')
1563           else
1564               save(profil_perso, 'series_fct')
1565           end
1566       end
[2]1567   end
1568end
1569
[446]1570%check the current ActionPath to the selected function
[2]1571PathName=list_path{index_ACTION};%current recorded path
[446]1572set(handles.ActionPath,'String',PathName); %show the path to the senlected function
[2]1573
1574%default setting for the visibility of the GUI elements
[339]1575set(handles.num_NbSlice,'Visible','off')
[2]1576set(handles.NbSlice_title,'Visible','off')
[446]1577set(handles.VelType,'Visible','off');
[2]1578set(handles.VelType_text,'Visible','off');
[446]1579set(handles.VelType_1,'Visible','off');
[2]1580set(handles.VelType_text_1,'Visible','off');
1581view_FieldMenu(handles,'off')
1582view_FieldMenu_1(handles,'off')
[339]1583set(handles.FieldTransform,'Visible','off')
[446]1584set(handles.CheckObject,'Visible','off');
1585set(handles.ProjObject,'Visible','off');
1586set(handles.CheckMask,'Visible','off')
[2]1587set(handles.Mask,'Visible','off')
[446]1588% set(handles.OutputDirExt,'Visible','off');
[2]1589set(handles.ParamKey,'Visible','off')
1590set(handles.ParamVal,'Visible','off')
1591ParamKey={};
[446]1592set(handles.FieldName,'Enable','off')
1593set(handles.VelType,'Enable','off')
1594set(handles.FieldName_1,'Enable','off')
1595set(handles.VelType_1,'Enable','off')
1596set(handles.TransformName,'Enable','off')
1597set(handles.OutputDirExt,'Visible','off')
1598set(handles.OutputSubDir,'Visible','off')
1599set(handles.OutputDir_title,'Visible','off')
[2]1600%set the displayed GUI item needed for input parameters
[29]1601if ~isequal(path_series,PathName)
1602    addpath(PathName)
1603end
1604eval(['h_function=@' ACTION ';']);
[244]1605try
1606    [fid,errormsg] =fopen([ACTION '.m']);
1607    InputText=textscan(fid,'%s',1,'delimiter','\n');
1608    fclose(fid)
[456]1609    set(handles.ActionName,'ToolTipString',InputText{1}{1})% put the first line of the selected function as tooltip help
[244]1610end
[29]1611if ~isequal(path_series,PathName)
1612    rmpath(PathName)
1613end
1614varargout=h_function();
[2]1615Param_list={};
1616
[372]1617InputTable=get(handles.InputTable,'Data');
1618nb_series=size(InputTable,1);
[2]1619testima_series=1; %test for a list of images only
1620testima=1;
1621testima_1=1;
1622testciv_series=1;
1623for iview=1:nb_series
[372]1624     ext=InputTable{iview,5};
[2]1625    if length(ext)<2
1626        ext='.none';
1627    end
1628    testimaview=~isempty(imformats(ext(2:end))) || isequal(lower(ext),'.avi');
1629    if ~testimaview
1630        if iview==1
1631            testima=0;
1632        end
1633        if iview==2
1634            testima_1=0;
1635        end
1636        testima_series=0;
1637    end
1638end
1639for ilist=1:length(varargout)-1
1640    switch varargout{ilist}
[446]1641        case 'NbViewMax'
1642            if ~isempty (varargout{ilist+1})
1643                if size(InputTable,1)>varargout{ilist+1}
1644                InputTable=InputTable(1:varargout{ilist+1},:);
1645                set(handles.InputTable,'Data',InputTable)
1646                end
1647            end
1648        case 'AllowInputSort'
1649            if isequal(lower(varargout{ilist+1}),'on')% sort the input table by alphabetical order of the SubDir
1650                SeriesData=get(handles.series,'UserData');
1651                SeriesData.AllowInputSort=1;
1652                set(handles.series,'UserData',SeriesData)
[456]1653            end                     
1654        case 'WholeIndexRange'
1655            if isequal(lower(varargout{ilist+1}),'on')% sort the input table by alphabetical order of the SubDir
1656                MinIndex=get(handles.MinIndex,'Data');
1657                MaxIndex=get(handles.MaxIndex,'Data');
1658                if ~isempty(MinIndex)
1659                    set(handles.num_first_i,'String',num2str(MinIndex{1}))
1660                    set(handles.num_last_i,'String',num2str(MaxIndex{1}))
1661                    set(handles.num_incr_i,'String','1')
1662                    if size(MinIndex,2)>=2
1663                        set(handles.num_first_j,'String',num2str(MinIndex{1,2}))
1664                        set(handles.num_last_j,'String',num2str(MaxIndex{1,2}))
1665                        set(handles.num_incr_j,'String','1')
1666                    end
1667                end
1668            end           
[2]1669        case 'NbSlice'   %hidden by default
1670            if isequal(lower(varargout{ilist+1}),'on')
[339]1671                set(handles.num_NbSlice,'Visible','on')
[2]1672                set(handles.NbSlice_title,'Visible','on')
1673            end
[446]1674        case 'VelType'   %hidden by default
[372]1675             if isequal(lower(varargout{ilist+1}),'one') || isequal(lower(varargout{ilist+1}),'two')
[446]1676                set(handles.VelType,'Enable','on')
[2]1677                if nb_series >=1 && ~testima_series
[446]1678                    set(handles.VelType,'Visible','on')
[2]1679                    set(handles.VelType_text,'Visible','on');
1680                end
[372]1681             end
[2]1682            if isequal(lower(varargout{ilist+1}),'two')
[446]1683                set(handles.VelType_1,'Enable','on')
[2]1684                if nb_series >=2 && ~testima_series
[446]1685                    set(handles.VelType_1,'Visible','on')
[2]1686                    set(handles.VelType_text_1,'Visible','on');
1687                end
1688            end
[446]1689        case 'FieldName'   %hidden by default
[2]1690            if isequal(lower(varargout{ilist+1}),'one')||isequal(lower(varargout{ilist+1}),'two')
[446]1691                set(handles.FieldName,'Enable','on') % test for MenuBorser
[2]1692                if nb_series >=1 && ~testima_series
1693                    view_FieldMenu(handles,'on')
1694                end
1695            end
1696            if isequal(lower(varargout{ilist+1}),'two')
[446]1697                set(handles.FieldName_1,'Enable','on')
[2]1698                if nb_series >=2 && ~testima_1
1699                    view_FieldMenu_1(handles,'on')
1700                end
1701            end
[446]1702        case 'FieldTransform'   %hidden by default
[2]1703            if isequal(lower(varargout{ilist+1}),'on')
[446]1704                set(handles.TransformName,'Enable','on')
[339]1705                set(handles.FieldTransform,'Visible','on')
[2]1706            end
[446]1707        case 'ProjObject'   %hidden by default
[2]1708            if isequal(lower(varargout{ilist+1}),'on')   
[446]1709                set(handles.CheckObject,'Visible','on')
1710                set(handles.ProjObject,'Visible','on')
[2]1711            end
1712        case 'Mask'   %hidden by default
1713            if isequal(lower(varargout{ilist+1}),'on')   
[446]1714                set(handles.Mask,'Visible','on')
1715                 set(handles.CheckMask,'Visible','on');
[2]1716            end
[446]1717        case 'PARAMETER'  % NOT USED
[2]1718            set(handles.PARAMETERS_frame,'Visible','on')
1719            set(handles.PARAMETERS_title,'Visible','on')
1720            set(handles.ParamKey,'Visible','on')
1721            %set(handles.ParamVal,'Visible','on')
1722            Param_str=varargout{ilist+1};
[446]1723            Param_list=[Param_list; {Param_str}];   
1724        case 'OutputDirExt'
1725            if ~isempty(varargout{ilist+1})
1726            set(handles.OutputDirExt,'String',varargout{ilist+1})
1727            set(handles.OutputDirExt,'Visible','on')
1728            set(handles.OutputSubDir,'Visible','on')
1729            set(handles.OutputDir_title,'Visible','on') 
1730            end
[2]1731    end
1732end
1733if ~isempty(Param_list)
1734    set(handles.ParamKey,'String',Param_list)
1735    set(handles.ParamVal,'Visible','on')
1736end
1737
[41]1738%------------------------------------------------------------------------
[446]1739% --- Executes on selection change in FieldName.
1740function FieldName_Callback(hObject, eventdata, handles)
[41]1741%------------------------------------------------------------------------
[446]1742field_str=get(handles.FieldName,'String');
1743field_index=get(handles.FieldName,'Value');
[2]1744field=field_str{field_index(1)};
1745if isequal(field,'get_field...')   
1746     hget_field=findobj(allchild(0),'name','get_field');
1747     if ~isempty(hget_field)
1748         delete(hget_field)%delete opened versions of get_field
1749     end
[453]1750     filecell=get_file_series(read_GUI(handles.series));
[428]1751     if exist(filecell{1,1},'file')
1752        get_field(filecell{1,1})
[2]1753     end
1754elseif isequal(field,'more...')
1755    str=calc_field;
1756    [ind_answer,v] = listdlg('PromptString','Select a file:',...
1757                'SelectionMode','single',...
1758                'ListString',str);
[446]1759       % edit the choice in the fields and actionname menu
[2]1760     scalar=cell2mat(str(ind_answer));
[446]1761     update_menu(handles.FieldName,scalar)
[2]1762end
1763
[41]1764%------------------------------------------------------------------------
[446]1765% --- Executes on selection change in FieldName_1.
1766function FieldName_1_Callback(hObject, eventdata, handles)
[41]1767%------------------------------------------------------------------------
[446]1768field_str=get(handles.FieldName_1,'String');
1769field_index=get(handles.FieldName_1,'Value');
[2]1770field=field_str{field_index};
1771if isequal(field,'get_field...')   
1772     hget_field=findobj(allchild(0),'name','get_field_1');
1773     if ~isempty(hget_field)
1774         delete(hget_field)
1775     end
[332]1776     SeriesData=get(handles.series,'UserData');
[2]1777     filename=SeriesData.CurrentInputFile_1;
1778     if exist(filename,'file')
1779        hget_field=get_field(filename);
1780        set(hget_field,'name','get_field_1')
1781     end
1782elseif isequal(field,'more...')
1783    str=calc_field;
1784    [ind_answer,v] = listdlg('PromptString','Select a file:',...
1785                'SelectionMode','single',...
1786                'ListString',str);
[446]1787       % edit the choice in the fields and actionname menu
[2]1788     scalar=cell2mat(str(ind_answer));
[446]1789     update_menu(handles.FieldName_1,scalar)
[2]1790end   
[29]1791
[244]1792
[2]1793%%%%%%%%%%%%%
1794function [ind_remove]=find_pairs(dirpair,ind_i,last_i)
[339]1795indsel=ind_i;
1796indiff=diff(ind_i); %test index increment to detect multiplets (several pairs with the same index ind_i) and holes in the series
1797indiff=[1 indiff last_i-ind_i(end)+1];%for testing gaps with the imposed bounds
1798if ~isempty(indiff)
1799    indiff2=diff(indiff);
1800    indiffp=[indiff2 1];
1801    indiffm=[1 indiff2];
1802    ind_multi_m=find((indiff==0)&(indiffm<0))-1;%indices of first members of multiplets
1803    ind_multi_p=find((indiff==0)&(indiffp>0));%indices of last members of multiplets
1804    %for each multiplet, select the most recent file
1805    ind_remove=[];
1806    for i=1:length(ind_multi_m)
1807        ind_pairs=ind_multi_m(i):ind_multi_p(i);
1808        for imulti=1:length(ind_pairs)
1809            datepair(imulti)=datenum(dirpair(ind_pairs(imulti)).date);%dates of creation
[2]1810        end
[339]1811        [datenew,indsort2]=sort(datepair); %sort the multiplet by creation date
1812        ind_s=indsort2(1:end-1);%
1813        ind_remove=[ind_remove ind_pairs(ind_s)];%remove these indices, leave the last one
1814    end
1815end
[2]1816
[89]1817%------------------------------------------------------------------------
[408]1818% --- determine the list of index pairstring of processing file
[32]1819function [num_i1,num_i2,num_j1,num_j2,num_i_out,num_j_out]=find_file_indices(num_i,num_j,ind_shift,NomType,mode)
[89]1820%------------------------------------------------------------------------
[32]1821num_i1=num_i;% set of first image numbers by default
1822num_i2=num_i;
1823num_j1=num_j;
1824num_j2=num_j;
1825num_i_out=num_i;
1826num_j_out=num_j;
[339]1827% if isequal (NomType,'_1-2_1') || isequal (NomType,'_1-2')
1828if isequal(mode,'series(Di)')
[32]1829    num_i1_line=num_i+ind_shift(3);% set of first image numbers
1830    num_i2_line=num_i+ind_shift(4);
1831    % adjust the first and last field number
1832        indsel=find(num_i1_line >= 1);
1833    num_i_out=num_i(indsel);
1834    num_i1_line=num_i1_line(indsel);
1835    num_i2_line=num_i2_line(indsel);
1836    num_j1=meshgrid(num_j,ones(size(num_i1_line)));
1837    num_j2=meshgrid(num_j,ones(size(num_i1_line)));
1838    [xx,num_i1]=meshgrid(num_j,num_i1_line);
1839    [xx,num_i2]=meshgrid(num_j,num_i2_line);
[339]1840elseif isequal (mode,'series(Dj)')||isequal (mode,'bursts')
[32]1841    if isequal(mode,'bursts') %case of bursts (png_old or png_2D)
1842        num_j1=ind_shift(1)*ones(size(num_i));
1843        num_j2=ind_shift(2)*ones(size(num_i));
1844    else
1845        num_j1_col=num_j+ind_shift(1);% set of first image numbers
1846        num_j2_col=num_j+ind_shift(2);
1847        % adjust the first field number
1848        indsel=find((num_j1_col >= 1));   
1849        num_j_out=num_j(indsel);
1850        num_j1_col=num_j1_col(indsel);
1851        num_j2_col=num_j2_col(indsel);
1852        [num_i1,num_j1]=meshgrid(num_i,num_j1_col);
1853        [num_i2,num_j2]=meshgrid(num_i,num_j2_col);
1854    end   
1855end
[2]1856
[41]1857%------------------------------------------------------------------------
[446]1858% --- Executes on button press in CheckObject.
1859function CheckObject_Callback(hObject, eventdata, handles)
[41]1860%------------------------------------------------------------------------
[446]1861% SeriesData=get(handles.series,'UserData');
1862value=get(handles.CheckObject,'Value');
[2]1863if value
[446]1864     set(handles.CheckObject,'BackgroundColor',[1 1 0])%put unactivated buttons to yellow
[76]1865     hset_object=findobj(allchild(0),'tag','set_object');%find the set_object interface handle
[2]1866     if ishandle(hset_object)
[421]1867         uistack(hset_object,'top')% show the GUI set_object if opened
[2]1868     else
[41]1869         %get the object file
[376]1870         InputTable=get(handles.InputTable,'Data');
1871         defaultname=InputTable{1,1};
[106]1872         if isempty(defaultname)
1873            defaultname={''};
1874         end
[41]1875        [FileName, PathName, filterindex] = uigetfile( ...
1876       {'*.xml;*.mat', ' (*.xml,*.mat)';
1877       '*.xml',  '.xml files '; ...
1878        '*.mat',  '.mat matlab files '}, ...
[427]1879        'Pick an xml object file (or use uvmat to create it)',defaultname);
[41]1880        fileinput=[PathName FileName];%complete file name
1881        sizf=size(fileinput);
1882        if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
1883        %read the file
[427]1884        data=xml2struct(fileinput);
[446]1885        if ~isfield(data,'Type')
1886             msgbox_uvmat('ERROR',[fileinput ' is not an object xml file'])
1887             return
[41]1888        end
1889        if ~isfield(data,'ProjMode')
[446]1890             data.ProjMode='none';
[41]1891        end
[446]1892        hset_object=set_object(data);% call the set_object interface
[2]1893     end
[446]1894     Object=read_GUI(hset_object);
1895     set(handles.ProjObject,'String',Object.Name);%display the object name
[2]1896else
[446]1897    set(handles.CheckObject,'BackgroundColor',[0.7 0.7 0.7])%put activated buttons to green
[2]1898end
[446]1899%set(handles.series,'UserData',SeriesData)
[2]1900
1901%--------------------------------------------------------------
[446]1902function CheckMask_Callback(hObject, eventdata, handles)
1903value=get(handles.CheckMask,'Value');
[2]1904if value
[41]1905    msgbox_uvmat('ERROR','not implemented yet')
[2]1906end
1907%--------------------------------------------------------------
1908
[41]1909%-------------------------------------------------------------------
[2]1910%'uv_ncbrowser': interactively calls the netcdf file browser 'get_field.m'
1911function ncbrowser_uvmat(hObject, eventdata)
[41]1912%-------------------------------------------------------------------
[2]1913     bla=get(gcbo,'String');
1914     ind=get(gcbo,'Value');
1915     filename=cell2mat(bla(ind));
1916      blank=find(filename==' ');
1917      filename=filename(1:blank-1);
1918     get_field(filename)
1919
[41]1920% ------------------------------------------------------------------
[2]1921function MenuHelp_Callback(hObject, eventdata, handles)
[41]1922%-------------------------------------------------------------------
[2]1923path_to_uvmat=which ('uvmat');% check the path of uvmat
1924pathelp=fileparts(path_to_uvmat);
[36]1925helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
1926if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
[2]1927else
[36]1928    addpath (fullfile(pathelp,'uvmat_doc'))
1929    web([helpfile '#series'])
[2]1930end
1931
[41]1932%-------------------------------------------------------------------
[446]1933% --- Executes on selection change in TransformName.
1934function TransformName_Callback(hObject, eventdata, handles)
[41]1935%-------------------------------------------------------------------
[39]1936global nb_transform
[2]1937
[446]1938menu=get(handles.TransformName,'String');
1939ind_coord=get(handles.TransformName,'Value');
[39]1940coord_option=menu{ind_coord};
[446]1941list_transform=get(handles.TransformName,'UserData');
[39]1942ff=functions(list_transform{end});
1943if isequal(coord_option,'more...');
1944    coord_fct='';
1945    prompt = {'Enter the name of the transform function'};
1946    dlg_title = 'user defined transform';
1947    num_lines= 1;
1948    [FileName, PathName, filterindex] = uigetfile( ...
1949       {'*.m', ' (*.m)';
1950        '*.m',  '.m files '; ...
1951        '*.*', 'All Files (*.*)'}, ...
1952        'Pick a file', ff.file);
1953    if isequal(PathName(end),'/')||isequal(PathName(end),'\')
1954        PathName(end)=[];
1955    end
1956    transform_selected =fullfile(PathName,FileName);
1957    if ~exist(transform_selected,'file')
1958          return
1959    end
1960    [ppp,transform,xt_fct]=fileparts(FileName);% removes extension .m
1961    if ~isequal(ext_fct,'.m')
1962        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
1963        return
1964    end
[446]1965   menu=update_menu(handles.TransformName,transform);%add the selected fct to the menu
1966   ind_coord=get(handles.TransformName,'Value');
[39]1967   addpath(PathName)
1968   list_transform{ind_coord}=str2func(transform);% create the function handle corresponding to the newly seleced function
[446]1969   set(handles.TransformName,'UserData',list_transform)
[39]1970   rmpath(PathName)
1971   % save the new menu in the personal file 'uvmat_perso.mat'
1972   dir_perso=prefdir;%personal Matalb directory
1973   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1974   if exist(profil_perso,'file')
1975       for ilist=nb_transform+1:numel(list_transform)
[55]1976           ff=functions(list_transform{ilist});
[39]1977           transform_fct{ilist-nb_transform}=ff.file;
1978       end
1979        save (profil_perso,'transform_fct','-append'); %store the root name for future opening of uvmat
1980   end
1981end
[2]1982
[446]1983%check the current ActionPath to the selected function
[248]1984if ~isempty(list_transform{ind_coord})
[39]1985func=functions(list_transform{ind_coord});
[446]1986set(handles.TransformPath,'String',fileparts(func.file)); %show the path to the senlected function
[248]1987else
[446]1988   set(handles.TransformPath,'String',''); %show the path to the senlected function
[248]1989end
[350]1990
[446]1991% %------------------------------------------------------------------------
1992% % --- Executes on button press in REFRESH_INDICES.
1993%     function REFRESH_INDICES_Callback(hObject, eventdata, handles)
1994% %------------------------------------------------------------------------       
1995% % hObject    handle to REFRESH_INDICES (see GCBO)
1996% % eventdata  reserved - to be defined in a future version of MATLAB
1997% % handles    structure with handles and user data (see GUIDATA)
1998% set(handles.REFRESH_INDICES,'BackgroundColor',[0.7 0.7 0.7])
1999% InputTable=get(handles.InputTable,'Data');
2000% check_lines=get(handles.REFRESH_INDICES,'UserData');
2001%
2002% %% check the indices and FileTypes for each series (limited to the new ones to save time)
2003% for ind_list=1:length(check_lines)
2004%     if  check_lines(ind_list)
2005%         InputLine=InputTable(ind_list,:);
2006%         detect_idem=strcmp('"',InputLine);% look for '" (repeat of previous data)
2007%         detect_idem=detect_idem(detect_idem>0);
2008%         if ~isempty (detect_idem)
2009%             InputLine(detect_idem)=InputTable(ind_list-1,detect_idem);
2010%             set(handles.InputTable,'Data',InputTable)
2011%         end
2012%         fileinput=fullfile_uvmat(InputLine{1},InputLine{2},InputLine{3},InputLine{5},InputLine{4},1,2,1,2);
2013%         %fileinput=name_generator(fullfile(InputLine{1},InputLine{3}),1,1,InputLine{5},InputLine{4},1,2,2,InputLine{2})
2014%         %update file series defined by the selected line
2015%         [InputTable{ind_list,3},InputTable{(ind_list),4},errormsg]=update_indices(handles,fileinput,ind_list);
2016%         if ~isempty(errormsg)
2017%                 msgbox_uvmat('ERROR',errormsg)
2018%                 return
2019%         end
2020%     end
2021% end
2022% set(handles.InputTable,'Data',InputTable)
2023% SeriesData=get(handles.series,'UserData');
2024%
2025% state_j='off';
2026% state_Pairs='off';
2027% state_InputFields='off';
2028% val=get(handles.ListView,'Value');
2029% ListViewString={''};
2030% if ~isempty(SeriesData)
2031% %     ListViewString={};
2032%     for iview=1:size(InputTable,1)
2033%         if ~isempty(SeriesData.j1_series{iview})
2034%             state_j='on';
2035%         end
2036%         if ~isempty(SeriesData.i2_series{iview})||~isempty(SeriesData.j2_series{iview})
2037%             state_Pairs='on';
2038%             ListViewString{iview}=num2str(iview);
2039%             if check_lines(iview)
2040%                 val=iview;%select the last pair if it is a new entry
2041%             end
2042%         end
2043%         if strcmp(SeriesData.FileType{iview},'civx')||strcmp(SeriesData.FileType{iview},'civdata')
2044%             state_InputFields='on';
2045%         end
2046%     end
2047% end
2048% set(handles.ListView,'Value',val)
2049% set(handles.ListView,'String',ListViewString)
2050% if strcmp(state_Pairs,'on')
2051%     ListView_Callback(hObject,eventdata,handles)
2052% end
2053% set(handles.PairString,'Visible',state_Pairs)
2054% enable_j(handles,state_j)
2055% set(handles.REFRESH_INDICES,'BackgroundColor',[1 0 0])
2056% set(handles.REFRESH_INDICES,'visible','off')
[350]2057
[372]2058% -----------------------------------------------------------------------
2059% --- Update min and max indices of a file series by scanning with find_file_series
2060% --- which also changes the root file and NomType in case of movie. Also adjust the string representation of indices (e.g;
2061% --- 1 or 001 by the function find_file_series
2062% --- This function also dispaly the set of availbale files in the series
2063% --- and the menus appropriate to the file type as well as timing possibly set
2064% --- by an xml image documentation file
2065function [RootFile,NomType,errormsg]=update_indices(handles,fileinput,iview)
2066% -----------------------------------------------------------------------
[350]2067%% look for min and max indices existing in the file series and update SeriesData
2068errormsg='';
[398]2069[FilePath,FileName,FileExt]=fileparts(fileinput);
2070% detect the file type, get the movie object if relevant, and look for the corresponding file series:
2071% the root name and indices may be corrected by including the first index i1 if a corresponding xml file exists
2072[RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,NomType,FileType,Object,i1,i2,j1,j2]=find_file_series(FilePath,[FileName FileExt]);
[350]2073if isempty(RootFile)&&isempty(i1_series)
[358]2074    errormsg='no input file in the series';
[350]2075    return
2076end
2077
[408]2078%% adjust the min and max indices common to all the file series
[350]2079MinIndex=get(handles.MinIndex,'Data');
2080MaxIndex=get(handles.MaxIndex,'Data');
2081MinIndex_i=min(i1_series(i1_series>0));
2082if ~isempty(i2_series)
2083    MaxIndex_i=max(i2_series(i2_series>0));
2084else
2085    MaxIndex_i=max(i1_series(i1_series>0));
2086end
2087MinIndex_j=min(j1_series(j1_series>0));
2088if ~isempty(j2_series)
2089    MaxIndex_j=max(j2_series(j2_series>0));
2090else
2091    MaxIndex_j=max(j1_series(j1_series>0));
2092end
[358]2093MinIndex{iview,1}=MinIndex_i;
2094MinIndex{iview,2}=MinIndex_j;
2095MaxIndex{iview,1}=MaxIndex_i;
2096MaxIndex{iview,2}=MaxIndex_j;
[350]2097set(handles.MinIndex,'Data',MinIndex)
2098set(handles.MaxIndex,'Data',MaxIndex)
2099SeriesData=get(handles.series,'UserData');
[358]2100SeriesData.i1_series{iview}=i1_series;
2101SeriesData.i2_series{iview}=i2_series;
2102SeriesData.j1_series{iview}=j1_series;
2103SeriesData.j2_series{iview}=j2_series;
2104SeriesData.FileType{iview}=FileType;
[350]2105
[372]2106%% display the set of existing files as an image
[350]2107set(handles.waitbar_frame,'Units','pixels')
2108pos=get(handles.waitbar_frame,'Position');
2109xima=0.5:pos(3)-0.5;% pixel positions on the image representing the existing file indices
2110yima=0.5:pos(4)-0.5;
2111[XIma,YIma]=meshgrid(xima,yima);
2112nb_i=size(i1_series,1);
2113nb_j=size(i1_series,2);
2114ind_i=(0.5:nb_i-0.5)*pos(3)/nb_i;
2115ind_j=(0.5:nb_j-0.5)*pos(4)/nb_j;
2116[Ind_i,Ind_j]=meshgrid(ind_i,ind_j);
2117CData=zeros([size(XIma) 3]);
2118file_ima=double((i1_series(:,:,1)>0)');
2119if numel(file_ima)>=2
2120if size(file_ima,1)==1
2121    CLine=interp1(ind_i,file_ima,xima,'nearest');
2122    CData(:,:,2)=ones(size(yima'))*CLine;
2123else
2124    CData(:,:,2)=interp2(Ind_i,Ind_j,file_ima,XIma,YIma,'nearest');
2125end
2126set(handles.waitbar_frame,'CData',CData)
2127end
2128set(handles.waitbar_frame,'Units','normalized')
2129
2130%% enable field and veltype menus
[446]2131testfield=isequal(get(handles.FieldName,'enable'),'on');
2132testfield_1=isequal(get(handles.FieldName_1,'enable'),'on');
2133testveltype=isequal(get(handles.VelType,'enable'),'on');
2134testveltype_1=isequal(get(handles.VelType_1,'enable'),'on');
2135testtransform=isequal(get(handles.TransformName,'Enable'),'on');
[372]2136% testnc=0;
2137% testnc_1=0;
2138% testcivx=0;
2139% testcivx_1=0;
2140% testima=0; %test for image input
2141% if isequal(lower(FileExt),'.avi') %.avi file
2142%     testima=1;
2143% elseif ~isempty(imformats(FileExt(2:end)))
2144%     testima=1;
2145% elseif isequal(FileExt,'.vol')
2146%      testima=1;
2147% end
[350]2148%TODO: update
2149% if length(FileExtCell)==1 || length(FileExtCell)>2
2150%     for iview=1:length(FileExtCell)
2151%         if isequal(FileExtCell{iview},'.nc')
2152%             testnc=1;
2153%         end
2154%         if isequal(FileTypeCell{iview},'civx')
2155%             testcivx=1;
2156%         end
2157%     end
2158% elseif length(FileExtCell)==2
2159%     testnc=isequal(FileExtCell{1},'.nc');
2160%     testnc_1=isequal(FileExtCell{2},'.nc');
2161%     testcivx=isequal(FileTypeCell{1},'civx');
2162%     testcivx_1=isequal(FileTypeCell{2},'civx');
2163% end
[372]2164switch FileType
2165    case {'civx','civdata'}
[350]2166    view_FieldMenu(handles,'on')
[446]2167    menustr=get(handles.FieldName,'String');
[372]2168    if isequal(menustr,{'get_field...'})
[446]2169        set(handles.FieldName,'String',{'get_field...';'velocity';'vort';'div';'more...'})
[350]2170    end
[446]2171    set(handles.VelType,'Visible','on')
[372]2172    set(handles.FieldTransform,'Visible','on')
2173    %      view_TRANSFORM(handles,'on')
2174    %     TODO: second menu
2175    %           view_FieldMenu_1(handles,'on')
2176    %     if testcivx_1
[446]2177    %         menustr=get(handles.FieldName_1,'String');
[372]2178    %         if isequal(menustr,{'get_field...'})
[446]2179    %             set(handles.FieldName_1,'String',{'get_field...';'velocity';'vort';'div';'more...'})
[372]2180    %         end
2181    %     else
[446]2182    %         set(handles.FieldName_1,'Value',1)
2183    %         set(handles.FieldName_1,'String',{'get_field...'})
2184    %     set(handles.VelType_1,'Visible','on')
[372]2185    %     set(handles.VelType_text_1,'Visible','on');
2186    %     end
2187    %     view_FieldMenu_1(handles,'off')
2188    case 'netcdf'
2189    view_FieldMenu(handles,'on')
[446]2190    set(handles.FieldName,'Value',1)
2191    set(handles.FieldName,'String',{'get_field...'})
[372]2192    set(handles.FieldTransform,'Visible','off')
2193    %     view_TRANSFORM(handles,'off')
2194    case {'image','multimage','video'}
[350]2195    view_FieldMenu(handles,'off')
2196    view_FieldMenu_1(handles,'off')
[446]2197    set(handles.VelType,'Visible','off')
[350]2198    set(handles.VelType_text,'Visible','off');
2199end
[372]2200
2201
[350]2202%TODO:update
2203% if ~isequal(FileExt,'.nc') && ~isequal(FileExt,'.cdf') && ~testima
2204%     msgbox_uvmat('ERROR',['invalid input file extension ' FileExt])
2205%     return
2206% end 
2207
2208%%  read image documentation file  if found%%%%%%%%%%%%%%%%%%%%%%%%%%%
2209ext_imadoc='';
[398]2210FileBase=fullfile(RootPath,RootFile);
[350]2211if isequal(FileExt,'.xml')||isequal(FileExt,'.civ')
2212    ext_imadoc=FileExt;
2213elseif exist([FileBase '.xml'],'file')
2214    ext_imadoc='.xml';
2215elseif exist([FileBase '.civ'],'file')
2216    ext_imadoc='.civ';
2217end
2218%read the ImaDoc file
2219XmlData=[];
2220NbSlice_calib={};
2221if isequal(ext_imadoc,'.xml')
2222        [XmlData,warntext]=imadoc2struct([FileBase '.xml']);
2223        if isfield(XmlData,'Heading') && isfield(XmlData.Heading,'ImageName') && ischar(XmlData.Heading.ImageName)
2224            [PP,FF,ext_ima_read]=fileparts(XmlData.Heading.ImageName);
2225        end
2226        if isfield(XmlData,'Time')
[408]2227            time{iview}=XmlData.Time;
[350]2228        end
2229        if isfield(XmlData,'Camera')
2230            if isfield(XmlData.Camera,'NbSlice')&& ~isempty(XmlData.Camera.NbSlice)
2231                NbSlice_calib{iview}=XmlData.Camera.NbSlice;% Nbre of slices for Zindex in phys transform
2232                if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
2233                    msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
2234                end
2235            end
2236            if isfield(XmlData.Camera,'TimeUnit')&& ~isempty(XmlData.Camera.TimeUnit)
2237                TimeUnit=XmlData.Camera.TimeUnit;
2238            end
2239        end
2240        if ~isempty(warntext)
2241            msgbox_uvmat('WARNING',warntext)
2242        end 
2243elseif isequal(ext_imadoc,'.civ')
2244    [error,XmlData.Time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([FileBase '.civ']);
[408]2245    time{iview}=XmlData.Time;
[350]2246    if error==2, warntext=['no file ' FileBase '.civ'];
2247    elseif error==1, warntext='inconsistent number of fields in the .civ file';
2248    end 
[408]2249end
[350]2250
[408]2251%% update time table
[446]2252TimeTable=get(handles.TimeTable,'Data');
[408]2253TimeTable{iview,1}=time(MinIndex_i,MinIndex_j);
2254TimeTable{iview,4}=time(MaxIndex_i,MaxIndex_j);
2255set(handles.TimeTable,'Data',TimeTable)
[350]2256
2257%% number of slices
2258if isfield(XmlData,'GeometryCalib') && isfield(XmlData.GeometryCalib,'SliceCoord')
2259       siz=size(XmlData.GeometryCalib.SliceCoord);
2260       if siz(1)>1
2261           NbSlice=siz(1);
2262       else
2263           NbSlice=1;
2264       end
2265       set(handles.num_NbSlice,'String',num2str(NbSlice))
2266end
[408]2267% set(handles.mode,'Visible','off') % do not show index pairstring by default
2268set(handles.PairString,'Visible','off')
2269% set(handles.num_ref_i,'Visible','off')
[350]2270% set(handles.ref_i_text,'Visible','off')
2271testpair=0;
[408]2272%set the menus of image pairstring and default selection for series
2273%list pairstring if relevant
[350]2274% Val=get(handles.NomType,'Value');
2275% synchronise_view(handles,Val)
2276
2277% if ~isfield(SeriesData,'j1_series')||isempty(SeriesData.j1_series{index})
2278%     state_j='off'; %no need for j index
2279% else
2280%     state_j='on'; %case of j index
2281% end
[408]2282% show index pairstring if files exist
[350]2283set(handles.series,'UserData',SeriesData)
2284
[351]2285
[446]2286% --------------------------------------------------------------------
2287function MenuExportConfig_Callback(hObject, eventdata, handles)
2288global Series
2289[tild,Series,errormsg]=prepare_jobs(handles);
2290% Series=read_GUI(handles.series);
[358]2291
[446]2292evalin('base','global Series')%make CurData global in the workspace
2293display('current series config :')
2294evalin('base','Series') %display CurData in the workspace
2295commandwindow; %brings the Matlab command window to the front
Note: See TracBrowser for help on using the repository browser.