source: trunk/src/view_field.m @ 85

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

uvmat;fig: cleaning out of buttons for mask record
view_field, write_plot_param: improve plot by view_field (projection)
uvmat: bug fixing for yellow coloring of buttons, improve switch from velocity to images
find_field_indices: bug fix for NbDim?
name_generator: help comments improved
civ: bugs corrected for BATCH button colouring

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