source: trunk/src/series.m @ 405

Last change on this file since 405 was 399, checked in by sommeria, 13 years ago

implementation of thin plate interpolation (proj on planes with mode 'filter'), rationalisation of variable formats in civ_matlab

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