source: trunk/src/series.m @ 606

Last change on this file since 606 was 606, checked in by sommeria, 8 years ago

bug on compilation solved (still to test with transform_field fct). faster browser inrtroduced. Various bug corrections

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