source: trunk/src/series.m @ 450

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

various bugs repaired

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