source: trunk/src/series.m @ 602

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

limit time increased for series with cluster, status improved

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