Changeset 112


Ignore:
Timestamp:
Oct 14, 2010, 5:48:05 PM (14 years ago)
Author:
gostiaux
Message:

launch_jobs now reads correctly PARAM.xml
lots of autoindent corrections

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/civ.m

    r111 r112  
    1 %'civ': function associated with the interface 'civ.fig' for PIV, spline interpolation and stereo PIV (patch)   
     1%'civ': function associated with the interface 'civ.fig' for PIV, spline interpolation and stereo PIV (patch)
    22%------------------------------------------------------------------------
    33%  provides an interface for the software CIVx
     
    88%  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
    99%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    10 %     This file is part of the toolbox UVMAT. 
    11 % 
     10%     This file is part of the toolbox UVMAT.
     11%
    1212%     UVMAT is free software; you can redistribute it and/or modify
    1313%     it under the terms of the GNU General Public License as published by
    1414%     the Free Software Foundation; either version 2 of the License, or
    1515%     (at your option) any later version.
    16 % 
     16%
    1717%     UVMAT is distributed in the hope that it will be useful,
    1818%     but WITHOUT ANY WARRANTY; without even the implied warranty of
     
    2626gui_Singleton = 1;
    2727gui_State = struct('gui_Name',       mfilename, ...
    28                    'gui_Singleton',  gui_Singleton, ...
    29                    'gui_OpeningFcn', @civ_OpeningFcn, ...
    30                    'gui_OutputFcn',  @civ_OutputFcn, ...
    31                    'gui_LayoutFcn',  [] , ...
    32                    'gui_Callback',   []);
     28    'gui_Singleton',  gui_Singleton, ...
     29    'gui_OpeningFcn', @civ_OpeningFcn, ...
     30    'gui_OutputFcn',  @civ_OutputFcn, ...
     31    'gui_LayoutFcn',  [] , ...
     32    'gui_Callback',   []);
    3333if nargin && ischar(varargin{1})
    3434    gui_State.gui_Callback = str2func(varargin{1});
     
    5252% varargin   command line arguments to civ (see VARARGIN)
    5353global patch_newBin %=1 if new patch processing available
    54 %filebase: root name 
     54%filebase: root name
    5555%nom_type: nomencalture used ('png_old','_i_j'...)
    5656%list of field numbers to process
    57 %subdir: subdirectory of the opened netcdf file 
     57%subdir: subdirectory of the opened netcdf file
    5858%ind_opening: operation number advised for beginning (1=civ1,2=fix1,3=patch1,4=civ2,5=fix2,6=patch2),
    5959%ind_a_opening ind_b_opening chosen pair from the opened netcdf file
     
    6666filebase=''; % root file name ('filebase'.civ)
    6767ext=[];
    68 testall=0; 
     68testall=0;
    6969browse=[];
    7070%default input parameters:
     
    7474num_b=1; % second set of field j numbers (fields b)
    7575subdir='A'; % subdir for the netcdf result files
    76 ind_opening=1; % proposed operation number (1=civ1,2=fix1,3=patch1,4=civ2,5=fix2,6=patch2) 
    77 %load the initial parameters if the interface is started from uvmat 
     76ind_opening=1; % proposed operation number (1=civ1,2=fix1,3=patch1,4=civ2,5=fix2,6=patch2)
     77%load the initial parameters if the interface is started from uvmat
    7878if exist('param','var')&&isstruct(param)% the interface is opened from uvmat
    7979    filebase=param.RootName;
     
    8888end
    8989if ~isempty(ext) && (~isempty(imformats(ext(2:end)))||...
    90                        strcmp(lower(ext),'.avi'));%if an image file has been opened by uvmat
    91         set(handles.ImaExt,'String',ext)
    92         if exist('nom_type_read','var')
    93             browse.nom_type_ima=nom_type_read; % the image nomenclature is stored
    94         end
     90        strcmp(lower(ext),'.avi'));%if an image file has been opened by uvmat
     91    set(handles.ImaExt,'String',ext)
     92    if exist('nom_type_read','var')
     93        browse.nom_type_ima=nom_type_read; % the image nomenclature is stored
     94    end
    9595elseif isequal(ext,'.nc')
    9696    if exist('nom_type_read','var')
     
    109109% xmlfile=fullfile(path_UVMAT,'PARAM.xml');
    110110% if ~exist(xmlfile,'file')
    111     xmlfile='PARAM.xml';
     111xmlfile='PARAM.xml';
    112112% end
    113113if exist(xmlfile,'file')
    114114    try
    115     t=xmltree(xmlfile);
    116     sparam=convert(t);
     115        t=xmltree(xmlfile);
     116        sparam=convert(t);
    117117    catch
    118          errormsg={' Unable to read the file PARAM.xml defining the civx binaries:'; lasterr};   
     118        errormsg={' Unable to read the file PARAM.xml defining the civx binaries:'; lasterr};
    119119    end
    120120else
     
    124124
    125125if ~isempty(errormsg)
    126        msgbox_uvmat('ERROR',errormsg);
     126    msgbox_uvmat('ERROR',errormsg);
    127127end
    128128% patch_newBin='';
     
    137137if isfield(sparam.RunParam,'CivBin')
    138138    if ~exist(sparam.RunParam.CivBin,'file')
    139          sparam.RunParam.CivBin=fullfile(path_UVMAT,sparam.RunParam.CivBin);
     139        sparam.RunParam.CivBin=fullfile(path_UVMAT,sparam.RunParam.CivBin);
    140140    end
    141141else
     
    151151end
    152152% set default operation options
    153     enable_civ1(handles,'off')
    154     enable_civ2(handles,'off')
    155     enable_pair1(handles,'on')
    156     enable_fix1(handles,'off')
    157     desable_patch1(handles)
    158     desable_fix2(handles)
    159     desable_patch2(handles)
    160     set(handles.CIV1,'Value',0)
    161     set(handles.FIX1,'Value',0)
    162     set(handles.PATCH1,'Value',0)
    163     set(handles.CIV2,'Value',0)
    164     set(handles.FIX2,'Value',0)
    165     set(handles.PATCH2,'Value',0)
    166     set(handles.frame_subdirciv2,'BackgroundColor',[0.831 0.816 0.784])
     153enable_civ1(handles,'off')
     154enable_civ2(handles,'off')
     155enable_pair1(handles,'on')
     156enable_fix1(handles,'off')
     157desable_patch1(handles)
     158desable_fix2(handles)
     159desable_patch2(handles)
     160set(handles.CIV1,'Value',0)
     161set(handles.FIX1,'Value',0)
     162set(handles.PATCH1,'Value',0)
     163set(handles.CIV2,'Value',0)
     164set(handles.FIX2,'Value',0)
     165set(handles.PATCH2,'Value',0)
     166set(handles.frame_subdirciv2,'BackgroundColor',[0.831 0.816 0.784])
    167167if isequal(ind_opening,1)
    168168    set(handles.CIV1,'Value',1)
     
    180180    set(handles.FIX2,'Value',1)
    181181    enable_fix2(handles)
    182      set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
    183      set(handles.list_pair_civ2,'Enable','On')
    184      set(handles.list_pair_civ2,'Enable','On')
    185      enable_pair1(handles,'off')
     182    set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
     183    set(handles.list_pair_civ2,'Enable','On')
     184    set(handles.list_pair_civ2,'Enable','On')
     185    enable_pair1(handles,'off')
    186186elseif isequal(ind_opening,6)
    187187    set(handles.PATCH2,'Value',1)
     
    208208else
    209209    num_ref_j=floor((num_a+num_b)/2);
    210     browse.incr_pair(2)=num_b-num_a; 
     210    browse.incr_pair(2)=num_b-num_a;
    211211end
    212212set(handles.first_i,'String',num2str(num_ref_i));
     
    220220set(handles.browse_root,'UserData',browse);
    221221if exist('param','var')%varargin the interface is opened from uvmat
    222     RootName_Callback(hObject, eventdata, handles); 
     222    RootName_Callback(hObject, eventdata, handles);
    223223end
    224224
     
    247247oldfile=''; %default
    248248if isempty(filebase)|| isequal(filebase,'')%loads the previously stored file name and set it as default in the file_input box
    249      dir_perso=prefdir;
    250      profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
    251      display(profil_perso)
    252      if exist(profil_perso,'file')
    253           h=load (profil_perso);
    254          if isfield(h,'filebase')&& ischar(h.filebase)
    255                  oldfile=h.filebase;
    256          end
    257          if isfield(h,'RootPath') && ischar(h.RootPath)
    258                  oldfile=h.RootPath;
    259          end
    260      end
    261  else
    262      oldfile=filebase;
    263  end
     249    dir_perso=prefdir;
     250    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
     251    if exist(profil_perso,'file')
     252        h=load (profil_perso);
     253        if isfield(h,'filebase')&& ischar(h.filebase)
     254            oldfile=h.filebase;
     255        end
     256        if isfield(h,'RootPath') && ischar(h.RootPath)
     257            oldfile=h.RootPath;
     258        end
     259    end
     260else
     261    oldfile=filebase;
     262end
    264263testall=get(handles.ImaDoc,'UserData');
    265264ind_opening=1;%default
    266265browse.incr_pair=[0 0]; %default
    267 if testall 
     266if testall
    268267    menu={'*.*', 'All Files (*.*)'; '*.xml; *.avi;*.AVI;*.nc','(*.xml,*.avi,*.nc)'; ...
    269268        '*.xml', '.xml files';'*.avi;*.AVI', '.avi files';'*.nc','.nc files'};
    270269else % menu selecting only .civ or .avi files
    271 menu={'*.xml;*.avi;*.AVI;*.nc','(*.xml,*.avi,*.nc)'; ...
     270    menu={'*.xml;*.avi;*.AVI;*.nc','(*.xml,*.avi,*.nc)'; ...
    272271        '*.xml', '.xml files';'*.avi;*.AVI', '.avi files';'*.nc', '.nc files';...
    273272        '*.*', 'All Files (*.*)'};
    274273end
    275274[FileName, PathName, filtindex] = uigetfile( menu, 'Pick a file',oldfile);
    276 fileinput=[PathName FileName];%complete file name 
     275fileinput=[PathName FileName];%complete file name
    277276sizf=size(fileinput);
    278277if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
     
    288287end
    289288if testeditxml==1 || isequal(ext,'.xls')
    290    heditxml=editxml({fileinput});
    291    set(heditxml,'Tag','browser')
    292    waitfor(heditxml,'Tag','idle')
    293    if ~ishandle(heditxml)
    294        return
    295    end
    296    attr=findobj(get(heditxml,'children'),'Tag','CurrentAttributes');
    297    set(handles.browse,'UserData',fileinput)% store for future opening with browser
    298    fileinput=get(attr,'UserData');
    299    if ~exist(fileinput,'file')
    300        return
    301    end
     289    heditxml=editxml({fileinput});
     290    set(heditxml,'Tag','browser')
     291    waitfor(heditxml,'Tag','idle')
     292    if ~ishandle(heditxml)
     293        return
     294    end
     295    attr=findobj(get(heditxml,'children'),'Tag','CurrentAttributes');
     296    set(handles.browse,'UserData',fileinput)% store for future opening with browser
     297    fileinput=get(attr,'UserData');
     298    if ~exist(fileinput,'file')
     299        return
     300    end
    302301end
    303302[RootPath,RootFile,str1,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fileinput);
     
    310309if isnan(num_j1),num_j1=1;end
    311310num_j2=stra2num(str_b);
    312 if isnan(num_j2),num_j2=num_j1;end 
     311if isnan(num_j2),num_j2=num_j1;end
    313312if isequal(get(handles.compare,'Value'),1)
    314313    browse=[];%initialisation
     
    317316end
    318317if length(ext)>1 && (~isempty(imformats(ext(2:end)))||...
    319                        isequal(ext,'.avi')||isequal(ext,'.AVI'));%if an image file has been opened by uvmat
     318        isequal(ext,'.avi')||isequal(ext,'.AVI'));%if an image file has been opened by uvmat
    320319    set(handles.ImaExt,'String',ext)
    321320    browse.nom_type_ima=nom_type;
     
    327326if isequal(ext,'.nc')
    328327    browse.nom_type_nc=nom_type;
    329     ind_opening=2;% propose 'fix' as the default option   
     328    ind_opening=2;% propose 'fix' as the default option
    330329    Data=nc2struct(fileinput,[]);
    331     if isfield(Data,'absolut_time_T0')%test for civx files       
     330    if isfield(Data,'absolut_time_T0')%test for civx files
    332331        if isfield(Data,'fix') && isequal(Data.fix,1)
    333332            ind_opening=3;
     
    344343        testciv=1; %TO SUPPRESS WITH NEW VERSION OF CIVX
    345344    else
    346         ind_opening=3; %GUI used only for patch 
     345        ind_opening=3; %GUI used only for patch
    347346        testciv=0;
    348347    end
     
    373372    if ~isempty(num_j2)
    374373        ref_j=floor((num_j1+num_j2)/2);
    375         browse.incr_pair(2)=num_j2-num_j1; 
     374        browse.incr_pair(2)=num_j2-num_j1;
    376375    end
    377376    set(handles.first_j,'String',num2str(ref_j));
    378377    set(handles.last_j,'String',num2str(ref_j));
    379     set(handles.ref_j,'String',num2str(ref_j)); 
     378    set(handles.ref_j,'String',num2str(ref_j));
    380379    set(handles.ref_j_civ2,'String',num2str(ref_j));
    381380end
     
    412411    set(handles.FIX2,'Value',1)
    413412    enable_fix2(handles)
    414      set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
    415      set(handles.list_pair_civ2,'Enable','On')
    416      set(handles.list_pair_civ2,'Enable','On')
     413    set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
     414    set(handles.list_pair_civ2,'Enable','On')
     415    set(handles.list_pair_civ2,'Enable','On')
    417416elseif isequal(ind_opening,6)
    418417    enable_pair1(handles,'off')
     
    438437%------------------------------------------------------------------------
    439438set(handles.compare,'Visible','on')
    440 ext_ima=get(handles.ImaExt,'String'); 
     439ext_ima=get(handles.ImaExt,'String');
    441440nom_type_ima=[];%default
    442441field_count=1;%default
     
    451450ext=get(handles.ImaDoc,'String');
    452451browse=get(handles.browse_root,'UserData');%default
    453 if ~isempty(browse) 
     452if ~isempty(browse)
    454453    if isfield(browse,'nom_type_ima')
    455454        nom_type_ima=browse.nom_type_ima;% get an image nomenclature type already determined by an input image name
     
    490489nburst=[];%default
    491490pxcmx=1;
    492 pxcmy=1; 
    493 
    494  %look for an image documentation file
     491pxcmy=1;
     492
     493%look for an image documentation file
    495494if ~isequal(ext,'.xml') && ~isequal(ext,'.civ')&& ~isequal(ext,'.avi')&& ~isequal(ext,'.AVI')
    496495    if exist([filebase '.xml'],'file')
    497          ext='.xml';
     496        ext='.xml';
    498497    elseif exist([filebase '.civxml'],'file')
    499          ext='.civxml';
     498        ext='.civxml';
    500499    elseif exist([filebase '.civ'],'file')
    501          ext='.civ';
    502     elseif exist([filebase '.avi'],'file') 
    503          ext='.avi';
     500        ext='.civ';
     501    elseif exist([filebase '.avi'],'file')
     502        ext='.avi';
    504503    elseif exist([filebase '.AVI'],'file')
    505          ext='.AVI';
     504        ext='.AVI';
    506505    end
    507506    set(handles.ImaDoc,'String',ext)
     
    526525    mode='pair j1-j2';
    527526    if isempty(nom_type_ima)% dtermine types by default if not already selected by browser or uvmat
    528             nom_type_ima='_i_j';
     527        nom_type_ima='_i_j';
    529528    end
    530529elseif isequal(ext,'.xml')
     
    534533    if isfield(XmlData,'Heading')&&isfield(XmlData.Heading','ImageName')&&ischar(XmlData.Heading.ImageName)% get image nom type and extension from the xml file
    535534        [PP,FF,fc,str2,str_a,str_b,ext_ima_read,nom_type_read]=name2display(XmlData.Heading.ImageName);
    536         fullname=fullfile(fileparts(filebase),XmlData.Heading.ImageName); %full name (including path) of the first image defined by the xmle file, 
     535        fullname=fullfile(fileparts(filebase),XmlData.Heading.ImageName); %full name (including path) of the first image defined by the xmle file,
    537536        if ~exist(fullname,'file')
    538537            msgbox_uvmat('WARNING',['FirstImage ' fullname ' defined in the xml file does not exist'])
     
    563562    if isfield(XmlData,'GeometryCalib')
    564563        tsai=XmlData.GeometryCalib;
    565         if isfield(tsai,'f') && isfield(tsai,'Tz') && isfield(tsai,'dpx') && isfield(tsai,'dpy')&& isfield(tsai,'R') 
    566              rot2D=tsai.R(1:2,[1,2]);
    567              pxcmx_search=tsai.f * sqrt(det(rot2D))/(tsai.Tz*tsai.dpx);
    568              pxcmy_search=tsai.f * sqrt(det(rot2D))/(tsai.Tz*tsai.dpy);           
    569         end
    570         if isfield(tsai,'CoordUnit') 
    571              CoordUnit=tsai.CoordUnit;
    572         end
    573     end               
     564        if isfield(tsai,'f') && isfield(tsai,'Tz') && isfield(tsai,'dpx') && isfield(tsai,'dpy')&& isfield(tsai,'R')
     565            rot2D=tsai.R(1:2,[1,2]);
     566            pxcmx_search=tsai.f * sqrt(det(rot2D))/(tsai.Tz*tsai.dpx);
     567            pxcmy_search=tsai.f * sqrt(det(rot2D))/(tsai.Tz*tsai.dpy);
     568        end
     569        if isfield(tsai,'CoordUnit')
     570            CoordUnit=tsai.CoordUnit;
     571        end
     572    end
    574573    if ~isempty(ext_ima_read) && ~isempty(nom_type_read)
    575574        if isempty(ext_ima)
    576              ext_ima=ext_ima_read;% define image extension from the xml file if an image has not been opened previously
    577         else   %keep the image extension           
     575            ext_ima=ext_ima_read;% define image extension from the xml file if an image has not been opened previously
     576        else   %keep the image extension
    578577            if  ~strcmp(ext_ima_read,ext_ima)
    579               msgbox_uvmat('WARNING',['FirtsImage extension ' ext_ima_read ' announced in the xml file inconsistent with the selected image'])
     578                msgbox_uvmat('WARNING',['FirtsImage extension ' ext_ima_read ' announced in the xml file inconsistent with the selected image'])
    580579            end
    581580        end
     
    583582    end
    584583elseif isequal(ext,'.civ')% case of .civ image documentation file
    585         [error,time,TimeUnit,mode,npx,npy]=read_imatext([filebase '.civ']);
    586         if error==2, msgbox_uvmat('WARNING',['no file ' filebase '.civ']);
    587         elseif error==1, msgbox_uvmat('WARNING','inconsistent number of fields in the .civ file');
    588         end
    589 %         ImaExt='.png';
    590         nom_type_ima='png_old';       
    591 elseif isequal(lower(ext),'.avi') 
    592         nom_type_ima='*';
    593         ext_ima=ext;
    594         set(handles.mode,'String',{'series(Di)'})
    595         dt=0.04;%default
    596         if exist([filebase ext],'file')==2
    597             info=aviinfo([filebase ext]);%read infos on the avi movie
    598             dt=1/info.FramesPerSecond;%time interval between successive frames
    599             nbfield=info.NumFrames;%number of frames
    600         end
    601         time=(dt*(0:nbfield-1))';%list of image times   
    602         %set(handles.dt,'String',num2str(dt*1000));%store the time interval between successive images
     584    [error,time,TimeUnit,mode,npx,npy]=read_imatext([filebase '.civ']);
     585    if error==2, msgbox_uvmat('WARNING',['no file ' filebase '.civ']);
     586    elseif error==1, msgbox_uvmat('WARNING','inconsistent number of fields in the .civ file');
     587    end
     588    %         ImaExt='.png';
     589    nom_type_ima='png_old';
     590elseif isequal(lower(ext),'.avi')
     591    nom_type_ima='*';
     592    ext_ima=ext;
     593    set(handles.mode,'String',{'series(Di)'})
     594    dt=0.04;%default
     595    if exist([filebase ext],'file')==2
     596        info=aviinfo([filebase ext]);%read infos on the avi movie
     597        dt=1/info.FramesPerSecond;%time interval between successive frames
     598        nbfield=info.NumFrames;%number of frames
     599    end
     600    time=(dt*(0:nbfield-1))';%list of image times
     601    %set(handles.dt,'String',num2str(dt*1000));%store the time interval between successive images
    603602end
    604603if isempty(time)
     
    612611    dirima=dir([filebase '_' num2str(first_i) '_' num2str(first_j) '.*']);
    613612    if isempty(dirima)
    614        % look for images series  with sub marker '_'
    615        dirima=dir([filebase '_*' num2str(first_i) '.*']);
    616        if isempty(dirima)
    617           % look for other images series
    618           dirima=dir([filebase '*' num2str(first_i) '.*']);
    619           if ~isempty(dirima)
    620               [pp,ff,fc,str2,str_a,str_b,ext_ima,nom_type_ima]=name2display(dirima(1).name);
    621           end
    622        else
    623            [pp,ff,fc,str2,str_a,str_b,ext_ima,nom_type_ima]=name2display(dirima(1).name);
    624        end
     613        % look for images series  with sub marker '_'
     614        dirima=dir([filebase '_*' num2str(first_i) '.*']);
     615        if isempty(dirima)
     616            % look for other images series
     617            dirima=dir([filebase '*' num2str(first_i) '.*']);
     618            if ~isempty(dirima)
     619                [pp,ff,fc,str2,str_a,str_b,ext_ima,nom_type_ima]=name2display(dirima(1).name);
     620            end
     621        else
     622            [pp,ff,fc,str2,str_a,str_b,ext_ima,nom_type_ima]=name2display(dirima(1).name);
     623        end
    625624    else
    626        [pp,ff,fc,str2,str_a,str_b,ext_ima,nom_type_ima]=name2display(dirima(1).name);
    627     end
    628 end   
    629 % no image documentation file found: look for a series of existing images or .nc files 
     625        [pp,ff,fc,str2,str_a,str_b,ext_ima,nom_type_ima]=name2display(dirima(1).name);
     626    end
     627end
     628% no image documentation file found: look for a series of existing images or .nc files
    630629if isempty(time) && ~isequal(ext,'.nc') && ~strcmp(nom_type_ima,'none') && ~strcmp(nom_type_ima,'') && ~strcmp(nom_type_ima,'*')
    631630    subdir=get(handles.subdir_civ1,'String');
    632631    incr_pair=[0 0];%default
    633632    if isfield(browse,'incr_pair')
    634             incr_pair=browse.incr_pair;
    635     end
    636 %     nbdetect=0;%test of detected images
     633        incr_pair=browse.incr_pair;
     634    end
     635    %     nbdetect=0;%test of detected images
    637636    field_i=field_count;
    638637    idetect=1;
    639     while idetect==1 %look for the maximum file number in the series     
     638    while idetect==1 %look for the maximum file number in the series
    640639        imagename=name_generator(filebase,field_i+1,1,ext_ima,nom_type_ima);
    641640        idetect=(exist(imagename,'file')==2);
     
    643642            field_i=field_i+1;
    644643        end
    645             %SEE CASE OF NETCDF FILES
    646 %             nbdetect=nbdetect+(exist(imagename,'file')==2);
     644        %SEE CASE OF NETCDF FILES
     645        %             nbdetect=nbdetect+(exist(imagename,'file')==2);
    647646    end
    648647    nb_field=field_i;% last detected field number
    649648    field_i=field_count;%look for the minimum file number in the series
    650649    idetect=1;
    651     while idetect==1 
     650    while idetect==1
    652651        imagename=name_generator(filebase,field_i-1,1,ext_ima,nom_type_ima);
    653652        idetect=(exist(imagename,'file')==2);
    654653        if idetect
    655            field_i=field_i-1;
     654            field_i=field_i-1;
    656655        end
    657656    end
    658657    first_i=max(field_i,1);
    659 
     658   
    660659    if strcmp(nom_type_ima,'_i_j')
    661660        field_i=field_count;
     
    673672        nb_field_j=field_j-1;% last detected field number
    674673    end
    675 
     674   
    676675   
    677676    %determine the set of times and possible intervals for CIV
    678  %   dt=(1/1000)*str2num(get(handles.dt,'String'));
     677    %   dt=(1/1000)*str2num(get(handles.dt,'String'));
    679678    time=(0:nb_field-1)';% time=file index -1  by default
    680     if strcmp(nom_type_ima,'_i_j') 
    681        % time=[0:nb_field-1]'*ones(1,nb_field_j);% time=file index -1  by default
    682        time=[0:nb_field-1]'*[0:nb_field_j-1];% time=file index -1  by default
    683     end
    684  
    685 
     679    if strcmp(nom_type_ima,'_i_j')
     680        % time=[0:nb_field-1]'*ones(1,nb_field_j);% time=file index -1  by default
     681        time=[0:nb_field-1]'*[0:nb_field_j-1];% time=file index -1  by default
     682    end
     683   
     684   
    686685    set(handles.mode,'String',{'series(Di)'})
    687686end
    688687% if isequal(nom_type_ima,'none')% no file numbering used
    689 %   first_i=1; 
     688%   first_i=1;
    690689%   last_i=1;
    691690%    first_j=1;
     
    715714set(handles.browse_root,'UserData',browse)% store the nomenclature type
    716715
    717         %%%%%%%%%%%  set the menus of image pairs and default selection for civ   %%%%%%%%%%%%%%%%%%%
     716%%%%%%%%%%%  set the menus of image pairs and default selection for civ   %%%%%%%%%%%%%%%%%%%
    718717if isequal(nom_type_ima,'_i')|| isequal(nom_type_nc,'_i1-i2')||~(exist('nbfield2','var')&&(nbfield2~=1))
    719718    set(handles.mode,'String',{'series(Di)'})
     
    728727    set(handles.mode,'String',{'pair j1-j2';'series(Dj)';'series(Di)'})%multiple choice
    729728    if nbfield2 <= 5
    730          set(handles.mode,'Value',1)% advice 'pair j1-j2' for small burst
    731     end
    732 %     else
    733 %     if isequal(mode,'volume')
    734 %         set(handles.mode,'Value',3)
    735 %     elseif nbfield2 <= 5
    736 %         set(handles.mode,'Value',1)% advice 'pair j1-j2' for small bursts
    737 %     else
    738 %         set(handles.mode,'Value',2)% advice series Dj for long bursts, not volume
    739 %     end
    740 end
    741 
    742 %update the subdir 
     729        set(handles.mode,'Value',1)% advice 'pair j1-j2' for small burst
     730    end
     731    %     else
     732    %     if isequal(mode,'volume')
     733    %         set(handles.mode,'Value',3)
     734    %     elseif nbfield2 <= 5
     735    %         set(handles.mode,'Value',1)% advice 'pair j1-j2' for small bursts
     736    %     else
     737    %         set(handles.mode,'Value',2)% advice series Dj for long bursts, not volume
     738    %     end
     739end
     740
     741%update the subdir
    743742pathdir=fileparts(filebase);%path to the current xml file
    744743listot=dir(pathdir);
     
    754753    end
    755754end
    756 set(handles.list_subdir_civ1,'Value',1) 
     755set(handles.list_subdir_civ1,'Value',1)
    757756set(handles.list_subdir_civ2,'Value',1)
    758757set(handles.list_subdir_civ1,'String',[{'browse...'};listdir])
     
    762761subdir_civ2=get(handles.subdir_civ2,'String');
    763762
    764 mode_Callback(hObject, eventdata, handles) 
     763mode_Callback(hObject, eventdata, handles)
    765764
    766765%%%%%% initialize waitbars and RUN button
     
    774773    set(handles.BATCH,'BackgroundColor',[1 0 0])
    775774end
    776    
     775
    777776%%%%% store the root input filename for future opening
    778777dir_perso=prefdir;
     
    786785    relnumb=str2num(Release(3:4));
    787786    if relnumb >= 14
    788         save (profil_perso,'RootPath','-V6'); %store the root name for future opening of uvmat 
     787        save (profil_perso,'RootPath','-V6'); %store the root name for future opening of uvmat
    789788    else
    790789        save (profil_perso,'RootPath'); %store the root name for future opening of uvmat
     
    828827    for numod_a=1:nbfield2-1 %nbfield2 always >=2 for 'pair j1-j2' mode
    829828        for numod_b=(numod_a+1):nbfield2
    830              index=index+1;
    831              numlist_a(index)=numod_a;
    832              numlist_b(index)=numod_b;
    833              if ~isempty(time)
     829            index=index+1;
     830            numlist_a(index)=numod_a;
     831            numlist_b(index)=numod_b;
     832            if ~isempty(time)
    834833                dt(numod_a,numod_b)=time(ref_i,numod_b)-time(ref_i,numod_a);%first time interval dt
    835834                displ_dt(index)=dt(numod_a,numod_b);
    836              else
    837                  displ_dt(index)=1;
    838              end
    839          end
    840      end
    841      [dtsort,indsort]=sort(displ_dt);
    842      if ~isempty(numlist_a)
    843      displ_num(1,:)=numlist_a(indsort);
    844      displ_num(2,:)=numlist_b(indsort);
    845      end
    846      displ_num(3,:)=0;
    847      displ_num(4,:)=0;
    848      set(handles.jtext,'Visible','Off')
     835            else
     836                displ_dt(index)=1;
     837            end
     838        end
     839    end
     840    [dtsort,indsort]=sort(displ_dt);
     841    if ~isempty(numlist_a)
     842        displ_num(1,:)=numlist_a(indsort);
     843        displ_num(2,:)=numlist_b(indsort);
     844    end
     845    displ_num(3,:)=0;
     846    displ_num(4,:)=0;
     847    set(handles.jtext,'Visible','Off')
    849848    set(handles.first_j,'Visible','Off')
    850849    set(handles.last_j,'Visible','Off')
     
    853852    set(handles.ref_j,'Visible','Off')
    854853elseif isequal(mode,'series(Dj)') %| isequal(mode,'st_series(Dj)')
    855      for index=1:min(nbfield2-1,200)
    856          displ_num(1,index)=-floor(index/2);
    857          displ_num(2,index)=ceil(index/2);
    858          displ_num(3,index)=0;
    859          displ_num(4,index)=0;
    860      end       
    861      set(handles.jtext,'Visible','On')
    862      set(handles.first_j,'Visible','On')
    863      set(handles.last_j,'Visible','On')
    864      set(handles.incr_j,'Visible','On')
    865      set(handles.nb_field2,'Visible','On')
    866      set(handles.ref_j,'Visible','On')
    867      if nbfield > 1
     854    for index=1:min(nbfield2-1,200)
     855        displ_num(1,index)=-floor(index/2);
     856        displ_num(2,index)=ceil(index/2);
     857        displ_num(3,index)=0;
     858        displ_num(4,index)=0;
     859    end
     860    set(handles.jtext,'Visible','On')
     861    set(handles.first_j,'Visible','On')
     862    set(handles.last_j,'Visible','On')
     863    set(handles.incr_j,'Visible','On')
     864    set(handles.nb_field2,'Visible','On')
     865    set(handles.ref_j,'Visible','On')
     866    if nbfield > 1
    868867        set(handles.itext,'Visible','On')
    869868        set(handles.first_i,'Visible','On')
     
    880879        set(handles.ref_i,'Visible','Off')
    881880    end
    882 elseif isequal(mode,'series(Di)') %| isequal(mode,'st_series(Di)') 
    883      for index=1:200%min(nbfield-1,200)
    884          displ_num(1,index)=0;
    885          displ_num(2,index)=0;
    886          displ_num(3,index)=-floor(index/2);
    887          displ_num(4,index)=ceil(index/2);
    888      end
    889      set(handles.itext,'Visible','On')
    890      set(handles.first_i,'Visible','On')
    891      set(handles.last_i,'Visible','On')
    892      set(handles.incr_i,'Visible','On')
    893      set(handles.nb_field,'Visible','On')
    894      set(handles.ref_i,'Visible','On')
    895      if nbfield2 > 1
     881elseif isequal(mode,'series(Di)') %| isequal(mode,'st_series(Di)')
     882    for index=1:200%min(nbfield-1,200)
     883        displ_num(1,index)=0;
     884        displ_num(2,index)=0;
     885        displ_num(3,index)=-floor(index/2);
     886        displ_num(4,index)=ceil(index/2);
     887    end
     888    set(handles.itext,'Visible','On')
     889    set(handles.first_i,'Visible','On')
     890    set(handles.last_i,'Visible','On')
     891    set(handles.incr_i,'Visible','On')
     892    set(handles.nb_field,'Visible','On')
     893    set(handles.ref_i,'Visible','On')
     894    if nbfield2 > 1
    896895        set(handles.jtext,'Visible','On')
    897896        set(handles.first_j,'Visible','On')
     
    900899        set(handles.nb_field2,'Visible','On')
    901900        set(handles.ref_j,'Visible','On')
    902      else
     901    else
    903902        set(handles.jtext,'Visible','Off')
    904903        set(handles.first_j,'Visible','Off')
     
    909908    end
    910909elseif isequal(mode,'displacement')%the pairs have the same indices
    911      displ_num(1,1)=0;
    912      displ_num(2,1)=0;
    913      displ_num(3,1)=0;
    914      displ_num(4,1)=0;
    915      if nbfield > 1
     910    displ_num(1,1)=0;
     911    displ_num(2,1)=0;
     912    displ_num(3,1)=0;
     913    displ_num(4,1)=0;
     914    if nbfield > 1
    916915        set(handles.itext,'Visible','On')
    917916        set(handles.first_i,'Visible','On')
     
    929928    end
    930929    if nbfield2 > 1
    931       set(handles.jtext,'Visible','On')
    932      set(handles.first_j,'Visible','On')
    933      set(handles.last_j,'Visible','On')
    934      set(handles.incr_j,'Visible','On')
    935      set(handles.nb_field2,'Visible','On')
    936      set(handles.ref_j,'Visible','On')
     930        set(handles.jtext,'Visible','On')
     931        set(handles.first_j,'Visible','On')
     932        set(handles.last_j,'Visible','On')
     933        set(handles.incr_j,'Visible','On')
     934        set(handles.nb_field2,'Visible','On')
     935        set(handles.ref_j,'Visible','On')
    937936    else
    938937        set(handles.jtext,'Visible','Off')
     
    943942        set(handles.ref_j,'Visible','Off')
    944943    end
    945 end 
     944end
    946945set(handles.list_pair_civ1,'UserData',displ_num);
    947946find_netcpair_civ1(hObject, eventdata, handles)
     
    975974end
    976975
    977 %determine nom_type_nc: 
     976%determine nom_type_nc:
    978977nom_type_nc=[];%default
    979978if isfield(browse,'nom_type_nc')
     
    981980end
    982981if isempty(nom_type_nc)
    983      [nom_type_nc]=nomtype2pair(nom_type_ima,isequal(mode,'series(Di)'),isequal(mode,'series(Dj)'));
     982    [nom_type_nc]=nomtype2pair(nom_type_ima,isequal(mode,'series(Di)'),isequal(mode,'series(Dj)'));
    984983end
    985984browse.nom_type_nc=nom_type_nc;
     
    10051004if isempty(time)
    10061005    time=[0 1];
    1007 end 
     1006end
    10081007%dt_unit=str2double(get(handles.dt,'String'));% used when there is no image documentation file
    10091008dt_unit=1000;%default
    10101009displ_num=get(handles.list_pair_civ1,'UserData');
    10111010
    1012 %eliminate the first pairs inconsistent with the position 
    1013  if isempty(displ_num)
    1014      nbpair=0;
    1015  else
     1011%eliminate the first pairs inconsistent with the position
     1012if isempty(displ_num)
     1013    nbpair=0;
     1014else
    10161015    nbpair=length(displ_num(1,:));%nbre of displayed pairs
    10171016    if  isequal(mode,'series(Di)')  %| isequal(mode,'st_series(Di)')
     
    10201019        nbpair=min(2*ref_j-1,nbpair);%limit the number of pairs with positive first index
    10211020    end
    1022  end
     1021end
    10231022nbpair=min(200,nbpair);%limit the number of displayed pairs to 200
    10241023
    1025 %look for existing processed pairs involving the field at the middle of the series if civ1 will not 
     1024%look for existing processed pairs involving the field at the middle of the series if civ1 will not
    10261025% be performed, while the result is needed for next steps.
    10271026displ_pair={''};
     
    10291028testpair=0;
    10301029if get(handles.CIV1,'Value')==0 %
    1031     if ~exist(fullfile(filepath,subdir_civ1,ext_dir),'dir') 
    1032          msgbox_uvmat('ERROR',['no civ1 file available: subdirectory ' subdir_civ1 ' does not exist']);
    1033          set(handles.list_pair_civ1,'String',{});
    1034          return
    1035     end
    1036     for ipair=1:nbpair   
     1030    if ~exist(fullfile(filepath,subdir_civ1,ext_dir),'dir')
     1031        msgbox_uvmat('ERROR',['no civ1 file available: subdirectory ' subdir_civ1 ' does not exist']);
     1032        set(handles.list_pair_civ1,'String',{});
     1033        return
     1034    end
     1035    for ipair=1:nbpair
    10371036        filename=name_generator(filebase,ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair),'.nc',nom_type_nc,1,...
    1038         ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair),subdir_civ1);
     1037            ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair),subdir_civ1);
    10391038        select(ipair)=exist(filename,'file')==2;
    10401039    end
    10411040    if ~exist('select','var') || isequal(select,zeros(size(1:nbpair)))
    1042         if isfield(browse,'incr_pair') 
     1041        if isfield(browse,'incr_pair')
    10431042            num_i1=ref_i-floor(browse.incr_pair(1)/2);
    10441043            num_i2=ref_i+ceil(browse.incr_pair(1)/2);
     
    10491048            testpair=1;
    10501049        else
    1051             if  isequal(mode,'series(Dj)')% | isequal(mode,'st_series(Dj)') 
     1050            if  isequal(mode,'series(Dj)')% | isequal(mode,'st_series(Dj)')
    10521051                msgbox_uvmat('ERROR',['no civ1 file available for the selected reference index j=' num2str(ref_j) ' and subdirectory ' subdir_civ1]);
    10531052            else
    10541053                msgbox_uvmat('ERROR',['no civ1 file available for the selected reference index i=' num2str(ref_i) ' and subdirectory ' subdir_civ1]);
    10551054            end
    1056              set(handles.list_pair_civ1,'String',{''});
    1057              %COMPLETER CAS STEREO
     1055            set(handles.list_pair_civ1,'String',{''});
     1056            %COMPLETER CAS STEREO
    10581057            return
    10591058        end
     
    10881087elseif isequal(mode,'series(Dj)')%|isequal(mode,'st_series(Dj)')% series on the j index
    10891088    if testpair
    1090          displ_pair{1}=['Dj= ' num2str(-floor(browse.incr_pair(1)/2)) '|' num2str(ceil(browse.incr_pair(1)/2))];
     1089        displ_pair{1}=['Dj= ' num2str(-floor(browse.incr_pair(1)/2)) '|' num2str(ceil(browse.incr_pair(1)/2))];
    10911090    else
    1092        for ipair=1:nbpair
    1093           if select(ipair)
    1094               if size(time,1)>=ref_i+displ_num(4,ipair) && size(time,2)>=ref_j+displ_num(2,ipair)
    1095               dt=time(ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair));%time interval dt
    1096               displ_pair{ipair}=['Dj= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt*1000)];
    1097               end
    1098            elseif testpair
    1099               displ_pair{1}=['Dj= ' num2str(-floor(browse.incr_pair(2)/2)) '|' num2str(ceil(browse.incr_pair(2)/2))];
    1100           else
    1101              displ_pair{ipair}='...'; %pair not displayed in the menu
    1102           end
    1103        end
    1104    end
     1091        for ipair=1:nbpair
     1092            if select(ipair)
     1093                if size(time,1)>=ref_i+displ_num(4,ipair) && size(time,2)>=ref_j+displ_num(2,ipair)
     1094                    dt=time(ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair));%time interval dt
     1095                    displ_pair{ipair}=['Dj= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt*1000)];
     1096                end
     1097            elseif testpair
     1098                displ_pair{1}=['Dj= ' num2str(-floor(browse.incr_pair(2)/2)) '|' num2str(ceil(browse.incr_pair(2)/2))];
     1099            else
     1100                displ_pair{ipair}='...'; %pair not displayed in the menu
     1101            end
     1102        end
     1103    end
    11051104elseif isequal(mode,'pair j1-j2')%|isequal(mode,'st_pair j1-j2')%case of pairs
    11061105    for ipair=1:nbpair
    11071106        if select(ipair)
    1108            dt=time(ref_i+displ_num(4,ipair),displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),displ_num(1,ipair));%time interval dt
    1109            displ_pair{ipair}=['j= ' num2stra(displ_num(1,ipair),nom_type_ima) '-' num2stra(displ_num(2,ipair),nom_type_ima) ...
    1110                         ' :dt= ' num2str(dt*1000)];
    1111        else
    1112           displ_pair{ipair}='...'; %pair not displayed in the menu
    1113         end   
    1114    end
     1107            dt=time(ref_i+displ_num(4,ipair),displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),displ_num(1,ipair));%time interval dt
     1108            displ_pair{ipair}=['j= ' num2stra(displ_num(1,ipair),nom_type_ima) '-' num2stra(displ_num(2,ipair),nom_type_ima) ...
     1109                ' :dt= ' num2str(dt*1000)];
     1110        else
     1111            displ_pair{ipair}='...'; %pair not displayed in the menu
     1112        end
     1113    end
    11151114elseif isequal(mode,'displacement')
    1116     displ_pair={'Di=Dj=0'}; 
    1117 end   
     1115    displ_pair={'Di=Dj=0'};
     1116end
    11181117set(handles.list_pair_civ1,'String',displ_pair');
    11191118ichoice=min(find(select));
    11201119if (isempty(ichoice) || ichoice < 1); ichoice=1; end;
    11211120initial=get(handles.list_pair_civ1,'Value');%initial choice of pair
    1122 if initial>nbpair 
    1123      set(handles.list_pair_civ1,'Value',ichoice);% first valid pair proposed by default in the menu
     1121if initial>nbpair
     1122    set(handles.list_pair_civ1,'Value',ichoice);% first valid pair proposed by default in the menu
    11241123end
    11251124if numel(select)>=initial && ~isequal(select(initial),1)
     
    11401139
    11411140%------------------------------------------------------------------------
    1142 % determine the menu for civ2 pairs depending on the existing netcdf file at the 
    1143 %middle of the series set by first_i, incr, last_i 
     1141% determine the menu for civ2 pairs depending on the existing netcdf file at the
     1142%middle of the series set by first_i, incr, last_i
    11441143function find_netcpair_civ2(hObject, eventdata, handles)
    11451144%------------------------------------------------------------------------
     
    11741173    nom_type_nc='none';
    11751174elseif isequal(nom_type_ima,'avi')||isequal(nom_type_ima,'_i')||isequal(nom_type_ima,'ima_num')||isequal(nom_type_nc,'_i1-i2')
    1176      nom_type_nc='_i1-i2';
     1175    nom_type_nc='_i1-i2';
    11771176else
    11781177    if  isequal(mode,'series(Di)')%|isequal(mode,'st_series(Di)')
     
    11801179    else
    11811180        nom_type_nc='_i_j1-j2';
    1182     end   
     1181    end
    11831182end
    11841183browse.nom_type_nc=nom_type_nc;
     
    12121211
    12131212
    1214 %eliminate the first pairs inconsistent with the position 
     1213%eliminate the first pairs inconsistent with the position
    12151214if isempty(displ_num)
    12161215    nbpair=0;
    12171216else
    12181217    nbpair=length(displ_num(1,:));%nbre of displayed pairs
    1219     if  isequal(mode,'series(Di)')% | isequal(mode,'st_series(Di)') 
     1218    if  isequal(mode,'series(Di)')% | isequal(mode,'st_series(Di)')
    12201219        nbpair=min(2*ref_i-1,nbpair);%limit the number of pairs with positive first index
    1221     elseif  isequal(mode,'series(Dj)')% | isequal(mode,'st_series(Dj)') 
     1220    elseif  isequal(mode,'series(Dj)')% | isequal(mode,'st_series(Dj)')
    12221221        nbpair=min(2*ref_j-1,nbpair);%limit the number of pairs with positive first index
    12231222    end
     
    12251224nbpair=min(200,nbpair);%limit the number of displayed pairs to 200
    12261225
    1227 %look for existing processed pairs involving the field at the middle of the series if civ1 will not 
     1226%look for existing processed pairs involving the field at the middle of the series if civ1 will not
    12281227% be performed, while the result is needed for next steps.
    12291228displ_pair={''}; %default
    12301229select=ones(size(1:nbpair));%default =1 for numbers of displayed pairs
    12311230if get(handles.CIV2,'Value')==0 & get(handles.CIV1,'Value')==0 & get(handles.FIX1,'Value')==0 & get(handles.PATCH1,'Value')==0%&...
    1232     if ~exist(fullfile(filepath,subdir_civ2,ext_dir),'dir') 
    1233          errordlg(['no civ2 file available: subdirectory ' subdir_civ2 ' does not exist'])
    1234          set(handles.list_pair_civ2,'Value',1);
    1235          set(handles.list_pair_civ2,'String',{''});
    1236          return
    1237     end
    1238     for ipair=1:nbpair       
     1231    if ~exist(fullfile(filepath,subdir_civ2,ext_dir),'dir')
     1232        errordlg(['no civ2 file available: subdirectory ' subdir_civ2 ' does not exist'])
     1233        set(handles.list_pair_civ2,'Value',1);
     1234        set(handles.list_pair_civ2,'String',{''});
     1235        return
     1236    end
     1237    for ipair=1:nbpair
    12391238        filename=name_generator(filebase,ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair),'.nc',nom_type_nc,1,...
    1240         ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair),subdir_civ1);
     1239            ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair),subdir_civ1);
    12411240        select(ipair)=exist(filename,'file')==2;
    12421241    end
    12431242    if  isequal(select,zeros(size(1:nbpair)))
    1244         if isfield(browse,'incr_pair') 
     1243        if isfield(browse,'incr_pair')
    12451244            num_i1=ref_i-floor(browse.incr_pair(1)/2);
    12461245            num_i2=ref_i+floor((browse.incr_pair(1)+1)/2);
     
    12501249            select(1)=exist(filename,'file')==2;
    12511250        else
    1252             if  isequal(mode,'series(Dj)')% | isequal(mode,'st_series(Dj)') 
     1251            if  isequal(mode,'series(Dj)')% | isequal(mode,'st_series(Dj)')
    12531252                errordlg(['no civ2 file available for the selected reference index j=' num2str(ref_j) ' and subdirectory ' subdir_civ2])
    12541253            else
    12551254                errordlg(['no civ2 file available for the selected reference index i=' num2str(ref_i) ' and subdirectory ' subdir_civ2])
    12561255            end
    1257              set(handles.list_pair_civ2,'Value',1);
    1258              set(handles.list_pair_civ2,'String',{''});
     1256            set(handles.list_pair_civ2,'Value',1);
     1257            set(handles.list_pair_civ2,'String',{''});
    12591258            return
    12601259        end
    12611260    end
    12621261end
    1263 if isequal(mode,'series(Di)') % | isequal(mode,'st_series(Di)') 
    1264        for ipair=1:nbpair
    1265           if select(ipair)
    1266               if size(time,1)>=ref_i+displ_num(4,ipair) && size(time,2)>=ref_j+displ_num(2,ipair)
     1262if isequal(mode,'series(Di)') % | isequal(mode,'st_series(Di)')
     1263    for ipair=1:nbpair
     1264        if select(ipair)
     1265            if size(time,1)>=ref_i+displ_num(4,ipair) && size(time,2)>=ref_j+displ_num(2,ipair)
    12671266                dt=time(ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair));%time interval dt
    12681267                displ_pair{ipair}=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt*1000)];
    1269               end
    1270           else
    1271              displ_pair{ipair}='...'; %pair not displayed in the menu
    1272           end
    1273        end
     1268            end
     1269        else
     1270            displ_pair{ipair}='...'; %pair not displayed in the menu
     1271        end
     1272    end
    12741273elseif isequal(mode,'series(Dj)') %| isequal(mode,'st_series(Dj)') % series on the j index
    1275        for ipair=1:nbpair
    1276           if select(ipair)
    1277               if size(time,1)>=ref_i+displ_num(4,ipair) && size(time,2)>=ref_j+displ_num(2,ipair)
    1278               dt=time(ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair));%time interval dt
    1279               displ_pair{ipair}=['Dj= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt*1000)];
    1280               end
    1281           else
    1282              displ_pair{ipair}='...'; %pair not displayed in the menu
    1283           end
    1284        end
     1274    for ipair=1:nbpair
     1275        if select(ipair)
     1276            if size(time,1)>=ref_i+displ_num(4,ipair) && size(time,2)>=ref_j+displ_num(2,ipair)
     1277                dt=time(ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair));%time interval dt
     1278                displ_pair{ipair}=['Dj= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt*1000)];
     1279            end
     1280        else
     1281            displ_pair{ipair}='...'; %pair not displayed in the menu
     1282        end
     1283    end
    12851284elseif isequal(mode,'pair j1-j2')% | isequal(mode,'st_pair j1-j2') %case of pairs
    12861285    for ipair=1:nbpair
    12871286        if select(ipair)
    1288            dt=time(ref_i+displ_num(4,ipair),displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),displ_num(1,ipair));%time interval dt
    1289            displ_pair{ipair}=['j= ' num2stra(displ_num(1,ipair),nom_type_ima) '-' num2stra(displ_num(2,ipair),nom_type_ima) ...
    1290                         ' :dt= ' num2str(dt*1000)];
    1291        else
    1292           displ_pair{ipair}='...'; %pair not displayed in the menu
    1293        end   
    1294    end
     1287            dt=time(ref_i+displ_num(4,ipair),displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),displ_num(1,ipair));%time interval dt
     1288            displ_pair{ipair}=['j= ' num2stra(displ_num(1,ipair),nom_type_ima) '-' num2stra(displ_num(2,ipair),nom_type_ima) ...
     1289                ' :dt= ' num2str(dt*1000)];
     1290        else
     1291            displ_pair{ipair}='...'; %pair not displayed in the menu
     1292        end
     1293    end
    12951294elseif isequal(mode,'displacement')
    1296     displ_pair={'Di=Dj=0'}; 
    1297 end   
     1295    displ_pair={'Di=Dj=0'};
     1296end
    12981297val=get(handles.list_pair_civ2,'Value');
    12991298ichoice=min(find(select));
     
    13111310
    13121311%------------------------------------------------------------------------
    1313 %  determine the list of index pairs of processing file 
     1312%  determine the list of index pairs of processing file
    13141313function [num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2]=...
    13151314    find_pair_indices(handles,mode)
    13161315%------------------------------------------------------------------------
    1317 first_i=str2double(get(handles.first_i,'String'));%first index i 
    1318 last_i=str2double(get(handles.last_i,'String'));%last index i 
     1316first_i=str2double(get(handles.first_i,'String'));%first index i
     1317last_i=str2double(get(handles.last_i,'String'));%last index i
    13191318incr=str2double(get(handles.incr_i,'String'));% increment
    13201319num_i=[first_i:incr:last_i];% list of i indices (reference values for each pair)
    13211320if isequal(get(handles.first_j,'Visible'),'on')
    13221321    first_j=str2double(get(handles.first_j,'String'));%first index j
    1323     last_j=str2double(get(handles.last_j,'String'));%last index j 
     1322    last_j=str2double(get(handles.last_j,'String'));%last index j
    13241323    incr_j=str2double(get(handles.incr_j,'String'));% increment
    13251324else
     
    13441343str_civ2=list_civ2{index_civ2};%string defining the image pairs for civ2
    13451344if isempty(first_i)||isempty(first_j), msgbox_uvmat('ERROR','first field number not defined'),...
    1346     return,end;
     1345        return,end;
    13471346if isequal(last_i,[])|| isequal(last_j,[]),msgbox_uvmat('ERROR','last field number not defined'),...
    1348     return,end;
     1347        return,end;
    13491348if isequal(incr,[])|| isequal(incr_j,[]),msgbox_uvmat('ERROR','increment in field number not defined'),...
    1350     return,end;
     1349        return,end;
    13511350if last_i < first_i || last_j < first_j , msgbox_uvmat('ERROR','last field number must be larger than the first one'),...
    1352     return,end;
    1353 if isequal (mode,'series(Di)') 
    1354      %recognize the pair civ1 from the display
    1355         indsel=find((double(str_civ1)<48)|(double(str_civ1)>57));% character indices of non numerical characters
     1351        return,end;
     1352if isequal (mode,'series(Di)')
     1353    %recognize the pair civ1 from the display
     1354    indsel=find((double(str_civ1)<48)|(double(str_civ1)>57));% character indices of non numerical characters
    13561355    str_raw=str_civ1(indsel);
    13571356    indsepar=find(str_raw=='|'); %character index of the separator
     
    13611360    else
    13621361        d2=str2double(str_civ1([indsel(indsepar)+1:indsel(indsepar+1)-1]));
    1363     end   
     1362    end
    13641363    num1_civ1=num_i-d1;% set of first image numbers
    13651364    num2_civ1=num_i+d2;
     
    13761375    else
    13771376        d2=str2num(str_civ2([indsel(indsepar)+1:indsel(indsepar+1)-1]));
    1378     end   
     1377    end
    13791378    if isempty(d1)
    13801379        num1_civ2=num_i;
     
    14721471end
    14731472
    1474 %update first_i and last_i according to the chosen image pairs 
     1473%update first_i and last_i according to the chosen image pairs
    14751474mode_list=get(handles.mode,'String');
    14761475mode_value=get(handles.mode,'Value');
     
    14841483    if ~isequal(lastfield,[])
    14851484        ind=find((num1-floor(index_pair/2)*ones(size(num1))>0)& ...
    1486              (num1+ceil(index_pair/2)*ones(size(num1))<=lastfield));
     1485            (num1+ceil(index_pair/2)*ones(size(num1))<=lastfield));
    14871486        num1=num1(ind);
    14881487    end
     
    14971496    if ~isequal(lastfield2,[])
    14981497        ind=find((num_j-floor(index_pair/2)*ones(size(num_j))>0)& ...
    1499              (num_j+ceil(index_pair/2)*ones(size(num_j))<=lastfield2));
     1498            (num_j+ceil(index_pair/2)*ones(size(num_j))<=lastfield2));
    15001499        num1=num_j(ind);
    15011500    end
    15021501    set(handles.first_j,'String',num2str(num1(1)));
    15031502    set(handles.last_j,'String',num2str(num1(end)));
    1504 end 
     1503end
    15051504
    15061505%------------------------------------------------------------------------
     
    15081507function list_pair_civ2_Callback(hObject, eventdata, handles)
    15091508%------------------------------------------------------------------------
    1510 index_pair=get(handles.list_pair_civ2,'Value');%get the selected position index in the menu 
    1511 
    1512 %update first_i and last_i according to the chosen image pairs 
     1509index_pair=get(handles.list_pair_civ2,'Value');%get the selected position index in the menu
     1510
     1511%update first_i and last_i according to the chosen image pairs
    15131512mode_list=get(handles.mode,'String');
    15141513mode_value=get(handles.mode,'Value');
     
    15221521    if ~isequal(lastfield,[])
    15231522        ind=find((num1-floor(index_pair/2)*ones(size(num1))>0)& ...
    1524              (num1+ceil(index_pair/2)*ones(size(num1))<=lastfield));
     1523            (num1+ceil(index_pair/2)*ones(size(num1))<=lastfield));
    15251524        num1=num1(ind);
    15261525    end
     
    15351534    if ~isequal(lastfield2,[])
    15361535        ind=find((num_j-floor(index_pair/2)*ones(size(num_j))>0)& ...
    1537              (num_j+ceil(index_pair/2)*ones(size(num_j))<=lastfield2));
     1536            (num_j+ceil(index_pair/2)*ones(size(num_j))<=lastfield2));
    15381537        num1=num_j(ind);
    15391538    end
    15401539    set(handles.first_j,'String',num2str(num1(1)));
    15411540    set(handles.last_j,'String',num2str(num1(end)));
    1542 end 
     1541end
    15431542
    15441543%------------------------------------------------------------------------
     
    15701569%     return
    15711570% end
    1572 % 
     1571%
    15731572% %root name
    15741573% filebase=get(handles.RootName,'String');
     
    16021601%     end
    16031602% end
    1604 % 
    1605 % %read names of the .exe file 
    1606 % if box_test(1)==1 || box_test(3)==1 || box_test(4)==1 || box_test(6)==1 
     1603%
     1604% %read names of the .exe file
     1605% if box_test(1)==1 || box_test(3)==1 || box_test(4)==1 || box_test(6)==1
    16071606%     path_uvmat=which('uvmat');% check the path detected for source file uvmat
    16081607%     path_UVMAT=fileparts(path_uvmat); %path to UVMAT
     
    16361635%     if isfield(sparam,'SGE')
    16371636%         sge=str2double(sparam.SGE);
    1638 %     end 
     1637%     end
    16391638%     if ~isunix % for windows system, check whether the Matlab working dir is a UBC name
    16401639%         dircur=pwd;
     
    16451644%     end
    16461645% end
    1647 % 
     1646%
    16481647% %initialize the waitbars
    16491648% set(handles.waitbar_1,'Position',[0.946 0.877 0.03 0.001])
     
    16541653% set(handles.RUN, 'Enable','Off')
    16551654% drawnow
    1656 % 
     1655%
    16571656% % get the list of file names and check the files
    16581657% display('checking the files...')
     
    16611660% nbfield=numel(num1_civ1);
    16621661% nbslice=size(num_a_civ1);
    1663 % 
     1662%
    16641663% if isempty(filecell)
    16651664%    set(handles.RUN, 'Enable','On')
     
    16691668%    return
    16701669% end
    1671 % display('files OK, processing...')   
     1670% display('files OK, processing...')
    16721671% nbfield=size(num1_civ1,2);
    16731672% nbslice=size(num1_civ1,1);
    1674 % 
     1673%
    16751674% %RUN CIV1
    16761675% if box_test(1)==1
     
    16801679%      end
    16811680% end
    1682 % 
     1681%
    16831682% %RUN FIX1
    1684 % if box_test(2)==1 
     1683% if box_test(2)==1
    16851684%     filebase=get(handles.RootName,'String');
    16861685%     %names of the civ1 fields
     
    17041703%     else
    17051704%         fieldchoice=menu{index};
    1706 %     end   
    1707 %     h = waitbar(0,'removing velocity vectors, fix1');% display a wait bar 
    1708 %     test_mask=get(handles.get_mask_fix1,'Value');   
     1705%     end
     1706%     h = waitbar(0,'removing velocity vectors, fix1');% display a wait bar
     1707%     test_mask=get(handles.get_mask_fix1,'Value');
    17091708%     if test_mask
    17101709%         maskdispl=get(handles.mask_fix1,'String');
     
    17231722%                 maskflag=0;
    17241723%             elseif test_mask==1
    1725 %                 nbslice_mask=str2double(maskdispl(1:end-4)); % 
     1724%                 nbslice_mask=str2double(maskdispl(1:end-4)); %
    17261725%                 num1_mask=mod(num1_civ1(ifile)-1,nbslice_mask)+1;
    17271726%                 maskname=name_generator(maskbase,num1_mask,1,'.png','_i');% mask corresponding to the first image of the pair
    17281727%                 maskflag= exist(maskname,'file')==2;
    1729 %                 if ~maskflag; 
     1728%                 if ~maskflag;
    17301729%                     maskname='noFile use default';
    1731 %                 end             
     1730%                 end
    17321731%             end
    17331732%             if ~isempty(file_ref_fix1)
     
    17381737%             error=RUN_FIX(filecell.nc.civ1{ifile,j},field1,flagindex,1,thresh_vecC,maskflag,maskname,...
    17391738%                                     thresh_vel,inf_sup,file_ref,fieldchoice);
    1740 % 
     1739%
    17411740%             if compare==3 &&(isequal(mode,'pair j1-j2') || isequal(mode,'series(Dj)') || isequal(mode,'series(Di)'))
    1742 %                  if test_mask==0 
     1741%                  if test_mask==0
    17431742%                       maskname='noFile use default';
    17441743%                       maskflag=0;
    17451744%                  else
    17461745%                      maskbase=[get(handles.RootName2,'String') '_' maskdispl]; % mask root name
    1747 %                      nbslice_mask=str2num(maskdispl(1:end-4)); % 
    1748 %                      num1_mask=mod(num1_civ1(ifile)-1,nbslice_mask)+1;               
     1746%                      nbslice_mask=str2num(maskdispl(1:end-4)); %
     1747%                      num1_mask=mod(num1_civ1(ifile)-1,nbslice_mask)+1;
    17491748%                      maskname=name_generator(maskbase,num1_mask,1,'.png','_i');
    17501749%                      maskflag= exist(maskname,'file')==2;
    1751 %                      if ~maskflag; 
     1750%                      if ~maskflag;
    17521751%                         maskname='noFile use default';
    17531752%                      end
     
    17581757%                     msgbox_uvmat('ERROR',error)
    17591758%                     return
    1760 %                  end             
     1759%                  end
    17611760%             end
    17621761%         end
     
    17641763%     close(h)
    17651764% end
    1766 % 
     1765%
    17671766% % RUN PATCH1
    17681767% if box_test(3)==1
     
    17861785%     subdomain_patch1=get(handles.subdomain_patch1,'String');
    17871786%     thresh_patch1=get(handles.thresh_patch1,'String');
    1788 %     test_interp=get(handles.test_interp,'Value'); 
     1787%     test_interp=get(handles.test_interp,'Value');
    17891788%     icount=0;
    17901789%     for ifile=1:nbfield
     
    18021801%                 if s~=0
    18031802%                     display(['!' cmd])
    1804 %                     eval(['!' cmd]);                 
     1803%                     eval(['!' cmd]);
    18051804%                 end
    1806 % 
     1805%
    18071806%                 %stereo case:
    18081807%             elseif  isequal(get(handles.test_stereo1,'Value'),1)
     
    18111810%                           nx_patch1,ny_patch1,rho_patch1,subdomain_patch1,thresh_patch1,[filebase_A '.xml'],[filebase_B '.xml']);
    18121811%                     display(['!' cmd])
    1813 %                     eval(['!' cmd]);       
     1812%                     eval(['!' cmd]);
    18141813%                 else
    18151814%                     RUN_STLIN(filecell.ncA.civ1{ifile,j},filecell.nc.civ1{ifile,j},'civ1',filecell.st{ifile,j},...
     
    18311830%     end
    18321831% end
    1833 % 
     1832%
    18341833% % CIV2
    1835 % if box_test(4)==1 
     1834% if box_test(4)==1
    18361835%     RUN_CIV2(handles,filecell.ima1.civ2,filecell.ima2.civ2,filecell.nc.civ1,filecell.nc.civ2,num1_civ2,num2_civ2,...
    18371836%         num_a_civ2,num_b_civ2,nom_type_nc)
    18381837% end
    1839 % 
     1838%
    18401839% % FIX2
    1841 % if box_test(5)==1 
     1840% if box_test(5)==1
    18421841%     %names of the civ2 fields
    18431842%     field2.vel_type='civ2';
     
    18601859%     else
    18611860%         fieldchoice=menu{index};
    1862 %     end   
     1861%     end
    18631862%     h = waitbar(0,['removing velocity vectors, fix2']);% display a wait bar
    18641863%     test_mask=get(handles.get_mask_fix2,'Value');
     
    18741873%     for ifile=1:nbfield
    18751874%         waitbar(ifile/nbfield); %update the waitbar
    1876 %         for j=1:nbslice       
    1877 %            if test_mask==0 
     1875%         for j=1:nbslice
     1876%            if test_mask==0
    18781877%                 maskname='noFile use default';
    18791878%                 maskflag=0;
    18801879%            elseif test_mask==1
    1881 %                 nbslice_mask=str2num(maskdispl(1:end-4)); % 
     1880%                 nbslice_mask=str2num(maskdispl(1:end-4)); %
    18821881%                 num1_mask=mod(num1_civ2(ifile)-1,nbslice_mask)+1;
    18831882%                 maskname=name_generator(maskbase,num1_mask,1,'.png','_i');
    18841883%                 maskflag= exist(maskname,'file')==2;
    1885 %                 if ~maskflag; 
     1884%                 if ~maskflag;
    18861885%                       maskname='noFile use default';
    18871886%                 end
     
    18931892%             end
    18941893%             error=RUN_FIX(filecell.nc.civ2{ifile,j},field2,flagindex,2,thresh_vec2C,maskflag,maskname,...
    1895 %                                     thresh_vel2,inf_sup,file_ref,fieldchoice); 
     1894%                                     thresh_vel2,inf_sup,file_ref,fieldchoice);
    18961895%             if ~isempty(error)
    18971896%                 msgbox_uvmat('ERROR',error)
    18981897%                 return
    1899 %             end 
     1898%             end
    19001899%             if compare==3
    1901 %                  if test_mask==0 
     1900%                  if test_mask==0
    19021901%                       maskname='noFile use default';
    19031902%                       maskflag=0;
    19041903%                  else
    19051904%                       maskbase=[get(handles.RootName2,'String') '_' maskdispl]; % mask root name
    1906 %                       nbslice_mask=str2num(maskdispl(1:end-4)); % 
     1905%                       nbslice_mask=str2num(maskdispl(1:end-4)); %
    19071906%                       num1_mask=mod(num1_civ2(ifile)-1,nbslice_mask)+1;
    19081907%                       maskname=name_generator(maskbase,num1_mask,1,'.png','_i');
    19091908%                       maskflag= exist(maskname,'file')==2;
    1910 %                       if ~maskflag; 
     1909%                       if ~maskflag;
    19111910%                          maskname='noFile use default';
    19121911%                       end
     
    19171916%                     msgbox_uvmat('ERROR',error)
    19181917%                     return
    1919 %                  end 
     1918%                  end
    19201919%             end
    19211920%         end
     
    19231922%     close(h)
    19241923% end
    1925 % 
     1924%
    19261925% %PATCH 2
    19271926% if box_test(6)==1
     
    19631962%                 end
    19641963%             elseif compare==3 &&  isequal(get(handles.test_stereo2,'Value'),1)
    1965 %                if exist('stinterp_exe','var')%Prog Gauthier 
     1964%                if exist('stinterp_exe','var')%Prog Gauthier
    19661965%                    cmd=RUN_STINTERP(stinterp_exe,filecell.ncA.civ2{ifile,j},filecell.nc.civ2{ifile,j},filecell.st{ifile,j},...
    19671966%                    nx_patch2,ny_patch2,rho_patch2,subdomain_patch2,thresh_patch2,[filebase_A '.xml'],[filebase_B '.xml']);
     
    19721971%                    str2num(nx_patch2),str2num(ny_patch2),str2num(thresh_patch2),[filebase_A '.xml'],[filebase_B '.xml'])
    19731972%                end
    1974 %             end   
     1973%             end
    19751974%             if compare==3 && isequal(get(handles.test_stereo2,'Value'),0)
    19761975%                 cmd=RUN_PATCH(filecell.ncA.civ2{ifile,j},nx_patch2,ny_patch2,rho_patch2,subdomain_patch2,1,0);
     
    19871986%     end
    19881987% end
    1989 % 
     1988%
    19901989% set(handles.RUN, 'Enable','On')
    19911990% set(handles.RUN,'BackgroundColor',[1 0 0])
    1992 % 
     1991%
    19931992% %save the current interface setting as figure namefig, append .0 to the name if it already exists
    19941993% if isfield(filecell,'st')
     
    20032002% [RootPath,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fileresu);
    20042003% namedoc=fullfile(RootPath,subdir,RootFile);
    2005 % detect=1; 
     2004% detect=1;
    20062005% while detect==1
    20072006%     namefigfull=[namedoc '.fig'];
     
    20732072    return
    20742073end
    2075    
     2074
    20762075%check mask if selecetd
    20772076if isequal(get(handles.get_mask_civ1,'Value'),1)
     
    20902089    maskname=get(handles.mask_civ2,'String');
    20912090    if ~exist(maskname,'file')
    2092      get_mask_civ2_Callback(hObject, eventdata, handles);
     2091        get_mask_civ2_Callback(hObject, eventdata, handles);
    20932092    end
    20942093end
     
    20962095    maskname=get(handles.mask_fix2,'String');
    20972096    if ~exist(maskname,'file')
    2098      get_mask_fix2_Callback(hObject, eventdata, handles);
     2097        get_mask_fix2_Callback(hObject, eventdata, handles);
    20992098    end
    21002099end
     
    21032102path_uvmat=which('uvmat');% check the path detected for source file uvmat
    21042103path_UVMAT=fileparts(path_uvmat); %path to UVMAT
    2105 xmlfile=fullfile(path_UVMAT,'PARAM.xml');
     2104xmlfile='PARAM.xml';
    21062105if exist(xmlfile,'file')
    21072106    t=xmltree(xmlfile);
     
    21252124        return
    21262125    end
    2127 end
    2128 if isfield(sparam,'CivBin')
    2129     if ~exist(sparam.CivBin,'file')
    2130          sparam.CivBin=fullfile(path_UVMAT,sparam.CivBin);
    2131     end
    2132 end
    2133 if isfield(sparam,'Civ1Bin')
    2134     if ~exist(sparam.Civ1Bin,'file')
    2135          sparam.Civ1Bin=fullfile(path_UVMAT,sparam.Civ1Bin);
    2136     end
    2137 end
    2138 if isfield(sparam,'Civ2Bin')
    2139     if ~exist(sparam.Civ2Bin,'file')
    2140          sparam.Civ2Bin=fullfile(path_UVMAT,sparam.Civ2Bin);
    2141     end
    2142 end
    2143 %test_interp=get(handles.test_interp,'Value');
    2144 test_interp=0;
    2145 if  isfield(sparam,'PatchBin')
    2146     if ~exist(sparam.PatchBin,'file')
    2147          sparam.PatchBin=fullfile(path_UVMAT,sparam.PatchBin);
    2148     end
    2149 end
    2150 % if test_interp && isfield(sparam,'PatchNewBin')
    2151 %     if ~exist(sparam.PatchNewBin,'file')
    2152 %          sparam.PatchNewBin=fullfile(path_UVMAT,sparam.PatchNewBin);
    2153 %     end
    2154 % end
    2155 if isfield(sparam,'FixBin')
    2156 %     fixBin=sparam.FixBin;
    2157     if ~exist(sparam.FixBin,'file')
    2158          sparam.FixBin=fullfile(path_UVMAT,sparam.FixBin);
    2159     end
    2160 end
     2126    if isfield(sparam,'CivBin')
     2127        if ~exist(sparam.CivBin,'file')
     2128            sparam.CivBin=fullfile(path_UVMAT,sparam.CivBin);
     2129        end
     2130    end
     2131    if isfield(sparam,'Civ1Bin')
     2132        if ~exist(sparam.Civ1Bin,'file')
     2133            sparam.Civ1Bin=fullfile(path_UVMAT,sparam.Civ1Bin);
     2134        end
     2135    end
     2136    if isfield(sparam,'Civ2Bin')
     2137        if ~exist(sparam.Civ2Bin,'file')
     2138            sparam.Civ2Bin=fullfile(path_UVMAT,sparam.Civ2Bin);
     2139        end
     2140    end
     2141    %test_interp=get(handles.test_interp,'Value');
     2142    test_interp=0;
     2143    if  isfield(sparam,'PatchBin')
     2144        if ~exist(sparam.PatchBin,'file')
     2145            sparam.PatchBin=fullfile(path_UVMAT,sparam.PatchBin);
     2146        end
     2147    end
     2148    % if test_interp && isfield(sparam,'PatchNewBin')
     2149    %     if ~exist(sparam.PatchNewBin,'file')
     2150    %          sparam.PatchNewBin=fullfile(path_UVMAT,sparam.PatchNewBin);
     2151    %     end
     2152    % end
     2153    if isfield(sparam,'FixBin')
     2154        %     fixBin=sparam.FixBin;
     2155        if ~exist(sparam.FixBin,'file')
     2156            sparam.FixBin=fullfile(path_UVMAT,sparam.FixBin);
     2157        end
     2158    end
     2159end
     2160
     2161
     2162
    21612163if batch
    21622164    if isfield(sparam,'BatchMode')
     
    21652167else
    21662168    MaxCivProcesses=50;
    2167    if isfield(sparam,'MaxCivProcesses')
     2169    if isfield(sparam,'MaxCivProcesses')
    21682170        MaxCivProcesses=str2double(sparam.MaxCivProcesses);
    2169    end
     2171    end
    21702172end
    21712173
     
    21832185%     cur_dir=pwd;
    21842186%     if ~isequal(cur_dir(2:3),':\')
    2185 %         cd(matlabroot); %move to the Matlab root directory if the current Matlab dir does not allow the dos command or is M: 
     2187%         cd(matlabroot); %move to the Matlab root directory if the current Matlab dir does not allow the dos command or is M:
    21862188%     end
    21872189%     [ss,ww]=dos(['net use ' filebase(1:2)]);
     
    22052207display('checking the files...')
    22062208[filecell,num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2,nom_type_nc,file_ref_fix1,file_ref_fix2]=...
    2207        set_civ_filenames(handles,compare,box_test);
     2209    set_civ_filenames(handles,compare,box_test);
    22082210if isempty(filecell)
    22092211    return
     
    22182220        str={'urgent';'normal';'low'};
    22192221        [ind_answer,v] = listdlg('PromptString',str_displ,...
    2220                 'SelectionMode','single',...
    2221                 'ListString',str,'ListSize',[200 200],'Name','job priority','InitialValue',3);
    2222         if isequal(v,0) % to handle Cancel button and figure close, 
    2223            return % a better way should be create
     2222            'SelectionMode','single',...
     2223            'ListString',str,'ListSize',[200 200],'Name','job priority','InitialValue',3);
     2224        if isequal(v,0) % to handle Cancel button and figure close,
     2225            return % a better way should be create
    22242226        end
    22252227    else
     
    22372239    end
    22382240end
    2239  
    2240 display('files OK, processing...') 
     2241
     2242display('files OK, processing...')
    22412243nbfield=numel(num1_civ1);
    22422244nbslice=numel(num_a_civ1);
    22432245
    22442246%GET PARAMETERS:
    2245   %get civ parameters
     2247%get civ parameters
    22462248if box_test(1)==1
    22472249    par_civ1=read_param_civ1(handles,filecell.ima1.civ1{1,1});
    2248 end 
     2250end
    22492251
    22502252%get fix1 parameters
    2251 if box_test(2)==1 
     2253if box_test(2)==1
    22522254    flagindex1(1)=get(handles.vec_Fmin2, 'Value');
    22532255    flagindex1(2)=get(handles.vec_F3, 'Value');
     
    22582260    nbslice_mask=get(handles.mask_fix1,'UserData'); % get the number of slices (= number of masks)
    22592261    %%%%%%%%%%%%%COMPLETER LE PROGRAMME FIX
    2260 %     inf_sup=get(handles.inf_sup1,'Value');80
    2261 %     fileref=get(handles.ref_fix1,'String');
    2262 %     refpath=get(handles.ref_fix1,'UserData');
    2263 %     fileref=fullfile(refpath,fileref);
     2262    %     inf_sup=get(handles.inf_sup1,'Value');80
     2263    %     fileref=get(handles.ref_fix1,'String');
     2264    %     refpath=get(handles.ref_fix1,'UserData');
     2265    %     fileref=fullfile(refpath,fileref);
    22642266    menu=get(handles.field_ref1,'String');
    22652267    index=get(handles.field_ref1,'Value');
     
    22682270    else
    22692271        fieldchoice=menu{index};
    2270          msgbox_uvmat('WARNING','reference field is not used presently with batch, use RUN option')
    2271     end   
    2272 end
    2273  
    2274  %get patch1 parameters
     2272        msgbox_uvmat('WARNING','reference field is not used presently with batch, use RUN option')
     2273    end
     2274end
     2275
     2276%get patch1 parameters
    22752277if box_test(3)==1
    2276         rho_patch1=str2num(get(handles.rho_patch1,'String'));
    2277         if isempty(rho_patch1)
    2278             rho_patch1='1000';
    2279             set(handles.rho_patch1,'String','1')
    2280         else
    2281             rho_patch1=num2str(1000*rho_patch1);
    2282         end
    2283         nx_patch1=get(handles.nx_patch1,'String');
    2284         ny_patch1=get(handles.ny_patch1,'String');
    2285         if isequal(str2num(nx_patch1),[])
    2286             nx_patch1='50' ;%default
    2287             set(handles.nx_patch1,'String','50');
    2288         end
    2289         if isequal(str2num(ny_patch1),[])
    2290             ny_patch1='50' ;%default
    2291             set(handles.ny_patch1,'String','50');
    2292         end
    2293         subdomain_patch1=get(handles.subdomain_patch1,'String');
    2294         thresh_patch1=get(handles.thresh_patch1,'String');
    2295  end
    2296  
    2297  %get civ2 parameters
     2278    rho_patch1=str2num(get(handles.rho_patch1,'String'));
     2279    if isempty(rho_patch1)
     2280        rho_patch1='1000';
     2281        set(handles.rho_patch1,'String','1')
     2282    else
     2283        rho_patch1=num2str(1000*rho_patch1);
     2284    end
     2285    nx_patch1=get(handles.nx_patch1,'String');
     2286    ny_patch1=get(handles.ny_patch1,'String');
     2287    if isequal(str2num(nx_patch1),[])
     2288        nx_patch1='50' ;%default
     2289        set(handles.nx_patch1,'String','50');
     2290    end
     2291    if isequal(str2num(ny_patch1),[])
     2292        ny_patch1='50' ;%default
     2293        set(handles.ny_patch1,'String','50');
     2294    end
     2295    subdomain_patch1=get(handles.subdomain_patch1,'String');
     2296    thresh_patch1=get(handles.thresh_patch1,'String');
     2297end
     2298
     2299%get civ2 parameters
    22982300if box_test(4)==1
    22992301    par_civ2=read_param_civ2(handles,cell2mat(filecell.ima1.civ2(1,1)));
     
    23012303
    23022304%get fix2 parameters
    2303 if box_test(5)==1 
     2305if box_test(5)==1
    23042306    flagindex2(1)=get(handles.vec_Fmin2_2, 'Value');
    23052307    flagindex2(2)=get(handles.vec_F3_2, 'Value');
     
    23092311    test_mask=get(handles.get_mask_fix2,'Value');
    23102312    nbslice_mask=get(handles.mask_fix2,'UserData'); % get the number of slices (= number of masks)
    2311         %%%%%%%%%%%%%COMPLETER LE PROGRAMME FIX AVEC REF FILE ET OPTION inf_sup=2
    2312 %     inf_sup=get(handles.inf_sup2,'Value');
    2313 %     ref=get(handles.ref_fix2,'UserData');
    2314 
     2313    %%%%%%%%%%%%%COMPLETER LE PROGRAMME FIX AVEC REF FILE ET OPTION inf_sup=2
     2314    %     inf_sup=get(handles.inf_sup2,'Value');
     2315    %     ref=get(handles.ref_fix2,'UserData');
     2316   
    23152317    %%%%%%%%%%%%%%%%%%%
    23162318end
     
    23392341    subdomain_patch2=get(handles.subdomain_patch2,'String');
    23402342    thresh_patch2=get(handles.thresh_patch2,'String');
    2341 %              test_interp=get(handles.test_interp,'Value');
     2343    %              test_interp=get(handles.test_interp,'Value');
    23422344end
    23432345
     
    23462348p1text=[];%initiate command text
    23472349time=get(handles.RootName,'UserData'); %get the set of times
    2348 civAll=get(handles.Experimental,'Value'); % Boolean for new civ excution method 
     2350civAll=get(handles.Experimental,'Value'); % Boolean for new civ excution method
    23492351for ifile=1:nbfield
    23502352    for j=1:nbslice
    2351         i_cmd=0; 
     2353        i_cmd=0;
    23522354        cmd='';
    23532355        if isunix % check: necessaire aussi en RUN?
    2354            %fid=fopen([filename '.cmx'],'w')
    2355            cmd='#!/bin/bash \n';
    2356            cmd=[cmd '#$ -cwd \n'];
    2357            cmd=[cmd 'hostname && date \n'];
     2356            %fid=fopen([filename '.cmx'],'w')
     2357            cmd='#!/bin/bash \n';
     2358            cmd=[cmd '#$ -cwd \n'];
     2359            cmd=[cmd 'hostname && date \n'];
    23582360        end
    23592361        if civAll
     
    23662368        filename_cmx=[filename_cmx 'x'];
    23672369       
    2368    %CIV1
     2370        %CIV1
    23692371        if box_test(1)==1
    23702372            par_civ1.filename_ima_a=filecell.ima1.civ1{ifile,j};
    2371             par_civ1.filename_ima_b=filecell.ima2.civ1{ifile,j};         
     2373            par_civ1.filename_ima_b=filecell.ima2.civ1{ifile,j};
    23722374            namelog=[filename_cmx([1:end-3]) 'log'];
    23732375            par_civ1.Dt=num2str(time(num2_civ1(ifile),num_b_civ1(j))-time(num1_civ1(ifile),num_a_civ1(j)));
    2374             par_civ1.T0=num2str((time(num2_civ1(ifile),num_b_civ1(j))+time(num1_civ1(ifile),num_a_civ1(j)))/2); 
     2376            par_civ1.T0=num2str((time(num2_civ1(ifile),num_b_civ1(j))+time(num1_civ1(ifile),num_a_civ1(j)))/2);
    23752377            par_civ1.term_a=num2stra(num_a_civ1(j),nom_type_nc);%UTILITE?
    2376             par_civ1.term_b=num2stra(num_b_civ1(j),nom_type_nc);% 
     2378            par_civ1.term_b=num2stra(num_b_civ1(j),nom_type_nc);%
    23772379            test_mask=get(handles.get_mask_civ1,'Value');
    2378             if test_mask==0 
     2380            if test_mask==0
    23792381                par_civ1.maskname='noFile use default';
    23802382                par_civ1.maskflag='n';
     
    23832385                if exist(maskdispl,'file')
    23842386                    par_civ1.maskname=maskdispl;
    2385                     par_civ1.maskflag='y';   
     2387                    par_civ1.maskflag='y';
    23862388                else
    2387                     maskbase=[filebase '_' maskdispl]; % 
    2388                     nbslice_mask=str2num(maskdispl(1:end-4)); % 
     2389                    maskbase=[filebase '_' maskdispl]; %
     2390                    nbslice_mask=str2num(maskdispl(1:end-4)); %
    23892391                    num1_mask=mod(num1_civ1(ifile)-1,nbslice_mask)+1;
    23902392                    par_civ1.maskname=name_generator(maskbase,num1_mask,1,'.png','_i');
     
    23932395                    else
    23942396                        par_civ1.maskname='noFile use default';
    2395                         par_civ1.maskflag='n'; 
     2397                        par_civ1.maskflag='n';
    23962398                    end
    23972399                end
     
    24082410                        par_civ1.gridname=[filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
    24092411                        if ~exist(par_civ1.gridname,'file')
    2410                            msgbox_uvmat('ERROR','grid file absent for civ1')
     2412                            msgbox_uvmat('ERROR','grid file absent for civ1')
    24112413                        end
    24122414                    elseif exist(gridname,'file')
    2413                         par_civ1.gridname=gridname; 
     2415                        par_civ1.gridname=gridname;
    24142416                    else
    24152417                        msgbox_uvmat('ERROR','grid file absent for civ1')
     
    24172419                end
    24182420            else
    2419                   par_civ1.gridname='noFile use default';
    2420                   par_civ1.gridflag='n';
    2421             end
    2422             %           
     2421                par_civ1.gridname='noFile use default';
     2422                par_civ1.gridflag='n';
     2423            end
     2424            %
    24232425            i_cmd=i_cmd+1;
    24242426            if isequal(civAll,0)
    24252427                cmd=[cmd CIV1_CMD(filename_cmx(1:end-4),namelog,par_civ1,handles,sparam) '\n'];
    24262428            else
    2427                  civAllCmd=[civAllCmd ' civ1 '];
    2428                  str=CIV1_CMD_Unified(filename_cmx([1:end-4]),namelog,par_civ1);
    2429                  fieldnames=fields(str);
     2429                civAllCmd=[civAllCmd ' civ1 '];
     2430                str=CIV1_CMD_Unified(filename_cmx([1:end-4]),namelog,par_civ1);
     2431                fieldnames=fields(str);
    24302432                [civAllxml,uid_civ1]=add(civAllxml,1,'element','civ1');
    24312433                for ilist=1:length(fieldnames)
    2432                   val=eval(['str.' fieldnames{ilist}]);
    2433                   if ischar(val)
    2434                     [civAllxml,uid_t]=add(civAllxml,uid_civ1,'element',fieldnames{ilist});
    2435                     [civAllxml,uid_t2]=add(civAllxml,uid_t,'chardata',val);
    2436                    end
    2437                 end   
     2434                    val=eval(['str.' fieldnames{ilist}]);
     2435                    if ischar(val)
     2436                        [civAllxml,uid_t]=add(civAllxml,uid_civ1,'element',fieldnames{ilist});
     2437                        [civAllxml,uid_t2]=add(civAllxml,uid_t,'chardata',val);
     2438                    end
     2439                end
    24382440            end
    24392441        end
    24402442       
    2441    % FIX1
    2442        if box_test(2)==1
    2443            test_mask=get(handles.get_mask_fix1,'Value');
    2444            if test_mask==0
     2443        % FIX1
     2444        if box_test(2)==1
     2445            test_mask=get(handles.get_mask_fix1,'Value');
     2446            if test_mask==0
    24452447                maskname='';
    2446            else
     2448            else
    24472449                maskdispl=get(handles.mask_fix1,'String');
    2448                 nbslice_mask=str2num(maskdispl(1:end-4)); % 
     2450                nbslice_mask=str2num(maskdispl(1:end-4)); %
    24492451                num1_mask=mod(num1_civ1(ifile)-1,nbslice_mask)+1;
    24502452                maskbase=[filebase '_' maskdispl];
    24512453                maskname=name_generator(maskbase,num1_mask,1,'.png','_i');
    2452            end
    2453            if isequal(civAll,0)
     2454            end
     2455            if isequal(civAll,0)
    24542456                cmd_FIX=[sparam.FixBin ' -f ' filecell.nc.civ1{ifile,j} ' -fi1 ' num2str(flagindex1(1)) ...
    2455                    ' -fi2 ' num2str(flagindex1(2)) ' -fi3 ' num2str(flagindex1(3)) ...
    2456                    ' -threshC ' num2str(thresh_vecC1) ' -threshV ' num2str(thresh_vel1) ' -maskName ' maskname];
     2457                    ' -fi2 ' num2str(flagindex1(2)) ' -fi3 ' num2str(flagindex1(3)) ...
     2458                    ' -threshC ' num2str(thresh_vecC1) ' -threshV ' num2str(thresh_vel1) ' -maskName ' maskname];
    24572459                cmd_FIX=regexprep(cmd_FIX,'\\','\\\\');
    24582460                cmd=[cmd cmd_FIX '\n'];
    2459            else
     2461            else
    24602462                fix1.inputFileName=filecell.nc.civ1{ifile,j} ;
    24612463                fix1.fi1=num2str(flagindex1(1));
     
    24632465                fix1.fi3=num2str(flagindex1(3));
    24642466                fix1.threshC=num2str(thresh_vecC1);
    2465                 fix1.threshV=num2str(thresh_vel1);                 
     2467                fix1.threshV=num2str(thresh_vel1);
    24662468                fieldnames=fields(fix1);
    24672469                [civAllxml,uid_fix1]=add(civAllxml,1,'element','fix1');
    24682470                for ilist=1:length(fieldnames)
    2469                   val=eval(['fix1.' fieldnames{ilist}]);
    2470                   if ischar(val)
    2471                     [civAllxml,uid_t]=add(civAllxml,uid_fix1,'element',fieldnames{ilist});
    2472                     [civAllxml,uid_t2]=add(civAllxml,uid_t,'chardata',val);
    2473                    end
    2474                 end
    2475              civAllCmd=[civAllCmd ' fix1 '];           
    2476            end         
    2477        end
    2478    
    2479     %PATCH1
    2480     if box_test(3)==1
    2481         if isequal(civAll,0)
    2482             cmd_PATCH=PATCH_CMD(filecell.nc.civ1{ifile,j},nx_patch1,ny_patch1,rho_patch1,subdomain_patch1,thresh_patch1,test_interp,sparam.PatchBin);
    2483             cmd_PATCH=regexprep(cmd_PATCH,'\\','\\\\');
    2484             cmd=[cmd cmd_PATCH '\n'];
    2485         else
    2486             patch1.inputFileName=filecell.nc.civ1{ifile,j} ;
    2487             patch1.nopt=subdomain_patch1;
    2488             patch1.maxdiff=thresh_patch1;
    2489             patch1.ro=rho_patch1;
    2490             test_grid=get(handles.get_gridpatch1,'Value');
    2491             if test_grid
    2492                  patch1.gridflag='y';
    2493                 gridname=get(handles.grid_patch1,'String');
    2494                 if isequal(gridname(end-3:end),'grid')
    2495                     nbslice_grid=str2num(gridname(1:end-4)); %
    2496                     if ~isempty(nbslice_grid)
    2497                         num1_grid=mod(num1_civ1(ifile)-1,nbslice_grid)+1;
    2498                         patch1.gridPatch=[filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
    2499                         if ~exist(patch1.gridPatch,'file')
    2500                            msgbox_uvmat('ERROR','grid file absent for patch1')
    2501                         end
    2502                     elseif exist(gridname,'file')
    2503                         patch1.gridPatch=gridname;
    2504                     else
    2505                         msgbox_uvmat('ERROR','grid file absent for patch1')
     2471                    val=eval(['fix1.' fieldnames{ilist}]);
     2472                    if ischar(val)
     2473                        [civAllxml,uid_t]=add(civAllxml,uid_fix1,'element',fieldnames{ilist});
     2474                        [civAllxml,uid_t2]=add(civAllxml,uid_t,'chardata',val);
    25062475                    end
    25072476                end
     2477                civAllCmd=[civAllCmd ' fix1 '];
     2478            end
     2479        end
     2480       
     2481        %PATCH1
     2482        if box_test(3)==1
     2483            if isequal(civAll,0)
     2484                cmd_PATCH=PATCH_CMD(filecell.nc.civ1{ifile,j},nx_patch1,ny_patch1,rho_patch1,subdomain_patch1,thresh_patch1,test_interp,sparam.PatchBin);
     2485                cmd_PATCH=regexprep(cmd_PATCH,'\\','\\\\');
     2486                cmd=[cmd cmd_PATCH '\n'];
    25082487            else
    2509                    patch1.gridPatch='none';
    2510                    patch1.gridflag='n';
    2511                   patch1.m=nx_patch1;
    2512                   patch1.n=ny_patch1;
    2513             end
    2514             patch1.convectFlow='n';
    2515                fieldnames=fields(patch1);
     2488                patch1.inputFileName=filecell.nc.civ1{ifile,j} ;
     2489                patch1.nopt=subdomain_patch1;
     2490                patch1.maxdiff=thresh_patch1;
     2491                patch1.ro=rho_patch1;
     2492                test_grid=get(handles.get_gridpatch1,'Value');
     2493                if test_grid
     2494                    patch1.gridflag='y';
     2495                    gridname=get(handles.grid_patch1,'String');
     2496                    if isequal(gridname(end-3:end),'grid')
     2497                        nbslice_grid=str2num(gridname(1:end-4)); %
     2498                        if ~isempty(nbslice_grid)
     2499                            num1_grid=mod(num1_civ1(ifile)-1,nbslice_grid)+1;
     2500                            patch1.gridPatch=[filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
     2501                            if ~exist(patch1.gridPatch,'file')
     2502                                msgbox_uvmat('ERROR','grid file absent for patch1')
     2503                            end
     2504                        elseif exist(gridname,'file')
     2505                            patch1.gridPatch=gridname;
     2506                        else
     2507                            msgbox_uvmat('ERROR','grid file absent for patch1')
     2508                        end
     2509                    end
     2510                else
     2511                    patch1.gridPatch='none';
     2512                    patch1.gridflag='n';
     2513                    patch1.m=nx_patch1;
     2514                    patch1.n=ny_patch1;
     2515                end
     2516                patch1.convectFlow='n';
     2517                fieldnames=fields(patch1);
    25162518                [civAllxml,uid_patch1]=add(civAllxml,1,'element','patch1');
    25172519                for ilist=1:length(fieldnames)
    2518                   val=eval(['patch1.' fieldnames{ilist}]);
    2519                   if ischar(val)
    2520                     [civAllxml,uid_t]=add(civAllxml,uid_patch1,'element',fieldnames{ilist});
    2521                     [civAllxml,uid_t2]=add(civAllxml,uid_t,'chardata',val);
    2522                    end
    2523                 end             
    2524             civAllCmd=[civAllCmd ' patch1 '];
    2525         end
    2526     end
    2527    
    2528     if box_test(4)==1 | box_test(5)==1 | box_test(6)==1
    2529         filename_cmx=filecell.nc.civ2{ifile,j};%output netcdf file
    2530         filename_cmx([end-1:end])=[ 'cm'];%name of cmx file
    2531         filename_cmx=[filename_cmx 'x'];
    2532     end
    2533    
    2534     if box_test(4)==1
     2520                    val=eval(['patch1.' fieldnames{ilist}]);
     2521                    if ischar(val)
     2522                        [civAllxml,uid_t]=add(civAllxml,uid_patch1,'element',fieldnames{ilist});
     2523                        [civAllxml,uid_t2]=add(civAllxml,uid_t,'chardata',val);
     2524                    end
     2525                end
     2526                civAllCmd=[civAllCmd ' patch1 '];
     2527            end
     2528        end
     2529       
     2530        if box_test(4)==1 | box_test(5)==1 | box_test(6)==1
     2531            filename_cmx=filecell.nc.civ2{ifile,j};%output netcdf file
     2532            filename_cmx([end-1:end])=[ 'cm'];%name of cmx file
     2533            filename_cmx=[filename_cmx 'x'];
     2534        end
     2535       
     2536        if box_test(4)==1
    25352537            par_civ2.filename_ima_a=filecell.ima1.civ2{ifile,j};
    25362538            %par_civ2.filename_ima_a([end-3:end])=[];%remove .png extension
     
    25392541            namelog=[filename_cmx([1:end-3]) 'log'];
    25402542            par_civ2.Dt=num2str(time(num2_civ2(ifile),num_b_civ2(j))-time(num1_civ2(ifile),num_a_civ2(j)));
    2541             par_civ2.T0=num2str((time(num2_civ1(ifile),num_b_civ2(j))+time(num1_civ2(ifile),num_a_civ2(j)))/2); 
     2543            par_civ2.T0=num2str((time(num2_civ1(ifile),num_b_civ2(j))+time(num1_civ2(ifile),num_a_civ2(j)))/2);
    25422544            par_civ2.term_a=num2stra(num_a_civ2(j),nom_type_nc);
    2543             par_civ2.term_b=num2stra(num_b_civ2(j),nom_type_nc);         
     2545            par_civ2.term_b=num2stra(num_b_civ2(j),nom_type_nc);
    25442546            par_civ2.filename_nc1=filecell.nc.civ1{ifile,j};
    25452547            par_civ2.filename_nc1([end-2:end])=[]; % remove '.nc'
    25462548            test_mask=get(handles.get_mask_civ2,'Value');
    2547             if test_mask==0 
     2549            if test_mask==0
    25482550                par_civ2.maskname='noFile use default';
    25492551                par_civ2.maskflag='n';
     
    25542556                    par_civ2.maskflag='y';
    25552557                else
    2556                     maskbase=[filebase '_' maskdispl]; % 
    2557                     nbslice_mask=str2num(maskdispl(1:end-4)); % 
     2558                    maskbase=[filebase '_' maskdispl]; %
     2559                    nbslice_mask=str2num(maskdispl(1:end-4)); %
    25582560                    num1_mask=mod(num1_civ2(ifile)-1,nbslice_mask)+1;
    25592561                    par_civ2.maskname=name_generator(maskbase,num1_mask,1,'.png','_i');
    25602562                    if exist(par_civ2.maskname,'file')
    2561                         par_civ2.maskflag='y'; 
     2563                        par_civ2.maskflag='y';
    25622564                    else
    25632565                        par_civ2.maskname='noFile use default';
    2564                         par_civ2.maskflag='n'; 
     2566                        par_civ2.maskflag='n';
    25652567                    end
    25662568                end
     
    25772579                    par_civ2.gridname=[filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
    25782580                    if exist(par_civ2.gridname,'file')
    2579                         par_civ2.gridflag='y'; 
     2581                        par_civ2.gridflag='y';
    25802582                    else
    25812583                        par_civ2.gridname='noFile use default';
    2582                         par_civ2.gridflag='n'; 
     2584                        par_civ2.gridflag='n';
    25832585                    end
    25842586                elseif exist(gridname,'file')
    2585                     par_civ2.gridflag='y'; 
     2587                    par_civ2.gridflag='y';
    25862588                else
    25872589                    par_civ2.gridname='noFile use default';
    2588                     par_civ2.gridflag='n'; 
     2590                    par_civ2.gridflag='n';
    25892591                end
    25902592            end
     
    26002602                end
    26012603            else
    2602                  civAllCmd=[civAllCmd ' civ2 '];
    2603                  str=CIV2_CMD_Unified(filename_cmx([1:end-4]),namelog,par_civ2);
    2604                  fieldnames=fields(str);
     2604                civAllCmd=[civAllCmd ' civ2 '];
     2605                str=CIV2_CMD_Unified(filename_cmx([1:end-4]),namelog,par_civ2);
     2606                fieldnames=fields(str);
    26052607                [civAllxml,uid_civ2]=add(civAllxml,1,'element','civ2');
    26062608                for ilist=1:length(fieldnames)
    26072609                    val=eval(['str.' fieldnames{ilist}]);
    26082610                    if ischar(val)
    2609                        [civAllxml,uid_t]=add(civAllxml,uid_civ2,'element',fieldnames{ilist});
    2610                        [civAllxml,uid_t2]=add(civAllxml,uid_t,'chardata',val);
     2611                        [civAllxml,uid_t]=add(civAllxml,uid_civ2,'element',fieldnames{ilist});
     2612                        [civAllxml,uid_t2]=add(civAllxml,uid_t,'chardata',val);
    26112613                    end
    2612                 end   
    2613             end
    2614      end
    2615      
    2616      % FIX2
    2617      if box_test(5)==1
    2618            test_mask=get(handles.get_mask_fix2,'Value');   
    2619             if test_mask==0 
    2620                 maskname=''; %no mask used 
     2614                end
     2615            end
     2616        end
     2617        
     2618        % FIX2
     2619        if box_test(5)==1
     2620            test_mask=get(handles.get_mask_fix2,'Value');
     2621            if test_mask==0
     2622                maskname=''; %no mask used
    26212623            else
    26222624                maskdispl=get(handles.mask_fix2,'String');
    2623                 maskbase=[filebase '_' maskdispl]; % 
    2624                 nbslice_mask=str2num(maskdispl(1:end-4)); % 
     2625                maskbase=[filebase '_' maskdispl]; %
     2626                nbslice_mask=str2num(maskdispl(1:end-4)); %
    26252627                num1_mask=mod(num1_civ2(ifile)-1,nbslice_mask)+1;
    26262628                maskname =name_generator(maskbase,num1_mask,1,'.png','_i');
    2627             end                 
    2628            if isequal(civAll,0)
     2629            end
     2630            if isequal(civAll,0)
    26292631                cmd_FIX=[sparam.FixBin ' -f ' filecell.nc.civ2{ifile,j} ' -fi1 ' num2str(flagindex2(1)) ...
    2630                    ' -fi2 ' num2str(flagindex2(2)) ' -fi3 ' num2str(flagindex2(3)) ...
    2631                    ' -threshC ' num2str(thresh_vec2C) ' -threshV ' num2str(thresh_vel2) ' -maskName ' maskname];
    2632                cmd_FIX=regexprep(cmd_FIX,'\\','\\\\');
    2633                cmd=[cmd cmd_FIX '\n'];
    2634            else                     
     2632                    ' -fi2 ' num2str(flagindex2(2)) ' -fi3 ' num2str(flagindex2(3)) ...
     2633                    ' -threshC ' num2str(thresh_vec2C) ' -threshV ' num2str(thresh_vel2) ' -maskName ' maskname];
     2634                cmd_FIX=regexprep(cmd_FIX,'\\','\\\\');
     2635                cmd=[cmd cmd_FIX '\n'];
     2636            else
    26352637                fix2.inputFileName=filecell.nc.civ2{ifile,j} ;
    26362638                fix2.fi1=num2str(flagindex2(1));
     
    26382640                fix2.fi3=num2str(flagindex2(3));
    26392641                fix2.threshC=num2str(thresh_vec2C);
    2640                 fix2.threshV=num2str(thresh_vel2);                 
     2642                fix2.threshV=num2str(thresh_vel2);
    26412643                fieldnames=fields(fix2);
    26422644                [civAllxml,uid_fix2]=add(civAllxml,1,'element','fix2');
    26432645                for ilist=1:length(fieldnames)
    2644                   val=eval(['fix2.' fieldnames{ilist}]);
    2645                   if ischar(val)
    2646                     [civAllxml,uid_t]=add(civAllxml,uid_fix2,'element',fieldnames{ilist});
    2647                     [civAllxml,uid_t2]=add(civAllxml,uid_t,'chardata',val);
    2648                    end
    2649                 end 
    2650                 civAllCmd=[civAllCmd ' fix2 '];           
    2651            end
    2652        end
    2653        
    2654      %PATCH2
    2655        if box_test(6)==1
     2646                    val=eval(['fix2.' fieldnames{ilist}]);
     2647                    if ischar(val)
     2648                        [civAllxml,uid_t]=add(civAllxml,uid_fix2,'element',fieldnames{ilist});
     2649                        [civAllxml,uid_t2]=add(civAllxml,uid_t,'chardata',val);
     2650                    end
     2651                end
     2652                civAllCmd=[civAllCmd ' fix2 '];
     2653            end
     2654        end
     2655        
     2656        %PATCH2
     2657        if box_test(6)==1
    26562658            if isequal(civAll,0)
    26572659                cmd_PATCH=PATCH_CMD(filecell.nc.civ2{ifile,j},nx_patch2,ny_patch2,rho_patch2,subdomain_patch2,thresh_patch2,test_interp,sparam.PatchBin);
     
    26732675                            patch2.gridPatch=[filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
    26742676                            if ~exist(patch2.gridPatch,'file')
    2675                                msgbox_uvmat('ERROR','grid file absent for patch2')
     2677                                msgbox_uvmat('ERROR','grid file absent for patch2')
    26762678                            end
    26772679                        elseif exist(gridname,'file')
    2678                             patch2.gridPatch=gridname; 
     2680                            patch2.gridPatch=gridname;
    26792681                        else
    26802682                            msgbox_uvmat('ERROR','grid file absent for patch2')
     
    26822684                    end
    26832685                else
    2684                       patch2.gridPatch='none';
    2685                       patch2.gridflag='n';
    2686                       patch2.m=nx_patch2;
    2687                       patch2.n=ny_patch2;
     2686                    patch2.gridPatch='none';
     2687                    patch2.gridflag='n';
     2688                    patch2.m=nx_patch2;
     2689                    patch2.n=ny_patch2;
    26882690                end
    26892691                patch2.convectFlow='n';
     
    26912693                [civAllxml,uid_patch2]=add(civAllxml,1,'element','patch2');
    26922694                for ilist=1:length(fieldnames)
    2693                    val=eval(['patch2.' fieldnames{ilist}]);
    2694                    if ischar(val)
    2695                       [civAllxml,uid_t]=add(civAllxml,uid_patch2,'element',fieldnames{ilist});
    2696                       [civAllxml,uid_t2]=add(civAllxml,uid_t,'chardata',val);
    2697                    end
    2698                 end             
     2695                    val=eval(['patch2.' fieldnames{ilist}]);
     2696                    if ischar(val)
     2697                        [civAllxml,uid_t]=add(civAllxml,uid_patch2,'element',fieldnames{ilist});
     2698                        [civAllxml,uid_t2]=add(civAllxml,uid_t,'chardata',val);
     2699                    end
     2700                end
    26992701                civAllCmd=[civAllCmd ' patch2 '];
    2700             end     
     2702            end
    27012703        end
    27022704        if isequal(civAll,1)
     
    27052707            cmd=[cmd CivBin ' -f ' filename_cmx(1:end-4) '.xml '  civAllCmd  '\n'];
    27062708        end
    2707       % create the .bat file:
     2709        % create the .bat file:
    27082710        if batch
    2709                 [Rootbat,Filebat,extbat]=fileparts(filename_cmx);
    2710                 filename_bat=fullfile(Rootbat,['job_' Filebat extbat]);
     2711            [Rootbat,Filebat,extbat]=fileparts(filename_cmx);
     2712            filename_bat=fullfile(Rootbat,['job_' Filebat extbat]);
    27112713        else
    27122714            filename_bat=filename_cmx;
     
    27262728            end
    27272729        else
    2728 %% to lauch the jobs locally :
     2730            %% to lauch the jobs locally :
    27292731            if(isunix)
    2730               eval(['!. ' filename_bat ' &']);
    2731               display(['!. ' filename_bat ' &'])
     2732                eval(['!. ' filename_bat ' &']);
     2733                display(['!. ' filename_bat ' &'])
    27322734            else
    2733               eval(['!' filename_bat ' &']);
    2734               display(['!' filename_bat ' &'])
    2735             end
    2736         end
    2737      end
     2735                eval(['!' filename_bat ' &']);
     2736                display(['!' filename_bat ' &'])
     2737            end
     2738        end
     2739    end
    27382740end
    27392741% set(handles.BATCH, 'Enable','On')
     
    27502752[RootPath,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fileresu);
    27512753namedoc=fullfile(RootPath,subdir,RootFile);
    2752 detect=1; 
     2754detect=1;
    27532755while detect==1
    27542756    namefigfull=[namedoc '.fig'];
     
    27772779% num1_civ2(i),num2_civ2(i): lists of first and last i indices for civ2
    27782780% num_a_civ2(j),num_b_civ2(j): lists of first and last j indices for civ2
    2779 % nom_type_nc: nomenclature type for velocity files 
     2781% nom_type_nc: nomenclature type for velocity files
    27802782% file_ref_fix1,file_ref_fix2: reference files possibly used by Fix1 and 2
    27812783function [filecell,num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2,nom_type_nc,file_ref_fix1,file_ref_fix2]=...
     
    28072809filebase_B=filebase;% root name of the second field series for stereo
    28082810if strcmp(compare,'displacement') || strcmp(compare,'stereo PIV')
    2809     test_disp=1;   
     2811    test_disp=1;
    28102812    nom_type_ima1=browse.nom_type_ima_1; %nomenclature type of the second file series
    28112813    [Path2,Name2]=fileparts(filebase_B);
     
    28272829end
    28282830if strcmp(compare,'displacement')
    2829         filebase_ima1=filebase_A;
    2830         filebase_ima2=filebase_B;
    2831         filebase_nc=filebase_AB; %root name for the result of civ2 
    2832 else
    2833         filebase_ima1=filebase_B;
    2834         filebase_ima2=filebase_B;
    2835         filebase_nc=filebase_B;
    2836 end   
     2831    filebase_ima1=filebase_A;
     2832    filebase_ima2=filebase_B;
     2833    filebase_nc=filebase_AB; %root name for the result of civ2
     2834else
     2835    filebase_ima1=filebase_B;
     2836    filebase_ima2=filebase_B;
     2837    filebase_nc=filebase_B;
     2838end
    28372839
    28382840%determine reference files for fix:
     
    29622964[erread,message]=fileattrib(Path_ima);
    29632965if ~isempty(message) & ~isequal(message.UserWrite,1)
    2964       msgbox_uvmat('ERROR',['No writting access to ' Path_ima])
    2965       filecell=[];
    2966       cd(currentdir);
    2967       return
     2966    msgbox_uvmat('ERROR',['No writting access to ' Path_ima])
     2967    filecell=[];
     2968    cd(currentdir);
     2969    return
    29682970end
    29692971
     
    29712973% %%%%%%%%%%%%  case CIV1 activated   %%%%%%%%%%%%%
    29722974if box_test(1)==1;
    2973      detect=1;     
    2974      while detect==1 %create a new subdir if the netcdf files already exist
    2975           for ifile=1:nbfield;
    2976               for j=1:nbslice
    2977                   filename=name_generator(filebase_nc,num1_civ1(ifile),num_a_civ1(j),'.nc',nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1);
    2978                   detect=exist(filename,'file')==2;
    2979                   if detect% if a netcdf file already exists
    2980                      subdir_civ1=[subdir_civ1 '.0'];
    2981                      subdir_civ2=subdir_civ1;
    2982                      break
    2983                   end
    2984                   filecell.nc.civ1(ifile,j)={filename};
    2985               end
    2986               if detect% if a netcdf file already exists
    2987                   break
    2988               end
    2989           end
    2990            %create the new subdir_civ1
    2991           if ~exist(fullfile(Path_ima,subdir_civ1),'dir')
    2992               [m1,m2,m3]=mkdir(subdir_civ1);
     2975    detect=1;
     2976    while detect==1 %create a new subdir if the netcdf files already exist
     2977        for ifile=1:nbfield;
     2978            for j=1:nbslice
     2979                filename=name_generator(filebase_nc,num1_civ1(ifile),num_a_civ1(j),'.nc',nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1);
     2980                detect=exist(filename,'file')==2;
     2981                if detect% if a netcdf file already exists
     2982                    subdir_civ1=[subdir_civ1 '.0'];
     2983                    subdir_civ2=subdir_civ1;
     2984                    break
     2985                end
     2986                filecell.nc.civ1(ifile,j)={filename};
     2987            end
     2988            if detect% if a netcdf file already exists
     2989                break
     2990            end
     2991        end
     2992        %create the new subdir_civ1
     2993        if ~exist(fullfile(Path_ima,subdir_civ1),'dir')
     2994            [m1,m2,m3]=mkdir(subdir_civ1);
     2995            if ~isequal(m2,'')
     2996                msgbox_uvmat('ERROR', m2)
     2997                %msgbox(m2);%error message for directory creation
     2998            end
     2999        end
     3000        if strcmp(compare,'stereo PIV')&&(strcmp(mode,'pair j1-j2')||strcmp(mode,'series(Dj)')||strcmp(mode,'series(Di)'))%check second nc series
     3001            for ifile=1:nbfield
     3002                for j=1:nbslice
     3003                    filename=name_generator(filebase_A,num1_civ1(ifile),num_a_civ1(j),'.nc',nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1);%
     3004                    detect=exist(filename,'file')==2;
     3005                    if detect% if a netcdf file already exists
     3006                        subdir_civ1=[subdir_civ1 '.0'];
     3007                        subdir_civ2=subdir_civ1;
     3008                        break
     3009                    end
     3010                    filecell.ncA.civ1(ifile,j)={filename};
     3011                end
     3012                if detect% if a netcdf file already exists
     3013                    break
     3014                end
     3015            end
     3016            %create the new subdir_civ1
     3017            if ~exist(fullfile(Path_ima,subdir_civ1),'dir')
     3018                [m1,m2,m3]=mkdir(subdir_civ1);
    29933019                if ~isequal(m2,'')
    2994                    msgbox_uvmat('ERROR', m2)
    2995                    %msgbox(m2);%error message for directory creation
    2996               end
    2997           end
    2998           if strcmp(compare,'stereo PIV')&&(strcmp(mode,'pair j1-j2')||strcmp(mode,'series(Dj)')||strcmp(mode,'series(Di)'))%check second nc series
    2999                 for ifile=1:nbfield
    3000                      for j=1:nbslice
    3001                          filename=name_generator(filebase_A,num1_civ1(ifile),num_a_civ1(j),'.nc',nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1);%
    3002                           detect=exist(filename,'file')==2;
    3003                           if detect% if a netcdf file already exists
    3004                               subdir_civ1=[subdir_civ1 '.0'];
    3005                               subdir_civ2=subdir_civ1;
    3006                               break
    3007                           end
    3008                           filecell.ncA.civ1(ifile,j)={filename};
    3009                      end
    3010                     if detect% if a netcdf file already exists
    3011                          break
    3012                     end
    3013               end
    3014            %create the new subdir_civ1
    3015                if ~exist(fullfile(Path_ima,subdir_civ1),'dir')
    3016                       [m1,m2,m3]=mkdir(subdir_civ1);
    3017                        if ~isequal(m2,'')
    3018                             msgbox_uvmat('ERROR', m2)
    3019                       end
    3020                end
    3021           end
    3022      end       
     3020                    msgbox_uvmat('ERROR', m2)
     3021                end
     3022            end
     3023        end
     3024    end
    30233025    % get image names
    30243026    for ifile=1:nbfield
    3025          for j=1:nbslice
     3027        for j=1:nbslice
    30263028            filename=name_generator(filebase_ima1, num1_civ1(ifile),num_a_civ1(j),ext_ima,nom_type_ima1);
    30273029            idetect(j)=exist(filename,'file')==2;
     
    30303032            idetect_1(j)=exist(filename,'file')==2;
    30313033            filecell.ima2.civ1(ifile,j)={filename};%second image
    3032          end
     3034        end
     3035        [idetectmin,indexj]=min(idetect);
     3036        if idetectmin==0,
     3037            msgbox_uvmat('ERROR',[filecell.ima1.civ1{ifile,indexj} ' not found'])
     3038            filecell=[];
     3039            return
     3040        end
     3041        [idetectmin,indexj]=min(idetect_1);
     3042        if idetectmin==0,
     3043            msgbox_uvmat('ERROR',[filecell.ima2.civ1{ifile,indexj} ' not found'])
     3044            filecell=[];
     3045            cd(currentdir)
     3046            return
     3047        end
     3048    end
     3049    if strcmp(compare,'stereo PIV') && (strcmp(mode,'pair j1-j2') || strcmp(mode,'series(Dj)') || strcmp(mode,'series(Di)'))
     3050        for ifile=1:nbfield
     3051            for j=1:nbslice
     3052                filename=name_generator(filebase_A, num1_civ1(ifile),num_a_civ1(j),ext_ima,nom_type_ima1);
     3053                idetect(j)=exist(filename,'file')==2;
     3054                filecell.imaA1.civ1(ifile,j)={filename} ;%first image
     3055                filename=name_generator(filebase_A, num2_civ1(ifile),num_b_civ1(j),ext_ima,nom_type_ima2);
     3056                idetect_1(j)=exist(filename,'file')==2;
     3057                filecell.imaA2.civ1(ifile,j)={filename};%second image
     3058            end
    30333059            [idetectmin,indexj]=min(idetect);
    3034           if idetectmin==0,
    3035                 msgbox_uvmat('ERROR',[filecell.ima1.civ1{ifile,indexj} ' not found'])
    3036                 filecell=[];
    3037                 return
    3038           end
    3039             [idetectmin,indexj]=min(idetect_1);
    3040           if idetectmin==0,
    3041                 msgbox_uvmat('ERROR',[filecell.ima2.civ1{ifile,indexj} ' not found'])
     3060            if idetectmin==0,
     3061                msgbox_uvmat('ERROR',[filecell.imaA1.civ1{ifile,indexj} ' not found'])
    30423062                filecell=[];
    30433063                cd(currentdir)
    30443064                return
    3045           end
    3046     end
    3047     if strcmp(compare,'stereo PIV') && (strcmp(mode,'pair j1-j2') || strcmp(mode,'series(Dj)') || strcmp(mode,'series(Di)'))
    3048          for ifile=1:nbfield
    3049              for j=1:nbslice
    3050                   filename=name_generator(filebase_A, num1_civ1(ifile),num_a_civ1(j),ext_ima,nom_type_ima1);
    3051                   idetect(j)=exist(filename,'file')==2;
    3052                   filecell.imaA1.civ1(ifile,j)={filename} ;%first image
    3053                   filename=name_generator(filebase_A, num2_civ1(ifile),num_b_civ1(j),ext_ima,nom_type_ima2);
    3054                   idetect_1(j)=exist(filename,'file')==2;
    3055                   filecell.imaA2.civ1(ifile,j)={filename};%second image
    3056              end
    3057               [idetectmin,indexj]=min(idetect);
    3058               if idetectmin==0,
    3059                     msgbox_uvmat('ERROR',[filecell.imaA1.civ1{ifile,indexj} ' not found'])
     3065            end
     3066            [idetectmin,indexj]=min(idetect_1);
     3067            if idetectmin==0,
     3068                msgbox_uvmat('ERROR',[filecell.imaA2.civ1{ifile,indexj} ' not found'])
     3069                filecell=[];
     3070                cd(currentdir)
     3071                return
     3072            end
     3073        end
     3074    end
     3075   
     3076    %%%%%%%%%%%%%  fix1 or patch1 activated but no civ1   %%%%%%%%%%%%%
     3077elseif (box_test(2)==1 || box_test(3)==1);
     3078    for ifile=1:nbfield
     3079        for j=1:nbslice
     3080            filename=name_generator(filebase_nc,num1_civ1(ifile),num_a_civ1(j),'.nc',...
     3081                nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1);%
     3082            detect=exist(filename,'file')==2;
     3083            filecell.nc.civ1(ifile,j)={filename};
     3084        end
     3085    end
     3086    if strcmp(compare,'stereo PIV')
     3087        for ifile=1:nbfield
     3088            for j=1:nbslice
     3089                filename=name_generator(filebase_A,num1_civ1(ifile),num_a_civ1(j),'.nc',nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1);%
     3090                filecell.ncA.civ1(ifile,j)={filename};
     3091                if ~exist(filename,'file')
     3092                    msgbox_uvmat('ERROR',['input file ' filename ' not found'])
     3093                    set(handles.RUN, 'Enable','On')
     3094                    set(handles.RUN,'BackgroundColor',[1 0 0])
     3095                    %                         set(handles.BATCH, 'Enable','On')
     3096                    %                         set(handles.BATCH,'BackgroundColor',[1 0 0])
    30603097                    filecell=[];
    30613098                    cd(currentdir)
    30623099                    return
    3063               end
    3064                [idetectmin,indexj]=min(idetect_1);
    3065                if idetectmin==0,
    3066                    msgbox_uvmat('ERROR',[filecell.imaA2.civ1{ifile,indexj} ' not found'])
    3067                   filecell=[];
    3068                   cd(currentdir)
    3069                   return
    3070                end
    3071          end
    3072     end
    3073        
    3074  %%%%%%%%%%%%%  fix1 or patch1 activated but no civ1   %%%%%%%%%%%%%
    3075 elseif (box_test(2)==1 || box_test(3)==1); 
    3076     for ifile=1:nbfield
    3077         for j=1:nbslice
    3078             filename=name_generator(filebase_nc,num1_civ1(ifile),num_a_civ1(j),'.nc',...
    3079                     nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1);%
    3080             detect=exist(filename,'file')==2;   
    3081             filecell.nc.civ1(ifile,j)={filename};
    3082         end
    3083     end
    3084     if strcmp(compare,'stereo PIV')
    3085             for ifile=1:nbfield
    3086                 for j=1:nbslice
    3087                     filename=name_generator(filebase_A,num1_civ1(ifile),num_a_civ1(j),'.nc',nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1);%
    3088                     filecell.ncA.civ1(ifile,j)={filename};
    3089                     if ~exist(filename,'file')
    3090                         msgbox_uvmat('ERROR',['input file ' filename ' not found'])
    3091                         set(handles.RUN, 'Enable','On')
    3092                         set(handles.RUN,'BackgroundColor',[1 0 0])
    3093 %                         set(handles.BATCH, 'Enable','On')
    3094 %                         set(handles.BATCH,'BackgroundColor',[1 0 0])
    3095                         filecell=[];
    3096                         cd(currentdir)
    3097                         return
    3098                     end
    30993100                end
    31003101            end
     3102        end
    31013103    end
    31023104end
     
    31053107testdiff=0;
    31063108if (box_test(4)==1)&&...
    3107         ((get(handles.list_pair_civ1,'Value')~=get(handles.list_pair_civ2,'Value'))||~isequal(subdir_civ2,subdir_civ1)) 
     3109        ((get(handles.list_pair_civ1,'Value')~=get(handles.list_pair_civ2,'Value'))||~isequal(subdir_civ2,subdir_civ1))
    31083110    testdiff=1;
    3109     detect=1; 
     3111    detect=1;
    31103112    while detect==1 %create a new subdir if the netcdf files already exist
    3111           for ifile=1:nbfield
    3112               for j=1:nbslice
    3113                   filename=name_generator(filebase_nc,num1_civ2(ifile),num_a_civ2(j),'.nc',nom_type_nc,1,num2_civ2(ifile),num_b_civ2(j),subdir_civ2);%
    3114                   detect=exist(filename,'file')==2;
    3115                   if detect% if a netcdf file already exists
    3116                      subdir_civ2=[subdir_civ2 '.0'];
    3117                      break
    3118                   end
    3119                   filecell.nc.civ2(ifile,j)={filename};
    3120               end
    3121               if detect% if a netcdf file already exists
    3122                   break
    3123               end
    3124           end
    3125            %create the new subdir_civ2
    3126           if ~exist(fullfile(Path_ima,subdir_civ2),'dir')
    3127               [m1,m2,m3]=mkdir(subdir_civ2);
    3128               if ~isequal(m2,'')
    3129                    msgbox_uvmat('ERROR', m2)
    3130               end
    3131           end
    3132            if strcmp(compare,'stereo PIV')%check second nc series
    3133                 for ifile=1:nbfield
    3134                      for j=1:nbslice
    3135                          filename=name_generator(filebase_A,num1_civ2(ifile),num_a_civ2(j),'.nc',...
    3136                           nom_type_nc,1,num2_civ2(ifile),num_b_civ1(j),subdir_civ2);%
    3137                           detect=exist(filename,'file')==2;
    3138                           if detect% if a netcdf file already exists
    3139                               subdir_civ2=[subdir_civ2 '.0'];
    3140                               break
    3141                           end
    3142                           filecell.ncA.civ2(ifile,j)={filename};
    3143                      end
     3113        for ifile=1:nbfield
     3114            for j=1:nbslice
     3115                filename=name_generator(filebase_nc,num1_civ2(ifile),num_a_civ2(j),'.nc',nom_type_nc,1,num2_civ2(ifile),num_b_civ2(j),subdir_civ2);%
     3116                detect=exist(filename,'file')==2;
     3117                if detect% if a netcdf file already exists
     3118                    subdir_civ2=[subdir_civ2 '.0'];
     3119                    break
     3120                end
     3121                filecell.nc.civ2(ifile,j)={filename};
     3122            end
     3123            if detect% if a netcdf file already exists
     3124                break
     3125            end
     3126        end
     3127        %create the new subdir_civ2
     3128        if ~exist(fullfile(Path_ima,subdir_civ2),'dir')
     3129            [m1,m2,m3]=mkdir(subdir_civ2);
     3130            if ~isequal(m2,'')
     3131                msgbox_uvmat('ERROR', m2)
     3132            end
     3133        end
     3134        if strcmp(compare,'stereo PIV')%check second nc series
     3135            for ifile=1:nbfield
     3136                for j=1:nbslice
     3137                    filename=name_generator(filebase_A,num1_civ2(ifile),num_a_civ2(j),'.nc',...
     3138                        nom_type_nc,1,num2_civ2(ifile),num_b_civ1(j),subdir_civ2);%
     3139                    detect=exist(filename,'file')==2;
    31443140                    if detect% if a netcdf file already exists
    3145                          break
     3141                        subdir_civ2=[subdir_civ2 '.0'];
     3142                        break
    31463143                    end
    3147               end
    3148            %create the new subdir_civ1
    3149                if ~exist(fullfile(Path_ima,subdir_civ2),'dir')
    3150                       [m1,m2,m3]=mkdir(subdir_civ2);
    3151                         if ~isequal(m2,'')
    3152                             msgbox_uvmat('ERROR', m2)
    3153                             %msgbox(m2);%error message for directory creation
    3154                       end
    3155                end
    3156           end
    3157     end 
     3144                    filecell.ncA.civ2(ifile,j)={filename};
     3145                end
     3146                if detect% if a netcdf file already exists
     3147                    break
     3148                end
     3149            end
     3150            %create the new subdir_civ1
     3151            if ~exist(fullfile(Path_ima,subdir_civ2),'dir')
     3152                [m1,m2,m3]=mkdir(subdir_civ2);
     3153                if ~isequal(m2,'')
     3154                    msgbox_uvmat('ERROR', m2)
     3155                    %msgbox(m2);%error message for directory creation
     3156                end
     3157            end
     3158        end
     3159    end
    31583160end
    31593161cd(currentdir);%come back to the current working directory
    3160    
     3162
    31613163
    31623164%%%%%%%%%%%%%  if civ2 results are obtained or used  %%%%%%%%%%%%%
     
    31713173                if ~exist(filename,'file')
    31723174                    msgbox_uvmat('ERROR',['input file ' filename ' not found'])
    3173                   filecell=[];
     3175                    filecell=[];
    31743176                    return
    31753177                end
     
    31813183                            filecell=[];
    31823184                            return
    3183                         end 
     3185                        end
    31843186                    elseif box_test(3)==0; %check the existence of patch if it is not calculated
    31853187                        Data=nc2struct(filename,'ListGlobalAttribute','patch');
     
    31893191                            return
    31903192                        end
    3191                     end 
     3193                    end
    31923194                end
    31933195            end
     
    32033205                        set(handles.RUN, 'Enable','On')
    32043206                        set(handles.RUN,'BackgroundColor',[1 0 0])
    3205 %                                set(handles.BATCH, 'Enable','On')
    3206 %                     set(handles.BATCH,'BackgroundColor',[1 0 0])
     3207                        %                                set(handles.BATCH, 'Enable','On')
     3208                        %                     set(handles.BATCH,'BackgroundColor',[1 0 0])
    32073209                        cd(currentdir)
    32083210                        return
     
    32123214        end
    32133215    end
    3214 
    3215     detect=1; 
    3216 %     while detect==1%creates a new subdir if the netcdf files already contain civ2 data
    3217         for ifile=1:nbfield
    3218             for j=1:nbslice
    3219                 filename=name_generator(filebase_nc,num1_civ2(ifile),num_a_civ2(j),'.nc',...
     3216   
     3217    detect=1;
     3218    %     while detect==1%creates a new subdir if the netcdf files already contain civ2 data
     3219    for ifile=1:nbfield
     3220        for j=1:nbslice
     3221            filename=name_generator(filebase_nc,num1_civ2(ifile),num_a_civ2(j),'.nc',...
    32203222                nom_type_nc,1,num2_civ2(ifile),num_b_civ2(j),subdir_civ2);
    3221                 detect=exist(filename,'file')==2;
    3222                 filecell.nc.civ2(ifile,j)={filename};
    3223             end
    3224         end
     3223            detect=exist(filename,'file')==2;
     3224            filecell.nc.civ2(ifile,j)={filename};
     3225        end
     3226    end
    32253227    %get first image names for civ2
    32263228    if box_test(1)==1 & isequal(num1_civ1,num1_civ2) & isequal(num_a_civ1,num_a_civ2)
     
    32333235                filecell.ima1.civ2(ifile,j)={filename};%first image
    32343236            end
    3235                 [idetectmin,indexj]=min(idetect_2);
     3237            [idetectmin,indexj]=min(idetect_2);
    32363238            if idetectmin==0,
    3237                     msgbox_uvmat('ERROR',['input image ' filecell.ima1.civ2{ifile,indexj} ' not found'])
    3238                     filecell=[];
    3239                     return
     3239                msgbox_uvmat('ERROR',['input image ' filecell.ima1.civ2{ifile,indexj} ' not found'])
     3240                filecell=[];
     3241                return
    32403242            end
    32413243        end
     
    32523254                filecell.ima2.civ2(ifile,j)={filename};%first image
    32533255            end
    3254                 [idetectmin,indexj]=min(idetect_3);
     3256            [idetectmin,indexj]=min(idetect_3);
    32553257            if idetectmin==0,
    3256                     msgbox_uvmat('ERROR',['input image ' filecell.ima2.civ2{ifile,indexj} ' not found'])
    3257                     filecell=[];
    3258                     return
     3258                msgbox_uvmat('ERROR',['input image ' filecell.ima2.civ2{ifile,indexj} ' not found'])
     3259                filecell=[];
     3260                return
    32593261            end
    32603262        end
     
    32643266    if ~testdiff
    32653267        filecell.nc.civ2=filecell.nc.civ1;% file already checked
    3266     else     % check the civ2 files 
     3268    else     % check the civ2 files
    32673269        for ifile=1:nbfield
    32683270            for j=1:nbslice
    32693271                filename=name_generator(filebase_nc,num1_civ2(ifile),num_a_civ2(j),'.nc',...
    3270                         nom_type_nc,1,num2_civ2(ifile),num_b_civ2(j),subdir_civ2);%
     3272                    nom_type_nc,1,num2_civ2(ifile),num_b_civ2(j),subdir_civ2);%
    32713273                filecell.nc.civ2(ifile,j)={filename};
    32723274                if ~exist(filename,'file')
     
    32763278                else
    32773279                    Data=nc2struct(filename,'ListGlobalAttribute','civ2');
    3278                     if isempty(Data.civ2)||isequal(Data.civ2,0)         
     3280                    if isempty(Data.civ2)||isequal(Data.civ2,0)
    32793281                        msgbox_uvmat('ERROR',['no civ2 data in ' filename])
    32803282                        filecell=[];
     
    32893291%%%%%%%%%%%%%  if stereo fields are calculated by PATCH %%%%%%%%%%%%%
    32903292if strcmp(compare,'stereo PIV')
    3291     if  box_test(3)==1 & isequal(get(handles.test_stereo1,'Value'),1) 
     3293    if  box_test(3)==1 & isequal(get(handles.test_stereo1,'Value'),1)
    32923294        for ifile=1:nbfield
    32933295            for j=1:nbslice
     
    32983300        end
    32993301    end
    3300      if  box_test(6)==1 & isequal(get(handles.test_stereo2,'Value'),1)
     3302    if  box_test(6)==1 & isequal(get(handles.test_stereo2,'Value'),1)
    33013303        for ifile=1:nbfield
    33023304            for j=1:nbslice
     
    33063308            end
    33073309        end
    3308      end
     3310    end
    33093311end
    33103312set(handles.subdir_civ1,'String',subdir_civ1);%update the edit box
     
    33373339            type_ima1='avi';
    33383340        end
    3339     else 
    3340        form=imformats(ext_ima(2:end));
    3341        if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
    3342            if isequal(nom_type_ima1,'*');
    3343                type_ima1='multimage';%image series in a single image file
    3344            else
    3345                type_ima1='image';
    3346            end
    3347        end
     3341    else
     3342        form=imformats(ext_ima(2:end));
     3343        if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
     3344            if isequal(nom_type_ima1,'*');
     3345                type_ima1='multimage';%image series in a single image file
     3346            else
     3347                type_ima1='image';
     3348            end
     3349        end
    33483350    end
    33493351    type_ima2='none';%default
     
    33573359            type_ima2='avi';
    33583360        end
    3359     else 
    3360        form=imformats(ext_ima(2:end));
    3361        if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
    3362            if isequal(nom_type_ima1,'*');
    3363                type_ima2='multimage';%image series in a single image file
    3364            else
    3365                type_ima2='image';
    3366            end
    3367        end
     3361    else
     3362        form=imformats(ext_ima(2:end));
     3363        if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
     3364            if isequal(nom_type_ima1,'*');
     3365                type_ima2='multimage';%image series in a single image file
     3366            else
     3367                type_ima2='image';
     3368            end
     3369        end
    33683370    end
    33693371    %npxy=get(handles.ImaExt,'UserData');
    3370 % %     if numel(npxy)<2
    3371 %     
    3372 %         filename=name_generator(filebase_ima1,num1_civ1(1),num_a_civ1(1),ImaExt,nom_type_ima1);
    3373 %         A=imread(filename);
    3374 %         npxy=size(A);
    3375 % %     end
    3376 %     npy=npxy(1);
    3377 %     npx=npxy(2);
     3372    % %     if numel(npxy)<2
     3373    %
     3374    %         filename=name_generator(filebase_ima1,num1_civ1(1),num_a_civ1(1),ImaExt,nom_type_ima1);
     3375    %         A=imread(filename);
     3376    %         npxy=size(A);
     3377    % %     end
     3378    %     npy=npxy(1);
     3379    %     npx=npxy(2);
    33783380    if box_test(1)==1 %if civ1 is performed
    3379        h = waitbar(0,['copy images to the .png format for civ1']);% display a wait bar
    3380        for ifile=1:nbfield
    3381             waitbar(ifile/nbfield);
    3382             for j=1:nbslice
    3383                     filename=name_generator(filebase_ima1,num1_civ1(ifile),num_a_civ1(j),'.png',nom_type_imanew1);
    3384                     if ~exist(filename,'file')
    3385                         A=read_image(filecell.ima1.civ1{ifile,j},type_ima1,num1_civ1(ifile),movieobject1);
    3386                         imwrite(A,filename,'BitDepth',16);
    3387                     end
    3388                     filecell.ima1.civ1(ifile,j)={filename};
    3389                     filename=name_generator(filebase_ima2, num2_civ1(ifile),num_b_civ1(j),'.png',nom_type_imanew2);
    3390                     if ~exist(filename,'file')
    3391                         A=read_image(filecell.ima2.civ1{ifile,j},type_ima2,num2_civ1(ifile),movieobject2);
    3392                         imwrite(A,filename,'BitDepth',16);
    3393                     end
    3394                     filecell.ima2.civ1(ifile,j)={filename};
    3395             end
    3396         end
    3397         close(h)
    3398     end
    3399     if box_test(4)==1 %if civ2 is performed
    3400         h = waitbar(0,['copy images to the .png format for civ2']);% display a wait bar
     3381        h = waitbar(0,['copy images to the .png format for civ1']);% display a wait bar
    34013382        for ifile=1:nbfield
    34023383            waitbar(ifile/nbfield);
    34033384            for j=1:nbslice
    3404                     filename=name_generator(filebase_ima1,num1_civ2(ifile),num_a_civ2(j),'.png',nom_type_imanew1);
    3405                     if ~exist(filename,'file')
    3406                         A=read_image(cell2mat(filecell.ima1.civ2(ifile,j)),type_ima2,num1_civ2(ifile));
    3407                         imwrite(A,filename,'BitDepth',16);
    3408                     end
    3409                     filecell.ima1.civ2(ifile,j)={filename};
    3410                     filename=name_generator(filebase_ima2, num2_civ2(ifile),num_b_civ2(j),'.png',nom_type_imanew2);
    3411                     if ~exist(filename,'file')
    3412                         A=read_image(cell2mat(filecell.ima2.civ2(ifile,j)),type_ima2,num2_civ2(ifile));
    3413                         imwrite(A,filename,'BitDepth',16);
    3414                     end
    3415                     filecell.ima2.civ2(ifile,j)={filename};
     3385                filename=name_generator(filebase_ima1,num1_civ1(ifile),num_a_civ1(j),'.png',nom_type_imanew1);
     3386                if ~exist(filename,'file')
     3387                    A=read_image(filecell.ima1.civ1{ifile,j},type_ima1,num1_civ1(ifile),movieobject1);
     3388                    imwrite(A,filename,'BitDepth',16);
     3389                end
     3390                filecell.ima1.civ1(ifile,j)={filename};
     3391                filename=name_generator(filebase_ima2, num2_civ1(ifile),num_b_civ1(j),'.png',nom_type_imanew2);
     3392                if ~exist(filename,'file')
     3393                    A=read_image(filecell.ima2.civ1{ifile,j},type_ima2,num2_civ1(ifile),movieobject2);
     3394                    imwrite(A,filename,'BitDepth',16);
     3395                end
     3396                filecell.ima2.civ1(ifile,j)={filename};
     3397            end
     3398        end
     3399        close(h)
     3400    end
     3401    if box_test(4)==1 %if civ2 is performed
     3402        h = waitbar(0,['copy images to the .png format for civ2']);% display a wait bar
     3403        for ifile=1:nbfield
     3404            waitbar(ifile/nbfield);
     3405            for j=1:nbslice
     3406                filename=name_generator(filebase_ima1,num1_civ2(ifile),num_a_civ2(j),'.png',nom_type_imanew1);
     3407                if ~exist(filename,'file')
     3408                    A=read_image(cell2mat(filecell.ima1.civ2(ifile,j)),type_ima2,num1_civ2(ifile));
     3409                    imwrite(A,filename,'BitDepth',16);
     3410                end
     3411                filecell.ima1.civ2(ifile,j)={filename};
     3412                filename=name_generator(filebase_ima2, num2_civ2(ifile),num_b_civ2(j),'.png',nom_type_imanew2);
     3413                if ~exist(filename,'file')
     3414                    A=read_image(cell2mat(filecell.ima2.civ2(ifile,j)),type_ima2,num2_civ2(ifile));
     3415                    imwrite(A,filename,'BitDepth',16);
     3416                end
     3417                filecell.ima2.civ2(ifile,j)={filename};
    34163418            end
    34173419        end
     
    34313433if isempty(ibx_val)
    34323434    ibx='21'; set(handles.ibx,'String','21')
    3433 else 
     3435else
    34343436    ibx=num2str(ibx_val);
    34353437end
     
    34373439if isempty(iby_val)
    34383440    iby='21'; set(handles.iby,'String','21')
    3439 else 
     3441else
    34403442    iby=num2str(iby_val);
    34413443end
     
    34783480    if numel(gridname)>4 && isequal(gridname(end-3:end),'grid')
    34793481        nbslice_grid=str2num(gridname(1:end-4)); %
    3480         if ~isempty(nbslice_grid) 
    3481             gridflag='y'; 
     3482        if ~isempty(nbslice_grid)
     3483            gridflag='y';
    34823484        end
    34833485    elseif exist(gridname,'file')
     
    34963498    min_ima='0';
    34973499    max_ima='4096';
    3498 end 
    3499  %main loop
     3500end
     3501%main loop
    35003502filebase=get(handles.RootName,'String');
    35013503sizcell=size(filecell);
     
    35163518        filename_cmx([end-1:end])=[ 'cm'];%name of cmx file
    35173519        filename_cmx=[filename_cmx 'x'];
    3518         namelog=[filename_cmx([1:end-3]) 'log'];       
     3520        namelog=[filename_cmx([1:end-3]) 'log'];
    35193521        if size(time,1)>=num2(ifile) &  size(time,2)>=num_b(j)
    35203522            Dt=num2str(time(num2(ifile),num_b(j))-time(num1(ifile),num_a(j)));
     
    35263528            Dt='1';
    35273529            T0='0';
    3528         end 
     3530        end
    35293531        term_a=num2stra(num_a(j),nom_type_nc);%UTILITE?
    35303532        term_b=num2stra(num_b(j),nom_type_nc);%
    3531         if test_grid && ~isempty(nbslice_grid)       
    3532              num1_grid=mod(num1(ifile)-1,nbslice_grid)+1;
     3533        if test_grid && ~isempty(nbslice_grid)
     3534            num1_grid=mod(num1(ifile)-1,nbslice_grid)+1;
    35333535            gridname=[filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
    35343536            if ~exist(gridname,'file')
     
    35433545        else
    35443546            maskdispl=get(handles.mask_civ1,'String');%look for mask name in edit box
    3545             maskbase=[filebase '_' maskdispl];% 
    3546             nbslice=str2num(maskdispl(1:end-4)); % 
     3547            maskbase=[filebase '_' maskdispl];%
     3548            nbslice=str2num(maskdispl(1:end-4)); %
    35473549            num1_mask=mod(num1(ifile)-1,nbslice)+1;
    35483550            maskname=name_generator(maskbase,num1_mask,1,'.png','_i');
    35493551            if exist(maskname,'file')
    3550                 maskflag='y'; 
     3552                maskflag='y';
    35513553            else
    35523554                maskname='noFile use default';
    3553                 maskflag='n'; 
    3554             end
    3555         end
    3556                 textcmx={'##############   CMX file';...
    3557                 ['FirstImage ' filename_ima];...
    3558                 ['LastImage  ' filename_ima_1];...
    3559                 'XX' ;...
    3560                 ['Mask ' maskflag] ;...
    3561                 ['MaskName ' maskname];...
    3562                 ['ImageSize ' npx ' ' npy];...   %VERIFIER CAS GENERAL ?
    3563                 ['CorrelationBoxesSize ' ibx ' ' iby];...
    3564                 ['SearchBoxeSize ' isx ' ' isy];...
    3565                 ['RO ' rho];...
    3566                 ['GridSpacing ' dx ' ' dy];...
    3567                 'XX 1.0';...
    3568                 ['Dt_TO ' Dt ' ' T0];...
    3569                 ['PixCmXY ' pxcmx ' ' pxcmy];...
    3570                 'XX 1';...
    3571                 ['ShiftXY ' shiftx ' ' shifty];...
    3572                 ['Grid ' gridflag];...
    3573                 ['GridName ' gridname] ;...
    3574                 'XX 85';...
    3575                 'XX 1.0';...
    3576                 'XX 1.0';...
    3577                 'Hart 1';...
    3578                 'DecimalShift 0';...
    3579                 'Deformation 0';...
    3580                 'CorrelationMin 0';...
    3581                 'IntensityMin 0';...
    3582                 ['SeuilImage ' threshflag];...
    3583                 ['SeuilImageValues ' min_ima ' ' max_ima];...
    3584                 ['ImageToUse ' term_a ' ' term_b];... % VERIFIER ?
    3585                 'ImageUsedBefore null null'};
    3586                 textout=char(textcmx);
    3587 %               dlmwrite(filename_cmx,textout,'');
    3588      fid=fopen([filename_cmx],'w');
    3589 fprintf(fid, ['##############   CMX file' '\n']);
    3590  fprintf(fid,   ['FirstImage ' regexprep(filename_ima,'\\','\\\\') '\n' ]);
    3591  fprintf(fid,   ['LastImage  ' regexprep(filename_ima_1,'\\','\\\\') '\n' ]);
    3592   fprintf(fid,  ['XX' '\n' ]);
    3593   fprintf(fid,  ['Mask '  maskflag '\n' ]);
    3594   fprintf(fid,  ['MaskName '  maskname '\n' ]);
    3595  fprintf(fid,   ['ImageSize '  npx ' '  npy '\n' ]);   %VERIFIER CAS GENERAL ?
    3596  fprintf(fid,   ['CorrelationBoxesSize '  ibx ' '  iby '\n' ]);
    3597  fprintf(fid,   ['SearchBoxeSize '  isx ' '  isy '\n' ]);
    3598  fprintf(fid,   ['RO '  rho '\n' ]);
    3599  fprintf(fid,   ['GridSpacing '  dx ' '  dy '\n' ]);
    3600  fprintf(fid,   ['XX 1.0' '\n' ]);
    3601  fprintf(fid,   ['Dt_TO '  Dt ' '  T0 '\n' ]);
    3602   fprintf(fid,  ['PixCmXY '  pxcmx ' '  pxcmy '\n' ]);
    3603   fprintf(fid,  ['XX 1' '\n' ]);
    3604  fprintf(fid,   ['ShiftXY '  shiftx ' '   shifty '\n' ]);
    3605   fprintf(fid,  ['Grid '  gridflag '\n' ]);
    3606  fprintf(fid,   ['GridName '  gridname '\n' ]);
    3607  fprintf(fid,   ['XX 85' '\n' ]);
    3608  fprintf(fid,   ['XX 1.0' '\n' ]);
    3609  fprintf(fid,   ['XX 1.0' '\n' ]);
    3610  fprintf(fid,   ['Hart 1' '\n' ]);
    3611  fprintf(fid,  [ 'DecimalShift 0' '\n' ]);
    3612  fprintf(fid,   ['Deformation 0' '\n' ]);
    3613   fprintf(fid,  ['CorrelationMin 0' '\n' ]);
    3614  fprintf(fid,   ['IntensityMin 0' '\n' ]);
    3615   fprintf(fid,  ['SeuilImage n' '\n' ]);
    3616  fprintf(fid,   ['SeuilImageValues 0 4096' '\n' ]);
    3617  fprintf(fid,   ['ImageToUse '  term_a ' '  term_b '\n' ]); % VERIFIER ?
    3618  fprintf(fid,   ['ImageUsedBefore null null' '\n' ]);
    3619 fclose(fid);
    3620        
    3621                 s=-1;
     3555                maskflag='n';
     3556            end
     3557        end
     3558        textcmx={'##############   CMX file';...
     3559            ['FirstImage ' filename_ima];...
     3560            ['LastImage  ' filename_ima_1];...
     3561            'XX' ;...
     3562            ['Mask ' maskflag] ;...
     3563            ['MaskName ' maskname];...
     3564            ['ImageSize ' npx ' ' npy];...   %VERIFIER CAS GENERAL ?
     3565            ['CorrelationBoxesSize ' ibx ' ' iby];...
     3566            ['SearchBoxeSize ' isx ' ' isy];...
     3567            ['RO ' rho];...
     3568            ['GridSpacing ' dx ' ' dy];...
     3569            'XX 1.0';...
     3570            ['Dt_TO ' Dt ' ' T0];...
     3571            ['PixCmXY ' pxcmx ' ' pxcmy];...
     3572            'XX 1';...
     3573            ['ShiftXY ' shiftx ' ' shifty];...
     3574            ['Grid ' gridflag];...
     3575            ['GridName ' gridname] ;...
     3576            'XX 85';...
     3577            'XX 1.0';...
     3578            'XX 1.0';...
     3579            'Hart 1';...
     3580            'DecimalShift 0';...
     3581            'Deformation 0';...
     3582            'CorrelationMin 0';...
     3583            'IntensityMin 0';...
     3584            ['SeuilImage ' threshflag];...
     3585            ['SeuilImageValues ' min_ima ' ' max_ima];...
     3586            ['ImageToUse ' term_a ' ' term_b];... % VERIFIER ?
     3587            'ImageUsedBefore null null'};
     3588        textout=char(textcmx);
     3589        %               dlmwrite(filename_cmx,textout,'');
     3590        fid=fopen([filename_cmx],'w');
     3591        fprintf(fid, ['##############   CMX file' '\n']);
     3592        fprintf(fid,   ['FirstImage ' regexprep(filename_ima,'\\','\\\\') '\n' ]);
     3593        fprintf(fid,   ['LastImage  ' regexprep(filename_ima_1,'\\','\\\\') '\n' ]);
     3594        fprintf(fid,  ['XX' '\n' ]);
     3595        fprintf(fid,  ['Mask '  maskflag '\n' ]);
     3596        fprintf(fid,  ['MaskName '  maskname '\n' ]);
     3597        fprintf(fid,   ['ImageSize '  npx ' '  npy '\n' ]);   %VERIFIER CAS GENERAL ?
     3598        fprintf(fid,   ['CorrelationBoxesSize '  ibx ' '  iby '\n' ]);
     3599        fprintf(fid,   ['SearchBoxeSize '  isx ' '  isy '\n' ]);
     3600        fprintf(fid,   ['RO '  rho '\n' ]);
     3601        fprintf(fid,   ['GridSpacing '  dx ' '  dy '\n' ]);
     3602        fprintf(fid,   ['XX 1.0' '\n' ]);
     3603        fprintf(fid,   ['Dt_TO '  Dt ' '  T0 '\n' ]);
     3604        fprintf(fid,  ['PixCmXY '  pxcmx ' '  pxcmy '\n' ]);
     3605        fprintf(fid,  ['XX 1' '\n' ]);
     3606        fprintf(fid,   ['ShiftXY '  shiftx ' '   shifty '\n' ]);
     3607        fprintf(fid,  ['Grid '  gridflag '\n' ]);
     3608        fprintf(fid,   ['GridName '  gridname '\n' ]);
     3609        fprintf(fid,   ['XX 85' '\n' ]);
     3610        fprintf(fid,   ['XX 1.0' '\n' ]);
     3611        fprintf(fid,   ['XX 1.0' '\n' ]);
     3612        fprintf(fid,   ['Hart 1' '\n' ]);
     3613        fprintf(fid,  [ 'DecimalShift 0' '\n' ]);
     3614        fprintf(fid,   ['Deformation 0' '\n' ]);
     3615        fprintf(fid,  ['CorrelationMin 0' '\n' ]);
     3616        fprintf(fid,   ['IntensityMin 0' '\n' ]);
     3617        fprintf(fid,  ['SeuilImage n' '\n' ]);
     3618        fprintf(fid,   ['SeuilImageValues 0 4096' '\n' ]);
     3619        fprintf(fid,   ['ImageToUse '  term_a ' '  term_b '\n' ]); % VERIFIER ?
     3620        fprintf(fid,   ['ImageUsedBefore null null' '\n' ]);
     3621        fclose(fid);
     3622        
     3623        s=-1;
    36223624        display(['!' civ1Bin ' -f ' filename_cmx ' > ' namelog ])
    36233625        eval(['!' civ1Bin ' -f ' filename_cmx ' > ' namelog ]);
    3624 %               if sge%dispatch computation on the cluster using interactive queue
    3625 %           %  [s,w] = unix(['qrsh -q fast.q ' civ1Bin ' -f ' filename_cmx ' > ' namelog ' 2>&1' ]);
    3626 %        end     
    3627 %         if s~=0
    3628 %            %  ['!' civ1Bin ' -f ' filename_cmx ' > ' namelog]
    3629 %            % eval(['!' civ1Bin ' -f ' filename_cmx ' > ' namelog]);       
    3630 %         end
     3626        %               if sge%dispatch computation on the cluster using interactive queue
     3627        %           %  [s,w] = unix(['qrsh -q fast.q ' civ1Bin ' -f ' filename_cmx ' > ' namelog ' 2>&1' ]);
     3628        %        end
     3629        %         if s~=0
     3630        %            %  ['!' civ1Bin ' -f ' filename_cmx ' > ' namelog]
     3631        %            % eval(['!' civ1Bin ' -f ' filename_cmx ' > ' namelog]);
     3632        %         end
    36313633    end
    36323634end
     
    36393641% %filecell_3: names of second images
    36403642% global civ2Bin sge
    3641 % 
     3643%
    36423644% %names of the civ2 fields
    36433645% field.vel_type='civ2';
     
    36473649% field.U='vec2_U';
    36483650% field.V='vec2_V';
    3649 % 
     3651%
    36503652% %get civ parameters
    36513653% ibx=get(handles.ibx_civ2,'String');
     
    36793681%     if numel(gridname)>4 && isequal(gridname(end-3:end),'grid')
    36803682%         nbslice_grid=str2num(gridname(1:end-4)); %
    3681 %         if ~isempty(nbslice_grid) 
    3682 %             gridflag='y'; 
     3683%         if ~isempty(nbslice_grid)
     3684%             gridflag='y';
    36833685%         end
    36843686%     elseif exist(gridname,'file')
     
    36923694% nbfield=sizcell(1);
    36933695% nbslice=sizcell(2);
    3694 %   
     3696%
    36953697% %main loop
    36963698% icount=0;
     
    37083710%         filename_cmx([end-1:end])=[ 'cm'];%name of cmx file
    37093711%         filename_cmx=[filename_cmx 'x'];
    3710 %         namelog=[filename_cmx([1:end-3]) 'log']; 
     3712%         namelog=[filename_cmx([1:end-3]) 'log'];
    37113713%         if size(time,1)>=num2(ifile) &  size(time,2)>=num_b(j)
    37123714%             Dt=num2str(time(num2(ifile),num_b(j))-time(num1(ifile),num_a(j)));
     
    37183720%             Dt='1';
    37193721%             T0='0';
    3720 %         end 
     3722%         end
    37213723%         term_a=num2stra(num_a(j),nom_type_nc);
    37223724%         term_b=num2stra(num_b(j),nom_type_nc);
    37233725%         filename_nc1=cell2mat(filecell_nc1(ifile,j));
    3724 %         filename_nc1([end-2:end])=[]; % remove '.nc'     
    3725 %         if test_grid && ~isempty(nbslice_grid)       
     3726%         filename_nc1([end-2:end])=[]; % remove '.nc'
     3727%         if test_grid && ~isempty(nbslice_grid)
    37263728%             num1_grid=mod(num1(ifile)-1,nbslice_grid)+1;
    37273729%             gridname=[filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
     
    37303732%                 return
    37313733%             end
    3732 %         end     
     3734%         end
    37333735%         test_mask=get(handles.get_mask_civ2,'Value');
    3734 %         if test_mask==0 
     3736%         if test_mask==0
    37353737%             maskname='noFile use default';
    37363738%             maskflag='n';
    37373739%         else
    37383740%             maskdispl=get(handles.mask_civ2,'String');
    3739 %             maskbase=[filebase '_' maskdispl]; % 
    3740 %             nbslice_mask=str2num(maskdispl(1:end-4)); % 
     3741%             maskbase=[filebase '_' maskdispl]; %
     3742%             nbslice_mask=str2num(maskdispl(1:end-4)); %
    37413743%             num1_mask=mod(num1(ifile)-1,nbslice_mask)+1;
    37423744%             maskname =name_generator(maskbase,num1_mask,1,'.png','_i');
    37433745%             if ~exist(maskname,'file')
    3744 %                 maskflag='y'; 
     3746%                 maskflag='y';
    37453747%             else
    37463748%                 maskname='noFile use default';
    3747 %                 maskflag='n'; 
     3749%                 maskflag='n';
    37483750%             end
    37493751%         end
    3750 %     
     3752%
    37513753%               textcmx={'##############   CMX file';...
    37523754%               ['FirstImage ' filename_ima_2];...
     
    37553757%               ['Mask ' maskflag];...
    37563758%               ['MaskName ' maskname];...
    3757 %               ['ImageSize ' npx ' ' npy];...   
     3759%               ['ImageSize ' npx ' ' npy];...
    37583760%               ['CorrelationBoxesSize ' ibx ' ' iby];...
    37593761%               ['SearchBoxeSize ' ibx ' ' iby];...
     
    37803782%               ['ImageUsedBefore ' filename_nc1]};
    37813783%         textout=char(textcmx);
    3782 %         dlmwrite(filename_cmx,textout,''); 
    3783 %         s=-1; 
     3784%         dlmwrite(filename_cmx,textout,'');
     3785%         s=-1;
    37843786%         display(['!' civ2Bin ' -f ' filename_cmx ' > ' namelog ])
    3785 %         eval(['!' civ2Bin ' -f ' filename_cmx ' > ' namelog ]);   
    3786 %     
     3787%         eval(['!' civ2Bin ' -f ' filename_cmx ' > ' namelog ]);
     3788%
    37873789% %             if sge%dispatch computation on the cluster using interactive queue
    37883790% %             [s,w] = unix(['qrsh -q fast.q ' civ2Bin ' -f ' filename_cmx ' > ' namelog ' 2>&1']);
    3789 % %         end     
     3791% %         end
    37903792% %         if s~=0
    37913793% %             eval(['!' civ2Bin ' -f ' filename_cmx ' > ' namelog]);
    37923794% %             ['!' civ2Bin ' -f ' filename_cmx ' > ' namelog]
    3793 % %         end                     
     3795% %         end
    37943796%     end
    37953797% end
    3796 % % close(h) 
     3798% % close(h)
    37973799
    37983800%------------------------------------------------------------------------
     
    38003802function cmd_PATCH=PATCH_CMD(filename_nc,nx_patch,ny_patch,rho_patch,subdomain_patch,thresh_value,test_interp,PatchBin)
    38013803%------------------------------------------------------------------------
    3802         namelog=[filename_nc([1:end-3]) '_patch.log'];
    3803         if test_interp==0
    3804             cmd_PATCH=[PatchBin ' -f ' filename_nc ' -m ' nx_patch  ' -n ' ny_patch ' -ro ' rho_patch ' -nopt ' subdomain_patch ...
    3805             '  > ' namelog ' 2>&1']; % redirect standard output to the log file
    3806          else %nouveau programme patch
    3807              cmd_PATCH=[PatchBin ' -f ' filename_nc ' -m ' nx_patch  ' -n ' ny_patch ' -ro ' rho_patch ...
    3808                 ' -max ' thresh_value ' -nopt ' subdomain_patch  '  > ' namelog ' 2>&1']; % redirect standard output to the log file
    3809         end
     3804namelog=[filename_nc([1:end-3]) '_patch.log'];
     3805if test_interp==0
     3806    cmd_PATCH=[PatchBin ' -f ' filename_nc ' -m ' nx_patch  ' -n ' ny_patch ' -ro ' rho_patch ' -nopt ' subdomain_patch ...
     3807        '  > ' namelog ' 2>&1']; % redirect standard output to the log file
     3808else %nouveau programme patch
     3809    cmd_PATCH=[PatchBin ' -f ' filename_nc ' -m ' nx_patch  ' -n ' ny_patch ' -ro ' rho_patch ...
     3810        ' -max ' thresh_value ' -nopt ' subdomain_patch  '  > ' namelog ' 2>&1']; % redirect standard output to the log file
     3811end
    38103812
    38113813%------------------------------------------------------------------------
     
    39223924    num_a=1;
    39233925    num_b=1;
    3924 elseif isequal (mode, 'series(Dj)') 
     3926elseif isequal (mode, 'series(Dj)')
    39253927    num1=1;
    39263928    num2=1;
     
    39593961subdir=get(handles.subdir_civ1,'String');
    39603962set(handles.subdir_civ2,'String',subdir);
    3961 if get(handles.CIV1,'Value')==0 
     3963if get(handles.CIV1,'Value')==0
    39623964    find_netcpair_civ1(hObject, eventdata, handles); %update the list of available pairs from netcdf files in the new directory
    39633965end
     
    39843986    [ nbslice_mask, flag_mask]=get_mask(filebase,handles);
    39853987    if isequal(flag_mask,1)
    3986           mask_displ=[num2str(nbslice_mask) 'mask'];
     3988        mask_displ=[num2str(nbslice_mask) 'mask'];
    39873989    elseif get(handles.compare,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
    3988             common_path=fileparts(filebase);
    3989             filebase_a=fullfile(common_path,get(handles.RootName_1,'String'));
    3990             [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
    3991             if isequal(flag_mask_a,0) || ~isequal(nbslice_a,nbslice_mask)
    3992                 mask_displ='no mask';
    3993             end
     3990        common_path=fileparts(filebase);
     3991        filebase_a=fullfile(common_path,get(handles.RootName_1,'String'));
     3992        [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
     3993        if isequal(flag_mask_a,0) || ~isequal(nbslice_a,nbslice_mask)
     3994            mask_displ='no mask';
     3995        end
    39943996    end
    39953997    if isequal(mask_displ,'no mask')
    39963998        [FileName, PathName, filterindex] = uigetfile( ...
    3997                {'*.png', ' (*.png)';
    3998                 '*.png',  '.png files '; ...
    3999                 '*.*', 'All Files (*.*)'}, ...
    4000                 'Pick a mask file *.png',filebase);
    4001         mask_displ=fullfile(PathName,FileName); 
     3999            {'*.png', ' (*.png)';
     4000            '*.png',  '.png files '; ...
     4001            '*.*', 'All Files (*.*)'}, ...
     4002            'Pick a mask file *.png',filebase);
     4003        mask_displ=fullfile(PathName,FileName);
    40024004        if ~exist(mask_displ,'file')
    40034005            mask_displ='no mask';
     
    40284030    set(handles.mask_fix1,'String','')
    40294031else
    4030 mask_displ='no mask'; %default
    4031 filebase=get(handles.RootName,'String');
    4032 [nbslice, flag_mask]=get_mask(filebase,handles);
    4033 if isequal(flag_mask,1)
    4034       mask_displ=[num2str(nbslice) 'mask'];
    4035 elseif get(handles.compare,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
     4032    mask_displ='no mask'; %default
     4033    filebase=get(handles.RootName,'String');
     4034    [nbslice, flag_mask]=get_mask(filebase,handles);
     4035    if isequal(flag_mask,1)
     4036        mask_displ=[num2str(nbslice) 'mask'];
     4037    elseif get(handles.compare,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
    40364038        filebase_a=get(handles.RootName_1,'String');
    40374039        [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
     
    40394041            mask_displ='no mask';
    40404042        end
    4041 end
    4042 if isequal(mask_displ,'no mask')
    4043     [FileName, PathName, filterindex] = uigetfile( ...
    4044            {'*.png', ' (*.png)';
     4043    end
     4044    if isequal(mask_displ,'no mask')
     4045        [FileName, PathName, filterindex] = uigetfile( ...
     4046            {'*.png', ' (*.png)';
    40454047            '*.png',  '.png files '; ...
    40464048            '*.*', 'All Files (*.*)'}, ...
    40474049            'Pick a mask file *.png',filebase);
    4048     mask_displ=fullfile(PathName,FileName); 
    4049     if ~exist(mask_displ,'file')
    4050         mask_displ='no mask';
    4051     end
    4052 end
    4053 if isequal(mask_displ,'no mask')
    4054     set(handles.get_mask_fix1,'Value',0)
    4055     set(handles.get_mask_civ2,'Value',0)
    4056     set(handles.get_mask_fix2,'Value',0)
    4057 else
    4058     %set(handles.get_mask_civ2,'Value',1)
    4059     set(handles.get_mask_fix2,'Value',1)
    4060 end
    4061 set(handles.mask_fix1,'String',mask_displ)
    4062 set(handles.mask_civ2,'String',mask_displ)
    4063 set(handles.mask_fix2,'String',mask_displ)
     4050        mask_displ=fullfile(PathName,FileName);
     4051        if ~exist(mask_displ,'file')
     4052            mask_displ='no mask';
     4053        end
     4054    end
     4055    if isequal(mask_displ,'no mask')
     4056        set(handles.get_mask_fix1,'Value',0)
     4057        set(handles.get_mask_civ2,'Value',0)
     4058        set(handles.get_mask_fix2,'Value',0)
     4059    else
     4060        %set(handles.get_mask_civ2,'Value',1)
     4061        set(handles.get_mask_fix2,'Value',1)
     4062    end
     4063    set(handles.mask_fix1,'String',mask_displ)
     4064    set(handles.mask_civ2,'String',mask_displ)
     4065    set(handles.mask_fix2,'String',mask_displ)
    40644066end
    40654067
     
    40724074    set(handles.mask_civ2,'String','')
    40734075else
    4074 mask_displ='no mask'; %default
    4075 filebase=get(handles.RootName,'String');
    4076 [nbslice, flag_mask]=get_mask(filebase,handles);
    4077 if isequal(flag_mask,1)
    4078       mask_displ=[num2str(nbslice) 'mask'];
    4079 elseif get(handles.compare,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
     4076    mask_displ='no mask'; %default
     4077    filebase=get(handles.RootName,'String');
     4078    [nbslice, flag_mask]=get_mask(filebase,handles);
     4079    if isequal(flag_mask,1)
     4080        mask_displ=[num2str(nbslice) 'mask'];
     4081    elseif get(handles.compare,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
    40804082        filebase_a=get(handles.RootName_1,'String');
    40814083        [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
     
    40834085            mask_displ='no mask';
    40844086        end
    4085 end
    4086 if isequal(mask_displ,'no mask')
    4087     [FileName, PathName, filterindex] = uigetfile( ...
    4088            {'*.png', ' (*.png)';
     4087    end
     4088    if isequal(mask_displ,'no mask')
     4089        [FileName, PathName, filterindex] = uigetfile( ...
     4090            {'*.png', ' (*.png)';
    40894091            '*.png',  '.png files '; ...
    40904092            '*.*', 'All Files (*.*)'}, ...
    40914093            'Pick a mask file *.png',filebase);
    4092     mask_displ=fullfile(PathName,FileName);
    4093     if ~exist(mask_displ,'file')
    4094         mask_displ='no mask';
    4095     end
    4096 end
    4097 if isequal(mask_displ,'no mask')
    4098     set(handles.get_mask_civ2,'Value',0)
    4099     set(handles.get_mask_fix2,'Value',0)
    4100 else
    4101     set(handles.get_mask_fix2,'Value',1)
    4102 end
    4103 set(handles.mask_civ2,'String',mask_displ)
    4104 set(handles.mask_fix2,'String',mask_displ)
     4094        mask_displ=fullfile(PathName,FileName);
     4095        if ~exist(mask_displ,'file')
     4096            mask_displ='no mask';
     4097        end
     4098    end
     4099    if isequal(mask_displ,'no mask')
     4100        set(handles.get_mask_civ2,'Value',0)
     4101        set(handles.get_mask_fix2,'Value',0)
     4102    else
     4103        set(handles.get_mask_fix2,'Value',1)
     4104    end
     4105    set(handles.mask_civ2,'String',mask_displ)
     4106    set(handles.mask_fix2,'String',mask_displ)
    41054107end
    41064108
     
    41174119    [nbslice, flag_mask]=get_mask(filebase,handles);
    41184120    if isequal(flag_mask,1)
    4119           mask_displ=[num2str(nbslice) 'mask'];
     4121        mask_displ=[num2str(nbslice) 'mask'];
    41204122    elseif get(handles.compare,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
    4121             filebase_a=get(handles.RootName_1,'String');
    4122             [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
    4123             if isequal(flag_mask_a,0) | ~isequal(nbslice_a,nbslice)
    4124                 mask_displ='no mask';
    4125             end
     4123        filebase_a=get(handles.RootName_1,'String');
     4124        [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
     4125        if isequal(flag_mask_a,0) | ~isequal(nbslice_a,nbslice)
     4126            mask_displ='no mask';
     4127        end
    41264128    end
    41274129    if isequal(mask_displ,'no mask')
    41284130        [FileName, PathName, filterindex] = uigetfile( ...
    4129                {'*.png', ' (*.png)';
    4130                 '*.png',  '.png files '; ...
    4131                 '*.*', 'All Files (*.*)'}, ...
    4132                 'Pick a mask file *.png',filebase);
    4133         mask_displ=fullfile(PathName,FileName); 
     4131            {'*.png', ' (*.png)';
     4132            '*.png',  '.png files '; ...
     4133            '*.*', 'All Files (*.*)'}, ...
     4134            'Pick a mask file *.png',filebase);
     4135        mask_displ=fullfile(PathName,FileName);
    41344136        if ~exist(mask_displ,'file')
    41354137            mask_displ='no mask';
     
    41384140    if isequal(mask_displ,'no mask')
    41394141        set(handles.get_mask_fix2,'Value',0)
    4140     end 
     4142    end
    41414143    set(handles.mask_fix2,'String',mask_displ)
    41424144end
     
    41464148function [nbslice, flag_mask]=get_mask(filebase,handles)
    41474149%------------------------------------------------------------------------
    4148 %detect mask files, images with appropriate file base 
     4150%detect mask files, images with appropriate file base
    41494151%[filebase '_' xx 'mask'], xx=nbslice
    41504152%flag_mask=1 indicates detection
     
    41644166cd(currentdir);%come back to the current working directory
    41654167if ~isempty(maskfiles)
    4166 %     msgbox_uvmat('ERROR','no mask available, to create it use Tools/Make mask in the upper menu bar of uvmat')
    4167 % else
     4168    %     msgbox_uvmat('ERROR','no mask available, to create it use Tools/Make mask in the upper menu bar of uvmat')
     4169    % else
    41684170    flag_mask=1;
    41694171    maskname=maskfiles(1).name;% take the first mask file in the list
     
    41744176    i=ind_mask-1;
    41754177    while val(i)==0 & i>0
    4176        i=i-1;
     4178        i=i-1;
    41774179    end
    41784180    nbslice=str2num(Name(i+1:ind_mask-1));
    41794181    if ~isequal(nbslice,[]) & Name(i)=='_'
    4180           flag_mask=1;
     4182        flag_mask=1;
    41814183    else
    4182           msgbox_uvmat('ERROR',['bad mask file ' Name ext ' found in ' Path2])
    4183           return
    4184           nbslice=1;
    4185     end
    4186 end   
     4184        msgbox_uvmat('ERROR',['bad mask file ' Name ext ' found in ' Path2])
     4185        return
     4186        nbslice=1;
     4187    end
     4188end
    41874189
    41884190%------------------------------------------------------------------------
     
    42064208    i=ind_mask-1;
    42074209    while val(i)==0 & i>0
    4208        i=i-1;
     4210        i=i-1;
    42094211    end
    42104212    nbslice=str2num(Name(i+1:ind_mask-1));
    42114213    if ~isequal(nbslice,[]) & Name(i)=='_'
    4212           flag_mask=1;
     4214        flag_mask=1;
    42134215    else
    4214           msgbox_uvmat('ERROR',['bad grid file ' Name ext ' found in ' Path2])
    4215           return
    4216           nbslice=1;
     4216        msgbox_uvmat('ERROR',['bad grid file ' Name ext ' found in ' Path2])
     4217        return
     4218        nbslice=1;
    42174219    end
    42184220end
     
    42864288testgrid=0;
    42874289if value
    4288         filebase=get(handles.RootName,'String');
     4290    filebase=get(handles.RootName,'String');
    42894291    [nbslice, flag_grid]=get_grid(filebase,handles);
    42904292    if isequal(flag_grid,1)
    4291        filegrid=[num2str(nbslice) 'grid'];
    4292        testgrid=1;
    4293     else   
     4293        filegrid=[num2str(nbslice) 'grid'];
     4294        testgrid=1;
     4295    else
    42944296        [FileName, PathName, filterindex] = uigetfile( ...
    4295                {'*.grid', ' (*.grid)';
    4296                 '*.grid',  '.grid files '; ...
    4297                 '*.*', 'All Files (*.*)'}, ...
    4298                 'Pick a file',filebase);
     4297            {'*.grid', ' (*.grid)';
     4298            '*.grid',  '.grid files '; ...
     4299            '*.*', 'All Files (*.*)'}, ...
     4300            'Pick a file',filebase);
    42994301        filegrid=fullfile(PathName,FileName);
    43004302        if ~(isempty(FileName)||isempty(PathName)||isequal(FileName,0)||~exist(filegrid,'file'))
    43014303            testgrid=1;
    43024304        end
    4303     end       
     4305    end
    43044306end
    43054307if testgrid
    4306         set(handles.browse_gridciv2,'Value',1)
    4307         set(handles.get_gridpatch1,'Value',1)
    4308         set(handles.get_gridpatch2,'Value',1)
    4309         set(handles.dx_civ1,'Visible','off');
    4310         set(handles.dy_civ1,'Visible','off');
    4311         set(handles.dx_civ2,'Visible','off');
    4312         set(handles.dy_civ2,'Visible','off');
    4313         set(handles.grid_civ1,'String',filegrid)     
    4314         set(handles.grid_patch1,'String',filegrid)
    4315         set(handles.grid_civ2,'String',filegrid)
    4316         set(handles.grid_patch2,'String',filegrid)
    4317     else
    4318         set(handles.browse_gridciv1,'Value',0);
    4319         set(handles.browse_gridciv2,'Value',0);
    4320         set(handles.get_gridpatch1,'Value',0)
    4321         set(handles.get_gridpatch2,'Value',0)
    4322         set(handles.dx_civ1,'Visible','on');
    4323         set(handles.dy_civ1,'Visible','on');
    4324         set(handles.dx_civ2,'Visible','on');
    4325         set(handles.dy_civ2,'Visible','on');
    4326         set(handles.grid_civ1,'String','')     
    4327         set(handles.grid_patch1,'String','')
    4328         set(handles.grid_civ2,'String','')
    4329         set(handles.grid_patch2,'String','')
     4308    set(handles.browse_gridciv2,'Value',1)
     4309    set(handles.get_gridpatch1,'Value',1)
     4310    set(handles.get_gridpatch2,'Value',1)
     4311    set(handles.dx_civ1,'Visible','off');
     4312    set(handles.dy_civ1,'Visible','off');
     4313    set(handles.dx_civ2,'Visible','off');
     4314    set(handles.dy_civ2,'Visible','off');
     4315    set(handles.grid_civ1,'String',filegrid)
     4316    set(handles.grid_patch1,'String',filegrid)
     4317    set(handles.grid_civ2,'String',filegrid)
     4318    set(handles.grid_patch2,'String',filegrid)
     4319else
     4320    set(handles.browse_gridciv1,'Value',0);
     4321    set(handles.browse_gridciv2,'Value',0);
     4322    set(handles.get_gridpatch1,'Value',0)
     4323    set(handles.get_gridpatch2,'Value',0)
     4324    set(handles.dx_civ1,'Visible','on');
     4325    set(handles.dy_civ1,'Visible','on');
     4326    set(handles.dx_civ2,'Visible','on');
     4327    set(handles.dy_civ2,'Visible','on');
     4328    set(handles.grid_civ1,'String','')
     4329    set(handles.grid_patch1,'String','')
     4330    set(handles.grid_civ2,'String','')
     4331    set(handles.grid_patch2,'String','')
    43304332end
    43314333
     
    43364338value=get(handles.browse_gridciv2,'Value');
    43374339if value
    4338         filebase=get(handles.RootName,'String');
     4340    filebase=get(handles.RootName,'String');
    43394341    [nbslice, flag_grid]=get_grid(filebase,handles);
    43404342    if isequal(flag_grid,1)
     
    43434345        set(handles.dx_civ2,'Visible','off');
    43444346        set(handles.dy_civ2,'Visible','off');
    4345     else   
     4347    else
    43464348        [FileName, PathName, filterindex] = uigetfile( ...
    4347                {'*.grid', ' (*.grid)';
    4348                 '*.grid',  '.grid files '; ...
    4349                 '*.*', 'All Files (*.*)'}, ...
    4350                 'Pick a file',filebase);
     4349            {'*.grid', ' (*.grid)';
     4350            '*.grid',  '.grid files '; ...
     4351            '*.*', 'All Files (*.*)'}, ...
     4352            'Pick a file',filebase);
    43514353        filegrid=fullfile(PathName,FileName);
    43524354        if isempty(FileName)|isempty(PathName)|isequal(FileName,0)|~exist(filegrid,'file')
     
    43654367else
    43664368    set(handles.grid_civ2,'string','');
    4367         set(handles.dx_civ2,'Visible','on');
    4368         set(handles.dy_civ2,'Visible','on');
    4369         set(handles.grid_civ2,'string','');
     4369    set(handles.dx_civ2,'Visible','on');
     4370    set(handles.dy_civ2,'Visible','on');
     4371    set(handles.grid_civ2,'string','');
    43704372end
    43714373
    43724374% % --- Executes on button press in browse_gridciv2.
    43734375% function browse_gridciv2_Callback(hObject, eventdata, handles)
    4374 % 
     4376%
    43754377% filebase=get(handles.RootName,'String');
    43764378% [FileName, PathName, filterindex] = uigetfile( ...
     
    43934395filebase=get(handles.RootName,'String');
    43944396[FileName, PathName, filterindex] = uigetfile( ...
    4395        {'*.grid', ' (*.grid)';
    4396         '*.grid',  '.grid files '; ...
    4397         '*.*', 'All Files (*.*)'}, ...
    4398         'Pick a file',filebase);
     4397    {'*.grid', ' (*.grid)';
     4398    '*.grid',  '.grid files '; ...
     4399    '*.*', 'All Files (*.*)'}, ...
     4400    'Pick a file',filebase);
    43994401filegrid=fullfile(PathName,FileName);
    44004402set(handles.grid_patch1,'string',filegrid);
     
    45084510set(handles.nx_patch1_title,'Visible','on')
    45094511set(handles.ny_patch1_title,'Visible','on')
    4510 % if ~isempty(patch_newBin) 
     4512% if ~isempty(patch_newBin)
    45114513%     set(handles.test_interp,'Visible','on');
    45124514% end
     
    45784580    set(handles.MaxIma2,'Visible','off')
    45794581    set(handles.ImaThreshold2,'Value',0)
    4580     if isequal(get(handles.FIX2,'Value'),0) & isequal(get(handles.PATCH2,'Value'),0) 
     4582    if isequal(get(handles.FIX2,'Value'),0) & isequal(get(handles.PATCH2,'Value'),0)
    45814583        set(handles.list_pair_civ2,'Visible','off')
    45824584        set(handles.subdir_civ2,'Visible','off')
     
    46404642set(handles.inf_sup2,'Visible','off')
    46414643set(handles.field_ref2,'Visible','off')
    4642 if isequal(get(handles.CIV2,'Value'),0) & isequal(get(handles.PATCH2,'Value'),0) 
     4644if isequal(get(handles.CIV2,'Value'),0) & isequal(get(handles.PATCH2,'Value'),0)
    46434645    set(handles.list_pair_civ2,'Visible','off')
    46444646    set(handles.subdir_civ2,'Visible','off')
     
    46824684set(handles.get_gridpatch2,'Visible','off')
    46834685set(handles.grid_patch2,'Visible','off')
    4684 if isequal(get(handles.CIV2,'Value'),0) & isequal(get(handles.FIX2,'Value'),0) 
     4686if isequal(get(handles.CIV2,'Value'),0) & isequal(get(handles.FIX2,'Value'),0)
    46854687    set(handles.list_pair_civ2,'Visible','off')
    46864688    set(handles.subdir_civ2,'Visible','off')
     
    47194721par.shifty=get(handles.shifty,'String');
    47204722if isempty(str2num(par.isx))
    4721          par.isx='41';%default
    4722          set(handles.isx,'String','41');
     4723    par.isx='41';%default
     4724    set(handles.isx,'String','41');
    47234725end
    47244726if isempty(str2num(par.isy))
    4725          par.isy='41'; %default
    4726          set(handles.isy,'String','41');
     4727    par.isy='41'; %default
     4728    set(handles.isy,'String','41');
    47274729end
    47284730if isempty(str2num(par.shiftx))
    4729          par.shiftx='0';%default
    4730          set(handles.shiftx,'String','0');
    4731 end 
     4731    par.shiftx='0';%default
     4732    set(handles.shiftx,'String','0');
     4733end
    47324734if isempty(str2num(par.shifty))
    4733          par.shifty='0'; %default
    4734          set(handles.shifty,'String','0');
    4735 end
    4736  par.rho=get(handles.rho,'String');
    4737  par.dx=get(handles.dx_civ1,'String');
    4738  par.dy=get(handles.dy_civ1,'String');
    4739  if isequal(str2num(par.dx),[])
    4740      if isempty(get(handles.grid_civ1,'String'));
    4741          par.dx='0'; %just read by civ program, not used
    4742      else
     4735    par.shifty='0'; %default
     4736    set(handles.shifty,'String','0');
     4737end
     4738par.rho=get(handles.rho,'String');
     4739par.dx=get(handles.dx_civ1,'String');
     4740par.dy=get(handles.dy_civ1,'String');
     4741if isequal(str2num(par.dx),[])
     4742    if isempty(get(handles.grid_civ1,'String'));
     4743        par.dx='0'; %just read by civ program, not used
     4744    else
    47434745        par.dx='20';%default
    47444746        set(handles.dx_civ1,'String','20');
    4745      end
    4746  end
    4747  if isequal(str2num(par.dy),[])
    4748      if isempty(get(handles.grid_civ1,'String'));
    4749          par.dy='0';%just read by civ program, not used
    4750      else
     4747    end
     4748end
     4749if isequal(str2num(par.dy),[])
     4750    if isempty(get(handles.grid_civ1,'String'));
     4751        par.dy='0';%just read by civ program, not used
     4752    else
    47514753        par.dy='20';%default
    47524754        set(handles.dy_civ1_title,'String','20');
    4753      end
    4754  end
    4755     par.pxcmx='1'; %velocities are expressed in pixel dispalcement
    4756      par.pxcmy='1';
     4755    end
     4756end
     4757par.pxcmx='1'; %velocities are expressed in pixel dispalcement
     4758par.pxcmy='1';
    47574759%      end
    4758  A=imread(file_ima);%read the first image to get the size
    4759  sizim=size(A);
    4760  par.npx=num2str(sizim(2));
    4761  par.npy=num2str(sizim(1));
    4762  time=get(handles.RootName,'UserData'); %get the set of times
    4763  par.gridname=get(handles.grid_civ1,'String');
    4764  par.gridflag='y';
    4765  if isequal(par.gridname,'')| isempty(par.gridname)
    4766      par.gridname='nogrid';
    4767      par.gridflag='n';
    4768  end
     4760A=imread(file_ima);%read the first image to get the size
     4761sizim=size(A);
     4762par.npx=num2str(sizim(2));
     4763par.npy=num2str(sizim(1));
     4764time=get(handles.RootName,'UserData'); %get the set of times
     4765par.gridname=get(handles.grid_civ1,'String');
     4766par.gridflag='y';
     4767if isequal(par.gridname,'')| isempty(par.gridname)
     4768    par.gridname='nogrid';
     4769    par.gridflag='n';
     4770end
    47694771
    47704772%------------------------------------------------------------------------
     
    47784780par.dx=get(handles.dx_civ2,'String');
    47794781par.dy=get(handles.dy_civ2,'String');
    4780 if isequal(str2num(par.dx),[]) 
    4781      if isempty(get(handles.grid_civ2,'String'));
    4782          par.dx='0'; %just read by civ program, not used
    4783      else
     4782if isequal(str2num(par.dx),[])
     4783    if isempty(get(handles.grid_civ2,'String'));
     4784        par.dx='0'; %just read by civ program, not used
     4785    else
    47844786        par.dx='20';%default
    47854787        set(handles.dx_civ2,'String','20');
    4786      end
    4787  end
    4788  if isequal(str2num(par.dy),[])
    4789      if isempty(get(handles.grid_civ2,'String'));
    4790          par.dy='0';%just read by civ program, not used
    4791      else
     4788    end
     4789end
     4790if isequal(str2num(par.dy),[])
     4791    if isempty(get(handles.grid_civ2,'String'));
     4792        par.dy='0';%just read by civ program, not used
     4793    else
    47924794        par.dy='20';%default
    47934795        set(handles.dy_civ2,'String','20');
    4794      end
    4795  end
    4796  par.pxcmx='1';
    4797  par.pxcmy='1';
     4796    end
     4797end
     4798par.pxcmx='1';
     4799par.pxcmy='1';
    47984800A=imread(file_ima);%read the first image to get the size
    47994801sizim=size(A);
     
    48164818%changes : filename_cmx -> filename ( no extension )
    48174819
    4818             if isequal(par.Dt,'0')
    4819                 par.Dt='1' ;%case of 'displacement' mode
    4820             end         
    4821 % 
     4820if isequal(par.Dt,'0')
     4821    par.Dt='1' ;%case of 'displacement' mode
     4822end
     4823%
    48224824%     textcmx={'##############   CMX file';...
    48234825%     ['FirstImage ' par.filename_ima_a];...
     
    48504852%     ['ImageToUse ' par.term_a ' ' par.term_b];... % VERIFIER ?
    48514853%     'ImageUsedBefore null null'};
    4852 % 
     4854%
    48534855%             textout=char(textcmx);
    48544856par.filename_ima_a=regexprep(par.filename_ima_a,'.png','');
     
    48564858fid=fopen([filename '.cmx'],'w');
    48574859fprintf(fid,['##############   CMX file' '\n' ]);
    4858  fprintf(fid,   ['FirstImage ' regexprep(par.filename_ima_a,'\\','\\\\') '\n' ]);% for windows compatibility
    4859  fprintf(fid,   ['LastImage  ' regexprep(par.filename_ima_b,'\\','\\\\') '\n' ]);% for windows compatibility
    4860   fprintf(fid,  ['XX' '\n' ]);
    4861   fprintf(fid,  ['Mask ' par.maskflag '\n' ]);
    4862   fprintf(fid,  ['MaskName ' regexprep(par.maskname,'\\','\\\\') '\n' ]);
    4863  fprintf(fid,   ['ImageSize ' par.npx ' ' par.npy '\n' ]);   %VERIFIER CAS GENERAL ?
    4864  fprintf(fid,   ['CorrelationBoxesSize ' par.ibx ' ' par.iby '\n' ]);
    4865  fprintf(fid,   ['SearchBoxeSize ' par.isx ' ' par.isy '\n' ]);
    4866  fprintf(fid,   ['RO ' par.rho '\n' ]);
    4867  fprintf(fid,   ['GridSpacing ' par.dx ' ' par.dy '\n' ]);
    4868  fprintf(fid,   ['XX 1.0' '\n' ]);
    4869  fprintf(fid,   ['Dt_TO ' par.Dt ' ' par.T0 '\n' ]);
    4870   fprintf(fid,  ['PixCmXY ' par.pxcmx ' ' par.pxcmy '\n' ]);
    4871   fprintf(fid,  ['XX 1' '\n' ]);
    4872  fprintf(fid,   ['ShiftXY ' par.shiftx ' '  par.shifty '\n' ]);
    4873   fprintf(fid,  ['Grid ' par.gridflag '\n' ]);
    4874  fprintf(fid,   ['GridName ' regexprep(par.gridname,'\\','\\\\') '\n' ]);
    4875  fprintf(fid,   ['XX 85' '\n' ]);
    4876  fprintf(fid,   ['XX 1.0' '\n' ]);
    4877  fprintf(fid,   ['XX 1.0' '\n' ]);
    4878  fprintf(fid,   ['Hart 1' '\n' ]);
    4879  fprintf(fid,  [ 'DecimalShift 0' '\n' ]);
    4880  fprintf(fid,   ['Deformation 0' '\n' ]);
    4881   fprintf(fid,  ['CorrelationMin 0' '\n' ]);
    4882  fprintf(fid,   ['IntensityMin 0' '\n' ]);
    4883   fprintf(fid,  ['SeuilImage n' '\n' ]);
    4884  fprintf(fid,   ['SeuilImageValues 0 4096' '\n' ]);
    4885  fprintf(fid,   ['ImageToUse ' par.term_a ' ' par.term_b '\n' ]); % VERIFIER ?
    4886  fprintf(fid,   ['ImageUsedBefore null null' '\n' ]);
     4860fprintf(fid,   ['FirstImage ' regexprep(par.filename_ima_a,'\\','\\\\') '\n' ]);% for windows compatibility
     4861fprintf(fid,   ['LastImage  ' regexprep(par.filename_ima_b,'\\','\\\\') '\n' ]);% for windows compatibility
     4862fprintf(fid,  ['XX' '\n' ]);
     4863fprintf(fid,  ['Mask ' par.maskflag '\n' ]);
     4864fprintf(fid,  ['MaskName ' regexprep(par.maskname,'\\','\\\\') '\n' ]);
     4865fprintf(fid,   ['ImageSize ' par.npx ' ' par.npy '\n' ]);   %VERIFIER CAS GENERAL ?
     4866fprintf(fid,   ['CorrelationBoxesSize ' par.ibx ' ' par.iby '\n' ]);
     4867fprintf(fid,   ['SearchBoxeSize ' par.isx ' ' par.isy '\n' ]);
     4868fprintf(fid,   ['RO ' par.rho '\n' ]);
     4869fprintf(fid,   ['GridSpacing ' par.dx ' ' par.dy '\n' ]);
     4870fprintf(fid,   ['XX 1.0' '\n' ]);
     4871fprintf(fid,   ['Dt_TO ' par.Dt ' ' par.T0 '\n' ]);
     4872fprintf(fid,  ['PixCmXY ' par.pxcmx ' ' par.pxcmy '\n' ]);
     4873fprintf(fid,  ['XX 1' '\n' ]);
     4874fprintf(fid,   ['ShiftXY ' par.shiftx ' '  par.shifty '\n' ]);
     4875fprintf(fid,  ['Grid ' par.gridflag '\n' ]);
     4876fprintf(fid,   ['GridName ' regexprep(par.gridname,'\\','\\\\') '\n' ]);
     4877fprintf(fid,   ['XX 85' '\n' ]);
     4878fprintf(fid,   ['XX 1.0' '\n' ]);
     4879fprintf(fid,   ['XX 1.0' '\n' ]);
     4880fprintf(fid,   ['Hart 1' '\n' ]);
     4881fprintf(fid,  [ 'DecimalShift 0' '\n' ]);
     4882fprintf(fid,   ['Deformation 0' '\n' ]);
     4883fprintf(fid,  ['CorrelationMin 0' '\n' ]);
     4884fprintf(fid,   ['IntensityMin 0' '\n' ]);
     4885fprintf(fid,  ['SeuilImage n' '\n' ]);
     4886fprintf(fid,   ['SeuilImageValues 0 4096' '\n' ]);
     4887fprintf(fid,   ['ImageToUse ' par.term_a ' ' par.term_b '\n' ]); % VERIFIER ?
     4888fprintf(fid,   ['ImageUsedBefore null null' '\n' ]);
    48874889fclose(fid);
    4888  
     4890
    48894891cmd_CIV1=[sparam.Civ1Bin ' -f ' filename '.cmx' ]; % redirect standard output to the log file
    48904892cmd_CIV1=regexprep(cmd_CIV1,'\\','\\\\');
     
    49064908%global CivBin%name of the executable for civ1 calculation
    49074909
    4908     civ1.image1=par.filename_ima_a;
    4909     civ1.image2=par.filename_ima_b;
    4910     civ1.imageSize_X=par.npx;
    4911     civ1.imageSize_Y=par.npy;
    4912     civ1.outputFileName=[filename '.nc'];
    4913     civ1.correlationBoxesSize_X=par.ibx;
    4914     civ1.correlationBoxesSize_Y=par.iby;
    4915     civ1.searchBoxesSize_X=par.isx;
    4916     civ1.searchBoxesSize_Y=par.isy;
    4917     civ1.globalShift_X=par.shiftx;
    4918     civ1.globalShift_Y=par.shifty;
    4919     civ1.ro=par.rho;
    4920     civ1.hart='y';
    4921     if isequal(par.gridflag,'y')
    4922         civ1.grid=par.gridname;
    4923     else
    4924         civ1.grid='n';
    4925         civ1.gridSpacing_X=par.dx;
    4926         civ1.gridSpacing_Y=par.dy;
    4927     end
    4928     if isequal(par.maskflag,'y')
    4929         civ1.mask=par.maskname;
    4930     end
    4931     civ1.dt=par.Dt;
    4932     civ1.unit='pixel';
    4933     civ1.absolut_time_T0=par.T0;
    4934     civ1.pixcmx=par.pxcmx;
    4935     civ1.pixcmy=par.pxcmy;
    4936     civ1.convectFlow='n';
    4937  
    4938     xml_civ1_parameters=civ1;
     4910civ1.image1=par.filename_ima_a;
     4911civ1.image2=par.filename_ima_b;
     4912civ1.imageSize_X=par.npx;
     4913civ1.imageSize_Y=par.npy;
     4914civ1.outputFileName=[filename '.nc'];
     4915civ1.correlationBoxesSize_X=par.ibx;
     4916civ1.correlationBoxesSize_Y=par.iby;
     4917civ1.searchBoxesSize_X=par.isx;
     4918civ1.searchBoxesSize_Y=par.isy;
     4919civ1.globalShift_X=par.shiftx;
     4920civ1.globalShift_Y=par.shifty;
     4921civ1.ro=par.rho;
     4922civ1.hart='y';
     4923if isequal(par.gridflag,'y')
     4924    civ1.grid=par.gridname;
     4925else
     4926    civ1.grid='n';
     4927    civ1.gridSpacing_X=par.dx;
     4928    civ1.gridSpacing_Y=par.dy;
     4929end
     4930if isequal(par.maskflag,'y')
     4931    civ1.mask=par.maskname;
     4932end
     4933civ1.dt=par.Dt;
     4934civ1.unit='pixel';
     4935civ1.absolut_time_T0=par.T0;
     4936civ1.pixcmx=par.pxcmx;
     4937civ1.pixcmy=par.pxcmy;
     4938civ1.convectFlow='n';
     4939
     4940xml_civ1_parameters=civ1;
    49394941
    49404942%------------------------------------------------------------------------
     
    49474949civ2.image1=par.filename_ima_a;
    49484950civ2.image2=par.filename_ima_b;
    4949 civ2.imageSize_X=par.npx; 
     4951civ2.imageSize_X=par.npx;
    49504952civ2.imageSize_Y=par.npy;
    49514953civ2.inputFileName=[par.filename_nc1 '.nc'];
     
    49964998%pixels per cm and matrix of the image times, read from the .civ file by uvmat
    49974999% global civ2Bin sge%name of the executable for civ1 calculation
    4998    if isequal(par.Dt,'0')
    4999                 par.Dt='1' ;%case of 'displacement' mode
    5000   end
     5000if isequal(par.Dt,'0')
     5001    par.Dt='1' ;%case of 'displacement' mode
     5002end
    50015003% textcmx=['##############   CMX file'  '\n'...
    50025004% ['FirstImage ' par.filename_ima_a]  '\n'...
     
    50055007% ['Mask ' par.maskflag]  '\n'...
    50065008% ['MaskName ' par.maskname]  '\n'...
    5007 % ['ImageSize ' par.npx ' ' par.npy]  '\n'...   
     5009% ['ImageSize ' par.npx ' ' par.npy]  '\n'...
    50085010% ['CorrelationBoxesSize ' par.ibx ' ' par.iby]  '\n'...
    50095011% ['SearchBoxeSize ' par.ibx ' ' par.iby]  '\n'...
     
    50315033% textout=char(textcmx);
    50325034% fid=fopen([filename_cmx '2'],'w');
    5033 % fprintf(fid,textout); 
     5035% fprintf(fid,textout);
    50345036% fclose(fid)
    50355037
    50365038par.filename_ima_a=regexprep(par.filename_ima_a,'.png','');
    50375039par.filename_ima_b=regexprep(par.filename_ima_b,'.png','');% bug : .png appears two times ?
    5038 fid=fopen([filename_cmx '2'],'w'); 
     5040fid=fopen([filename_cmx '2'],'w');
    50395041fprintf(fid,['##############   CMX file' '\n' ]);
    50405042fprintf(fid,   ['FirstImage ' regexprep(par.filename_ima_a,'\\','\\\\') '\n' ]);% for windows compatibility
     
    50825084else
    50835085    addpath (fullfile(pathelp,'uvmat_doc'))
    5084     web([helpfile '#civ'])   
     5086    web([helpfile '#civ'])
    50855087end
    50865088
     
    50945096        A=read(movieobject,num);
    50955097    case 'avi'
    5096        mov=aviread(filename,num);     
    5097        A=frame2im(mov(1));
     5098        mov=aviread(filename,num);
     5099        A=frame2im(mov(1));
    50985100    case 'multimage'
    50995101        A=imread(filename,num);
    5100     case 'image'   
     5102    case 'image'
    51015103        A=imread(filename);
    51025104end
     
    51155117find_netcpair_civ1(hObject, eventdata, handles);% update the menu of pairs depending on the available netcdf files
    51165118if isequal(mode,'series(Di)') || ...% we do patch2 only
    5117    (get(handles.CIV2,'Value')==0 && get(handles.CIV1,'Value')==0 && get(handles.FIX1,'Value')==0 && get(handles.PATCH1,'Value')==0)
     5119        (get(handles.CIV2,'Value')==0 && get(handles.CIV1,'Value')==0 && get(handles.FIX1,'Value')==0 && get(handles.PATCH1,'Value')==0)
    51185120    find_netcpair_civ2(hObject, eventdata, handles);
    51195121end
     
    51255127mode_value=get(handles.mode,'Value');
    51265128mode=mode_list{mode_value};
    5127 if isequal(get(handles.CIV1,'Value'),0)|| isequal(mode,'series(Dj)') 
     5129if isequal(get(handles.CIV1,'Value'),0)|| isequal(mode,'series(Dj)')
    51285130    find_netcpair_civ1(hObject, eventdata, handles);% update the menu of pairs depending on the available netcdf files
    51295131end
    51305132if isequal(mode,'series(Dj)') || ...
    5131    (get(handles.CIV2,'Value')==0 && get(handles.CIV1,'Value')==0 && get(handles.FIX1,'Value')==0 && get(handles.PATCH1,'Value')==0)
     5133        (get(handles.CIV2,'Value')==0 && get(handles.CIV1,'Value')==0 && get(handles.FIX1,'Value')==0 && get(handles.PATCH1,'Value')==0)
    51325134    find_netcpair_civ2(hObject, eventdata, handles);
    51335135end
     
    51475149mode_value=get(handles.mode,'Value');
    51485150mode=mode_list{mode_value};
    5149 if  isequal(mode,'series(Dj)') 
     5151if  isequal(mode,'series(Dj)')
    51505152    find_netcpair_civ2(hObject, eventdata, handles);% update the menu of pairs depending on the available netcdf files
    51515153end
     
    51565158%------------------------------------------------------------------------
    51575159test=get(handles.compare,'Value');
    5158 if test==2 || test==3   
     5160if test==2 || test==3
    51595161    filebase=get(handles.RootName,'String');
    51605162    browse=get(handles.browse_root,'Userdata');
     
    51625164    set(handles.browse_root,'UserData',browse);
    51635165    set(handles.sub_txt,'Visible','on')
    5164     set(handles.RootName_1,'Visible','On');%mkes the second file input window visible 
     5166    set(handles.RootName_1,'Visible','On');%mkes the second file input window visible
    51655167    mode_store=get(handles.mode,'String');%get the present 'mode'
    5166     set(handles.compare,'UserData',mode_store);%store the mode display 
     5168    set(handles.compare,'UserData',mode_store);%store the mode display
    51675169    set(handles.mode,'Visible','off')
    51685170    if test==2
    5169         set(handles.mode,'Visible','off')       
     5171        set(handles.mode,'Visible','off')
    51705172    else
    51715173        set(handles.mode,'Visible','on')
     
    51775179    oldfile=get(handles.RootName,'String');
    51785180    menu={'*.xml;*.avi;*.AVI;*.nc','(*.xml,*.avi,*.nc)'; ...
    5179             '*.xml', '.xml files';'*.avi;*.AVI', '.avi files';'*.nc', '.nc files';...
    5180             '*.*', 'All Files (*.*)'};
     5181        '*.xml', '.xml files';'*.avi;*.AVI', '.avi files';'*.nc', '.nc files';...
     5182        '*.*', 'All Files (*.*)'};
    51815183    [FileName, PathName, filtindex] = uigetfile( menu, 'Pick a file',oldfile);
    5182     fileinput=[PathName FileName];%complete file name 
     5184    fileinput=[PathName FileName];%complete file name
    51835185    sizf=size(fileinput);
    51845186    if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
     
    51865188    [path1]=fileparts(filebase);
    51875189    if ~strcmp(path1,path)
    5188          msgbox_uvmat('ERROR','The two  input image series must be in the same directory')
     5190        msgbox_uvmat('ERROR','The two  input image series must be in the same directory')
    51895191        return
    51905192    end
     
    51935195    browse=get(handles.browse_root,'UserData');
    51945196    browse.nom_type_ima_1=nom_type;
    5195     set(handles.browse_root,'UserData',browse) 
     5197    set(handles.browse_root,'UserData',browse)
    51965198   
    51975199    %check image extension
     
    52265228filebase=get(handles.RootName,'String');
    52275229[FileName, PathName, filterindex] = uigetfile( ...
    5228        {'*.nc', ' (*.nc)';
    5229         '*.nc',  'netcdf files '; ...
    5230         '*.*', 'All Files (*.*)'}, ...
    5231         'Pick a file',filebase);
    5232    
     5230    {'*.nc', ' (*.nc)';
     5231    '*.nc',  'netcdf files '; ...
     5232    '*.*', 'All Files (*.*)'}, ...
     5233    'Pick a file',filebase);
     5234
    52335235fileinput=[PathName FileName];
    52345236sizf=size(fileinput);
     
    52715273    filebase=get(handles.RootName,'String');
    52725274    [FileName, PathName, filterindex] = uigetfile( ...
    5273            {'*.nc', ' (*.nc)';
    5274             '*.nc',  'netcdf files '; ...
    5275             '*.*', 'All Files (*.*)'}, ...
    5276             'Pick a file',filebase);
     5275        {'*.nc', ' (*.nc)';
     5276        '*.nc',  'netcdf files '; ...
     5277        '*.*', 'All Files (*.*)'}, ...
     5278        'Pick a file',filebase);
    52775279    fileinput=[PathName FileName];
    52785280    sizf=size(fileinput);
     
    52905292    end
    52915293    set(handles.ref_fix2,'String',[fullfile(ref.subdir,File) '....nc']);
    5292     set(handles.ref_fix2,'UserData',ref)   
     5294    set(handles.ref_fix2,'UserData',ref)
    52935295    menu_field{1}='civ1';
    52945296    Data=nc2struct(fileinput,[]);
     
    53235325set(handles.ref_fix1,'String','');
    53245326set(handles.thresh_vel1,'String','0');
    5325  
     5327
    53265328%------------------------------------------------------------------------
    53275329function ref_fix2_Callback(hObject, eventdata, handles)
Note: See TracChangeset for help on using the changeset viewer.