source: trunk/src/series.m @ 458

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

bugs corrected in series

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