source: trunk/src/view_field.m @ 88

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

improvement of vioew_field
suppress spurious 'todo' path in civ

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