source: trunk/src/series.m @ 609

Last change on this file since 609 was 609, checked in by sommeria, 11 years ago

various bugs corrected after tests with Windows OS.

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