source: trunk/src/series.m @ 446

Last change on this file since 446 was 446, checked in by sommeria, 12 years ago

series rationalized. TO BE TESTED.

File size: 86.3 KB
Line 
1%'series': master function associated to the GUI series.m for analysis field series 
2%------------------------------------------------------------------------
3% function varargout = series(varargin)
4% associated with the GUI series.fig
5%
6%INPUT
7% param: structure with input parameters (link with the GUI uvmat)
8%      .menu_coord_str: string for the TransformName (menu for coordinate transforms)
9%      .menu_coord_val: value for TransformName (menu for coordinate transforms)
10%      .FileName: input file name
11%      .FileName_1: second input file name
12%      .list_field: menu of input fields
13%      .index_fields: chosen index
14%      .civ1=0 or 1, .interp1,  ... : input civ field type
15%
16%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
17%  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
18%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
19%     This file is part of the toolbox UVMAT.
20%
21%     UVMAT is free software; you can redistribute it and/or modify
22%     it under the terms of the GNU General Public License as published by
23%     the Free Software Foundation; either version 2 of the License, or
24%     (at your option) any later version.
25%
26%     UVMAT is distributed in the hope that it will be useful,
27%     but WITHOUT ANY WARRANTY; without even the implied warranty of
28%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29%     GNU General Public License (file UVMAT/COPYING.txt) for more details.
30%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
31
32%------------------------------------------------------------------------
33%------------------------------------------------------------------------
34%  I - MAIN FUNCTION series
35%------------------------------------------------------------------------
36%------------------------------------------------------------------------
37function varargout = series(varargin)
38
39% Begin initialization code - DO NOT EDIT
40gui_Singleton = 1;
41gui_State = struct('gui_Name',       mfilename, ...
42                   'gui_Singleton',  gui_Singleton, ...
43                   'gui_OpeningFcn', @series_OpeningFcn, ...
44                   'gui_OutputFcn',  @series_OutputFcn, ...
45                   'gui_LayoutFcn',  [] , ...
46                   'gui_Callback',   []);
47if nargin && ischar(varargin{1})
48    gui_State.gui_Callback = str2func(varargin{1});
49end
50
51if nargout
52    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
53else
54    gui_mainfcn(gui_State, varargin{:});
55end
56% End initialization code - DO NOT EDIT
57
58%--------------------------------------------------------------------------
59% --- Executes just before series is made visible.
60%--------------------------------------------------------------------------
61function series_OpeningFcn(hObject, eventdata, handles,param)
62global nb_builtin_ACTION nb_builtin_transform
63% Choose default command line output for series
64handles.output = hObject;
65% Update handles structure
66guidata(hObject, handles);
67%default initial parameters
68drawnow
69set(hObject,'Units','pixels')
70set(handles.PairString,'ColumnEditable',logical(0))
71set(handles.PairString,'ColumnFormat',{'char'})
72set(handles.PairString,'ColumnWidth',{60})
73set(handles.PairString,'Data',{''})
74% set(0,'Units','pixels')
75% screensize=get(0,'ScreenSize'); %screen size in pixels
76set(hObject,'WindowButtonDownFcn',{'mouse_down'})%allows mouse action with right button (zoom for uicontrol display)
77%set(hObject,'Position',[150 100 1000 600] );%position and size in pixels (get adjusted to the screen size in case of excess)
78%load the list of previously browsed files in menus Open and Open_1
79dir_perso=prefdir;
80test_profil_perso=0;
81profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
82if exist(profil_perso,'file')
83     h=load (profil_perso);
84     test_profil_perso=1;
85     if isfield(h,'MenuFile_1') && exist(h.MenuFile_1,'file')
86          set(handles.MenuFile_1,'Label',h.MenuFile_1);
87          set(handles.MenuFile_insert_1,'Label',h.MenuFile_1);
88     end
89     if isfield(h,'MenuFile_2')&& exist(h.MenuFile_2,'file')
90          set(handles.MenuFile_2,'Label',h.MenuFile_2);
91          set(handles.MenuFile_insert_2,'Label',h.MenuFile_2);
92     end
93     if isfield(h,'MenuFile_3')&& exist(h.MenuFile_3,'file')
94          set(handles.MenuFile_3,'Label',h.MenuFile_3);
95          set(handles.MenuFile_insert_3,'Label',h.MenuFile_3);
96     end
97     if isfield(h,'MenuFile_4')&& exist(h.MenuFile_4,'file')
98          set(handles.MenuFile_4,'Label',h.MenuFile_4);
99          set(handles.MenuFile_insert_4,'Label',h.MenuFile_4);
100     end
101     if isfield(h,'MenuFile_5')&& exist(h.MenuFile_5,'file')
102          set(handles.MenuFile_5,'Label',h.MenuFile_5);
103          set(handles.MenuFile_insert_5,'Label',h.MenuFile_5);
104     end
105end
106
107%check default input data
108if ~exist('param','var')
109    param=[]; %default
110end
111
112%% file name and browser initialisation
113if isfield(param,'menu_coord_str')
114    set(handles.TransformName,'String',param.menu_coord_str)
115end
116if isfield(param,'menu_coord_val')
117    set(handles.TransformName,'Value',param.menu_coord_val);
118else
119     set(handles.TransformName,'Value',1);%default
120end
121if isfield(param,'FileName')
122    if isfield(param,'FileName_1')
123        display_file_name(handles,param.FileName_1,0)
124        display_file_name(handles,param.FileName,1)
125    else
126        display_file_name(handles,param.FileName,0)
127    end
128end 
129
130%% fields input initialisation
131if isfield(param,'list_fields')&& isfield(param,'index_fields') &&~isempty(param.list_fields) &&~isempty(param.index_fields)
132    set(handles.FieldName,'String',param.list_fields);% list menu fields
133    set(handles.FieldName,'Value',param.index_fields);% selected string index
134    FieldCell{1}=param.list_fields{param.index_fields};
135end
136
137%loads the information stored in prefdir to initiate  the list of ActionName functions
138fct_menu={'check_data_files';'aver_stat';'time_series';'merge_proj';'clean_civ_cmx'};
139transform_menu={'';'phys';'px';'phys_polar'};
140nb_builtin_ACTION=numel(fct_menu); %number of functions
141nb_transform=numel(transform_menu);
142[path_series,name,ext]=fileparts(which('series'));
143path_series=fullfile(path_series,'series');%path of the function 'series'
144addpath (path_series) ; %add the path to UVMAT, (useful in case of change of working directory after civ has been s opened in the working directory)
145path_transform=fullfile(path_series,'transform_field');%path to the field transform functions
146for ilist=1:length(fct_menu)
147    fct_path{ilist,1}=path_series;%paths of the fuctions buil-in in 'series.m'
148end
149
150%% TRANSFORM menu: loads the information stored in prefdir to initiate  the list of field transform functions
151menu_str={'';'phys';'px';'phys_polar'};
152nb_builtin_transform=numel(menu_str); %number of functions
153[path_uvmat,name,ext]=fileparts(which('uvmat'));
154addpath(fullfile(path_uvmat,'transform_field'))
155fct_handle{1,1}=[];
156testexist(1)=1;
157for ilist=2:length(menu_str)
158    if exist(menu_str{ilist},'file')
159        fct_handle{ilist,1}=str2func(menu_str{ilist});
160        testexist(ilist)=1;
161    else
162        testexist(ilist)=0;
163    end
164end
165rmpath(fullfile(path_uvmat,'transform_field'))
166
167%% read the list of functions stored in the personal file 'uvmat_perso.mat' in prefdir
168if test_profil_perso
169    if isfield(h,'series_fct') && iscell(h.series_fct)
170         for ilist=1:length(h.series_fct)
171             [path,file]=fileparts(h.series_fct{ilist});
172             fct_path=[fct_path; {path}];%concatene the list of paths
173             fct_menu=[fct_menu; {file}];
174         end
175    end
176    if isfield(h,'transform_fct') && iscell(h.transform_fct)
177        for ilist=1:length(h.transform_fct);
178             [path,file]=fileparts(h.transform_fct{ilist});
179             addpath(path)
180             if exist(file,'file')
181                h_func=str2func(file);
182                testexist=[testexist 1];
183             else
184                h_func=[];
185                testexist=[testexist 0];
186             end
187             fct_handle=[fct_handle; {h_func}];%concatene the list of paths
188             rmpath(path)
189             menu_str=[menu_str; {file}];
190        end
191    end
192end
193fct_menu=[fct_menu;{'more...'}];
194set(handles.ActionName,'String',fct_menu)
195set(handles.ActionName,'UserData',fct_path)% store the list of path in UserData of ACTION
196menu_str=menu_str(find(testexist));
197fct_handle=fct_handle(find(testexist));
198menu_str=[menu_str;{'more...'}];
199set(handles.TransformName,'String',menu_str)
200set(handles.TransformName,'UserData',fct_handle)% store the list of path in UserData of ACTION
201
202% display the GUI for the default actionname 'check_data_files'
203ActionName_Callback(hObject, eventdata, handles)
204
205%------------------------------------------------------------------------
206% --- Outputs from this function are returned to the command line.
207function varargout = series_OutputFcn(hObject, eventdata, handles)
208%------------------------------------------------------------------------
209% varargout  cell array for returning output args (see VARARGOUT);
210% hObject    handle to figure
211% eventdata  reserved - to be defined in a future version of MATLAB
212% handles    structure with handles and user data (see GUIDATA)
213% Get default command line output from handles structure
214varargout{1} = handles.output;
215
216%------------------------------------------------------------------------
217%------------------------------------------------------------------------
218%  II - FUNCTIONS FOR INTRODUCING THE INPUT FILES
219% automatically sets the global properties when the rootfile name is introduced
220% then activate the view-field actionname if selected
221% it is activated either by clicking on the RootPath window or by the
222% browser
223%------------------------------------------------------------------------
224%------------------------------------------------------------------------
225function MenuBrowse_Callback(hObject, eventdata, handles)
226%------------------------------------------------------------------------   
227InputTable=get(handles.InputTable,'Data');
228RootPathCell=InputTable(:,1);
229SubDirCell=InputTable(:,2);
230RootFileCell=InputTable(:,3);
231oldfile=''; %default
232if isempty(RootPathCell)||isequal(RootPathCell,{''})%loads the previously stored file name and set it as default in the file_input box
233     dir_perso=prefdir;
234     profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
235     if exist(profil_perso,'file')
236          h=load (profil_perso);
237         if isfield(h,'filebase')&&ischar(h.filebase)
238                 oldfile=h.filebase;
239         end
240         if isfield(h,'RootPath')&&ischar(h.RootPath)
241                 oldfile=h.RootPath;
242         end
243     end
244 else
245     oldfile=fullfile(RootPathCell{1},SubDirCell{1},RootFileCell{1});
246 end
247[FileName, PathName, filterindex] = uigetfile( ...
248       {'*.xml;*.xls;*.png;*.tif;*.avi;*.AVI;*.nc', ' (*.xml,*.xls, *.png,*.tif, *.avi,*.nc)';
249       '*.xml',  '.xml files '; ...
250        '*.xls',  '.xls files '; ...
251        '*.png','.png image files'; ...
252        '*.tif','.tif image files'; ...
253        '*.avi;*.AVI','.avi movie files'; ...
254        '*.nc','.netcdf files'; ...
255        '*.*',  'All Files (*.*)'}, ...
256        'Pick a file',oldfile);
257fileinput=[PathName FileName];%complete file name
258sizf=size(fileinput);
259if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
260[path,name,ext]=fileparts(fileinput);
261SeriesData=[];%dfault
262if isequal(ext,'.xml')
263    msgbox_uvmat('ERROR','input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
264elseif isequal(ext,'.xls')
265    msg_box_uvmat('ERROR','input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
266else
267    display_file_name(handles,fileinput,0)
268     %update list of recent files in the menubar
269%     MenuFile_1=fileinput;
270%     MenuFile_2=get(handles.MenuFile_1,'Label');
271%     MenuFile_3=get(handles.MenuFile_2,'Label');
272%     MenuFile_4=get(handles.MenuFile_3,'Label');
273%     MenuFile_5=get(handles.MenuFile_4,'Label');
274%     set(handles.MenuFile_1,'Label',MenuFile_1)
275%     set(handles.MenuFile_2,'Label',MenuFile_2)
276%     set(handles.MenuFile_3,'Label',MenuFile_3)
277%     set(handles.MenuFile_4,'Label',MenuFile_4)
278%     set(handles.MenuFile_5,'Label',MenuFile_5)
279%     set(handles.MenuFile_insert_1,'Label',MenuFile_1)
280%     set(handles.MenuFile_insert_2,'Label',MenuFile_2)
281%     set(handles.MenuFile_insert_3,'Label',MenuFile_3)
282%     set(handles.MenuFile_insert_4,'Label',MenuFile_4)
283%     set(handles.MenuFile_insert_5,'Label',MenuFile_5)
284%     dir_perso=prefdir;
285%     profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
286%     if exist(profil_perso,'file')
287%         save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-append'); %store the file names for future opening of uvmat
288%     else
289%     txt=ver('MATLAB');
290%     Release=txt.Release;
291%         relnumb=str2num(Release(3:4));
292%         if relnumb >= 14
293%             save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-V6'); %store the file names for future opening of uvmat
294%         else
295%             save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5'); %store the file names for future opening of uvmat
296%         end
297%     end
298end
299
300% --------------------------------------------------------------------
301function MenuFile_1_Callback(hObject, eventdata, handles)
302fileinput=get(handles.MenuFile_1,'Label');
303display_file_name(handles,fileinput,0)
304
305% --------------------------------------------------------------------
306function MenuFile_2_Callback(hObject, eventdata, handles)
307fileinput=get(handles.MenuFile_2,'Label');
308display_file_name(handles,fileinput,0)
309
310% --------------------------------------------------------------------
311function MenuFile_3_Callback(hObject, eventdata, handles)
312fileinput=get(handles.MenuFile_3,'Label');
313display_file_name( handles,fileinput,0)
314
315% --------------------------------------------------------------------
316function MenuFile_4_Callback(hObject, eventdata, handles)
317fileinput=get(handles.MenuFile_4,'Label');
318display_file_name(handles,fileinput,0)
319
320% --------------------------------------------------------------------
321function MenuFile_5_Callback(hObject, eventdata, handles)
322fileinput=get(handles.MenuFile_5,'Label');
323display_file_name(handles,fileinput,0)
324
325% --------------------------------------------------------------------
326function MenuBrowse_insert_Callback(hObject, eventdata, handles)
327InputTable=get(handles.InputTable,'Data');
328RootPathCell=InputTable(:,1);
329SubDirCell=InputTable(:,3);
330RootFileCell=InputTable(:,2);
331oldfile=''; %default
332if isempty(RootPathCell)||isequal(RootPathCell,{''})%loads the previously stored file name and set it as default in the file_input box
333     dir_perso=prefdir;
334     profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
335     if exist(profil_perso,'file')
336          h=load (profil_perso);
337         if isfield(h,'filebase')&ischar(h.filebase)
338                 oldfile=h.filebase;
339         end
340         if isfield(h,'RootPath')&ischar(h.RootPath)
341                 oldfile=h.RootPath;
342         end
343     end
344 else
345     oldfile=fullfile(RootPathCell{1},RootFileCell{1});
346 end
347[FileName, PathName, filterindex] = uigetfile( ...
348       {'*.xml;*.xls;*.png;*.avi;*.AVI;*.nc', ' (*.xml,*.xls, *.png, *.avi,*.nc)';
349       '*.xml',  '.xml files '; ...
350        '*.xls',  '.xls files '; ...
351        '*.png','.png image files'; ...
352        '*.avi;*.AVI','.avi movie files'; ...
353        '*.nc','.netcdf files'; ...
354        '*.*',  'All Files (*.*)'}, ...
355        'Pick a file',oldfile);
356fileinput=[PathName FileName];%complete file name
357sizf=size(fileinput);
358if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
359[path,name,ext]=fileparts(fileinput);
360if isequal(ext,'.xml')
361    msgbox_uvmat('ERROR','input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
362elseif isequal(ext,'.xls')
363    msgbox_uvmat('ERROR','input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
364else
365    display_file_name(handles,fileinput,1)
366end
367
368% --------------------------------------------------------------------
369function MenuFile_insert_1_Callback(hObject, eventdata, handles)
370% --------------------------------------------------------------------   
371fileinput=get(handles.MenuFile_insert_1,'Label');
372display_file_name(handles,fileinput,1)
373
374% --------------------------------------------------------------------
375function MenuFile_insert_2_Callback(hObject, eventdata, handles)
376% --------------------------------------------------------------------   
377fileinput=get(handles.MenuFile_insert_2,'Label');
378display_file_name(handles,fileinput,1)
379
380% --------------------------------------------------------------------
381function MenuFile_insert_3_Callback(hObject, eventdata, handles)
382% --------------------------------------------------------------------   
383fileinput=get(handles.MenuFile_insert_3,'Label');
384display_file_name( handles,fileinput,1)
385
386% --------------------------------------------------------------------
387function MenuFile_insert_4_Callback(hObject, eventdata, handles)
388% --------------------------------------------------------------------   
389fileinput=get(handles.MenuFile_insert_4,'Label');
390display_file_name( handles,fileinput,1)
391
392% --------------------------------------------------------------------
393function MenuFile_insert_5_Callback(hObject, eventdata, handles)
394% --------------------------------------------------------------------   
395fileinput=get(handles.MenuFile_insert_5,'Label');
396display_file_name(handles,fileinput,1)
397
398%------------------------------------------------------------------------
399% --- Executes when entered data in editable cell(s) in InputTable.
400function InputTable_CellEditCallback(hObject, eventdata, handles)
401%------------------------------------------------------------------------
402iview=eventdata.Indices(1);
403InputTable=get(handles.InputTable,'Data');
404fileinput=fullfile(InputTable{iview,1},InputTable{iview,2},[InputTable{iview,3} InputTable{iview,4} InputTable{iview,5}]);
405display_file_name(handles,fileinput,0)
406%update the output dir
407SubDir=sort(InputTable(:,2)); %set of subdirectories sorted in alphabetical order
408SubDirOut=SubDir{1};
409if numel(SubDir)>1
410    for ilist=2:numel(SubDir)
411        SubDirOut=[SubDirOut '-' SubDir{ilist}];
412    end
413end
414set(handles.OutputSubDir,'String',SubDirOut)
415
416%------------------------------------------------------------------------
417% ---  refresh the GUI data after introduction of a new file
418% INPUT:
419% handles: handles of the elements in the GUI series
420% fileinput: name of the input file
421% append: =0 to refresh the list of file series, =1 to append a new series to the list (from the menu bar option 'Open_insert')
422function display_file_name(handles,fileinput,append)
423%------------------------------------------------------------------------ 
424
425%% get the input root name, indices, file extension and nomenclature NomType
426if ~exist(fileinput,'file')
427    msgbox_uvmat('ERROR',['input file ' fileinput  ' does not exist'])
428    return
429end
430
431%% enable other menus and uicontrols
432set(handles.MenuOpen_insert,'Enable','on')
433set(handles.MenuFile_insert_1,'Enable','on')
434set(handles.MenuFile_insert_2,'Enable','on')
435set(handles.MenuFile_insert_3,'Enable','on')
436set(handles.MenuFile_insert_4,'Enable','on')
437set(handles.MenuFile_insert_5,'Enable','on')
438set(handles.RUN, 'Enable','On')
439set(handles.RUN,'BackgroundColor',[1 0 0])% set RUN button to red
440set(handles.InputTable,'BackgroundColor',[1 1 0]) % set RootPath edit box  to yellow
441drawnow
442
443%% detect root name, nomenclature and indices in the input file name:
444[FilePath,FileName,FileExt]=fileparts(fileinput);
445% detect the file type, get the movie object if relevant, and look for the corresponding file series:
446% the root name and indices may be corrected by including the first index i1 if a corresponding xml file exists
447[RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,NomType,FileType,MovieObject,i1,i2,j1,j2]=find_file_series(FilePath,[FileName FileExt]);
448if isempty(RootFile)&&isempty(i1_series)
449    errormsg='no input file in the series';
450    return
451end
452
453%% fill the list of file series
454InputTable=get(handles.InputTable,'Data');
455if append % display the input data as a new line in the table
456     lastview=size(InputTable,1)+1;
457     InputTable(lastview,:)=[{RootPath},{SubDir},{RootFile},{NomType},{FileExt}];
458    set(handles.ListView,'String',[get(handles.ListView,'String');{num2str(lastview)}])
459    set(handles.ListView,'Value',lastview)
460
461else % or re-initialise the list of  input  file series
462    lastview=1;
463    InputTable=[{RootPath},{SubDir},{RootFile},{NomType},{FileExt}];
464    set(handles.TimeTable,'Data',[{[]},{[]},{[]},{[]}])
465    set(handles.MinIndex,'Data',[{[]},{[]}])
466    set(handles.MaxIndex,'Data',[{[]},{[]}])
467    set(handles.ListView,'Value',1)
468    set(handles.ListView,'String',{'1'})
469end
470set(handles.InputTable,'Data',InputTable)
471
472%update the output dir
473SubDir=sort(InputTable(:,2)); %set of subdirectories sorted in alphabetical order
474SubDirOut=SubDir{1};
475if numel(SubDir)>1
476    for ilist=2:numel(SubDir)
477        SubDirOut=[SubDirOut '-' SubDir{ilist}];
478    end
479end
480set(handles.OutputSubDir,'String',SubDirOut)
481
482%% determine the selected reference field indices for pair display
483ref_i=1; %default ref_i is a reference frame index used to find existing pairs from PIV
484if ~isempty(i1)
485    ref_i=i1;
486    if ~isempty(i2)
487        ref_i=floor((ref_i+i2)/2);% reference image number corresponding to the file
488    end
489end
490set(handles.num_ref_i,'String',num2str(ref_i));
491ref_j=1; %default  ref_j is a reference frame index used to find existing pairs from PIV
492if ~isempty(j1)
493    ref_j=j1;
494    if ~isempty(j2)
495        ref_j=floor((j1+j2)/2);
496    end         
497end
498set(handles.num_ref_j,'String',num2str(ref_j));
499
500%% update the list of recent files in the menubar and save it for future opening
501MenuFile=[{get(handles.MenuFile_1,'Label')};{get(handles.MenuFile_2,'Label')};...
502    {get(handles.MenuFile_3,'Label')};{get(handles.MenuFile_4,'Label')};{get(handles.MenuFile_5,'Label')}];
503str_find=strcmp(fileinput,MenuFile);
504if isempty(find(str_find,1))
505    MenuFile=[{fileinput};MenuFile];%insert the current file if not already in the list
506end
507for ifile=1:min(length(MenuFile),5)
508    eval(['set(handles.MenuFile_' num2str(ifile) ',''Label'',MenuFile{ifile});'])
509    eval(['set(handles.MenuFile_insert_' num2str(ifile) ',''Label'',MenuFile{ifile});'])
510end
511dir_perso=prefdir;
512profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
513if exist(profil_perso,'file')
514    save (profil_perso,'MenuFile','-append'); %store the file names for future opening of uvmat
515else
516    save (profil_perso,'MenuFile','-V6'); %store the file names for future opening of uvmat
517end
518
519set(handles.InputTable,'BackgroundColor',[1 1 1])
520
521%% initiate input file series and refresh the current field view:     
522update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,MovieObject,lastview);
523
524%------------------------------------------------------------------------
525% --- Update information about a new field series (indices to scan, timing,
526%     calibration from an xml file, then refresh current plots
527function update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,VideoObject,iview)
528%------------------------------------------------------------------------
529
530%% enable j index visibility
531if isempty(j1_series)
532    state='off';
533else
534    state='on';
535end
536enable_j(handles,state)
537
538%% display the min and max indices for all the file series
539MinIndex=get(handles.MinIndex,'Data');%retrieve the min indices in the table MinIndex
540MaxIndex=get(handles.MaxIndex,'Data');%retrieve the max indices in the table MaxIndex
541i_sum=sum(sum(i1_series,2),3);
542MaxIndex_i=max(find(i_sum>0))-1;
543MinIndex_i=min(find(i_sum>0))-1;
544j_sum=sum(sum(i1_series,1),3);
545MaxIndex_j=max(find(j_sum>0))-1;
546MinIndex_j=min(find(j_sum>0))-1;
547MinIndex{iview,1}=MinIndex_i;
548MinIndex{iview,2}=MinIndex_j;
549MaxIndex{iview,1}=MaxIndex_i;
550MaxIndex{iview,2}=MaxIndex_j;
551set(handles.MinIndex,'Data',MinIndex)%display the min indices in the table MinIndex
552set(handles.MaxIndex,'Data',MaxIndex)%display the max indices in the table MaxIndex
553
554%% adjust the first and last indices if requested by the bounds
555first_i=str2num(get(handles.num_first_i,'String'));
556ref_i=str2num(get(handles.num_ref_i,'String'));
557ref_j=str2num(get(handles.num_ref_j,'String'));
558if isempty(first_i)
559    first_i=ref_i;
560elseif first_i < MinIndex_i
561    first_i=MinIndex_i;
562end
563first_j=str2num(get(handles.num_first_j,'String'));
564if isempty(first_j)
565    first_j=ref_j;
566elseif first_j<MinIndex_j
567    first_j=MinIndex_j;
568end
569last_i=str2num(get(handles.num_last_i,'String'));
570if isempty(last_i)
571    last_i=ref_i;
572elseif last_i > MaxIndex_i
573    last_i=MaxIndex_i;
574end
575last_j=str2num(get(handles.num_first_j,'String'));
576if isempty(last_j)
577    last_j=ref_j;
578elseif last_j>MaxIndex_j
579    last_j=MaxIndex_j;
580end
581set(handles.num_first_i,'String',num2str(first_i));
582set(handles.num_first_j,'String',num2str(first_j));
583set(handles.num_last_i,'String',num2str(last_i));
584set(handles.num_last_j,'String',num2str(last_j));
585
586%% read timing and total frame number from the current file (movie files) !! may be overrid by xml file
587InputTable=get(handles.InputTable,'Data');
588FileBase=fullfile(InputTable{iview,1},InputTable{iview,3});
589time=[];%default
590% case of movies
591if strcmp(InputTable{iview,4},'*')
592    if ~isempty(VideoObject)
593        imainfo=get(VideoObject);
594        time=(0:1/imainfo.FrameRate:(imainfo.NumberOfFrames-1)/imainfo.FrameRate)';
595        set(handles.Dt_txt,'String',['Dt=' num2str(1000/imainfo.FrameRate) 'ms']);%display the elementary time interval in millisec
596        ColorType='truecolor';
597    elseif ~isempty(imformats(regexprep(InputTable{iview,5},'^.',''))) || isequal(InputTable{iview,5},'.vol')%&& isequal(NomType,'*')% multi-frame image
598        if ~isempty(InputTable{iview,2})
599            imainfo=imfinfo(fullfile(InputTable{iview,1},InputTable{iview,2},[InputTable{iview,3} InputTable{iview,5}]));
600        else
601            imainfo=imfinfo([FileBase InputTable{iview,5}]);
602        end
603        ColorType=imainfo.ColorType;%='truecolor' for color images
604        if length(imainfo) >1 %case of image with multiple frames
605            nbfield=length(imainfo);
606            nbfield_j=1;
607        end
608    end
609end
610
611%%  read image documentation file  if found%%%%%%%%%%%%%%%%%%%%%%%%%%%
612ext_imadoc='';
613if exist([FileBase '.xml'],'file')
614    ext_imadoc='.xml';
615elseif exist([FileBase '.civ'],'file')
616    ext_imadoc='.civ';
617end
618%read the ImaDoc file
619XmlData=[];
620NbSlice_calib={};
621if isequal(ext_imadoc,'.xml')
622        [XmlData,warntext]=imadoc2struct([FileBase '.xml']);
623        if isfield(XmlData,'Heading') && isfield(XmlData.Heading,'ImageName') && ischar(XmlData.Heading.ImageName)
624            [PP,FF,ext_ima_read]=fileparts(XmlData.Heading.ImageName);
625        end
626        if isfield(XmlData,'Time')
627            time=XmlData.Time;
628        end
629        if isfield(XmlData,'Camera')
630            if isfield(XmlData.Camera,'NbSlice')&& ~isempty(XmlData.Camera.NbSlice)
631                NbSlice_calib{iview}=XmlData.Camera.NbSlice;% Nbre of slices for Zindex in phys transform
632                if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
633                    msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
634                end
635            end
636            if isfield(XmlData.Camera,'TimeUnit')&& ~isempty(XmlData.Camera.TimeUnit)
637                TimeUnit=XmlData.Camera.TimeUnit;
638            end
639        end
640        if ~isempty(warntext)
641            msgbox_uvmat('WARNING',warntext)
642        end 
643elseif isequal(ext_imadoc,'.civ')
644    [error,XmlData.Time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([FileBase '.civ']);
645    time=XmlData.Time;
646    if error==2, warntext=['no file ' FileBase '.civ'];
647    elseif error==1, warntext='inconsistent number of fields in the .civ file';
648    end 
649end
650
651%% update time table
652TimeTable=get(handles.TimeTable,'Data');
653if isempty(MinIndex_j)
654    TimeTable{iview,1}=time(MinIndex_i);
655    TimeTable{iview,2}=time(first_i);
656    TimeTable{iview,3}=time(last_i);
657    TimeTable{iview,4}=time(MaxIndex_i);
658elseif ~isempty(time)
659    TimeTable{iview,1}=time(MinIndex_i,MinIndex_j);
660    TimeTable{iview,2}=time(first_i,first_j);
661    TimeTable{iview,3}=time(last_i,last_j);
662    TimeTable{iview,4}=time(MaxIndex_i,MaxIndex_j);
663end
664set(handles.TimeTable,'Data',TimeTable)
665
666%% number of slices
667if isfield(XmlData,'GeometryCalib') && isfield(XmlData.GeometryCalib,'SliceCoord')
668    siz=size(XmlData.GeometryCalib.SliceCoord);
669    if siz(1)>1
670        NbSlice=siz(1);
671    else
672        NbSlice=1;
673    end
674    set(handles.num_NbSlice,'String',num2str(NbSlice))
675end
676
677%% update pair menus
678set(handles.Pairs,'Visible','on')
679set(handles.PairString,'Visible','on')
680ListView=get(handles.ListView,'String');
681ListView{iview}=num2str(iview);
682set(handles.ListView,'String');
683set(handles.ListView,'Value',iview)
684update_mode(handles,i1_series,i2_series,j1_series,j2_series,time)
685
686
687%% display the set of existing files as an image
688set(handles.waitbar_frame,'Units','pixels')
689pos=get(handles.waitbar_frame,'Position');
690xima=0.5:pos(3)-0.5;% pixel positions on the image representing the existing file indices
691yima=0.5:pos(4)-0.5;
692[XIma,YIma]=meshgrid(xima,yima);
693nb_i=size(i1_series,1);
694nb_j=size(i1_series,2);
695ind_i=(0.5:nb_i-0.5)*pos(3)/nb_i;
696ind_j=(0.5:nb_j-0.5)*pos(4)/nb_j;
697[Ind_i,Ind_j]=meshgrid(ind_i,ind_j);
698CData=zeros([size(XIma) 3]);
699file_ima=double((i1_series(:,:,1)>0)');
700if numel(file_ima)>=2
701if size(file_ima,1)==1
702    CLine=interp1(ind_i,file_ima,xima,'nearest');
703    CData(:,:,2)=ones(size(yima'))*CLine;
704else
705    CData(:,:,2)=interp2(Ind_i,Ind_j,file_ima,XIma,YIma,'nearest');
706end
707set(handles.waitbar_frame,'CData',CData)
708end
709set(handles.waitbar_frame,'Units','normalized')
710
711%% enable field and veltype menus
712SeriesData=get(handles.series,'UserData');
713SeriesData.FileType{iview}=FileType;
714check_civ=0;
715check_netcdf=0;
716for iview=1:length(SeriesData.FileType)
717    switch SeriesData.FileType{iview}
718        case {'civx','civdata'}
719            check_civ=check_civ+1;
720        case 'netcdf'
721            check_netcdf=check_netcdf+1;
722    end
723end
724if check_civ
725    enable='on';
726else
727    enable='off';
728end
729set(handles.VelType,'Visible',enable)
730set(handles.VelType_text,'Visible',enable)
731if check_civ>=2
732    enable='on';
733else
734    enable='off';
735end
736set(handles.VelType_1,'Visible',enable)
737set(handles.VelType_text_1,'Visible',enable)
738if check_civ || check_netcdf
739    enable='on';
740else
741    enable='off';
742end
743set(handles.FieldName,'Visible',enable)
744set(handles.Field_text,'Visible',enable)
745if check_civ+ check_netcdf>=2
746    enable='on';
747else
748    enable='off';
749end
750set(handles.FieldName_1,'Visible',enable)
751set(handles.Field_text_1,'Visible',enable)
752FieldString={''};
753if check_civ
754    FieldString=[calc_field;{'get_field...'}];
755elseif check_netcdf
756    FieldString={'get_field...'};
757end
758set(handles.FieldName,'String',FieldString)
759FieldString={''};
760if check_civ>=2
761    FieldString=[calc_field;{'get_field...'}];
762elseif check_civ+check_netcdf>=2
763    FieldString={'get_field...'};
764end
765set(handles.FieldName_1,'String',{'get_field...'})
766
767
768%% store the series info in 'UserData'
769SeriesData.i1_series{iview}=i1_series;
770SeriesData.i2_series{iview}=i2_series;
771SeriesData.j1_series{iview}=j1_series;
772SeriesData.j2_series{iview}=j2_series;
773SeriesData.FileType{iview}=FileType;
774SeriesData.Time{iview}=time;
775set(handles.series,'UserData',SeriesData)
776
777%% check for pair display
778check_pairs=0;
779for iview=1:numel(SeriesData.i2_series)
780    if ~isempty(SeriesData.i2_series{iview})||~isempty(SeriesData.j2_series{iview})
781        check_pairs=1;
782    end
783end
784if check_pairs
785    set(handles.Pairs,'Visible','on')
786    set(handles.PairString,'Visible','on')
787else
788    set(handles.Pairs,'Visible','off')
789    set(handles.PairString,'Visible','off')
790end
791
792return
793
794%% set default options in menu 'Fields'%% TODO: check VelType
795if ~testima
796    testcivx=0;
797    if isfield(UvData,'FieldsString') && isequal(UvData.FieldsString,{'get_field...'})% field menu defined as input (from get_field)
798        set(handles_Fields,'Value',1)
799        set(handles_Fields,'String',{'get_field...'})
800        UvData=rmfield(UvData,'FieldsString');
801    else
802        Data=nc2struct(FileName,'ListGlobalAttribute','Conventions','absolut_time_T0','civ');
803        if strcmp(Data.Conventions,'uvmat/civdata') ||( ~isempty(Data.absolut_time_T0)&& ~isequal(Data.civ,0))%if the new input is Civx
804            FieldList=calc_field;
805            set(handles_Fields,'String',[{'image'};FieldList;{'get_field...'}]);%standard menu for civx data
806            set(handles_Fields,'Value',2) % set menu to 'velocity'
807            col_vec=FieldList;
808            col_vec(1)=[];%remove 'velocity' option for vector color (must be a scalar)
809            testcivx=1;
810        end
811        if ~testcivx
812            set(handles_Fields,'Value',1) % set menu to 'get_field...
813            set(handles_Fields,'String',{'get_field...'})
814            col_vec={'get_field...'};
815        end
816        set(handles.ColorScalar,'String',col_vec)
817    end
818end
819set(handles.uvmat,'UserData',UvData)
820
821%% set index navigation options and refresh plots
822scan_option='i';%default
823state_j='off'; %default
824if index==2
825    if get(handles.scan_j,'Value')
826        scan_option='j'; %keep the scan option for the second fiel series
827    end
828    if strcmp(get(handles.j1,'Visible'),'on')
829        state_j='on';
830    end
831end
832if ~isempty(j1_series)
833        state_j='on';
834        if isequal(nbfield,1) &&index==1
835            scan_option='j'; %scan j index by default if nbfield=1               
836        end
837end
838if isequal(scan_option,'i')
839     set(handles.scan_i,'Value',1)
840     scan_i_Callback([],[], handles);
841else
842     set(handles.scan_j,'Value',1)
843     scan_j_Callback([],[], handles);
844end
845set(handles.scan_j,'Visible',state_j)
846set(handles.j1,'Visible',state_j)
847set(handles.j2,'Visible',state_j)
848set(handles.last_j,'Visible',state_j);
849set(handles.frame_j,'Visible',state_j);
850set(handles.j_text,'Visible',state_j);
851if ~isempty(i2_series)||~isempty(j2_series)
852    set(handles.CheckFixPair,'Visible','on')
853elseif index==1
854    set(handles.CheckFixPair,'Visible','off')
855end
856
857
858mode_Callback(hObject, eventdata, handles)
859
860set(handles.REFRESH_INDICES,'BackgroundColor',[0.7 0.7 0.7])
861InputTable=get(handles.InputTable,'Data');
862check_lines=get(handles.REFRESH_INDICES,'UserData');
863
864%% check the indices and FileTypes for each series (limited to the new ones to save time)
865for ind_list=1:length(check_lines)
866    if  check_lines(ind_list)
867        InputLine=InputTable(ind_list,:);
868        detect_idem=strcmp('"',InputLine);% look for '" (repeat of previous data)
869        detect_idem=detect_idem(detect_idem>0);
870        if ~isempty (detect_idem)
871            InputLine(detect_idem)=InputTable(ind_list-1,detect_idem);
872            set(handles.InputTable,'Data',InputTable)
873        end
874        fileinput=fullfile_uvmat(InputLine{1},InputLine{2},InputLine{3},InputLine{5},InputLine{4},1,2,1,2);
875        %fileinput=name_generator(fullfile(InputLine{1},InputLine{3}),1,1,InputLine{5},InputLine{4},1,2,2,InputLine{2})
876        %update file series defined by the selected line
877        [InputTable{ind_list,3},InputTable{(ind_list),4},errormsg]=update_indices(handles,fileinput,ind_list);
878        if ~isempty(errormsg)
879                msgbox_uvmat('ERROR',errormsg)
880                return
881        end
882    end
883end
884set(handles.InputTable,'Data',InputTable)
885SeriesData=get(handles.series,'UserData');
886
887state_j='off';
888state_Pairs='off';
889state_InputFields='off';
890val=get(handles.ListView,'Value');
891ListViewString={''};
892if ~isempty(SeriesData)
893%     ListViewString={};
894    for iview=1:size(InputTable,1)
895        if ~isempty(SeriesData.j1_series{iview})
896            state_j='on';
897        end
898        if ~isempty(SeriesData.i2_series{iview})||~isempty(SeriesData.j2_series{iview})
899            state_Pairs='on';
900            ListViewString{iview}=num2str(iview);
901            if check_lines(iview)
902                val=iview;%select the last pair if it is a new entry
903            end
904        end
905        if strcmp(SeriesData.FileType{iview},'civx')||strcmp(SeriesData.FileType{iview},'civdata')
906            state_InputFields='on';
907        end
908    end
909end
910set(handles.ListView,'Value',val)
911set(handles.ListView,'String',ListViewString)
912if strcmp(state_Pairs,'on')
913    ListView_Callback(hObject,eventdata,handles)
914end
915set(handles.PairString,'Visible',state_Pairs)
916enable_j(handles,state_j)
917
918%------------------------------------------------------------------------
919function num_first_i_Callback(hObject, eventdata, handles)
920%------------------------------------------------------------------------
921num_last_i_Callback(hObject, eventdata, handles)
922
923%------------------------------------------------------------------------
924function num_last_i_Callback(hObject, eventdata, handles)
925%------------------------------------------------------------------------
926SeriesData=get(handles.series,'UserData');
927if ~isfield(SeriesData,'Time')
928    SeriesData.Time{1}=[];
929end
930displ_time(handles);
931
932%------------------------------------------------------------------------
933function num_first_j_Callback(hObject, eventdata, handles)
934%------------------------------------------------------------------------
935 num_last_j_Callback(hObject, eventdata, handles)
936
937%------------------------------------------------------------------------
938function num_last_j_Callback(hObject, eventdata, handles)
939%------------------------------------------------------------------------
940first_j=str2num(get(handles.num_first_j,'String'));
941last_j=str2num(get(handles.num_last_j,'String'));
942ref_j=ceil((first_j+last_j)/2);
943set(handles.num_ref_j,'String', num2str(ref_j))
944num_ref_j_Callback(hObject, eventdata, handles)
945SeriesData=get(handles.series,'UserData');
946if ~isfield(SeriesData,'Time')
947    SeriesData.Time{1}=[];
948end
949displ_time(handles);
950
951%------------------------------------------------------------------------
952% ---- find the times corresponding to the first and last indices of a series
953function displ_time(handles)
954%------------------------------------------------------------------------
955SeriesData=get(handles.series,'UserData');%
956ref_i=[str2num(get(handles.num_first_i,'String')) str2num(get(handles.num_last_i,'String'))];
957ref_j=[str2num(get(handles.num_first_j,'String')) str2num(get(handles.num_last_j,'String'))];
958% last_i=str2num(get(handles.num_last_i,'String'));
959% last_j=str2num(get(handles.num_last_j,'String'));
960TimeTable=get(handles.TimeTable,'Data');
961Pairs=get(handles.PairString,'Data');
962for iview=1:size(TimeTable,1)
963    if size(SeriesData.Time,1)<iview
964        break
965    end
966    i1=ref_i;
967    j1=ref_j;
968    i2=ref_i;
969    j2=ref_j;
970    % case of pairs
971    if ~isempty(Pairs{iview,1})
972        r=regexp(Pairs{iview,1},'(?<mode>(Di=)|(Dj=)) -*(?<num1>\d+)\|(?<num2>\d+)','names');
973        if isempty(r)
974            r=regexp(Pairs{iview,1},'(?<num1>\d+)(?<mode>-)(?<num2>\d+)','names');
975        end
976        switch r.mode
977            case 'Di='  %  case 'series(Di)')
978                i1=ref_i-str2num(r.num1);
979                i2=ref_i+str2num(r.num2);
980            case 'Dj='  %  case 'series(Dj)'
981                j1=ref_j-str2num(r.num1);
982                j2=ref_j+str2num(r.num2);
983            case '-'  % case 'bursts'
984                j1=str2num(r.num1)*ones(size(ref_i));
985                j2=str2num(r.num2)*ones(size(ref_i));
986        end
987    end
988    TimeTable{iview,2}=[];
989    TimeTable{iview,3}=[];
990    if size(SeriesData.Time{iview},1)>=i2(2)&&size(SeriesData.Time{iview},1)>=j2(2)
991        if isempty(ref_j)
992            time_first=(SeriesData.Time{iview}(i1(1))+SeriesData.Time{iview}(i2(1)))/2;
993            time_last=(SeriesData.Time{iview}(i1(2))+SeriesData.Time{iview}(i2(2)))/2;
994        else
995            time_first=(SeriesData.Time{iview}(i1(1),j1(1))+SeriesData.Time{iview}(i2(1),j2(1)))/2;
996            time_last=(SeriesData.Time{iview}(i1(2),j1(2))+SeriesData.Time{iview}(i2(2),j2(2)))/2;
997        end
998        TimeTable{iview,2}=time_first; %TODO: take into account pairs
999        TimeTable{iview,3}=time_last; %TODO: take into account pairs
1000    end
1001end
1002set(handles.TimeTable,'Data',TimeTable)
1003
1004%------------------------------------------------------------------------
1005% --- Executes when selected cell(s) is changed in PairString.
1006function PairString_CellSelectionCallback(hObject, eventdata, handles)
1007%------------------------------------------------------------------------   
1008set(handles.ListView,'Value',eventdata.Indices(1))% detect the selected raw index
1009ListView_Callback ([],[],handles) % update the list of available pairs
1010
1011%------------------------------------------------------------------------
1012%------------------------------------------------------------------------
1013%  III - FUNCTIONS ASSOCIATED TO THE FRAME SET PAIRS
1014%------------------------------------------------------------------------
1015%------------------------------------------------------------------------
1016% --- Executes on selection change in ListView.
1017function ListView_Callback(hObject, eventdata, handles)
1018%------------------------------------------------------------------------   
1019SeriesData=get(handles.series,'UserData');
1020i2_series=[];
1021j2_series=[];
1022iview=get(handles.ListView,'Value');
1023if ~isempty(SeriesData.i2_series{iview})
1024    i2_series=SeriesData.i2_series{iview};
1025end
1026if ~isempty(SeriesData.j2_series{iview})
1027    j2_series=SeriesData.j2_series{iview};
1028end
1029update_mode(handles,SeriesData.i1_series{iview},SeriesData.i2_series{iview},...
1030    SeriesData.j1_series{iview},SeriesData.j2_series{iview},SeriesData.Time{iview})
1031
1032%------------------------------------------------------------------------
1033% --- Executes on button press in mode.
1034function mode_Callback(hObject, eventdata, handles)
1035%------------------------------------------------------------------------       
1036SeriesData=get(handles.series,'UserData');
1037iview=get(handles.ListView,'Value');
1038mode_list=get(handles.mode,'String');
1039mode=mode_list{get(handles.mode,'Value')};
1040if isequal(mode,'bursts')
1041    enable_i(handles,'On')
1042    enable_j(handles,'Off') %do not display j index scanning in burst mode (j is fixed by the burst choice)
1043else
1044    enable_i(handles,'On')
1045    enable_j(handles,'Off')
1046end
1047fill_ListPair(handles,SeriesData.i1_series{iview},SeriesData.i2_series{iview},...
1048    SeriesData.j1_series{iview},SeriesData.j2_series{iview},SeriesData.Time{iview})
1049ListPairs_Callback([],[],handles)
1050
1051%-------------------------------------------------------------
1052% --- Executes on selection in ListPairs.
1053function ListPairs_Callback(hObject,eventdata,handles)
1054%------------------------------------------------------------
1055list_pair=get(handles.ListPairs,'String');%get the menu of image pairs
1056if isempty(list_pair)
1057    string='';
1058else
1059    string=list_pair{get(handles.ListPairs,'Value')};
1060    string=regexprep(string,',.*','');%removes time indication (after ',')
1061end
1062PairString=get(handles.PairString,'Data');
1063iview=get(handles.ListView,'Value');
1064PairString{iview,1}=string;
1065% report the selected pair string to the table PairString
1066set(handles.PairString,'Data',PairString)
1067
1068%------------------------------------------------------------------------
1069function num_ref_i_Callback(hObject, eventdata, handles)
1070%------------------------------------------------------------------------
1071mode_list=get(handles.mode,'String');
1072mode=mode_list{get(handles.mode,'Value')};
1073SeriesData=get(handles.series,'UserData');
1074iview=get(handles.ListView,'Value');
1075fill_ListPair(handles,SeriesData.i1_series{iview},SeriesData.i2_series{iview},...
1076    SeriesData.j1_series{iview},SeriesData.j2_series{iview},SeriesData.Time{iview});% update the menu of pairs depending on the available netcdf files
1077ListPairs_Callback([],[],handles)
1078
1079%------------------------------------------------------------------------
1080function num_ref_j_Callback(hObject, eventdata, handles)
1081%------------------------------------------------------------------------
1082num_ref_i_Callback(hObject, eventdata, handles)
1083
1084%------------------------------------------------------------------------
1085function update_mode(handles,i1_series,i2_series,j1_series,j2_series,time)
1086%------------------------------------------------------------------------   
1087check_burst=0;
1088if isempty(j2_series)% no pair menu to display
1089    if isempty(i2_series)
1090        set(handles.mode,'String',{''})
1091    else
1092        set(handles.mode,'Value',1)
1093        set(handles.mode,'String',{'series(Di)'})
1094    end
1095else
1096    nbfield=size(j2_series,1);
1097    nbfield2=size(j2_series,2);
1098    set(handles.mode,'String',{'bursts';'series(Dj)'})
1099    if nbfield2>10 || nbfield==1
1100        set(handles.mode,'Value',2);%set mode to series(Dj) if more than 10 j values
1101    else
1102        set(handles.mode,'Value',1);
1103        check_burst=1;
1104    end
1105end
1106if check_burst
1107    enable_i(handles,'On')
1108    enable_j(handles,'Off') %do not display j index scanning in burst mode (j is fixed by the burst choice)
1109else
1110    enable_i(handles,'On')
1111    enable_j(handles,'On')
1112end
1113fill_ListPair(handles,i1_series,i2_series,j1_series,j2_series,time)
1114ListPairs_Callback([],[],handles)
1115
1116%--------------------------------------------------------------
1117% determine the menu for civ1 pairstring depending on existing netcdf files
1118% with the reference indices num_ref_i and num_ref_j
1119%----------------------------------------------------------------
1120function fill_ListPair(handles,i1_series,i2_series,j1_series,j2_series,time)
1121
1122mode_list=get(handles.mode,'String');
1123mode=mode_list{get(handles.mode,'Value')};
1124ref_i=str2num(get(handles.num_ref_i,'String'));
1125ref_j=str2num(get(handles.num_ref_j,'String'));
1126if isempty(ref_i)
1127    ref_i=1;
1128end
1129if isempty(ref_j)
1130    ref_j=1;
1131end
1132TimeUnit=get(handles.TimeUnit,'String');
1133if length(TimeUnit)>=1
1134    dtunit=['m' TimeUnit];
1135else
1136    dtunit='e-03';
1137end
1138
1139displ_pair={};
1140if strcmp(mode,'series(Di)')
1141    if isempty(i2_series)
1142        msgbox_uvmat('ERROR','no i1-i2 pair available')
1143        return
1144    end
1145    diff_i=i2_series-i1_series;
1146    min_diff=min(diff_i(diff_i>0));
1147    max_diff=max(diff_i(diff_i>0));
1148    for ipair=min_diff:max_diff
1149        if numel(diff_i(diff_i==ipair))>0
1150            pair_string=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ];
1151            if ~isempty(time)
1152                Dt=time(ref_i+ceil(ipair/2),ref_j)-time(ref_i-floor(ipair/2),ref_j);
1153                pair_string=[pair_string ', Dt=' num2str(Dt) ' ' dtunit];
1154            end
1155            displ_pair=[displ_pair;{pair_string}];
1156        end
1157    end
1158    if ~isempty(displ_pair)
1159        displ_pair=[displ_pair;{'Di=*|*'}];
1160    end
1161elseif strcmp(mode,'series(Dj)')
1162    if isempty(j2_series)
1163        msgbox_uvmat('ERROR','no j1-j2 pair available')
1164        return
1165    end
1166    diff_j=j2_series-j1_series;
1167    min_diff=min(diff_j(diff_j>0));
1168    max_diff=max(diff_j(diff_j>0));
1169    for ipair=min_diff:max_diff
1170        if numel(diff_j(diff_j==ipair))>0
1171            pair_string=['Dj= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ];
1172            if ~isempty(time)
1173                Dt=time(ref_i,ref_j+ceil(ipair/2))-time(ref_i,ref_j-floor(ipair/2));
1174                pair_string=[pair_string ', Dt=' num2str(Dt) ' ' dtunit];
1175            end
1176            displ_pair=[displ_pair;{pair_string}];
1177        end
1178    end
1179    if ~isempty(displ_pair)
1180        displ_pair=[displ_pair;{'Dj=*|*'}];
1181    end
1182elseif strcmp(mode,'bursts')
1183    if isempty(j2_series)
1184        msgbox_uvmat('ERROR','no j1-j2 pair available')
1185        return
1186    end
1187    diff_j=j2_series-j1_series;
1188    min_j1=min(j1_series(j1_series>0));
1189    max_j1=max(j1_series(j1_series>0));
1190    min_j2=min(j2_series(j2_series>0));
1191    max_j2=max(j2_series(j2_series>0));
1192    for pair1=min_j1:min(max_j1,min_j1+20)
1193        for pair2=min_j2:min(max_j2,min_j2+20)
1194        if numel(j1_series(j1_series==pair1))>0 && numel(j2_series(j2_series==pair2))>0
1195            displ_pair=[displ_pair;{['j= ' num2str(pair1) '-' num2str(pair2)]}];
1196        end
1197        end
1198    end
1199    if ~isempty(displ_pair)
1200        displ_pair=[displ_pair;{'j=*-*'}];
1201    end
1202end
1203
1204%% display list of pairstring
1205displ_pair_list=get(handles.ListPairs,'String');
1206NewVal=[];
1207if ~isempty(displ_pair_list)
1208Val=get(handles.ListPairs,'Value');
1209NewVal=find(strcmp(displ_pair_list{Val},displ_pair),1);% look at the previous display in the new menu displ_pï¿œir
1210end
1211if ~isempty(NewVal)
1212    set(handles.ListPairs,'Value',NewVal)
1213else
1214    set(handles.ListPairs,'Value',1)
1215end
1216set(handles.ListPairs,'String',displ_pair)
1217
1218%-------------------------------------
1219function enable_i(handles,state)
1220set(handles.i_txt,'Visible',state)
1221set(handles.num_first_i,'Visible',state)
1222set(handles.num_last_i,'Visible',state)
1223set(handles.num_incr_i,'Visible',state)
1224% set(handles.num_MaxIndex_i,'Visible',state)
1225set(handles.num_ref_i,'Visible',state)
1226set(handles.ref_i_text,'Visible',state)
1227
1228%-----------------------------------
1229function enable_j(handles,state)
1230set(handles.j_txt,'Visible',state)
1231% set(handles.num_MinIndex_j,'Visible',state)
1232set(handles.num_first_j,'Visible',state)
1233set(handles.num_last_j,'Visible',state)
1234set(handles.num_incr_j,'Visible',state)
1235% set(handles.num_MaxIndex_j,'Visible',state)
1236set(handles.num_ref_j,'Visible',state)
1237set(handles.ref_j_text,'Visible',state)
1238
1239%-----------------------------------
1240function view_FieldMenu(handles,state)
1241% set(handles.FieldName,'Visible',state)
1242% set(handles.Field_text,'Visible',state)
1243set(handles.InputFields,'Visible',state)
1244
1245%-----------------------------------
1246function view_FieldMenu_1(handles,state)
1247set(handles.FieldName_1,'Visible',state)
1248set(handles.Field_text_1,'Visible',state)
1249
1250
1251%%%%%%%%%%%%%%%%%%%%
1252%%  MAIN ActionName FUNCTIONS
1253%%%%%%%%%%%%%%%%%%%%
1254%------------------------------------------------------------------------
1255% --- Executes on button press in RUN.
1256function RUN_Callback(hObject, eventdata, handles)
1257%------------------------------------------------------------------------
1258set(handles.RUN,'BusyAction','queue');
1259set(0,'CurrentFigure',handles.series)
1260set(handles.RUN, 'Enable','Off')
1261set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784])
1262[h_fun,Series,errormsg]=prepare_jobs(handles);
1263if ~isempty(errormsg)
1264    msgbox_uvmat('ERROR',errormsg)
1265else
1266    h_fun(Series);
1267end
1268set(handles.RUN, 'Enable','On')
1269set(handles.RUN,'BackgroundColor',[1 0 0])
1270
1271%------------------------------------------------------------------------
1272function STOP_Callback(hObject, eventdata, handles)
1273%------------------------------------------------------------------------
1274set(handles.RUN, 'BusyAction','cancel')
1275set(handles.RUN,'BackgroundColor',[1 0 0])
1276set(handles.RUN,'enable','on')
1277
1278%------------------------------------------------------------------------
1279% --- Executes on button press in BATCH.
1280function BATCH_Callback(hObject, eventdata, handles)
1281%------------------------------------------------------------------------   
1282set(handles.BATCH, 'Enable','Off')
1283set(handles.BATCH,'BackgroundColor',[0.831 0.816 0.784])
1284[h_fun,errormsg]=prepare_jobs(handles);
1285set(handles.BATCH, 'Enable','On')
1286set(handles.BATCH,'BackgroundColor',[1 0 0])
1287path_civ=fileparts(which('civ'));
1288filename_bat=[OutputFile '.bat'];
1289[fid,message]=fopen(filename_bat,'w');
1290if isequal(fid,-1)
1291    errormsg= ['creation of .bat file: ' message];
1292    return
1293end
1294text_matlabscript=[...
1295    '#!/bin/bash \n'...
1296    '. /etc/sysprofile \n'...
1297    'matlab -nodisplay -nosplash -nojvm <<END_MATLAB \n'...
1298    'cd(''' path_civ '''); \n'...
1299    'civ_matlab(''' filename_xml ''',''' OutputFile '.nc''); \n'...
1300    'exit \n'...
1301    'END_MATLAB \n'];
1302fprintf(fid,text_matlabscript);
1303fclose(fid);
1304if isunix
1305    system(['chmod +x ' filename_bat]);
1306end
1307
1308%------------------------------------------------------------------------
1309% --- Executes on button press in BIN.
1310function BIN_Callback(hObject, eventdata, handles)
1311%------------------------------------------------------------------------
1312    cmd=['#!/bin/bash \n '...
1313        '#$ -cwd \n '...
1314        'hostname && date \n '...
1315        'umask 002 \n'...
1316        Param.xml.CivmBin ' ' Param.xml.RunTime ' ' filename_xml ' ' OutputFile '.nc'];
1317   
1318%------------------------------------------------------------------------
1319% --- Main lauch command, called by RUN and BATCH
1320function [h_fun,Series,errormsg]=prepare_jobs(handles)
1321%------------------------------------------------------------------------
1322errormsg='';
1323%% Read parameters from series
1324Series=read_GUI(handles.series);
1325if isfield(Series,'Pairs')
1326Series=rmfield(Series,'Pairs'); %info Pairs not needed for output
1327end
1328
1329%% read root name and field type
1330first_i=1;
1331last_i=1;
1332incr_i=1;
1333first_j=1;
1334last_j=1;
1335incr_j=1;
1336if isfield(Series.IndexRange,'first_i')
1337    first_i=Series.IndexRange.first_i;
1338    incr_i=Series.IndexRange.incr_i;
1339    last_i=Series.IndexRange.last_i;
1340end
1341if isfield(Series.IndexRange,'first_j')
1342    first_j=Series.IndexRange.first_j;
1343    incr_j=Series.IndexRange.incr_j;
1344    last_j=Series.IndexRange.last_j;
1345end
1346
1347%% read input file parameters and set menus
1348menu_coord_state=get(handles.TransformName,'Visible');
1349if isequal(menu_coord_state,'on')
1350    menu_index=get(handles.TransformName,'Value');
1351    transform_list=get(handles.TransformName,'UserData');
1352    Series.FieldTransform.TransformHandle=transform_list{menu_index};% transform function handles
1353end
1354
1355if last_i < first_i | last_j < first_j , msgbox_uvmat('ERROR','last field number must be larger than the first one'),...
1356    set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
1357
1358%% projection object
1359if isfield(Series,'CheckObject')
1360    if Series.CheckObject
1361        hset_object=findobj(allchild(0),'tag','set_object');
1362        Series.ProjObject=read_GUI(hset_object);
1363        GetObject_Callback([], [], handles)
1364    end
1365else
1366    Series.CheckObject=0;
1367end
1368
1369%% get_field GUI
1370if isfield(Series,'InputFields')&&isfield(Series.InputFields,'Field')
1371    if strcmp(Series.InputFields.Field,'get_field...')
1372        hget_field=findobj(allchild(0),'name','get_field');
1373        Series.GetField=read_GUI(hget_field);
1374    end
1375end
1376
1377%% defining the ActionName function handle
1378list_action=get(handles.ActionName,'String');% list menu action
1379index=get(handles.ActionName,'Value');
1380action= list_action{index}; % selected string
1381Series.Action=action;%name of the processing programme
1382Series.hseries=handles.series; % handles to the series GUI
1383path_series=which('series');
1384list_path=get(handles.ActionName,'UserData');
1385fct_path=list_path{index}; %path stored for the function ACTION
1386if ~isequal(fct_path,path_series)
1387    eval(['spath=which(''' action ''');']) %spath = current path of the selected function ACTION
1388    if ~exist(fct_path,'dir')
1389        errormsg=['The prescibed function path ' fct_path ' does not exist'];
1390        return
1391    end
1392    if ~isequal(spath,fct_path)
1393        addpath(fct_path)% add the prescribed path if not the current one
1394    end
1395end
1396eval(['h_fun=@' action ';'])%create a function handle for ACTION
1397if ~isequal(fct_path,path_series)
1398        rmpath(fct_path)% add the prescribed path if not the current one   
1399end
1400
1401%% create the output data directory and write in it the xml file from the GUI config
1402%determine the root file corresponding to the first sub dir
1403if isfield(Series,'OutputSubDir')
1404    SubDirOut=[Series.OutputSubDir Series.OutputDirExt];
1405    SubDirOutNew=SubDirOut;
1406    iview=1;
1407    SeriesData=get(handles.series,'UserData');
1408    if size(Series.InputTable,1)>1 && isfield(SeriesData,'AllowInputSort') && isfield(SeriesData.AllowInputSort)
1409        [tild,iview]=sort(Series.InputTable(:,2)); %subdirectories sorted in alphabetical order
1410        Series.InputTable=Series.InputTable(iview,:);
1411    end
1412    detect=exist(fullfile(Series.InputTable{1,1},SubDirOutNew),'file')==2;% test if  the dir  already exist
1413    while detect
1414        r=regexp(SubDirOut,'(?<root>.*\D)(?<num1>\d+)$','names');%detect whether name ends by a number
1415        if isempty(r)
1416            r(1).root=[SubDirOut '_'];
1417            r(1).num1='0';
1418        end
1419        SubDirOutNew=[r(1).root num2str(str2num(r(1).num1)+1)];%increment the index by 1 or put 1
1420        detect=exist(fullfile(Series.InputTable{1,1},SubDirOutNew),'file')==2;% test if  the dir  already exists
1421    end
1422    Series.OutputSubDir=SubDirOutNew;
1423    Series.OutputDir=fullfile(Series.InputTable{1,1},Series.OutputSubDir);%directory set for output results
1424    Series.OutputRootFile=Series.InputTable{1,3};% the first sorted RootFile taken for output
1425    Series=rmfield(Series,'OutputDirExt');%removes redondant information
1426    % create output directory
1427    answer='No';
1428    if exist(Series.OutputDir,'dir')
1429        answer=msgbox_uvmat('INPUT_Y-N',['use existing ouput directory: ' Series.OutputDir ', possibly delete previous data']);
1430    end
1431    if ~isequal(answer,'Yes')
1432        [tild,msg1]=mkdir(Series.OutputDir);
1433        if ~strcmp(msg1,'')
1434            errormsg=['cannot create ' Series.OutputDir ': ' msg1];%error message for directory creation
1435            return
1436        end
1437    end
1438    filexml=fullfile(Series.OutputDir,[Series.InputTable{1,3} '.xml']);% name of the parameter xml file set in this directory
1439    t=struct2xml(Series);
1440    save(t,filexml);
1441end
1442
1443%------------------------------------------------------------------------
1444% --- Executes on selection change in ActionName.
1445function ActionName_Callback(hObject, eventdata, handles)
1446%------------------------------------------------------------------------
1447global nb_builtin_ACTION
1448list_ACTION=get(handles.ActionName,'String');% list menu fields
1449index_ACTION=get(handles.ActionName,'Value');% selected string index
1450ACTION= list_ACTION{index_ACTION}; % selected function name
1451path_series=which('series');%path to series.m
1452list_path=get(handles.ActionName,'UserData');%list of recorded paths to functions of the list ACTION
1453default_file=fullfile(list_path{end},ACTION);
1454% add a new function to the menu if the selected item is 'more...'
1455if isequal(ACTION,'more...')
1456    pathfct=fileparts(path_series);
1457    [FileName, PathName, filterindex] = uigetfile( ...
1458       {'*.m', ' (*.m)';
1459        '*.m',  '.m files '; ...
1460        '*.*', 'All Files (*.*)'}, ...
1461        'Pick a file',default_file);
1462    if length(FileName)<2
1463        return
1464    end
1465    [pp,ACTION,ext_fct]=fileparts(FileName);%(end-1:end);
1466    if ~isequal(ext_fct,'.m')
1467        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
1468        return
1469    end
1470   
1471   % insert the choice in the actionname menu
1472   menu_str=update_menu(handles.ActionName,ACTION);%new action menu in which the new item has been appended if needed
1473   index_ACTION=get(handles.ActionName,'Value');% currently selected index in the list
1474   list_path{index_ACTION}=PathName;
1475   if length(menu_str)>nb_builtin_ACTION+5; %nb_builtin=nbre of functions always remaining in the initial menu
1476       nbremove=length(menu_str)-nb_builtin_ACTION-5;
1477       menu_str(nb_builtin_ACTION+1:end-5)=[];
1478       list_path(nb_builtin_ACTION+1:end-4)=[];
1479       index_ACTION=index_ACTION-nbremove;
1480       set(handles.ActionName,'Value',index_ACTION)
1481       set(handles.ActionName,'String',menu_str)
1482   end
1483   list_path{index_ACTION}=PathName;
1484   set(handles.ActionName,'UserData',list_path);
1485   set(handles.ActionPath,'enable','inactive')% indicate that the current path is accessible (not 'off')
1486   
1487   %record the current menu in personal file profil_perso
1488   dir_perso=prefdir;
1489   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1490   for ilist=nb_builtin_ACTION+1:length(menu_str)-1
1491       series_fct{ilist-nb_builtin_ACTION}=fullfile(list_path{ilist},[menu_str{ilist} '.m']);     
1492   end
1493   if nb_builtin_ACTION+1<=length(menu_str)-1
1494       if exist(profil_perso,'file')% && nb_builtin_ACTION+1>=length(menu_str)-1
1495           save(profil_perso,'series_fct','-append')
1496       else
1497           txt=ver('MATLAB');
1498           Release=txt.Release;
1499           relnumb=str2num(Release(3:4));
1500           if relnumb >= 14%recent relaese of Matlab
1501               save(profil_perso,'series_fct','-V6')
1502           else
1503               save(profil_perso, 'series_fct')
1504           end
1505       end
1506   end
1507end
1508
1509%check the current ActionPath to the selected function
1510PathName=list_path{index_ACTION};%current recorded path
1511set(handles.ActionPath,'String',PathName); %show the path to the senlected function
1512
1513%default setting for the visibility of the GUI elements
1514set(handles.num_NbSlice,'Visible','off')
1515set(handles.NbSlice_title,'Visible','off')
1516set(handles.VelType,'Visible','off');
1517set(handles.VelType_text,'Visible','off');
1518set(handles.VelType_1,'Visible','off');
1519set(handles.VelType_text_1,'Visible','off');
1520view_FieldMenu(handles,'off')
1521view_FieldMenu_1(handles,'off')
1522set(handles.FieldTransform,'Visible','off')
1523set(handles.CheckObject,'Visible','off');
1524set(handles.ProjObject,'Visible','off');
1525set(handles.CheckMask,'Visible','off')
1526set(handles.Mask,'Visible','off')
1527% set(handles.OutputDirExt,'Visible','off');
1528set(handles.ParamKey,'Visible','off')
1529set(handles.ParamVal,'Visible','off')
1530ParamKey={};
1531set(handles.FieldName,'Enable','off')
1532set(handles.VelType,'Enable','off')
1533set(handles.FieldName_1,'Enable','off')
1534set(handles.VelType_1,'Enable','off')
1535set(handles.TransformName,'Enable','off')
1536set(handles.OutputDirExt,'Visible','off')
1537set(handles.OutputSubDir,'Visible','off')
1538set(handles.OutputDir_title,'Visible','off')
1539%set the displayed GUI item needed for input parameters
1540if ~isequal(path_series,PathName)
1541    addpath(PathName)
1542end
1543eval(['h_function=@' ACTION ';']);
1544try
1545    [fid,errormsg] =fopen([ACTION '.m']);
1546    InputText=textscan(fid,'%s',1,'delimiter','\n');
1547    fclose(fid)
1548    set(handles.ActionName,'ToolTipString',InputText{1}{1})
1549end
1550if ~isequal(path_series,PathName)
1551    rmpath(PathName)
1552end
1553varargout=h_function();
1554Param_list={};
1555
1556InputTable=get(handles.InputTable,'Data');
1557nb_series=size(InputTable,1);
1558testima_series=1; %test for a list of images only
1559testima=1;
1560testima_1=1;
1561testciv_series=1;
1562for iview=1:nb_series
1563     ext=InputTable{iview,5};
1564    if length(ext)<2
1565        ext='.none';
1566    end
1567    testimaview=~isempty(imformats(ext(2:end))) || isequal(lower(ext),'.avi');
1568    if ~testimaview
1569        if iview==1
1570            testima=0;
1571        end
1572        if iview==2
1573            testima_1=0;
1574        end
1575        testima_series=0;
1576    end
1577end
1578for ilist=1:length(varargout)-1
1579    switch varargout{ilist}
1580        case 'NbViewMax'
1581            if ~isempty (varargout{ilist+1})
1582                if size(InputTable,1)>varargout{ilist+1}
1583                InputTable=InputTable(1:varargout{ilist+1},:);
1584                set(handles.InputTable,'Data',InputTable)
1585                end
1586            end
1587        case 'AllowInputSort'
1588            if isequal(lower(varargout{ilist+1}),'on')% sort the input table by alphabetical order of the SubDir
1589                SeriesData=get(handles.series,'UserData');
1590                SeriesData.AllowInputSort=1;
1591                set(handles.series,'UserData',SeriesData)
1592            end             
1593        case 'NbSlice'   %hidden by default
1594            if isequal(lower(varargout{ilist+1}),'on')
1595                set(handles.num_NbSlice,'Visible','on')
1596                set(handles.NbSlice_title,'Visible','on')
1597            end
1598        case 'VelType'   %hidden by default
1599             if isequal(lower(varargout{ilist+1}),'one') || isequal(lower(varargout{ilist+1}),'two')
1600                set(handles.VelType,'Enable','on')
1601                if nb_series >=1 && ~testima_series
1602                    set(handles.VelType,'Visible','on')
1603                    set(handles.VelType_text,'Visible','on');
1604                end
1605             end
1606            if isequal(lower(varargout{ilist+1}),'two')
1607                set(handles.VelType_1,'Enable','on')
1608                if nb_series >=2 && ~testima_series
1609                    set(handles.VelType_1,'Visible','on')
1610                    set(handles.VelType_text_1,'Visible','on');
1611                end
1612            end
1613        case 'FieldName'   %hidden by default
1614            if isequal(lower(varargout{ilist+1}),'one')||isequal(lower(varargout{ilist+1}),'two')
1615                set(handles.FieldName,'Enable','on') % test for MenuBorser
1616                if nb_series >=1 && ~testima_series
1617                    view_FieldMenu(handles,'on')
1618                end
1619            end
1620            if isequal(lower(varargout{ilist+1}),'two')
1621                set(handles.FieldName_1,'Enable','on')
1622                if nb_series >=2 && ~testima_1
1623                    view_FieldMenu_1(handles,'on')
1624                end
1625            end
1626        case 'FieldTransform'   %hidden by default
1627            if isequal(lower(varargout{ilist+1}),'on')
1628                set(handles.TransformName,'Enable','on')
1629                set(handles.FieldTransform,'Visible','on')
1630            end
1631        case 'ProjObject'   %hidden by default
1632            if isequal(lower(varargout{ilist+1}),'on')   
1633                set(handles.CheckObject,'Visible','on')
1634                set(handles.ProjObject,'Visible','on')
1635            end
1636        case 'Mask'   %hidden by default
1637            if isequal(lower(varargout{ilist+1}),'on')   
1638                set(handles.Mask,'Visible','on')
1639                 set(handles.CheckMask,'Visible','on');
1640            end
1641        case 'PARAMETER'  % NOT USED
1642            set(handles.PARAMETERS_frame,'Visible','on')
1643            set(handles.PARAMETERS_title,'Visible','on')
1644            set(handles.ParamKey,'Visible','on')
1645            %set(handles.ParamVal,'Visible','on')
1646            Param_str=varargout{ilist+1};
1647            Param_list=[Param_list; {Param_str}];   
1648        case 'OutputDirExt'
1649            if ~isempty(varargout{ilist+1})
1650            set(handles.OutputDirExt,'String',varargout{ilist+1})
1651            set(handles.OutputDirExt,'Visible','on')
1652            set(handles.OutputSubDir,'Visible','on')
1653            set(handles.OutputDir_title,'Visible','on') 
1654            end
1655    end
1656end
1657if ~isempty(Param_list)
1658    set(handles.ParamKey,'String',Param_list)
1659    set(handles.ParamVal,'Visible','on')
1660end
1661
1662%------------------------------------------------------------------------
1663% --- Executes on selection change in FieldName.
1664function FieldName_Callback(hObject, eventdata, handles)
1665%------------------------------------------------------------------------
1666field_str=get(handles.FieldName,'String');
1667field_index=get(handles.FieldName,'Value');
1668field=field_str{field_index(1)};
1669if isequal(field,'get_field...')   
1670     hget_field=findobj(allchild(0),'name','get_field');
1671     if ~isempty(hget_field)
1672         delete(hget_field)%delete opened versions of get_field
1673     end
1674     [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(read_GUI(handles.series));
1675     if exist(filecell{1,1},'file')
1676        get_field(filecell{1,1})
1677     end
1678elseif isequal(field,'more...')
1679    str=calc_field;
1680    [ind_answer,v] = listdlg('PromptString','Select a file:',...
1681                'SelectionMode','single',...
1682                'ListString',str);
1683       % edit the choice in the fields and actionname menu
1684     scalar=cell2mat(str(ind_answer));
1685     update_menu(handles.FieldName,scalar)
1686end
1687
1688%------------------------------------------------------------------------
1689% --- Executes on selection change in FieldName_1.
1690function FieldName_1_Callback(hObject, eventdata, handles)
1691%------------------------------------------------------------------------
1692field_str=get(handles.FieldName_1,'String');
1693field_index=get(handles.FieldName_1,'Value');
1694field=field_str{field_index};
1695if isequal(field,'get_field...')   
1696     hget_field=findobj(allchild(0),'name','get_field_1');
1697     if ~isempty(hget_field)
1698         delete(hget_field)
1699     end
1700     SeriesData=get(handles.series,'UserData');
1701     filename=SeriesData.CurrentInputFile_1;
1702     if exist(filename,'file')
1703        hget_field=get_field(filename);
1704        set(hget_field,'name','get_field_1')
1705     end
1706elseif isequal(field,'more...')
1707    str=calc_field;
1708    [ind_answer,v] = listdlg('PromptString','Select a file:',...
1709                'SelectionMode','single',...
1710                'ListString',str);
1711       % edit the choice in the fields and actionname menu
1712     scalar=cell2mat(str(ind_answer));
1713     update_menu(handles.FieldName_1,scalar)
1714end   
1715
1716
1717%%%%%%%%%%%%%
1718function [ind_remove]=find_pairs(dirpair,ind_i,last_i)
1719indsel=ind_i;
1720indiff=diff(ind_i); %test index increment to detect multiplets (several pairs with the same index ind_i) and holes in the series
1721indiff=[1 indiff last_i-ind_i(end)+1];%for testing gaps with the imposed bounds
1722if ~isempty(indiff)
1723    indiff2=diff(indiff);
1724    indiffp=[indiff2 1];
1725    indiffm=[1 indiff2];
1726    ind_multi_m=find((indiff==0)&(indiffm<0))-1;%indices of first members of multiplets
1727    ind_multi_p=find((indiff==0)&(indiffp>0));%indices of last members of multiplets
1728    %for each multiplet, select the most recent file
1729    ind_remove=[];
1730    for i=1:length(ind_multi_m)
1731        ind_pairs=ind_multi_m(i):ind_multi_p(i);
1732        for imulti=1:length(ind_pairs)
1733            datepair(imulti)=datenum(dirpair(ind_pairs(imulti)).date);%dates of creation
1734        end
1735        [datenew,indsort2]=sort(datepair); %sort the multiplet by creation date
1736        ind_s=indsort2(1:end-1);%
1737        ind_remove=[ind_remove ind_pairs(ind_s)];%remove these indices, leave the last one
1738    end
1739end
1740
1741%------------------------------------------------------------------------
1742% --- determine the list of index pairstring of processing file
1743function [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)
1744%------------------------------------------------------------------------
1745num_i1=num_i;% set of first image numbers by default
1746num_i2=num_i;
1747num_j1=num_j;
1748num_j2=num_j;
1749num_i_out=num_i;
1750num_j_out=num_j;
1751% if isequal (NomType,'_1-2_1') || isequal (NomType,'_1-2')
1752if isequal(mode,'series(Di)')
1753    num_i1_line=num_i+ind_shift(3);% set of first image numbers
1754    num_i2_line=num_i+ind_shift(4);
1755    % adjust the first and last field number
1756        indsel=find(num_i1_line >= 1);
1757    num_i_out=num_i(indsel);
1758    num_i1_line=num_i1_line(indsel);
1759    num_i2_line=num_i2_line(indsel);
1760    num_j1=meshgrid(num_j,ones(size(num_i1_line)));
1761    num_j2=meshgrid(num_j,ones(size(num_i1_line)));
1762    [xx,num_i1]=meshgrid(num_j,num_i1_line);
1763    [xx,num_i2]=meshgrid(num_j,num_i2_line);
1764elseif isequal (mode,'series(Dj)')||isequal (mode,'bursts')
1765    if isequal(mode,'bursts') %case of bursts (png_old or png_2D)
1766        num_j1=ind_shift(1)*ones(size(num_i));
1767        num_j2=ind_shift(2)*ones(size(num_i));
1768    else
1769        num_j1_col=num_j+ind_shift(1);% set of first image numbers
1770        num_j2_col=num_j+ind_shift(2);
1771        % adjust the first field number
1772        indsel=find((num_j1_col >= 1));   
1773        num_j_out=num_j(indsel);
1774        num_j1_col=num_j1_col(indsel);
1775        num_j2_col=num_j2_col(indsel);
1776        [num_i1,num_j1]=meshgrid(num_i,num_j1_col);
1777        [num_i2,num_j2]=meshgrid(num_i,num_j2_col);
1778    end   
1779end
1780
1781%------------------------------------------------------------------------
1782% --- Executes on button press in CheckObject.
1783function CheckObject_Callback(hObject, eventdata, handles)
1784%------------------------------------------------------------------------
1785% SeriesData=get(handles.series,'UserData');
1786value=get(handles.CheckObject,'Value');
1787if value
1788     set(handles.CheckObject,'BackgroundColor',[1 1 0])%put unactivated buttons to yellow
1789     hset_object=findobj(allchild(0),'tag','set_object');%find the set_object interface handle
1790     if ishandle(hset_object)
1791         uistack(hset_object,'top')% show the GUI set_object if opened
1792     else
1793         %get the object file
1794         InputTable=get(handles.InputTable,'Data');
1795         defaultname=InputTable{1,1};
1796         if isempty(defaultname)
1797            defaultname={''};
1798         end
1799        [FileName, PathName, filterindex] = uigetfile( ...
1800       {'*.xml;*.mat', ' (*.xml,*.mat)';
1801       '*.xml',  '.xml files '; ...
1802        '*.mat',  '.mat matlab files '}, ...
1803        'Pick an xml object file (or use uvmat to create it)',defaultname);
1804        fileinput=[PathName FileName];%complete file name
1805        sizf=size(fileinput);
1806        if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
1807        %read the file
1808        data=xml2struct(fileinput);
1809        if ~isfield(data,'Type')
1810             msgbox_uvmat('ERROR',[fileinput ' is not an object xml file'])
1811             return
1812        end
1813        if ~isfield(data,'ProjMode')
1814             data.ProjMode='none';
1815        end
1816        hset_object=set_object(data);% call the set_object interface
1817     end
1818     Object=read_GUI(hset_object);
1819     set(handles.ProjObject,'String',Object.Name);%display the object name
1820else
1821    set(handles.CheckObject,'BackgroundColor',[0.7 0.7 0.7])%put activated buttons to green
1822end
1823%set(handles.series,'UserData',SeriesData)
1824
1825%--------------------------------------------------------------
1826function CheckMask_Callback(hObject, eventdata, handles)
1827value=get(handles.CheckMask,'Value');
1828if value
1829    msgbox_uvmat('ERROR','not implemented yet')
1830end
1831%--------------------------------------------------------------
1832
1833%-------------------------------------------------------------------
1834%'uv_ncbrowser': interactively calls the netcdf file browser 'get_field.m'
1835function ncbrowser_uvmat(hObject, eventdata)
1836%-------------------------------------------------------------------
1837     bla=get(gcbo,'String');
1838     ind=get(gcbo,'Value');
1839     filename=cell2mat(bla(ind));
1840      blank=find(filename==' ');
1841      filename=filename(1:blank-1);
1842     get_field(filename)
1843
1844% ------------------------------------------------------------------
1845function MenuHelp_Callback(hObject, eventdata, handles)
1846%-------------------------------------------------------------------
1847path_to_uvmat=which ('uvmat');% check the path of uvmat
1848pathelp=fileparts(path_to_uvmat);
1849helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
1850if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
1851else
1852    addpath (fullfile(pathelp,'uvmat_doc'))
1853    web([helpfile '#series'])
1854end
1855
1856%-------------------------------------------------------------------
1857% --- Executes on selection change in TransformName.
1858function TransformName_Callback(hObject, eventdata, handles)
1859%-------------------------------------------------------------------
1860global nb_transform
1861
1862menu=get(handles.TransformName,'String');
1863ind_coord=get(handles.TransformName,'Value');
1864coord_option=menu{ind_coord};
1865list_transform=get(handles.TransformName,'UserData');
1866ff=functions(list_transform{end});
1867if isequal(coord_option,'more...');
1868    coord_fct='';
1869    prompt = {'Enter the name of the transform function'};
1870    dlg_title = 'user defined transform';
1871    num_lines= 1;
1872    [FileName, PathName, filterindex] = uigetfile( ...
1873       {'*.m', ' (*.m)';
1874        '*.m',  '.m files '; ...
1875        '*.*', 'All Files (*.*)'}, ...
1876        'Pick a file', ff.file);
1877    if isequal(PathName(end),'/')||isequal(PathName(end),'\')
1878        PathName(end)=[];
1879    end
1880    transform_selected =fullfile(PathName,FileName);
1881    if ~exist(transform_selected,'file')
1882          return
1883    end
1884    [ppp,transform,xt_fct]=fileparts(FileName);% removes extension .m
1885    if ~isequal(ext_fct,'.m')
1886        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
1887        return
1888    end
1889   menu=update_menu(handles.TransformName,transform);%add the selected fct to the menu
1890   ind_coord=get(handles.TransformName,'Value');
1891   addpath(PathName)
1892   list_transform{ind_coord}=str2func(transform);% create the function handle corresponding to the newly seleced function
1893   set(handles.TransformName,'UserData',list_transform)
1894   rmpath(PathName)
1895   % save the new menu in the personal file 'uvmat_perso.mat'
1896   dir_perso=prefdir;%personal Matalb directory
1897   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1898   if exist(profil_perso,'file')
1899       for ilist=nb_transform+1:numel(list_transform)
1900           ff=functions(list_transform{ilist});
1901           transform_fct{ilist-nb_transform}=ff.file;
1902       end
1903        save (profil_perso,'transform_fct','-append'); %store the root name for future opening of uvmat
1904   end
1905end
1906
1907%check the current ActionPath to the selected function
1908if ~isempty(list_transform{ind_coord})
1909func=functions(list_transform{ind_coord});
1910set(handles.TransformPath,'String',fileparts(func.file)); %show the path to the senlected function
1911else
1912   set(handles.TransformPath,'String',''); %show the path to the senlected function
1913end
1914
1915% %------------------------------------------------------------------------
1916% % --- Executes on button press in REFRESH_INDICES.
1917%     function REFRESH_INDICES_Callback(hObject, eventdata, handles)
1918% %------------------------------------------------------------------------       
1919% % hObject    handle to REFRESH_INDICES (see GCBO)
1920% % eventdata  reserved - to be defined in a future version of MATLAB
1921% % handles    structure with handles and user data (see GUIDATA)
1922% set(handles.REFRESH_INDICES,'BackgroundColor',[0.7 0.7 0.7])
1923% InputTable=get(handles.InputTable,'Data');
1924% check_lines=get(handles.REFRESH_INDICES,'UserData');
1925%
1926% %% check the indices and FileTypes for each series (limited to the new ones to save time)
1927% for ind_list=1:length(check_lines)
1928%     if  check_lines(ind_list)
1929%         InputLine=InputTable(ind_list,:);
1930%         detect_idem=strcmp('"',InputLine);% look for '" (repeat of previous data)
1931%         detect_idem=detect_idem(detect_idem>0);
1932%         if ~isempty (detect_idem)
1933%             InputLine(detect_idem)=InputTable(ind_list-1,detect_idem);
1934%             set(handles.InputTable,'Data',InputTable)
1935%         end
1936%         fileinput=fullfile_uvmat(InputLine{1},InputLine{2},InputLine{3},InputLine{5},InputLine{4},1,2,1,2);
1937%         %fileinput=name_generator(fullfile(InputLine{1},InputLine{3}),1,1,InputLine{5},InputLine{4},1,2,2,InputLine{2})
1938%         %update file series defined by the selected line
1939%         [InputTable{ind_list,3},InputTable{(ind_list),4},errormsg]=update_indices(handles,fileinput,ind_list);
1940%         if ~isempty(errormsg)
1941%                 msgbox_uvmat('ERROR',errormsg)
1942%                 return
1943%         end
1944%     end
1945% end
1946% set(handles.InputTable,'Data',InputTable)
1947% SeriesData=get(handles.series,'UserData');
1948%
1949% state_j='off';
1950% state_Pairs='off';
1951% state_InputFields='off';
1952% val=get(handles.ListView,'Value');
1953% ListViewString={''};
1954% if ~isempty(SeriesData)
1955% %     ListViewString={};
1956%     for iview=1:size(InputTable,1)
1957%         if ~isempty(SeriesData.j1_series{iview})
1958%             state_j='on';
1959%         end
1960%         if ~isempty(SeriesData.i2_series{iview})||~isempty(SeriesData.j2_series{iview})
1961%             state_Pairs='on';
1962%             ListViewString{iview}=num2str(iview);
1963%             if check_lines(iview)
1964%                 val=iview;%select the last pair if it is a new entry
1965%             end
1966%         end
1967%         if strcmp(SeriesData.FileType{iview},'civx')||strcmp(SeriesData.FileType{iview},'civdata')
1968%             state_InputFields='on';
1969%         end
1970%     end
1971% end
1972% set(handles.ListView,'Value',val)
1973% set(handles.ListView,'String',ListViewString)
1974% if strcmp(state_Pairs,'on')
1975%     ListView_Callback(hObject,eventdata,handles)
1976% end
1977% set(handles.PairString,'Visible',state_Pairs)
1978% enable_j(handles,state_j)
1979% set(handles.REFRESH_INDICES,'BackgroundColor',[1 0 0])
1980% set(handles.REFRESH_INDICES,'visible','off')
1981
1982% -----------------------------------------------------------------------
1983% --- Update min and max indices of a file series by scanning with find_file_series
1984% --- which also changes the root file and NomType in case of movie. Also adjust the string representation of indices (e.g;
1985% --- 1 or 001 by the function find_file_series
1986% --- This function also dispaly the set of availbale files in the series
1987% --- and the menus appropriate to the file type as well as timing possibly set
1988% --- by an xml image documentation file
1989function [RootFile,NomType,errormsg]=update_indices(handles,fileinput,iview)
1990% -----------------------------------------------------------------------
1991%% look for min and max indices existing in the file series and update SeriesData
1992errormsg='';
1993[FilePath,FileName,FileExt]=fileparts(fileinput);
1994% detect the file type, get the movie object if relevant, and look for the corresponding file series:
1995% the root name and indices may be corrected by including the first index i1 if a corresponding xml file exists
1996[RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,NomType,FileType,Object,i1,i2,j1,j2]=find_file_series(FilePath,[FileName FileExt]);
1997if isempty(RootFile)&&isempty(i1_series)
1998    errormsg='no input file in the series';
1999    return
2000end
2001
2002%% adjust the min and max indices common to all the file series
2003MinIndex=get(handles.MinIndex,'Data');
2004MaxIndex=get(handles.MaxIndex,'Data');
2005MinIndex_i=min(i1_series(i1_series>0));
2006if ~isempty(i2_series)
2007    MaxIndex_i=max(i2_series(i2_series>0));
2008else
2009    MaxIndex_i=max(i1_series(i1_series>0));
2010end
2011MinIndex_j=min(j1_series(j1_series>0));
2012if ~isempty(j2_series)
2013    MaxIndex_j=max(j2_series(j2_series>0));
2014else
2015    MaxIndex_j=max(j1_series(j1_series>0));
2016end
2017MinIndex{iview,1}=MinIndex_i;
2018MinIndex{iview,2}=MinIndex_j;
2019MaxIndex{iview,1}=MaxIndex_i;
2020MaxIndex{iview,2}=MaxIndex_j;
2021set(handles.MinIndex,'Data',MinIndex)
2022set(handles.MaxIndex,'Data',MaxIndex)
2023SeriesData=get(handles.series,'UserData');
2024SeriesData.i1_series{iview}=i1_series;
2025SeriesData.i2_series{iview}=i2_series;
2026SeriesData.j1_series{iview}=j1_series;
2027SeriesData.j2_series{iview}=j2_series;
2028SeriesData.FileType{iview}=FileType;
2029
2030%% display the set of existing files as an image
2031set(handles.waitbar_frame,'Units','pixels')
2032pos=get(handles.waitbar_frame,'Position');
2033xima=0.5:pos(3)-0.5;% pixel positions on the image representing the existing file indices
2034yima=0.5:pos(4)-0.5;
2035[XIma,YIma]=meshgrid(xima,yima);
2036nb_i=size(i1_series,1);
2037nb_j=size(i1_series,2);
2038ind_i=(0.5:nb_i-0.5)*pos(3)/nb_i;
2039ind_j=(0.5:nb_j-0.5)*pos(4)/nb_j;
2040[Ind_i,Ind_j]=meshgrid(ind_i,ind_j);
2041CData=zeros([size(XIma) 3]);
2042file_ima=double((i1_series(:,:,1)>0)');
2043if numel(file_ima)>=2
2044if size(file_ima,1)==1
2045    CLine=interp1(ind_i,file_ima,xima,'nearest');
2046    CData(:,:,2)=ones(size(yima'))*CLine;
2047else
2048    CData(:,:,2)=interp2(Ind_i,Ind_j,file_ima,XIma,YIma,'nearest');
2049end
2050set(handles.waitbar_frame,'CData',CData)
2051end
2052set(handles.waitbar_frame,'Units','normalized')
2053
2054%% enable field and veltype menus
2055testfield=isequal(get(handles.FieldName,'enable'),'on');
2056testfield_1=isequal(get(handles.FieldName_1,'enable'),'on');
2057testveltype=isequal(get(handles.VelType,'enable'),'on');
2058testveltype_1=isequal(get(handles.VelType_1,'enable'),'on');
2059testtransform=isequal(get(handles.TransformName,'Enable'),'on');
2060% testnc=0;
2061% testnc_1=0;
2062% testcivx=0;
2063% testcivx_1=0;
2064% testima=0; %test for image input
2065% if isequal(lower(FileExt),'.avi') %.avi file
2066%     testima=1;
2067% elseif ~isempty(imformats(FileExt(2:end)))
2068%     testima=1;
2069% elseif isequal(FileExt,'.vol')
2070%      testima=1;
2071% end
2072%TODO: update
2073% if length(FileExtCell)==1 || length(FileExtCell)>2
2074%     for iview=1:length(FileExtCell)
2075%         if isequal(FileExtCell{iview},'.nc')
2076%             testnc=1;
2077%         end
2078%         if isequal(FileTypeCell{iview},'civx')
2079%             testcivx=1;
2080%         end
2081%     end
2082% elseif length(FileExtCell)==2
2083%     testnc=isequal(FileExtCell{1},'.nc');
2084%     testnc_1=isequal(FileExtCell{2},'.nc');
2085%     testcivx=isequal(FileTypeCell{1},'civx');
2086%     testcivx_1=isequal(FileTypeCell{2},'civx');
2087% end
2088switch FileType
2089    case {'civx','civdata'}
2090    view_FieldMenu(handles,'on')
2091    menustr=get(handles.FieldName,'String');
2092    if isequal(menustr,{'get_field...'})
2093        set(handles.FieldName,'String',{'get_field...';'velocity';'vort';'div';'more...'})
2094    end
2095    set(handles.VelType,'Visible','on')
2096    set(handles.FieldTransform,'Visible','on')
2097    %      view_TRANSFORM(handles,'on')
2098    %     TODO: second menu
2099    %           view_FieldMenu_1(handles,'on')
2100    %     if testcivx_1
2101    %         menustr=get(handles.FieldName_1,'String');
2102    %         if isequal(menustr,{'get_field...'})
2103    %             set(handles.FieldName_1,'String',{'get_field...';'velocity';'vort';'div';'more...'})
2104    %         end
2105    %     else
2106    %         set(handles.FieldName_1,'Value',1)
2107    %         set(handles.FieldName_1,'String',{'get_field...'})
2108    %     set(handles.VelType_1,'Visible','on')
2109    %     set(handles.VelType_text_1,'Visible','on');
2110    %     end
2111    %     view_FieldMenu_1(handles,'off')
2112    case 'netcdf'
2113    view_FieldMenu(handles,'on')
2114    set(handles.FieldName,'Value',1)
2115    set(handles.FieldName,'String',{'get_field...'})
2116    set(handles.FieldTransform,'Visible','off')
2117    %     view_TRANSFORM(handles,'off')
2118    case {'image','multimage','video'}
2119    view_FieldMenu(handles,'off')
2120    view_FieldMenu_1(handles,'off')
2121    set(handles.VelType,'Visible','off')
2122    set(handles.VelType_text,'Visible','off');
2123end
2124
2125
2126%TODO:update
2127% if ~isequal(FileExt,'.nc') && ~isequal(FileExt,'.cdf') && ~testima
2128%     msgbox_uvmat('ERROR',['invalid input file extension ' FileExt])
2129%     return
2130% end 
2131
2132%%  read image documentation file  if found%%%%%%%%%%%%%%%%%%%%%%%%%%%
2133ext_imadoc='';
2134FileBase=fullfile(RootPath,RootFile);
2135if isequal(FileExt,'.xml')||isequal(FileExt,'.civ')
2136    ext_imadoc=FileExt;
2137elseif exist([FileBase '.xml'],'file')
2138    ext_imadoc='.xml';
2139elseif exist([FileBase '.civ'],'file')
2140    ext_imadoc='.civ';
2141end
2142%read the ImaDoc file
2143XmlData=[];
2144NbSlice_calib={};
2145if isequal(ext_imadoc,'.xml')
2146        [XmlData,warntext]=imadoc2struct([FileBase '.xml']);
2147        if isfield(XmlData,'Heading') && isfield(XmlData.Heading,'ImageName') && ischar(XmlData.Heading.ImageName)
2148            [PP,FF,ext_ima_read]=fileparts(XmlData.Heading.ImageName);
2149        end
2150        if isfield(XmlData,'Time')
2151            time{iview}=XmlData.Time;
2152        end
2153        if isfield(XmlData,'Camera')
2154            if isfield(XmlData.Camera,'NbSlice')&& ~isempty(XmlData.Camera.NbSlice)
2155                NbSlice_calib{iview}=XmlData.Camera.NbSlice;% Nbre of slices for Zindex in phys transform
2156                if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
2157                    msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
2158                end
2159            end
2160            if isfield(XmlData.Camera,'TimeUnit')&& ~isempty(XmlData.Camera.TimeUnit)
2161                TimeUnit=XmlData.Camera.TimeUnit;
2162            end
2163        end
2164        if ~isempty(warntext)
2165            msgbox_uvmat('WARNING',warntext)
2166        end 
2167elseif isequal(ext_imadoc,'.civ')
2168    [error,XmlData.Time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([FileBase '.civ']);
2169    time{iview}=XmlData.Time;
2170    if error==2, warntext=['no file ' FileBase '.civ'];
2171    elseif error==1, warntext='inconsistent number of fields in the .civ file';
2172    end 
2173end
2174
2175%% update time table
2176TimeTable=get(handles.TimeTable,'Data');
2177TimeTable{iview,1}=time(MinIndex_i,MinIndex_j);
2178TimeTable{iview,4}=time(MaxIndex_i,MaxIndex_j);
2179set(handles.TimeTable,'Data',TimeTable)
2180
2181%% number of slices
2182if isfield(XmlData,'GeometryCalib') && isfield(XmlData.GeometryCalib,'SliceCoord')
2183       siz=size(XmlData.GeometryCalib.SliceCoord);
2184       if siz(1)>1
2185           NbSlice=siz(1);
2186       else
2187           NbSlice=1;
2188       end
2189       set(handles.num_NbSlice,'String',num2str(NbSlice))
2190end
2191% set(handles.mode,'Visible','off') % do not show index pairstring by default
2192set(handles.PairString,'Visible','off')
2193% set(handles.num_ref_i,'Visible','off')
2194% set(handles.ref_i_text,'Visible','off')
2195testpair=0;
2196%set the menus of image pairstring and default selection for series
2197%list pairstring if relevant
2198% Val=get(handles.NomType,'Value');
2199% synchronise_view(handles,Val)
2200
2201% if ~isfield(SeriesData,'j1_series')||isempty(SeriesData.j1_series{index})
2202%     state_j='off'; %no need for j index
2203% else
2204%     state_j='on'; %case of j index
2205% end
2206% show index pairstring if files exist
2207set(handles.series,'UserData',SeriesData)
2208
2209
2210% --------------------------------------------------------------------
2211function MenuExportConfig_Callback(hObject, eventdata, handles)
2212global Series
2213[tild,Series,errormsg]=prepare_jobs(handles);
2214% Series=read_GUI(handles.series);
2215
2216evalin('base','global Series')%make CurData global in the workspace
2217display('current series config :')
2218evalin('base','Series') %display CurData in the workspace
2219commandwindow; %brings the Matlab command window to the front
Note: See TracBrowser for help on using the repository browser.