source: trunk/src/series.m @ 453

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

series adapted to BATCH mode. Tests still needed.

File size: 87.4 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
667NbSlice=MaxIndex_j-MinIndex_j+1;%default
668if isfield(XmlData,'GeometryCalib') && isfield(XmlData.GeometryCalib,'SliceCoord')
669    siz=size(XmlData.GeometryCalib.SliceCoord);
670    if siz(1)>1
671        NbSlice=siz(1);
672    end
673end
674set(handles.num_NbSlice,'String',num2str(NbSlice))
675   
676%% update pair menus
677set(handles.Pairs,'Visible','on')
678set(handles.PairString,'Visible','on')
679ListView=get(handles.ListView,'String');
680ListView{iview}=num2str(iview);
681set(handles.ListView,'String');
682set(handles.ListView,'Value',iview)
683update_mode(handles,i1_series,i2_series,j1_series,j2_series,time)
684
685
686%% display the set of existing files as an image
687set(handles.waitbar_frame,'Units','pixels')
688pos=get(handles.waitbar_frame,'Position');
689xima=0.5:pos(3)-0.5;% pixel positions on the image representing the existing file indices
690yima=0.5:pos(4)-0.5;
691[XIma,YIma]=meshgrid(xima,yima);
692nb_i=size(i1_series,1);
693nb_j=size(i1_series,2);
694ind_i=(0.5:nb_i-0.5)*pos(3)/nb_i;
695ind_j=(0.5:nb_j-0.5)*pos(4)/nb_j;
696[Ind_i,Ind_j]=meshgrid(ind_i,ind_j);
697CData=zeros([size(XIma) 3]);
698file_ima=double((i1_series(:,:,1)>0)');
699if numel(file_ima)>=2
700if size(file_ima,1)==1
701    CLine=interp1(ind_i,file_ima,xima,'nearest');
702    CData(:,:,2)=ones(size(yima'))*CLine;
703else
704    CData(:,:,2)=interp2(Ind_i,Ind_j,file_ima,XIma,YIma,'nearest');
705end
706set(handles.waitbar_frame,'CData',CData)
707end
708set(handles.waitbar_frame,'Units','normalized')
709
710%% enable field and veltype menus
711SeriesData=get(handles.series,'UserData');
712SeriesData.FileType{iview}=FileType;
713check_civ=0;
714check_netcdf=0;
715for iview=1:length(SeriesData.FileType)
716    switch SeriesData.FileType{iview}
717        case {'civx','civdata'}
718            check_civ=check_civ+1;
719        case 'netcdf'
720            check_netcdf=check_netcdf+1;
721    end
722end
723if check_civ
724    enable='on';
725else
726    enable='off';
727end
728set(handles.VelType,'Visible',enable)
729set(handles.VelType_text,'Visible',enable)
730if check_civ>=2
731    enable='on';
732else
733    enable='off';
734end
735set(handles.VelType_1,'Visible',enable)
736set(handles.VelType_text_1,'Visible',enable)
737if check_civ || check_netcdf
738    enable='on';
739else
740    enable='off';
741end
742set(handles.FieldName,'Visible',enable)
743set(handles.Field_text,'Visible',enable)
744if check_civ+ check_netcdf>=2
745    enable='on';
746else
747    enable='off';
748end
749set(handles.FieldName_1,'Visible',enable)
750set(handles.Field_text_1,'Visible',enable)
751FieldString={''};
752if check_civ
753    FieldString=[calc_field;{'get_field...'}];
754elseif check_netcdf
755    FieldString={'get_field...'};
756end
757set(handles.FieldName,'String',FieldString)
758FieldString={''};
759if check_civ>=2
760    FieldString=[calc_field;{'get_field...'}];
761elseif check_civ+check_netcdf>=2
762    FieldString={'get_field...'};
763end
764set(handles.FieldName_1,'String',{'get_field...'})
765
766
767%% store the series info in 'UserData'
768SeriesData.i1_series{iview}=i1_series;
769SeriesData.i2_series{iview}=i2_series;
770SeriesData.j1_series{iview}=j1_series;
771SeriesData.j2_series{iview}=j2_series;
772SeriesData.FileType{iview}=FileType;
773SeriesData.Time{iview}=time;
774set(handles.series,'UserData',SeriesData)
775
776%% check for pair display
777check_pairs=0;
778for iview=1:numel(SeriesData.i2_series)
779    if ~isempty(SeriesData.i2_series{iview})||~isempty(SeriesData.j2_series{iview})
780        check_pairs=1;
781    end
782end
783if check_pairs
784    set(handles.Pairs,'Visible','on')
785    set(handles.PairString,'Visible','on')
786else
787    set(handles.Pairs,'Visible','off')
788    set(handles.PairString,'Visible','off')
789end
790
791return
792
793%% set default options in menu 'Fields'%% TODO: check VelType
794if ~testima
795    testcivx=0;
796    if isfield(UvData,'FieldsString') && isequal(UvData.FieldsString,{'get_field...'})% field menu defined as input (from get_field)
797        set(handles_Fields,'Value',1)
798        set(handles_Fields,'String',{'get_field...'})
799        UvData=rmfield(UvData,'FieldsString');
800    else
801        Data=nc2struct(FileName,'ListGlobalAttribute','Conventions','absolut_time_T0','civ');
802        if strcmp(Data.Conventions,'uvmat/civdata') ||( ~isempty(Data.absolut_time_T0)&& ~isequal(Data.civ,0))%if the new input is Civx
803            FieldList=calc_field;
804            set(handles_Fields,'String',[{'image'};FieldList;{'get_field...'}]);%standard menu for civx data
805            set(handles_Fields,'Value',2) % set menu to 'velocity'
806            col_vec=FieldList;
807            col_vec(1)=[];%remove 'velocity' option for vector color (must be a scalar)
808            testcivx=1;
809        end
810        if ~testcivx
811            set(handles_Fields,'Value',1) % set menu to 'get_field...
812            set(handles_Fields,'String',{'get_field...'})
813            col_vec={'get_field...'};
814        end
815        set(handles.ColorScalar,'String',col_vec)
816    end
817end
818set(handles.uvmat,'UserData',UvData)
819
820%% set index navigation options and refresh plots
821scan_option='i';%default
822state_j='off'; %default
823if index==2
824    if get(handles.scan_j,'Value')
825        scan_option='j'; %keep the scan option for the second fiel series
826    end
827    if strcmp(get(handles.j1,'Visible'),'on')
828        state_j='on';
829    end
830end
831if ~isempty(j1_series)
832        state_j='on';
833        if isequal(nbfield,1) &&index==1
834            scan_option='j'; %scan j index by default if nbfield=1               
835        end
836end
837if isequal(scan_option,'i')
838     set(handles.scan_i,'Value',1)
839     scan_i_Callback([],[], handles);
840else
841     set(handles.scan_j,'Value',1)
842     scan_j_Callback([],[], handles);
843end
844set(handles.scan_j,'Visible',state_j)
845set(handles.j1,'Visible',state_j)
846set(handles.j2,'Visible',state_j)
847set(handles.last_j,'Visible',state_j);
848set(handles.frame_j,'Visible',state_j);
849set(handles.j_text,'Visible',state_j);
850if ~isempty(i2_series)||~isempty(j2_series)
851    set(handles.CheckFixPair,'Visible','on')
852elseif index==1
853    set(handles.CheckFixPair,'Visible','off')
854end
855
856
857mode_Callback(hObject, eventdata, handles)
858
859set(handles.REFRESH_INDICES,'BackgroundColor',[0.7 0.7 0.7])
860InputTable=get(handles.InputTable,'Data');
861check_lines=get(handles.REFRESH_INDICES,'UserData');
862
863%% check the indices and FileTypes for each series (limited to the new ones to save time)
864for ind_list=1:length(check_lines)
865    if  check_lines(ind_list)
866        InputLine=InputTable(ind_list,:);
867        detect_idem=strcmp('"',InputLine);% look for '" (repeat of previous data)
868        detect_idem=detect_idem(detect_idem>0);
869        if ~isempty (detect_idem)
870            InputLine(detect_idem)=InputTable(ind_list-1,detect_idem);
871            set(handles.InputTable,'Data',InputTable)
872        end
873        fileinput=fullfile_uvmat(InputLine{1},InputLine{2},InputLine{3},InputLine{5},InputLine{4},1,2,1,2);
874        %fileinput=name_generator(fullfile(InputLine{1},InputLine{3}),1,1,InputLine{5},InputLine{4},1,2,2,InputLine{2})
875        %update file series defined by the selected line
876        [InputTable{ind_list,3},InputTable{(ind_list),4},errormsg]=update_indices(handles,fileinput,ind_list);
877        if ~isempty(errormsg)
878                msgbox_uvmat('ERROR',errormsg)
879                return
880        end
881    end
882end
883set(handles.InputTable,'Data',InputTable)
884SeriesData=get(handles.series,'UserData');
885
886state_j='off';
887state_Pairs='off';
888state_InputFields='off';
889val=get(handles.ListView,'Value');
890ListViewString={''};
891if ~isempty(SeriesData)
892%     ListViewString={};
893    for iview=1:size(InputTable,1)
894        if ~isempty(SeriesData.j1_series{iview})
895            state_j='on';
896        end
897        if ~isempty(SeriesData.i2_series{iview})||~isempty(SeriesData.j2_series{iview})
898            state_Pairs='on';
899            ListViewString{iview}=num2str(iview);
900            if check_lines(iview)
901                val=iview;%select the last pair if it is a new entry
902            end
903        end
904        if strcmp(SeriesData.FileType{iview},'civx')||strcmp(SeriesData.FileType{iview},'civdata')
905            state_InputFields='on';
906        end
907    end
908end
909set(handles.ListView,'Value',val)
910set(handles.ListView,'String',ListViewString)
911if strcmp(state_Pairs,'on')
912    ListView_Callback(hObject,eventdata,handles)
913end
914set(handles.PairString,'Visible',state_Pairs)
915enable_j(handles,state_j)
916
917%------------------------------------------------------------------------
918function num_first_i_Callback(hObject, eventdata, handles)
919%------------------------------------------------------------------------
920num_last_i_Callback(hObject, eventdata, handles)
921
922%------------------------------------------------------------------------
923function num_last_i_Callback(hObject, eventdata, handles)
924%------------------------------------------------------------------------
925SeriesData=get(handles.series,'UserData');
926if ~isfield(SeriesData,'Time')
927    SeriesData.Time{1}=[];
928end
929displ_time(handles);
930
931%------------------------------------------------------------------------
932function num_first_j_Callback(hObject, eventdata, handles)
933%------------------------------------------------------------------------
934 num_last_j_Callback(hObject, eventdata, handles)
935
936%------------------------------------------------------------------------
937function num_last_j_Callback(hObject, eventdata, handles)
938%------------------------------------------------------------------------
939first_j=str2num(get(handles.num_first_j,'String'));
940last_j=str2num(get(handles.num_last_j,'String'));
941ref_j=ceil((first_j+last_j)/2);
942set(handles.num_ref_j,'String', num2str(ref_j))
943num_ref_j_Callback(hObject, eventdata, handles)
944SeriesData=get(handles.series,'UserData');
945if ~isfield(SeriesData,'Time')
946    SeriesData.Time{1}=[];
947end
948displ_time(handles);
949
950%------------------------------------------------------------------------
951% ---- find the times corresponding to the first and last indices of a series
952function displ_time(handles)
953%------------------------------------------------------------------------
954SeriesData=get(handles.series,'UserData');%
955ref_i=[str2num(get(handles.num_first_i,'String')) str2num(get(handles.num_last_i,'String'))];
956ref_j=[str2num(get(handles.num_first_j,'String')) str2num(get(handles.num_last_j,'String'))];
957% last_i=str2num(get(handles.num_last_i,'String'));
958% last_j=str2num(get(handles.num_last_j,'String'));
959TimeTable=get(handles.TimeTable,'Data');
960Pairs=get(handles.PairString,'Data');
961for iview=1:size(TimeTable,1)
962    if size(SeriesData.Time,1)<iview
963        break
964    end
965    i1=ref_i;
966    j1=ref_j;
967    i2=ref_i;
968    j2=ref_j;
969    % case of pairs
970    if ~isempty(Pairs{iview,1})
971        r=regexp(Pairs{iview,1},'(?<mode>(Di=)|(Dj=)) -*(?<num1>\d+)\|(?<num2>\d+)','names');
972        if isempty(r)
973            r=regexp(Pairs{iview,1},'(?<num1>\d+)(?<mode>-)(?<num2>\d+)','names');
974        end
975        switch r.mode
976            case 'Di='  %  case 'series(Di)')
977                i1=ref_i-str2num(r.num1);
978                i2=ref_i+str2num(r.num2);
979            case 'Dj='  %  case 'series(Dj)'
980                j1=ref_j-str2num(r.num1);
981                j2=ref_j+str2num(r.num2);
982            case '-'  % case 'bursts'
983                j1=str2num(r.num1)*ones(size(ref_i));
984                j2=str2num(r.num2)*ones(size(ref_i));
985        end
986    end
987    TimeTable{iview,2}=[];
988    TimeTable{iview,3}=[];
989    if size(SeriesData.Time{iview},1)>=i2(2)&&size(SeriesData.Time{iview},1)>=j2(2)
990        if isempty(ref_j)
991            time_first=(SeriesData.Time{iview}(i1(1))+SeriesData.Time{iview}(i2(1)))/2;
992            time_last=(SeriesData.Time{iview}(i1(2))+SeriesData.Time{iview}(i2(2)))/2;
993        else
994            time_first=(SeriesData.Time{iview}(i1(1),j1(1))+SeriesData.Time{iview}(i2(1),j2(1)))/2;
995            time_last=(SeriesData.Time{iview}(i1(2),j1(2))+SeriesData.Time{iview}(i2(2),j2(2)))/2;
996        end
997        TimeTable{iview,2}=time_first; %TODO: take into account pairs
998        TimeTable{iview,3}=time_last; %TODO: take into account pairs
999    end
1000end
1001set(handles.TimeTable,'Data',TimeTable)
1002
1003%------------------------------------------------------------------------
1004% --- Executes when selected cell(s) is changed in PairString.
1005function PairString_CellSelectionCallback(hObject, eventdata, handles)
1006%------------------------------------------------------------------------   
1007set(handles.ListView,'Value',eventdata.Indices(1))% detect the selected raw index
1008ListView_Callback ([],[],handles) % update the list of available pairs
1009
1010%------------------------------------------------------------------------
1011%------------------------------------------------------------------------
1012%  III - FUNCTIONS ASSOCIATED TO THE FRAME SET PAIRS
1013%------------------------------------------------------------------------
1014%------------------------------------------------------------------------
1015% --- Executes on selection change in ListView.
1016function ListView_Callback(hObject, eventdata, handles)
1017%------------------------------------------------------------------------   
1018SeriesData=get(handles.series,'UserData');
1019i2_series=[];
1020j2_series=[];
1021iview=get(handles.ListView,'Value');
1022if ~isempty(SeriesData.i2_series{iview})
1023    i2_series=SeriesData.i2_series{iview};
1024end
1025if ~isempty(SeriesData.j2_series{iview})
1026    j2_series=SeriesData.j2_series{iview};
1027end
1028update_mode(handles,SeriesData.i1_series{iview},SeriesData.i2_series{iview},...
1029    SeriesData.j1_series{iview},SeriesData.j2_series{iview},SeriesData.Time{iview})
1030
1031%------------------------------------------------------------------------
1032% --- Executes on button press in mode.
1033function mode_Callback(hObject, eventdata, handles)
1034%------------------------------------------------------------------------       
1035SeriesData=get(handles.series,'UserData');
1036iview=get(handles.ListView,'Value');
1037mode_list=get(handles.mode,'String');
1038mode=mode_list{get(handles.mode,'Value')};
1039if isequal(mode,'bursts')
1040    enable_i(handles,'On')
1041    enable_j(handles,'Off') %do not display j index scanning in burst mode (j is fixed by the burst choice)
1042else
1043    enable_i(handles,'On')
1044    enable_j(handles,'Off')
1045end
1046fill_ListPair(handles,SeriesData.i1_series{iview},SeriesData.i2_series{iview},...
1047    SeriesData.j1_series{iview},SeriesData.j2_series{iview},SeriesData.Time{iview})
1048ListPairs_Callback([],[],handles)
1049
1050%-------------------------------------------------------------
1051% --- Executes on selection in ListPairs.
1052function ListPairs_Callback(hObject,eventdata,handles)
1053%------------------------------------------------------------
1054list_pair=get(handles.ListPairs,'String');%get the menu of image pairs
1055if isempty(list_pair)
1056    string='';
1057else
1058    string=list_pair{get(handles.ListPairs,'Value')};
1059    string=regexprep(string,',.*','');%removes time indication (after ',')
1060end
1061PairString=get(handles.PairString,'Data');
1062iview=get(handles.ListView,'Value');
1063PairString{iview,1}=string;
1064% report the selected pair string to the table PairString
1065set(handles.PairString,'Data',PairString)
1066
1067%------------------------------------------------------------------------
1068function num_ref_i_Callback(hObject, eventdata, handles)
1069%------------------------------------------------------------------------
1070mode_list=get(handles.mode,'String');
1071mode=mode_list{get(handles.mode,'Value')};
1072SeriesData=get(handles.series,'UserData');
1073iview=get(handles.ListView,'Value');
1074fill_ListPair(handles,SeriesData.i1_series{iview},SeriesData.i2_series{iview},...
1075    SeriesData.j1_series{iview},SeriesData.j2_series{iview},SeriesData.Time{iview});% update the menu of pairs depending on the available netcdf files
1076ListPairs_Callback([],[],handles)
1077
1078%------------------------------------------------------------------------
1079function num_ref_j_Callback(hObject, eventdata, handles)
1080%------------------------------------------------------------------------
1081num_ref_i_Callback(hObject, eventdata, handles)
1082
1083%------------------------------------------------------------------------
1084function update_mode(handles,i1_series,i2_series,j1_series,j2_series,time)
1085%------------------------------------------------------------------------   
1086check_burst=0;
1087if isempty(j2_series)% no pair menu to display
1088    if isempty(i2_series)
1089        set(handles.mode,'String',{''})
1090    else
1091        set(handles.mode,'Value',1)
1092        set(handles.mode,'String',{'series(Di)'})
1093    end
1094else
1095    nbfield=size(j2_series,1);
1096    nbfield2=size(j2_series,2);
1097    set(handles.mode,'String',{'bursts';'series(Dj)'})
1098    if nbfield2>10 || nbfield==1
1099        set(handles.mode,'Value',2);%set mode to series(Dj) if more than 10 j values
1100    else
1101        set(handles.mode,'Value',1);
1102        check_burst=1;
1103    end
1104end
1105if check_burst
1106    enable_i(handles,'On')
1107    enable_j(handles,'Off') %do not display j index scanning in burst mode (j is fixed by the burst choice)
1108else
1109    enable_i(handles,'On')
1110    enable_j(handles,'On')
1111end
1112fill_ListPair(handles,i1_series,i2_series,j1_series,j2_series,time)
1113ListPairs_Callback([],[],handles)
1114
1115%--------------------------------------------------------------
1116% determine the menu for civ1 pairstring depending on existing netcdf files
1117% with the reference indices num_ref_i and num_ref_j
1118%----------------------------------------------------------------
1119function fill_ListPair(handles,i1_series,i2_series,j1_series,j2_series,time)
1120
1121mode_list=get(handles.mode,'String');
1122mode=mode_list{get(handles.mode,'Value')};
1123ref_i=str2num(get(handles.num_ref_i,'String'));
1124ref_j=str2num(get(handles.num_ref_j,'String'));
1125if isempty(ref_i)
1126    ref_i=1;
1127end
1128if isempty(ref_j)
1129    ref_j=1;
1130end
1131TimeUnit=get(handles.TimeUnit,'String');
1132if length(TimeUnit)>=1
1133    dtunit=['m' TimeUnit];
1134else
1135    dtunit='e-03';
1136end
1137
1138displ_pair={};
1139if strcmp(mode,'series(Di)')
1140    if isempty(i2_series)
1141        msgbox_uvmat('ERROR','no i1-i2 pair available')
1142        return
1143    end
1144    diff_i=i2_series-i1_series;
1145    min_diff=min(diff_i(diff_i>0));
1146    max_diff=max(diff_i(diff_i>0));
1147    for ipair=min_diff:max_diff
1148        if numel(diff_i(diff_i==ipair))>0
1149            pair_string=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ];
1150            if ~isempty(time)
1151                Dt=time(ref_i+ceil(ipair/2),ref_j)-time(ref_i-floor(ipair/2),ref_j);
1152                pair_string=[pair_string ', Dt=' num2str(Dt) ' ' dtunit];
1153            end
1154            displ_pair=[displ_pair;{pair_string}];
1155        end
1156    end
1157    if ~isempty(displ_pair)
1158        displ_pair=[displ_pair;{'Di=*|*'}];
1159    end
1160elseif strcmp(mode,'series(Dj)')
1161    if isempty(j2_series)
1162        msgbox_uvmat('ERROR','no j1-j2 pair available')
1163        return
1164    end
1165    diff_j=j2_series-j1_series;
1166    min_diff=min(diff_j(diff_j>0));
1167    max_diff=max(diff_j(diff_j>0));
1168    for ipair=min_diff:max_diff
1169        if numel(diff_j(diff_j==ipair))>0
1170            pair_string=['Dj= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ];
1171            if ~isempty(time)
1172                Dt=time(ref_i,ref_j+ceil(ipair/2))-time(ref_i,ref_j-floor(ipair/2));
1173                pair_string=[pair_string ', Dt=' num2str(Dt) ' ' dtunit];
1174            end
1175            displ_pair=[displ_pair;{pair_string}];
1176        end
1177    end
1178    if ~isempty(displ_pair)
1179        displ_pair=[displ_pair;{'Dj=*|*'}];
1180    end
1181elseif strcmp(mode,'bursts')
1182    if isempty(j2_series)
1183        msgbox_uvmat('ERROR','no j1-j2 pair available')
1184        return
1185    end
1186    diff_j=j2_series-j1_series;
1187    min_j1=min(j1_series(j1_series>0));
1188    max_j1=max(j1_series(j1_series>0));
1189    min_j2=min(j2_series(j2_series>0));
1190    max_j2=max(j2_series(j2_series>0));
1191    for pair1=min_j1:min(max_j1,min_j1+20)
1192        for pair2=min_j2:min(max_j2,min_j2+20)
1193        if numel(j1_series(j1_series==pair1))>0 && numel(j2_series(j2_series==pair2))>0
1194            displ_pair=[displ_pair;{['j= ' num2str(pair1) '-' num2str(pair2)]}];
1195        end
1196        end
1197    end
1198    if ~isempty(displ_pair)
1199        displ_pair=[displ_pair;{'j=*-*'}];
1200    end
1201end
1202
1203%% display list of pairstring
1204displ_pair_list=get(handles.ListPairs,'String');
1205NewVal=[];
1206if ~isempty(displ_pair_list)
1207Val=get(handles.ListPairs,'Value');
1208NewVal=find(strcmp(displ_pair_list{Val},displ_pair),1);% look at the previous display in the new menu displ_pï¿œir
1209end
1210if ~isempty(NewVal)
1211    set(handles.ListPairs,'Value',NewVal)
1212else
1213    set(handles.ListPairs,'Value',1)
1214end
1215set(handles.ListPairs,'String',displ_pair)
1216
1217%-------------------------------------
1218function enable_i(handles,state)
1219set(handles.i_txt,'Visible',state)
1220set(handles.num_first_i,'Visible',state)
1221set(handles.num_last_i,'Visible',state)
1222set(handles.num_incr_i,'Visible',state)
1223% set(handles.num_MaxIndex_i,'Visible',state)
1224set(handles.num_ref_i,'Visible',state)
1225set(handles.ref_i_text,'Visible',state)
1226
1227%-----------------------------------
1228function enable_j(handles,state)
1229set(handles.j_txt,'Visible',state)
1230% set(handles.num_MinIndex_j,'Visible',state)
1231set(handles.num_first_j,'Visible',state)
1232set(handles.num_last_j,'Visible',state)
1233set(handles.num_incr_j,'Visible',state)
1234% set(handles.num_MaxIndex_j,'Visible',state)
1235set(handles.num_ref_j,'Visible',state)
1236set(handles.ref_j_text,'Visible',state)
1237
1238%-----------------------------------
1239function view_FieldMenu(handles,state)
1240% set(handles.FieldName,'Visible',state)
1241% set(handles.Field_text,'Visible',state)
1242set(handles.InputFields,'Visible',state)
1243
1244%-----------------------------------
1245function view_FieldMenu_1(handles,state)
1246set(handles.FieldName_1,'Visible',state)
1247set(handles.Field_text_1,'Visible',state)
1248
1249
1250%%%%%%%%%%%%%%%%%%%%
1251%%  MAIN ActionName FUNCTIONS
1252%%%%%%%%%%%%%%%%%%%%
1253%------------------------------------------------------------------------
1254% --- Executes on button press in RUN.
1255function RUN_Callback(hObject, eventdata, handles)
1256%------------------------------------------------------------------------
1257set(handles.RUN,'BusyAction','queue');
1258set(0,'CurrentFigure',handles.series)
1259set(handles.RUN, 'Enable','Off')
1260set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784])
1261[h_fun,Series,filexml,errormsg]=prepare_jobs(handles);
1262if ~isempty(errormsg)
1263    msgbox_uvmat('ERROR',errormsg)
1264else
1265   Series.Specific=h_fun(Series,0);   
1266   t=struct2xml(Series);
1267    t=set(t,1,'name','Series');
1268    save(t,filexml);
1269    h_fun(Series);
1270end
1271set(handles.RUN, 'Enable','On')
1272set(handles.RUN,'BackgroundColor',[1 0 0])
1273
1274%------------------------------------------------------------------------
1275function STOP_Callback(hObject, eventdata, handles)
1276%------------------------------------------------------------------------
1277set(handles.RUN, 'BusyAction','cancel')
1278set(handles.RUN,'BackgroundColor',[1 0 0])
1279set(handles.RUN,'enable','on')
1280set(handles.BATCH,'BackgroundColor',[1 0 0])
1281set(handles.BATCH,'enable','on')
1282
1283%------------------------------------------------------------------------
1284% --- Executes on button press in BATCH.
1285function BATCH_Callback(hObject, eventdata, handles)
1286%------------------------------------------------------------------------   
1287set(handles.BATCH, 'Enable','Off')
1288set(handles.BATCH,'BackgroundColor',[0.831 0.816 0.784])
1289[h_fun,Series,filexml,errormsg]=prepare_jobs(handles);
1290if ~isempty(errormsg)
1291    msgbox_uvmat('ERROR',errormsg)
1292    return
1293end
1294% update the xml file after interactive input with the function
1295Series.Specific=h_fun(Series,0);   
1296t=struct2xml(Series);
1297t=set(t,1,'name','Series');
1298save(t,filexml);
1299path_series=fileparts(which('series'));
1300filename_xml=fullfile(Series.OutputDir,[Series.OutputRootFile '.xml']);
1301filename_bat=fullfile(Series.OutputDir,[Series.OutputRootFile '.bat']);
1302[fid,message]=fopen(filename_bat,'w');
1303if isequal(fid,-1)
1304    msgbox_uvmat('ERROR', ['creation of .bat file: ' message]);
1305    return
1306end
1307fctpath=get(handles.ActionPath,'String');
1308text_matlabscript=[...
1309    '#!/bin/bash \n'...
1310    '. /etc/sysprofile \n'...
1311    'matlab -nodisplay -nosplash -nojvm <<END_MATLAB \n'...
1312    'cd(''' path_series '''); \n'...
1313    'addpath(''' fctpath '''); \n'...
1314    '' Series.Action  '( ''' filename_xml '''); \n'...
1315    'exit \n'...
1316    'END_MATLAB \n'];
1317fprintf(fid,text_matlabscript);
1318fclose(fid);
1319if isunix
1320    system(['chmod +x ' filename_bat]);
1321end
1322set(handles.BATCH, 'Enable','On')
1323set(handles.BATCH,'BackgroundColor',[1 0 0])
1324%------------------------------------------------------------------------
1325% --- Executes on button press in BIN.
1326function BIN_Callback(hObject, eventdata, handles)
1327%------------------------------------------------------------------------
1328    cmd=['#!/bin/bash \n '...
1329        '#$ -cwd \n '...
1330        'hostname && date \n '...
1331        'umask 002 \n'...
1332        Param.xml.CivmBin ' ' Param.xml.RunTime ' ' filename_xml ' ' OutputFile '.nc'];
1333   
1334%------------------------------------------------------------------------
1335% --- Main lauch command, called by RUN and BATCH
1336function [h_fun,Series,filexml,errormsg]=prepare_jobs(handles)
1337%------------------------------------------------------------------------
1338errormsg='';
1339%% Read parameters from series
1340Series=read_GUI(handles.series);
1341if isfield(Series,'Pairs')
1342Series=rmfield(Series,'Pairs'); %info Pairs not needed for output
1343end
1344
1345%% read root name and field type
1346first_i=1;
1347last_i=1;
1348incr_i=1;
1349first_j=1;
1350last_j=1;
1351incr_j=1;
1352if isfield(Series.IndexRange,'first_i')
1353    first_i=Series.IndexRange.first_i;
1354    incr_i=Series.IndexRange.incr_i;
1355    last_i=Series.IndexRange.last_i;
1356end
1357if isfield(Series.IndexRange,'first_j')
1358    first_j=Series.IndexRange.first_j;
1359    incr_j=Series.IndexRange.incr_j;
1360    last_j=Series.IndexRange.last_j;
1361end
1362
1363%% read input file parameters and set menus
1364menu_coord_state=get(handles.TransformName,'Visible');
1365if isequal(menu_coord_state,'on')
1366    menu_index=get(handles.TransformName,'Value');
1367    transform_list=get(handles.TransformName,'UserData');
1368    Series.FieldTransform.TransformHandle=transform_list{menu_index};% transform function handles
1369end
1370
1371if last_i < first_i | last_j < first_j , msgbox_uvmat('ERROR','last field number must be larger than the first one'),...
1372    set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
1373
1374%% projection object
1375if isfield(Series,'CheckObject')
1376    if Series.CheckObject
1377        hset_object=findobj(allchild(0),'tag','set_object');
1378        Series.ProjObject=read_GUI(hset_object);
1379        GetObject_Callback([], [], handles)
1380    end
1381else
1382    Series.CheckObject=0;
1383end
1384
1385%% get_field GUI
1386if isfield(Series,'InputFields')&&isfield(Series.InputFields,'Field')
1387    if strcmp(Series.InputFields.Field,'get_field...')
1388        hget_field=findobj(allchild(0),'name','get_field');
1389        Series.GetField=read_GUI(hget_field);
1390    end
1391end
1392
1393%% defining the ActionName function handle
1394list_action=get(handles.ActionName,'String');% list menu action
1395index=get(handles.ActionName,'Value');
1396action= list_action{index}; % selected string
1397Series.Action=action;%name of the processing programme
1398Series.hseries=handles.series; % handles to the series GUI
1399path_series=which('series');
1400list_path=get(handles.ActionName,'UserData');
1401fct_path=list_path{index}; %path stored for the function ACTION
1402if ~isequal(fct_path,path_series)
1403    eval(['spath=which(''' action ''');']) %spath = current path of the selected function ACTION
1404    if ~exist(fct_path,'dir')
1405        errormsg=['The prescibed function path ' fct_path ' does not exist'];
1406        return
1407    end
1408    if ~isequal(spath,fct_path)
1409        addpath(fct_path)% add the prescribed path if not the current one
1410    end
1411end
1412eval(['h_fun=@' action ';'])%create a function handle for ACTION
1413if ~isequal(fct_path,path_series)
1414        rmpath(fct_path)% add the prescribed path if not the current one   
1415end
1416
1417%% create the output data directory and write in it the xml file from the GUI config
1418%determine the root file corresponding to the first sub dir
1419if isfield(Series,'OutputSubDir')
1420    SubDirOut=[Series.OutputSubDir Series.OutputDirExt];
1421    SubDirOutNew=SubDirOut;
1422    iview=1;
1423    SeriesData=get(handles.series,'UserData');
1424    if size(Series.InputTable,1)>1 && isfield(SeriesData,'AllowInputSort') && isfield(SeriesData.AllowInputSort)
1425        [tild,iview]=sort(Series.InputTable(:,2)); %subdirectories sorted in alphabetical order
1426        Series.InputTable=Series.InputTable(iview,:);
1427    end
1428    detect=exist(fullfile(Series.InputTable{1,1},SubDirOutNew),'dir');% test if  the dir  already exist
1429    check_create=1; %need to create the result directory by default
1430    while detect
1431        answer=msgbox_uvmat('INPUT_Y-N',['use existing ouput directory: ' fullfile(Series.InputTable{1,1},SubDirOutNew) ', possibly delete previous data']);
1432        if isequal(answer,'Yes')
1433            detect=0;
1434            check_create=0;
1435        else
1436            r=regexp(SubDirOutNew,'(?<root>.*\D)(?<num1>\d+)$','names');%detect whether name ends by a number
1437            if isempty(r)
1438                r(1).root=[SubDirOutNew '_'];
1439                r(1).num1='0';
1440            end
1441            SubDirOutNew=[r(1).root num2str(str2num(r(1).num1)+1)];%increment the index by 1 or put 1
1442            detect=exist(fullfile(Series.InputTable{1,1},SubDirOutNew),'dir');% test if  the dir  already exists   
1443            check_create=1;
1444        end
1445    end
1446    Series.OutputDirExt=regexprep(SubDirOutNew,Series.OutputSubDir,'');
1447    Series.OutputSubDir=SubDirOutNew;
1448    Series.OutputDir=fullfile(Series.InputTable{1,1},Series.OutputSubDir);%directory set for output results
1449    Series.OutputRootFile=Series.InputTable{1,3};% the first sorted RootFile taken for output
1450    set(handles.OutputDirExt,'String',Series.OutputDirExt)
1451    %removes redondant information
1452    Series=rmfield(Series,'OutputDirExt');
1453    Series.IndexRange=rmfield(Series.IndexRange,'TimeTable');
1454    Series.IndexRange=rmfield(Series.IndexRange,'MinIndex');
1455    Series.IndexRange=rmfield(Series.IndexRange,'MaxIndex');
1456    % create output directory
1457    if check_create
1458        [tild,msg1]=mkdir(Series.OutputDir);
1459        if ~strcmp(msg1,'')
1460            errormsg=['cannot create ' Series.OutputDir ': ' msg1];%error message for directory creation
1461            return
1462        end
1463    end
1464    filexml=fullfile(Series.OutputDir,[Series.InputTable{1,3} '.xml']);% name of the parameter xml file set in this directory
1465    t=struct2xml(Series);
1466    t=set(t,1,'name','Series');
1467    save(t,filexml);
1468end
1469
1470%------------------------------------------------------------------------
1471% --- Executes on selection change in ActionName.
1472function ActionName_Callback(hObject, eventdata, handles)
1473%------------------------------------------------------------------------
1474global nb_builtin_ACTION
1475list_ACTION=get(handles.ActionName,'String');% list menu fields
1476index_ACTION=get(handles.ActionName,'Value');% selected string index
1477ACTION= list_ACTION{index_ACTION}; % selected function name
1478path_series=which('series');%path to series.m
1479list_path=get(handles.ActionName,'UserData');%list of recorded paths to functions of the list ACTION
1480default_file=fullfile(list_path{end},ACTION);
1481% add a new function to the menu if the selected item is 'more...'
1482if isequal(ACTION,'more...')
1483    pathfct=fileparts(path_series);
1484    [FileName, PathName, filterindex] = uigetfile( ...
1485       {'*.m', ' (*.m)';
1486        '*.m',  '.m files '; ...
1487        '*.*', 'All Files (*.*)'}, ...
1488        'Pick a file',default_file);
1489    if length(FileName)<2
1490        return
1491    end
1492    [pp,ACTION,ext_fct]=fileparts(FileName);%(end-1:end);
1493    if ~isequal(ext_fct,'.m')
1494        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
1495        return
1496    end
1497   
1498   % insert the choice in the actionname menu
1499   menu_str=update_menu(handles.ActionName,ACTION);%new action menu in which the new item has been appended if needed
1500   index_ACTION=get(handles.ActionName,'Value');% currently selected index in the list
1501   list_path{index_ACTION}=PathName;
1502   if length(menu_str)>nb_builtin_ACTION+5; %nb_builtin=nbre of functions always remaining in the initial menu
1503       nbremove=length(menu_str)-nb_builtin_ACTION-5;
1504       menu_str(nb_builtin_ACTION+1:end-5)=[];
1505       list_path(nb_builtin_ACTION+1:end-4)=[];
1506       index_ACTION=index_ACTION-nbremove;
1507       set(handles.ActionName,'Value',index_ACTION)
1508       set(handles.ActionName,'String',menu_str)
1509   end
1510   list_path{index_ACTION}=PathName;
1511   set(handles.ActionName,'UserData',list_path);
1512   set(handles.ActionPath,'enable','inactive')% indicate that the current path is accessible (not 'off')
1513   
1514   %record the current menu in personal file profil_perso
1515   dir_perso=prefdir;
1516   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1517   for ilist=nb_builtin_ACTION+1:length(menu_str)-1
1518       series_fct{ilist-nb_builtin_ACTION}=fullfile(list_path{ilist},[menu_str{ilist} '.m']);     
1519   end
1520   if nb_builtin_ACTION+1<=length(menu_str)-1
1521       if exist(profil_perso,'file')% && nb_builtin_ACTION+1>=length(menu_str)-1
1522           save(profil_perso,'series_fct','-append')
1523       else
1524           txt=ver('MATLAB');
1525           Release=txt.Release;
1526           relnumb=str2num(Release(3:4));
1527           if relnumb >= 14%recent relaese of Matlab
1528               save(profil_perso,'series_fct','-V6')
1529           else
1530               save(profil_perso, 'series_fct')
1531           end
1532       end
1533   end
1534end
1535
1536%check the current ActionPath to the selected function
1537PathName=list_path{index_ACTION};%current recorded path
1538set(handles.ActionPath,'String',PathName); %show the path to the senlected function
1539
1540%default setting for the visibility of the GUI elements
1541set(handles.num_NbSlice,'Visible','off')
1542set(handles.NbSlice_title,'Visible','off')
1543set(handles.VelType,'Visible','off');
1544set(handles.VelType_text,'Visible','off');
1545set(handles.VelType_1,'Visible','off');
1546set(handles.VelType_text_1,'Visible','off');
1547view_FieldMenu(handles,'off')
1548view_FieldMenu_1(handles,'off')
1549set(handles.FieldTransform,'Visible','off')
1550set(handles.CheckObject,'Visible','off');
1551set(handles.ProjObject,'Visible','off');
1552set(handles.CheckMask,'Visible','off')
1553set(handles.Mask,'Visible','off')
1554% set(handles.OutputDirExt,'Visible','off');
1555set(handles.ParamKey,'Visible','off')
1556set(handles.ParamVal,'Visible','off')
1557ParamKey={};
1558set(handles.FieldName,'Enable','off')
1559set(handles.VelType,'Enable','off')
1560set(handles.FieldName_1,'Enable','off')
1561set(handles.VelType_1,'Enable','off')
1562set(handles.TransformName,'Enable','off')
1563set(handles.OutputDirExt,'Visible','off')
1564set(handles.OutputSubDir,'Visible','off')
1565set(handles.OutputDir_title,'Visible','off')
1566%set the displayed GUI item needed for input parameters
1567if ~isequal(path_series,PathName)
1568    addpath(PathName)
1569end
1570eval(['h_function=@' ACTION ';']);
1571try
1572    [fid,errormsg] =fopen([ACTION '.m']);
1573    InputText=textscan(fid,'%s',1,'delimiter','\n');
1574    fclose(fid)
1575    set(handles.ActionName,'ToolTipString',InputText{1}{1})
1576end
1577if ~isequal(path_series,PathName)
1578    rmpath(PathName)
1579end
1580varargout=h_function();
1581Param_list={};
1582
1583InputTable=get(handles.InputTable,'Data');
1584nb_series=size(InputTable,1);
1585testima_series=1; %test for a list of images only
1586testima=1;
1587testima_1=1;
1588testciv_series=1;
1589for iview=1:nb_series
1590     ext=InputTable{iview,5};
1591    if length(ext)<2
1592        ext='.none';
1593    end
1594    testimaview=~isempty(imformats(ext(2:end))) || isequal(lower(ext),'.avi');
1595    if ~testimaview
1596        if iview==1
1597            testima=0;
1598        end
1599        if iview==2
1600            testima_1=0;
1601        end
1602        testima_series=0;
1603    end
1604end
1605for ilist=1:length(varargout)-1
1606    switch varargout{ilist}
1607        case 'NbViewMax'
1608            if ~isempty (varargout{ilist+1})
1609                if size(InputTable,1)>varargout{ilist+1}
1610                InputTable=InputTable(1:varargout{ilist+1},:);
1611                set(handles.InputTable,'Data',InputTable)
1612                end
1613            end
1614        case 'AllowInputSort'
1615            if isequal(lower(varargout{ilist+1}),'on')% sort the input table by alphabetical order of the SubDir
1616                SeriesData=get(handles.series,'UserData');
1617                SeriesData.AllowInputSort=1;
1618                set(handles.series,'UserData',SeriesData)
1619            end             
1620        case 'NbSlice'   %hidden by default
1621            if isequal(lower(varargout{ilist+1}),'on')
1622                set(handles.num_NbSlice,'Visible','on')
1623                set(handles.NbSlice_title,'Visible','on')
1624            end
1625        case 'VelType'   %hidden by default
1626             if isequal(lower(varargout{ilist+1}),'one') || isequal(lower(varargout{ilist+1}),'two')
1627                set(handles.VelType,'Enable','on')
1628                if nb_series >=1 && ~testima_series
1629                    set(handles.VelType,'Visible','on')
1630                    set(handles.VelType_text,'Visible','on');
1631                end
1632             end
1633            if isequal(lower(varargout{ilist+1}),'two')
1634                set(handles.VelType_1,'Enable','on')
1635                if nb_series >=2 && ~testima_series
1636                    set(handles.VelType_1,'Visible','on')
1637                    set(handles.VelType_text_1,'Visible','on');
1638                end
1639            end
1640        case 'FieldName'   %hidden by default
1641            if isequal(lower(varargout{ilist+1}),'one')||isequal(lower(varargout{ilist+1}),'two')
1642                set(handles.FieldName,'Enable','on') % test for MenuBorser
1643                if nb_series >=1 && ~testima_series
1644                    view_FieldMenu(handles,'on')
1645                end
1646            end
1647            if isequal(lower(varargout{ilist+1}),'two')
1648                set(handles.FieldName_1,'Enable','on')
1649                if nb_series >=2 && ~testima_1
1650                    view_FieldMenu_1(handles,'on')
1651                end
1652            end
1653        case 'FieldTransform'   %hidden by default
1654            if isequal(lower(varargout{ilist+1}),'on')
1655                set(handles.TransformName,'Enable','on')
1656                set(handles.FieldTransform,'Visible','on')
1657            end
1658        case 'ProjObject'   %hidden by default
1659            if isequal(lower(varargout{ilist+1}),'on')   
1660                set(handles.CheckObject,'Visible','on')
1661                set(handles.ProjObject,'Visible','on')
1662            end
1663        case 'Mask'   %hidden by default
1664            if isequal(lower(varargout{ilist+1}),'on')   
1665                set(handles.Mask,'Visible','on')
1666                 set(handles.CheckMask,'Visible','on');
1667            end
1668        case 'PARAMETER'  % NOT USED
1669            set(handles.PARAMETERS_frame,'Visible','on')
1670            set(handles.PARAMETERS_title,'Visible','on')
1671            set(handles.ParamKey,'Visible','on')
1672            %set(handles.ParamVal,'Visible','on')
1673            Param_str=varargout{ilist+1};
1674            Param_list=[Param_list; {Param_str}];   
1675        case 'OutputDirExt'
1676            if ~isempty(varargout{ilist+1})
1677            set(handles.OutputDirExt,'String',varargout{ilist+1})
1678            set(handles.OutputDirExt,'Visible','on')
1679            set(handles.OutputSubDir,'Visible','on')
1680            set(handles.OutputDir_title,'Visible','on') 
1681            end
1682    end
1683end
1684if ~isempty(Param_list)
1685    set(handles.ParamKey,'String',Param_list)
1686    set(handles.ParamVal,'Visible','on')
1687end
1688
1689%------------------------------------------------------------------------
1690% --- Executes on selection change in FieldName.
1691function FieldName_Callback(hObject, eventdata, handles)
1692%------------------------------------------------------------------------
1693field_str=get(handles.FieldName,'String');
1694field_index=get(handles.FieldName,'Value');
1695field=field_str{field_index(1)};
1696if isequal(field,'get_field...')   
1697     hget_field=findobj(allchild(0),'name','get_field');
1698     if ~isempty(hget_field)
1699         delete(hget_field)%delete opened versions of get_field
1700     end
1701     filecell=get_file_series(read_GUI(handles.series));
1702     if exist(filecell{1,1},'file')
1703        get_field(filecell{1,1})
1704     end
1705elseif isequal(field,'more...')
1706    str=calc_field;
1707    [ind_answer,v] = listdlg('PromptString','Select a file:',...
1708                'SelectionMode','single',...
1709                'ListString',str);
1710       % edit the choice in the fields and actionname menu
1711     scalar=cell2mat(str(ind_answer));
1712     update_menu(handles.FieldName,scalar)
1713end
1714
1715%------------------------------------------------------------------------
1716% --- Executes on selection change in FieldName_1.
1717function FieldName_1_Callback(hObject, eventdata, handles)
1718%------------------------------------------------------------------------
1719field_str=get(handles.FieldName_1,'String');
1720field_index=get(handles.FieldName_1,'Value');
1721field=field_str{field_index};
1722if isequal(field,'get_field...')   
1723     hget_field=findobj(allchild(0),'name','get_field_1');
1724     if ~isempty(hget_field)
1725         delete(hget_field)
1726     end
1727     SeriesData=get(handles.series,'UserData');
1728     filename=SeriesData.CurrentInputFile_1;
1729     if exist(filename,'file')
1730        hget_field=get_field(filename);
1731        set(hget_field,'name','get_field_1')
1732     end
1733elseif isequal(field,'more...')
1734    str=calc_field;
1735    [ind_answer,v] = listdlg('PromptString','Select a file:',...
1736                'SelectionMode','single',...
1737                'ListString',str);
1738       % edit the choice in the fields and actionname menu
1739     scalar=cell2mat(str(ind_answer));
1740     update_menu(handles.FieldName_1,scalar)
1741end   
1742
1743
1744%%%%%%%%%%%%%
1745function [ind_remove]=find_pairs(dirpair,ind_i,last_i)
1746indsel=ind_i;
1747indiff=diff(ind_i); %test index increment to detect multiplets (several pairs with the same index ind_i) and holes in the series
1748indiff=[1 indiff last_i-ind_i(end)+1];%for testing gaps with the imposed bounds
1749if ~isempty(indiff)
1750    indiff2=diff(indiff);
1751    indiffp=[indiff2 1];
1752    indiffm=[1 indiff2];
1753    ind_multi_m=find((indiff==0)&(indiffm<0))-1;%indices of first members of multiplets
1754    ind_multi_p=find((indiff==0)&(indiffp>0));%indices of last members of multiplets
1755    %for each multiplet, select the most recent file
1756    ind_remove=[];
1757    for i=1:length(ind_multi_m)
1758        ind_pairs=ind_multi_m(i):ind_multi_p(i);
1759        for imulti=1:length(ind_pairs)
1760            datepair(imulti)=datenum(dirpair(ind_pairs(imulti)).date);%dates of creation
1761        end
1762        [datenew,indsort2]=sort(datepair); %sort the multiplet by creation date
1763        ind_s=indsort2(1:end-1);%
1764        ind_remove=[ind_remove ind_pairs(ind_s)];%remove these indices, leave the last one
1765    end
1766end
1767
1768%------------------------------------------------------------------------
1769% --- determine the list of index pairstring of processing file
1770function [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)
1771%------------------------------------------------------------------------
1772num_i1=num_i;% set of first image numbers by default
1773num_i2=num_i;
1774num_j1=num_j;
1775num_j2=num_j;
1776num_i_out=num_i;
1777num_j_out=num_j;
1778% if isequal (NomType,'_1-2_1') || isequal (NomType,'_1-2')
1779if isequal(mode,'series(Di)')
1780    num_i1_line=num_i+ind_shift(3);% set of first image numbers
1781    num_i2_line=num_i+ind_shift(4);
1782    % adjust the first and last field number
1783        indsel=find(num_i1_line >= 1);
1784    num_i_out=num_i(indsel);
1785    num_i1_line=num_i1_line(indsel);
1786    num_i2_line=num_i2_line(indsel);
1787    num_j1=meshgrid(num_j,ones(size(num_i1_line)));
1788    num_j2=meshgrid(num_j,ones(size(num_i1_line)));
1789    [xx,num_i1]=meshgrid(num_j,num_i1_line);
1790    [xx,num_i2]=meshgrid(num_j,num_i2_line);
1791elseif isequal (mode,'series(Dj)')||isequal (mode,'bursts')
1792    if isequal(mode,'bursts') %case of bursts (png_old or png_2D)
1793        num_j1=ind_shift(1)*ones(size(num_i));
1794        num_j2=ind_shift(2)*ones(size(num_i));
1795    else
1796        num_j1_col=num_j+ind_shift(1);% set of first image numbers
1797        num_j2_col=num_j+ind_shift(2);
1798        % adjust the first field number
1799        indsel=find((num_j1_col >= 1));   
1800        num_j_out=num_j(indsel);
1801        num_j1_col=num_j1_col(indsel);
1802        num_j2_col=num_j2_col(indsel);
1803        [num_i1,num_j1]=meshgrid(num_i,num_j1_col);
1804        [num_i2,num_j2]=meshgrid(num_i,num_j2_col);
1805    end   
1806end
1807
1808%------------------------------------------------------------------------
1809% --- Executes on button press in CheckObject.
1810function CheckObject_Callback(hObject, eventdata, handles)
1811%------------------------------------------------------------------------
1812% SeriesData=get(handles.series,'UserData');
1813value=get(handles.CheckObject,'Value');
1814if value
1815     set(handles.CheckObject,'BackgroundColor',[1 1 0])%put unactivated buttons to yellow
1816     hset_object=findobj(allchild(0),'tag','set_object');%find the set_object interface handle
1817     if ishandle(hset_object)
1818         uistack(hset_object,'top')% show the GUI set_object if opened
1819     else
1820         %get the object file
1821         InputTable=get(handles.InputTable,'Data');
1822         defaultname=InputTable{1,1};
1823         if isempty(defaultname)
1824            defaultname={''};
1825         end
1826        [FileName, PathName, filterindex] = uigetfile( ...
1827       {'*.xml;*.mat', ' (*.xml,*.mat)';
1828       '*.xml',  '.xml files '; ...
1829        '*.mat',  '.mat matlab files '}, ...
1830        'Pick an xml object file (or use uvmat to create it)',defaultname);
1831        fileinput=[PathName FileName];%complete file name
1832        sizf=size(fileinput);
1833        if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
1834        %read the file
1835        data=xml2struct(fileinput);
1836        if ~isfield(data,'Type')
1837             msgbox_uvmat('ERROR',[fileinput ' is not an object xml file'])
1838             return
1839        end
1840        if ~isfield(data,'ProjMode')
1841             data.ProjMode='none';
1842        end
1843        hset_object=set_object(data);% call the set_object interface
1844     end
1845     Object=read_GUI(hset_object);
1846     set(handles.ProjObject,'String',Object.Name);%display the object name
1847else
1848    set(handles.CheckObject,'BackgroundColor',[0.7 0.7 0.7])%put activated buttons to green
1849end
1850%set(handles.series,'UserData',SeriesData)
1851
1852%--------------------------------------------------------------
1853function CheckMask_Callback(hObject, eventdata, handles)
1854value=get(handles.CheckMask,'Value');
1855if value
1856    msgbox_uvmat('ERROR','not implemented yet')
1857end
1858%--------------------------------------------------------------
1859
1860%-------------------------------------------------------------------
1861%'uv_ncbrowser': interactively calls the netcdf file browser 'get_field.m'
1862function ncbrowser_uvmat(hObject, eventdata)
1863%-------------------------------------------------------------------
1864     bla=get(gcbo,'String');
1865     ind=get(gcbo,'Value');
1866     filename=cell2mat(bla(ind));
1867      blank=find(filename==' ');
1868      filename=filename(1:blank-1);
1869     get_field(filename)
1870
1871% ------------------------------------------------------------------
1872function MenuHelp_Callback(hObject, eventdata, handles)
1873%-------------------------------------------------------------------
1874path_to_uvmat=which ('uvmat');% check the path of uvmat
1875pathelp=fileparts(path_to_uvmat);
1876helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
1877if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
1878else
1879    addpath (fullfile(pathelp,'uvmat_doc'))
1880    web([helpfile '#series'])
1881end
1882
1883%-------------------------------------------------------------------
1884% --- Executes on selection change in TransformName.
1885function TransformName_Callback(hObject, eventdata, handles)
1886%-------------------------------------------------------------------
1887global nb_transform
1888
1889menu=get(handles.TransformName,'String');
1890ind_coord=get(handles.TransformName,'Value');
1891coord_option=menu{ind_coord};
1892list_transform=get(handles.TransformName,'UserData');
1893ff=functions(list_transform{end});
1894if isequal(coord_option,'more...');
1895    coord_fct='';
1896    prompt = {'Enter the name of the transform function'};
1897    dlg_title = 'user defined transform';
1898    num_lines= 1;
1899    [FileName, PathName, filterindex] = uigetfile( ...
1900       {'*.m', ' (*.m)';
1901        '*.m',  '.m files '; ...
1902        '*.*', 'All Files (*.*)'}, ...
1903        'Pick a file', ff.file);
1904    if isequal(PathName(end),'/')||isequal(PathName(end),'\')
1905        PathName(end)=[];
1906    end
1907    transform_selected =fullfile(PathName,FileName);
1908    if ~exist(transform_selected,'file')
1909          return
1910    end
1911    [ppp,transform,xt_fct]=fileparts(FileName);% removes extension .m
1912    if ~isequal(ext_fct,'.m')
1913        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
1914        return
1915    end
1916   menu=update_menu(handles.TransformName,transform);%add the selected fct to the menu
1917   ind_coord=get(handles.TransformName,'Value');
1918   addpath(PathName)
1919   list_transform{ind_coord}=str2func(transform);% create the function handle corresponding to the newly seleced function
1920   set(handles.TransformName,'UserData',list_transform)
1921   rmpath(PathName)
1922   % save the new menu in the personal file 'uvmat_perso.mat'
1923   dir_perso=prefdir;%personal Matalb directory
1924   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1925   if exist(profil_perso,'file')
1926       for ilist=nb_transform+1:numel(list_transform)
1927           ff=functions(list_transform{ilist});
1928           transform_fct{ilist-nb_transform}=ff.file;
1929       end
1930        save (profil_perso,'transform_fct','-append'); %store the root name for future opening of uvmat
1931   end
1932end
1933
1934%check the current ActionPath to the selected function
1935if ~isempty(list_transform{ind_coord})
1936func=functions(list_transform{ind_coord});
1937set(handles.TransformPath,'String',fileparts(func.file)); %show the path to the senlected function
1938else
1939   set(handles.TransformPath,'String',''); %show the path to the senlected function
1940end
1941
1942% %------------------------------------------------------------------------
1943% % --- Executes on button press in REFRESH_INDICES.
1944%     function REFRESH_INDICES_Callback(hObject, eventdata, handles)
1945% %------------------------------------------------------------------------       
1946% % hObject    handle to REFRESH_INDICES (see GCBO)
1947% % eventdata  reserved - to be defined in a future version of MATLAB
1948% % handles    structure with handles and user data (see GUIDATA)
1949% set(handles.REFRESH_INDICES,'BackgroundColor',[0.7 0.7 0.7])
1950% InputTable=get(handles.InputTable,'Data');
1951% check_lines=get(handles.REFRESH_INDICES,'UserData');
1952%
1953% %% check the indices and FileTypes for each series (limited to the new ones to save time)
1954% for ind_list=1:length(check_lines)
1955%     if  check_lines(ind_list)
1956%         InputLine=InputTable(ind_list,:);
1957%         detect_idem=strcmp('"',InputLine);% look for '" (repeat of previous data)
1958%         detect_idem=detect_idem(detect_idem>0);
1959%         if ~isempty (detect_idem)
1960%             InputLine(detect_idem)=InputTable(ind_list-1,detect_idem);
1961%             set(handles.InputTable,'Data',InputTable)
1962%         end
1963%         fileinput=fullfile_uvmat(InputLine{1},InputLine{2},InputLine{3},InputLine{5},InputLine{4},1,2,1,2);
1964%         %fileinput=name_generator(fullfile(InputLine{1},InputLine{3}),1,1,InputLine{5},InputLine{4},1,2,2,InputLine{2})
1965%         %update file series defined by the selected line
1966%         [InputTable{ind_list,3},InputTable{(ind_list),4},errormsg]=update_indices(handles,fileinput,ind_list);
1967%         if ~isempty(errormsg)
1968%                 msgbox_uvmat('ERROR',errormsg)
1969%                 return
1970%         end
1971%     end
1972% end
1973% set(handles.InputTable,'Data',InputTable)
1974% SeriesData=get(handles.series,'UserData');
1975%
1976% state_j='off';
1977% state_Pairs='off';
1978% state_InputFields='off';
1979% val=get(handles.ListView,'Value');
1980% ListViewString={''};
1981% if ~isempty(SeriesData)
1982% %     ListViewString={};
1983%     for iview=1:size(InputTable,1)
1984%         if ~isempty(SeriesData.j1_series{iview})
1985%             state_j='on';
1986%         end
1987%         if ~isempty(SeriesData.i2_series{iview})||~isempty(SeriesData.j2_series{iview})
1988%             state_Pairs='on';
1989%             ListViewString{iview}=num2str(iview);
1990%             if check_lines(iview)
1991%                 val=iview;%select the last pair if it is a new entry
1992%             end
1993%         end
1994%         if strcmp(SeriesData.FileType{iview},'civx')||strcmp(SeriesData.FileType{iview},'civdata')
1995%             state_InputFields='on';
1996%         end
1997%     end
1998% end
1999% set(handles.ListView,'Value',val)
2000% set(handles.ListView,'String',ListViewString)
2001% if strcmp(state_Pairs,'on')
2002%     ListView_Callback(hObject,eventdata,handles)
2003% end
2004% set(handles.PairString,'Visible',state_Pairs)
2005% enable_j(handles,state_j)
2006% set(handles.REFRESH_INDICES,'BackgroundColor',[1 0 0])
2007% set(handles.REFRESH_INDICES,'visible','off')
2008
2009% -----------------------------------------------------------------------
2010% --- Update min and max indices of a file series by scanning with find_file_series
2011% --- which also changes the root file and NomType in case of movie. Also adjust the string representation of indices (e.g;
2012% --- 1 or 001 by the function find_file_series
2013% --- This function also dispaly the set of availbale files in the series
2014% --- and the menus appropriate to the file type as well as timing possibly set
2015% --- by an xml image documentation file
2016function [RootFile,NomType,errormsg]=update_indices(handles,fileinput,iview)
2017% -----------------------------------------------------------------------
2018%% look for min and max indices existing in the file series and update SeriesData
2019errormsg='';
2020[FilePath,FileName,FileExt]=fileparts(fileinput);
2021% detect the file type, get the movie object if relevant, and look for the corresponding file series:
2022% the root name and indices may be corrected by including the first index i1 if a corresponding xml file exists
2023[RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,NomType,FileType,Object,i1,i2,j1,j2]=find_file_series(FilePath,[FileName FileExt]);
2024if isempty(RootFile)&&isempty(i1_series)
2025    errormsg='no input file in the series';
2026    return
2027end
2028
2029%% adjust the min and max indices common to all the file series
2030MinIndex=get(handles.MinIndex,'Data');
2031MaxIndex=get(handles.MaxIndex,'Data');
2032MinIndex_i=min(i1_series(i1_series>0));
2033if ~isempty(i2_series)
2034    MaxIndex_i=max(i2_series(i2_series>0));
2035else
2036    MaxIndex_i=max(i1_series(i1_series>0));
2037end
2038MinIndex_j=min(j1_series(j1_series>0));
2039if ~isempty(j2_series)
2040    MaxIndex_j=max(j2_series(j2_series>0));
2041else
2042    MaxIndex_j=max(j1_series(j1_series>0));
2043end
2044MinIndex{iview,1}=MinIndex_i;
2045MinIndex{iview,2}=MinIndex_j;
2046MaxIndex{iview,1}=MaxIndex_i;
2047MaxIndex{iview,2}=MaxIndex_j;
2048set(handles.MinIndex,'Data',MinIndex)
2049set(handles.MaxIndex,'Data',MaxIndex)
2050SeriesData=get(handles.series,'UserData');
2051SeriesData.i1_series{iview}=i1_series;
2052SeriesData.i2_series{iview}=i2_series;
2053SeriesData.j1_series{iview}=j1_series;
2054SeriesData.j2_series{iview}=j2_series;
2055SeriesData.FileType{iview}=FileType;
2056
2057%% display the set of existing files as an image
2058set(handles.waitbar_frame,'Units','pixels')
2059pos=get(handles.waitbar_frame,'Position');
2060xima=0.5:pos(3)-0.5;% pixel positions on the image representing the existing file indices
2061yima=0.5:pos(4)-0.5;
2062[XIma,YIma]=meshgrid(xima,yima);
2063nb_i=size(i1_series,1);
2064nb_j=size(i1_series,2);
2065ind_i=(0.5:nb_i-0.5)*pos(3)/nb_i;
2066ind_j=(0.5:nb_j-0.5)*pos(4)/nb_j;
2067[Ind_i,Ind_j]=meshgrid(ind_i,ind_j);
2068CData=zeros([size(XIma) 3]);
2069file_ima=double((i1_series(:,:,1)>0)');
2070if numel(file_ima)>=2
2071if size(file_ima,1)==1
2072    CLine=interp1(ind_i,file_ima,xima,'nearest');
2073    CData(:,:,2)=ones(size(yima'))*CLine;
2074else
2075    CData(:,:,2)=interp2(Ind_i,Ind_j,file_ima,XIma,YIma,'nearest');
2076end
2077set(handles.waitbar_frame,'CData',CData)
2078end
2079set(handles.waitbar_frame,'Units','normalized')
2080
2081%% enable field and veltype menus
2082testfield=isequal(get(handles.FieldName,'enable'),'on');
2083testfield_1=isequal(get(handles.FieldName_1,'enable'),'on');
2084testveltype=isequal(get(handles.VelType,'enable'),'on');
2085testveltype_1=isequal(get(handles.VelType_1,'enable'),'on');
2086testtransform=isequal(get(handles.TransformName,'Enable'),'on');
2087% testnc=0;
2088% testnc_1=0;
2089% testcivx=0;
2090% testcivx_1=0;
2091% testima=0; %test for image input
2092% if isequal(lower(FileExt),'.avi') %.avi file
2093%     testima=1;
2094% elseif ~isempty(imformats(FileExt(2:end)))
2095%     testima=1;
2096% elseif isequal(FileExt,'.vol')
2097%      testima=1;
2098% end
2099%TODO: update
2100% if length(FileExtCell)==1 || length(FileExtCell)>2
2101%     for iview=1:length(FileExtCell)
2102%         if isequal(FileExtCell{iview},'.nc')
2103%             testnc=1;
2104%         end
2105%         if isequal(FileTypeCell{iview},'civx')
2106%             testcivx=1;
2107%         end
2108%     end
2109% elseif length(FileExtCell)==2
2110%     testnc=isequal(FileExtCell{1},'.nc');
2111%     testnc_1=isequal(FileExtCell{2},'.nc');
2112%     testcivx=isequal(FileTypeCell{1},'civx');
2113%     testcivx_1=isequal(FileTypeCell{2},'civx');
2114% end
2115switch FileType
2116    case {'civx','civdata'}
2117    view_FieldMenu(handles,'on')
2118    menustr=get(handles.FieldName,'String');
2119    if isequal(menustr,{'get_field...'})
2120        set(handles.FieldName,'String',{'get_field...';'velocity';'vort';'div';'more...'})
2121    end
2122    set(handles.VelType,'Visible','on')
2123    set(handles.FieldTransform,'Visible','on')
2124    %      view_TRANSFORM(handles,'on')
2125    %     TODO: second menu
2126    %           view_FieldMenu_1(handles,'on')
2127    %     if testcivx_1
2128    %         menustr=get(handles.FieldName_1,'String');
2129    %         if isequal(menustr,{'get_field...'})
2130    %             set(handles.FieldName_1,'String',{'get_field...';'velocity';'vort';'div';'more...'})
2131    %         end
2132    %     else
2133    %         set(handles.FieldName_1,'Value',1)
2134    %         set(handles.FieldName_1,'String',{'get_field...'})
2135    %     set(handles.VelType_1,'Visible','on')
2136    %     set(handles.VelType_text_1,'Visible','on');
2137    %     end
2138    %     view_FieldMenu_1(handles,'off')
2139    case 'netcdf'
2140    view_FieldMenu(handles,'on')
2141    set(handles.FieldName,'Value',1)
2142    set(handles.FieldName,'String',{'get_field...'})
2143    set(handles.FieldTransform,'Visible','off')
2144    %     view_TRANSFORM(handles,'off')
2145    case {'image','multimage','video'}
2146    view_FieldMenu(handles,'off')
2147    view_FieldMenu_1(handles,'off')
2148    set(handles.VelType,'Visible','off')
2149    set(handles.VelType_text,'Visible','off');
2150end
2151
2152
2153%TODO:update
2154% if ~isequal(FileExt,'.nc') && ~isequal(FileExt,'.cdf') && ~testima
2155%     msgbox_uvmat('ERROR',['invalid input file extension ' FileExt])
2156%     return
2157% end 
2158
2159%%  read image documentation file  if found%%%%%%%%%%%%%%%%%%%%%%%%%%%
2160ext_imadoc='';
2161FileBase=fullfile(RootPath,RootFile);
2162if isequal(FileExt,'.xml')||isequal(FileExt,'.civ')
2163    ext_imadoc=FileExt;
2164elseif exist([FileBase '.xml'],'file')
2165    ext_imadoc='.xml';
2166elseif exist([FileBase '.civ'],'file')
2167    ext_imadoc='.civ';
2168end
2169%read the ImaDoc file
2170XmlData=[];
2171NbSlice_calib={};
2172if isequal(ext_imadoc,'.xml')
2173        [XmlData,warntext]=imadoc2struct([FileBase '.xml']);
2174        if isfield(XmlData,'Heading') && isfield(XmlData.Heading,'ImageName') && ischar(XmlData.Heading.ImageName)
2175            [PP,FF,ext_ima_read]=fileparts(XmlData.Heading.ImageName);
2176        end
2177        if isfield(XmlData,'Time')
2178            time{iview}=XmlData.Time;
2179        end
2180        if isfield(XmlData,'Camera')
2181            if isfield(XmlData.Camera,'NbSlice')&& ~isempty(XmlData.Camera.NbSlice)
2182                NbSlice_calib{iview}=XmlData.Camera.NbSlice;% Nbre of slices for Zindex in phys transform
2183                if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
2184                    msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
2185                end
2186            end
2187            if isfield(XmlData.Camera,'TimeUnit')&& ~isempty(XmlData.Camera.TimeUnit)
2188                TimeUnit=XmlData.Camera.TimeUnit;
2189            end
2190        end
2191        if ~isempty(warntext)
2192            msgbox_uvmat('WARNING',warntext)
2193        end 
2194elseif isequal(ext_imadoc,'.civ')
2195    [error,XmlData.Time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([FileBase '.civ']);
2196    time{iview}=XmlData.Time;
2197    if error==2, warntext=['no file ' FileBase '.civ'];
2198    elseif error==1, warntext='inconsistent number of fields in the .civ file';
2199    end 
2200end
2201
2202%% update time table
2203TimeTable=get(handles.TimeTable,'Data');
2204TimeTable{iview,1}=time(MinIndex_i,MinIndex_j);
2205TimeTable{iview,4}=time(MaxIndex_i,MaxIndex_j);
2206set(handles.TimeTable,'Data',TimeTable)
2207
2208%% number of slices
2209if isfield(XmlData,'GeometryCalib') && isfield(XmlData.GeometryCalib,'SliceCoord')
2210       siz=size(XmlData.GeometryCalib.SliceCoord);
2211       if siz(1)>1
2212           NbSlice=siz(1);
2213       else
2214           NbSlice=1;
2215       end
2216       set(handles.num_NbSlice,'String',num2str(NbSlice))
2217end
2218% set(handles.mode,'Visible','off') % do not show index pairstring by default
2219set(handles.PairString,'Visible','off')
2220% set(handles.num_ref_i,'Visible','off')
2221% set(handles.ref_i_text,'Visible','off')
2222testpair=0;
2223%set the menus of image pairstring and default selection for series
2224%list pairstring if relevant
2225% Val=get(handles.NomType,'Value');
2226% synchronise_view(handles,Val)
2227
2228% if ~isfield(SeriesData,'j1_series')||isempty(SeriesData.j1_series{index})
2229%     state_j='off'; %no need for j index
2230% else
2231%     state_j='on'; %case of j index
2232% end
2233% show index pairstring if files exist
2234set(handles.series,'UserData',SeriesData)
2235
2236
2237% --------------------------------------------------------------------
2238function MenuExportConfig_Callback(hObject, eventdata, handles)
2239global Series
2240[tild,Series,errormsg]=prepare_jobs(handles);
2241% Series=read_GUI(handles.series);
2242
2243evalin('base','global Series')%make CurData global in the workspace
2244display('current series config :')
2245evalin('base','Series') %display CurData in the workspace
2246commandwindow; %brings the Matlab command window to the front
Note: See TracBrowser for help on using the repository browser.