source: trunk/src/series.m @ 606

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

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

File size: 111.5 KB
RevLine 
[2]1%'series': master function associated to the GUI series.m for analysis field series 
2%------------------------------------------------------------------------
3% function varargout = series(varargin)
4% associated with the GUI series.fig
5%
6%INPUT
7% param: structure with input parameters (link with the GUI uvmat)
[446]8%      .menu_coord_str: string for the TransformName (menu for coordinate transforms)
9%      .menu_coord_val: value for TransformName (menu for coordinate transforms)
[2]10%      .FileName: input file name
11%      .FileName_1: second input file name
12%      .list_field: menu of input fields
13%      .index_fields: chosen index
14%      .civ1=0 or 1, .interp1,  ... : input civ field type
15%
16%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
17%  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
18%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
19%     This file is part of the toolbox UVMAT.
20%
21%     UVMAT is free software; you can redistribute it and/or modify
22%     it under the terms of the GNU General Public License as published by
23%     the Free Software Foundation; either version 2 of the License, or
24%     (at your option) any later version.
25%
26%     UVMAT is distributed in the hope that it will be useful,
27%     but WITHOUT ANY WARRANTY; without even the implied warranty of
28%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29%     GNU General Public License (file UVMAT/COPYING.txt) for more details.
30%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
31
[408]32%------------------------------------------------------------------------
33%------------------------------------------------------------------------
34%  I - MAIN FUNCTION series
35%------------------------------------------------------------------------
36%------------------------------------------------------------------------
[2]37function varargout = series(varargin)
38
39% Begin initialization code - DO NOT EDIT
40gui_Singleton = 1;
41gui_State = struct('gui_Name',       mfilename, ...
42                   'gui_Singleton',  gui_Singleton, ...
43                   'gui_OpeningFcn', @series_OpeningFcn, ...
44                   'gui_OutputFcn',  @series_OutputFcn, ...
45                   'gui_LayoutFcn',  [] , ...
46                   'gui_Callback',   []);
47if nargin && ischar(varargin{1})
48    gui_State.gui_Callback = str2func(varargin{1});
49end
50
51if nargout
52    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
53else
54    gui_mainfcn(gui_State, varargin{:});
55end
56% End initialization code - DO NOT EDIT
57
58%--------------------------------------------------------------------------
59% --- Executes just before series is made visible.
60%--------------------------------------------------------------------------
[591]61function series_OpeningFcn(hObject, eventdata, handles,Param)
62
[2]63% Choose default command line output for series
64handles.output = hObject;
65% Update handles structure
66guidata(hObject, handles);
[591]67
68%% initial settings
[156]69drawnow
[244]70set(hObject,'Units','pixels')
[526]71set(handles.PairString,'ColumnName',{'pairs'})
[598]72set(handles.PairString,'ColumnEditable',false)
[408]73set(handles.PairString,'ColumnFormat',{'char'})
74set(handles.PairString,'Data',{''})
[526]75series_ResizeFcn(hObject, eventdata, handles)%resize table according to series GUI size
[332]76set(hObject,'WindowButtonDownFcn',{'mouse_down'})%allows mouse action with right button (zoom for uicontrol display)
[591]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'
[598]86%path_bin=fullfile(path_series,'bin');%path of the binary functions (compiled)
[591]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)
[598]88ActionPathList=[ActionPathList ActionPathList];% set path to .sh commands for compiled functions
[591]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
[2]107dir_perso=prefdir;
108profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
109if exist(profil_perso,'file')
[591]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
[2]130end
131
[591]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');
[2]136end
[591]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);
[2]144end
[591]145if isempty(ActionIndex)
146    ActionIndex=1;
[2]147end
[591]148set(handles.ActionName,'Value',ActionIndex)
149set(handles.ActionPath,'String',ActionPathList{ActionIndex})
150set(handles.ActionExt,'Value',1)
151set(handles.ActionExt,'String',ActionExtList)
[2]152
[591]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');
[2]158end
[591]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);
[526]166end
[591]167if isempty(TransformIndex)
168    TransformIndex=1;
[526]169end
[591]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
[2]177end
[591]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
[38]181end
[591]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
[2]185end
[39]186
[472]187%% Adjust the GUI according to the binaries available in PARAM.xml
[594]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
[2]218
[591]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
[408]238%------------------------------------------------------------------------
[2]239% --- Outputs from this function are returned to the command line.
240function varargout = series_OutputFcn(hObject, eventdata, handles)
[408]241%------------------------------------------------------------------------
[2]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
[408]249%------------------------------------------------------------------------
250%------------------------------------------------------------------------
251%  II - FUNCTIONS FOR INTRODUCING THE INPUT FILES
252% automatically sets the global properties when the rootfile name is introduced
[446]253% then activate the view-field actionname if selected
[408]254% it is activated either by clicking on the RootPath window or by the
255% browser
256%------------------------------------------------------------------------
257%------------------------------------------------------------------------
[2]258function MenuBrowse_Callback(hObject, eventdata, handles)
[408]259%------------------------------------------------------------------------   
[606]260%get the previous input file in the Input Table
261oldfile=''; %default
[350]262InputTable=get(handles.InputTable,'Data');
[606]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;
[472]270        end
[463]271    end
[606]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)
[408]280    display_file_name(handles,fileinput,0)
[2]281end
[606]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
[2]313
314% --------------------------------------------------------------------
315function MenuFile_1_Callback(hObject, eventdata, handles)
316fileinput=get(handles.MenuFile_1,'Label');
[408]317display_file_name(handles,fileinput,0)
[2]318
319% --------------------------------------------------------------------
320function MenuFile_2_Callback(hObject, eventdata, handles)
321fileinput=get(handles.MenuFile_2,'Label');
[408]322display_file_name(handles,fileinput,0)
[2]323
324% --------------------------------------------------------------------
325function MenuFile_3_Callback(hObject, eventdata, handles)
326fileinput=get(handles.MenuFile_3,'Label');
[408]327display_file_name( handles,fileinput,0)
[2]328
329% --------------------------------------------------------------------
330function MenuFile_4_Callback(hObject, eventdata, handles)
331fileinput=get(handles.MenuFile_4,'Label');
[408]332display_file_name(handles,fileinput,0)
[2]333
334% --------------------------------------------------------------------
335function MenuFile_5_Callback(hObject, eventdata, handles)
336fileinput=get(handles.MenuFile_5,'Label');
[408]337display_file_name(handles,fileinput,0)
[2]338
339% --------------------------------------------------------------------
340function MenuBrowse_insert_Callback(hObject, eventdata, handles)
[350]341InputTable=get(handles.InputTable,'Data');
342RootPathCell=InputTable(:,1);
343SubDirCell=InputTable(:,3);
344RootFileCell=InputTable(:,2);
[2]345oldfile=''; %default
[206]346if isempty(RootPathCell)||isequal(RootPathCell,{''})%loads the previously stored file name and set it as default in the file_input box
[2]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')
[206]375    msgbox_uvmat('ERROR','input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
[2]376elseif isequal(ext,'.xls')
[206]377    msgbox_uvmat('ERROR','input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
[2]378else
[472]379    display_file_name(handles,fileinput,'append')
[2]380end
381
382% --------------------------------------------------------------------
383function MenuFile_insert_1_Callback(hObject, eventdata, handles)
[408]384% --------------------------------------------------------------------   
[2]385fileinput=get(handles.MenuFile_insert_1,'Label');
[472]386display_file_name(handles,fileinput,'append')
[2]387
388% --------------------------------------------------------------------
389function MenuFile_insert_2_Callback(hObject, eventdata, handles)
[408]390% --------------------------------------------------------------------   
[2]391fileinput=get(handles.MenuFile_insert_2,'Label');
[472]392display_file_name(handles,fileinput,'append')
[2]393
394% --------------------------------------------------------------------
395function MenuFile_insert_3_Callback(hObject, eventdata, handles)
[408]396% --------------------------------------------------------------------   
[2]397fileinput=get(handles.MenuFile_insert_3,'Label');
[472]398display_file_name( handles,fileinput,'append')
[2]399
400% --------------------------------------------------------------------
401function MenuFile_insert_4_Callback(hObject, eventdata, handles)
[408]402% --------------------------------------------------------------------   
[2]403fileinput=get(handles.MenuFile_insert_4,'Label');
[472]404display_file_name( handles,fileinput,'append')
[2]405
406% --------------------------------------------------------------------
407function MenuFile_insert_5_Callback(hObject, eventdata, handles)
[408]408% --------------------------------------------------------------------   
[2]409fileinput=get(handles.MenuFile_insert_5,'Label');
[472]410display_file_name(handles,fileinput,'append')
[2]411
[89]412%------------------------------------------------------------------------
[408]413% --- Executes when entered data in editable cell(s) in InputTable.
414function InputTable_CellEditCallback(hObject, eventdata, handles)
415%------------------------------------------------------------------------
[472]416set(handles.REFRESH,'Visible','on')
[605]417set(handles.REFRESH_title,'Visible','on')
[408]418iview=eventdata.Indices(1);
[472]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%------------------------------------------------------------------------
[408]437InputTable=get(handles.InputTable,'Data');
[472]438view_set=get(handles.REFRESH,'UserData');
[605]439set(handles.REFRESH,'BackgroundColor',[1 1 0])% set REFRESH  button to yellow color (indicate activation)
[472]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
[599]447        [RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,tild,FileType,FileInfo,MovieObject]=...
[472]448            find_file_series(fullfile(InputTable{iview,1},InputTable{iview,2}),[InputTable{iview,3} InputTable{iview,4} InputTable{iview,5}]);
[446]449    end
[472]450    if isempty(i1_series)
[605]451        [FileName, PathName] = uigetfile( ...
[472]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 (*.*)'}, ...
[605]460            ['unvalid entry at line ' num2str(iview) ', pick a new input file'],RootPath);
[472]461        fileinput=[PathName FileName];%complete file name
[605]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
[472]466        [path,name,ext]=fileparts(fileinput);
467        display_file_name(handles,fileinput,iview)
468    else
[599]469        update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,FileInfo,MovieObject,iview)
[472]470    end
[446]471end
[472]472set(handles.REFRESH,'Visible','off')
[605]473set(handles.REFRESH_title,'Visible','off')
[472]474set(handles.REFRESH,'UserData',[])
[408]475
476%------------------------------------------------------------------------
[472]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%
[332]481% INPUT:
[472]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
[332]485
[408]486%% get the input root name, indices, file extension and nomenclature NomType
487if ~exist(fileinput,'file')
488    msgbox_uvmat('ERROR',['input file ' fileinput  ' does not exist'])
489    return
490end
491
[332]492%% enable other menus and uicontrols
493set(handles.MenuOpen_insert,'Enable','on')
494set(handles.MenuFile_insert_1,'Enable','on')
495set(handles.MenuFile_insert_2,'Enable','on')
496set(handles.MenuFile_insert_3,'Enable','on')
497set(handles.MenuFile_insert_4,'Enable','on')
498set(handles.MenuFile_insert_5,'Enable','on')
499set(handles.RUN, 'Enable','On')
500set(handles.RUN,'BackgroundColor',[1 0 0])% set RUN button to red
[350]501set(handles.InputTable,'BackgroundColor',[1 1 0]) % set RootPath edit box  to yellow
[332]502drawnow
503
[408]504%% detect root name, nomenclature and indices in the input file name:
505[FilePath,FileName,FileExt]=fileparts(fileinput);
506% detect the file type, get the movie object if relevant, and look for the corresponding file series:
507% the root name and indices may be corrected by including the first index i1 if a corresponding xml file exists
[599]508[RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,NomType,FileType,FileInfo,MovieObject,i1,i2,j1,j2]=find_file_series(FilePath,[FileName FileExt]);
[408]509if isempty(RootFile)&&isempty(i1_series)
510    errormsg='no input file in the series';
[29]511    return
512end
[89]513
[376]514%% fill the list of file series
515InputTable=get(handles.InputTable,'Data');
[472]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}];
[376]524    set(handles.TimeTable,'Data',[{[]},{[]},{[]},{[]}])
525    set(handles.MinIndex,'Data',[{[]},{[]}])
526    set(handles.MaxIndex,'Data',[{[]},{[]}])
[408]527    set(handles.ListView,'Value',1)
528    set(handles.ListView,'String',{'1'})
[376]529end
[472]530nbview=size(InputTable,1);
531set(handles.ListView,'String',mat2cell((1:nbview)',ones(nbview,1)))
532set(handles.ListView,'Value',iview)
[376]533set(handles.InputTable,'Data',InputTable)
534
[472]535%% determine the selected reference field indices for pair display
[603]536if isempty(i1)
537    i1=1;
[472]538end
[603]539if isempty(i2)
540    i2=i1;
541end
542ref_i=floor((i1+i2)/2);% reference image number corresponding to the file
[472]543set(handles.num_ref_i,'String',num2str(ref_i));
[603]544set(handles.num_ref_i,'UserData',[i1 i2])
545if isempty(j1)
546    j1=1;
[472]547end
[603]548if isempty(j2)
549    j2=j1;
550end
551ref_j=floor((j1+j2)/2);% reference image number corresponding to the file
[472]552set(handles.num_ref_j,'String',num2str(ref_j));
[603]553set(handles.num_ref_j,'UserData',[j1 j2])
[472]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:     
[599]577update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,FileInfo,MovieObject,iview);
[472]578
579%------------------------------------------------------------------------
580% --- Update information about a new field series (indices to scan, timing,
581%     calibration from an xml file
[599]582function update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,FileInfo,VideoObject,iview)
[472]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
[521]595%% display the min and max indices for the file series
[554]596if size(i1_series,2)==2 && min(min(i1_series(:,1,:)))==0
[526]597    MinIndex_j=1;
[554]598    MaxIndex_j=1;
599    MinIndex_i=find(i1_series(:,2,:), 1 )-1;
600    MaxIndex_i=find(i1_series(:,2,:), 1, 'last' )-1;
[526]601else
[554]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);
[526]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
[554]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);
[526]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
[460]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
[554]621if isequal(MinIndex_i,-1)
622    MinIndex_i=0;
623end
624if isequal(MinIndex_j,-1)
625    MinIndex_j=0;
626end
[472]627MinIndex{iview,1}=MinIndex_i;
628MinIndex{iview,2}=MinIndex_j;
629MaxIndex{iview,1}=MaxIndex_i;
630MaxIndex{iview,2}=MaxIndex_j;
[460]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;
[526]643elseif first_i >MaxIndex_i
644    first_i=MinIndex_i;
[460]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;
[526]651elseif first_j >MaxIndex_j
652    first_j=MinIndex_j;
[460]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;
[526]659elseif last_i<first_i
660    last_i=first_i;
[460]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;
[526]667elseif last_i<first_i
668    last_i=first_i;
[460]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
[526]675%% read timing and total frame number from the current file (movie files) may be overrid by xml file
[408]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)';
[526]684       % set(handles.Dt_txt,'String',['Dt=' num2str(1000/imainfo.FrameRate) 'ms']);%display the elementary time interval in millisec
[408]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={};
[525]703XmlFileName=find_imadoc(InputTable{iview,1},InputTable{iview,2},InputTable{iview,3},InputTable{iview,5});
[599]704TimeUnit='';
[525]705if ~isempty(XmlFileName)
706        [XmlData,warntext]=imadoc2struct(XmlFileName);
[408]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
[456]730if ~isempty(time)
[523]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};
[553]742    if isempty(MinIndex_j)% only i index
[523]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
[554]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
[553]757        if size(time)>=[MaxIndex_i MaxIndex_j];
[554]758            TimeTable{iview,4}=time(MaxIndex_i,MaxIndex_j);
[553]759        end
[456]760    end
[523]761    set(handles.TimeTable,'Data',TimeTable)
[408]762end
763
764%% number of slices
[460]765NbSlice=1;%default
[600]766check_calib=0;
[599]767if isfield(XmlData,'GeometryCalib')
768    check_calib=1;
769    if isfield(XmlData.GeometryCalib,'SliceCoord')
[408]770    siz=size(XmlData.GeometryCalib.SliceCoord);
771    if siz(1)>1
772        NbSlice=siz(1);
773    end
[599]774    end
[408]775end
[450]776set(handles.num_NbSlice,'String',num2str(NbSlice))
777   
[408]778%% update pair menus
[441]779set(handles.Pairs,'Visible','on')
780set(handles.PairString,'Visible','on')
[408]781ListView=get(handles.ListView,'String');
782ListView{iview}=num2str(iview);
[472]783set(handles.ListView,'String',ListView);
[408]784set(handles.ListView,'Value',iview)
785update_mode(handles,i1_series,i2_series,j1_series,j2_series,time)
786
[472]787%% update the series info in 'UserData'
[408]788SeriesData=get(handles.series,'UserData');
[603]789SeriesData.Ref_i{iview}=get(handles.num_ref_i,'UserData');
790SeriesData.Ref_j{iview}=get(handles.num_ref_j,'UserData');
[408]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;
[599]796SeriesData.FileInfo{iview}=FileInfo;
[408]797SeriesData.Time{iview}=time;
[599]798if ~isempty(TimeUnit)
799    SeriesData.TimeUnit=TimeUnit;
800end
801if check_calib
802SeriesData.GeometryCalib{iview}=XmlData.GeometryCalib;
803end
[408]804set(handles.series,'UserData',SeriesData)
805
[521]806%% enable j index visibilitycellfun(@isempty,regexp(PairString,'^j'))
[553]807% state='off';
[472]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
[521]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
[472]818end
819
[477]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);
[523]826pair_max=cell(1,nbview);
[477]827for iview=1:nbview
[523]828    pair_max{iview}=squeeze(max(SeriesData.i1_series{iview},[],1)); %max on pair index
[526]829    if (strcmp(get(handles.num_first_j,'Visible'),'off')&& size(pair_max{iview},2)~=1)
[525]830        pair_max{iview}=squeeze(max(pair_max{iview},[],1)); % consider only the i index
831    end
[523]832    index_min(iview)=find(pair_max{iview}>0, 1 );
833    index_max(iview)=find(pair_max{iview}>0, 1, 'last' );
[477]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);
[523]847    x_index=find(pair_max{iview}>0)-index_min+1;
[477]848    LineData(x_index)=1;
[591]849    if numel(x)>1
[477]850    LineData=interp1(x,LineData,xI,'nearest');
851    CData(ind_y,:)=ones(size(ind_y'))*LineData;
[591]852    end
[477]853end
854CData=cat(3,zeros(size(CData)),CData,zeros(size(CData)));
855set(handles.FileStatus,'CData',CData);
856
857
[472]858%% enable field and veltype menus, in accordance with the current action
859ActionName_Callback([],[], handles)
860
[441]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
[408]875
[477]876%% set length of waitbar
877displ_time(handles)
878
879
[525]880%% set default options in menu 'Fields'
881switch FileType
882    case {'civx','civdata'}
[596]883        [FieldList,ColorList]=set_field_list('U','V','C');
[525]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'
[526]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);
[595]909%         hget_field=get_field(FileName);
910%         hhget_field=guidata(hget_field);
911%         get_field('RUN_Callback',hhget_field.RUN,[],hhget_field);
[525]912    otherwise
[526]913        set(handles.FieldName,'Value',1) % set menu to 'image'
914        set(handles.FieldName,'String',{'image'})
[525]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
[408]920
[446]921%------------------------------------------------------------------------
922function num_first_i_Callback(hObject, eventdata, handles)
923%------------------------------------------------------------------------
924num_last_i_Callback(hObject, eventdata, handles)
[408]925
926%------------------------------------------------------------------------
[446]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
[477]954
[446]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
[477]1006%% set the waitbar position with respect to the min and max in the series
1007for iview=1:numel(SeriesData.i1_series)
[526]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' );
[477]1015end
1016[index_min,iview_min]=min(index_min);
1017[index_max,iview_max]=min(index_max);
[526]1018if size(SeriesData.i1_series{iview_min},2)==1% movie
[533]1019    index_first=ref_i(1);
1020    index_last=ref_i(2);
[526]1021else
[533]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;
[526]1024end
[477]1025range=index_max-index_min+1;
1026coeff_min=(index_first-index_min)/range;
1027coeff_max=(index_last-index_min+1)/range;
[533]1028Position=get(handles.Waitbar,'Position');% position of the waitbar:= [ x,y, width, height]
[477]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
[446]1035%------------------------------------------------------------------------
[408]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%------------------------------------------------------------------------
[2]1064% --- Executes on button press in mode.
[376]1065function mode_Callback(hObject, eventdata, handles)
[408]1066%------------------------------------------------------------------------       
[376]1067SeriesData=get(handles.series,'UserData');
[408]1068iview=get(handles.ListView,'Value');
[376]1069mode_list=get(handles.mode,'String');
[408]1070mode=mode_list{get(handles.mode,'Value')};
[376]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
[408]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)
[339]1081
[408]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
[441]1087if isempty(list_pair)
1088    string='';
1089else
1090    string=list_pair{get(handles.ListPairs,'Value')};
1091    string=regexprep(string,',.*','');%removes time indication (after ',')
1092end
[408]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)
[2]1098
[408]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},...
[446]1107    SeriesData.j1_series{iview},SeriesData.j2_series{iview},SeriesData.Time{iview});% update the menu of pairs depending on the available netcdf files
[408]1108ListPairs_Callback([],[],handles)
[2]1109
[408]1110%------------------------------------------------------------------------
1111function num_ref_j_Callback(hObject, eventdata, handles)
1112%------------------------------------------------------------------------
1113num_ref_i_Callback(hObject, eventdata, handles)
[2]1114
[408]1115%------------------------------------------------------------------------
1116function update_mode(handles,i1_series,i2_series,j1_series,j2_series,time)
1117%------------------------------------------------------------------------   
[521]1118% check_burst=0;
1119if isempty(j2_series)% no j pair
[408]1120    if isempty(i2_series)
1121        set(handles.mode,'Value',1)
[521]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
[408]1126    end
[521]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
[408]1136        set(handles.mode,'Value',1);
[521]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)'})
[456]1142    else
[521]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
[456]1150    end
[408]1151end
[521]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
[408]1163fill_ListPair(handles,i1_series,i2_series,j1_series,j2_series,time)
1164ListPairs_Callback([],[],handles)
[2]1165
1166%--------------------------------------------------------------
[408]1167% determine the menu for civ1 pairstring depending on existing netcdf files
1168% with the reference indices num_ref_i and num_ref_j
[2]1169%----------------------------------------------------------------
[408]1170function fill_ListPair(handles,i1_series,i2_series,j1_series,j2_series,time)
1171
[2]1172mode_list=get(handles.mode,'String');
[408]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
[472]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
[408]1184    ref_j=1;
1185end
[2]1186TimeUnit=get(handles.TimeUnit,'String');
1187if length(TimeUnit)>=1
1188    dtunit=['m' TimeUnit];
1189else
1190    dtunit='e-03';
1191end
[339]1192
1193displ_pair={};
[118]1194if strcmp(mode,'series(Di)')
[339]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
[408]1204            pair_string=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ];
1205            if ~isempty(time)
[472]1206                if ref_i<=floor(ipair/2)
1207                    ref_i=floor(ipair/2)+1;% shift ref_i to get the first pair
1208                end
[408]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}];
[339]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
[408]1228            pair_string=['Dj= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ];
1229            if ~isempty(time)
[472]1230                if ref_j<=floor(ipair/2)
1231                    ref_j=floor(ipair/2)+1;% shift ref_i to get the first pair
1232                end
[408]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}];
[339]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
[472]1263set(handles.num_ref_i,'String',num2str(ref_i)) % update ref_i and ref_j
1264set(handles.num_ref_j,'String',num2str(ref_j))
[408]1265
1266%% display list of pairstring
1267displ_pair_list=get(handles.ListPairs,'String');
[339]1268NewVal=[];
1269if ~isempty(displ_pair_list)
[408]1270Val=get(handles.ListPairs,'Value');
[419]1271NewVal=find(strcmp(displ_pair_list{Val},displ_pair),1);% look at the previous display in the new menu displ_pï¿œir
[339]1272end
1273if ~isempty(NewVal)
[408]1274    set(handles.ListPairs,'Value',NewVal)
[339]1275else
[408]1276    set(handles.ListPairs,'Value',1)
[339]1277end
[408]1278set(handles.ListPairs,'String',displ_pair)
[339]1279
[408]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)
[2]1289
[408]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)
[526]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
[41]1304
[408]1305
[446]1306%%%%%%%%%%%%%%%%%%%%
1307%%  MAIN ActionName FUNCTIONS
1308%%%%%%%%%%%%%%%%%%%%
[41]1309%------------------------------------------------------------------------
[2]1310% --- Executes on button press in RUN.
1311function RUN_Callback(hObject, eventdata, handles)
[41]1312%------------------------------------------------------------------------
[595]1313
[2]1314set(handles.RUN,'BusyAction','queue');
[332]1315set(0,'CurrentFigure',handles.series)
[446]1316set(handles.RUN, 'Enable','Off')
1317set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784])
[456]1318drawnow
[595]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
[446]1322if ~isempty(errormsg)
[599]1323    if ~strcmp(errormsg,'Cancel')
[446]1324    msgbox_uvmat('ERROR',errormsg)
[599]1325    end
1326    STOP_Callback([],[], handles)
[472]1327    return
[2]1328end
[595]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
[601]1340RunMode='local';%default
1341if isfield(Series.Action,'RunMode')
1342RunMode=Series.Action.RunMode;
1343end
[595]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;
[594]1350path_series=fileparts(which('series'));
[472]1351
[595]1352%% create the Action fct handle if RunMode option = 'local'
[594]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);
[598]1381        if strcmp(RunMode,'cluster_oar') && isfield(s,'BatchParam')
[594]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
[598]1397    if isempty(RunTime) && strcmp(RunMode,'cluster_oar')
[594]1398        msgbox_uvmat('ERROR','RunTime name not found in PARAM.xml, compiled version .sh cannot run on cluster')
1399        return
1400    end
[598]1401%     Series.RunTime=RunTime;
[594]1402end
[595]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
[591]1414            answer=inputdlg({'Number of cores (max 36)','extra oar options'},'oarsub parameter',1,{'12',''});
1415            NbCore=str2double(answer{1});
[595]1416            extra_oar=answer{2};
1417        end
1418end
1419if ~isfield(Series.IndexRange,'NbSlice')
1420    Series.IndexRange.NbSlice=[];
1421end
1422if isempty(Series.IndexRange.NbSlice)
[591]1423    NbProcess=NbCore;% choose one process per core
[594]1424else
[595]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
[591]1427end
[602]1428       
[594]1429
1430%% read index ranges
1431first_i=1;
1432last_i=1;
1433incr_i=1;
1434first_j=1;
1435last_j=1;
[602]1436incr_j=1;
[594]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;
[602]1445    incr_j=Series.IndexRange.incr_j;
[594]1446end
1447if last_i < first_i || last_j < first_j , msgbox_uvmat('ERROR','last field number must be larger than the first one'),...
[595]1448        set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return
[594]1449else
1450    BlockLength=ceil(numel(first_i:incr_i:last_i)/NbProcess);
1451end
[602]1452nbfield_j=numel(first_j:incr_j:last_j);
[594]1453
[604]1454%% record nbre of output files and starting time for computation for status
[602]1455StatusData=get(handles.status,'UserData');
[605]1456if isfield(StatusData,'OutputFileMode')
[604]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
[605]1465end
[604]1466StatusData.TimeStart=now;
1467set(handles.status,'UserData',StatusData)
[602]1468
[595]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)
[601]1475            Series.IndexRange.first_i=first_i+(iprocess-1)*BlockLength*incr_i;
[598]1476            if Series.IndexRange.first_i>last_i
1477                break
1478            end
[601]1479            Series.IndexRange.last_i=min(first_i+(iprocess)*BlockLength*incr_i-1,last_i);
[595]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
[598]1496                        system([fullfile(ActionPath,[ActionName '.sh']) ' ' RunTime ' ' filexml]);% TODO: adapt to DOS system
[595]1497                    case {'GLNX86','GLNXA64','MACI64'}%Linux  system
[598]1498                        system([fullfile(ActionPath,[ActionName '.sh']) ' ' RunTime ' ' filexml]);
[591]1499                end
[472]1500        end
[595]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
[472]1515        end
[595]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
[601]1528            Series.IndexRange.first_i=first_i+(iprocess-1)*BlockLength*incr_i;
[598]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
[601]1533            Series.IndexRange.last_i=min(last_i,first_i+(iprocess)*BlockLength*incr_i-1);
[595]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
[598]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);
[595]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
[591]1586                end
[595]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'...
[598]1594                            fullfile(ActionPath,[ActionName '.sh']) ' ' RunTime ' ' filexml];%allow writting access to created files for user group
[595]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
[591]1598                       
[595]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);
[591]1605                        fclose(fid);
[595]1606                        %                               dos([filebat ' &']);
[591]1607                end
1608        end
[595]1609    end
[472]1610end
1611
[595]1612%% launch the executable files for background or cluster processing
1613switch RunMode
1614    case 'background'
1615        for iprocess=1:NbProcess
[604]1616            system([batch_file_list{iprocess} ' &'])% directly execute the command file for each process
[595]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
[602]1628        max_walltime=3600*12; % 12h max total calculation
1629        walltime_onejob=600;%seconds, max estimated time for asingle file index value
[595]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)
[598]1633            fprintf(fid,[batch_file_list{p} '\n']);% list of exe files
[595]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) ','...
[602]1640            'walltime=' datestr(min(1.05*walltime_onejob/86400*max(NbProcess*BlockLength*nbfield_j,NbCore)/NbCore,max_walltime/86400),13) ' '...
[595]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
[446]1657set(handles.RUN, 'Enable','On')
1658set(handles.RUN,'BackgroundColor',[1 0 0])
[591]1659set(handles.RUN, 'Value',0)
[2]1660
[446]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')
[591]1667set(handles.RUN, 'Value',0)
[446]1668
[472]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%     
[446]1679%------------------------------------------------------------------------
[456]1680% --- Main launch command, called by RUN and BATCH
[591]1681
[595]1682function [Series,OutputDir,errormsg]=prepare_jobs(handles)
[472]1683%INPUT:
1684% handles: handles of graphic objects on the GUI series
1685
[446]1686%------------------------------------------------------------------------
[595]1687OutputDir='';
[446]1688errormsg='';
[594]1689
[446]1690%% Read parameters from series
1691Series=read_GUI(handles.series);
1692
1693%% get_field GUI
[595]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);
[594]1698%     end
1699% end
[26]1700
[595]1701%% create the output data directory
[446]1702%determine the root file corresponding to the first sub dir
[591]1703if get(handles.RUN,'value') && isfield(Series,'OutputSubDir')
1704    SubDirOut=[get(handles.OutputSubDir,'String') Series.OutputDirExt];
[446]1705    SubDirOutNew=SubDirOut;
1706    SeriesData=get(handles.series,'UserData');
[591]1707    if size(Series.InputTable,1)>1 && isfield(SeriesData,'AllowInputSort') && SeriesData.AllowInputSort
[446]1708        [tild,iview]=sort(Series.InputTable(:,2)); %subdirectories sorted in alphabetical order
1709        Series.InputTable=Series.InputTable(iview,:);
[421]1710    end
[448]1711    detect=exist(fullfile(Series.InputTable{1,1},SubDirOutNew),'dir');% test if  the dir  already exist
[450]1712    check_create=1; %need to create the result directory by default
[446]1713    while detect
[448]1714        answer=msgbox_uvmat('INPUT_Y-N',['use existing ouput directory: ' fullfile(Series.InputTable{1,1},SubDirOutNew) ', possibly delete previous data']);
[599]1715        if strcmp(answer,'Cancel')
1716            errormsg='Cancel';
1717            return
1718        elseif strcmp(answer,'Yes')
[448]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;
[408]1730        end
1731    end
[448]1732    Series.OutputDirExt=regexprep(SubDirOutNew,Series.OutputSubDir,'');
[446]1733    Series.OutputRootFile=Series.InputTable{1,3};% the first sorted RootFile taken for output
[448]1734    set(handles.OutputDirExt,'String',Series.OutputDirExt)
[595]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
[472]1737        [tild,msg1]=mkdir(OutputDir);
[446]1738        if ~strcmp(msg1,'')
[472]1739            errormsg=['cannot create ' OutputDir ': ' msg1];%error message for directory creation
[446]1740            return
[421]1741        end
[408]1742    end
[595]1743   % RootOut=fullfile(OutputDir,Series.InputTable{1,3});% name of the parameter xml file set in this directory
[408]1744end
[595]1745
1746%% removes unused information on Series
1747if isfield(Series,'Pairs')
1748    Series=rmfield(Series,'Pairs'); %info Pairs not needed for output
1749end
[472]1750Series.IndexRange=rmfield(Series.IndexRange,'TimeTable');
[598]1751% Series.IndexRange=rmfield(Series.IndexRange,'MinIndex');
1752% Series.IndexRange=rmfield(Series.IndexRange,'MaxIndex');
[591]1753empty_line=false(size(Series.InputTable,1),1);
[472]1754for iline=1:size(Series.InputTable,1)
1755    empty_line(iline)=isequal(Series.InputTable(iline,1:3),{'','',''});
1756end
[591]1757Series.InputTable(empty_line,:)=[];
[408]1758
[41]1759%------------------------------------------------------------------------
[446]1760% --- Executes on selection change in ActionName.
1761function ActionName_Callback(hObject, eventdata, handles)
[41]1762%------------------------------------------------------------------------
[591]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
[598]1772set(handles.ActionName,'BackgroundColor',[1 1 0])
1773drawnow
[591]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)';
[2]1793        '*.m',  '.m files '; ...
1794        '*.*', 'All Files (*.*)'}, ...
[591]1795        'Pick a series processing function ',get(handles.ActionPath,'String'));
[2]1796    if length(FileName)<2
1797        return
1798    end
[591]1799    [ActionPath,ActionName,ActionExt]=fileparts(FileName);
[598]1800   
1801    % insert the choice in the menu ActionName
[591]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
[2]1808   
[598]1809    % record the file extension and extend the path list if it is a new extension
[591]1810    ActionExtList=get(handles.ActionExt,'String');
1811    ActionExtIndex=find(strcmp(ActionExt,ActionExtList), 1);
1812    if isempty(ActionExtIndex)
1813        set(handles.ActionExt,'String',[ActionExtList;{ActionExt}])
[598]1814        ActionExtIndex=numel(ActionExtList)+1;
[591]1815        ActionPathNew=cell(size(ActionPathList,1),1);%new column of ActionPath
1816        ActionPathList=[ActionPathList ActionPathNew];
1817    end
1818    set(handles.ActionName,'UserData',ActionPathList);
[598]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
[591]1827   
[598]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
[591]1835    dir_perso=prefdir;
1836    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
[598]1837    if nb_builtin_ACTION+1<=numel(ActionList)-1
[591]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
[2]1850end
1851
[591]1852%% check the current ActionPath to the selected function
[594]1853ActionPath=ActionPathList{ActionIndex};%current recorded path
1854set(handles.ActionPath,'String',ActionPath); %show the path to the senlected function
[2]1855
[591]1856%% reinitialise the waitbar
[477]1857update_waitbar(handles.Waitbar,0)
1858
[591]1859%% default setting for the visibility of the GUI elements
[598]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')
[591]1865
[594]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
[598]1883%% Activate the Action fct
1884[Series,tild,errormsg]=prepare_jobs(handles);% read the parameters from the GUI series
[591]1885if ~isempty(errormsg)
[599]1886    if ~strcmp(errormsg,'Cancel')
[591]1887    msgbox_uvmat('ERROR',errormsg)
[599]1888    end
[591]1889    return
[29]1890end
[591]1891ParamOut=h_fun(Series);
1892
[598]1893%% Put the first line of the selected Action fct as tooltip help
[244]1894try
[591]1895    [fid,errormsg] =fopen([ActionName '.m']);
[244]1896    InputText=textscan(fid,'%s',1,'delimiter','\n');
[553]1897    fclose(fid);
[456]1898    set(handles.ActionName,'ToolTipString',InputText{1}{1})% put the first line of the selected function as tooltip help
[244]1899end
[2]1900
[591]1901%% Detect the types of input files
[472]1902SeriesData=get(handles.series,'UserData');
[591]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
[2]1928    end
[594]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;
[604]1934    incr_i=Series.IndexRange.incr_i;
[594]1935    last_i=Series.IndexRange.last_i;
[2]1936end
[594]1937if isfield(Series.IndexRange,'first_j')
1938    first_j=Series.IndexRange.first_j;
[604]1939     incr_j=Series.IndexRange.incr_j;
[594]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
[591]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
[2]1953end
[591]1954set(handles.num_NbSlice,'Visible',NbSliceVisible)
1955set(handles.NbSlice_title,'Visible',NbSliceVisible)
[2]1956
[591]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)
[606]2006if isfield(ParamOut,'TransformPath')
2007    set(handles.ActionExt,'UserData',ParamOut.TransformPath)
2008else
2009    set(handles.ActionExt,'UserData',[])
2010end
[591]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
[602]2048%% Expected nbre of output files
2049if isfield(ParamOut,'OutputFileMode')
[604]2050StatusData.OutputFileMode=ParamOut.OutputFileMode;
[602]2051set(handles.status,'UserData',StatusData)
2052end
2053
[591]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')
[598]2058    set(handles.ActionInputView,'Visible','on')
2059    set(handles.ActionInputView,'Value',0)
[591]2060    set(handles.ActionInput,'String',ActionName)
[598]2061    ParamOut.ActionInput.Program=ActionName; % record the program in ActionInput
[591]2062    SeriesData.ActionInput=ParamOut.ActionInput;
2063else
2064    set(handles.ActionInput,'Visible','off')
2065    set(handles.ActionInput_title,'Visible','off')
[598]2066    set(handles.ActionInputView,'Visible','off')
[591]2067    if isfield(SeriesData,'ActionInput')
2068    SeriesData=rmfield(SeriesData,'ActionInput');
2069    end
2070end   
2071set(handles.series,'UserData',SeriesData)
[598]2072set(handles.ActionName,'BackgroundColor',[1 1 1])
[591]2073
[41]2074%------------------------------------------------------------------------
[598]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%------------------------------------------------------------------------
[446]2083% --- Executes on selection change in FieldName.
2084function FieldName_Callback(hObject, eventdata, handles)
[41]2085%------------------------------------------------------------------------
[446]2086field_str=get(handles.FieldName,'String');
2087field_index=get(handles.FieldName,'Value');
[2]2088field=field_str{field_index(1)};
[595]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)
[2]2133end
2134
[41]2135%------------------------------------------------------------------------
[446]2136% --- Executes on selection change in FieldName_1.
2137function FieldName_1_Callback(hObject, eventdata, handles)
[41]2138%------------------------------------------------------------------------
[446]2139field_str=get(handles.FieldName_1,'String');
2140field_index=get(handles.FieldName_1,'Value');
[2]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
[332]2147     SeriesData=get(handles.series,'UserData');
[2]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
[595]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)
[2]2161end   
[29]2162
[244]2163
[2]2164%%%%%%%%%%%%%
2165function [ind_remove]=find_pairs(dirpair,ind_i,last_i)
[339]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
[2]2181        end
[339]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
[2]2187
[89]2188%------------------------------------------------------------------------
[408]2189% --- determine the list of index pairstring of processing file
[32]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)
[89]2191%------------------------------------------------------------------------
[32]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;
[339]2198% if isequal (NomType,'_1-2_1') || isequal (NomType,'_1-2')
2199if isequal(mode,'series(Di)')
[32]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);
[339]2211elseif isequal (mode,'series(Dj)')||isequal (mode,'bursts')
[32]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
[2]2227
[41]2228%------------------------------------------------------------------------
[446]2229% --- Executes on button press in CheckObject.
2230function CheckObject_Callback(hObject, eventdata, handles)
[41]2231%------------------------------------------------------------------------
[606]2232hset_object=findobj(allchild(0),'tag','set_object');%find the set_object interface handle
[446]2233value=get(handles.CheckObject,'Value');
[2]2234if value
[606]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
[41]2264        end
[606]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');
[2]2274else
[606]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');
[2]2281end
[446]2282%set(handles.series,'UserData',SeriesData)
[2]2283
2284%--------------------------------------------------------------
[446]2285function CheckMask_Callback(hObject, eventdata, handles)
2286value=get(handles.CheckMask,'Value');
[2]2287if value
[41]2288    msgbox_uvmat('ERROR','not implemented yet')
[2]2289end
2290%--------------------------------------------------------------
2291
[41]2292%-------------------------------------------------------------------
[2]2293%'uv_ncbrowser': interactively calls the netcdf file browser 'get_field.m'
2294function ncbrowser_uvmat(hObject, eventdata)
[41]2295%-------------------------------------------------------------------
[2]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
[41]2303% ------------------------------------------------------------------
[2]2304function MenuHelp_Callback(hObject, eventdata, handles)
[41]2305%-------------------------------------------------------------------
[2]2306path_to_uvmat=which ('uvmat');% check the path of uvmat
2307pathelp=fileparts(path_to_uvmat);
[36]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')
[2]2310else
[36]2311    addpath (fullfile(pathelp,'uvmat_doc'))
2312    web([helpfile '#series'])
[2]2313end
2314
[41]2315%-------------------------------------------------------------------
[446]2316% --- Executes on selection change in TransformName.
2317function TransformName_Callback(hObject, eventdata, handles)
[591]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( ...
[39]2331       {'*.m', ' (*.m)';
2332        '*.m',  '.m files '; ...
2333        '*.*', 'All Files (*.*)'}, ...
[591]2334        'Pick a transform function',get(handles.TransformPath,'String'));
2335    if isequal(FileName,0)
2336        return     %browser closed without choice
2337    end
[39]2338    if isequal(PathName(end),'/')||isequal(PathName(end),'\')
2339        PathName(end)=[];
2340    end
[591]2341    [TransformPath,TransformName,TransformExt]=fileparts(FileName);% removes extension .m
2342    if ~strcmp(TransformExt,'.m')
[39]2343        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
2344        return
2345    end
[591]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
[39]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')
[591]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};
[39]2361       end
[591]2362       save (profil_perso,'TransformPathListUser','TransformListUser','-append'); %store the root name for future opening of uvmat
[39]2363   end
2364end
[2]2365
[591]2366%display the current function path
2367set(handles.TransformPath,'String',TransformPathList{TransformIndex}); %show the path to the senlected function
2368set(handles.TransformName,'UserData',TransformPathList);
[350]2369
2370
[446]2371% --------------------------------------------------------------------
2372function MenuExportConfig_Callback(hObject, eventdata, handles)
2373global Series
[596]2374[Series,errormsg]=prepare_jobs(handles);
[358]2375
[446]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
[472]2380
2381
[603]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
[472]2396% --- Executes on selection change in RunMode.
2397function RunMode_Callback(hObject, eventdata, handles)
[525]2398
[526]2399% --- Executes on selection change in Coord_x.
2400function Coord_x_Callback(hObject, eventdata, handles)
[525]2401
2402
[526]2403% --- Executes on selection change in Coord_y.
2404function Coord_y_Callback(hObject, eventdata, handles)
[525]2405
2406
2407
[526]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})
[586]2445
2446
2447% --- Executes on button press in status.
2448function status_Callback(hObject, eventdata, handles)
[591]2449
[595]2450if get(handles.status,'Value')
2451    set(handles.status,'BackgroundColor',[1 1 0])
2452    drawnow
[604]2453    %StatusData.time_ref=get(handles.RUN,'UserData');% get the time of launch
[595]2454    Param=read_GUI(handles.series);
2455    RootPath=Param.InputTable{1,1};
[599]2456    if ~isfield(Param,'OutputSubDir')   
2457        msgbox_uvmat('ERROR','no directory defined for output files')
2458        return
2459    end
[595]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)
[604]2464        ScreenSize=get(0,'ScreenSize');
2465        hfig=figure('DeleteFcn',@stop_status,'Position',[ScreenSize(3)-600 ScreenSize(4)-640 560 600]);
[595]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);
[606]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);
[604]2475        %set(hrefresh,'UserData',StatusData)
[595]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
[606]2480    refresh_GUI(hfig)
[595]2481else
2482    %% delete current display fig if selection is off
[586]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
[595]2490
2491
2492%------------------------------------------------------------------------   
2493% launched by selecting a file on the list
2494function view_file(hObject, eventdata)
[604]2495%------------------------------------------------------------------------
[595]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);
[586]2503end
[595]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)
[598]2524    elseif strcmp(FileType,'xml')
2525        editxml(FullSelectName)
[595]2526    else
2527        uvmat(FullSelectName)
2528    end
2529    set(gcbo,'Value',1)
2530end
[591]2531
[595]2532
[591]2533%------------------------------------------------------------------------   
2534% launched by refreshing the status figure
[606]2535function refresh_GUI(hfig)
[591]2536%------------------------------------------------------------------------
[595]2537htitlebox=findobj(hfig,'tag','titlebox');
[591]2538hlist=findobj(hfig,'tag','list');
[604]2539hseries=findobj(allchild(0),'tag','series');
2540hstatus=findobj(hseries,'tag','status');
2541StatusData=get(hstatus,'UserData');
[595]2542OutputDir=get(htitlebox,'String');
[602]2543if ischar(OutputDir),OutputDir={OutputDir};end
2544ListFiles=dir(OutputDir{1});
[604]2545if numel(ListFiles)<1
2546    return
2547end
2548ListFiles(1)=[];%removes the first line ='.'
[591]2549ListDisplay=cell(numel(ListFiles),1);
[602]2550testrecent=0;
[604]2551datnum=zeros(numel(ListDisplay),1);
2552for ilist=1:numel(ListDisplay)
2553    ListDisplay{ilist}=ListFiles(ilist).name;
[602]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
[591]2558end
2559set(hlist,'String',ListDisplay)
[602]2560
2561%% Look at date of creation
[604]2562ListDisplay=ListDisplay(datnum~=0);
[602]2563datnum=datnum(datnum~=0);%keep the non zero values corresponding to existing files
[606]2564NbOutputFile=[];
[602]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);
[604]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)];...
[602]2581        ['latest modification:  ' ListDisplay{indlast} ' : ' datestr(last)]};
2582end
[604]2583set(htitlebox,'String', [OutputDir{1};message])
2584
2585%% update the waitbar
[602]2586hwaitbar=findobj(hfig,'tag','waitbar');
[604]2587if ~isempty(NbOutputFile)
2588    BarPosition=get(hwaitbar,'Position');
2589    BarPosition(3)=0.9*numel(datnum)/NbOutputFile;
2590    set(hwaitbar,'Position',BarPosition)
2591end
[602]2592%TODO: adjust waitbar
2593
[591]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');
[595]2664% htitlebox=findobj(hfig,'tag','titlebox');
[591]2665% hwaitbar=findobj(hfig,'tag','waitbar');
2666% set(hlist,'String',Tabchar)
[595]2667% set(htitlebox,'String', message)
[604]2668%
[591]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')};
[606]2685TransformPath='';
2686if ~isempty(get(handles.ActionExt,'UserData'))
2687    TransformPath=get(handles.ActionExt,'UserData');
2688end
[591]2689if strcmp(ActionExt,'.sh')
[606]2690    set(handles.ActionExt,'BackgroundColor',[1 1 0])
[594]2691    ActionFullName=fullfile(get(handles.ActionPath,'String'),[ActionName '.sh']);
[591]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')
[606]2695            set(handles.ActionExt,'BackgroundColor',[1 1 0])
2696            path_uvmat=fileparts(which('series'));
[591]2697            currentdir=pwd;
[606]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)
[591]2703            cd(currentdir)
2704        end
[606]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
[594]2723        end
2724    end
[606]2725    set(handles.ActionExt,'BackgroundColor',[1 1 1])
[591]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')
[606]2742    set(handles.DeleteObject,'Value',0)
[591]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.