source: trunk/src/series.m @ 39

Last change on this file since 39 was 39, checked in by sommeria, 14 years ago

civ: bug corrected for civ in batch
series and uvmat: further improvement and debugging for the menu of field transforms

File size: 87.9 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% --- Executes on button press in RUN.
1299%------------------------------------------------------
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');
1313if 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
1319end
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    Series.CoordType=menu_coord{menu_index};
1363end
1364Series.hseries=get(hObject,'Parent');
1365if isequal(get(handles.ParamVal,'Visible'),'on')
1366    ParamKey=get(handles.ParamKey,'String');
1367    if ischar(ParamKey)
1368        ParamKey{1}=ParamKey;
1369    end
1370    ParamString=get(handles.ParamVal,'String');
1371    if ischar(ParamString)
1372        for ilist=1:size(ParamString,1)
1373            ParamVal{ilist}=ParamString(ilist,:);
1374        end
1375    else
1376        ParamVal=ParamString;
1377    end   
1378end
1379
1380%read the set of field numbers
1381first_i=str2num(get(handles.first_i,'String'));
1382last_i=str2num(get(handles.last_i,'String'));
1383incr_i=str2num(get(handles.incr_i,'String'));
1384first_j=str2num(get(handles.first_j,'String'));
1385last_j=str2num(get(handles.last_j,'String'));
1386incr_j=str2num(get(handles.incr_j,'String'));
1387if ~isequal(get(handles.first_i,'Visible'),'on')
1388   first_i=1;
1389   last_i=1;
1390   incr_i=1;
1391end
1392if ~isequal(get(handles.first_j,'Visible'),'on')
1393    first_j=1;
1394    last_j=1;
1395    incr_j=1;
1396end
1397Series.NbSlice=str2num(get(handles.NbSlice,'String'));
1398if isequal(first_i,[])|isequal(first_j,[]), msgbox_uvmat('ERROR','first field number not defined'),...
1399    set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
1400if isequal(last_i,[])| isequal(last_j,[]),msgbox_uvmat('ERROR','last field number not defined'),...
1401    set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
1402if isequal(incr_i,[])| isequal(incr_j,[]),msgbox_uvmat('ERROR','increment in field number not defined'),...
1403    set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
1404if last_i < first_i | last_j < first_j , msgbox_uvmat('ERROR','last field number must be larger than the first one'),...
1405    set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
1406num_i=[first_i:incr_i:last_i];
1407num_j=[first_j:incr_j:last_j];
1408nbfield_cell=get(handles.nb_field,'String');
1409nbfield=[]; %default
1410for iview=1:length(nbfield_cell)
1411    nb=str2num(nbfield_cell{iview});
1412    if ~isempty(nb)
1413        nbfield=[nbfield nb];
1414    end
1415end
1416nbfield=min(nbfield);
1417nbfield2_cell=get(handles.nb_field2,'String');
1418nbfield2=[]; %default
1419for iview=1:length(nbfield2_cell)
1420    nb=str2num(nbfield2_cell{iview});
1421    if ~isempty(nb)
1422        nbfield2=[nbfield2 nb];
1423    end
1424end
1425nbfield2=min(nbfield2);
1426
1427%get complementary information from the 'series' interface
1428list_action=get(handles.ACTION,'String');% list menu action
1429index_action=get(handles.ACTION,'Value');% selected string index
1430action= list_action{index_action}; % selected string
1431mode_list=get(handles.mode,'String');
1432index_mode=get(handles.mode,'Value');
1433mode=mode_list{index_mode};
1434ind_shift=0;%default
1435
1436%determine the list of input file names
1437nbmissing=0;
1438for iview=1:length(RootPath)
1439    %case of pairs (.nc files)
1440   
1441    if isequal(NomType{iview},'_i_j1-j2')| isequal(NomType{iview},'_i1-i2_j')| isequal(NomType{iview},'_i1-i2')| isequal(NomType{iview},'#_ab')
1442        ind_shift=SeriesData.displ_num(iview,:);
1443        if isequal(ind_shift,[0 0 0 0]) % undefined pairs
1444            if isequal(NomType{iview},'#_ab')
1445                mode='#_ab';
1446            end
1447            [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);
1448        else   
1449            [num_i1,num_i2,num_j1,num_j2,num_i,num_j]=find_file_indices(num_i,num_j,ind_shift,NomType{iview},mode);
1450            if isempty(num_i)
1451                msgbox_uvmat('ERROR','ERROR: empty set of input files chosen')
1452                return
1453            end
1454            if num_i(1)>first_i
1455               set(handles.first_i,'String',num2str(num_i(1)))%update the display of first field
1456               last_i_Callback(hObject, eventdata, handles)
1457            end
1458            if num_i(end)<last_i
1459               set(handles.last_i,'String',num2str(num_i(end)))%update the display of last field
1460               last_i_Callback(hObject, eventdata, handles)
1461            end
1462            if num_j(1)>first_j
1463               set(handles.first_j,'String',num2str(num_j(1)))%update the display of first field
1464               last_j_Callback(hObject, eventdata, handles)
1465            end
1466            if num_j(end)<last_j
1467               set(handles.last_j,'String',num2str(num_j(end)))%update the display of last field
1468               last_j_Callback(hObject, eventdata, handles)
1469            end
1470        end
1471    else%case of images
1472        [num_i1,num_j1]=meshgrid(num_i,num_j);
1473        num_i2=num_i1;
1474        num_j2=num_j1;
1475    end
1476    if length(RootPath)>1
1477        num_i1_cell{iview}=num_i1;
1478        num_i2_cell{iview}=num_i2;
1479        num_j1_cell{iview}=num_j1;
1480        num_j2_cell{iview}=num_j2;
1481    end
1482end
1483
1484% RUN RUN'
1485path_series=which('series');
1486list_path=get(handles.ACTION,'UserData');
1487index=get(handles.ACTION,'Value');
1488fct_path=list_path{index}; %path stored for the function ACTION
1489if ~isequal(fct_path,path_series)
1490    eval(['spath=which(''' action ''');']) %spath = current path of the selected function ACTION
1491    if ~isequal(spath,fct_path)& exist(fct_path,'dir')
1492        addpath(fct_path)% add the prescribed path if not the current one
1493    end
1494end
1495% fct_path
1496eval(['h_fun=@' action ';'])
1497if ~isequal(fct_path,path_series)
1498        rmpath(fct_path)% add the prescribed path if not the current one   
1499end
1500
1501Series.Action=action;%name of the processing programme
1502set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784])
1503drawnow
1504if length(RootPath)>1
1505%    feval(action,num_i1_cell,num_i2_cell,num_j1_cell,num_j2_cell,Series);
1506    h_fun(num_i1_cell,num_i2_cell,num_j1_cell,num_j2_cell,Series);
1507else
1508    h_fun(num_i1,num_i2,num_j1,num_j2,Series);
1509%     feval(action,num_i1,num_i2,num_j1,num_j2,Series);
1510end
1511set(handles.RUN,'BackgroundColor',[1 0 0])
1512
1513% %save the current interface setting as figure namefig, append .0 to the name if it already exists
1514% detect=1;
1515% while detect==1
1516%     namefigfull=[namedoc '.fig'];
1517%     hh=dir(namefigfull);
1518%     if ~isempty(hh)
1519%         detect=1;
1520%         namedoc=[namedoc '.0'];
1521%     else
1522%         detect=0;
1523%     end
1524% end
1525% saveas(gcbf,namefigfull);%save the interface with name namefigfull (A CHANGER EN FICHIER  .xml)
1526
1527%----------------------------------------------------
1528function STOP_Callback(hObject, eventdata, handles)
1529set(handles.RUN, 'BusyAction','cancel')
1530set(handles.RUN,'BackgroundColor',[1 0 0])
1531
1532%----------------------------------------------
1533
1534%----------------------------------------------------
1535function first_i_Callback(hObject, eventdata, handles)
1536last_i_Callback(hObject, eventdata, handles)
1537
1538%----------------------------------------------
1539function last_i_Callback(hObject, eventdata, handles)
1540%     hseries=get(handles.last_i,'parent');
1541first_i=str2num(get(handles.first_i,'String'));
1542last_i=str2num(get(handles.last_i,'String'));
1543ref_i=ceil((first_i+last_i)/2);
1544set(handles.ref_i,'String', num2str(ref_i))
1545ref_i_Callback(hObject, eventdata, handles)
1546SeriesData=get(handles.figure1,'UserData');
1547if ~isfield(SeriesData,'Time')
1548    SeriesData.Time{1}=[];
1549end
1550displ_time(handles,SeriesData.Time{1});
1551
1552%-------------------------------------------------------
1553function first_j_Callback(hObject, eventdata, handles)
1554 last_j_Callback(hObject, eventdata, handles)
1555
1556%-------------------------------------------------------
1557function last_j_Callback(hObject, eventdata, handles)
1558   % hseries=get(handles.last_i,'parent');
1559first_j=str2num(get(handles.first_j,'String'));
1560last_j=str2num(get(handles.last_j,'String'));
1561ref_j=ceil((first_j+last_j)/2);
1562set(handles.ref_j,'String', num2str(ref_j))
1563
1564ref_j_Callback(hObject, eventdata, handles)
1565SeriesData=get(handles.figure1,'UserData');
1566if ~isfield(SeriesData,'Time')
1567    SeriesData.Time{1}=[];
1568end
1569displ_time(handles,SeriesData.Time{1});
1570
1571
1572
1573
1574%-------------------------------------------------------
1575function ref_i_Callback(hObject, eventdata, handles)
1576mode_list=get(handles.mode,'String');
1577mode_value=get(handles.mode,'Value');
1578mode=mode_list{mode_value};
1579%hseries=get(handles.ref_i,'parent');
1580SeriesData=get(handles.figure1,'UserData');
1581%NomTypeCell=get(handles.NomType,'String');
1582NomTypeCell=SeriesData.NomType;
1583if ~isempty(NomTypeCell)
1584Val=get(handles.NomType,'Value');
1585NomType=NomTypeCell{Val};
1586% for ilist=1:length(NomType)
1587    if isequal(NomType,'_i_j1-j2')|| isequal(NomType,'_i1-i2_j')|| isequal(NomType,'_i1-i2')
1588        if isequal(mode,'series(Di)')
1589            find_netcpair_civ(hObject, eventdata, handles,Val);% update the menu of pairs depending on the available netcdf files
1590%             break
1591        end
1592    end
1593end
1594
1595%----------------------------------------------------
1596function ref_j_Callback(hObject, eventdata, handles)
1597mode_list=get(handles.mode,'String');
1598mode_value=get(handles.mode,'Value');
1599mode=mode_list{mode_value};
1600%hseries=get(handles.ref_i,'parent');
1601SeriesData=get(handles.figure1,'UserData');
1602NomTypeCell=SeriesData.NomType;
1603if ~isempty(NomTypeCell)
1604    Val=get(handles.NomType,'Value');
1605    NomType=NomTypeCell{Val};
1606    if isequal(NomType,'_i_j1-j2')|| isequal(NomType,'_i1-i2_j')|| isequal(NomType,'_i1-i2')
1607        if isequal(mode,'series(Dj)')
1608            find_netcpair_civ(hObject, eventdata, handles,Val);% update the menu of pairs depending on the available netcdf files
1609        end
1610    end
1611end
1612
1613%----------------------------------------------------
1614% --- Executes on selection change in ACTION.
1615function ACTION_Callback(hObject, eventdata, handles)
1616global nb_builtin
1617list_ACTION=get(handles.ACTION,'String');% list menu fields
1618index_ACTION=get(handles.ACTION,'Value');% selected string index
1619ACTION= list_ACTION{index_ACTION}; % selected function name
1620path_series=which('series');%path to series.m
1621list_path=get(handles.ACTION,'UserData');%list of recorded paths to functions of the list ACTION
1622default_file=fullfile(list_path{end},ACTION);
1623% add a new function to the menu if the selected item is 'more...'
1624if isequal(ACTION,'more...')
1625    pathfct=fileparts(path_series);
1626    [FileName, PathName, filterindex] = uigetfile( ...
1627       {'*.m', ' (*.m)';
1628        '*.m',  '.m files '; ...
1629        '*.*', 'All Files (*.*)'}, ...
1630        'Pick a file',default_file);
1631    if length(FileName)<2
1632        return
1633    end
1634    [pp,ACTION,ext_fct]=fileparts(FileName);%(end-1:end);
1635    if ~isequal(ext_fct,'.m')
1636        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
1637        return
1638    end
1639   
1640   % insert the choice in the action menu
1641   menu_str=update_menu(handles.ACTION,ACTION);%new action menu in which the new item has been appended if needed
1642   index_ACTION=get(handles.ACTION,'Value');% currently selected index in the list
1643   list_path{index_ACTION}=PathName;
1644   if length(menu_str)>nb_builtin+5; %nb_builtin=nbre of functions always remaining in the initial menu
1645       nbremove=length(menu_str)-nb_builtin-5;
1646       menu_str(nb_builtin+1:end-5)=[];
1647       list_path(nb_builtin+1:end-4)=[];
1648       index_ACTION=index_ACTION-nbremove;
1649       set(handles.ACTION,'Value',index_ACTION)
1650       set(handles.ACTION,'String',menu_str)
1651   end
1652   list_path{index_ACTION}=PathName;
1653   set(handles.ACTION,'UserData',list_path);
1654   set(handles.path,'enable','inactive')% indicate that the current path is accessible (not 'off')
1655   
1656   %record the current menu in personal file profil_perso
1657   dir_perso=prefdir;
1658   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1659   for ilist=nb_builtin+1:length(menu_str)-1
1660       series_fct{ilist-nb_builtin}=fullfile(list_path{ilist},[menu_str{ilist} '.m']);
1661   end
1662   if exist(profil_perso,'file')
1663        save(profil_perso,'series_fct','-append')
1664   else
1665        txt=ver;
1666        Release=txt(1).Release;
1667        relnumb=str2num(Release(3:4));
1668        if relnumb >= 14
1669            save(profil_perso,'series_fct','-V6')
1670        else
1671            save(profil_perso, 'series_fct')
1672        end
1673   end
1674end
1675
1676%check the current path to the selected function
1677PathName=list_path{index_ACTION};%current recorded path
1678set(handles.path,'String',PathName); %show the path to the senlected function
1679
1680%default setting for the visibility of the GUI elements
1681set(handles.RootPath,'UserData','many')
1682set(handles.SubDir,'Visible','on')
1683set(handles.RootFile,'Visible','on')
1684set(handles.NomType,'Visible','on')
1685set(handles.FileExt,'Visible','on')
1686set(handles.NbSlice,'Visible','off')
1687set(handles.NbSlice_title,'Visible','off')
1688set(handles.VelTypeMenu,'Visible','off');
1689set(handles.VelType_text,'Visible','off');
1690set(handles.VelTypeMenu_1,'Visible','off');
1691set(handles.VelType_text_1,'Visible','off');
1692view_FieldMenu(handles,'off')
1693view_FieldMenu_1(handles,'off')
1694view_TRANSFORM(handles,'off')
1695set(handles.ProjObject_frame,'Visible','off');
1696set(handles.GetMask,'Visible','off')
1697set(handles.Mask,'Visible','off')
1698set(handles.GetObject,'Visible','off');
1699set(handles.ProjObject,'Visible','off');
1700set(handles.OutputDir,'Visible','off');
1701set(handles.PARAMETERS_frame,'Visible','off');
1702set(handles.PARAMETERS_title,'Visible','off');
1703set(handles.ParamKey,'Visible','off')
1704set(handles.ParamVal,'Visible','off')
1705ParamKey={};
1706set(handles.FieldMenu,'Enable','off')
1707set(handles.VelTypeMenu,'Enable','off')
1708set(handles.FieldMenu_1,'Enable','off')
1709set(handles.VelTypeMenu_1,'Enable','off')
1710set(handles.transform_fct,'Enable','off')
1711%set the displayed GUI item needed for input parameters
1712%list_input=feval(ACTION);% input list asked by the selected function
1713if ~isequal(path_series,PathName)
1714    addpath(PathName)
1715end
1716eval(['h_function=@' ACTION ';']);
1717if ~isequal(path_series,PathName)
1718    rmpath(PathName)
1719end
1720
1721varargout=h_function();
1722%varargout=feval(ACTION);% input list asked by the selected function
1723Param_list={};
1724% RootPath=get(handles.RootPath,'String');
1725% RootFile=get(handles.RootFile,'String');
1726
1727%nb_series=length(RootFile);
1728FileExt=get(handles.FileExt,'String');
1729nb_series=length(FileExt);
1730testima_series=1; %test for a list of images only
1731testima=1;
1732testima_1=1;
1733testciv_series=1;
1734for iview=1:nb_series
1735    ext=FileExt{iview};
1736    if length(ext)<2
1737        ext='.none';
1738    end
1739    testimaview=~isempty(imformats(ext(2:end))) || isequal(lower(ext),'.avi');
1740    if ~testimaview
1741        if iview==1
1742            testima=0;
1743        end
1744        if iview==2
1745            testima_1=0;
1746        end
1747        testima_series=0;
1748    end
1749end
1750for ilist=1:length(varargout)-1
1751    switch varargout{ilist}
1752                       %RootFile always visible
1753         case 'RootPath'   %visible by default
1754            value=lower(varargout{ilist+1});
1755            if isequal(value,'one')||isequal(value,'two')||isequal(value,'many')
1756                set(handles.RootFile,'UserData',value)% for use in menu Open_insert
1757            end
1758        case 'SubDir' %visible by default
1759            if isequal(lower(varargout{ilist+1}),'off')
1760                set(handles.SubDir,'Visible','off')
1761            end
1762        case 'RootFile'   %visible by default
1763            value=lower(varargout{ilist+1});
1764            if isequal(value,'off')
1765                set(handles.RootFile,'Visible','off')
1766            elseif isequal(value,'one')||isequal(value,'two')||isequal(value,'many')
1767                set(handles.RootFile,'Visible','on')
1768                set(handles.RootFile,'UserData',value)% for use in menu Open_insert
1769            end
1770        case 'NomType'   %visible by default
1771            if isequal(lower(varargout{ilist+1}),'off')
1772                set(handles.NomType,'Visible','off')
1773            end
1774        case 'FileExt'   %visible by default
1775            if isequal(lower(varargout{ilist+1}),'off')
1776                set(handles.FileExt,'Visible','off')
1777            end
1778        case 'NbSlice'   %hidden by default
1779            if isequal(lower(varargout{ilist+1}),'on')
1780                set(handles.NbSlice,'Visible','on')
1781                set(handles.NbSlice_title,'Visible','on')
1782            end
1783        case 'VelTypeMenu'   %hidden by default
1784            if isequal(lower(varargout{ilist+1}),'one') || isequal(lower(varargout{ilist+1}),'two')
1785                set(handles.VelTypeMenu,'Enable','on')
1786                if nb_series >=1 && ~testima_series
1787                    set(handles.VelTypeMenu,'Visible','on')
1788                    set(handles.VelType_text,'Visible','on');
1789                    set(handles.Field_frame,'Visible','on')
1790                end
1791            end
1792            if isequal(lower(varargout{ilist+1}),'two')
1793                set(handles.VelTypeMenu_1,'Enable','on')
1794                if nb_series >=2 && ~testima_series
1795                    set(handles.VelTypeMenu_1,'Visible','on')
1796                    set(handles.VelType_text_1,'Visible','on');
1797                end
1798            end
1799        case 'FieldMenu'   %hidden by default
1800            if isequal(lower(varargout{ilist+1}),'one')||isequal(lower(varargout{ilist+1}),'two')
1801                set(handles.FieldMenu,'Enable','on') % test for MenuBorser
1802                if nb_series >=1 && ~testima_series
1803                    view_FieldMenu(handles,'on')
1804                end
1805            end
1806            if isequal(lower(varargout{ilist+1}),'two')
1807                set(handles.FieldMenu_1,'Enable','on')
1808                if nb_series >=2 && ~testima_1
1809                    view_FieldMenu_1(handles,'on')
1810                end
1811            end
1812        case 'CoordType'   %hidden by default
1813            if isequal(lower(varargout{ilist+1}),'on')
1814                set(handles.transform_fct,'Enable','on')
1815                view_TRANSFORM(handles,'on')
1816            end
1817        case 'GetObject'   %hidden by default
1818            if isequal(lower(varargout{ilist+1}),'on')   
1819                set(handles.ProjObject_frame,'Visible','on')
1820                set(handles.GetObject,'Visible','on');
1821            end
1822        case 'Mask'   %hidden by default
1823            if isequal(lower(varargout{ilist+1}),'on')   
1824                set(handles.ProjObject_frame,'Visible','on')
1825                set(handles.GetMask,'Visible','on');
1826            end
1827        case 'PARAMETER' 
1828            set(handles.PARAMETERS_frame,'Visible','on')
1829            set(handles.PARAMETERS_title,'Visible','on')
1830            set(handles.ParamKey,'Visible','on')
1831            %set(handles.ParamVal,'Visible','on')
1832            Param_str=varargout{ilist+1};
1833            Param_list=[Param_list; {Param_str}];         
1834    end
1835end
1836if ~isempty(Param_list)
1837    set(handles.ParamKey,'String',Param_list)
1838    set(handles.ParamVal,'Visible','on')
1839end
1840
1841%-------------------------------------------------------------------
1842% --- Executes on selection change in FieldMenu.
1843%-------------------------------------------------------------------
1844function FieldMenu_Callback(hObject, eventdata, handles)
1845
1846field_str=get(handles.FieldMenu,'String');
1847field_index=get(handles.FieldMenu,'Value');
1848field=field_str{field_index(1)};
1849if isequal(field,'get_field...')   
1850     hget_field=findobj(allchild(0),'name','get_field');
1851     if ~isempty(hget_field)
1852         delete(hget_field)%delete opened versions of get_field
1853     end
1854     %hseries=get(handles.FieldMenu,'parent');
1855     SeriesData=get(handles.figure1,'UserData');
1856     filename=SeriesData.CurrentInputFile;
1857     if exist(filename,'file')
1858        get_field(filename)
1859     end
1860elseif isequal(field,'more...')
1861    str=calc_field;
1862    [ind_answer,v] = listdlg('PromptString','Select a file:',...
1863                'SelectionMode','single',...
1864                'ListString',str);
1865       % edit the choice in the fields and action menu
1866     scalar=cell2mat(str(ind_answer));
1867     update_menu(handles.FieldMenu,scalar)
1868end
1869
1870%------------------------------------------------------
1871% --- Executes on selection change in FieldMenu_1.
1872%-----------------------------------------------------
1873function FieldMenu_1_Callback(hObject, eventdata, handles)
1874field_str=get(handles.FieldMenu_1,'String');
1875field_index=get(handles.FieldMenu_1,'Value');
1876field=field_str{field_index};
1877if isequal(field,'get_field...')   
1878     hget_field=findobj(allchild(0),'name','get_field_1');
1879     if ~isempty(hget_field)
1880         delete(hget_field)
1881     end
1882     %hseries=get(handles.FieldMenu,'parent');
1883     SeriesData=get(handles.figure1,'UserData');
1884     filename=SeriesData.CurrentInputFile_1;
1885     if exist(filename,'file')
1886        hget_field=get_field(filename);
1887        set(hget_field,'name','get_field_1')
1888     end
1889elseif isequal(field,'more...')
1890    str=calc_field;
1891    [ind_answer,v] = listdlg('PromptString','Select a file:',...
1892                'SelectionMode','single',...
1893                'ListString',str);
1894       % edit the choice in the fields and action menu
1895     scalar=cell2mat(str(ind_answer));
1896     update_menu(handles.FieldMenu_1,scalar)
1897end   
1898
1899
1900% %group the variables (fields of 'FieldData') in cells of variables with the same dimensions
1901% %%%%%%%%%%%%%%%%%%%%%%% Function independante maintenant
1902% %-----------------------------------------------------------------
1903% [CellVarIndex,NbDim,VarTypeCell]=find_field_indices(Data{1});
1904% %LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
1905% % CellVarIndex=cells of variable index arrays
1906% ivar_new=0; % index of the current variable in the projected field
1907% icoord=0;
1908% for icell=1:length(CellVarIndex)
1909%     if NbDim(icell)==1
1910%         continue
1911%     end
1912%     VarIndex=CellVarIndex{icell};%  indices of the selected variables in the list FieldData.ListVarName
1913%     VarType=VarTypeCell{icell};
1914%     ivar_X=VarType.coord_x;
1915%     ivar_Y=VarType.coord_y;
1916%     ivar_FF=VarType.errorflag;
1917%     if isempty(ivar_X)
1918%         test_grid=1;%test for input data on regular grid (e.g. image)coordinates
1919%     else
1920%         if length(ivar_Y)~=1
1921%                 warndlg_uvmat('y coordinate missing in proj_field.m','ERROR')
1922%                 return
1923%         end
1924%         test_grid=0;
1925%     end
1926% %    DimIndices=Data{1}.VarDimIndex{VarIndex(1)};%indices of the dimensions of the first variable (common to all variables in the cell)
1927%     %case of input fields with unstructured coordinates
1928%     if ~test_grid
1929%         for ivar=VarIndex
1930%             VarName=MergeData.ListVarName{ivar};
1931%             for iview=1:nbview
1932%                 eval(['MergeData.' VarName '=[MergeData.' VarName '; Data{iview}.' VarName ';'])
1933%             end
1934%         end
1935%     %case of fields defined on a structured  grid
1936%     else 
1937% %        DimValue=MergeData.DimValue(DimIndices);%set of dimension values
1938%         testFF=0;
1939%         for iview=2:nbview
1940% %             if ~isequal(DimValue,Data{iview}.DimValue(DimIndices))
1941% %                 MergeData.Txt='ERROR: attempt at merging structured fields with different sizes';
1942% %                 return
1943% %             end
1944%             for ivar=VarIndex
1945%                 VarName=MergeData.ListVarName{ivar};
1946%                 if isfield(MergeData,'VarAttribute')
1947%                     if length(MergeData.VarAttribute)>=ivar && isfield(MergeData.VarAttribute{ivar},'Role') && isequal(MergeData.VarAttribute{ivar}.Role,'errorflag')
1948%                         testFF=1;
1949%                     end
1950%                 end
1951%                 eval(['MergeData.' VarName '=MergeData.' VarName '+ Data{iview}.' VarName ';'])
1952%             end
1953%         end
1954%         if testFF
1955%             nbaver=nbview-MergeData.FF;
1956%             indgood=find(nbaver>0);
1957%             for ivar=VarIndex
1958%                 VarName=MergeData.ListVarName{ivar};
1959%                 eval(['MergeData.' VarName '(indgood)=double(MergeData.' VarName '(indgood))./nbaver(indgood);'])
1960%             end
1961%         else
1962%             for ivar=VarIndex
1963%                 VarName=MergeData.ListVarName{ivar};
1964%                 eval(['MergeData.' VarName '=double(MergeData.' VarName ')./nbview;'])
1965%             end   
1966%         end
1967%     end
1968% end
1969%     
1970
1971%-----------------------------
1972function mouse_up_gui(ggg,eventdata,handles)
1973if isequal(get(ggg,'SelectionType'),'alt')
1974    display('global CurData, UserData of GUI series')
1975    global CurData
1976    CurData=get(ggg,'UserData');
1977    evalin('base','global CurData');%make CurData global in the workspace
1978    evalin('base','CurData'); %display CurData in the workspace
1979    commandwindow
1980   % plot_text(CurData)
1981end
1982
1983%%%%%%%%%%%%%
1984function [ind_remove]=find_pairs(dirpair,ind_i,last_i)
1985
1986        indsel=ind_i;
1987        indiff=diff(ind_i); %test index increment to detect multiplets (several pairs with the same index ind_i) and holes in the series
1988        indiff=[1 indiff last_i-ind_i(end)+1];%for testing gaps with the imposed bounds
1989        if ~isempty(indiff)
1990            indiff2=diff(indiff);
1991            indiffp=[indiff2 1];
1992            indiffm=[1 indiff2];
1993            ind_multi_m=find((indiff==0)&(indiffm<0))-1;%indices of first members of multiplets
1994            ind_multi_p=find((indiff==0)&(indiffp>0));%indices of last members of multiplets
1995                %for each multiplet, select the most recent file
1996            ind_remove=[];
1997            for i=1:length(ind_multi_m)
1998                ind_pairs=ind_multi_m(i):ind_multi_p(i);
1999                for imulti=1:length(ind_pairs)
2000                    datepair(imulti)=datenum(dirpair(ind_pairs(imulti)).date);%dates of creation
2001                end
2002                [datenew,indsort2]=sort(datepair); %sort the multiplet by creation date
2003                ind_s=indsort2(1:end-1);%
2004                ind_remove=[ind_remove ind_pairs(ind_s)];%remove these indices, leave the last one
2005            end
2006        end
2007
2008%----------------------------------------------------
2009%  determine the list of index pairs of processing file
2010%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2011function [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)
2012num_i1=num_i;% set of first image numbers by default
2013num_i2=num_i;
2014num_j1=num_j;
2015num_j2=num_j;
2016num_i_out=num_i;
2017num_j_out=num_j;
2018if isequal (NomType,'_i1-i2_j') |isequal (NomType,'_i1-i2')
2019    num_i1_line=num_i+ind_shift(3);% set of first image numbers
2020    num_i2_line=num_i+ind_shift(4);
2021    % adjust the first and last field number
2022        indsel=find(num_i1_line >= 1);
2023    num_i_out=num_i(indsel);
2024    num_i1_line=num_i1_line(indsel);
2025    num_i2_line=num_i2_line(indsel);
2026    num_j1=meshgrid(num_j,ones(size(num_i1_line)));
2027    num_j2=meshgrid(num_j,ones(size(num_i1_line)));
2028    [xx,num_i1]=meshgrid(num_j,num_i1_line);
2029    [xx,num_i2]=meshgrid(num_j,num_i2_line);
2030elseif isequal (NomType,'_i_j1-j2') || isequal (NomType,'#_ab')
2031    if isequal(mode,'bursts') %case of bursts (png_old or png_2D)
2032        num_j1=ind_shift(1)*ones(size(num_i));
2033        num_j2=ind_shift(2)*ones(size(num_i));
2034    else
2035        num_j1_col=num_j+ind_shift(1);% set of first image numbers
2036        num_j2_col=num_j+ind_shift(2);
2037        % adjust the first field number
2038        indsel=find((num_j1_col >= 1));   
2039        num_j_out=num_j(indsel);
2040        num_j1_col=num_j1_col(indsel);
2041        num_j2_col=num_j2_col(indsel);
2042        [num_i1,num_j1]=meshgrid(num_i,num_j1_col);
2043        [num_i2,num_j2]=meshgrid(num_i,num_j2_col);
2044    end   
2045end
2046
2047 
2048%-----------------------------------------------------------
2049% find the times corresponding to the first and last indices of a series
2050%
2051function displ_time(handles,times)
2052hseries=get(handles.last_i,'parent');
2053SeriesData=get(hseries,'UserData');%
2054first_i=str2num(get(handles.first_i,'String'));
2055first_j=str2num(get(handles.first_j,'String'));
2056last_i=str2num(get(handles.last_i,'String'));
2057last_j=str2num(get(handles.last_j,'String'));
2058% index_civ=get(handles.list_pair_civ,'Value');
2059% NomType=get(handles.NomType,'String');
2060NomType=SeriesData.NomType;
2061mode_list=get(handles.mode,'String');
2062index_mode=get(handles.mode,'Value');
2063mode=mode_list{index_mode};
2064% ind_shift=0;%default
2065
2066time_first=[];
2067time_last=[];
2068if ~isfield(SeriesData,'Time')
2069    SeriesData.Time{1}=[];
2070end
2071for iview=1:length(NomType)
2072    time_first_cell{iview}='?';
2073    time_last_cell{iview}='?';%default
2074    time=SeriesData.Time{iview};
2075    if isequal(NomType{iview},'_i1-i2_j')|isequal(NomType{iview},'_i_j1-j2')|isequal(NomType{iview},'#_ab')|isequal(NomType{iview},'_i1-i2')
2076        if isfield(SeriesData,'displ_num')& ~isempty(SeriesData.displ_num)
2077            ind_shift=SeriesData.displ_num(iview,:);
2078            if isequal(mode,'bursts')
2079                first_j=0;
2080                last_j=0;
2081            end
2082            first_i1=first_i +ind_shift(3);
2083            first_i2 =first_i +ind_shift(4);
2084            first_j1 =first_j +ind_shift(1);
2085            first_j2 =first_j +ind_shift(2);
2086            last_i1=last_i +ind_shift(3);
2087            last_i2 =last_i +ind_shift(4);   
2088            last_j1 =last_j +ind_shift(1);
2089            last_j2 =last_j +ind_shift(2);
2090            siz=size(SeriesData.Time{1});
2091            if first_i1>=1 && first_j1>=1 && siz(1)>=last_i2 && siz(2)>=last_j2
2092                time_first=(time(first_i1,first_j1)+time(first_i2,first_j2))/2;
2093                time_last=(time(last_i1,last_j1)+time(last_i2,last_j2))/2;
2094            else%read the time in the nc files
2095                RootPath=get(handles.RootPath,'String');
2096                RootFile=get(handles.RootFile,'String');
2097                SubDir=get(handles.SubDir,'String');
2098                %VelType=get(handles.VelType,'String');
2099                VelType_str=get(handles.VelTypeMenu,'String');
2100                VelType_val=get(handles.VelTypeMenu,'Value');
2101                VelType=VelType_str{VelType_val};
2102                filebase=fullfile(RootPath{1},RootFile{1});
2103                [filefirst]=name_generator(filebase,first_i1,first_j1,'.nc',NomType{iview},1,first_i2,first_j2,SubDir{iview});
2104                if  exist(filefirst,'file')
2105                    Attrib=nc2struct(filefirst,[]);
2106                    if isfield(Attrib,'Time')
2107                        time_first=Attrib.Time;
2108                    else
2109                        if isfield(Attrib,'absolut_time_T0')
2110                            time_first=Attrib.absolut_time_T0;
2111                        end
2112                        if isfield(Attrib,'absolut_time_T0_2')&&~(isequal(VelType,'civ1')||isequal(VelType,'interp1')||isequal(VelType,'filter1'))
2113                            time_first=Attrib.absolut_time_T0_2;
2114                        end
2115                    end
2116                end
2117                [filelast]=name_generator(filebase,last_i1,last_j1,'.nc',NomType{iview},1,last_i2,last_j2,SubDir{iview});
2118                if exist(filelast,'file')
2119                   Attrib=nc2struct(filelast,[]);
2120                    if isfield(Attrib,'Time')
2121                        time_last=Attrib.Time;
2122                    else
2123                        if isfield(Attrib,'absolut_time_T0')
2124                            time_last=Attrib.absolut_time_T0;
2125                        end
2126                        if isfield(Attrib,'absolut_time_T0_2')&&~(isequal(VelType,'civ1')||isequal(VelType,'interp1')||isequal(VelType,'filter1'))
2127                            time_last=Attrib.absolut_time_T0_2;
2128                        end
2129                    end
2130                end
2131            end
2132        end
2133    else
2134        siz=size(times);
2135        if siz(1)>=last_i && siz(2)>=last_j && first_i>=1 && first_j>=1
2136            time_first=times(first_i,first_j);
2137            time_last=times(last_i,last_j);
2138        end
2139    end
2140    time_first_cell{iview}=num2str(time_first,4);
2141    time_last_cell{iview}=num2str(time_last,4);
2142end
2143set(handles.time_first,'Value',1)
2144set(handles.time_last,'Value',1)
2145set(handles.time_first,'String',time_first_cell);
2146set(handles.time_last,'String',time_last_cell);
2147
2148%--------------------------------------------------------------------
2149% --- Executes on selection change in VelTypeMenu.
2150function VelTypeMenu_Callback(hObject, eventdata, handles)
2151% VelTypeList=get(handles.VelTypeMenu,'String');
2152% VelTypeIndex=get(handles.VelTypeMenu,'Value');
2153% VelTypeCell=get(handles.VelType,'String');
2154% VelTypeCell{1}=VelTypeList{VelTypeIndex};
2155% set(handles.VelType,'String',VelTypeCell)
2156
2157
2158%--------------------------------------------------------------------
2159% --- Executes on button press in GetObject.
2160function GetObject_Callback(hObject, eventdata, handles)
2161hseries=get(handles.GetObject,'parent');
2162SeriesData=get(hseries,'UserData');
2163value=get(handles.GetObject,'Value');
2164if value
2165     set(handles.GetObject,'BackgroundColor',[1 1 0])%put unactivated buttons to yellow
2166     DataInit.ParentButton=handles.GetObject;
2167     hset_object=findobj(allchild(0),'Name','set_object');%find the set_object interface handle
2168     if ishandle(hset_object)
2169         [SeriesData.hset_object,SeriesData.sethandles]=set_object(DataInit); %open the set_object interface
2170     else
2171         DataInit.TITLE='POINTS';%default option
2172         [SeriesData.hset_object,SeriesData.sethandles]=set_object(DataInit); %open the set_object interface
2173     end
2174else
2175    set(handles.GetObject,'BackgroundColor',[0 1 0])%put activated buttons to green
2176    if isfield(SeriesData,'hset_object')&& ishandle(SeriesData.hset_object)
2177        close(SeriesData.hset_object)
2178    end
2179end
2180set(hseries,'UserData',SeriesData)
2181
2182%--------------------------------------------------------------
2183function GetMask_Callback(hObject, eventdata, handles)
2184value=get(handles.GetMask,'Value');
2185if value
2186    errordlg('not implemented yet')
2187end
2188%--------------------------------------------------------------
2189
2190%--------------------------------------------------------------------------
2191%'uv_ncbrowser': interactively calls the netcdf file browser 'get_field.m'
2192function ncbrowser_uvmat(hObject, eventdata)
2193     bla=get(gcbo,'String');
2194     ind=get(gcbo,'Value');
2195     filename=cell2mat(bla(ind));
2196      blank=find(filename==' ');
2197      filename=filename(1:blank-1);
2198     get_field(filename)
2199
2200% --------------------------------------------------------------------
2201function MenuHelp_Callback(hObject, eventdata, handles)
2202
2203path_to_uvmat=which ('uvmat');% check the path of uvmat
2204pathelp=fileparts(path_to_uvmat);
2205helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
2206if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
2207else
2208    addpath (fullfile(pathelp,'uvmat_doc'))
2209    web([helpfile '#series'])
2210end
2211
2212
2213% --- Executes on selection change in transform_fct.
2214function transform_fct_Callback(hObject, eventdata, handles)
2215
2216global nb_transform
2217
2218% huvmat=get(handles.transform_fct,'parent');
2219menu=get(handles.transform_fct,'String');
2220ind_coord=get(handles.transform_fct,'Value');
2221coord_option=menu{ind_coord};
2222list_transform=get(handles.transform_fct,'UserData')
2223ff=functions(list_transform{end});
2224if isequal(coord_option,'more...');
2225    coord_fct='';
2226    prompt = {'Enter the name of the transform function'};
2227    dlg_title = 'user defined transform';
2228    num_lines= 1;
2229    [FileName, PathName, filterindex] = uigetfile( ...
2230       {'*.m', ' (*.m)';
2231        '*.m',  '.m files '; ...
2232        '*.*', 'All Files (*.*)'}, ...
2233        'Pick a file', ff.file);
2234    if isequal(PathName(end),'/')||isequal(PathName(end),'\')
2235        PathName(end)=[];
2236    end
2237    transform_selected =fullfile(PathName,FileName);
2238    if ~exist(transform_selected,'file')
2239          return
2240    end
2241    [ppp,transform,xt_fct]=fileparts(FileName);% removes extension .m
2242    if ~isequal(ext_fct,'.m')
2243        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
2244        return
2245    end
2246   menu=update_menu(handles.transform_fct,transform);%add the selected fct to the menu
2247   ind_coord=get(handles.transform_fct,'Value');
2248   addpath(PathName)
2249   list_transform{ind_coord}=str2func(transform);% create the function handle corresponding to the newly seleced function
2250   set(handles.transform_fct,'UserData',list_transform)
2251   rmpath(PathName)
2252   % save the new menu in the personal file 'uvmat_perso.mat'
2253   dir_perso=prefdir;%personal Matalb directory
2254   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
2255   if exist(profil_perso,'file')
2256       for ilist=nb_transform+1:numel(list_transform)
2257           ff=functions(list_transform{ilist})
2258           transform_fct{ilist-nb_transform}=ff.file;
2259       end
2260        save (profil_perso,'transform_fct','-append'); %store the root name for future opening of uvmat
2261   end
2262end
2263
2264%check the current path to the selected function
2265func=functions(list_transform{ind_coord});
2266set(handles.path_transform,'String',fileparts(func.file)); %show the path to the senlected function
2267
2268
2269
2270function path_transform_Callback(hObject, eventdata, handles)
2271% hObject    handle to path_transform (see GCBO)
2272% eventdata  reserved - to be defined in a future version of MATLAB
2273% handles    structure with handles and user data (see GUIDATA)
2274
2275% Hints: get(hObject,'String') returns contents of path_transform as text
2276%        str2double(get(hObject,'String')) returns contents of path_transform as a double
2277
2278
2279% --- Executes during object creation, after setting all properties.
2280function path_transform_CreateFcn(hObject, eventdata, handles)
2281% hObject    handle to path_transform (see GCBO)
2282% eventdata  reserved - to be defined in a future version of MATLAB
2283% handles    empty - handles not created until after all CreateFcns called
2284
2285% Hint: edit controls usually have a white background on Windows.
2286%       See ISPC and COMPUTER.
2287if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
2288    set(hObject,'BackgroundColor','white');
2289end
2290
2291
Note: See TracBrowser for help on using the repository browser.