source: trunk/src/series.m @ 448

Last change on this file since 448 was 448, checked in by sommeria, 9 years ago

bug corrected in output dir
BATCH mode implemented: still a problem to solve for writing the content of InputTable? in the xml file

File size: 86.8 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')
1277set(handles.BATCH,'BackgroundColor',[1 0 0])
1278set(handles.BATCH,'enable','on')
1279
1280%------------------------------------------------------------------------
1281% --- Executes on button press in BATCH.
1282function BATCH_Callback(hObject, eventdata, handles)
1283%------------------------------------------------------------------------   
1284set(handles.BATCH, 'Enable','Off')
1285set(handles.BATCH,'BackgroundColor',[0.831 0.816 0.784])
1286[h_fun,Series,errormsg]=prepare_jobs(handles);
1287if ~isempty(errormsg)
1288    msgbox_uvmat('ERROR',errormsg)
1289    return
1290end
1291path_series=fileparts(which('series'));
1292filename_xml=fullfile(Series.OutputDir,[Series.OutputRootFile '.xml']);
1293filename_bat=fullfile(Series.OutputDir,[Series.OutputRootFile '.bat']);
1294[fid,message]=fopen(filename_bat,'w');
1295if isequal(fid,-1)
1296    msgbox_uvmat('ERROR', ['creation of .bat file: ' message]);
1297    return
1298end
1299text_matlabscript=[...
1300    '#!/bin/bash \n'...
1301    '. /etc/sysprofile \n'...
1302    'matlab -nodisplay -nosplash -nojvm <<END_MATLAB \n'...
1303    'cd(''' path_series '''); \n'...
1304    '' Series.Action  '( ''' filename_xml '''); \n'...
1305    'exit \n'...
1306    'END_MATLAB \n'];
1307fprintf(fid,text_matlabscript);
1308fclose(fid);
1309if isunix
1310    system(['chmod +x ' filename_bat]);
1311end
1312set(handles.BATCH, 'Enable','On')
1313set(handles.BATCH,'BackgroundColor',[1 0 0])
1314%------------------------------------------------------------------------
1315% --- Executes on button press in BIN.
1316function BIN_Callback(hObject, eventdata, handles)
1317%------------------------------------------------------------------------
1318    cmd=['#!/bin/bash \n '...
1319        '#$ -cwd \n '...
1320        'hostname && date \n '...
1321        'umask 002 \n'...
1322        Param.xml.CivmBin ' ' Param.xml.RunTime ' ' filename_xml ' ' OutputFile '.nc'];
1323   
1324%------------------------------------------------------------------------
1325% --- Main lauch command, called by RUN and BATCH
1326function [h_fun,Series,errormsg]=prepare_jobs(handles)
1327%------------------------------------------------------------------------
1328errormsg='';
1329%% Read parameters from series
1330Series=read_GUI(handles.series);
1331if isfield(Series,'Pairs')
1332Series=rmfield(Series,'Pairs'); %info Pairs not needed for output
1333end
1334
1335%% read root name and field type
1336first_i=1;
1337last_i=1;
1338incr_i=1;
1339first_j=1;
1340last_j=1;
1341incr_j=1;
1342if isfield(Series.IndexRange,'first_i')
1343    first_i=Series.IndexRange.first_i;
1344    incr_i=Series.IndexRange.incr_i;
1345    last_i=Series.IndexRange.last_i;
1346end
1347if isfield(Series.IndexRange,'first_j')
1348    first_j=Series.IndexRange.first_j;
1349    incr_j=Series.IndexRange.incr_j;
1350    last_j=Series.IndexRange.last_j;
1351end
1352
1353%% read input file parameters and set menus
1354menu_coord_state=get(handles.TransformName,'Visible');
1355if isequal(menu_coord_state,'on')
1356    menu_index=get(handles.TransformName,'Value');
1357    transform_list=get(handles.TransformName,'UserData');
1358    Series.FieldTransform.TransformHandle=transform_list{menu_index};% transform function handles
1359end
1360
1361if last_i < first_i | last_j < first_j , msgbox_uvmat('ERROR','last field number must be larger than the first one'),...
1362    set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
1363
1364%% projection object
1365if isfield(Series,'CheckObject')
1366    if Series.CheckObject
1367        hset_object=findobj(allchild(0),'tag','set_object');
1368        Series.ProjObject=read_GUI(hset_object);
1369        GetObject_Callback([], [], handles)
1370    end
1371else
1372    Series.CheckObject=0;
1373end
1374
1375%% get_field GUI
1376if isfield(Series,'InputFields')&&isfield(Series.InputFields,'Field')
1377    if strcmp(Series.InputFields.Field,'get_field...')
1378        hget_field=findobj(allchild(0),'name','get_field');
1379        Series.GetField=read_GUI(hget_field);
1380    end
1381end
1382
1383%% defining the ActionName function handle
1384list_action=get(handles.ActionName,'String');% list menu action
1385index=get(handles.ActionName,'Value');
1386action= list_action{index}; % selected string
1387Series.Action=action;%name of the processing programme
1388Series.hseries=handles.series; % handles to the series GUI
1389path_series=which('series');
1390list_path=get(handles.ActionName,'UserData');
1391fct_path=list_path{index}; %path stored for the function ACTION
1392if ~isequal(fct_path,path_series)
1393    eval(['spath=which(''' action ''');']) %spath = current path of the selected function ACTION
1394    if ~exist(fct_path,'dir')
1395        errormsg=['The prescibed function path ' fct_path ' does not exist'];
1396        return
1397    end
1398    if ~isequal(spath,fct_path)
1399        addpath(fct_path)% add the prescribed path if not the current one
1400    end
1401end
1402eval(['h_fun=@' action ';'])%create a function handle for ACTION
1403if ~isequal(fct_path,path_series)
1404        rmpath(fct_path)% add the prescribed path if not the current one   
1405end
1406
1407%% create the output data directory and write in it the xml file from the GUI config
1408%determine the root file corresponding to the first sub dir
1409if isfield(Series,'OutputSubDir')
1410    SubDirOut=[Series.OutputSubDir Series.OutputDirExt];
1411    SubDirOutNew=SubDirOut;
1412    iview=1;
1413    SeriesData=get(handles.series,'UserData');
1414    if size(Series.InputTable,1)>1 && isfield(SeriesData,'AllowInputSort') && isfield(SeriesData.AllowInputSort)
1415        [tild,iview]=sort(Series.InputTable(:,2)); %subdirectories sorted in alphabetical order
1416        Series.InputTable=Series.InputTable(iview,:);
1417    end
1418    detect=exist(fullfile(Series.InputTable{1,1},SubDirOutNew),'dir');% test if  the dir  already exist
1419    while detect
1420        answer=msgbox_uvmat('INPUT_Y-N',['use existing ouput directory: ' fullfile(Series.InputTable{1,1},SubDirOutNew) ', possibly delete previous data']);
1421        if isequal(answer,'Yes')
1422            detect=0;
1423            check_create=0;
1424        else
1425            r=regexp(SubDirOutNew,'(?<root>.*\D)(?<num1>\d+)$','names');%detect whether name ends by a number
1426            if isempty(r)
1427                r(1).root=[SubDirOutNew '_'];
1428                r(1).num1='0';
1429            end
1430            SubDirOutNew=[r(1).root num2str(str2num(r(1).num1)+1)];%increment the index by 1 or put 1
1431            detect=exist(fullfile(Series.InputTable{1,1},SubDirOutNew),'dir');% test if  the dir  already exists   
1432            check_create=1;
1433        end
1434    end
1435    Series.OutputDirExt=regexprep(SubDirOutNew,Series.OutputSubDir,'');
1436    Series.OutputSubDir=SubDirOutNew;
1437    Series.OutputDir=fullfile(Series.InputTable{1,1},Series.OutputSubDir);%directory set for output results
1438    Series.OutputRootFile=Series.InputTable{1,3};% the first sorted RootFile taken for output
1439    set(handles.OutputDirExt,'String',Series.OutputDirExt)
1440    Series=rmfield(Series,'OutputDirExt');%removes redondant information
1441    % create output directory
1442    if check_create
1443        [tild,msg1]=mkdir(Series.OutputDir);
1444        if ~strcmp(msg1,'')
1445            errormsg=['cannot create ' Series.OutputDir ': ' msg1];%error message for directory creation
1446            return
1447        end
1448    end
1449    filexml=fullfile(Series.OutputDir,[Series.InputTable{1,3} '.xml']);% name of the parameter xml file set in this directory
1450    t=struct2xml(Series);
1451    save(t,filexml);
1452end
1453
1454%------------------------------------------------------------------------
1455% --- Executes on selection change in ActionName.
1456function ActionName_Callback(hObject, eventdata, handles)
1457%------------------------------------------------------------------------
1458global nb_builtin_ACTION
1459list_ACTION=get(handles.ActionName,'String');% list menu fields
1460index_ACTION=get(handles.ActionName,'Value');% selected string index
1461ACTION= list_ACTION{index_ACTION}; % selected function name
1462path_series=which('series');%path to series.m
1463list_path=get(handles.ActionName,'UserData');%list of recorded paths to functions of the list ACTION
1464default_file=fullfile(list_path{end},ACTION);
1465% add a new function to the menu if the selected item is 'more...'
1466if isequal(ACTION,'more...')
1467    pathfct=fileparts(path_series);
1468    [FileName, PathName, filterindex] = uigetfile( ...
1469       {'*.m', ' (*.m)';
1470        '*.m',  '.m files '; ...
1471        '*.*', 'All Files (*.*)'}, ...
1472        'Pick a file',default_file);
1473    if length(FileName)<2
1474        return
1475    end
1476    [pp,ACTION,ext_fct]=fileparts(FileName);%(end-1:end);
1477    if ~isequal(ext_fct,'.m')
1478        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
1479        return
1480    end
1481   
1482   % insert the choice in the actionname menu
1483   menu_str=update_menu(handles.ActionName,ACTION);%new action menu in which the new item has been appended if needed
1484   index_ACTION=get(handles.ActionName,'Value');% currently selected index in the list
1485   list_path{index_ACTION}=PathName;
1486   if length(menu_str)>nb_builtin_ACTION+5; %nb_builtin=nbre of functions always remaining in the initial menu
1487       nbremove=length(menu_str)-nb_builtin_ACTION-5;
1488       menu_str(nb_builtin_ACTION+1:end-5)=[];
1489       list_path(nb_builtin_ACTION+1:end-4)=[];
1490       index_ACTION=index_ACTION-nbremove;
1491       set(handles.ActionName,'Value',index_ACTION)
1492       set(handles.ActionName,'String',menu_str)
1493   end
1494   list_path{index_ACTION}=PathName;
1495   set(handles.ActionName,'UserData',list_path);
1496   set(handles.ActionPath,'enable','inactive')% indicate that the current path is accessible (not 'off')
1497   
1498   %record the current menu in personal file profil_perso
1499   dir_perso=prefdir;
1500   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1501   for ilist=nb_builtin_ACTION+1:length(menu_str)-1
1502       series_fct{ilist-nb_builtin_ACTION}=fullfile(list_path{ilist},[menu_str{ilist} '.m']);     
1503   end
1504   if nb_builtin_ACTION+1<=length(menu_str)-1
1505       if exist(profil_perso,'file')% && nb_builtin_ACTION+1>=length(menu_str)-1
1506           save(profil_perso,'series_fct','-append')
1507       else
1508           txt=ver('MATLAB');
1509           Release=txt.Release;
1510           relnumb=str2num(Release(3:4));
1511           if relnumb >= 14%recent relaese of Matlab
1512               save(profil_perso,'series_fct','-V6')
1513           else
1514               save(profil_perso, 'series_fct')
1515           end
1516       end
1517   end
1518end
1519
1520%check the current ActionPath to the selected function
1521PathName=list_path{index_ACTION};%current recorded path
1522set(handles.ActionPath,'String',PathName); %show the path to the senlected function
1523
1524%default setting for the visibility of the GUI elements
1525set(handles.num_NbSlice,'Visible','off')
1526set(handles.NbSlice_title,'Visible','off')
1527set(handles.VelType,'Visible','off');
1528set(handles.VelType_text,'Visible','off');
1529set(handles.VelType_1,'Visible','off');
1530set(handles.VelType_text_1,'Visible','off');
1531view_FieldMenu(handles,'off')
1532view_FieldMenu_1(handles,'off')
1533set(handles.FieldTransform,'Visible','off')
1534set(handles.CheckObject,'Visible','off');
1535set(handles.ProjObject,'Visible','off');
1536set(handles.CheckMask,'Visible','off')
1537set(handles.Mask,'Visible','off')
1538% set(handles.OutputDirExt,'Visible','off');
1539set(handles.ParamKey,'Visible','off')
1540set(handles.ParamVal,'Visible','off')
1541ParamKey={};
1542set(handles.FieldName,'Enable','off')
1543set(handles.VelType,'Enable','off')
1544set(handles.FieldName_1,'Enable','off')
1545set(handles.VelType_1,'Enable','off')
1546set(handles.TransformName,'Enable','off')
1547set(handles.OutputDirExt,'Visible','off')
1548set(handles.OutputSubDir,'Visible','off')
1549set(handles.OutputDir_title,'Visible','off')
1550%set the displayed GUI item needed for input parameters
1551if ~isequal(path_series,PathName)
1552    addpath(PathName)
1553end
1554eval(['h_function=@' ACTION ';']);
1555try
1556    [fid,errormsg] =fopen([ACTION '.m']);
1557    InputText=textscan(fid,'%s',1,'delimiter','\n');
1558    fclose(fid)
1559    set(handles.ActionName,'ToolTipString',InputText{1}{1})
1560end
1561if ~isequal(path_series,PathName)
1562    rmpath(PathName)
1563end
1564varargout=h_function();
1565Param_list={};
1566
1567InputTable=get(handles.InputTable,'Data');
1568nb_series=size(InputTable,1);
1569testima_series=1; %test for a list of images only
1570testima=1;
1571testima_1=1;
1572testciv_series=1;
1573for iview=1:nb_series
1574     ext=InputTable{iview,5};
1575    if length(ext)<2
1576        ext='.none';
1577    end
1578    testimaview=~isempty(imformats(ext(2:end))) || isequal(lower(ext),'.avi');
1579    if ~testimaview
1580        if iview==1
1581            testima=0;
1582        end
1583        if iview==2
1584            testima_1=0;
1585        end
1586        testima_series=0;
1587    end
1588end
1589for ilist=1:length(varargout)-1
1590    switch varargout{ilist}
1591        case 'NbViewMax'
1592            if ~isempty (varargout{ilist+1})
1593                if size(InputTable,1)>varargout{ilist+1}
1594                InputTable=InputTable(1:varargout{ilist+1},:);
1595                set(handles.InputTable,'Data',InputTable)
1596                end
1597            end
1598        case 'AllowInputSort'
1599            if isequal(lower(varargout{ilist+1}),'on')% sort the input table by alphabetical order of the SubDir
1600                SeriesData=get(handles.series,'UserData');
1601                SeriesData.AllowInputSort=1;
1602                set(handles.series,'UserData',SeriesData)
1603            end             
1604        case 'NbSlice'   %hidden by default
1605            if isequal(lower(varargout{ilist+1}),'on')
1606                set(handles.num_NbSlice,'Visible','on')
1607                set(handles.NbSlice_title,'Visible','on')
1608            end
1609        case 'VelType'   %hidden by default
1610             if isequal(lower(varargout{ilist+1}),'one') || isequal(lower(varargout{ilist+1}),'two')
1611                set(handles.VelType,'Enable','on')
1612                if nb_series >=1 && ~testima_series
1613                    set(handles.VelType,'Visible','on')
1614                    set(handles.VelType_text,'Visible','on');
1615                end
1616             end
1617            if isequal(lower(varargout{ilist+1}),'two')
1618                set(handles.VelType_1,'Enable','on')
1619                if nb_series >=2 && ~testima_series
1620                    set(handles.VelType_1,'Visible','on')
1621                    set(handles.VelType_text_1,'Visible','on');
1622                end
1623            end
1624        case 'FieldName'   %hidden by default
1625            if isequal(lower(varargout{ilist+1}),'one')||isequal(lower(varargout{ilist+1}),'two')
1626                set(handles.FieldName,'Enable','on') % test for MenuBorser
1627                if nb_series >=1 && ~testima_series
1628                    view_FieldMenu(handles,'on')
1629                end
1630            end
1631            if isequal(lower(varargout{ilist+1}),'two')
1632                set(handles.FieldName_1,'Enable','on')
1633                if nb_series >=2 && ~testima_1
1634                    view_FieldMenu_1(handles,'on')
1635                end
1636            end
1637        case 'FieldTransform'   %hidden by default
1638            if isequal(lower(varargout{ilist+1}),'on')
1639                set(handles.TransformName,'Enable','on')
1640                set(handles.FieldTransform,'Visible','on')
1641            end
1642        case 'ProjObject'   %hidden by default
1643            if isequal(lower(varargout{ilist+1}),'on')   
1644                set(handles.CheckObject,'Visible','on')
1645                set(handles.ProjObject,'Visible','on')
1646            end
1647        case 'Mask'   %hidden by default
1648            if isequal(lower(varargout{ilist+1}),'on')   
1649                set(handles.Mask,'Visible','on')
1650                 set(handles.CheckMask,'Visible','on');
1651            end
1652        case 'PARAMETER'  % NOT USED
1653            set(handles.PARAMETERS_frame,'Visible','on')
1654            set(handles.PARAMETERS_title,'Visible','on')
1655            set(handles.ParamKey,'Visible','on')
1656            %set(handles.ParamVal,'Visible','on')
1657            Param_str=varargout{ilist+1};
1658            Param_list=[Param_list; {Param_str}];   
1659        case 'OutputDirExt'
1660            if ~isempty(varargout{ilist+1})
1661            set(handles.OutputDirExt,'String',varargout{ilist+1})
1662            set(handles.OutputDirExt,'Visible','on')
1663            set(handles.OutputSubDir,'Visible','on')
1664            set(handles.OutputDir_title,'Visible','on') 
1665            end
1666    end
1667end
1668if ~isempty(Param_list)
1669    set(handles.ParamKey,'String',Param_list)
1670    set(handles.ParamVal,'Visible','on')
1671end
1672
1673%------------------------------------------------------------------------
1674% --- Executes on selection change in FieldName.
1675function FieldName_Callback(hObject, eventdata, handles)
1676%------------------------------------------------------------------------
1677field_str=get(handles.FieldName,'String');
1678field_index=get(handles.FieldName,'Value');
1679field=field_str{field_index(1)};
1680if isequal(field,'get_field...')   
1681     hget_field=findobj(allchild(0),'name','get_field');
1682     if ~isempty(hget_field)
1683         delete(hget_field)%delete opened versions of get_field
1684     end
1685     [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(read_GUI(handles.series));
1686     if exist(filecell{1,1},'file')
1687        get_field(filecell{1,1})
1688     end
1689elseif isequal(field,'more...')
1690    str=calc_field;
1691    [ind_answer,v] = listdlg('PromptString','Select a file:',...
1692                'SelectionMode','single',...
1693                'ListString',str);
1694       % edit the choice in the fields and actionname menu
1695     scalar=cell2mat(str(ind_answer));
1696     update_menu(handles.FieldName,scalar)
1697end
1698
1699%------------------------------------------------------------------------
1700% --- Executes on selection change in FieldName_1.
1701function FieldName_1_Callback(hObject, eventdata, handles)
1702%------------------------------------------------------------------------
1703field_str=get(handles.FieldName_1,'String');
1704field_index=get(handles.FieldName_1,'Value');
1705field=field_str{field_index};
1706if isequal(field,'get_field...')   
1707     hget_field=findobj(allchild(0),'name','get_field_1');
1708     if ~isempty(hget_field)
1709         delete(hget_field)
1710     end
1711     SeriesData=get(handles.series,'UserData');
1712     filename=SeriesData.CurrentInputFile_1;
1713     if exist(filename,'file')
1714        hget_field=get_field(filename);
1715        set(hget_field,'name','get_field_1')
1716     end
1717elseif isequal(field,'more...')
1718    str=calc_field;
1719    [ind_answer,v] = listdlg('PromptString','Select a file:',...
1720                'SelectionMode','single',...
1721                'ListString',str);
1722       % edit the choice in the fields and actionname menu
1723     scalar=cell2mat(str(ind_answer));
1724     update_menu(handles.FieldName_1,scalar)
1725end   
1726
1727
1728%%%%%%%%%%%%%
1729function [ind_remove]=find_pairs(dirpair,ind_i,last_i)
1730indsel=ind_i;
1731indiff=diff(ind_i); %test index increment to detect multiplets (several pairs with the same index ind_i) and holes in the series
1732indiff=[1 indiff last_i-ind_i(end)+1];%for testing gaps with the imposed bounds
1733if ~isempty(indiff)
1734    indiff2=diff(indiff);
1735    indiffp=[indiff2 1];
1736    indiffm=[1 indiff2];
1737    ind_multi_m=find((indiff==0)&(indiffm<0))-1;%indices of first members of multiplets
1738    ind_multi_p=find((indiff==0)&(indiffp>0));%indices of last members of multiplets
1739    %for each multiplet, select the most recent file
1740    ind_remove=[];
1741    for i=1:length(ind_multi_m)
1742        ind_pairs=ind_multi_m(i):ind_multi_p(i);
1743        for imulti=1:length(ind_pairs)
1744            datepair(imulti)=datenum(dirpair(ind_pairs(imulti)).date);%dates of creation
1745        end
1746        [datenew,indsort2]=sort(datepair); %sort the multiplet by creation date
1747        ind_s=indsort2(1:end-1);%
1748        ind_remove=[ind_remove ind_pairs(ind_s)];%remove these indices, leave the last one
1749    end
1750end
1751
1752%------------------------------------------------------------------------
1753% --- determine the list of index pairstring of processing file
1754function [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)
1755%------------------------------------------------------------------------
1756num_i1=num_i;% set of first image numbers by default
1757num_i2=num_i;
1758num_j1=num_j;
1759num_j2=num_j;
1760num_i_out=num_i;
1761num_j_out=num_j;
1762% if isequal (NomType,'_1-2_1') || isequal (NomType,'_1-2')
1763if isequal(mode,'series(Di)')
1764    num_i1_line=num_i+ind_shift(3);% set of first image numbers
1765    num_i2_line=num_i+ind_shift(4);
1766    % adjust the first and last field number
1767        indsel=find(num_i1_line >= 1);
1768    num_i_out=num_i(indsel);
1769    num_i1_line=num_i1_line(indsel);
1770    num_i2_line=num_i2_line(indsel);
1771    num_j1=meshgrid(num_j,ones(size(num_i1_line)));
1772    num_j2=meshgrid(num_j,ones(size(num_i1_line)));
1773    [xx,num_i1]=meshgrid(num_j,num_i1_line);
1774    [xx,num_i2]=meshgrid(num_j,num_i2_line);
1775elseif isequal (mode,'series(Dj)')||isequal (mode,'bursts')
1776    if isequal(mode,'bursts') %case of bursts (png_old or png_2D)
1777        num_j1=ind_shift(1)*ones(size(num_i));
1778        num_j2=ind_shift(2)*ones(size(num_i));
1779    else
1780        num_j1_col=num_j+ind_shift(1);% set of first image numbers
1781        num_j2_col=num_j+ind_shift(2);
1782        % adjust the first field number
1783        indsel=find((num_j1_col >= 1));   
1784        num_j_out=num_j(indsel);
1785        num_j1_col=num_j1_col(indsel);
1786        num_j2_col=num_j2_col(indsel);
1787        [num_i1,num_j1]=meshgrid(num_i,num_j1_col);
1788        [num_i2,num_j2]=meshgrid(num_i,num_j2_col);
1789    end   
1790end
1791
1792%------------------------------------------------------------------------
1793% --- Executes on button press in CheckObject.
1794function CheckObject_Callback(hObject, eventdata, handles)
1795%------------------------------------------------------------------------
1796% SeriesData=get(handles.series,'UserData');
1797value=get(handles.CheckObject,'Value');
1798if value
1799     set(handles.CheckObject,'BackgroundColor',[1 1 0])%put unactivated buttons to yellow
1800     hset_object=findobj(allchild(0),'tag','set_object');%find the set_object interface handle
1801     if ishandle(hset_object)
1802         uistack(hset_object,'top')% show the GUI set_object if opened
1803     else
1804         %get the object file
1805         InputTable=get(handles.InputTable,'Data');
1806         defaultname=InputTable{1,1};
1807         if isempty(defaultname)
1808            defaultname={''};
1809         end
1810        [FileName, PathName, filterindex] = uigetfile( ...
1811       {'*.xml;*.mat', ' (*.xml,*.mat)';
1812       '*.xml',  '.xml files '; ...
1813        '*.mat',  '.mat matlab files '}, ...
1814        'Pick an xml object file (or use uvmat to create it)',defaultname);
1815        fileinput=[PathName FileName];%complete file name
1816        sizf=size(fileinput);
1817        if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
1818        %read the file
1819        data=xml2struct(fileinput);
1820        if ~isfield(data,'Type')
1821             msgbox_uvmat('ERROR',[fileinput ' is not an object xml file'])
1822             return
1823        end
1824        if ~isfield(data,'ProjMode')
1825             data.ProjMode='none';
1826        end
1827        hset_object=set_object(data);% call the set_object interface
1828     end
1829     Object=read_GUI(hset_object);
1830     set(handles.ProjObject,'String',Object.Name);%display the object name
1831else
1832    set(handles.CheckObject,'BackgroundColor',[0.7 0.7 0.7])%put activated buttons to green
1833end
1834%set(handles.series,'UserData',SeriesData)
1835
1836%--------------------------------------------------------------
1837function CheckMask_Callback(hObject, eventdata, handles)
1838value=get(handles.CheckMask,'Value');
1839if value
1840    msgbox_uvmat('ERROR','not implemented yet')
1841end
1842%--------------------------------------------------------------
1843
1844%-------------------------------------------------------------------
1845%'uv_ncbrowser': interactively calls the netcdf file browser 'get_field.m'
1846function ncbrowser_uvmat(hObject, eventdata)
1847%-------------------------------------------------------------------
1848     bla=get(gcbo,'String');
1849     ind=get(gcbo,'Value');
1850     filename=cell2mat(bla(ind));
1851      blank=find(filename==' ');
1852      filename=filename(1:blank-1);
1853     get_field(filename)
1854
1855% ------------------------------------------------------------------
1856function MenuHelp_Callback(hObject, eventdata, handles)
1857%-------------------------------------------------------------------
1858path_to_uvmat=which ('uvmat');% check the path of uvmat
1859pathelp=fileparts(path_to_uvmat);
1860helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
1861if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
1862else
1863    addpath (fullfile(pathelp,'uvmat_doc'))
1864    web([helpfile '#series'])
1865end
1866
1867%-------------------------------------------------------------------
1868% --- Executes on selection change in TransformName.
1869function TransformName_Callback(hObject, eventdata, handles)
1870%-------------------------------------------------------------------
1871global nb_transform
1872
1873menu=get(handles.TransformName,'String');
1874ind_coord=get(handles.TransformName,'Value');
1875coord_option=menu{ind_coord};
1876list_transform=get(handles.TransformName,'UserData');
1877ff=functions(list_transform{end});
1878if isequal(coord_option,'more...');
1879    coord_fct='';
1880    prompt = {'Enter the name of the transform function'};
1881    dlg_title = 'user defined transform';
1882    num_lines= 1;
1883    [FileName, PathName, filterindex] = uigetfile( ...
1884       {'*.m', ' (*.m)';
1885        '*.m',  '.m files '; ...
1886        '*.*', 'All Files (*.*)'}, ...
1887        'Pick a file', ff.file);
1888    if isequal(PathName(end),'/')||isequal(PathName(end),'\')
1889        PathName(end)=[];
1890    end
1891    transform_selected =fullfile(PathName,FileName);
1892    if ~exist(transform_selected,'file')
1893          return
1894    end
1895    [ppp,transform,xt_fct]=fileparts(FileName);% removes extension .m
1896    if ~isequal(ext_fct,'.m')
1897        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
1898        return
1899    end
1900   menu=update_menu(handles.TransformName,transform);%add the selected fct to the menu
1901   ind_coord=get(handles.TransformName,'Value');
1902   addpath(PathName)
1903   list_transform{ind_coord}=str2func(transform);% create the function handle corresponding to the newly seleced function
1904   set(handles.TransformName,'UserData',list_transform)
1905   rmpath(PathName)
1906   % save the new menu in the personal file 'uvmat_perso.mat'
1907   dir_perso=prefdir;%personal Matalb directory
1908   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1909   if exist(profil_perso,'file')
1910       for ilist=nb_transform+1:numel(list_transform)
1911           ff=functions(list_transform{ilist});
1912           transform_fct{ilist-nb_transform}=ff.file;
1913       end
1914        save (profil_perso,'transform_fct','-append'); %store the root name for future opening of uvmat
1915   end
1916end
1917
1918%check the current ActionPath to the selected function
1919if ~isempty(list_transform{ind_coord})
1920func=functions(list_transform{ind_coord});
1921set(handles.TransformPath,'String',fileparts(func.file)); %show the path to the senlected function
1922else
1923   set(handles.TransformPath,'String',''); %show the path to the senlected function
1924end
1925
1926% %------------------------------------------------------------------------
1927% % --- Executes on button press in REFRESH_INDICES.
1928%     function REFRESH_INDICES_Callback(hObject, eventdata, handles)
1929% %------------------------------------------------------------------------       
1930% % hObject    handle to REFRESH_INDICES (see GCBO)
1931% % eventdata  reserved - to be defined in a future version of MATLAB
1932% % handles    structure with handles and user data (see GUIDATA)
1933% set(handles.REFRESH_INDICES,'BackgroundColor',[0.7 0.7 0.7])
1934% InputTable=get(handles.InputTable,'Data');
1935% check_lines=get(handles.REFRESH_INDICES,'UserData');
1936%
1937% %% check the indices and FileTypes for each series (limited to the new ones to save time)
1938% for ind_list=1:length(check_lines)
1939%     if  check_lines(ind_list)
1940%         InputLine=InputTable(ind_list,:);
1941%         detect_idem=strcmp('"',InputLine);% look for '" (repeat of previous data)
1942%         detect_idem=detect_idem(detect_idem>0);
1943%         if ~isempty (detect_idem)
1944%             InputLine(detect_idem)=InputTable(ind_list-1,detect_idem);
1945%             set(handles.InputTable,'Data',InputTable)
1946%         end
1947%         fileinput=fullfile_uvmat(InputLine{1},InputLine{2},InputLine{3},InputLine{5},InputLine{4},1,2,1,2);
1948%         %fileinput=name_generator(fullfile(InputLine{1},InputLine{3}),1,1,InputLine{5},InputLine{4},1,2,2,InputLine{2})
1949%         %update file series defined by the selected line
1950%         [InputTable{ind_list,3},InputTable{(ind_list),4},errormsg]=update_indices(handles,fileinput,ind_list);
1951%         if ~isempty(errormsg)
1952%                 msgbox_uvmat('ERROR',errormsg)
1953%                 return
1954%         end
1955%     end
1956% end
1957% set(handles.InputTable,'Data',InputTable)
1958% SeriesData=get(handles.series,'UserData');
1959%
1960% state_j='off';
1961% state_Pairs='off';
1962% state_InputFields='off';
1963% val=get(handles.ListView,'Value');
1964% ListViewString={''};
1965% if ~isempty(SeriesData)
1966% %     ListViewString={};
1967%     for iview=1:size(InputTable,1)
1968%         if ~isempty(SeriesData.j1_series{iview})
1969%             state_j='on';
1970%         end
1971%         if ~isempty(SeriesData.i2_series{iview})||~isempty(SeriesData.j2_series{iview})
1972%             state_Pairs='on';
1973%             ListViewString{iview}=num2str(iview);
1974%             if check_lines(iview)
1975%                 val=iview;%select the last pair if it is a new entry
1976%             end
1977%         end
1978%         if strcmp(SeriesData.FileType{iview},'civx')||strcmp(SeriesData.FileType{iview},'civdata')
1979%             state_InputFields='on';
1980%         end
1981%     end
1982% end
1983% set(handles.ListView,'Value',val)
1984% set(handles.ListView,'String',ListViewString)
1985% if strcmp(state_Pairs,'on')
1986%     ListView_Callback(hObject,eventdata,handles)
1987% end
1988% set(handles.PairString,'Visible',state_Pairs)
1989% enable_j(handles,state_j)
1990% set(handles.REFRESH_INDICES,'BackgroundColor',[1 0 0])
1991% set(handles.REFRESH_INDICES,'visible','off')
1992
1993% -----------------------------------------------------------------------
1994% --- Update min and max indices of a file series by scanning with find_file_series
1995% --- which also changes the root file and NomType in case of movie. Also adjust the string representation of indices (e.g;
1996% --- 1 or 001 by the function find_file_series
1997% --- This function also dispaly the set of availbale files in the series
1998% --- and the menus appropriate to the file type as well as timing possibly set
1999% --- by an xml image documentation file
2000function [RootFile,NomType,errormsg]=update_indices(handles,fileinput,iview)
2001% -----------------------------------------------------------------------
2002%% look for min and max indices existing in the file series and update SeriesData
2003errormsg='';
2004[FilePath,FileName,FileExt]=fileparts(fileinput);
2005% detect the file type, get the movie object if relevant, and look for the corresponding file series:
2006% the root name and indices may be corrected by including the first index i1 if a corresponding xml file exists
2007[RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,NomType,FileType,Object,i1,i2,j1,j2]=find_file_series(FilePath,[FileName FileExt]);
2008if isempty(RootFile)&&isempty(i1_series)
2009    errormsg='no input file in the series';
2010    return
2011end
2012
2013%% adjust the min and max indices common to all the file series
2014MinIndex=get(handles.MinIndex,'Data');
2015MaxIndex=get(handles.MaxIndex,'Data');
2016MinIndex_i=min(i1_series(i1_series>0));
2017if ~isempty(i2_series)
2018    MaxIndex_i=max(i2_series(i2_series>0));
2019else
2020    MaxIndex_i=max(i1_series(i1_series>0));
2021end
2022MinIndex_j=min(j1_series(j1_series>0));
2023if ~isempty(j2_series)
2024    MaxIndex_j=max(j2_series(j2_series>0));
2025else
2026    MaxIndex_j=max(j1_series(j1_series>0));
2027end
2028MinIndex{iview,1}=MinIndex_i;
2029MinIndex{iview,2}=MinIndex_j;
2030MaxIndex{iview,1}=MaxIndex_i;
2031MaxIndex{iview,2}=MaxIndex_j;
2032set(handles.MinIndex,'Data',MinIndex)
2033set(handles.MaxIndex,'Data',MaxIndex)
2034SeriesData=get(handles.series,'UserData');
2035SeriesData.i1_series{iview}=i1_series;
2036SeriesData.i2_series{iview}=i2_series;
2037SeriesData.j1_series{iview}=j1_series;
2038SeriesData.j2_series{iview}=j2_series;
2039SeriesData.FileType{iview}=FileType;
2040
2041%% display the set of existing files as an image
2042set(handles.waitbar_frame,'Units','pixels')
2043pos=get(handles.waitbar_frame,'Position');
2044xima=0.5:pos(3)-0.5;% pixel positions on the image representing the existing file indices
2045yima=0.5:pos(4)-0.5;
2046[XIma,YIma]=meshgrid(xima,yima);
2047nb_i=size(i1_series,1);
2048nb_j=size(i1_series,2);
2049ind_i=(0.5:nb_i-0.5)*pos(3)/nb_i;
2050ind_j=(0.5:nb_j-0.5)*pos(4)/nb_j;
2051[Ind_i,Ind_j]=meshgrid(ind_i,ind_j);
2052CData=zeros([size(XIma) 3]);
2053file_ima=double((i1_series(:,:,1)>0)');
2054if numel(file_ima)>=2
2055if size(file_ima,1)==1
2056    CLine=interp1(ind_i,file_ima,xima,'nearest');
2057    CData(:,:,2)=ones(size(yima'))*CLine;
2058else
2059    CData(:,:,2)=interp2(Ind_i,Ind_j,file_ima,XIma,YIma,'nearest');
2060end
2061set(handles.waitbar_frame,'CData',CData)
2062end
2063set(handles.waitbar_frame,'Units','normalized')
2064
2065%% enable field and veltype menus
2066testfield=isequal(get(handles.FieldName,'enable'),'on');
2067testfield_1=isequal(get(handles.FieldName_1,'enable'),'on');
2068testveltype=isequal(get(handles.VelType,'enable'),'on');
2069testveltype_1=isequal(get(handles.VelType_1,'enable'),'on');
2070testtransform=isequal(get(handles.TransformName,'Enable'),'on');
2071% testnc=0;
2072% testnc_1=0;
2073% testcivx=0;
2074% testcivx_1=0;
2075% testima=0; %test for image input
2076% if isequal(lower(FileExt),'.avi') %.avi file
2077%     testima=1;
2078% elseif ~isempty(imformats(FileExt(2:end)))
2079%     testima=1;
2080% elseif isequal(FileExt,'.vol')
2081%      testima=1;
2082% end
2083%TODO: update
2084% if length(FileExtCell)==1 || length(FileExtCell)>2
2085%     for iview=1:length(FileExtCell)
2086%         if isequal(FileExtCell{iview},'.nc')
2087%             testnc=1;
2088%         end
2089%         if isequal(FileTypeCell{iview},'civx')
2090%             testcivx=1;
2091%         end
2092%     end
2093% elseif length(FileExtCell)==2
2094%     testnc=isequal(FileExtCell{1},'.nc');
2095%     testnc_1=isequal(FileExtCell{2},'.nc');
2096%     testcivx=isequal(FileTypeCell{1},'civx');
2097%     testcivx_1=isequal(FileTypeCell{2},'civx');
2098% end
2099switch FileType
2100    case {'civx','civdata'}
2101    view_FieldMenu(handles,'on')
2102    menustr=get(handles.FieldName,'String');
2103    if isequal(menustr,{'get_field...'})
2104        set(handles.FieldName,'String',{'get_field...';'velocity';'vort';'div';'more...'})
2105    end
2106    set(handles.VelType,'Visible','on')
2107    set(handles.FieldTransform,'Visible','on')
2108    %      view_TRANSFORM(handles,'on')
2109    %     TODO: second menu
2110    %           view_FieldMenu_1(handles,'on')
2111    %     if testcivx_1
2112    %         menustr=get(handles.FieldName_1,'String');
2113    %         if isequal(menustr,{'get_field...'})
2114    %             set(handles.FieldName_1,'String',{'get_field...';'velocity';'vort';'div';'more...'})
2115    %         end
2116    %     else
2117    %         set(handles.FieldName_1,'Value',1)
2118    %         set(handles.FieldName_1,'String',{'get_field...'})
2119    %     set(handles.VelType_1,'Visible','on')
2120    %     set(handles.VelType_text_1,'Visible','on');
2121    %     end
2122    %     view_FieldMenu_1(handles,'off')
2123    case 'netcdf'
2124    view_FieldMenu(handles,'on')
2125    set(handles.FieldName,'Value',1)
2126    set(handles.FieldName,'String',{'get_field...'})
2127    set(handles.FieldTransform,'Visible','off')
2128    %     view_TRANSFORM(handles,'off')
2129    case {'image','multimage','video'}
2130    view_FieldMenu(handles,'off')
2131    view_FieldMenu_1(handles,'off')
2132    set(handles.VelType,'Visible','off')
2133    set(handles.VelType_text,'Visible','off');
2134end
2135
2136
2137%TODO:update
2138% if ~isequal(FileExt,'.nc') && ~isequal(FileExt,'.cdf') && ~testima
2139%     msgbox_uvmat('ERROR',['invalid input file extension ' FileExt])
2140%     return
2141% end 
2142
2143%%  read image documentation file  if found%%%%%%%%%%%%%%%%%%%%%%%%%%%
2144ext_imadoc='';
2145FileBase=fullfile(RootPath,RootFile);
2146if isequal(FileExt,'.xml')||isequal(FileExt,'.civ')
2147    ext_imadoc=FileExt;
2148elseif exist([FileBase '.xml'],'file')
2149    ext_imadoc='.xml';
2150elseif exist([FileBase '.civ'],'file')
2151    ext_imadoc='.civ';
2152end
2153%read the ImaDoc file
2154XmlData=[];
2155NbSlice_calib={};
2156if isequal(ext_imadoc,'.xml')
2157        [XmlData,warntext]=imadoc2struct([FileBase '.xml']);
2158        if isfield(XmlData,'Heading') && isfield(XmlData.Heading,'ImageName') && ischar(XmlData.Heading.ImageName)
2159            [PP,FF,ext_ima_read]=fileparts(XmlData.Heading.ImageName);
2160        end
2161        if isfield(XmlData,'Time')
2162            time{iview}=XmlData.Time;
2163        end
2164        if isfield(XmlData,'Camera')
2165            if isfield(XmlData.Camera,'NbSlice')&& ~isempty(XmlData.Camera.NbSlice)
2166                NbSlice_calib{iview}=XmlData.Camera.NbSlice;% Nbre of slices for Zindex in phys transform
2167                if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
2168                    msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
2169                end
2170            end
2171            if isfield(XmlData.Camera,'TimeUnit')&& ~isempty(XmlData.Camera.TimeUnit)
2172                TimeUnit=XmlData.Camera.TimeUnit;
2173            end
2174        end
2175        if ~isempty(warntext)
2176            msgbox_uvmat('WARNING',warntext)
2177        end 
2178elseif isequal(ext_imadoc,'.civ')
2179    [error,XmlData.Time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([FileBase '.civ']);
2180    time{iview}=XmlData.Time;
2181    if error==2, warntext=['no file ' FileBase '.civ'];
2182    elseif error==1, warntext='inconsistent number of fields in the .civ file';
2183    end 
2184end
2185
2186%% update time table
2187TimeTable=get(handles.TimeTable,'Data');
2188TimeTable{iview,1}=time(MinIndex_i,MinIndex_j);
2189TimeTable{iview,4}=time(MaxIndex_i,MaxIndex_j);
2190set(handles.TimeTable,'Data',TimeTable)
2191
2192%% number of slices
2193if isfield(XmlData,'GeometryCalib') && isfield(XmlData.GeometryCalib,'SliceCoord')
2194       siz=size(XmlData.GeometryCalib.SliceCoord);
2195       if siz(1)>1
2196           NbSlice=siz(1);
2197       else
2198           NbSlice=1;
2199       end
2200       set(handles.num_NbSlice,'String',num2str(NbSlice))
2201end
2202% set(handles.mode,'Visible','off') % do not show index pairstring by default
2203set(handles.PairString,'Visible','off')
2204% set(handles.num_ref_i,'Visible','off')
2205% set(handles.ref_i_text,'Visible','off')
2206testpair=0;
2207%set the menus of image pairstring and default selection for series
2208%list pairstring if relevant
2209% Val=get(handles.NomType,'Value');
2210% synchronise_view(handles,Val)
2211
2212% if ~isfield(SeriesData,'j1_series')||isempty(SeriesData.j1_series{index})
2213%     state_j='off'; %no need for j index
2214% else
2215%     state_j='on'; %case of j index
2216% end
2217% show index pairstring if files exist
2218set(handles.series,'UserData',SeriesData)
2219
2220
2221% --------------------------------------------------------------------
2222function MenuExportConfig_Callback(hObject, eventdata, handles)
2223global Series
2224[tild,Series,errormsg]=prepare_jobs(handles);
2225% Series=read_GUI(handles.series);
2226
2227evalin('base','global Series')%make CurData global in the workspace
2228display('current series config :')
2229evalin('base','Series') %display CurData in the workspace
2230commandwindow; %brings the Matlab command window to the front
Note: See TracBrowser for help on using the repository browser.