source: trunk/src/series.m @ 764

Last change on this file since 764 was 764, checked in by sommeria, 10 years ago

improvement of movie-pair for uvmat and introduction of a separate window SetPair? in series.

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