source: trunk/src/series.m @ 770

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