source: trunk/src/series.m @ 849

Last change on this file since 849 was 845, checked in by sommeria, 9 years ago

stereo_civ updated

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