source: trunk/src/series.m @ 771

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