source: trunk/src/series.m @ 41

Last change on this file since 41 was 41, checked in by sommeria, 11 years ago

-relabel_i_j: improve the question dlg box for image transform
-aver_stat,time_series,merge_proj: include modification of field transform and call of set_object.
-series: introduce a browser for set_object
-ima2vol: create volume images (png images of a slice concacened along y) for PIV 3D
-set_object: suppress TITLE, introduce Tooltip helps for parameters
-civ: fixed bug on BATCH sequences

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