source: trunk/src/series.m @ 635

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