source: trunk/src/view_field.m @ 61

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

gestion of projection objects improved. Implementation of view_field.fig
introduction of a circle to mark vectors with the mouse
various cleaning and debugging

File size: 107.3 KB
Line 
1
2%'view_field': function associated with the GUI 'view_field.fig' for images and data field visualization
3%------------------------------------------------------------------------
4% function huvmat=view_field(input)
5%
6%OUTPUT
7% huvmat=current handles of the GUI view_field.fig
8%%
9%
10%INPUT:
11% input: input file name (if character chain), or input image matrix to
12% visualize, or Matlab structure representing  netcdf fields (with fields
13% ListVarName....)
14%
15%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
16%  Copyright Joel Sommeria,  2008, LEGI / CNRS-UJF-INPG, joel.sommeria@legi.grenoble-inp.fr.
17%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
18%     This open is part of the toolbox VIEW_FIELD.
19%
20%     VIEW_FIELD is free software; you can redistribute it and/or modify
21%     it under the terms of the GNU General Public License as published by
22%     the Free Software Foundation; either version 2 of the License, or
23%     (at your option) any later version.
24%
25%     VIEW_FIELD is distributed in the hope that it will be useful,
26%     but WITHOUT ANY WARRANTY; without even the implied warranty of
27%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28%     GNU General Public License (open VIEW_FIELD/COPYING.txt) for more details.
29%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
30
31%-------------------------------------------------------------------
32%  I - MAIN FUNCTION VIEW_FIELD (DO NOT MODIFY)
33%-------------------------------------------------------------------
34%-------------------------------------------------------------------
35function varargout = view_field(varargin)
36
37% Begin initialization code - DO NOT EDIT
38gui_Singleton = 1;
39gui_State = struct('gui_Name',          mfilename, ...
40                   'gui_Singleton',     gui_Singleton, ...
41                   'gui_OpeningFcn',    @view_field_OpeningFcn, ...
42                   'gui_OutputFcn',     @view_field_OutputFcn, ...
43                   'gui_LayoutFcn',     [], ...
44                   'gui_Callback',      []);
45if nargin && ischar(varargin{1})
46    gui_State.gui_Callback = str2func(varargin{1});
47end
48
49if nargout
50    varargout{1:nargout} = gui_mainfcn(gui_State, varargin{:});
51else
52    gui_mainfcn(gui_State, varargin{:});
53end
54% End initialization code - DO NOT EDIT
55
56%-------------------------------------------------------------------
57% --- Executes just before view_field is made visible.
58function view_field_OpeningFcn(hObject, eventdata, handles, Field )
59%-------------------------------------------------------------------
60
61% Choose default command menuline output for view_field
62handles.output = handles.axes3;
63
64% Update handles structure
65guidata(hObject, handles);
66
67dircur=pwd; %current working directory
68dir_opening=dircur;
69
70% set the position of colorbar and ancillary GUIs:
71set(hObject,'Units','Normalized')
72handles_mouse=handles;
73huvmat=findobj(allchild(0),'Name','uvmat');
74hhuvmat=guidata(huvmat);
75set(hhuvmat.list_object_2,'Visible','on')
76% handles_mouse.create=hhuvmat.create;
77handles_mouse.edit=hhuvmat.edit;
78pos_uvmat=get(huvmat,'Position');
79pos_view_field(1)=pos_uvmat(1)+pos_uvmat(3)/2;
80pos_view_field(2)=pos_uvmat(2)-pos_uvmat(3)/4;
81pos_view_field(3:4)=pos_uvmat(3:4);
82set(hObject,'Position',pos_view_field)
83
84
85
86%functions for the mouse and keyboard
87set(hObject,'KeyPressFcn',{'keyboard_callback',handles_mouse})%set keyboard action function
88set(hObject,'WindowButtonMotionFcn',{'mouse_motion',handles_mouse})%set mouse action functio
89set(hObject,'WindowButtonDownFcn',{'mouse_down'})%set mouse click action function
90set(hObject,'WindowButtonUpFcn',{'mouse_up',handles_mouse})
91% set(hObject,'CloseRequestFcn ',{'close_fcn'})
92
93[PlotType,PlotParamOut,haxes]= plot_field(Field,handles.axes3)%,PlotParam,KeepLim,PosColorbar)
94%-------------------------------------------------------------------
95% --- Outputs from this function are returned to the command menuline.
96function varargout = view_field_OutputFcn(hObject, eventdata, handles)
97varargout{1} = handles.output;% the only output argument is the handle to the GUI figure
98
99
100%-------------------------------------------------------------------
101%-------------------------------------------------------------------
102% II - FUNCTIONS FOR INTRODUCING THE INPUT FILES
103% automatically sets the global properties when the rootfile name is introduced
104% then activate the view-field action if selected
105% it is activated either by clicking on the RootPath window or by the
106% browser
107%------------------------------------------------------------------
108%------------------------------------------------------------------
109
110%-------------------------------------------------------------------
111function update_mask(handles,num_i1,num_j1)
112%-------------------------------------------------------------------
113
114MaskData=get(handles.mask_test,'UserData');
115if isfield(MaskData,'maskhandle')&& ishandle(MaskData.maskhandle)
116    uistack(MaskData.maskhandle,'top');
117end
118num_i1_mask=mod(num_i1-1,MaskData.NbSlice)+1;
119[MaskName,mdetect]=name_generator(MaskData.Base,num_i1_mask,num_j1,'.png',MaskData.NomType);
120huvmat=get(handles.mask_test,'parent');
121UvData=get(huvmat,'UserData');
122
123%update mask image if the mask is new
124if ~ (isfield(UvData,'MaskName') && isequal(UvData.MaskName,MaskName))
125    UvData.MaskName=MaskName; %update the recorded name on UvData
126    set(huvmat,'UserData',UvData);
127    if mdetect==0
128        if isfield(MaskData,'maskhandle')&& ishandle(MaskData.maskhandle)
129            delete(MaskData.maskhandle)   
130        end
131    else
132        %read mask image
133        Mask.AName='image';
134        Mask.A=imread(MaskName);
135        npxy=size(Mask.A);
136        Mask.AX=[0.5 npxy(2)-0.5];
137        Mask.AY=[npxy(1)-0.5 0.5 ];
138        Mask.CoordType='px';
139        if isequal(get(handles.slices,'Value'),1)
140           NbSlice=str2num(get(handles.nb_slice,'String'));
141           num_i1=str2num(get(handles.i1,'String'));
142           Mask.ZIndex=mod(num_i1-1,NbSlice)+1;
143        end
144        %px to phys or other transform on field
145         menu_transform=get(handles.transform_fct,'String');
146        choice_value=get(handles.transform_fct,'Value');
147        transform_name=menu_transform{choice_value};%name of the transform fct  given by the menu 'transform_fct'
148        transform_list=get(handles.transform_fct,'UserData');
149        transform=transform_list{choice_value};
150        if  ~isequal(transform_name,'') && ~isequal(transform_name,'px')
151            if isfield(UvData,'XmlData') && isfield(UvData.XmlData,'GeometryCalib')%use geometry calib recorded from the ImaDoc xml file as first priority
152                Calib=UvData.XmlData.GeometryCalib;
153                Mask=transform(Mask,UvData.XmlData);
154            end
155        end
156        flagmask=Mask.A < 200;
157       
158        %make brown color image
159        imflag(:,:,1)=0.9*flagmask;
160        imflag(:,:,2)=0.7*flagmask;
161        imflag(:,:,3)=zeros(size(flagmask));
162       
163        %update mask image
164        hmask=[]; %default
165        if isfield(MaskData,'maskhandle')&& ishandle(MaskData.maskhandle)
166            hmask=MaskData.maskhandle;
167        end
168        if ~isempty(hmask)
169            set(hmask,'CData',imflag)   
170            set(hmask,'AlphaData',flagmask*0.6)
171            set(hmask,'XData',Mask.AX);
172            set(hmask,'YData',Mask.AY);
173%             uistack(hmask,'top')
174        else
175            axes(handles.axes3)
176            hold on   
177            MaskData.maskhandle=image(Mask.AX,Mask.AY,imflag,'Tag','mask','HitTest','off','AlphaData',0.6*flagmask);
178%             set(MaskData.maskhandle,'AlphaData',0.6*flagmask)
179            set(handles.mask_test,'UserData',MaskData)
180        end
181    end
182end
183
184
185%-------------------------------------------------------------------
186function MenuExportFigure_Callback(hObject, eventdata, handles)
187%-------------------------------------------------------------------
188huvmat=get(handles.MenuExport,'parent');
189UvData=get(huvmat,'UserData');
190hfig=figure;
191newaxes=copyobj(handles.axes3,hfig);
192map=colormap(handles.axes3);
193colormap(map);%transmit the current colormap to the zoom fig
194colorbar
195
196%-------------------------------------------------------------------
197%-------------------------------------------------------------------
198% III - MAIN REFRESH FUNCTIONS : 'FRAME PLOT'
199%-------------------------------------------------------------------
200%-------------------------------------------------------------------
201
202%Executes on button press in runplus: make one step forward and call
203%run0. The step forward is along the fields series 1 or 2 depending on
204%the scan_i and scan_j check box (exclusive each other)
205%-------------------------------------------------------------------
206function runplus_Callback(hObject, eventdata, handles)
207increment=str2num(get(handles.increment_scan,'String')); %get the field increment d
208runpm(hObject,eventdata,handles,increment)
209
210%-------------------------------------------------------------------
211%Executes on button press in runmin: make one step backward and call
212%run0. The step backward is along the fields series 1 or 2 depending on
213%the scan_i and scan_j check box (exclusive each other)
214%-------------------------------------------------------------------
215function runmin_Callback(hObject, eventdata, handles)
216increment=-str2num(get(handles.increment_scan,'String')); %get the field increment d
217runpm(hObject,eventdata,handles,increment)
218
219%-------------------------------------------------------------------
220%Executes on button press in runmin: make one step backward and call
221%run0. The step backward is along the fields series 1 or 2 depending on
222%the scan_i and scan_j check box (exclusive each other)
223%-------------------------------------------------------------------
224function RunMovie_Callback(hObject, eventdata, handles)
225%------------------------------------------------------------------
226set(handles.RunMovie,'BackgroundColor',[1 1 0])%paint the command button in yellow
227drawnow
228increment=str2num(get(handles.increment_scan,'String')); %get the field increment d
229set(handles.STOP,'Visible','on')
230set(handles.speed,'Visible','on')
231set(handles.speed_txt,'Visible','on')
232set(handles.RunMovie,'BusyAction','queue')
233testavi=0;
234UvData=get(handles.view_field,'UserData');
235
236while get(handles.speed,'Value')~=0 & isequal(get(handles.RunMovie,'BusyAction'),'queue') % enable STOP command
237        runpm(hObject,eventdata,handles,increment)
238        pause(1.02-get(handles.speed,'Value'))% wait for next image
239end
240if isfield(UvData,'aviobj') && ~isempty( UvData.aviobj),
241    UvData.aviobj=close(UvData.aviobj);
242   set(handles.view_field,'UserData',UvData);
243end
244set(handles.RunMovie,'BackgroundColor',[1 0 0])%paint the command buttonback to red
245
246%-------------------------------------------------------------------
247function STOP_Callback(hObject, eventdata, handles)
248%-------------------------------------------------------------------
249set(handles.movie_pair,'BusyAction','Cancel')
250set(handles.movie_pair,'value',0)
251set(handles.RunMovie,'BusyAction','Cancel')
252set(handles.MenuExportMovie,'BusyAction','Cancel')
253
254
255%------------------------------------------------------------------
256function runpm(hObject,eventdata,handles,increment)
257%------------------------------------------------------------------
258%check for mùovie pair status
259movie_status=get(handles.movie_pair,'Value');
260if isequal(movie_status,1)
261    STOP_Callback(hObject, eventdata, handles)
262end
263%read the data on the current input rootfile(s)
264
265[FileName,RootPath,filebase,FileIndices,FileExt,subdir]=read_file_boxes(handles);
266NomType=get(handles.FileIndex,'UserData');
267
268num1=stra2num(get(handles.i1,'String'));
269num2=stra2num(get(handles.i2,'String'));
270num_a=stra2num(get(handles.j1,'String'));
271num_b=stra2num(get(handles.j2,'String'));
272
273sub_value= get(handles.SubField,'Value');
274if sub_value ==1
275    [FileName_1,RootPath_1,filebase_1,FileIndices_1,FileExt_1,SubDir_1]=read_file_boxes_1(handles);
276end   
277
278comp_input=get(handles.fix_pair,'Value');
279if isequal(NomType,'_i1-i2')|isequal(NomType,'_i1-i2_j')
280    comp_input=1; %impose a fixed pair interval
281    set(handles.fix_pair,'Value',1)
282end
283
284%case of scanning along the first direction (rootfile numbers)
285if get(handles.scan_i,'Value')==1% case of scanning along field numbers   
286     num1=num1+increment;
287     num2=num2+increment;
288    if comp_input==0% find a free pair
289        [filename,num_i1_out,num_j1_out,num_i2_out,num_j2_out]=...
290           name_generator(filebase,num1,num_a,FileExt,NomType,0,num2,num_b,subdir);
291        if exist(filename,'file')
292            num_a=num_j1_out;
293            num_b=num_j2_out;
294        end
295    end
296    if sub_value>=2
297        num_i1=num_i1+increment;
298        num_i2=num_i2+increment;
299    end   
300else % case of scanning along the second direction (burst numbers)
301    lastfield_cell=get(handles.last_j,'String'); % get the last field number
302    lastfield=str2num(lastfield_cell{1});
303    num_a=num_a+increment;
304    num_b=num_b+increment;
305    if sub_value >=2
306      num_j1=num_j1+increment;
307      num_j2=num_j2+increment;
308    elseif ~isempty(lastfield) && num_a>lastfield
309        num_a=1;
310        num1=num1+1;
311        num2=num2+1;
312    end
313end
314
315% display the new open numbers
316set(handles.i1,'String',num2stra(num1,NomType,1));
317set(handles.i2,'String',num2stra(num2,NomType,1));
318set(handles.j1,'String',num2stra(num_a,NomType,2));
319set(handles.j2,'String',num2stra(num_b,NomType,2));
320[indices]=name_generator('',num1,num_a,'',NomType,1,num2,num_b,'');
321set(handles.FileIndex,'String',indices);
322if sub_value ==1
323    NomType_1=get(handles.FileIndex_1,'UserData');
324     [indices]=...
325           name_generator('',num1,num_a,'',NomType_1,1,num2,num_b,'');
326     set(handles.FileIndex_1,'String',indices);
327end
328
329if isequal(movie_status,1)
330    set(handles.movie_pair,'Value',1)
331    movie_pair_Callback(hObject, eventdata, handles); %run
332else
333% refresh plots
334    run0_Callback(hObject, eventdata, handles); %run
335end
336
337
338%-------------------------------------------------------
339% --- Executes on button press in movie_pair: create an alternating movie with two view
340%-------------------------------------------------------
341function movie_pair_Callback(hObject, eventdata, handles)
342status=get(handles.movie_pair,'value');
343if isequal(status,0)
344    set(handles.movie_pair,'BusyAction','Cancel')
345    return
346else
347    set(handles.movie_pair,'BusyAction','queue')
348end
349%initialisation
350set(handles.movie_pair,'BackgroundColor',[1 1 0])%paint the command button in yellow
351drawnow
352list_fields=get(handles.Fields,'String');% list menu fields
353index_fields=get(handles.Fields,'Value');% selected string index
354FieldName=list_fields{index_fields}; % selected field
355if isequal(FieldName,'image')
356    run0_Callback(hObject, eventdata, handles)%display the first image
357    UvData=get(handles.view_field,'UserData');
358else
359    msgbox_view_field('ERROR','an image or movie must be first introduced as input')
360    return
361end
362[ff,rr,filebase,xx,Ext,SubDir]=read_file_boxes(handles);
363NomType=get(handles.FileIndex,'UserData');
364num_i1=stra2num(get(handles.i1,'String'));
365num_j1=stra2num(get(handles.j1,'String'));
366num_i2=stra2num(get(handles.i2,'String'));
367num_j2=stra2num(get(handles.j2,'String'));
368if isempty(num_j2)
369    if isempty(num_i2)   
370        msgbox_view_field('ERROR', 'a second image index i2 or j2 is needed to show the pair as a movie')
371        return
372    else
373        num_j2=num_j1;%repeat the index i1 by default
374    end
375end
376if isempty(num_i2)
377    num_i2=num_i1;%repeat the index i1 by default
378end
379imaname_1=name_generator(filebase,num_i2,num_j2,Ext,NomType);
380if ~exist(imaname_1,'file')
381      msgbox_view_field('ERROR',['second input open (-)  ' imaname_1 ' not found']);
382      return
383end
384% set(handles.i2,'String',''); % indicates that the second index i2 is not used
385% set(handles.j2,'String',''); % indicates that the second index i2 is not used
386
387%read the second image
388Field.AName='image';
389Field.AX=UvData.Field.AX;
390Field.AY=UvData.Field.AY;
391% z index
392nbslice=str2double(get(handles.nb_slice,'String'));
393if ~isempty(nbslice)
394    Field.ZIndex=mod(num_i2-1,nbslice)+1;
395end
396Field.CoordType='px';
397%determine the input file type
398if isfield(UvData,'MovieObject')
399    FileType='movie';
400elseif isequal(lower(Ext),'.avi')
401    FileType='avi';
402elseif isequal(lower(Ext),'.vol')
403    FileType='vol';
404else
405   form=imformats(Ext([2:end]));
406   if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
407       if isequal(NomType,'*');
408           FileType='multimage';
409       else
410           FileType='image';
411       end
412   end
413end
414switch FileType
415        case 'movie'
416            Field.A=read(UvData.MovieObject,num_i2);
417        case 'avi'
418            mov=aviread(imaname_1,num_i2);
419            Field.A=frame2im(mov(1));
420        case 'vol'
421            Field.A=imread(imaname_1);
422        case 'multimage'
423            Field.A=imread(imaname_1,num_i2);
424        case 'image'
425            Field.A=imread(imaname_1);
426end
427
428%px to phys or other transform on field
429menu_transform=get(handles.transform_fct,'String');
430choice_value=get(handles.transform_fct,'Value');
431transform_name=menu_transform{choice_value};%name of the transform fct  given by the menu 'transform_fct'
432transform_list=get(handles.transform_fct,'UserData');
433transform=transform_list{choice_value};
434if  ~isequal(transform_name,'') && ~isequal(transform_name,'px')
435    if isfield(UvData,'XmlData') && isfield(UvData.XmlData,'GeometryCalib')%use geometry calib recorded from the ImaDoc xml file as first priority
436        Field=transform(Field,UvData.XmlData);
437    end
438end
439
440 % make movie until movie speed is set to 0 or STOP is activated
441hima=findobj(handles.axes3,'Tag','ima');% %handles.axes3 =main plotting window (A GENERALISER)
442set(handles.STOP,'Visible','on')
443set(handles.speed,'Visible','on')
444set(handles.speed_txt,'Visible','on')
445while get(handles.speed,'Value')~=0 && isequal(get(handles.movie_pair,'BusyAction'),'queue')%isequal(get(handles.run0,'BusyAction'),'queue'); % enable STOP command
446    % read and plot the series of images in non erase mode
447    set(hima,'CData',Field.A);
448    pause(1.02-get(handles.speed,'Value'));% wait for next image
449    set(hima,'CData',UvData.Field.A);
450    pause(1.02-get(handles.speed,'Value'));% wait for next image
451end
452set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
453
454%-------------------------------------------------------
455% --- Executes on button press in run0.
456%-------------------------------------------------
457function run0_Callback(hObject, eventdata, handles)
458
459%initialisation
460set(handles.run0,'BackgroundColor',[1 1 0])%paint the command button in yellow
461drawnow
462abstime=[];
463abstime_1=[];
464dt=[];
465Field={};
466UvData=get(handles.view_field,'UserData');
467if isfield(UvData,'Txt')
468    UvData=rmfield(UvData,'Txt');%erase previous error message
469end
470%set(handles.run0,'BusyAction','queue');
471if ishandle(handles.VIEW_FIELD_title) %remove title panel on view_field
472    delete(handles.VIEW_FIELD_title)
473end
474
475% determine the main input file information for action
476TestInputFile=1;%default
477if isfield(UvData,'TestInputFile')&& isequal(UvData.TestInputFile,0),
478    TestInputFile=0;
479end
480num_i1=[];%default
481FileType=[];%default
482if TestInputFile
483    [filename,RootPath,filebase,xx,Ext]=read_file_boxes(handles);
484    if ~exist(filename,'file')
485        msgbox_view_field('ERROR',['input file ' filename ' does not exist'])
486        return
487    end
488    num_i1=stra2num(get(handles.i1,'String'));
489    num_i2=stra2num(get(handles.i2,'String'));
490    num_j1=stra2num(get(handles.j1,'String'));
491    num_j2=stra2num(get(handles.j2,'String'));
492    NomType=get(handles.FileIndex,'UserData');
493    %update the z position index
494    nbslice=str2double(get(handles.nb_slice,'String'));
495    if ~isnan(nbslice)
496        z_index=mod(num_i1-1,nbslice)+1;
497        set(handles.z_index,'String',num2str(z_index))
498        % refresh menu for save_mask if relevant
499        masknumber=get(handles.masklevel,'String');
500        if length(masknumber)>=z_index
501            set(handles.masklevel,'Value',z_index)
502        end
503    end
504    % determine the input file type
505    if isequal(Ext,'.nc')||isequal(Ext,'.cdf')
506        FileType='netcdf';
507    elseif isfield(UvData,'MovieObject')
508        FileType='movie';
509        FieldName='image';
510    elseif isequal(lower(Ext),'.avi')
511        FileType='avi';
512        FieldName='image';
513    elseif isequal(lower(Ext),'.vol')
514        FileType='vol';
515        FieldName='image';
516    else
517       form=imformats(Ext([2:end]));
518       if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
519           if isequal(NomType,'*');
520               FileType='multimage';
521           else
522               FileType='image';
523           end
524           FieldName='image';
525       end
526    end
527else
528    filename=[];
529    FileType='netcdf';
530    FieldName='get_field...';
531end
532VelType=[];%default
533if isequal(FileType,'netcdf')
534    list_fields=get(handles.Fields,'String');% list menu fields
535    index_fields=get(handles.Fields,'Value');% selected string index
536    FieldName= list_fields{index_fields}; % selected field
537    if isequal(FieldName,'get_field...')% read the field names on the interface get_field...
538        VelType=get(handles.Fields,'UserData');
539        Field{1}=get(handles.Fields,'UserData');
540    else
541       VelType=setfield(handles);
542    end
543end
544
545% choose a second field if Subfield option is 'on'
546filename_1=[];
547FieldName_1=[];
548scal_color=[];
549VelType_1=setfield_1(handles);
550sub_value=get(handles.SubField,'Value');
551FileType_1='none';%default
552if sub_value==1
553    filename_1=read_file_boxes_1(handles);
554    if ~exist(filename_1,'file')
555        msgbox_view_field('ERROR',['second file ' filename_1 ' does not exist'])
556        return
557    end
558    NomType_1=get(handles.FileIndex_1,'UserData');
559    Ext_1=get(handles.FileExt_1,'String');
560    % determine the input file type
561    if isequal(Ext_1,'.nc')||isequal(Ext_1,'.cdf')
562        FileType_1='netcdf';
563    elseif isfield(UvData,'MovieObject_1')
564        FileType_1='movie';
565        FieldName_1='image';
566    elseif isequal(lower(Ext_1),'.avi')
567        FileType='avi';
568        FieldName_1='image';
569    elseif isequal(lower(Ext_1),'.vol')
570        FileType_1='vol';
571        FieldName_1='image';
572    else
573       form=imformats(Ext([2:end]));
574       if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
575           if isequal(NomType_1,'*');
576               FileType_1='multimage';
577           else
578               FileType_1='image';
579           end
580           FieldName_1='image';
581       end
582    end
583    if ~isequal(FieldName_1,'image')
584        list_fields=get(handles.Fields_1,'String');% list menu fields
585        index_fields=get(handles.Fields_1,'Value');% selected string index
586        FieldName_1= list_fields{index_fields}; % selected field
587        if isequal(VelType_1,'*')% free veltype choice
588            VelType_1=[];
589        elseif isequal(VelType_1,'"')% veltype the same as for the first field
590            if isempty(VelType)
591                VelType_1=[];
592            else
593                VelType_1=VelType;
594            end
595        end
596    end
597end
598
599% test for keeping the previous stored data if the input files are unchanged
600test_keepdata_1=0;%defautl
601test_keepdata=0;
602if sub_value>=2
603    if ~isequal(NomType_1,'*')%in cas of a series of files (not avi movie)
604        if isfield(UvData,'filename_1')&& isfield(UvData,'VelType_1') && isfield(UvData,'FieldName_1')
605            test_keepdata_1= isequal(filename_1,UvData.filename_1)&&...
606                isequal(VelType_1,UvData.filename_1) && isequal(FieldName_1,UvData.FieldName_1);
607
608        end
609    end
610end
611
612%read the input field(s)
613
614%read images
615if ~isempty(filename) && isequal(FieldName,'image')
616     switch FileType
617        case 'movie'
618            A=read(UvData.MovieObject,num_i1);
619        case 'avi'
620            mov=aviread(filename,num_i1);
621            A=frame2im(mov(1));
622        case 'vol'
623            A=imread(filename);
624        case 'multimage'
625            A=imread(filename,num_i1);
626        case 'image'
627            A=imread(filename);
628    end
629    npxy=size(A);
630    set(handles.npx,'String',num2str(npxy(2)));% display image size on the interface
631    set(handles.npy,'String',num2str(npxy(1)));
632    Rangx=[0.5 npxy(2)-0.5]; % coordinates of the first and last pixel centers
633    Rangy=[npxy(1)-0.5 0.5]; %
634    Field{1}.AName='image';
635    Field{1}.ListVarName={'AY','AX','A'}; %
636    if size(A,3)==3;%color
637        Field{1}.VarDimName={'AY','AX',{'AY','AX','rgb'}}; %
638    else
639        Field{1}.VarDimName={'AY','AX',{'AY','AX'}}; %
640    end
641    Field{1}.AY=Rangy;
642    Field{1}.AX=Rangx;
643    Field{1}.A=A;
644    Field{1}.CoordType='px'; %used for mouse_motion
645    Field{1}.CoordUnit='pixel'; %used for mouse_motion
646end
647
648%read a second image
649if ~isfield(UvData,'Txt')&& ~isempty(filename_1) && isequal(FieldName_1,'image')
650    switch FileType_1
651        case 'movie'
652            A=read(UvData.MovieObject_1,num_i1);
653        case 'avi'
654            mov=aviread(filename,num_i1);
655            A=frame2im(mov(1));
656        case 'vol'
657            A=imread(filename);
658        case 'multimage'
659            A=imread(filename,num_i1);
660        case 'image'
661            A=imread(filename);
662    end
663    npxy=size(A);
664    set(handles.npx,'String',num2str(npxy(2)));% display image size on the interface
665    set(handles.npy,'String',num2str(npxy(1)));
666    Rangx=[0.5 npxy(2)-0.5]; % coordinates of the first and last pixel centers
667    Rangy=[npxy(1)-0.5 0.5]; %
668    Field{2}.AName='image';
669    Field{2}.ListVarName={'AY','AX','A'}; %
670    if size(A,3)==3;%color
671        Field{2}.VarDimName={'AY','AX',{'AY','AX','rgb'}}; %
672    else
673        Field{2}.VarDimName={'AY','AX',{'AY','AX'}}; %
674    end
675    Field{2}.AY=Rangy;
676    Field{2}.AX=Rangx;
677    Field{2}.A=A;
678    Field{2}.CoordType='px'; %used for mouse_motion
679    Field{2}.CoordUnit='px'; %used for move_mou
680end
681
682%read ncfile(s)
683CivStage_1=0;%default
684VelType_out_1=[];
685InputField={FieldName};
686InputField_1={FieldName_1};
687if ~isfield(UvData,'Txt') && ((~isempty(filename)&& isequal(FileType,'netcdf')) || (~isempty(filename_1)&& isequal(FileType,'netcdf'))) ;
688    %read the velocity field(s) from netcdf rootfile(s)
689    list_code=get(handles.col_vec,'String');% list menu fields
690    index_code=get(handles.col_vec,'Value');% selected string index
691    scal_color= list_code{index_code(1)}; % selected field
692    if isequal(FieldName,'velocity')&& ~isequal(scal_color,'black') && ~isequal(scal_color,'white')
693        InputField=[InputField scal_color];
694    end
695    if isequal(FieldName_1,'velocity') && ~isequal(scal_color,'black') && ~isequal(scal_color,'white')
696        InputField_1=[InputField_1 scal_color];
697    end
698    if isequal(FileType,'netcdf')  %read the first nc field
699        if isequal(FieldName,'get_field...')% read the field names on the interface get_field.
700            VelType=get(handles.Fields,'UserData');
701            hget_field=findobj(allchild(0),'Name','get_field');%find the get_field... GUI
702            if isempty(hget_field)
703                hget_field= get_field(filename);%open the get_field GUI   
704            end
705            hhget_field=guidata(hget_field);
706            set(hhget_field.inputfile,'String',filename)% update the list of input fields in get_field
707            set(hhget_field.ACTION,'Value',1)% PLOT option selected
708            set(hhget_field.list_fig,'Value',2)% plotting axes =view_field selected
709            [Field{1},errormsg]=read_get_field(hget_field); %read the names of the variables to plot in the get_field GUI
710            if ~isempty(errormsg)
711                msgbox_view_field('ERROR',['error in view_field/run0_Callback/read_get_field: ' errormsg])
712                return
713            end
714            CivStage=0;
715            VelType_out=[];         
716        else
717            [Field{1},VelType_out]=read_civxdata(filename,InputField,VelType);
718            if isfield(Field{1},'Txt')
719                msgbox_view_field('ERROR',Field{1}.Txt)
720                return
721            end
722            CivStage=Field{1}.CivStage;
723            UvData.NbDim=Field{1}.nb_dim;
724        end
725    end
726    if ~isempty(filename_1) && isequal(FileType_1,'netcdf') %read the second file
727        if isequal(FieldName_1,'get_field...')% read the field names on the interface get_field.
728            hget_field=findobj(allchild(0),'Name','get_field_1');%find the get_field... GUI
729             if isempty(hget_field)
730                 hget_field= get_field(filename_1);%open the get_field GUI
731                 set(hget_field,'name','get_field_1')
732%                 enable_transform(handles,'off')% no field transform (possible transform in the GUI get_field)
733             end
734            hhget_field=guidata(hget_field);%handles of GUI elements in get_field
735            SubField=get_field('read_var_names',hObject,eventdata,hhget_field); %read the names of the variables to plot in the get_field GUI
736            [Field{2},var_detect]=nc2struct(filename_1,SubField.ListVarName); %read the corresponding input data               
737            Field{2}.VarAttribute=SubField.VarAttribute;
738            %update the display on get_field
739            set(hhget_field.inputfile,'String',filename_1)
740            set(hhget_field.variables,'Value',1)
741            Tabchar={''};%default
742            Tabcell=[];
743            if isfield(Field{2},'ListGlobalAttribute')& ~isempty(Field{2}.ListGlobalAttribute)
744                for iline=1:length(Field{2}.ListGlobalAttribute)
745                    Tabcell{iline,1}=Field{2}.ListGlobalAttribute{iline};
746                    if isfield(Field{2}, Field{2}.ListGlobalAttribute{iline})
747                        eval(['val=Field{2}.' Field{2}.ListGlobalAttribute{iline} ';'])
748                        if ischar(val);
749                            Tabcell{iline,2}=val;
750                        else
751                            Tabcell{iline,2}=num2str(val);
752                        end
753                    end
754                end
755                if ~isempty(Tabcell)
756                    Tabchar=cell2tab(Tabcell,'=');
757                    Tabchar=[{''};Tabchar];
758                end
759            end
760            set(hhget_field.attributes,'String',Tabchar);%update list of global attributes in get_field
761        else
762            [Field{2},VelType_out_1]=read_civxdata(filename_1,[],VelType_1);
763            CivStage_1=Field{2}.CivStage;
764        end
765        if ~isequal(FileType,'netcdf')
766            VelType_out=VelType_out_1;
767        end
768    end
769end
770
771%update the display buttons for the first velocity type (first menuline)
772veltype_handles=[handles.civ1 handles.interp1 handles.filter1 handles.civ2 handles.interp2 handles.filter2];
773if ~isequal(FileType,'netcdf')
774    reset_vel_type(veltype_handles)
775elseif isempty(VelType)
776    set_veltype_display(veltype_handles,CivStage)%update the display of available velocity types for the first field
777    if isempty(VelType_out)
778        reset_vel_type(veltype_handles)
779    else
780        handle1=eval(['handles.' VelType_out]);
781        reset_vel_type(veltype_handles,handle1)
782    end
783end
784
785%update the display buttons for the second velocity type (second menuline)
786veltype_handles_1=[handles.civ1_1 handles.interp1_1 handles.filter1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1];
787if ~isequal(FileType_1,'netcdf')
788    reset_vel_type(veltype_handles_1)
789elseif isempty(VelType_1)
790    set_veltype_display(veltype_handles_1,CivStage_1)%update the display of available velocity types for the first field
791    if isempty(VelType_out_1)
792        reset_vel_type(veltype_handles_1)
793    else
794        handle1=eval(['handles.' VelType_out_1 '_1']);
795        reset_vel_type(veltype_handles_1,handle1)
796    end
797end
798
799%introduce w as background image by default for a new series (only for nbdim=2)
800if ~isfield(UvData,'NewSeries')
801    UvData.NewSeries=1;
802end
803%put W as background image by default if NbDim=2:
804if ~isfield(UvData,'NbDim')||isempty(UvData.NbDim)||~isequal(UvData.NbDim,3)
805    if UvData.NewSeries && isequal(get(handles.SubField,'Value'),0) && isfield(Field{1},'W') && ~isempty(Field{1}.W);
806        set(handles.SubField,'Value',1);
807        %menu=update_menu(handles.Fields_1,'w');%update the menu for the background scalar nd set the choice to 'w'
808        set(handles.RootPath_1,'String','"')
809        set(handles.RootFile_1,'String','"')
810        set(handles.SubDir_1,'String','"');
811        [indices]=name_generator('',num_i1,num_j1,'',NomType,1,num_i2,num_j2,'');
812        set(handles.FileIndex_1,'String',indices)
813        set(handles.FileExt_1,'String','"');
814        set(handles.Fields_1,'Visible','on');
815        set(handles.Fields_1,'Visible','on');
816        set(handles.RootPath_1,'Visible','on')
817        set(handles.RootFile_1,'Visible','on')
818        set(handles.SubDir_1,'Visible','on');
819        set(handles.FileIndex_1,'Visible','on');
820        set(handles.FileExt_1,'Visible','on');
821        set(handles.Fields_1,'Visible','on');
822        Field{1}.AName='w';
823        testscal=1;
824    end
825end           
826
827%multislice case
828if TestInputFile &&(~isfield(UvData,'NbDim') || isequal(UvData.NbDim,2))&&...%2D case
829      isfield(UvData,'XmlData') && isfield(UvData.XmlData,'GeometryCalib')&& isfield(UvData.XmlData.GeometryCalib,'SliceCoord')
830%     nbfield2=str2num(get(handles.last_j,'String'));
831       siz=size(UvData.XmlData.GeometryCalib.SliceCoord);
832       if siz(1)>1
833           NbSlice=siz(1);
834           set(handles.slices,'Visible','on')
835           set(handles.slices,'Value',1)
836       else
837           NbSlice=1;
838       end
839       set(handles.nb_slice,'String',num2str(NbSlice))
840       slices_Callback(hObject, eventdata, handles)
841%        Coord=UvData.XmlData.GeometryCalib.SliceCoord;
842%        ZIndex=num_i1-NbSlice*(floor((num_i1-1)/NbSlice));
843%        Field{1}.Z=ZIndex;
844end
845
846%store the current open names, fields and vel types in view_field interface
847UvData.filename=filename;
848UvData.filename_1=filename_1;
849UvData.VelType=VelType;
850UvData.VelType_1=VelType_1;
851UvData.FieldName=FieldName;
852UvData.FieldName_1=FieldName_1;
853if ~isempty(scal_color)
854    UvData.CName=scal_color;
855end
856
857%coordinate transform or user fct
858XmlData=[];%default
859if isfield(UvData,'XmlData')%use geometry calib recorded from the ImaDoc xml file as first priority
860    XmlData=UvData.XmlData;
861end
862XmlData_1=[];%default
863if isfield(UvData,'XmlData_1')
864   XmlData_1=UvData.XmlData_1;
865end
866menu_transform=get(handles.transform_fct,'String');
867choice_value=get(handles.transform_fct,'Value');
868%transform=menu_transform{choice_value};%name of the transform fct  given by the menu 'transform_fct'
869transform_list=get(handles.transform_fct,'UserData');
870transform=transform_list{choice_value};%selected function handles
871
872% z index
873if TestInputFile
874    Field{1}.ZIndex=mod(num_i1-1,nbslice)+1;
875end
876%px to phys or other transform on field
877if  ~isempty(transform)
878    if length(Field)>=2
879        Field{2}.ZIndex=mod(num_i1-1,nbslice)+1;
880        [Field{1},Field{2}]=transform(Field{1},XmlData,Field{2},XmlData_1);
881        if isempty(Field{2})
882            Field(2)=[];
883        end
884    else
885        Field{1}=transform(Field{1},XmlData);
886    end
887end
888
889%calculate scalar
890if isequal(FileType,'netcdf') && ~isequal(FieldName,'get_field...')%
891    Field{1}=calc_field(InputField,Field{1});
892end
893if length(Field)==2 && isequal(FileType_1,'netcdf') && ~isequal(FieldName_1,'get_field...')
894    Field{2}=calc_field(InputField_1,Field{2});
895end
896
897% combine the two input fields (e.g. substract velocity fields)
898if numel(Field)==2
899    if ~(isequal(get(handles.movie_pair,'Value'),1) && isequal(FieldName,'image') && isequal(FieldName_1,'image')) %combine fields if not viewing image pairs
900        UvData.Field=sub_field(Field{1},Field{2}); %TO UPDATE FOR MORE GENERAL INPUT
901    end
902else
903   UvData.Field=Field{1};
904end
905UvData.NewSeries=0;% put to 0 the test for a new field series (set by RootPath_callback)
906% test 3D , default projection menuplane and typical mesh (needed to menuopen set_object)
907test_x=0;
908test_z=0;% test for unstructured z coordinate
909UvData.ZMax=0;
910UvData.ZMin=0;%default
911UvData.Mesh=1; %default
912[UvData.Field,errormsg]=check_field_structure(UvData.Field);
913if ~isempty(errormsg)
914    msgbox_view_field('ERROR',['error in view_field/run0_Callback/check_field_structure: ' errormsg])
915    return
916end
917[CellVarIndex,NbDim,VarType]=find_field_indices(UvData.Field);
918[NbDim,imax]=max(NbDim);
919if isempty(imax)
920%    DimVarIndex=0;   
921    coord_x=[];
922else
923%     VarIndex=CellVarIndex{imax};
924    coord_x=VarType{imax}.coord_x;
925end
926if isfield(UvData,'NbDim') && ~isempty(UvData.NbDim)
927    NbDim=UvData.NbDim;
928else 
929    UvData.NbDim=NbDim;
930end
931if ~isempty(CellVarIndex) && ~isempty(VarType{imax}.coord_x)  && ~isempty(VarType{imax}.coord_y)    %unstructured coordinate z
932    XName=UvData.Field.ListVarName{VarType{imax}.coord_x};
933    YName=UvData.Field.ListVarName{VarType{imax}.coord_y};
934    test_x=1;
935elseif isfield(UvData.Field,'X') && isfield(UvData.Field,'Y')
936    XName='X';
937    YName='Y';
938    test_x=1;
939end
940if test_x
941    eval(['UvData.XMax=max(UvData.Field.' XName ');'])
942    eval(['UvData.XMin=min(UvData.Field.' XName ');'])
943    eval(['UvData.YMax=max(UvData.Field.' YName ');'])
944    eval(['UvData.YMin=min(UvData.Field.' YName ');'])
945    eval(['nbvec=length(UvData.Field.' XName ');'])
946    if NbDim==3%
947        if ~isempty(CellVarIndex) && ~isempty(VarType{imax}.coord_z)%unstructured coordinate z
948            ZName=UvData.Field.ListVarName{VarType{imax}.coord_z};
949            eval(['UvData.ZMax=max(UvData.Field.' ZName ');'])
950            eval(['UvData.ZMin=min(UvData.Field.' ZName ');'])
951            test_z=1;   
952        elseif isfield(UvData,'Z')% usual civ data
953            UvData.ZMax=max(UvData.Z);
954            UvData.ZMin=min(UvData.Z);
955            test_z=1;
956        end
957    end
958    if isequal(UvData.ZMin,UvData.ZMax)%no z dependency
959        NbDim=2;
960        test_z=0;
961    end   
962    if test_z
963         UvData.Mesh=((UvData.XMax-UvData.XMin)*(UvData.YMax-UvData.YMin)*(UvData.ZMax-UvData.ZMin))/nbvec;% volume per vector
964         UvData.Mesh=(UvData.Mesh)^(1/3);
965    else
966        UvData.Mesh=sqrt((UvData.XMax-UvData.XMin)*(UvData.YMax-UvData.YMin)/nbvec);%2D
967    end
968end
969%case of structured coordinates
970if isfield(UvData.Field,'AX') & isfield(UvData.Field,'AY')& isfield(UvData.Field,'A')
971    UvData.XMax=max(UvData.Field.AX);
972    UvData.XMin=min(UvData.Field.AX);
973    UvData.YMax=max(UvData.Field.AY);
974    UvData.YMin=min(UvData.Field.AY);
975    np_A=size(UvData.Field.A);
976    UvData.Mesh=sqrt((UvData.XMax-UvData.XMin)*(UvData.YMax-UvData.YMin)/((np_A(1)-1) * (np_A(2)-1))) ;
977end
978if  isempty(coord_x)&~isempty(CellVarIndex)
979    VarIndex=CellVarIndex{imax}; % list of variable indices
980    DimIndex=UvData.Field.VarDimIndex{VarIndex(1)}; %list of dim indices for the variable
981    if NbDim==3
982        nbpoints=UvData.Field.DimValue(DimIndex(1));
983        %Zvar=DimVarIndex(DimIndex(1));
984         %Zvar=DimVarIndex(1);
985         Zvar=VarType{imax}.coord_3;
986        if Zvar~=0 % z is a dimension variable
987            ZName=UvData.Field.ListVarName{Zvar};
988            eval(['UvData.ZMax=max(UvData.Field.' ZName ');'])
989            eval(['UvData.ZMin=min(UvData.Field.' ZName ');'])
990        else
991            testcoord_z=0;
992            if length(UvData.Field.VarAttribute)>=VarIndex(1)
993                if isfield(UvData.Field.VarAttribute{VarIndex(1)},'Coord_1')%regular grid
994                    Coord_z=UvData.Field.VarAttribute{VarIndex(1)}.Coord_1;
995                    UvData.ZMax=max(Coord_z);
996                    UvData.ZMin=min(Coord_z);
997                    testcoord_z=1;
998                end
999            end
1000            if ~testcoord_z
1001                  UvData.ZMin=1;
1002                  UvData.ZMax=UvData.Field.DimValue(DimIndex(1));
1003            end
1004        end
1005        UvData.Mesh=(UvData.ZMax-UvData.ZMin)/(nbpoints-1);
1006    elseif NbDim==2
1007        nbpoints_y=UvData.Field.DimValue(DimIndex(1));       
1008        Yvar=VarType{imax}.coord_y;
1009        if Yvar~=0  % x is a dimension variable
1010            YName=UvData.Field.ListVarName{Yvar};
1011            eval(['UvData.YMax=max(UvData.Field.' YName ');'])
1012            eval(['UvData.YMin=min(UvData.Field.' YName ');'])
1013        else
1014            testcoord_y=0;
1015            if ~testcoord_y
1016                  UvData.YMin=1;
1017                  UvData.YMax=UvData.Field.DimValue(DimIndex(1));
1018            end
1019        end
1020        DY=(UvData.YMax-UvData.YMin)/(nbpoints_y-1);
1021        nbpoints_x=UvData.Field.DimValue(DimIndex(2));
1022        Xvar=VarType{imax}.coord_x;
1023        if Xvar~=0  % x is a dimension variable
1024            XName=UvData.Field.ListVarName{Xvar};
1025            eval(['UvData.XMax=max(UvData.Field.' XName ');'])
1026            eval(['UvData.XMin=min(UvData.Field.' XName ');'])
1027        else
1028            testcoord_x=0;
1029            if ~testcoord_x
1030                  UvData.XMin=1;
1031                  UvData.XMax=UvData.Field.DimValue(DimIndex(2));
1032            end
1033        end
1034        DX=(UvData.XMax-UvData.XMin)/(nbpoints_x-1);
1035        UvData.Mesh= sqrt(DX*DY);
1036    end
1037end
1038
1039%create a default projection menuplane
1040UvData.Object{1}.Style='plane';%main plotting plane
1041UvData.Object{1}.ProjMode='projection';%main plotting plane
1042if ~isfield(UvData.Object{1},'plotaxes')
1043    UvData.Object{1}.plotaxes=handles.axes3;%default plotting axis
1044    set(handles.list_object,'String',{'1-PLANE';'...'});
1045    set(handles.list_object,'Value',1);
1046end
1047
1048%3D case (menuvolume)
1049if NbDim==3
1050    UvData.Object{1}.NbDim=UvData.NbDim;%test for 3D objects
1051    UvData.Object{1}.RangeZ=UvData.Mesh;%main plotting plane
1052    UvData.Object{1}.Coord(1,3)=(UvData.ZMin+UvData.ZMax)/2;%section at a middle plane chosen
1053    UvData.Object{1}.Phi=0;
1054    UvData.Object{1}.Theta=0;
1055    UvData.Object{1}.Psi=0;
1056    UvData.Object{1}.HandlesDisplay=plot(0,0,'Tag','proj_object');% A REVOIR 
1057    PlotHandles=get_plot_handles(handles);
1058    ZBounds(1)=UvData.ZMin; %minimum for the Z slider
1059    ZBounds(2)=UvData.ZMax;%maximum for the Z slider
1060    set_object(UvData.Object{1},PlotHandles,ZBounds);
1061    set(handles.list_object,'Value',1);
1062%multilevel case (single menuplane in a 3D space)
1063elseif isfield(UvData,'Z')
1064    if isfield(UvData,'CoordType')& isequal(UvData.CoordType,'phys') & isfield(UvData,'XmlData')
1065        XmlData=UvData.XmlData;
1066        if isfield(XmlData,'PlanePos')
1067             UvData.Object{1}.Coord=XmlData.PlanePos(UvData.ZIndex,:);
1068        end
1069        if isfield(XmlData,'PlaneAngle')
1070            siz=size(XmlData.PlaneAngle);
1071            indangle=min(siz(1),UvData.ZIndex);%take first angle if a single angle is defined (translating scanning)             
1072            UvData.Object{1}.Phi=XmlData.PlaneAngle(indangle,1);
1073            UvData.Object{1}.Theta=XmlData.PlaneAngle(indangle,2);
1074            UvData.Object{1}.Psi=XmlData.PlaneAngle(indangle,3);
1075        end
1076    elseif isfield(UvData,'ZIndex')
1077        UvData.Object{1}.ZObject=UvData.ZIndex;
1078    end
1079end
1080
1081%Plot the projections on all existing  projection objects
1082keeplim=get(handles.FixedLimits,'Value');
1083%reset the min and max of scalar if only the mask is displayed
1084if isfield(UvData,'Mask')&~isfield(UvData,'A')
1085    set(handles.MinA,'String','0')
1086    set(handles.MaxA,'String','255')
1087end
1088
1089Object=UvData.Object;
1090for iobj=1:length(Object)
1091    if ~isempty(Object{iobj})%& isfield(Object{iobj},'plotaxes')& ishandle(Object{iobj}.plotaxes)
1092        %Projeter les champs sur l'objet:*
1093        ObjectData=proj_field(UvData.Field,Object{iobj},iobj);
1094   
1095        %use of mask
1096        if isfield(ObjectData,'NbDim')&isequal(ObjectData.NbDim,2)
1097            if isfield(ObjectData,'Mask') & isfield(ObjectData,'A')
1098                 flag_mask=double(ObjectData.Mask>200);%=0 for masked regions
1099                 AX=ObjectData.AX;
1100                 AY=ObjectData.AY;
1101                 MaskX=ObjectData.MaskX;
1102                 MaskY=ObjectData.MaskY;
1103                 if ~isequal(MaskX,AX)|~isequal(MaskY,AY)
1104                     nxy=size(flag_mask);
1105                     sizpx=(ObjectData.MaskX(end)-ObjectData.MaskX(1))/(nxy(2)-1);%size of a mask pixel
1106                     sizpy=(ObjectData.MaskY(1)-ObjectData.MaskY(end))/(nxy(1)-1);
1107                     x_mask=[ObjectData.MaskX(1):sizpx:ObjectData.MaskX(end)]; % pixel x coordinates for image display
1108                     y_mask=[ObjectData.MaskY(1):-sizpy:ObjectData.MaskY(end)];% pixel x coordinates for image display
1109                     %project on the positions of the scalar
1110                     npxy=size(ObjectData.A);
1111                     dxy(1)=(ObjectData.AY(end)-ObjectData.AY(1))/(npxy(1)-1);%grid mesh in y
1112                     dxy(2)=(ObjectData.AX(end)-ObjectData.AX(1))/(npxy(2)-1);%grid mesh in x
1113                     xi=[ObjectData.AX(1):dxy(2):ObjectData.AX(end)];
1114                     yi=[ObjectData.AY(1):dxy(1):ObjectData.AY(end)];     
1115                     [XI,YI]=meshgrid(xi,yi);% creates the matrix of regular coordinates
1116                    flag_mask = interp2(x_mask,y_mask,flag_mask,XI,YI);
1117                 end
1118                 AClass=class(ObjectData.A);
1119                 ObjectData.A=flag_mask.*double(ObjectData.A);
1120                 ObjectData.A=feval(AClass,ObjectData.A);
1121                 ind_off=[];
1122                 if isfield(ObjectData,'ListVarName')
1123                      for ilist=1:length(ObjectData.ListVarName)
1124                           if isequal(ObjectData.ListVarName{ilist},'Mask')|isequal(ObjectData.ListVarName{ilist},'MaskX')|isequal(ObjectData.ListVarName{ilist},'MaskY')
1125                               ind_off=[ind_off ilist];
1126                           end
1127                      end
1128                      ObjectData.ListVarName(ind_off)=[];
1129                      ObjectData.VarDimIndex(ind_off)=[];
1130                      ind_off=[];       
1131                      for ilist=1:length(ObjectData.ListDimName)       
1132                           if isequal(ObjectData.ListDimName{ilist},'MaskX')|isequal(ObjectData.ListDimName{ilist},'MaskY')
1133                               ind_off=[ind_off ilist];
1134                           end
1135                      end
1136                      ObjectData.ListDimName(ind_off)=[];
1137                      ObjectData.DimValue(ind_off)=[];
1138                 end
1139            end 
1140        end
1141        if ~isempty(ObjectData)
1142            haxes=[];%default
1143            if isfield(Object{iobj},'plotaxes')
1144                haxes=Object{iobj}.plotaxes;%axes used for representing the projection on the object
1145            end
1146            PosColorbar=[];%default: no colorbar
1147            if ishandle(haxes) & isequal(get(haxes,'Tag'),'axes3')& isfield(UvData,'PosColorbar')
1148                PosColorbar=UvData.PosColorbar;%prescribe the colorbar position on the view_field interface
1149            else
1150                PosColorbar='*';%default position
1151            end
1152            PlotParam=read_plot_param(handles);%read plotting parameters on the view_field interface
1153            [PlotType,ScalOut,UvData.Object{iobj}.plotaxes]=plot_field(ObjectData,haxes,PlotParam,keeplim,PosColorbar);
1154            if isequal(PlotType,'none')
1155                hget_field=findobj(allchild(0),'name','get_field');
1156                if isempty(hget_field)
1157                    get_field([],ObjectData)% the projected field cannot be automatically plotted: use get_field to specify the variablesdelete(hget_field)
1158                else
1159                    msgbox_view_field('ERROR','The field defined by get_field cannot be plotted')
1160                end
1161            end 
1162            UvData.Object{iobj}.PlotParam=ScalOut; %record the plotting parameters
1163        end
1164       
1165    end
1166end
1167
1168%display the updated plotting parameters for the base menuplane
1169write_plot_param(handles,UvData.Object{1}.PlotParam);% update the display of the plotting parameters
1170set(handles.view_field,'UserData',UvData)
1171
1172%update the mask
1173if isequal(get(handles.mask_test,'Value'),1)%if the mask option is on
1174   update_mask(handles,num_i1,num_i2);
1175end
1176
1177%prepare the menus of histograms (for the whole menuvolume in 3D case)
1178menu_histo=(UvData.Field.ListVarName)';
1179ind_bad=[];
1180nb_histo=1;
1181for ivar=1:numel(menu_histo)
1182    if isfield(UvData.Field,'VarAttribute') && numel(UvData.Field.VarAttribute)>=ivar && isfield(UvData.Field.VarAttribute{ivar},'Role')
1183        Role=UvData.Field.VarAttribute{ivar}.Role;
1184        switch Role
1185            case {'coord_x','coord_y','coord_z','dimvar'}
1186                ind_bad=[ind_bad ivar];
1187            case {'vector_y'}
1188                nb_histo=nb_histo+1;
1189        end
1190    end
1191    DimCell=UvData.Field.VarDimName{ivar};
1192    DimName='';
1193    if ischar(DimCell)
1194        DimName=DimCell;
1195    elseif iscell(DimCell)&& numel(DimCell)==1
1196        DimName=DimCell{1};
1197    end
1198    if strcmp(DimName,menu_histo{ivar})
1199        ind_bad=[ind_bad ivar];
1200    end
1201end
1202menu_histo(ind_bad)=[];
1203test_v=0;
1204if ~isempty(menu_histo)
1205    set(handles.histo1_menu,'Value',1)
1206    set(handles.histo1_menu,'String',menu_histo)
1207    histo1_menu_Callback(hObject, eventdata, handles)
1208    if nb_histo > 1
1209        test_v=1;
1210        set(handles.histo2_menu,'Visible','on')
1211        set(handles.histo_v,'Visible','on')
1212        set(handles.histo2_menu,'String',menu_histo)
1213        set(handles.histo2_menu,'Value',2)
1214        histo2_menu_Callback(hObject, eventdata, handles)
1215    end
1216end
1217if ~test_v
1218    set(handles.histo2_menu,'Visible','off')
1219    set(handles.histo_v,'Visible','off')
1220    cla(handles.histo_v)
1221    set(handles.histo2_menu,'Value',1)
1222end
1223
1224%display time
1225testimedoc=0;
1226if isfield(UvData,'XmlData') && isfield(UvData.XmlData,'Time')
1227    if isempty(num_i2)
1228        num_i2=num_i1;
1229    end
1230    if isempty(num_j1)
1231        num_j1=1;
1232    end
1233    if isempty(num_j2)
1234        num_j2=num_j1;
1235    end
1236    siz=size(UvData.XmlData.Time);
1237    if siz(1)>=max(num_i1,num_i2) & siz(2)>=max(num_j1,num_j2)
1238        abstime=(UvData.XmlData.Time(num_i1,num_j1)+UvData.XmlData.Time(num_i2,num_j2))/2;%overset the time read from files
1239        dt=(UvData.XmlData.Time(num_i2,num_j2)-UvData.XmlData.Time(num_i1,num_j1));
1240        testimedoc=1;
1241    end
1242end
1243if isfield(UvData,'XmlData_1') && isfield(UvData.XmlData_1,'Time')
1244    [P,F,str1,str2,str_a,str_b,E,NomType]=name2display(['xx' get(handles.FileIndex_1,'String') get(handles.FileExt_1,'String')]);
1245    num_i2=str2num(str2);
1246    if isempty(num_i2)
1247        num_i2=num_i1;
1248    end
1249    num_j1=str2num(str_a);
1250    if isempty(num_j1)
1251        num_j1=1;
1252    end
1253    num_j2=str2num(str_b);
1254    if isempty(num_j2)
1255        num_j2=num_j1;
1256    end
1257    num_i1=str2num(str1);
1258    siz=size(UvData.XmlData_1.Time);
1259    if siz(1)>=max(num_i1,num_i2) & siz(2)>=max(num_j1,num_j2)
1260        abstime_1=(UvData.XmlData_1.Time(num_i1,num_j1)+UvData.XmlData_1.Time(num_i2,num_j2))/2;%overset the time read from files
1261    end
1262end
1263set(handles.abs_time,'String',num2str(abstime,4))
1264set(handles.abs_time_1,'String',num2str(abstime_1,4))
1265if testimedoc && isfield(UvData,'dt')
1266    dt=UvData.dt;
1267end
1268if isequal(dt,0)
1269    set(handles.Dt_txt,'String','')
1270else
1271    if ~(isfield(UvData,'TimeUnit') && ~isempty(UvData.TimeUnit))
1272        set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) '  10^(-3)'] )
1273    else
1274        set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) '  m' UvData.TimeUnit] )
1275    end
1276end
1277set(handles.run0,'BackgroundColor',[1 0 0])
1278
1279
1280
1281%-------------------------------------------------------------------
1282% --- translate coordinate to matrix index
1283%-------------------------------------------------------------------
1284function [indx,indy]=pos2ind(x0,rangx0,nxy)
1285indx=1+round((nxy(2)-1)*(x0-rangx0(1))/(rangx0(2)-rangx0(1)));% index x of pixel 
1286indy=1+round((nxy(1)-1)*(y12-rangy0(1))/(rangy0(2)-rangy0(1)));% index y of pixel
1287
1288%-------------------------------------------------------------------
1289% --- Executes on button press in 'FixedLimits'.
1290%-------------------------------------------------------------------
1291function FixedLimits_Callback(hObject, eventdata, handles)
1292test=get(handles.FixedLimits,'Value');
1293if test
1294    set(handles.FixedLimits,'BackgroundColor',[1 1 0])
1295else
1296    set(handles.FixedLimits,'BackgroundColor',[0.7 0.7 0.7])
1297end
1298
1299%-------------------------------------------------------------------
1300% --- Executes on button press in auto_xy.
1301function auto_xy_Callback(hObject, eventdata, handles)
1302test=get(handles.auto_xy,'Value');
1303if test
1304    set(handles.auto_xy,'BackgroundColor',[1 1 0])
1305    cla(handles.axes3)
1306    update_plot(handles)
1307else
1308    set(handles.auto_xy,'BackgroundColor',[0.7 0.7 0.7])
1309    update_plot(handles)
1310%     axis(handles.axes3,'image')
1311end
1312
1313
1314%-------------------------------------------------------------------
1315
1316%-------------------------------------------------------------------
1317% --- Executes on button press in 'zoom'.
1318%-------------------------------------------------------------------
1319function zoom_Callback(hObject, eventdata, handles)
1320if (get(handles.zoom,'Value') == 1);
1321    set(handles.zoom,'BackgroundColor',[1 1 0])
1322    set(handles.FixedLimits,'Value',1)% propose by default fixed limits for the plotting axes
1323    set(handles.FixedLimits,'BackgroundColor',[1 1 0])
1324else
1325    set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
1326end
1327
1328%-------------------------------------------------------------------
1329%----Executes on button press in 'record': records the current flags of manual correction.
1330%-------------------------------------------------------------------
1331function record_Callback(hObject, eventdata, handles)
1332% [filebase,num_i1,num_j1,num_i2,num_j2,Ext,NomType,SubDir]=read_input_file(handles);
1333filename=read_file_boxes(handles);
1334AxeData=get(gca,'UserData');
1335[erread,message]=fileattrib(filename);
1336if ~isempty(message) && ~isequal(message.UserWrite,1)
1337     msgbox_view_field('ERROR',['no writting access to ' filename])
1338     return
1339end
1340test_civ2=isequal(get(handles.civ2,'BackgroundColor'),[1 1 0]);
1341test_civ1=isequal(get(handles.civ1,'BackgroundColor'),[1 1 0]);
1342if ~test_civ2 && ~test_civ1
1343    msgbox_view_field('ERROR','manual correction only possible for CIV1 or CIV2 velocity fields')
1344end
1345if test_civ2
1346    nbname='nb_vectors2';
1347   flagname='vec2_FixFlag';
1348   attrname='fix2';
1349end
1350if test_civ1
1351    nbname='nb_vectors';
1352   flagname='vec_FixFlag';
1353   attrname='fix';
1354end
1355%write fix flags in the netcdf file
1356hhh=which('netcdf.open');% look for built-in matlab netcdf library
1357if ~isequal(hhh,'')% case of new builtin Matlab netcdf library
1358    nc=netcdf.open(filename,'NC_WRITE');
1359    netcdf.reDef(nc)
1360    netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),attrname,1)
1361    dimid = netcdf.inqDimID(nc,nbname);
1362    try
1363        varid = netcdf.inqVarID(nc,flagname);% look for already existing fixflag variable
1364    catch
1365        varid=netcdf.defVar(nc,flagname,'double',dimid);%create fixflag variable if it does not exist
1366    end
1367    netcdf.endDef(nc)
1368    netcdf.putVar(nc,varid,AxeData.FF);
1369    netcdf.close(nc) 
1370else %old netcdf library
1371    netcdf_toolbox(filename,AxeData,attrname,nbname,flagname)
1372end
1373
1374function netcdf_toolbox(filename,AxeData,attrname,nbname,flagname)
1375nc=netcdf(filename,'write'); %open netcdf file
1376result=redef(nc);
1377eval(['nc.' attrname '=1;']);
1378theDim=nc(nbname) ;% get the number of velocity vectors
1379nb_vectors=size(theDim);
1380var_FixFlag=ncvar(flagname,nc);% var_FixFlag will be written as the netcdf variable vec_FixFlag
1381var_FixFlag(1:nb_vectors)=AxeData.FF;%
1382fin=close(nc);
1383
1384
1385%-------------------------------------------------------------------
1386%determines the fields to read from the interface
1387%------------------------------------------------------------------
1388function [VelType,civ]=setfield(handles)
1389
1390VelType=[]; %default
1391if (get(handles.civ1,'Value') == 1);
1392        VelType='civ1';
1393% interp1   
1394elseif (get(handles.interp1,'Value') == 1);
1395    VelType='interp1';
1396% filter1   
1397elseif (get(handles.filter1,'Value') == 1);
1398    VelType='filter1'; 
1399% CIV2
1400elseif (get(handles.civ2,'Value') == 1);
1401    VelType='civ2';
1402% interp2   
1403elseif (get(handles.interp2,'Value') == 1);
1404    VelType='interp2';
1405% filter2   
1406elseif (get(handles.filter2,'Value') == 1); 
1407    VelType='filter2';
1408end
1409
1410if isequal(get(handles.filter2,'Visible'),'on');
1411    civ=6;
1412% interp1   
1413elseif isequal(get(handles.interp2,'Visible'),'on');
1414    civ=5;
1415% filter1   
1416elseif isequal(get(handles.civ2,'Visible'),'on');
1417    civ=4; 
1418% CIV2
1419elseif isequal(get(handles.filter1,'Visible'),'on');
1420   civ=3;
1421% interp2   
1422elseif isequal(get(handles.interp1,'Visible'),'on');
1423    civ=2;
1424% filter2   
1425elseif isequal(get(handles.civ1,'Visible'),'on'); 
1426    civ=1;
1427else
1428    civ=0;
1429end
1430
1431%-------------------------------------------------------------------
1432%determines the veltype of the second field to read from the iinterface
1433%------------------------------------------------------------------
1434function VelType=setfield_1(handles)
1435
1436VelType=[]; %default
1437if (get(handles.civ1_1,'Value') == 1);
1438    VelType='civ1';
1439% interp1   
1440elseif (get(handles.interp1_1,'Value') == 1);
1441    VelType='interp1';
1442% filter1   
1443elseif (get(handles.filter1_1,'Value') == 1);
1444    VelType='filter1'; 
1445% CIV2
1446elseif (get(handles.civ2_1,'Value') == 1);
1447    VelType='civ2';
1448% interp2   
1449elseif (get(handles.interp2_1,'Value') == 1);
1450    VelType='interp2';
1451% filter2   
1452elseif (get(handles.filter2_1,'Value') == 1); 
1453    VelType='filter2';
1454end
1455
1456
1457%---------------------------------------------------
1458% --- Executes on button press in SubField
1459function SubField_Callback(hObject, eventdata, handles)
1460huvmat=get(handles.run0,'parent');
1461UvData=get(huvmat,'UserData');
1462if get(handles.SubField,'Value')==0% if the subfield button is desactivated   
1463    set(handles.RootPath_1,'String','')
1464    set(handles.RootFile_1,'String','')
1465    set(handles.SubDir_1,'String','');
1466    set(handles.FileIndex_1,'String','');
1467    set(handles.FileExt_1,'String','');
1468    set(handles.RootPath_1,'Visible','off')
1469    set(handles.RootFile_1,'Visible','off')
1470    set(handles.SubDir_1,'Visible','off');
1471    set(handles.FileIndex_1,'Visible','off');
1472    set(handles.FileExt_1,'Visible','off');
1473    set(handles.Fields_1,'Value',1);%set to blank state
1474    set_veltype_display([handles.civ1_1 handles.interp1_1 handles.filter1_1 ...
1475            handles.civ2_1 handles.interp2_1 handles.filter2_1],0)
1476    if isfield(UvData,'XmlData_1')
1477        UvData=rmfield(UvData,'XmlData_1');
1478    end
1479    set(huvmat,'UserData',UvData);
1480    run0_Callback(hObject, eventdata, handles); %run
1481else
1482    MenuBrowse_1_Callback(hObject, eventdata, handles)
1483end
1484
1485% %----------------------------------------------
1486% %read the data displayed for the input rootfile windows (new)
1487% %-------------------------------------------------
1488function [FileName,RootPath,FileBase,FileIndices,FileExt,SubDir]=read_file_boxes(handles)
1489RootPath=get(handles.RootPath,'String');
1490FileName=RootPath; %default
1491SubDir=get(handles.SubDir,'String');
1492if ~isempty(SubDir) && ~isequal(SubDir,'')
1493    if (isequal(SubDir(1),'/')|| isequal(SubDir(1),'\'))
1494        SubDir(1)=[]; %suppress possible / or \ separator
1495    end
1496    FileName=fullfile(RootPath,SubDir);
1497end
1498RootFile=get(handles.RootFile,'String');
1499if ~isempty(RootFile) && ~isequal(RootFile,'')
1500    if (isequal(RootFile(1),'/')|| isequal(RootFile(1),'\'))
1501        RootFile(1)=[]; %suppress possible / or \ separator
1502    end
1503    FileName=fullfile(FileName,RootFile);
1504end
1505FileBase=fullfile(RootPath,RootFile);
1506FileIndices=get(handles.FileIndex,'String');
1507FileExt=get(handles.FileExt,'String');
1508FileName=[FileName FileIndices FileExt];
1509
1510%----------------------------------------------
1511%read the data displayed for the second input rootfile windows
1512%-------------------------------------------------
1513function [FileName_1,RootPath_1,FileBase_1,FileIndices_1,FileExt_1,SubDir_1]=read_file_boxes_1(handles)
1514RootPath_1=get(handles.RootPath_1,'String'); % read the data from the file1_input window
1515if isequal(RootPath_1,'"'),RootPath_1=get(handles.RootPath,'String'); end;
1516FileName_1=RootPath_1; %default
1517SubDir_1=get(handles.SubDir_1,'String');
1518if isequal(SubDir_1,'"')
1519    SubDir_1=get(handles.SubDir,'String');
1520end
1521if ~isempty(SubDir_1) && ~isequal(SubDir_1,'')
1522    if (isequal(SubDir_1(1),'/')|| isequal(SubDir_1(1),'\'))
1523        SubDir_1(1)=[]; %suppress possible / or \ separator
1524    end
1525    FileName_1=fullfile(RootPath_1,SubDir_1);
1526end
1527RootFile_1=get(handles.RootFile_1,'String');
1528if isequal(RootFile_1,'"'),RootFile_1=get(handles.RootFile,'String'); end;
1529if ~isempty(RootFile_1) && ~isequal(RootFile_1,'')
1530    if ~(isequal(RootFile_1(1),'/')|isequal(RootFile_1(1),'\'))
1531        RootFile_1(1)=[];%suppress possible / or \ separator
1532    end
1533    FileName_1=fullfile(FileName_1,RootFile_1);
1534end
1535FileBase_1=fullfile(RootPath_1,RootFile_1);
1536FileIndices_1=get(handles.FileIndex_1,'String');
1537FileExt_1=get(handles.FileExt_1,'String');
1538if isequal(FileExt_1,'"'),FileExt_1=get(handles.FileExt,'String'); end;
1539FileName_1=[FileName_1 FileIndices_1 FileExt_1];
1540
1541%---------------------------------------------------
1542% --- Executes on menu selection Fields
1543function Fields_Callback(hObject, eventdata, handles)
1544%-------------------------------------------------
1545huvmat=get(handles.Fields,'parent');
1546list_fields=get(handles.Fields,'String');% list menu fields
1547index_fields=get(handles.Fields,'Value');% selected string index
1548field= list_fields{index_fields(1)}; % selected string
1549if isequal(field,'get_field...')
1550     veltype_handles=[handles.civ1 handles.interp1 handles.filter1 handles.civ2 handles.interp2 handles.filter2];
1551     set_veltype_display(veltype_handles,0) % unvisible civ buttons
1552     filename=read_file_boxes(handles);
1553     hget_field=findobj(allchild(0),'name','get_field');
1554     if ~isempty(hget_field)
1555         delete(hget_field)
1556     end
1557     get_field(filename)
1558    return %no action
1559end
1560list_fields=get(handles.Fields_1,'String');% list menu fields
1561index_fields=get(handles.Fields_1,'Value');% selected string index
1562field_1= list_fields{index_fields(1)}; % selected string
1563UvData=get(huvmat,'UserData');
1564
1565%read the rootfile input display
1566FileExt=get(handles.FileExt,'String');
1567[P,F,str1,str2,str_a,str_b,E,NomType]=name2display(['xxx' get(handles.FileIndex,'String') FileExt]);
1568NomTypeNew=NomType;%default
1569if isequal(field,'image')
1570    % transform netc type to the corresponding image type
1571    if isequal(NomType,'_i1-i2_j')||isequal(NomType,'_i_j1-j2')|| isequal(NomType,'#_ab')|| isequal(NomType,'_i1-i2')
1572        UvData.SubDir=get(handles.SubDir,'String'); %preserve the subdir in memory
1573        if ~isempty(UvData.SubDir) && (isequal(UvData.SubDir(1),'/')||isequal(UvData.SubDir(1),'/'))
1574            UvData.SubDir(1)=[];
1575        end
1576        set(handles.SubDir,'String','')
1577        set(handles.FileExt,'String','.png');
1578        if isequal(NomType,'_i1-i2_j')||isequal(NomType,'_i_j1-j2')
1579            NomTypeNew='_i_j';
1580        elseif isequal(NomType,'#_ab')
1581            NomTypeNew='#a';
1582        elseif isequal(NomType,'_i1-i2')
1583            NomTypeNew='_i';
1584        end 
1585    end
1586    veltype_handles=[handles.civ1 handles.interp1 handles.filter1 handles.civ2 handles.interp2 handles.filter2];
1587    set_veltype_display(veltype_handles,0) % unvisible civ buttons
1588else
1589    ext=get(handles.FileExt,'String');
1590    if ~isequal(ext,'.nc') %find the new NomType if the previous display was not already a netcdf file
1591         MenuBrowse_Callback(hObject, eventdata, handles)
1592    end
1593    if isequal(field,'vort') || isequal(field,'div') || isequal(field,'strain')
1594        set(handles.civ1,'BackgroundColor',[0.702 0.702 0.702]) % put their color to grey
1595        set(handles.civ2,'BackgroundColor',[0.702 0.702 0.702])
1596        set(handles.interp1,'BackgroundColor',[0.702 0.702 0.702])
1597        set(handles.interp2,'BackgroundColor',[0.702 0.702 0.702])
1598    elseif isequal(field,'more...');
1599        set(handles.civ1,'BackgroundColor',[0.702 0.702 0.702]) % put their color to grey
1600        set(handles.civ2,'BackgroundColor',[0.702 0.702 0.702])
1601        str=calc_field;%get the list of available scalars by the function calc_scal
1602        [ind_answer] = listdlg('PromptString','Select a file:',...
1603                'SelectionMode','single',...
1604                'ListString',str);
1605       % edit the choice in the field and action menu
1606        scalar=cell2mat(str(ind_answer));
1607        menu=update_menu(handles.Fields,scalar);
1608        menu=[{''};menu];
1609        set(handles.Fields_1,'String',menu);% store the selected scalar type
1610    end
1611end
1612indices=name_generator('',str2double(str1),str2double(str_a),'',NomTypeNew,1,str2double(str2),str2double(str_b),'');
1613set(handles.FileIndex,'String',indices)
1614set(handles.FileIndex,'UserData',NomTypeNew)
1615%common to Fields_1_Callback
1616if isequal(field,'image')||isequal(field_1,'image')
1617    set(handles.npx_title,'Visible','on')% visible npx,pxcm... buttons
1618    set(handles.npy_title,'Visible','on')
1619    set(handles.npx,'Visible','on')
1620    set(handles.npy,'Visible','on')
1621    set(handles.fix_pair,'Value',0)
1622else
1623    set(handles.npx_title,'Visible','off')% visible npx,pxcm... buttons
1624    set(handles.npy_title,'Visible','off')
1625    set(handles.npx,'Visible','off')
1626    set(handles.npy,'Visible','off')
1627    set(handles.fix_pair,'Value',1)
1628end
1629% if isequal(field,'velocity')|isequal(field_1,'velocity');
1630%     state_vect='on';
1631% else
1632%     state_vect='off';
1633% end
1634% if ~isequal(field,'velocity')|(~isequal(field_1,'velocity'));
1635%     state_scal='on';
1636% else
1637%     state_scal='off';
1638% end
1639setfield(handles);% update the field structure ('civ1'....)
1640
1641if ~isfield(UvData,'NewSeries')||isequal(UvData.NewSeries,0)
1642    run0_Callback(hObject, eventdata, handles)
1643end
1644
1645%---------------------------------------------------
1646% --- Executes on menu selection Fields
1647function Fields_1_Callback(hObject, eventdata, handles)
1648%-------------------------------------------------
1649huvmat=get(handles.Fields_1,'parent');
1650list_fields=get(handles.Fields,'String');% list menu fields
1651index_fields=get(handles.Fields,'Value');% selected string index
1652field= list_fields{index_fields(1)}; % selected string
1653list_fields=get(handles.Fields_1,'String');% list menu fields
1654index_fields=get(handles.Fields_1,'Value');% selected string index
1655field_1= list_fields{index_fields(1)}; % selected string for the second field
1656if isequal(field_1,'') %remove second field if 'blank' field is selected
1657    set(handles.SubField,'Value',0)
1658    SubField_Callback(hObject, eventdata, handles)
1659    return
1660end
1661UvData=get(huvmat,'UserData');
1662
1663%read the rootfile input display
1664FileExt_prev=get(handles.FileExt_1,'String');
1665if isempty(FileExt_prev)|isequal(FileExt_prev,'')
1666    FileExt_1=get(handles.FileExt,'String');
1667else
1668    FileExt_1=FileExt_prev;
1669end
1670NomType_1=get(handles.FileIndex_1,'UserData');
1671if isempty(NomType_1)|isequal(NomType_1,'')
1672    NomType_1=get(handles.FileIndex,'UserData');
1673end
1674NomTypeNew=NomType_1;%default
1675
1676set(handles.SubField,'Value',1)%introduce second field
1677if isfield(UvData,'XmlData')
1678    UvData.XmlData_1=UvData.XmlData;
1679end
1680set(handles.FileIndex_1,'Visible','on')
1681set(handles.FileExt_1,'Visible','on')
1682RootPath_1=get(handles.RootPath_1,'String');
1683RootFile_1=get(handles.RootFile_1,'String');
1684if isempty(RootPath_1)|isequal(RootPath_1,'')
1685    set(handles.RootPath_1,'String','"')
1686end
1687if isempty(RootFile_1) | isequal(RootFile_1,'')
1688    set(handles.RootFile_1,'String','"')
1689end
1690if ~isempty(RootFile_1)&(isequal(RootFile_1(1),'/')|isequal(RootFile_1(1),'\'))
1691    RootFile_1(1)=[];
1692end
1693
1694if isequal(field_1,'get_field...')
1695     veltype_handles=[handles.civ1 handles.interp1 handles.filter1 handles.civ2 handles.interp2 handles.filter2];
1696     set_veltype_display(veltype_handles,0) % unvisible civ buttons
1697     filename=read_file_boxes_1(handles);
1698     hget_field=findobj(allchild(0),'name','get_field_1');
1699     if ~isempty(hget_field)
1700         delete(hget_field)
1701     end
1702     hget_field=get_field(filename);
1703     set(hget_field,'name','get_field_1')
1704    return %no action
1705end
1706if isequal(field_1,'image')
1707    % transform netc type to the corresponding image type
1708    set(handles.FileExt_1,'String','.png');
1709    if isequal(NomType_1,'_i1-i2_j')|isequal(NomType_1,'_i_j1-j2')| isequal(NomType_1,'#_ab')| isequal(NomType_1,'_i1-i2')
1710        UvData.SubDir_1=get(handles.SubDir_1,'String'); %preserve the subdir in memory
1711        set(handles.SubDir_1,'String','')
1712%         set(handles.FileExt_1,'String','.png');       
1713        if isequal(NomType_1,'_i1-i2_j')|isequal(NomType_1,'_i_j1-j2')
1714            NomTypeNew='_i_j';
1715        elseif isequal(NomType_1,'#_ab')
1716            NomTypeNew='#a';
1717        elseif isequal(NomType_1,'_i1-i2')
1718            NomTypeNew='_i';
1719        end 
1720    end
1721    veltype_handles=[handles.civ1_1 handles.interp1_1 handles.filter1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1];
1722    set_veltype_display(veltype_handles,0) % unvisible civ buttons
1723else
1724    set(handles.SubDir_1,'Visible','on')
1725    if ~isequal(FileExt_prev,'.nc') %find the new NomType if the previous display was not already a netcdf file
1726        veltype_handles=[handles.civ1_1 handles.interp1_1 handles.filter1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1];
1727        set_veltype_display(veltype_handles,6); % make all civ buttons visible
1728        RootPath_1=get(handles.RootPath_1,'String');
1729        RootFile_1=get(handles.RootFile_1,'String');
1730        if isempty(RootPath_1)|isequal(RootPath_1,'')
1731            set(handles.RootPath_1,'String','"')
1732        end
1733        if isempty(RootFile_1) | isequal(RootFile_1,'')
1734            set(handles.RootFile_1,'String','"')
1735        end
1736        if ~isempty(RootFile_1)&(isequal(RootFile_1(1),'/')|isequal(RootFile_1(1),'\'))
1737            RootFile_1(1)=[];
1738        end
1739        filebase_1=fullfile(RootPath_1,RootFile_1);
1740        SubDir_1=get(handles.SubDir,'String');
1741        if isempty(SubDir_1)|isequal(SubDir_1,'')
1742            if isfield(UvData,'SubDir_1')
1743                SubDir_1=UvData.SubDir_1;%retrieve previous subdir
1744            else
1745                SubDir_1='?';
1746            end
1747        end
1748        if isequal(NomType_1,'#_ab')|isequal(NomType_1,'_i1-i2_j')|isequal(NomType_1,'_i_j1-j2')|isequal(NomType_1,'_i1-i2')
1749            NomTypeNew=NomType_1;
1750        elseif isequal(NomType_1,'#a')
1751             [filename,idetect,n1,na,n2,nb,SubDir_1]=name_generator(filebase_1, str2num(str1),str2num(str_a),'.nc','#_ab',0,[],[],SubDir_1);
1752             NomTypeNew='#_ab';
1753        elseif isequal(NomType_1,'_i_j')
1754             [filename,idetect,n1,na,n2,nb,SubDir_1]=name_generator(filebase_1,str2num(str1),str2num(str_a),'.nc','_i1-i2_j',0,str2num(str1),[],SubDir_1);
1755            if idetect==1
1756                NomTypeNew='_i1-i2_j';
1757            else
1758                NomTypeNew='_i_j1-j2';
1759            end
1760        else %for instance avi files or any ima_num series
1761            [filename,idetect,n1,na,n2,nb,SubDir_1]=name_generator(filebase_1,str2num(str1),str2num(str_a),'.nc','_i1-i2',0,str2num(str1),[],SubDir_1);
1762            NomTypeNew='_i1-i2';
1763        end           
1764        [Path,Name]=fileparts(filebase_1);
1765        set(handles.FileExt_1,'String','.nc');
1766        if ~isempty(SubDir_1) & ~isequal(SubDir_1,'''')& ~isequal(SubDir_1,'"')
1767            SubDir_1=['/' SubDir_1];
1768        end
1769        set(handles.SubDir_1,'String',SubDir_1);
1770    end
1771    if isequal(field,'vort') | isequal(field,'div') | isequal(field,'strain')
1772        set(handles.civ1_1,'BackgroundColor',[0.702 0.702 0.702]) % put their color to grey
1773        set(handles.civ2_1,'BackgroundColor',[0.702 0.702 0.702])
1774        set(handles.interp1_1,'BackgroundColor',[0.702 0.702 0.702])
1775        set(handles.interp2_1,'BackgroundColor',[0.702 0.702 0.702])
1776    elseif isequal(field_1,'more...'); %add new item to the menu
1777        set(handles.civ1_1,'BackgroundColor',[0.702 0.702 0.702]) % put their color to grey
1778        set(handles.civ2_1,'BackgroundColor',[0.702 0.702 0.702])
1779        str=calc_field;%get the list of available scalars by the function calc_scal
1780        [ind_answer,v] = listdlg('PromptString','Select a file:',...
1781                'SelectionMode','single',...
1782                'ListString',str);
1783       % edit the choice in the field and action menu
1784        scalar=cell2mat(str(ind_answer));
1785        menu=update_menu(handles.Fields_1,scalar);
1786        set(handles.Fields_1,'String',menu);% store the selected scalar type
1787    end
1788end
1789str1=get(handles.i1,'String');
1790str2=get(handles.i2,'String');
1791str_a=get(handles.j1,'String');
1792str_b=get(handles.j2,'String');
1793indices=name_generator('',str2num(str1),stra2num(str_a),'',NomTypeNew,1,str2num(str2),stra2num(str_b),'');
1794set(handles.FileIndex_1,'String',indices)
1795set(handles.FileIndex_1,'UserData',NomTypeNew)
1796
1797%common to Fields_Callback
1798if isequal(field,'image')|isequal(field_1,'image')
1799    set(handles.npx_title,'Visible','on')% visible npx,pxcm... buttons
1800    set(handles.npy_title,'Visible','on')
1801    set(handles.npx,'Visible','on')
1802    set(handles.npy,'Visible','on')
1803    set(handles.fix_pair,'Value',0)
1804else
1805    set(handles.npx_title,'Visible','off')% visible npx,pxcm... buttons
1806    set(handles.npy_title,'Visible','off')
1807    set(handles.npx,'Visible','off')
1808    set(handles.npy,'Visible','off')
1809    set(handles.fix_pair,'Value',1)
1810end
1811if isequal(field,'velocity')|isequal(field_1,'velocity');
1812    state_vect='on';
1813else
1814    state_vect='off';
1815end
1816if ~isequal(field,'velocity')|(~isequal(field_1,'velocity')&~isequal(field_1,''));
1817    state_scal='on';
1818else
1819    state_scal='off';
1820end
1821set(huvmat,'UserData',UvData)
1822setfield(handles);% update the field structure ('civ1'....)
1823if ~isfield(UvData,'NewSeries')|isequal(UvData.NewSeries,0)
1824    run0_Callback(hObject, eventdata, handles)
1825end
1826
1827%------------------------------------------------------------------------
1828% --- set the visibility of relevant velocity type menus:
1829function set_veltype_display(handles,Civ)
1830%------------------------------------------------------------------------
1831%Civ=0; all states 'off'
1832%Civ=6; all states 'on'
1833if isequal(Civ,0)
1834    imax=0;
1835%    set(handles(1),'Visible','on')  % unvisible civ buttons
1836% else
1837%    set(handles(1),'String','civ1')
1838% end
1839elseif isequal(Civ,1) || isequal(Civ,2)
1840   imax=1;
1841elseif isequal(Civ,3)
1842    imax=3;
1843elseif isequal(Civ,4) || isequal(Civ,5)
1844    imax=4;
1845elseif isequal(Civ,6) %patch2
1846    imax=6;
1847end
1848for ibutton=1:imax;
1849    set(handles(ibutton),'Visible','on')  % unvisible civ buttons
1850end
1851% for ibutton=max(imax+1,2):6;
1852for ibutton=imax+1:6;
1853    set(handles(ibutton),'Visible','off')  % unvisible civ buttons
1854    set(handles(ibutton),'Value',0)%unactivate unvisible buttons
1855end
1856
1857%-------------------------------------------------------------------
1858% --- Executes on button press in civ1.
1859function civ1_Callback(hObject, eventdata, handles)
1860%-------------------------------------------------------------------
1861if get(handles.civ1,'Value')==1
1862    reset_vel_type([handles.interp1 handles.civ2 handles.filter1 handles.interp1 handles.interp2 handles.filter2],handles.civ1)
1863else
1864    reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
1865end
1866run0_Callback(hObject, eventdata, handles)
1867
1868%-------------------------------------------------------------------
1869% --- Executes on button press in interp1.
1870function interp1_Callback(hObject, eventdata, handles)
1871%-------------------------------------------------------------------
1872if get(handles.interp1,'Value')==1
1873    reset_vel_type([handles.civ1 handles.civ2 handles.filter1 handles.interp2 handles.filter2],handles.interp1)
1874else
1875     reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
1876end
1877run0_Callback(hObject, eventdata, handles)
1878
1879%-------------------------------------------------------------------
1880% --- Executes on button press in filter1.
1881function filter1_Callback(hObject, eventdata, handles)
1882%-------------------------------------------------------------------
1883if get(handles.filter1,'Value')==1
1884    reset_vel_type([handles.civ1 handles.civ2 handles.interp1 handles.interp2 handles.filter2],handles.filter1)
1885else
1886     reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
1887end
1888run0_Callback(hObject, eventdata, handles)
1889
1890%-------------------------------------------------------------------
1891% --- Executes on button press in civ2.
1892function civ2_Callback(hObject, eventdata, handles)
1893%-------------------------------------------------------------------
1894if get(handles.civ2,'Value')==1
1895    reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.interp2 handles.filter2],handles.civ2)
1896else
1897     reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
1898end
1899run0_Callback(hObject, eventdata, handles)
1900
1901%-----------------------------------------
1902% --- Executes on button press in interp2.
1903%-------------------------------------------
1904function interp2_Callback(hObject, eventdata, handles)
1905if get(handles.interp2,'Value')==1
1906    reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.filter2],handles.interp2)
1907else
1908     reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
1909end
1910run0_Callback(hObject, eventdata, handles)
1911%---------------------------------------------
1912% --- Executes on button press in filter2.
1913%-------------------------------------------
1914function filter2_Callback(hObject, eventdata, handles)
1915if get(handles.filter2,'Value')==1
1916    reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2],handles.filter2)
1917else
1918     reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
1919end
1920run0_Callback(hObject, eventdata, handles)
1921
1922%---------------------------------------------
1923function civ1_1_Callback(hObject, eventdata, handles)
1924%---------------------------------------------
1925if get(handles.civ1_1,'Value')==1
1926    reset_vel_type([handles.interp1_1 handles.civ2_1 handles.filter1_1 handles.interp1_1 handles.interp2_1 handles.filter2_1],handles.civ1_1)
1927else
1928     reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
1929end
1930run0_Callback(hObject, eventdata, handles)
1931
1932%--------------------------------------------
1933function interp1_1_Callback(hObject, eventdata, handles)
1934%--------------------------------------------
1935if get(handles.interp1_1,'Value')==1
1936    reset_vel_type([handles.civ1_1 handles.civ2_1 handles.filter1_1 handles.interp2_1 handles.filter2_1],handles.interp1_1)
1937else
1938    reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
1939end
1940run0_Callback(hObject, eventdata, handles)
1941
1942%--------------------------------------------
1943function filter1_1_Callback(hObject, eventdata, handles)
1944%--------------------------------------------
1945if get(handles.filter1_1,'Value')==1
1946    reset_vel_type([handles.interp1_1 handles.civ2_1 handles.interp1_1 handles.interp2_1 handles.filter2_1],handles.filter1_1)
1947else
1948    reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
1949end
1950run0_Callback(hObject, eventdata, handles)
1951
1952%--------------------------------------------
1953function civ2_1_Callback(hObject, eventdata, handles)
1954%--------------------------------------------
1955if get(handles.civ2_1,'Value')==1
1956    reset_vel_type([handles.civ1_1 handles.interp1_1  handles.filter1_1 handles.interp2_1 handles.filter2_1],handles.civ2_1)
1957else
1958    reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
1959end
1960run0_Callback(hObject, eventdata, handles)
1961
1962%--------------------------------------------
1963function interp2_1_Callback(hObject, eventdata, handles)
1964%--------------------------------------------
1965if get(handles.interp2_1,'Value')==1
1966    reset_vel_type([handles.civ1_1 handles.civ2_1 handles.filter1_1 handles.interp1_1 handles.filter2_1],handles.interp2_1)
1967else
1968    reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
1969end
1970run0_Callback(hObject, eventdata, handles)
1971
1972%--------------------------------------------
1973function filter2_1_Callback(hObject, eventdata, handles)
1974%--------------------------------------------
1975if get(handles.filter2_1,'Value')==1
1976    reset_vel_type([handles.civ1_1 handles.interp1_1 handles.civ2_1 handles.filter1_1 handles.interp1_1 handles.interp2_1],handles.filter2_1)
1977else
1978    reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
1979end
1980run0_Callback(hObject, eventdata, handles)
1981
1982%-----------------------------------------------
1983% --- reset civ buttons
1984function reset_vel_type(handles_civ0,handle1)
1985for ibutton=1:length(handles_civ0)
1986    set(handles_civ0(ibutton),'BackgroundColor',[0.831 0.816 0.784])
1987    set(handles_civ0(ibutton),'Value',0)
1988end
1989if exist('handle1','var')%handles of selected button
1990        set(handle1,'BackgroundColor',[1 1 0]) 
1991end
1992
1993
1994%-------------------------------------------------------------------
1995%-------------------------------------------------------------------
1996%  - FUNCTIONS FOR SETTING PLOTTING PARAMETERS
1997
1998%------------------------------------------------------------------
1999
2000
2001
2002%------------------------------------------------------------------
2003% --- Executes on selection change in col_vec: choice of the color code.
2004%
2005function col_vec_Callback(hObject, eventdata, handles)
2006%------------------------------------------------------------------
2007% edit the choice for color code
2008list_code=get(handles.col_vec,'String');% list menu fields
2009index_code=get(handles.col_vec,'Value');% selected string index
2010col_code= list_code{index_code(1)}; % selected field
2011if isequal(col_code,'black') | isequal(col_code,'white')
2012   set(handles.slider1,'Visible','off')
2013   set(handles.slider2,'Visible','off')
2014   set(handles.colcode1,'Visible','off')
2015   set(handles.colcode2,'Visible','off')
2016   set(handles.AutoVecColor,'Visible','off')
2017   set_vec_col_bar(handles)
2018else
2019   set(handles.slider1,'Visible','on')
2020   set(handles.slider2,'Visible','on')
2021   set(handles.colcode1,'Visible','on')
2022   set(handles.colcode2,'Visible','on')
2023   set(handles.AutoVecColor,'Visible','on') 
2024   if isequal(col_code,'ima_cor')
2025       set(handles.AutoVecColor,'Value',0)%fixed scale by default
2026       set(handles.vec_col_bar,'Value',0)% 3 colors r,g,b by default
2027       set(handles.slider1,'Min',0);
2028       set(handles.slider1,'Max',1);
2029       set(handles.slider2,'Min',0);
2030       set(handles.slider2,'Max',1);
2031 %      set(handles.min_title_vec,'String','0')
2032       set(handles.max_vec,'String','1')
2033       set(handles.colcode1,'String','0.333')
2034       colcode1_Callback(hObject, eventdata, handles)
2035       set(handles.colcode2,'String','0.666')
2036       colcode2_Callback(hObject, eventdata, handles)
2037   else
2038       set(handles.AutoVecColor,'Value',1)%auto scale between min,max by default
2039       set(handles.vec_col_bar,'Value',1)% colormap 'jet' by default
2040       minval=get(handles.slider1,'Min');
2041       maxval=get(handles.slider1,'Max');
2042       set(handles.slider1,'Value',minval)
2043       set(handles.slider2,'Value',maxval)
2044       set_vec_col_bar(handles)
2045   end
2046%    slider_update(handles)
2047end
2048%replot the current graph
2049run0_Callback(hObject, eventdata, handles)
2050
2051
2052%----------------------------------------------------------------
2053% -- Executes on slider movement to set the color code
2054%
2055function slider1_Callback(hObject, eventdata, handles)
2056%------------------------------------------------------------------
2057slider1=get(handles.slider1,'Value');
2058min_val=str2num(get(handles.min_vec,'String'));
2059max_val=str2num(get(handles.max_vec,'String'));
2060col=min_val+(max_val-min_val)*slider1;
2061set(handles.colcode1,'String',num2str(col))
2062if(get(handles.slider2,'Value') < col)%move also the second slider at the same value if needed
2063    set(handles.slider2,'Value',col)
2064    set(handles.colcode2,'String',num2str(col))
2065end
2066colcode1_Callback(hObject, eventdata, handles)
2067
2068%----------------------------------------------------------------
2069% Executes on slider movement to set the color code
2070%----------------------------------------------------------------
2071function slider2_Callback(hObject, eventdata, handles)
2072slider2=get(handles.slider2,'Value');
2073min_val=str2num(get(handles.min_vec,'String'));
2074max_val=str2num(get(handles.max_vec,'String'));
2075col=min_val+(max_val-min_val)*slider2;
2076set(handles.colcode2,'String',num2str(col))
2077if(get(handles.slider1,'Value') > col)%move also the first slider at the same value if needed
2078    set(handles.slider1,'Value',col)
2079    set(handles.colcode1,'String',num2str(col))
2080end
2081colcode2_Callback(hObject, eventdata, handles)
2082
2083%----------------------------------------------------------------
2084%execute on return carriage on the edit box corresponding to slider 1
2085%----------------------------------------------------------------
2086function colcode1_Callback(hObject, eventdata, handles)
2087% col=str2num(get(handles.colcode1,'String'));
2088% set(handles.slider1,'Value',col)
2089set_vec_col_bar(handles)
2090update_plot(handles)
2091
2092%----------------------------------------------------------------
2093%execute on return carriage on the edit box corresponding to slider 2
2094%----------------------------------------------------------------
2095function colcode2_Callback(hObject, eventdata, handles)
2096% col=str2num(get(handles.colcode2,'String'));
2097% set(handles.slider2,'Value',col)
2098% slider2_Callback(hObject, eventdata, handles)
2099set_vec_col_bar(handles)
2100update_plot(handles)
2101%------------------------------------------------------------
2102%update the slider values after displaying vectors
2103%--------------------------------------------------------
2104% function slider_update(handles,auto,minC,colcode1,colcode2,maxC)
2105% set(handles.slider1,'Min',minC)
2106% set(handles.slider1,'Max',maxC)
2107% set(handles.slider2,'Min',minC)
2108% set(handles.slider2,'Max',maxC)
2109% set(handles.min_title_vec,'String',num2str(minC))
2110% set(handles.max_vec,'String',num2str(maxC))
2111% if auto
2112%         set(handles.colcode1,'String',num2str(colcode1,3))%update display
2113%         set(handles.colcode2,'String',num2str(colcode2,3))
2114% end
2115% set(handles.slider1,'Value',colcode1)%update slider with constant display
2116% set(handles.slider2,'Value',colcode2)
2117% set_vec_col_bar(handles)
2118
2119
2120%-------------------------------------------------------
2121% --- Executes on button press in AutoVecColor.
2122%-------------------------------------------------------
2123function vec_col_bar_Callback(hObject, eventdata, handles)
2124set_vec_col_bar(handles)
2125
2126% %--------------------------------------------
2127% %update the display of color code for vectors
2128% %--------------------------------------------
2129% function set_vec_col_bar(handles)
2130% %get the image of the color display button 'vec_col_bar' in pixels
2131% uni=get(handles.vec_col_bar,'Unit');
2132% set(handles.vec_col_bar,'Unit','pixel')
2133% pos_vert=get(handles.vec_col_bar,'Position');
2134% set(handles.vec_col_bar,'Unit','Normalized')
2135% width=ceil(pos_vert(3));
2136% height=ceil(pos_vert(4));
2137% %get slider indications
2138% colcode.min=get(handles.slider1,'Min');
2139% colcode.max=get(handles.slider1,'Max');
2140% colcode.colcode1=get(handles.slider1,'Value');
2141% colcode.colcode2=get(handles.slider2,'Value');
2142% colcode.option=get(handles.vec_col_bar,'Value');
2143% colcode.auto=1;
2144% list_code=get(handles.col_vec,'String');% list menu fields
2145% index_code=get(handles.col_vec,'Value');% selected string index
2146% colcode.CName= list_code{index_code(1)}; % selected field used for vector color
2147% vec_C=colcode.min+(colcode.max-colcode.min)*[0.5:width-0.5]/width;%sample of vec_C values from min to max
2148% [colorlist,col_vec]=set_col_vec(colcode,vec_C);
2149% oneheight=ones(1,height);
2150% A1=colorlist(col_vec,1)*oneheight;
2151% A2=colorlist(col_vec,2)*oneheight;
2152% A3=colorlist(col_vec,3)*oneheight;
2153% A(:,:,1)=A1';
2154% A(:,:,2)=A2';
2155% A(:,:,3)=A3';
2156% set(handles.vec_col_bar,'Cdata',A)
2157
2158
2159%------------------------------------------------
2160%CALLBACKS FOR PLOTTING PARAMETERS
2161%-------------------------------------------------
2162
2163%-----------------------------------------------------------------
2164function MinA_Callback(hObject, eventdata, handles)
2165%------------------------------------------
2166set(handles.AutoScal,'Value',1) %suppress auto mode
2167set(handles.AutoScal,'BackgroundColor',[1 1 0])
2168update_plot(handles)
2169
2170%-----------------------------------------------------------------
2171function MaxA_Callback(hObject, eventdata, handles)
2172%--------------------------------------------
2173set(handles.AutoScal,'Value',1) %suppress auto mode
2174set(handles.AutoScal,'BackgroundColor',[1 1 0])
2175update_plot(handles)
2176
2177%-----------------------------------------------
2178function AutoScal_Callback(hObject, eventdata, handles)
2179%--------------------------------------------
2180test=get(handles.AutoScal,'Value');
2181if test
2182    set(handles.AutoScal,'BackgroundColor',[1 1 0])
2183else
2184    set(handles.AutoScal,'BackgroundColor',[0.7 0.7 0.7])
2185    update_plot(handles);
2186%     set(handles.MinA,'String',num2str(ScalOut.MinA,3))
2187%     set(handles.MaxA,'String',num2str(ScalOut.MaxA,3))
2188end
2189
2190%-------------------------------------------------------------------
2191function BW_Callback(hObject, eventdata, handles)
2192%-------------------------------------------------------------------
2193update_plot(handles)
2194
2195%-------------------------------------------------------------------
2196function Contours_Callback(hObject, eventdata, handles)
2197%-------------------------------------------------------------------
2198val=get(handles.Contours,'Value');
2199if val==2
2200    set(handles.interval_txt,'Visible','on')
2201    set(handles.IncrA,'Visible','on')
2202else
2203    set(handles.interval_txt,'Visible','off')
2204    set(handles.IncrA,'Visible','off')
2205end
2206update_plot(handles)
2207
2208%-------------------------------------------------------------------
2209function IncrA_Callback(hObject, eventdata, handles)
2210%-------------------------------------------------------------------
2211update_plot(handles)
2212
2213%-------------------------------------------------------------------
2214function HideWarning_Callback(hObject, eventdata, handles)
2215%-------------------------------------------------------------------
2216update_plot(handles)
2217
2218%-------------------------------------------------------------------
2219function HideFalse_Callback(hObject, eventdata, handles)
2220%-------------------------------------------------------------------
2221update_plot(handles)
2222
2223%-------------------------------------------------------------------
2224function VecScale_Callback(hObject, eventdata, handles)
2225%-------------------------------------------------------------------
2226set(handles.AutoVec,'Value',1);
2227set(handles.AutoVec,'BackgroundColor',[1 1 0])
2228update_plot(handles)
2229
2230%-------------------------------------------------------------------
2231function AutoVec_Callback(hObject, eventdata, handles)
2232%-------------------------------------------------------------------
2233test=get(handles.AutoVec,'Value');
2234if test
2235    set(handles.AutoVec,'BackgroundColor',[1 1 0])
2236else
2237    update_plot(handles);
2238    %set(handles.VecScale,'String',num2str(ScalOut.VecScale,3))
2239    set(handles.AutoVec,'BackgroundColor',[0.7 0.7 0.7])
2240end
2241
2242%-------------------------------------------------------
2243% --- Executes on selection change in decimate4 (nb_vec/4).
2244%-------------------------------------------------------
2245function decimate4_Callback(hObject, eventdata, handles)
2246update_plot(handles)
2247
2248
2249%-------------------------------------------------------
2250% --- Executes on selection change in color_code menu
2251%-------------------------------------------------------
2252function color_code_Callback(hObject, eventdata, handles)
2253set_vec_col_bar(handles)
2254update_plot(handles);
2255
2256%-------------------------------------------------------
2257% --- Executes on button press in AutoVecColor.
2258%-------------------------------------------------------
2259function AutoVecColor_Callback(hObject, eventdata, handles)
2260test=get(handles.AutoVecColor,'Value');
2261if test
2262    set(handles.AutoVecColor,'BackgroundColor',[1 1 0])
2263else
2264    update_plot(handles);
2265    %set(handles.VecScale,'String',num2str(ScalOut.VecScale,3))
2266    set(handles.AutoVecColor,'BackgroundColor',[0.7 0.7 0.7])
2267end
2268%set_vec_col_bar(handles)
2269
2270%-------------------------------------------------------
2271% --- Executes on selection change in max_vec.
2272%-------------------------------------------------------
2273function min_vec_Callback(hObject, eventdata, handles)
2274max_vec_Callback(hObject, eventdata, handles)
2275
2276% --- Executes on selection change in max_vec.
2277function max_vec_Callback(hObject, eventdata, handles)
2278set(handles.AutoVecColor,'Value',1)
2279AutoVecColor_Callback(hObject, eventdata, handles)
2280min_val=str2num(get(handles.min_vec,'String'));
2281max_val=str2num(get(handles.max_vec,'String'));
2282slider1=get(handles.slider1,'Value');
2283slider2=get(handles.slider2,'Value');
2284colcode1=min_val+(max_val-min_val)*slider1;
2285colcode2=min_val+(max_val-min_val)*slider2;
2286set(handles.colcode1,'String',num2str(colcode1))
2287set(handles.colcode2,'String',num2str(colcode2))
2288update_plot(handles);
2289
2290%-------------------------------------------------------------------
2291%update the display of color code for vectors
2292function set_vec_col_bar(handles)
2293%-------------------------------------------------------------------
2294%get the image of the color display button 'vec_col_bar' in pixels
2295set(handles.vec_col_bar,'Unit','pixel');
2296pos_vert=get(handles.vec_col_bar,'Position');
2297set(handles.vec_col_bar,'Unit','Normalized');
2298width=ceil(pos_vert(3));
2299height=ceil(pos_vert(4));
2300
2301%get slider indications
2302list=get(handles.color_code,'String');
2303ichoice=get(handles.color_code,'Value');
2304colcode.ColorCode=list{ichoice};
2305colcode.MinC=str2num(get(handles.min_vec,'String'));
2306colcode.MaxC=str2num(get(handles.max_vec,'String'));
2307test3color=strcmp(colcode.ColorCode,'rgb') || strcmp(colcode.ColorCode,'bgr');
2308if test3color
2309    colcode.colcode1=str2num(get(handles.colcode1,'String'));
2310    colcode.colcode2=str2num(get(handles.colcode2,'String'));
2311end
2312% colcode.option=get(handles.vec_col_bar,'Value');
2313colcode.FixedCbounds=0;
2314% list_code=get(handles.col_vec,'String');% list menu fields
2315% index_code=get(handles.col_vec,'Value');% selected string index
2316% colcode.CName= list_code{index_code(1)}; % selected field used for vector color
2317colcode.FixedCbounds=1;
2318vec_C=colcode.MinC+(colcode.MaxC-colcode.MinC)*[0.5:width-0.5]/width;%sample of vec_C values from min to max
2319[colorlist,col_vec]=set_col_vec(colcode,vec_C);
2320oneheight=ones(1,height);
2321A1=colorlist(col_vec,1)*oneheight;
2322A2=colorlist(col_vec,2)*oneheight;
2323A3=colorlist(col_vec,3)*oneheight;
2324A(:,:,1)=A1';
2325A(:,:,2)=A2';
2326A(:,:,3)=A3';
2327set(handles.vec_col_bar,'Cdata',A)
2328
2329
2330%-------------------------------------------------------------------
2331function [PlotType,ScalOut]=update_plot(handles)
2332%-------------------------------------------------------------------
2333haxes= handles.axes3;
2334AxeData=get(haxes,'UserData');
2335PlotParam=read_plot_param(handles);
2336[PlotType,PlotParamOut]= plot_field(AxeData,haxes,PlotParam,1);
2337write_plot_param(handles,PlotParamOut); %update the auto plot parameters
2338
2339
2340
2341%------------------------------------------------------
2342% --- Executes on button press in Menu/Export/field in workspace.
2343%------------------------------------------------------
2344function MenuExportField_Callback(hObject, eventdata, handles)
2345
2346global CurData
2347huvmat=findobj(allchild(0),'Name','uvmat');
2348CurData=get(huvmat,'UserData');
2349evalin('base','global CurData')%make CurData global in the workspace
2350display(['UserData of view_field :'])
2351evalin('base','CurData') %display CurData in the workspace
2352commandwindow;
2353
2354%------------------------------------------------------
2355% --- Executes on button press in Menu/Export/extract figure.
2356%------------------------------------------------------
2357function MenuExport_plot_Callback(hObject, eventdata, handles)
2358huvmat=get(handles.MenuExport_plot,'parent');
2359UvData=get(huvmat,'UserData');
2360hfig=figure;
2361newaxes=copyobj(handles.axes3,hfig);
2362map=colormap(handles.axes3);
2363colormap(map);%transmit the current colormap to the zoom fig
2364colorbar
2365
2366
2367
2368function npx_Callback(hObject, eventdata, handles)
2369% hObject    handle to npx (see GCBO)
2370% eventdata  reserved - to be defined in a future version of MATLAB
2371% handles    structure with handles and user data (see GUIDATA)
2372
2373% Hints: get(hObject,'String') returns contents of npx as text
2374%        str2double(get(hObject,'String')) returns contents of npx as a double
2375
2376
2377% --- Executes during object creation, after setting all properties.
2378function npx_CreateFcn(hObject, eventdata, handles)
2379% hObject    handle to npx (see GCBO)
2380% eventdata  reserved - to be defined in a future version of MATLAB
2381% handles    empty - handles not created until after all CreateFcns called
2382
2383% Hint: edit controls usually have a white background on Windows.
2384%       See ISPC and COMPUTER.
2385if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
2386    set(hObject,'BackgroundColor','white');
2387end
2388
2389
2390
2391function npy_Callback(hObject, eventdata, handles)
2392% hObject    handle to npy (see GCBO)
2393% eventdata  reserved - to be defined in a future version of MATLAB
2394% handles    structure with handles and user data (see GUIDATA)
2395
2396% Hints: get(hObject,'String') returns contents of npy as text
2397%        str2double(get(hObject,'String')) returns contents of npy as a double
2398
2399
2400% --- Executes during object creation, after setting all properties.
2401function npy_CreateFcn(hObject, eventdata, handles)
2402% hObject    handle to npy (see GCBO)
2403% eventdata  reserved - to be defined in a future version of MATLAB
2404% handles    empty - handles not created until after all CreateFcns called
2405
2406% Hint: edit controls usually have a white background on Windows.
2407%       See ISPC and COMPUTER.
2408if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
2409    set(hObject,'BackgroundColor','white');
2410end
2411
2412
2413
2414function edit86_Callback(hObject, eventdata, handles)
2415% hObject    handle to MaxA (see GCBO)
2416% eventdata  reserved - to be defined in a future version of MATLAB
2417% handles    structure with handles and user data (see GUIDATA)
2418
2419% Hints: get(hObject,'String') returns contents of MaxA as text
2420%        str2double(get(hObject,'String')) returns contents of MaxA as a double
2421
2422
2423% --- Executes during object creation, after setting all properties.
2424function MaxA_CreateFcn(hObject, eventdata, handles)
2425% hObject    handle to MaxA (see GCBO)
2426% eventdata  reserved - to be defined in a future version of MATLAB
2427% handles    empty - handles not created until after all CreateFcns called
2428
2429% Hint: edit controls usually have a white background on Windows.
2430%       See ISPC and COMPUTER.
2431if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
2432    set(hObject,'BackgroundColor','white');
2433end
2434
2435
2436
2437function edit87_Callback(hObject, eventdata, handles)
2438% hObject    handle to MinA (see GCBO)
2439% eventdata  reserved - to be defined in a future version of MATLAB
2440% handles    structure with handles and user data (see GUIDATA)
2441
2442% Hints: get(hObject,'String') returns contents of MinA as text
2443%        str2double(get(hObject,'String')) returns contents of MinA as a double
2444
2445
2446% --- Executes during object creation, after setting all properties.
2447function MinA_CreateFcn(hObject, eventdata, handles)
2448% hObject    handle to MinA (see GCBO)
2449% eventdata  reserved - to be defined in a future version of MATLAB
2450% handles    empty - handles not created until after all CreateFcns called
2451
2452% Hint: edit controls usually have a white background on Windows.
2453%       See ISPC and COMPUTER.
2454if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
2455    set(hObject,'BackgroundColor','white');
2456end
2457
2458
2459% --- Executes on button press in auto_sclar.
2460function auto_sclar_Callback(hObject, eventdata, handles)
2461% hObject    handle to auto_sclar (see GCBO)
2462% eventdata  reserved - to be defined in a future version of MATLAB
2463% handles    structure with handles and user data (see GUIDATA)
2464
2465% Hint: get(hObject,'Value') returns toggle state of auto_sclar
2466
2467
2468
2469function edit88_Callback(hObject, eventdata, handles)
2470% hObject    handle to IncrA (see GCBO)
2471% eventdata  reserved - to be defined in a future version of MATLAB
2472% handles    structure with handles and user data (see GUIDATA)
2473
2474% Hints: get(hObject,'String') returns contents of IncrA as text
2475%        str2double(get(hObject,'String')) returns contents of IncrA as a double
2476
2477
2478% --- Executes during object creation, after setting all properties.
2479function IncrA_CreateFcn(hObject, eventdata, handles)
2480% hObject    handle to IncrA (see GCBO)
2481% eventdata  reserved - to be defined in a future version of MATLAB
2482% handles    empty - handles not created until after all CreateFcns called
2483
2484% Hint: edit controls usually have a white background on Windows.
2485%       See ISPC and COMPUTER.
2486if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
2487    set(hObject,'BackgroundColor','white');
2488end
2489
2490
2491% --- Executes on button press in AutoScal.
2492function checkbox40_Callback(hObject, eventdata, handles)
2493% hObject    handle to AutoScal (see GCBO)
2494% eventdata  reserved - to be defined in a future version of MATLAB
2495% handles    structure with handles and user data (see GUIDATA)
2496
2497% Hint: get(hObject,'Value') returns toggle state of AutoScal
2498
2499
2500
2501function edit82_Callback(hObject, eventdata, handles)
2502% hObject    handle to edit82 (see GCBO)
2503% eventdata  reserved - to be defined in a future version of MATLAB
2504% handles    structure with handles and user data (see GUIDATA)
2505
2506% Hints: get(hObject,'String') returns contents of edit82 as text
2507%        str2double(get(hObject,'String')) returns contents of edit82 as a double
2508
2509
2510% --- Executes during object creation, after setting all properties.
2511function edit82_CreateFcn(hObject, eventdata, handles)
2512% hObject    handle to edit82 (see GCBO)
2513% eventdata  reserved - to be defined in a future version of MATLAB
2514% handles    empty - handles not created until after all CreateFcns called
2515
2516% Hint: edit controls usually have a white background on Windows.
2517%       See ISPC and COMPUTER.
2518if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
2519    set(hObject,'BackgroundColor','white');
2520end
2521
2522
2523
2524function edit83_Callback(hObject, eventdata, handles)
2525% hObject    handle to min_vec (see GCBO)
2526% eventdata  reserved - to be defined in a future version of MATLAB
2527% handles    structure with handles and user data (see GUIDATA)
2528
2529% Hints: get(hObject,'String') returns contents of min_vec as text
2530%        str2double(get(hObject,'String')) returns contents of min_vec as a double
2531
2532
2533% --- Executes during object creation, after setting all properties.
2534function min_vec_CreateFcn(hObject, eventdata, handles)
2535% hObject    handle to min_vec (see GCBO)
2536% eventdata  reserved - to be defined in a future version of MATLAB
2537% handles    empty - handles not created until after all CreateFcns called
2538
2539% Hint: edit controls usually have a white background on Windows.
2540%       See ISPC and COMPUTER.
2541if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
2542    set(hObject,'BackgroundColor','white');
2543end
2544
2545
2546% --- Executes on slider movement.
2547function slider9_Callback(hObject, eventdata, handles)
2548% hObject    handle to slider9 (see GCBO)
2549% eventdata  reserved - to be defined in a future version of MATLAB
2550% handles    structure with handles and user data (see GUIDATA)
2551
2552% Hints: get(hObject,'Value') returns position of slider
2553%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
2554
2555
2556% --- Executes during object creation, after setting all properties.
2557function slider9_CreateFcn(hObject, eventdata, handles)
2558% hObject    handle to slider9 (see GCBO)
2559% eventdata  reserved - to be defined in a future version of MATLAB
2560% handles    empty - handles not created until after all CreateFcns called
2561
2562% Hint: slider controls usually have a light gray background.
2563if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
2564    set(hObject,'BackgroundColor',[.9 .9 .9]);
2565end
2566
2567
2568% --- Executes on slider movement.
2569function slider10_Callback(hObject, eventdata, handles)
2570% hObject    handle to slider10 (see GCBO)
2571% eventdata  reserved - to be defined in a future version of MATLAB
2572% handles    structure with handles and user data (see GUIDATA)
2573
2574% Hints: get(hObject,'Value') returns position of slider
2575%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
2576
2577
2578% --- Executes during object creation, after setting all properties.
2579function slider10_CreateFcn(hObject, eventdata, handles)
2580% hObject    handle to slider10 (see GCBO)
2581% eventdata  reserved - to be defined in a future version of MATLAB
2582% handles    empty - handles not created until after all CreateFcns called
2583
2584% Hint: slider controls usually have a light gray background.
2585if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
2586    set(hObject,'BackgroundColor',[.9 .9 .9]);
2587end
2588
2589
2590% --- Executes on button press in AutoVecColor.
2591function checkbox41_Callback(hObject, eventdata, handles)
2592% hObject    handle to AutoVecColor (see GCBO)
2593% eventdata  reserved - to be defined in a future version of MATLAB
2594% handles    structure with handles and user data (see GUIDATA)
2595
2596% Hint: get(hObject,'Value') returns toggle state of AutoVecColor
2597
2598
2599
2600function edit89_Callback(hObject, eventdata, handles)
2601% hObject    handle to max_vec (see GCBO)
2602% eventdata  reserved - to be defined in a future version of MATLAB
2603% handles    structure with handles and user data (see GUIDATA)
2604
2605% Hints: get(hObject,'String') returns contents of max_vec as text
2606%        str2double(get(hObject,'String')) returns contents of max_vec as a double
2607
2608
2609% --- Executes during object creation, after setting all properties.
2610function max_vec_CreateFcn(hObject, eventdata, handles)
2611% hObject    handle to max_vec (see GCBO)
2612% eventdata  reserved - to be defined in a future version of MATLAB
2613% handles    empty - handles not created until after all CreateFcns called
2614
2615% Hint: edit controls usually have a white background on Windows.
2616%       See ISPC and COMPUTER.
2617if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
2618    set(hObject,'BackgroundColor','white');
2619end
2620
2621
2622
2623function edit90_Callback(hObject, eventdata, handles)
2624% hObject    handle to edit90 (see GCBO)
2625% eventdata  reserved - to be defined in a future version of MATLAB
2626% handles    structure with handles and user data (see GUIDATA)
2627
2628% Hints: get(hObject,'String') returns contents of edit90 as text
2629%        str2double(get(hObject,'String')) returns contents of edit90 as a double
2630
2631
2632% --- Executes during object creation, after setting all properties.
2633function edit90_CreateFcn(hObject, eventdata, handles)
2634% hObject    handle to edit90 (see GCBO)
2635% eventdata  reserved - to be defined in a future version of MATLAB
2636% handles    empty - handles not created until after all CreateFcns called
2637
2638% Hint: edit controls usually have a white background on Windows.
2639%       See ISPC and COMPUTER.
2640if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
2641    set(hObject,'BackgroundColor','white');
2642end
2643
2644
2645% --- Executes on button press in vec_col_bar.
2646function pushbutton35_Callback(hObject, eventdata, handles)
2647% hObject    handle to vec_col_bar (see GCBO)
2648% eventdata  reserved - to be defined in a future version of MATLAB
2649% handles    structure with handles and user data (see GUIDATA)
2650
2651
2652function close_fcn(hObject, eventdata, handles)
2653huvmat=findobj(allchild(0),'Name','uvmat');
2654hhuvmat=guidata(huvmat);
2655set(hhuvmat.list_object_2,'Visible','off')
Note: See TracBrowser for help on using the repository browser.