source: trunk/src/series.m @ 767

Last change on this file since 767 was 767, checked in by sommeria, 11 years ago

Setpairs improved in series

File size: 136.0 KB
Line 
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)
8%      .menu_coord_str: string for the TransformName (menu for coordinate transforms)
9%      .menu_coord_val: value for TransformName (menu for coordinate transforms)
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
32%------------------------------------------------------------------------
33%------------------------------------------------------------------------
34%  I - MAIN FUNCTION series
35%------------------------------------------------------------------------
36%------------------------------------------------------------------------
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)
62
63% Choose default command line output for series
64handles.output = hObject;
65% Update handles structure
66guidata(hObject, handles);
67
68%% initial settings
69% position and  size of the GUI at opening
70set(0,'Unit','points')
71ScreenSize=get(0,'ScreenSize');%size of the current screen, in points (1/72 inch)
72Width=900;% prefered width of the GUI in points (1/72 inch)
73Height=624;% prefered height of the GUI in points (1/72 inch)
74%adjust to screen size (reduced by a min margin)
75RescaleFactor=min((ScreenSize(3)-80)/Width,(ScreenSize(4)-80)/Height);
76if RescaleFactor>1
77    RescaleFactor=min(RescaleFactor,1);
78end
79Width=Width*RescaleFactor;
80Height=Height*RescaleFactor;
81LeftX=80*RescaleFactor;%position of the left fig side, in pixels (put to the left side, with some margin)
82LowY=round(ScreenSize(4)/2-Height/2); % put at the middle height on the screen
83set(hObject,'Units','points')
84set(hObject,'Position',[LeftX LowY Width Height])% position and size of the GUI at opening
85
86% settings of table MinIndex_j
87set(handles.MinIndex_i,'ColumnFormat',{'numeric'})
88set(handles.MinIndex_i,'ColumnEditable',false)
89set(handles.MinIndex_i,'ColumnName',{'i min'})
90set(handles.MinIndex_i,'Data',[])% initiate Data to double (not cell)
91
92% settings of table MinIndex_j
93set(handles.MinIndex_j,'ColumnFormat',{'numeric'})
94set(handles.MinIndex_j,'ColumnEditable',false)
95set(handles.MinIndex_j,'ColumnName',{'j min'})
96set(handles.MinIndex_j,'Data',[])% initiate Data to double (not cell)
97
98% settings of table MaxIndex_i
99set(handles.MaxIndex_i,'ColumnFormat',{'numeric'})
100set(handles.MaxIndex_i,'ColumnEditable',false)
101set(handles.MaxIndex_i,'ColumnName',{'i max'})
102set(handles.MaxIndex_i,'Data',[])% initiate Data to double (not cell)
103
104% settings of table MaxIndex_j
105set(handles.MaxIndex_j,'ColumnFormat',{'numeric'})
106set(handles.MaxIndex_j,'ColumnEditable',false)
107set(handles.MaxIndex_j,'ColumnName',{'j max'})
108set(handles.MaxIndex_j,'Data',[])% initiate Data to double (not cell)
109
110% settings of table PairString
111set(handles.PairString,'ColumnName',{'pairs'})
112set(handles.PairString,'ColumnEditable',false)
113set(handles.PairString,'ColumnFormat',{'char'})
114set(handles.PairString,'Data',{''})
115
116% settings of table MaskTable
117set(handles.MaskTable,'ColumnName',{'mask name'})
118set(handles.PairString,'ColumnEditable',false)
119set(handles.PairString,'ColumnFormat',{'char'})
120set(handles.PairString,'Data',{''})
121
122series_ResizeFcn(hObject, eventdata, handles)%resize table according to series GUI size
123set(hObject,'WindowButtonDownFcn',{'mouse_down'})%allows mouse action with right button (zoom for uicontrol display)
124set(handles.InputTable,'KeyPressFcn',{@key_press_fcn,handles})%set keyboard action function (allow action on uvmat when set_object is in front)
125set(hObject,'DeleteFcn',{@closefcn})%
126
127% check default input data
128if ~exist('Param','var')
129    Param=[]; %default
130end
131
132%% list of builtin functions in the mebu ActionName
133ActionList={'check_data_files';'aver_stat';'time_series';'civ_series';'merge_proj'};% WARNING: fits with nb_builtin_ACTION=4 in ActionName_callback
134NbBuiltinAction=numel(ActionList);
135[path_series,name,ext]=fileparts(which('series'));% path to the GUI series
136path_series_fct=fullfile(path_series,'series');%path of the functions in subdirectroy 'series'
137ActionExtList={'.m';'.sh'};% default choice of extensions (Matlab fct .m or compiled version .sh
138ActionPathList=cell(NbBuiltinAction,numel(ActionExtList));%initiate the cell matrix of Action fct paths
139ActionPathList(:)={path_series_fct}; %set the default path to series fcts to all list members
140RunModeList={'local';'background'};% default choice of extensions (Matlab fct .m or compiled version .sh)
141[s,w]=system('oarstat');% look for cluster system 'oar'
142if isequal(s,0)
143    RunModeList=[RunModeList;{'cluster_oar'}];
144end
145[s,w]=system('qstat');% look for cluster system 'sge'
146if isequal(s,0)
147    RunModeList=[RunModeList;{'cluster_sge'}];
148end
149set(handles.RunMode,'String',RunModeList)
150
151%% list of builtin transform functions in the mebu TransformName
152TransformList={'';'sub_field';'phys';'phys_polar'};% WARNING: must fit with the corresponding menu in uvmat and nb_builtin_transform=4 in  TransformName_callback
153NbBuiltinTransform=numel(TransformList);
154path_transform_fct=fullfile(path_series,'transform_field');
155TransformPathList=cell(NbBuiltinTransform,1);%initiate the cell matrix of Action fct paths
156TransformPathList(:)={path_transform_fct}; %set the default path to series fcts to all list members
157
158%% get the user defined functions stored in the personal file uvmat_perso.mat
159dir_perso=prefdir;
160profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
161if exist(profil_perso,'file')
162    h=load (profil_perso);
163    %get the list of previous input files in the upper bar menu Open
164    if isfield(h,'MenuFile')
165        for ifile=1:min(length(h.MenuFile),5)
166            set(handles.(['MenuFile_' num2str(ifile)]),'Label',h.MenuFile{ifile});
167            set(handles.(['MenuFile_' num2str(ifile+5)]),'Label',h.MenuFile{ifile});
168        end
169    end
170    %get the list of previous camapigns in the upper bar menu Open campaign
171    if isfield(h,'MenuCampaign')
172        for ifile=1:min(length(h.MenuCampaign),5)
173            set(handles.(['MenuCampaign_' num2str(ifile)]),'Label',h.MenuCampaign{ifile});
174        end
175    end
176    %get the menu of actions
177    if isfield(h,'ActionExtListUser') && iscell(h.ActionExtListUser)
178        ActionExtList=[ActionExtList; h.ActionExtListUser];
179    end
180    if isfield(h,'ActionListUser') && iscell(h.ActionListUser) && isfield(h,'ActionPathListUser') && iscell(h.ActionPathListUser)
181        ActionList=[ActionList;h.ActionListUser];
182        ActionPathList=[ActionPathList;h.ActionPathListUser];
183    end
184    %get the menu of transform fct
185    if isfield(h,'TransformListUser') && iscell(h.TransformListUser) && isfield(h,'TransformPathListUser') && iscell(h.TransformPathListUser)
186        TransformList=[TransformList;h.TransformListUser];
187        TransformPathList=[TransformPathList;h.TransformPathListUser];
188    end
189end
190
191%% selection of the input Action fct
192ActionCheckExist=true(size(ActionList));%initiate the check of the path to the listed action fct
193for ilist=NbBuiltinAction+1:numel(ActionList)%check  the validity of the path of the user defined Action fct
194    ActionCheckExist(ilist)=exist(fullfile(ActionPathList{ilist},[ActionList{ilist} '.m']),'file');
195end
196ActionPathList=ActionPathList(ActionCheckExist,:);% suppress the menu options which are not valid anymore
197ActionList=ActionList(ActionCheckExist);
198set(handles.ActionName,'String',[ActionList;{'more...'}])
199set(handles.ActionName,'UserData',ActionPathList)
200ActionIndex=[];
201if isfield(Param,'ActionName')% copy the selected menu index transferred in Param from uvmat
202    ActionIndex=find(strcmp(Param.ActionName,ActionList),1);
203end
204if isempty(ActionIndex)
205    ActionIndex=1;
206end
207set(handles.ActionName,'Value',ActionIndex)
208set(handles.ActionPath,'String',ActionPathList{ActionIndex})
209set(handles.ActionExt,'Value',1)
210set(handles.ActionExt,'String',ActionExtList)
211
212%% selection of the input transform fct
213TransformCheckExist=true(size(TransformList));
214for ilist=NbBuiltinTransform+1:numel(TransformList)
215    TransformCheckExist(ilist)=exist(fullfile(TransformPathList{ilist},[TransformList{ilist} '.m']),'file');
216end
217TransformPathList=TransformPathList(TransformCheckExist);
218TransformList=TransformList(TransformCheckExist);
219set(handles.TransformName,'String',[TransformList;{'more...'}])
220set(handles.TransformName,'UserData',TransformPathList)
221TransformIndex=[];
222if isfield(Param,'TransformName')% copy the selected menu index transferred in Param from uvmat
223    TransformIndex=find(strcmp(Param.TransformName,TransformList),1);
224end
225if isempty(TransformIndex)
226    TransformIndex=1;
227end
228set(handles.TransformName,'Value',TransformIndex)
229set(handles.TransformPath,'String',TransformPathList{TransformIndex})
230   
231%% fields input initialisation
232if isfield(Param,'list_fields')&& isfield(Param,'index_fields') &&~isempty(Param.list_fields) &&~isempty(Param.index_fields)
233    set(handles.FieldName,'String',Param.list_fields);% list menu fields
234    set(handles.FieldName,'Value',Param.index_fields);% selected string index
235end
236if isfield(Param,'Coord_x_str')&& isfield(Param,'Coord_x_val')
237        set(handles.Coord_x,'String',Param.Coord_x_str);% list menu fields
238    set(handles.Coord_x,'Value',Param.Coord_x_val);% selected string index
239end
240if isfield(Param,'Coord_y_str')&& isfield(Param,'Coord_y_val')
241        set(handles.Coord_y,'String',Param.Coord_y_str);% list menu fields
242    set(handles.Coord_y,'Value',Param.Coord_y_val);% selected string index
243end
244
245%% introduce the input file name(s) if defined from input Param
246if isfield(Param,'FileName')&&~isempty(Param.FileName)
247    InputTable={};
248    set(handles.InputTable,'Data',InputTable)
249    if isfield(Param,'FileName_1')
250        display_file_name(handles,Param.FileName,'one')%refresh the input table
251        display_file_name(handles,Param.FileName_1,1)
252    else
253        display_file_name(handles,Param.FileName,'one')%refresh the input table
254    end
255end 
256if isfield(Param,'incr_i')
257    set(handles.num_incr_i,'String',num2str(Param.incr_i))
258end
259if isfield(Param,'incr_j')
260    set(handles.num_incr_j,'String',num2str(Param.incr_j))
261end
262set(handles.REFRESH,'BackgroundColor',[1 0 1])% set REFRESH button to magenta color to indicate that input refresh is needed
263
264%------------------------------------------------------------------------
265% --- Outputs from this function are returned to the command line.
266function varargout = series_OutputFcn(hObject, eventdata, handles)
267%------------------------------------------------------------------------
268varargout{1} = handles.output;
269
270%------------------------------------------------------------------------
271% --- executed when closing uvmat: delete or desactivate the associated figures if exist
272function closefcn(gcbo,eventdata)
273%------------------------------------------------------------------------
274
275% delete set_object_series if detected
276hh=findobj(allchild(0),'name','view_object_series');
277if ~isempty(hh)
278    delete(hh)
279end
280hh=findobj(allchild(0),'name','edit_object_series');
281if ~isempty(hh)
282    delete(hh)
283end
284
285%delete the bowser if detected
286hh=findobj(allchild(0),'tag','browser');
287if ~isempty(hh)
288    delete(hh)
289end
290
291
292%------------------------------------------------------------------------
293%------------------------------------------------------------------------
294%  II - FUNCTIONS FOR INTRODUCING THE INPUT FILES
295% automatically sets the global properties when the rootfile name is introduced
296% then activate the view-field actionname if selected
297% it is activated either by clicking on the RootPath window or by the
298% browser
299%------------------------------------------------------------------------
300%------------------------------------------------------------------------
301% --- fct activated by the browser under 'Open'
302%------------------------------------------------------------------------ 
303function MenuBrowse_Callback(hObject, eventdata, handles)
304%% look for the previously opened file 'oldfile'
305InputTable=get(handles.InputTable,'Data');
306oldfile=InputTable{1,1};
307if isempty(oldfile)
308    % use a file name stored in prefdir
309    dir_perso=prefdir;
310    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
311    if exist(profil_perso,'file')
312        h=load (profil_perso);
313        if isfield(h,'RootPath') && ischar(h.RootPath)
314            oldfile=h.RootPath;
315        end
316    end
317end
318%% launch the browser
319fileinput=uigetfile_uvmat('pick an input file in the series',oldfile);
320hh=dir(fileinput);
321if numel(hh)>1
322    msgbox_uvmat('ERROR','invalid input, probably a broken link');
323else
324    if ~isempty(fileinput)
325        display_file_name(handles,fileinput,'one')
326    end
327end
328
329% --------------------------------------------------------------------
330function MenuBrowseAppend_Callback(hObject, eventdata, handles)
331
332%% look for the previously opened file 'oldfile'
333InputTable=get(handles.InputTable,'Data');
334RootPathCell=InputTable(:,1);
335if isempty(RootPathCell{1})% no input file in the table
336     MenuBrowse_Callback(hObject, eventdata, handles)%refresh the input table, not append
337     return
338end
339SubDirCell=InputTable(:,2);
340oldfile=fullfile(RootPathCell{1},SubDirCell{1});
341
342%% use a file name stored in prefdir
343dir_perso=prefdir;
344profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
345if exist(profil_perso,'file')
346    h=load (profil_perso);
347    if isfield(h,'RootPath') && ischar(h.RootPath)
348        oldfile=h.RootPath;
349    end
350end
351
352%% launch the browser
353fileinput=uigetfile_uvmat('pick a file to append in the input table',oldfile);
354hh=dir(fileinput);
355if numel(hh)>1
356    msgbox_uvmat('ERROR','invalid input, probably a broken link');
357else
358    if ~isempty(fileinput)
359        display_file_name(handles,fileinput,'append')
360    end
361end
362
363%------------------------------------------------------------------------
364% --- fct activated by selecting a previous file under the menu Open
365%------------------------------------------------------------------------
366function MenuFile_Callback(hObject, eventdata, handles)
367
368errormsg=display_file_name(handles,get(hObject,'Label'),'one');
369if ~isempty(errormsg)
370    set(hObject,'Label','')
371    MenuFile=[{get(handles.MenuFile_1,'Label')};{get(handles.MenuFile_2,'Label')};...
372        {get(handles.MenuFile_3,'Label')};{get(handles.MenuFile_4,'Label')};{get(handles.MenuFile_5,'Label')}];
373    str_find=strcmp(get(hObject,'Label'),MenuFile);
374    MenuFile(str_find)=[];% suppress the input file to the list
375    for ifile=1:numel(MenuFile)
376        set(handles.(['MenuFile_' num2str(ifile)]),'Label',MenuFile{ifile});
377    end
378end
379
380%------------------------------------------------------------------------
381% --- fct activated by selecting a previous file under the menu Open/append
382%------------------------------------------------------------------------
383function MenuFile_append_Callback(hObject, eventdata, handles)
384
385InputTable=get(handles.InputTable,'Data');
386if isempty(InputTable{1,1})% no input file in the table
387    display_file_name(handles,get(hObject,'Label'),'one') %refresh the input table, not append
388else
389    display_file_name(handles,get(hObject,'Label'),'append')% append the selected file to the current list of InputTable
390end
391
392%------------------------------------------------------------------------
393% --- fct activated by the browser under 'Open campaign'
394%------------------------------------------------------------------------
395function MenuBrowseCampaign_Callback(hObject, eventdata, handles)
396
397set(handles.MenuOpenCampaign,'ForegroundColor',[1 1 0])
398drawnow
399InputTable=get(handles.InputTable,'Data');
400RootPath=InputTable{1,1};
401CampaignPath=fileparts(fileparts(RootPath));
402DirFull=uigetfile_uvmat('define this path as the Campaign folder:',CampaignPath,'uigetdir');
403if ~ischar(DirFull)|| ~exist(DirFull,'dir')
404    return
405end
406OutPut=browse_data(DirFull);% open the GUI browse_data to get select a campaign dir, experiment and device
407if ~isfield(OutPut,'Campaign')
408    return
409end
410DirName=fullfile(OutPut.Campaign,OutPut.Experiment{1},OutPut.DataSeries{1});
411ListStruct=dir(DirName); %list files and the dir DataSeries
412% select the first appropriate file in the dir
413FileName='';
414for ilist=1:numel(ListStruct)
415    if ~isequal(ListStruct(ilist).isdir,1)%look for files, not dir
416        FileName=ListStruct(ilist).name;
417        FileType=get_file_type(fullfile(DirName,FileName));
418        switch FileType
419            case {'image','multimage','civx','civdata','netcdf'}
420                break
421        end
422    end
423end
424if isempty(FileName)
425    msgbox_uvmat('ERROR',['no appropriate input file in the DataSeries folder ' fullfile(DirName)])
426    return
427end
428
429%% update the list of campaigns in the menubar
430MenuCampaign=[{get(handles.MenuCampaign_1,'Label')};{get(handles.MenuCampaign_2,'Label')};...
431    {get(handles.MenuCampaign_3,'Label')};{get(handles.MenuCampaign_4,'Label')};{get(handles.MenuCampaign_5,'Label')}];
432check_dir=isempty(find(strcmp(DirFull,MenuCampaign)));
433if check_dir %insert the new campaign in the list if it is not found
434    MenuCampaign(end)=[]; %suppress the last item
435    MenuCampaign=[{DirFull};MenuCampaign];%insert the new campaign
436    for ilist=1:numel(MenuCampaign)
437        set(handles.(['MenuCampaign_' num2str(ilist)]),'Label',MenuCampaign{ilist})
438    end
439    % save the list for future opening:
440    dir_perso=prefdir;
441    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
442    if exist(profil_perso,'file')
443        save (profil_perso,'MenuCampaign','RootPath','-append'); %store the file names for future opening of uvmat
444    else
445        save (profil_perso,'MenuCampaign','RootPath','-V6'); %store the file names for future opening of uvmat
446    end
447end
448
449%% display the selected field and related information
450if get(handles.CheckAppend,'Value')
451    display_file_name(handles,fullfile(DirName,FileName),'append')
452else
453    display_file_name(handles,fullfile(DirName,FileName),'one')
454end
455set(handles.MenuOpenCampaign,'ForegroundColor',[0 0 0])
456
457% --------------------------------------------------------------------
458function MenuCampaign_Callback(hObject, eventdata, handles)
459% --------------------------------------------------------------------
460set(handles.MenuOpenCampaign,'ForegroundColor',[1 1 0])
461OutPut=browse_data(get(hObject,'Label'));% open the GUI browse_data to get select a campaign dir, experiment and device
462if ~isfield(OutPut,'Campaign')
463    return
464end
465DirName=fullfile(OutPut.Campaign,OutPut.Experiment{1},OutPut.DataSeries{1});
466hdir=dir(DirName); %list files and dirs
467for ilist=1:numel(hdir)
468    if ~isequal(hdir(ilist).isdir,1)%look for files, not dir
469        FileName=hdir(ilist).name;
470        FileType=get_file_type(fullfile(DirName,FileName));
471        switch FileType
472            case {'image','multimage','civx','civdata','netcdf'}
473            break
474        end
475    end
476end
477if get(handles.CheckAppend,'Value')
478    display_file_name(handles,fullfile(DirName,FileName),'append')
479else
480    display_file_name(handles,fullfile(DirName,FileName),'one')
481end
482set(handles.MenuOpenCampaign,'ForegroundColor',[0 0 0])
483
484
485
486%------------------------------------------------------------------------
487% --- Executes when entered data in editable cell(s) in InputTable.
488function InputTable_CellEditCallback(hObject, eventdata, handles)
489%------------------------------------------------------------------------
490set(handles.REFRESH,'BackgroundColor',[1 0 1])% set REFRESH button to magenta color to indicate that input refresh is needed
491% set(handles.REFRESH_title,'Visible','on')
492iview=eventdata.Indices(1);
493view_set=get(handles.REFRESH,'UserData');
494if isempty(find(view_set==iview))
495    set(handles.REFRESH,'UserData',[view_set iview])
496end
497%% enable other menus and uicontrols
498set(handles.MenuOpenCampaign,'Enable','on')
499set(handles.MenuCampaign_1,'Enable','on')
500set(handles.MenuCampaign_2,'Enable','on')
501set(handles.MenuCampaign_3,'Enable','on')
502set(handles.MenuCampaign_4,'Enable','on')
503set(handles.MenuCampaign_5,'Enable','on')
504set(handles.RUN, 'Enable','On')
505set(handles.RUN,'BackgroundColor',[1 0 0])% set RUN button to red
506
507%------------------------------------------------------------------------
508% --- 'key_press_fcn:' function activated when a key is pressed on the keyboard
509%------------------------------------------------------------------------
510function key_press_fcn(hObject,eventdata,handles)
511
512xx=double(get(handles.series,'CurrentCharacter')); %get the keyboard character
513if ismember(xx,[8 127 31])%backspace or delete, or downward
514    InputTable=get(handles.InputTable,'Data');
515    iline=get(handles.InputTable,'UserData');
516            if isequal(xx, 31)
517                if isequal(iline,size(InputTable,1))% arrow downward
518                InputTable=[InputTable;cell(1,size(InputTable,2))];
519                end
520            else
521    InputTable(iline,:)=[];% suppress the current line
522            end
523    set(handles.InputTable,'Data',InputTable);
524end
525
526
527%------------------------------------------------------------------------
528% --- Executes on button press in REFRESH.
529function REFRESH_Callback(hObject, eventdata, handles)
530%------------------------------------------------------------------------
531InputTable=get(handles.InputTable,'Data');
532set(handles.series,'Pointer','watch') % set the mouse pointer to 'watch'
533set(handles.REFRESH,'BackgroundColor',[1 1 0])% set REFRESH  button to yellow color (indicate activation)
534drawnow
535empty_line=false(size(InputTable,1),1);
536for iline=1:size(InputTable,1)
537    empty_line(iline)= isempty(cell2mat(InputTable(iline,1:3)));
538end
539InputTable(empty_line,:)=[];%remove empty lines
540set(handles.InputTable,'Data',InputTable)
541for iview=1:size(InputTable,1)
542    RootPath=fullfile(InputTable{iview,1},InputTable{iview,2});
543    if ~exist(RootPath,'dir')
544        i1_series=[];
545        RootPath=fileparts(RootPath); %will try the upper folder
546    else %scan the input folder
547        [RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,tild,FileType,FileInfo,MovieObject]=...
548            find_file_series(fullfile(InputTable{iview,1},InputTable{iview,2}),[InputTable{iview,3} InputTable{iview,4} InputTable{iview,5}]);
549    end
550    % if no file is found, open a browser
551    if isempty(i1_series)
552        fileinput=uigetfile_uvmat(['wrong input at line ' num2str(iview) ':pick a new input file'],RootPath);
553        if isempty(fileinput)
554            set(handles.REFRESH,'BackgroundColor',[1 0 0])% set REFRESH  back to red color
555            return
556        else
557            display_file_name(handles,fileinput,iview)
558        end
559    else
560       update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,FileInfo,MovieObject,iview)
561    end
562end
563set(handles.REFRESH,'BackgroundColor',[1 0 0])% set REFRESH  button to red color (indicate activation finished)
564set(handles.series,'Pointer','arrow') % set the mouse pointer to 'watch'
565
566%------------------------------------------------------------------------
567% --- Function called when a new file is opened, either by series_OpeningFcn or by the browser
568function errormsg=display_file_name(handles,fileinput,iview)
569%------------------------------------------------------------------------ 
570%
571% INPUT:
572% handles: handles of elements in the GUI
573% fileinput: input file name, including path
574% iview: line index in the input table
575%       or 'one': refresh the list
576%         'append': add a new line to the input table
577set(handles.REFRESH,'BackgroundColor',[1 1 0])% set REFRESH  button to yellow color (indicate activation)
578drawnow
579errormsg='';%default
580%% get the input root name, indices, file extension and nomenclature NomType
581if ~exist(fileinput,'file')
582    errormsg=['input file ' fileinput  ' does not exist'];
583    msgbox_uvmat('ERROR',errormsg)
584    set(handles.REFRESH,'BackgroundColor',[1 0 1])% set REFRESH  button to magenta color (refresh still needed)
585    return
586end
587
588%% detect root name, nomenclature and indices in the input file name:
589[FilePath,FileName,FileExt]=fileparts(fileinput);
590% detect the file type, get the movie object if relevant, and look for the corresponding file series:
591% the root name and indices may be corrected by including the first index i1 if a corresponding xml file exists
592[RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,NomType,FileType,FileInfo,MovieObject,i1,i2,j1,j2]=find_file_series(FilePath,[FileName FileExt]);
593if isempty(RootFile)&&isempty(i1_series)
594    errormsg='no input file in the series';
595    msgbox_uvmat('ERROR',errormsg)
596    set(handles.REFRESH,'BackgroundColor',[1 0 1])% set REFRESH  button to magenta color (end of activation)
597    return
598end
599if strcmp(FileType,'txt')
600    edit(fileinput)
601    set(handles.REFRESH,'BackgroundColor',[1 0 1])% set REFRESH  button to  magenta color (end of activation)
602    return
603elseif strcmp(FileType,'xml')
604    editxml(fileinput)
605    set(handles.REFRESH,'BackgroundColor',[1 0 1])% set REFRESH  button to magenta  color (end of activation)
606     return
607elseif strcmp(FileType,'figure')
608    open(fileinput)
609    set(handles.REFRESH,'BackgroundColor',[1 0 1])% set REFRESH  button to magenta  color (end of activation)
610     return
611end
612
613%% enable other menus and uicontrols
614set(handles.MenuOpenCampaign,'Enable','on')
615set(handles.MenuCampaign_1,'Enable','on')
616set(handles.MenuCampaign_2,'Enable','on')
617set(handles.MenuCampaign_3,'Enable','on')
618set(handles.MenuCampaign_4,'Enable','on')
619set(handles.MenuCampaign_5,'Enable','on')
620set(handles.RUN, 'Enable','On')
621set(handles.RUN,'BackgroundColor',[1 0 0])% set RUN button to red
622set(handles.InputTable,'BackgroundColor',[1 1 0]) % set RootPath edit box  to yellow
623drawnow
624
625
626%% fill the list of file series
627InputTable=get(handles.InputTable,'Data');
628SeriesData=get(handles.series,'UserData');
629if strcmp(iview,'append') % display the input data as a new line in the table
630    iview=size(InputTable,1)+1;% the next line in InputTable becomes the current line
631    InputTable(iview,:)=[{RootPath},{SubDir},{RootFile},{NomType},{FileExt}];
632elseif strcmp(iview,'one') % refresh the list of  input  file series
633    iview=1; %the first line in InputTable becomes the current line
634    InputTable={'','','','',''};
635    InputTable(iview,:)=[{RootPath},{SubDir},{RootFile},{NomType},{FileExt}];
636    set(handles.TimeTable,'Data',[{[]},{[]},{[]},{[]}])
637    set(handles.MinIndex_i,'Data',[])
638    set(handles.MaxIndex_i,'Data',[])
639    set(handles.MinIndex_j,'Data',[])
640    set(handles.MaxIndex_j,'Data',[])
641    set(handles.ListView,'Value',1)
642    set(handles.ListView,'String',{'1'})
643    set(handles.PairString,'Data',{''})
644    SeriesData.i1_series={};
645    SeriesData.i2_series={};
646    SeriesData.j1_series={};
647    SeriesData.j2_series={};
648    SeriesData.FileType={};
649    SeriesData.FileInfo={};
650    SeriesData.Time={};
651end
652nbview=size(InputTable,1);
653set(handles.ListView,'String',mat2cell((1:nbview)',ones(nbview,1)))
654set(handles.ListView,'Value',iview)
655SeriesData.ListViewValue=iview;
656SeriesData.ListViewMenu=mat2cell((1:nbview)',ones(nbview,1));
657set(handles.InputTable,'Data',InputTable)
658
659%% determine the selected reference field indices for pair display
660if isempty(i1)
661    i1=1;
662end
663if isempty(i2)
664    i2=i1;
665end
666ref_i=floor((i1+i2)/2);% reference image number corresponding to the file
667% set(handles.num_ref_i,'String',num2str(ref_i));
668if isempty(j1)
669    j1=1;
670end
671if isempty(j2)
672    j2=j1;
673end
674ref_j=floor((j1+j2)/2);% reference image number corresponding to the file
675% set(handles.num_ref_j,'String',num2str(ref_j));
676SeriesData.ref_i=ref_i;
677SeriesData.ref_j=ref_j;
678
679%% update first and last indices if they do not exist
680Param=read_GUI(handles.series);
681first_j=[];
682if isfield(Param.IndexRange,'first_j'); first_j=Param.IndexRange.first_j; end
683last_j=[];
684if isfield(Param.IndexRange,'last_j'); last_j=Param.IndexRange.last_j; end
685PairString='';
686if isfield(Param.IndexRange,'PairString'); PairString=Param.IndexRange.PairString; end
687[i1,i2,j1,j2] = get_file_index(Param.IndexRange.first_i,first_j,PairString);
688FirstFileName=fullfile_uvmat(Param.InputTable{1,1},Param.InputTable{1,2},Param.InputTable{1,3},...
689    Param.InputTable{1,5},Param.InputTable{1,4},i1,i2,j1,j2);
690if ~exist(FirstFileName,'file')
691    set(handles.num_first_i,'String',num2str(ref_i))
692    set(handles.num_first_j,'String',num2str(ref_j))
693end
694[i1,i2,j1,j2] = get_file_index(Param.IndexRange.last_i,last_j,PairString);
695LastFileName=fullfile_uvmat(Param.InputTable{1,1},Param.InputTable{1,2},Param.InputTable{1,3},...
696    Param.InputTable{1,5},Param.InputTable{1,4},i1,i2,j1,j2);
697if ~exist(LastFileName,'file')
698    set(handles.num_last_i,'String',num2str(ref_i))
699    set(handles.num_last_j,'String',num2str(ref_j))
700end
701
702%% update the list of recent files in the menubar and save it for future opening
703MenuFile=[{get(handles.MenuFile_1,'Label')};{get(handles.MenuFile_2,'Label')};...
704    {get(handles.MenuFile_3,'Label')};{get(handles.MenuFile_4,'Label')};{get(handles.MenuFile_5,'Label')}];
705str_find=strcmp(fileinput,MenuFile);
706if isempty(find(str_find,1))
707    MenuFile=[{fileinput};MenuFile];%insert the current file if not already in the list
708end
709for ifile=1:min(length(MenuFile),5)
710    eval(['set(handles.MenuFile_' num2str(ifile) ',''Label'',MenuFile{ifile});'])
711end
712dir_perso=prefdir;
713profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
714if exist(profil_perso,'file')
715    save (profil_perso,'MenuFile','-append'); %store the file names for future opening of uvmat
716else
717    save (profil_perso,'MenuFile','-V6'); %store the file names for future opening of uvmat
718end
719% save the opened file to initiate future opening
720SeriesData.RefFile{iview}=fileinput;% reference opening file for line iview
721SeriesData.Ref_i1=i1;
722SeriesData.Ref_i2=i2;
723SeriesData.Ref_j1=j1;
724SeriesData.Ref_j2=j2;
725set(handles.series,'UserData',SeriesData)
726
727set(handles.InputTable,'BackgroundColor',[1 1 1])
728
729%% initiate input file series and refresh the current field view:     
730update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,FileInfo,MovieObject,iview);
731set(handles.REFRESH,'BackgroundColor',[1 0 0])% set REFRESH  button to red color (end of activation)
732
733%------------------------------------------------------------------------
734% --- Update information about a new field series (indices to scan, timing,
735%     calibration from an xml file
736function update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,FileInfo,VideoObject,iview)
737%------------------------------------------------------------------------
738InputTable=get(handles.InputTable,'Data');
739
740%% display the min and max indices for the whole file series
741if size(i1_series,2)==2 && min(min(i1_series(:,1,:)))==0
742    MinIndex_j=1;% index j set to 1 by default
743    MaxIndex_j=1;
744    MinIndex_i=find(i1_series(1,2,:), 1 )-1;% min ref index i detected in the series (corresponding to the first non-zero value of i1_series, except for zero index)
745    MaxIndex_i=find(i1_series(1,2,:),1,'last' )-1;%max ref index i detected in the series (corresponding to the last non-zero value of i1_series)
746else
747    ref_i=squeeze(max(i1_series(1,:,:),[],2));% select ref_j index for each ref_i
748    ref_j=squeeze(max(j1_series(1,:,:),[],3));% select ref_i index for each ref_j
749     MinIndex_i=min(find(ref_i))-1;
750     MaxIndex_i=max(find(ref_i))-1;
751     MaxIndex_j=max(find(ref_j))-1;
752     MinIndex_j=min(find(ref_j))-1;
753    diff_j_max=diff(ref_j);
754    diff_i_max=diff(ref_i);
755    if ~isempty(diff_i_max) && isequal (diff_i_max,diff_i_max(1)*ones(size(diff_i_max)))
756        set(handles.num_incr_i,'String',num2str(diff_i_max(1)))% detect an increment to dispaly by default
757    end
758    if ~isempty(diff_j_max) && isequal (diff_j_max,diff_j_max(1)*ones(size(diff_j_max)))
759        set(handles.num_incr_j,'String',num2str(diff_j_max(1)))
760    end
761end
762if isequal(MinIndex_i,-1)
763    MinIndex_i=0;
764end
765if isequal(MinIndex_j,-1)
766    MinIndex_j=0;
767end
768MinIndex_i_table=get(handles.MinIndex_i,'Data');%retrieve the min indices in the table MinIndex
769MinIndex_j_table=get(handles.MinIndex_j,'Data');%retrieve the min indices in the table MinIndex
770MaxIndex_i_table=get(handles.MaxIndex_i,'Data');%retrieve the min indices in the table MinIndex
771MaxIndex_j_table=get(handles.MaxIndex_j,'Data');%retrieve the min indices in the table MinIndex
772if ~isempty(MinIndex_i)&&~isempty(MaxIndex_i)
773MinIndex_i_table(iview,1)=MinIndex_i;
774MaxIndex_i_table(iview,1)=MaxIndex_i;
775end
776if ~isempty(MinIndex_j)&&~isempty(MaxIndex_j)
777MinIndex_j_table(iview,1)=MinIndex_j;
778MaxIndex_j_table(iview,1)=MaxIndex_j;
779end
780set(handles.MinIndex_i,'Data',MinIndex_i_table)%display the min indices in the table MinIndex
781set(handles.MinIndex_j,'Data',MinIndex_j_table)%display the max indices in the table MaxIndex
782set(handles.MaxIndex_i,'Data',MaxIndex_i_table)%display the min indices in the table MinIndex
783set(handles.MaxIndex_j,'Data',MaxIndex_j_table)%display the max indices in the table MaxIndex
784
785%% adjust the first and last indices for the selected series, only if requested by the bounds
786% i index, compare input to min index i
787first_i=str2num(get(handles.num_first_i,'String'));%retrieve previous first i
788ref_i=str2num(get(handles.num_ref_i,'String'));%index i given by the input field
789if isempty(first_i)
790    first_i=ref_i;% first_i updated by the input value
791elseif first_i < MinIndex_i
792    first_i=MinIndex_i; % first_i set to the min i index (restricted by oter input lines)
793elseif first_i >MaxIndex_i
794    first_i=MaxIndex_i;% first_i set to the max i index (restricted by oter input lines)
795end
796% j index,  compare input to min index j
797first_j=str2num(get(handles.num_first_j,'String'));
798ref_j=str2num(get(handles.num_ref_j,'String'));%index j given by the input field
799if isempty(first_j)
800    first_j=ref_j;% first_j updated by the input value
801elseif first_j<MinIndex_j
802    first_j=MinIndex_j; % first_j set to the min j index (restricted by oter input lines)
803elseif first_j >MaxIndex_j
804    first_j=MaxIndex_j; % first_j set to the max j index (restricted by oter input lines)
805end
806% i index, compare input to max index i
807last_i=str2num(get(handles.num_last_i,'String'));
808if isempty(last_i)
809    last_i=ref_i;
810elseif last_i > MaxIndex_i
811    last_i=MaxIndex_i;
812elseif last_i<first_i
813    last_i=first_i;
814end
815% j index, compare input to max index j
816last_j=str2num(get(handles.num_last_j,'String'));
817if isempty(last_j)
818    last_j=ref_j;
819elseif last_j>MaxIndex_j
820    last_j=MaxIndex_j;
821elseif last_j<first_j
822    last_j=first_j;
823end
824set(handles.num_first_i,'String',num2str(first_i));
825set(handles.num_first_j,'String',num2str(first_j));
826set(handles.num_last_i,'String',num2str(last_i));
827set(handles.num_last_j,'String',num2str(last_j));
828
829%% number of slices set by default
830NbSlice=1;%default
831% read  value set by the first series for the checkappend mode (iwiew >1)
832if iview>1 && strcmp(get(handles.num_NbSlice,'Visible'),'on')
833    NbSlice=str2num(get(handles.num_NbSlice,'String'));
834end
835
836%% default time unit
837TimeUnit='';
838% read  value set by the first series for the checkappend mode (iwiew >1)
839if iview>1
840    TimeUnit=get(handles.TimeUnit,'String');
841end
842TimeSource='';
843Time=[];%default
844
845%%  read image documentation file if found
846XmlData=[];
847check_calib=0;
848XmlFileName=find_imadoc(InputTable{iview,1},InputTable{iview,2},InputTable{iview,3},InputTable{iview,5});
849if ~isempty(XmlFileName)
850    [XmlData,errormsg]=imadoc2struct(XmlFileName);
851    if ~isempty(errormsg)
852         msgbox_uvmat('WARNING',['error in reading ' XmlFileName ': ' errormsg]);
853    end
854    % read time if available
855    if isfield(XmlData,'Time')
856        Time=XmlData.Time;
857        TimeSource='xml';
858    end
859    if isfield(XmlData,'Camera')
860        if isfield(XmlData.Camera,'NbSlice')&& ~isempty(XmlData.Camera.NbSlice)
861            if iview>1 && ~isempty(NbSlice) && ~strcmp(NbSlice,XmlData.Camera.NbSlice)
862                msgbox_uvmat('WARNING','inconsistent number of slices with the first field series');
863            end
864            NbSlice=XmlData.Camera.NbSlice;% Nbre of slices from camera
865        end
866        if isfield(XmlData.Camera,'TimeUnit')&& ~isempty(XmlData.Camera.TimeUnit)
867            if iview>1 && ~isempty(TimeUnit) && ~strcmp(TimeUnit,XmlData.Camera.TimeUnit)
868                msgbox_uvmat('WARNING','inconsistent time unit with the first field series');
869            end
870            TimeUnit=XmlData.Camera.TimeUnit;
871        end
872    end
873    % number of slices
874    if isfield(XmlData,'GeometryCalib')
875        check_calib=1;
876        if isfield(XmlData.GeometryCalib,'SliceCoord')
877            siz=size(XmlData.GeometryCalib.SliceCoord);
878            if siz(1)>1
879                if iview>1 && ~isempty(NbSlice) && ~strcmp(NbSlice,siz(1))
880                    msgbox_uvmat('WARNING','inconsistent number of Z indices with the first field series');
881                end
882                NbSlice=siz(1);
883            end
884        end
885    end
886    set(handles.num_NbSlice,'String',num2str(NbSlice))
887end
888
889%% read timing and total frame number from the current file (movie files) if not already set by the xml file (prioritary)
890InputTable=get(handles.InputTable,'Data');
891
892% case of movies
893if isempty(Time)
894    if ~isempty(VideoObject)
895        imainfo=get(VideoObject);
896        if isempty(j1_series); %frame index along i
897            Time=zeros(imainfo.NumberOfFrames+1,2);
898            Time(:,2)=(0:1/imainfo.FrameRate:(imainfo.NumberOfFrames)/imainfo.FrameRate)';
899        else
900            Time=[0;ones(size(i1_series,3)-1,1)]*(0:1/imainfo.FrameRate:(imainfo.NumberOfFrames)/imainfo.FrameRate);
901        end
902        TimeSource='video';
903    end
904end
905
906%% update time table
907if ~isempty(Time)
908    TimeTable=get(handles.TimeTable,'Data');
909    TimeTable{iview,1}=Time(MinIndex_i+1,MinIndex_j+1);
910    if size(Time)>=[first_i+1 first_j+1]
911        TimeTable{iview,2}=Time(first_i+1,first_j+1);
912    end
913    if size(Time)>=[last_i+1 last_j+1]
914        TimeTable{iview,3}=Time(last_i+1,last_j+1);
915    end
916    if size(Time)>=[MaxIndex_i+1 MaxIndex_j+1];
917        TimeTable{iview,4}=Time(MaxIndex_i+1,MaxIndex_j+1);
918    end
919    set(handles.TimeTable,'Data',TimeTable)
920end
921
922%% update the series info in 'UserData'
923SeriesData=get(handles.series,'UserData');
924SeriesData.i1_series{iview}=i1_series;
925SeriesData.i2_series{iview}=i2_series;
926SeriesData.j1_series{iview}=j1_series;
927SeriesData.j2_series{iview}=j2_series;
928SeriesData.FileType{iview}=FileType;
929SeriesData.FileInfo{iview}=FileInfo;
930SeriesData.Time{iview}=Time;
931if ~isempty(TimeSource)
932    SeriesData.TimeSource=TimeSource;
933end
934% if ~isempty(TimeUnit)
935%     SeriesData.TimeUnit=TimeUnit;
936% end
937if check_calib
938    SeriesData.GeometryCalib{iview}=XmlData.GeometryCalib;
939end
940set(handles.series,'UserData',SeriesData)
941
942%% update pair menus
943ListView=get(handles.ListView,'String');
944ListView{iview}=num2str(iview);
945set(handles.ListView,'String',ListView);
946set(handles.ListView,'Value',iview)
947update_mode(handles,i1_series,i2_series,j1_series,j2_series,Time)
948
949%% enable j index visibility
950status_j='on';%default
951if isempty(find(~cellfun(@isempty,SeriesData.j1_series), 1)); % case of empty j indices
952    status_j='off'; % no j index needed
953elseif strcmp(get(handles.PairString,'Visible'),'on')
954    PairString=get(handles.PairString,'Data');
955    check_burst=cellfun(@isempty,regexp(PairString,'^j'));%=0 for burst case, 1 otherwise
956    if isempty(find(check_burst, 1))% if all pair string begins by j (burst)
957        status_j='off'; % no j index needed for bust case
958    end
959end
960enable_j(handles,status_j) % no j index needed
961
962%% display the set of existing files as an image
963set(handles.FileStatus,'Units','pixels')
964Position=get(handles.FileStatus,'Position');
965set(handles.FileStatus,'Units','normalized')
966%xI=0.5:Position(3)-0.5;
967nbview=numel(SeriesData.i1_series);
968j_max=cell(1,nbview);
969MaxIndex_i=ones(1,nbview);%default
970MinIndex_i=ones(1,nbview);%default
971for iview=1:nbview
972    pair_max=squeeze(max(SeriesData.i1_series{iview},[],1)); %max on pair index
973    j_max{iview}=max(pair_max,[],1);%max on j index
974    if ~isempty(j_max{iview})
975    MaxIndex_i(iview)=max(find(j_max{iview}))-1;% max ref index i
976    MinIndex_i(iview)=min(find(j_max{iview}))-1;% min ref index i
977    end
978end
979MinIndex_i=min(MinIndex_i);
980MaxIndex_i=max(MaxIndex_i);
981range_index=MaxIndex_i-MinIndex_i+1;
982range_y=max(1,floor(Position(4)/nbview));
983npx=floor(Position(3));
984file_indices=MinIndex_i+floor(((0.5:npx-0.5)/npx)*range_index)+1;
985CData=zeros(nbview*range_y,npx);% initiate the image representing the existing files
986for iview=1:nbview
987    ind_y=1+(iview-1)*range_y:iview*range_y;
988    LineData=zeros(size(file_indices));
989    file_select=file_indices(file_indices<=numel(j_max{iview}));
990    ind_select=find(file_indices<=numel(j_max{iview}));
991    LineData(ind_select)=j_max{iview}(file_select)~=0;
992    CData(ind_y,:)=ones(size(ind_y'))*LineData;
993end
994CData=cat(3,zeros(size(CData)),CData,zeros(size(CData)));%make color images r=0,g,b=0
995set(handles.FileStatus,'CData',CData);
996
997%% check for pair display
998check_pairs=0;
999for iview=1:numel(SeriesData.i2_series)
1000    if ~isempty(SeriesData.i2_series{iview})||~isempty(SeriesData.j2_series{iview})
1001        check_pairs=1;
1002    end
1003end
1004if check_pairs
1005%     set(handles.Pairs,'Visible','on')
1006    set(handles.PairString,'Visible','on')
1007    set(handles.SetPairs,'Visible','on')
1008else
1009%     set(handles.Pairs,'Visible','off')
1010    set(handles.PairString,'Visible','off')
1011    set(handles.SetPairs,'Visible','off')
1012end
1013
1014
1015%% enable field and veltype menus, in accordance with the current action
1016ActionName_Callback([],[], handles)
1017
1018%% set length of waitbar
1019displ_time(handles)
1020
1021%% set default options in menu 'Fields'
1022switch FileType
1023    case {'civx','civdata'}
1024        FieldList=set_field_list('U','V','C');
1025        set(handles.FieldName,'String',[FieldList;{'get_field...'}]);%standard menu for civx data
1026        set(handles.FieldName,'Value',1) % set menu to 'velocity
1027        set(handles.Coord_x,'Value',1);
1028        set(handles.Coord_x,'String',{'X'});
1029        set(handles.Coord_y,'Value',1);
1030        set(handles.Coord_y,'String',{'Y'});
1031    case 'netcdf'
1032        set(handles.FieldName,'Value',1)
1033        set(handles.FieldName,'String',{'get_field...'})
1034        if isempty(i2_series)
1035            i2=[];
1036        else
1037            i2=i2_series(1,ref_j+1,ref_i+1);
1038        end
1039        if isempty(j1_series)
1040            j1=[];j2=[];
1041        else
1042            j1=j1_series(1,ref_j+1,ref_i+1);
1043            if isempty(j2_series)
1044                j2=[];
1045            else
1046                j2=j2_series(1,ref_j+1,ref_i+1);
1047            end
1048        end
1049       % FieldName_Callback([], [], handles)
1050    otherwise
1051        set(handles.FieldName,'Value',1) % set menu to 'image'
1052        set(handles.FieldName,'String',{'image'})
1053        set(handles.Coord_x,'Value',1);
1054        set(handles.Coord_x,'String',{'AX'});
1055        set(handles.Coord_y,'Value',1);
1056        set(handles.Coord_y,'String',{'AY'});
1057end
1058
1059%------------------------------------------------------------------------
1060function num_first_i_Callback(hObject, eventdata, handles)
1061%------------------------------------------------------------------------
1062num_last_i_Callback(hObject, eventdata, handles)
1063
1064%------------------------------------------------------------------------
1065function num_last_i_Callback(hObject, eventdata, handles)
1066%------------------------------------------------------------------------
1067SeriesData=get(handles.series,'UserData');
1068if ~isfield(SeriesData,'Time')
1069    SeriesData.Time{1}=[];
1070end
1071displ_time(handles);
1072
1073%------------------------------------------------------------------------
1074function num_first_j_Callback(hObject, eventdata, handles)
1075%------------------------------------------------------------------------
1076 num_last_j_Callback(hObject, eventdata, handles)
1077
1078%------------------------------------------------------------------------
1079function num_last_j_Callback(hObject, eventdata, handles)
1080%------------------------------------------------------------------------
1081first_j=str2num(get(handles.num_first_j,'String'));
1082last_j=str2num(get(handles.num_last_j,'String'));
1083ref_j=ceil((first_j+last_j)/2);
1084set(handles.num_ref_j,'String', num2str(ref_j))
1085num_ref_j_Callback(hObject, eventdata, handles)
1086SeriesData=get(handles.series,'UserData');
1087if ~isfield(SeriesData,'Time')
1088    SeriesData.Time{1}=[];
1089end
1090displ_time(handles);
1091
1092
1093%------------------------------------------------------------------------
1094% ---- find the times corresponding to the first and last indices of a series
1095function displ_time(handles)
1096%------------------------------------------------------------------------
1097SeriesData=get(handles.series,'UserData');%
1098PairString=get(handles.PairString,'Data');
1099ref_i_1=str2num(get(handles.num_first_i,'String'));%first reference index
1100ref_i_2=str2num(get(handles.num_last_i,'String'));%last reference index
1101ref_j_1=[];ref_j_2=[];
1102if strcmp(get(handles.num_first_j,'Visible'),'on')
1103ref_j_1=str2num(get(handles.num_first_j,'String'));
1104ref_j_2=str2num(get(handles.num_last_j,'String'));
1105end
1106[i1_1,i2_1,j1_1,j2_1] = get_file_index(ref_i_1,ref_j_1,PairString);
1107[i1_2,i2_2,j1_2,j2_2] = get_file_index(ref_i_2,ref_j_2,PairString);
1108TimeTable=get(handles.TimeTable,'Data');
1109
1110%Pairs=get(handles.PairString,'Data');
1111for iview=1:size(TimeTable,1)
1112    if size(SeriesData.Time,1)<iview
1113        break
1114    end
1115    TimeTable{iview,2}=[];
1116    TimeTable{iview,3}=[];
1117    if size(SeriesData.Time{iview},1)>=i2_2+1 && (isempty(ref_j_1)||size(SeriesData.Time{iview},2)>=j2_2+1)
1118        if isempty(ref_j_1)
1119            time_first=(SeriesData.Time{iview}(i1_1+1,2)+SeriesData.Time{iview}(i2_1+1,2))/2;
1120            time_last=(SeriesData.Time{iview}(i1_2+1,2)+SeriesData.Time{iview}(i2_2+1,2))/2;
1121        else
1122            time_first=(SeriesData.Time{iview}(i1_1+1,j1_1+1)+SeriesData.Time{iview}(i2_1+1,j2_1+1))/2;
1123            time_last=(SeriesData.Time{iview}(i1_2+1,j1_2+1)+SeriesData.Time{iview}(i2_2+1,j2_1+1))/2;
1124        end
1125        TimeTable{iview,2}=time_first; %TODO: take into account pairs
1126        TimeTable{iview,3}=time_last; %TODO: take into account pairs
1127    end
1128end
1129set(handles.TimeTable,'Data',TimeTable)
1130
1131%% set the waitbar position with respect to the min and max in the series
1132MinIndex_i=min(get(handles.MinIndex_i,'Data'));
1133MaxIndex_i=max(get(handles.MaxIndex_i,'Data'));
1134pos_first=(ref_i_1-MinIndex_i)/(MaxIndex_i-MinIndex_i+1);
1135pos_last=(ref_i_2-MinIndex_i+1)/(MaxIndex_i-MinIndex_i+1);
1136if isempty(pos_first), pos_first=0; end
1137if isempty(pos_last), pos_last=1; end
1138Position=get(handles.Waitbar,'Position');% position of the waitbar:= [ x,y, width, height]
1139Position_status=get(handles.FileStatus,'Position');
1140Position(1)=Position_status(1)+Position_status(3)*pos_first;
1141Position(3)=max(Position_status(3)*(pos_last-pos_first),0.001);% width must remain positive
1142set(handles.Waitbar,'Position',Position)
1143update_waitbar(handles.Waitbar,0)
1144
1145%------------------------------------------------------------------------
1146% --- Executes when selected cell(s) is changed in PairString.
1147function PairString_CellSelectionCallback(hObject, eventdata, handles)
1148%------------------------------------------------------------------------   
1149if numel(eventdata.Indices)>=1
1150set(handles.ListView,'Value',eventdata.Indices(1))% detect the selected raw index
1151ListView_Callback ([],[],handles) % update the list of available pairs
1152end
1153
1154%------------------------------------------------------------------------
1155%------------------------------------------------------------------------
1156%  III - FUNCTIONS ASSOCIATED TO THE FRAME SET PAIRS
1157%------------------------------------------------------------------------
1158%------------------------------------------------------------------------
1159% --- Executes on selection change in ListView.
1160function ListView_Callback(hObject, eventdata, handles)
1161%------------------------------------------------------------------------   
1162SeriesData=get(handles.series,'UserData');
1163i2_series=[];
1164j2_series=[];
1165iview=get(handles.ListView,'Value');
1166if ~isempty(SeriesData.i2_series{iview})
1167    i2_series=SeriesData.i2_series{iview};
1168end
1169if ~isempty(SeriesData.j2_series{iview})
1170    j2_series=SeriesData.j2_series{iview};
1171end
1172update_mode(handles,SeriesData.i1_series{iview},SeriesData.i2_series{iview},...
1173    SeriesData.j1_series{iview},SeriesData.j2_series{iview},SeriesData.Time{iview})
1174
1175%------------------------------------------------------------------------
1176% --- Executes on button press in mode.
1177function mode_Callback(hObject, eventdata, handles)
1178%------------------------------------------------------------------------       
1179SeriesData=get(handles.series,'UserData');
1180iview=get(handles.ListView,'Value');
1181mode_list=get(handles.mode,'String');
1182mode=mode_list{get(handles.mode,'Value')};
1183if isequal(mode,'bursts')
1184    enable_i(handles,'On')
1185    enable_j(handles,'Off') %do not display j index scanning in burst mode (j is fixed by the burst choice)
1186else
1187    enable_i(handles,'On')
1188    enable_j(handles,'Off')
1189end
1190fill_ListPair(handles,SeriesData.i1_series{iview},SeriesData.i2_series{iview},...
1191    SeriesData.j1_series{iview},SeriesData.j2_series{iview},SeriesData.Time{iview})
1192ListPairs_Callback([],[],handles)
1193
1194%-------------------------------------------------------------
1195% --- Executes on selection in ListPairs.
1196function ListPairs_Callback(hObject,eventdata,handles)
1197%------------------------------------------------------------
1198list_pair=get(handles.ListPairs,'String');%get the menu of image pairs
1199if isempty(list_pair)
1200    string='';
1201else
1202    string=list_pair{get(handles.ListPairs,'Value')};
1203    string=regexprep(string,',.*','');%removes time indication (after ',')
1204end
1205PairString=get(handles.PairString,'Data');
1206iview=get(handles.ListView,'Value');
1207PairString{iview,1}=string;
1208% report the selected pair string to the table PairString
1209set(handles.PairString,'Data',PairString)
1210
1211
1212%------------------------------------------------------------------------
1213function update_mode(handles,i1_series,i2_series,j1_series,j2_series,time)
1214%------------------------------------------------------------------------   
1215% check_burst=0;
1216ModeMenu={''};
1217if isempty(j2_series)% no j pair
1218    ModeValue=1;
1219    if isempty(i2_series)
1220        set(handles.mode,'String',{''})% no pair menu to display
1221    else   
1222        set(handles.mode,'Value',1)
1223        ModeMenu={'series(Di)'}; % pair menu with only option Di
1224    end
1225else %existence of j pairs
1226    pair_max=squeeze(max(i1_series,[],1)); %max on pair index
1227    j_max=max(pair_max,[],1);
1228    MaxIndex_i=max(find(j_max))-1;% max ref index i
1229    MinIndex_i=min(find(j_max))-1;% min ref index i
1230    i_max=max(pair_max,[],2);
1231    MaxIndex_j=max(find(i_max))-1;% max ref index i
1232    MinIndex_j=min(find(i_max))-1;% min ref index i
1233    if MaxIndex_j==MinIndex_j
1234        ModeValue=1;
1235        ModeMenu={'bursts'};
1236    elseif MaxIndex_i==MinIndex_i
1237    ModeValue=1;
1238    ModeMenu={'series(Dj)'};
1239    else
1240        ModeMenu={'bursts';'series(Dj)'};
1241        if (MaxIndex_j-MinIndex_j)>10
1242            ModeValue=2;%set mode to series(Dj) if more than 10 j values
1243        else
1244            ModeValue=1;
1245        end
1246    end
1247end
1248
1249set(handles.mode,'String',ModeMenu)
1250set(handles.mode,'Value',ModeValue)
1251SeriesData=get(handles.series,'UserData');
1252SeriesData.ModeMenu=ModeMenu;
1253SeriesData.ModeValue=ModeValue;
1254set(handles.series,'UserData',SeriesData)
1255fill_ListPair(handles,i1_series,i2_series,j1_series,j2_series,time)
1256ListPairs_Callback([],[],handles)
1257
1258%--------------------------------------------------------------
1259% determine the menu for pairstring depending on existing netcdf files
1260% with the reference indices num_ref_i and num_ref_j
1261%----------------------------------------------------------------
1262function fill_ListPair(handles,i1_series,i2_series,j1_series,j2_series,time)
1263
1264mode_list=get(handles.mode,'String');
1265mode=mode_list{get(handles.mode,'Value')};
1266ref_i=str2num(get(handles.num_ref_i,'String'));
1267if isempty(ref_i)
1268    ref_i=1;
1269end
1270if strcmp(get(handles.num_ref_j,'Visible'),'on')
1271    ref_j=str2num(get(handles.num_ref_j,'String'));
1272    if isempty(ref_j)
1273        ref_j=1;
1274    end
1275else
1276    ref_j=1;
1277end
1278TimeUnit=get(handles.TimeUnit,'String');
1279if length(TimeUnit)>=1
1280    dtunit=['m' TimeUnit];
1281else
1282    dtunit='e-03';
1283end
1284
1285displ_pair={};
1286if strcmp(mode,'series(Di)')
1287    if isempty(i2_series)
1288        msgbox_uvmat('ERROR','no i1-i2 pair available')
1289        return
1290    end
1291    diff_i=i2_series-i1_series;
1292    min_diff=min(diff_i(diff_i>0));
1293    max_diff=max(diff_i(diff_i>0));
1294    for ipair=min_diff:max_diff
1295        if numel(diff_i(diff_i==ipair))>0
1296            pair_string=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ];
1297            if ~isempty(time)
1298                if ref_i<=floor(ipair/2)
1299                    ref_i=floor(ipair/2)+1;% shift ref_i to get the first pair
1300                end
1301                Dt=time(ref_i+ceil(ipair/2),ref_j)-time(ref_i-floor(ipair/2),ref_j);
1302                pair_string=[pair_string ', Dt=' num2str(Dt) ' ' dtunit];
1303            end
1304            displ_pair=[displ_pair;{pair_string}];
1305        end
1306    end
1307    if ~isempty(displ_pair)
1308        displ_pair=[displ_pair;{'Di=*|*'}];
1309    end
1310elseif strcmp(mode,'series(Dj)')
1311    if isempty(j2_series)
1312        msgbox_uvmat('ERROR','no j1-j2 pair available')
1313        return
1314    end
1315    diff_j=j2_series-j1_series;
1316    min_diff=min(diff_j(diff_j>0));
1317    max_diff=max(diff_j(diff_j>0));
1318    for ipair=min_diff:max_diff
1319        if numel(diff_j(diff_j==ipair))>0
1320            pair_string=['Dj= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ];
1321            if ~isempty(time)
1322                if ref_j<=floor(ipair/2)
1323                    ref_j=floor(ipair/2)+1;% shift ref_i to get the first pair
1324                end
1325                Dt=time(ref_i,ref_j+ceil(ipair/2))-time(ref_i,ref_j-floor(ipair/2));
1326                pair_string=[pair_string ', Dt=' num2str(Dt) ' ' dtunit];
1327            end
1328            displ_pair=[displ_pair;{pair_string}];
1329        end
1330    end
1331    if ~isempty(displ_pair)
1332        displ_pair=[displ_pair;{'Dj=*|*'}];
1333    end
1334elseif strcmp(mode,'bursts')
1335    if isempty(j2_series)
1336        msgbox_uvmat('ERROR','no j1-j2 pair available')
1337        return
1338    end
1339    diff_j=j2_series-j1_series;
1340    min_j1=min(j1_series(j1_series>0));
1341    max_j1=max(j1_series(j1_series>0));
1342    min_j2=min(j2_series(j2_series>0));
1343    max_j2=max(j2_series(j2_series>0));
1344    for pair1=min_j1:min(max_j1,min_j1+20)
1345        for pair2=min_j2:min(max_j2,min_j2+20)
1346        if numel(j1_series(j1_series==pair1))>0 && numel(j2_series(j2_series==pair2))>0
1347            displ_pair=[displ_pair;{['j= ' num2str(pair1) '-' num2str(pair2)]}];
1348        end
1349        end
1350    end
1351    if ~isempty(displ_pair)
1352        displ_pair=[displ_pair;{'j=*-*'}];
1353    end
1354end
1355set(handles.num_ref_i,'String',num2str(ref_i)) % update ref_i and ref_j
1356set(handles.num_ref_j,'String',num2str(ref_j))
1357
1358%% display list of pairstring
1359SeriesData=get(handles.series,'UserData');
1360displ_pair_list=get(handles.ListPairs,'String');
1361NewVal=[];
1362if ~isempty(displ_pair_list)
1363Val=get(handles.ListPairs,'Value');
1364NewVal=find(strcmp(displ_pair_list{Val},displ_pair),1);% look at the previous display in the new menu displ_pï¿œir
1365end
1366if ~isempty(NewVal)
1367    set(handles.ListPairs,'Value',NewVal)
1368    SeriesData.ListPairsValue=NewVal;
1369else
1370    set(handles.ListPairs,'Value',1)
1371    SeriesData.ListPairsValue=1;
1372end
1373set(handles.ListPairs,'String',displ_pair)
1374SeriesData.ListPairsMenu=displ_pair;
1375set(handles.series,'UserData',SeriesData);
1376
1377%-------------------------------------
1378function enable_i(handles,state)
1379set(handles.i_txt,'Visible',state)
1380set(handles.num_first_i,'Visible',state)
1381set(handles.num_last_i,'Visible',state)
1382set(handles.num_incr_i,'Visible',state)
1383set(handles.num_ref_i,'Visible',state)
1384set(handles.ref_i_text,'Visible',state)
1385
1386%-----------------------------------
1387function enable_j(handles,state)
1388set(handles.j_txt,'Visible',state)
1389set(handles.num_first_j,'Visible',state)
1390set(handles.num_last_j,'Visible',state)
1391set(handles.num_incr_j,'Visible',state)
1392set(handles.num_ref_j,'Visible',state)
1393set(handles.ref_j_text,'Visible',state)
1394set(handles.MinIndex_j,'Visible',state)
1395set(handles.MaxIndex_j,'Visible',state)
1396
1397
1398%%%%%%%%%%%%%%%%%%%%
1399%%  MAIN ActionName FUNCTIONS
1400%%%%%%%%%%%%%%%%%%%%
1401%------------------------------------------------------------------------
1402% --- Executes on button press in RUN.
1403%------------------------------------------------------------------------
1404function RUN_Callback(hObject, eventdata, handles)
1405
1406%% settings of the button RUN
1407set(handles.RUN,'BusyAction','queue');% activation of STOP button will set BusyAction to 'cancel'
1408set(handles.RUN, 'Enable','Off')% avoid further RUN action until the current one is finished
1409set(handles.RUN,'BackgroundColor',[1 1 0])%show activation of RUN by yellow color
1410drawnow
1411set(handles.status,'Value',0)% desable status display if relevant
1412status_Callback(hObject, eventdata, handles)
1413
1414%% read the data on the GUI series
1415Param=read_GUI_series(handles);%displayed parameters
1416SeriesData=get(handles.series,'UserData');%hidden parameters
1417
1418
1419
1420%% select the Action mode, 'local', 'background' or 'cluster' (if available)
1421RunMode='local';%default (needed for first opening of the GUI series)
1422if isfield(Param.Action,'RunMode')
1423    RunMode=Param.Action.RunMode;
1424end
1425ActionExt='.m';%default
1426if isfield(Param.Action,'ActionExt')
1427    ActionExt=Param.Action.ActionExt;% '.m' or '.sh' (compiled)
1428end
1429ActionName=Param.Action.ActionName;
1430ActionPath=Param.Action.ActionPath;
1431path_series=fileparts(which('series'));
1432
1433%% create the Action fct handle if RunMode option = 'local'
1434if strcmp(RunMode,'local')
1435    if ~isequal(ActionPath,path_series)
1436        eval(['spath=which(''' ActionName ''');']) %spath = current path of the selected function ACTION
1437        if ~exist(ActionPath,'dir')
1438            msgbox_uvmat('ERROR',['The prescribed function path ' ActionPath ' does not exist']);
1439            return
1440        end
1441        if ~isequal(spath,ActionPath)
1442            addpath(ActionPath)% add the prescribed path if not the current one
1443        end
1444    end
1445    eval(['h_fun=@' ActionName ';'])%create a function handle for ACTION
1446    if ~isequal(ActionPath,path_series)
1447        rmpath(ActionPath)% add the prescribed path if not the current one
1448    end
1449end
1450
1451%% Get RunTime code from the file PARAM.xml (needed to run compiled functions)
1452errormsg='';%default error message
1453xmlfile=fullfile(path_series,'PARAM.xml');
1454test_batch=0;%default: ,no batch mode available
1455if ~exist(xmlfile,'file')
1456    [success,message]=copyfile(fullfile(path_series,'PARAM.xml.default'),xmlfile);
1457end
1458RunTime='';
1459if strcmp(ActionExt,'.sh')
1460    if exist(xmlfile,'file')
1461        s=xml2struct(xmlfile);
1462        if strcmp(RunMode,'cluster_oar') && isfield(s,'BatchParam')
1463            if isfield(s.BatchParam,'RunTime')
1464                RunTime=s.BatchParam.RunTime;
1465            end
1466            if isfield(s.BatchParam,'NbCore')
1467                NbCore=s.BatchParam.NbCore;
1468            end
1469        elseif (strcmp(RunMode,'background')||strcmp(RunMode,'local')) && isfield(s,'RunParam')
1470            if isfield(s.RunParam,'RunTime')
1471                RunTime=s.RunParam.RunTime;
1472            end
1473            if isfield(s.RunParam,'NbCore')
1474                NbCore=s.RunParam.NbCore;
1475            end
1476        end
1477    end
1478    if isempty(RunTime) && strcmp(RunMode,'cluster_oar')
1479        msgbox_uvmat('ERROR','RunTime name not found in PARAM.xml, compiled version .sh cannot run on cluster')
1480        return
1481    end
1482end
1483
1484%% If a compiled version has been selected (ext .sh) check weather it needs to be recompiled
1485% ActionExtList=get(handles.ActionExt,'String');
1486% ActionExt=ActionExtList{get(handles.ActionExt,'Value')};
1487% ActionList=get(handles.ActionName,'String');
1488% ActionName=ActionList{get(handles.ActionName,'Value')};
1489% TransformPath='';
1490% if ~isempty(get(handles.ActionExt,'UserData'))
1491%     TransformPath=get(handles.ActionExt,'UserData');
1492% end
1493if strcmp(ActionExt,'.sh')
1494    TransformPath='';
1495    if ~isempty(get(handles.ActionExt,'UserData'))
1496        TransformPath=get(handles.ActionExt,'UserData');
1497    end
1498    set(handles.series,'Pointer','watch') % set the mouse pointer to 'watch'
1499    set(handles.ActionExt,'BackgroundColor',[1 1 0])
1500    ActionFullName=fullfile(get(handles.ActionPath,'String'),[ActionName '.sh']);
1501    if ~exist(ActionFullName,'file')
1502        answer=msgbox_uvmat('INPUT_Y-N','compiled version has not been created: compile now?');
1503        if strcmp(answer,'Yes')
1504            set(handles.ActionExt,'BackgroundColor',[1 1 0])
1505            path_uvmat=fileparts(which('series'));
1506            currentdir=pwd;
1507            cd(get(handles.ActionPath,'String'))% go to the directory of Action
1508            %  addpath(get(handles.TransformPath,'String'))
1509            addpath(path_uvmat)% add the path to uvmat to run the fct 'compile'
1510           % addpath(fullfile(path_uvmat,'transform_field'))% add the path to uvmat to run the fct 'compile'
1511            compile(ActionName,TransformPath)
1512            cd(currentdir)
1513        end       
1514    else
1515        sh_file_info=dir(fullfile(get(handles.ActionPath,'String'),[ActionName '.sh']));
1516        m_file_info=dir(fullfile(get(handles.ActionPath,'String'),[ActionName '.m']));
1517        if isfield(m_file_info,'datenum') && m_file_info.datenum>sh_file_info.datenum
1518            set(handles.ActionExt,'BackgroundColor',[1 1 0])
1519            drawnow
1520            answer=msgbox_uvmat('INPUT_Y-N',[ActionName '.sh needs to be updated: recompile now?']);
1521            if strcmp(answer,'Yes')
1522                path_uvmat=fileparts(which('series'));
1523                currentdir=pwd;
1524                cd(get(handles.ActionPath,'String'))% go to the directory of Action
1525                %  addpath(get(handles.TransformPath,'String'))
1526                addpath(path_uvmat)% add the path to uvmat to run the fct 'compile'
1527                addpath(fullfile(path_uvmat,'transform_field'))% add the path to uvmat to run the fct 'compile'
1528                compile(ActionName,TransformPath)
1529                cd(currentdir)
1530            end
1531        end
1532    end
1533    set(handles.ActionExt,'BackgroundColor',[1 1 1])
1534     set(handles.series,'Pointer','arrow') % set the mouse pointer to 'watch
1535end
1536
1537%% set nbre of cluster cores and processes
1538switch RunMode
1539    case {'local','background'}
1540        NbCore=1;% no need to split the calculation
1541    case 'cluster_oar'
1542        if strcmp(Param.Action.ActionExt,'.m')% case of Matlab function (uncompiled)
1543            NbCore=1;% one core used only (limitation of Matlab licences)
1544            msgbox_uvmat('WARNING','Number of cores =1: select the compiled version civ_matlab.sh for multi-core processing');
1545            extra_oar='';
1546        else
1547            answer=inputdlg({'Number of cores (max 36)','extra oar options'},'oarsub parameter',1,{'12',''});
1548            NbCore=str2double(answer{1});
1549            extra_oar=answer{2};
1550        end
1551end
1552if ~isfield(Param.IndexRange,'NbSlice')
1553    Param.IndexRange.NbSlice=[];
1554end
1555if isempty(Param.IndexRange.NbSlice)
1556    NbProcess=NbCore;% choose one process per core
1557else
1558    NbProcess=Param.IndexRange.NbSlice;% the nbre of run processes is equal to the number of slices
1559    NbCore=min(NbCore,NbProcess);% at least one process per core
1560end
1561
1562%% create the output data directory if needed
1563if isfield(Param,'OutputSubDir')
1564    SubDirOut=[get(handles.OutputSubDir,'String') Param.OutputDirExt];
1565    SubDirOutNew=SubDirOut;
1566    detect=exist(fullfile(Param.InputTable{1,1},SubDirOutNew),'dir');% test if  the dir  already exist
1567    check_create=1; %need to create the result directory by default
1568    while detect
1569        answer=msgbox_uvmat('INPUT_Y-N',['use existing ouput directory: ' fullfile(Param.InputTable{1,1},SubDirOutNew) ', possibly delete previous data']);
1570        if strcmp(answer,'Cancel')
1571            errormsg='Cancel';
1572            return
1573        elseif strcmp(answer,'Yes')
1574            detect=0;
1575            check_create=0;
1576        else
1577            r=regexp(SubDirOutNew,'(?<root>.*\D)(?<num1>\d+)$','names');%detect whether name ends by a number
1578            if isempty(r)
1579                r(1).root=[SubDirOutNew '_'];
1580                r(1).num1='0';
1581            end
1582            SubDirOutNew=[r(1).root num2str(str2num(r(1).num1)+1)];%increment the index by 1 or put 1
1583            detect=exist(fullfile(Param.InputTable{1,1},SubDirOutNew),'dir');% test if  the dir  already exists
1584            check_create=1;
1585        end
1586    end
1587    Param.OutputDirExt=regexprep(SubDirOutNew,Param.OutputSubDir,'');
1588    Param.OutputRootFile=Param.InputTable{1,3};% the first sorted RootFile taken for output
1589    set(handles.OutputDirExt,'String',Param.OutputDirExt)
1590    OutputDir=fullfile(Param.InputTable{1,1},[Param.OutputSubDir Param.OutputDirExt]);% full name (with path) of output directory
1591    if check_create    % create output directory if it does not exist
1592        [tild,msg1]=mkdir(OutputDir);
1593        if ~strcmp(msg1,'')
1594            msgbox_uvmat('ERROR',['cannot create ' OutputDir ': ' msg1]);%error message for directory creation
1595            return
1596        end
1597        [success,msg] = fileattrib(OutputDir,'+w','g','s');% allow writing access for the group of users, recursively in the folder 
1598        if success==0
1599            msgbox_uvmat('WARNING',{['unable to set group write access to ' OutputDir ':']; msg1});%error message for directory creation
1600            return
1601        end
1602    end
1603    OutputNomType=nomtype2pair(Param.InputTable{1,4});% nomenclature for output files
1604    DirXml=fullfile(OutputDir,'0_XML');
1605    if ~exist(DirXml,'dir')
1606        [tild,msg1]=mkdir(DirXml);
1607        if ~strcmp(msg1,'')
1608            msgbox_uvmat('ERROR',['cannot create ' DirXml ': ' msg1]);%error message for directory creation
1609            return
1610        end
1611                [success,msg] = fileattrib(DirXml,'+w','g','s');% allow writing access for the group of users, recursively in the folder 
1612        if success==0
1613            msgbox_uvmat('WARNING',{['unable to set group write access to ' DirXml ':']; msg1});%error message for directory creation
1614            return
1615        end
1616    end
1617end
1618       
1619%% get the set of reference field indices
1620first_i=1;
1621last_i=1;
1622incr_i=1;
1623first_j=1;
1624last_j=1;
1625incr_j=1;
1626if isfield(Param.IndexRange,'first_i')
1627    first_i=Param.IndexRange.first_i;
1628    incr_i=Param.IndexRange.incr_i;
1629    last_i=Param.IndexRange.last_i;
1630end
1631if isfield(Param.IndexRange,'first_j')
1632    first_j=Param.IndexRange.first_j;
1633    last_j=Param.IndexRange.last_j;
1634    incr_j=Param.IndexRange.incr_j;
1635end
1636if last_i < first_i || last_j < first_j
1637    msgbox_uvmat('ERROR', 'series/Run_Callback:last field index must be larger or equal to the first one')
1638    set(handles.RUN, 'Enable','On'),
1639    set(handles.RUN,'BackgroundColor',[1 0 0])
1640    return
1641end
1642%incr_i must be defined, =1 by default, if NbSlice is active
1643if isempty(incr_i)&& ~isempty(Param.IndexRange.NbSlice)
1644    incr_i=1;
1645    set(handles.num_incr_i,'String','1')
1646end
1647if isempty(incr_i)
1648    if isempty(incr_j)
1649        [ref_j,ref_i]=find(squeeze(SeriesData.i1_series{1}(1,:,:)));
1650        ref_j=ref_j(ref_j>=first_j & ref_j<=last_j);
1651        ref_i=ref_i(ref_i>=first_i & ref_i<=last_i);
1652        ref_j=ref_j-1;
1653        ref_i=ref_i-1;
1654    else
1655        ref_j=first_j:incr_j:last_j;
1656        [tild,ref_i]=find(squeeze(SeriesData.i1_series{1}(1,:,:)));
1657        ref_i=ref_i-1;
1658        ref_i=ref_i(ref_i>=first_i & ref_i<=last_i);
1659    end
1660else
1661    ref_i=first_i:incr_i:last_i;
1662    if isempty(incr_j)
1663    [ref_j,tild]=find(squeeze(SeriesData.i1_series{1}(1,:,:)));
1664    ref_j=ref_j-1;
1665    ref_j=ref_j(ref_j>=first_j & ref_j<=last_j);
1666    else
1667        ref_j=first_j:incr_j:last_j;
1668    end
1669end
1670BlockLength=ceil(numel(ref_i)/NbProcess);
1671nbfield_j=numel(ref_j);
1672
1673%% record nbre of output files and starting time for computation for status
1674StatusData=get(handles.status,'UserData');
1675if isfield(StatusData,'OutputFileMode')
1676    switch StatusData.OutputFileMode
1677        case 'NbInput'
1678            StatusData.NbOutputFile=numel(ref_i)*nbfield_j;
1679        case 'NbInput_i'
1680            StatusData.NbOutputFile=numel(ref_i);
1681        case 'NbSlice'   
1682            StatusData.NbOutputFile=str2num(get(handles.num_NbSlice,'String'));
1683    end
1684end
1685StatusData.TimeStart=now;
1686set(handles.status,'UserData',StatusData)
1687
1688%% direct processing on the current Matlab session
1689if strcmp (RunMode,'local')
1690    for iprocess=1:NbProcess
1691        if isempty(Param.IndexRange.NbSlice)
1692            %Param.IndexRange.first_i=first_i+(iprocess-1)*BlockLength*incr_i;
1693            Param.IndexRange.first_i=ref_i(1+(iprocess-1)*BlockLength);
1694            if Param.IndexRange.first_i>last_i
1695                break
1696            end
1697            Param.IndexRange.last_i=min(ref_i(iprocess*BlockLength),last_i);
1698            %Param.IndexRange.last_i=min(first_i+(iprocess)*BlockLength*incr_i-1,last_i);
1699        else %multislices (then incr_i is not empty)
1700             Param.IndexRange.first_i= first_i+incr_i*(iprocess-1);
1701             Param.IndexRange.incr_i=incr_i*Param.IndexRange.NbSlice;
1702        end
1703        if isfield(Param,'OutputSubDir')
1704        t=struct2xml(Param);
1705        t=set(t,1,'name','Series');
1706        filexml=fullfile_uvmat(DirXml,'',Param.InputTable{1,3},'.xml',OutputNomType,...
1707            Param.IndexRange.first_i,Param.IndexRange.last_i,first_j,last_j);
1708        save(t,filexml);
1709        end
1710        switch ActionExt
1711            case '.m'
1712                h_fun(Param);
1713            case '.sh'
1714                switch computer
1715                    case {'PCWIN','PCWIN64'} %Windows system
1716                        filexml=regexprep(filexml,'\\','\\\\');% add '\' so that '\' are left as characters
1717                        system([fullfile(ActionPath,[ActionName '.sh']) ' ' RunTime ' ' filexml]);% TODO: adapt to DOS system
1718                    case {'GLNX86','GLNXA64','MACI64'}%Linux  system
1719                        system([fullfile(ActionPath,[ActionName '.sh']) ' ' RunTime ' ' filexml]);
1720                end
1721        end
1722    end
1723elseif strcmp(get(handles.OutputDirExt,'Visible'),'off')
1724    msgbox_uvmat('ERROR',['no output file for Action ' ActionName ', use run mode = local']);% a output dir is needed for background option
1725    return
1726else
1727    %% processing on a different session of the same computer (background) or cluster, create executable files
1728    batch_file_list=cell(NbProcess,1);% initiate the list of executable files
1729    DirBat=fullfile(OutputDir,'0_EXE');
1730    switch computer
1731        case {'PCWIN','PCWIN64'} %Windows system
1732            ExeExt='.bat';
1733        case {'GLNX86','GLNXA64','MACI64'}%Linux  system
1734           ExeExt='.sh';
1735    end
1736    %create subdirectory for executable files
1737    if ~exist(DirBat,'dir')
1738        [tild,msg1]=mkdir(DirBat);
1739        if ~strcmp(msg1,'')
1740            msgbox_uvmat('ERROR',['cannot create ' DirBat ': ' msg1]);%error message for directory creation
1741            return
1742        end
1743    end
1744    %create subdirectory for log files
1745    DirLog=fullfile(OutputDir,'0_LOG');
1746    if ~exist(DirLog,'dir')
1747        [tild,msg1]=mkdir(DirLog);
1748        if ~strcmp(msg1,'')
1749            msgbox_uvmat('ERROR',['cannot create ' DirLog ': ' msg1]);%error message for directory creation
1750            return
1751        end
1752    end
1753    for iprocess=1:NbProcess
1754        if isempty(Param.IndexRange.NbSlice)% process by blocks of i index
1755            Param.IndexRange.first_i=first_i+(iprocess-1)*BlockLength*incr_i;
1756            if Param.IndexRange.first_i>last_i
1757                NbProcess=iprocess-1;
1758                break% leave the loop, we are at the end of the calculation
1759            end
1760            Param.IndexRange.last_i=min(last_i,first_i+(iprocess)*BlockLength*incr_i-1);
1761        else% process by slices of i index if NbSlice is defined, computation in a single process if NbSlice =1
1762            Param.IndexRange.first_i= first_i+iprocess-1;
1763            Param.IndexRange.incr_i=incr_i*Param.IndexRange.NbSlice;
1764        end
1765       
1766        % create, fill and save the xml parameter file
1767        t=struct2xml(Param);
1768        t=set(t,1,'name','Series');
1769        filexml=fullfile_uvmat(DirXml,'',Param.InputTable{1,3},'.xml',OutputNomType,...
1770            Param.IndexRange.first_i,Param.IndexRange.last_i,first_j,last_j);
1771        save(t,filexml);% save the parameter file
1772       
1773        %create the executable file
1774         filebat=fullfile_uvmat(DirBat,'',Param.InputTable{1,3},ExeExt,OutputNomType,...
1775           Param.IndexRange.first_i,Param.IndexRange.last_i,first_j,last_j);
1776        batch_file_list{iprocess}=filebat;
1777        [fid,message]=fopen(filebat,'w');% create the executable file
1778        if isequal(fid,-1)
1779            msgbox_uvmat('ERROR', ['creation of .bat file: ' message]);
1780            return
1781        end
1782       
1783        % set the log file name
1784        filelog=fullfile_uvmat(DirLog,'',Param.InputTable{1,3},'.log',OutputNomType,...
1785            Param.IndexRange.first_i,Param.IndexRange.last_i,first_j,last_j);
1786       
1787        % fill and save the executable file
1788        switch ActionExt
1789            case '.m'% Matlab function
1790                switch computer
1791                    case {'GLNX86','GLNXA64','MACI64'}
1792                        cmd=[...
1793                            '#!/bin/bash \n'...
1794                            '. /etc/sysprofile \n'...
1795                            'matlab -nodisplay -nosplash -nojvm -logfile ''' filelog ''' <<END_MATLAB \n'...
1796                            'addpath(''' path_series '''); \n'...
1797                            'addpath(''' Param.Action.ActionPath '''); \n'...
1798                            '' Param.Action.ActionName  '( ''' filexml '''); \n'...
1799                            'exit \n'...
1800                            'END_MATLAB \n'];
1801                        fprintf(fid,cmd);%fill the executable file with the  char string cmd
1802                        fclose(fid);% close the executable file
1803                        system(['chmod +x ' filebat]);% set the file to executable
1804                    case {'PCWIN','PCWIN64'}
1805                        text_matlabscript=['matlab -automation -logfile ' regexprep(filelog,'\\','\\\\')...
1806                            ' -r "addpath(''' regexprep(path_series,'\\','\\\\') ''');'...
1807                            'addpath(''' regexprep(Param.Action.ActionPath,'\\','\\\\') ''');'...
1808                            '' Param.Action.ActionName  '( ''' regexprep(filexml,'\\','\\\\') ''');exit"'];
1809                        fprintf(fid,text_matlabscript);%fill the executable file with the  char string cmd
1810                        fclose(fid);% close the executable file
1811                end
1812            case '.sh' % compiled Matlab function
1813                switch computer
1814                    case {'GLNX86','GLNXA64','MACI64'}
1815                        cmd=['#!/bin/bash \n '...
1816                            '#$ -cwd \n '...
1817                            'hostname && date \n '...
1818                            'umask 002 \n'...
1819                            fullfile(ActionPath,[ActionName '.sh']) ' ' RunTime ' ' filexml];%allow writting access to created files for user group
1820                        fprintf(fid,cmd);%fill the executable file with the  char string cmd
1821                        fclose(fid);% close the executable file
1822                        system(['chmod +x ' filebat]);% set the file to executable
1823                       
1824                    case {'PCWIN','PCWIN64'}    %       TODO: adapt to Windows system
1825                        %                                 cmd=['matlab -automation -logfile ' regexprep(filelog,'\\','\\\\')...
1826                        %                                     ' -r "addpath(''' regexprep(path_series,'\\','\\\\') ''');'...
1827                        %                                     'addpath(''' regexprep(Param.Action.ActionPath,'\\','\\\\') ''');'...
1828                        %                                     '' Param.Action.ActionName  '( ''' regexprep(filexml,'\\','\\\\') ''');exit"'];
1829                        fprintf(fid,cmd);
1830                        fclose(fid);
1831                        %                               dos([filebat ' &']);
1832                end
1833        end
1834    end
1835end
1836
1837%% launch the executable files for background or cluster processing
1838switch RunMode
1839    case 'background'
1840        for iprocess=1:NbProcess
1841            system([batch_file_list{iprocess} ' &'])% directly execute the command file for each process
1842            msgbox_uvmat('CONFIRMATION',[ActionName 'launched in background: press STATUS to see results'])
1843        end
1844    case 'cluster_oar' % option 'oar-parexec' used
1845        %create subdirectory for oar command and log files
1846        DirOAR=fullfile(OutputDir,'0_OAR');
1847        if exist(DirOAR,'dir')% delete the content of the dir 0_OAR to allow new input
1848            curdir=pwd;
1849            cd(DirOAR)
1850            delete('*')
1851            cd(curdir)
1852        else
1853            [tild,msg1]=mkdir(DirOAR);
1854            if ~strcmp(msg1,'')
1855                msgbox_uvmat('ERROR',['cannot create ' DirOAR ': ' msg1]);%error message for directory creation
1856                return
1857            end
1858        end
1859        max_walltime=3600*12; % 12h max total calculation
1860        walltime_onejob=600;%seconds, max estimated time for asingle file index value
1861        filename_joblist=fullfile(DirOAR,'job_list.txt');%create name of the global executable file
1862        fid=fopen(filename_joblist,'w');
1863        for p=1:length(batch_file_list)
1864            fprintf(fid,[batch_file_list{p} '\n']);% list of exe files
1865        end
1866        fclose(fid);
1867        system(['chmod +x ' filename_joblist]);% set the file to executable
1868        oar_command=['oarsub -n CIVX '...
1869            '-t idempotent --checkpoint ' num2str(walltime_onejob+60) ' '...
1870            '-l /core=' num2str(NbCore) ','...
1871            'walltime=' datestr(min(1.05*walltime_onejob/86400*max(NbProcess*BlockLength*nbfield_j,NbCore)/NbCore,max_walltime/86400),13) ' '...
1872            '-E ' regexprep(filename_joblist,'\.txt\>','.stderr') ' '...
1873            '-O ' regexprep(filename_joblist,'\.txt\>','.stdout') ' '...
1874            extra_oar ' '...
1875            '"oar-parexec -s -f ' filename_joblist ' '...
1876            '-l ' filename_joblist '.log"\n'];
1877        filename_oarcommand=fullfile(DirOAR,'oar_command');
1878        fid=fopen(filename_oarcommand,'w');
1879        fprintf(fid,oar_command);
1880        fclose(fid);
1881        fprintf(oar_command);% display in command line
1882        system(oar_command); 
1883        msgbox_uvmat('CONFIRMATION',[ActionName ' launched in cluster: press STATUS to see results'])
1884end
1885
1886%% reset the GUI series
1887update_waitbar(handles.Waitbar,1); % put the waitbar to end position to indicate launching is finished
1888set(handles.RUN, 'Enable','On')
1889set(handles.RUN,'BackgroundColor',[1 0 0])
1890set(handles.RUN, 'Value',0)
1891
1892%------------------------------------------------------------------------
1893function STOP_Callback(hObject, eventdata, handles)
1894%------------------------------------------------------------------------
1895set(handles.RUN, 'BusyAction','cancel')
1896set(handles.RUN,'BackgroundColor',[1 0 0])
1897set(handles.RUN,'enable','on')
1898set(handles.RUN, 'Value',0)
1899
1900
1901%------------------------------------------------------------------------
1902% --- read parameters from the GUI series
1903%------------------------------------------------------------------------
1904function Param=read_GUI_series(handles)
1905
1906%% read raw parameters from the GUI series
1907Param=read_GUI(handles.series);
1908
1909%% clean the output structure by removing unused information
1910if isfield(Param,'Pairs')
1911    Param=rmfield(Param,'Pairs'); %info Pairs not needed for output
1912end
1913Param.IndexRange=rmfield(Param.IndexRange,'TimeTable');
1914empty_line=false(size(Param.InputTable,1),1);
1915for iline=1:size(Param.InputTable,1)
1916    empty_line(iline)=isempty(cell2mat(Param.InputTable(iline,1:3)));
1917end
1918Param.InputTable(empty_line,:)=[];
1919
1920%------------------------------------------------------------------------
1921% --- Executes on selection change in ActionName.
1922function ActionName_Callback(hObject, eventdata, handles)
1923%------------------------------------------------------------------------
1924
1925%% stop any ongoing series processing
1926if isequal(get(handles.RUN,'Value'),1)
1927    answer= msgbox_uvmat('INPUT_Y-N','stop current Action process?');
1928    if strcmp(answer,'Yes')
1929        STOP_Callback(hObject, eventdata, handles)
1930    else
1931        return
1932    end
1933end
1934set(handles.ActionName,'BackgroundColor',[1 1 0])
1935huigetfile=findobj(allchild(0),'tag','status_display');
1936if ~isempty(huigetfile)
1937    delete(huigetfile)
1938end
1939drawnow
1940
1941%% get Action name and path
1942nb_builtin_ACTION=4; %nbre of functions initially proposed in the menu ActionName (as defined in the Opening fct of series)
1943ActionList=get(handles.ActionName,'String');% list menu fields
1944ActionIndex=get(handles.ActionName,'Value');
1945if ~isequal(ActionIndex,1)% if we are not just opening series
1946    InputTable=get(handles.InputTable,'Data');
1947    if isempty(InputTable{1,4})
1948        msgbox_uvmat('ERROR','no input file available: use Open in the menu bar')
1949        return
1950    end
1951end
1952ActionName= ActionList{get(handles.ActionName,'Value')}; % selected function name
1953ActionPathList=get(handles.ActionName,'UserData');%list of recorded paths to functions of the list ActionName
1954
1955%% add a new function to the menu if 'more...' has been selected in the menu ActionName
1956if isequal(ActionName,'more...')
1957    [FileName, PathName] = uigetfile( ...
1958        {'*.m', ' (*.m)';
1959        '*.m',  '.m files '; ...
1960        '*.*', 'All Files (*.*)'}, ...
1961        'Pick a series processing function ',get(handles.ActionPath,'String'));
1962    if length(FileName)<2
1963        return
1964    end
1965    [ActionPath,ActionName,ActionExt]=fileparts(FileName);
1966   
1967    % insert the choice in the menu ActionName
1968    ActionIndex=find(strcmp(ActionName,ActionList),1);% look for the selected function in the menu Action
1969    if isempty(ActionIndex)%the input string does not exist in the menu
1970        ActionIndex= length(ActionList);
1971        ActionList=[ActionList(1:end-1);{ActionName};ActionList(end)];% the selected function is appended in the menu, before the last item 'more...'
1972        set(handles.ActionName,'String',ActionList)
1973    end
1974   
1975    % record the file extension and extend the path list if it is a new extension
1976    ActionExtList=get(handles.ActionExt,'String');
1977    ActionExtIndex=find(strcmp(ActionExt,ActionExtList), 1);
1978    if isempty(ActionExtIndex)
1979        set(handles.ActionExt,'String',[ActionExtList;{ActionExt}])
1980        ActionExtIndex=numel(ActionExtList)+1;
1981        ActionPathNew=cell(size(ActionPathList,1),1);%new column of ActionPath
1982        ActionPathList=[ActionPathList ActionPathNew];
1983    end
1984    set(handles.ActionName,'UserData',ActionPathList);
1985
1986    % remove old Action options in the menu (keeping a menu length <nb_builtin_ACTION+5)
1987    if length(ActionList)>nb_builtin_ACTION+5; %nb_builtin=nbre of functions always remaining in the initial menu
1988        nbremove=length(ActionList)-nb_builtin_ACTION-5;
1989        ActionList(nb_builtin_ACTION+1:end-5)=[];
1990        ActionPathList(nb_builtin_ACTION+1:end-4,:)=[];
1991        ActionIndex=ActionIndex-nbremove;
1992    end
1993   
1994    % record action menu, choice and path
1995    set(handles.ActionName,'Value',ActionIndex)
1996    set(handles.ActionName,'String',ActionList)
1997    set(handles.ActionExt,'Value',ActionExtIndex)
1998    ActionPathList{ActionIndex,ActionExtIndex}=PathName;
1999       
2000    %record the user defined menu additions in personal file profil_perso
2001    dir_perso=prefdir;
2002    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
2003    if nb_builtin_ACTION+1<=numel(ActionList)-1
2004        ActionListUser=ActionList(nb_builtin_ACTION+1:numel(ActionList)-1);
2005        ActionPathListUser=ActionPathList(nb_builtin_ACTION+1:numel(ActionList)-1,:);
2006        ActionExtListUser={};
2007        if numel(ActionExtList)>2
2008            ActionExtListUser=ActionExtList(3:end);
2009        end
2010        if exist(profil_perso,'file')
2011            save(profil_perso,'ActionListUser','ActionPathListUser','ActionExtListUser','-append')
2012        else
2013            save(profil_perso,'ActionListUser','ActionPathListUser','ActionExtListUser','-V6')
2014        end
2015    end
2016end
2017
2018%% check the current ActionPath to the selected function
2019ActionPath=ActionPathList{ActionIndex};%current recorded path
2020set(handles.ActionPath,'String',ActionPath); %show the path to the senlected function
2021
2022%% reinitialise the waitbar
2023update_waitbar(handles.Waitbar,0)
2024
2025%% create the function handle for Action
2026path_series=which('series');
2027if ~isequal(ActionPath,path_series)
2028    eval(['spath=which(''' ActionName ''');']) %spath = current path of the selected function ACTION
2029    if ~exist(ActionPath,'dir')
2030        errormsg=['The prescribed function path ' ActionPath ' does not exist'];
2031        return
2032    end
2033    if ~isequal(spath,ActionPath)
2034        addpath(ActionPath)% add the prescribed path if not the current one
2035    end
2036end
2037eval(['h_fun=@' ActionName ';'])%create a function handle for ACTION
2038if ~isequal(ActionPath,path_series)
2039        rmpath(ActionPath)% add the prescribed path if not the current one   
2040end
2041
2042%% Activate the Action fct
2043Param=read_GUI_series(handles);% read the parameters from the GUI series
2044ParamOut=h_fun(Param);%run the selected Action function to get the relevant input
2045
2046%% Put the first line of the selected Action fct as tooltip help
2047try
2048    [fid,errormsg] =fopen([ActionName '.m']);
2049    InputText=textscan(fid,'%s',1,'delimiter','\n');
2050    fclose(fid);
2051    set(handles.ActionName,'ToolTipString',InputText{1}{1})% put the first line of the selected function as tooltip help
2052end
2053
2054%% Detect the types of input files
2055SeriesData=get(handles.series,'UserData');% info on the input file series
2056iview_civ=[];nb_netcdf=0;
2057if ~isempty(SeriesData)&&isfield(SeriesData,'FileType')
2058    iview_civ=find(strcmp('civx',SeriesData.FileType)|strcmp('civdata',SeriesData.FileType));
2059    nb_netcdf=numel(find(strcmp('netcdf',SeriesData.FileType)));
2060end
2061if numel(iview_civ)>=1 && ~isempty(iview_civ(1))
2062    menu=set_veltype_display(SeriesData.FileInfo{iview_civ(1)}.CivStage,SeriesData.FileType{iview_civ(1)});
2063    set(handles.VelType,'String',[{'*'};menu])
2064    if numel(iview_civ)>=2
2065        menu=set_veltype_display(SeriesData.FileInfo{iview_civ(2)}.CivStage,SeriesData.FileType{iview_civ(2)});
2066        set(handles.VelType_1,'String',[{'*'};menu])
2067    end
2068end       
2069
2070%% Check whether alphabetical sorting of input Subdir is allowed by the Action fct  (for multiples series entries)
2071if isfield(ParamOut,'AllowInputSort')&&isequal(ParamOut.AllowInputSort,'on')&& size(Param.InputTable,1)>1
2072    [tild,iview]=sort(InputTable(:,2)); %subdirectories sorted in alphabetical order
2073    set(handles.InputTable,'Data',InputTable(iview,:));
2074    MinIndex_i=get(handles.MinIndex_i,'Data');
2075    MinIndex_j=get(handles.MinIndex_j,'Data');
2076    MaxIndex_i=get(handles.MaxIndex_i,'Data');
2077    MaxIndex_j=get(handles.MaxIndex_j,'Data');
2078    set(handles.MinIndex_i,'Data',MinIndex_i(iview,:));
2079    set(handles.MinIndex_j,'Data',MinIndex_j(iview,:));
2080    set(handles.MaxIndex_i,'Data',MaxIndex_i(iview,:));
2081    set(handles.MaxIndex_j,'Data',MaxIndex_j(iview,:));
2082    TimeTable=get(handles.TimeTable,'Data');
2083    set(handles.TimeTable,'Data',TimeTable(iview,:));
2084    PairString=get(handles.PairString,'Data');
2085    set(handles.PairString,'Data',PairString(iview,:));
2086end
2087
2088%% Impose the whole input file index range if requested
2089if isfield(ParamOut,'WholeIndexRange')&&isequal(ParamOut.WholeIndexRange,'on')
2090    MinIndex_i=get(handles.MinIndex_i,'Data');
2091    MinIndex_j=get(handles.MinIndex_j,'Data');
2092    MaxIndex_i=get(handles.MaxIndex_i,'Data');
2093    MaxIndex_j=get(handles.MaxIndex_j,'Data');
2094    set(handles.num_first_i,'String',num2str(MinIndex_i(1)))% set first as the min index (for the first line)
2095    set(handles.num_last_i,'String',num2str(MaxIndex_i(1)))% set last as the max index (for the first line)
2096    set(handles.num_incr_i,'String','1')
2097    set(handles.num_first_j,'String',num2str(MinIndex_j(1)))% set first as the min index (for the first line)
2098    set(handles.num_last_j,'String',num2str(MaxIndex_j(1)))% set last as the max index (for the first line)
2099    set(handles.num_incr_j,'String','1')
2100else  % check index ranges
2101    first_i=1;last_i=1;first_j=1;last_j=1;
2102    if isfield(Param.IndexRange,'first_i')
2103        first_i=Param.IndexRange.first_i;
2104       % incr_i=Param.IndexRange.incr_i;
2105        last_i=Param.IndexRange.last_i;
2106    end
2107    if isfield(Param.IndexRange,'first_j')
2108        first_j=Param.IndexRange.first_j;
2109       % incr_j=Param.IndexRange.incr_j;
2110        last_j=Param.IndexRange.last_j;
2111    end
2112    if last_i < first_i || last_j < first_j , msgbox_uvmat('ERROR','last field number must be larger than the first one'),...
2113            set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
2114end
2115
2116%% desable j index if if set by the civ_input GUI
2117if isfield(ParamOut,'Desable_j_index')&&isequal(ParamOut.Desable_j_index,'on')
2118    set(handles.num_first_j,'Enable','off')
2119    set(handles.num_last_j,'Enable','off')
2120    set(handles.num_incr_j,'Enable','off')
2121    set(handles.num_incr_j,'String','')
2122else
2123   set(handles.num_first_j,'Enable','on')
2124    set(handles.num_last_j,'Enable','on')
2125    set(handles.num_incr_j,'Enable','on')
2126end
2127
2128%% NbSlice visibility
2129NbSliceVisible='off';%default
2130if isfield(ParamOut,'NbSlice') && isequal(ParamOut.NbSlice,'on')
2131    NbSliceVisible='on';
2132    set(handles.num_NbProcess,'String',get(handles.num_NbSlice,'String'))% the nbre of processes is imposed as the nbre of slices
2133else
2134    set(handles.num_NbProcess,'String','')% free nbre of processes
2135end
2136set(handles.num_NbSlice,'Visible',NbSliceVisible)
2137set(handles.NbSlice_title,'Visible',NbSliceVisible)
2138
2139%% Visibility of VelType and VelType_1 menus
2140VelTypeVisible='off';  %hidden by default
2141VelType_1Visible='off';
2142InputFieldsVisible='off';%visibility of the frame Fields
2143if isfield(ParamOut,'VelType')
2144    if strcmp( ParamOut.VelType,'on')||strcmp(ParamOut.VelType,'one')||strcmp( ParamOut.VelType,'two')
2145        if numel(iview_civ)>=1
2146            VelTypeVisible='on';
2147            InputFieldsVisible='on';
2148        end
2149    end
2150    if strcmp( ParamOut.VelType,'two')
2151        if numel(iview_civ)>=2
2152            VelType_1Visible='on';
2153        end
2154    end
2155end
2156set(handles.VelType,'Visible',VelTypeVisible)
2157set(handles.VelType_text,'Visible',VelTypeVisible);
2158set(handles.VelType_1,'Visible',VelType_1Visible)
2159set(handles.VelType_text_1,'Visible',VelType_1Visible);
2160
2161%% Visibility of FieldName and FieldName_1 menus
2162FieldNameVisible='off';  %hidden by default
2163FieldName_1Visible='off';  %hidden by default
2164if isfield(ParamOut,'FieldName')
2165    if strcmp( ParamOut.FieldName,'on') || strcmp(ParamOut.FieldName,'one')||strcmp( ParamOut.FieldName,'two')
2166        if (numel(iview_civ)+nb_netcdf)>=1
2167            InputFieldsVisible='on';
2168            FieldNameVisible='on';
2169        end
2170    end
2171    if strcmp( ParamOut.FieldName,'two')
2172        if (numel(iview_civ)+nb_netcdf)>=1
2173            FieldName_1Visible='on';
2174        end
2175    end
2176end
2177set(handles.InputFields,'Visible',InputFieldsVisible)
2178set(handles.FieldName,'Visible',FieldNameVisible) % test for MenuBorser
2179set(handles.FieldName_1,'Visible',FieldName_1Visible)
2180
2181%% Visibility of FieldTransform menu
2182FieldTransformVisible='off';  %hidden by default
2183if isfield(ParamOut,'FieldTransform')
2184    FieldTransformVisible=ParamOut.FieldTransform; 
2185    TransformName_Callback([],[], handles)
2186end
2187set(handles.FieldTransform,'Visible',FieldTransformVisible)
2188if isfield(ParamOut,'TransformPath')
2189    set(handles.ActionExt,'UserData',ParamOut.TransformPath)
2190else
2191    set(handles.ActionExt,'UserData',[])
2192end
2193
2194%% Visibility of projection object
2195ProjObjectVisible='off';  %hidden by default
2196if isfield(ParamOut,'ProjObject')
2197    ProjObjectVisible=ParamOut.ProjObject;
2198end
2199set(handles.CheckObject,'Visible',ProjObjectVisible)
2200if ~get(handles.CheckObject,'Value')
2201    ProjObjectVisible='off';
2202end
2203set(handles.ProjObject,'Visible',ProjObjectVisible)
2204set(handles.DeleteObject,'Visible',ProjObjectVisible)
2205set(handles.ViewObject,'Visible',ProjObjectVisible)
2206set(handles.EditObject,'Visible',ProjObjectVisible)
2207
2208%% Visibility of mask input
2209MaskVisible='off';  %hidden by default
2210if isfield(ParamOut,'Mask')
2211    MaskVisible=ParamOut.Mask;
2212end
2213%set(handles.Mask,'Visible',MaskVisible)
2214set(handles.CheckMask,'Visible',MaskVisible);
2215
2216%% definition of the directory containing the output files
2217OutputDirVisible='off';
2218if isfield(ParamOut,'OutputDirExt')&&~isempty(ParamOut.OutputDirExt)
2219    OutputSubDirMode='all';%default
2220    if isfield(ParamOut,'OutputSubDirMode')
2221        OutputSubDirMode=ParamOut.OutputSubDirMode;
2222    end
2223    set(handles.OutputDirExt,'String',ParamOut.OutputDirExt)
2224    OutputDirVisible='on';
2225    SubDir=InputTable(1:end,2); %set of subdirectories sorted in alphabetical order
2226    if strcmp(OutputSubDirMode,'last')
2227        SubDirOut=SubDir{end};
2228    else
2229        SubDirOut=SubDir{1};
2230        if ~strcmp(OutputSubDirMode,'first')  && numel(SubDir)>1
2231            for ilist=2:numel(SubDir)
2232                SubDirOut=[SubDirOut '-' SubDir{ilist}];
2233            end
2234        end
2235    end
2236    set(handles.OutputSubDir,'String',SubDirOut)
2237end
2238set(handles.OutputDirExt,'Visible',OutputDirVisible)
2239set(handles.OutputSubDir,'Visible',OutputDirVisible)
2240set(handles.OutputDir_title,'Visible',OutputDirVisible)
2241set(handles.RunMode,'Visible',OutputDirVisible)
2242set(handles.ActionExt,'Visible',OutputDirVisible)
2243set(handles.RunMode_title,'Visible',OutputDirVisible)
2244set(handles.ActionExt_title,'Visible',OutputDirVisible)
2245
2246
2247%% Expected nbre of output files
2248if isfield(ParamOut,'OutputFileMode')
2249    StatusData.OutputFileMode=ParamOut.OutputFileMode;
2250    set(handles.status,'UserData',StatusData)
2251end
2252
2253%% definition of an additional parameter set, determined by an ancillary GUI
2254if isfield(ParamOut,'ActionInput')
2255%     set(handles.ActionInput,'Visible','on')
2256%     set(handles.ActionInput_title,'Visible','on')
2257    set(handles.ActionInput,'Visible','on')
2258 %   set(handles.ActionInput,'Value',0)
2259%     set(handles.ActionInput,'String',ActionName)
2260    ParamOut.ActionInput.Program=ActionName; % record the program in ActionInput
2261    SeriesData.ActionInput=ParamOut.ActionInput;
2262else
2263%     set(handles.ActionInput,'Visible','off')
2264%     set(handles.ActionInput_title,'Visible','off')
2265    set(handles.ActionInput,'Visible','off')
2266    if isfield(SeriesData,'ActionInput')
2267    SeriesData=rmfield(SeriesData,'ActionInput');
2268    end
2269end   
2270set(handles.series,'UserData',SeriesData)
2271set(handles.ActionName,'BackgroundColor',[1 1 1])
2272
2273%------------------------------------------------------------------------
2274% --- Executes on button press in ActionInput.
2275function ActionInput_Callback(hObject, eventdata, handles)
2276%------------------------------------------------------------------------
2277% if get(handles.ActionInput,'Value')
2278ActionName_Callback(hObject, eventdata, handles)
2279% end
2280
2281%------------------------------------------------------------------------
2282% --- Executes on selection change in FieldName.
2283function FieldName_Callback(hObject, eventdata, handles)
2284%------------------------------------------------------------------------
2285field_str=get(handles.FieldName,'String');
2286field_index=get(handles.FieldName,'Value');
2287field=field_str{field_index(1)};
2288if isequal(field,'get_field...')
2289    hget_field=findobj(allchild(0),'name','get_field');
2290    if ~isempty(hget_field)
2291        delete(hget_field)%delete opened versions of get_field
2292    end
2293    Param=read_GUI(handles.series);
2294    Param.InputTable=Param.InputTable(1,:);
2295    % check the existence of the first file in the series
2296    first_j=[];
2297    if isfield(Param.IndexRange,'first_j'); first_j=Param.IndexRange.first_j; end
2298    last_j=[];
2299    if isfield(Param.IndexRange,'last_j'); last_j=Param.IndexRange.last_j; end
2300    PairString='';
2301    if isfield(Param.IndexRange,'PairString'); PairString=Param.IndexRange.PairString; end
2302    [i1,i2,j1,j2] = get_file_index(Param.IndexRange.first_i,first_j,PairString);
2303    FirstFileName=fullfile_uvmat(Param.InputTable{1,1},Param.InputTable{1,2},Param.InputTable{1,3},...
2304        Param.InputTable{1,5},Param.InputTable{1,4},i1,i2,j1,j2);
2305    if exist(FirstFileName,'file')
2306        ParamIn.SeriesInput=1;
2307        GetFieldData=get_field(FirstFileName,ParamIn);
2308        FieldList={};
2309        switch GetFieldData.FieldOption
2310            case 'vectors'
2311                UName=GetFieldData.PanelVectors.vector_x;
2312                VName=GetFieldData.PanelVectors.vector_y;
2313                YName={GetFieldData.Coordinates.Coord_y};
2314                FieldList={['vec(' UName ',' VName ')'];...
2315                    ['norm(' UName ',' VName ')'];...
2316                    UName;VName};
2317            case {'scalar','pick variables'}
2318                FieldList=GetFieldData.PanelScalar.scalar;
2319                YName={GetFieldData.Coordinates.Coord_y};
2320                if ischar(FieldList)
2321                    FieldList={FieldList};
2322                end
2323            case '1D plot'
2324                YName=GetFieldData.PanelOrdinate.ordinate;
2325            case 'civdata...'
2326                FieldList=[set_field_list('U','V','C') ;{'C'}];
2327                set(handles.FieldName,'Value',2) % set menu to 'velocity
2328                XName='X';
2329                YName='y';
2330                set(handles.VelType,'visible','on')
2331        end
2332        if ~strcmp(GetFieldData.FieldOption,'civdata...')
2333            set(handles.VelType,'visible','off')
2334            XName=GetFieldData.Coordinates.Coord_x;
2335            TimeNameStr=GetFieldData.Time.SwitchVarIndexTime;
2336            switch TimeNameStr
2337                case 'file index'
2338                    set(handles.TimeName,'String','');
2339                case 'attribute'
2340                    set(handles.TimeName,'String',['att:' GetFieldData.Time.TimeName]);
2341                case 'variable'
2342                    set(handles.TimeName,'String',['var:' GetFieldData.Time.TimeName])
2343                    set(handles.NomType,'String','*')
2344                    set(handles.RootFile,'String',[get(handles.RootFile,'String') get(handles.FileIndex,'String')])% A VERIFIER !!!!!!
2345                    set(handles.FileIndex,'String','')
2346                    ParamIn.TimeVarName=GetFieldData.Time.TimeName;
2347                case 'matrix_index'
2348                    set(handles.TimeName,'String',['dim:' GetFieldData.Time.TimeName]);
2349                    set(handles.NomType,'String','*')
2350                    set(handles.RootFile,'String',[get(handles.RootFile,'String') get(handles.FileIndex,'String')])
2351                    set(handles.FileIndex,'String','')
2352                    ParamIn.TimeDimName=GetFieldData.Time.TimeName;
2353            end
2354        end
2355        set(handles.Coord_x,'String',{XName})
2356        set(handles.Coord_y,'String',YName)
2357        set(handles.FieldName,'Value',1)
2358        set(handles.FieldName,'String',[FieldList; {'get_field...'}]);
2359    end
2360end
2361
2362%------------------------------------------------------------------------
2363% --- Executes on selection change in FieldName_1.
2364function FieldName_1_Callback(hObject, eventdata, handles)
2365%------------------------------------------------------------------------
2366field_str=get(handles.FieldName_1,'String');
2367field_index=get(handles.FieldName_1,'Value');
2368field=field_str{field_index(1)};
2369if isequal(field,'get_field...')
2370    hget_field=findobj(allchild(0),'name','get_field');
2371    if ~isempty(hget_field)
2372        delete(hget_field)%delete opened versions of get_field
2373    end
2374    Param=read_GUI(handles.series);
2375    Param.InputTable=Param.InputTable(1,:);
2376    % check the existence of the first file in the series
2377    first_j=[];
2378    if isfield(Param.IndexRange,'first_j'); first_j=Param.IndexRange.first_j; end
2379    if isfield(Param.IndexRange,'last_j'); last_j=Param.IndexRange.last_j; end
2380    PairString='';
2381    if isfield(Param.IndexRange,'PairString'); PairString=Param.IndexRange.PairString; end
2382    [i1,i2,j1,j2] = get_file_index(Param.IndexRange.first_i,first_j,PairString);
2383    FirstFileName=fullfile_uvmat(Param.InputTable{1,1},Param.InputTable{1,2},Param.InputTable{1,3},...
2384        Param.InputTable{1,5},Param.InputTable{1,4},i1,i2,j1,j2);
2385    if exist(FirstFileName,'file')
2386        ParamIn.SeriesInput=1;
2387        GetFieldData=get_field(FirstFileName,ParamIn);
2388        FieldList={};
2389        switch GetFieldData.FieldOption
2390            case 'vectors'
2391                UName=GetFieldData.PanelVectors.vector_x;
2392                VName=GetFieldData.PanelVectors.vector_y;
2393                FieldList={['vec(' UName ',' VName ')'];...
2394                    ['norm(' UName ',' VName ')'];...
2395                    UName;VName};
2396            case {'scalar','pick variables'}
2397                FieldList=GetFieldData.PanelScalar.scalar;
2398                if ischar(FieldList)
2399                    FieldList={FieldList};
2400                end
2401            case '1D plot'
2402
2403            case 'civdata...'
2404                FieldList=set_field_list('U','V','C');
2405                set(handles.FieldName,'Value',2) % set menu to 'velocity
2406        end
2407        if ~strcmp(GetFieldData.FieldOption,'civdata...')
2408            TimeNameStr=GetFieldData.Time.SwitchVarIndexTime;
2409            switch TimeNameStr
2410                case 'file index'
2411                    set(handles.TimeName,'String','');
2412                case 'attribute'
2413                    set(handles.TimeName,'String',['att:' GetFieldData.Time.TimeName]);
2414                case 'variable'
2415                    set(handles.TimeName,'String',['var:' GetFieldData.Time.TimeName])
2416                    set(handles.NomType,'String','*')
2417                    set(handles.RootFile,'String',[get(handles.RootFile,'String') get(handles.FileIndex,'String')])% A VERIFIER !!!!!!
2418                    set(handles.FileIndex,'String','')
2419                    ParamIn.TimeVarName=GetFieldData.Time.TimeName;
2420                case 'matrix_index'
2421                    set(handles.TimeName,'String',['dim:' GetFieldData.Time.TimeName]);
2422                    set(handles.NomType,'String','*')
2423                    set(handles.RootFile,'String',[get(handles.RootFile,'String') get(handles.FileIndex,'String')])
2424                    set(handles.FileIndex,'String','')
2425                    ParamIn.TimeDimName=GetFieldData.Time.TimeName;
2426            end
2427        end
2428        set(handles.FieldName_1,'Value',1)
2429        set(handles.FieldName_1,'String',[FieldList; {'get_field...'}]);
2430    end
2431end   
2432
2433
2434%%%%%%%%%%%%%
2435function [ind_remove]=find_pairs(dirpair,ind_i,last_i)
2436indsel=ind_i;
2437indiff=diff(ind_i); %test index increment to detect multiplets (several pairs with the same index ind_i) and holes in the series
2438indiff=[1 indiff last_i-ind_i(end)+1];%for testing gaps with the imposed bounds
2439if ~isempty(indiff)
2440    indiff2=diff(indiff);
2441    indiffp=[indiff2 1];
2442    indiffm=[1 indiff2];
2443    ind_multi_m=find((indiff==0)&(indiffm<0))-1;%indices of first members of multiplets
2444    ind_multi_p=find((indiff==0)&(indiffp>0));%indices of last members of multiplets
2445    %for each multiplet, select the most recent file
2446    ind_remove=[];
2447    for i=1:length(ind_multi_m)
2448        ind_pairs=ind_multi_m(i):ind_multi_p(i);
2449        for imulti=1:length(ind_pairs)
2450            datepair(imulti)=datenum(dirpair(ind_pairs(imulti)).date);%dates of creation
2451        end
2452        [datenew,indsort2]=sort(datepair); %sort the multiplet by creation date
2453        ind_s=indsort2(1:end-1);%
2454        ind_remove=[ind_remove ind_pairs(ind_s)];%remove these indices, leave the last one
2455    end
2456end
2457
2458%------------------------------------------------------------------------
2459% --- determine the list of index pairstring of processing file
2460function [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)
2461%------------------------------------------------------------------------
2462num_i1=num_i;% set of first image numbers by default
2463num_i2=num_i;
2464num_j1=num_j;
2465num_j2=num_j;
2466num_i_out=num_i;
2467num_j_out=num_j;
2468% if isequal (NomType,'_1-2_1') || isequal (NomType,'_1-2')
2469if isequal(mode,'series(Di)')
2470    num_i1_line=num_i+ind_shift(3);% set of first image numbers
2471    num_i2_line=num_i+ind_shift(4);
2472    % adjust the first and last field number
2473        indsel=find(num_i1_line >= 1);
2474    num_i_out=num_i(indsel);
2475    num_i1_line=num_i1_line(indsel);
2476    num_i2_line=num_i2_line(indsel);
2477    num_j1=meshgrid(num_j,ones(size(num_i1_line)));
2478    num_j2=meshgrid(num_j,ones(size(num_i1_line)));
2479    [xx,num_i1]=meshgrid(num_j,num_i1_line);
2480    [xx,num_i2]=meshgrid(num_j,num_i2_line);
2481elseif isequal (mode,'series(Dj)')||isequal (mode,'bursts')
2482    if isequal(mode,'bursts') %case of bursts (png_old or png_2D)
2483        num_j1=ind_shift(1)*ones(size(num_i));
2484        num_j2=ind_shift(2)*ones(size(num_i));
2485    else
2486        num_j1_col=num_j+ind_shift(1);% set of first image numbers
2487        num_j2_col=num_j+ind_shift(2);
2488        % adjust the first field number
2489        indsel=find((num_j1_col >= 1));   
2490        num_j_out=num_j(indsel);
2491        num_j1_col=num_j1_col(indsel);
2492        num_j2_col=num_j2_col(indsel);
2493        [num_i1,num_j1]=meshgrid(num_i,num_j1_col);
2494        [num_i2,num_j2]=meshgrid(num_i,num_j2_col);
2495    end   
2496end
2497
2498%------------------------------------------------------------------------
2499% --- Executes on button press in CheckObject.
2500function CheckObject_Callback(hObject, eventdata, handles)
2501%------------------------------------------------------------------------
2502hset_object=findobj(allchild(0),'tag','set_object');%find the set_object interface handle
2503if get(handles.CheckObject,'Value')
2504    SeriesData=get(handles.series,'UserData');
2505    if isfield(SeriesData,'ProjObject') && ~isempty(SeriesData.ProjObject)
2506        set(handles.ViewObject,'Value',1)
2507        ViewObject_Callback(hObject, eventdata, handles)
2508    else
2509        if ishandle(hset_object)
2510            uistack(hset_object,'top')% show the GUI set_object if opened
2511        else
2512            %get the object file
2513            InputTable=get(handles.InputTable,'Data');
2514            defaultname=InputTable{1,1};
2515            if isempty(defaultname)
2516                defaultname={''};
2517            end
2518            fileinput=uigetfile_uvmat('pick a xml object file (or use uvmat to create it)',defaultname,'.xml');
2519            if isempty(fileinput)% exit if no object file is selected
2520                set(handles.CheckObject,'Value',0)
2521                return
2522            end
2523            %read the file
2524            data=xml2struct(fileinput);
2525            if ~isfield(data,'Type')
2526                msgbox_uvmat('ERROR',[fileinput ' is not an object xml file'])
2527                set(handles.CheckObject,'Value',0)
2528                return
2529            end
2530            if ~isfield(data,'ProjMode')
2531                data.ProjMode='none';
2532            end
2533            hset_object=set_object(data);% call the set_object interface
2534            set(hset_object,'Name','set_object_series')% name to distinguish from set_object used with uvmat
2535        end
2536        ProjObject=read_GUI(hset_object);
2537        set(handles.ProjObject,'String',ProjObject.Name);%display the object name
2538        SeriesData=get(handles.series,'UserData');
2539        SeriesData.ProjObject=ProjObject;
2540        set(handles.series,'UserData',SeriesData);
2541    end
2542    set(handles.EditObject,'Visible','on');
2543    set(handles.DeleteObject,'Visible','on');
2544    set(handles.ViewObject,'Visible','on');
2545    set(handles.ProjObject,'Visible','on');
2546else
2547    set(handles.EditObject,'Visible','off');
2548    set(handles.DeleteObject,'Visible','off');
2549    set(handles.ViewObject,'Visible','off');
2550    if ~ishandle(hset_object)
2551        set(handles.ViewObject,'Value',0);
2552    end
2553    set(handles.ProjObject,'Visible','off');
2554end
2555
2556%------------------------------------------------------------------------
2557% --- Executes on button press in ViewObject.
2558%------------------------------------------------------------------------
2559function ViewObject_Callback(hObject, eventdata, handles)
2560
2561UserData=get(handles.series,'UserData');
2562hset_object=findobj(allchild(0),'Tag','set_object');
2563if ~isempty(hset_object)
2564    delete(hset_object)% refresh set_object if already opened
2565end
2566hset_object=set_object(UserData.ProjObject);
2567set(hset_object,'Name','view_object_series')
2568
2569
2570%------------------------------------------------------------------------
2571% --- Executes on button press in EditObject.
2572function EditObject_Callback(hObject, eventdata, handles)
2573%------------------------------------------------------------------------
2574if get(handles.EditObject,'Value')
2575    set(handles.ViewObject,'Value',0)
2576        UserData=get(handles.series,'UserData');
2577    hset_object=set_object(UserData.ProjObject);
2578    set(hset_object,'Name','edit_object_series')
2579    set(get(hset_object,'Children'),'Enable','on')
2580else
2581    hset_object=findobj(allchild(0),'Tag','set_object');
2582    if ~isempty(hset_object)
2583        set(get(hset_object,'Children'),'Enable','off')
2584    end
2585end
2586
2587%------------------------------------------------------------------------
2588% --- Executes on button press in DeleteObject.
2589function DeleteObject_Callback(hObject, eventdata, handles)
2590%------------------------------------------------------------------------
2591SeriesData=get(handles.series,'UserData');
2592SeriesData.ProjObject=[];
2593set(handles.series,'UserData',SeriesData)
2594set(handles.ProjObject,'String','')
2595set(handles.ProjObject,'Visible','off')
2596set(handles.CheckObject,'Value',0)
2597set(handles.ViewObject,'Visible','off')
2598set(handles.EditObject,'Visible','off')
2599hset_object=findobj(allchild(0),'name','set_object_series');
2600if ~isempty(hset_object)
2601    delete(hset_object)
2602end
2603set(handles.DeleteObject,'Visible','off')
2604
2605%------------------------------------------------------------------------
2606% --- Executed when CheckMask is activated
2607%------------------------------------------------------------------------
2608function CheckMask_Callback(hObject, eventdata, handles)
2609
2610if get(handles.CheckMask,'Value')
2611    InputTable=get(handles.InputTable,'Data');
2612    nbview=size(InputTable,1);
2613    MaskTable=cell(nbview,1);%default
2614    ListMask=cell(nbview,1);%default
2615    MaskData=get(handles.MaskTable,'Data');
2616    MaskData(size(MaskData,1):nbview,1)=cell(size(MaskData,1):nbview,1);%complement if undefined lines
2617    for iview=1:nbview
2618        ListMask{iview,1}=num2str(iview);
2619        RootPath=InputTable{iview,1};
2620        if ~isempty(RootPath)
2621            if isempty(MaskData{iview})
2622                SubDir=InputTable{iview,2};
2623                MaskPath=fullfile(RootPath,[regexprep(SubDir,'\..*','') '.mask']);%take the root part of SubDir, before the first dot '.'
2624                if exist(MaskPath,'dir')
2625                    ListStruct=dir(MaskPath);%look for a mask file
2626                    ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray
2627                    check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files
2628                    ListFiles=ListCells(1,:);%list of file and dri names
2629                    ListFiles=ListFiles(~check_dir);%list of file names (excluding dir)
2630                    mdetect=0;
2631                    if ~isempty(ListFiles)
2632                        for ifile=1:numel(ListFiles)
2633                            [tild,tild,MaskFile{ifile},i1_series,i2_series,j1_series,j2_series,MaskNomType,MaskFileType]=find_file_series(MaskPath,ListFiles{ifile},0);
2634                            if strcmp(MaskFileType,'image') && isempty(i2_series) && isempty(j2_series)
2635                                mdetect=1;
2636                                MaskName=ListFiles{ifile};
2637                            end
2638                            if ~strcmp(MaskFile{ifile},MaskFile{1})
2639                                mdetect=0;% cancel detection test in case of multiple masks, use the brower for selection
2640                                break
2641                            end
2642                        end
2643                    end
2644                    if mdetect==1
2645                        MaskName=fullfile(MaskPath,'mask_1.png');
2646                    else
2647                        MaskName=uigetfile_uvmat('select a mask file:',MaskPath,'image');
2648                    end
2649                else
2650                    MaskName=uigetfile_uvmat('select a mask file:',RootPath,'image');
2651                end
2652                MaskTable{iview,1}=MaskName ;
2653                ListMask{iview,1}=num2str(iview);
2654            end
2655        end
2656    end
2657    set(handles.MaskTable,'Data',MaskTable)
2658    set(handles.MaskTable,'Visible','on')
2659    set(handles.MaskBrowse,'Visible','on')
2660    set(handles.ListMask,'Visible','on')
2661    set(handles.ListMask,'String',ListMask)
2662    set(handles.ListMask,'Value',1)
2663else
2664    set(handles.MaskTable,'Visible','off')
2665    set(handles.MaskBrowse,'Visible','off')
2666    set(handles.ListMask,'Visible','off')
2667end
2668
2669%------------------------------------------------------------------------
2670% --- Executes on button press in MaskBrowse.
2671%------------------------------------------------------------------------
2672function MaskBrowse_Callback(hObject, eventdata, handles)
2673
2674InputTable=get(handles.InputTable,'Data');
2675iview=get(handles.ListMask,'Value');
2676RootPath=InputTable{iview,1};
2677MaskName=uigetfile_uvmat('select a mask file:',RootPath,'image');
2678if ~isempty(MaskName)
2679    MaskTable=get(handles.MaskTable,'Data');
2680    MaskTable{iview,1}=MaskName ;
2681    set(handles.MaskTable,'Data',MaskTable)
2682end
2683
2684%------------------------------------------------------------------------
2685% --- Executes when selected cell(s) is changed in MaskTable.
2686%------------------------------------------------------------------------
2687function MaskTable_CellSelectionCallback(hObject, eventdata, handles)
2688
2689if numel(eventdata.Indices)>=1
2690set(handles.ListMask,'Value',eventdata.Indices(1))
2691end
2692
2693%-------------------------------------------------------------------
2694function MenuHelp_Callback(hObject, eventdata, handles)
2695%-------------------------------------------------------------------
2696path_to_uvmat=which ('uvmat');% check the path of uvmat
2697pathelp=fileparts(path_to_uvmat);
2698helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
2699if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
2700else
2701    addpath (fullfile(pathelp,'uvmat_doc'))
2702    web([helpfile '#series'])
2703end
2704
2705%-------------------------------------------------------------------
2706% --- Executes on selection change in TransformName.
2707function TransformName_Callback(hObject, eventdata, handles)
2708%----------------------------------------------------------------------
2709TransformList=get(handles.TransformName,'String');
2710TransformIndex=get(handles.TransformName,'Value');
2711TransformName=TransformList{TransformIndex};
2712TransformPathList=get(handles.TransformName,'UserData');
2713nb_builtin_transform=4;
2714if isequal(TransformName,'more...');     
2715    FileName=uigetfile_uvmat('Pick a transform function',get(handles.TransformPath,'String'),'.m');
2716    if isempty(FileName)
2717        return     %browser closed without choice
2718    end
2719    [TransformPath,TransformName,TransformExt]=fileparts(FileName);% removes extension .m
2720    if ~strcmp(TransformExt,'.m')
2721        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
2722        return
2723    end
2724     % insert the choice in the menu
2725    TransformIndex=find(strcmp(TransformName,TransformList),1);% look for the selected function in the menu Action
2726    if isempty(TransformIndex)%the input string does not exist in the menu
2727        TransformIndex= length(TransformList);
2728        TransformList=[TransformList(1:end-1);{TransformName};TransformList(end)];% the selected function is appended in the menu, before the last item 'more...'
2729        set(handles.TransformName,'String',TransformList)
2730        TransformPathList=[TransformPathList;{TransformPath}];
2731    else% the input function already exist, we update its path (possibly new)
2732        TransformPathList{TransformIndex}=TransformPath;%
2733        set(handles.TransformName,'Value',TransformIndex)
2734    end
2735   % save the new menu in the personal file 'uvmat_perso.mat'
2736   dir_perso=prefdir;%personal Matalb directory
2737   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
2738   if exist(profil_perso,'file')
2739       for ilist=nb_builtin_transform+1:numel(TransformPathList)
2740           TransformListUser{ilist-nb_builtin_transform}=TransformList{ilist};
2741           TransformPathListUser{ilist-nb_builtin_transform}=TransformPathList{ilist};
2742       end
2743       TransformPathListUser=TransformPathListUser';
2744       TransformListUser=TransformListUser';
2745       save (profil_perso,'TransformPathListUser','TransformListUser','-append'); %store the root name for future opening of uvmat
2746   end
2747end
2748
2749%display the current function path
2750set(handles.TransformPath,'String',TransformPathList{TransformIndex}); %show the path to the senlected function
2751set(handles.TransformName,'UserData',TransformPathList);
2752
2753%------------------------------------------------------------------------
2754% --- fct activated by the upper bar menu ExportConfig
2755%------------------------------------------------------------------------
2756function MenuExportConfig_Callback(hObject, eventdata, handles)
2757
2758global Param
2759Param=read_GUI_series(handles);
2760evalin('base','global Param')%make CurData global in the workspace
2761display('current series config :')
2762evalin('base','Param') %display CurData in the workspace
2763commandwindow; %brings the Matlab command window to the front
2764
2765%------------------------------------------------------------------------
2766% --- fct activated by the upper bar menu InportConfig: import
2767%     menu settings from an xml file (stored in /0_XML for each run)
2768%------------------------------------------------------------------------
2769function MenuImportConfig_Callback(hObject, eventdata, handles)
2770% SeriesData=get(handles.series,'UserData');
2771% if isfield(SeriesData,'RefFile')
2772%     oldfile=SeriesData.RefFile{1};
2773% end
2774%% use a strating file name for browserr
2775InputTable=get(handles.InputTable,'Data');
2776oldfile=InputTable{1,1};
2777if isempty(oldfile)
2778    % use a file name stored in prefdir
2779    dir_perso=prefdir;
2780    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
2781    if exist(profil_perso,'file')
2782        h=load (profil_perso);
2783        if isfield(h,'RootPath') && ischar(h.RootPath)
2784            oldfile=h.RootPath;
2785        end
2786    end
2787end
2788filexml=uigetfile_uvmat('pick a xml parameter file',oldfile,'.xml');% get the xml file containing processing parameters
2789%proceed only if a file has been introduced by the browser
2790if ~isempty(filexml)
2791    Param=xml2struct(filexml);% read the input xml file as a Matlab structure
2792    % ask to stop current Action if button RUN is in action (another process is already running)
2793    if isequal(get(handles.RUN,'Value'),1)
2794        answer= msgbox_uvmat('INPUT_Y-N','stop current Action process?');
2795        if strcmp(answer,'Yes')
2796            STOP_Callback(hObject, eventdata, handles)
2797        else
2798            return
2799        end
2800    end
2801    Param.Action.RUN=0; %desactivate the input RUN=1
2802    fill_GUI(Param,handles.series)% fill the elements of the GUI series with the input parameters
2803    SeriesData=get(handles.series,'UserData');
2804    if isfield(Param,'ActionInput')%  introduce  parameters specific to an Action fct, for instance PIV parameters
2805        set(handles.ActionInput,'Visible','on')
2806        set(handles.ActionInput,'Value',0)
2807        SeriesData.ActionInput=Param.ActionInput;
2808    end
2809    if isfield(Param,'ProjObject') %introduce projection object if relevant
2810        SeriesData.ProjObject=Param.ProjObject;
2811    end
2812    set(handles.series,'UserData',SeriesData)
2813    if isfield(Param,'CheckObject') && isequal(Param.CheckObject,1)
2814        set(handles.ProjObject,'String',Param.ProjObject.Name)
2815        set(handles.ViewObject,'Visible','on')
2816        set(handles.EditObject,'Visible','on')
2817        set(handles.DeleteObject,'Visible','on')
2818    else     
2819        set(handles.ProjObject,'String','')
2820        set(handles.ProjObject,'Visible','off')
2821        set(handles.ViewObject,'Visible','off')
2822        set(handles.EditObject,'Visible','off')
2823        set(handles.DeleteObject,'Visible','off')     
2824    end     
2825    set(handles.REFRESH,'BackgroundColor',[1 0 1]); %paint REFRESH button in magenta to indicate that it should be activated
2826end
2827
2828%------------------------------------------------------------------------
2829% --- Executes when the GUI series is resized.
2830%------------------------------------------------------------------------
2831function series_ResizeFcn(hObject, eventdata, handles)
2832
2833%% input table
2834set(handles.InputTable,'Unit','pixel')
2835Pos=get(handles.InputTable,'Position');
2836set(handles.InputTable,'Unit','normalized')
2837ColumnWidth=round([0.5 0.14 0.14 0.14 0.08]*(Pos(3)-52));
2838ColumnWidth=num2cell(ColumnWidth);
2839set(handles.InputTable,'ColumnWidth',ColumnWidth)
2840
2841%% MinIndex_j and MaxIndex_i
2842unit=get(handles.MinIndex_i,'Unit');
2843set(handles.MinIndex_i,'Unit','pixel')
2844Pos=get(handles.MinIndex_i,'Position');
2845set(handles.MinIndex_i,'Unit',unit)
2846set(handles.MinIndex_i,'ColumnWidth',{Pos(3)-18})
2847set(handles.MaxIndex_i,'ColumnWidth',{Pos(3)-18})
2848set(handles.MinIndex_j,'ColumnWidth',{Pos(3)-18})
2849set(handles.MaxIndex_j,'ColumnWidth',{Pos(3)-18})
2850
2851%% TimeTable
2852set(handles.TimeTable,'Unit','pixel')
2853Pos=get(handles.TimeTable,'Position');
2854set(handles.TimeTable,'Unit','normalized')
2855% ColumnWidth=get(handles.TimeTable,'ColumnWidth');
2856ColumnWidth=num2cell(floor([0.25 0.25 0.25 0.25]*(Pos(3)-20)));
2857set(handles.TimeTable,'ColumnWidth',ColumnWidth)
2858
2859
2860%% PairString
2861set(handles.PairString,'Unit','pixel')
2862Pos=get(handles.PairString,'Position');
2863set(handles.PairString,'Unit','normalized')
2864set(handles.PairString,'ColumnWidth',{Pos(3)-5})
2865
2866%% MaskTable
2867set(handles.MaskTable,'Unit','pixel')
2868Pos=get(handles.MaskTable,'Position');
2869set(handles.MaskTable,'Unit','normalized')
2870set(handles.MaskTable,'ColumnWidth',{Pos(3)-5})
2871
2872%------------------------------------------------------------------------
2873% --- Executes on button press in status.
2874%------------------------------------------------------------------------
2875function status_Callback(hObject, eventdata, handles)
2876
2877if get(handles.status,'Value')
2878    set(handles.status,'BackgroundColor',[1 1 0])
2879    drawnow
2880    Param=read_GUI(handles.series);
2881    RootPath=Param.InputTable{1,1};
2882    if ~isfield(Param,'OutputSubDir')   
2883        msgbox_uvmat('ERROR','no directory defined for output files')
2884        return
2885    end
2886    OutputSubDir=[Param.OutputSubDir Param.OutputDirExt];% subdirectory for output files
2887    OutputDir=fullfile(RootPath,OutputSubDir);
2888    if exist(OutputDir,'dir')
2889        uigetfile_uvmat('status_display',OutputDir)
2890    else
2891        msgbox_uvmat('ERROR','output folder not created yet: calculation did not start')
2892        set(handles.status,'BackgroundColor',[0 1 0])
2893    end
2894else
2895    %% delete current display fig if selection is off
2896    set(handles.status,'BackgroundColor',[0 1 0])
2897    hfig=findobj(allchild(0),'name','status_display');
2898    if ~isempty(hfig)
2899        delete(hfig)
2900    end
2901    return
2902end
2903
2904
2905%------------------------------------------------------------------------   
2906% launched by selecting a file on the list
2907%------------------------------------------------------------------------
2908function view_file(hObject, eventdata)
2909
2910list=get(hObject,'String');
2911index=get(hObject,'Value');
2912rootroot=get(hObject,'UserData');
2913selectname=list{index};
2914ind_dot=regexp(selectname,'\.\.\.');
2915if ~isempty(ind_dot)
2916    selectname=selectname(1:ind_dot-1);
2917end
2918FullSelectName=fullfile(rootroot,selectname);
2919if exist(FullSelectName,'dir')% a directory has been selected
2920    ListFiles=dir(FullSelectName);
2921    ListDisplay=cell(numel(ListFiles),1);
2922    for ilist=2:numel(ListDisplay)% suppress the first line '.'
2923        ListDisplay{ilist-1}=ListFiles(ilist).name;
2924    end
2925    set(hObject,'Value',1)
2926    set(hObject,'String',ListDisplay)
2927    if strcmp(selectname,'..')
2928        FullSelectName=fileparts(fileparts(FullSelectName));
2929    end
2930    set(hObject,'UserData',FullSelectName)
2931    hfig=get(hObject,'parent');
2932    htitlebox=findobj(hfig,'tag','titlebox');   
2933    set(htitlebox,'String',FullSelectName)
2934elseif exist(FullSelectName,'file')%visualise the vel field if it exists
2935    FileType=get_file_type(FullSelectName);
2936    if strcmp(FileType,'txt')
2937        edit(FullSelectName)
2938    elseif strcmp(FileType,'xml')
2939        editxml(FullSelectName)
2940    else
2941        uvmat(FullSelectName)
2942    end
2943    set(gcbo,'Value',1)
2944end
2945
2946
2947%------------------------------------------------------------------------   
2948% launched by refreshing the status figure
2949%------------------------------------------------------------------------
2950function refresh_GUI(hfig)
2951
2952htitlebox=findobj(hfig,'tag','titlebox');
2953hlist=findobj(hfig,'tag','list');
2954hseries=findobj(allchild(0),'tag','series');
2955hstatus=findobj(hseries,'tag','status');
2956StatusData=get(hstatus,'UserData');
2957OutputDir=get(htitlebox,'String');
2958if ischar(OutputDir),OutputDir={OutputDir};end
2959ListFiles=dir(OutputDir{1});
2960if numel(ListFiles)<1
2961    return
2962end
2963ListFiles(1)=[];%removes the first line ='.'
2964ListDisplay=cell(numel(ListFiles),1);
2965testrecent=0;
2966datnum=zeros(numel(ListDisplay),1);
2967for ilist=1:numel(ListDisplay)
2968    ListDisplay{ilist}=ListFiles(ilist).name;
2969      if ~ListFiles(ilist).isdir && isfield(ListFiles(ilist),'datenum')
2970            datnum(ilist)=ListFiles(ilist).datenum;%only available in recent matlab versions
2971            testrecent=1;
2972       end
2973end
2974set(hlist,'String',ListDisplay)
2975
2976%% Look at date of creation
2977ListDisplay=ListDisplay(datnum~=0);
2978datnum=datnum(datnum~=0);%keep the non zero values corresponding to existing files
2979NbOutputFile=[];
2980if isempty(datnum)
2981    if testrecent
2982        message='no civ result created yet';
2983    else
2984        message='';
2985    end
2986else
2987    [first,indfirst]=min(datnum);
2988    [last,indlast]=max(datnum);
2989    NbOutputFile_str='?';
2990    NbOutputFile=[];
2991    if isfield(StatusData,'NbOutputFile')
2992        NbOutputFile=StatusData.NbOutputFile;
2993        NbOutputFile_str=num2str(NbOutputFile);
2994    end
2995    message={[num2str(numel(datnum)) ' file(s) done over ' NbOutputFile_str] ;['oldest modification:  ' ListDisplay{indfirst} ' : ' datestr(first)];...
2996        ['latest modification:  ' ListDisplay{indlast} ' : ' datestr(last)]};
2997end
2998set(htitlebox,'String', [OutputDir{1};message])
2999
3000%% update the waitbar
3001hwaitbar=findobj(hfig,'tag','waitbar');
3002if ~isempty(NbOutputFile)
3003    BarPosition=get(hwaitbar,'Position');
3004    BarPosition(3)=0.9*numel(datnum)/NbOutputFile;
3005    set(hwaitbar,'Position',BarPosition)
3006end
3007
3008%------------------------------------------------------------------------
3009% --- Executes on selection change in ActionExt.
3010%------------------------------------------------------------------------
3011function ActionExt_Callback(hObject, eventdata, handles)
3012
3013ActionExtList=get(handles.ActionExt,'String');
3014ActionExt=ActionExtList{get(handles.ActionExt,'Value')};
3015ActionList=get(handles.ActionName,'String');
3016ActionName=ActionList{get(handles.ActionName,'Value')};
3017% TransformPath='';
3018% if ~isempty(get(handles.ActionExt,'UserData'))
3019%     TransformPath=get(handles.ActionExt,'UserData');
3020% end
3021% if strcmp(ActionExt,'.sh')
3022%     set(handles.series,'Pointer','watch') % set the mouse pointer to 'watch'
3023%     set(handles.ActionExt,'BackgroundColor',[1 1 0])
3024%     ActionFullName=fullfile(get(handles.ActionPath,'String'),[ActionName '.sh']);
3025%     if ~exist(ActionFullName,'file')
3026%         answer=msgbox_uvmat('INPUT_Y-N','compiled version has not been created: compile now?');
3027%         if strcmp(answer,'Yes')
3028%             set(handles.ActionExt,'BackgroundColor',[1 1 0])
3029%             path_uvmat=fileparts(which('series'));
3030%             currentdir=pwd;
3031%             cd(get(handles.ActionPath,'String'))% go to the directory of Action
3032%             %  addpath(get(handles.TransformPath,'String'))
3033%             addpath(path_uvmat)% add the path to uvmat to run the fct 'compile'
3034%            % addpath(fullfile(path_uvmat,'transform_field'))% add the path to uvmat to run the fct 'compile'
3035%             compile(ActionName,TransformPath)
3036%             cd(currentdir)
3037%         end       
3038%     else
3039%         sh_file_info=dir(fullfile(get(handles.ActionPath,'String'),[ActionName '.sh']));
3040%         m_file_info=dir(fullfile(get(handles.ActionPath,'String'),[ActionName '.m']));
3041%         if isfield(m_file_info,'datenum') && m_file_info.datenum>sh_file_info.datenum
3042%             set(handles.ActionExt,'BackgroundColor',[1 1 0])
3043%             drawnow
3044%             answer=msgbox_uvmat('INPUT_Y-N',[ActionName '.sh needs to be updated: recompile now?']);
3045%             if strcmp(answer,'Yes')
3046%                 path_uvmat=fileparts(which('series'));
3047%                 currentdir=pwd;
3048%                 cd(get(handles.ActionPath,'String'))% go to the directory of Action
3049%                 %  addpath(get(handles.TransformPath,'String'))
3050%                 addpath(path_uvmat)% add the path to uvmat to run the fct 'compile'
3051%                 addpath(fullfile(path_uvmat,'transform_field'))% add the path to uvmat to run the fct 'compile'
3052%                 compile(ActionName,TransformPath)
3053%                 cd(currentdir)
3054%             end
3055%         end
3056%     end
3057%     set(handles.ActionExt,'BackgroundColor',[1 1 1])
3058%      set(handles.series,'Pointer','arrow') % set the mouse pointer to 'watch
3059% end
3060
3061
3062function num_NbProcess_Callback(hObject, eventdata, handles)
3063
3064
3065function num_NbSlice_Callback(hObject, eventdata, handles)
3066NbSlice=str2num(get(handles.num_NbSlice,'String'));
3067set(handles.num_NbProcess,'String',num2str(NbSlice))
3068
3069%------------------------------------------------------------------------
3070% --- set the visibility of relevant velocity type menus:
3071function menu=set_veltype_display(Civ,FileType)
3072%------------------------------------------------------------------------
3073if ~exist('FileType','var')
3074    FileType='civx';
3075end
3076switch FileType
3077    case 'civx'
3078        menu={'civ1';'interp1';'filter1';'civ2';'interp2';'filter2'};
3079        if isequal(Civ,0)
3080            imax=0;
3081        elseif isequal(Civ,1) || isequal(Civ,2)
3082            imax=1;
3083        elseif isequal(Civ,3)
3084            imax=3;
3085        elseif isequal(Civ,4) || isequal(Civ,5)
3086            imax=4;
3087        elseif isequal(Civ,6) %patch2
3088            imax=6;
3089        end
3090    case 'civdata'
3091        menu={'civ1';'filter1';'civ2';'filter2'};
3092        if isequal(Civ,0)
3093            imax=0;
3094        elseif isequal(Civ,1) || isequal(Civ,2)
3095            imax=1;
3096        elseif isequal(Civ,3)
3097            imax=2;
3098        elseif isequal(Civ,4) || isequal(Civ,5)
3099            imax=3;
3100        elseif isequal(Civ,6) %patch2
3101            imax=4;
3102        end
3103end
3104menu=menu(1:imax);
3105
3106
3107% --- Executes on mouse motion over figure - except title and menu.
3108function series_WindowButtonMotionFcn(hObject, eventdata, handles)
3109set(hObject,'Pointer','arrow');
3110
3111
3112% --- Executes on button press in SetPairs.
3113function SetPairs_Callback(hObject, eventdata, handles)
3114
3115%% create the GUI set_pairs
3116set(0,'Unit','points')
3117ScreenSize=get(0,'ScreenSize');% get the size of the screen, to put the fig on the upper right
3118Width=220;% fig width in points (1/72 inch)
3119Height=min(0.8*ScreenSize(4),300);
3120Left=ScreenSize(3)- Width-40; %right edge close to the right, with margin=40
3121Bottom=ScreenSize(4)-Height-40; %put fig at top right
3122hfig=findobj(allchild(0),'Tag','set_slice');
3123if ~isempty(hfig),delete(hfig), end; %delete existing version of the GUI
3124hfig=figure('name','set_pairs','tag','set_pairs','MenuBar','none','NumberTitle','off','Unit','points','Position',[Left,Bottom,Width,Height]);
3125BackgroundColor=get(hfig,'Color');
3126hh=0.14; % box height (relative)
3127ii=0.01; % gap between uicontrols
3128
3129ww=0.9; % box width (relative)
3130SeriesData=get(handles.series,'UserData');
3131% first raw of the GUI
3132uicontrol('Style','text','Units','normalized', 'Position', [0.05 0.88 0.5 0.1],'BackgroundColor',BackgroundColor,...
3133    'String','row to edit #','FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','right');%title
3134uicontrol('Style','popupmenu','Units','normalized', 'Position', [0.54 0.8 0.3 0.2],'tag','ListView','BackgroundColor',[1 1 1],...
3135    'String',SeriesData.ListViewMenu,'Value',SeriesData.ListViewValue,'FontUnits','points','FontSize',12,'FontWeight','bold','TooltipString','''ListView'':choice of the file series w for pair display');
3136% second raw of the GUI
3137uicontrol('Style','text','Units','normalized', 'Position', [0.05 0.79 0.7 0.1],'BackgroundColor',BackgroundColor,...
3138    'String','mode of index pairing:','FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','left');%title
3139uicontrol('Style','popupmenu','Units','normalized', 'Position', [0.05 0.62 ww 0.2],'tag','Mode','BackgroundColor',[1 1 1],'Callback',@(hObject,eventdata)ModeMenu_Callback(hObject,eventdata),...
3140    'String',SeriesData.ModeMenu,'Value',SeriesData.ModeValue,'FontUnits','points','FontSize',12,'FontWeight','bold','TooltipString','''Mode'': choice of the image pair mode');
3141% third raw
3142uicontrol('Style','text','Units','normalized', 'Position', [0.05 0.6 0.7 0.1],'BackgroundColor',BackgroundColor,...
3143    'String','pair choice:','FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','left');%title
3144uicontrol('Style','listbox','Units','normalized', 'Position', [0.05 0.42 ww 0.2],'tag','ListPairs','BackgroundColor',[1 1 1],'Callback',@(hObject,eventdata)ListPairsMenu_Callback(hObject,eventdata),...
3145    'String',SeriesData.ListPairsMenu,'Value',SeriesData.ListPairsValue,'FontUnits','points','FontSize',12,'FontWeight','bold','TooltipString','''ListPairs'': menu for selecting the image pair');
3146uicontrol('Style','text','Units','normalized', 'Position', [0.1 0.22 0.8 0.1],'BackgroundColor',BackgroundColor,...
3147    'String','ref_i           ref_j','FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','center');%title
3148uicontrol('Style','edit','Units','normalized', 'Position', [0.15 0.17 0.3 0.08],'tag','num_ref_i','BackgroundColor',[1 1 1],'Callback',@(hObject,eventdata)num_ref_i_Callback(hObject,eventdata),...
3149    'String',num2str(SeriesData.ref_i),'FontUnits','points','FontSize',12,'FontWeight','bold','TooltipString','''num_ref_i'': reference field index i used to display dt in ''list_pair_civ''');
3150uicontrol('Style','edit','Units','normalized', 'Position', [0.55 0.17 0.3 0.08],'tag','num_ref_j','BackgroundColor',[1 1 1],'Callback',@(hObject,eventdata)num_ref_j_Callback(hObject,eventdata),...
3151    'String',num2str(SeriesData.ref_j),'FontUnits','points','FontSize',12,'FontWeight','bold','TooltipString','''num_ref_j'': reference field index i used to display dt in ''list_pair_civ''');
3152%  last raw  of the GUI: pushbuttons
3153uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.35 0.01 0.3 0.15],'BackgroundColor',[0 1 0],'String','OK','Callback',@(hObject,eventdata)OK_Callback(hObject,eventdata),...
3154    'FontWeight','bold','FontUnits','points','FontSize',12,'TooltipString','''OK'': apply the output to the current field series in uvmat');
3155drawnow
3156
3157function ModeMenu_Callback(hObject,eventdata)
3158hseries=findobj(allchild(0),'tag','series');
3159hhseries=guidata(hseries);
3160SeriesData=get(hseries,'UserData');
3161hListView=findobj(get(hObject,'parent'),'Tag','ListView');
3162iview=get(hListView,'Value');
3163hMode=findobj(get(hObject,'parent'),'Tag','Mode');
3164mode_list=get(hMode,'String');
3165mode=mode_list{get(hMode,'Value')};
3166if isequal(mode,'bursts')
3167    enable_i(hhseries,'On')
3168    enable_j(hhseries,'Off') %do not display j index scanning in burst mode (j is fixed by the burst choice)
3169else
3170    enable_i(hhseries,'On')
3171    enable_j(hhseries,'Off')
3172end
3173fill_ListPair(hhseries,SeriesData.i1_series{iview},SeriesData.i2_series{iview},...
3174    SeriesData.j1_series{iview},SeriesData.j2_series{iview},SeriesData.Time{iview})
3175ListPairs_Callback([],[],hhseries)
3176
3177%-------------------------------------------------------------
3178% --- Executes on selection in ListPairs.
3179function ListPairsMenu_Callback(hObject,eventdata)
3180%------------------------------------------------------------
3181list_pair=get(hObject,'String');%get the menu of image pairs
3182if isempty(list_pair)
3183    string='';
3184else
3185    string=list_pair{get(hObject,'Value')};
3186    string=regexprep(string,',.*','');%removes time indication (after ',')
3187end
3188hseries=findobj(allchild(0),'tag','series');
3189hPairString=findobj(hseries,'tag','PairString');
3190PairString=get(hPairString,'Data');
3191hListView=findobj(get(hObject,'parent'),'Tag','ListView');
3192iview=get(hListView,'Value');
3193PairString{iview,1}=string;
3194% report the selected pair string to the table PairString
3195set(hPairString,'Data',PairString)
3196
3197%------------------------------------------------------------------------
3198function num_ref_i_Callback(hObject, eventdata)
3199%------------------------------------------------------------------------
3200hMode=findobj(get(hObject,'parent'),'Tag','Mode');
3201mode_list=get(hMode,'String');
3202mode=mode_list{get(hMode,'Value')};
3203hseries=findobj(allchild(0),'tag','series');
3204hhseries=guidata(hseries);
3205SeriesData=get(hseries,'UserData');
3206hListView=findobj(get(hObject,'parent'),'Tag','ListView');
3207iview=get(hListView,'Value');
3208fill_ListPair(hhseries,SeriesData.i1_series{iview},SeriesData.i2_series{iview},...
3209    SeriesData.j1_series{iview},SeriesData.j2_series{iview},SeriesData.Time{iview});% update the menu of pairs depending on the available netcdf files
3210
3211hListPairs=findobj(get(hObject,'parent'),'Tag','ListPairs');
3212ListPairsMenu_Callback(hListPairs,eventdata)
3213
3214%------------------------------------------------------------------------
3215function num_ref_j_Callback(hObject, eventdata)
3216%------------------------------------------------------------------------
3217num_ref_i_Callback(hObject, eventdata)
3218
3219%-------------------------------------------------------------
3220% --- Executes on selection in ListPairs.
3221function OK_Callback(hObject,eventdata)
3222%------------------------------------------------------------
3223delete(get(hObject,'parent'))
Note: See TracBrowser for help on using the repository browser.