Changeset 784


Ignore:
Timestamp:
Jun 7, 2014, 6:17:53 PM (11 years ago)
Author:
sommeria
Message:

adpat uvmat to reading data from rdvision

Location:
trunk/src
Files:
3 added
24 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/civ.m

    r783 r784  
    12051205% if strcmp(Param.Program,'civ_matlab')
    12061206    if Param.CheckCiv1
    1207         [ImageInfoA_civ1,Param.Civ1.ImageA]=get_file_type(filecell.ima1.civ1{1});
     1207        [ImageInfoA_civ1,Param.Civ1.ImageA]=get_file_info(filecell.ima1.civ1{1});
    12081208        Param.Civ1.FileTypeA=ImageInfoA_civ1.FileType;
    1209         [ImageInfoB_civ1,Param.Civ1.ImageB]=get_file_type(filecell.ima2.civ1{1});
     1209        [ImageInfoB_civ1,Param.Civ1.ImageB]=get_file_info(filecell.ima2.civ1{1});
    12101210        Param.Civ1.FileTypeB=ImageInfoB_civ1.FileType;
    12111211    end
    12121212    if Param.CheckCiv2
    1213         [ImageInfoA_civ2,Param.Civ2.ImageA]=get_file_type(filecell.ima1.civ2{1});
     1213        [ImageInfoA_civ2,Param.Civ2.ImageA]=get_file_info(filecell.ima1.civ2{1});
    12141214        Param.Civ2.FileTypeA=ImageInfoA_civ2.FileType;
    1215         [ImageInfoB_civ2,Param.Civ2.ImageB]=get_file_type(filecell.ima2.civ2{1});
     1215        [ImageInfoB_civ2,Param.Civ2.ImageB]=get_file_info(filecell.ima2.civ2{1});
    12161216        Param.Civ2.FileTypeB=ImageInfoB_civ2.FileType;
    12171217    end
     
    23262326    if ~isequal(ext_ima,'.png')
    23272327        if checkbox(1) %if civ1 is performed
    2328              [FileInfo,MovieObject]=get_file_type(filecell.ima1.civ1{1});
     2328             [FileInfo,MovieObject]=get_file_info(filecell.ima1.civ1{1});
    23292329             FileType=FileInfo.FileType;
    23302330            check_j=0;
     
    23662366        end
    23672367        if checkbox(4) %if civ2 is performed
    2368              [FileInfo,MovieObject]=get_file_type(filecell.ima1.civ2{1});
     2368             [FileInfo,MovieObject]=get_file_info(filecell.ima1.civ2{1});
    23692369             FileType=FileInfo.FileType;
    23702370            check_j=0;
     
    37823782    Data.CoordUnit='pixel';% used to set equal scaling for x and y in image dispaly
    37833783    par_civ1=read_GUI(handles.Civ1);
    3784     FileInfo=get_file_type(filecell.ima1.civ1{1});
     3784    FileInfo=get_file_info(filecell.ima1.civ1{1});
    37853785    par_civ1.FileTypeA=FileInfo.FileType;
    37863786    par_civ1.ImageWidth=size(Data.A,2);
  • trunk/src/find_file_series.m

    r783 r784  
    5656j1_series=zeros(1,1,1);
    5757j2_series=zeros(1,1,1);
    58 [FileInfo,MovieObject]=get_file_type(fullfileinput);
     58[FileInfo,MovieObject]=get_file_info(fullfileinput);
    5959if ~exist(FilePath,'dir')
    6060    return % don't go further if the dir path does not exist
     
    238238        %% update the file type if the input file does not exist (pb of 0001)
    239239        if isempty(FileInfo.FileType)
    240             [FileInfo,MovieObject]=get_file_type(fullfile(FilePath,dirpair(ifile_min).name));
     240            [FileInfo,MovieObject]=get_file_info(fullfile(FilePath,dirpair(ifile_min).name));
    241241        end
    242242    end
     
    248248if isequal(j1_series,0), j1_series=[]; end
    249249if isequal(j2_series,0), j2_series=[]; end
     250
     251%% detect rdvision format
     252if strcmp(FileExt,'.bin')
     253    if exist(fullfile(RootPath,SubDir,[RootFile '.seq']),'file')
     254        FileInfo.FileType='rdvision';
     255        FileInfo.SeqFile=[RootFile '.seq'];
     256    end
     257end
    250258
    251259%% introduce the frame index in case of movies or multimage type
  • trunk/src/get_file_type.m

    r783 r784  
    1 %'get_file_type': determine info about a file (image, multimage, civdata,...) .
     1%'get_file_type': OBSOLETE, replaced by get_file_info
    22%------------------------------------------------------------------------
    33% [FileType,FileInfo,Object]=get_file_type(fileinput)
    44%
    55% OUTPUT:
    6 % FileType: type of file
    76% FileInfo: structure containing info on the file (case of images or video), in particular
     7%      .FileType: type of file, needed as input of read_field.m
    88%      .Height: image height in pixels
    99%      .Width:  image width in pixels
     
    1616% INPUT:
    1717% fileinput: name, including path, of the file to analyse
    18 function [FileInfo,VideoObject]=get_file_type(fileinput)
     18function [FileType,FileInfo,VideoObject]=get_file_type(fileinput)
    1919VideoObject=[];
    2020if exist(fileinput,'file')
     
    2323else
    2424    FileInfo.FileType='';
     25    FileType=FileInfo.FileType;
    2526    return
    2627end
     
    3031    case '.fig'
    3132        FileInfo.FileType='figure';
    32     case '.xml'
    33         FileInfo.FileType='xml';
    34     case '.xls'
    35         FileInfo.FileType='xls';
    36     case '.dat'
    37         FileInfo.FileType='dat';;
     33    case {'.xml','.xls','.dat','.bin'}
     34        FileInfo.FileType=regexprep(FileExt,'^.','');% eliminate the dot of the extension;
    3835    otherwise
    3936        if ~isempty(FileExt)% exclude empty extension
     
    109106        end
    110107end
     108FileType=FileInfo.FileType;
  • trunk/src/read_field.m

    r782 r784  
    1414%INPUT
    1515% FileName: name of the input file
    16 % FileType: type of file, as determined by the function get_file_type.m
     16% FileType: type of file, as determined by the function get_file_info.m
    1717% ParamIn: movie object or Matlab structure of input parameters
    1818%     .FieldName: name (char string) of the input field (for Civx data)
     
    213213        A=permute(A,[3 2 1]);
    214214    case 'multimage'
    215         warning 'off'
     215      %  warning 'off'
    216216        A=imread(FileName,num);
    217217    case 'image'
    218218        A=imread(FileName);
    219 end
    220 if ~isempty(errormsg)
    221     errormsg=[FileType ' input: ' errormsg];
    222     return
     219    case 'rdvision'
     220        [A,timestamps]=binread_rdv(FileName,num);
     221    otherwise
     222        errormsg=[ FileType ': invalid input file type for uvmat'];
    223223end
    224224
    225225%% case of image
    226226if ~isempty(A)
     227    if strcmp(FileType,'rdvision')
     228        Field.Time=timestamps;
     229    end
    227230    if isstruct(ParamOut)
    228231        ParamOut.FieldName='image';
     
    268271    Field.A=A;
    269272    Field.CoordUnit='pixel'; %used for mouse_motion
    270 end
    271 
    272 
    273 
     273       
     274end
     275
     276
     277
  • trunk/src/read_image.m

    r610 r784  
    1010% FileName: input file name
    1111%                 other inputs needed  only for video and multi-image file:
    12 % FileType: input file type, as determined by the function get_file_type.m
     12% FileType: input file type, as determined by the function get_file_info.m
    1313% VideoObject: video object (for faster reading if availlable)
    1414% num: frame index for movies or multimage types
  • trunk/src/series.m

    r783 r784  
    424424    if ~isequal(ListStruct(ilist).isdir,1)%look for files, not dir
    425425        FileName=ListStruct(ilist).name;
    426         FileInfo=get_file_type(fullfile(DirName,FileName));
     426        FileInfo=get_file_info(fullfile(DirName,FileName));
    427427        switch FileInfo.FileType
    428428            case {'image','multimage','civx','civdata','netcdf'}
     
    477477    if ~isequal(hdir(ilist).isdir,1)%look for files, not dir
    478478        FileName=hdir(ilist).name;
    479         FileInfo=get_file_type(fullfile(DirName,FileName));
     479        FileInfo=get_file_info(fullfile(DirName,FileName));
    480480        switch FileInfo.FileType
    481481            case {'image','multimage','civx','civdata','netcdf'}
     
    29752975    set(htitlebox,'String',FullSelectName)
    29762976elseif exist(FullSelectName,'file')%visualise the vel field if it exists
    2977     FileInfo=get_file_type(FullSelectName);   
     2977    FileInfo=get_file_info(FullSelectName);   
    29782978    if strcmp(FileInfo.FileType,'txt')
    29792979        edit(FullSelectName)
  • trunk/src/series/aver_stat.m

    r783 r784  
    121121        return
    122122    end
    123     [FileInfo{iview},MovieObject{iview}]=get_file_type(filecell{iview,1});
     123    [FileInfo{iview},MovieObject{iview}]=get_file_info(filecell{iview,1});
    124124    FileType{iview}=FileInfo{iview}.FileType;
    125125    CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images
  • trunk/src/series/aver_synchro.m

    r783 r784  
    9393FileExt=Param.InputTable(:,5);
    9494[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
    95 FileInfo=get_file_type(filecell{1,1});
     95FileInfo=get_file_info(filecell{1,1});
    9696 FileType=FileInfo.FileType;
    9797%%%%%%%%%%%%
  • trunk/src/series/beam_forming.m

    r783 r784  
    8282        return
    8383    end
    84     [FileInfo{iview},MovieObject{iview}]=get_file_type(filecell{iview,1});
     84    [FileInfo{iview},MovieObject{iview}]=get_file_info(filecell{iview,1});
    8585    FileType{iview}=FileInfo{iview}.FileType;
    8686    CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images
  • trunk/src/series/check_data_files.m

    r783 r784  
    9292NcTypeOptions={'netcdf','civx','civdata'};
    9393for iview=1:nbview
    94     [FileInfo{iview},Object{iview}]=get_file_type(filecell{iview,1});
     94    [FileInfo{iview},Object{iview}]=get_file_info(filecell{iview,1});
    9595    FileType{iview}=FileInfo{iview}.FileType;
    9696    CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images
     
    101101for iview=1:nbview
    102102    if isequal(FileType{iview},'mmreader')||isequal(FileType{iview},'video')||isequal(FileType{iview},'multimage')
    103         [FileInfo]=get_file_type(filecell{iview,1});
     103        [FileInfo]=get_file_info(filecell{iview,1});
    104104        Tabchar{1}=filecell{iview,1};%info.Filename;
    105105        Tabchar{2}='';
     
    131131                    end
    132132                    lastfield='';
    133                     [FileInfo,Object]=get_file_type(file);
     133                    [FileInfo,Object]=get_file_info(file);
    134134                    FileType{iview}=FileInfo.FileType;
    135135                    if strcmp(FileType{iview},'civx')||strcmp(FileType{iview},'civdata')
  • trunk/src/series/check_peaklock.m

    r783 r784  
    113113        return
    114114    end
    115     [FileInfo{iview},MovieObject{iview}]=get_file_type(filecell{iview,1});
     115    [FileInfo{iview},MovieObject{iview}]=get_file_info(filecell{iview,1});
    116116    FileType{iview}=FileInfo{iview}.FileType;
    117117    CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images
  • trunk/src/series/civ_input.m

    r783 r784  
    20682068 Data.CoordUnit='pixel';% used to set equal scaling for x and y in image dispa=ly
    20692069 par_civ1=read_GUI(handles.Civ1);
    2070  FileInfo=get_file_type(ImageName_A);
     2070 FileInfo=get_file_info(ImageName_A);
    20712071 par_civ1.FileTypeA=FileInfo.FileType;
    20722072 par_civ1.ImageWidth=size(Data.A,2);
  • trunk/src/series/civ_series.m

    r783 r784  
    220220            return
    221221        end
    222         [FileInfo_A,VideoObject_A]=get_file_type(ImageName_A);
     222        [FileInfo_A,VideoObject_A]=get_file_info(ImageName_A);
    223223        FileType_A=FileInfo_A.FileType;
    224224        if strcmp(FileInfo_A.FileType,'netcdf')
     
    234234            return
    235235        end
    236         [FileInfo_B,VideoObject_B]=get_file_type(ImageName_B);
     236        [FileInfo_B,VideoObject_B]=get_file_info(ImageName_B);
    237237        FileType_B=FileInfo_B.FileType;
    238238        if strcmp(FileInfo_B.FileType,'netcdf')
     
    250250            return
    251251        end
    252         [FileType_A,FileInfo_A,VideoObject_A]=get_file_type(ImageName_A);
     252        [FileType_A,FileInfo_A,VideoObject_A]=get_file_info(ImageName_A);
    253253        [par_civ1.ImageA,VideoObject_A] = read_image(ImageName_A,FileInfo_A.FileType,VideoObject_A,FrameIndex_A_Civ2(1));
    254254        ImageName_B=fullfile_uvmat(RootPath_B,SubDir_B,RootFile_B,FileExt_B,NomType_B,i2_series_Civ2(1),[],j2_series_Civ2(1));
     
    257257            return
    258258        end
    259         [FileInfo_B,VideoObject_B]=get_file_type(ImageName_B);
     259        [FileInfo_B,VideoObject_B]=get_file_info(ImageName_B);
    260260        FileType_B=FileInfo_B.FileType;
    261261        [par_civ1.ImageB,VideoObject_B] = read_image(ImageName_B,FileType_B,VideoObject_B,FrameIndex_B_Civ2(1));
  • trunk/src/series/float_tracking.m

    r783 r784  
    124124
    125125%% check the input file type 
    126 [FileInfo,VideoObject]=get_file_type(filecell{1,1});
     126[FileInfo,VideoObject]=get_file_info(filecell{1,1});
    127127FileType=FileInfo.FileType;
    128128ImageTypeOptions={'image','multimage','mmreader','video'};
  • trunk/src/series/ima_levels.m

    r783 r784  
    6565        msgbox_uvmat('WARNING','the first input file does not exist')
    6666    else
    67         FileInfo=get_file_type(filecell{1,1});
     67        FileInfo=get_file_info(filecell{1,1});
    6868        FileType=FileInfo.FileType;
    6969        if isempty(find(strcmp(FileType,{'image','multimage','mmreader','video'})));% =1 for images
     
    107107nbfield_i=size(i1_series{1},2); %nb of fields for the i index
    108108nbfield=nbfield_j*nbfield_i; %total number of fields
    109 [FileInfo{1},VideoObject{1}]=get_file_type(filecell{1,1});% type of input file
     109[FileInfo{1},VideoObject{1}]=get_file_info(filecell{1,1});% type of input file
    110110FileType{1}=FileInfo{1}.FileType;
    111111
  • trunk/src/series/merge_proj.m

    r783 r784  
    121121        return
    122122    end
    123     [FileInfo{iview},MovieObject{iview}]=get_file_type(filecell{iview,1});
     123    [FileInfo{iview},MovieObject{iview}]=get_file_info(filecell{iview,1});
    124124    FileType{iview}=FileInfo{iview}.FileType;
    125125    CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images
  • trunk/src/series/particle_tracking.m

    r783 r784  
    124124
    125125%% check the input file type 
    126 [FileInfo,VideoObject]=get_file_type(filecell{1,1});
     126[FileInfo,VideoObject]=get_file_info(filecell{1,1});
    127127FileType=FileInfo.FileType;
    128128ImageTypeOptions={'image','multimage','mmreader','video'};
  • trunk/src/series/relabel_i_j.m

    r783 r784  
    9595    return
    9696end
    97 [FileInfo{1},MovieObject{1}]=get_file_type(filecell{1,1});
     97[FileInfo{1},MovieObject{1}]=get_file_info(filecell{1,1});
    9898FileType{1}=FileInfo{1}.FileType;
    9999CheckImage=~isempty(find(strcmp(FileType{1},ImageTypeOptions)));% =1 for images
  • trunk/src/series/sub_background.m

    r783 r784  
    9090    %% check the validity of  input file types
    9191    ImageTypeOptions={'image','multimage','mmreader','video'};%allowed input file types(images)
    92     FileInfo=get_file_type(FirstFileName);
     92    FileInfo=get_file_info(FirstFileName);
    9393    FileType=FileInfo.FileType;
    9494    CheckImage=~isempty(find(strcmp(FileType,ImageTypeOptions), 1));% =1 for images
     
    201201    % i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
    202202%%%%%%%%%%%%
    203 [FileInfo{1},MovieObject{1}]=get_file_type(filecell{1,1});
     203[FileInfo{1},MovieObject{1}]=get_file_info(filecell{1,1});
    204204FileType{1}=FileInfo{1}.FileType;
    205205    if ~isempty(j1_series{1})
  • trunk/src/series/time_series.m

    r783 r784  
    124124        return
    125125    end
    126     [FileInfo{iview},MovieObject{iview}]=get_file_type(filecell{iview,1});
     126    [FileInfo{iview},MovieObject{iview}]=get_file_info(filecell{iview,1});
    127127    FileType{iview}=FileInfo{iview}.FileType;
    128128    if strcmp(FileType{iview},'civdata')||strcmp(FileType{iview},'civx')
  • trunk/src/series/turb_stat.m

    r783 r784  
    103103        return
    104104    end
    105     [FileInfo{iview},MovieObject{iview}]=get_file_type(filecell{iview,1});
     105    [FileInfo{iview},MovieObject{iview}]=get_file_info(filecell{iview,1});
    106106    FileType{iview}=FileInfo{iview}.FileType;
    107107    CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images
  • trunk/src/set_grid.m

    r783 r784  
    228228    return
    229229end
    230 [FileInfo,VideoObject]=get_file_type(GUI.ImageA);
     230[FileInfo,VideoObject]=get_file_info(GUI.ImageA);
    231231switch FileInfo.FileType
    232232    case {'image','multimage','video','mmreader'}% case of input image or movie OK
     
    323323            'Pick the second image file',fileparts(fileparts(get(handles.ImageA,'String'))));
    324324        ImageB=fullfile(PathName,FileName);
    325         [FileInfo,tild,VideoObject]=get_file_type(ImageB);
     325        [FileInfo,tild,VideoObject]=get_file_info(ImageB);
    326326    switch FileInfo.FileType
    327327        case {'image','multimage','video','mmreader'}% case of input image or movie OK
  • trunk/src/uigetfile_uvmat.m

    r783 r784  
    147147                uiresume(hfig)
    148148            case 'status_display'
    149                 FileInfo=get_file_type(FullSelectName);
     149                FileInfo=get_file_info(FullSelectName);
    150150                if strcmp(FileInfo.FileType,'txt')
    151151                    edit(FullSelectName)
  • trunk/src/uvmat.m

    r783 r784  
    357357
    358358%% reset position of text_display and TableDisplay
    359 % if strcmp(get(handles.TableDisplay,'Visible'),'off')
    360     set(handles.text_display,'Units','pixels')
    361     pos_1=get(handles.text_display,'Position');% [lower x lower y width height] for text_display
    362         pos_1(3)=1.2*ColumnWidth;
    363     pos_1(1)=size_fig(3)-pos_1(3);             % set text display to the right of the fig
    364     pos_1(2)=size_fig(4)-pos_InputFile(4)-pos_1(4);             % set text display to the top of the fig
    365     set(handles.text_display,'Position',pos_1)
    366     % reset position of TableDisplay
    367 % else
    368 %     set(handles.TableDisplay,'Units','pixels')
    369 %     pos_1=get(handles.TableDisplay,'Position');
    370 %     pos_1(3)=1.2*ColumnWidth;
    371 %     pos_1(1)=size_fig(3)-pos_1(3);
    372 %     pos_1(2)=size_fig(4)-pos_InputFile(4)-pos_1(4);
    373     set(handles.TableDisplay,'Position',pos_1)
    374     % reset position of CheckTable
    375     set(handles.CheckTable,'Units','pixels')
     359set(handles.text_display,'Units','pixels')
     360pos_1=get(handles.text_display,'Position');% [lower x lower y width height] for text_display
     361    pos_1(3)=1.2*ColumnWidth;
     362pos_1(1)=size_fig(3)-pos_1(3);             % set text display to the right of the fig
     363pos_1(2)=size_fig(4)-pos_InputFile(4)-pos_1(4);             % set text display to the top of the fig
     364set(handles.text_display,'Position',pos_1)
     365set(handles.TableDisplay,'Position',pos_1)
     366% reset position of CheckTable
     367set(handles.CheckTable,'Units','pixels')
    376368pos_CheckTable=get(handles.CheckTable,'Position');% [lower x lower y width height] for CheckHold
    377369pos_CheckTable(1)=pos_1(1)-pos_CheckTable(3);       % set 'CheckHold' to the right of the fig
    378370pos_CheckTable(2)=pos_InputFile(2)-pos_CheckTable(4);          % set 'CheckHold' to the lower edge of text display
    379371set(handles.CheckTable,'Position',pos_CheckTable)
    380 % end
    381372
    382373%% reset position of CheckHold
     
    436427
    437428
    438 %------------------------------------------------------------------------
    439 %------------------------------------------------------------------------
    440 %  II - FUNCTIONS FOR INTRODUCING THE INPUT FILES
    441 % automatically sets the global properties when the rootfile name is introduced
    442 % then activate the view-field action if selected
    443 % it is activated either by clicking on the RootPath window or by the
    444 % browser
    445 %------------------------------------------------------------------------
     429
     430%------------------------------------------------------------------------
     431%------------------------------------------------------------------------
     432%  II - TOOLS FROM THE UPPER MENU BAR
     433%------------------------------------------------------------------------
     434%------------------------------------------------------------------------
     435
     436%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     437% Open Menu Callbacks
     438%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     439
    446440%------------------------------------------------------------------------
    447441% --- Executes on the menu Open/Browse...
     
    514508end
    515509
    516 %
    517 % DirName=fullfile(OutPut.Campaign,OutPut.Experiment{1},OutPut.DataSeries{1});
    518 % ListStruct=dir(DirName); %list files and the dir DataSeries
    519 % % select the first appropriate file in the dir
    520 % FileName='';
    521 % for ilist=1:numel(ListStruct)
    522 %     if ~isequal(ListStruct(ilist).isdir,1)%look for files, not dir
    523 %         FileName=ListStruct(ilist).name;
    524 %         FileType=get_file_type(fullfile(DirName,FileName));
    525 %         switch FileType
    526 %             case {'image','multimage','civx','civdata','netcdf'}
    527 %                 break
    528 %         end
    529 %     end
    530 % end
    531 % if isempty(FileName)
    532 %     msgbox_uvmat('ERROR',['no appropriate input file in the DataSeries folder ' fullfile(DirName)])
    533 %     return
    534 % end
    535 
    536510%% update the list of campaigns in the menubar
    537511MenuCampaign=[{get(handles.MenuCampaign_1,'Label')};{get(handles.MenuCampaign_2,'Label')};...
     
    566540set(handles.MenuOpenCampaign,'ForegroundColor',[1 1 0])
    567541OutPut=browse_data(get(hObject,'Label'));% open the GUI browse_data to get select a campaign dir, experiment and device
    568 if ~isfield(OutPut,'Campaign')
    569     return
    570 end
    571 DirName=fullfile(OutPut.Campaign,OutPut.Experiment{1},OutPut.DataSeries{1});
    572 fileinput=uigetfile_uvmat('pick an input file',fullfile(OutPut.Campaign,OutPut.Experiment{1},OutPut.DataSeries{1}));
    573 hh=dir(fileinput);
    574 if numel(hh)>1
    575     msgbox_uvmat('ERROR','invalid input, probably a broken link');
    576     return
    577 end
    578 %
    579 % hdir=dir(DirName); %list files and dirs
    580 % FileName='';
    581 % for ilist=1:numel(hdir)
    582 %     if ~isequal(hdir(ilist).isdir,1)%look for files, not dir
    583 %         FileName=hdir(ilist).name;
    584 %         FileType=get_file_type(fullfile(DirName,FileName));
    585 %         switch FileType
    586 %             case {'image','multimage','civx','civdata','netcdf'}
    587 %             break
    588 %         end
    589 %     end
    590 % end
    591 % if isempty(FileName)
    592 %     msgbox_uvmat('ERROR','no valid input file in the selected directory')
    593 % else
    594 display_file_name(handles,fileinput)
    595 % end
    596 set(handles.MenuOpenCampaign,'ForegroundColor',[0 0 0])
    597 
    598 %------------------------------------------------------------------------
    599 % --- Called by action in FileIndex edit box
    600 function FileIndex_Callback(hObject, eventdata, handles)
    601 %------------------------------------------------------------------------
    602 [tild,tild,tild,i1,i2,j1,j2]=fileparts_uvmat(get(handles.FileIndex,'String'));
    603 set(handles.i1,'String',num2str(i1));%update the counters
    604 set(handles.i2,'String',num2str(i2));
    605 set(handles.j1,'String',num2str(j1));
    606 set(handles.j2,'String',num2str(j2));
    607 
    608 
    609 %------------------------------------------------------------------------
    610 % --- Called by action in NomType edit box
    611 function NomType_Callback(hObject, eventdata, handles)
    612 %------------------------------------------------------------------------
    613 i1=str2num(get(handles.i1,'String'));
    614 i2=str2num(get(handles.i2,'String'));
    615 j1=str2num(get(handles.j1,'String'));
    616 j2=str2num(get(handles.j2,'String'));
    617 FileIndex=fullfile_uvmat('','','','',get(handles.NomType,'String'),i1,i2,j1,j2);
    618 set(handles.FileIndex,'String',FileIndex)
    619 % refresh the current settings and refresh the field view
    620 RootPath_Callback(hObject,eventdata,handles)
    621 
    622 %------------------------------------------------------------------------
    623 % --- Called by action in NomType edit box
    624 function NomType_1_Callback(hObject, eventdata, handles)
    625 %------------------------------------------------------------------------
    626 i1=str2num(get(handles.i1,'String'));
    627 i2=str2num(get(handles.i2,'String'));
    628 j1=str2num(get(handles.j1,'String'));
    629 j2=str2num(get(handles.j2,'String'));
    630 FileIndex=fullfile_uvmat('','','','',get(handles.NomType_1,'String'),i1,i2,j1,j2);
    631 set(handles.FileIndex_1,'String',FileIndex)
    632 % inputfilerefresh the current settings and inputfilerefresh the field view
    633 RootPath_1_Callback(hObject,eventdata,handles)
    634 
    635 %------------------------------------------------------------------------
    636 % --- Executes on button press in InputFileREFRESH.
    637 function InputFileREFRESH_Callback(hObject, eventdata, handles)
    638 %------------------------------------------------------------------------
    639 set(handles.InputFileREFRESH,'BackgroundColor',[1 1 0])% set button color to yellow to indicate that refresh is under action
    640 set(handles.uvmat,'Pointer','watch') % set the mouse pointer to 'watch'
    641 drawnow
    642 % read the current input file name:
    643 [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles);
    644 % detect the file type, get the movie object if relevant, and look for the corresponding file series:
    645 [RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,tild,FileInfo,MovieObject]=find_file_series(fullfile(RootPath,SubDir),[RootFile FileIndices FileExt]);
    646 if isempty(i1_series)
    647     fileinput=uigetfile_uvmat('pick an input file',fullfile(RootPath,SubDir));
     542if isfield(OutPut,'Campaign')
     543    fileinput=uigetfile_uvmat('pick an input file',fullfile(OutPut.Campaign,OutPut.Experiment{1},OutPut.DataSeries{1}));
    648544    hh=dir(fileinput);
    649545    if numel(hh)>1
    650546        msgbox_uvmat('ERROR','invalid input, probably a broken link');
    651547    else
    652         %% display the selected field and related information
    653         if isempty(fileinput)
    654             errormsg='aborted';
    655         else
    656             display_file_name(handles,fileinput,1)
    657         end
    658     end
    659 else
    660     % initiate the input file series and refresh the current field view:
    661     errormsg=update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileInfo,MovieObject,1);
    662 end
    663 
    664 %% refresh the second series if relevant
    665 if ~isempty(errormsg) && get(handles.SubField,'Value')
    666     [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes_1(handles);
    667     % detect the file type, get the movie object if relevant, and look for the corresponding file series:
    668     [RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,tild,FileInfo,MovieObject]=find_file_series(fullfile(RootPath,SubDir),[RootFile FileIndices FileExt]);
    669     if isempty(i1_series)
    670         fileinput=uigetfile_uvmat('pick an input file for the second line',fullfile(RootPath,SubDir));
    671         hh=dir(fileinput);
    672         if numel(hh)>1
    673             msgbox_uvmat('ERROR','invalid input, probably a broken link');
    674         else
    675             %% display the selected field and related information
    676             if isempty(fileinput)
    677                 errormsg='aborted';
    678             else
    679                 display_file_name(handles,fileinput,2)
    680             end
    681         end
    682     else
    683         % initiate the input file series and inputfilerefresh the current field view:
    684         errormsg=update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileInfo,MovieObject,2);
    685     end
    686 end
    687 if ~isempty(errormsg)
    688     set(handles.InputFileREFRESH,'BackgroundColor',[1 0 1])% put back button color to magenta, input not succesfull
    689 end
    690 set(handles.uvmat,'Pointer','arrow')% set back the mouse pointer to arrow
    691 
    692 %------------------------------------------------------------------------
    693 % --- Fills the edit boxes RootPath, RootFile,NomType...from an input file name 'fileinput'
    694 function errormsg=display_file_name(handles,fileinput,index)
    695 %------------------------------------------------------------------------
    696 %% look for the input file existence
    697 errormsg='';%default
    698 if ~exist(fileinput,'file')
    699     errormsg=['input file ' fileinput  ' does not exist'];
    700     msgbox_uvmat('ERROR',errormsg)
    701     return
    702 end
    703 
    704 %% define the relevant handles for the first field series (index=1) or the second file series (index=2)
    705 if ~exist('index','var')
    706     index=1;
    707 end
    708 if index==1
    709     handles_RootPath=handles.RootPath;
    710     handles_SubDir=handles.SubDir;
    711     handles_RootFile=handles.RootFile;
    712     handles_FileIndex=handles.FileIndex;
    713     handles_NomType=handles.NomType;
    714     handles_FileExt=handles.FileExt;
    715 elseif index==2
    716     handles_RootPath=handles.RootPath_1;
    717     handles_SubDir=handles.SubDir_1;
    718     handles_RootFile=handles.RootFile_1;
    719     handles_FileIndex=handles.FileIndex_1;
    720     handles_NomType=handles.NomType_1;
    721     handles_FileExt=handles.FileExt_1;
    722     set(handles.RootPath_1,'Visible','on')
    723     set(handles.RootFile_1,'Visible','on')
    724     set(handles.SubDir_1,'Visible','on');
    725     set(handles.FileIndex_1,'Visible','on');
    726     set(handles.FileExt_1,'Visible','on');
    727     set(handles.NomType_1,'Visible','on');
    728     set(handles.TimeName_1,'Visible','on')
    729     set(handles.TimeValue_1,'Visible','on')
    730 end
    731 set(handles.InputFileREFRESH,'BackgroundColor',[1 1 0])% paint REFRESH button to yellow to visualise root file input
    732 set(handles.uvmat,'Pointer','watch') % set the mouse pointer to 'watch'
    733 drawnow
    734 
    735 %% detect root name, nomenclature and indices in the input file name:
    736 [FilePath,FileName,FileExt]=fileparts(fileinput);
    737 % detect the file type, get the movie object if relevant, and look for the corresponding file series:
    738 % the root name and indices may be corrected by including the first index i1 if a corresponding xml file exists
    739 [RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,NomType,FileInfo,MovieObject,i1,i2,j1,j2]=find_file_series(FilePath,[FileName FileExt]);
    740 FileType=FileInfo.FileType;
    741 if strcmp(FileType,'txt')
    742     try
    743         edit(fileinput)
    744     catch ME
    745         msgbox_uvmat('ERROR','invalid intput file')
    746     end
    747     return
    748 elseif strcmp(FileType,'xml')
    749     editxml(fileinput)
    750      return
    751 elseif strcmp(FileType,'figure')
    752     open(fileinput)
    753      return
    754 end
    755 
    756 %% open the file or fill the GUI uvmat according to the detected file type
    757 switch FileType
    758     case ''
    759         msgbox_uvmat('ERROR','invalid input file type')
    760     case 'txt'
    761         edit(fileinput)
    762     case 'figure'                           %display matlab figure
    763         hfig=open(fileinput);
    764         set(hfig,'WindowButtonMotionFcn','mouse_motion')%set mouse action functio
    765         set(hfig,'WindowButtonUpFcn','mouse_up')%set mouse click action function
    766         set(hfig,'WindowButtonUpFcn','mouse_down')%set mouse click action function
    767     case 'xml'                % edit xml files
    768         t=xmltree(fileinput);
    769         % the xml file marks a project or project link, open datatree_browser
    770         if strcmp(get(t,1,'name'),'Project')&& exist(regexprep(fileinput,'.xml$',''),'dir')
    771             datatree_browser(fileinput)
    772         else % other xml file, open the xml editor
    773             editxml(fileinput);
    774         end
    775     case 'xls'% Excel file opended by editxml
    776         editxml(fileinput);
    777     otherwise
    778         set(handles_RootPath,'String',RootPath);
    779         rootname=fullfile(RootPath,SubDir,RootFile);
    780         set(handles_SubDir,'String',['/' SubDir]);
    781         set(handles_RootFile,'String',['/' RootFile]); %display the separator
    782         indices=fileinput(length(rootname)+1:end);
    783         indices(end-length(FileExt)+1:end)=[]; %remove extension
    784         set(handles_FileIndex,'String',indices);
    785         set(handles_NomType,'String',NomType);
    786         set(handles_FileExt,'String',FileExt);
    787         if index==1
    788             % fill file index counters if the first file series is opened
    789             set(handles.i1,'String',num2str(i1));
    790             set(handles.i2,'String',num2str(i2));
    791             set(handles.j1,'String',num2stra(j1,NomType));
    792             set(handles.j2,'String',num2stra(j2,NomType));
    793         else %read the current field index to synchronise with the first series
    794             i1_s=str2num(get(handles.i1,'String'));
    795             i2_0=str2num(get(handles.i2,'String'));
    796             if ~isempty(i2_0)
    797                 i2_s=i2_0;
    798             else
    799                i2_s=i2;
    800             end
    801             j1_0=stra2num(get(handles.j1,'String'));
    802             if ~isempty(j1_0)
    803                 j1_s=j1_0;
    804             else
    805                 j1_s=j1;
    806             end
    807             j2_0=stra2num(get(handles.j2,'String'));
    808             if ~isempty(j2_0)
    809                 j2_s=j2_0;
    810             else
    811                 j2_s=j2;
    812             end
    813         end
    814        
    815         % synchronise indices of the second  input file if it exists
    816         if get(handles.SubField,'Value')==1% if the subfield button is activated, update the field numbers
    817             Input=read_GUI(handles.InputFile);
    818             if ~isfield(Input,'RootPath_1')||strcmp(Input.RootPath_1,'"')
    819                 Input.RootPath_1=Input.RootPath;
    820             end
    821             if ~isfield(Input,'SubDir_1')||strcmp(Input.SubDir_1,'"')
    822                 Input.SubDir_1=Input.SubDir;
    823             end
    824             if ~isfield(Input,'RootFile_1')||strcmp(Input.RootFile_1,'"')
    825                 Input.RootFile_1=Input.RootFile;
    826             end
    827             if ~isfield(Input,'FileExt_1')||strcmp(Input.FileExt_1,'"')
    828                 Input.FileExt_1=Input.FileExt;
    829             end
    830             if ~isfield(Input,'NomType_1')||strcmp(Input.NomType_1,'"')
    831                 Input.NomType_1=Input.NomType;
    832             end
    833             %updtate the indices of the second field series to correspond to the newly opened one
    834             FileName_1=fullfile_uvmat(Input.RootPath_1,Input.SubDir_1,Input.RootFile_1,Input.FileExt_1,Input.NomType_1,i1_s,i2_s,j1_s,j2_s);
    835             if exist(FileName_1,'file')
    836                 FileIndex_1=fullfile_uvmat('','','','',Input.NomType_1,i1_s,i2_s,j1_s,j2_s);
    837             else
    838                 FileIndex_1=fullfile_uvmat('','','','',Input.NomType_1,i1,i2,j1,j2);
    839                 msgbox_uvmat('WARNING','unable to synchronise the indices of the two series')
    840             end
    841             set(handles.FileIndex_1,'String',FileIndex_1)
    842         end
    843        
    844         %enable other menus
    845         set(handles.MenuOpenCampaign,'Enable','on')
    846         set(handles.MenuExport,'Enable','on')
    847         set(handles.MenuExportFigure,'Enable','on')
    848         set(handles.MenuExportMovie,'Enable','on')
    849         set(handles.MenuTools,'Enable','on')
    850 
    851         % initiate input file series and inputfilerefresh the current field view:     
    852         update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileInfo,MovieObject,index);
    853 
    854 end
    855 
    856 %% update list of recent files in the menubar and save it for future opening
    857 MenuFile=[{get(handles.MenuFile_1,'Label')};{get(handles.MenuFile_2,'Label')};...
    858     {get(handles.MenuFile_3,'Label')};{get(handles.MenuFile_4,'Label')};{get(handles.MenuFile_5,'Label')}];
    859 str_find=strcmp(fileinput,MenuFile);
    860 if isempty(find(str_find,1))
    861     MenuFile=[{fileinput};MenuFile];%insert the current file if not already in the list
    862 end
    863 for ifile=1:min(length(MenuFile),5)
    864     set(handles.(['MenuFile_' num2str(ifile)]),'Label',MenuFile{ifile});
    865     %set(handles.(['MenuFile_' num2str(ifile) '_1']),'Label',MenuFile{ifile});
    866 end
    867 dir_perso=prefdir;
    868 profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
    869 if exist(profil_perso,'file')
    870     save (profil_perso,'MenuFile','RootPath','-append'); %store the file names for future opening of uvmat
    871 else
    872     save (profil_perso,'MenuFile','RootPath','-V6'); %store the file names for future opening of uvmat
    873 end
    874 
    875 set(handles.InputFileREFRESH,'BackgroundColor',[1 0 0])% paint back button to red to indicate update is finished
    876 set(handles.uvmat,'Pointer','arrow')% set back the mouse pointer to arrow
    877 
    878 
    879 %------------------------------------------------------------------------
    880 % --- Update information about a new field series (indices to scan, timing,
    881 %     calibration from an xml file, then inputfilerefresh current plots
    882 function errormsg=update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileInfo,VideoObject,index)
    883 %------------------------------------------------------------------------
    884 errormsg=''; %default error msg
    885 %% define the relevant handles depending on the index (1=first file series, 2= second file series)
    886 if ~exist('index','var')
    887     index=1;
    888 end
    889 if index==1
    890     handles_Fields=handles.FieldName;
    891 elseif index==2
    892     handles_Fields=handles.FieldName_1;
    893 end
    894 
    895 set(handles.FieldName,'UserData',[])% reinialize data from uvmat opening
    896 UvData=get(handles.uvmat,'UserData');%huvmat=handles of the uvmat interface
    897 UvData.NewSeries=1; %flag for REFRESH: begin a new series
    898 UvData.FileName_1='';% name of the current second field (used to detect a  constant field during file scanning)
    899 UvData.FileType{index}=FileInfo.FileType;
    900 UvData.FileInfo{index}=FileInfo;
    901 UvData.i1_series{index}=i1_series;
    902 UvData.i2_series{index}=i2_series;
    903 UvData.j1_series{index}=j1_series;
    904 UvData.j2_series{index}=j2_series;
    905 set(handles.FixVelType,'Value',0); %desactivate fixed veltype
    906 if index==1
    907     [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles);
    908 else
    909     [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes_1(handles);
    910 end
    911 FileName=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt];
    912 FileBase=fullfile(RootPath,RootFile);
    913 if ~exist(FileName,'file')
    914     errormsg=['input file ' FileName ' not found'];
    915    msgbox_uvmat('ERROR',errormsg);   
    916     return
    917 end
    918 
    919 %% read timing and total frame number from the current file (movie files) !! may be overrid by xml file
    920 TimeUnit='';%default
    921 TimeName='';%default
    922 XmlData.Time=[];%default
    923 imainfo=[];
    924 ColorType='falsecolor'; %default
    925 UvData.MovieObject{index}=VideoObject;
    926 if ~isempty(VideoObject)% case of video data
    927     imainfo=get(VideoObject);
    928     TimeUnit='s';
    929     if isempty(j1_series); %frame index along i
    930         XmlData.Time=zeros(imainfo.NumberOfFrames+1,2);
    931         XmlData.Time(:,2)=(0:1/imainfo.FrameRate:(imainfo.NumberOfFrames)/imainfo.FrameRate)';
    932     else
    933         XmlData.Time=[0;ones(size(i1_series,3)-1,1)]*(0:1/imainfo.FrameRate:(imainfo.NumberOfFrames)/imainfo.FrameRate);
    934     end
    935     %set(handles.Dt_txt,'String',['Dt=' num2str(1000/imainfo.FrameRate) 'ms']);%display the elementary time interval in millisec
    936     TimeName='video';
    937     ColorType='truecolor';
    938 elseif ~isempty(FileExt(2:end))&&(~isempty(imformats(FileExt(2:end))) || isequal(FileExt,'.vol'))%&& isequal(NomType,'*')% multi-frame image
    939     if ~isequal(SubDir,'')
    940         imainfo=imfinfo([fullfile(RootPath,SubDir,RootFile) FileIndices FileExt]);
    941     else
    942         imainfo=imfinfo([FileBase FileIndices FileExt]);
    943     end
    944     ColorType=imainfo.ColorType;%='truecolor' for color images
    945 end
    946 if isfield(imainfo,'Width') && isfield(imainfo,'Height')
    947     if length(imainfo)>1
    948         set(handles.num_Npx,'String',num2str(imainfo(1).Width));%fills nbre of pixels x box
    949         set(handles.num_Npy,'String',num2str(imainfo(1).Height));%fills nbre of pixels x box
    950     else
    951         set(handles.num_Npx,'String',num2str(imainfo.Width));%fills nbre of pixels x box
    952         set(handles.num_Npy,'String',num2str(imainfo.Height));%fills nbre of pixels x box
    953     end
    954 else
    955     set(handles.num_Npx,'String','');%fills nbre of pixels x box
    956     set(handles.num_Npy,'String','');%fills nbre of pixels x box
    957 end
    958 set(handles.CheckBW,'Value',strcmp(ColorType,'grayscale'))% select handles.CheckBW if grayscale image
    959 
    960 %% read parameters (time, geometric calibration..) from a documentation file (.xml advised)
    961 XmlData.GeometryCalib=[];%default
    962 XmlFileName=find_imadoc(RootPath,SubDir,RootFile,FileExt);
    963 [tild,tild,DocExt]=fileparts(XmlFileName);
    964 warntext='';%default warning message
    965 NbSlice=1;%default
    966 ImaDoc_str='';
    967 if ~isempty(XmlFileName)
    968     set(handles.view_xml,'Visible','on')
    969     set(handles.view_xml,'BackgroundColor',[1 1 0])% paint  to yellow color to indicate reading of the xml file
    970     set(handles.view_xml,'String','view .xml')
    971     drawnow
    972     [XmlDataRead,warntext]=imadoc2struct(XmlFileName);
    973     if ~isempty(warntext)
    974         msgbox_uvmat('WARNING',warntext)
    975     end
    976     if ~isempty(XmlDataRead)
    977         ImaDoc_str=['view ' DocExt];  % DocExt= '.xml' or .civ (obsolete case)
    978         %XmlData=XmlDataRead;
    979         if isfield(XmlDataRead,'TimeUnit')&& ~isempty(XmlDataRead.TimeUnit)
    980             TimeUnit=XmlDataRead.TimeUnit;
    981         end
    982         if isfield(XmlDataRead,'Time')&& ~isempty(XmlDataRead.Time)
    983             XmlData.Time=XmlDataRead.Time;
    984         end
    985         set(handles.view_xml,'BackgroundColor',[1 1 1])% paint back to white
    986         drawnow
    987         if isfield(XmlDataRead, 'GeometryCalib') && ~isempty(XmlDataRead.GeometryCalib)
    988             XmlData.GeometryCalib=XmlDataRead.GeometryCalib;
    989             if isfield(XmlData.GeometryCalib,'CheckVolumeScan') && isequal(XmlData.GeometryCalib.CheckVolumeScan,1)
    990                 set (handles.slices,'String','volume')
    991             end
    992             % check whether the GUI geometry_calib is opened
    993             hgeometry_calib=findobj('tag','geometry_calib');
    994             if ~isempty(hgeometry_calib) % check whether the display of the GUI geometry_calib is consistent with the current calib param
    995                 GUserData=get(hgeometry_calib,'UserData');
    996                 if ~(isfield(GUserData,'XmlInputFile') && strcmp(GUserData.XmlInputFile,XmlFileName))
    997                     answer=msgbox_uvmat('INPUT_Y-N','refresh the display of the GUI geometry_calib with the new input data?');
    998                     if strcmp(answer,'Yes')
    999                         geometry_calib(XmlFileName);%diplay the new calibration points and parameters in geometry_calib
    1000                     end
    1001                 end
    1002             end
    1003         end
    1004     end
    1005 end
    1006 if isempty(ImaDoc_str)
    1007     set(handles.view_xml,'Visible','off') % no .xml (or .civ) file detected
    1008 else
    1009     set(handles.view_xml,'String',ImaDoc_str)% indicate that a xml file has been detected
    1010 end
    1011 
    1012 %% Define timing
    1013 % time not set by the input file: images or civ data: indicate that time is read from the xml file
    1014 FileType=FileInfo.FileType;
    1015 if isfield(XmlData,'Time')&& ~isempty(XmlData.Time) && ...
    1016         (strcmp(FileType,'image')|| strcmp(FileType,'multimage'))%||strcmp(FileType,'civdata')||strcmp(FileType,'civx'))
    1017     TimeName='xml';
    1018 elseif strcmp(FileType,'civdata')
    1019     TimeName='civdata';
    1020 elseif strcmp(FileType,'civx')
    1021     TimeName='civx';
    1022 end
    1023 if index==1
    1024     set(handles.TimeName,'String',TimeName)
    1025 else
    1026     set(handles.TimeName_1,'String',TimeName)
    1027     set(handles.TimeName_1,'Visible','on')
    1028 end
    1029 
    1030 %% store last index in handles.MaxIndex_i and .MaxIndex_j
    1031 nbfield=max(max(max(i2_series)));
    1032 if isempty(nbfield)
    1033     nbfield=max(max(max(i1_series)));
    1034 end
    1035 nbfield_j=max(max(max(j2_series)));
    1036 if isempty(nbfield_j)
    1037     nbfield_j=max(max(max(j1_series)));
    1038 end
    1039 if isfield(XmlData,'Time')&& ~isempty(XmlData.Time)
    1040     %transform .Time to a column vector if it is a line vector the nomenclature uses a single index
    1041     if isequal(size(XmlData.Time,1),1)
    1042         XmlData.Time=(XmlData.Time)';
    1043     end
    1044 end
    1045 last_i_cell=get(handles.MaxIndex_i,'String');
    1046 if isempty(nbfield)
    1047     last_i_cell{index}='';
    1048 else
    1049     last_i_cell{index}=num2str(nbfield);
    1050 end
    1051 set(handles.MaxIndex_i,'String',last_i_cell)
    1052 last_j_cell=get(handles.MaxIndex_j,'String');
    1053 if isempty(nbfield_j)
    1054      last_j_cell{index}='';
    1055 else
    1056      last_j_cell{index}=num2str(nbfield_j);
    1057 end
    1058 set(handles.MaxIndex_j,'String',last_j_cell);
    1059 
    1060 %% store geometric calibration in UvData
    1061 if isfield(XmlData,'GeometryCalib')
    1062     GeometryCalib=XmlData.GeometryCalib;
    1063     if isempty(GeometryCalib)
    1064         set(handles.pxcmx,'String','')
    1065         set(handles.pxcmy,'String','')
    1066         set(handles.pxcmx,'Visible','off')
    1067         set(handles.pxcmy,'Visible','off')
    1068         set(handles.TransformName,'Value',1); %  no transform by default
    1069     else
    1070         set(handles.pxcmx,'Visible','on')
    1071         set(handles.pxcmy,'Visible','on')
    1072         if (isfield(GeometryCalib,'R')&& ~isequal(GeometryCalib.R(2,1),0) && ~isequal(GeometryCalib.R(1,2),0)) ||...
    1073             (isfield(GeometryCalib,'kappa1')&& ~isequal(GeometryCalib.kappa1,0))
    1074             set(handles.pxcmx,'String','var')
    1075             set(handles.pxcmy,'String','var')
    1076         elseif isfield(GeometryCalib,'fx_fy')
    1077             pixcmx=GeometryCalib.fx_fy(1);%*GeometryCalib.R(1,1)*GeometryCalib.sx/(GeometryCalib.Tz*GeometryCalib.dpx);
    1078             pixcmy=GeometryCalib.fx_fy(2);%*GeometryCalib.R(2,2)/(GeometryCalib.Tz*GeometryCalib.dpy);
    1079             set(handles.pxcmx,'String',num2str(pixcmx))
    1080             set(handles.pxcmy,'String',num2str(pixcmy))
    1081         end
    1082         if ~get(handles.CheckFixLimits,'Value')
    1083             set(handles.TransformName,'Value',3); % phys transform by default if fixedLimits is off
    1084         end
    1085         if isfield(GeometryCalib,'SliceCoord')           
    1086            siz=size(GeometryCalib.SliceCoord);
    1087            if siz(1)>1
    1088                NbSlice=siz(1);
    1089                set(handles.slices,'Visible','on')
    1090                set(handles.slices,'Value',1)
    1091            end
    1092            if isfield(GeometryCalib,'CheckVolumeScan') && isequal(GeometryCalib.CheckVolumeScan,1)
    1093                set(handles.num_NbSlice,'Visible','off')
    1094            else
    1095                set(handles.num_NbSlice,'Visible','on')
    1096                set(handles.num_NbSlice,'String',num2str(NbSlice))
    1097            end
    1098            slices_Callback([],[], handles)
    1099         end           
    1100     end
    1101 end
    1102 
    1103 %% update the data attached to the uvmat interface
    1104 if ~isempty(TimeUnit)
    1105     if index==2 && isfield(UvData,'TimeUnit') && ~strcmp(UvData.TimeUnit,TimeUnit)
    1106         msgbox_uvmat('WARNING',['time unit for second file series ' TimeUnit ' inconsistent with first series'])
    1107     else
    1108         UvData.TimeUnit=TimeUnit;
    1109     end
    1110 end
    1111 UvData.XmlData{index}=XmlData;
    1112 UvData.NewSeries=1;
    1113 
    1114 %display warning message
    1115 if ~isequal(warntext,'')
    1116     msgbox_uvmat('WARNING',warntext);
    1117 end
    1118 
    1119 %% set default options in menu 'FieldName'
    1120 switch FileType
    1121     case {'civx','civdata'}
    1122         [FieldList,ColorList]=set_field_list('U','V','C');
    1123         set(handles_Fields,'String',[{'image'};FieldList;{'get_field...'}]);%standard menu for civx data
    1124         set(handles_Fields,'Value',2) % set menu to 'velocity
    1125         if index==1
    1126             set(handles.FieldName_1,'Value',1);
    1127             set(handles.FieldName_1,'String',[{''};{'image'};FieldList;{'get_field...'}]);%standard menu for civx data reproduced for the second field
    1128         end
    1129         set(handles.ColorScalar,'Value',1)
    1130         set(handles.ColorScalar,'String',ColorList)
    1131         set(handles.Vectors,'Visible','on')
    1132         %set(handles.Coord_x,'Value',1);
    1133         set(handles.Coord_x,'String','X');
    1134         set(handles.Coord_y,'String','Y');
    1135     case 'netcdf'
    1136         set(handles_Fields,'Value',1)
    1137         set(handles_Fields,'String',{'get_field...'})
    1138         if index==1
    1139             FieldName_Callback([],[], handles)
    1140         else
    1141             FieldName_1_Callback([],[], handles)
    1142         end
    1143     otherwise
    1144         set(handles_Fields,'Value',1) % set menu to 'image'
    1145         set(handles_Fields,'String',{'image'})
    1146         %set(handles.Coord_x,'Value',1);
    1147         set(handles.Coord_x,'String','Coord_x');
    1148     set(handles.Coord_y,'String','Coord_y');
    1149 end
    1150 set(handles.uvmat,'UserData',UvData)
    1151 
    1152 %% set index navigation options
    1153 scan_option='i';%default
    1154 state_j='off'; %default
    1155 if index==2
    1156     if get(handles.scan_j,'Value')
    1157         scan_option='j'; %keep the scan option for the second file series
    1158     end
    1159     if strcmp(get(handles.j1,'Visible'),'on')
    1160         state_j='on';
    1161     end
    1162 end
    1163 [ref_j,ref_i]=find(squeeze(i1_series(1,:,:)));
    1164 if ~isempty(j1_series)
    1165         state_j='on';
    1166         if index==1
    1167             if isequal(ref_i,ref_i(1)*ones(size(ref_j)))% if ref_i is always equal to its first value
    1168                 scan_option='j'; %scan j indext               
    1169             end
    1170         end
    1171 end
    1172 if isequal(scan_option,'i')
    1173     diff_ref_i=diff(ref_i,1);
    1174     if isempty(diff_ref_i)
    1175         diff_ref_i=1;
    1176     end
    1177     if isequal (diff_ref_i,diff_ref_i(1)*ones(size(diff_ref_i)))
    1178         set(handles.num_IndexIncrement,'String',num2str(diff_ref_i(1)))
    1179     end
    1180      set(handles.scan_i,'Value',1)
    1181      scan_i_Callback([],[], handles);
    1182 else
    1183     diff_ref_j=diff(ref_j);
    1184     if isempty(diff_ref_j)
    1185         diff_ref_j=1;
    1186     end
    1187     if isequal (diff_ref_j,diff_ref_j(1)*ones(size(diff_ref_j)))
    1188         set(handles.num_IndexIncrement,'String',num2str(diff_ref_j(1)))
    1189     end
    1190      set(handles.scan_j,'Value',1)
    1191      scan_j_Callback([],[], handles);
    1192 end
    1193 set(handles.scan_j,'Visible',state_j)
    1194 set(handles.j1,'Visible',state_j)
    1195 set(handles.j2,'Visible',state_j)
    1196 set(handles.MaxIndex_j,'Visible',state_j);
    1197 set(handles.j_text,'Visible',state_j);
    1198 if ~isempty(i2_series)||~isempty(j2_series)
    1199     set(handles.CheckFixPair,'Visible','on')
    1200 elseif index==1
    1201     set(handles.CheckFixPair,'Visible','off')
    1202 end
    1203 
    1204 %% apply the effect of the transform fct and view the field 
    1205 transform=get(handles.TransformPath,'UserData');
    1206 if index==2 && (~isa(transform,'function_handle')||nargin(transform)<3)
    1207     set(handles.TransformName,'value',2); % set transform to sub_field if the current fct doe not accept two input fields
    1208 end
    1209 set(handles.InputFileREFRESH,'BackgroundColor',[1 0 0])% set button color to red to indicate that refresh has been updated
    1210 TransformName_Callback([],[],handles)% callback for the selection of transform function, then refresh the current plot
    1211 mask_test=get(handles.CheckMask,'value');
    1212 if mask_test
    1213     MaskData=get(handles.CheckMask,'UserData');
    1214     if isfield(MaskData,'maskhandle') && ishandle(MaskData.maskhandle)
    1215           delete(MaskData.maskhandle)    %delete old mask
    1216     end
    1217     CheckMask_Callback([],[],handles)
    1218 end
    1219 
    1220 %------------------------------------------------------------------------
    1221 % --- switch file index scanning options scan_i and scan_j in an exclusive way
    1222 %------------------------------------------------------------------------
    1223 function scan_i_Callback(hObject, eventdata, handles)
    1224 
    1225 if get(handles.scan_i,'Value')==1
    1226     set(handles.scan_j,'Value',0)
    1227 else
    1228     set(handles.scan_j,'Value',1)
    1229 end
    1230 scan_j_Callback(hObject, eventdata, handles)
    1231 
    1232 %------------------------------------------------------------------------
    1233 % --- switch file index scanning options scan_i and scan_j in an exclusive way
    1234 %------------------------------------------------------------------------
    1235 function scan_j_Callback(hObject, eventdata, handles)
    1236 
    1237 if get(handles.scan_j,'Value')==1
    1238     set(handles.scan_i,'Value',0)
    1239 else
    1240     set(handles.scan_i,'Value',1)
    1241     set(handles.CheckFixPair,'Visible','off')
    1242 end
    1243 
    1244 %------------------------------------------------------------------------
    1245 function i1_Callback(hObject, eventdata, handles)
    1246 %------------------------------------------------------------------------
    1247 update_ij(handles,1)
    1248 
    1249 %------------------------------------------------------------------------
    1250 function i2_Callback(hObject, eventdata, handles)
    1251 %------------------------------------------------------------------------
    1252 update_ij(handles,2)
    1253 
    1254 %------------------------------------------------------------------------
    1255 function j1_Callback(hObject, eventdata, handles)
    1256 %------------------------------------------------------------------------
    1257 update_ij(handles,3)
    1258 
    1259 %------------------------------------------------------------------------
    1260 function j2_Callback(hObject, eventdata, handles)
    1261 %------------------------------------------------------------------------
    1262 update_ij(handles,4)
    1263 
    1264 %------------------------------------------------------------------------
    1265 %--- update the index display after action on edit boxes i1, i2, j1 or j2
    1266 %------------------------------------------------------------------------
    1267 function update_ij(handles,index_rank)
    1268    
    1269 NomType=get(handles.NomType,'String');
    1270 indices=get(handles.FileIndex,'String');
    1271 [tild,tild,tild,i1,i2,j1,j2]=fileparts_uvmat(indices);% the indices for the second series taken from FileIndex
    1272 switch index_rank
    1273     case 1
    1274         indices=fullfile_uvmat('','','','',NomType,stra2num(get(handles.i1,'String')),i2,j1,j2);
    1275 %        set(handles.i1,'BackgroundColor',[0.7 0.7 0.7])% mark the edit box in grey, then RUN0 will mark it in white for confirmation
    1276     case 2
    1277         indices=fullfile_uvmat('','','','',NomType,i1,stra2num(get(handles.i2,'String')),j1,j2);
    1278 %        set(handles.i2,'BackgroundColor',[0.7 0.7 0.7])% mark the edit box in grey, then RUN0 will mark it in white for confirmation
    1279     case 3
    1280         indices=fullfile_uvmat('','','','',NomType,i1,i2,stra2num(get(handles.j1,'String')),j2);
    1281 %        set(handles.j1,'BackgroundColor',[0.7 0.7 0.7])% mark the edit box in grey, then RUN0 will mark it in white for confirmation
    1282     case 4
    1283         indices=fullfile_uvmat('','','','',NomType,i1,i2,j1,stra2num(get(handles.j2,'String')));
    1284 %        set(handles.j2,'BackgroundColor',[0.7 0.7 0.7])% mark the edit box in grey, then RUN0 will mark it in white for confirmation
    1285 end
    1286 set(handles.FileIndex,'String',indices)
    1287 %set(handles.FileIndex,'BackgroundColor',[0.7 0.7 0.7])% mark the edit box in grey, then RUN0 will mark it in white for confirmation
    1288 % update the second index if relevant
    1289 if strcmp(get(handles.FileIndex_1,'Visible'),'on')
    1290     NomType_1=get(handles.NomType_1,'String');
    1291     indices_1=get(handles.FileIndex_1,'String');
    1292     [tild,tild,tild,i1_1,i2_1,j1_1,j2_1]=fileparts_uvmat(indices_1);% the indices for the second series taken from FileIndex_1
    1293     switch index_rank
    1294         case 1
    1295             indices_1=fullfile_uvmat('','','','',NomType_1,stra2num(get(handles.i1,'String')),i2_1,j1_1,j2_1);
    1296         case 2
    1297             indices_1=fullfile_uvmat('','','','',NomType_1,i1_1,stra2num(get(handles.i2,'String')),j1_1,j2_1);
    1298         case 3
    1299             indices_1=fullfile_uvmat('','','','',NomType_1,i1_1,i2_1,stra2num(get(handles.j1,'String')),j2_1);
    1300         case 4
    1301             indices_1=fullfile_uvmat('','','','',NomType_1,i1_1,i2_1,j1_1,stra2num(get(handles.j2,'String')));
    1302     end
    1303     set(handles.FileIndex_1,'String',indices_1)
    1304     set(handles.FileIndex_1,'BackgroundColor',[0.7 0.7 0.7])% mark the edit box in grey, then RUN0 will mark it in white for confirmation
    1305 end
    1306    
    1307 %------------------------------------------------------------------------
    1308 
    1309 %------------------------------------------------------------------------
    1310 function slices_Callback(hObject, eventdata, handles)
    1311 %------------------------------------------------------------------------
    1312 if strcmp(get(handles.slices,'String'),'slices')
    1313     if get(handles.slices,'Value')==1
    1314         set(handles.num_NbSlice,'Visible','on')
    1315         set(handles.z_text,'Visible','on')
    1316         set(handles.z_index,'Visible','on')
    1317         num_NbSlice_Callback(hObject, eventdata, handles)
    1318     else
    1319         set(handles.num_NbSlice,'Visible','off')
    1320         set(handles.z_text,'Visible','off')
    1321         set(handles.z_index,'Visible','off')
    1322         set(handles.masklevel,'Value',1)
    1323         set(handles.masklevel,'String',{'1'})
    1324     end
    1325 end
    1326 
    1327 %------------------------------------------------------------------------
    1328 function num_NbSlice_Callback(hObject, eventdata, handles)
    1329 %------------------------------------------------------------------------
    1330 mode=get(handles.slices,'String');
    1331 nb_slice_str=get(handles.num_NbSlice,'String');
    1332 if strcmp(mode,'volume')
    1333     z=stra2num(get(handles.j1,'String'));
    1334 else
    1335     num=str2double(get(handles.i1,'String'));
    1336     nbslice=str2double(get(handles.num_NbSlice,'String'));
    1337     z=mod(num-1,nbslice)+1;
    1338 end
    1339 set(handles.z_index,'String',num2str(z))
    1340 for ilist=1:nbslice
    1341     list_index{ilist,1}=num2str(ilist);
    1342 end   
    1343 set(handles.masklevel,'String',list_index)
    1344 set(handles.masklevel,'Value',z)
    1345 
    1346 %------------------------------------------------------------------------
    1347 % --- Executes on button press in view_xml.
    1348 %------------------------------------------------------------------------
    1349 function view_xml_Callback(hObject, eventdata, handles)
    1350 
    1351 % if TimeName defined, open the xml file corresponding to the first file
    1352 % series, else open the xml file corresponding to the second series
    1353 if isempty(get(handles.TimeName,'String'))% open the xml file corresponding to the secodn file series
    1354     [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes_1(handles);
    1355 else
    1356    [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles);
    1357 end
    1358 option=get(handles.view_xml,'String');
    1359 if isequal(option,'view .xml')     
    1360     FileXml=fullfile(RootPath,[SubDir '.xml']);
    1361     if ~exist(FileXml,'file')% case of civ files , removes the extension for subdir
    1362         FileXml=fullfile(RootPath,[regexprep(SubDir,'\..+$','') '.xml']);
    1363     end
    1364     heditxml=editxml(FileXml);
    1365 end
    1366 
    1367 %------------------------------------------------------------------------
    1368 % --- Executes on button press in CheckMask.
    1369 function CheckMask_Callback(hObject, eventdata, handles)
    1370 %------------------------------------------------------------------------
    1371 %case of view mask selection
    1372 if isequal(get(handles.CheckMask,'Value'),1)
    1373     [RootPath,SubDir]=read_file_boxes(handles);
    1374     MaskSubDir=regexprep(SubDir,'\..*','');%take the root part of SubDir, before the first dot '.'
    1375     MaskPath=fullfile(RootPath,[MaskSubDir '.mask']);
    1376     mdetect=0;
    1377     if exist(MaskPath,'dir')
    1378         ListStruct=dir(MaskPath);%look for a mask file
    1379         ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray
    1380         check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files
    1381         ListFiles=ListCells(1,:);%list of file and dri names
    1382         ListFiles=ListFiles(~check_dir);%list of file names (excluding dir)
    1383         if ~isempty(ListFiles)
    1384             for ifile=1:numel(ListFiles)
    1385                 [tild,tild,MaskExt]=fileparts(ListFiles{1});
    1386                 [tild,tild,MaskFile{ifile},i1_series,i2_series,j1_series,j2_series,MaskNomType,MaskFileInfo]=find_file_series(MaskPath,ListFiles{ifile},0);
    1387                 MaskFileType=MaskFileInfo.FileType;
    1388                 if strcmp(MaskFileType,'image') && isempty(i2_series) && isempty(j2_series)
    1389                     mdetect=1;
    1390                 end
    1391                 if ~strcmp(MaskFile{ifile},MaskFile{1})
    1392                     mdetect=0;% cancel detection test in case of multiple masks, use the brower for selection
    1393                     break
    1394                 end
    1395             end
    1396         end
    1397         RootPath=MaskPath;
    1398     end
    1399     if mdetect==0
    1400         MaskFullName=uigetfile_uvmat('pick a mask image file:',RootPath,'image');
    1401         if isempty(MaskFullName)
    1402             set(handles.CheckMask,'Value',0)
    1403         end
    1404         [MaskPath,MaskName,MaskExt]=fileparts(MaskFullName);
    1405         [tild,tild,MaskFile,i1_series,i2_series,j1_series,j2_series,MaskNomType]=find_file_series(MaskPath,[MaskName MaskExt],0);
    1406         if ~(isempty(i2_series) && isempty(j2_series))
    1407             MaskNomType='*';
    1408         end
    1409     end
    1410     Mask.Path=MaskPath;
    1411     if isempty(MaskFile)
    1412         Mask.File='';
    1413     elseif ischar(MaskFile)
    1414         Mask.File=MaskFile;
    1415     else
    1416         Mask.File=MaskFile{1};
    1417     end
    1418     Mask.Ext=MaskExt;
    1419     Mask.NomType=MaskNomType;
    1420     set(handles.CheckMask,'UserData',Mask);
    1421     errormsg=update_mask(handles);
    1422 else % desactivate mask display
    1423     MaskData=get(handles.CheckMask,'UserData');
    1424     if isfield(MaskData,'maskhandle') && ishandle(MaskData.maskhandle)
    1425         delete(MaskData.maskhandle)
    1426     end
    1427     set(handles.CheckMask,'UserData',[])
    1428     UvData=get(handles.uvmat,'UserData');
    1429     if isfield(UvData,'MaskName')
    1430         UvData=rmfield(UvData,'MaskName');
    1431         set(handles.uvmat,'UserData',UvData)
    1432     end
    1433     set(handles.CheckMask,'BackgroundColor',[0.7 0.7 0.7])
    1434 end
    1435 
    1436 %------------------------------------------------------------------------
    1437 function errormsg=update_mask(handles)
    1438 %------------------------------------------------------------------------
    1439 errormsg=[];%default
    1440 Mask=get(handles.CheckMask,'UserData');
    1441 MaskIndex=1;
    1442 if strcmp(get(handles.z_index,'Visible'),'on')
    1443     MaskIndex=str2num(get(handles.z_index,'String'));
    1444 end
    1445 if isfield(Mask,'maskhandle')&& ishandle(Mask.maskhandle)
    1446     uistack(Mask.maskhandle,'top');
    1447 end
    1448 MaskName=fullfile_uvmat(Mask.Path,'',Mask.File,Mask.Ext,Mask.NomType,MaskIndex);
    1449 UvData=get(handles.uvmat,'UserData');
    1450 
    1451 %% update mask image if the mask is new
    1452 if ~ (isfield(UvData,'MaskName') && isequal(UvData.MaskName,MaskName))
    1453     UvData.MaskName=MaskName; %update the recorded name on UvData
    1454     set(handles.uvmat,'UserData',UvData);
    1455     if ~exist(MaskName,'file')
    1456         if isfield(Mask,'maskhandle')&& ishandle(Mask.maskhandle)
    1457             delete(Mask.maskhandle)   
    1458         end
    1459     else
    1460         %read mask image
    1461         [MaskField,tild,errormsg] = read_field(MaskName,'image');
    1462         if ~isempty(errormsg)
    1463             return
    1464         end
    1465         npxy=size(MaskField.A);
    1466         if length(npxy)>2
    1467             errormsg=[MaskName ' is not a grey scale image'];
    1468             return
    1469         elseif ~isa(MaskField.A,'uint8')
    1470             errormsg=[MaskName ' is not a 8 bit grey level image'];
    1471             return
    1472         end
    1473         MaskField.ZIndex=MaskIndex;
    1474         %px to phys or other transform on field
    1475          menu_transform=get(handles.TransformName,'String');
    1476         choice_value=get(handles.TransformName,'Value');
    1477         transform_name=menu_transform{choice_value};%name of the transform fct  given by the menu 'transform_fct'
    1478         transform=get(handles.TransformPath,'UserData');
    1479         if  ~isequal(transform_name,'') && ~isequal(transform_name,'px')
    1480             if isfield(UvData,'XmlData') && isfield(UvData.XmlData{1},'GeometryCalib')%use geometry calib recorded from the ImaDoc xml file as first priority
    1481                 Calib=UvData.XmlData{1}.GeometryCalib;
    1482                 MaskField=transform(MaskField,UvData.XmlData{1});
    1483             end
    1484         end
    1485         flagmask=MaskField.A < 200;
    1486        
    1487         %make brown color image
    1488         imflag(:,:,1)=0.9*flagmask;
    1489         imflag(:,:,2)=0.7*flagmask;
    1490         imflag(:,:,3)=zeros(size(flagmask));
    1491        
    1492         %update mask image
    1493         hmask=[]; %default
    1494         if isfield(Mask,'maskhandle')&& ishandle(Mask.maskhandle)
    1495             hmask=Mask.maskhandle;
    1496         end
    1497         if ~isempty(hmask)
    1498             set(hmask,'CData',imflag)   
    1499             set(hmask,'AlphaData',flagmask*0.6)
    1500             set(hmask,'XData',MaskField.Coord_x);
    1501             set(hmask,'YData',MaskField.Coord_y);
    1502 %             uistack(hmask,'top')
    1503         else
    1504             axes(handles.PlotAxes)
    1505             hold on   
    1506             Mask.maskhandle=image(MaskField.Coord_x,MaskField.Coord_y,imflag,'Tag','mask','HitTest','off','AlphaData',0.6*ones(size(flagmask)));
    1507             set(handles.CheckMask,'UserData',Mask)
    1508         end
    1509     end
    1510 end
    1511 
    1512 %------------------------------------------------------------------------
    1513 %------------------------------------------------------------------------
    1514 % III - MAIN InputFileREFRESH FUNCTIONS : 'FRAME PLOT'
    1515 %------------------------------------------------------------------------
    1516 
    1517 %------------------------------------------------------------------------
    1518 % --- Executes on button press in runplus: make one step forward and call
    1519 % --- InputFileREFRESH. The step forward is along the fieldname series 1 or 2 depending on
    1520 % --- the scan_i and scan_j check box (exclusive each other)
    1521 function runplus_Callback(hObject, eventdata, handles)
    1522 %------------------------------------------------------------------------
    1523 
    1524 set(handles.runplus,'BackgroundColor',[1 1 0])%paint the command button in yellow
    1525 drawnow
    1526 increment=str2double(get(handles.num_IndexIncrement,'String')); %get the field increment d
    1527 if isnan(increment)% case of free increment: move to next available field index
    1528     increment='+';
    1529 end
    1530 errormsg=runpm(hObject,eventdata,handles,increment);
    1531 if ~isempty(errormsg)
    1532     msgbox_uvmat('ERROR',errormsg);
    1533 end
    1534 
    1535 %------------------------------------------------------------------------
    1536 % --- Executes on button press in runmin: make one step backward and call
    1537 % --- InputFileREFRESH. The step backward is along the fieldname series 1 or 2 depending on
    1538 % --- the scan_i and scan_j check box (exclusive each other)
    1539 function runmin_Callback(hObject, eventdata, handles)
    1540 %------------------------------------------------------------------------
    1541 
    1542 set(handles.runmin,'BackgroundColor',[1 1 0])%paint the command button in yellow
    1543 drawnow
    1544 increment=-str2double(get(handles.num_IndexIncrement,'String')); %get the field increment d
    1545 if isnan(increment)% case of free increment: move to previous available field index
    1546     increment='-';
    1547 end
    1548 errormsg=runpm(hObject,eventdata,handles,increment);
    1549 if ~isempty(errormsg)
    1550     msgbox_uvmat('ERROR',errormsg);
    1551 end
    1552 
    1553 %------------------------------------------------------------------------
    1554 % -- Executes on button press in Movie: make a series of +> steps
    1555 function Movie_Callback(hObject, eventdata, handles)
    1556 %------------------------------------------------------------------------
    1557 
    1558 set(handles.Movie,'BackgroundColor',[1 1 0])%paint the command button in yellow
    1559 drawnow
    1560 increment=str2double(get(handles.num_IndexIncrement,'String')); %get the field increment d
    1561 if isnan(increment)% case of free increment: move to next available field index
    1562     increment='+';
    1563 end
    1564 set(handles.STOP,'Visible','on')
    1565 set(handles.speed,'Visible','on')
    1566 set(handles.speed_txt,'Visible','on')
    1567 set(handles.Movie,'BusyAction','queue')
    1568 UvData=get(handles.uvmat,'UserData');
    1569 
    1570 while get(handles.Movie,'Value')==1 && get(handles.speed,'Value')~=0 && isequal(get(handles.Movie,'BusyAction'),'queue') % enable STOP command
    1571         errormsg=runpm(hObject,eventdata,handles,increment);
    1572         if ~isempty(errormsg)
    1573             set(handles.Movie,'BackgroundColor',[1 0 0])%paint the command buttonback to red
    1574             return
    1575         end
    1576         pause(1.02-get(handles.speed,'Value'))% wait for next image
    1577 end
    1578 if isfield(UvData,'aviobj') && ~isempty( UvData.aviobj),
    1579     UvData.aviobj=close(UvData.aviobj);
    1580    set(handles.uvmat,'UserData',UvData);
    1581 end
    1582 set(handles.Movie,'BackgroundColor',[1 0 0])%paint the command buttonback to red
    1583 
    1584 %------------------------------------------------------------------------
    1585 % -- Executes on button press in Movie: make a series of <- steps
    1586 function MovieBackward_Callback(hObject, eventdata, handles)
    1587 %------------------------------------------------------------------------
    1588 set(handles.MovieBackward,'BackgroundColor',[1 1 0])%paint the command button in yellow
    1589 drawnow
    1590 increment=-str2double(get(handles.num_IndexIncrement,'String')); %get the field increment d
    1591 if isnan(increment)% case of free increment: move to next available field index
    1592     increment='-';
    1593 end
    1594 set(handles.STOP,'Visible','on')
    1595 set(handles.speed,'Visible','on')
    1596 set(handles.speed_txt,'Visible','on')
    1597 set(handles.MovieBackward,'BusyAction','queue')
    1598 UvData=get(handles.uvmat,'UserData');
    1599 
    1600 while get(handles.MovieBackward,'Value')==1 && get(handles.speed,'Value')~=0 && isequal(get(handles.MovieBackward,'BusyAction'),'queue') % enable STOP command
    1601         errormsg=runpm(hObject,eventdata,handles,increment);
    1602         if ~isempty(errormsg)
    1603             set(handles.MovieBackward,'BackgroundColor',[1 0 0])%paint the command buttonback to red
    1604             return
    1605         end
    1606         pause(1.02-get(handles.speed,'Value'))% wait for next image
    1607 end
    1608 if isfield(UvData,'aviobj') && ~isempty( UvData.aviobj),
    1609     UvData.aviobj=close(UvData.aviobj);
    1610    set(handles.uvmat,'UserData',UvData);
    1611 end
    1612 set(handles.MovieBackward,'BackgroundColor',[1 0 0])%paint the command buttonback to red
    1613 
    1614 %------------------------------------------------------------------------
    1615 function STOP_Callback(hObject, eventdata, handles)
    1616 %------------------------------------------------------------------------
    1617 set(handles.movie_pair,'BusyAction','Cancel')
    1618 set(handles.movie_pair,'value',0)
    1619 set(handles.Movie,'BusyAction','Cancel')
    1620 set(handles.MovieBackward,'BusyAction','Cancel')
    1621 set(handles.MenuExportMovie,'BusyAction','Cancel')
    1622 %set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command buttonback to red
    1623 set(handles.Movie,'BackgroundColor',[1 0 0])%paint the command buttonback to red
    1624 set(handles.MovieBackward,'BackgroundColor',[1 0 0])%paint the command buttonback to red
    1625 
    1626 %------------------------------------------------------------------------
    1627 % --- function activated by runplus and run minus
    1628 function errormsg=runpm(hObject,eventdata,handles,increment)
    1629 %------------------------------------------------------------------------
    1630 errormsg='';%default
    1631 %% check for movie pair status
    1632 movie_status=get(handles.movie_pair,'Value');
    1633 if movie_status
    1634     STOP_Callback(hObject, eventdata, handles)%interrupt movie pair if active
    1635 end
    1636 
    1637 %% read the current input file name(s) and field indices
    1638 InputFile=read_GUI(handles.InputFile);
    1639 InputFile.RootFile=regexprep(InputFile.RootFile,'^[\\/]|[\\/]$','');%suppress possible / or \ separator at the beginning or the end of the string
    1640 InputFile.SubDir=regexprep(InputFile.SubDir,'^[\\/]|[\\/]$','');%suppress possible / or \ separator at the beginning or the end of the string
    1641 FileExt=InputFile.FileExt;
    1642 NomType=InputFile.NomType;
    1643 [tild,tild,tild,i1,i2,j1,j2]=fileparts_uvmat(InputFile.FileIndex);% check back the indices used
    1644 if isempty(i1)
    1645     i1=str2num(get(handles.i1,'String'));%read the field indices (for movie, it is not given by the file name)
    1646 elseif isempty(j1) && strcmp(get(handles.j1,'Visible'),'on')
    1647     j1=str2num(get(handles.j1,'String'));%case of indexed movie
    1648 end
    1649 if movie_status% we read the second index from the edit box
    1650     i2=str2num(get(handles.i2,'String'));%read the field indices (for movie, it is not given by the file name)
    1651     if strcmp(get(handles.j2,'Visible'),'on')
    1652     j2=str2num(get(handles.j2,'String'));%
    1653     end
    1654 end
    1655 sub_value= get(handles.SubField,'Value');
    1656 if sub_value % a second input file has been entered
    1657     [InputFile.RootPath_1,InputFile.SubDir_1,InputFile.RootFile_1,InputFile.FileIndex_1,InputFile.FileExt_1,InputFile.NomType_1]=read_file_boxes_1(handles);
    1658     [tild,tild,tild,i1_1,i2_1,j1_1,j2_1]=fileparts_uvmat(InputFile.FileIndex_1);% the indices for the second series taken from FileIndex_1
    1659     if isempty(i1_1)
    1660         i1_1=str2num(get(handles.i1,'String'));%read the field indices (for movie, it is not given by the file name)
    1661     elseif isempty(j1_1) && strcmp(get(handles.j1,'Visible'),'on')
    1662         j1_1=str2num(get(handles.j1,'String'));%case of indexed movie
    1663     end
    1664 else
    1665     filename_1=[];
    1666 end
    1667 
    1668 %% increment (or decrement) the field indices and update the input filename(s)
    1669 if ~isnumeric(increment)% undefined increment value
    1670     set(handles.CheckFixPair,'Value',0)
    1671 end
    1672 CheckFixPair=get(handles.CheckFixPair,'Value')||(isempty(i2)&&isempty(j2));
    1673 
    1674 % the pair i1-i2 or j1-j2 is imposed (check box CheckFixPair selected)
    1675 if CheckFixPair && isnumeric(increment)
    1676     if get(handles.scan_i,'Value')==1% case of scanning along index i
    1677         i1=i1+increment;
    1678         i2=i2+increment;
    1679         if sub_value
    1680             i1_1=i1_1+increment;
    1681             i2_1=i2_1+increment;
    1682         end
    1683     else % case of scanning along index j (burst numbers)
    1684         j1=j1+increment;
    1685         j2=j2+increment;
    1686         if sub_value
    1687             j1_1=j1_1+increment;
    1688             j2_1=j2_1+increment;
    1689         end
    1690     end
    1691    
    1692 % the pair i1-i2 or j1-j2 is free (check box CheckFixPair not selected): the list of existing indices recorded in UvData is used
    1693 else
    1694     UvData=get(handles.uvmat,'UserData');
    1695     ref_i=i1;
    1696     if ~isempty(i2)
    1697         ref_i=floor((i1+i2)/2);% current reference index i
    1698     end
    1699     ref_j=1;
    1700     if ~isempty(j1)
    1701         ref_j=j1;
    1702         if ~isempty(j2)
    1703             ref_j=floor((j1+j2)/2);% current reference index j
    1704         end
    1705     end
    1706     if isnumeric(increment)
    1707         if get(handles.scan_i,'Value')==1% case of scanning along index i
    1708             ref_i=ref_i+increment;% increment the current reference index i
    1709         else % case of scanning along index j (burst numbers)
    1710             ref_j=ref_j+increment;% increment the current reference index j if scan_j option is used
    1711         end
    1712     else % free increment
    1713        % runaction=get(gcbo,'tag');
    1714         if strcmp(increment,'+')% if runplus or movie is activated
    1715             step=1;
    1716         else
    1717             step=-1;
    1718         end
    1719         if get(handles.scan_i,'Value')==1% case of scanning along index i
    1720             ref_i=ref_i+step;
    1721             while ref_i>=0  && size(UvData.i1_series{1},3)>=ref_i+1 && UvData.i1_series{1}(1,ref_j+1,ref_i+1)==0
    1722                 ref_i=ref_i+step;
    1723             end
    1724         else % case of scanning along index j (burst numbers)
    1725             ref_j=ref_j+step;
    1726             while ref_j>=0  && size(UvData.i1_series{1},2)>=ref_j+1 && UvData.i1_series{1}(1,ref_j+1,ref_i+1)==0
    1727                 ref_j=ref_j+step;
    1728             end
    1729         end
    1730     end
    1731     if ref_i<0
    1732         errormsg='minimum i index reached';
    1733     elseif ref_j<0
    1734         errormsg='minimum j index reached';
    1735     elseif ref_i+1>size(UvData.i1_series{1},3)
    1736         errormsg='maximum i index reached (reload the input file to update the index bound)';
    1737     elseif ref_j+1>size(UvData.i1_series{1},2)
    1738         errormsg='maximum j index reached (reload the input file to update the index bound)';
    1739     end
    1740     if ~isempty(errormsg),return,end
    1741     siz=size(UvData.i1_series{1});
    1742     ref_indices=ref_i*siz(1)*siz(2)+ref_j*siz(1)+1:ref_i*siz(1)*siz(2)+(ref_j+1)*siz(1);
    1743     i1_subseries=UvData.i1_series{1}(ref_indices);
    1744     ref_indices=ref_indices(i1_subseries>0);
    1745     if isempty(ref_indices)% case of pairs (free index i)
    1746         ref_indices=ref_i*siz(1)*siz(2)+1:(ref_i+1)*siz(1)*siz(2);
    1747         i1_subseries=UvData.i1_series{1}(ref_indices);
    1748         ref_indices=ref_indices(i1_subseries>0);
    1749     end
    1750     if isempty(ref_indices),errormsg='no next frame: set num_IndexIncrement =''*'' to reach the next existing file';return
    1751     end
    1752     i1=UvData.i1_series{1}(ref_indices(end));
    1753     if ~isempty(UvData.i2_series{1})
    1754         i2=UvData.i2_series{1}(ref_indices(end));
    1755     end
    1756     if ~isempty(UvData.j1_series{1})
    1757         j1=UvData.j1_series{1}(ref_indices(end));
    1758     end
    1759     if ~isempty(UvData.j2_series{1})
    1760         j2=UvData.j2_series{1}(ref_indices(end));
    1761     end
    1762    
    1763     % case of a second file series
    1764     if sub_value
    1765         ref_i_1=i1_1;
    1766         if ~isempty(i2_1)
    1767             ref_i_1=floor((i1_1+i2_1)/2);% current reference index i
    1768         end
    1769         ref_j_1=1;
    1770         if ~isempty(j1_1)
    1771             ref_j_1=j1_1;
    1772             if ~isempty(j2_1)
    1773                 ref_j_1=floor((j1_1+j2_1)/2);% current reference index j
    1774             end
    1775         end
    1776         if isnumeric(increment)
    1777             if get(handles.scan_i,'Value')==1% case of scanning along index i
    1778                 ref_i_1=ref_i_1+increment;% increment the current reference index i
    1779             else % case of scanning along index j (burst numbers)
    1780                 ref_j_1=ref_j_1+increment;% increment the current reference index j if scan_j option is used
    1781             end
    1782         else % free increment, synchronise the ref indices with the first series
    1783             ref_i_1=ref_i;
    1784             ref_j_1=ref_j;
    1785         end
    1786         if numel(UvData.i1_series)==1
    1787             UvData.i1_series{2}=UvData.i1_series{1};
    1788             UvData.j1_series{2}=UvData.j1_series{1};
    1789             UvData.i2_series{2}=UvData.i2_series{1};
    1790             UvData.j2_series{2}=UvData.j2_series{1};
    1791         end
    1792         if ref_i_1<0
    1793             errormsg='minimum i index reached';
    1794         elseif ref_j_1<0
    1795             errormsg='minimum j index reached';
    1796         elseif ref_i_1+1>size(UvData.i1_series{2},3)
    1797             errormsg='maximum i index reached for the second series (reload the input file to update the index bound)';
    1798         elseif ref_j_1+1>size(UvData.i1_series{2},2)
    1799             errormsg='maximum j index reached for the second series(reload the input file to update the index bound)';
    1800         end
    1801         if ~isempty(errormsg),return,end
    1802         siz=size(UvData.i1_series{2});
    1803         ref_indices=ref_i_1*siz(1)*siz(2)+ref_j_1*siz(1)+1:ref_i_1*siz(1)*siz(2)+(ref_j_1+1)*siz(1);
    1804         i1_subseries=UvData.i1_series{2}(ref_indices);
    1805         ref_indices=ref_indices(i1_subseries>0);
    1806         if isempty(ref_indices)% case of pairs (free index i)
    1807             ref_indices=ref_i_1*siz(1)*siz(2)+1:(ref_i_1+1)*siz(1)*siz(2);
    1808             i1_subseries=UvData.i1_series{2}(ref_indices);
    1809             ref_indices=ref_indices(i1_subseries>0);
    1810         end
    1811         i1_1=UvData.i1_series{2}(ref_indices(end));
    1812         if ~isempty(UvData.i2_series{2})
    1813             i2_1=UvData.i2_series{2}(ref_indices(end));
    1814         end
    1815         if ~isempty(UvData.j1_series{2})
    1816             j1_1=UvData.j1_series{2}(ref_indices(end));
    1817         end
    1818         if ~isempty(UvData.j2_series{2})
    1819             j2_1=UvData.j2_series{1}(ref_indices(end));
    1820         end
    1821     else% the second series (if needed) is the same file as the first
    1822         i1_1=i1;
    1823         i2_1=i2;
    1824         j1_1=j1;
    1825         j2_1=j2;
    1826     end
    1827 end
    1828 filename=fullfile_uvmat(InputFile.RootPath,InputFile.SubDir,InputFile.RootFile,FileExt,NomType,i1,i2,j1,j2);
    1829 
    1830 %% refresh plots
    1831 if sub_value
    1832     filename_1=fullfile_uvmat(InputFile.RootPath_1,InputFile.SubDir_1,InputFile.RootFile_1,InputFile.FileExt_1,InputFile.NomType_1,i1_1,i2_1,j1_1,j2_1);
    1833     errormsg=refresh_field(handles,filename,filename_1,i1,i2,j1,j2,i1_1,i2_1,j1_1,j2_1);
    1834 else
    1835     errormsg=refresh_field(handles,filename,filename_1,i1,i2,j1,j2);
    1836 end
    1837 set(handles.InputFileREFRESH,'BackgroundColor',[1 0 0])
    1838 set(handles.runplus,'BackgroundColor',[1 0 0])
    1839 set(handles.runmin,'BackgroundColor',[1 0 0])
    1840 
    1841 %% update the index counters if the index move is successfull
    1842 
    1843 if isempty(errormsg)
    1844     set(handles.i1,'String',num2stra(i1,NomType,1));
    1845     if isequal(i2,i1)
    1846         set(handles.i2,'String','');
    1847     else
    1848         set(handles.i2,'String',num2stra(i2,NomType,1));
    1849     end
    1850     set(handles.j1,'String',num2stra(j1,NomType,2));
    1851     if isequal(j2,j1)
    1852         set(handles.j2,'String','');
    1853     else
    1854         set(handles.j2,'String',num2stra(j2,NomType,2));
    1855     end
    1856     indices=fullfile_uvmat('','','','',NomType,i1,i2,j1,j2);
    1857     set(handles.FileIndex,'String',indices);
    1858     if ~isempty(filename_1)
    1859         indices_1=fullfile_uvmat('','','','',InputFile.NomType_1,i1_1,i2_1,j1_1,j2_1);
    1860         set(handles.FileIndex_1,'String',indices_1);
    1861     end
    1862     if isequal(movie_status,1)
    1863         set(handles.movie_pair,'Value',1)
    1864         movie_pair_Callback(hObject, eventdata, handles); %reactivate moviepair if it was activated
    1865     else
    1866         if isempty(i2), set(handles.i2,'String',''); end % suppress the second index display if not used
    1867         if isempty(j2), set(handles.j2,'String',''); end
    1868     end
    1869 end
    1870 
    1871 %------------------------------------------------------------------------
    1872 % --- Executes on button press in movie_pair: create an alternating movie with two view
    1873 function movie_pair_Callback(hObject, eventdata, handles)
    1874 %------------------------------------------------------------------------
    1875 
    1876 %% stop movie action if the movie_pair button is off
    1877 if ~get(handles.movie_pair,'value')
    1878     set(handles.movie_pair,'BusyAction','Cancel')%stop movie pair if button is 'off'
    1879     set(handles.i2,'String','')% the second i index display is suppressed
    1880     set(handles.j2,'String','')% the second j index display is suppressed
    1881     set(handles.Dt_txt,'String','')% the time interval indication is suppressed
    1882     return
    1883 end
    1884    
    1885 %% check the input file indexing:
    1886 [RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles);
    1887 NomType=get(handles.NomType,'String');
    1888 if ~isempty(find(regexp(NomType,'-')))
    1889     msgbox_uvmat('ERROR','The movie pair requires file series with a single index on the first input line')
    1890     return
    1891 end
    1892 filename=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt];% build the input file name (first line)
    1893 
    1894 set(handles.movie_pair,'BusyAction','queue')%
    1895 set(handles.CheckFixPair,'Value',1)% impose fixed pair (needed for function runpm)
    1896 set(handles.REFRESH,'BackgroundColor',[1 1 0])%paint the command button in yellow to indicate its activity
    1897 set(handles.movie_pair,'BackgroundColor',[1 1 0])%paint the command button in yellow to indicate its activity
    1898 drawnow
    1899 % list_fields=get(handles.FieldName,'String');% list menu fields
    1900 % index_fields=get(handles.FieldName,'Value');% selected string index
    1901 % FieldName=list_fields{index_fields}; % selected field
    1902 
    1903 
    1904 % if isequal(FieldName,'image')
    1905 %     index=1;
    1906 
    1907 % else
    1908 %     list_fields=get(handles.FieldName_1,'String');% list menu fields
    1909 %     index_fields=get(handles.FieldName_1,'Value');% selected string index
    1910 %     FieldName=list_fields{index_fields}; % selected field
    1911 %     if isequal(FieldName,'image')
    1912 %         index=2;
    1913 %         [RootPath,SubDir,RootFile,FileIndex_1,Ext,NomType]=read_file_boxes_1(handles);% get info from the second input line
    1914 %     else
    1915 %         msgbox_uvmat('ERROR','an image or movie must be first introduced as input')
    1916 %         set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
    1917 %         set(handles.movie_pair,'Value',0)
    1918 %         return
    1919 %     end
    1920 % end
    1921 num_i1=str2num(get(handles.i1,'String'));
    1922 num_j1=stra2num(get(handles.j1,'String'));
    1923 num_i2=str2num(get(handles.i2,'String'));
    1924 num_j2=stra2num(get(handles.j2,'String'));
    1925 
    1926 %% determine the name 'imaname_1' of the second file in the pair
    1927 imaname_1='';
    1928 if isempty(num_j2)% no second j index indicated
    1929     if isempty(num_i2)
    1930         if strcmp(get(handles.j2,'Visible'),'on') %if the j box is visible
    1931             imaname_1=fullfile_uvmat(RootPath,SubDir,RootFile,FileExt,NomType,num_i1,[],num_j1+1);
    1932         end
    1933         if exist(imaname_1,'file')
    1934             num_j2=num_j1+1;% look by default for the next j index as the second file
    1935             set(handles.j2,'String',num2stra(num_j2,NomType));
    1936         else
    1937             imaname_1=fullfile_uvmat(RootPath,SubDir,RootFile,FileExt,NomType,num_i1+1,[],num_j1);
    1938             if exist(imaname_1,'file')
    1939                 num_i2=num_i1+1;
    1940                 set(handles.i2,'String',num2str(num_i2));
    1941             else
    1942                 msgbox_uvmat('ERROR', 'a second image index i2 or j2 is needed to show the pair as a movie')
    1943                 set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
    1944                 set(handles.movie_pair,'Value',0)
    1945                 return
    1946             end
    1947         end
    1948     else
    1949         num_j2=num_j1;%repeat the index i1 by default
    1950     end
    1951 end
    1952 if isempty(num_i2)
    1953     num_i2=num_i1;%repeat the index i1 by default
    1954 end
    1955 if isempty(num_j1)
    1956     num_j1=1;
    1957 end
    1958 if isempty(num_j2)
    1959     num_j2=num_j1;%repeat the index i1 by default
    1960 end
    1961 imaname_1=fullfile_uvmat(RootPath,SubDir,RootFile,FileExt,NomType,num_i2,[],num_j2);
    1962 if strcmp(NomType,'*')
    1963     num_frame=num_i2;
    1964 else
    1965     num_frame=num_j2;
    1966 end
    1967 if ~exist(imaname_1,'file')
    1968       msgbox_uvmat('ERROR',['second input open (-)  ' imaname_1 ' not found']);
    1969       set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
    1970        set(handles.movie_pair,'Value',0)
    1971       return
    1972 end
    1973 
    1974 %% display the first field in the pair (including possibly a background field from second line input filename_1)
    1975 filename_1='';%default
    1976 FileIndex_1='';
    1977 if get(handles.SubField,'Value')
    1978     [RootPath_1,SubDir_1,RootFile_1,FileIndex_1,FileExt_1]=read_file_boxes_1(handles);
    1979     filename_1=[fullfile(RootPath_1,SubDir_1,RootFile_1) FileIndex_1 FileExt_1];
    1980 end
    1981 % num_i1=stra2num(get(handles.i1,'String'));
    1982 % num_i2=stra2num(get(handles.i2,'String'));
    1983 % num_j1=stra2num(get(handles.j1,'String'));
    1984 % num_j2=stra2num(get(handles.j2,'String'));
    1985 [tild,tild,tild,i1_1,i2_1,j1_1,j2_1]=fileparts_uvmat(FileIndex_1);% get the indices of the second series from the string FileIndex_1
    1986 if isempty(j1_1)% case of movies, the index is not given by file index
    1987     j1_1=num_j1;
    1988 end
    1989 
    1990 errormsg=refresh_field(handles,filename,filename_1,num_i1,num_i2,num_j1,num_j2,i1_1,i2_1,j1_1,j2_1);
    1991 
    1992 if isempty(errormsg)
    1993     set(handles.REFRESH,'BackgroundColor',[1 0 0])% set button color to red, update successfull
    1994 else
    1995      msgbox_uvmat('ERROR',errormsg);
    1996      set(handles.REFRESH,'BackgroundColor',[1 0 1])% keep button color magenta, input not succesfull
    1997 end
    1998 UvData=get(handles.uvmat,'UserData');
    1999 Field_a=UvData.Field;% movie on the field defined by the second input line
    2000 
    2001 %% display time interval for the image pair
    2002 if isfield(UvData,'XmlData')&&isfield(UvData.XmlData{1},'Time')...
    2003         && size(UvData.XmlData{1}.Time,1)>=num_i2+1 && size(UvData.XmlData{1}.Time,2)>=num_j2+1
    2004     dt=(UvData.XmlData{1}.Time(num_i2+1,num_j2+1)-UvData.XmlData{1}.Time(num_i1+1,num_j1+1));
    2005     if  isfield(UvData,'TimeUnit')
    2006         set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) '  m' UvData.TimeUnit] )
    2007     else
    2008         set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) '  10^(-3)'] )
    2009     end
    2010 else
    2011     set(handles.Dt_txt,'String','')
    2012 end
    2013 
    2014 %% read the second field
    2015 if isempty(UvData.MovieObject)
    2016     [Field_b,ParamOut,errormsg] = read_field(imaname_1,UvData.FileType{index},[],num_frame);
    2017 else
    2018     [Field_b,ParamOut,errormsg] = read_field(imaname_1,UvData.FileType{1},UvData.MovieObject{1},num_frame);
    2019 end
    2020 if ~isempty(errormsg)
    2021     msgbox_uvmat('ERROR',['Error in reading second image: ' errormsg])
    2022     return
    2023 end
    2024 
    2025 %% apply phys or other transform on the two input fields
    2026 transform=get(handles.TransformPath,'UserData');
    2027 if  ~isempty(transform)
    2028     if isfield(UvData,'XmlData') && ~isempty(UvData.XmlData) %use geometry calib recorded from the ImaDoc xml file as first priority
    2029         if nargin(transform)>=2
    2030             Field_b=transform(Field_b,UvData.XmlData{1});
    2031         else
    2032             Field_b=transform(Field_b);
    2033         end
    2034     end
    2035 end
    2036 
    2037 %% make movie until movie speed is set to 0 or STOP is activated
    2038 hima=findobj(handles.PlotAxes,'Tag','ima');% %handles.PlotAxes =main plotting window (A GENERALISER)
    2039 set(handles.STOP,'Visible','on')
    2040 set(handles.speed,'Visible','on')
    2041 set(handles.speed_txt,'Visible','on')
    2042 while get(handles.speed,'Value')~=0 && isequal(get(handles.movie_pair,'BusyAction'),'queue') % enable STOP command
    2043     % read and plot the series of images in non erase mode
    2044     set(hima,'CData',Field_b.A); %TODO: generalise to other kinds of fields
    2045     pause(1.02-get(handles.speed,'Value'));% wait for next image
    2046     set(hima,'CData',Field_a.A);
    2047     pause(1.02-get(handles.speed,'Value'));% wait for next image
    2048 end
    2049 set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
    2050 set(handles.movie_pair,'Value',0)
    2051 set(handles.Dt_txt,'String','')
    2052 
    2053 %------------------------------------------------------------------------
    2054 % --- Executes on button press in InputFileREFRESH.
    2055 function REFRESH_Callback(hObject, eventdata, handles)
    2056 %------------------------------------------------------------------------
    2057 set(handles.REFRESH,'BackgroundColor',[1 1 0])%paint the REFRESH button in yellow to indicate its activity
    2058 drawnow
    2059 [RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles);%read the features of the input file name (first line)
    2060 [tild,tild,tild,i1,i2,j1,j2]=fileparts_uvmat(FileIndex);% check back the indices used
    2061 if isempty(i2), set(handles.i2,'String',''); end % suppress the second i index display if not used
    2062 if isempty(j2), set(handles.j2,'String',''); end % suppress the second j index display if not used
    2063 filename=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt];% build the input file name (first line)
    2064 filename_1='';%default second file name
    2065 FileIndex_1='';
    2066 if get(handles.SubField,'Value')% if a second file is introduced
    2067     [RootPath_1,SubDir_1,RootFile_1,FileIndex_1,FileExt_1]=read_file_boxes_1(handles);%read the features of the input file name (second line)
    2068     filename_1=[fullfile(RootPath_1,SubDir_1,RootFile_1) FileIndex_1 FileExt_1]; %build the input file name (second line)
    2069 end
    2070 num_i1=stra2num(get(handles.i1,'String'));
    2071 num_i2=stra2num(get(handles.i2,'String'));
    2072 num_j1=stra2num(get(handles.j1,'String'));
    2073 num_j2=stra2num(get(handles.j2,'String'));
    2074 [tild,tild,tild,i1_1,i2_1,j1_1,j2_1]=fileparts_uvmat(FileIndex_1);% get the indices of the second series from the string FileIndex_1
    2075 if isempty(j1_1)% case of movies, the index is not given by file index
    2076     j1_1=num_j1;
    2077 end
    2078 % in case of movies the index is set by edit boxes i1 or j1 (case of movies indexed by index i)
    2079 errormsg=refresh_field(handles,filename,filename_1,num_i1,num_i2,num_j1,num_j2,i1_1,i2_1,j1_1,j2_1);
    2080 ResizeFcn(handles.uvmat,[],handles)
    2081 if isempty(errormsg)
    2082     set(handles.REFRESH,'BackgroundColor',[1 0 0])% set button color to red, update successfull
    2083 else
    2084      msgbox_uvmat('ERROR',errormsg);
    2085      set(handles.REFRESH,'BackgroundColor',[1 0 1])% keep button color magenta, input not succesfull
    2086 end
    2087 
    2088 %------------------------------------------------------------------------
    2089 % --- read the input files and inputfilerefresh all the plots, including projection.
    2090 % OUTPUT:
    2091 %  errormsg: error message char string  =[] by default
    2092 % INPUT:
    2093 % FileName: first input file (=[] in the absence of input file)
    2094 % FileName_1: second input file (=[] in the asbsence of second input file)
    2095 % num_i1,num_i2,num_j1,num_j2; frame indices
    2096 % i1_1,i2_1,j1_1,j2_1: frame indices for the second input file  (needed if FileName_1 is not empty)
    2097 %------------------------------------------------------------------------
    2098 function errormsg=refresh_field(handles,FileName,FileName_1,num_i1,num_i2,num_j1,num_j2,i1_1,i2_1,j1_1,j2_1)
    2099 %------------------------------------------------------------------------
    2100 
    2101 %% initialisation
    2102 pointer=get(handles.uvmat,'Pointer');
    2103 if strcmp(pointer,'watch')% reinitialise the mouse if stuck to 'watch'
    2104     set(handles.CheckZoom,'Value',0)
    2105     pointer='arrow';
    2106 end
    2107 set(handles.uvmat,'Pointer','watch')
    2108 drawnow
    2109 if ~exist('Field','var')
    2110     Field={};
    2111 end
    2112 UvData=get(handles.uvmat,'UserData');
    2113 if ishandle(handles.UVMAT_title) %remove title panel on uvmat
    2114     delete(handles.UVMAT_title)
    2115 end
    2116 
    2117 %% determine the main input file information for action
    2118 if ~exist(FileName,'file')
    2119     errormsg=['input file ' FileName ' does not exist'];
    2120     return
    2121 end
    2122 NomType=get(handles.NomType,'String');
    2123 NomType_1='';
    2124 if strcmp(get(handles.NomType_1,'Visible'),'on')
    2125     NomType_1=get(handles.NomType_1,'String');
    2126 end
    2127 %update the z position index
    2128 mode_slice=get(handles.slices,'String');
    2129 if strcmp(mode_slice,'volume')
    2130     z_index=num_j1;
    2131     set(handles.z_index,'String',num2str(z_index))
    2132 else
    2133     nbslice=str2num(get(handles.num_NbSlice,'String'));
    2134     z_index=mod(num_i1-1,nbslice)+1;
    2135     set(handles.z_index,'String',num2str(z_index))
    2136 end
    2137 % inputfilerefresh menu for save_mask if relevant
    2138 masknumber=get(handles.masklevel,'String');
    2139 if length(masknumber)>=z_index
    2140     set(handles.masklevel,'Value',z_index)
    2141 end
    2142 
    2143 %% test for need of tps
    2144 check_proj_tps=0;
    2145 if  (strcmp(UvData.FileType{1},'civdata')||strcmp(UvData.FileType{1},'civx'))
    2146     for iobj=1:numel(UvData.ProjObject)
    2147         if isfield(UvData.ProjObject{iobj},'ProjMode')&& strcmp(UvData.ProjObject{iobj}.ProjMode,'interp_tps')
    2148             check_proj_tps=1;
    2149             break
    2150         end
    2151     end
    2152 end
    2153 
    2154 %% read the first input field
    2155 ParamIn.ColorVar='';%default variable name for vector color
    2156 frame_index=1;%default
    2157 FieldName='';%default
    2158 VelType='';%default
    2159 switch UvData.FileType{1}
    2160     case {'civx','civdata','netcdf'};
    2161         list_fields=get(handles.FieldName,'String');% list menu fields
    2162         FieldName= list_fields{get(handles.FieldName,'Value')}; % selected field
    2163         if ~strcmp(FieldName,'get_field...')
    2164             if get(handles.FixVelType,'Value')
    2165                 VelTypeList=get(handles.VelType,'String');
    2166                 VelType=VelTypeList{get(handles.VelType,'Value')};
    2167             end
    2168         end
    2169         % case of input vector field, get the scalar used for vector color
    2170         if ~isempty(regexp(FieldName,'^vec('))
    2171             list_code=get(handles.ColorCode,'String');% list menu fields
    2172             index_code=get(handles.ColorCode,'Value');% selected string index
    2173             if  ~strcmp(list_code{index_code},'black') &&  ~strcmp(list_code{index_code},'white')
    2174                 list_code=get(handles.ColorScalar,'String');% list menu fields
    2175                 index_code=get(handles.ColorScalar,'Value');% selected string index
    2176                 ParamIn.ColorVar= list_code{index_code}; % selected field
    2177             end
    2178         end
    2179     case {'video','mmreader'}
    2180         ParamIn=UvData.MovieObject{1}; % movie object     
    2181         if strcmp(NomType,'*')
    2182             frame_index=num_i1;%frame index from a single movies or multimage
    2183         else
    2184             frame_index=num_j1;% frame index from a set of indexed movies
    2185         end
    2186     case 'multimage'
    2187         if ~strcmp(NomType,'*')
    2188             MaxIndex_j_cell=get(handles.MaxIndex_j,'String');
    2189             if num_j1>str2num(MaxIndex_j_cell{1})
    2190                 errormsg='specified frame index exceeds file content';
    2191                 return
    2192             else
    2193             frame_index=num_j1;%frame index for movies or multimage
    2194             end
    2195         else
    2196             MaxIndex_i_cell=get(handles.MaxIndex_i,'String');
    2197             if num_i1>str2num(MaxIndex_i_cell{1})
    2198                 errormsg='specified frame index exceeds file content';
    2199                 return
    2200             else
    2201             frame_index=num_i1;
    2202             end
    2203         end
    2204     case 'vol' %TODO: update
    2205         if isfield(UvData.XmlData,'Npy') && isfield(UvData.XmlData,'Npx')
    2206             ParamIn.Npy=UvData.XmlData.Npy;
    2207             ParamIn.Npx=UvData.XmlData.Npx;
    2208         else           
    2209             errormsg='Npx and Npy need to be defined in the xml file for volume images .vol';
    2210             return
    2211         end
    2212 end
    2213 if isstruct (ParamIn)
    2214     ParamIn.FieldName=FieldName;
    2215     ParamIn.VelType=VelType;
    2216     ParamIn.Coord_x=get(handles.Coord_x,'String');
    2217     ParamIn.Coord_y=get(handles.Coord_y,'String');
    2218     ParamIn.Coord_z=get(handles.Coord_z,'String');
    2219     TimeName=get(handles.TimeName,'String');
    2220     r=regexp(TimeName,'^(?<type>(dim:)|(var:))','names');%look for 'var:' or 'dim:' at the beginning of time name
    2221     if ~isempty(r)
    2222         frame_index=num_i1;%time index chosen by i1
    2223         if strcmp(r.type,'dim:')
    2224             ParamIn.TimeDimName=TimeName(5:end);
    2225         elseif strcmp(r.type,'var:')
    2226             ParamIn.TimeVarName=TimeName(5:end);
    2227         end
    2228     end
    2229 end
    2230 % check_tps = 0;         
    2231 % if strcmp(UvData.FileType{1},'civdata')&&~strcmp(ParamIn.FieldName,'velocity')&&~strcmp(ParamIn.FieldName,'get_field...')
    2232 %        check_tps=1;%tps needed to get the requested field
    2233 % end
    2234 [Field{1},ParamOut,errormsg] = read_field(FileName,UvData.FileType{1},ParamIn,frame_index);
    2235 if ~isempty(errormsg)
    2236     errormsg=['uvmat / refresh_field / read_field( ' FileName ') / ' errormsg];
    2237     return
    2238 end 
    2239 if isfield(ParamOut,'Npx')&& isfield(ParamOut,'Npy')
    2240     set(handles.num_Npx,'String',num2str(ParamOut.Npx));% display image size on the interface
    2241     set(handles.num_Npy,'String',num2str(ParamOut.Npy));
    2242 end
    2243 Field{1}.ZIndex=z_index; %used for multiplane 3D calibration
    2244 
    2245 %% choose and read a second field FileName_1 if defined
    2246 VelType_1=[];%default
    2247 FieldName_1=[];
    2248 ParamIn_1=[];
    2249 ParamOut_1=[];
    2250 frame_index_1=1;
    2251 if ~isempty(FileName_1)
    2252     if ~exist(FileName_1,'file')
    2253         errormsg=['second file ' FileName_1 ' does not exist'];
    2254         return
    2255     end
    2256     switch UvData.FileType{2}
    2257         case {'civx','civdata','netcdf'};
    2258             list_fields=get(handles.FieldName_1,'String');% list menu fields
    2259             if ischar(list_fields),list_fields={list_fields};end
    2260             FieldName_1= list_fields{get(handles.FieldName_1,'Value')}; % selected field
    2261             if ~strcmp(FieldName,'get_field...')
    2262                 if get(handles.FixVelType,'Value')
    2263                     VelTypeList=get(handles.VelType_1,'String');
    2264                     VelType_1=VelTypeList{get(handles.VelType_1,'Value')};% read the velocity type.
    2265                 end
    2266             end
    2267             if strcmp(FieldName_1,'velocity')&& strcmp(get(handles.ColorCode,'Visible'),'on')
    2268                 list_code=get(handles.ColorCode,'String');% list menu fields
    2269                 index_code=get(handles.ColorCode,'Value');% selected string index
    2270                 if  ~strcmp(list_code{index_code},'black') &&  ~strcmp(list_code{index_code},'white')
    2271                     list_code=get(handles.ColorScalar,'String');% list menu fields
    2272                     index_code=get(handles.ColorScalar,'Value');% selected string index
    2273                     ParamIn_1.ColorVar= list_code{index_code}; % selected field for vector color display                 
    2274                 end
    2275             end
    2276         case {'video','mmreader'}
    2277             ParamIn_1=UvData.MovieObject{2};
    2278             if ~strcmp(NomType_1,'*')
    2279                 frame_index_1=j1_1;%frame index for movies or multimage
    2280             else
    2281                 frame_index_1=i1_1;
    2282             end 
    2283          case 'multimage'
    2284             if strcmp(NomType_1,'*')%frame index for movies or multimage
    2285                 frame_index_1=i1_1;
    2286             else
    2287                 frame_index_1=j1_1;
    2288             end   
    2289         case 'vol' %TODO: update
    2290             if isfield(UvData.XmlData,'Npy') && isfield(UvData.XmlData,'Npx')
    2291                 ParamIn_1.Npy=UvData.XmlData.Npy;
    2292                 ParamIn_1.Npx=UvData.XmlData.Npx;
    2293             else
    2294                 errormsg='Npx and Npy need to be defined in the xml file for volume images .vol';
    2295                 return
    2296             end
    2297     end
    2298     if isequal(get(handles.NomType_1,'Visible'),'on')
    2299         NomType_1=get(handles.NomType_1,'String');
    2300     else
    2301         NomType_1=get(handles.NomType,'String');
    2302     end
    2303     test_keepdata_1=0;% test for keeping the previous stored data if the input files are unchanged
    2304     if ~isequal(NomType_1,'*')&& isfield(UvData,'FileName_1')
    2305            test_keepdata_1= strcmp(FileName_1,UvData.FileName_1) ;
    2306     end
    2307     if test_keepdata_1
    2308         Field{2}=UvData.Field_1;% keep the stored field
    2309         ParamOut_1=UvData.ParamOut_1;
    2310     else
    2311         if isempty(ParamIn_1) || isstruct(ParamIn_1)
    2312         ParamIn_1.FieldName=FieldName_1;
    2313         ParamIn_1.VelType=VelType_1;
    2314         ParamIn_1.Coord_x=get(handles.Coord_x,'String');
    2315         ParamIn_1.Coord_y=get(handles.Coord_y,'String');
    2316         end 
    2317         [Field{2},ParamOut_1,errormsg] = read_field(FileName_1,UvData.FileType{2},ParamIn_1,frame_index_1);
    2318         if ~isempty(errormsg)
    2319             errormsg=['error in reading ' FieldName_1 ' in ' FileName_1 ': ' errormsg];
    2320             return
    2321         end
    2322         if isstruct(ParamOut_1)&&~strcmp(ParamOut_1.FieldName,'get_field...')&& (strcmp(UvData.FileType{2},'civdata')||strcmp(UvData.FileType{2},'civx'))...
    2323                 &&~strcmp(ParamOut_1.FieldName,'velocity') && ~strcmp(ParamOut_1.FieldName,'get_field...')
    2324             if ~check_proj_tps
    2325             end
    2326         end
    2327     end
    2328     Field{2}.ZIndex=z_index;%used for multi-plane 3D calibration
    2329 end
    2330 
    2331 %% update uvmat interface
    2332 if isfield(ParamOut,'Npx')
    2333     set(handles.num_Npx,'String',num2str(ParamOut.Npx));% display image size on the interface
    2334     set(handles.num_Npy,'String',num2str(ParamOut.Npy));
    2335 elseif isfield(ParamOut_1,'Npx')
    2336     set(handles.num_Npx,'String',num2str(ParamOut_1.Npx));% display image size on the interface
    2337     set(handles.num_Npy,'String',num2str(ParamOut_1.Npy));
    2338 end
    2339 
    2340 %% update the display menu for the first velocity type (first menuline)
    2341 test_veltype=0;
    2342 if (strcmp(UvData.FileType{1},'civx')||strcmp(UvData.FileType{1},'civdata'))&& ~strcmp(FieldName,'get_field...')
    2343     test_veltype=1;
    2344     set(handles.VelType,'Visible','on')
    2345     set(handles.VelType_1,'Visible','on')
    2346     set(handles.FixVelType,'Visible','on')
    2347     menu=set_veltype_display(ParamOut.CivStage,UvData.FileType{1});
    2348     index_menu=strcmp(ParamOut.VelType,menu);%look for VelType in  the menu
    2349     index_val=find(index_menu,1);
    2350     if isempty(index_val)
    2351         index_val=1;
    2352     end
    2353     set(handles.VelType,'Value',index_val)
    2354     if ~get(handles.SubField,'value')
    2355         set(handles.VelType,'String',menu)
    2356         set(handles.VelType_1,'Value',1)
    2357         set(handles.VelType_1,'String',[{''};menu])
    2358     end
    2359 else
    2360     set(handles.VelType,'Visible','off')
    2361 end
    2362 
    2363 %% update the display menu for the second velocity type (second menuline)
    2364 test_veltype_1=0;
    2365 if isempty(FileName_1)
    2366 elseif ~test_keepdata_1
    2367     if (strcmp(UvData.FileType{2},'civx')||strcmp(UvData.FileType{2},'civdata'))&& ~strcmp(FieldName_1,'get_field...')
    2368         test_veltype_1=1;
    2369         set(handles.VelType_1,'Visible','on')
    2370         menu=set_veltype_display(ParamOut_1.CivStage,UvData.FileType{2});
    2371         index_menu=strcmp(ParamOut_1.VelType,menu);
    2372         set(handles.VelType_1,'Value',1+find(index_menu,1))
    2373         set(handles.VelType_1,'String',[{''};menu])
    2374     else
    2375          set(handles.VelType_1,'Visible','off')
    2376     end
    2377     % update the second field menu: the same quantity
    2378     if isstruct(ParamOut_1)
    2379         % display the FieldName menu from the input file and pick the selected one:
    2380         FieldList=get(handles.FieldName_1,'String');
    2381         field_index=strcmp(ParamOut_1.FieldName,FieldList);
    2382         if ~isempty(field_index)
    2383             set(handles.FieldName_1,'Value',find(field_index,1))
    2384         end
    2385     end
    2386 end
    2387 if test_veltype||test_veltype_1
    2388     set(handles.FixVelType,'Visible','on')
    2389 else
    2390     set(handles.FixVelType,'Visible','off')
    2391 end
    2392    
    2393 %% introduce w as background image by default for a new series (only for nbdim=2)
    2394 if ~isfield(UvData,'NewSeries')
    2395     UvData.NewSeries=1;
    2396 end
    2397 %put W as background image by default if NbDim=2:
    2398 if  UvData.NewSeries && isequal(get(handles.SubField,'Value'),0) && isfield(Field{1},'W') && ~isempty(Field{1}.W) && ~isequal(Field{1}.NbDim,3);
    2399         set(handles.SubField,'Value',1);
    2400         set(handles.RootPath_1,'String','"')
    2401         set(handles.RootFile_1,'String','"')
    2402         set(handles.SubDir_1,'String','"');
    2403          indices=fullfile_uvmat('','','','',NomType,num_i1,num_i2,num_j1,num_j2);
    2404         set(handles.FileIndex_1,'String',indices)
    2405         set(handles.FileExt_1,'String','"');
    2406         set(handles.FieldName_1,'Visible','on');
    2407         set(handles.FieldName_1,'Visible','on');
    2408         set(handles.RootPath_1,'Visible','on')
    2409         set(handles.RootFile_1,'Visible','on')
    2410         set(handles.SubDir_1,'Visible','on');
    2411         set(handles.FileIndex_1,'Visible','on');
    2412         set(handles.FileExt_1,'Visible','on');
    2413         set(handles.FieldName_1,'Visible','on');
    2414         Field{1}.AName='w';
    2415 end           
    2416 
    2417 %% display time value of the current file
    2418 abstime=[];%default inputs
    2419 dt=[];
    2420 TimeUnit='';
    2421 if isfield(UvData,'TimeUnit')
    2422     TimeUnit=UvData.TimeUnit;%retrieve info from update_rootinfo
    2423 end
    2424 TimeName=get(handles.TimeName,'String');
    2425 
    2426 % time from xml file or video movie
    2427 if strcmp(TimeName,'xml')||strcmp(TimeName,'video')
    2428     if isempty(num_i2)||isnan(num_i2)
    2429         num_i2=num_i1;
    2430     end
    2431     if isempty(num_j1)||isnan(num_j1)
    2432         num_j1=1;
    2433     end
    2434     if isempty(num_j2)||isnan(num_j2)
    2435         num_j2=num_j1;
    2436     end
    2437     siz=size(UvData.XmlData{1}.Time);
    2438     if ~isempty(num_i1)&& ~isempty(num_i2) && num_i1>=0 &&siz(1)>=max(num_i1+1,num_i2+1) && siz(2)>=max(num_j1+1,num_j2+1)
    2439         abstime=(UvData.XmlData{1}.Time(num_i1+1,num_j1+1)+UvData.XmlData{1}.Time(num_i2+1,num_j2+1))/2;%overset the time read from files
    2440         dt=(UvData.XmlData{1}.Time(num_i2+1,num_j2+1)-UvData.XmlData{1}.Time(num_i1+1,num_j1+1));
    2441         Field{1}.Dt=dt;
    2442         if isfield(UvData.XmlData{1},'TimeUnit')
    2443             TimeUnit=UvData.XmlData{1}.TimeUnit;
    2444         end
    2445     end
    2446 end
    2447 
    2448 % time in the input file, not defined in a xml file or movie
    2449 if isempty(abstime)
    2450     if strcmp(TimeName,'civdata')||strcmp(TimeName,'civx')
    2451         abstime=Field{1}.Time;
    2452     elseif ~isempty(regexp(TimeName,'^att:', 'once'))
    2453         abstime=Field{1}.(TimeName(5:end));%the time is an attribute  selected by get_file
    2454         if isfield(Field{1},[TimeName(5:end) 'Unit'])
    2455             TimeUnit=Field{1}.([TimeName(5:end) 'Unit']);
    2456         else
    2457             TimeUnit='';
    2458         end
    2459     elseif  ~isempty(regexp(TimeName,'^var:'))
    2460         abstime=Field{1}.(TimeName(5:end));%the time is a variale selected by get_file
    2461         % TODO: look for time unit attribute
    2462     elseif ~isempty(regexp(TimeName,'^dim:'))
    2463         abstime=str2num(get(handles.i1,'String'));
    2464         TimeUnit='index';
    2465     end
    2466     if isfield(Field{1},'Dt')
    2467         dt=Field{1}.Dt;%dt read from the netcdf input file
    2468     elseif numel(Field)==2 && isfield(Field{2},'Dt')%dt obtained from the second field if not defined in the first
    2469         dt=Field{2}.Dt;%dt read from the netcdf input file
    2470     end
    2471 end
    2472 set(handles.TimeValue,'String',num2str(abstime))
    2473 
    2474 %% display time value of the second current file if relevant
    2475 abstime_1=[];
    2476 if ~isempty(FileName_1)
    2477     TimeName_1=get(handles.TimeName_1,'String');% indicate whether time is from xml or video
    2478     % time from xml file or video movie as a second file series
    2479     if strcmp(TimeName_1,'xml')||strcmp(TimeName_1,'video')
    2480         if numel(UvData.XmlData)==2
    2481             if isempty(i2_1)
    2482                 i2_1=num_i1;
    2483             end
    2484             if isempty(j1_1)
    2485                 j1_1=1;
    2486             end
    2487             if isempty(j2_1)
    2488                 j2_1=j1_1;
    2489             end
    2490             siz=size(UvData.XmlData{2}.Time);
    2491             if ~isempty(i1_1) && siz(1)>=max(i1_1+1,i2_1+1) && siz(2)>=max(j1_1+1,j2_1+1)
    2492                 abstime_1=(UvData.XmlData{2}.Time(i1_1+1,j1_1+1)+UvData.XmlData{2}.Time(i2_1+1,j2_1+1))/2;%overset the time read from files
    2493                 Field{2}.Dt=(UvData.XmlData{2}.Time(i2_1+1,j2_1+1)-UvData.XmlData{2}.Time(i1_1+1,j1_1+1));
    2494             end
    2495         end
    2496     end
    2497    
    2498     % get time in the input file of the second series, not defined in a xml file or movie
    2499     if isempty(abstime_1) && numel(Field)==2
    2500          if strcmp(TimeName_1,'civdata')||strcmp(TimeName_1,'civx')
    2501         abstime_1=Field{2}.Time;
    2502          elseif  ~isempty(regexp(TimeName_1,'^att:')) ||~isempty(regexp(TimeName_1,'^dim:'))||~isempty(regexp(TimeName_1,'^var:'))
    2503         abstime_1=Field{2}.(TimeName_1(5:end));%the time is an attribute or variale selected by get_file
    2504          end
    2505     end
    2506     set(handles.TimeValue_1,'String',num2str(abstime_1,5))
    2507 end
    2508 
    2509 if isempty(dt)||isequal(dt,0)
    2510     set(handles.Dt_txt,'String','')
    2511 else
    2512     if  isempty(TimeUnit)
    2513         set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) '  10^(-3)'] )
    2514     else
    2515         set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) '  m' TimeUnit] )
    2516     end
    2517 end
    2518 
    2519 %% Time title with unit
    2520 if isempty(abstime)&&isempty(abstime_1)
    2521     Time_title='';
    2522 else
    2523     Time_title='Time';
    2524     if ~isempty(TimeUnit)
    2525         Time_title=['Time (' TimeUnit ')'];
    2526     end
    2527 end
    2528 set(handles.Time_title,'String',Time_title)
    2529 
    2530 %% store the current open names, fieldname and vel types in uvmat interface
    2531 UvData.FileName_1=FileName_1;
    2532 UvData.ParamOut_1=ParamOut_1;
    2533 if numel(Field)==2
    2534     UvData.Field_1=Field{2}; %store the second field for possible use at next RUN
    2535 end
    2536 
    2537 %% apply coordinate transform or other user fct
    2538 transform=get(handles.TransformPath,'UserData');
    2539 if isempty(transform)
    2540     UvData.Field=Field{1};
    2541 else
    2542     XmlData=[];%default
    2543     XmlData_1=[];%default
    2544     if isfield(UvData,'XmlData')%use geometry calib recorded from the ImaDoc xml file as first priority
    2545         XmlData=UvData.XmlData{1};
    2546         if numel(UvData.XmlData)==2
    2547             XmlData_1=UvData.XmlData{2};
    2548         end
    2549     end
    2550     switch nargin(transform)
    2551         case 4
    2552             if length(Field)==2
    2553                 UvData.Field=transform(Field{1},XmlData,Field{2},XmlData_1);
    2554             else
    2555                 UvData.Field=transform(Field{1},XmlData);
    2556             end
    2557         case 3
    2558             if length(Field)==2
    2559                 UvData.Field=transform(Field{1},XmlData,Field{2});
    2560             else
    2561                 UvData.Field=transform(Field{1},XmlData);
    2562             end
    2563         case 2
    2564             UvData.Field=transform(Field{1},XmlData);
    2565         case 1
    2566             UvData.Field=transform(Field{1});
    2567     end
    2568 end
    2569 
    2570 %% calculate tps coefficients if needed
    2571 UvData.Field=tps_coeff_field(UvData.Field,check_proj_tps);
    2572 
    2573 %% get bounds and dimensions of the input field
    2574 UvData.Field=find_field_bounds(UvData.Field);
    2575 
    2576 testnewseries=UvData.NewSeries;
    2577 UvData.NewSeries=0;% put to 0 the test for a new field series (set by RootPath_callback)
    2578 
    2579 %% reset the min and max of scalar if only the mask is displayed(TODO: check the need)
    2580 % if isfield(UvData,'Mask')&& ~isfield(UvData,'A')
    2581 %     set(handles.num_MinA,'String','0')
    2582 %     set(handles.num_MaxA,'String','255')
    2583 % end
    2584 
    2585 %% usual 1D (x,y) plots
    2586 if UvData.Field.NbDim<=1
    2587     set(handles.Objects,'Visible','off')
    2588     [PlotType,PlotParamOut]=plot_field(UvData.Field,handles.PlotAxes,read_GUI(handles.uvmat));
    2589     errormsg=fill_GUI(PlotParamOut,handles.uvmat);
    2590     for list={'Scalar','Vectors'}
    2591         if ~isfield(PlotParamOut,list{1})
    2592             set(handles.(list{1}),'Visible','off')
    2593         end
    2594     end
    2595     set(handles.uvmat,'UserData',UvData)
    2596 %% 2D or 3D fieldname are generally projected
    2597 else
    2598     set(handles.Objects,'Visible','on')
    2599    
    2600     %% Plot the projections on the selected  projection objects
    2601     %if no projection object exists, create a default one
    2602     if isempty(UvData.ProjObject{1})
    2603         set(handles.ListObject,'Value',1)
    2604         set(handles.ListObject,'String',{'plane'})
    2605         UvData.ProjObject{1}.Type='plane';%main plotting plane
    2606         UvData.ProjObject{1}.ProjMode='projection';%main plotting plane
    2607         UvData.ProjObject{1}.DisplayHandle.uvmat=[]; %plane not visible in uvmat
    2608         UvData.ProjObject{1}.DisplayHandle.view_field=[]; %plane not visible in uvmat
    2609         set(handles.ListObject_1,'Value',1)
    2610         set(handles.ListObject_1,'String',{'plane'})
    2611         if UvData.Field.NbDim==3 %3D case
    2612 %             ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider
    2613 %             ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider
    2614             UvData.ProjObject{1}.NbDim=3;%test for 3D objects
    2615             UvData.ProjObject{1}.RangeZ=UvData.Field.CoordMesh;%main plotting plane
    2616             UvData.ProjObject{1}.Coord(1,3)=(UvData.Field.ZMin+UvData.Field.ZMax)/2;%section at a middle plane chosen
    2617             UvData.ProjObject{1}.Angle=[0 0 0];
    2618         elseif isfield(UvData,'Z')
    2619             %multilevel case (single menuplane in a 3D space)
    2620             if isfield(UvData,'CoordType')&& isequal(UvData.CoordType,'phys') && isfield(UvData,'XmlData')
    2621                 XmlData=UvData.XmlData{1};
    2622                 if isfield(XmlData,'PlanePos')
    2623                     UvData.ProjObject{1}.Coord=XmlData.PlanePos(UvData.ZIndex,:);
    2624                 end
    2625                 if isfield(XmlData,'PlaneAngle')
    2626                     siz=size(XmlData.PlaneAngle);
    2627                     indangle=min(siz(1),UvData.ZIndex);%take first angle if a single angle is defined (translating scanning)
    2628                     UvData.ProjObject{1}.PlaneAngle=XmlData.PlaneAngle(indangle,:);
    2629                 end
    2630             elseif isfield(UvData,'ZIndex')
    2631                 UvData.ProjObject{1}.ZObject=UvData.ZIndex;
    2632             end
    2633         end
    2634     end
    2635     IndexObj=get(handles.ListObject_1,'Value');%selected projection object for main view
    2636     if IndexObj> numel(UvData.ProjObject)
    2637         IndexObj=1;%select the first object if the selected one does not exist
    2638         set(handles.ListObject_1,'Value',1)
    2639     end
    2640     if get(handles.CheckViewField,'Value')
    2641         IndexObj_2=get(handles.ListObject,'Value');%selected projection object for view_field
    2642         if ~isequal(IndexObj_2,IndexObj(1))
    2643             IndexObj(2)=IndexObj_2;
    2644         end
    2645     end
    2646     plot_handles{1}=handles;
    2647     if isfield(UvData,'plotaxes')%case of movies
    2648         haxes(1)=UvData.plotaxes;
    2649     else
    2650         haxes(1)=handles.PlotAxes;
    2651     end
    2652     PlotParam{1}=read_GUI(handles.uvmat);
    2653     %default settings if vectors not visible
    2654     if ~isfield(PlotParam{1},'Vectors')
    2655         PlotParam{1}.Vectors.MaxVec=1;
    2656         PlotParam{1}.Vectors.MinVec=0;
    2657         PlotParam{1}.Vectors.CheckFixVecColor=1;
    2658         PlotParam{1}.Vectors.ColCode1=0.33;
    2659         PlotParam{1}.Vectors.ColCode2=0.66;
    2660         PlotParam{1}.Vectors.ColorScalar={''};
    2661         PlotParam{1}.Vectors.ColorCode= {'rgb'};
    2662     end
    2663     %PosColorbar{1}=UvData.OpenParam.PosColorbar;%prescribe the colorbar position on the uvmat interface
    2664    
    2665     %% second projection object (view_field display)
    2666     if length( IndexObj)==2
    2667         view_field_handle=findobj(allchild(0),'tag','view_field');%handles of the view_field GUI
    2668         if ~isempty(view_field_handle)
    2669             plot_handles{2}=guidata(view_field_handle);
    2670             haxes(2)=plot_handles{2}.PlotAxes;
    2671             PlotParam{2}=read_GUI(view_field_handle);
    2672             %PosColorbar{2}='*'; %TODO: deal with colorbar position on view_field
    2673         end
    2674     end
    2675    
    2676     %% loop on the projection objects: one or two
    2677    
    2678     for imap=1:numel(IndexObj)
    2679         iobj=IndexObj(imap);
    2680         if numel(UvData.ProjObject)<iobj
    2681             break
    2682         end
    2683         if UvData.Field.NbDim==3
    2684             UvData.ProjObject{iobj}.NbDim=3;%test for 3D objects
    2685             if ~isfield(UvData.ProjObject{iobj},'RangeZ')
    2686             UvData.ProjObject{iobj}.RangeZ=UvData.Field.CoordMesh;%main plotting plane
    2687             end
    2688             if ~(isfield(UvData.ProjObject{iobj},'Coord') && UvData.ProjObject{iobj}.Coord(1,3)<UvData.Field.ZMax && UvData.ProjObject{iobj}.Coord(1,3)>UvData.Field.ZMin)
    2689                  UvData.ProjObject{iobj}.Coord(1,3)=(UvData.Field.ZMin+UvData.Field.ZMax)/2;%section at a middle plane chosen
    2690             end         
    2691         end
    2692         [ObjectData,errormsg]=proj_field(UvData.Field,UvData.ProjObject{iobj});% project field on the object
    2693         if ~isempty(errormsg)
    2694             return
    2695         end
    2696         if testnewseries
    2697             PlotParam{imap}.Scalar.CheckBW=[]; %B/W option depends on the input field (image or scalar)
    2698             if isfield(ObjectData,'CoordUnit')
    2699                 PlotParam{imap}.Axes.CheckFixAspectRatio=1;% set x and y scaling equal if CoordUnit is defined (common unit for x and y)
    2700                 PlotParam{imap}.Axes.AspectRatio=1; %set aspect ratio to 1
    2701             end
    2702         end
    2703         %use of mask (TODO: check)
    2704         if isfield(ObjectData,'NbDim') && isequal(ObjectData.NbDim,2) && isfield(ObjectData,'Mask') && isfield(ObjectData,'A')
    2705             flag_mask=double(ObjectData.Mask>200);%=0 for masked regions
    2706             Coord_x=ObjectData.Coord_x;%x coordiantes for the scalar field
    2707             Coord_y=ObjectData.Coord_y;%y coordinates for the scalar field
    2708             MaskX=ObjectData.MaskX;%x coordiantes for the mask
    2709             MaskY=ObjectData.MaskY;%y coordiantes for the mask
    2710             if ~isequal(MaskX,Coord_x)||~isequal(MaskY,Coord_y)
    2711                 nxy=size(flag_mask);
    2712                 sizpx=(ObjectData.MaskX(end)-ObjectData.MaskX(1))/(nxy(2)-1);%size of a mask pixel
    2713                 sizpy=(ObjectData.MaskY(1)-ObjectData.MaskY(end))/(nxy(1)-1);
    2714                 x_mask=ObjectData.MaskX(1):sizpx:ObjectData.MaskX(end); % pixel x coordinates for image display
    2715                 y_mask=ObjectData.MaskY(1):-sizpy:ObjectData.MaskY(end);% pixel x coordinates for image display
    2716                 %project on the positions of the scalar
    2717                 npxy=size(ObjectData.A);
    2718                 dxy(1)=(ObjectData.Coord_y(end)-ObjectData.Coord_y(1))/(npxy(1)-1);%grid mesh in y
    2719                 dxy(2)=(ObjectData.Coord_x(end)-ObjectData.Coord_x(1))/(npxy(2)-1);%grid mesh in x
    2720                 xi=ObjectData.Coord_x(1):dxy(2):ObjectData.Coord_x(end);
    2721                 yi=ObjectData.Coord_y(1):dxy(1):ObjectData.Coord_y(end);
    2722                 [XI,YI]=meshgrid(xi,yi);% creates the matrix of regular coordinates
    2723                 flag_mask = interp2(x_mask,y_mask,flag_mask,XI,YI);
    2724             end
    2725             AClass=class(ObjectData.A);
    2726             ObjectData.A=flag_mask.*double(ObjectData.A);
    2727             ObjectData.A=feval(AClass,ObjectData.A);
    2728         end       
    2729         set(handles.uvmat,'UserData',UvData)
    2730         if ~isempty(ObjectData)
    2731             %PlotType='none'; %default
    2732             if imap==2 && isempty(view_field_handle)
    2733                 view_field(ObjectData)
    2734             else
    2735                 [PlotType,PlotParamOut]=plot_field(ObjectData,haxes(imap),PlotParam{imap});
    2736                 if imap==1
    2737                     errormsg=fill_GUI(PlotParamOut,handles.uvmat);
    2738                 else
    2739                     errormsg=fill_GUI(PlotParamOut,view_field_handle);
    2740                 end
    2741                 for list={'Scalar','Vectors'}
    2742                     if ~isfield(PlotParamOut,list{1})
    2743                         set(plot_handles{imap}.(list{1}),'Visible','off')
    2744                     end
    2745                 end
    2746                 if isfield(Field,'CoordMesh')&&~isempty(Field.CoordMesh)
    2747                     ObjectData.CoordMesh=Field.CoordMesh; % gives an estimated mesh size (useful for mouse action on the plot)
    2748                 end
    2749             end
    2750         end
    2751     end
    2752    
    2753     %% update the mask
    2754     if isequal(get(handles.CheckMask,'Value'),1)%if the mask option is on
    2755         update_mask(handles);
    2756     end
    2757    
    2758     %% prepare the menus of histograms and plot them (histogram of the whole volume in 3D case)
    2759     menu_histo=(UvData.Field.ListVarName)';%list of field variables to be displayed for the menu of histogram display
    2760     ind_skip=[];
    2761     % nb_histo=1;
    2762     Ustring='';
    2763     Vstring='';
    2764     % suppress axes from the histogram menu
    2765     for ivar=1:numel(menu_histo)%l loop on field variables:
    2766         if isfield(UvData.Field,'VarAttribute') && numel(UvData.Field.VarAttribute)>=ivar && isfield(UvData.Field.VarAttribute{ivar},'Role')
    2767             Role=UvData.Field.VarAttribute{ivar}.Role;
    2768             switch Role
    2769                 case {'coord_x','coord_y','coord_z','dimvar'}
    2770                     ind_skip=[ind_skip ivar];
    2771                 case {'vector_x'}
    2772                     Ustring=UvData.Field.ListVarName{ivar};
    2773                     ind_skip=[ind_skip ivar];
    2774                 case {'vector_y'}
    2775                     Vstring=UvData.Field.ListVarName{ivar};
    2776                     ind_skip=[ind_skip ivar];
    2777             end
    2778         end
    2779         DimCell=UvData.Field.VarDimName{ivar};
    2780         DimName='';
    2781         if ischar(DimCell)
    2782             DimName=DimCell;
    2783         elseif iscell(DimCell)&& numel(DimCell)==1
    2784             DimName=DimCell{1};
    2785         end
    2786         if strcmp(DimName,menu_histo{ivar})
    2787             ind_skip=[ind_skip ivar];
    2788         end
    2789     end
    2790     menu_histo(ind_skip)=[];% remove skipped items
    2791     if ~isempty(Ustring)
    2792         menu_histo=[{[Ustring ',' Vstring]};menu_histo];% add U, V at the beginning if they exist
    2793     end
    2794    
    2795     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    2796     % display menus and plot histograms
    2797     test_v=0;
    2798     if ~isempty(menu_histo)
    2799         set(handles.histo1_menu,'Value',1)
    2800         set(handles.histo1_menu,'String',menu_histo)
    2801         histo1_menu_Callback(handles.histo1_menu, [], handles)% plot first histogram
    2802     end
    2803 end
    2804 
    2805 if UvData.Field.NbDim==3
    2806     set(handles.CheckEditObject,'Value',1)
    2807     CheckEditObject_Callback(handles.uvmat, [], handles)
    2808 end   
    2809 %ResizeFcn(handles.uvmat,[],handles)
    2810 set(handles.uvmat,'Pointer',pointer)
    2811 
    2812 %------------------------------------------------------------------------
    2813 function histo1_menu_Callback(hObject, eventdata, handles)
    2814 %--------------------------------------------
    2815 %% get the current field stored in uvmat user data
    2816 UvData=get(handles.uvmat,'UserData');
    2817 Field=UvData.Field;
    2818 
    2819 %% get from the menu 'histo1_menu' the name(s) of the fields to use
    2820 histo_menu=get(handles.histo1_menu,'String');
    2821 histo_value=get(handles.histo1_menu,'Value');
    2822 FieldName=histo_menu{histo_value};
    2823 r=regexp(FieldName,'(?<var1>.*)(?<sep>,)(?<var2>.*)','names');
    2824 FieldName_2='';
    2825 if ~isempty(r)
    2826     FieldName=r.var1;% name of first variable
    2827     FieldName_2=r.var2;% name of second variable
    2828 end
    2829 if ~isfield(UvData.Field,FieldName)
    2830     msgbox_uvmat('ERROR',['no field  ' FieldName ' for histogram'])
    2831     return
    2832 end
    2833 
    2834 %% extract the fields to use
    2835 % eliminate false data if relevant (false flag FF exists)
    2836 check_false=0;
    2837 if isfield(Field,'FF') && ~isempty(Field.FF) && isequal(size(Field.FF),size(Field.(FieldName)))
    2838     indsel=find(Field.FF==0);%find values marked as false
    2839     if ~isempty(indsel)
    2840         FieldHisto=Field.(FieldName)(indsel);%field of the first variable (U)
    2841         if ~isempty(FieldName_2)
    2842             if isfield(Field,'NbDim') && Field.NbDim==3
    2843                  FieldHisto(:,:,:,2)=Field.(FieldName_2)(indsel);%field of the second variable (U)
    2844             else
    2845             FieldHisto(:,:,2)=Field.(FieldName_2)(indsel);%field of the second variable (U)
    2846             end
    2847         end
    2848         check_false=1;
    2849     end
    2850 end
    2851 % no false data
    2852 if ~check_false
    2853     FieldHisto=Field.(FieldName);%field of the first variable (U)
    2854     if ~isempty(FieldName_2)
    2855         if isfield(Field,'NbDim') && Field.NbDim==3
    2856             FieldHisto(:,:,:,2)=Field.(FieldName_2);%field of the second variable (V)
    2857         else
    2858             FieldHisto(:,:,2)=Field.(FieldName_2);%field of the second variable (V)
    2859         end
    2860     end
    2861 end
    2862 
    2863 %% calculate and plot histogram
    2864 if isempty(Field)
    2865     msgbox_uvmat('ERROR',['empty field ' FieldName])
    2866 else
    2867     nxy=size(FieldHisto);
    2868     Amin=double(min(min(min(min(FieldHisto)))));%min of field value
    2869     Amax=double(max(max(max(max(FieldHisto)))));%max of field value
    2870     if isequal(Amin,Amax)
    2871         cla(handles.HistoAxes)
    2872     else
    2873         Histo.ListVarName={FieldName,'histo'};
    2874         if isfield(Field,'NbDim') && isequal(Field.NbDim,3)
    2875             Histo.VarDimName={FieldName,FieldName}; %dimensions for the histogram
    2876         else
    2877             if numel(nxy)==2
    2878                 Histo.VarDimName={FieldName,FieldName}; %dimensions for the histogram
    2879             else
    2880                 Histo.VarDimName={FieldName,{FieldName,'component'}}; %dimensions for the histogram
    2881             end
    2882         end
    2883         %unit
    2884         units=[]; %default
    2885         for ivar=1:numel(Field.ListVarName)
    2886             if strcmp(Field.ListVarName{ivar},FieldName)
    2887                 if isfield(Field,'VarAttribute') && numel(Field.VarAttribute)>=ivar && isfield(Field.VarAttribute{ivar},'units')
    2888                     units=Field.VarAttribute{ivar}.units;
    2889                     break
    2890                 end
    2891             end
    2892         end
    2893         if ~isempty(units)
    2894             Histo.VarAttribute{1}.units=units;
    2895         end
    2896         Histo.(FieldName)=linspace(Amin,Amax,50); %absissa values for histo
    2897         if isfield(Field,'NbDim') && isequal(Field.NbDim,3)
    2898             C=reshape(double(FieldHisto),1,[]);% reshape in a vector
    2899             Histo.histo(:,1)=hist(C, Histo.(FieldName));  %calculate histogram
    2900         else
    2901             for col=1:size(FieldHisto,3)
    2902                 B=FieldHisto(:,:,col);
    2903                 C=reshape(double(B),1,nxy(1)*nxy(2));% reshape in a vector
    2904                 Histo.histo(:,col)=hist(C, Histo.(FieldName));  %calculate histogram
    2905             end
    2906         end
    2907         plot_field(Histo,handles.HistoAxes);
    2908         hlegend=legend;
    2909         if isempty(FieldName_2)
    2910         set(hlegend,'String',FieldName)
    2911         else
    2912             set(hlegend,'String',{FieldName;FieldName_2})
    2913         end
    2914     end
    2915 end
    2916 
    2917 %------------------------------------------------------------------------
    2918 % --- translate coordinate to matrix index
    2919 %------------------------------------------------------------------------
    2920 function [indx,indy]=pos2ind(x0,rangx0,nxy)
    2921 indx=1+round((nxy(2)-1)*(x0-rangx0(1))/(rangx0(2)-rangx0(1)));% index x of pixel 
    2922 indy=1+round((nxy(1)-1)*(y12-rangy0(1))/(rangy0(2)-rangy0(1)));% index y of pixel
    2923 
    2924 %------------------------------------------------------------------------
    2925 % --- Executes on button press in 'CheckZoom'.
    2926 %------------------------------------------------------------------------
    2927 function CheckZoom_Callback(hObject, eventdata, handles)
    2928 
    2929     if get(handles.CheckZoom,'Value')
    2930         set(handles.CheckFixLimits,'Value',1)% propose by default fixed limits for the plotting axes
    2931         set(handles.CheckZoomFig,'Value',0)%desactivate zoom fig
    2932     end
    2933 
    2934 
    2935 %------------------------------------------------------------------------
    2936 % --- Executes on button press in CheckZoomFig.
    2937 %------------------------------------------------------------------------
    2938 function CheckZoomFig_Callback(hObject, eventdata, handles)
    2939 
    2940 if get(handles.CheckZoomFig,'Value')
    2941     set(handles.CheckZoom,'value',0)
    2942 end
    2943 
    2944 %------------------------------------------------------------------------
    2945 % --- Executes on button press in 'CheckFixLimits'.
    2946 %------------------------------------------------------------------------
    2947 function CheckFixLimits_Callback(hObject, eventdata, handles)
    2948 
    2949 if ~get(handles.CheckFixLimits,'Value')
    2950     update_plot(handles)
    2951     set(handles.CheckZoom,'Value',0)
    2952 end
    2953 
    2954 %------------------------------------------------------------------------
    2955 % --- Executes on button press in CheckFixAspectRatio.
    2956 function CheckFixAspectRatio_Callback(hObject, eventdata, handles)
    2957 %------------------------------------------------------------------------
    2958  update_plot(handles);
    2959 
    2960 %------------------------------------------------------------------------
    2961 function num_AspectRatio_Callback(hObject, eventdata, handles)
    2962 %------------------------------------------------------------------------
    2963 set(handles.CheckFixAspectRatio,'Value',1)% select the fixed aspect ratio button
    2964 update_plot(handles);
    2965 
    2966 %------------------------------------------------------------------------
    2967 %----Executes on button press in 'record': records the current flags of manual correction.
    2968 %------------------------------------------------------------------------
    2969 function record_Callback(hObject, eventdata, handles)
    2970 
    2971 [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles);
    2972 FileName=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt];
    2973 [erread,message]=fileattrib(FileName);
    2974 if ~isempty(message) && ~isequal(message.UserWrite,1)
    2975      msgbox_uvmat('ERROR',['no writting access to ' FileName])
    2976      return
    2977 end
    2978 MenuVelType=get(handles.VelType,'String');
    2979 test_civ2=strcmp(MenuVelType{get(handles.VelType,'Value')},'civ2');
    2980 test_civ1=strcmp(MenuVelType{get(handles.VelType,'Value')},'civ1');
    2981 if ~test_civ2 && ~test_civ1
    2982     msgbox_uvmat('ERROR','manual correction only possible for CIV1 or CIV2 velocity fields')
    2983 end
    2984 if test_civ2
    2985     nbname='nb_vec_2';
    2986    flagname='Civ2_FF';
    2987    CivStage=5;
    2988 end
    2989 if test_civ1
    2990     nbname='nb_vec_1';
    2991    flagname='Civ1_FF';
    2992     CivStage=2;
    2993 end
    2994 %write fix flags in the netcdf file
    2995 UvData=get(handles.uvmat,'UserData');
    2996 hhh=which('netcdf.open');% look for built-in matlab netcdf library
    2997 if ~isequal(hhh,'')% case of  builtin Matlab netcdf library
    2998     nc=netcdf.open(FileName,'NC_WRITE');
    2999     netcdf.reDef(nc);
    3000     netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'CivStage',CivStage);
    3001     dimid = netcdf.inqDimID(nc,nbname);
    3002     try
    3003         varid = netcdf.inqVarID(nc,flagname);% look for already existing fixflag variable
    3004     catch
    3005         varid=netcdf.defVar(nc,flagname,'double',dimid);%create fixflag variable if it does not exist
    3006     end
    3007     netcdf.endDef(nc);
    3008     netcdf.putVar(nc,varid,UvData.PlotAxes.FF);
    3009     netcdf.close(nc); 
    3010 else %old netcdf library
    3011     netcdf_toolbox(FileName,AxeData,attrname,nbname,flagname)
    3012 end
    3013 
    3014 %-------------------------------------------------------------------
    3015 %----Correct the netcdf file, using toolbox (old versions of Matlab).
    3016 %-------------------------------------------------------------------
    3017 function netcdf_toolbox(FileName,AxeData,attrname,nbname,flagname)
    3018 nc=netcdf(FileName,'write'); %open netcdf file
    3019 result=redef(nc);
    3020 eval(['nc.' attrname '=1;']);
    3021 theDim=nc(nbname) ;% get the number of velocity vectors
    3022 nb_vectors=size(theDim);
    3023 var_FixFlag=ncvar(flagname,nc);% var_FixFlag will be written as the netcdf variable vec_FixFlag
    3024 var_FixFlag(1:nb_vectors)=AxeData.FF;%
    3025 fin=close(nc);
    3026 
    3027 %-----------------------------------------------------------------------
    3028 % --- Executes on button press in SubField
    3029 %-----------------------------------------------------------------------
    3030 function SubField_Callback(hObject, eventdata, handles)
    3031 
    3032 if get(handles.SubField,'Value')==0% if the subfield button is desactivated 
    3033     desable_subfield(handles)
    3034     transform_fct_list=get(handles.TransformName,'String');
    3035     transform_fct=transform_fct_list(get(handles.TransformName,'Value'));
    3036     if strcmp(transform_fct,'sub_field')
    3037         set(handles.TransformName,'Value',1)%suppress the sub_field transform
    3038         TransformName_Callback(hObject, eventdata, handles);
    3039     else
    3040         REFRESH_Callback(hObject, eventdata, handles)
    3041     end 
    3042 else
    3043     fileinput_1=uigetfile_uvmat('select a second input file:',get(handles.RootPath,'String'));
    3044     if isempty(fileinput_1)
    3045         set(handles.SubField,'Value',0)
    3046     else       
    3047         % refresh the current displayed field
    3048         display_file_name(handles,fileinput_1,2)
    3049        
    3050         %update list of recent files in the menubar
    3051         MenuFile_1=fileinput_1;
    3052         MenuFile_2=get(handles.MenuFile_1,'Label');
    3053         MenuFile_3=get(handles.MenuFile_2,'Label');
    3054         MenuFile_4=get(handles.MenuFile_3,'Label');
    3055         MenuFile_5=get(handles.MenuFile_4,'Label');
    3056         set(handles.MenuFile_1,'Label',MenuFile_1)
    3057         set(handles.MenuFile_2,'Label',MenuFile_2)
    3058         set(handles.MenuFile_3,'Label',MenuFile_3)
    3059         set(handles.MenuFile_4,'Label',MenuFile_4)
    3060         set(handles.MenuFile_5,'Label',MenuFile_5)
    3061     end
    3062 end
    3063 
    3064 %-----------------------------------------------------------------------
    3065 % --- desactivate display used for a second file series
    3066 %-----------------------------------------------------------------------
    3067 function desable_subfield(handles)
    3068    
    3069 set(handles.RootPath_1,'String','')
    3070 set(handles.RootFile_1,'String','')
    3071 set(handles.SubDir_1,'String','');
    3072 set(handles.FileIndex_1,'String','');
    3073 set(handles.FileExt_1,'String','');
    3074 set(handles.RootPath_1,'Visible','off')
    3075 set(handles.RootFile_1,'Visible','off')
    3076 set(handles.SubDir_1,'Visible','off');
    3077 set(handles.NomType_1,'Visible','off');
    3078 set(handles.FileIndex_1,'Visible','off');
    3079 set(handles.FileExt_1,'Visible','off');
    3080 set(handles.TimeName_1,'String','');
    3081 set(handles.TimeName_1,'Visible','off');
    3082 set(handles.TimeValue_1,'String','');
    3083 set(handles.TimeValue_1,'Visible','off');
    3084 set(handles.FieldName_1,'Value',1);%set to blank state
    3085 set(handles.VelType_1,'Value',1);%set to blank state
    3086 set(handles.num_Opacity,'String','')% desactivate opacity setting
    3087 FieldList=get(handles.FieldName,'String');
    3088 if numel(FieldList)>1   % if a choice of fields exists
    3089     set(handles.FieldName_1,'Value',1)% set second field choice to blank
    3090     set(handles.FieldName_1,'String',[{''};FieldList])% reproduce the menu FieldName plus a blank option
    3091 else
    3092     set(handles.FieldName_1,'String',{''})% set second field choice to blank
    3093 end
    3094 if ~strcmp(get(handles.VelType,'Visible'),'on')
    3095     set(handles.VelType_1,'Visible','off')
    3096 end
    3097 UvData=get(handles.uvmat,'UserData');
    3098 if isfield(UvData,'XmlData_1')
    3099     UvData=rmfield(UvData,'XmlData_1');
    3100 end
    3101 set(handles.uvmat,'UserData',UvData);
    3102 
    3103 %------------------------------------------------------------------------
    3104 % --- read the data displayed for the input rootfile windows (new): TODO use read_GUI
    3105 %------------------------------------------------------------------------
    3106 function [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles)
    3107 
    3108 InputFile=read_GUI(handles.InputFile);
    3109 RootPath=InputFile.RootPath;
    3110 SubDir=regexprep(InputFile.SubDir,'/|\','');
    3111 RootFile=regexprep(InputFile.RootFile,'/|\','');
    3112 FileIndices=InputFile.FileIndex;
    3113 FileExt=InputFile.FileExt;
    3114 
    3115 
    3116 %------------------------------------------------------------------------
    3117 % ---- read the data displayed for the second input rootfile windows
    3118 %------------------------------------------------------------------------
    3119 function [RootPath_1,SubDir_1,RootFile_1,FileIndex_1,FileExt_1,NomType_1]=read_file_boxes_1(handles)
    3120 
    3121 RootPath_1=get(handles.RootPath_1,'String'); % read the data from the file1_input window
    3122 if isequal(get(handles.RootPath_1,'Visible'),'off') || isequal(RootPath_1,'"')
    3123     RootPath_1=get(handles.RootPath,'String');
    3124 end;
    3125 SubDir_1=get(handles.SubDir_1,'String');
    3126 if isequal(get(handles.SubDir_1,'Visible'),'off')|| isequal(SubDir_1,'"')
    3127     SubDir_1=get(handles.SubDir,'String');
    3128 end
    3129 SubDir_1=regexprep(SubDir_1,'\<[\\/]|[\\/]\>','');%suppress possible / or \ separator at the beginning or the end of the string
    3130 RootFile_1=get(handles.RootFile_1,'String');
    3131 if isequal(get(handles.RootFile_1,'Visible'),'off') || isequal(RootFile_1,'"')
    3132     RootFile_1=get(handles.RootFile,'String');
    3133 end
    3134 RootFile_1=regexprep(RootFile_1,'\<[\\/]|[\\/]\>','');%suppress possible / or \ separator at the beginning or the end of the string
    3135 FileIndex_1=get(handles.FileIndex_1,'String');
    3136 if isequal(get(handles.FileIndex_1,'Visible'),'off')|| isequal(FileIndex_1,'"')
    3137     FileIndex_1=get(handles.FileIndex,'String');
    3138 end
    3139 FileExt_1=get(handles.FileExt_1,'String');
    3140 if isequal(get(handles.FileExt_1,'Visible'),'off') || isequal(FileExt_1,'"')
    3141     FileExt_1=get(handles.FileExt,'String');%read FileExt by default
    3142 end
    3143 NomType_1=get(handles.NomType_1,'String');
    3144 if isequal(get(handles.NomType_1,'Visible'),'off') || isequal(NomType_1,'"')
    3145     NomType_1=get(handles.NomType,'String');%read FileExt by default
    3146 end
    3147 %------------------------------------------------------------------------
    3148 % --- Executes on menu selection FieldName
    3149 
    3150     function FieldName_Callback(hObject, eventdata, handles)
    3151 %------------------------------------------------------------------------
    3152 
    3153 %% read data from uvmat
    3154 UvData=get(handles.uvmat,'UserData');
    3155 list_fields=get(handles.FieldName,'String');% list menu fields
    3156 index_fields=get(handles.FieldName,'Value');% selected string index
    3157 field= list_fields{index_fields(1)}; % selected string
    3158 [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles);
    3159 FileName=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt];
    3160 [tild,tild,tild,i1,i2,j1,j2,tild,NomType]=fileparts_uvmat(['xxx' get(handles.FileIndex,'String') FileExt]);
    3161 
    3162 switch field 
    3163     case 'get_field...'
    3164         %% fill the axes and variables from selections in get_field
    3165         ParamIn.Title='get_field: choose input field for display in uvmat' ;
    3166         % in case of civ data, we use the civ choice as default input for the GUI get_field
    3167         if strcmp(get(handles.VelType,'Visible'),'on')
    3168             ParamIn.SwitchVarIndexTime='attribute';
    3169             ListVelType=get(handles.VelType,'String');
    3170             VelType=ListVelType{get(handles.VelType,'Value')};
    3171             switch VelType
    3172                 case 'civ1'
    3173                     ParamIn.TimeAttrName='Civ1_Time';
    3174                     ParamIn.vector_x='Civ1_U';
    3175                     ParamIn.vector_y='Civ1_V';
    3176                     ParamIn.vec_color='Civ1_C';
    3177                 case 'filter1'
    3178                     ParamIn.TimeAttrName='Civ1_Time';
    3179                     ParamIn.vector_x='Civ1_U_smooth';
    3180                     ParamIn.vector_y='Civ1_V_smooth';
    3181                 case 'civ2'
    3182                     ParamIn.TimeAttrName='Civ2_Time';
    3183                     ParamIn.vector_x='Civ2_U';
    3184                     ParamIn.vector_y='Civ2_V';
    3185                 case 'filter2'
    3186                     ParamIn.TimeAttrName='Civ2_Time';
    3187                     ParamIn.vector_x='Civ2_U_smooth';
    3188                     ParamIn.vector_y='Civ2_V_smooth';
    3189                     ParamIn.vec_color='Civ2_C';
    3190             end
    3191         end
    3192        
    3193         % VelType menu desactivated
    3194         set(handles.FixVelType,'visible','off')
    3195         set(handles.VelType,'Visible','off')
    3196        
    3197         %read selection from get_field
    3198         [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles);
    3199         FileName=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt];
    3200         GetFieldData=get_field(FileName,ParamIn);% inport field names from the GUI get_field
    3201         FieldList={};
    3202         VecColorList={''};
    3203         ZName='';
    3204         switch GetFieldData.FieldOption
    3205             case 'vectors'
    3206                 UName=GetFieldData.PanelVectors.vector_x;
    3207                 VName=GetFieldData.PanelVectors.vector_y;
    3208                 YName=GetFieldData.Coordinates.Coord_y;
    3209                 if isfield(GetFieldData.Coordinates,'Coord_z')
    3210                 ZName=GetFieldData.Coordinates.Coord_z;
    3211                 end
    3212                 CName=GetFieldData.PanelVectors.vec_color;
    3213                 FieldList={['vec(' UName ',' VName ')'];...
    3214                     ['norm(' UName ',' VName ')'];...
    3215                     UName;VName};
    3216                 VecColorList={['norm(' UName ',' VName ')'];...
    3217                     UName;VName};
    3218                 if ~isempty(CName)
    3219                     VecColorList=[{CName};VecColorList];
    3220                 end
    3221             case 'scalar'
    3222                 AName=GetFieldData.PanelScalar.scalar;
    3223                 YName=GetFieldData.Coordinates.Coord_y;
    3224                 if isfield(GetFieldData.Coordinates,'Coord_z')
    3225                 ZName=GetFieldData.Coordinates.Coord_z;
    3226                 end
    3227                 FieldList={AName};
    3228             case '1D plot'
    3229                 YName=GetFieldData.PanelOrdinate.ordinate;
    3230             case 'civdata...'%reinitiate input, return to automatic civ data reading
    3231                 display_file_name(handles,FileName,1)
    3232         end
    3233         % get time as file index, attribute, variable or matrix index
    3234         if ~strcmp(GetFieldData.FieldOption,'civdata...')
    3235             XName=GetFieldData.Coordinates.Coord_x;
    3236             TimeNameStr=GetFieldData.Time.SwitchVarIndexTime;
    3237             switch TimeNameStr
    3238                 case 'file index'
    3239                     set(handles.TimeName,'String','');
    3240                 case 'attribute'
    3241                     set(handles.TimeName,'String',['att:' GetFieldData.Time.TimeName]);
    3242                 case 'variable'
    3243                     set(handles.TimeName,'String',['var:' GetFieldData.Time.TimeName])
    3244                     set(handles.NomType,'String','*')
    3245                     set(handles.RootFile,'String',[get(handles.RootFile,'String') get(handles.FileIndex,'String')])
    3246                     set(handles.i1,'String','1')% set counter to 1 (now the time index in the input matrix)
    3247                     MaxIndex_i=get(handles.MaxIndex_i,'String');
    3248                     MaxIndex_i{1}=num2str(GetFieldData.Time.TimeDimension);
    3249                     set(handles.MaxIndex_i,'String',MaxIndex_i)%TODO: record time unit
    3250                     UvData=get(handles.uvmat,'UserData');
    3251                     UvData.TimeUnit=GetFieldData.Time.TimeUnit;
    3252                     set(handles.uvmat,'UserData',UvData);
    3253                     set(handles.FileIndex,'String','')
    3254                     ParamIn.TimeVarName=GetFieldData.Time.TimeName;
    3255                 case 'matrix index'
    3256                     set(handles.TimeName,'String',['dim:' GetFieldData.Time.TimeName]);
    3257                     set(handles.NomType,'String','*')
    3258                     set(handles.RootFile,'String',[get(handles.RootFile,'String') get(handles.FileIndex,'String')])             
    3259                     set(handles.i1,'String','1')% set counter to 1 (now the time index in the input matrix)
    3260                     MaxIndex_i=get(handles.MaxIndex_i,'String');
    3261                     MaxIndex_i{1}=num2str(GetFieldData.Time.TimeDimension);
    3262                     set(handles.MaxIndex_i,'String',MaxIndex_i)%TODO: record time unit
    3263                     UvData=get(handles.uvmat,'UserData');
    3264                     UvData.TimeUnit=GetFieldData.Time.TimeUnit;
    3265                     set(handles.uvmat,'UserData',UvData);
    3266                     set(handles.FileIndex,'String','')
    3267                     ParamIn.TimeDimName=GetFieldData.Time.TimeName;
    3268             end
    3269             set(handles.Coord_x,'String',XName)
    3270 %             if ischar(YName)
    3271 %                 YName={YName};
    3272 %             end
    3273             set(handles.Coord_y,'String',YName)
    3274             set(handles.Coord_z,'String',ZName)
    3275             set(handles.FieldName,'Value',1)
    3276             set(handles.FieldName,'String',[FieldList; {'get_field...'}]);
    3277             set(handles.ColorScalar,'Value',1)
    3278             set(handles.ColorScalar,'String',VecColorList);
    3279             UvData.FileType{1}='netcdf';
    3280             set(handles.uvmat,'UserData',UvData)
    3281             REFRESH_Callback(hObject, eventdata, handles)
    3282         end
    3283        
    3284     case 'image'
    3285         %% look for image corresponding to civ data
    3286         if  isfield(UvData.Field,'Civ2_ImageA')%get the corresponding input image in the netcdf file
    3287             imagename=UvData.Field.Civ2_ImageA;
    3288         elseif isfield(UvData.Field,'Civ1_ImageA')%
    3289             imagename=UvData.Field.Civ1_ImageA;
    3290         else
    3291             SubDirBase=regexprep(SubDir,'\..*','');%take the root part of SubDir, before the first dot '.'
    3292             imagename=fullfile_uvmat(RootPath,SubDirBase,RootFile,'.png',NomType,i1,[],j1,[]);
    3293         end
    3294         if ~exist(imagename,'file')
    3295             imagename=uigetfile_uvmat('Pick an image file',imagename,'image');
    3296             if isempty(imagename)
    3297                 return
    3298             end
    3299         end
    3300         % display the selected field and related information
    3301         display_file_name(handles,imagename)%display the image
    3302     otherwise
    3303         REFRESH_Callback(hObject, eventdata, handles)
    3304 end
    3305 
    3306 %----------------------------------------------------------------
    3307 % --- Executes on menu selection FieldName
    3308 function FieldName_1_Callback(hObject, eventdata, handles)
    3309 %-------------------------------------------------
    3310 
    3311 %%%%%% TODO: modify like FieldName_Callback
    3312 %% read input data
    3313 check_new=~get(handles.SubField,'Value'); %check_new=1 if a second field was not previously entered
    3314 UvData=get(handles.uvmat,'UserData');
    3315 if check_new && isfield(UvData,'XmlData')
    3316     UvData.XmlData{2}=UvData.XmlData{1};
    3317 end
    3318 if isfield(UvData,'Field_1')
    3319     UvData=rmfield(UvData,'Field_1');% remove the stored second field (a new one needs to be read)
    3320 end
    3321 UvData.FileName_1='';% desactivate the use of a constant second file
    3322 list_fields=get(handles.FieldName,'String');% list menu fields
    3323 field= list_fields{get(handles.FieldName,'Value')}; % selected string
    3324 list_fields=get(handles.FieldName_1,'String');% list menu fields
    3325 field_1= list_fields{get(handles.FieldName_1,'Value')}; % selected string for the second field
    3326 if isempty(field_1)%||(numel(UvData.FileType)>=2 && strcmp(UvData.FileType{2},'image'))
    3327     set(handles.SubField,'Value',0)
    3328     SubField_Callback(hObject, eventdata, handles)
    3329     return
    3330 else
    3331     set(handles.SubField,'Value',1)%state that a second field is now entered
    3332 end
    3333 
    3334 %% read the rootfile input display
    3335 [RootPath_1,SubDir_1,RootFile_1,FileIndex_1,FileExt_1]=read_file_boxes_1(handles);
    3336 FileName_1=[fullfile(RootPath_1,SubDir_1,RootFile_1) FileIndex_1 FileExt_1];
    3337 [tild,tild,tild,i1,i2,j1,j2]=fileparts_uvmat(get(handles.FileIndex,'String'));
    3338 switch field_1
    3339     case 'get_field...'
    3340          %% fill the axes and variables from selections in get_field
    3341         ParamIn=[];
    3342         % in case of civ data, we use the civ choice as default input for the GUI get_field
    3343         if strcmp(get(handles.VelType_1,'Visible'),'on')
    3344             ParamIn.SwitchVarIndexTime='attribute';
    3345             ListVelType=get(handles.VelType_1,'String');
    3346             VelType=ListVelType{get(handles.VelType_1,'Value')};
    3347             switch VelType
    3348                 case 'civ1'
    3349                     ParamIn.TimeAttrName='Civ1_Time';
    3350                     ParamIn.vector_x='Civ1_U';
    3351                     ParamIn.vector_y='Civ1_V';
    3352                     ParamIn.vec_color='Civ1_C';
    3353                 case 'filter1'
    3354                     ParamIn.TimeAttrName='Civ1_Time';
    3355                     ParamIn.vector_x='Civ1_U_smooth';
    3356                     ParamIn.vector_y='Civ1_V_smooth';
    3357                 case 'civ2'
    3358                     ParamIn.TimeAttrName='Civ2_Time';
    3359                     ParamIn.vector_x='Civ2_U';
    3360                     ParamIn.vector_y='Civ2_V';
    3361                 case 'filter2'
    3362                     ParamIn.TimeAttrName='Civ2_Time';
    3363                     ParamIn.vector_x='Civ2_U_smooth';
    3364                     ParamIn.vector_y='Civ2_V_smooth';
    3365                     ParamIn.vec_color='Civ2_C';
    3366             end
    3367         end
    3368        
    3369         % VelType menu desactivated
    3370         set(handles.FixVelType,'visible','off')
    3371         set(handles.VelType,'Visible','off')
    3372        
    3373         %read selection from get_field
    3374         [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes_1(handles);
    3375         FileName=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt];
    3376         GetFieldData=get_field(FileName,ParamIn);% inport field names from the GUI get_field
    3377         FieldList={};
    3378         VecColorList={};
    3379         switch GetFieldData.FieldOption
    3380             case 'vectors'
    3381                 UName=GetFieldData.PanelVectors.vector_x;
    3382                 VName=GetFieldData.PanelVectors.vector_y;
    3383                 YName=GetFieldData.Coordinates.Coord_y;
    3384                 CName=GetFieldData.PanelVectors.vec_color;
    3385                 FieldList={['vec(' UName ',' VName ')'];...
    3386                     ['norm(' UName ',' VName ')'];...
    3387                     UName;VName};
    3388                 VecColorList={['norm(' UName ',' VName ')'];...
    3389                     UName;VName};
    3390                 if ~isempty(CName)
    3391                     VecColorList=[{CName};VecColorList];
    3392                 end
    3393             case 'scalar'
    3394                 AName=GetFieldData.PanelScalar.scalar;
    3395                 YName=GetFieldData.Coordinates.Coord_y;
    3396                 FieldList={AName};
    3397             case '1D plot'
    3398                 YName=GetFieldData.PanelOrdinate.ordinate;
    3399             case 'civdata...'%reinitiate input, return to automatic civ data reading
    3400                 display_file_name(handles,FileName,1)
    3401         end
    3402         if ~strcmp(GetFieldData.FieldOption,'civdata...')
    3403             XName=GetFieldData.Coordinates.Coord_x;
    3404             TimeNameStr=GetFieldData.Time.SwitchVarIndexTime;
    3405             switch TimeNameStr
    3406                 case 'file index'
    3407                     set(handles.TimeName_1,'String','');
    3408                 case 'attribute'
    3409                     set(handles.TimeName_1,'String',['att:' GetFieldData.Time.TimeName]);
    3410                 case 'variable'
    3411                     set(handles.TimeName_1,'String',['var:' GetFieldData.Time.TimeName])
    3412                     set(handles.NomType_1,'String','*')
    3413                     set(handles.RootFile_1,'String',[get(handles.RootFile,'String') get(handles.FileIndex,'String')])
    3414                     set(handles.FileIndex_1,'String','')
    3415                     ParamIn.TimeVarName=GetFieldData.Time.TimeName;
    3416                 case 'matrix_index'
    3417                     set(handles.TimeName_1,'String',['dim:' GetFieldData.Time.TimeName]);
    3418                     set(handles.NomType_1,'String','*')
    3419                     set(handles.RootFile_1,'String',[get(handles.RootFile,'String') get(handles.FileIndex,'String')])
    3420                     set(handles.FileIndex_1,'String','')
    3421                     ParamIn.TimeDimName_1=GetFieldData.Time.TimeName;
    3422             end
    3423             set(handles.Coord_x,'String',XName)
    3424 %             if ischar(YName)
    3425 %                 YName={YName};
    3426 %             end
    3427             set(handles.Coord_y,'String',YName)
    3428             set(handles.FieldName_1,'Value',1)
    3429             set(handles.FieldName_1,'String',[FieldList; {'get_field...'}]);
    3430             set(handles.ColorScalar,'Value',1)
    3431             set(handles.ColorScalar,'String',VecColorList);
    3432             UvData.FileType{2}='netcdf';
    3433             set(handles.uvmat,'UserData',UvData)
    3434             REFRESH_Callback(hObject, eventdata, handles)
    3435         end
    3436          
    3437 %         set_veltype_display(0) % no veltype display
    3438 %         hget_field=findobj(allchild(0),'name','get_field_1');
    3439 %         if ~isempty(hget_field)
    3440 %             delete(hget_field)
    3441 %         end
    3442 %         hget_field=get_field(FileName_1);
    3443 %         set(hget_field,'name','get_field_1')
    3444 %         hhget_field=guidata(hget_field);
    3445 %         set(hhget_field.list_fig,'Value',1)
    3446 %         set(hhget_field.list_fig,'String',{'uvmat'})
    3447 %         if check_new
    3448 %             UvData.FileType{2}=UvData.FileType{1};
    3449 %             set(handles.FileIndex_1,'String',get(handles.FileIndex,'String'))
    3450 %               set(handles.uvmat,'UserData',UvData)
    3451 %         end
    3452     case 'image'
    3453         %% look for image corresponding to civ data
    3454         imagename='';
    3455         if  isfield(UvData.Field,'Civ2_ImageA')%get the corresponding input image in the netcdf file
    3456             imagename=UvData.Field.Civ2_ImageA;
    3457         elseif isfield(UvData.Field,'Civ1_ImageA')%
    3458             imagename=UvData.Field.Civ1_ImageA;
    3459         else
    3460             SubDirBase=regexprep(SubDir,'\..*','');%take the root part of SubDir, before the first dot '.'
    3461             imagename=fullfile_uvmat(RootPath,SubDirBase,RootFile,'.png',NomType,i1,[],j1,[]);
    3462         end
    3463         if ~exist(imagename,'file')
    3464             imagename=uigetfile_uvmat('Pick an image file',imagename,'image');
    3465            
    3466         end
    3467         if isempty(imagename)
    3468             set(handles.SubField,'Value',0)
    3469             return
    3470         else
    3471             display_file_name(handles,imagename,2)%display the image as second field
    3472         end
    3473     otherwise
    3474         check_refresh=1;
    3475         if check_new% if a second field was not previously entered, we just read another field in the first input file
    3476             set(handles.FileIndex_1,'String',get(handles.FileIndex,'String'))
    3477             set(handles.FileExt_1,'String',get(handles.FileExt,'String'))
    3478            
    3479             UvData.FileType{2}=UvData.FileType{1};
    3480             UvData.XmlData{2}= UvData.XmlData{1};
    3481             transform=get(handles.TransformPath,'UserData');
    3482              if (~isa(transform,'function_handle')||nargin(transform)<3)
    3483                 set(handles.uvmat,'UserData',UvData)
    3484                 set(handles.TransformName,'value',2); % set transform fct to 'sub_field' if the current fct does not accept two input fields
    3485                 TransformName_Callback(hObject, eventdata, handles)% activate transform_fct_Callback and refresh current plot
    3486                  check_refresh=0;
    3487              end             
    3488         end
    3489         if ~isequal(field,'image')
    3490             set(handles.TitleNpxy,'Visible','off')% visible npx,pxcm... buttons
    3491             set(handles.num_Npx,'Visible','off')
    3492             set(handles.num_Npy,'Visible','off')
    3493         end
    3494         set(handles.uvmat,'UserData',UvData)
    3495  
    3496         if check_refresh && ~(isfield(UvData,'NewSeries')&&isequal(UvData.NewSeries,1))
    3497             REFRESH_Callback(hObject, eventdata, handles)
    3498         end
    3499 end
    3500 
    3501 %------------------------------------------------------------------------
    3502 % --- set the visibility of relevant velocity type menus:
    3503 function menu=set_veltype_display(Civ,FileType)
    3504 %------------------------------------------------------------------------
    3505 if ~exist('FileType','var')
    3506     FileType='civx';
    3507 end
    3508 switch FileType
    3509     case 'civx'
    3510         menu={'civ1';'interp1';'filter1';'civ2';'interp2';'filter2'};
    3511         if isequal(Civ,0)
    3512             imax=0;
    3513         elseif isequal(Civ,1) || isequal(Civ,2)
    3514             imax=1;
    3515         elseif isequal(Civ,3)
    3516             imax=3;
    3517         elseif isequal(Civ,4) || isequal(Civ,5)
    3518             imax=4;
    3519         elseif isequal(Civ,6) %patch2
    3520             imax=6;
    3521         end
    3522     case 'civdata'
    3523         menu={'civ1';'filter1';'civ2';'filter2'};
    3524         if isequal(Civ,0)
    3525             imax=0;
    3526         elseif isequal(Civ,1) || isequal(Civ,2)
    3527             imax=1;
    3528         elseif isequal(Civ,3)
    3529             imax=2;
    3530         elseif isequal(Civ,4) || isequal(Civ,5)
    3531             imax=3;
    3532         elseif isequal(Civ,6) %patch2
    3533             imax=4;
    3534         end
    3535 end
    3536 menu=menu(1:imax);
    3537 
    3538 %------------------------------------------------------------------------
    3539 % --- Executes on button press in FixVelType.
    3540 function FixVelType_Callback(hObject, eventdata, handles)
    3541 %------------------------------------------------------------------------
    3542 % inputfilerefresh the current plot if the fixed  veltype is unselected
    3543 if ~get(handles.FixVelType,'Value')
    3544     REFRESH_Callback(hObject, eventdata, handles)
    3545 end
    3546 
    3547 %------------------------------------------------------------------------
    3548 % --- Executes on button press in VelType.
    3549 function VelType_Callback(hObject, eventdata, handles)
    3550 %------------------------------------------------------------------------
    3551 set(handles.FixVelType,'Value',1)
    3552 REFRESH_Callback(hObject, eventdata, handles)
    3553 
    3554 %------------------------------------------------------------------------
    3555 % --- Executes on choice selection in VelType_1.
    3556 function VelType_1_Callback(hObject, eventdata, handles)
    3557 %------------------------------------------------------------------------
    3558 set(handles.FixVelType,'Value',1)% the velocity type is now imposed by the GUI (not automatic)
    3559 UvData=get(handles.uvmat,'UserData');
    3560 set(handles.InputFileREFRESH,'BackgroundColor',[1 1 0])%paint REFRESH button in yellow to indicate its activation
    3561 drawnow   
    3562 InputFile=read_GUI(handles.InputFile);% read the input file parameters
    3563 [RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles);
    3564 [RootPath_1,SubDir_1,RootFile_1,FileIndex_1,FileExt_1]=read_file_boxes_1(handles);
    3565 FileName=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt];% name of the first input file
    3566 
    3567 check_refresh=0;
    3568 if isempty(InputFile.VelType_1)
    3569         FileName_1='';% we plot the first input field without the second field
    3570         set(handles.SubField,'Value',0)
    3571         SubField_Callback(hObject, eventdata, handles)% activate SubField_Callback and refresh current plot, removing the second field
    3572 elseif get(handles.SubField,'Value')% if subfield is already 'on'
    3573      FileName_1=[fullfile(RootPath_1,SubDir_1,RootFile_1) FileIndex_1 FileExt_1];% name of the second input file
    3574      check_refresh=1;%will refresh the current plot
    3575 else% we introduce the same file (with a different field) for the second series
    3576      FileName_1=FileName;% we compare two fields in the same file
    3577      UvData.FileType{2}=UvData.FileType{1};
    3578      UvData.XmlData{2}= UvData.XmlData{1};
    3579      set(handles.SubField,'Value',1)
    3580      transform=get(handles.TransformPath,'UserData');
    3581      if (~isa(transform,'function_handle')||nargin(transform)<3)
    3582         set(handles.uvmat,'UserData',UvData)
    3583         set(handles.TransformName,'value',2); % set transform fct to 'sub_field' if the current fct does not accept two input fields
    3584         TransformName_Callback(hObject, eventdata, handles)% activate transform_fct_Callback and refresh current plot
    3585      else
    3586          check_refresh=1;
    3587      end 
    3588 end
    3589 
    3590 % inputfilerefresh the current plot if it has not been done previously
    3591 if check_refresh
    3592     UvData.FileName_1='';% desactivate the use of a constant second file
    3593     set(handles.uvmat,'UserData',UvData)
    3594     num_i1=stra2num(get(handles.i1,'String'));
    3595     num_i2=stra2num(get(handles.i2,'String'));
    3596     num_j1=stra2num(get(handles.j1,'String'));
    3597     num_j2=stra2num(get(handles.j2,'String'));
    3598     [tild,tild,tild,i1_1,i2_1,j1_1,j2_1]=fileparts_uvmat(['xx' FileIndex_1]);
    3599     errormsg=refresh_field(handles,FileName,FileName_1,num_i1,num_i2,num_j1,num_j2,i1_1,i2_1,j1_1,j2_1);
    3600     if ~isempty(errormsg)
    3601         msgbox_uvmat('ERROR',errormsg);
    3602     else
    3603 %         set(handles.i1,'BackgroundColor',[1 1 1])
    3604 %         set(handles.i2,'BackgroundColor',[1 1 1])
    3605 %         set(handles.j1,'BackgroundColor',[1 1 1])
    3606 %         set(handles.j2,'BackgroundColor',[1 1 1])
    3607 %         set(handles.FileIndex,'BackgroundColor',[1 1 1])
    3608 %         set(handles.FileIndex_1,'BackgroundColor',[1 1 1])
    3609     end
    3610     set(handles.InputFileREFRESH,'BackgroundColor',[1 0 0])
    3611 end
    3612 
    3613 
    3614 %------------------------------------------------------------------------
    3615 % --- reset civ buttons
    3616 function reset_vel_type(handles_civ0,handle1)
    3617 %------------------------------------------------------------------------
    3618 for ibutton=1:length(handles_civ0)
    3619     set(handles_civ0(ibutton),'BackgroundColor',[0.831 0.816 0.784])
    3620     set(handles_civ0(ibutton),'Value',0)
    3621 end
    3622 if exist('handle1','var')%handles of selected button
    3623         set(handle1,'BackgroundColor',[1 1 0]) 
    3624 end
    3625 
    3626 %-----------------------------------------------------------------------
    3627 % --- Executes on button press in MENUVOLUME.
    3628 function VOLUME_Callback(hObject, eventdata, handles)
    3629 %-----------------------------------------------------------------------
    3630 %errordlg('command VOL not implemented yet')
    3631 if ishandle(handles.UVMAT_title)
    3632     delete(handles.UVMAT_title)
    3633 end
    3634 UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
    3635 if isequal(get(handles.VOLUME,'Value'),1)
    3636     set(handles.CheckZoom,'Value',0)
    3637 %     set(handles.CheckZoom,'BackgroundColor',[0.7 0.7 0.7])
    3638     set(handles.edit_vect,'Value',0)
    3639     edit_vect_Callback(hObject, eventdata, handles)
    3640     set(handles.CheckEditObject,'Value',0)
    3641 %     set(handles.CheckEditObject,'BackgroundColor',[0.7 0.7 0.7])
    3642 %     set(handles.cal,'Value',0)
    3643 %     set(handles.cal,'BackgroundColor',[0 1 0])
    3644     set(handles.edit_vect,'Value',0)
    3645     edit_vect_Callback(hObject, eventdata, handles)
    3646     %initiate set_object GUI
    3647     data.Name='VOLUME';
    3648     if isfield(UvData,'CoordType')
    3649         data.CoordType=UvData.CoordType;
    3650     end
    3651     if isfield(UvData.Field,'CoordMesh')&~isempty(UvData.Field.CoordMesh)
    3652         data.RangeX=[UvData.Field.XMin UvData.Field.XMax];
    3653         data.RangeY=[UvData.Field.YMin UvData.Field.YMax];
    3654         data.DX=UvData.Field.CoordMesh;
    3655         data.DY=UvData.Field.CoordMesh;
    3656     elseif isfield(UvData.Field,'Coord_x')&isfield(UvData.Field,'Coord_y')& isfield(UvData.Field,'A')%only image
    3657         np=size(UvData.Field.A);
    3658         meshx=(UvData.Field.Coord_x(end)-UvData.Field.Coord_x(1))/np(2);
    3659         meshy=abs(UvData.Field.Coord_y(end)-UvData.Field.Coord_y(1))/np(1);
    3660         data.RangeY=max(meshx,meshy);
    3661         data.RangeX=max(meshx,meshy);
    3662         data.DX=max(meshx,meshy);
    3663     end
    3664     data.ParentButton=handles.VOLUME;
    3665     PlotHandles=get_plot_handles(handles);%get the handles of the interface elements setting the plotting parameters
    3666     [hset_object,UvData.sethandles]=set_object(data,PlotHandles);% call the set_object interface with action on haxes,
    3667                                                       % associate the set_object interface handle to the plotting axes
    3668     set(hset_object,'name','set_object')
    3669     UvData.MouseAction='create_object';
    3670 else
    3671     set(handles.VOLUME,'BackgroundColor',[0 1 0])
    3672 end
    3673 set(handles.uvmat,'UserData',UvData)
    3674 
    3675 %-------------------------------------------------------
    3676 function edit_vect_Callback(hObject, eventdata, handles)
    3677 %-------------------------------------------------------
    3678 %
    3679 if isequal(get(handles.edit_vect,'Value'),1)
    3680     VelTypeMenu=get(handles.VelType,'String');
    3681     VelType=VelTypeMenu{get(handles.VelType,'Value')};
    3682     if ~strcmp(VelType,'civ2') && ~strcmp(VelType,'civ1')
    3683         msgbox_uvmat('ERROR','manual correction only possible for CIV1 or CIV2 velocity fields')
    3684     end
    3685     set(handles.record,'Visible','on')
    3686     set(handles.edit_vect,'BackgroundColor',[1 1 0])
    3687     set(handles.CheckEditObject,'Value',0)
    3688     set(handles.CheckZoom,'Value',0)
    3689     set(gcf,'Pointer','arrow')
    3690 else
    3691     set(handles.record,'Visible','off')
    3692     set(handles.edit_vect,'BackgroundColor',[0.7 0.7 0.7])
    3693 end
    3694 
    3695 %----------------------------------------------
    3696 function save_mask_Callback(hObject, eventdata, handles)
    3697 %-----------------------------------------------------------------------
    3698 UvData=get(handles.uvmat,'UserData');
    3699 
    3700 flag=1;
    3701 npx=size(UvData.Field.A,2);
    3702 npy=size(UvData.Field.A,1);
    3703 xi=0.5:npx-0.5;
    3704 yi=0.5:npy-0.5;
    3705 [Xi,Yi]=meshgrid(xi,yi);
    3706 if isfield(UvData,'ProjObject')
    3707     for iobj=1:length(UvData.ProjObject)
    3708         ObjectData=UvData.ProjObject{iobj};
    3709         if isfield(ObjectData,'ProjMode') &&(isequal(ObjectData.ProjMode,'mask_inside')||isequal(ObjectData.ProjMode,'mask_outside'));
    3710             flagobj=1;
    3711             testphys=0; %coordinates in pixels by default
    3712             if isfield(ObjectData,'CoordType') && isequal(ObjectData.CoordType,'phys')
    3713                 if isfield(UvData,'XmlData')&& isfield(UvData.XmlData{1},'GeometryCalib')
    3714                     Calib=UvData.XmlData{1}.GeometryCalib;
    3715                     testphys=1;
    3716                 end
    3717             end
    3718             if isfield(ObjectData,'Coord')& isfield(ObjectData,'Style')
    3719                 if isequal(ObjectData.Type,'polygon')
    3720                     X=ObjectData.Coord(:,1);
    3721                     Y=ObjectData.Coord(:,2);
    3722                     if testphys
    3723                         [X,Y]=px_XYZ(Calib,X,Y,0);% to generalise with 3D cases
    3724                     end
    3725                     flagobj=~inpolygon(Xi,Yi,X',Y');%=0 inside the polygon, 1 outside                 
    3726                 elseif isequal(ObjectData.Type,'ellipse')
    3727                     if testphys
    3728                         %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys
    3729                     end
    3730                     RangeX=max(ObjectData.RangeX);
    3731                     RangeY=max(ObjectData.RangeY);
    3732                     X2Max=RangeX*RangeX;
    3733                     Y2Max=RangeY*RangeY;
    3734                     distX=(Xi-ObjectData.Coord(1,1));
    3735                     distY=(Yi-ObjectData.Coord(1,2));
    3736                     flagobj=(distX.*distX/X2Max+distY.*distY/Y2Max)>1;
    3737                 elseif isequal(ObjectData.Type,'rectangle')
    3738                     if testphys
    3739                         %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys
    3740                     end
    3741                     distX=abs(Xi-ObjectData.Coord(1,1));
    3742                     distY=abs(Yi-ObjectData.Coord(1,2));
    3743                     flagobj=distX>max(ObjectData.RangeX) | distY>max(ObjectData.RangeY);
    3744                 end
    3745                 if isequal(ObjectData.ProjMode,'mask_outside')
    3746                     flagobj=~flagobj;
    3747                 end
    3748                 flag=flag & flagobj;
    3749             end
    3750         end
    3751     end
    3752 end
    3753 % flag=~flag;
    3754 %mask name
    3755 RootPath=get(handles.RootPath,'String');
    3756 RootFile=get(handles.RootFile,'String');
    3757 RootFile=regexprep(RootFile,'\<[\\/]|[\\/]\>','');%suppress possible / or \ separator at the beginning or the end of the string
    3758 filebase=fullfile(RootPath,RootFile);
    3759 list=get(handles.masklevel,'String');
    3760 masknumber=num2str(length(list));
    3761 maskindex=get(handles.masklevel,'Value');
    3762 mask_name=fullfile_uvmat(RootPath,SubDir,[RootFile '_' masknumber 'mask'],'.png','_1',maskindex);
    3763 %mask_name=name_generator([filebase '_' masknumber 'mask'],maskindex,1,'.png','_i');
    3764 imflag=uint8(255*(0.392+0.608*flag));% =100 for flag=0 (vectors not computed when 20<imflag<200)
    3765 imflag=flipdim(imflag,1);
    3766 % imflag=uint8(255*flag);% =0 for flag=0 (vectors=0 when 20<imflag<200)
    3767 msgbox_uvmat('CONFIRMATION',[mask_name ' saved'])
    3768 imwrite(imflag,mask_name,'BitDepth',8);
    3769 
    3770 %display the mask
    3771 figure;
    3772 vec=linspace(0,1,256);%define a linear greyscale colormap
    3773 map=[vec' vec' vec'];
    3774 colormap(map)
    3775 
    3776 image(imflag);
    3777 
    3778 %------------------------------------------------------------------------
    3779 %------------------------------------------------------------------------
    3780 %  - FUNCTIONS FOR SETTING PLOTTING PARAMETERS
    3781 
    3782 %------------------------------------------------------------------------
    3783 %------------------------------------------------------------------------
    3784 % --- Executes on selection change in TransformName.
    3785 
    3786 function TransformName_Callback(hObject, eventdata, handles)
    3787 %------------------------------------------------------------------------
    3788 set(handles.TransformName,'backgroundColor',[1 1 0])% indicate activation  of the menu
    3789 drawnow
    3790 UvData=get(handles.uvmat,'UserData');
    3791 menu=get(handles.TransformName,'String');%refresh
    3792 ichoice=get(handles.TransformName,'Value');%item number in the menu
    3793 transform_name=menu{ichoice};% choice of the transform fct
    3794 list_path=get(handles.TransformName,'UserData');
    3795 
    3796 %% handles  visibility of the path to the transform function
    3797 if isempty(transform_name)
    3798     set(handles.TransformPath,'Visible','off')
    3799 else
    3800     set(handles.TransformPath,'Visible','on')
    3801 end
    3802 
    3803 %% add a new item to the menu if the option 'more...' has been selected
    3804 prev_path=fullfile(get(handles.TransformPath,'String'));
    3805 if ~exist(prev_path,'dir')
    3806     prev_path=fullfile(fileparts(which('uvmat')),'transform_field');
    3807 end
    3808 if strcmp(transform_name,'more...');
    3809     transform_fct_chosen=uigetfile_uvmat('Pick the transform function',prev_path,'.m');
    3810     if ~isempty(transform_fct_chosen)
    3811         [PathName,transform_name]=fileparts(transform_fct_chosen);
    3812         ichoice=find(strcmp(transform_name,menu),1);%look for the selected fct in the existing menu
    3813         if isempty(ichoice)% if the item is not found, add it to the menu (before 'more...' and select it)
    3814             menu=[menu(1:end-1);{transform_name};{'more...'}];
    3815             ichoice=numel(menu)-1;
    3816         end
    3817         list_path{ichoice}=PathName;%update the list fo fct paths
    3818         set(handles.TransformName,'String',menu)
    3819         set(handles.TransformName,'Value',ichoice)
    3820        
    3821         % save the new menu in the personal file 'uvmat_perso.mat'
    3822         dir_perso=prefdir;%personal Matalb directory
    3823         profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
    3824         if exist(profil_perso,'file')
    3825             nb_builtin=UvData.OpenParam.NbBuiltin;% number of 'builtin' (basic) transform fcts in uvmat
    3826             if nb_builtin<numel(list_path)
    3827                 for ilist=nb_builtin+1:numel(list_path)
    3828                     transform_fct{ilist-nb_builtin}=[fullfile(list_path{ilist},menu{ilist}) '.m'];
    3829                 end
    3830                 save (profil_perso,'transform_fct','-append'); %store the root name for future opening of uvmat
    3831             end
    3832         end
    3833     end
    3834 end
    3835 
    3836 %% create the function handle of the selected fct
    3837 if isempty(list_path{ichoice})% case of no selected fct
    3838     transform_handle=[];
    3839 else
    3840     if ~exist(list_path{ichoice},'dir')
    3841         msgbox_uvmat('ERROR','invalid fct path: select the transform fct again with the option more...')
    3842         return
    3843     end
    3844     current_dir=pwd;%current working dir
    3845     cd(list_path{ichoice})
    3846     transform_handle=str2func(transform_name);
    3847     cd(current_dir)
    3848 end
    3849 set(handles.TransformPath,'String',list_path{ichoice})
    3850 set(handles.TransformPath,'UserData',transform_handle)
    3851 set(handles.TransformName,'UserData',list_path)
    3852 
    3853 %% update the ToolTip string of the menu TransformName with the first line of the selected fct file
    3854 if isempty(list_path{ichoice})% case of no selected fct
    3855     set(handles.TransformName,'ToolTipString','transform_fct:choose a transform function')
    3856 else
    3857     try
    3858         [fid,errormsg] =fopen([fullfile(list_path{ichoice},transform_name) '.m']);
    3859         InputText=textscan(fid,'%s',1,'delimiter','\n');
    3860         fclose(fid);
    3861         set(handles.TransformName,'ToolTipString',['transform_fct: ' InputText{1}{1}])% put the first line of the selected function as tooltip help
    3862     end
    3863 end
    3864 
    3865 %% adapt the GUI to the input/output conditions of the selected transform fct
    3866 CoordUnit='';
    3867 CoordUnitPrev='';
    3868 if isfield(UvData,'Field')&&isfield(UvData.Field,'CoordUnit')
    3869     CoordUnitPrev=UvData.Field.CoordUnit;
    3870 end
    3871 if ~isempty(list_path{ichoice})
    3872     if nargin(transform_handle)>1 %&& isfield(UvData,'XmlData')&&~isempty(UvData.XmlData)
    3873         XmlData=[];
    3874         if isfield(UvData,'XmlData')&&~isempty(UvData.XmlData)
    3875             XmlData=UvData.XmlData{1};
    3876         end
    3877         UvData.Field.Action.RUN=0;% indicate that the transform fct is called only to get input param
    3878         DataOut=feval(transform_handle,UvData.Field,XmlData);% execute the transform fct to get the required conditions
    3879         if isfield(DataOut,'CoordUnit')% set the requested coord unit (info used to possibly delete the current projection objects)
    3880             CoordUnit=DataOut.CoordUnit;
    3881         end
    3882         if isfield(DataOut,'InputFieldType')% to be used to impose a type of input file (eg. for image transform)
    3883             UvData.InputFieldType=DataOut.InputFieldType;
    3884         end
    3885         if isfield(DataOut,'TransformInput')%  used to add transform parameters at selection of the transform fct
    3886             UvData.XmlData{1}.TransformInput=DataOut.TransformInput;
    3887         end
    3888     end
    3889 end
    3890 
    3891 %% delete drawn objects if the output CooordUnit is different from the previous one
    3892 if  ~isempty(CoordUnit) && ~isempty(CoordUnitPrev) && ~strcmp(CoordUnit,CoordUnitPrev)
    3893     set(handles.CheckFixLimits,'Value',0)
    3894     hother=findobj('Tag','proj_object');%find all the proj objects
    3895     for iobj=1:length(hother)
    3896         delete_object(hother(iobj))
    3897     end
    3898     hother=findobj('Tag','DeformPoint');%find all the proj objects
    3899     for iobj=1:length(hother)
    3900         delete_object(hother(iobj))
    3901     end
    3902     hh=findobj('Tag','calib_points');
    3903     if ~isempty(hh)
    3904         delete(hh)
    3905     end
    3906     hhh=findobj('Tag','calib_marker');
    3907     if ~isempty(hhh)
    3908         delete(hhh)
    3909     end
    3910     set(handles.ListObject,'Value',1)
    3911     set(handles.ListObject,'String',{''})
    3912     set(handles.ListObject_1,'Value',1)
    3913     set(handles.ListObject_1,'String',{''})
    3914     set(handles.CheckViewObject,'value',0)
    3915     CheckViewObject_Callback(hObject, eventdata, handles)
    3916     set(handles.CheckViewField,'value',0)
    3917     CheckViewField_Callback(hObject, eventdata, handles)
    3918     set(handles.CheckEditObject,'Value',0)
    3919     CheckEditObject_Callback(hObject, eventdata, handles)
    3920     UvData.ProjObject={[]};
    3921 end
    3922 set(handles.uvmat,'UserData',UvData)
    3923 set(handles.TransformName,'backgroundColor',[1 1 1])% indicate desactivation  of the menu
    3924 drawnow
    3925 
    3926 %% inputfilerefresh the current plot
    3927 if isempty(list_path{ichoice}) || nargin(transform_handle)<3
    3928     set(handles.SubField,'Value',0)
    3929     SubField_Callback(hObject, eventdata, handles)
    3930 else
    3931     REFRESH_Callback(hObject, eventdata, handles)
    3932 end
    3933 
    3934 %------------------------------------------------
    3935 %CALLBACKS FOR PLOTTING PARAMETERS
    3936 %-------------------------------------------------
    3937 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    3938 % Plot axes
    3939 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    3940 %------------------------------------------------------------------------
    3941 function num_MinX_Callback(hObject, eventdata, handles)
    3942 %------------------------------------------------------------------------
    3943 set(handles.CheckFixLimits,'Value',1) %suppress auto mode
    3944 % set(handles.CheckFixLimits,'BackgroundColor',[1 1 0])
    3945 update_plot(handles);
    3946 
    3947 %------------------------------------------------------------------------
    3948 function num_MaxX_Callback(hObject, eventdata, handles)
    3949 %------------------------------------------------------------------------
    3950 set(handles.CheckFixLimits,'Value',1) %suppress auto mode
    3951 % set(handles.CheckFixLimits,'BackgroundColor',[1 1 0])
    3952 update_plot(handles);
    3953 
    3954 %------------------------------------------------------------------------
    3955 function num_MinY_Callback(hObject, eventdata, handles)
    3956 %------------------------------------------
    3957 set(handles.CheckFixLimits,'Value',1) %suppress auto mode
    3958 % set(handles.CheckFixLimits,'BackgroundColor',[1 1 0])
    3959 update_plot(handles);
    3960 
    3961 %------------------------------------------------------------------------
    3962 function num_MaxY_Callback(hObject, eventdata, handles)
    3963 %------------------------------------------------------------------------
    3964 set(handles.CheckFixLimits,'Value',1) %suppress auto mode
    3965 % set(handles.CheckFixLimits,'BackgroundColor',[1 1 0])
    3966 update_plot(handles);
    3967 
    3968 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    3969 % Scalar or image representation
    3970 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    3971 %------------------------------------------------------------------------
    3972 function num_MinA_Callback(hObject, eventdata, handles)
    3973 %------------------------------------------
    3974 set(handles.CheckFixScalar,'Value',1) %suppress auto mode
    3975 % set(handles.CheckFixScalar,'BackgroundColor',[1 1 0])
    3976 MinA=str2double(get(handles.num_MinA,'String'));
    3977 MaxA=str2double(get(handles.num_MaxA,'String'));
    3978 if MinA>MaxA% switch minA and maxA in case of error
    3979     MinA_old=MinA;
    3980     MinA=MaxA;
    3981     MaxA=MinA_old;
    3982     set(handles.num_MinA,'String',num2str(MinA,5));
    3983     set(handles.num_MaxA,'String',num2str(MaxA,5));
    3984 end
    3985 update_plot(handles);
    3986 
    3987 %------------------------------------------------------------------------
    3988 function num_MaxA_Callback(hObject, eventdata, handles)
    3989 %------------------------------------------------------------------------
    3990 set(handles.CheckFixScalar,'Value',1) %suppress auto mode
    3991 % set(handles.CheckFixScalar,'BackgroundColor',[1 1 0])
    3992 MinA=str2double(get(handles.num_MinA,'String'));
    3993 MaxA=str2double(get(handles.num_MaxA,'String'));
    3994 if MinA>MaxA% switch minA and maxA in case of error
    3995         MinA_old=MinA;
    3996     MinA=MaxA;
    3997     MaxA=MinA_old;
    3998     set(handles.num_MinA,'String',num2str(MinA,5));
    3999     set(handles.num_MaxA,'String',num2str(MaxA,5));
    4000 end
    4001 update_plot(handles);
    4002 
    4003 %------------------------------------------------------------------------
    4004 function CheckFixScalar_Callback(hObject, eventdata, handles)
    4005 %------------------------------------------------------------------------
    4006 test=get(handles.CheckFixScalar,'Value');
    4007 if test
    4008 %     set(handles.CheckFixScalar,'BackgroundColor',[1 1 0])
    4009 else
    4010 %     set(handles.CheckFixScalar,'BackgroundColor',[0.7 0.7 0.7])
    4011     update_plot(handles);
    4012 end
    4013 
    4014 %-------------------------------------------------------------------
    4015 function CheckBW_Callback(hObject, eventdata, handles)
    4016 %-------------------------------------------------------------------
    4017 update_plot(handles);
    4018 
    4019 %-------------------------------------------------------------------
    4020 function num_Opacity_Callback(hObject, eventdata, handles)
    4021 update_plot(handles);
    4022 %-------------------------------------------------------------------
    4023 
    4024 %-------------------------------------------------------------------
    4025 function ListContour_Callback(hObject, eventdata, handles)
    4026 %-------------------------------------------------------------------
    4027 val=get(handles.ListContour,'Value');
    4028 if val==2% option 'contours'
    4029     set(handles.interval_txt,'Visible','on')
    4030     set(handles.num_IncrA,'Visible','on')
    4031     set(handles.num_IncrA,'String','')% refresh contour interval
    4032 %     set(handles.opacity_txt,'Visible','off')
    4033 %     set(handles.num_Opacity,'Visible','off')
    4034 else % option 'image'
    4035     set(handles.interval_txt,'Visible','off')
    4036     set(handles.num_IncrA,'Visible','off')
    4037 %     set(handles.opacity_txt,'Visible','on')
    4038 %     set(handles.num_Opacity,'Visible','on')
    4039 end
    4040 update_plot(handles);
    4041 
    4042 %-------------------------------------------------------------------
    4043 function num_IncrA_Callback(hObject, eventdata, handles)
    4044 %-------------------------------------------------------------------
    4045 update_plot(handles);
    4046 
    4047 
    4048 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    4049 % Vector representation
    4050 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    4051 %-------------------------------------------------------------------
    4052 function CheckHideWarning_Callback(hObject, eventdata, handles)
    4053 %-------------------------------------------------------------------
    4054 update_plot(handles);
    4055 
    4056 %-------------------------------------------------------------------
    4057 function CheckHideFalse_Callback(hObject, eventdata, handles)
    4058 %-------------------------------------------------------------------
    4059 update_plot(handles);
    4060 
    4061 %-------------------------------------------------------------------
    4062 function num_VecScale_Callback(hObject, eventdata, handles)
    4063 %-------------------------------------------------------------------
    4064 set(handles.CheckFixVectors,'Value',1);
    4065 %set(handles.CheckFixVectors,'BackgroundColor',[1 1 0])
    4066 update_plot(handles);
    4067 
    4068 %-------------------------------------------------------------------
    4069 function CheckFixVectors_Callback(hObject, eventdata, handles)
    4070 %-------------------------------------------------------------------
    4071 if ~get(handles.CheckFixVectors,'Value')
    4072     update_plot(handles);
    4073 end
    4074 
    4075 %------------------------------------------------------------------------
    4076 % --- Executes on selection change in CheckDecimate4 (nb_vec/4).
    4077 %------------------------------------------------------------------------
    4078 function CheckDecimate4_Callback(hObject, eventdata, handles)
    4079 
    4080 if isequal(get(handles.CheckDecimate4,'Value'),1)
    4081     set(handles.CheckDecimate16,'Value',0)
    4082 end
    4083 update_plot(handles);
    4084 
    4085 %------------------------------------------------------------------------
    4086 % --- Executes on selection change in CheckDecimate16 (nb_vec/16).
    4087 %------------------------------------------------------------------------
    4088 function CheckDecimate16_Callback(hObject, eventdata, handles)
    4089 
    4090 if isequal(get(handles.CheckDecimate16,'Value'),1)
    4091     set(handles.CheckDecimate4,'Value',0)
    4092 end
    4093 update_plot(handles);
    4094 
    4095 %------------------------------------------------------------------------
    4096 % --- Executes on selection change in ColorCode menu
    4097 function ColorCode_Callback(hObject, eventdata, handles)
    4098 %------------------------------------------------------------------------
    4099 % edit the choice for color code
    4100 update_color_code_boxes(handles);
    4101 update_plot(handles);
    4102 
    4103 %------------------------------------------------------------------------
    4104 function update_color_code_boxes(handles)
    4105 %------------------------------------------------------------------------
    4106 list_code=get(handles.ColorCode,'String');% list menu fields
    4107 colcode= list_code{get(handles.ColorCode,'Value')}; % selected field
    4108 enable_slider='off';%default
    4109 enable_bounds='off';%default
    4110 enable_scalar='off';%default
    4111 switch colcode
    4112     case {'rgb','bgr'}
    4113         enable_slider='on';
    4114         enable_bounds='on';
    4115         enable_scalar='on';
    4116     case '64 colors'
    4117         enable_bounds='on';
    4118         enable_scalar='on';
    4119 end
    4120 set(handles.Slider1,'Visible',enable_slider)
    4121 set(handles.Slider2,'Visible', enable_slider)
    4122 set(handles.num_ColCode1,'Visible',enable_slider)
    4123 set(handles.num_ColCode2,'Visible',enable_slider)
    4124 set(handles.TitleColCode1,'Visible',enable_slider)
    4125 set(handles.TitleColCode2,'Visible',enable_slider)
    4126 set(handles.CheckFixVecColor,'Visible',enable_bounds)
    4127 set(handles.num_MinVec,'Visible',enable_bounds)
    4128 set(handles.num_MaxVec,'Visible',enable_bounds)
    4129 set(handles.ColorScalar,'Visible',enable_scalar)
    4130 set_vec_col_bar(handles)
    4131 
    4132 %------------------------------------------------------------------
    4133 % --- Executes on selection change in ColorScalar: choice of the color code.
    4134 function ColorScalar_Callback(hObject, eventdata, handles)
    4135 %------------------------------------------------------------------
    4136 % edit the choice for color code
    4137 list_scalar=get(handles.ColorScalar,'String');% list menu fields
    4138 col_scalar= list_scalar{get(handles.ColorScalar,'Value')}; % selected field
    4139 if isequal(col_scalar,'ima_cor')
    4140     set(handles.CheckFixVecColor,'Value',1)%fixed scale by default
    4141     ColorCode='rgb';
    4142     set(handles.num_MinVec,'String','0')
    4143     set(handles.num_MaxVec,'String','1')
    4144     set(handles.num_ColCode1,'String','0.333')
    4145     set(handles.num_ColCode2,'String','0.666')
    4146 else
    4147     set(handles.CheckFixVecColor,'Value',0)%auto scale between min,max by default
    4148     ColorCode='64 colors';
    4149 end
    4150 ColorCodeList=get(handles.ColorCode,'String');
    4151 ichoice=find(strcmp(ColorCode,ColorCodeList),1);
    4152 set(handles.ColorCode,'Value',ichoice)% set color code in the menu
    4153 
    4154 update_color_code_boxes(handles);
    4155 %replot the current graph
    4156 REFRESH_Callback(hObject, eventdata, handles)
    4157 
    4158 %----------------------------------------------------------------
    4159 % -- Executes on slider movement to set the color code
    4160 %
    4161 function Slider1_Callback(hObject, eventdata, handles)
    4162 %------------------------------------------------------------------
    4163 slider1=get(handles.Slider1,'Value');
    4164 min_val=str2num(get(handles.num_MinVec,'String'));
    4165 max_val=str2num(get(handles.num_MaxVec,'String'));
    4166 col=min_val+(max_val-min_val)*slider1;
    4167 set(handles.num_ColCode1,'String',num2str(col))
    4168 if(get(handles.Slider2,'Value') < col)%move also the second slider at the same value if needed
    4169     set(handles.Slider2,'Value',col)
    4170     set(handles.num_ColCode2,'String',num2str(col))
    4171 end
    4172 set_vec_col_bar(handles)
    4173 update_plot(handles);
    4174 
    4175 %----------------------------------------------------------------
    4176 % Executes on slider movement to set the color code
    4177 %----------------------------------------------------------------
    4178 function Slider2_Callback(hObject, eventdata, handles)
    4179 slider2=get(handles.Slider2,'Value');
    4180 min_val=str2num(get(handles.num_MinVec,'String'));
    4181 max_val=str2num(get(handles.num_MaxVec,'String'));
    4182 col=min_val+(max_val-min_val)*slider2;
    4183 set(handles.num_ColCode2,'String',num2str(col))
    4184 if(get(handles.Slider1,'Value') > col)%move also the first slider at the same value if needed
    4185     set(handles.Slider1,'Value',col)
    4186     set(handles.num_ColCode1,'String',num2str(col))
    4187 end
    4188 set_vec_col_bar(handles)
    4189 update_plot(handles);
    4190 
    4191 %----------------------------------------------------------------
    4192 % --- Execute on return carriage on the edit box corresponding to slider 1
    4193 %----------------------------------------------------------------
    4194 function num_ColCode1_Callback(hObject, eventdata, handles)
    4195 set_vec_col_bar(handles)
    4196 update_plot(handles);
    4197 
    4198 %----------------------------------------------------------------
    4199 % --- Execute on return carriage on the edit box corresponding to slider 2
    4200 %----------------------------------------------------------------
    4201 function num_ColCode2_Callback(hObject, eventdata, handles)
    4202 set_vec_col_bar(handles)
    4203 update_plot(handles);
    4204 %------------------------------------------------------------------------
    4205 %-------------------------------------------------------
    4206 % --- Executes on button press in CheckFixVecColor.
    4207 %-------------------------------------------------------
    4208 function VecColBar_Callback(hObject, eventdata, handles)
    4209 set_vec_col_bar(handles)
    4210 
    4211 %------------------------------------------------------------------------
    4212 % --- Executes on button press in CheckFixVecColor.
    4213 function CheckFixVecColor_Callback(hObject, eventdata, handles)
    4214 %------------------------------------------------------------------------
    4215 if ~get(handles.CheckFixVecColor,'Value')
    4216     update_plot(handles);
    4217 end
    4218 
    4219 %------------------------------------------------------------------------
    4220 % --- Executes on selection change in num_MaxVec.
    4221 function num_MinVec_Callback(hObject, eventdata, handles)
    4222 %------------------------------------------------------------------------
    4223 num_MaxVec_Callback(hObject, eventdata, handles)
    4224 
    4225 %------------------------------------------------------------------------
    4226 % --- Executes on selection change in num_MaxVec.
    4227 function num_MaxVec_Callback(hObject, eventdata, handles)
    4228 %------------------------------------------------------------------------
    4229 set(handles.CheckFixVecColor,'Value',1)
    4230 CheckFixVecColor_Callback(hObject, eventdata, handles)
    4231 min_val=str2num(get(handles.num_MinVec,'String'));
    4232 max_val=str2num(get(handles.num_MaxVec,'String'));
    4233 slider1=get(handles.Slider1,'Value');
    4234 slider2=get(handles.Slider2,'Value');
    4235 colcode1=min_val+(max_val-min_val)*slider1;
    4236 colcode2=min_val+(max_val-min_val)*slider2;
    4237 set(handles.num_ColCode1,'String',num2str(colcode1))
    4238 set(handles.num_ColCode2,'String',num2str(colcode2))
    4239 update_plot(handles);
    4240 
    4241 %------------------------------------------------------------------------
    4242 % --- update the display of color code for vectors (on vecColBar)
    4243 function set_vec_col_bar(handles)
    4244 %------------------------------------------------------------------------
    4245 %get the image of the color display button 'VecColBar' in pixels
    4246 set(handles.VecColBar,'Units','pixel');
    4247 pos_vert=get(handles.VecColBar,'Position');
    4248 set(handles.VecColBar,'Units','Normalized');
    4249 width=ceil(pos_vert(3));
    4250 height=ceil(pos_vert(4));
    4251 
    4252 %get slider indications
    4253 list=get(handles.ColorCode,'String');
    4254 ichoice=get(handles.ColorCode,'Value');
    4255 colcode.ColorCode=list{ichoice};
    4256 colcode.MinVec=str2num(get(handles.num_MinVec,'String'));
    4257 colcode.MaxVec=str2num(get(handles.num_MaxVec,'String'));
    4258 test3color=strcmp(colcode.ColorCode,'rgb') || strcmp(colcode.ColorCode,'bgr');
    4259 if test3color
    4260     colcode.ColCode1=str2num(get(handles.num_ColCode1,'String'));
    4261     colcode.ColCode2=str2num(get(handles.num_ColCode2,'String'));
    4262 end
    4263 vec_C=colcode.MinVec+(colcode.MaxVec-colcode.MinVec)*(0.5:width-0.5)/width;%sample of vec_C values from min to max
    4264 [colorlist,col_vec]=set_col_vec(colcode,vec_C);
    4265 oneheight=ones(1,height);
    4266 A1=colorlist(col_vec,1)*oneheight;
    4267 A2=colorlist(col_vec,2)*oneheight;
    4268 A3=colorlist(col_vec,3)*oneheight;
    4269 A(:,:,1)=A1';
    4270 A(:,:,2)=A2';
    4271 A(:,:,3)=A3';
    4272 set(handles.VecColBar,'Cdata',A)
    4273 
    4274 %-------------------------------------------------------------------
    4275 function update_plot(handles)
    4276 %-------------------------------------------------------------------
    4277 set(handles.REFRESH,'BackgroundColor',[1 1 0]);% display plot activity by yellow color
    4278 drawnow
    4279 UvData=get(handles.uvmat,'UserData');
    4280 AxeData=UvData.PlotAxes;% retrieve the current plotted data
    4281 PlotParam=read_GUI(handles.uvmat);
    4282 [tild,PlotParamOut]= plot_field(AxeData,handles.PlotAxes,PlotParam);
    4283 errormsg=fill_GUI(PlotParamOut,handles.uvmat);
    4284 if isempty(errormsg)
    4285     set(handles.REFRESH,'BackgroundColor',[1 0 0]);% operation finished, back to red color
    4286 else
    4287     msgbox_uvmat('ERROR',errormsg)
    4288     set(handles.REFRESH,'BackgroundColor',[1 0 1]);% magenta color: graph still needs to be updated
    4289 end
    4290 
    4291 
    4292 %------------------------------------------------------------------------
    4293 %------------------------------------------------------------------------
    4294 %   SELECTION AND EDITION OF PROJECTION OBJECTS
    4295 %------------------------------------------------------------------------
    4296 %------------------------------------------------------------------------
    4297 
    4298 % --- Executes on selection change in ListObject_1.
    4299 function ListObject_1_Callback(hObject, eventdata, handles)
    4300 list_str=get(handles.ListObject,'String');
    4301 UvData=get(handles.uvmat,'UserData');
    4302 ObjectData=UvData.ProjObject{get(handles.ListObject_1,'Value')};
    4303 
    4304 %% update the projection plot on uvmat
    4305 ProjData= proj_field(UvData.Field,ObjectData);%project the current input field on object ObjectData
    4306 plot_field(ProjData,handles.PlotAxes,read_GUI(handles.uvmat));% plot the projected field;
    4307 %replot all the objects within the new projected field
    4308 for IndexObj=1:numel(list_str)
    4309         hobject=UvData.ProjObject{IndexObj}.DisplayHandle.uvmat;
    4310         if isempty(hobject) || ~ishandle(hobject)
    4311             hobject=handles.PlotAxes;
    4312         end
    4313         if isequal(IndexObj,get(handles.ListObject,'Value'))
    4314             objectcolor='m'; %paint in magenta the currently selected object in ListObject
    4315         else
    4316             objectcolor='b';
    4317         end
    4318         UvData.ProjObject{IndexObj}.DisplayHandle.uvmat=plot_object(UvData.ProjObject{IndexObj},ObjectData,hobject,objectcolor);%draw the object in uvmat     
    4319 end
    4320 set(handles.uvmat,'UserData',UvData)
    4321 
    4322 %% display the object parameters if the GUI set_object is already opened
    4323 if ~get(handles.CheckViewObject,'Value')
    4324     ZBounds=0; % default
    4325     if isfield(UvData.Field,'ZMin') && isfield(UvData.Field,'ZMax')
    4326         ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider
    4327         ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider
    4328     end
    4329     ObjectData.Name=list_str{get(handles.ListObject_1,'Value')};
    4330     hset_object=set_object(ObjectData,[],ZBounds);
    4331     set(hset_object,'name','set_object')
    4332     set(handles.CheckViewObject,'Value',1)% show that the selected object in ListObject_1 is currently visualised
    4333 end
    4334 
    4335 %  desactivate the edit object mode
    4336 set(handles.CheckEditObject,'Value',0)
    4337 % set(handles.CheckEditObject,'BackgroundColor',[0.7,0.7,0.7])
    4338 
    4339 %------------------------------------------------------------------------
    4340 % --- Executes on selection change in ListObject.
    4341 function ListObject_Callback(hObject, eventdata, handles)
    4342 %------------------------------------------------------------------------
    4343 list_str=get(handles.ListObject,'String');
    4344 IndexObj=get(handles.ListObject,'Value');%present object selection
    4345 UvData=get(handles.uvmat,'UserData');
    4346 if numel(UvData.ProjObject)<IndexObj
    4347     return
    4348 end
    4349 ObjectData=UvData.ProjObject{IndexObj};
    4350     ZBounds=0; % default
    4351     if isfield(UvData.Field,'ZMin') && isfield(UvData.Field,'ZMax')
    4352         ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider
    4353         ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider
    4354     end
    4355 
    4356 %% show object features if view_object isselected
    4357 if get(handles.CheckViewObject,'value')
    4358     hset_object=set_object(ObjectData,[],ZBounds);
    4359     set(hset_object,'name','set_object')
    4360 end
    4361 
    4362 %%  desactivate the edit object mode for security
    4363 set(handles.CheckEditObject,'Value',0)
    4364 
    4365 %% update the  plot on view_field if view_field is already openened
    4366 hview_field=findobj(allchild(0),'tag','view_field');
    4367 if isempty(hview_field)
    4368     hhview_field.PlotAxes=[];
    4369 else
    4370     Data=get(hview_field,'UserData');
    4371     hhview_field=guidata(hview_field);
    4372     ProjData= proj_field(UvData.Field,ObjectData);%project the current interface field on ObjectData
    4373     [PlotType,PlotParam]=plot_field(ProjData,hhview_field.PlotAxes,read_GUI(hview_field));%read plotting parameters on the uvmat interface
    4374     haxes=findobj(hview_field,'tag','axes3');
    4375     pos=get(hview_field,'Position'); 
    4376     if strcmp(get(haxes,'Visible'),'off')%sempty(PlotParam.Axes)% case of no plot display (pure text table)
    4377         h_TableDisplay=findobj(hview_field,'tag','TableDisplay');
    4378         pos_table=get(h_TableDisplay,'Position');
    4379         set(hview_field,'Position',[pos(1)+pos(3)-pos_table(3) pos(2)+pos(4)-pos_table(4) pos_table(3) pos_table(4)])
    4380         drawnow% needed to change position before the next command
    4381         set(hview_field,'UserData',Data);% restore the previously stored GUI position after GUI resizing
    4382     else
    4383 %         set(hview_field,'Position',Data.GUISize)% return to the previously stored GUI position and size
    4384     end
    4385 end
    4386 
    4387 %% update the color of the graphic object representation: the selected object in magenta, others in blue
    4388 update_object_color(handles.PlotAxes,hhview_field.PlotAxes,UvData.ProjObject{IndexObj}.DisplayHandle.uvmat)
    4389 
    4390 %------------------------------------------------------------------------
    4391 %--- update the color representation of objects (indicating the selected ones)
    4392 function update_object_color(axes_uvmat,axes_view_field,DisplayHandle)
    4393 %------------------------------------------------------------------------
    4394 if isempty(axes_view_field)% case with no view_field plot
    4395 hother=[findobj(axes_uvmat,'Tag','proj_object');findobj(axes_uvmat,'Tag','DeformPoint')];%find all the proj object and deform point representations
    4396 else
    4397 hother=[findobj(axes_uvmat,'Tag','proj_object') ;findobj(axes_view_field,'Tag','proj_object');... %find all the proj object representations
    4398 findobj(axes_uvmat,'Tag','DeformPoint'); findobj(axes_view_field,'Tag','DeformPoint')];%find all the deform point representations
    4399 end
    4400 for iobj=1:length(hother)
    4401     if isequal(get(hother(iobj),'Type'),'rectangle')||isequal(get(hother(iobj),'Type'),'patch')
    4402         set(hother(iobj),'EdgeColor','b')
    4403         if isequal(get(hother(iobj),'FaceColor'),'m')
    4404             set(hother(iobj),'FaceColor','b')
    4405         end
    4406     elseif isequal(get(hother(iobj),'Type'),'image')
    4407         Acolor=get(hother(iobj),'CData');
    4408         Acolor(:,:,1)=zeros(size(Acolor,1),size(Acolor,2));
    4409         set(hother(iobj),'CData',Acolor);
    4410     else
    4411         set(hother(iobj),'Color','b')
    4412     end
    4413     set(hother(iobj),'Selected','off')
    4414 end
    4415 if ishandle(DisplayHandle)
    4416     linetype=get(DisplayHandle,'Type');
    4417     if isequal(linetype,'line')
    4418         set(DisplayHandle,'Color','m'); %set the selected object to magenta color
    4419     elseif isequal(linetype,'rectangle')
    4420         set(DisplayHandle,'EdgeColor','m'); %set the selected object to magenta color
    4421     elseif isequal(linetype,'patch')
    4422         set(DisplayHandle,'FaceColor','m'); %set the selected object to magenta color
    4423     end
    4424     SubObjectData=get(DisplayHandle,'UserData');
    4425     if isfield(SubObjectData,'SubObject') & ishandle(SubObjectData.SubObject)
    4426         for iobj=1:length(SubObjectData.SubObject)
    4427             hsub=SubObjectData.SubObject(iobj);
    4428             if isequal(get(hsub,'Type'),'rectangle')
    4429                 set(hsub,'EdgeColor','m'); %set the selected object to magenta color
    4430             elseif isequal(get(hsub,'Type'),'image')
    4431                 Acolor=get(hsub,'CData');
    4432                 Acolor(:,:,1)=Acolor(:,:,3);
    4433                 set(hsub,'CData',Acolor);
    4434             else
    4435                 set(hsub,'Color','m')
    4436             end
    4437         end
    4438     end
    4439     if isfield(SubObjectData,'DeformPoint') & ishandle(SubObjectData.DeformPoint)
    4440         set(SubObjectData.DeformPoint,'Color','m')
    4441     end
    4442 end
    4443 
    4444 %-------------------------------------------------------------------
    4445 % --- Executes on selection change in CheckEditObject.
    4446 function CheckEditObject_Callback(hObject, eventdata, handles)
    4447 %-------------------------------------------------------------------
    4448 hset_object=findobj(allchild(0),'Tag','set_object');
    4449 if get(handles.CheckEditObject,'Value')
    4450     %suppress the other options
    4451     set(handles.MenuObject,'checked','off')
    4452     set(handles.CheckZoom,'Value',0)
    4453     CheckZoom_Callback(hObject, eventdata, handles)
    4454     hgeometry_calib=findobj(allchild(0),'tag','geometry_calib');
    4455     if ishandle(hgeometry_calib)
    4456         hhgeometry_calib=guidata(hgeometry_calib);
    4457         set(hhgeometry_calib.CheckEnableMouse,'Value',0)% desactivate mouse action in geometry_calib
    4458         set(hhgeometry_calib.CheckEnableMouse,'BackgroundColor',[0.7 0.7 0.7])
    4459     end
    4460     set(handles.CheckViewObject,'value',1)
    4461     CheckViewObject_Callback(hObject, eventdata, handles)
    4462 else % desactivate object edit mode
    4463     if ~isempty(hset_object)% open the
    4464         set(get(hset_object,'children'),'Enable','off')
    4465         hSAVE=findobj(hset_object,'Tag','SAVE');
    4466         set(hSAVE,'Enable','on')
    4467     end
    4468 end
    4469 
    4470 
    4471 %------------------------------------------------------------------------
    4472 % --- Executes on button press in CheckViewObject.
    4473 function CheckViewObject_Callback(hObject, eventdata, handles)
    4474 %------------------------------------------------------------------------
    4475 check_view=get(handles.CheckViewObject,'Value');
    4476 
    4477 if check_view %activate set_object   
    4478     IndexObj=get(handles.ListObject,'Value');
    4479     list_object=get(handles.ListObject,'String');
    4480     UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
    4481     UvData.ProjObject{IndexObj}.Name=list_object{IndexObj};
    4482     if numel(UvData.ProjObject)<IndexObj;% error in UvData
    4483         msgbox_uvmat('ERROR','invalid object list')
    4484         return
    4485     end
    4486     ZBounds=0; % default
    4487     if isfield(UvData.Field,'ZMin') && isfield(UvData.Field,'ZMax')
    4488         ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider
    4489         ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider
    4490     end
    4491     data=UvData.ProjObject{IndexObj};
    4492     if ~isfield(data,'Type')% default plane
    4493         data.Type='plane';
    4494     end
    4495     hset_object=set_object(data,[],ZBounds);
    4496     set(hset_object,'name','set_object')
    4497     hhset_object=guidata(hset_object);
    4498     if get(handles.CheckEditObject,'Value')% edit mode
    4499         set(get(hset_object,'children'),'Enable','on')
    4500     else
    4501         set(get(hset_object,'children'),'Enable','off')% deactivate the GUI except SAVE
    4502         set(hhset_object.SAVE,'Enable','on')
    4503     end
    4504 else
    4505     hset_object=findobj(allchild(0),'tag','set_object');
    4506     if ~isempty(hset_object)
    4507         delete(hset_object)% delete existing version of set_object
    4508     end
    4509 end
    4510  
    4511 
    4512 %------------------------------------------------------------------------
    4513 % --- Executes on button press in CheckViewField.
    4514 function CheckViewField_Callback(hObject, eventdata, handles)
    4515 %------------------------------------------------------------------------
    4516 check_view=get(handles.CheckViewField,'Value');
    4517 
    4518 if check_view
    4519     IndexObj=get(handles.ListObject,'Value');
    4520     UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
    4521     if numel(UvData.ProjObject)<IndexObj(end);% error in UvData
    4522         msgbox_uvmat('ERROR','invalid object list')
    4523         return
    4524     end
    4525     ZBounds=0; % default
    4526     if isfield(UvData.Field,'ZMin') && isfield(UvData.Field,'ZMax')
    4527         ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider
    4528         ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider
    4529     end
    4530     set(handles.ListObject,'Value',IndexObj);%restore ListObject selection after set_object deletion
    4531     if ~isfield(UvData.ProjObject{IndexObj(1)},'Type')% default plane
    4532         UvData.ProjObject{IndexObj(1)}.Type='plane';
    4533     end
    4534     list_object=get(handles.ListObject,'String');
    4535     UvData.ProjObject{IndexObj(end)}.Name=list_object{IndexObj(end)};
    4536    
    4537     %% show the projection of the selected object on view_field
    4538     ProjData= proj_field(UvData.Field,UvData.ProjObject{IndexObj});%project the current field on ObjectData
    4539     hview_field=findobj(allchild(0),'tag','view_field');
    4540     if isempty(hview_field)
    4541         hview_field=view_field;
    4542     end
    4543     hhview_field=guidata(hview_field);
    4544     [PlotType,PlotParam]=plot_field(ProjData,hhview_field.PlotAxes,read_GUI(hview_field));%read plotting parameters on the GUI view_field);
    4545     errormsg=fill_GUI(PlotParam,hview_field);
    4546     for list={'Scalar','Vectors'}
    4547         if ~isfield(PlotParam,list{1})
    4548             set(hhview_field.(list{1}),'Visible','off')
    4549         end
    4550     end
    4551     haxes=findobj(hview_field,'tag','axes3');
    4552     pos=get(hview_field,'Position');
    4553     if strcmp(get(haxes,'Visible'),'off')%sempty(PlotParam.Axes)% case of no plot display (pure text table)
    4554         h_TableDisplay=findobj(hview_field,'tag','TableDisplay');
    4555         pos_table=get(h_TableDisplay,'Position');
    4556         set(hview_field,'Position',[pos(1)+pos(3)-pos_table(3) pos(2)+pos(4)-pos_table(4) pos_table(3) pos_table(4)])
    4557     else
    4558         Data=get(hview_field,'UserData');
    4559     end
    4560 else
    4561     hview_field=findobj(allchild(0),'tag','view_field');
    4562     if ~isempty(hview_field)
    4563         delete(hview_field)% delete existing version of set_object
    4564     end
    4565 end
    4566 
    4567 
    4568 %------------------------------------------------------------------------
    4569 % --- Executes on button press in DeleteObject.
    4570 %------------------------------------------------------------------------
    4571 function DeleteObject_Callback(hObject, eventdata, handles)
    4572 
    4573 IndexObj=get(handles.ListObject,'Value');%projection object selected for view_field
    4574 IndexObj_1=get(handles.ListObject_1,'Value');%projection object selected for uvmat plot
    4575 if IndexObj>1 && ~isequal(IndexObj,IndexObj_1) % do not delete the object used for the uvmat plot
    4576     delete_object(IndexObj)
    4577 end
    4578 
    4579 %'DeleteObject': delete a projection object, defined by its index in the Uvmat list or by its graphic handle
    4580 %------------------------------------------------------------------------
    4581 % function DeleteObject(hObject)
    4582 %
    4583 % INPUT:
    4584 % hObject: object index (if integer) or handle of the graphic object. If
    4585 %          hObject is a subobject, the parent object is detected and deleted.
    4586 
    4587 function delete_object(IndexObj)
    4588 
    4589 huvmat=findobj('tag','uvmat');%handles of the uvmat interface
    4590 UvData=get(huvmat,'UserData');
    4591 hlist_object=findobj(huvmat,'Tag','ListObject');%handles of the object list in the uvmat interface
    4592 list_str=get(hlist_object,'String');%objet list
    4593 if  ~isempty(UvData) && isfield(UvData, 'ProjObject') && length(UvData.ProjObject)>=IndexObj
    4594     if isfield(UvData.ProjObject{IndexObj},'DisplayHandle') && isfield(UvData.ProjObject{IndexObj}.DisplayHandle,'uvmat')
    4595         hdisplay=UvData.ProjObject{IndexObj}.DisplayHandle.uvmat;%handle of the object graphic representation in uvmat
    4596         for iview=1:length(hdisplay)
    4597             if ishandle(hdisplay(iview)) && ~isequal(hdisplay(iview),0)
    4598                 ObjectData=get(hdisplay(iview),'UserData');
    4599                 if isfield(ObjectData,'SubObject') && ~isempty(ObjectData.SubObject)
    4600                     delete(ObjectData.SubObject(ishandle(ObjectData.SubObject)));% delete the graphic 'sub-objects (e.g. projection bounds)
    4601                 end
    4602                 if isfield(ObjectData,'DeformPoint')&& ~isempty(ObjectData.DeformPoint)
    4603                     delete(ObjectData.DeformPoint(ishandle(ObjectData.DeformPoint)));% delete the graphic deformation points
    4604                     delete(hdisplay(iview))% delete the main graphic representation of the object
    4605                 end
    4606             end
    4607             ishandle(hdisplay(iview))
    4608         end
    4609         for iobj=IndexObj+1:length(UvData.ProjObject)
    4610             hdisplay=UvData.ProjObject{iobj}.DisplayHandle.uvmat;
    4611             for iview=1:length(hdisplay)
    4612                 if ishandle(hdisplay(iview)) && ~isequal(hdisplay(iview),0)
    4613                     PlotData=get(hdisplay(iview),'UserData');
    4614                     PlotData.IndexObj=iobj-1;
    4615                     set(hdisplay(iview),'UserData',PlotData);
    4616                 end
    4617             end
    4618         end
    4619     end
    4620     UvData.ProjObject(IndexObj)=[];
    4621 end
    4622 if numel(list_str)>=IndexObj
    4623     list_str(IndexObj)=[];
    4624 end
    4625 set(huvmat,'UserData',UvData);
    4626 set(hlist_object,'String',list_str)
    4627 set(hlist_object,'Value',length(list_str))
    4628 hlist_object_1=findobj(huvmat,'Tag','ListObject_1');%handles of the first object list in the uvmat interface
    4629 old_index=get(hlist_object_1,'Value');
    4630 set(hlist_object_1,'String',list_str)
    4631 if IndexObj<=old_index
    4632     set(hlist_object_1,'Value',old_index-1)
    4633 end
    4634 
    4635 %------------------------------------------------------------------------
    4636 %------------------------------------------------------------------------
    4637 %  II - TOOLS FROM THE UPPER MENU BAR
    4638 %------------------------------------------------------------------------
    4639 %------------------------------------------------------------------------
     548        display_file_name(handles,fileinput)
     549    end
     550end
     551set(handles.MenuOpenCampaign,'ForegroundColor',[0 0 0])
     552
    4640553
    4641554%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     
    4862775msgbox_uvmat('CONFIRMATION',{['movie ' MovieName ' created '];['with ' num2str(FrameNumber) ' frames']})
    4863776
    4864 
    4865777%------------------------------------------------------------------------
    4866778% function called by pressing APPLY in the GUI  set_slices
     
    4868780%------------------------------------------------------------------------   
    4869781delete(hObject)
    4870 %
    4871 %
    4872 %
    4873 %  %read the current input file name
    4874 % prompt = {'movie file name';'frames per second';'frame resolution (*[512x384] pixels)';'axis position relative to the frame';'total frame number (starting from the current uvmat display)'};
    4875 % dlg_title = 'select properties of the output avi movie';
    4876 % num_lines= 1;
    4877 % def     = {[FileBase '_out.avi'];'10';'1';'[0.05 0.07 0.9 0.9]';'10'};
     782
    4878783
    4879784%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     
    56321537series('ActionName_Callback',hObject,eventdata,hhseries); %file input with xml reading  in uvmat, show the image in phys coordinates
    56331538
    5634 
    56351539%------------------------------------------------------------------------
    56361540% -- open the GUI civ.fig for PIV
     
    56411545civ(FileName);% interface de civ(not in the uvmat file)
    56421546
    5643 % function Param=read_param(handles)
    5644 %     
    5645 % [RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles);
    5646 % Param.FileName=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt];%first input file name
    5647 % if isequal(get(handles.SubField,'Value'),1)
    5648 %     [RootPath_1,SubDir_1,RootFile_1,FileIndex_1,FileExt_1]=read_file_boxes_1(handles);
    5649 %     FileName_1=[fullfile(RootPath_1,SubDir_1,RootFile_1) FileIndex_1 FileExt_1];
    5650 %     if ~isequal(FileName_1,Param.FileName)
    5651 %         Param.FileName_1=FileName_1;%second input file name if relevant
    5652 %     end
    5653 % end
    5654 % Param.NomType=get(handles.NomType,'String');
    5655 % Param.NomType_1=get(handles.NomType_1,'String');
    5656 % Param.CheckFixPair=get(handles.CheckFixPair,'Value');
    5657 % UvData=get(handles.uvmat,'UserData');
    5658 % if isfield(UvData,'XmlData')&& isfield(UvData.XmlData{1},'Time')
    5659 %     Param.Time=UvData.XmlData{1}.Time;
    5660 % end
    5661 % if isequal(get(handles.scan_i,'Value'),1)
    5662 %     Param.incr_i=str2num(get(handles.num_IndexIncrement,'String'));
    5663 % elseif isequal(get(handles.scan_j,'Value'),1)
    5664 %     Param.incr_j=str2num(get(handles.num_IndexIncrement,'String'));
    5665 % end
    5666 %
    5667 % %% transfer fields and coordinate names
    5668 % Param.list_fields=get(handles.FieldName,'String');% list menu fields
    5669 % FieldName=Param.list_fields{get(handles.FieldName,'Value')};
    5670 % ind_image=find(strcmp('image',Param.list_fields));
    5671 % if ~isempty(ind_image) && numel(Param.list_fields)>1
    5672 %     Param.list_fields(ind_image)=[]; %suppress  'image' option
    5673 % end
    5674 % Param.index_fields=find(strcmp(FieldName,Param.list_fields));% selected string index
    5675 % Param.list_fields_1=get(handles.FieldName_1,'String');% list menu fields
    5676 % if ischar(Param.list_fields_1),Param.list_fields_1={Param.list_fields_1};end
    5677 % FieldName_1=Param.list_fields_1{get(handles.FieldName_1,'Value')};
    5678 % ind_image=find(strcmp('image',Param.list_fields_1));
    5679 % if ~isempty(ind_image) && numel(Param.list_fields_1)>1
    5680 %     Param.list_fields_1(ind_image)=[]; %suppress  'image' option
    5681 % end
    5682 % Param.index_fields_1=find(strcmp(FieldName_1,Param.list_fields_1));% selected string index
    5683 % TransformList=get(handles.TransformName,'String');
    5684 % Param.TransformName=TransformList{get(handles.TransformName,'Value')};
    5685 % Param.Coord_x_str=get(handles.Coord_x,'String');
    5686 % %Param.Coord_x_val=get(handles.Coord_x,'Value');
    5687 % Param.Coord_y_str=get(handles.Coord_y,'String');
    5688 
     1547%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     1548% MenuHelp Callback
     1549%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    56891550% --------------------------------------------------------------------
    56901551function MenuHelp_Callback(hObject, eventdata, handles)
     
    56921553web('http://servforge.legi.grenoble-inp.fr/projects/soft-uvmat/wiki/UvmatHelp')
    56931554
    5694 % path_to_uvmat=which ('uvmat');% check the path of uvmat
    5695 % pathelp=fileparts(path_to_uvmat);
    5696 % helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
    5697 % if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
     1555
     1556
     1557
     1558
     1559
     1560
     1561
     1562
     1563
     1564%------------------------------------------------------------------------
     1565% --- Called by action in FileIndex edit box
     1566function FileIndex_Callback(hObject, eventdata, handles)
     1567%------------------------------------------------------------------------
     1568[tild,tild,tild,i1,i2,j1,j2]=fileparts_uvmat(get(handles.FileIndex,'String'));
     1569set(handles.i1,'String',num2str(i1));%update the counters
     1570set(handles.i2,'String',num2str(i2));
     1571set(handles.j1,'String',num2str(j1));
     1572set(handles.j2,'String',num2str(j2));
     1573
     1574
     1575%------------------------------------------------------------------------
     1576% --- Called by action in NomType edit box
     1577function NomType_Callback(hObject, eventdata, handles)
     1578%------------------------------------------------------------------------
     1579i1=str2num(get(handles.i1,'String'));
     1580i2=str2num(get(handles.i2,'String'));
     1581j1=str2num(get(handles.j1,'String'));
     1582j2=str2num(get(handles.j2,'String'));
     1583FileIndex=fullfile_uvmat('','','','',get(handles.NomType,'String'),i1,i2,j1,j2);
     1584set(handles.FileIndex,'String',FileIndex)
     1585% refresh the current settings and refresh the field view
     1586RootPath_Callback(hObject,eventdata,handles)
     1587
     1588%------------------------------------------------------------------------
     1589% --- Called by action in NomType edit box
     1590function NomType_1_Callback(hObject, eventdata, handles)
     1591%------------------------------------------------------------------------
     1592i1=str2num(get(handles.i1,'String'));
     1593i2=str2num(get(handles.i2,'String'));
     1594j1=str2num(get(handles.j1,'String'));
     1595j2=str2num(get(handles.j2,'String'));
     1596FileIndex=fullfile_uvmat('','','','',get(handles.NomType_1,'String'),i1,i2,j1,j2);
     1597set(handles.FileIndex_1,'String',FileIndex)
     1598% inputfilerefresh the current settings and inputfilerefresh the field view
     1599RootPath_1_Callback(hObject,eventdata,handles)
     1600
     1601%------------------------------------------------------------------------
     1602% --- Executes on button press in InputFileREFRESH.
     1603function InputFileREFRESH_Callback(hObject, eventdata, handles)
     1604%------------------------------------------------------------------------
     1605set(handles.InputFileREFRESH,'BackgroundColor',[1 1 0])% set button color to yellow to indicate that refresh is under action
     1606set(handles.uvmat,'Pointer','watch') % set the mouse pointer to 'watch'
     1607drawnow
     1608% read the current input file name:
     1609[RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles);
     1610% detect the file type, get the movie object if relevant, and look for the corresponding file series:
     1611[RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,tild,FileInfo,MovieObject]=find_file_series(fullfile(RootPath,SubDir),[RootFile FileIndices FileExt]);
     1612if isempty(i1_series)
     1613    fileinput=uigetfile_uvmat('pick an input file',fullfile(RootPath,SubDir));
     1614    hh=dir(fileinput);
     1615    if numel(hh)>1
     1616        msgbox_uvmat('ERROR','invalid input, probably a broken link');
     1617    else
     1618        %% display the selected field and related information
     1619        if isempty(fileinput)
     1620            errormsg='aborted';
     1621        else
     1622            display_file_name(handles,fileinput,1)
     1623        end
     1624    end
     1625else
     1626    % initiate the input file series and refresh the current field view:
     1627    errormsg=update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileInfo,MovieObject,1);
     1628end
     1629
     1630%% refresh the second series if relevant
     1631if ~isempty(errormsg) && get(handles.SubField,'Value')
     1632    [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes_1(handles);
     1633    % detect the file type, get the movie object if relevant, and look for the corresponding file series:
     1634    [RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,tild,FileInfo,MovieObject]=find_file_series(fullfile(RootPath,SubDir),[RootFile FileIndices FileExt]);
     1635    if isempty(i1_series)
     1636        fileinput=uigetfile_uvmat('pick an input file for the second line',fullfile(RootPath,SubDir));
     1637        hh=dir(fileinput);
     1638        if numel(hh)>1
     1639            msgbox_uvmat('ERROR','invalid input, probably a broken link');
     1640        else
     1641            %% display the selected field and related information
     1642            if isempty(fileinput)
     1643                errormsg='aborted';
     1644            else
     1645                display_file_name(handles,fileinput,2)
     1646            end
     1647        end
     1648    else
     1649        % initiate the input file series and inputfilerefresh the current field view:
     1650        errormsg=update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileInfo,MovieObject,2);
     1651    end
     1652end
     1653if ~isempty(errormsg)
     1654    set(handles.InputFileREFRESH,'BackgroundColor',[1 0 1])% put back button color to magenta, input not succesfull
     1655end
     1656set(handles.uvmat,'Pointer','arrow')% set back the mouse pointer to arrow
     1657
     1658%------------------------------------------------------------------------
     1659% --- Fills the edit boxes RootPath, RootFile,NomType...from an input file name 'fileinput'
     1660function errormsg=display_file_name(handles,fileinput,index)
     1661%------------------------------------------------------------------------
     1662%% look for the input file existence
     1663errormsg='';%default
     1664if ~exist(fileinput,'file')
     1665    errormsg=['input file ' fileinput  ' does not exist'];
     1666    msgbox_uvmat('ERROR',errormsg)
     1667    return
     1668end
     1669
     1670%% define the relevant handles for the first field series (index=1) or the second file series (index=2)
     1671if ~exist('index','var')
     1672    index=1;
     1673end
     1674if index==1
     1675    handles_RootPath=handles.RootPath;
     1676    handles_SubDir=handles.SubDir;
     1677    handles_RootFile=handles.RootFile;
     1678    handles_FileIndex=handles.FileIndex;
     1679    handles_NomType=handles.NomType;
     1680    handles_FileExt=handles.FileExt;
     1681elseif index==2
     1682    handles_RootPath=handles.RootPath_1;
     1683    handles_SubDir=handles.SubDir_1;
     1684    handles_RootFile=handles.RootFile_1;
     1685    handles_FileIndex=handles.FileIndex_1;
     1686    handles_NomType=handles.NomType_1;
     1687    handles_FileExt=handles.FileExt_1;
     1688    set(handles.RootPath_1,'Visible','on')
     1689    set(handles.RootFile_1,'Visible','on')
     1690    set(handles.SubDir_1,'Visible','on');
     1691    set(handles.FileIndex_1,'Visible','on');
     1692    set(handles.FileExt_1,'Visible','on');
     1693    set(handles.NomType_1,'Visible','on');
     1694    set(handles.TimeName_1,'Visible','on')
     1695    set(handles.TimeValue_1,'Visible','on')
     1696end
     1697set(handles.InputFileREFRESH,'BackgroundColor',[1 1 0])% paint REFRESH button to yellow to visualise root file input
     1698set(handles.uvmat,'Pointer','watch') % set the mouse pointer to 'watch'
     1699drawnow
     1700
     1701%% detect root name, nomenclature and indices in the input file name:
     1702[FilePath,FileName,FileExt]=fileparts(fileinput);
     1703% detect the file type, get the movie object if relevant, and look for the corresponding file series:
     1704% the root name and indices may be corrected by including the first index i1 if a corresponding xml file exists
     1705[RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,NomType,FileInfo,MovieObject,i1,i2,j1,j2]=find_file_series(FilePath,[FileName FileExt]);
     1706FileType=FileInfo.FileType;
     1707if strcmp(FileType,'txt')
     1708    try
     1709        edit(fileinput)
     1710    catch ME
     1711        msgbox_uvmat('ERROR','invalid intput file')
     1712    end
     1713    return
     1714elseif strcmp(FileType,'xml')
     1715    editxml(fileinput)
     1716     return
     1717elseif strcmp(FileType,'figure')
     1718    open(fileinput)
     1719     return
     1720end
     1721
     1722%% open the file or fill the GUI uvmat according to the detected file type
     1723switch FileType
     1724    case ''
     1725        msgbox_uvmat('ERROR','invalid input file type')
     1726    case 'txt'
     1727        edit(fileinput)
     1728    case 'figure'                           %display matlab figure
     1729        hfig=open(fileinput);
     1730        set(hfig,'WindowButtonMotionFcn','mouse_motion')%set mouse action functio
     1731        set(hfig,'WindowButtonUpFcn','mouse_up')%set mouse click action function
     1732        set(hfig,'WindowButtonUpFcn','mouse_down')%set mouse click action function
     1733    case 'xml'                % edit xml files
     1734        t=xmltree(fileinput);
     1735        % the xml file marks a project or project link, open datatree_browser
     1736        if strcmp(get(t,1,'name'),'Project')&& exist(regexprep(fileinput,'.xml$',''),'dir')
     1737            datatree_browser(fileinput)
     1738        else % other xml file, open the xml editor
     1739            editxml(fileinput);
     1740        end
     1741    case 'xls'% Excel file opended by editxml
     1742        editxml(fileinput);
     1743    otherwise
     1744        set(handles_RootPath,'String',RootPath);
     1745        rootname=fullfile(RootPath,SubDir,RootFile);
     1746        set(handles_SubDir,'String',['/' SubDir]);
     1747        set(handles_RootFile,'String',['/' RootFile]); %display the separator
     1748        indices=fileinput(length(rootname)+1:end);
     1749        indices(end-length(FileExt)+1:end)=[]; %remove extension
     1750        set(handles_FileIndex,'String',indices);
     1751        set(handles_NomType,'String',NomType);
     1752        set(handles_FileExt,'String',FileExt);
     1753        if index==1
     1754            % fill file index counters if the first file series is opened
     1755            set(handles.i1,'String',num2str(i1));
     1756            set(handles.i2,'String',num2str(i2));
     1757            set(handles.j1,'String',num2stra(j1,NomType));
     1758            set(handles.j2,'String',num2stra(j2,NomType));
     1759        else %read the current field index to synchronise with the first series
     1760            i1_s=str2num(get(handles.i1,'String'));
     1761            i2_0=str2num(get(handles.i2,'String'));
     1762            if ~isempty(i2_0)
     1763                i2_s=i2_0;
     1764            else
     1765               i2_s=i2;
     1766            end
     1767            j1_0=stra2num(get(handles.j1,'String'));
     1768            if ~isempty(j1_0)
     1769                j1_s=j1_0;
     1770            else
     1771                j1_s=j1;
     1772            end
     1773            j2_0=stra2num(get(handles.j2,'String'));
     1774            if ~isempty(j2_0)
     1775                j2_s=j2_0;
     1776            else
     1777                j2_s=j2;
     1778            end
     1779        end
     1780       
     1781        % synchronise indices of the second  input file if it exists
     1782        if get(handles.SubField,'Value')==1% if the subfield button is activated, update the field numbers
     1783            Input=read_GUI(handles.InputFile);
     1784            if ~isfield(Input,'RootPath_1')||strcmp(Input.RootPath_1,'"')
     1785                Input.RootPath_1=Input.RootPath;
     1786            end
     1787            if ~isfield(Input,'SubDir_1')||strcmp(Input.SubDir_1,'"')
     1788                Input.SubDir_1=Input.SubDir;
     1789            end
     1790            if ~isfield(Input,'RootFile_1')||strcmp(Input.RootFile_1,'"')
     1791                Input.RootFile_1=Input.RootFile;
     1792            end
     1793            if ~isfield(Input,'FileExt_1')||strcmp(Input.FileExt_1,'"')
     1794                Input.FileExt_1=Input.FileExt;
     1795            end
     1796            if ~isfield(Input,'NomType_1')||strcmp(Input.NomType_1,'"')
     1797                Input.NomType_1=Input.NomType;
     1798            end
     1799            %updtate the indices of the second field series to correspond to the newly opened one
     1800            FileName_1=fullfile_uvmat(Input.RootPath_1,Input.SubDir_1,Input.RootFile_1,Input.FileExt_1,Input.NomType_1,i1_s,i2_s,j1_s,j2_s);
     1801            if exist(FileName_1,'file')
     1802                FileIndex_1=fullfile_uvmat('','','','',Input.NomType_1,i1_s,i2_s,j1_s,j2_s);
     1803            else
     1804                FileIndex_1=fullfile_uvmat('','','','',Input.NomType_1,i1,i2,j1,j2);
     1805                msgbox_uvmat('WARNING','unable to synchronise the indices of the two series')
     1806            end
     1807            set(handles.FileIndex_1,'String',FileIndex_1)
     1808        end
     1809       
     1810        %enable other menus
     1811        set(handles.MenuOpenCampaign,'Enable','on')
     1812        set(handles.MenuExport,'Enable','on')
     1813        set(handles.MenuExportFigure,'Enable','on')
     1814        set(handles.MenuExportMovie,'Enable','on')
     1815        set(handles.MenuTools,'Enable','on')
     1816
     1817        % initiate input file series and inputfilerefresh the current field view:     
     1818        update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileInfo,MovieObject,index);
     1819
     1820end
     1821
     1822%% update list of recent files in the menubar and save it for future opening
     1823MenuFile=[{get(handles.MenuFile_1,'Label')};{get(handles.MenuFile_2,'Label')};...
     1824    {get(handles.MenuFile_3,'Label')};{get(handles.MenuFile_4,'Label')};{get(handles.MenuFile_5,'Label')}];
     1825str_find=strcmp(fileinput,MenuFile);
     1826if isempty(find(str_find,1))
     1827    MenuFile=[{fileinput};MenuFile];%insert the current file if not already in the list
     1828end
     1829for ifile=1:min(length(MenuFile),5)
     1830    set(handles.(['MenuFile_' num2str(ifile)]),'Label',MenuFile{ifile});
     1831    %set(handles.(['MenuFile_' num2str(ifile) '_1']),'Label',MenuFile{ifile});
     1832end
     1833dir_perso=prefdir;
     1834profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
     1835if exist(profil_perso,'file')
     1836    save (profil_perso,'MenuFile','RootPath','-append'); %store the file names for future opening of uvmat
     1837else
     1838    save (profil_perso,'MenuFile','RootPath','-V6'); %store the file names for future opening of uvmat
     1839end
     1840
     1841set(handles.InputFileREFRESH,'BackgroundColor',[1 0 0])% paint back button to red to indicate update is finished
     1842set(handles.uvmat,'Pointer','arrow')% set back the mouse pointer to arrow
     1843
     1844
     1845%------------------------------------------------------------------------
     1846% --- Update information about a new field series (indices to scan, timing,
     1847%     calibration from an xml file, then inputfilerefresh current plots
     1848function errormsg=update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileInfo,VideoObject,index)
     1849%------------------------------------------------------------------------
     1850errormsg=''; %default error msg
     1851
     1852%% define the relevant handles depending on the index (1=first file series, 2= second file series)
     1853if ~exist('index','var')
     1854    index=1;
     1855end
     1856if index==1
     1857    handles_Fields=handles.FieldName;
     1858elseif index==2
     1859    handles_Fields=handles.FieldName_1;
     1860end
     1861set(handles.FixVelType,'Value',0); %desactivate fixed veltype by default
     1862
     1863%% record info in UserData of the figure uvmat
     1864UvData=get(handles.uvmat,'UserData');%huvmat=handles of the uvmat interface
     1865UvData.NewSeries=1; %flag for REFRESH: begin a new series
     1866UvData.FileName_1='';% name of the current second field (used to detect a  constant field during file scanning)
     1867UvData.FileType{index}=FileInfo.FileType;
     1868UvData.FileInfo{index}=FileInfo;
     1869UvData.MovieObject{index}=VideoObject;
     1870UvData.i1_series{index}=i1_series;
     1871UvData.i2_series{index}=i2_series;
     1872UvData.j1_series{index}=j1_series;
     1873UvData.j2_series{index}=j2_series;
     1874
     1875%% read timing and total frame number from the current file (e.g. movie files)
     1876TimeUnit='';%default
     1877TimeName='';%default
     1878XmlData.Time=[];%default
     1879ColorType='falsecolor'; %default
     1880if isfield(FileInfo,'FrameRate')% frame rate given in the file (case of video data)
     1881    TimeUnit='s';
     1882    if isempty(j1_series); %frame index along i
     1883        XmlData.Time=zeros(FileInfo.NumberOfFrames+1,2);
     1884        XmlData.Time(:,2)=(0:1/FileInfo.FrameRate:(FileInfo.NumberOfFrames)/FileInfo.FrameRate)';
     1885    else
     1886        XmlData.Time=[0;ones(size(i1_series,3)-1,1)]*(0:1/FileInfo.FrameRate:(FileInfo.NumberOfFrames)/FileInfo.FrameRate);
     1887    end
     1888    if strcmp(FileInfo.FileType,'rdvision')
     1889        TimeName='timestamp';
     1890    else
     1891    TimeName='video';
     1892    end
     1893end
     1894if isfield(FileInfo,'ColorType')
     1895    ColorType=FileInfo.ColorType;%='truecolor' for color images
     1896end
     1897set(handles.CheckBW,'Value',strcmp(ColorType,'grayscale'))% select handles.CheckBW if grayscale image
     1898
     1899%% read parameters (time, geometric calibration..) from a documentation file (.xml advised)
     1900XmlData.GeometryCalib=[];%default
     1901if index==1
     1902    [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles);
     1903else
     1904    [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes_1(handles);
     1905end
     1906XmlFileName=find_imadoc(RootPath,SubDir,RootFile,FileExt);
     1907[tild,tild,DocExt]=fileparts(XmlFileName);
     1908warntext='';%default warning message
     1909NbSlice=1;%default
     1910ImaDoc_str='';
     1911if ~isempty(XmlFileName)
     1912    set(handles.view_xml,'Visible','on')
     1913    set(handles.view_xml,'BackgroundColor',[1 1 0])% paint  to yellow color to indicate reading of the xml file
     1914    set(handles.view_xml,'String','view .xml')
     1915    drawnow
     1916    [XmlDataRead,warntext]=imadoc2struct(XmlFileName);
     1917    if ~isempty(warntext)
     1918        msgbox_uvmat('WARNING',warntext)
     1919    end
     1920    if ~isempty(XmlDataRead)
     1921        ImaDoc_str=['view ' DocExt];  % DocExt= '.xml' or .civ (obsolete case)
     1922        if isfield(XmlDataRead,'TimeUnit')&& ~isempty(XmlDataRead.TimeUnit)
     1923            TimeUnit=XmlDataRead.TimeUnit;
     1924        end
     1925        if isfield(XmlDataRead,'Time')&& ~isempty(XmlDataRead.Time)
     1926            XmlData.Time=XmlDataRead.Time;
     1927        end
     1928        set(handles.view_xml,'BackgroundColor',[1 1 1])% paint back to white
     1929        drawnow
     1930        if isfield(XmlDataRead, 'GeometryCalib') && ~isempty(XmlDataRead.GeometryCalib)
     1931            XmlData.GeometryCalib=XmlDataRead.GeometryCalib;
     1932            if isfield(XmlData.GeometryCalib,'CheckVolumeScan') && isequal(XmlData.GeometryCalib.CheckVolumeScan,1)
     1933                set (handles.slices,'String','volume')
     1934            end
     1935            % check whether the GUI geometry_calib is opened
     1936            hgeometry_calib=findobj('tag','geometry_calib');
     1937            if ~isempty(hgeometry_calib) % check whether the display of the GUI geometry_calib is consistent with the current calib param
     1938                GUserData=get(hgeometry_calib,'UserData');
     1939                if ~(isfield(GUserData,'XmlInputFile') && strcmp(GUserData.XmlInputFile,XmlFileName))
     1940                    answer=msgbox_uvmat('INPUT_Y-N','refresh the display of the GUI geometry_calib with the new input data?');
     1941                    if strcmp(answer,'Yes')
     1942                        geometry_calib(XmlFileName);%diplay the new calibration points and parameters in geometry_calib
     1943                    end
     1944                end
     1945            end
     1946        end
     1947    end
     1948end
     1949if isempty(ImaDoc_str)
     1950    set(handles.view_xml,'Visible','off') % no .xml (or .civ) file detected
     1951else
     1952    set(handles.view_xml,'String',ImaDoc_str)% indicate that a xml file has been detected
     1953end
     1954
     1955%% Define timing
     1956% time not set by the input file: images or civ data: indicate that time is read from the xml file
     1957FileType=FileInfo.FileType;
     1958if isfield(XmlData,'Time')&& ~isempty(XmlData.Time) && ...
     1959        (strcmp(FileType,'image')|| strcmp(FileType,'multimage'))%||strcmp(FileType,'civdata')||strcmp(FileType,'civx'))
     1960    TimeName='xml';
     1961elseif strcmp(FileType,'civdata')
     1962    TimeName='civdata';
     1963elseif strcmp(FileType,'civx')
     1964    TimeName='civx';
     1965end
     1966if index==1
     1967    set(handles.TimeName,'String',TimeName)
     1968else
     1969    set(handles.TimeName_1,'String',TimeName)
     1970    set(handles.TimeName_1,'Visible','on')
     1971end
     1972
     1973%% store last index in handles.MaxIndex_i and .MaxIndex_j
     1974nbfield=max(max(max(i2_series)));
     1975if isempty(nbfield)
     1976    nbfield=max(max(max(i1_series)));
     1977end
     1978nbfield_j=max(max(max(j2_series)));
     1979if isempty(nbfield_j)
     1980    nbfield_j=max(max(max(j1_series)));
     1981end
     1982if isfield(XmlData,'Time')&& ~isempty(XmlData.Time)
     1983    %transform .Time to a column vector if it is a line vector the nomenclature uses a single index
     1984    if isequal(size(XmlData.Time,1),1)
     1985        XmlData.Time=(XmlData.Time)';
     1986    end
     1987end
     1988last_i_cell=get(handles.MaxIndex_i,'String');
     1989if isempty(nbfield)
     1990    last_i_cell{index}='';
     1991else
     1992    last_i_cell{index}=num2str(nbfield);
     1993end
     1994set(handles.MaxIndex_i,'String',last_i_cell)
     1995last_j_cell=get(handles.MaxIndex_j,'String');
     1996if isempty(nbfield_j)
     1997     last_j_cell{index}='';
     1998else
     1999     last_j_cell{index}=num2str(nbfield_j);
     2000end
     2001set(handles.MaxIndex_j,'String',last_j_cell);
     2002
     2003%% store geometric calibration in UvData
     2004if isfield(XmlData,'GeometryCalib')
     2005    GeometryCalib=XmlData.GeometryCalib;
     2006    if isempty(GeometryCalib)
     2007        set(handles.pxcmx,'String','')
     2008        set(handles.pxcmy,'String','')
     2009        set(handles.pxcmx,'Visible','off')
     2010        set(handles.pxcmy,'Visible','off')
     2011        set(handles.TransformName,'Value',1); %  no transform by default
     2012    else
     2013        set(handles.pxcmx,'Visible','on')
     2014        set(handles.pxcmy,'Visible','on')
     2015        if (isfield(GeometryCalib,'R')&& ~isequal(GeometryCalib.R(2,1),0) && ~isequal(GeometryCalib.R(1,2),0)) ||...
     2016            (isfield(GeometryCalib,'kappa1')&& ~isequal(GeometryCalib.kappa1,0))
     2017            set(handles.pxcmx,'String','var')
     2018            set(handles.pxcmy,'String','var')
     2019        elseif isfield(GeometryCalib,'fx_fy')
     2020            pixcmx=GeometryCalib.fx_fy(1);%*GeometryCalib.R(1,1)*GeometryCalib.sx/(GeometryCalib.Tz*GeometryCalib.dpx);
     2021            pixcmy=GeometryCalib.fx_fy(2);%*GeometryCalib.R(2,2)/(GeometryCalib.Tz*GeometryCalib.dpy);
     2022            set(handles.pxcmx,'String',num2str(pixcmx))
     2023            set(handles.pxcmy,'String',num2str(pixcmy))
     2024        end
     2025        if ~get(handles.CheckFixLimits,'Value')
     2026            set(handles.TransformName,'Value',3); % phys transform by default if fixedLimits is off
     2027        end
     2028        if isfield(GeometryCalib,'SliceCoord')           
     2029           siz=size(GeometryCalib.SliceCoord);
     2030           if siz(1)>1
     2031               NbSlice=siz(1);
     2032               set(handles.slices,'Visible','on')
     2033               set(handles.slices,'Value',1)
     2034           end
     2035           if isfield(GeometryCalib,'CheckVolumeScan') && isequal(GeometryCalib.CheckVolumeScan,1)
     2036               set(handles.num_NbSlice,'Visible','off')
     2037           else
     2038               set(handles.num_NbSlice,'Visible','on')
     2039               set(handles.num_NbSlice,'String',num2str(NbSlice))
     2040           end
     2041           slices_Callback([],[], handles)
     2042        end           
     2043    end
     2044end
     2045
     2046%% update the data attached to the uvmat interface
     2047if ~isempty(TimeUnit)
     2048    if index==2 && isfield(UvData,'TimeUnit') && ~strcmp(UvData.TimeUnit,TimeUnit)
     2049        msgbox_uvmat('WARNING',['time unit for second file series ' TimeUnit ' inconsistent with first series'])
     2050    else
     2051        UvData.TimeUnit=TimeUnit;
     2052    end
     2053end
     2054UvData.XmlData{index}=XmlData;
     2055UvData.NewSeries=1;
     2056
     2057%display warning message
     2058if ~isequal(warntext,'')
     2059    msgbox_uvmat('WARNING',warntext);
     2060end
     2061
     2062%% set default options in menu 'FieldName'
     2063switch FileType
     2064    case {'civx','civdata'}
     2065        [FieldList,ColorList]=set_field_list('U','V','C');
     2066        set(handles_Fields,'String',[{'image'};FieldList;{'get_field...'}]);%standard menu for civx data
     2067        set(handles_Fields,'Value',2) % set menu to 'velocity
     2068        if index==1
     2069            set(handles.FieldName_1,'Value',1);
     2070            set(handles.FieldName_1,'String',[{''};{'image'};FieldList;{'get_field...'}]);%standard menu for civx data reproduced for the second field
     2071        end
     2072        set(handles.ColorScalar,'Value',1)
     2073        set(handles.ColorScalar,'String',ColorList)
     2074        set(handles.Vectors,'Visible','on')
     2075        %set(handles.Coord_x,'Value',1);
     2076        set(handles.Coord_x,'String','X');
     2077        set(handles.Coord_y,'String','Y');
     2078    case 'netcdf'
     2079        set(handles_Fields,'Value',1)
     2080        set(handles_Fields,'String',{'get_field...'})
     2081        if index==1
     2082            FieldName_Callback([],[], handles)
     2083        else
     2084            FieldName_1_Callback([],[], handles)
     2085        end
     2086    otherwise
     2087        set(handles_Fields,'Value',1) % set menu to 'image'
     2088        set(handles_Fields,'String',{'image'})
     2089        %set(handles.Coord_x,'Value',1);
     2090        set(handles.Coord_x,'String','Coord_x');
     2091    set(handles.Coord_y,'String','Coord_y');
     2092end
     2093set(handles.uvmat,'UserData',UvData)
     2094
     2095%% set index navigation options
     2096scan_option='i';%default
     2097state_j='off'; %default
     2098if index==2
     2099    if get(handles.scan_j,'Value')
     2100        scan_option='j'; %keep the scan option for the second file series
     2101    end
     2102    if strcmp(get(handles.j1,'Visible'),'on')
     2103        state_j='on';
     2104    end
     2105end
     2106[ref_j,ref_i]=find(squeeze(i1_series(1,:,:)));
     2107if ~isempty(j1_series)
     2108        state_j='on';
     2109        if index==1
     2110            if isequal(ref_i,ref_i(1)*ones(size(ref_j)))% if ref_i is always equal to its first value
     2111                scan_option='j'; %scan j indext               
     2112            end
     2113        end
     2114end
     2115if isequal(scan_option,'i')
     2116    diff_ref_i=diff(ref_i,1);
     2117    if isempty(diff_ref_i)
     2118        diff_ref_i=1;
     2119    end
     2120    if isequal (diff_ref_i,diff_ref_i(1)*ones(size(diff_ref_i)))
     2121        set(handles.num_IndexIncrement,'String',num2str(diff_ref_i(1)))
     2122    end
     2123     set(handles.scan_i,'Value',1)
     2124     scan_i_Callback([],[], handles);
     2125else
     2126    diff_ref_j=diff(ref_j);
     2127    if isempty(diff_ref_j)
     2128        diff_ref_j=1;
     2129    end
     2130    if isequal (diff_ref_j,diff_ref_j(1)*ones(size(diff_ref_j)))
     2131        set(handles.num_IndexIncrement,'String',num2str(diff_ref_j(1)))
     2132    end
     2133     set(handles.scan_j,'Value',1)
     2134     scan_j_Callback([],[], handles);
     2135end
     2136set(handles.scan_j,'Visible',state_j)
     2137set(handles.j1,'Visible',state_j)
     2138set(handles.j2,'Visible',state_j)
     2139set(handles.MaxIndex_j,'Visible',state_j);
     2140set(handles.j_text,'Visible',state_j);
     2141if ~isempty(i2_series)||~isempty(j2_series)
     2142    set(handles.CheckFixPair,'Visible','on')
     2143elseif index==1
     2144    set(handles.CheckFixPair,'Visible','off')
     2145end
     2146
     2147%% apply the effect of the transform fct and view the field 
     2148transform=get(handles.TransformPath,'UserData');
     2149if index==2 && (~isa(transform,'function_handle')||nargin(transform)<3)
     2150    set(handles.TransformName,'value',2); % set transform to sub_field if the current fct doe not accept two input fields
     2151end
     2152set(handles.InputFileREFRESH,'BackgroundColor',[1 0 0])% set button color to red to indicate that refresh has been updated
     2153TransformName_Callback([],[],handles)% callback for the selection of transform function, then refresh the current plot
     2154mask_test=get(handles.CheckMask,'value');
     2155if mask_test
     2156    MaskData=get(handles.CheckMask,'UserData');
     2157    if isfield(MaskData,'maskhandle') && ishandle(MaskData.maskhandle)
     2158          delete(MaskData.maskhandle)    %delete old mask
     2159    end
     2160    CheckMask_Callback([],[],handles)
     2161end
     2162
     2163%------------------------------------------------------------------------
     2164% --- switch file index scanning options scan_i and scan_j in an exclusive way
     2165%------------------------------------------------------------------------
     2166function scan_i_Callback(hObject, eventdata, handles)
     2167
     2168if get(handles.scan_i,'Value')==1
     2169    set(handles.scan_j,'Value',0)
     2170else
     2171    set(handles.scan_j,'Value',1)
     2172end
     2173scan_j_Callback(hObject, eventdata, handles)
     2174
     2175%------------------------------------------------------------------------
     2176% --- switch file index scanning options scan_i and scan_j in an exclusive way
     2177%------------------------------------------------------------------------
     2178function scan_j_Callback(hObject, eventdata, handles)
     2179
     2180if get(handles.scan_j,'Value')==1
     2181    set(handles.scan_i,'Value',0)
     2182else
     2183    set(handles.scan_i,'Value',1)
     2184    set(handles.CheckFixPair,'Visible','off')
     2185end
     2186
     2187%------------------------------------------------------------------------
     2188function i1_Callback(hObject, eventdata, handles)
     2189%------------------------------------------------------------------------
     2190update_ij(handles,1)
     2191
     2192%------------------------------------------------------------------------
     2193function i2_Callback(hObject, eventdata, handles)
     2194%------------------------------------------------------------------------
     2195update_ij(handles,2)
     2196
     2197%------------------------------------------------------------------------
     2198function j1_Callback(hObject, eventdata, handles)
     2199%------------------------------------------------------------------------
     2200update_ij(handles,3)
     2201
     2202%------------------------------------------------------------------------
     2203function j2_Callback(hObject, eventdata, handles)
     2204%------------------------------------------------------------------------
     2205update_ij(handles,4)
     2206
     2207%------------------------------------------------------------------------
     2208%--- update the index display after action on edit boxes i1, i2, j1 or j2
     2209%------------------------------------------------------------------------
     2210function update_ij(handles,index_rank)
     2211   
     2212NomType=get(handles.NomType,'String');
     2213indices=get(handles.FileIndex,'String');
     2214[tild,tild,tild,i1,i2,j1,j2]=fileparts_uvmat(indices);% the indices for the second series taken from FileIndex
     2215switch index_rank
     2216    case 1
     2217        indices=fullfile_uvmat('','','','',NomType,stra2num(get(handles.i1,'String')),i2,j1,j2);
     2218%        set(handles.i1,'BackgroundColor',[0.7 0.7 0.7])% mark the edit box in grey, then RUN0 will mark it in white for confirmation
     2219    case 2
     2220        indices=fullfile_uvmat('','','','',NomType,i1,stra2num(get(handles.i2,'String')),j1,j2);
     2221%        set(handles.i2,'BackgroundColor',[0.7 0.7 0.7])% mark the edit box in grey, then RUN0 will mark it in white for confirmation
     2222    case 3
     2223        indices=fullfile_uvmat('','','','',NomType,i1,i2,stra2num(get(handles.j1,'String')),j2);
     2224%        set(handles.j1,'BackgroundColor',[0.7 0.7 0.7])% mark the edit box in grey, then RUN0 will mark it in white for confirmation
     2225    case 4
     2226        indices=fullfile_uvmat('','','','',NomType,i1,i2,j1,stra2num(get(handles.j2,'String')));
     2227%        set(handles.j2,'BackgroundColor',[0.7 0.7 0.7])% mark the edit box in grey, then RUN0 will mark it in white for confirmation
     2228end
     2229set(handles.FileIndex,'String',indices)
     2230%set(handles.FileIndex,'BackgroundColor',[0.7 0.7 0.7])% mark the edit box in grey, then RUN0 will mark it in white for confirmation
     2231% update the second index if relevant
     2232if strcmp(get(handles.FileIndex_1,'Visible'),'on')
     2233    NomType_1=get(handles.NomType_1,'String');
     2234    indices_1=get(handles.FileIndex_1,'String');
     2235    [tild,tild,tild,i1_1,i2_1,j1_1,j2_1]=fileparts_uvmat(indices_1);% the indices for the second series taken from FileIndex_1
     2236    switch index_rank
     2237        case 1
     2238            indices_1=fullfile_uvmat('','','','',NomType_1,stra2num(get(handles.i1,'String')),i2_1,j1_1,j2_1);
     2239        case 2
     2240            indices_1=fullfile_uvmat('','','','',NomType_1,i1_1,stra2num(get(handles.i2,'String')),j1_1,j2_1);
     2241        case 3
     2242            indices_1=fullfile_uvmat('','','','',NomType_1,i1_1,i2_1,stra2num(get(handles.j1,'String')),j2_1);
     2243        case 4
     2244            indices_1=fullfile_uvmat('','','','',NomType_1,i1_1,i2_1,j1_1,stra2num(get(handles.j2,'String')));
     2245    end
     2246    set(handles.FileIndex_1,'String',indices_1)
     2247    set(handles.FileIndex_1,'BackgroundColor',[0.7 0.7 0.7])% mark the edit box in grey, then RUN0 will mark it in white for confirmation
     2248end
     2249   
     2250%------------------------------------------------------------------------
     2251
     2252%------------------------------------------------------------------------
     2253function slices_Callback(hObject, eventdata, handles)
     2254%------------------------------------------------------------------------
     2255if strcmp(get(handles.slices,'String'),'slices')
     2256    if get(handles.slices,'Value')==1
     2257        set(handles.num_NbSlice,'Visible','on')
     2258        set(handles.z_text,'Visible','on')
     2259        set(handles.z_index,'Visible','on')
     2260        num_NbSlice_Callback(hObject, eventdata, handles)
     2261    else
     2262        set(handles.num_NbSlice,'Visible','off')
     2263        set(handles.z_text,'Visible','off')
     2264        set(handles.z_index,'Visible','off')
     2265        set(handles.masklevel,'Value',1)
     2266        set(handles.masklevel,'String',{'1'})
     2267    end
     2268end
     2269
     2270%------------------------------------------------------------------------
     2271function num_NbSlice_Callback(hObject, eventdata, handles)
     2272%------------------------------------------------------------------------
     2273mode=get(handles.slices,'String');
     2274nb_slice_str=get(handles.num_NbSlice,'String');
     2275if strcmp(mode,'volume')
     2276    z=stra2num(get(handles.j1,'String'));
     2277else
     2278    num=str2double(get(handles.i1,'String'));
     2279    nbslice=str2double(get(handles.num_NbSlice,'String'));
     2280    z=mod(num-1,nbslice)+1;
     2281end
     2282set(handles.z_index,'String',num2str(z))
     2283for ilist=1:nbslice
     2284    list_index{ilist,1}=num2str(ilist);
     2285end   
     2286set(handles.masklevel,'String',list_index)
     2287set(handles.masklevel,'Value',z)
     2288
     2289%------------------------------------------------------------------------
     2290% --- Executes on button press in view_xml.
     2291%------------------------------------------------------------------------
     2292function view_xml_Callback(hObject, eventdata, handles)
     2293
     2294% if TimeName defined, open the xml file corresponding to the first file
     2295% series, else open the xml file corresponding to the second series
     2296if isempty(get(handles.TimeName,'String'))% open the xml file corresponding to the secodn file series
     2297    [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes_1(handles);
     2298else
     2299   [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles);
     2300end
     2301option=get(handles.view_xml,'String');
     2302if isequal(option,'view .xml')     
     2303    FileXml=fullfile(RootPath,[SubDir '.xml']);
     2304    if ~exist(FileXml,'file')% case of civ files , removes the extension for subdir
     2305        FileXml=fullfile(RootPath,[regexprep(SubDir,'\..+$','') '.xml']);
     2306    end
     2307    heditxml=editxml(FileXml);
     2308end
     2309
     2310%------------------------------------------------------------------------
     2311% --- Executes on button press in CheckMask.
     2312function CheckMask_Callback(hObject, eventdata, handles)
     2313%------------------------------------------------------------------------
     2314%case of view mask selection
     2315if isequal(get(handles.CheckMask,'Value'),1)
     2316    [RootPath,SubDir]=read_file_boxes(handles);
     2317    MaskSubDir=regexprep(SubDir,'\..*','');%take the root part of SubDir, before the first dot '.'
     2318    MaskPath=fullfile(RootPath,[MaskSubDir '.mask']);
     2319    mdetect=0;
     2320    if exist(MaskPath,'dir')
     2321        ListStruct=dir(MaskPath);%look for a mask file
     2322        ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray
     2323        check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files
     2324        ListFiles=ListCells(1,:);%list of file and dri names
     2325        ListFiles=ListFiles(~check_dir);%list of file names (excluding dir)
     2326        if ~isempty(ListFiles)
     2327            for ifile=1:numel(ListFiles)
     2328                [tild,tild,MaskExt]=fileparts(ListFiles{1});
     2329                [tild,tild,MaskFile{ifile},i1_series,i2_series,j1_series,j2_series,MaskNomType,MaskFileInfo]=find_file_series(MaskPath,ListFiles{ifile},0);
     2330                MaskFileType=MaskFileInfo.FileType;
     2331                if strcmp(MaskFileType,'image') && isempty(i2_series) && isempty(j2_series)
     2332                    mdetect=1;
     2333                end
     2334                if ~strcmp(MaskFile{ifile},MaskFile{1})
     2335                    mdetect=0;% cancel detection test in case of multiple masks, use the brower for selection
     2336                    break
     2337                end
     2338            end
     2339        end
     2340        RootPath=MaskPath;
     2341    end
     2342    if mdetect==0
     2343        MaskFullName=uigetfile_uvmat('pick a mask image file:',RootPath,'image');
     2344        if isempty(MaskFullName)
     2345            set(handles.CheckMask,'Value',0)
     2346        end
     2347        [MaskPath,MaskName,MaskExt]=fileparts(MaskFullName);
     2348        [tild,tild,MaskFile,i1_series,i2_series,j1_series,j2_series,MaskNomType]=find_file_series(MaskPath,[MaskName MaskExt],0);
     2349        if ~(isempty(i2_series) && isempty(j2_series))
     2350            MaskNomType='*';
     2351        end
     2352    end
     2353    Mask.Path=MaskPath;
     2354    if isempty(MaskFile)
     2355        Mask.File='';
     2356    elseif ischar(MaskFile)
     2357        Mask.File=MaskFile;
     2358    else
     2359        Mask.File=MaskFile{1};
     2360    end
     2361    Mask.Ext=MaskExt;
     2362    Mask.NomType=MaskNomType;
     2363    set(handles.CheckMask,'UserData',Mask);
     2364    errormsg=update_mask(handles);
     2365else % desactivate mask display
     2366    MaskData=get(handles.CheckMask,'UserData');
     2367    if isfield(MaskData,'maskhandle') && ishandle(MaskData.maskhandle)
     2368        delete(MaskData.maskhandle)
     2369    end
     2370    set(handles.CheckMask,'UserData',[])
     2371    UvData=get(handles.uvmat,'UserData');
     2372    if isfield(UvData,'MaskName')
     2373        UvData=rmfield(UvData,'MaskName');
     2374        set(handles.uvmat,'UserData',UvData)
     2375    end
     2376    set(handles.CheckMask,'BackgroundColor',[0.7 0.7 0.7])
     2377end
     2378
     2379%------------------------------------------------------------------------
     2380function errormsg=update_mask(handles)
     2381%------------------------------------------------------------------------
     2382errormsg=[];%default
     2383Mask=get(handles.CheckMask,'UserData');
     2384MaskIndex=1;
     2385if strcmp(get(handles.z_index,'Visible'),'on')
     2386    MaskIndex=str2num(get(handles.z_index,'String'));
     2387end
     2388if isfield(Mask,'maskhandle')&& ishandle(Mask.maskhandle)
     2389    uistack(Mask.maskhandle,'top');
     2390end
     2391MaskName=fullfile_uvmat(Mask.Path,'',Mask.File,Mask.Ext,Mask.NomType,MaskIndex);
     2392UvData=get(handles.uvmat,'UserData');
     2393
     2394%% update mask image if the mask is new
     2395if ~ (isfield(UvData,'MaskName') && isequal(UvData.MaskName,MaskName))
     2396    UvData.MaskName=MaskName; %update the recorded name on UvData
     2397    set(handles.uvmat,'UserData',UvData);
     2398    if ~exist(MaskName,'file')
     2399        if isfield(Mask,'maskhandle')&& ishandle(Mask.maskhandle)
     2400            delete(Mask.maskhandle)   
     2401        end
     2402    else
     2403        %read mask image
     2404        [MaskField,tild,errormsg] = read_field(MaskName,'image');
     2405        if ~isempty(errormsg)
     2406            return
     2407        end
     2408        npxy=size(MaskField.A);
     2409        if length(npxy)>2
     2410            errormsg=[MaskName ' is not a grey scale image'];
     2411            return
     2412        elseif ~isa(MaskField.A,'uint8')
     2413            errormsg=[MaskName ' is not a 8 bit grey level image'];
     2414            return
     2415        end
     2416        MaskField.ZIndex=MaskIndex;
     2417        %px to phys or other transform on field
     2418         menu_transform=get(handles.TransformName,'String');
     2419        choice_value=get(handles.TransformName,'Value');
     2420        transform_name=menu_transform{choice_value};%name of the transform fct  given by the menu 'transform_fct'
     2421        transform=get(handles.TransformPath,'UserData');
     2422        if  ~isequal(transform_name,'') && ~isequal(transform_name,'px')
     2423            if isfield(UvData,'XmlData') && isfield(UvData.XmlData{1},'GeometryCalib')%use geometry calib recorded from the ImaDoc xml file as first priority
     2424                Calib=UvData.XmlData{1}.GeometryCalib;
     2425                MaskField=transform(MaskField,UvData.XmlData{1});
     2426            end
     2427        end
     2428        flagmask=MaskField.A < 200;
     2429       
     2430        %make brown color image
     2431        imflag(:,:,1)=0.9*flagmask;
     2432        imflag(:,:,2)=0.7*flagmask;
     2433        imflag(:,:,3)=zeros(size(flagmask));
     2434       
     2435        %update mask image
     2436        hmask=[]; %default
     2437        if isfield(Mask,'maskhandle')&& ishandle(Mask.maskhandle)
     2438            hmask=Mask.maskhandle;
     2439        end
     2440        if ~isempty(hmask)
     2441            set(hmask,'CData',imflag)   
     2442            set(hmask,'AlphaData',flagmask*0.6)
     2443            set(hmask,'XData',MaskField.Coord_x);
     2444            set(hmask,'YData',MaskField.Coord_y);
     2445%             uistack(hmask,'top')
     2446        else
     2447            axes(handles.PlotAxes)
     2448            hold on   
     2449            Mask.maskhandle=image(MaskField.Coord_x,MaskField.Coord_y,imflag,'Tag','mask','HitTest','off','AlphaData',0.6*ones(size(flagmask)));
     2450            set(handles.CheckMask,'UserData',Mask)
     2451        end
     2452    end
     2453end
     2454
     2455%------------------------------------------------------------------------
     2456%------------------------------------------------------------------------
     2457% III - MAIN InputFileREFRESH FUNCTIONS : 'FRAME PLOT'
     2458%------------------------------------------------------------------------
     2459
     2460%------------------------------------------------------------------------
     2461% --- Executes on button press in runplus: make one step forward and call
     2462% --- InputFileREFRESH. The step forward is along the fieldname series 1 or 2 depending on
     2463% --- the scan_i and scan_j check box (exclusive each other)
     2464function runplus_Callback(hObject, eventdata, handles)
     2465%------------------------------------------------------------------------
     2466
     2467set(handles.runplus,'BackgroundColor',[1 1 0])%paint the command button in yellow
     2468drawnow
     2469increment=str2double(get(handles.num_IndexIncrement,'String')); %get the field increment d
     2470if isnan(increment)% case of free increment: move to next available field index
     2471    increment='+';
     2472end
     2473errormsg=runpm(hObject,eventdata,handles,increment);
     2474if ~isempty(errormsg)
     2475    msgbox_uvmat('ERROR',errormsg);
     2476end
     2477
     2478%------------------------------------------------------------------------
     2479% --- Executes on button press in runmin: make one step backward and call
     2480% --- InputFileREFRESH. The step backward is along the fieldname series 1 or 2 depending on
     2481% --- the scan_i and scan_j check box (exclusive each other)
     2482function runmin_Callback(hObject, eventdata, handles)
     2483%------------------------------------------------------------------------
     2484
     2485set(handles.runmin,'BackgroundColor',[1 1 0])%paint the command button in yellow
     2486drawnow
     2487increment=-str2double(get(handles.num_IndexIncrement,'String')); %get the field increment d
     2488if isnan(increment)% case of free increment: move to previous available field index
     2489    increment='-';
     2490end
     2491errormsg=runpm(hObject,eventdata,handles,increment);
     2492if ~isempty(errormsg)
     2493    msgbox_uvmat('ERROR',errormsg);
     2494end
     2495
     2496%------------------------------------------------------------------------
     2497% -- Executes on button press in Movie: make a series of +> steps
     2498function Movie_Callback(hObject, eventdata, handles)
     2499%------------------------------------------------------------------------
     2500
     2501set(handles.Movie,'BackgroundColor',[1 1 0])%paint the command button in yellow
     2502drawnow
     2503increment=str2double(get(handles.num_IndexIncrement,'String')); %get the field increment d
     2504if isnan(increment)% case of free increment: move to next available field index
     2505    increment='+';
     2506end
     2507set(handles.STOP,'Visible','on')
     2508set(handles.speed,'Visible','on')
     2509set(handles.speed_txt,'Visible','on')
     2510set(handles.Movie,'BusyAction','queue')
     2511UvData=get(handles.uvmat,'UserData');
     2512
     2513while get(handles.Movie,'Value')==1 && get(handles.speed,'Value')~=0 && isequal(get(handles.Movie,'BusyAction'),'queue') % enable STOP command
     2514        errormsg=runpm(hObject,eventdata,handles,increment);
     2515        if ~isempty(errormsg)
     2516            set(handles.Movie,'BackgroundColor',[1 0 0])%paint the command buttonback to red
     2517            return
     2518        end
     2519        pause(1.02-get(handles.speed,'Value'))% wait for next image
     2520end
     2521if isfield(UvData,'aviobj') && ~isempty( UvData.aviobj),
     2522    UvData.aviobj=close(UvData.aviobj);
     2523   set(handles.uvmat,'UserData',UvData);
     2524end
     2525set(handles.Movie,'BackgroundColor',[1 0 0])%paint the command buttonback to red
     2526
     2527%------------------------------------------------------------------------
     2528% -- Executes on button press in Movie: make a series of <- steps
     2529function MovieBackward_Callback(hObject, eventdata, handles)
     2530%------------------------------------------------------------------------
     2531set(handles.MovieBackward,'BackgroundColor',[1 1 0])%paint the command button in yellow
     2532drawnow
     2533increment=-str2double(get(handles.num_IndexIncrement,'String')); %get the field increment d
     2534if isnan(increment)% case of free increment: move to next available field index
     2535    increment='-';
     2536end
     2537set(handles.STOP,'Visible','on')
     2538set(handles.speed,'Visible','on')
     2539set(handles.speed_txt,'Visible','on')
     2540set(handles.MovieBackward,'BusyAction','queue')
     2541UvData=get(handles.uvmat,'UserData');
     2542
     2543while get(handles.MovieBackward,'Value')==1 && get(handles.speed,'Value')~=0 && isequal(get(handles.MovieBackward,'BusyAction'),'queue') % enable STOP command
     2544        errormsg=runpm(hObject,eventdata,handles,increment);
     2545        if ~isempty(errormsg)
     2546            set(handles.MovieBackward,'BackgroundColor',[1 0 0])%paint the command buttonback to red
     2547            return
     2548        end
     2549        pause(1.02-get(handles.speed,'Value'))% wait for next image
     2550end
     2551if isfield(UvData,'aviobj') && ~isempty( UvData.aviobj),
     2552    UvData.aviobj=close(UvData.aviobj);
     2553   set(handles.uvmat,'UserData',UvData);
     2554end
     2555set(handles.MovieBackward,'BackgroundColor',[1 0 0])%paint the command buttonback to red
     2556
     2557%------------------------------------------------------------------------
     2558function STOP_Callback(hObject, eventdata, handles)
     2559%------------------------------------------------------------------------
     2560set(handles.movie_pair,'BusyAction','Cancel')
     2561set(handles.movie_pair,'value',0)
     2562set(handles.Movie,'BusyAction','Cancel')
     2563set(handles.MovieBackward,'BusyAction','Cancel')
     2564set(handles.MenuExportMovie,'BusyAction','Cancel')
     2565%set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command buttonback to red
     2566set(handles.Movie,'BackgroundColor',[1 0 0])%paint the command buttonback to red
     2567set(handles.MovieBackward,'BackgroundColor',[1 0 0])%paint the command buttonback to red
     2568
     2569%------------------------------------------------------------------------
     2570% --- function activated by runplus and run minus
     2571function errormsg=runpm(hObject,eventdata,handles,increment)
     2572%------------------------------------------------------------------------
     2573errormsg='';%default
     2574%% check for movie pair status
     2575movie_status=get(handles.movie_pair,'Value');
     2576if movie_status
     2577    STOP_Callback(hObject, eventdata, handles)%interrupt movie pair if active
     2578end
     2579
     2580%% read the current input file name(s) and field indices
     2581InputFile=read_GUI(handles.InputFile);
     2582InputFile.RootFile=regexprep(InputFile.RootFile,'^[\\/]|[\\/]$','');%suppress possible / or \ separator at the beginning or the end of the string
     2583InputFile.SubDir=regexprep(InputFile.SubDir,'^[\\/]|[\\/]$','');%suppress possible / or \ separator at the beginning or the end of the string
     2584FileExt=InputFile.FileExt;
     2585NomType=InputFile.NomType;
     2586[tild,tild,tild,i1,i2,j1,j2]=fileparts_uvmat(InputFile.FileIndex);% check back the indices used
     2587if isempty(i1)
     2588    i1=str2num(get(handles.i1,'String'));%read the field indices (for movie, it is not given by the file name)
     2589elseif isempty(j1) && strcmp(get(handles.j1,'Visible'),'on')
     2590    j1=str2num(get(handles.j1,'String'));%case of indexed movie
     2591end
     2592if movie_status% we read the second index from the edit box
     2593    i2=str2num(get(handles.i2,'String'));%read the field indices (for movie, it is not given by the file name)
     2594    if strcmp(get(handles.j2,'Visible'),'on')
     2595    j2=str2num(get(handles.j2,'String'));%
     2596    end
     2597end
     2598sub_value= get(handles.SubField,'Value');
     2599if sub_value % a second input file has been entered
     2600    [InputFile.RootPath_1,InputFile.SubDir_1,InputFile.RootFile_1,InputFile.FileIndex_1,InputFile.FileExt_1,InputFile.NomType_1]=read_file_boxes_1(handles);
     2601    [tild,tild,tild,i1_1,i2_1,j1_1,j2_1]=fileparts_uvmat(InputFile.FileIndex_1);% the indices for the second series taken from FileIndex_1
     2602    if isempty(i1_1)
     2603        i1_1=str2num(get(handles.i1,'String'));%read the field indices (for movie, it is not given by the file name)
     2604    elseif isempty(j1_1) && strcmp(get(handles.j1,'Visible'),'on')
     2605        j1_1=str2num(get(handles.j1,'String'));%case of indexed movie
     2606    end
     2607else
     2608    filename_1=[];
     2609end
     2610
     2611%% increment (or decrement) the field indices and update the input filename(s)
     2612if ~isnumeric(increment)% undefined increment value
     2613    set(handles.CheckFixPair,'Value',0)
     2614end
     2615CheckFixPair=get(handles.CheckFixPair,'Value')||(isempty(i2)&&isempty(j2));
     2616
     2617% the pair i1-i2 or j1-j2 is imposed (check box CheckFixPair selected)
     2618if CheckFixPair && isnumeric(increment)
     2619    if get(handles.scan_i,'Value')==1% case of scanning along index i
     2620        i1=i1+increment;
     2621        i2=i2+increment;
     2622        if sub_value
     2623            i1_1=i1_1+increment;
     2624            i2_1=i2_1+increment;
     2625        end
     2626    else % case of scanning along index j (burst numbers)
     2627        j1=j1+increment;
     2628        j2=j2+increment;
     2629        if sub_value
     2630            j1_1=j1_1+increment;
     2631            j2_1=j2_1+increment;
     2632        end
     2633    end
     2634   
     2635% the pair i1-i2 or j1-j2 is free (check box CheckFixPair not selected): the list of existing indices recorded in UvData is used
     2636else
     2637    UvData=get(handles.uvmat,'UserData');
     2638    ref_i=i1;
     2639    if ~isempty(i2)
     2640        ref_i=floor((i1+i2)/2);% current reference index i
     2641    end
     2642    ref_j=1;
     2643    if ~isempty(j1)
     2644        ref_j=j1;
     2645        if ~isempty(j2)
     2646            ref_j=floor((j1+j2)/2);% current reference index j
     2647        end
     2648    end
     2649    if isnumeric(increment)
     2650        if get(handles.scan_i,'Value')==1% case of scanning along index i
     2651            ref_i=ref_i+increment;% increment the current reference index i
     2652        else % case of scanning along index j (burst numbers)
     2653            ref_j=ref_j+increment;% increment the current reference index j if scan_j option is used
     2654        end
     2655    else % free increment
     2656       % runaction=get(gcbo,'tag');
     2657        if strcmp(increment,'+')% if runplus or movie is activated
     2658            step=1;
     2659        else
     2660            step=-1;
     2661        end
     2662        if get(handles.scan_i,'Value')==1% case of scanning along index i
     2663            ref_i=ref_i+step;
     2664            while ref_i>=0  && size(UvData.i1_series{1},3)>=ref_i+1 && UvData.i1_series{1}(1,ref_j+1,ref_i+1)==0
     2665                ref_i=ref_i+step;
     2666            end
     2667        else % case of scanning along index j (burst numbers)
     2668            ref_j=ref_j+step;
     2669            while ref_j>=0  && size(UvData.i1_series{1},2)>=ref_j+1 && UvData.i1_series{1}(1,ref_j+1,ref_i+1)==0
     2670                ref_j=ref_j+step;
     2671            end
     2672        end
     2673    end
     2674    if ref_i<0
     2675        errormsg='minimum i index reached';
     2676    elseif ref_j<0
     2677        errormsg='minimum j index reached';
     2678    elseif ref_i+1>size(UvData.i1_series{1},3)
     2679        errormsg='maximum i index reached (reload the input file to update the index bound)';
     2680    elseif ref_j+1>size(UvData.i1_series{1},2)
     2681        errormsg='maximum j index reached (reload the input file to update the index bound)';
     2682    end
     2683    if ~isempty(errormsg),return,end
     2684    siz=size(UvData.i1_series{1});
     2685    ref_indices=ref_i*siz(1)*siz(2)+ref_j*siz(1)+1:ref_i*siz(1)*siz(2)+(ref_j+1)*siz(1);
     2686    i1_subseries=UvData.i1_series{1}(ref_indices);
     2687    ref_indices=ref_indices(i1_subseries>0);
     2688    if isempty(ref_indices)% case of pairs (free index i)
     2689        ref_indices=ref_i*siz(1)*siz(2)+1:(ref_i+1)*siz(1)*siz(2);
     2690        i1_subseries=UvData.i1_series{1}(ref_indices);
     2691        ref_indices=ref_indices(i1_subseries>0);
     2692    end
     2693    if isempty(ref_indices),errormsg='no next frame: set num_IndexIncrement =''*'' to reach the next existing file';return
     2694    end
     2695    i1=UvData.i1_series{1}(ref_indices(end));
     2696    if ~isempty(UvData.i2_series{1})
     2697        i2=UvData.i2_series{1}(ref_indices(end));
     2698    end
     2699    if ~isempty(UvData.j1_series{1})
     2700        j1=UvData.j1_series{1}(ref_indices(end));
     2701    end
     2702    if ~isempty(UvData.j2_series{1})
     2703        j2=UvData.j2_series{1}(ref_indices(end));
     2704    end
     2705   
     2706    % case of a second file series
     2707    if sub_value
     2708        ref_i_1=i1_1;
     2709        if ~isempty(i2_1)
     2710            ref_i_1=floor((i1_1+i2_1)/2);% current reference index i
     2711        end
     2712        ref_j_1=1;
     2713        if ~isempty(j1_1)
     2714            ref_j_1=j1_1;
     2715            if ~isempty(j2_1)
     2716                ref_j_1=floor((j1_1+j2_1)/2);% current reference index j
     2717            end
     2718        end
     2719        if isnumeric(increment)
     2720            if get(handles.scan_i,'Value')==1% case of scanning along index i
     2721                ref_i_1=ref_i_1+increment;% increment the current reference index i
     2722            else % case of scanning along index j (burst numbers)
     2723                ref_j_1=ref_j_1+increment;% increment the current reference index j if scan_j option is used
     2724            end
     2725        else % free increment, synchronise the ref indices with the first series
     2726            ref_i_1=ref_i;
     2727            ref_j_1=ref_j;
     2728        end
     2729        if numel(UvData.i1_series)==1
     2730            UvData.i1_series{2}=UvData.i1_series{1};
     2731            UvData.j1_series{2}=UvData.j1_series{1};
     2732            UvData.i2_series{2}=UvData.i2_series{1};
     2733            UvData.j2_series{2}=UvData.j2_series{1};
     2734        end
     2735        if ref_i_1<0
     2736            errormsg='minimum i index reached';
     2737        elseif ref_j_1<0
     2738            errormsg='minimum j index reached';
     2739        elseif ref_i_1+1>size(UvData.i1_series{2},3)
     2740            errormsg='maximum i index reached for the second series (reload the input file to update the index bound)';
     2741        elseif ref_j_1+1>size(UvData.i1_series{2},2)
     2742            errormsg='maximum j index reached for the second series(reload the input file to update the index bound)';
     2743        end
     2744        if ~isempty(errormsg),return,end
     2745        siz=size(UvData.i1_series{2});
     2746        ref_indices=ref_i_1*siz(1)*siz(2)+ref_j_1*siz(1)+1:ref_i_1*siz(1)*siz(2)+(ref_j_1+1)*siz(1);
     2747        i1_subseries=UvData.i1_series{2}(ref_indices);
     2748        ref_indices=ref_indices(i1_subseries>0);
     2749        if isempty(ref_indices)% case of pairs (free index i)
     2750            ref_indices=ref_i_1*siz(1)*siz(2)+1:(ref_i_1+1)*siz(1)*siz(2);
     2751            i1_subseries=UvData.i1_series{2}(ref_indices);
     2752            ref_indices=ref_indices(i1_subseries>0);
     2753        end
     2754        i1_1=UvData.i1_series{2}(ref_indices(end));
     2755        if ~isempty(UvData.i2_series{2})
     2756            i2_1=UvData.i2_series{2}(ref_indices(end));
     2757        end
     2758        if ~isempty(UvData.j1_series{2})
     2759            j1_1=UvData.j1_series{2}(ref_indices(end));
     2760        end
     2761        if ~isempty(UvData.j2_series{2})
     2762            j2_1=UvData.j2_series{1}(ref_indices(end));
     2763        end
     2764    else% the second series (if needed) is the same file as the first
     2765        i1_1=i1;
     2766        i2_1=i2;
     2767        j1_1=j1;
     2768        j2_1=j2;
     2769    end
     2770end
     2771filename=fullfile_uvmat(InputFile.RootPath,InputFile.SubDir,InputFile.RootFile,FileExt,NomType,i1,i2,j1,j2);
     2772
     2773%% refresh plots
     2774if sub_value
     2775    filename_1=fullfile_uvmat(InputFile.RootPath_1,InputFile.SubDir_1,InputFile.RootFile_1,InputFile.FileExt_1,InputFile.NomType_1,i1_1,i2_1,j1_1,j2_1);
     2776    errormsg=refresh_field(handles,filename,filename_1,i1,i2,j1,j2,i1_1,i2_1,j1_1,j2_1);
     2777else
     2778    errormsg=refresh_field(handles,filename,filename_1,i1,i2,j1,j2);
     2779end
     2780set(handles.InputFileREFRESH,'BackgroundColor',[1 0 0])
     2781set(handles.runplus,'BackgroundColor',[1 0 0])
     2782set(handles.runmin,'BackgroundColor',[1 0 0])
     2783
     2784%% update the index counters if the index move is successfull
     2785
     2786if isempty(errormsg)
     2787    set(handles.i1,'String',num2stra(i1,NomType,1));
     2788    if isequal(i2,i1)
     2789        set(handles.i2,'String','');
     2790    else
     2791        set(handles.i2,'String',num2stra(i2,NomType,1));
     2792    end
     2793    set(handles.j1,'String',num2stra(j1,NomType,2));
     2794    if isequal(j2,j1)
     2795        set(handles.j2,'String','');
     2796    else
     2797        set(handles.j2,'String',num2stra(j2,NomType,2));
     2798    end
     2799    indices=fullfile_uvmat('','','','',NomType,i1,i2,j1,j2);
     2800    set(handles.FileIndex,'String',indices);
     2801    if ~isempty(filename_1)
     2802        indices_1=fullfile_uvmat('','','','',InputFile.NomType_1,i1_1,i2_1,j1_1,j2_1);
     2803        set(handles.FileIndex_1,'String',indices_1);
     2804    end
     2805    if isequal(movie_status,1)
     2806        set(handles.movie_pair,'Value',1)
     2807        movie_pair_Callback(hObject, eventdata, handles); %reactivate moviepair if it was activated
     2808    else
     2809        if isempty(i2), set(handles.i2,'String',''); end % suppress the second index display if not used
     2810        if isempty(j2), set(handles.j2,'String',''); end
     2811    end
     2812end
     2813
     2814%------------------------------------------------------------------------
     2815% --- Executes on button press in movie_pair: create an alternating movie with two view
     2816function movie_pair_Callback(hObject, eventdata, handles)
     2817%------------------------------------------------------------------------
     2818
     2819%% stop movie action if the movie_pair button is off
     2820if ~get(handles.movie_pair,'value')
     2821    set(handles.movie_pair,'BusyAction','Cancel')%stop movie pair if button is 'off'
     2822    set(handles.i2,'String','')% the second i index display is suppressed
     2823    set(handles.j2,'String','')% the second j index display is suppressed
     2824    set(handles.Dt_txt,'String','')% the time interval indication is suppressed
     2825    return
     2826end
     2827   
     2828%% check the input file indexing:
     2829[RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles);
     2830NomType=get(handles.NomType,'String');
     2831if ~isempty(find(regexp(NomType,'-')))
     2832    msgbox_uvmat('ERROR','The movie pair requires file series with a single index on the first input line')
     2833    return
     2834end
     2835filename=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt];% build the input file name (first line)
     2836
     2837set(handles.movie_pair,'BusyAction','queue')%
     2838set(handles.CheckFixPair,'Value',1)% impose fixed pair (needed for function runpm)
     2839set(handles.REFRESH,'BackgroundColor',[1 1 0])%paint the command button in yellow to indicate its activity
     2840set(handles.movie_pair,'BackgroundColor',[1 1 0])%paint the command button in yellow to indicate its activity
     2841drawnow
     2842% list_fields=get(handles.FieldName,'String');% list menu fields
     2843% index_fields=get(handles.FieldName,'Value');% selected string index
     2844% FieldName=list_fields{index_fields}; % selected field
     2845
     2846
     2847% if isequal(FieldName,'image')
     2848%     index=1;
     2849
    56982850% else
    5699 %     addpath (fullfile(pathelp,'uvmat_doc'))
    5700 %     web(helpfile);
     2851%     list_fields=get(handles.FieldName_1,'String');% list menu fields
     2852%     index_fields=get(handles.FieldName_1,'Value');% selected string index
     2853%     FieldName=list_fields{index_fields}; % selected field
     2854%     if isequal(FieldName,'image')
     2855%         index=2;
     2856%         [RootPath,SubDir,RootFile,FileIndex_1,Ext,NomType]=read_file_boxes_1(handles);% get info from the second input line
     2857%     else
     2858%         msgbox_uvmat('ERROR','an image or movie must be first introduced as input')
     2859%         set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
     2860%         set(handles.movie_pair,'Value',0)
     2861%         return
     2862%     end
    57012863% end
     2864num_i1=str2num(get(handles.i1,'String'));
     2865num_j1=stra2num(get(handles.j1,'String'));
     2866num_i2=str2num(get(handles.i2,'String'));
     2867num_j2=stra2num(get(handles.j2,'String'));
     2868
     2869%% determine the name 'imaname_1' of the second file in the pair
     2870imaname_1='';
     2871if isempty(num_j2)% no second j index indicated
     2872    if isempty(num_i2)
     2873        if strcmp(get(handles.j2,'Visible'),'on') %if the j box is visible
     2874            imaname_1=fullfile_uvmat(RootPath,SubDir,RootFile,FileExt,NomType,num_i1,[],num_j1+1);
     2875        end
     2876        if exist(imaname_1,'file')
     2877            num_j2=num_j1+1;% look by default for the next j index as the second file
     2878            set(handles.j2,'String',num2stra(num_j2,NomType));
     2879        else
     2880            imaname_1=fullfile_uvmat(RootPath,SubDir,RootFile,FileExt,NomType,num_i1+1,[],num_j1);
     2881            if exist(imaname_1,'file')
     2882                num_i2=num_i1+1;
     2883                set(handles.i2,'String',num2str(num_i2));
     2884            else
     2885                msgbox_uvmat('ERROR', 'a second image index i2 or j2 is needed to show the pair as a movie')
     2886                set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
     2887                set(handles.movie_pair,'Value',0)
     2888                return
     2889            end
     2890        end
     2891    else
     2892        num_j2=num_j1;%repeat the index i1 by default
     2893    end
     2894end
     2895if isempty(num_i2)
     2896    num_i2=num_i1;%repeat the index i1 by default
     2897end
     2898if isempty(num_j1)
     2899    num_j1=1;
     2900end
     2901if isempty(num_j2)
     2902    num_j2=num_j1;%repeat the index i1 by default
     2903end
     2904imaname_1=fullfile_uvmat(RootPath,SubDir,RootFile,FileExt,NomType,num_i2,[],num_j2);
     2905if strcmp(NomType,'*')
     2906    num_frame=num_i2;
     2907else
     2908    num_frame=num_j2;
     2909end
     2910if ~exist(imaname_1,'file')
     2911      msgbox_uvmat('ERROR',['second input open (-)  ' imaname_1 ' not found']);
     2912      set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
     2913       set(handles.movie_pair,'Value',0)
     2914      return
     2915end
     2916
     2917%% display the first field in the pair (including possibly a background field from second line input filename_1)
     2918filename_1='';%default
     2919FileIndex_1='';
     2920if get(handles.SubField,'Value')
     2921    [RootPath_1,SubDir_1,RootFile_1,FileIndex_1,FileExt_1]=read_file_boxes_1(handles);
     2922    filename_1=[fullfile(RootPath_1,SubDir_1,RootFile_1) FileIndex_1 FileExt_1];
     2923end
     2924% num_i1=stra2num(get(handles.i1,'String'));
     2925% num_i2=stra2num(get(handles.i2,'String'));
     2926% num_j1=stra2num(get(handles.j1,'String'));
     2927% num_j2=stra2num(get(handles.j2,'String'));
     2928[tild,tild,tild,i1_1,i2_1,j1_1,j2_1]=fileparts_uvmat(FileIndex_1);% get the indices of the second series from the string FileIndex_1
     2929if isempty(j1_1)% case of movies, the index is not given by file index
     2930    j1_1=num_j1;
     2931end
     2932
     2933errormsg=refresh_field(handles,filename,filename_1,num_i1,num_i2,num_j1,num_j2,i1_1,i2_1,j1_1,j2_1);
     2934
     2935if isempty(errormsg)
     2936    set(handles.REFRESH,'BackgroundColor',[1 0 0])% set button color to red, update successfull
     2937else
     2938     msgbox_uvmat('ERROR',errormsg);
     2939     set(handles.REFRESH,'BackgroundColor',[1 0 1])% keep button color magenta, input not succesfull
     2940end
     2941UvData=get(handles.uvmat,'UserData');
     2942Field_a=UvData.Field;% movie on the field defined by the second input line
     2943
     2944%% display time interval for the image pair
     2945if isfield(UvData,'XmlData')&&isfield(UvData.XmlData{1},'Time')...
     2946        && size(UvData.XmlData{1}.Time,1)>=num_i2+1 && size(UvData.XmlData{1}.Time,2)>=num_j2+1
     2947    dt=(UvData.XmlData{1}.Time(num_i2+1,num_j2+1)-UvData.XmlData{1}.Time(num_i1+1,num_j1+1));
     2948    if  isfield(UvData,'TimeUnit')
     2949        set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) '  m' UvData.TimeUnit] )
     2950    else
     2951        set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) '  10^(-3)'] )
     2952    end
     2953else
     2954    set(handles.Dt_txt,'String','')
     2955end
     2956
     2957%% read the second field
     2958if isempty(UvData.MovieObject)
     2959    [Field_b,ParamOut,errormsg] = read_field(imaname_1,UvData.FileType{index},[],num_frame);
     2960else
     2961    [Field_b,ParamOut,errormsg] = read_field(imaname_1,UvData.FileType{1},UvData.MovieObject{1},num_frame);
     2962end
     2963if ~isempty(errormsg)
     2964    msgbox_uvmat('ERROR',['Error in reading second image: ' errormsg])
     2965    return
     2966end
     2967
     2968%% apply phys or other transform on the two input fields
     2969transform=get(handles.TransformPath,'UserData');
     2970if  ~isempty(transform)
     2971    if isfield(UvData,'XmlData') && ~isempty(UvData.XmlData) %use geometry calib recorded from the ImaDoc xml file as first priority
     2972        if nargin(transform)>=2
     2973            Field_b=transform(Field_b,UvData.XmlData{1});
     2974        else
     2975            Field_b=transform(Field_b);
     2976        end
     2977    end
     2978end
     2979
     2980%% make movie until movie speed is set to 0 or STOP is activated
     2981hima=findobj(handles.PlotAxes,'Tag','ima');% %handles.PlotAxes =main plotting window (A GENERALISER)
     2982set(handles.STOP,'Visible','on')
     2983set(handles.speed,'Visible','on')
     2984set(handles.speed_txt,'Visible','on')
     2985while get(handles.speed,'Value')~=0 && isequal(get(handles.movie_pair,'BusyAction'),'queue') % enable STOP command
     2986    % read and plot the series of images in non erase mode
     2987    set(hima,'CData',Field_b.A); %TODO: generalise to other kinds of fields
     2988    pause(1.02-get(handles.speed,'Value'));% wait for next image
     2989    set(hima,'CData',Field_a.A);
     2990    pause(1.02-get(handles.speed,'Value'));% wait for next image
     2991end
     2992set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
     2993set(handles.movie_pair,'Value',0)
     2994set(handles.Dt_txt,'String','')
     2995
     2996%------------------------------------------------------------------------
     2997% --- Executes on button press in InputFileREFRESH.
     2998function REFRESH_Callback(hObject, eventdata, handles)
     2999%------------------------------------------------------------------------
     3000set(handles.REFRESH,'BackgroundColor',[1 1 0])%paint the REFRESH button in yellow to indicate its activity
     3001drawnow
     3002[RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles);%read the features of the input file name (first line)
     3003[tild,tild,tild,i1,i2,j1,j2]=fileparts_uvmat(FileIndex);% check back the indices used
     3004if isempty(i2), set(handles.i2,'String',''); end % suppress the second i index display if not used
     3005if isempty(j2), set(handles.j2,'String',''); end % suppress the second j index display if not used
     3006filename=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt];% build the input file name (first line)
     3007filename_1='';%default second file name
     3008FileIndex_1='';
     3009if get(handles.SubField,'Value')% if a second file is introduced
     3010    [RootPath_1,SubDir_1,RootFile_1,FileIndex_1,FileExt_1]=read_file_boxes_1(handles);%read the features of the input file name (second line)
     3011    filename_1=[fullfile(RootPath_1,SubDir_1,RootFile_1) FileIndex_1 FileExt_1]; %build the input file name (second line)
     3012end
     3013num_i1=stra2num(get(handles.i1,'String'));
     3014num_i2=stra2num(get(handles.i2,'String'));
     3015num_j1=stra2num(get(handles.j1,'String'));
     3016num_j2=stra2num(get(handles.j2,'String'));
     3017[tild,tild,tild,i1_1,i2_1,j1_1,j2_1]=fileparts_uvmat(FileIndex_1);% get the indices of the second series from the string FileIndex_1
     3018if isempty(j1_1)% case of movies, the index is not given by file index
     3019    j1_1=num_j1;
     3020end
     3021% in case of movies the index is set by edit boxes i1 or j1 (case of movies indexed by index i)
     3022errormsg=refresh_field(handles,filename,filename_1,num_i1,num_i2,num_j1,num_j2,i1_1,i2_1,j1_1,j2_1);
     3023ResizeFcn(handles.uvmat,[],handles)
     3024if isempty(errormsg)
     3025    set(handles.REFRESH,'BackgroundColor',[1 0 0])% set button color to red, update successfull
     3026else
     3027     msgbox_uvmat('ERROR',errormsg);
     3028     set(handles.REFRESH,'BackgroundColor',[1 0 1])% keep button color magenta, input not succesfull
     3029end
     3030
     3031%------------------------------------------------------------------------
     3032% --- read the input files and inputfilerefresh all the plots, including projection.
     3033% OUTPUT:
     3034%  errormsg: error message char string  =[] by default
     3035% INPUT:
     3036% FileName: first input file (=[] in the absence of input file)
     3037% FileName_1: second input file (=[] in the asbsence of second input file)
     3038% num_i1,num_i2,num_j1,num_j2; frame indices
     3039% i1_1,i2_1,j1_1,j2_1: frame indices for the second input file  (needed if FileName_1 is not empty)
     3040%------------------------------------------------------------------------
     3041function errormsg=refresh_field(handles,FileName,FileName_1,num_i1,num_i2,num_j1,num_j2,i1_1,i2_1,j1_1,j2_1)
     3042%------------------------------------------------------------------------
     3043
     3044%% initialisation
     3045pointer=get(handles.uvmat,'Pointer');
     3046if strcmp(pointer,'watch')% reinitialise the mouse if stuck to 'watch'
     3047    set(handles.CheckZoom,'Value',0)
     3048    pointer='arrow';
     3049end
     3050set(handles.uvmat,'Pointer','watch')
     3051drawnow
     3052if ~exist('Field','var')
     3053    Field={};
     3054end
     3055UvData=get(handles.uvmat,'UserData');
     3056if ishandle(handles.UVMAT_title) %remove title panel on uvmat
     3057    delete(handles.UVMAT_title)
     3058end
     3059
     3060%% determine the main input file information for action
     3061if ~exist(FileName,'file')
     3062    errormsg=['input file ' FileName ' does not exist'];
     3063    return
     3064end
     3065NomType=get(handles.NomType,'String');
     3066NomType_1='';
     3067if strcmp(get(handles.NomType_1,'Visible'),'on')
     3068    NomType_1=get(handles.NomType_1,'String');
     3069end
     3070%update the z position index
     3071mode_slice=get(handles.slices,'String');
     3072if strcmp(mode_slice,'volume')
     3073    z_index=num_j1;
     3074    set(handles.z_index,'String',num2str(z_index))
     3075else
     3076    nbslice=str2num(get(handles.num_NbSlice,'String'));
     3077    z_index=mod(num_i1-1,nbslice)+1;
     3078    set(handles.z_index,'String',num2str(z_index))
     3079end
     3080% inputfilerefresh menu for save_mask if relevant
     3081masknumber=get(handles.masklevel,'String');
     3082if length(masknumber)>=z_index
     3083    set(handles.masklevel,'Value',z_index)
     3084end
     3085
     3086%% test for need of tps
     3087check_proj_tps=0;
     3088if  (strcmp(UvData.FileType{1},'civdata')||strcmp(UvData.FileType{1},'civx'))
     3089    for iobj=1:numel(UvData.ProjObject)
     3090        if isfield(UvData.ProjObject{iobj},'ProjMode')&& strcmp(UvData.ProjObject{iobj}.ProjMode,'interp_tps')
     3091            check_proj_tps=1;
     3092            break
     3093        end
     3094    end
     3095end
     3096
     3097%% read the first input field
     3098ParamIn.ColorVar='';%default variable name for vector color
     3099frame_index=1;%default
     3100FieldName='';%default
     3101VelType='';%default
     3102switch UvData.FileType{1}
     3103    case {'civx','civdata','netcdf'};
     3104        list_fields=get(handles.FieldName,'String');% list menu fields
     3105        FieldName= list_fields{get(handles.FieldName,'Value')}; % selected field
     3106        if ~strcmp(FieldName,'get_field...')
     3107            if get(handles.FixVelType,'Value')
     3108                VelTypeList=get(handles.VelType,'String');
     3109                VelType=VelTypeList{get(handles.VelType,'Value')};
     3110            end
     3111        end
     3112        % case of input vector field, get the scalar used for vector color
     3113        if ~isempty(regexp(FieldName,'^vec('))
     3114            list_code=get(handles.ColorCode,'String');% list menu fields
     3115            index_code=get(handles.ColorCode,'Value');% selected string index
     3116            if  ~strcmp(list_code{index_code},'black') &&  ~strcmp(list_code{index_code},'white')
     3117                list_code=get(handles.ColorScalar,'String');% list menu fields
     3118                index_code=get(handles.ColorScalar,'Value');% selected string index
     3119                ParamIn.ColorVar= list_code{index_code}; % selected field
     3120            end
     3121        end
     3122    case {'video','mmreader','rdvision'}
     3123        ParamIn=UvData.MovieObject{1}; % movie object     
     3124        if strcmp(NomType,'*')
     3125            frame_index=num_i1;%frame index from a single movies or multimage
     3126        else
     3127            frame_index=num_j1;% frame index from a set of indexed movies
     3128        end
     3129    case 'multimage'
     3130        if ~strcmp(NomType,'*')
     3131            MaxIndex_j_cell=get(handles.MaxIndex_j,'String');
     3132            if num_j1>str2num(MaxIndex_j_cell{1})
     3133                errormsg='specified frame index exceeds file content';
     3134                return
     3135            else
     3136            frame_index=num_j1;%frame index for movies or multimage
     3137            end
     3138        else
     3139            MaxIndex_i_cell=get(handles.MaxIndex_i,'String');
     3140            if num_i1>str2num(MaxIndex_i_cell{1})
     3141                errormsg='specified frame index exceeds file content';
     3142                return
     3143            else
     3144            frame_index=num_i1;
     3145            end
     3146        end
     3147    case 'vol' %TODO: update
     3148        if isfield(UvData.XmlData,'Npy') && isfield(UvData.XmlData,'Npx')
     3149            ParamIn.Npy=UvData.XmlData.Npy;
     3150            ParamIn.Npx=UvData.XmlData.Npx;
     3151        else           
     3152            errormsg='Npx and Npy need to be defined in the xml file for volume images .vol';
     3153            return
     3154        end
     3155end
     3156if isstruct (ParamIn)
     3157    ParamIn.FieldName=FieldName;
     3158    ParamIn.VelType=VelType;
     3159    ParamIn.Coord_x=get(handles.Coord_x,'String');
     3160    ParamIn.Coord_y=get(handles.Coord_y,'String');
     3161    ParamIn.Coord_z=get(handles.Coord_z,'String');
     3162    TimeName=get(handles.TimeName,'String');
     3163    r=regexp(TimeName,'^(?<type>(dim:)|(var:))','names');%look for 'var:' or 'dim:' at the beginning of time name
     3164    if ~isempty(r)
     3165        frame_index=num_i1;%time index chosen by i1
     3166        if strcmp(r.type,'dim:')
     3167            ParamIn.TimeDimName=TimeName(5:end);
     3168        elseif strcmp(r.type,'var:')
     3169            ParamIn.TimeVarName=TimeName(5:end);
     3170        end
     3171    end
     3172end
     3173% check_tps = 0;         
     3174% if strcmp(UvData.FileType{1},'civdata')&&~strcmp(ParamIn.FieldName,'velocity')&&~strcmp(ParamIn.FieldName,'get_field...')
     3175%        check_tps=1;%tps needed to get the requested field
     3176% end
     3177[Field{1},ParamOut,errormsg] = read_field(FileName,UvData.FileType{1},ParamIn,frame_index);
     3178if ~isempty(errormsg)
     3179    errormsg=['uvmat / refresh_field / read_field( ' FileName ') / ' errormsg];
     3180    return
     3181end 
     3182if isfield(ParamOut,'Npx')&& isfield(ParamOut,'Npy')
     3183    set(handles.num_Npx,'String',num2str(ParamOut.Npx));% display image size on the interface
     3184    set(handles.num_Npy,'String',num2str(ParamOut.Npy));
     3185end
     3186Field{1}.ZIndex=z_index; %used for multiplane 3D calibration
     3187
     3188%% choose and read a second field FileName_1 if defined
     3189VelType_1=[];%default
     3190FieldName_1=[];
     3191ParamIn_1=[];
     3192ParamOut_1=[];
     3193frame_index_1=1;
     3194if ~isempty(FileName_1)
     3195    if ~exist(FileName_1,'file')
     3196        errormsg=['second file ' FileName_1 ' does not exist'];
     3197        return
     3198    end
     3199    switch UvData.FileType{2}
     3200        case {'civx','civdata','netcdf'};
     3201            list_fields=get(handles.FieldName_1,'String');% list menu fields
     3202            if ischar(list_fields),list_fields={list_fields};end
     3203            FieldName_1= list_fields{get(handles.FieldName_1,'Value')}; % selected field
     3204            if ~strcmp(FieldName,'get_field...')
     3205                if get(handles.FixVelType,'Value')
     3206                    VelTypeList=get(handles.VelType_1,'String');
     3207                    VelType_1=VelTypeList{get(handles.VelType_1,'Value')};% read the velocity type.
     3208                end
     3209            end
     3210            if strcmp(FieldName_1,'velocity')&& strcmp(get(handles.ColorCode,'Visible'),'on')
     3211                list_code=get(handles.ColorCode,'String');% list menu fields
     3212                index_code=get(handles.ColorCode,'Value');% selected string index
     3213                if  ~strcmp(list_code{index_code},'black') &&  ~strcmp(list_code{index_code},'white')
     3214                    list_code=get(handles.ColorScalar,'String');% list menu fields
     3215                    index_code=get(handles.ColorScalar,'Value');% selected string index
     3216                    ParamIn_1.ColorVar= list_code{index_code}; % selected field for vector color display                 
     3217                end
     3218            end
     3219        case {'video','mmreader'}
     3220            ParamIn_1=UvData.MovieObject{2};
     3221            if ~strcmp(NomType_1,'*')
     3222                frame_index_1=j1_1;%frame index for movies or multimage
     3223            else
     3224                frame_index_1=i1_1;
     3225            end 
     3226         case 'multimage'
     3227            if strcmp(NomType_1,'*')%frame index for movies or multimage
     3228                frame_index_1=i1_1;
     3229            else
     3230                frame_index_1=j1_1;
     3231            end   
     3232        case 'vol' %TODO: update
     3233            if isfield(UvData.XmlData,'Npy') && isfield(UvData.XmlData,'Npx')
     3234                ParamIn_1.Npy=UvData.XmlData.Npy;
     3235                ParamIn_1.Npx=UvData.XmlData.Npx;
     3236            else
     3237                errormsg='Npx and Npy need to be defined in the xml file for volume images .vol';
     3238                return
     3239            end
     3240    end
     3241    if isequal(get(handles.NomType_1,'Visible'),'on')
     3242        NomType_1=get(handles.NomType_1,'String');
     3243    else
     3244        NomType_1=get(handles.NomType,'String');
     3245    end
     3246    test_keepdata_1=0;% test for keeping the previous stored data if the input files are unchanged
     3247    if ~isequal(NomType_1,'*')&& isfield(UvData,'FileName_1')
     3248           test_keepdata_1= strcmp(FileName_1,UvData.FileName_1) ;
     3249    end
     3250    if test_keepdata_1
     3251        Field{2}=UvData.Field_1;% keep the stored field
     3252        ParamOut_1=UvData.ParamOut_1;
     3253    else
     3254        if isempty(ParamIn_1) || isstruct(ParamIn_1)
     3255        ParamIn_1.FieldName=FieldName_1;
     3256        ParamIn_1.VelType=VelType_1;
     3257        ParamIn_1.Coord_x=get(handles.Coord_x,'String');
     3258        ParamIn_1.Coord_y=get(handles.Coord_y,'String');
     3259        end 
     3260        [Field{2},ParamOut_1,errormsg] = read_field(FileName_1,UvData.FileType{2},ParamIn_1,frame_index_1);
     3261        if ~isempty(errormsg)
     3262            errormsg=['error in reading ' FieldName_1 ' in ' FileName_1 ': ' errormsg];
     3263            return
     3264        end
     3265        if isstruct(ParamOut_1)&&~strcmp(ParamOut_1.FieldName,'get_field...')&& (strcmp(UvData.FileType{2},'civdata')||strcmp(UvData.FileType{2},'civx'))...
     3266                &&~strcmp(ParamOut_1.FieldName,'velocity') && ~strcmp(ParamOut_1.FieldName,'get_field...')
     3267            if ~check_proj_tps
     3268            end
     3269        end
     3270    end
     3271    Field{2}.ZIndex=z_index;%used for multi-plane 3D calibration
     3272end
     3273
     3274%% update uvmat interface
     3275if isfield(ParamOut,'Npx')
     3276    set(handles.num_Npx,'String',num2str(ParamOut.Npx));% display image size on the interface
     3277    set(handles.num_Npy,'String',num2str(ParamOut.Npy));
     3278elseif isfield(ParamOut_1,'Npx')
     3279    set(handles.num_Npx,'String',num2str(ParamOut_1.Npx));% display image size on the interface
     3280    set(handles.num_Npy,'String',num2str(ParamOut_1.Npy));
     3281end
     3282
     3283%% update the display menu for the first velocity type (first menuline)
     3284test_veltype=0;
     3285if (strcmp(UvData.FileType{1},'civx')||strcmp(UvData.FileType{1},'civdata'))&& ~strcmp(FieldName,'get_field...')
     3286    test_veltype=1;
     3287    set(handles.VelType,'Visible','on')
     3288    set(handles.VelType_1,'Visible','on')
     3289    set(handles.FixVelType,'Visible','on')
     3290    menu=set_veltype_display(ParamOut.CivStage,UvData.FileType{1});
     3291    index_menu=strcmp(ParamOut.VelType,menu);%look for VelType in  the menu
     3292    index_val=find(index_menu,1);
     3293    if isempty(index_val)
     3294        index_val=1;
     3295    end
     3296    set(handles.VelType,'Value',index_val)
     3297    if ~get(handles.SubField,'value')
     3298        set(handles.VelType,'String',menu)
     3299        set(handles.VelType_1,'Value',1)
     3300        set(handles.VelType_1,'String',[{''};menu])
     3301    end
     3302else
     3303    set(handles.VelType,'Visible','off')
     3304end
     3305
     3306%% update the display menu for the second velocity type (second menuline)
     3307test_veltype_1=0;
     3308if isempty(FileName_1)
     3309elseif ~test_keepdata_1
     3310    if (strcmp(UvData.FileType{2},'civx')||strcmp(UvData.FileType{2},'civdata'))&& ~strcmp(FieldName_1,'get_field...')
     3311        test_veltype_1=1;
     3312        set(handles.VelType_1,'Visible','on')
     3313        menu=set_veltype_display(ParamOut_1.CivStage,UvData.FileType{2});
     3314        index_menu=strcmp(ParamOut_1.VelType,menu);
     3315        set(handles.VelType_1,'Value',1+find(index_menu,1))
     3316        set(handles.VelType_1,'String',[{''};menu])
     3317    else
     3318         set(handles.VelType_1,'Visible','off')
     3319    end
     3320    % update the second field menu: the same quantity
     3321    if isstruct(ParamOut_1)
     3322        % display the FieldName menu from the input file and pick the selected one:
     3323        FieldList=get(handles.FieldName_1,'String');
     3324        field_index=strcmp(ParamOut_1.FieldName,FieldList);
     3325        if ~isempty(field_index)
     3326            set(handles.FieldName_1,'Value',find(field_index,1))
     3327        end
     3328    end
     3329end
     3330if test_veltype||test_veltype_1
     3331    set(handles.FixVelType,'Visible','on')
     3332else
     3333    set(handles.FixVelType,'Visible','off')
     3334end
     3335   
     3336%% introduce w as background image by default for a new series (only for nbdim=2)
     3337if ~isfield(UvData,'NewSeries')
     3338    UvData.NewSeries=1;
     3339end
     3340%put W as background image by default if NbDim=2:
     3341if  UvData.NewSeries && isequal(get(handles.SubField,'Value'),0) && isfield(Field{1},'W') && ~isempty(Field{1}.W) && ~isequal(Field{1}.NbDim,3);
     3342        set(handles.SubField,'Value',1);
     3343        set(handles.RootPath_1,'String','"')
     3344        set(handles.RootFile_1,'String','"')
     3345        set(handles.SubDir_1,'String','"');
     3346         indices=fullfile_uvmat('','','','',NomType,num_i1,num_i2,num_j1,num_j2);
     3347        set(handles.FileIndex_1,'String',indices)
     3348        set(handles.FileExt_1,'String','"');
     3349        set(handles.FieldName_1,'Visible','on');
     3350        set(handles.FieldName_1,'Visible','on');
     3351        set(handles.RootPath_1,'Visible','on')
     3352        set(handles.RootFile_1,'Visible','on')
     3353        set(handles.SubDir_1,'Visible','on');
     3354        set(handles.FileIndex_1,'Visible','on');
     3355        set(handles.FileExt_1,'Visible','on');
     3356        set(handles.FieldName_1,'Visible','on');
     3357        Field{1}.AName='w';
     3358end           
     3359
     3360%% display time value of the current file
     3361abstime=[];%default inputs
     3362dt=[];
     3363TimeUnit='';
     3364if isfield(UvData,'TimeUnit')
     3365    TimeUnit=UvData.TimeUnit;%retrieve info from update_rootinfo
     3366end
     3367TimeName=get(handles.TimeName,'String');
     3368
     3369% time from xml file or video movie
     3370if strcmp(TimeName,'xml')||strcmp(TimeName,'video')
     3371    if isempty(num_i2)||isnan(num_i2)
     3372        num_i2=num_i1;
     3373    end
     3374    if isempty(num_j1)||isnan(num_j1)
     3375        num_j1=1;
     3376    end
     3377    if isempty(num_j2)||isnan(num_j2)
     3378        num_j2=num_j1;
     3379    end
     3380    siz=size(UvData.XmlData{1}.Time);
     3381    if ~isempty(num_i1)&& ~isempty(num_i2) && num_i1>=0 &&siz(1)>=max(num_i1+1,num_i2+1) && siz(2)>=max(num_j1+1,num_j2+1)
     3382        abstime=(UvData.XmlData{1}.Time(num_i1+1,num_j1+1)+UvData.XmlData{1}.Time(num_i2+1,num_j2+1))/2;%overset the time read from files
     3383        dt=(UvData.XmlData{1}.Time(num_i2+1,num_j2+1)-UvData.XmlData{1}.Time(num_i1+1,num_j1+1));
     3384        Field{1}.Dt=dt;
     3385        if isfield(UvData.XmlData{1},'TimeUnit')
     3386            TimeUnit=UvData.XmlData{1}.TimeUnit;
     3387        end
     3388    end
     3389end
     3390
     3391% time in the input file, not defined in a xml file or movie
     3392if isempty(abstime)
     3393    if strcmp(TimeName,'civdata')||strcmp(TimeName,'civx')||strcmp(TimeName,'timestamp')
     3394        abstime=Field{1}.Time;
     3395    elseif ~isempty(regexp(TimeName,'^att:', 'once'))
     3396        abstime=Field{1}.(TimeName(5:end));%the time is an attribute  selected by get_file
     3397        if isfield(Field{1},[TimeName(5:end) 'Unit'])
     3398            TimeUnit=Field{1}.([TimeName(5:end) 'Unit']);
     3399        else
     3400            TimeUnit='';
     3401        end
     3402    elseif  ~isempty(regexp(TimeName,'^var:'))
     3403        abstime=Field{1}.(TimeName(5:end));%the time is a variale selected by get_file
     3404        % TODO: look for time unit attribute
     3405    elseif ~isempty(regexp(TimeName,'^dim:'))
     3406        abstime=str2num(get(handles.i1,'String'));
     3407        TimeUnit='index';
     3408    end
     3409    if isfield(Field{1},'Dt')
     3410        dt=Field{1}.Dt;%dt read from the netcdf input file
     3411    elseif numel(Field)==2 && isfield(Field{2},'Dt')%dt obtained from the second field if not defined in the first
     3412        dt=Field{2}.Dt;%dt read from the netcdf input file
     3413    end
     3414end
     3415set(handles.TimeValue,'String',num2str(abstime))
     3416
     3417%% display time value of the second current file if relevant
     3418abstime_1=[];
     3419if ~isempty(FileName_1)
     3420    TimeName_1=get(handles.TimeName_1,'String');% indicate whether time is from xml or video
     3421    % time from xml file or video movie as a second file series
     3422    if strcmp(TimeName_1,'xml')||strcmp(TimeName_1,'video')
     3423        if numel(UvData.XmlData)==2
     3424            if isempty(i2_1)
     3425                i2_1=num_i1;
     3426            end
     3427            if isempty(j1_1)
     3428                j1_1=1;
     3429            end
     3430            if isempty(j2_1)
     3431                j2_1=j1_1;
     3432            end
     3433            siz=size(UvData.XmlData{2}.Time);
     3434            if ~isempty(i1_1) && siz(1)>=max(i1_1+1,i2_1+1) && siz(2)>=max(j1_1+1,j2_1+1)
     3435                abstime_1=(UvData.XmlData{2}.Time(i1_1+1,j1_1+1)+UvData.XmlData{2}.Time(i2_1+1,j2_1+1))/2;%overset the time read from files
     3436                Field{2}.Dt=(UvData.XmlData{2}.Time(i2_1+1,j2_1+1)-UvData.XmlData{2}.Time(i1_1+1,j1_1+1));
     3437            end
     3438        end
     3439    end
     3440   
     3441    % get time in the input file of the second series, not defined in a xml file or movie
     3442    if isempty(abstime_1) && numel(Field)==2
     3443         if strcmp(TimeName_1,'civdata')||strcmp(TimeName_1,'civx')
     3444        abstime_1=Field{2}.Time;
     3445         elseif  ~isempty(regexp(TimeName_1,'^att:')) ||~isempty(regexp(TimeName_1,'^dim:'))||~isempty(regexp(TimeName_1,'^var:'))
     3446        abstime_1=Field{2}.(TimeName_1(5:end));%the time is an attribute or variale selected by get_file
     3447         end
     3448    end
     3449    set(handles.TimeValue_1,'String',num2str(abstime_1,5))
     3450end
     3451
     3452if isempty(dt)||isequal(dt,0)
     3453    set(handles.Dt_txt,'String','')
     3454else
     3455    if  isempty(TimeUnit)
     3456        set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) '  10^(-3)'] )
     3457    else
     3458        set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) '  m' TimeUnit] )
     3459    end
     3460end
     3461
     3462%% Time title with unit
     3463if isempty(abstime)&&isempty(abstime_1)
     3464    Time_title='';
     3465else
     3466    Time_title='Time';
     3467    if ~isempty(TimeUnit)
     3468        Time_title=['Time (' TimeUnit ')'];
     3469    end
     3470end
     3471set(handles.Time_title,'String',Time_title)
     3472
     3473%% store the current open names, fieldname and vel types in uvmat interface
     3474UvData.FileName_1=FileName_1;
     3475UvData.ParamOut_1=ParamOut_1;
     3476if numel(Field)==2
     3477    UvData.Field_1=Field{2}; %store the second field for possible use at next RUN
     3478end
     3479
     3480%% apply coordinate transform or other user fct
     3481transform=get(handles.TransformPath,'UserData');
     3482if isempty(transform)
     3483    UvData.Field=Field{1};
     3484else
     3485    XmlData=[];%default
     3486    XmlData_1=[];%default
     3487    if isfield(UvData,'XmlData')%use geometry calib recorded from the ImaDoc xml file as first priority
     3488        XmlData=UvData.XmlData{1};
     3489        if numel(UvData.XmlData)==2
     3490            XmlData_1=UvData.XmlData{2};
     3491        end
     3492    end
     3493    switch nargin(transform)
     3494        case 4
     3495            if length(Field)==2
     3496                UvData.Field=transform(Field{1},XmlData,Field{2},XmlData_1);
     3497            else
     3498                UvData.Field=transform(Field{1},XmlData);
     3499            end
     3500        case 3
     3501            if length(Field)==2
     3502                UvData.Field=transform(Field{1},XmlData,Field{2});
     3503            else
     3504                UvData.Field=transform(Field{1},XmlData);
     3505            end
     3506        case 2
     3507            UvData.Field=transform(Field{1},XmlData);
     3508        case 1
     3509            UvData.Field=transform(Field{1});
     3510    end
     3511end
     3512
     3513%% calculate tps coefficients if needed
     3514UvData.Field=tps_coeff_field(UvData.Field,check_proj_tps);
     3515
     3516%% get bounds and dimensions of the input field
     3517UvData.Field=find_field_bounds(UvData.Field);
     3518
     3519testnewseries=UvData.NewSeries;
     3520UvData.NewSeries=0;% put to 0 the test for a new field series (set by RootPath_callback)
     3521
     3522%% reset the min and max of scalar if only the mask is displayed(TODO: check the need)
     3523% if isfield(UvData,'Mask')&& ~isfield(UvData,'A')
     3524%     set(handles.num_MinA,'String','0')
     3525%     set(handles.num_MaxA,'String','255')
     3526% end
     3527
     3528%% usual 1D (x,y) plots
     3529if UvData.Field.NbDim<=1
     3530    set(handles.Objects,'Visible','off')
     3531    [PlotType,PlotParamOut]=plot_field(UvData.Field,handles.PlotAxes,read_GUI(handles.uvmat));
     3532    errormsg=fill_GUI(PlotParamOut,handles.uvmat);
     3533    for list={'Scalar','Vectors'}
     3534        if ~isfield(PlotParamOut,list{1})
     3535            set(handles.(list{1}),'Visible','off')
     3536        end
     3537    end
     3538    set(handles.uvmat,'UserData',UvData)
     3539%% 2D or 3D fieldname are generally projected
     3540else
     3541    set(handles.Objects,'Visible','on')
     3542   
     3543    %% Plot the projections on the selected  projection objects
     3544    %if no projection object exists, create a default one
     3545    if isempty(UvData.ProjObject{1})
     3546        set(handles.ListObject,'Value',1)
     3547        set(handles.ListObject,'String',{'plane'})
     3548        UvData.ProjObject{1}.Type='plane';%main plotting plane
     3549        UvData.ProjObject{1}.ProjMode='projection';%main plotting plane
     3550        UvData.ProjObject{1}.DisplayHandle.uvmat=[]; %plane not visible in uvmat
     3551        UvData.ProjObject{1}.DisplayHandle.view_field=[]; %plane not visible in uvmat
     3552        set(handles.ListObject_1,'Value',1)
     3553        set(handles.ListObject_1,'String',{'plane'})
     3554        if UvData.Field.NbDim==3 %3D case
     3555%             ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider
     3556%             ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider
     3557            UvData.ProjObject{1}.NbDim=3;%test for 3D objects
     3558            UvData.ProjObject{1}.RangeZ=UvData.Field.CoordMesh;%main plotting plane
     3559            UvData.ProjObject{1}.Coord(1,3)=(UvData.Field.ZMin+UvData.Field.ZMax)/2;%section at a middle plane chosen
     3560            UvData.ProjObject{1}.Angle=[0 0 0];
     3561        elseif isfield(UvData,'Z')
     3562            %multilevel case (single menuplane in a 3D space)
     3563            if isfield(UvData,'CoordType')&& isequal(UvData.CoordType,'phys') && isfield(UvData,'XmlData')
     3564                XmlData=UvData.XmlData{1};
     3565                if isfield(XmlData,'PlanePos')
     3566                    UvData.ProjObject{1}.Coord=XmlData.PlanePos(UvData.ZIndex,:);
     3567                end
     3568                if isfield(XmlData,'PlaneAngle')
     3569                    siz=size(XmlData.PlaneAngle);
     3570                    indangle=min(siz(1),UvData.ZIndex);%take first angle if a single angle is defined (translating scanning)
     3571                    UvData.ProjObject{1}.PlaneAngle=XmlData.PlaneAngle(indangle,:);
     3572                end
     3573            elseif isfield(UvData,'ZIndex')
     3574                UvData.ProjObject{1}.ZObject=UvData.ZIndex;
     3575            end
     3576        end
     3577    end
     3578    IndexObj=get(handles.ListObject_1,'Value');%selected projection object for main view
     3579    if IndexObj> numel(UvData.ProjObject)
     3580        IndexObj=1;%select the first object if the selected one does not exist
     3581        set(handles.ListObject_1,'Value',1)
     3582    end
     3583    if get(handles.CheckViewField,'Value')
     3584        IndexObj_2=get(handles.ListObject,'Value');%selected projection object for view_field
     3585        if ~isequal(IndexObj_2,IndexObj(1))
     3586            IndexObj(2)=IndexObj_2;
     3587        end
     3588    end
     3589    plot_handles{1}=handles;
     3590    if isfield(UvData,'plotaxes')%case of movies
     3591        haxes(1)=UvData.plotaxes;
     3592    else
     3593        haxes(1)=handles.PlotAxes;
     3594    end
     3595    PlotParam{1}=read_GUI(handles.uvmat);
     3596    %default settings if vectors not visible
     3597    if ~isfield(PlotParam{1},'Vectors')
     3598        PlotParam{1}.Vectors.MaxVec=1;
     3599        PlotParam{1}.Vectors.MinVec=0;
     3600        PlotParam{1}.Vectors.CheckFixVecColor=1;
     3601        PlotParam{1}.Vectors.ColCode1=0.33;
     3602        PlotParam{1}.Vectors.ColCode2=0.66;
     3603        PlotParam{1}.Vectors.ColorScalar={''};
     3604        PlotParam{1}.Vectors.ColorCode= {'rgb'};
     3605    end
     3606    %PosColorbar{1}=UvData.OpenParam.PosColorbar;%prescribe the colorbar position on the uvmat interface
     3607   
     3608    %% second projection object (view_field display)
     3609    if length( IndexObj)==2
     3610        view_field_handle=findobj(allchild(0),'tag','view_field');%handles of the view_field GUI
     3611        if ~isempty(view_field_handle)
     3612            plot_handles{2}=guidata(view_field_handle);
     3613            haxes(2)=plot_handles{2}.PlotAxes;
     3614            PlotParam{2}=read_GUI(view_field_handle);
     3615            %PosColorbar{2}='*'; %TODO: deal with colorbar position on view_field
     3616        end
     3617    end
     3618   
     3619    %% loop on the projection objects: one or two
     3620   
     3621    for imap=1:numel(IndexObj)
     3622        iobj=IndexObj(imap);
     3623        if numel(UvData.ProjObject)<iobj
     3624            break
     3625        end
     3626        if UvData.Field.NbDim==3
     3627            UvData.ProjObject{iobj}.NbDim=3;%test for 3D objects
     3628            if ~isfield(UvData.ProjObject{iobj},'RangeZ')
     3629            UvData.ProjObject{iobj}.RangeZ=UvData.Field.CoordMesh;%main plotting plane
     3630            end
     3631            if ~(isfield(UvData.ProjObject{iobj},'Coord') && UvData.ProjObject{iobj}.Coord(1,3)<UvData.Field.ZMax && UvData.ProjObject{iobj}.Coord(1,3)>UvData.Field.ZMin)
     3632                 UvData.ProjObject{iobj}.Coord(1,3)=(UvData.Field.ZMin+UvData.Field.ZMax)/2;%section at a middle plane chosen
     3633            end         
     3634        end
     3635        [ObjectData,errormsg]=proj_field(UvData.Field,UvData.ProjObject{iobj});% project field on the object
     3636        if ~isempty(errormsg)
     3637            return
     3638        end
     3639        if testnewseries
     3640            PlotParam{imap}.Scalar.CheckBW=[]; %B/W option depends on the input field (image or scalar)
     3641            if isfield(ObjectData,'CoordUnit')
     3642                PlotParam{imap}.Axes.CheckFixAspectRatio=1;% set x and y scaling equal if CoordUnit is defined (common unit for x and y)
     3643                PlotParam{imap}.Axes.AspectRatio=1; %set aspect ratio to 1
     3644            end
     3645        end
     3646        %use of mask (TODO: check)
     3647        if isfield(ObjectData,'NbDim') && isequal(ObjectData.NbDim,2) && isfield(ObjectData,'Mask') && isfield(ObjectData,'A')
     3648            flag_mask=double(ObjectData.Mask>200);%=0 for masked regions
     3649            Coord_x=ObjectData.Coord_x;%x coordiantes for the scalar field
     3650            Coord_y=ObjectData.Coord_y;%y coordinates for the scalar field
     3651            MaskX=ObjectData.MaskX;%x coordiantes for the mask
     3652            MaskY=ObjectData.MaskY;%y coordiantes for the mask
     3653            if ~isequal(MaskX,Coord_x)||~isequal(MaskY,Coord_y)
     3654                nxy=size(flag_mask);
     3655                sizpx=(ObjectData.MaskX(end)-ObjectData.MaskX(1))/(nxy(2)-1);%size of a mask pixel
     3656                sizpy=(ObjectData.MaskY(1)-ObjectData.MaskY(end))/(nxy(1)-1);
     3657                x_mask=ObjectData.MaskX(1):sizpx:ObjectData.MaskX(end); % pixel x coordinates for image display
     3658                y_mask=ObjectData.MaskY(1):-sizpy:ObjectData.MaskY(end);% pixel x coordinates for image display
     3659                %project on the positions of the scalar
     3660                npxy=size(ObjectData.A);
     3661                dxy(1)=(ObjectData.Coord_y(end)-ObjectData.Coord_y(1))/(npxy(1)-1);%grid mesh in y
     3662                dxy(2)=(ObjectData.Coord_x(end)-ObjectData.Coord_x(1))/(npxy(2)-1);%grid mesh in x
     3663                xi=ObjectData.Coord_x(1):dxy(2):ObjectData.Coord_x(end);
     3664                yi=ObjectData.Coord_y(1):dxy(1):ObjectData.Coord_y(end);
     3665                [XI,YI]=meshgrid(xi,yi);% creates the matrix of regular coordinates
     3666                flag_mask = interp2(x_mask,y_mask,flag_mask,XI,YI);
     3667            end
     3668            AClass=class(ObjectData.A);
     3669            ObjectData.A=flag_mask.*double(ObjectData.A);
     3670            ObjectData.A=feval(AClass,ObjectData.A);
     3671        end       
     3672        set(handles.uvmat,'UserData',UvData)
     3673        if ~isempty(ObjectData)
     3674            %PlotType='none'; %default
     3675            if imap==2 && isempty(view_field_handle)
     3676                view_field(ObjectData)
     3677            else
     3678                [PlotType,PlotParamOut]=plot_field(ObjectData,haxes(imap),PlotParam{imap});
     3679                if imap==1
     3680                    errormsg=fill_GUI(PlotParamOut,handles.uvmat);
     3681                else
     3682                    errormsg=fill_GUI(PlotParamOut,view_field_handle);
     3683                end
     3684                for list={'Scalar','Vectors'}
     3685                    if ~isfield(PlotParamOut,list{1})
     3686                        set(plot_handles{imap}.(list{1}),'Visible','off')
     3687                    end
     3688                end
     3689                if isfield(Field,'CoordMesh')&&~isempty(Field.CoordMesh)
     3690                    ObjectData.CoordMesh=Field.CoordMesh; % gives an estimated mesh size (useful for mouse action on the plot)
     3691                end
     3692            end
     3693        end
     3694    end
     3695   
     3696    %% update the mask
     3697    if isequal(get(handles.CheckMask,'Value'),1)%if the mask option is on
     3698        update_mask(handles);
     3699    end
     3700   
     3701    %% prepare the menus of histograms and plot them (histogram of the whole volume in 3D case)
     3702    menu_histo=(UvData.Field.ListVarName)';%list of field variables to be displayed for the menu of histogram display
     3703    ind_skip=[];
     3704    % nb_histo=1;
     3705    Ustring='';
     3706    Vstring='';
     3707    % suppress axes from the histogram menu
     3708    for ivar=1:numel(menu_histo)%l loop on field variables:
     3709        if isfield(UvData.Field,'VarAttribute') && numel(UvData.Field.VarAttribute)>=ivar && isfield(UvData.Field.VarAttribute{ivar},'Role')
     3710            Role=UvData.Field.VarAttribute{ivar}.Role;
     3711            switch Role
     3712                case {'coord_x','coord_y','coord_z','dimvar'}
     3713                    ind_skip=[ind_skip ivar];
     3714                case {'vector_x'}
     3715                    Ustring=UvData.Field.ListVarName{ivar};
     3716                    ind_skip=[ind_skip ivar];
     3717                case {'vector_y'}
     3718                    Vstring=UvData.Field.ListVarName{ivar};
     3719                    ind_skip=[ind_skip ivar];
     3720            end
     3721        end
     3722        DimCell=UvData.Field.VarDimName{ivar};
     3723        DimName='';
     3724        if ischar(DimCell)
     3725            DimName=DimCell;
     3726        elseif iscell(DimCell)&& numel(DimCell)==1
     3727            DimName=DimCell{1};
     3728        end
     3729        if strcmp(DimName,menu_histo{ivar})
     3730            ind_skip=[ind_skip ivar];
     3731        end
     3732    end
     3733    menu_histo(ind_skip)=[];% remove skipped items
     3734    if ~isempty(Ustring)
     3735        menu_histo=[{[Ustring ',' Vstring]};menu_histo];% add U, V at the beginning if they exist
     3736    end
     3737   
     3738    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     3739    % display menus and plot histograms
     3740    test_v=0;
     3741    if ~isempty(menu_histo)
     3742        set(handles.histo1_menu,'Value',1)
     3743        set(handles.histo1_menu,'String',menu_histo)
     3744        histo1_menu_Callback(handles.histo1_menu, [], handles)% plot first histogram
     3745    end
     3746end
     3747
     3748if UvData.Field.NbDim==3
     3749    set(handles.CheckEditObject,'Value',1)
     3750    CheckEditObject_Callback(handles.uvmat, [], handles)
     3751end   
     3752%ResizeFcn(handles.uvmat,[],handles)
     3753set(handles.uvmat,'Pointer',pointer)
     3754
     3755%------------------------------------------------------------------------
     3756function histo1_menu_Callback(hObject, eventdata, handles)
     3757%--------------------------------------------
     3758%% get the current field stored in uvmat user data
     3759UvData=get(handles.uvmat,'UserData');
     3760Field=UvData.Field;
     3761
     3762%% get from the menu 'histo1_menu' the name(s) of the fields to use
     3763histo_menu=get(handles.histo1_menu,'String');
     3764histo_value=get(handles.histo1_menu,'Value');
     3765FieldName=histo_menu{histo_value};
     3766r=regexp(FieldName,'(?<var1>.*)(?<sep>,)(?<var2>.*)','names');
     3767FieldName_2='';
     3768if ~isempty(r)
     3769    FieldName=r.var1;% name of first variable
     3770    FieldName_2=r.var2;% name of second variable
     3771end
     3772if ~isfield(UvData.Field,FieldName)
     3773    msgbox_uvmat('ERROR',['no field  ' FieldName ' for histogram'])
     3774    return
     3775end
     3776
     3777%% extract the fields to use
     3778% eliminate false data if relevant (false flag FF exists)
     3779check_false=0;
     3780if isfield(Field,'FF') && ~isempty(Field.FF) && isequal(size(Field.FF),size(Field.(FieldName)))
     3781    indsel=find(Field.FF==0);%find values marked as false
     3782    if ~isempty(indsel)
     3783        FieldHisto=Field.(FieldName)(indsel);%field of the first variable (U)
     3784        if ~isempty(FieldName_2)
     3785            if isfield(Field,'NbDim') && Field.NbDim==3
     3786                 FieldHisto(:,:,:,2)=Field.(FieldName_2)(indsel);%field of the second variable (U)
     3787            else
     3788            FieldHisto(:,:,2)=Field.(FieldName_2)(indsel);%field of the second variable (U)
     3789            end
     3790        end
     3791        check_false=1;
     3792    end
     3793end
     3794% no false data
     3795if ~check_false
     3796    FieldHisto=Field.(FieldName);%field of the first variable (U)
     3797    if ~isempty(FieldName_2)
     3798        if isfield(Field,'NbDim') && Field.NbDim==3
     3799            FieldHisto(:,:,:,2)=Field.(FieldName_2);%field of the second variable (V)
     3800        else
     3801            FieldHisto(:,:,2)=Field.(FieldName_2);%field of the second variable (V)
     3802        end
     3803    end
     3804end
     3805
     3806%% calculate and plot histogram
     3807if isempty(Field)
     3808    msgbox_uvmat('ERROR',['empty field ' FieldName])
     3809else
     3810    nxy=size(FieldHisto);
     3811    Amin=double(min(min(min(min(FieldHisto)))));%min of field value
     3812    Amax=double(max(max(max(max(FieldHisto)))));%max of field value
     3813    if isequal(Amin,Amax)
     3814        cla(handles.HistoAxes)
     3815    else
     3816        Histo.ListVarName={FieldName,'histo'};
     3817        if isfield(Field,'NbDim') && isequal(Field.NbDim,3)
     3818            Histo.VarDimName={FieldName,FieldName}; %dimensions for the histogram
     3819        else
     3820            if numel(nxy)==2
     3821                Histo.VarDimName={FieldName,FieldName}; %dimensions for the histogram
     3822            else
     3823                Histo.VarDimName={FieldName,{FieldName,'component'}}; %dimensions for the histogram
     3824            end
     3825        end
     3826        %unit
     3827        units=[]; %default
     3828        for ivar=1:numel(Field.ListVarName)
     3829            if strcmp(Field.ListVarName{ivar},FieldName)
     3830                if isfield(Field,'VarAttribute') && numel(Field.VarAttribute)>=ivar && isfield(Field.VarAttribute{ivar},'units')
     3831                    units=Field.VarAttribute{ivar}.units;
     3832                    break
     3833                end
     3834            end
     3835        end
     3836        if ~isempty(units)
     3837            Histo.VarAttribute{1}.units=units;
     3838        end
     3839        Histo.(FieldName)=linspace(Amin,Amax,50); %absissa values for histo
     3840        if isfield(Field,'NbDim') && isequal(Field.NbDim,3)
     3841            C=reshape(double(FieldHisto),1,[]);% reshape in a vector
     3842            Histo.histo(:,1)=hist(C, Histo.(FieldName));  %calculate histogram
     3843        else
     3844            for col=1:size(FieldHisto,3)
     3845                B=FieldHisto(:,:,col);
     3846                C=reshape(double(B),1,nxy(1)*nxy(2));% reshape in a vector
     3847                Histo.histo(:,col)=hist(C, Histo.(FieldName));  %calculate histogram
     3848            end
     3849        end
     3850        plot_field(Histo,handles.HistoAxes);
     3851        hlegend=legend;
     3852        if isempty(FieldName_2)
     3853        set(hlegend,'String',FieldName)
     3854        else
     3855            set(hlegend,'String',{FieldName;FieldName_2})
     3856        end
     3857    end
     3858end
     3859
     3860%------------------------------------------------------------------------
     3861% --- translate coordinate to matrix index
     3862%------------------------------------------------------------------------
     3863function [indx,indy]=pos2ind(x0,rangx0,nxy)
     3864indx=1+round((nxy(2)-1)*(x0-rangx0(1))/(rangx0(2)-rangx0(1)));% index x of pixel 
     3865indy=1+round((nxy(1)-1)*(y12-rangy0(1))/(rangy0(2)-rangy0(1)));% index y of pixel
     3866
     3867%------------------------------------------------------------------------
     3868% --- Executes on button press in 'CheckZoom'.
     3869%------------------------------------------------------------------------
     3870function CheckZoom_Callback(hObject, eventdata, handles)
     3871
     3872    if get(handles.CheckZoom,'Value')
     3873        set(handles.CheckFixLimits,'Value',1)% propose by default fixed limits for the plotting axes
     3874        set(handles.CheckZoomFig,'Value',0)%desactivate zoom fig
     3875    end
     3876
     3877
     3878%------------------------------------------------------------------------
     3879% --- Executes on button press in CheckZoomFig.
     3880%------------------------------------------------------------------------
     3881function CheckZoomFig_Callback(hObject, eventdata, handles)
     3882
     3883if get(handles.CheckZoomFig,'Value')
     3884    set(handles.CheckZoom,'value',0)
     3885end
     3886
     3887%------------------------------------------------------------------------
     3888% --- Executes on button press in 'CheckFixLimits'.
     3889%------------------------------------------------------------------------
     3890function CheckFixLimits_Callback(hObject, eventdata, handles)
     3891
     3892if ~get(handles.CheckFixLimits,'Value')
     3893    update_plot(handles)
     3894    set(handles.CheckZoom,'Value',0)
     3895end
     3896
     3897%------------------------------------------------------------------------
     3898% --- Executes on button press in CheckFixAspectRatio.
     3899function CheckFixAspectRatio_Callback(hObject, eventdata, handles)
     3900%------------------------------------------------------------------------
     3901 update_plot(handles);
     3902
     3903%------------------------------------------------------------------------
     3904function num_AspectRatio_Callback(hObject, eventdata, handles)
     3905%------------------------------------------------------------------------
     3906set(handles.CheckFixAspectRatio,'Value',1)% select the fixed aspect ratio button
     3907update_plot(handles);
     3908
     3909%------------------------------------------------------------------------
     3910%----Executes on button press in 'record': records the current flags of manual correction.
     3911%------------------------------------------------------------------------
     3912function record_Callback(hObject, eventdata, handles)
     3913
     3914[RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles);
     3915FileName=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt];
     3916[erread,message]=fileattrib(FileName);
     3917if ~isempty(message) && ~isequal(message.UserWrite,1)
     3918     msgbox_uvmat('ERROR',['no writting access to ' FileName])
     3919     return
     3920end
     3921MenuVelType=get(handles.VelType,'String');
     3922test_civ2=strcmp(MenuVelType{get(handles.VelType,'Value')},'civ2');
     3923test_civ1=strcmp(MenuVelType{get(handles.VelType,'Value')},'civ1');
     3924if ~test_civ2 && ~test_civ1
     3925    msgbox_uvmat('ERROR','manual correction only possible for CIV1 or CIV2 velocity fields')
     3926end
     3927if test_civ2
     3928    nbname='nb_vec_2';
     3929   flagname='Civ2_FF';
     3930   CivStage=5;
     3931end
     3932if test_civ1
     3933    nbname='nb_vec_1';
     3934   flagname='Civ1_FF';
     3935    CivStage=2;
     3936end
     3937%write fix flags in the netcdf file
     3938UvData=get(handles.uvmat,'UserData');
     3939hhh=which('netcdf.open');% look for built-in matlab netcdf library
     3940if ~isequal(hhh,'')% case of  builtin Matlab netcdf library
     3941    nc=netcdf.open(FileName,'NC_WRITE');
     3942    netcdf.reDef(nc);
     3943    netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'CivStage',CivStage);
     3944    dimid = netcdf.inqDimID(nc,nbname);
     3945    try
     3946        varid = netcdf.inqVarID(nc,flagname);% look for already existing fixflag variable
     3947    catch
     3948        varid=netcdf.defVar(nc,flagname,'double',dimid);%create fixflag variable if it does not exist
     3949    end
     3950    netcdf.endDef(nc);
     3951    netcdf.putVar(nc,varid,UvData.PlotAxes.FF);
     3952    netcdf.close(nc); 
     3953else %old netcdf library
     3954    netcdf_toolbox(FileName,AxeData,attrname,nbname,flagname)
     3955end
     3956
     3957%-------------------------------------------------------------------
     3958%----Correct the netcdf file, using toolbox (old versions of Matlab).
     3959%-------------------------------------------------------------------
     3960function netcdf_toolbox(FileName,AxeData,attrname,nbname,flagname)
     3961nc=netcdf(FileName,'write'); %open netcdf file
     3962result=redef(nc);
     3963eval(['nc.' attrname '=1;']);
     3964theDim=nc(nbname) ;% get the number of velocity vectors
     3965nb_vectors=size(theDim);
     3966var_FixFlag=ncvar(flagname,nc);% var_FixFlag will be written as the netcdf variable vec_FixFlag
     3967var_FixFlag(1:nb_vectors)=AxeData.FF;%
     3968fin=close(nc);
     3969
     3970%-----------------------------------------------------------------------
     3971% --- Executes on button press in SubField
     3972%-----------------------------------------------------------------------
     3973function SubField_Callback(hObject, eventdata, handles)
     3974
     3975if get(handles.SubField,'Value')==0% if the subfield button is desactivated 
     3976    desable_subfield(handles)
     3977    transform_fct_list=get(handles.TransformName,'String');
     3978    transform_fct=transform_fct_list(get(handles.TransformName,'Value'));
     3979    if strcmp(transform_fct,'sub_field')
     3980        set(handles.TransformName,'Value',1)%suppress the sub_field transform
     3981        TransformName_Callback(hObject, eventdata, handles);
     3982    else
     3983        REFRESH_Callback(hObject, eventdata, handles)
     3984    end 
     3985else
     3986    fileinput_1=uigetfile_uvmat('select a second input file:',get(handles.RootPath,'String'));
     3987    if isempty(fileinput_1)
     3988        set(handles.SubField,'Value',0)
     3989    else       
     3990        % refresh the current displayed field
     3991        display_file_name(handles,fileinput_1,2)
     3992       
     3993        %update list of recent files in the menubar
     3994        MenuFile_1=fileinput_1;
     3995        MenuFile_2=get(handles.MenuFile_1,'Label');
     3996        MenuFile_3=get(handles.MenuFile_2,'Label');
     3997        MenuFile_4=get(handles.MenuFile_3,'Label');
     3998        MenuFile_5=get(handles.MenuFile_4,'Label');
     3999        set(handles.MenuFile_1,'Label',MenuFile_1)
     4000        set(handles.MenuFile_2,'Label',MenuFile_2)
     4001        set(handles.MenuFile_3,'Label',MenuFile_3)
     4002        set(handles.MenuFile_4,'Label',MenuFile_4)
     4003        set(handles.MenuFile_5,'Label',MenuFile_5)
     4004    end
     4005end
     4006
     4007%-----------------------------------------------------------------------
     4008% --- desactivate display used for a second file series
     4009%-----------------------------------------------------------------------
     4010function desable_subfield(handles)
     4011   
     4012set(handles.RootPath_1,'String','')
     4013set(handles.RootFile_1,'String','')
     4014set(handles.SubDir_1,'String','');
     4015set(handles.FileIndex_1,'String','');
     4016set(handles.FileExt_1,'String','');
     4017set(handles.RootPath_1,'Visible','off')
     4018set(handles.RootFile_1,'Visible','off')
     4019set(handles.SubDir_1,'Visible','off');
     4020set(handles.NomType_1,'Visible','off');
     4021set(handles.FileIndex_1,'Visible','off');
     4022set(handles.FileExt_1,'Visible','off');
     4023set(handles.TimeName_1,'String','');
     4024set(handles.TimeName_1,'Visible','off');
     4025set(handles.TimeValue_1,'String','');
     4026set(handles.TimeValue_1,'Visible','off');
     4027set(handles.FieldName_1,'Value',1);%set to blank state
     4028set(handles.VelType_1,'Value',1);%set to blank state
     4029set(handles.num_Opacity,'String','')% desactivate opacity setting
     4030FieldList=get(handles.FieldName,'String');
     4031if numel(FieldList)>1   % if a choice of fields exists
     4032    set(handles.FieldName_1,'Value',1)% set second field choice to blank
     4033    set(handles.FieldName_1,'String',[{''};FieldList])% reproduce the menu FieldName plus a blank option
     4034else
     4035    set(handles.FieldName_1,'String',{''})% set second field choice to blank
     4036end
     4037if ~strcmp(get(handles.VelType,'Visible'),'on')
     4038    set(handles.VelType_1,'Visible','off')
     4039end
     4040UvData=get(handles.uvmat,'UserData');
     4041if isfield(UvData,'XmlData_1')
     4042    UvData=rmfield(UvData,'XmlData_1');
     4043end
     4044set(handles.uvmat,'UserData',UvData);
     4045
     4046%------------------------------------------------------------------------
     4047% --- read the data displayed for the input rootfile windows (new): TODO use read_GUI
     4048%------------------------------------------------------------------------
     4049function [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles)
     4050
     4051InputFile=read_GUI(handles.InputFile);
     4052RootPath=InputFile.RootPath;
     4053SubDir=regexprep(InputFile.SubDir,'/|\','');
     4054RootFile=regexprep(InputFile.RootFile,'/|\','');
     4055FileIndices=InputFile.FileIndex;
     4056FileExt=InputFile.FileExt;
     4057
     4058
     4059%------------------------------------------------------------------------
     4060% ---- read the data displayed for the second input rootfile windows
     4061%------------------------------------------------------------------------
     4062function [RootPath_1,SubDir_1,RootFile_1,FileIndex_1,FileExt_1,NomType_1]=read_file_boxes_1(handles)
     4063
     4064RootPath_1=get(handles.RootPath_1,'String'); % read the data from the file1_input window
     4065if isequal(get(handles.RootPath_1,'Visible'),'off') || isequal(RootPath_1,'"')
     4066    RootPath_1=get(handles.RootPath,'String');
     4067end;
     4068SubDir_1=get(handles.SubDir_1,'String');
     4069if isequal(get(handles.SubDir_1,'Visible'),'off')|| isequal(SubDir_1,'"')
     4070    SubDir_1=get(handles.SubDir,'String');
     4071end
     4072SubDir_1=regexprep(SubDir_1,'\<[\\/]|[\\/]\>','');%suppress possible / or \ separator at the beginning or the end of the string
     4073RootFile_1=get(handles.RootFile_1,'String');
     4074if isequal(get(handles.RootFile_1,'Visible'),'off') || isequal(RootFile_1,'"')
     4075    RootFile_1=get(handles.RootFile,'String');
     4076end
     4077RootFile_1=regexprep(RootFile_1,'\<[\\/]|[\\/]\>','');%suppress possible / or \ separator at the beginning or the end of the string
     4078FileIndex_1=get(handles.FileIndex_1,'String');
     4079if isequal(get(handles.FileIndex_1,'Visible'),'off')|| isequal(FileIndex_1,'"')
     4080    FileIndex_1=get(handles.FileIndex,'String');
     4081end
     4082FileExt_1=get(handles.FileExt_1,'String');
     4083if isequal(get(handles.FileExt_1,'Visible'),'off') || isequal(FileExt_1,'"')
     4084    FileExt_1=get(handles.FileExt,'String');%read FileExt by default
     4085end
     4086NomType_1=get(handles.NomType_1,'String');
     4087if isequal(get(handles.NomType_1,'Visible'),'off') || isequal(NomType_1,'"')
     4088    NomType_1=get(handles.NomType,'String');%read FileExt by default
     4089end
     4090%------------------------------------------------------------------------
     4091% --- Executes on menu selection FieldName
     4092
     4093    function FieldName_Callback(hObject, eventdata, handles)
     4094%------------------------------------------------------------------------
     4095
     4096%% read data from uvmat
     4097UvData=get(handles.uvmat,'UserData');
     4098list_fields=get(handles.FieldName,'String');% list menu fields
     4099index_fields=get(handles.FieldName,'Value');% selected string index
     4100field= list_fields{index_fields(1)}; % selected string
     4101[RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles);
     4102FileName=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt];
     4103[tild,tild,tild,i1,i2,j1,j2,tild,NomType]=fileparts_uvmat(['xxx' get(handles.FileIndex,'String') FileExt]);
     4104
     4105switch field 
     4106    case 'get_field...'
     4107        %% fill the axes and variables from selections in get_field
     4108        ParamIn.Title='get_field: choose input field for display in uvmat' ;
     4109        % in case of civ data, we use the civ choice as default input for the GUI get_field
     4110        if strcmp(get(handles.VelType,'Visible'),'on')
     4111            ParamIn.SwitchVarIndexTime='attribute';
     4112            ListVelType=get(handles.VelType,'String');
     4113            VelType=ListVelType{get(handles.VelType,'Value')};
     4114            switch VelType
     4115                case 'civ1'
     4116                    ParamIn.TimeAttrName='Civ1_Time';
     4117                    ParamIn.vector_x='Civ1_U';
     4118                    ParamIn.vector_y='Civ1_V';
     4119                    ParamIn.vec_color='Civ1_C';
     4120                case 'filter1'
     4121                    ParamIn.TimeAttrName='Civ1_Time';
     4122                    ParamIn.vector_x='Civ1_U_smooth';
     4123                    ParamIn.vector_y='Civ1_V_smooth';
     4124                case 'civ2'
     4125                    ParamIn.TimeAttrName='Civ2_Time';
     4126                    ParamIn.vector_x='Civ2_U';
     4127                    ParamIn.vector_y='Civ2_V';
     4128                case 'filter2'
     4129                    ParamIn.TimeAttrName='Civ2_Time';
     4130                    ParamIn.vector_x='Civ2_U_smooth';
     4131                    ParamIn.vector_y='Civ2_V_smooth';
     4132                    ParamIn.vec_color='Civ2_C';
     4133            end
     4134        end
     4135       
     4136        % VelType menu desactivated
     4137        set(handles.FixVelType,'visible','off')
     4138        set(handles.VelType,'Visible','off')
     4139       
     4140        %read selection from get_field
     4141        [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles);
     4142        FileName=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt];
     4143        GetFieldData=get_field(FileName,ParamIn);% inport field names from the GUI get_field
     4144        FieldList={};
     4145        VecColorList={''};
     4146        ZName='';
     4147        switch GetFieldData.FieldOption
     4148            case 'vectors'
     4149                UName=GetFieldData.PanelVectors.vector_x;
     4150                VName=GetFieldData.PanelVectors.vector_y;
     4151                YName=GetFieldData.Coordinates.Coord_y;
     4152                if isfield(GetFieldData.Coordinates,'Coord_z')
     4153                ZName=GetFieldData.Coordinates.Coord_z;
     4154                end
     4155                CName=GetFieldData.PanelVectors.vec_color;
     4156                FieldList={['vec(' UName ',' VName ')'];...
     4157                    ['norm(' UName ',' VName ')'];...
     4158                    UName;VName};
     4159                VecColorList={['norm(' UName ',' VName ')'];...
     4160                    UName;VName};
     4161                if ~isempty(CName)
     4162                    VecColorList=[{CName};VecColorList];
     4163                end
     4164            case 'scalar'
     4165                AName=GetFieldData.PanelScalar.scalar;
     4166                YName=GetFieldData.Coordinates.Coord_y;
     4167                if isfield(GetFieldData.Coordinates,'Coord_z')
     4168                ZName=GetFieldData.Coordinates.Coord_z;
     4169                end
     4170                FieldList={AName};
     4171            case '1D plot'
     4172                YName=GetFieldData.PanelOrdinate.ordinate;
     4173            case 'civdata...'%reinitiate input, return to automatic civ data reading
     4174                display_file_name(handles,FileName,1)
     4175        end
     4176        % get time as file index, attribute, variable or matrix index
     4177        if ~strcmp(GetFieldData.FieldOption,'civdata...')
     4178            XName=GetFieldData.Coordinates.Coord_x;
     4179            TimeNameStr=GetFieldData.Time.SwitchVarIndexTime;
     4180            switch TimeNameStr
     4181                case 'file index'
     4182                    set(handles.TimeName,'String','');
     4183                case 'attribute'
     4184                    set(handles.TimeName,'String',['att:' GetFieldData.Time.TimeName]);
     4185                case 'variable'
     4186                    set(handles.TimeName,'String',['var:' GetFieldData.Time.TimeName])
     4187                    set(handles.NomType,'String','*')
     4188                    set(handles.RootFile,'String',[get(handles.RootFile,'String') get(handles.FileIndex,'String')])
     4189                    set(handles.i1,'String','1')% set counter to 1 (now the time index in the input matrix)
     4190                    MaxIndex_i=get(handles.MaxIndex_i,'String');
     4191                    MaxIndex_i{1}=num2str(GetFieldData.Time.TimeDimension);
     4192                    set(handles.MaxIndex_i,'String',MaxIndex_i)%TODO: record time unit
     4193                    UvData=get(handles.uvmat,'UserData');
     4194                    UvData.TimeUnit=GetFieldData.Time.TimeUnit;
     4195                    set(handles.uvmat,'UserData',UvData);
     4196                    set(handles.FileIndex,'String','')
     4197                    ParamIn.TimeVarName=GetFieldData.Time.TimeName;
     4198                case 'matrix index'
     4199                    set(handles.TimeName,'String',['dim:' GetFieldData.Time.TimeName]);
     4200                    set(handles.NomType,'String','*')
     4201                    set(handles.RootFile,'String',[get(handles.RootFile,'String') get(handles.FileIndex,'String')])             
     4202                    set(handles.i1,'String','1')% set counter to 1 (now the time index in the input matrix)
     4203                    MaxIndex_i=get(handles.MaxIndex_i,'String');
     4204                    MaxIndex_i{1}=num2str(GetFieldData.Time.TimeDimension);
     4205                    set(handles.MaxIndex_i,'String',MaxIndex_i)%TODO: record time unit
     4206                    UvData=get(handles.uvmat,'UserData');
     4207                    UvData.TimeUnit=GetFieldData.Time.TimeUnit;
     4208                    set(handles.uvmat,'UserData',UvData);
     4209                    set(handles.FileIndex,'String','')
     4210                    ParamIn.TimeDimName=GetFieldData.Time.TimeName;
     4211            end
     4212            set(handles.Coord_x,'String',XName)
     4213%             if ischar(YName)
     4214%                 YName={YName};
     4215%             end
     4216            set(handles.Coord_y,'String',YName)
     4217            set(handles.Coord_z,'String',ZName)
     4218            set(handles.FieldName,'Value',1)
     4219            set(handles.FieldName,'String',[FieldList; {'get_field...'}]);
     4220            set(handles.ColorScalar,'Value',1)
     4221            set(handles.ColorScalar,'String',VecColorList);
     4222            UvData.FileType{1}='netcdf';
     4223            set(handles.uvmat,'UserData',UvData)
     4224            REFRESH_Callback(hObject, eventdata, handles)
     4225        end
     4226       
     4227    case 'image'
     4228        %% look for image corresponding to civ data
     4229        if  isfield(UvData.Field,'Civ2_ImageA')%get the corresponding input image in the netcdf file
     4230            imagename=UvData.Field.Civ2_ImageA;
     4231        elseif isfield(UvData.Field,'Civ1_ImageA')%
     4232            imagename=UvData.Field.Civ1_ImageA;
     4233        else
     4234            SubDirBase=regexprep(SubDir,'\..*','');%take the root part of SubDir, before the first dot '.'
     4235            imagename=fullfile_uvmat(RootPath,SubDirBase,RootFile,'.png',NomType,i1,[],j1,[]);
     4236        end
     4237        if ~exist(imagename,'file')
     4238            imagename=uigetfile_uvmat('Pick an image file',imagename,'image');
     4239            if isempty(imagename)
     4240                return
     4241            end
     4242        end
     4243        % display the selected field and related information
     4244        display_file_name(handles,imagename)%display the image
     4245    otherwise
     4246        REFRESH_Callback(hObject, eventdata, handles)
     4247end
     4248
     4249%----------------------------------------------------------------
     4250% --- Executes on menu selection FieldName
     4251function FieldName_1_Callback(hObject, eventdata, handles)
     4252%-------------------------------------------------
     4253
     4254%%%%%% TODO: modify like FieldName_Callback
     4255%% read input data
     4256check_new=~get(handles.SubField,'Value'); %check_new=1 if a second field was not previously entered
     4257UvData=get(handles.uvmat,'UserData');
     4258if check_new && isfield(UvData,'XmlData')
     4259    UvData.XmlData{2}=UvData.XmlData{1};
     4260end
     4261if isfield(UvData,'Field_1')
     4262    UvData=rmfield(UvData,'Field_1');% remove the stored second field (a new one needs to be read)
     4263end
     4264UvData.FileName_1='';% desactivate the use of a constant second file
     4265list_fields=get(handles.FieldName,'String');% list menu fields
     4266field= list_fields{get(handles.FieldName,'Value')}; % selected string
     4267list_fields=get(handles.FieldName_1,'String');% list menu fields
     4268field_1= list_fields{get(handles.FieldName_1,'Value')}; % selected string for the second field
     4269if isempty(field_1)%||(numel(UvData.FileType)>=2 && strcmp(UvData.FileType{2},'image'))
     4270    set(handles.SubField,'Value',0)
     4271    SubField_Callback(hObject, eventdata, handles)
     4272    return
     4273else
     4274    set(handles.SubField,'Value',1)%state that a second field is now entered
     4275end
     4276
     4277%% read the rootfile input display
     4278[RootPath_1,SubDir_1,RootFile_1,FileIndex_1,FileExt_1]=read_file_boxes_1(handles);
     4279FileName_1=[fullfile(RootPath_1,SubDir_1,RootFile_1) FileIndex_1 FileExt_1];
     4280[tild,tild,tild,i1,i2,j1,j2]=fileparts_uvmat(get(handles.FileIndex,'String'));
     4281switch field_1
     4282    case 'get_field...'
     4283         %% fill the axes and variables from selections in get_field
     4284        ParamIn=[];
     4285        % in case of civ data, we use the civ choice as default input for the GUI get_field
     4286        if strcmp(get(handles.VelType_1,'Visible'),'on')
     4287            ParamIn.SwitchVarIndexTime='attribute';
     4288            ListVelType=get(handles.VelType_1,'String');
     4289            VelType=ListVelType{get(handles.VelType_1,'Value')};
     4290            switch VelType
     4291                case 'civ1'
     4292                    ParamIn.TimeAttrName='Civ1_Time';
     4293                    ParamIn.vector_x='Civ1_U';
     4294                    ParamIn.vector_y='Civ1_V';
     4295                    ParamIn.vec_color='Civ1_C';
     4296                case 'filter1'
     4297                    ParamIn.TimeAttrName='Civ1_Time';
     4298                    ParamIn.vector_x='Civ1_U_smooth';
     4299                    ParamIn.vector_y='Civ1_V_smooth';
     4300                case 'civ2'
     4301                    ParamIn.TimeAttrName='Civ2_Time';
     4302                    ParamIn.vector_x='Civ2_U';
     4303                    ParamIn.vector_y='Civ2_V';
     4304                case 'filter2'
     4305                    ParamIn.TimeAttrName='Civ2_Time';
     4306                    ParamIn.vector_x='Civ2_U_smooth';
     4307                    ParamIn.vector_y='Civ2_V_smooth';
     4308                    ParamIn.vec_color='Civ2_C';
     4309            end
     4310        end
     4311       
     4312        % VelType menu desactivated
     4313        set(handles.FixVelType,'visible','off')
     4314        set(handles.VelType,'Visible','off')
     4315       
     4316        %read selection from get_field
     4317        [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes_1(handles);
     4318        FileName=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt];
     4319        GetFieldData=get_field(FileName,ParamIn);% inport field names from the GUI get_field
     4320        FieldList={};
     4321        VecColorList={};
     4322        switch GetFieldData.FieldOption
     4323            case 'vectors'
     4324                UName=GetFieldData.PanelVectors.vector_x;
     4325                VName=GetFieldData.PanelVectors.vector_y;
     4326                YName=GetFieldData.Coordinates.Coord_y;
     4327                CName=GetFieldData.PanelVectors.vec_color;
     4328                FieldList={['vec(' UName ',' VName ')'];...
     4329                    ['norm(' UName ',' VName ')'];...
     4330                    UName;VName};
     4331                VecColorList={['norm(' UName ',' VName ')'];...
     4332                    UName;VName};
     4333                if ~isempty(CName)
     4334                    VecColorList=[{CName};VecColorList];
     4335                end
     4336            case 'scalar'
     4337                AName=GetFieldData.PanelScalar.scalar;
     4338                YName=GetFieldData.Coordinates.Coord_y;
     4339                FieldList={AName};
     4340            case '1D plot'
     4341                YName=GetFieldData.PanelOrdinate.ordinate;
     4342            case 'civdata...'%reinitiate input, return to automatic civ data reading
     4343                display_file_name(handles,FileName,1)
     4344        end
     4345        if ~strcmp(GetFieldData.FieldOption,'civdata...')
     4346            XName=GetFieldData.Coordinates.Coord_x;
     4347            TimeNameStr=GetFieldData.Time.SwitchVarIndexTime;
     4348            switch TimeNameStr
     4349                case 'file index'
     4350                    set(handles.TimeName_1,'String','');
     4351                case 'attribute'
     4352                    set(handles.TimeName_1,'String',['att:' GetFieldData.Time.TimeName]);
     4353                case 'variable'
     4354                    set(handles.TimeName_1,'String',['var:' GetFieldData.Time.TimeName])
     4355                    set(handles.NomType_1,'String','*')
     4356                    set(handles.RootFile_1,'String',[get(handles.RootFile,'String') get(handles.FileIndex,'String')])
     4357                    set(handles.FileIndex_1,'String','')
     4358                    ParamIn.TimeVarName=GetFieldData.Time.TimeName;
     4359                case 'matrix_index'
     4360                    set(handles.TimeName_1,'String',['dim:' GetFieldData.Time.TimeName]);
     4361                    set(handles.NomType_1,'String','*')
     4362                    set(handles.RootFile_1,'String',[get(handles.RootFile,'String') get(handles.FileIndex,'String')])
     4363                    set(handles.FileIndex_1,'String','')
     4364                    ParamIn.TimeDimName_1=GetFieldData.Time.TimeName;
     4365            end
     4366            set(handles.Coord_x,'String',XName)
     4367%             if ischar(YName)
     4368%                 YName={YName};
     4369%             end
     4370            set(handles.Coord_y,'String',YName)
     4371            set(handles.FieldName_1,'Value',1)
     4372            set(handles.FieldName_1,'String',[FieldList; {'get_field...'}]);
     4373            set(handles.ColorScalar,'Value',1)
     4374            set(handles.ColorScalar,'String',VecColorList);
     4375            UvData.FileType{2}='netcdf';
     4376            set(handles.uvmat,'UserData',UvData)
     4377            REFRESH_Callback(hObject, eventdata, handles)
     4378        end
     4379         
     4380%         set_veltype_display(0) % no veltype display
     4381%         hget_field=findobj(allchild(0),'name','get_field_1');
     4382%         if ~isempty(hget_field)
     4383%             delete(hget_field)
     4384%         end
     4385%         hget_field=get_field(FileName_1);
     4386%         set(hget_field,'name','get_field_1')
     4387%         hhget_field=guidata(hget_field);
     4388%         set(hhget_field.list_fig,'Value',1)
     4389%         set(hhget_field.list_fig,'String',{'uvmat'})
     4390%         if check_new
     4391%             UvData.FileType{2}=UvData.FileType{1};
     4392%             set(handles.FileIndex_1,'String',get(handles.FileIndex,'String'))
     4393%               set(handles.uvmat,'UserData',UvData)
     4394%         end
     4395    case 'image'
     4396        %% look for image corresponding to civ data
     4397        imagename='';
     4398        if  isfield(UvData.Field,'Civ2_ImageA')%get the corresponding input image in the netcdf file
     4399            imagename=UvData.Field.Civ2_ImageA;
     4400        elseif isfield(UvData.Field,'Civ1_ImageA')%
     4401            imagename=UvData.Field.Civ1_ImageA;
     4402        else
     4403            SubDirBase=regexprep(SubDir,'\..*','');%take the root part of SubDir, before the first dot '.'
     4404            imagename=fullfile_uvmat(RootPath,SubDirBase,RootFile,'.png',NomType,i1,[],j1,[]);
     4405        end
     4406        if ~exist(imagename,'file')
     4407            imagename=uigetfile_uvmat('Pick an image file',imagename,'image');
     4408           
     4409        end
     4410        if isempty(imagename)
     4411            set(handles.SubField,'Value',0)
     4412            return
     4413        else
     4414            display_file_name(handles,imagename,2)%display the image as second field
     4415        end
     4416    otherwise
     4417        check_refresh=1;
     4418        if check_new% if a second field was not previously entered, we just read another field in the first input file
     4419            set(handles.FileIndex_1,'String',get(handles.FileIndex,'String'))
     4420            set(handles.FileExt_1,'String',get(handles.FileExt,'String'))
     4421           
     4422            UvData.FileType{2}=UvData.FileType{1};
     4423            UvData.XmlData{2}= UvData.XmlData{1};
     4424            transform=get(handles.TransformPath,'UserData');
     4425             if (~isa(transform,'function_handle')||nargin(transform)<3)
     4426                set(handles.uvmat,'UserData',UvData)
     4427                set(handles.TransformName,'value',2); % set transform fct to 'sub_field' if the current fct does not accept two input fields
     4428                TransformName_Callback(hObject, eventdata, handles)% activate transform_fct_Callback and refresh current plot
     4429                 check_refresh=0;
     4430             end             
     4431        end
     4432        if ~isequal(field,'image')
     4433            set(handles.TitleNpxy,'Visible','off')% visible npx,pxcm... buttons
     4434            set(handles.num_Npx,'Visible','off')
     4435            set(handles.num_Npy,'Visible','off')
     4436        end
     4437        set(handles.uvmat,'UserData',UvData)
     4438 
     4439        if check_refresh && ~(isfield(UvData,'NewSeries')&&isequal(UvData.NewSeries,1))
     4440            REFRESH_Callback(hObject, eventdata, handles)
     4441        end
     4442end
     4443
     4444%------------------------------------------------------------------------
     4445% --- set the visibility of relevant velocity type menus:
     4446function menu=set_veltype_display(Civ,FileType)
     4447%------------------------------------------------------------------------
     4448if ~exist('FileType','var')
     4449    FileType='civx';
     4450end
     4451switch FileType
     4452    case 'civx'
     4453        menu={'civ1';'interp1';'filter1';'civ2';'interp2';'filter2'};
     4454        if isequal(Civ,0)
     4455            imax=0;
     4456        elseif isequal(Civ,1) || isequal(Civ,2)
     4457            imax=1;
     4458        elseif isequal(Civ,3)
     4459            imax=3;
     4460        elseif isequal(Civ,4) || isequal(Civ,5)
     4461            imax=4;
     4462        elseif isequal(Civ,6) %patch2
     4463            imax=6;
     4464        end
     4465    case 'civdata'
     4466        menu={'civ1';'filter1';'civ2';'filter2'};
     4467        if isequal(Civ,0)
     4468            imax=0;
     4469        elseif isequal(Civ,1) || isequal(Civ,2)
     4470            imax=1;
     4471        elseif isequal(Civ,3)
     4472            imax=2;
     4473        elseif isequal(Civ,4) || isequal(Civ,5)
     4474            imax=3;
     4475        elseif isequal(Civ,6) %patch2
     4476            imax=4;
     4477        end
     4478end
     4479menu=menu(1:imax);
     4480
     4481%------------------------------------------------------------------------
     4482% --- Executes on button press in FixVelType.
     4483function FixVelType_Callback(hObject, eventdata, handles)
     4484%------------------------------------------------------------------------
     4485% inputfilerefresh the current plot if the fixed  veltype is unselected
     4486if ~get(handles.FixVelType,'Value')
     4487    REFRESH_Callback(hObject, eventdata, handles)
     4488end
     4489
     4490%------------------------------------------------------------------------
     4491% --- Executes on button press in VelType.
     4492function VelType_Callback(hObject, eventdata, handles)
     4493%------------------------------------------------------------------------
     4494set(handles.FixVelType,'Value',1)
     4495REFRESH_Callback(hObject, eventdata, handles)
     4496
     4497%------------------------------------------------------------------------
     4498% --- Executes on choice selection in VelType_1.
     4499function VelType_1_Callback(hObject, eventdata, handles)
     4500%------------------------------------------------------------------------
     4501set(handles.FixVelType,'Value',1)% the velocity type is now imposed by the GUI (not automatic)
     4502UvData=get(handles.uvmat,'UserData');
     4503set(handles.InputFileREFRESH,'BackgroundColor',[1 1 0])%paint REFRESH button in yellow to indicate its activation
     4504drawnow   
     4505InputFile=read_GUI(handles.InputFile);% read the input file parameters
     4506[RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles);
     4507[RootPath_1,SubDir_1,RootFile_1,FileIndex_1,FileExt_1]=read_file_boxes_1(handles);
     4508FileName=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt];% name of the first input file
     4509
     4510check_refresh=0;
     4511if isempty(InputFile.VelType_1)
     4512        FileName_1='';% we plot the first input field without the second field
     4513        set(handles.SubField,'Value',0)
     4514        SubField_Callback(hObject, eventdata, handles)% activate SubField_Callback and refresh current plot, removing the second field
     4515elseif get(handles.SubField,'Value')% if subfield is already 'on'
     4516     FileName_1=[fullfile(RootPath_1,SubDir_1,RootFile_1) FileIndex_1 FileExt_1];% name of the second input file
     4517     check_refresh=1;%will refresh the current plot
     4518else% we introduce the same file (with a different field) for the second series
     4519     FileName_1=FileName;% we compare two fields in the same file
     4520     UvData.FileType{2}=UvData.FileType{1};
     4521     UvData.XmlData{2}= UvData.XmlData{1};
     4522     set(handles.SubField,'Value',1)
     4523     transform=get(handles.TransformPath,'UserData');
     4524     if (~isa(transform,'function_handle')||nargin(transform)<3)
     4525        set(handles.uvmat,'UserData',UvData)
     4526        set(handles.TransformName,'value',2); % set transform fct to 'sub_field' if the current fct does not accept two input fields
     4527        TransformName_Callback(hObject, eventdata, handles)% activate transform_fct_Callback and refresh current plot
     4528     else
     4529         check_refresh=1;
     4530     end 
     4531end
     4532
     4533% inputfilerefresh the current plot if it has not been done previously
     4534if check_refresh
     4535    UvData.FileName_1='';% desactivate the use of a constant second file
     4536    set(handles.uvmat,'UserData',UvData)
     4537    num_i1=stra2num(get(handles.i1,'String'));
     4538    num_i2=stra2num(get(handles.i2,'String'));
     4539    num_j1=stra2num(get(handles.j1,'String'));
     4540    num_j2=stra2num(get(handles.j2,'String'));
     4541    [tild,tild,tild,i1_1,i2_1,j1_1,j2_1]=fileparts_uvmat(['xx' FileIndex_1]);
     4542    errormsg=refresh_field(handles,FileName,FileName_1,num_i1,num_i2,num_j1,num_j2,i1_1,i2_1,j1_1,j2_1);
     4543    if ~isempty(errormsg)
     4544        msgbox_uvmat('ERROR',errormsg);
     4545    else
     4546%         set(handles.i1,'BackgroundColor',[1 1 1])
     4547%         set(handles.i2,'BackgroundColor',[1 1 1])
     4548%         set(handles.j1,'BackgroundColor',[1 1 1])
     4549%         set(handles.j2,'BackgroundColor',[1 1 1])
     4550%         set(handles.FileIndex,'BackgroundColor',[1 1 1])
     4551%         set(handles.FileIndex_1,'BackgroundColor',[1 1 1])
     4552    end
     4553    set(handles.InputFileREFRESH,'BackgroundColor',[1 0 0])
     4554end
     4555
     4556
     4557%------------------------------------------------------------------------
     4558% --- reset civ buttons
     4559function reset_vel_type(handles_civ0,handle1)
     4560%------------------------------------------------------------------------
     4561for ibutton=1:length(handles_civ0)
     4562    set(handles_civ0(ibutton),'BackgroundColor',[0.831 0.816 0.784])
     4563    set(handles_civ0(ibutton),'Value',0)
     4564end
     4565if exist('handle1','var')%handles of selected button
     4566        set(handle1,'BackgroundColor',[1 1 0]) 
     4567end
     4568
     4569%-----------------------------------------------------------------------
     4570% --- Executes on button press in MENUVOLUME.
     4571function VOLUME_Callback(hObject, eventdata, handles)
     4572%-----------------------------------------------------------------------
     4573%errordlg('command VOL not implemented yet')
     4574if ishandle(handles.UVMAT_title)
     4575    delete(handles.UVMAT_title)
     4576end
     4577UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
     4578if isequal(get(handles.VOLUME,'Value'),1)
     4579    set(handles.CheckZoom,'Value',0)
     4580%     set(handles.CheckZoom,'BackgroundColor',[0.7 0.7 0.7])
     4581    set(handles.edit_vect,'Value',0)
     4582    edit_vect_Callback(hObject, eventdata, handles)
     4583    set(handles.CheckEditObject,'Value',0)
     4584%     set(handles.CheckEditObject,'BackgroundColor',[0.7 0.7 0.7])
     4585%     set(handles.cal,'Value',0)
     4586%     set(handles.cal,'BackgroundColor',[0 1 0])
     4587    set(handles.edit_vect,'Value',0)
     4588    edit_vect_Callback(hObject, eventdata, handles)
     4589    %initiate set_object GUI
     4590    data.Name='VOLUME';
     4591    if isfield(UvData,'CoordType')
     4592        data.CoordType=UvData.CoordType;
     4593    end
     4594    if isfield(UvData.Field,'CoordMesh')&~isempty(UvData.Field.CoordMesh)
     4595        data.RangeX=[UvData.Field.XMin UvData.Field.XMax];
     4596        data.RangeY=[UvData.Field.YMin UvData.Field.YMax];
     4597        data.DX=UvData.Field.CoordMesh;
     4598        data.DY=UvData.Field.CoordMesh;
     4599    elseif isfield(UvData.Field,'Coord_x')&isfield(UvData.Field,'Coord_y')& isfield(UvData.Field,'A')%only image
     4600        np=size(UvData.Field.A);
     4601        meshx=(UvData.Field.Coord_x(end)-UvData.Field.Coord_x(1))/np(2);
     4602        meshy=abs(UvData.Field.Coord_y(end)-UvData.Field.Coord_y(1))/np(1);
     4603        data.RangeY=max(meshx,meshy);
     4604        data.RangeX=max(meshx,meshy);
     4605        data.DX=max(meshx,meshy);
     4606    end
     4607    data.ParentButton=handles.VOLUME;
     4608    PlotHandles=get_plot_handles(handles);%get the handles of the interface elements setting the plotting parameters
     4609    [hset_object,UvData.sethandles]=set_object(data,PlotHandles);% call the set_object interface with action on haxes,
     4610                                                      % associate the set_object interface handle to the plotting axes
     4611    set(hset_object,'name','set_object')
     4612    UvData.MouseAction='create_object';
     4613else
     4614    set(handles.VOLUME,'BackgroundColor',[0 1 0])
     4615end
     4616set(handles.uvmat,'UserData',UvData)
     4617
     4618%-------------------------------------------------------
     4619function edit_vect_Callback(hObject, eventdata, handles)
     4620%-------------------------------------------------------
     4621%
     4622if isequal(get(handles.edit_vect,'Value'),1)
     4623    VelTypeMenu=get(handles.VelType,'String');
     4624    VelType=VelTypeMenu{get(handles.VelType,'Value')};
     4625    if ~strcmp(VelType,'civ2') && ~strcmp(VelType,'civ1')
     4626        msgbox_uvmat('ERROR','manual correction only possible for CIV1 or CIV2 velocity fields')
     4627    end
     4628    set(handles.record,'Visible','on')
     4629    set(handles.edit_vect,'BackgroundColor',[1 1 0])
     4630    set(handles.CheckEditObject,'Value',0)
     4631    set(handles.CheckZoom,'Value',0)
     4632    set(gcf,'Pointer','arrow')
     4633else
     4634    set(handles.record,'Visible','off')
     4635    set(handles.edit_vect,'BackgroundColor',[0.7 0.7 0.7])
     4636end
     4637
     4638%----------------------------------------------
     4639function save_mask_Callback(hObject, eventdata, handles)
     4640%-----------------------------------------------------------------------
     4641UvData=get(handles.uvmat,'UserData');
     4642
     4643flag=1;
     4644npx=size(UvData.Field.A,2);
     4645npy=size(UvData.Field.A,1);
     4646xi=0.5:npx-0.5;
     4647yi=0.5:npy-0.5;
     4648[Xi,Yi]=meshgrid(xi,yi);
     4649if isfield(UvData,'ProjObject')
     4650    for iobj=1:length(UvData.ProjObject)
     4651        ObjectData=UvData.ProjObject{iobj};
     4652        if isfield(ObjectData,'ProjMode') &&(isequal(ObjectData.ProjMode,'mask_inside')||isequal(ObjectData.ProjMode,'mask_outside'));
     4653            flagobj=1;
     4654            testphys=0; %coordinates in pixels by default
     4655            if isfield(ObjectData,'CoordType') && isequal(ObjectData.CoordType,'phys')
     4656                if isfield(UvData,'XmlData')&& isfield(UvData.XmlData{1},'GeometryCalib')
     4657                    Calib=UvData.XmlData{1}.GeometryCalib;
     4658                    testphys=1;
     4659                end
     4660            end
     4661            if isfield(ObjectData,'Coord')& isfield(ObjectData,'Style')
     4662                if isequal(ObjectData.Type,'polygon')
     4663                    X=ObjectData.Coord(:,1);
     4664                    Y=ObjectData.Coord(:,2);
     4665                    if testphys
     4666                        [X,Y]=px_XYZ(Calib,X,Y,0);% to generalise with 3D cases
     4667                    end
     4668                    flagobj=~inpolygon(Xi,Yi,X',Y');%=0 inside the polygon, 1 outside                 
     4669                elseif isequal(ObjectData.Type,'ellipse')
     4670                    if testphys
     4671                        %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys
     4672                    end
     4673                    RangeX=max(ObjectData.RangeX);
     4674                    RangeY=max(ObjectData.RangeY);
     4675                    X2Max=RangeX*RangeX;
     4676                    Y2Max=RangeY*RangeY;
     4677                    distX=(Xi-ObjectData.Coord(1,1));
     4678                    distY=(Yi-ObjectData.Coord(1,2));
     4679                    flagobj=(distX.*distX/X2Max+distY.*distY/Y2Max)>1;
     4680                elseif isequal(ObjectData.Type,'rectangle')
     4681                    if testphys
     4682                        %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys
     4683                    end
     4684                    distX=abs(Xi-ObjectData.Coord(1,1));
     4685                    distY=abs(Yi-ObjectData.Coord(1,2));
     4686                    flagobj=distX>max(ObjectData.RangeX) | distY>max(ObjectData.RangeY);
     4687                end
     4688                if isequal(ObjectData.ProjMode,'mask_outside')
     4689                    flagobj=~flagobj;
     4690                end
     4691                flag=flag & flagobj;
     4692            end
     4693        end
     4694    end
     4695end
     4696% flag=~flag;
     4697%mask name
     4698RootPath=get(handles.RootPath,'String');
     4699RootFile=get(handles.RootFile,'String');
     4700RootFile=regexprep(RootFile,'\<[\\/]|[\\/]\>','');%suppress possible / or \ separator at the beginning or the end of the string
     4701filebase=fullfile(RootPath,RootFile);
     4702list=get(handles.masklevel,'String');
     4703masknumber=num2str(length(list));
     4704maskindex=get(handles.masklevel,'Value');
     4705mask_name=fullfile_uvmat(RootPath,SubDir,[RootFile '_' masknumber 'mask'],'.png','_1',maskindex);
     4706%mask_name=name_generator([filebase '_' masknumber 'mask'],maskindex,1,'.png','_i');
     4707imflag=uint8(255*(0.392+0.608*flag));% =100 for flag=0 (vectors not computed when 20<imflag<200)
     4708imflag=flipdim(imflag,1);
     4709% imflag=uint8(255*flag);% =0 for flag=0 (vectors=0 when 20<imflag<200)
     4710msgbox_uvmat('CONFIRMATION',[mask_name ' saved'])
     4711imwrite(imflag,mask_name,'BitDepth',8);
     4712
     4713%display the mask
     4714figure;
     4715vec=linspace(0,1,256);%define a linear greyscale colormap
     4716map=[vec' vec' vec'];
     4717colormap(map)
     4718
     4719image(imflag);
     4720
     4721%------------------------------------------------------------------------
     4722%------------------------------------------------------------------------
     4723%  - FUNCTIONS FOR SETTING PLOTTING PARAMETERS
     4724
     4725%------------------------------------------------------------------------
     4726%------------------------------------------------------------------------
     4727% --- Executes on selection change in TransformName.
     4728
     4729function TransformName_Callback(hObject, eventdata, handles)
     4730%------------------------------------------------------------------------
     4731set(handles.TransformName,'backgroundColor',[1 1 0])% indicate activation  of the menu
     4732drawnow
     4733UvData=get(handles.uvmat,'UserData');
     4734menu=get(handles.TransformName,'String');%refresh
     4735ichoice=get(handles.TransformName,'Value');%item number in the menu
     4736transform_name=menu{ichoice};% choice of the transform fct
     4737list_path=get(handles.TransformName,'UserData');
     4738
     4739%% handles  visibility of the path to the transform function
     4740if isempty(transform_name)
     4741    set(handles.TransformPath,'Visible','off')
     4742else
     4743    set(handles.TransformPath,'Visible','on')
     4744end
     4745
     4746%% add a new item to the menu if the option 'more...' has been selected
     4747prev_path=fullfile(get(handles.TransformPath,'String'));
     4748if ~exist(prev_path,'dir')
     4749    prev_path=fullfile(fileparts(which('uvmat')),'transform_field');
     4750end
     4751if strcmp(transform_name,'more...');
     4752    transform_fct_chosen=uigetfile_uvmat('Pick the transform function',prev_path,'.m');
     4753    if ~isempty(transform_fct_chosen)
     4754        [PathName,transform_name]=fileparts(transform_fct_chosen);
     4755        ichoice=find(strcmp(transform_name,menu),1);%look for the selected fct in the existing menu
     4756        if isempty(ichoice)% if the item is not found, add it to the menu (before 'more...' and select it)
     4757            menu=[menu(1:end-1);{transform_name};{'more...'}];
     4758            ichoice=numel(menu)-1;
     4759        end
     4760        list_path{ichoice}=PathName;%update the list fo fct paths
     4761        set(handles.TransformName,'String',menu)
     4762        set(handles.TransformName,'Value',ichoice)
     4763       
     4764        % save the new menu in the personal file 'uvmat_perso.mat'
     4765        dir_perso=prefdir;%personal Matalb directory
     4766        profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
     4767        if exist(profil_perso,'file')
     4768            nb_builtin=UvData.OpenParam.NbBuiltin;% number of 'builtin' (basic) transform fcts in uvmat
     4769            if nb_builtin<numel(list_path)
     4770                for ilist=nb_builtin+1:numel(list_path)
     4771                    transform_fct{ilist-nb_builtin}=[fullfile(list_path{ilist},menu{ilist}) '.m'];
     4772                end
     4773                save (profil_perso,'transform_fct','-append'); %store the root name for future opening of uvmat
     4774            end
     4775        end
     4776    end
     4777end
     4778
     4779%% create the function handle of the selected fct
     4780if isempty(list_path{ichoice})% case of no selected fct
     4781    transform_handle=[];
     4782else
     4783    if ~exist(list_path{ichoice},'dir')
     4784        msgbox_uvmat('ERROR','invalid fct path: select the transform fct again with the option more...')
     4785        return
     4786    end
     4787    current_dir=pwd;%current working dir
     4788    cd(list_path{ichoice})
     4789    transform_handle=str2func(transform_name);
     4790    cd(current_dir)
     4791end
     4792set(handles.TransformPath,'String',list_path{ichoice})
     4793set(handles.TransformPath,'UserData',transform_handle)
     4794set(handles.TransformName,'UserData',list_path)
     4795
     4796%% update the ToolTip string of the menu TransformName with the first line of the selected fct file
     4797if isempty(list_path{ichoice})% case of no selected fct
     4798    set(handles.TransformName,'ToolTipString','transform_fct:choose a transform function')
     4799else
     4800    try
     4801        [fid,errormsg] =fopen([fullfile(list_path{ichoice},transform_name) '.m']);
     4802        InputText=textscan(fid,'%s',1,'delimiter','\n');
     4803        fclose(fid);
     4804        set(handles.TransformName,'ToolTipString',['transform_fct: ' InputText{1}{1}])% put the first line of the selected function as tooltip help
     4805    end
     4806end
     4807
     4808%% adapt the GUI to the input/output conditions of the selected transform fct
     4809CoordUnit='';
     4810CoordUnitPrev='';
     4811if isfield(UvData,'Field')&&isfield(UvData.Field,'CoordUnit')
     4812    CoordUnitPrev=UvData.Field.CoordUnit;
     4813end
     4814if ~isempty(list_path{ichoice})
     4815    if nargin(transform_handle)>1 %&& isfield(UvData,'XmlData')&&~isempty(UvData.XmlData)
     4816        XmlData=[];
     4817        if isfield(UvData,'XmlData')&&~isempty(UvData.XmlData)
     4818            XmlData=UvData.XmlData{1};
     4819        end
     4820        UvData.Field.Action.RUN=0;% indicate that the transform fct is called only to get input param
     4821        DataOut=feval(transform_handle,UvData.Field,XmlData);% execute the transform fct to get the required conditions
     4822        if isfield(DataOut,'CoordUnit')% set the requested coord unit (info used to possibly delete the current projection objects)
     4823            CoordUnit=DataOut.CoordUnit;
     4824        end
     4825        if isfield(DataOut,'InputFieldType')% to be used to impose a type of input file (eg. for image transform)
     4826            UvData.InputFieldType=DataOut.InputFieldType;
     4827        end
     4828        if isfield(DataOut,'TransformInput')%  used to add transform parameters at selection of the transform fct
     4829            UvData.XmlData{1}.TransformInput=DataOut.TransformInput;
     4830        end
     4831    end
     4832end
     4833
     4834%% delete drawn objects if the output CooordUnit is different from the previous one
     4835if  ~isempty(CoordUnit) && ~isempty(CoordUnitPrev) && ~strcmp(CoordUnit,CoordUnitPrev)
     4836    set(handles.CheckFixLimits,'Value',0)
     4837    hother=findobj('Tag','proj_object');%find all the proj objects
     4838    for iobj=1:length(hother)
     4839        delete_object(hother(iobj))
     4840    end
     4841    hother=findobj('Tag','DeformPoint');%find all the proj objects
     4842    for iobj=1:length(hother)
     4843        delete_object(hother(iobj))
     4844    end
     4845    hh=findobj('Tag','calib_points');
     4846    if ~isempty(hh)
     4847        delete(hh)
     4848    end
     4849    hhh=findobj('Tag','calib_marker');
     4850    if ~isempty(hhh)
     4851        delete(hhh)
     4852    end
     4853    set(handles.ListObject,'Value',1)
     4854    set(handles.ListObject,'String',{''})
     4855    set(handles.ListObject_1,'Value',1)
     4856    set(handles.ListObject_1,'String',{''})
     4857    set(handles.CheckViewObject,'value',0)
     4858    CheckViewObject_Callback(hObject, eventdata, handles)
     4859    set(handles.CheckViewField,'value',0)
     4860    CheckViewField_Callback(hObject, eventdata, handles)
     4861    set(handles.CheckEditObject,'Value',0)
     4862    CheckEditObject_Callback(hObject, eventdata, handles)
     4863    UvData.ProjObject={[]};
     4864end
     4865set(handles.uvmat,'UserData',UvData)
     4866set(handles.TransformName,'backgroundColor',[1 1 1])% indicate desactivation  of the menu
     4867drawnow
     4868
     4869%% inputfilerefresh the current plot
     4870if isempty(list_path{ichoice}) || nargin(transform_handle)<3
     4871    set(handles.SubField,'Value',0)
     4872    SubField_Callback(hObject, eventdata, handles)
     4873else
     4874    REFRESH_Callback(hObject, eventdata, handles)
     4875end
     4876
     4877%------------------------------------------------
     4878%CALLBACKS FOR PLOTTING PARAMETERS
     4879%-------------------------------------------------
     4880%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     4881% Plot axes
     4882%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     4883%------------------------------------------------------------------------
     4884function num_MinX_Callback(hObject, eventdata, handles)
     4885%------------------------------------------------------------------------
     4886set(handles.CheckFixLimits,'Value',1) %suppress auto mode
     4887% set(handles.CheckFixLimits,'BackgroundColor',[1 1 0])
     4888update_plot(handles);
     4889
     4890%------------------------------------------------------------------------
     4891function num_MaxX_Callback(hObject, eventdata, handles)
     4892%------------------------------------------------------------------------
     4893set(handles.CheckFixLimits,'Value',1) %suppress auto mode
     4894% set(handles.CheckFixLimits,'BackgroundColor',[1 1 0])
     4895update_plot(handles);
     4896
     4897%------------------------------------------------------------------------
     4898function num_MinY_Callback(hObject, eventdata, handles)
     4899%------------------------------------------
     4900set(handles.CheckFixLimits,'Value',1) %suppress auto mode
     4901% set(handles.CheckFixLimits,'BackgroundColor',[1 1 0])
     4902update_plot(handles);
     4903
     4904%------------------------------------------------------------------------
     4905function num_MaxY_Callback(hObject, eventdata, handles)
     4906%------------------------------------------------------------------------
     4907set(handles.CheckFixLimits,'Value',1) %suppress auto mode
     4908% set(handles.CheckFixLimits,'BackgroundColor',[1 1 0])
     4909update_plot(handles);
     4910
     4911%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     4912% Scalar or image representation
     4913%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     4914%------------------------------------------------------------------------
     4915function num_MinA_Callback(hObject, eventdata, handles)
     4916%------------------------------------------
     4917set(handles.CheckFixScalar,'Value',1) %suppress auto mode
     4918% set(handles.CheckFixScalar,'BackgroundColor',[1 1 0])
     4919MinA=str2double(get(handles.num_MinA,'String'));
     4920MaxA=str2double(get(handles.num_MaxA,'String'));
     4921if MinA>MaxA% switch minA and maxA in case of error
     4922    MinA_old=MinA;
     4923    MinA=MaxA;
     4924    MaxA=MinA_old;
     4925    set(handles.num_MinA,'String',num2str(MinA,5));
     4926    set(handles.num_MaxA,'String',num2str(MaxA,5));
     4927end
     4928update_plot(handles);
     4929
     4930%------------------------------------------------------------------------
     4931function num_MaxA_Callback(hObject, eventdata, handles)
     4932%------------------------------------------------------------------------
     4933set(handles.CheckFixScalar,'Value',1) %suppress auto mode
     4934% set(handles.CheckFixScalar,'BackgroundColor',[1 1 0])
     4935MinA=str2double(get(handles.num_MinA,'String'));
     4936MaxA=str2double(get(handles.num_MaxA,'String'));
     4937if MinA>MaxA% switch minA and maxA in case of error
     4938        MinA_old=MinA;
     4939    MinA=MaxA;
     4940    MaxA=MinA_old;
     4941    set(handles.num_MinA,'String',num2str(MinA,5));
     4942    set(handles.num_MaxA,'String',num2str(MaxA,5));
     4943end
     4944update_plot(handles);
     4945
     4946%------------------------------------------------------------------------
     4947function CheckFixScalar_Callback(hObject, eventdata, handles)
     4948%------------------------------------------------------------------------
     4949test=get(handles.CheckFixScalar,'Value');
     4950if test
     4951%     set(handles.CheckFixScalar,'BackgroundColor',[1 1 0])
     4952else
     4953%     set(handles.CheckFixScalar,'BackgroundColor',[0.7 0.7 0.7])
     4954    update_plot(handles);
     4955end
     4956
     4957%-------------------------------------------------------------------
     4958function CheckBW_Callback(hObject, eventdata, handles)
     4959%-------------------------------------------------------------------
     4960update_plot(handles);
     4961
     4962%-------------------------------------------------------------------
     4963function num_Opacity_Callback(hObject, eventdata, handles)
     4964update_plot(handles);
     4965%-------------------------------------------------------------------
     4966
     4967%-------------------------------------------------------------------
     4968function ListContour_Callback(hObject, eventdata, handles)
     4969%-------------------------------------------------------------------
     4970val=get(handles.ListContour,'Value');
     4971if val==2% option 'contours'
     4972    set(handles.interval_txt,'Visible','on')
     4973    set(handles.num_IncrA,'Visible','on')
     4974    set(handles.num_IncrA,'String','')% refresh contour interval
     4975%     set(handles.opacity_txt,'Visible','off')
     4976%     set(handles.num_Opacity,'Visible','off')
     4977else % option 'image'
     4978    set(handles.interval_txt,'Visible','off')
     4979    set(handles.num_IncrA,'Visible','off')
     4980%     set(handles.opacity_txt,'Visible','on')
     4981%     set(handles.num_Opacity,'Visible','on')
     4982end
     4983update_plot(handles);
     4984
     4985%-------------------------------------------------------------------
     4986function num_IncrA_Callback(hObject, eventdata, handles)
     4987%-------------------------------------------------------------------
     4988update_plot(handles);
     4989
     4990
     4991%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     4992% Vector representation
     4993%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     4994%-------------------------------------------------------------------
     4995function CheckHideWarning_Callback(hObject, eventdata, handles)
     4996%-------------------------------------------------------------------
     4997update_plot(handles);
     4998
     4999%-------------------------------------------------------------------
     5000function CheckHideFalse_Callback(hObject, eventdata, handles)
     5001%-------------------------------------------------------------------
     5002update_plot(handles);
     5003
     5004%-------------------------------------------------------------------
     5005function num_VecScale_Callback(hObject, eventdata, handles)
     5006%-------------------------------------------------------------------
     5007set(handles.CheckFixVectors,'Value',1);
     5008%set(handles.CheckFixVectors,'BackgroundColor',[1 1 0])
     5009update_plot(handles);
     5010
     5011%-------------------------------------------------------------------
     5012function CheckFixVectors_Callback(hObject, eventdata, handles)
     5013%-------------------------------------------------------------------
     5014if ~get(handles.CheckFixVectors,'Value')
     5015    update_plot(handles);
     5016end
     5017
     5018%------------------------------------------------------------------------
     5019% --- Executes on selection change in CheckDecimate4 (nb_vec/4).
     5020%------------------------------------------------------------------------
     5021function CheckDecimate4_Callback(hObject, eventdata, handles)
     5022
     5023if isequal(get(handles.CheckDecimate4,'Value'),1)
     5024    set(handles.CheckDecimate16,'Value',0)
     5025end
     5026update_plot(handles);
     5027
     5028%------------------------------------------------------------------------
     5029% --- Executes on selection change in CheckDecimate16 (nb_vec/16).
     5030%------------------------------------------------------------------------
     5031function CheckDecimate16_Callback(hObject, eventdata, handles)
     5032
     5033if isequal(get(handles.CheckDecimate16,'Value'),1)
     5034    set(handles.CheckDecimate4,'Value',0)
     5035end
     5036update_plot(handles);
     5037
     5038%------------------------------------------------------------------------
     5039% --- Executes on selection change in ColorCode menu
     5040function ColorCode_Callback(hObject, eventdata, handles)
     5041%------------------------------------------------------------------------
     5042% edit the choice for color code
     5043update_color_code_boxes(handles);
     5044update_plot(handles);
     5045
     5046%------------------------------------------------------------------------
     5047function update_color_code_boxes(handles)
     5048%------------------------------------------------------------------------
     5049list_code=get(handles.ColorCode,'String');% list menu fields
     5050colcode= list_code{get(handles.ColorCode,'Value')}; % selected field
     5051enable_slider='off';%default
     5052enable_bounds='off';%default
     5053enable_scalar='off';%default
     5054switch colcode
     5055    case {'rgb','bgr'}
     5056        enable_slider='on';
     5057        enable_bounds='on';
     5058        enable_scalar='on';
     5059    case '64 colors'
     5060        enable_bounds='on';
     5061        enable_scalar='on';
     5062end
     5063set(handles.Slider1,'Visible',enable_slider)
     5064set(handles.Slider2,'Visible', enable_slider)
     5065set(handles.num_ColCode1,'Visible',enable_slider)
     5066set(handles.num_ColCode2,'Visible',enable_slider)
     5067set(handles.TitleColCode1,'Visible',enable_slider)
     5068set(handles.TitleColCode2,'Visible',enable_slider)
     5069set(handles.CheckFixVecColor,'Visible',enable_bounds)
     5070set(handles.num_MinVec,'Visible',enable_bounds)
     5071set(handles.num_MaxVec,'Visible',enable_bounds)
     5072set(handles.ColorScalar,'Visible',enable_scalar)
     5073set_vec_col_bar(handles)
     5074
     5075%------------------------------------------------------------------
     5076% --- Executes on selection change in ColorScalar: choice of the color code.
     5077function ColorScalar_Callback(hObject, eventdata, handles)
     5078%------------------------------------------------------------------
     5079% edit the choice for color code
     5080list_scalar=get(handles.ColorScalar,'String');% list menu fields
     5081col_scalar= list_scalar{get(handles.ColorScalar,'Value')}; % selected field
     5082if isequal(col_scalar,'ima_cor')
     5083    set(handles.CheckFixVecColor,'Value',1)%fixed scale by default
     5084    ColorCode='rgb';
     5085    set(handles.num_MinVec,'String','0')
     5086    set(handles.num_MaxVec,'String','1')
     5087    set(handles.num_ColCode1,'String','0.333')
     5088    set(handles.num_ColCode2,'String','0.666')
     5089else
     5090    set(handles.CheckFixVecColor,'Value',0)%auto scale between min,max by default
     5091    ColorCode='64 colors';
     5092end
     5093ColorCodeList=get(handles.ColorCode,'String');
     5094ichoice=find(strcmp(ColorCode,ColorCodeList),1);
     5095set(handles.ColorCode,'Value',ichoice)% set color code in the menu
     5096
     5097update_color_code_boxes(handles);
     5098%replot the current graph
     5099REFRESH_Callback(hObject, eventdata, handles)
     5100
     5101%----------------------------------------------------------------
     5102% -- Executes on slider movement to set the color code
     5103%
     5104function Slider1_Callback(hObject, eventdata, handles)
     5105%------------------------------------------------------------------
     5106slider1=get(handles.Slider1,'Value');
     5107min_val=str2num(get(handles.num_MinVec,'String'));
     5108max_val=str2num(get(handles.num_MaxVec,'String'));
     5109col=min_val+(max_val-min_val)*slider1;
     5110set(handles.num_ColCode1,'String',num2str(col))
     5111if(get(handles.Slider2,'Value') < col)%move also the second slider at the same value if needed
     5112    set(handles.Slider2,'Value',col)
     5113    set(handles.num_ColCode2,'String',num2str(col))
     5114end
     5115set_vec_col_bar(handles)
     5116update_plot(handles);
     5117
     5118%----------------------------------------------------------------
     5119% Executes on slider movement to set the color code
     5120%----------------------------------------------------------------
     5121function Slider2_Callback(hObject, eventdata, handles)
     5122slider2=get(handles.Slider2,'Value');
     5123min_val=str2num(get(handles.num_MinVec,'String'));
     5124max_val=str2num(get(handles.num_MaxVec,'String'));
     5125col=min_val+(max_val-min_val)*slider2;
     5126set(handles.num_ColCode2,'String',num2str(col))
     5127if(get(handles.Slider1,'Value') > col)%move also the first slider at the same value if needed
     5128    set(handles.Slider1,'Value',col)
     5129    set(handles.num_ColCode1,'String',num2str(col))
     5130end
     5131set_vec_col_bar(handles)
     5132update_plot(handles);
     5133
     5134%----------------------------------------------------------------
     5135% --- Execute on return carriage on the edit box corresponding to slider 1
     5136%----------------------------------------------------------------
     5137function num_ColCode1_Callback(hObject, eventdata, handles)
     5138set_vec_col_bar(handles)
     5139update_plot(handles);
     5140
     5141%----------------------------------------------------------------
     5142% --- Execute on return carriage on the edit box corresponding to slider 2
     5143%----------------------------------------------------------------
     5144function num_ColCode2_Callback(hObject, eventdata, handles)
     5145set_vec_col_bar(handles)
     5146update_plot(handles);
     5147%------------------------------------------------------------------------
     5148%-------------------------------------------------------
     5149% --- Executes on button press in CheckFixVecColor.
     5150%-------------------------------------------------------
     5151function VecColBar_Callback(hObject, eventdata, handles)
     5152set_vec_col_bar(handles)
     5153
     5154%------------------------------------------------------------------------
     5155% --- Executes on button press in CheckFixVecColor.
     5156function CheckFixVecColor_Callback(hObject, eventdata, handles)
     5157%------------------------------------------------------------------------
     5158if ~get(handles.CheckFixVecColor,'Value')
     5159    update_plot(handles);
     5160end
     5161
     5162%------------------------------------------------------------------------
     5163% --- Executes on selection change in num_MaxVec.
     5164function num_MinVec_Callback(hObject, eventdata, handles)
     5165%------------------------------------------------------------------------
     5166num_MaxVec_Callback(hObject, eventdata, handles)
     5167
     5168%------------------------------------------------------------------------
     5169% --- Executes on selection change in num_MaxVec.
     5170function num_MaxVec_Callback(hObject, eventdata, handles)
     5171%------------------------------------------------------------------------
     5172set(handles.CheckFixVecColor,'Value',1)
     5173CheckFixVecColor_Callback(hObject, eventdata, handles)
     5174min_val=str2num(get(handles.num_MinVec,'String'));
     5175max_val=str2num(get(handles.num_MaxVec,'String'));
     5176slider1=get(handles.Slider1,'Value');
     5177slider2=get(handles.Slider2,'Value');
     5178colcode1=min_val+(max_val-min_val)*slider1;
     5179colcode2=min_val+(max_val-min_val)*slider2;
     5180set(handles.num_ColCode1,'String',num2str(colcode1))
     5181set(handles.num_ColCode2,'String',num2str(colcode2))
     5182update_plot(handles);
     5183
     5184%------------------------------------------------------------------------
     5185% --- update the display of color code for vectors (on vecColBar)
     5186function set_vec_col_bar(handles)
     5187%------------------------------------------------------------------------
     5188%get the image of the color display button 'VecColBar' in pixels
     5189set(handles.VecColBar,'Units','pixel');
     5190pos_vert=get(handles.VecColBar,'Position');
     5191set(handles.VecColBar,'Units','Normalized');
     5192width=ceil(pos_vert(3));
     5193height=ceil(pos_vert(4));
     5194
     5195%get slider indications
     5196list=get(handles.ColorCode,'String');
     5197ichoice=get(handles.ColorCode,'Value');
     5198colcode.ColorCode=list{ichoice};
     5199colcode.MinVec=str2num(get(handles.num_MinVec,'String'));
     5200colcode.MaxVec=str2num(get(handles.num_MaxVec,'String'));
     5201test3color=strcmp(colcode.ColorCode,'rgb') || strcmp(colcode.ColorCode,'bgr');
     5202if test3color
     5203    colcode.ColCode1=str2num(get(handles.num_ColCode1,'String'));
     5204    colcode.ColCode2=str2num(get(handles.num_ColCode2,'String'));
     5205end
     5206vec_C=colcode.MinVec+(colcode.MaxVec-colcode.MinVec)*(0.5:width-0.5)/width;%sample of vec_C values from min to max
     5207[colorlist,col_vec]=set_col_vec(colcode,vec_C);
     5208oneheight=ones(1,height);
     5209A1=colorlist(col_vec,1)*oneheight;
     5210A2=colorlist(col_vec,2)*oneheight;
     5211A3=colorlist(col_vec,3)*oneheight;
     5212A(:,:,1)=A1';
     5213A(:,:,2)=A2';
     5214A(:,:,3)=A3';
     5215set(handles.VecColBar,'Cdata',A)
     5216
     5217%-------------------------------------------------------------------
     5218function update_plot(handles)
     5219%-------------------------------------------------------------------
     5220set(handles.REFRESH,'BackgroundColor',[1 1 0]);% display plot activity by yellow color
     5221drawnow
     5222UvData=get(handles.uvmat,'UserData');
     5223AxeData=UvData.PlotAxes;% retrieve the current plotted data
     5224PlotParam=read_GUI(handles.uvmat);
     5225[tild,PlotParamOut]= plot_field(AxeData,handles.PlotAxes,PlotParam);
     5226errormsg=fill_GUI(PlotParamOut,handles.uvmat);
     5227if isempty(errormsg)
     5228    set(handles.REFRESH,'BackgroundColor',[1 0 0]);% operation finished, back to red color
     5229else
     5230    msgbox_uvmat('ERROR',errormsg)
     5231    set(handles.REFRESH,'BackgroundColor',[1 0 1]);% magenta color: graph still needs to be updated
     5232end
     5233
     5234
     5235%------------------------------------------------------------------------
     5236%------------------------------------------------------------------------
     5237%   SELECTION AND EDITION OF PROJECTION OBJECTS
     5238%------------------------------------------------------------------------
     5239%------------------------------------------------------------------------
     5240
     5241% --- Executes on selection change in ListObject_1.
     5242function ListObject_1_Callback(hObject, eventdata, handles)
     5243list_str=get(handles.ListObject,'String');
     5244UvData=get(handles.uvmat,'UserData');
     5245ObjectData=UvData.ProjObject{get(handles.ListObject_1,'Value')};
     5246
     5247%% update the projection plot on uvmat
     5248ProjData= proj_field(UvData.Field,ObjectData);%project the current input field on object ObjectData
     5249plot_field(ProjData,handles.PlotAxes,read_GUI(handles.uvmat));% plot the projected field;
     5250%replot all the objects within the new projected field
     5251for IndexObj=1:numel(list_str)
     5252        hobject=UvData.ProjObject{IndexObj}.DisplayHandle.uvmat;
     5253        if isempty(hobject) || ~ishandle(hobject)
     5254            hobject=handles.PlotAxes;
     5255        end
     5256        if isequal(IndexObj,get(handles.ListObject,'Value'))
     5257            objectcolor='m'; %paint in magenta the currently selected object in ListObject
     5258        else
     5259            objectcolor='b';
     5260        end
     5261        UvData.ProjObject{IndexObj}.DisplayHandle.uvmat=plot_object(UvData.ProjObject{IndexObj},ObjectData,hobject,objectcolor);%draw the object in uvmat     
     5262end
     5263set(handles.uvmat,'UserData',UvData)
     5264
     5265%% display the object parameters if the GUI set_object is already opened
     5266if ~get(handles.CheckViewObject,'Value')
     5267    ZBounds=0; % default
     5268    if isfield(UvData.Field,'ZMin') && isfield(UvData.Field,'ZMax')
     5269        ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider
     5270        ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider
     5271    end
     5272    ObjectData.Name=list_str{get(handles.ListObject_1,'Value')};
     5273    hset_object=set_object(ObjectData,[],ZBounds);
     5274    set(hset_object,'name','set_object')
     5275    set(handles.CheckViewObject,'Value',1)% show that the selected object in ListObject_1 is currently visualised
     5276end
     5277
     5278%  desactivate the edit object mode
     5279set(handles.CheckEditObject,'Value',0)
     5280% set(handles.CheckEditObject,'BackgroundColor',[0.7,0.7,0.7])
     5281
     5282%------------------------------------------------------------------------
     5283% --- Executes on selection change in ListObject.
     5284function ListObject_Callback(hObject, eventdata, handles)
     5285%------------------------------------------------------------------------
     5286list_str=get(handles.ListObject,'String');
     5287IndexObj=get(handles.ListObject,'Value');%present object selection
     5288UvData=get(handles.uvmat,'UserData');
     5289if numel(UvData.ProjObject)<IndexObj
     5290    return
     5291end
     5292ObjectData=UvData.ProjObject{IndexObj};
     5293    ZBounds=0; % default
     5294    if isfield(UvData.Field,'ZMin') && isfield(UvData.Field,'ZMax')
     5295        ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider
     5296        ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider
     5297    end
     5298
     5299%% show object features if view_object isselected
     5300if get(handles.CheckViewObject,'value')
     5301    hset_object=set_object(ObjectData,[],ZBounds);
     5302    set(hset_object,'name','set_object')
     5303end
     5304
     5305%%  desactivate the edit object mode for security
     5306set(handles.CheckEditObject,'Value',0)
     5307
     5308%% update the  plot on view_field if view_field is already openened
     5309hview_field=findobj(allchild(0),'tag','view_field');
     5310if isempty(hview_field)
     5311    hhview_field.PlotAxes=[];
     5312else
     5313    Data=get(hview_field,'UserData');
     5314    hhview_field=guidata(hview_field);
     5315    ProjData= proj_field(UvData.Field,ObjectData);%project the current interface field on ObjectData
     5316    [PlotType,PlotParam]=plot_field(ProjData,hhview_field.PlotAxes,read_GUI(hview_field));%read plotting parameters on the uvmat interface
     5317    haxes=findobj(hview_field,'tag','axes3');
     5318    pos=get(hview_field,'Position'); 
     5319    if strcmp(get(haxes,'Visible'),'off')%sempty(PlotParam.Axes)% case of no plot display (pure text table)
     5320        h_TableDisplay=findobj(hview_field,'tag','TableDisplay');
     5321        pos_table=get(h_TableDisplay,'Position');
     5322        set(hview_field,'Position',[pos(1)+pos(3)-pos_table(3) pos(2)+pos(4)-pos_table(4) pos_table(3) pos_table(4)])
     5323        drawnow% needed to change position before the next command
     5324        set(hview_field,'UserData',Data);% restore the previously stored GUI position after GUI resizing
     5325    else
     5326%         set(hview_field,'Position',Data.GUISize)% return to the previously stored GUI position and size
     5327    end
     5328end
     5329
     5330%% update the color of the graphic object representation: the selected object in magenta, others in blue
     5331update_object_color(handles.PlotAxes,hhview_field.PlotAxes,UvData.ProjObject{IndexObj}.DisplayHandle.uvmat)
     5332
     5333%------------------------------------------------------------------------
     5334%--- update the color representation of objects (indicating the selected ones)
     5335function update_object_color(axes_uvmat,axes_view_field,DisplayHandle)
     5336%------------------------------------------------------------------------
     5337if isempty(axes_view_field)% case with no view_field plot
     5338hother=[findobj(axes_uvmat,'Tag','proj_object');findobj(axes_uvmat,'Tag','DeformPoint')];%find all the proj object and deform point representations
     5339else
     5340hother=[findobj(axes_uvmat,'Tag','proj_object') ;findobj(axes_view_field,'Tag','proj_object');... %find all the proj object representations
     5341findobj(axes_uvmat,'Tag','DeformPoint'); findobj(axes_view_field,'Tag','DeformPoint')];%find all the deform point representations
     5342end
     5343for iobj=1:length(hother)
     5344    if isequal(get(hother(iobj),'Type'),'rectangle')||isequal(get(hother(iobj),'Type'),'patch')
     5345        set(hother(iobj),'EdgeColor','b')
     5346        if isequal(get(hother(iobj),'FaceColor'),'m')
     5347            set(hother(iobj),'FaceColor','b')
     5348        end
     5349    elseif isequal(get(hother(iobj),'Type'),'image')
     5350        Acolor=get(hother(iobj),'CData');
     5351        Acolor(:,:,1)=zeros(size(Acolor,1),size(Acolor,2));
     5352        set(hother(iobj),'CData',Acolor);
     5353    else
     5354        set(hother(iobj),'Color','b')
     5355    end
     5356    set(hother(iobj),'Selected','off')
     5357end
     5358if ishandle(DisplayHandle)
     5359    linetype=get(DisplayHandle,'Type');
     5360    if isequal(linetype,'line')
     5361        set(DisplayHandle,'Color','m'); %set the selected object to magenta color
     5362    elseif isequal(linetype,'rectangle')
     5363        set(DisplayHandle,'EdgeColor','m'); %set the selected object to magenta color
     5364    elseif isequal(linetype,'patch')
     5365        set(DisplayHandle,'FaceColor','m'); %set the selected object to magenta color
     5366    end
     5367    SubObjectData=get(DisplayHandle,'UserData');
     5368    if isfield(SubObjectData,'SubObject') & ishandle(SubObjectData.SubObject)
     5369        for iobj=1:length(SubObjectData.SubObject)
     5370            hsub=SubObjectData.SubObject(iobj);
     5371            if isequal(get(hsub,'Type'),'rectangle')
     5372                set(hsub,'EdgeColor','m'); %set the selected object to magenta color
     5373            elseif isequal(get(hsub,'Type'),'image')
     5374                Acolor=get(hsub,'CData');
     5375                Acolor(:,:,1)=Acolor(:,:,3);
     5376                set(hsub,'CData',Acolor);
     5377            else
     5378                set(hsub,'Color','m')
     5379            end
     5380        end
     5381    end
     5382    if isfield(SubObjectData,'DeformPoint') & ishandle(SubObjectData.DeformPoint)
     5383        set(SubObjectData.DeformPoint,'Color','m')
     5384    end
     5385end
     5386
     5387%-------------------------------------------------------------------
     5388% --- Executes on selection change in CheckEditObject.
     5389function CheckEditObject_Callback(hObject, eventdata, handles)
     5390%-------------------------------------------------------------------
     5391hset_object=findobj(allchild(0),'Tag','set_object');
     5392if get(handles.CheckEditObject,'Value')
     5393    %suppress the other options
     5394    set(handles.MenuObject,'checked','off')
     5395    set(handles.CheckZoom,'Value',0)
     5396    CheckZoom_Callback(hObject, eventdata, handles)
     5397    hgeometry_calib=findobj(allchild(0),'tag','geometry_calib');
     5398    if ishandle(hgeometry_calib)
     5399        hhgeometry_calib=guidata(hgeometry_calib);
     5400        set(hhgeometry_calib.CheckEnableMouse,'Value',0)% desactivate mouse action in geometry_calib
     5401        set(hhgeometry_calib.CheckEnableMouse,'BackgroundColor',[0.7 0.7 0.7])
     5402    end
     5403    set(handles.CheckViewObject,'value',1)
     5404    CheckViewObject_Callback(hObject, eventdata, handles)
     5405else % desactivate object edit mode
     5406    if ~isempty(hset_object)% open the
     5407        set(get(hset_object,'children'),'Enable','off')
     5408        hSAVE=findobj(hset_object,'Tag','SAVE');
     5409        set(hSAVE,'Enable','on')
     5410    end
     5411end
     5412
     5413
     5414%------------------------------------------------------------------------
     5415% --- Executes on button press in CheckViewObject.
     5416function CheckViewObject_Callback(hObject, eventdata, handles)
     5417%------------------------------------------------------------------------
     5418check_view=get(handles.CheckViewObject,'Value');
     5419
     5420if check_view %activate set_object   
     5421    IndexObj=get(handles.ListObject,'Value');
     5422    list_object=get(handles.ListObject,'String');
     5423    UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
     5424    UvData.ProjObject{IndexObj}.Name=list_object{IndexObj};
     5425    if numel(UvData.ProjObject)<IndexObj;% error in UvData
     5426        msgbox_uvmat('ERROR','invalid object list')
     5427        return
     5428    end
     5429    ZBounds=0; % default
     5430    if isfield(UvData.Field,'ZMin') && isfield(UvData.Field,'ZMax')
     5431        ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider
     5432        ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider
     5433    end
     5434    data=UvData.ProjObject{IndexObj};
     5435    if ~isfield(data,'Type')% default plane
     5436        data.Type='plane';
     5437    end
     5438    hset_object=set_object(data,[],ZBounds);
     5439    set(hset_object,'name','set_object')
     5440    hhset_object=guidata(hset_object);
     5441    if get(handles.CheckEditObject,'Value')% edit mode
     5442        set(get(hset_object,'children'),'Enable','on')
     5443    else
     5444        set(get(hset_object,'children'),'Enable','off')% deactivate the GUI except SAVE
     5445        set(hhset_object.SAVE,'Enable','on')
     5446    end
     5447else
     5448    hset_object=findobj(allchild(0),'tag','set_object');
     5449    if ~isempty(hset_object)
     5450        delete(hset_object)% delete existing version of set_object
     5451    end
     5452end
     5453 
     5454
     5455%------------------------------------------------------------------------
     5456% --- Executes on button press in CheckViewField.
     5457function CheckViewField_Callback(hObject, eventdata, handles)
     5458%------------------------------------------------------------------------
     5459check_view=get(handles.CheckViewField,'Value');
     5460
     5461if check_view
     5462    IndexObj=get(handles.ListObject,'Value');
     5463    UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
     5464    if numel(UvData.ProjObject)<IndexObj(end);% error in UvData
     5465        msgbox_uvmat('ERROR','invalid object list')
     5466        return
     5467    end
     5468    ZBounds=0; % default
     5469    if isfield(UvData.Field,'ZMin') && isfield(UvData.Field,'ZMax')
     5470        ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider
     5471        ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider
     5472    end
     5473    set(handles.ListObject,'Value',IndexObj);%restore ListObject selection after set_object deletion
     5474    if ~isfield(UvData.ProjObject{IndexObj(1)},'Type')% default plane
     5475        UvData.ProjObject{IndexObj(1)}.Type='plane';
     5476    end
     5477    list_object=get(handles.ListObject,'String');
     5478    UvData.ProjObject{IndexObj(end)}.Name=list_object{IndexObj(end)};
     5479   
     5480    %% show the projection of the selected object on view_field
     5481    ProjData= proj_field(UvData.Field,UvData.ProjObject{IndexObj});%project the current field on ObjectData
     5482    hview_field=findobj(allchild(0),'tag','view_field');
     5483    if isempty(hview_field)
     5484        hview_field=view_field;
     5485    end
     5486    hhview_field=guidata(hview_field);
     5487    [PlotType,PlotParam]=plot_field(ProjData,hhview_field.PlotAxes,read_GUI(hview_field));%read plotting parameters on the GUI view_field);
     5488    errormsg=fill_GUI(PlotParam,hview_field);
     5489    for list={'Scalar','Vectors'}
     5490        if ~isfield(PlotParam,list{1})
     5491            set(hhview_field.(list{1}),'Visible','off')
     5492        end
     5493    end
     5494    haxes=findobj(hview_field,'tag','axes3');
     5495    pos=get(hview_field,'Position');
     5496    if strcmp(get(haxes,'Visible'),'off')%sempty(PlotParam.Axes)% case of no plot display (pure text table)
     5497        h_TableDisplay=findobj(hview_field,'tag','TableDisplay');
     5498        pos_table=get(h_TableDisplay,'Position');
     5499        set(hview_field,'Position',[pos(1)+pos(3)-pos_table(3) pos(2)+pos(4)-pos_table(4) pos_table(3) pos_table(4)])
     5500    else
     5501        Data=get(hview_field,'UserData');
     5502    end
     5503else
     5504    hview_field=findobj(allchild(0),'tag','view_field');
     5505    if ~isempty(hview_field)
     5506        delete(hview_field)% delete existing version of set_object
     5507    end
     5508end
     5509
     5510
     5511%------------------------------------------------------------------------
     5512% --- Executes on button press in DeleteObject.
     5513%------------------------------------------------------------------------
     5514function DeleteObject_Callback(hObject, eventdata, handles)
     5515
     5516IndexObj=get(handles.ListObject,'Value');%projection object selected for view_field
     5517IndexObj_1=get(handles.ListObject_1,'Value');%projection object selected for uvmat plot
     5518if IndexObj>1 && ~isequal(IndexObj,IndexObj_1) % do not delete the object used for the uvmat plot
     5519    delete_object(IndexObj)
     5520end
     5521
     5522%'DeleteObject': delete a projection object, defined by its index in the Uvmat list or by its graphic handle
     5523%------------------------------------------------------------------------
     5524% function DeleteObject(hObject)
     5525%
     5526% INPUT:
     5527% hObject: object index (if integer) or handle of the graphic object. If
     5528%          hObject is a subobject, the parent object is detected and deleted.
     5529
     5530function delete_object(IndexObj)
     5531
     5532huvmat=findobj('tag','uvmat');%handles of the uvmat interface
     5533UvData=get(huvmat,'UserData');
     5534hlist_object=findobj(huvmat,'Tag','ListObject');%handles of the object list in the uvmat interface
     5535list_str=get(hlist_object,'String');%objet list
     5536if  ~isempty(UvData) && isfield(UvData, 'ProjObject') && length(UvData.ProjObject)>=IndexObj
     5537    if isfield(UvData.ProjObject{IndexObj},'DisplayHandle') && isfield(UvData.ProjObject{IndexObj}.DisplayHandle,'uvmat')
     5538        hdisplay=UvData.ProjObject{IndexObj}.DisplayHandle.uvmat;%handle of the object graphic representation in uvmat
     5539        for iview=1:length(hdisplay)
     5540            if ishandle(hdisplay(iview)) && ~isequal(hdisplay(iview),0)
     5541                ObjectData=get(hdisplay(iview),'UserData');
     5542                if isfield(ObjectData,'SubObject') && ~isempty(ObjectData.SubObject)
     5543                    delete(ObjectData.SubObject(ishandle(ObjectData.SubObject)));% delete the graphic 'sub-objects (e.g. projection bounds)
     5544                end
     5545                if isfield(ObjectData,'DeformPoint')&& ~isempty(ObjectData.DeformPoint)
     5546                    delete(ObjectData.DeformPoint(ishandle(ObjectData.DeformPoint)));% delete the graphic deformation points
     5547                    delete(hdisplay(iview))% delete the main graphic representation of the object
     5548                end
     5549            end
     5550            ishandle(hdisplay(iview))
     5551        end
     5552        for iobj=IndexObj+1:length(UvData.ProjObject)
     5553            hdisplay=UvData.ProjObject{iobj}.DisplayHandle.uvmat;
     5554            for iview=1:length(hdisplay)
     5555                if ishandle(hdisplay(iview)) && ~isequal(hdisplay(iview),0)
     5556                    PlotData=get(hdisplay(iview),'UserData');
     5557                    PlotData.IndexObj=iobj-1;
     5558                    set(hdisplay(iview),'UserData',PlotData);
     5559                end
     5560            end
     5561        end
     5562    end
     5563    UvData.ProjObject(IndexObj)=[];
     5564end
     5565if numel(list_str)>=IndexObj
     5566    list_str(IndexObj)=[];
     5567end
     5568set(huvmat,'UserData',UvData);
     5569set(hlist_object,'String',list_str)
     5570set(hlist_object,'Value',length(list_str))
     5571hlist_object_1=findobj(huvmat,'Tag','ListObject_1');%handles of the first object list in the uvmat interface
     5572old_index=get(hlist_object_1,'Value');
     5573set(hlist_object_1,'String',list_str)
     5574if IndexObj<=old_index
     5575    set(hlist_object_1,'Value',old_index-1)
     5576end
     5577
    57025578
    57035579
Note: See TracChangeset for help on using the changeset viewer.