Changeset 1059 for trunk/src


Ignore:
Timestamp:
Nov 29, 2018, 5:44:44 PM (6 years ago)
Author:
sommeria
Message:

various bugs repaired

Location:
trunk/src
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/browse_data.m

    r1039 r1059  
    2424function varargout = browse_data(varargin)
    2525
    26 % Last Modified by GUIDE v2.5 24-Jan-2015 16:55:04
     26% Last Modified by GUIDE v2.5 08-Sep-2018 19:03:40
    2727
    2828% Begin initialization code - DO NOT EDIT
     
    4747%------------------------------------------------------------------------
    4848% --- Executes just before browse_data is made visible.
    49 function browse_data_OpeningFcn(hObject, eventdata, handles, DataSeries,EnableMirror,MultiDevices)
     49function browse_data_OpeningFcn(hObject, eventdata, handles, InputDir,EnableMirror,MultiDevices)
    5050%------------------------------------------------------------------------
    5151
    5252%% Choose default command line output for browse_data
    53 handles.output = 'Cancel';
     53handles.output =hObject;% 'Cancel';
    5454
    5555%% Update handles structure
    5656guidata(hObject, handles);
    5757set(hObject,'WindowButtonDownFcn',{'mouse_down'}) % allows mouse action with right button (zoom for uicontrol display)
     58set(hObject,'DeleteFcn',{@closefcn})%
    5859
    5960%% Determine the position of the dialog - centered on the screen
     
    8788
    8889%% initialize the GUI
    89 if isempty(regexp(DataSeries,'^http:'))&& ~(exist('DataSeries','var') && ischar(DataSeries) && exist(DataSeries,'dir'))
    90     DataSeries=pwd;% current dir is the starting data series by default
    91 end
    92 [Experiment,DataSeries,Ext]=fileparts(DataSeries);
    93 DataSeries=[DataSeries Ext];
    94 [Campaign,Experiment,Ext]=fileparts(Experiment);
    95 Experiment=[Experiment Ext];
     90if isempty(regexp(InputDir,'^http:'))&& ~(exist('InputDir','var') && ischar(InputDir) && exist(InputDir,'dir'))
     91    InputDir=pwd;% current dir is the starting data series by default
     92end
     93% [Experiment,DataSeries,Ext]=fileparts(DataSeries);
     94% DataSeries=[DataSeries Ext];
     95% [Campaign,Experiment,Ext]=fileparts(Experiment);
     96% Experiment=[Experiment Ext];
     97[ExpWithPath,DataSeries]=fileparts(InputDir);
     98[Campaign,Experiment,Ext]=fileparts(ExpWithPath);
    9699[tild,CampaignName]=fileparts(Campaign);
    97100RootXml=fullfile(Campaign,[CampaignName '.xml']);
     
    111114    set(handles.CreateMirror,'String','create_mirror')
    112115end
    113 errormsg=scan_campaign(handles,Campaign,Experiment,DataSeries);
     116errormsg=scan_campaign(handles,Campaign,Experiment,ExpWithPath);
    114117if ~isempty(errormsg)
    115118    msgbox_uvmat('ERROR',errormsg)
    116119    return
    117120end
    118 set(handles.OK,'Visible','on')
    119 set(handles.Cancel,'Visible','on')
    120 
    121 set(handles.browse_data,'WindowStyle','modal')% Make the GUI modal
     121% set(handles.OK,'Visible','on')
     122% set(handles.Cancel,'Visible','on')
     123
     124%set(handles.browse_data,'WindowStyle','modal')% Make the GUI
     125%modal%%%%%%%%%%%%%%%%%%%%%%%
    122126set(hObject,'Visible','on')
    123127drawnow
    124 % UIWAIT makes GUI wait for user response (see UIRESUME)
    125 uiwait(handles.browse_data);
     128% UIWAIT makes GUI wait for user response (see UIRESUME)%%%%%%%%%%%%%%%%TO
     129% CHECK
     130%uiwait(handles.browse_data);
    126131
    127132
     
    133138% Get default command line output from handles structure
    134139varargout{1} = handles.output;
    135 delete(handles.browse_data)
     140%%%%%%%%%%%%%%%%%%delete(handles.browse_data)
    136141
    137142%------------------------------------------------------------------------
     
    213218    ListStruct=dir_uvmat(Campaign); %list files and dirs
    214219    if numel(ListStruct)>1000% A campaign folder must contain maily a list of 'experiment' sub-folders
    215         errormsg=[Campaign ' contains too many items (>1000) to be a Campaign folder'];
     220        errormsg=[Campaign ' contains too many items (>1000) to be a Project folder'];
    216221        return
    217222    end
     
    224229    ListFiles=sort((ListFiles(check_keep))');
    225230    index=find(strcmp(['+/' Experiment],ListFiles));
    226     if isempty(index), index=0; end
    227     set(handles.ListExperiments,'String',[{'*'};ListFiles])
    228     set(handles.ListExperiments,'Value',index+1)% initialise the menu selection with the folder defined by the input
     231    if isempty(index), index=1; end
     232    set(handles.ListExperiments,'String',ListFiles)
     233    set(handles.ListExperiments,'Value',index)% initialise the menu selection with the folder defined by the input
    229234    ListExperiments_Callback([],[], handles)
    230235    ListDevices=get(handles.ListDevices,'String');
     
    252257ListExperiments=get(handles.ListExperiments,'String');
    253258list_val=get(handles.ListExperiments,'Value');
    254 if isequal(list_val(1),1)
    255     ListExperiments=ListExperiments(2:end); %choose all experiments if the first line '*' is selected
    256     set(handles.ListExperiments,'Value',1)
    257 else
     259% if isequal(list_val(1),1)
     260%     ListExperiments=ListExperiments(2:end); %choose all experiments if the first line '*' is selected
     261%     set(handles.ListExperiments,'Value',1)
     262% else
    258263    ListExperiments=ListExperiments(list_val);%choose selected experiments
    259 end
     264% end
    260265list_dataseries(handles,ListExperiments,MirrorPath)
    261266
     
    283288                else %update the list of dataSeries
    284289                    [tild,msg]=fileattrib(mirror);
    285                     msg.Name=regexprep(msg.Name,'^/.','/');%remove the dot in /. at the beginning of the name
    286                     if ~strcmp(msg.Name,mirror)% if it is a link
    287                         ListFiles{ilist}=['~' ListFiles{ilist}];%mark link by '@' in the list
    288                     end
     290%                     msg.Name=regexprep(msg.Name,'^/.','/');%remove the dot in /. at the beginning of the name
     291%                     if ~strcmp(msg.Name,mirror)% if it is a link
     292%                         ListFiles{ilist}=['~' ListFiles{ilist}];%mark link by '@' in the list
     293%                     end
    289294                    if check_dir(ilist)
    290295                        ListFiles{ilist}=['+/' ListFiles{ilist}];%mark dir by '+' in the list
     
    298303    end
    299304end
     305set(handles.ListDevices,'Value',1)
    300306set(handles.ListDevices,'String',sort(ListDevices))
    301307
     
    438444save(t,outputfile)
    439445
    440 % %------------------------------------------------------------------------
    441 % % --- Executes on button press in CampaignDoc.
    442 % function edit_xml_Callback(hObject, eventdata, handles)
    443 % %------------------------------------------------------------------------
    444 % CurrentPath=get(handles.SourceDir,'String');
    445 % %[CurrentPath,Name,Ext]=fileparts(CurrentDir);
    446 % ListExperiments=get(handles.ListExperiments,'String');
    447 % Value=get(handles.ListExperiments,'Value');
    448 % if ~isequal(Value,1)
    449 %     ListExperiments=ListExperiments(Value);
    450 % end
    451 % ListDevices=get(handles.ListDevices,'String');
    452 % Value=get(handles.ListDevices,'Value');
    453 % if ~isequal(Value,1)
    454 %     ListDevices=ListDevices(Value);
    455 % end
    456 % ListRecords=get(handles.ListRecords,'String');
    457 % Value=get(handles.ListRecords,'Value');
    458 % if ~isequal(Value,1)
    459 %     ListRecords=ListRecords(Value);
    460 % end
    461 % [ListDevices,ListRecords,ListXml,List]=dir_scan(CurrentPath,ListExperiments,ListDevices,ListRecords);
    462 % ListXml=get(handles.ListXml,'String');
    463 % Value=get(handles.ListXml,'Value');
    464 % set(handles.ListXml,'Value',Value(1));
    465 % if isequal(Value(1),1)
    466 %     msgbox_uvmat('ERROR','an xml file needs to be selected')
    467 %    return
    468 % else
    469 %     XmlName=ListXml{Value(1)};
    470 % end
    471 % for iexp=1:length(List.Experiment)
    472 %     ExpName=List.Experiment{iexp}.name;
    473 %     if isfield(List.Experiment{iexp},'Device')
    474 %         for idevice=1:length(List.Experiment{iexp}.Device)
    475 %             DeviceName=List.Experiment{iexp}.Device{idevice}.name;
    476 %             if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile')
    477 %                 for ixml=1:length(List.Experiment{iexp}.Device{idevice}.xmlfile)
    478 %                     FileName=List.Experiment{iexp}.Device{idevice}.xmlfile{ixml};
    479 %                     if isequal(FileName,XmlName)
    480 %                         editxml(fullfile(CurrentPath,ExpName,DeviceName,FileName));
    481 %                         return
    482 %                     end
    483 %                 end
    484 %              elseif isfield(List.Experiment{iexp}.Device{idevice},'Record')
    485 %                 for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record)
    486 %                     RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name;
    487 %                     if isfield(List.Experiment{iexp}.Device{idevice}.Record{irecord},'xmlfile')
    488 %                         for ixml=1:length(List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile)
    489 %                             FileName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml};
    490 %                             if isequal(FileName,XmlName)
    491 %                                 editxml(fullfile(CurrentPath,ExpName,DeviceName,RecordName,FileName));
    492 %                                 return
    493 %                             end                         
    494 %                         end
    495 %                     end
    496 %                 end
    497 %             end
    498 %         end
    499 %     end
    500 % end
    501 %
    502 %
    503 %
    504 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    505 % % CurrentPath/Campaign: root directory
    506 % function  [Title,test_mod]=check_heading(Currentpath,Campaign,Experiment,Device,Record,xmlname,testSubCampaign)
    507 %
    508 %  %Shema for Heading:
    509 % %  Campaign             
    510 % %  (SubCampaign)
    511 % % Experiment
    512 % %  Device
    513 % %  (Record)
    514 % %  ImageName
    515 % %  DateExp
    516 % %                 old: %Project: suppressed ( changed to Campaign)
    517 %                        %Exp: suppressed (changed to experiment)
    518 %                        %ImaNames: changed to ImageName
    519 % if exist('Record','var') && ~isempty(Record)
    520 %     xmlfullname=fullfile(Currentpath,Campaign,Experiment,Device,Record,xmlname); 
    521 %     testrecord=1;
    522 % else
    523 %     xmlfullname=fullfile(Currentpath,Campaign,Experiment,Device,xmlname);
    524 %     testrecord=0;
    525 % end
    526 % if ~exist('testSubCampaign','var')
    527 %     testSubCampaign=0;
    528 % end
    529 % if testSubCampaign
    530 %    SubCampaign=Campaign;
    531 %    [Currentpath,Campaign,DirExt]=fileparts(Currentpath);
    532 %    Campaign=[Campaign DirExt];
    533 % end
    534 % test_mod=0; %test for the modification of the xml file
    535 % t_device=xmltree(xmlfullname);
    536 % Title=get(t_device,1,'name');
    537 % uid_child=children(t_device,1);
    538 % Heading_old=[];
    539 % uidheading=0;
    540 % for ilist=1:length(uid_child)
    541 %     name=get(t_device,uid_child(ilist),'name');
    542 %     if isequal(name,'Heading')
    543 %         uidheading=uid_child(ilist);
    544 %     end
    545 % end
    546 % if uidheading
    547 %     subt=branch(t_device,uidheading);
    548 %     Heading_old=convert(subt);
    549 % else
    550 %    return % do not edit xml files without element 'Heading'
    551 % end
    552 % if ~(isfield(Heading_old,'Campaign')&& isequal(Heading_old.Campaign,Campaign))
    553 %     test_mod=1;
    554 % end
    555 % Heading.Campaign=Campaign;
    556 % if testSubCampaign
    557 %     if ~(isfield(Heading_old,'SubCampaign')&& isequal(Heading_old.SubCampaign,SubCampaign))
    558 %         test_mod=1;
    559 %     end
    560 %     Heading.SubCampaign=SubCampaign;
    561 % end
    562 % if ~(isfield(Heading_old,'Experiment')&& isequal(Heading_old.Experiment,Experiment))
    563 %     test_mod=1;
    564 % end
    565 % Heading.Experiment=Experiment;
    566 % if ~(isfield(Heading_old,'Device')&& isequal(Heading_old.Device,Device))
    567 %     test_mod=1;
    568 % end
    569 % Heading.Device=Device;
    570 % if testrecord
    571 %     if ~(isfield(Heading_old,'Record')&& isequal(Heading_old.Record,Record))
    572 %         test_mod=1;
    573 %     end
    574 %     Heading.Record=Record;
    575 % end
    576 % if isfield(Heading_old,'ImaNames')
    577 %     test_mod=1;
    578 %     if  ~isempty(Heading_old.ImaNames)
    579 %         Heading.ImageName=Heading_old.ImaNames;
    580 %     end
    581 % end
    582 % if isfield(Heading_old,'ImageName')&& ~isempty(Heading_old.ImageName)
    583 %     Heading.ImageName=Heading_old.ImageName;
    584 % end
    585 % if isfield(Heading_old,'DateExp')&& ~isempty(Heading_old.DateExp)
    586 %     Heading.DateExp=Heading_old.DateExp;
    587 % end
    588 % if test_mod && uidheading
    589 %      uid_child=children(t_device,uidheading);
    590 %      t_device=delete(t_device,uid_child);
    591 %     t_device=struct2xml(Heading,t_device,uidheading);
    592 %     backupfile=xmlfullname;
    593 %     testexist=2;
    594 %     while testexist==2
    595 %        backupfile=[backupfile '~'];
    596 %        testexist=exist(backupfile,'file');
    597 %     end
    598 %     [success,message]=copyfile(xmlfullname,backupfile);%make backup
    599 %     if isequal(success,1)
    600 %         delete(xmlfullname)
    601 %     else
    602 %         return
    603 %     end
    604 %     save(t_device,xmlfullname)
    605 % end
     446
    606447
    607448%------------------------------------------------------------------------
     
    648489% --- Executes on button press in Cancel.
    649490%------------------------------------------------------------------------
    650 function Cancel_Callback(hObject, eventdata, handles)
    651    
    652 handles.output = get(hObject,'String');
    653 guidata(hObject, handles); % Update handles structure
    654 % Use UIRESUME instead of delete because the OutputFcn needs
    655 uiresume(handles.browse_data);
     491% function Cancel_Callback(hObject, eventdata, handles)
     492% % hseries=findobj(allchild(0),'Tag','series');
     493% % if ~isempty(hseries)
     494% %     hhh=guidata(hseries);
     495% %     set(hhh.Replicate,'Value',0)
     496% % end
     497% % delete(get(hObject,'parent'))
     498
     499% handles.output = get(hObject,'String');
     500% guidata(hObject, handles); % Update handles structure
     501% % Use UIRESUME instead of delete because the OutputFcn needs
     502% uiresume(handles.browse_data);
     503
     504%------------------------------------------------------------------------
     505% --- executes when user attempts to close geometry_calib.
     506function browse_data_CloseRequestFcn(hObject, eventdata, handles)
    656507
    657508%------------------------------------------------------------------------
    658509% --- Executes when user attempts to close browse_data.
    659510%------------------------------------------------------------------------
    660 function browse_data_CloseRequestFcn(hObject, eventdata, handles)
    661 if isequal(get(handles.browse_data, 'waitstatus'), 'waiting')
    662     % The GUI is still in UIWAIT, us UIRESUME
    663     handles.output = get(hObject,'String');
    664     guidata(hObject, handles); % Update handles structure
    665     uiresume(handles.browse_data);
    666 else
    667     % The GUI is no longer waiting, just close it
    668     delete(handles.browse_data);
     511function closefcn(gcbo, eventdata)
     512% if isequal(get(handles.browse_data, 'waitstatus'), 'waiting')
     513%     % The GUI is still in UIWAIT, us UIRESUME
     514%     handles.output = get(hObject,'String');
     515%     guidata(hObject, handles); % Update handles structure
     516%     uiresume(handles.browse_data);
     517% else
     518%     % The GUI is no longer waiting, just close it
     519%     delete(handles.browse_data);
     520% end
     521hseries=findobj(allchild(0),'Tag','series');
     522if ~isempty(hseries)
     523    hreplicate=findobj(hseries,'Tag','Replicate');
     524    set(hreplicate,'Value',0)
     525end
     526hcalib=findobj(allchild(0),'Tag','geometry_calib');
     527if ~isempty(hcalib)
     528    hreplicate=findobj(hcalib,'Tag','Replicate');
     529    set(hreplicate,'Value',0)
    669530end
    670531
     
    689550
    690551
    691 % --- Executes on button press in Browse.
    692 function Browse_Callback(hObject, eventdata, handles)
     552% --- Executes on button press in Up.
     553function Up_Callback(hObject, eventdata, handles)
     554SourceDir=get(handles.SourceDir,'String');
     555% Device=ListDevices{get(handles.ListDevices,'Value')};
     556% DataSeries=uigetfile_uvmat('open a data folder',Device,'uigetdir');
     557% uiresume(handles.browse_data);
     558browse_data(SourceDir)
     559
     560
     561% --- Executes on button press in Down.
     562function Down_Callback(hObject, eventdata, handles)
     563SourceDir=get(handles.SourceDir,'String');
     564ListExperiments=get(handles.ListExperiments,'String');
     565list_val=get(handles.ListExperiments,'Value');
     566SourceFolder=regexprep(ListExperiments{list_val(1)},'+','');
     567set(handles.SourceDir,'String',fullfile(SourceDir,SourceFolder))
    693568ListDevices=get(handles.ListDevices,'String');
    694 Device=ListDevices{get(handles.ListDevices,'Value')};
    695 DataSeries=uigetfile_uvmat('open a data folder',Device,'uigetdir');
    696 uiresume(handles.browse_data);
    697 browse_data(DataSeries)
     569ValueDevice=get(handles.ListDevices,'Value');
     570set(handles.ListExperiments,'String',ListDevices)
     571set(handles.ListExperiments,'Value',ValueDevice)
     572ListExperiments_Callback(hObject, [], handles)
     573% Device=regexprep(ListDevices{get(handles.ListDevices,'Value')},'+','');
     574% Device=regexprep(Device,'~','');
     575% PathDevice=fullfile(SourceDir,SourceFolder,Device);
     576% DirDevice=dir(PathDevice);
     577% NewDevice=DirDevice(end).name;
     578% % uiresume(handles.browse_data);
     579% browse_data(fullfile(PathDevice,NewDevice))
  • trunk/src/filter_tps.m

    r1027 r1059  
    7979%% calculate tps coeff in each subdomain
    8080for isub=1:NbSubDomain
     81    isub
    8182    SubRange(1,:,isub)=[CentreX(isub)-0.55*Siz(1) CentreX(isub)+0.55*Siz(1)];%bounds of subdomain #isub in x coordinate
    8283    SubRange(2,:,isub)=[CentreY(isub)-0.55*Siz(2) CentreY(isub)+0.55*Siz(2)];%bounds of subdomain #isub in y coordinate
     
    8788        ind_sel_previous=ind_sel;% record the set of selected vector indices for next iteration
    8889        ind_sel=find(Coord(:,1)>=SubRange(1,1,isub) & Coord(:,1)<=SubRange(1,2,isub) & Coord(:,2)>=SubRange(2,1,isub) & Coord(:,2)<=SubRange(2,2,isub));
     90        numel(ind_sel)
    8991        % if no vector in the subdomain  #isub, skip the subdomain
    9092        if isempty(ind_sel)
  • trunk/src/geometry_calib.m

    r1027 r1059  
    5252% Edit the above text to modify the response to help geometry_calib
    5353
    54 % Last Modified by GUIDE v2.5 16-Apr-2015 17:29:02
     54% Last Modified by GUIDE v2.5 20-Sep-2018 19:04:30
    5555
    5656% Begin initialization code - DO NOT edit
     
    108108set(handles.calib_type,'Position',[1 Height-40 194 30])%  rank 1
    109109set(handles.APPLY,'Position',[197 Height-40 110 30])%  rank 1
    110 set(handles.REPLICATE,'Position',[309 Height-40 110 30])%  rank 1
     110set(handles.Replicate,'Position',[309 Height-40 110 30])%  rank 1
    111111set(handles.Intrinsic,'Position',[1 Height-40-2-92 418 92])%  rank 2
    112112set(handles.Extrinsic,'Position',[1 Height-40-4-92-75 418 75])%  rank 3
     
    167167%------------------------------------------------------------------------
    168168% --- Executes on button press APPLY (used to launch the calibration).
    169 function APPLY_Callback(hObject, eventdata, handles)
     169    function APPLY_Callback(hObject, eventdata, handles)
     170        set(handles.CheckEnableMouse,'Value',0)% desactivate mouse (to avoid spurious creation of new points)
     171       
     172        %------------------------------------------------------------------------
     173        %% look for the GUI uvmat and check for an image as input
     174        set(handles.APPLY,'BackgroundColor',[1 1 0])% paint APPLY button in yellow to show activation
     175        huvmat=findobj(allchild(0),'Name','uvmat');% look for the GUI uvmat
     176        hhuvmat=guidata(huvmat);%handles of elements in the GUI uvmat
     177        if ~strcmp(get(hhuvmat.Scalar,'Visible'),'on')
     178            msgbox_uvmat('ERROR','An image needs to be opened in uvmat for calibration')
     179            return
     180        end
     181       
     182        RootPath='';
     183        if ~isempty(hhuvmat.RootPath)&& ~isempty(hhuvmat.RootFile)
     184            RootPath=get(hhuvmat.RootPath,'String');% path to the currently displayed image
     185            SubDirBase=regexprep(get(hhuvmat.SubDir,'String'),'\..+$','');
     186            outputfile=[fullfile(RootPath,SubDirBase) '.xml'];%xml file associated with the currently displayed image
     187        else
     188            question={'save the calibration data and point coordinates in'};
     189            def={fullfile(RootPath,'ObjectCalib.xml')};
     190            options.Resize='on';
     191            answer=inputdlg(question,'',1,def,options);
     192            outputfile=answer{1};
     193        end
     194       
     195        %% read coordinates of the calibration poinnts: Coord(:,1-3) in phys, Coord(:,4-5) image
     196        Coord=get(handles.ListCoord,'Data');
     197       
     198       
     199        %% read the type of calibration
     200        calib_cell=get(handles.calib_type,'String');
     201        val=get(handles.calib_type,'Value');
     202        CalibFcn=['calib_' calib_cell{val}];
     203       
     204        %% read the intrinsic parameters
     205        Intrinsic.Npx=str2num(get(hhuvmat.num_Npx,'String'));
     206        Intrinsic.Npy=str2num(get(hhuvmat.num_Npy,'String'));
     207        Intrinsic.coord_files=get(handles.ListCoordFiles,'String');
     208        Intrinsic.fx=str2num(get(handles.fx,'String'));
     209        Intrinsic.fy=str2num(get(handles.fy,'String'));
     210        Intrinsic.kc=str2num(get(handles.kc,'String'));
     211        Intrinsic.Cx=str2num(get(handles.Cx,'String'));
     212        Intrinsic.Cy=str2num(get(handles.Cy,'String'));
     213        if isempty(Intrinsic.kc)
     214            Intrinsic.kc=0;
     215        end
     216        if isempty(Intrinsic.Cx)||isempty(Intrinsic.Cy)
     217            Intrinsic.Cx=Intrinsic.Npx/2;
     218            Intrinsic.Cy=Intrinsic.Npy/2;
     219        end
     220       
     221        %% apply to cropped images if requested
     222        if get(handles.Replicate,'Value')
     223            answer=msgbox_uvmat('INPUT_Y-N','apply to full images (not cropped)?');
     224            if strcmp(answer,'No')
     225                prompt = {'npy_lower'};
     226                dlg_title = 'remove image the npy_lower image lines (removal of the upper line does not change calibration)';
     227                num_lines= 1;
     228                def     = {'0'};
     229                answer = inputdlg(prompt,dlg_title,num_lines,def);
     230                npy_crop=str2num(answer{1});
     231                Intrinsic.Npy=Intrinsic.Npy-npy_crop; %size of the filtering window
     232                Coord(:,5)=Coord(:,5)-npy_crop;% shift the image ordinates of the calibration points by removing the lower band
     233            end
     234        end
     235       
     236        %% Apply calibration
     237        [GeometryCalib,index,ind_removed,Z_plane]=calibrate(Coord,CalibFcn,Intrinsic);% apply calibration
     238       
     239        %% record the coordinate unit
     240        unitlist=get(handles.CoordUnit,'String');
     241        unit=unitlist{get(handles.CoordUnit,'value')};
     242        GeometryCalib.CoordUnit=unit;
     243       
     244        %% record the coordinates of the calibration points
     245        GeometryCalib.SourceCalib.PointCoord=Coord;
     246       
     247        %% display calibration results on the GUI geometry_calib
     248        display_intrinsic(GeometryCalib,handles)%display calibration intrinsic parameters
     249        display_extrinsic(GeometryCalib,handles)%display calibration extrinsic parameters
     250        %     (rotation and translation of camera with  respect to the phys coordinates)
     251       
     252        %% set the defqult plane and display the calibration data errors for validation
     253        answer=msgbox_uvmat('INPUT_Y-N',{'store calibration data';...
     254            ['Error rms (along x,y)=' num2str(GeometryCalib.ErrorRms) ' pixels'];...
     255            ['Error max (along x,y)=' num2str(GeometryCalib.ErrorMax) ' pixels'];
     256            [num2str(numel(ind_removed)) ' points removed']});
     257        if strcmp(answer,'Yes') %store the calibration data
     258            if strcmp(calib_cell{val}(1:2),'3D')%set the plane position for 3D (projection) calibration
     259                answer=msgbox_uvmat('INPUT_Y-N',{['Assume that the current image is in the plane of the calib points z=' num2str(Z_plane) ] ; 'can be later modified by MenuSetSlice in the upper bar menu of uvmat'});
     260                SliceCoord_ref=Z_plane'*[0 0 1];
     261            end
     262        else
     263            GeometryCalib=[];
     264            index=1;
     265        end
     266       
     267        if ~isempty(GeometryCalib) % if calibration is not cancelled
     268            if get(handles.Replicate,'Value')
     269                %% open the GUI browse_data
     270                hbrowse=findobj(allchild(0),'Tag','browse_data');
     271                if ~isempty(hbrowse)
     272                    BrowseHandles=guidata(hbrowse);
     273                    SourceDir=get(BrowseHandles.SourceDir,'String');
     274                    ListExperiments=get(BrowseHandles.ListExperiments,'String');
     275                    ListValues=get(BrowseHandles.ListExperiments,'Value');
     276                    ListExperiments=ListExperiments(ListValues);
     277                    ListDevices=get(BrowseHandles.ListDevices,'String');
     278                    Val=get(BrowseHandles.ListDevices,'Value');
     279                    DataFolder=ListDevices{Val};
     280                    nbcalib=0;
     281                    for ilist=1:numel(ListExperiments)
     282                        SubDirBase=regexprep(DataFolder,'+/','');
     283                        ListExperiments{ilist}=regexprep(ListExperiments{ilist},'+/','');
     284                        XmlName=fullfile(SourceDir,ListExperiments{ilist},[SubDirBase '.xml']);
     285                        % copy the xml file from the old location if appropriate, then update with the calibration parameters
     286                        %                 if ~exist(XmlName,'file') && ~isempty(SubDirBase)
     287                        %                     oldxml=fullfile(OutPut.Campaign,OutPut.Experiment{ilist},SubDirBase,[get(hhuvmat.RootFile,'String') '.xml']);
     288                        GeometryCalib.SliceCoord=SliceCoord_ref;%default input
     289                        if exist(XmlName,'file')
     290                            %[success,message]=copyfile(oldxml,XmlName);%copy the old xml file to a new one with the new convention
     291                            dispmesGeometryCalib=UvData.XmlData{1}.GeometryCalib;
     292                        else
     293                            msgbox_uvmat('ERROR','3D geometric calibration needed before defining slices')
     294                            return
     295                        end
     296                        SliceCoord=GeometryCalib.SliceCoord;
     297                        InterfaceCoord=min(SliceCoord(:,3));
     298                        if isfield(GeometryCalib,'InterfaceCoord')
     299                            InterfaceCoord=GeometryCalib.InterfaceCoord(1,3);
     300                        end
     301                        NbSlice=size(SliceCoord,1);
     302                        CheckVolumeScan=0;
     303                        if isfield(GeometryCalib,'CheckVolumeScan')
     304                            CheckVolumeScan=GeometryCalib.CheckVolumeScan;
     305                        end
     306                        RefractionIndex=1.33;
     307                        CheckRefraction=0;% default value of the check box refraction
     308                        if isfield(GeometryCalib,'RefractionIndex')
     309                            RefractionIndex=GeometryCalib.RefractionIndex;
     310                            CheckRefraction=1;
     311                        end
     312                        SliceAngle=[0 0 0];
     313                        if isfield(GeometryCalib,'SliceAngle')
     314                            SliceAngle=GeometryCalib.SliceAngle;
     315                        end
     316                        dispmessage=' updated with calibration parameters';
     317                        %                         if ~strcmp(answer,'yes')
     318                        [XmlDataOld,warntext]=imadoc2struct(XmlName);
     319                        if isfield(XmlDataOld,'GeometryCalib')
     320                            if isfield(XmlDataOld.GeometryCalib,'SliceAngle')
     321                                GeometryCalib.SliceAngle=XmlDataOld.GeometryCalib.SliceAngle;
     322                            end
     323                            if isfield(XmlDataOld.GeometryCalib,'CheckRefraction')
     324                                GeometryCalib.SliceAngle=XmlDataOld.GeometryCalib.CheckRefraction;
     325                            end
     326                            if isfield(XmlDataOld.GeometryCalib,'RefractionIndex')
     327                                GeometryCalib.SliceAngle=XmlDataOld.GeometryCalib.RefractionIndex;
     328                            end
     329                            if isfield(XmlDataOld.GeometryCalib,'InterfaceCoord')
     330                                GeometryCalib.SliceAngle=XmlDataOld.GeometryCalib.InterfaceCoord;
     331                            end
     332                        end
     333                       
     334                        end
     335                       
     336                        else
     337                            dispmessage=' created with calibration parameters';
     338                    end
     339                    errormsg=update_imadoc(GeometryCalib,XmlName,'GeometryCalib');% introduce the calibration data in the xml file
     340                    if ~strcmp(errormsg,'')
     341                        msgbox_uvmat('ERROR',errormsg);
     342                    else
     343                        display([XmlName dispmessage])
     344                        nbcalib=nbcalib+1;
     345                    end
     346                end
     347               
     348            end
     349            msgbox_uvmat('CONFIMATION',[SubDirBase ' calibrated for ' num2str(nbcalib) ' experiments']);
     350        else
     351           
     352            %% copy the xml file from the old location if appropriate, then update with the calibration parameters
     353            if ~exist(outputfile,'file') && ~isempty(SubDirBase)
     354                oldxml=[fullfile(RootPath,SubDirBase,get(hhuvmat.RootFile,'String')) '.xml'];
     355                if exist(oldxml,'file')
     356                    [success,message]=copyfile(oldxml,outputfile);%copy the old xml file to a new one with the new convention
     357                end
     358            end
     359            errormsg=update_imadoc(GeometryCalib,outputfile,'GeometryCalib');% introduce the calibration data in the xml file
     360            if ~strcmp(errormsg,'')
     361                msgbox_uvmat('ERROR',errormsg);
     362            end
     363           
     364            %% display image with new calibration in the currently opened uvmat interface
     365            FieldList=get(hhuvmat.FieldName,'String');
     366            val=get(hhuvmat.FieldName,'Value');
     367            if strcmp(FieldList{val},'image')
     368                set(hhuvmat.CheckFixLimits,'Value',0)% put FixedLimits option to 'off' to plot the whole image
     369                UserData=get(handles.geometry_calib,'UserData');
     370                UserData.XmlInputFile=outputfile;%save the current xml file name
     371                set(handles.geometry_calib,'UserData',UserData)
     372                uvmat('InputFileREFRESH_Callback',hObject,eventdata,hhuvmat); %file input with xml reading  in uvmat, show the image in phys coordinates
     373                PLOT_Callback(hObject, eventdata, handles)
     374                set(handles.CoordLine,'string',num2str(index))
     375                Coord=get(handles.ListCoord,'Data');
     376                update_calib_marker(Coord(index,:)); %indicate the point with max deviations from phys coord to calibration
     377                figure(handles.geometry_calib)% put the GUI geometry_calib in front
     378            else
     379                msgbox_uvmat('WARNING','open the image to see the effect of the new calibration')
     380            end
     381        end
     382    end
     383    set(handles.APPLY,'BackgroundColor',[1 0 0]) % set APPLY button to red color
     384
     385%------------------------------------------------------------------------
     386% --- Executes on button press in Replicate
     387function Replicate_Callback(hObject, eventdata, handles)
     388% %------------------------------------------------------------------------
    170389set(handles.CheckEnableMouse,'Value',0)% desactivate mouse (to avoid spurious creation of new points)
    171390
    172 %------------------------------------------------------------------------
    173 %% look for the GUI uvmat and check for an image as input
    174 set(handles.APPLY,'BackgroundColor',[1 1 0])% paint APPLY button in yellow to show activation
    175 huvmat=findobj(allchild(0),'Name','uvmat');% look for the GUI uvmat
    176 hhuvmat=guidata(huvmat);%handles of elements in the GUI uvmat
    177 if ~strcmp(get(hhuvmat.Scalar,'Visible'),'on')
    178     msgbox_uvmat('ERROR','An image needs to be opened in uvmat for calibration')
    179   return
    180 end
    181 
    182 RootPath='';
    183 if ~isempty(hhuvmat.RootPath)&& ~isempty(hhuvmat.RootFile)
    184     RootPath=get(hhuvmat.RootPath,'String');% path to the currently displayed image
    185     SubDirBase=regexprep(get(hhuvmat.SubDir,'String'),'\..+$','');
    186     outputfile=[fullfile(RootPath,SubDirBase) '.xml'];%xml file associated with the currently displayed image
     391if get(handles.Replicate,'Value') %open the GUI browse_data
     392    % look for the GUI uvmat and check for an image as input
     393    huvmat=findobj(allchild(0),'Name','uvmat');
     394    hhuvmat=guidata(huvmat);%handles of elements in the GUI uvmat
     395    RootPath=get(hhuvmat.RootPath,'String');
     396    SubDir=get(hhuvmat.SubDir,'String');
     397    browse_data(fullfile(RootPath,SubDir))
    187398else
    188     question={'save the calibration data and point coordinates in'};
    189     def={fullfile(RootPath,'ObjectCalib.xml')};
    190     options.Resize='on';
    191     answer=inputdlg(question,'',1,def,options);
    192     outputfile=answer{1};
    193 end
    194 
    195 %% read coordinates of the calibration poinnts: Coord(:,1-3) in phys, Coord(:,4-5) image
    196 Coord=get(handles.ListCoord,'Data');
    197 
    198  
    199 %% read the type of calibration
    200 calib_cell=get(handles.calib_type,'String');
    201 val=get(handles.calib_type,'Value');
    202 CalibFcn=['calib_' calib_cell{val}];
    203 
    204 %% read the intrinsic parameters
    205 Intrinsic.Npx=str2num(get(hhuvmat.num_Npx,'String'));
    206 Intrinsic.Npy=str2num(get(hhuvmat.num_Npy,'String'));
    207 Intrinsic.coord_files=get(handles.ListCoordFiles,'String');
    208 Intrinsic.fx=str2num(get(handles.fx,'String'));
    209 Intrinsic.fy=str2num(get(handles.fy,'String'));
    210 Intrinsic.kc=str2num(get(handles.kc,'String'));
    211 Intrinsic.Cx=str2num(get(handles.Cx,'String'));
    212 Intrinsic.Cy=str2num(get(handles.Cy,'String'));
    213 if isempty(Intrinsic.kc)
    214     Intrinsic.kc=0;
    215 end
    216 if isempty(Intrinsic.Cx)||isempty(Intrinsic.Cy)
    217     Intrinsic.Cx=Intrinsic.Npx/2;
    218     Intrinsic.Cy=Intrinsic.Npy/2;
    219 end 
    220 
    221 %% Apply calibration
    222 [GeometryCalib,index,ind_removed,Z_plane]=calibrate(Coord,CalibFcn,Intrinsic);% apply calibration
    223 
    224 %% record the coordinate unit
    225 unitlist=get(handles.CoordUnit,'String');
    226 unit=unitlist{get(handles.CoordUnit,'value')};
    227 GeometryCalib.CoordUnit=unit;
    228 
    229 %% record the coordinates of the calibration points
    230 GeometryCalib.SourceCalib.PointCoord=Coord;
    231 
    232 %% display calibration results on the GUI geometry_calib
    233 display_intrinsic(GeometryCalib,handles)%display calibration intrinsic parameters
    234 display_extrinsic(GeometryCalib,handles)%display calibration extrinsic parameters
    235 %     (rotation and translation of camera with  respect to the phys coordinates)
    236 
    237 %% store the calibration data, by default in the xml file of the currently displayed image
    238 answer=msgbox_uvmat('INPUT_Y-N',{'store calibration data';...
    239     ['Error rms (along x,y)=' num2str(GeometryCalib.ErrorRms) ' pixels'];...
    240     ['Error max (along x,y)=' num2str(GeometryCalib.ErrorMax) ' pixels'];
    241     [num2str(numel(ind_removed)) ' points removed']});
    242 if strcmp(answer,'Yes') %store the calibration data
    243     if strcmp(calib_cell{val}(1:2),'3D')%set the plane position for 3D (projection) calibration
    244         msgbox_uvmat('CONFIRMATION',{['The current image series is assumed by default in the plane of the calib points z=' num2str(Z_plane) ] ; 'can be modified by MenuSetSlice in the upper bar menu of uvmat'})
    245         GeometryCalib.SliceCoord=Z_plane'*[0 0 1];
    246     end   
    247 else
    248     GeometryCalib=[];
    249     index=1;
    250 end
    251 
    252 if isempty(GeometryCalib) % if calibration cancelled
    253     set(handles.APPLY,'BackgroundColor',[1 0 1])
    254 else   % if calibration confirmed
    255    
    256     %% copy the xml file from the old location if appropriate, then update with the calibration parameters
    257     if ~exist(outputfile,'file') && ~isempty(SubDirBase)
    258         oldxml=[fullfile(RootPath,SubDirBase,get(hhuvmat.RootFile,'String')) '.xml'];
    259         if exist(oldxml,'file')
    260             [success,message]=copyfile(oldxml,outputfile);%copy the old xml file to a new one with the new convention
    261         end
    262     end
    263     errormsg=update_imadoc(GeometryCalib,outputfile,'GeometryCalib');% introduce the calibration data in the xml file
    264     if ~strcmp(errormsg,'')
    265         msgbox_uvmat('ERROR',errormsg);
    266     end
    267    
    268     %% display image with new calibration in the currently opened uvmat interface
    269     FieldList=get(hhuvmat.FieldName,'String');
    270     val=get(hhuvmat.FieldName,'Value');
    271     if strcmp(FieldList{val},'image')
    272         set(hhuvmat.CheckFixLimits,'Value',0)% put FixedLimits option to 'off' to plot the whole image
    273         UserData=get(handles.geometry_calib,'UserData');
    274         UserData.XmlInputFile=outputfile;%save the current xml file name
    275         set(handles.geometry_calib,'UserData',UserData)
    276         uvmat('InputFileREFRESH_Callback',hObject,eventdata,hhuvmat); %file input with xml reading  in uvmat, show the image in phys coordinates
    277         PLOT_Callback(hObject, eventdata, handles)
    278         set(handles.CoordLine,'string',num2str(index))
    279         Coord=get(handles.ListCoord,'Data');
    280         update_calib_marker(Coord(index,:)); %indicate the point with max deviations from phys coord to calibration
    281         figure(handles.geometry_calib)% put the GUI geometry_calib in front
    282         set(handles.APPLY,'BackgroundColor',[1 0 0]) % set APPLY button to red color
    283     else
    284         msgbox_uvmat('WARNING','open the image to see the effect of the new calibration')
    285     end
    286 end
    287 
    288 %------------------------------------------------------------------------
    289 % --- Executes on button press in REPLICATE
    290 function REPLICATE_Callback(hObject, eventdata, handles)
    291 %------------------------------------------------------------------------
    292 set(handles.CheckEnableMouse,'Value',0)% desactivate mouse (to avoid spurious creation of new points)
    293 
    294 %% look for the GUI uvmat and check for an image as input
    295 huvmat=findobj(allchild(0),'Name','uvmat');
    296 hhuvmat=guidata(huvmat);%handles of elements in the GUI uvmat
    297 
    298 %% read coordinates of the calibration poinnts: Coord(:,1-3) in phys, Coord(:,4-5) image
    299 Coord=get(handles.ListCoord,'Data');
    300  
    301 %% read the type of calibration
    302 calib_cell=get(handles.calib_type,'String');
    303 val=get(handles.calib_type,'Value');
    304 CalibFcn=['calib_' calib_cell{val}];
    305 
    306 %% read the intrinsic parameters
    307 Intrinsic.Npx=str2num(get(hhuvmat.num_Npx,'String'));
    308 Intrinsic.Npy=str2num(get(hhuvmat.num_Npy,'String'));
    309 Intrinsic.coord_files=get(handles.ListCoordFiles,'String');
    310 Intrinsic.fx=str2num(get(handles.fx,'String'));
    311 Intrinsic.fy=str2num(get(handles.fy,'String'));
    312 Intrinsic.kc=str2num(get(handles.kc,'String'));
    313 Intrinsic.Cx=str2num(get(handles.Cx,'String'));
    314 Intrinsic.Cy=str2num(get(handles.Cy,'String'));
    315 if isempty(Intrinsic.kc)
    316     Intrinsic.kc=0;
    317 end
    318 if isempty(Intrinsic.Cx)||isempty(Intrinsic.Cy)
    319     Intrinsic.Cx=Intrinsic.Npx/2;
    320     Intrinsic.Cy=Intrinsic.Npy/2;
    321 end
    322 
    323 %% apply to cropped images if requested
    324 answer=msgbox_uvmat('INPUT_Y-N','apply to cropped images?');
    325 if strcmp(answer,'Yes')
    326     prompt = {'npy_lower'};
    327     dlg_title = 'remove image the npy_lower image lines (removal of the upper linedoes not change calibration)';
    328     num_lines= 1;
    329     def     = {'0'};
    330     answer = inputdlg(prompt,dlg_title,num_lines,def);
    331     npy_crop=str2num(answer{1});
    332     Intrinsic.Npy=Intrinsic.Npy-npy_crop; %size of the filtering window
    333     Coord(:,5)=Coord(:,5)-npy_crop;% shift the image ordinates of the calibration points by removing the lower band
    334 end
    335 
    336 %% Apply calibration
    337 [GeometryCalib,index,ind_removed,Z_plane]=calibrate(Coord,CalibFcn,Intrinsic);% apply calibration
    338 
    339 
    340 %% record the coordinate unit
    341 unitlist=get(handles.CoordUnit,'String');
    342 unit=unitlist{get(handles.CoordUnit,'value')};
    343 GeometryCalib.CoordUnit=unit;
    344 
    345 %% record the coordinates of the calibration points
    346 GeometryCalib.SourceCalib.PointCoord=Coord;
    347 
    348 %% display calibration results on the GUI geometry_calib
    349 display_intrinsic(GeometryCalib,handles)%display calibration intrinsic parameters
    350 display_extrinsic(GeometryCalib,handles)%display calibration extrinsic parameters
    351 %     (rotation and translation of camera with  respect to the phys coordinates)
    352 
    353 %% store the calibration data, by default in the xml file of the currently displayed image
    354 answer=msgbox_uvmat('INPUT_Y-N',{'store calibration data';...
    355     ['Error rms (along x,y)=' num2str(GeometryCalib.ErrorRms) ' pixels'];...
    356     ['Error max (along x,y)=' num2str(GeometryCalib.ErrorMax) ' pixels'];...
    357     [num2str(numel(ind_removed)) ' points removed']});
    358 if strcmp(answer,'Yes') %store the calibration data
    359     if strcmp(calib_cell{val}(1:2),'3D')%set the plane position for 3D (projection) calibration
    360         msgbox_uvmat('CONFIRMATION',{['The current image series is assumed by default in the plane of the calib points z=' num2str(Z_plane) ] ; 'can be modified by MenuSetSlice in the upper bar menu of uvmat'})
    361         GeometryCalib.SliceCoord=Z_plane'*[0 0 1];
    362     end   
    363 else
    364     GeometryCalib=[];
    365     index=1;
    366 end
    367 
    368 %% open the GUI browse_data
    369 CalibData=get(handles.geometry_calib,'UserData');%read the calibration image source on the interface userdata
    370 if isfield(CalibData,'XmlInputFile')
    371     InputDir=fileparts(fileparts(CalibData.XmlInputFile));
    372 end
    373 DataSeries=uigetfile_uvmat('open a folder of images to calibrate',InputDir,'uigetdir');
    374 %SubProject=uigetfile_uvmat('open folder of subproject to calibrate',InputDir,'uigetdir');
    375 OutPut=browse_data(DataSeries);
    376 nbcalib=0;
    377 for ilist=1:numel(OutPut.Experiment)
    378     SubDirBase=regexprep(OutPut.DataSeries{1},'\..+$','');
    379     XmlName=fullfile(OutPut.Campaign,OutPut.Experiment{ilist},[SubDirBase '.xml']);
    380     dispmessage=' created with calibration parameters';
    381     % copy the xml file from the old location if appropriate, then update with the calibration parameters
    382     if ~exist(XmlName,'file') && ~isempty(SubDirBase)
    383         oldxml=fullfile(OutPut.Campaign,OutPut.Experiment{ilist},SubDirBase,[get(hhuvmat.RootFile,'String') '.xml']);
    384         if exist(oldxml,'file')
    385             [success,message]=copyfile(oldxml,XmlName);%copy the old xml file to a new one with the new convention
    386             dispmessage=' updated with calibration parameters';
    387         end
    388     end
    389     errormsg=update_imadoc(GeometryCalib,XmlName,'GeometryCalib');% introduce the calibration data in the xml file
    390     if ~strcmp(errormsg,'')
    391         msgbox_uvmat('ERROR',errormsg);
    392     else
    393         display([XmlName dispmessage])
    394         nbcalib=nbcalib+1;
    395     end
    396 end
    397 msgbox_uvmat('CONFIMATION',[SubDirBase ' calibrated for ' num2str(nbcalib) ' experiments']);
    398 
     399    hbrowse=findobj(allchild(0),'Tag','browse_data');
     400    if ~isempty(hbrowse)
     401        delete(hbrowse)
     402    end
     403end
    399404%------------------------------------------------------------------------
    400405% --- activate calibration and store parameters in ouputfile .
  • trunk/src/phys_XYZ.m

    r1027 r1059  
    3030testangle=0;
    3131test_refraction=0;
    32 if exist('Zindex','var')&& isequal(Zindex,round(Zindex))&& Zindex>0 && isfield(Calib,'SliceCoord')&&length(Calib.SliceCoord)>=Zindex
     32if exist('Zindex','var')&& isequal(Zindex,round(Zindex))&& Zindex>0 && isfield(Calib,'SliceCoord')&&size(Calib.SliceCoord,1)>=Zindex
    3333    if isfield(Calib, 'SliceAngle') && ~isequal(Calib.SliceAngle,[0 0 0]) && ~isequal(Calib.SliceAngle(Zindex,:),[0 0 0])
    3434        testangle=1;
     
    4343%         Z0=norm_plane*Calib.SliceCoord(Zindex,:)'/norm_plane(3);
    4444    end
    45         Z0=Calib.SliceCoord(Zindex,3);%horizontal plane z=cte
     45    Z0=Calib.SliceCoord(Zindex,3);%horizontal plane z=cte
    4646%     end
    4747    Z0virt=Z0;
  • trunk/src/series.m

    r1051 r1059  
    1 
    2 
    3 
    41%'series': master function associated to the GUI series.m for analysis field series 
    52%------------------------------------------------------------------------
     
    212209    end
    213210    %get the list of previous campaigns in the upper bar menu Open campaign
    214     if isfield(h,'MenuCampaign')
    215         for ifile=1:min(length(h.MenuCampaign),5)
    216             set(handles.(['MenuCampaign_' num2str(ifile)]),'Label',h.MenuCampaign{ifile});
    217         end
    218     end
     211%     if isfield(h,'MenuCampaign')
     212%         for ifile=1:min(length(h.MenuCampaign),5)
     213%             set(handles.(['MenuCampaign_' num2str(ifile)]),'Label',h.MenuCampaign{ifile});
     214%         end
     215%     end
    219216    %get the menu of actions
    220217    if isfield(h,'ActionListUser') && iscell(h.ActionListUser) && isfield(h,'ActionPathListUser') && iscell(h.ActionPathListUser)
     
    498495    end
    499496end
    500 
    501 OutPut=browse_data(oldfile,'on','on'); % open the GUI browse_data to get select a campaign dir, experiment and device
    502 NbLines=numel(OutPut.Experiment)*numel(OutPut.DataSeries);
    503 icount=0;
    504 for iexp=1:numel(OutPut.Experiment)
    505     for idevice=1:numel(OutPut.DataSeries)
    506         icount=icount+1;
    507         InputTable{icount,1}=fullfile(OutPut.Campaign,OutPut.Experiment{iexp});
    508         InputTable{icount,2}=OutPut.DataSeries{idevice};
    509         if isempty(InputTable{icount,3})
    510             if icount>1
    511             InputTable{icount,3}=InputTable{icount-1,3};
    512             else
    513                 InputTable{icount,3}='';
    514             end
    515         end
    516         if isempty(InputTable{icount,4})
    517             if icount>1
    518             InputTable{icount,4}=InputTable{icount-1,4};
    519             else
    520                 InputTable{icount,4}='';
    521             end
    522         end
    523                 if isempty(InputTable{icount,5})
    524             if icount>1
    525             InputTable{icount,5}=InputTable{icount-1,5};
    526             else
    527                 InputTable{icount,5}='';
    528             end
    529         end
    530     end
    531 end
    532 if size(InputTable,1)>icount
    533     InputTable(icount+1:size(InputTable,1),:)=[];
    534 end
     497InputTable{1,1}='...';
    535498set(handles.InputTable,'Data',InputTable)
    536 REFRESH_Callback(hObject, eventdata, handles)
     499browse_data(oldfile,'on','on'); % open the GUI browse_data to get select a campaign dir, experiment and device
     500% NbLines=numel(OutPut.Experiment)*numel(OutPut.DataSeries);
     501% icount=0;
     502% for iexp=1:numel(OutPut.Experiment)
     503%     for idevice=1:numel(OutPut.DataSeries)
     504%         icount=icount+1;
     505%         InputTable{icount,1}=fullfile(OutPut.Campaign,OutPut.Experiment{iexp});
     506%         InputTable{icount,2}=OutPut.DataSeries{idevice};
     507%         if isempty(InputTable{icount,3})
     508%             if icount>1
     509%             InputTable{icount,3}=InputTable{icount-1,3};
     510%             else
     511%                 InputTable{icount,3}='';
     512%             end
     513%         end
     514%         if isempty(InputTable{icount,4})
     515%             if icount>1
     516%             InputTable{icount,4}=InputTable{icount-1,4};
     517%             else
     518%                 InputTable{icount,4}='';
     519%             end
     520%         end
     521%                 if isempty(InputTable{icount,5})
     522%             if icount>1
     523%             InputTable{icount,5}=InputTable{icount-1,5};
     524%             else
     525%                 InputTable{icount,5}='';
     526%             end
     527%         end
     528%     end
     529% end
     530% if size(InputTable,1)>icount
     531%     InputTable(icount+1:size(InputTable,1),:)=[];
     532% end
     533%REFRESH_Callback(hObject, eventdata, handles)
    537534
    538535% --------------------------------------------------------------------
    539 function MenuCampaign_Callback(hObject, eventdata, handles)
    540 % --------------------------------------------------------------------
    541 
    542 OutPut=browse_data(get(hObject,'Label'),'on','on'); % open the GUI browse_data to get select a campaign dir, experiment and device
    543 if ~isfield(OutPut,'Campaign')
    544     return
    545 end
    546 NbLines=numel(OutPut.Experiment)*numel(OutPut.DataSeries);
    547 icount=0;
    548 InputTable=get(handles.InputTable,'Data');
    549 for iexp=1:numel(OutPut.Experiment)
    550     for idevice=1:numel(OutPut.DataSeries)
    551         icount=icount+1;
    552         InputTable{icount,1}=fullfile(OutPut.Campaign,OutPut.Experiment{iexp});
    553         InputTable{icount,2}=OutPut.DataSeries{idevice};
    554         if isempty(InputTable{icount,3})
    555             if icount>1
    556                 InputTable{icount,3}=InputTable{icount-1,3};
    557             else
    558                 InputTable{icount,3}='';
    559             end
    560         end
    561         if isempty(InputTable{icount,4})
    562             if icount>1
    563                 InputTable{icount,4}=InputTable{icount-1,4};
    564             else
    565                 InputTable{icount,4}='';
    566             end
    567         end
    568         if isempty(InputTable{icount,5})
    569             if icount>1
    570                 InputTable{icount,5}=InputTable{icount-1,5};
    571             else
    572                 InputTable{icount,5}='';
    573             end
    574         end
    575     end
    576 end
    577 if size(InputTable,1)>icount
    578     InputTable(icount+1:size(InputTable,1),:)=[];
    579 end
    580 set(handles.InputTable,'Data',InputTable)
    581 REFRESH_Callback(hObject, eventdata, handles)
     536% function MenuCampaign_Callback(hObject, eventdata, handles)
     537% % --------------------------------------------------------------------
     538%
     539% OutPut=browse_data(get(hObject,'Label'),'on','on'); % open the GUI browse_data to get select a campaign dir, experiment and device
     540% if ~isfield(OutPut,'Campaign')
     541%     return
     542% end
     543% NbLines=numel(OutPut.Experiment)*numel(OutPut.DataSeries);
     544% icount=0;
     545% InputTable=get(handles.InputTable,'Data');
     546% for iexp=1:numel(OutPut.Experiment)
     547%     for idevice=1:numel(OutPut.DataSeries)
     548%         icount=icount+1;
     549%         InputTable{icount,1}=fullfile(OutPut.Campaign,OutPut.Experiment{iexp});
     550%         InputTable{icount,2}=OutPut.DataSeries{idevice};
     551%         if isempty(InputTable{icount,3})
     552%             if icount>1
     553%                 InputTable{icount,3}=InputTable{icount-1,3};
     554%             else
     555%                 InputTable{icount,3}='';
     556%             end
     557%         end
     558%         if isempty(InputTable{icount,4})
     559%             if icount>1
     560%                 InputTable{icount,4}=InputTable{icount-1,4};
     561%             else
     562%                 InputTable{icount,4}='';
     563%             end
     564%         end
     565%         if isempty(InputTable{icount,5})
     566%             if icount>1
     567%                 InputTable{icount,5}=InputTable{icount-1,5};
     568%             else
     569%                 InputTable{icount,5}='';
     570%             end
     571%         end
     572%     end
     573% end
     574% if size(InputTable,1)>icount
     575%     InputTable(icount+1:size(InputTable,1),:)=[];
     576% end
     577% set(handles.InputTable,'Data',InputTable)
     578% REFRESH_Callback(hObject, eventdata, handles)
    582579
    583580
     
    742739%% enable other menus and uicontrols
    743740% set(handles.MenuOpenCampaign,'Enable','on')
    744 set(handles.MenuCampaign_1,'Enable','on')
    745 set(handles.MenuCampaign_2,'Enable','on')
    746 set(handles.MenuCampaign_3,'Enable','on')
    747 set(handles.MenuCampaign_4,'Enable','on')
    748 set(handles.MenuCampaign_5,'Enable','on')
     741% set(handles.MenuCampaign_1,'Enable','on')
     742% set(handles.MenuCampaign_2,'Enable','on')
     743% set(handles.MenuCampaign_3,'Enable','on')
     744% set(handles.MenuCampaign_4,'Enable','on')
     745% set(handles.MenuCampaign_5,'Enable','on')
    749746set(handles.RUN, 'Enable','On')
    750747set(handles.RUN,'BackgroundColor',[1 0 0])% set RUN button to red
     
    15941591end
    15951592
    1596 %% create the output data directory if needed
    1597 OutputDir='';
    1598 if isfield(Param,'OutputSubDir')
    1599     SubDirOut=[get(handles.OutputSubDir,'String') Param.OutputDirExt];
    1600     SubDirOutNew=SubDirOut;
    1601     detect=exist(fullfile(Param.InputTable{1,1},SubDirOutNew),'dir'); % test if  the dir  already exist
    1602     check_create=1; % need to create the result directory by default
    1603     CheckOverwrite=1;
    1604     if isfield(Param,'CheckOverwrite')
    1605         CheckOverwrite=Param.CheckOverwrite;
    1606     end
    1607     while detect
    1608         if CheckOverwrite
    1609             comment=', possibly overwrite previous data';
     1593%% Look for prcessing on multiple experiments set by the GUI browse_data
     1594NbExp=1;
     1595ListExp=Param.InputTable(1,1);
     1596
     1597if get(handles.Replicate,'Value')
     1598    hh=findobj(allchild(0),'Tag','browse_data');
     1599    BrowseData=guidata(hh);
     1600    SourceDir=get(BrowseData.SourceDir,'String');
     1601    ListExp=get(BrowseData.ListExperiments,'String');
     1602    ListExp=ListExp(get(BrowseData.ListExperiments,'Value'));
     1603    NbExp=numel(ListExp) % number of experiments set possibly by the GUI browse_data, =1 otherwise
     1604    for ilist=1:NbExp
     1605        ListExp{ilist}=regexprep(ListExp{ilist},'+','');
     1606        ListExp{ilist}= [SourceDir ListExp{ilist}];
     1607    end
     1608end
     1609
     1610%%%%%%%%%%%%%%%%%%% LOOP ON EXPERIMENTS POSSIBLY SET BY THE GUI browse_data, NbExp=1 otherwise %%%%%%%%%
     1611for iexp=1:NbExp
     1612    Param.InputTable{1,1}=ListExp{iexp};
     1613    set(handles.InputTable,'Data',Param.InputTable)
     1614    [xx,ExpName]=fileparts(ListExp{iexp});
     1615    Param.IndexRange.first_i=str2num(get(handles.num_first_i,'String'));%reset the firrst_i and last_i for multiple experiments, modified by the splitting into NbProcess
     1616    Param.IndexRange.last_i=str2num(get(handles.num_last_i,'String'));
     1617    %% create the output data directory if needed
     1618    OutputDir='';
     1619    answer='';
     1620    if isfield(Param,'OutputSubDir')
     1621        SubDirOut=[get(handles.OutputSubDir,'String') Param.OutputDirExt];
     1622        SubDirOutNew=SubDirOut;
     1623        detect=exist(fullfile(Param.InputTable{1,1},SubDirOutNew),'dir'); % test if  the dir  already exist
     1624        check_create=1; % need to create the result directory by default
     1625        CheckOverwrite=1;
     1626        if isfield(Param,'CheckOverwrite')
     1627            CheckOverwrite=Param.CheckOverwrite;
     1628        end
     1629        while detect
     1630            if CheckOverwrite
     1631                comment=', possibly overwrite previous data';
     1632            else
     1633                comment=', will complement existing result files (no overwriting)';
     1634            end
     1635            answer=msgbox_uvmat('INPUT_Y-N-Cancel',['use existing ouput directory: ' fullfile(Param.InputTable{1,1},SubDirOutNew) comment]);
     1636            if strcmp(answer,'Cancel')
     1637                break
     1638            elseif strcmp(answer,'Yes')
     1639                detect=0;
     1640                check_create=0;
     1641            else
     1642                r=regexp(SubDirOutNew,'(?<root>.*\D)(?<num1>\d+)$','names'); % detect whether name ends by a number
     1643                if isempty(r)
     1644                    r(1).root=[SubDirOutNew '_'];
     1645                    r(1).num1='0';
     1646                end
     1647                SubDirOutNew=[r(1).root num2str(str2num(r(1).num1)+1)]; % increment the index by 1 or put 1
     1648                detect=exist(fullfile(Param.InputTable{1,1},SubDirOutNew),'dir'); % test if  the dir  already exists
     1649                check_create=1;
     1650            end
     1651        end
     1652        if strcmp(answer,'Cancel')
     1653            continue
     1654        end
     1655        Param.OutputDirExt=regexprep(SubDirOutNew,Param.OutputSubDir,'');
     1656        Param.OutputRootFile=Param.InputTable{1,3}; % the first sorted RootFile taken for output
     1657        set(handles.OutputDirExt,'String',Param.OutputDirExt)
     1658        OutputDir=fullfile(Param.InputTable{1,1},[Param.OutputSubDir Param.OutputDirExt]); % full name (with path) of output directory
     1659        if check_create    % create output directory if it does not exist
     1660            [tild,msg1]=mkdir(OutputDir);
     1661            if ~strcmp(msg1,'')
     1662                errormsg=['cannot create ' OutputDir ': ' msg1]; % error message for directory creation
     1663                return
     1664            end
     1665        end
     1666       
     1667    elseif isfield(Param,'ActionInput')&&isfield(Param.ActionInput,'LogPath')% custom definition of the output dir
     1668        OutputDir=Param.ActionInput.LogPath;
     1669    end
     1670    DirXml=fullfile(OutputDir,'0_XML');
     1671    if ~exist(DirXml,'dir')
     1672        [~,msg1]=mkdir(DirXml);
     1673        if ~strcmp(msg1,'')
     1674            errormsg=['cannot create ' DirXml ': ' msg1]; % error message for directory creation
     1675            return
     1676        end
     1677    end
     1678    OutputNomType=nomtype2pair(Param.InputTable{1,4}); % nomenclature for output files
     1679   
     1680    %% get the set of reference input field indices
     1681    first_i=1; % first i index to process
     1682    last_i=1; % last i index to process
     1683    incr_i=1; % increment step in i index
     1684    first_j=1; % first j index to process
     1685    last_j=1; % last j index to process
     1686    incr_j=1; % increment step in j index
     1687    if isfield(Param.IndexRange,'first_i')
     1688        first_i=Param.IndexRange.first_i;
     1689        incr_i=Param.IndexRange.incr_i;
     1690        last_i=Param.IndexRange.last_i;
     1691    end
     1692    if isfield(Param.IndexRange,'incr_j')
     1693        first_j=Param.IndexRange.first_j;
     1694        last_j=Param.IndexRange.last_j;
     1695        incr_j=Param.IndexRange.incr_j;
     1696    end
     1697    if last_i < first_i || last_j < first_j
     1698        errormsg= 'series/Run_Callback:last field index must be larger or equal to the first one';
     1699        return
     1700    end
     1701    %incr_i must be defined, =1 by default, if NbSlice is active
     1702    if isempty(incr_i)&& ~isempty(Param.IndexRange.NbSlice)
     1703        incr_i=1;
     1704        set(handles.num_incr_i,'String','1')
     1705    end
     1706    % case of no increment i defined: processing is done on the available files found in i1_series
     1707    if isempty(incr_i)
     1708        if isempty(incr_j)
     1709            [ref_j,ref_i]=find(squeeze(SeriesData.i1_series{1}(1,:,:)));
     1710            ref_j=ref_j(ref_j>=first_j & ref_j<=last_j);
     1711            ref_i=ref_i(ref_i>=first_i & ref_i<=last_i);
     1712            ref_j=ref_j-1;
     1713            ref_i=ref_i-1;
    16101714        else
    1611             comment=', will complement existing result files (no overwriting)';
    1612         end
    1613         answer=msgbox_uvmat('INPUT_Y-N-Cancel',['use existing ouput directory: ' fullfile(Param.InputTable{1,1},SubDirOutNew) comment]);
    1614         if strcmp(answer,'Cancel')
     1715            ref_j=first_j:incr_j:last_j;
     1716            [tild,ref_i]=find(squeeze(SeriesData.i1_series{1}(1,:,:)));
     1717            ref_i=ref_i-1;
     1718            ref_i=ref_i(ref_i>=first_i & ref_i<=last_i);
     1719        end
     1720        % increment i is defined: processing is done on first_i:incr_i:last_i;
     1721    else
     1722        ref_i=first_i:incr_i:last_i;
     1723        if isempty(incr_j)% automatic finding of the existing j indices
     1724            [ref_j,tild]=find(squeeze(SeriesData.i1_series{1}(1,:,:)));
     1725            ref_j=ref_j-1;
     1726            ref_j=ref_j(ref_j>=first_j & ref_j<=last_j);
     1727        else
     1728            ref_j=first_j:incr_j:last_j;
     1729        end
     1730    end
     1731    CPUTime=1; % job time estimated at 1 min per iteration (on index i and j) by default
     1732    if isfield(Param.Action, 'CPUTime') && ~isempty(Param.Action.CPUTime)
     1733        CPUTime=Param.Action.CPUTime; % Note: CpUTime for one iteration ref_i has to be multiplied by the number of j indices nbfield_j
     1734    end
     1735    nbfield_j=numel(ref_j); % number of j indices
     1736    BlockLength=numel(ref_i); % by default, job involves the full set of i field indices
     1737    NbProcess=1;
     1738    switch RunMode
     1739        case 'cluster'
     1740            JobNumberMax=SeriesData.SeriesParam.ClusterParam.JobNumberMax;
     1741            JobCPUTimeAdvised=SeriesData.SeriesParam.ClusterParam.JobCPUTimeAdvised;
     1742            if isempty(Param.IndexRange.NbSlice)% if NbSlice is not defined
     1743                BlockLength= ceil(JobCPUTimeAdvised/(CPUTime*nbfield_j)); % iterations are grouped in sets with length BlockLength  such that the typical CPU time of a job is JobCPUTimeAdvised.
     1744                BlockLength=max(BlockLength,ceil(numel(ref_i)*NbExp/JobNumberMax)); % possibly increase the BlockLength to have less than MaxJobNumber jobs
     1745                NbProcess=ceil(numel(ref_i)/BlockLength) ; % nbre of processes sent to oar
     1746            else
     1747                NbProcess=Param.IndexRange.NbSlice; % the parameter NbSlice sets the nbre of run processes
     1748            end
     1749            NbCore=min(NbCore,NbProcess); % reduces the number of cores if it exceeds the number of processes
     1750        otherwise
     1751            if ~isempty(Param.IndexRange.NbSlice)
     1752                NbProcess=Param.IndexRange.NbSlice; % the parameter NbSlice sets the nbre of run processes
     1753            end
     1754    end
     1755   
     1756    %% record nbre of output files and starting time for computation for status
     1757    StatusData=get(handles.status,'UserData');
     1758    if isfield(StatusData,'OutputFileMode')
     1759        switch StatusData.OutputFileMode
     1760            case 'NbInput'
     1761                StatusData.NbOutputFile=numel(ref_i)*nbfield_j;
     1762            case 'NbInput_i'
     1763                StatusData.NbOutputFile=numel(ref_i);
     1764            case 'NbSlice'
     1765                StatusData.NbOutputFile=str2num(get(handles.num_NbSlice,'String'));
     1766        end
     1767    end
     1768    StatusData.TimeStart=now;
     1769    set(handles.status,'UserData',StatusData)
     1770   
     1771    %% case of a function in Python
     1772    if strcmp(ActionExt, '.py (in dev.)')
     1773        fprintf([
     1774            '\n' ...
     1775            '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n' ...
     1776            'The option .py is used. It is still in development.\n' ...
     1777            'To try it, first install pyper and the most recent version of fluidimage\n' ...
     1778            '(see https://bitbucket.org/fluiddyn/fluidimage).\n' ...
     1779            'Warning: there is no direct correspondance between UVMAT and fluidimage parameters\n' ...
     1780            '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n'])
     1781        RunMode = 'python';
     1782    end
     1783   
     1784   
     1785    %% direct processing on the current Matlab session or creation of command files
     1786    filexml=cell(1,NbProcess); % initialisation of the names of the files containing the processing parameters
     1787    extxml=cell(1,NbProcess); % initialisation of the set of labels used for the files documenting each process
     1788    for iprocess=1:NbProcess
     1789        extxml{iprocess}='.xml';
     1790    end
     1791    for iprocess=1:NbProcess
     1792        if ~strcmp(get(handles.RUN,'BusyAction'),'queue')% allow for STOP action
     1793            disp('program stopped by user')
    16151794            return
    1616         elseif strcmp(answer,'Yes')
    1617             detect=0;
    1618             check_create=0;
    1619         else
    1620             r=regexp(SubDirOutNew,'(?<root>.*\D)(?<num1>\d+)$','names'); % detect whether name ends by a number
    1621             if isempty(r)
    1622                 r(1).root=[SubDirOutNew '_'];
    1623                 r(1).num1='0';
    1624             end
    1625             SubDirOutNew=[r(1).root num2str(str2num(r(1).num1)+1)]; % increment the index by 1 or put 1
    1626             detect=exist(fullfile(Param.InputTable{1,1},SubDirOutNew),'dir'); % test if  the dir  already exists
    1627             check_create=1;
    1628         end
    1629     end
    1630     Param.OutputDirExt=regexprep(SubDirOutNew,Param.OutputSubDir,'');
    1631     Param.OutputRootFile=Param.InputTable{1,3}; % the first sorted RootFile taken for output
    1632     set(handles.OutputDirExt,'String',Param.OutputDirExt)
    1633     OutputDir=fullfile(Param.InputTable{1,1},[Param.OutputSubDir Param.OutputDirExt]); % full name (with path) of output directory
    1634     if check_create    % create output directory if it does not exist
    1635         [tild,msg1]=mkdir(OutputDir);
    1636         if ~strcmp(msg1,'')
    1637             errormsg=['cannot create ' OutputDir ': ' msg1]; % error message for directory creation
    1638             return
     1795        end
     1796        if isempty(Param.IndexRange.NbSlice)
     1797            Param.IndexRange.first_i=first_i+(iprocess-1)*BlockLength*incr_i;
     1798            if Param.IndexRange.first_i>last_i
     1799                NbProcess=iprocess-1; % leave the loop, we are at the end of the calculation
     1800                break
     1801            end
     1802            Param.IndexRange.last_i=min(last_i,first_i+(iprocess)*BlockLength*incr_i-1);
     1803        else %multislices (then incr_i is not empty)
     1804            Param.IndexRange.first_i= first_i+iprocess-1;
     1805            Param.IndexRange.incr_i=incr_i*Param.IndexRange.NbSlice;
     1806        end
     1807        for ilist=1:size(Param.InputTable,1)
     1808            Param.InputTable{ilist,1}=regexprep(Param.InputTable{ilist,1},'\','/'); % correct path name for PCWIN system
     1809        end
     1810       
     1811        if isfield(Param,'OutputSubDir')
     1812            t=struct2xml(Param);
     1813            t=set(t,1,'name','Series');
     1814            extxml{iprocess}=fullfile_uvmat('','',Param.InputTable{1,3},'.xml',OutputNomType,...
     1815                Param.IndexRange.first_i,Param.IndexRange.last_i,first_j,last_j);
     1816            filexml{iprocess}=fullfile(OutputDir,'0_XML',extxml{iprocess});
     1817            try
     1818                save(t, filexml{iprocess}); % save the xml file containing the processing parameters
     1819            catch ME
     1820                if ~strcmp (RunMode,'local')
     1821                    errormsg=['error writting ' filexml{iprocess} ': ' ME.message];
     1822                    return
     1823                end
     1824            end
     1825        end
     1826        if strcmp (RunMode,'local')
     1827            switch ActionExt
     1828                case '.m'
     1829                    h_fun(Param); % direct launching
     1830                   
     1831                case '.sh'
     1832                    switch computer
     1833                        case {'PCWIN','PCWIN64'} %Windows system
     1834                            filexml=regexprep(filexml,'\\','\\\\'); % add '\' so that '\' are left as characters
     1835                            system([ActionFullName ' ' RunTime ' ' filexml{iprocess}]); % TODO: adapt to DOS system
     1836                        case {'GLNX86','GLNXA64','MACI64'}%Linux  system
     1837                            system([ActionFullName ' ' RunTime ' ' filexml{iprocess}]);
     1838                    end
     1839            end
    16391840        end
    16401841    end
    16411842   
    1642 elseif isfield(Param,'ActionInput')&&isfield(Param.ActionInput,'LogPath')% custom definition of the output dir
    1643     OutputDir=Param.ActionInput.LogPath;   
    1644 end
    1645 DirXml=fullfile(OutputDir,'0_XML');
    1646 if ~exist(DirXml,'dir')
    1647     [~,msg1]=mkdir(DirXml);
    1648     if ~strcmp(msg1,'')
    1649         errormsg=['cannot create ' DirXml ': ' msg1]; % error message for directory creation
    1650         return
    1651     end
    1652 end
    1653 OutputNomType=nomtype2pair(Param.InputTable{1,4}); % nomenclature for output files
    1654 
    1655 %% get the set of reference input field indices
    1656 first_i=1; % first i index to process
    1657 last_i=1; % last i index to process
    1658 incr_i=1; % increment step in i index
    1659 first_j=1; % first j index to process
    1660 last_j=1; % last j index to process
    1661 incr_j=1; % increment step in j index
    1662 if isfield(Param.IndexRange,'first_i')
    1663     first_i=Param.IndexRange.first_i;
    1664     incr_i=Param.IndexRange.incr_i;
    1665     last_i=Param.IndexRange.last_i;
    1666 end
    1667 if isfield(Param.IndexRange,'incr_j')
    1668     first_j=Param.IndexRange.first_j;
    1669     last_j=Param.IndexRange.last_j;
    1670     incr_j=Param.IndexRange.incr_j;
    1671 end
    1672 if last_i < first_i || last_j < first_j
    1673     errormsg= 'series/Run_Callback:last field index must be larger or equal to the first one';
    1674     return
    1675 end
    1676 %incr_i must be defined, =1 by default, if NbSlice is active
    1677 if isempty(incr_i)&& ~isempty(Param.IndexRange.NbSlice)
    1678     incr_i=1;
    1679     set(handles.num_incr_i,'String','1')
    1680 end
    1681 % case of no increment i defined: processing is done on the available files found in i1_series
    1682 if isempty(incr_i)
    1683     if isempty(incr_j)
    1684         [ref_j,ref_i]=find(squeeze(SeriesData.i1_series{1}(1,:,:)));
    1685         ref_j=ref_j(ref_j>=first_j & ref_j<=last_j);
    1686         ref_i=ref_i(ref_i>=first_i & ref_i<=last_i);
    1687         ref_j=ref_j-1;
    1688         ref_i=ref_i-1;
    1689     else
    1690         ref_j=first_j:incr_j:last_j;
    1691         [tild,ref_i]=find(squeeze(SeriesData.i1_series{1}(1,:,:)));
    1692         ref_i=ref_i-1;
    1693         ref_i=ref_i(ref_i>=first_i & ref_i<=last_i);
    1694     end
    1695     % increment i is defined: processing is done on first_i:incr_i:last_i;
    1696 else
    1697     ref_i=first_i:incr_i:last_i;
    1698     if isempty(incr_j)% automatic finding of the existing j indices
    1699         [ref_j,tild]=find(squeeze(SeriesData.i1_series{1}(1,:,:)));
    1700         ref_j=ref_j-1;
    1701         ref_j=ref_j(ref_j>=first_j & ref_j<=last_j);
    1702     else
    1703         ref_j=first_j:incr_j:last_j;
    1704     end
    1705 end
    1706 CPUTime=1; % job time estimated at 1 min per iteration (on index i and j) by default
    1707 if isfield(Param.Action, 'CPUTime') && ~isempty(Param.Action.CPUTime)
    1708     CPUTime=Param.Action.CPUTime; % Note: CpUTime for one iteration ref_i has to be multiplied by the number of j indices nbfield_j
    1709 end
    1710 nbfield_j=numel(ref_j); % number of j indices
    1711 BlockLength=numel(ref_i); % by default, job involves the full set of i field indices
    1712 NbProcess=1;
    1713 switch RunMode
    1714     case 'cluster'
    1715         JobNumberMax=SeriesData.SeriesParam.ClusterParam.JobNumberMax;
    1716         JobCPUTimeAdvised=SeriesData.SeriesParam.ClusterParam.JobCPUTimeAdvised;
    1717         if isempty(Param.IndexRange.NbSlice)% if NbSlice is not defined
    1718             BlockLength= ceil(JobCPUTimeAdvised/(CPUTime*nbfield_j)); % iterations are grouped in sets with length BlockLength  such that the typical CPU time of a job is MinJobNumber.
    1719             BlockLength=max(BlockLength,ceil(numel(ref_i)/JobNumberMax)); % possibly increase the BlockLength to have less than MaxJobNumber jobs
    1720             NbProcess=ceil(numel(ref_i)/BlockLength) ; % nbre of processes sent to oar
    1721         else
    1722             NbProcess=Param.IndexRange.NbSlice; % the parameter NbSlice sets the nbre of run processes
    1723         end
    1724         NbCore=min(NbCore,NbProcess); % reduces the number of cores if it exceeds the number of processes
    1725     otherwise
    1726         if ~isempty(Param.IndexRange.NbSlice)
    1727             NbProcess=Param.IndexRange.NbSlice; % the parameter NbSlice sets the nbre of run processes
    1728         end
    1729 end
    1730 
    1731 %% record nbre of output files and starting time for computation for status
    1732 StatusData=get(handles.status,'UserData');
    1733 if isfield(StatusData,'OutputFileMode')
    1734     switch StatusData.OutputFileMode
    1735         case 'NbInput'
    1736             StatusData.NbOutputFile=numel(ref_i)*nbfield_j;
    1737         case 'NbInput_i'
    1738             StatusData.NbOutputFile=numel(ref_i);
    1739         case 'NbSlice'
    1740             StatusData.NbOutputFile=str2num(get(handles.num_NbSlice,'String'));
    1741     end
    1742 end
    1743 StatusData.TimeStart=now;
    1744 set(handles.status,'UserData',StatusData)
    1745 
    1746 %% case of a function in Python
    1747 if strcmp(ActionExt, '.py (in dev.)')
    1748     fprintf([
    1749         '\n' ...
    1750         '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n' ...
    1751         'The option .py is used. It is still in development.\n' ...
    1752         'To try it, first install pyper and the most recent version of fluidimage\n' ...
    1753         '(see https://bitbucket.org/fluiddyn/fluidimage).\n' ...
    1754         'Warning: there is no direct correspondance between UVMAT and fluidimage parameters\n' ...
    1755         '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n'])
    1756     RunMode = 'python';
    1757 end
    1758 
    1759 
    1760 %% direct processing on the current Matlab session or creation of command files
    1761 filexml=cell(1,NbProcess); % initialisation of the names of the files containing the processing parameters
    1762 extxml=cell(1,NbProcess); % initialisation of the set of labels used for the files documenting each process
    1763 for iprocess=1:NbProcess
    1764     extxml{iprocess}='.xml';
    1765 end
    1766 for iprocess=1:NbProcess
    1767     if ~strcmp(get(handles.RUN,'BusyAction'),'queue')% allow for STOP action
    1768         disp('program stopped by user')
    1769         return
    1770     end
    1771     if isempty(Param.IndexRange.NbSlice)
    1772         Param.IndexRange.first_i=first_i+(iprocess-1)*BlockLength*incr_i;
    1773         if Param.IndexRange.first_i>last_i
    1774             NbProcess=iprocess-1; % leave the loop, we are at the end of the calculation
    1775             break
    1776         end
    1777         Param.IndexRange.last_i=min(last_i,first_i+(iprocess)*BlockLength*incr_i-1);
    1778     else %multislices (then incr_i is not empty)
    1779         Param.IndexRange.first_i= first_i+iprocess-1;
    1780         Param.IndexRange.incr_i=incr_i*Param.IndexRange.NbSlice;
    1781     end
    1782     for ilist=1:size(Param.InputTable,1)
    1783         Param.InputTable{ilist,1}=regexprep(Param.InputTable{ilist,1},'\','/'); % correct path name for PCWIN system
     1843    if ~strcmp (RunMode,'local') && ~strcmp(RunMode,'python')
     1844        %% processing on a different session of the same computer (background) or cluster, create executable files
     1845        batch_file_list=cell(NbProcess,1); % initiate the list of executable files
     1846        DirExe=fullfile(OutputDir,'0_EXE'); % directory name for executable files
     1847        switch computer
     1848            case {'PCWIN','PCWIN64'} %Windows system
     1849                ExeExt='.bat';
     1850            case {'GLNX86','GLNXA64','MACI64'}%Linux  system
     1851                ExeExt='.sh';
     1852        end
     1853        %create subdirectory for executable files
     1854        if ~exist(DirExe,'dir')
     1855            [tild,msg1]=mkdir(DirExe);
     1856            if ~strcmp(msg1,'')
     1857                errormsg=['cannot create ' DirExe ': ' msg1]; % error message for directory creation
     1858                return
     1859            end
     1860        end
     1861        %create subdirectory for log files
     1862        DirLog=fullfile(OutputDir,'0_LOG');
     1863        if ~exist(DirLog,'dir')
     1864            [tild,msg1]=mkdir(DirLog);
     1865            if ~strcmp(msg1,'')
     1866                errormsg=['cannot create ' DirLog ': ' msg1]; % error message for directory creation
     1867                return
     1868            end
     1869        end
     1870       
     1871        %create the executable file
     1872        file_exe_global=fullfile_uvmat('','',Param.InputTable{1,3},ExeExt,OutputNomType,...
     1873            first_i,last_i,first_j,last_j);
     1874        file_exe_global=fullfile(OutputDir,'0_EXE',file_exe_global);
     1875        filelog_global=fullfile_uvmat('','',Param.InputTable{1,3},'.log',OutputNomType,...
     1876            first_i,last_i,first_j,last_j);
     1877        filelog_global=fullfile(OutputDir,'0_LOG',filelog_global);
     1878       
     1879        for iprocess=1:NbProcess
     1880            %create the executable file
     1881            batch_file_list{iprocess}=fullfile(OutputDir,'0_EXE',regexprep(extxml{iprocess},'.xml$',ExeExt));
     1882           
     1883            % set the log file name
     1884            filelog{iprocess}=fullfile(OutputDir,'0_LOG',regexprep(extxml{iprocess},'.xml$','.log'));
     1885        end
    17841886    end
    17851887   
    1786     if isfield(Param,'OutputSubDir')
    1787         t=struct2xml(Param);
    1788         t=set(t,1,'name','Series');
    1789         extxml{iprocess}=fullfile_uvmat('','',Param.InputTable{1,3},'.xml',OutputNomType,...
    1790             Param.IndexRange.first_i,Param.IndexRange.last_i,first_j,last_j);
    1791         filexml{iprocess}=fullfile(OutputDir,'0_XML',extxml{iprocess});
    1792         try
    1793             save(t, filexml{iprocess}); % save the xml file containing the processing parameters
    1794         catch ME
    1795             if ~strcmp (RunMode,'local')
    1796                 errormsg=['error writting ' filexml{iprocess} ': ' ME.message];
     1888    %% launch the executable files for background or cluster processing
     1889   
     1890    switch RunMode
     1891       
     1892        case 'background'
     1893            [fid,message]=fopen(file_exe_global,'w');
     1894            if isequal(fid,-1)
     1895                errormsg=['creation of ' file_exe_global ':' message];
    17971896                return
    17981897            end
    1799         end
    1800     end
    1801     if strcmp (RunMode,'local')
    1802         switch ActionExt
    1803             case '.m'
    1804                 h_fun(Param); % direct launching
    1805                
    1806             case '.sh'
    1807                 switch computer
    1808                     case {'PCWIN','PCWIN64'} %Windows system
    1809                         filexml=regexprep(filexml,'\\','\\\\'); % add '\' so that '\' are left as characters
    1810                         system([ActionFullName ' ' RunTime ' ' filexml{iprocess}]); % TODO: adapt to DOS system
    1811                     case {'GLNX86','GLNXA64','MACI64'}%Linux  system
    1812                         system([ActionFullName ' ' RunTime ' ' filexml{iprocess}]);
    1813                 end
    1814         end
    1815     end
    1816 end
    1817 
    1818 if ~strcmp (RunMode,'local') && ~strcmp(RunMode,'python')
    1819     %% processing on a different session of the same computer (background) or cluster, create executable files
    1820     batch_file_list=cell(NbProcess,1); % initiate the list of executable files
    1821     DirExe=fullfile(OutputDir,'0_EXE'); % directory name for executable files
    1822     switch computer
    1823         case {'PCWIN','PCWIN64'} %Windows system
    1824             ExeExt='.bat';
    1825         case {'GLNX86','GLNXA64','MACI64'}%Linux  system
    1826             ExeExt='.sh';
    1827     end
    1828     %create subdirectory for executable files
    1829     if ~exist(DirExe,'dir')
    1830         [tild,msg1]=mkdir(DirExe);
    1831         if ~strcmp(msg1,'')
    1832             errormsg=['cannot create ' DirExe ': ' msg1]; % error message for directory creation
    1833             return
    1834         end
    1835     end
    1836     %create subdirectory for log files
    1837     DirLog=fullfile(OutputDir,'0_LOG');
    1838     if ~exist(DirLog,'dir')
    1839         [tild,msg1]=mkdir(DirLog);
    1840         if ~strcmp(msg1,'')
    1841             errormsg=['cannot create ' DirLog ': ' msg1]; % error message for directory creation
    1842             return
    1843         end
    1844     end
    1845    
    1846     %create the executable file
    1847     file_exe_global=fullfile_uvmat('','',Param.InputTable{1,3},ExeExt,OutputNomType,...
    1848         first_i,last_i,first_j,last_j);
    1849     file_exe_global=fullfile(OutputDir,'0_EXE',file_exe_global);
    1850     filelog_global=fullfile_uvmat('','',Param.InputTable{1,3},'.log',OutputNomType,...
    1851         first_i,last_i,first_j,last_j);
    1852     filelog_global=fullfile(OutputDir,'0_LOG',filelog_global);
    1853 
    1854     for iprocess=1:NbProcess   
    1855         %create the executable file       
    1856         batch_file_list{iprocess}=fullfile(OutputDir,'0_EXE',regexprep(extxml{iprocess},'.xml$',ExeExt));
    1857        
    1858         % set the log file name
    1859         filelog{iprocess}=fullfile(OutputDir,'0_LOG',regexprep(extxml{iprocess},'.xml$','.log'));     
    1860     end
    1861 end
    1862 
    1863 %% launch the executable files for background or cluster processing
    1864 
    1865 switch RunMode
    1866    
    1867     case 'background'
    1868         [fid,message]=fopen(file_exe_global,'w');
    1869         if isequal(fid,-1)
    1870             errormsg=['creation of ' file_exe_global ':' message];
    1871             return
    1872         end
    1873         switch ActionExt
    1874             case '.m'% Matlab function
    1875                 switch computer
    1876                     case {'GLNX86','GLNXA64','MACI64'}
    1877                         matlab_ver = ver('MATLAB');
    1878                         matlab_version = matlab_ver.Version;
    1879                         cmd=[...
    1880                             '#!/bin/bash\n'...
    1881                             'source /etc/profile\n'...
    1882                             'module load matlab/' matlab_version '\n'...% CHOICE OF MATLAB VERSION
    1883                             'time_start=$(date +%%s)\n'...
    1884                             'matlab -nodisplay -nosplash -nojvm -logfile ''' filelog_global ''' <<END_MATLAB\n'...
    1885                             'addpath(''' path_series ''');\n'...
    1886                             'addpath(''' Param.Action.ActionPath ''');\n'];
    1887                         for iprocess=1:NbProcess
    1888                             cmd=[cmd '' Param.Action.ActionName  '(''' filexml{iprocess} ''');\n'];
    1889                         end
    1890                         cmd=[cmd  'exit\n' 'END_MATLAB\n'...
    1891                             'time_end=$(date +%%s)\n'...
    1892                             'echo "global time = " $(($time_end - $time_start)) >> ''' filelog_global '''\n'];
    1893                         fprintf(fid,cmd); % fill the executable file with the  char string cmd
    1894                         fclose(fid); % close the executable filefilelog_global
    1895                         system(['chmod +x ' file_exe_global]); % set the file to executable
    1896                     case {'PCWIN','PCWIN64'}
    1897                         cmd=['matlab -automation -logfile ' regexprep(filelog{iprocess},'\\','\\\\')...
    1898                             ' -r "addpath(''' regexprep(path_series,'\\','\\\\') ''');'...
    1899                             'addpath(''' regexprep(Param.Action.ActionPath,'\\','\\\\') ''');'];
    1900                         for iprocess=1:NbProcess
    1901                             cmd=[cmd '' Param.Action.ActionName  '( ''' regexprep(filexml{iprocess},'\\','\\\\') ''');']
    1902                         end
    1903                         cmd=[cmd ';exit"'];
    1904                         fprintf(fid,cmd); % fill the executable file with the  char string cmd
    1905                         fclose(fid); % close the executable file
    1906                 end
    1907                 system([file_exe_global ' &'])% directly execute the command file
    1908             case '.sh' % compiled Matlab function
    1909                 for iprocess=1:NbProcess
     1898            switch ActionExt
     1899                case '.m'% Matlab function
    19101900                    switch computer
    19111901                        case {'GLNX86','GLNXA64','MACI64'}
    1912                             [fid,message]=fopen(batch_file_list{iprocess},'w'); % create the executable file
    1913                             if isequal(fid,-1)
    1914                                 errormsg=['creation of .bat file: ' message];
    1915                                 return
     1902                            matlab_ver = ver('MATLAB');
     1903                            matlab_version = matlab_ver.Version;
     1904                            cmd=[...
     1905                                '#!/bin/bash\n'...
     1906                                'source /etc/profile\n'...
     1907                                'module load matlab/' matlab_version '\n'...% CHOICE OF MATLAB VERSION
     1908                                'time_start=$(date +%%s)\n'...
     1909                                'matlab -nodisplay -nosplash -nojvm -logfile ''' filelog_global ''' <<END_MATLAB\n'...
     1910                                'addpath(''' path_series ''');\n'...
     1911                                'addpath(''' Param.Action.ActionPath ''');\n'];
     1912                            for iprocess=1:NbProcess
     1913                                cmd=[cmd '' Param.Action.ActionName  '(''' filexml{iprocess} ''');\n'];
    19161914                            end
    1917                             cmd=['#!/bin/bash \n '...
    1918                                 '#$ -cwd \n '...
    1919                                 'hostname && date \n '...
    1920                                 'umask 002 \n'...
    1921                                 ActionFullName ' ' RunTime ' ' filexml{iprocess}]; % allow writting access to created files for user group
     1915                            cmd=[cmd  'exit\n' 'END_MATLAB\n'...
     1916                                'time_end=$(date +%%s)\n'...
     1917                                'echo "global time = " $(($time_end - $time_start)) >> ''' filelog_global '''\n'];
     1918                            fprintf(fid,cmd); % fill the executable file with the  char string cmd
     1919                            fclose(fid); % close the executable filefilelog_global
     1920                            system(['chmod +x ' file_exe_global]); % set the file to executable
     1921                        case {'PCWIN','PCWIN64'}
     1922                            cmd=['matlab -automation -logfile ' regexprep(filelog{iprocess},'\\','\\\\')...
     1923                                ' -r "addpath(''' regexprep(path_series,'\\','\\\\') ''');'...
     1924                                'addpath(''' regexprep(Param.Action.ActionPath,'\\','\\\\') ''');'];
     1925                            for iprocess=1:NbProcess
     1926                                cmd=[cmd '' Param.Action.ActionName  '( ''' regexprep(filexml{iprocess},'\\','\\\\') ''');']
     1927                            end
     1928                            cmd=[cmd ';exit"'];
    19221929                            fprintf(fid,cmd); % fill the executable file with the  char string cmd
    19231930                            fclose(fid); % close the executable file
    1924                             system(['chmod +x ' batch_file_list{iprocess}]); % set the file to executable
    1925                             system([batch_file_list{iprocess} ' &'])% directly execute the command file
    1926                         case {'PCWIN','PCWIN64'}
    1927                             msgbox_uvmat('ERROR','option for compiled Matlab functions not implemented for Windows system')
    1928                             return
    19291931                    end
     1932                    system([file_exe_global ' &'])% directly execute the command file
     1933                case '.sh' % compiled Matlab function
     1934                    for iprocess=1:NbProcess
     1935                        switch computer
     1936                            case {'GLNX86','GLNXA64','MACI64'}
     1937                                [fid,message]=fopen(batch_file_list{iprocess},'w'); % create the executable file
     1938                                if isequal(fid,-1)
     1939                                    errormsg=['creation of .bat file: ' message];
     1940                                    return
     1941                                end
     1942                                cmd=['#!/bin/bash \n '...
     1943                                    '#$ -cwd \n '...
     1944                                    'hostname && date \n '...
     1945                                    'umask 002 \n'...
     1946                                    ActionFullName ' ' RunTime ' ' filexml{iprocess}]; % allow writting access to created files for user group
     1947                                fprintf(fid,cmd); % fill the executable file with the  char string cmd
     1948                                fclose(fid); % close the executable file
     1949                                system(['chmod +x ' batch_file_list{iprocess}]); % set the file to executable
     1950                                system([batch_file_list{iprocess} ' &'])% directly execute the command file
     1951                            case {'PCWIN','PCWIN64'}
     1952                                msgbox_uvmat('ERROR','option for compiled Matlab functions not implemented for Windows system')
     1953                                return
     1954                        end
     1955                    end
     1956                    msgbox_uvmat('CONFIRMATION',[ActionFullName ' launched in background for ' ExpName ': press STATUS to see results'])
     1957            end
     1958           
     1959        case 'cluster' % option 'oar-parexec' used
     1960            %create subdirectory for oar commands
     1961            for iprocess=1:NbProcess
     1962                [fid,message]=fopen(batch_file_list{iprocess},'w'); % create the executable file
     1963                if isequal(fid,-1)
     1964                    errormsg=['creation of .bat file: ' message];
     1965                    return
    19301966                end
    1931                 msgbox_uvmat('CONFIRMATION',[ActionFullName ' launched in background: press STATUS to see results'])
    1932         end
    1933        
    1934     case 'cluster' % option 'oar-parexec' used
    1935         %create subdirectory for oar commands
    1936         for iprocess=1:NbProcess
    1937             [fid,message]=fopen(batch_file_list{iprocess},'w'); % create the executable file
    1938             if isequal(fid,-1)
    1939                 errormsg=['creation of .bat file: ' message];
    1940                 return
    1941             end
    1942             if  strcmp(ActionExt,'.sh')
    1943                 cmd=['#!/bin/bash \n '...
    1944                     '#$ -cwd \n '...
    1945                     'hostname && date \n '...
    1946                     'umask 002 \n'...
    1947                     ActionFullName ' ' RunTime ' ' filexml{iprocess}]; % allow writting access to created files for user group
     1967                if  strcmp(ActionExt,'.sh')
     1968                    cmd=['#!/bin/bash \n '...
     1969                        '#$ -cwd \n '...
     1970                        'hostname && date \n '...
     1971                        'umask 002 \n'...
     1972                        ActionFullName ' ' RunTime ' ' filexml{iprocess}]; % allow writting access to created files for user group
     1973                else
     1974                    matlab_ver = ver('MATLAB');
     1975                    matlab_version = matlab_ver.Version;
     1976                    cmd=[...
     1977                        '#!/bin/bash\n'...
     1978                        'source /etc/profile\n'...
     1979                        'module load matlab/' matlab_version '\n'...% CHOICE OF MATLAB VERSION
     1980                        'matlab -nodisplay -nosplash -nojvm -singleCompThread -logfile ''' filelog{iprocess} ''' <<END_MATLAB\n'...
     1981                        'addpath(''' path_series ''');\n'...
     1982                        'addpath(''' Param.Action.ActionPath ''');\n'...
     1983                        '' Param.Action.ActionName  '(''' filexml{iprocess} ''');\n'...
     1984                        'exit\n'...
     1985                        'END_MATLAB\n'];
     1986                end
     1987                fprintf(fid,cmd); % fill the executable file with the  char string cmd
     1988                fclose(fid); % close the executable file
     1989                system(['chmod +x ' batch_file_list{iprocess}]); % set the file to executable
     1990            end
     1991            DIR_CLUSTER=fullfile(OutputDir,'0_CLUSTER');
     1992            if exist(DIR_CLUSTER,'dir')% delete the content of the dir 0_LOG to allow new input
     1993                curdir=pwd;
     1994                cd(DIR_CLUSTER)
     1995                delete('*')
     1996                cd(curdir)
    19481997            else
    1949                 matlab_ver = ver('MATLAB');
    1950                 matlab_version = matlab_ver.Version;
    1951                 cmd=[...
    1952                     '#!/bin/bash\n'...
    1953                     'source /etc/profile\n'...
    1954                     'module load matlab/' matlab_version '\n'...% CHOICE OF MATLAB VERSION
    1955                     'matlab -nodisplay -nosplash -nojvm -singleCompThread -logfile ''' filelog{iprocess} ''' <<END_MATLAB\n'...
    1956                     'addpath(''' path_series ''');\n'...
    1957                     'addpath(''' Param.Action.ActionPath ''');\n'...
    1958                     '' Param.Action.ActionName  '(''' filexml{iprocess} ''');\n'...
    1959                     'exit\n'...
    1960                     'END_MATLAB\n'];
    1961             end
    1962             fprintf(fid,cmd); % fill the executable file with the  char string cmd
    1963             fclose(fid); % close the executable file
    1964             system(['chmod +x ' batch_file_list{iprocess}]); % set the file to executable
    1965         end
    1966         DIR_CLUSTER=fullfile(OutputDir,'0_CLUSTER');
    1967         if exist(DIR_CLUSTER,'dir')% delete the content of the dir 0_LOG to allow new input
    1968             curdir=pwd;
    1969             cd(DIR_CLUSTER)
    1970             delete('*')
    1971             cd(curdir)
    1972         else
    1973             [tild,msg1]=mkdir(DIR_CLUSTER);
    1974             if ~strcmp(msg1,'')
    1975                 errormsg=['cannot create ' DIR_CLUSTER ': ' msg1]; % error message for directory creation
    1976                 return
    1977             end
    1978         end
    1979         % create file containing the list of jobs
    1980         ListProcess=fullfile(DIR_CLUSTER,'job_list.txt'); % name of the file containing the list of executables
    1981         fid=fopen(ListProcess,'w'); % open it for writting
    1982         for iprocess=1:length(batch_file_list)
    1983             fprintf(fid,[batch_file_list{iprocess} '\n']); % write list of exe files
    1984         end
    1985         fclose(fid);
    1986         system(['chmod +x ' ListProcess]); % set the file to executable
    1987  
    1988         CPUTimeProcess=CPUTime*BlockLength*nbfield_j; % estimated CPU time for one individual process (in minutes)
    1989         LaunchCmdFcn=SeriesData.SeriesParam.ClusterParam.LaunchCmdFcn;
    1990         oar_command=feval(LaunchCmdFcn,ListProcess,ActionFullName,DirLog,NbProcess, NbCore,CPUTimeProcess)
    1991         [status,result]=system(oar_command)% execute system command and show the result (ID number of the launched job) on the Matlab command window
    1992         filename_oarcommand=fullfile(DIR_CLUSTER,'0_cluster_command'); % keep track of the command in file '0-OAR/0_cluster_command'
    1993         fid=fopen(filename_oarcommand,'w');
    1994         fprintf(fid,oar_command); % store the command
    1995         fprintf(fid,result); % store the result (job ID number)
    1996         fclose(fid);
    1997         msgbox_uvmat('CONFIRMATION',[ActionFullName ' launched as  ' num2str(NbProcess) ' processes in cluster: press STATUS to see results'])
    1998        
    1999 %     case 'cluster_pbs' % for LMFA Kepler machine:  trqnsferred to fct
    2000 
    2001 %         %create subdirectory for pbs command and log files
    2002 %         DirPBS=fullfile(OutputDir,'0_PBS'); % todo : common name OAR/PBS
    2003 %         if exist(DirPBS,'dir')% delete the content of the dir 0_LOG to allow new input
    2004 %             curdir=pwd;
    2005 %             cd(DirPBS)
    2006 %             delete('*')
    2007 %             cd(curdir)
    2008 %         else
    2009 %             [tild,msg1]=mkdir(DirPBS);
    2010 %             if ~strcmp(msg1,'')
    2011 %                 errormsg=['cannot create ' DirPBS ': ' msg1]; % error message for directory creation
    2012 %                 return
    2013 %             end
    2014 %         end
    2015 %         max_walltime=3600*20; % 20h max total calculation (cannot exceed 24 h)
    2016 %         walltime_onejob=1800; % seconds, max estimated time for asingle file index value
    2017 %         ListProcess=fullfile(DirPBS,'job_list.txt'); % create name of the global executable file
    2018 %         fid=fopen(ListProcess,'w');
    2019 %         for iprocess=1:length(batch_file_list)
    2020 %             fprintf(fid,[batch_file_list{iprocess} '\n']); % list of exe files
    2021 %         end
    2022 %         fclose(fid);
    2023 %         system(['chmod +x ' ListProcess]); % set the file to executable
    2024 %         pbs_command=['qsub -n CIVX '...
    2025 %             '-t idempotent --checkpoint ' num2str(walltime_onejob+60) ' '...
    2026 %             '-l /core=' num2str(NbCore) ','...
    2027 %             'walltime=' datestr(min(1.05*walltime_onejob/86400*max(NbProcess*BlockLength*nbfield_j,NbCore)/NbCore,max_walltime/86400),13) ' '...
    2028 %             '-E ' regexprep(ListProcess,'\.txt\>','.stderr') ' '...
    2029 %             '-O ' regexprep(ListProcess,'\.txt\>','.log') ' '...
    2030 %             extra_qstat ' '...
    2031 %             '"oar-parexec -s -f ' ListProcess ' '...
    2032 %             '-l ' ListProcess '.log"'];
    2033 %         filename_oarcommand=fullfile(DirPBS,'pbs_command');
    2034 %         fid=fopen(filename_oarcommand,'w');
    2035 %         fprintf(fid,pbs_command);
    2036 %         fclose(fid);
    2037 %         fprintf(pbs_command); % display in command line
    2038 %         %system(pbs_command);
    2039 %         msgbox_uvmat('CONFIRMATION',[ActionFullName ' command ready to be launched in cluster'])
    2040 
    2041      case 'cluster_sge' % for PSMN % TODO: use the standard 'cluster' config with an external fct
    2042         % Au PSMN, on ne cr??e pas 1 job avec plusieurs c??urs, mais N jobs de 1 c??urs
    2043         % o?? N < 1000.
    2044         %create subdirectory for pbs command and log files
    2045 
    2046         DirSGE=fullfile(OutputDir,'0_SGE');
    2047         if exist(DirSGE,'dir')% delete the content of the dir 0_LOG to allow new input
    2048             curdir=pwd;
    2049             cd(DirSGE)
    2050             delete('*')
    2051             cd(curdir)
    2052         else
    2053             [tild,msg1]=mkdir(DirSGE);
    2054             if ~strcmp(msg1,'')
    2055                 errormsg=['cannot create ' DirSGE ': ' msg1]; % error message for directory creation
    2056                 return
    2057             end
    2058         end
    2059         maxImgsPerJob = ceil(length(batch_file_list)/NbCore);
    2060         disp(['Max number of jobs: ' num2str(NbCore)])
    2061         disp(['Images per job: ' num2str(maxImgsPerJob)])
    2062        
    2063         iprocess = 1;
    2064         imgsInJob = [];
    2065         currJobIndex = 1;
    2066         done = 0;
    2067         while(~done)
    2068             if(iprocess <= length(batch_file_list))
    2069                 imgsInJob = [imgsInJob, iprocess];
    2070             end
    2071             if((numel(imgsInJob) >= maxImgsPerJob) || (iprocess == length(batch_file_list)))
    2072                 cmd=['#!/bin/sh \n'...
    2073                      '#$ -cwd \n'...
    2074                      'hostname && date\n']
    2075                 for ii=1:numel(imgsInJob)
    2076                     cmd=[cmd ActionFullName ' /softs/matlab ' filexml{imgsInJob(ii)} '\n'];
     1998                [tild,msg1]=mkdir(DIR_CLUSTER);
     1999                if ~strcmp(msg1,'')
     2000                    errormsg=['cannot create ' DIR_CLUSTER ': ' msg1]; % error message for directory creation
     2001                    return
    20772002                end
    2078                 [fid, message] = fopen([DirSGE '/job' num2str(currJobIndex) '.sh'], 'w');
    2079                 fprintf(fid, cmd);
    2080                 fclose(fid);
    2081                 system(['chmod +x ' DirSGE '/job' num2str(currJobIndex) '.sh'])
    2082                 sge_command=['qsub -N civ_' num2str(currJobIndex) ' '...
    2083                     '-q ' qstat_Queue ' '...
    2084                     '-e ' fullfile([DirSGE '/job' num2str(currJobIndex) '.out']) ' '...
    2085                     '-o ' fullfile([DirSGE '/job' num2str(currJobIndex) '.out']) ' '...
    2086                     fullfile([DirSGE '/job' num2str(currJobIndex) '.sh'])];
    2087                 fprintf(sge_command); % display in command line
    2088                 [status, result] = system(sge_command);
    2089                 fprintf(result);
    2090                 currJobIndex = currJobIndex + 1;
    2091                 imgsInJob = [];
    2092             end
    2093             if(iprocess == length(batch_file_list))
    2094                 done = 1;
    2095             end
    2096             iprocess = iprocess + 1;
    2097         end
    2098         msgbox_uvmat('CONFIRMATION',[num2str(currJobIndex-1) ' jobs launched on queue ' qstat_Queue '.'])
    2099     case 'python'
    2100         command = ['LD_LIBRARY_PATH=$(echo $LD_LIBRARY_PATH | pyp "l = x.split('':''); l = [s for s in l if ''matlab'' not in s]; print('':''.join(l))") ' ...
    2101             'python -m fluidimage.run_from_xml ' filexml{iprocess}];
    2102         fprintf(['command:\n' command '\n\n'])
    2103         system(command, '-echo');
    2104 end
    2105 if exist(OutputDir,'dir')
    2106     [SUCCESS,MESSAGE,MESSAGEID] = fileattrib (OutputDir);
    2107     if MESSAGE.GroupWrite~=1
    2108     [success,msg] = fileattrib(OutputDir,'+w','g','s'); % allow writing access for the group of users, recursively in the folder
    2109     if success==0
    2110         msgbox_uvmat('WARNING',{['unable to set group write access to ' OutputDir ':']; msg}); % error message for directory creation
    2111     end
    2112     end
    2113 end
    2114 
     2003            end
     2004            % create file containing the list of jobs
     2005            ListProcess=fullfile(DIR_CLUSTER,'job_list.txt'); % name of the file containing the list of executables
     2006            fid=fopen(ListProcess,'w'); % open it for writting
     2007            for iprocess=1:length(batch_file_list)
     2008                fprintf(fid,[batch_file_list{iprocess} '\n']); % write list of exe files
     2009            end
     2010            fclose(fid);
     2011            system(['chmod +x ' ListProcess]); % set the file to executable
     2012           
     2013            CPUTimeProcess=CPUTime*BlockLength*nbfield_j; % estimated CPU time for one individual process (in minutes)
     2014            LaunchCmdFcn=SeriesData.SeriesParam.ClusterParam.LaunchCmdFcn;
     2015            oar_command=feval(LaunchCmdFcn,ListProcess,ActionFullName,DirLog,NbProcess, NbCore,CPUTimeProcess)
     2016            [status,result]=system(oar_command)% execute system command and show the result (ID number of the launched job) on the Matlab command window
     2017            filename_oarcommand=fullfile(DIR_CLUSTER,'0_cluster_command'); % keep track of the command in file '0-OAR/0_cluster_command'
     2018            fid=fopen(filename_oarcommand,'w');
     2019            fprintf(fid,oar_command); % store the command
     2020            fprintf(fid,result); % store the result (job ID number)
     2021            fclose(fid);
     2022            if status==0
     2023            msgbox_uvmat('CONFIRMATION',[ActionFullName ' launched for ' ExpName ' as ' num2str(NbProcess) ' processes in cluster: press STATUS to see results'])
     2024            else
     2025               msgbox_uvmat('ERROR',result)
     2026            end
     2027            %     case 'cluster_pbs' % for LMFA Kepler machine:  trqnsferred to fct
     2028           
     2029            %         %create subdirectory for pbs command and log files
     2030            %         DirPBS=fullfile(OutputDir,'0_PBS'); % todo : common name OAR/PBS
     2031            %         if exist(DirPBS,'dir')% delete the content of the dir 0_LOG to allow new input
     2032            %             curdir=pwd;
     2033            %             cd(DirPBS)
     2034            %             delete('*')
     2035            %             cd(curdir)
     2036            %         else
     2037            %             [tild,msg1]=mkdir(DirPBS);
     2038            %             if ~strcmp(msg1,'')
     2039            %                 errormsg=['cannot create ' DirPBS ': ' msg1]; % error message for directory creation
     2040            %                 return
     2041            %             end
     2042            %         end
     2043            %         max_walltime=3600*20; % 20h max total calculation (cannot exceed 24 h)
     2044            %         walltime_onejob=1800; % seconds, max estimated time for asingle file index value
     2045            %         ListProcess=fullfile(DirPBS,'job_list.txt'); % create name of the global executable file
     2046            %         fid=fopen(ListProcess,'w');
     2047            %         for iprocess=1:length(batch_file_list)
     2048            %             fprintf(fid,[batch_file_list{iprocess} '\n']); % list of exe files
     2049            %         end
     2050            %         fclose(fid);
     2051            %         system(['chmod +x ' ListProcess]); % set the file to executable
     2052            %         pbs_command=['qsub -n CIVX '...
     2053            %             '-t idempotent --checkpoint ' num2str(walltime_onejob+60) ' '...
     2054            %             '-l /core=' num2str(NbCore) ','...
     2055            %             'walltime=' datestr(min(1.05*walltime_onejob/86400*max(NbProcess*BlockLength*nbfield_j,NbCore)/NbCore,max_walltime/86400),13) ' '...
     2056            %             '-E ' regexprep(ListProcess,'\.txt\>','.stderr') ' '...
     2057            %             '-O ' regexprep(ListProcess,'\.txt\>','.log') ' '...
     2058            %             extra_qstat ' '...
     2059            %             '"oar-parexec -s -f ' ListProcess ' '...
     2060            %             '-l ' ListProcess '.log"'];
     2061            %         filename_oarcommand=fullfile(DirPBS,'pbs_command');
     2062            %         fid=fopen(filename_oarcommand,'w');
     2063            %         fprintf(fid,pbs_command);
     2064            %         fclose(fid);
     2065            %         fprintf(pbs_command); % display in command line
     2066            %         %system(pbs_command);
     2067            %         msgbox_uvmat('CONFIRMATION',[ActionFullName ' command ready to be launched in cluster'])
     2068           
     2069        case 'cluster_sge' % for PSMN % TODO: use the standard 'cluster' config with an external fct
     2070            % Au PSMN, on ne cr??e pas 1 job avec plusieurs c??urs, mais N jobs de 1 c??urs
     2071            % o?? N < 1000.
     2072            %create subdirectory for pbs command and log files
     2073           
     2074            DirSGE=fullfile(OutputDir,'0_SGE');
     2075            if exist(DirSGE,'dir')% delete the content of the dir 0_LOG to allow new input
     2076                curdir=pwd;
     2077                cd(DirSGE)
     2078                delete('*')
     2079                cd(curdir)
     2080            else
     2081                [tild,msg1]=mkdir(DirSGE);
     2082                if ~strcmp(msg1,'')
     2083                    errormsg=['cannot create ' DirSGE ': ' msg1]; % error message for directory creation
     2084                    return
     2085                end
     2086            end
     2087            maxImgsPerJob = ceil(length(batch_file_list)/NbCore);
     2088            disp(['Max number of jobs: ' num2str(NbCore)])
     2089            disp(['Images per job: ' num2str(maxImgsPerJob)])
     2090           
     2091            iprocess = 1;
     2092            imgsInJob = [];
     2093            currJobIndex = 1;
     2094            done = 0;
     2095            while(~done)
     2096                if(iprocess <= length(batch_file_list))
     2097                    imgsInJob = [imgsInJob, iprocess];
     2098                end
     2099                if((numel(imgsInJob) >= maxImgsPerJob) || (iprocess == length(batch_file_list)))
     2100                    cmd=['#!/bin/sh \n'...
     2101                        '#$ -cwd \n'...
     2102                        'hostname && date\n']
     2103                    for ii=1:numel(imgsInJob)
     2104                        cmd=[cmd ActionFullName ' /softs/matlab ' filexml{imgsInJob(ii)} '\n'];
     2105                    end
     2106                    [fid, message] = fopen([DirSGE '/job' num2str(currJobIndex) '.sh'], 'w');
     2107                    fprintf(fid, cmd);
     2108                    fclose(fid);
     2109                    system(['chmod +x ' DirSGE '/job' num2str(currJobIndex) '.sh'])
     2110                    sge_command=['qsub -N civ_' num2str(currJobIndex) ' '...
     2111                        '-q ' qstat_Queue ' '...
     2112                        '-e ' fullfile([DirSGE '/job' num2str(currJobIndex) '.out']) ' '...
     2113                        '-o ' fullfile([DirSGE '/job' num2str(currJobIndex) '.out']) ' '...
     2114                        fullfile([DirSGE '/job' num2str(currJobIndex) '.sh'])];
     2115                    fprintf(sge_command); % display in command line
     2116                    [status, result] = system(sge_command);
     2117                    fprintf(result);
     2118                    currJobIndex = currJobIndex + 1;
     2119                    imgsInJob = [];
     2120                end
     2121                if(iprocess == length(batch_file_list))
     2122                    done = 1;
     2123                end
     2124                iprocess = iprocess + 1;
     2125            end
     2126            msgbox_uvmat('CONFIRMATION',[num2str(currJobIndex-1) ' jobs launched on queue ' qstat_Queue '.'])
     2127        case 'python'
     2128            command = ['LD_LIBRARY_PATH=$(echo $LD_LIBRARY_PATH | pyp "l = x.split('':''); l = [s for s in l if ''matlab'' not in s]; print('':''.join(l))") ' ...
     2129                'python -m fluidimage.run_from_xml ' filexml{iprocess}];
     2130            fprintf(['command:\n' command '\n\n'])
     2131            system(command, '-echo');
     2132    end
     2133    if exist(OutputDir,'dir')
     2134        [SUCCESS,MESSAGE,MESSAGEID] = fileattrib (OutputDir);
     2135        if MESSAGE.GroupWrite~=1
     2136            [success,msg] = fileattrib(OutputDir,'+w','g','s'); % allow writing access for the group of users, recursively in the folder
     2137            if success==0
     2138                msgbox_uvmat('WARNING',{['unable to set group write access to ' OutputDir ':']; msg}); % error message for directory creation
     2139            end
     2140        end
     2141    end
     2142end
    21152143%------------------------------------------------------------------------
    21162144function STOP_Callback(hObject, eventdata, handles)
     
    34743502end
    34753503
    3476 %function num_NbProcess_Callback(hObject, eventdata, handles)
    3477 
    34783504
    34793505function num_NbSlice_Callback(hObject, eventdata, handles)
    34803506NbSlice=str2num(get(handles.num_NbSlice,'String'));
    3481 %set(handles.num_NbProcess,'String',num2str(NbSlice))
    34823507
    34833508%------------------------------------------------------------------------
     
    35203545
    35213546% --- Executes on mouse motion over figure - except title and menu.
    3522 function series_WindowButtonMotionFcn(hObject, eventdata, handles)
    3523 set(hObject,'Pointer','arrow');
     3547% function series_WindowButtonMotionFcn(hObject, eventdata, handles)
     3548% set(hObject,'Pointer','arrow');
    35243549
    35253550
     
    37363761
    37373762
     3763% --- Executes on button press in Replicate.
     3764function Replicate_Callback(hObject, eventdata, handles)
     3765if get(handles.Replicate,'Value')
     3766InputTable=get(handles.InputTable,'Data');
     3767browse_data(fullfile(InputTable{1,1},InputTable{1,2}))
     3768else
     3769    hh=findobj(allchild(0),'Tag','browse_data');
     3770    if ~isempty(hh)
     3771        delete(hh)
     3772    end
     3773end
  • trunk/src/series/extract_rdvision.m

    r1051 r1059  
    186186%      nbfield2=size(time,1);
    187187checkpreserve=0;% if =1, will npreserve the original images, else it erases them at the end
     188
    188189for iview=1:size(Param.InputTable,1)
     190    check_xml=0;
    189191    for iview_xml=1:size(Param.InputTable,1)% look for the xml files in the different data directories
    190192        filexml=[fullfile(RootPath,Param.InputTable{iview_xml,2},Param.InputTable{iview,3}) '.xml'];%new convention: xml at the level of the image folder
    191193        if exist(filexml,'file')
     194            check_xml=1;
    192195            break
    193196        end
    194197    end
    195     if ~exist(filexml,'file')
    196         disp_uvmat('ERROR',[filexml ' missing'],checkrun)
    197         return
    198     end
    199  
     198    %     if ~exist(filexml,'file')
     199    %         disp_uvmat('ERROR',[filexml ' missing'],checkrun)
     200    %         return
     201    %     end
     202    
    200203    newxml=fullfile(RootPath,Param.InputTable{iview,3});
    201204    newxml=regexprep(newxml,'_Master_Dalsa_4M180$','');%suppress '_Master_Dalsa_4M180'
     
    211214            [success,errormsg] = copyfile(filename_seq,[fullfile(RootPath,logdir,Param.InputTable{iview,3}) '.seq']); %copy the seq file in the upper folder
    212215            [success,errormsg] = copyfile(filename_sqb,[fullfile(RootPath,logdir,Param.InputTable{iview,3}) '.sqb']); %copy the sqb file in the upper folder
     216            if check_xml
    213217            [success,errormsg] = copyfile(filexml,[fullfile(RootPath,logdir,Param.InputTable{iview,3}) '.xml']); %copy the original xml file in the upper folder
     218            end
    214219        otherwise
    215220            errormsg='input file extension must be .seq or .sqb';
  • trunk/src/set_object.m

    r1027 r1059  
    332332        set(handles.num_RangeY_2,'TooltipString',['num_RangeY_2: half width of the ' ObjectStyle])
    333333    case {'plane','plane_z'} 
    334 %        set(handles.num_Angle_3,'Visible','on')
     334        set(handles.num_Angle_3,'Visible','on')
    335335        set(handles.num_RangeX_1,'Visible','on')
    336336        set(handles.num_RangeX_2,'Visible','on')
  • trunk/src/uvmat.m

    r1058 r1059  
    12021202uicontrol('Style','pushbutton','Units','normalized', 'Position', [ii ii wwp hh],'BackgroundColor',[1 0 0],'String','APPLY','Callback',@(hObject,eventdata)set_slice_APPLY_Callback(hObject,eventdata),...
    12031203    'FontWeight','bold','FontUnits','points','FontSize',12,'TooltipString','''APPLY'': apply the output to the current field series in uvmat');
    1204 uicontrol('Style','pushbutton','Units','normalized', 'Position', [2*ii+wwp ii wwp hh],'BackgroundColor',[1 0 0],'String','REPLICATE','Callback',@(hObject,eventdata)set_slice_REPLICATE_Callback(hObject,eventdata),...
    1205     'FontWeight','bold','FontUnits','points','FontSize',12,'TooltipString','''REPLICATE'': replicate the output for a series of experiments');
     1204uicontrol('Style','checkbox','Units','normalized', 'Position', [2*ii+wwp ii wwp hh],'BackgroundColor',[1 0 0],'String','Replicate','Callback',@(hObject,eventdata)set_slice_REPLICATE_Callback(hObject,eventdata),...
     1205    'FontWeight','bold','FontUnits','points','FontSize',12,'TooltipString','''Replicate'': select to replicate the output of APPLY to a series of experiments');
    12061206uicontrol('Style','pushbutton','Units','normalized', 'Position', [3*ii+2*wwp ii wwp hh],'Callback',@(hObject,eventdata)set_slice_Cancel_Callback(hObject,eventdata),...
    12071207    'String','Cancel','FontWeight','bold','FontUnits','points','FontSize',12,'TooltipString','''Cancel'': quit GUI without action');
     
    12721272end
    12731273
     1274hreplicate=findobj(hObject,'Tag','Replicate');
     1275if get(hreplicate,'Value')
     1276    'TEST'
     1277else
     1278
    12741279%% store the result in the xml file used for calibration
    12751280errormsg=update_imadoc(GeometryCalib,XmlFile,'GeometryCalib');% introduce the calibration data in the xml file
     
    12841289uvmat('InputFileREFRESH_Callback',huvmat,[],hhuvmat); %file input with xml reading  in uvmat, show the image in phys coordinates
    12851290set(hObject,'BackgroundColor',[1 0 0]);% paint button back to red
     1291end
    12861292
    12871293delete(hset_slice)
     
    12911297function set_slice_REPLICATE_Callback(hObject,eventdata)
    12921298%------------------------------------------------------------------------
    1293 set(hObject,'BackgroundColor',[1 1 0])
    1294 drawnow
    1295 
    1296 %% read the GUI set_slice
    1297 SliceData=read_GUI(get(hObject,'parent'));
    1298 
    1299 %% get info on the GUI uvmat
    1300 huvmat=findobj(allchild(0),'Tag','uvmat');
    1301 hhuvmat=guidata(huvmat);
    1302 RootPath=read_file_boxes(hhuvmat);
    1303 
    1304 OutPutDir=uigetfile_uvmat('choose an image folder to document with slice position?',fileparts(RootPath),'uigetdir');
    1305 OutPut=browse_data(OutPutDir,'off','on');
    1306 nbcalib=0;
    1307 for ilist=1:numel(OutPut.Experiment)
    1308     for idevice=1:numel(OutPut.DataSeries)
    1309         SubDirBase=regexprep(OutPut.DataSeries{idevice},'\..+$','');
    1310         XmlFile=fullfile(OutPut.Campaign,OutPut.Experiment{ilist},[SubDirBase '.xml']);
    1311 
    1312         % read the current xml file
    1313         if  exist(XmlFile,'file')
    1314             [s,errormsg]=imadoc2struct(XmlFile,'GeometryCalib');
    1315             if ~isempty(errormsg)
    1316                 msgbox_uvmat('ERROR',['error in reading ' XmlFile ': ' errormsg])
    1317                 return
    1318             end
    1319             GeometryCalib=s.GeometryCalib;
    1320             GeometryCalib.NbSlice=SliceData.NbSlice;
    1321             GeometryCalib.CheckVolumeScan=SliceData.CheckVolumeScan;
    1322             Z_plane=linspace(SliceData.Z(1),SliceData.Z(2),SliceData.NbSlice);
    1323             GeometryCalib.SliceCoord=Z_plane'*[0 0 1];
    1324             GeometryCalib.SliceAngle=zeros(GeometryCalib.NbSlice,3);
    1325             Angle_1=linspace(SliceData.SliceAngle_1(1),SliceData.SliceAngle_1(2),SliceData.NbSlice);
    1326             Angle_2=linspace(SliceData.SliceAngle_2(1),SliceData.SliceAngle_2(2),SliceData.NbSlice);
    1327             GeometryCalib.SliceAngle(:,1)=Angle_1';%rotation around x axis (to generalise)
    1328             GeometryCalib.SliceAngle(:,2)=Angle_2';%rotation around y axis (to generalise)
    1329             GeometryCalib.SliceAngle(:,3)=0;
    1330             if SliceData.CheckRefraction
    1331                 GeometryCalib.InterfaceCoord=[0 0 SliceData.H];
    1332                 GeometryCalib.RefractionIndex=SliceData.RefractionIndex;
    1333             elseif isfield(GeometryCalib,'RefractionIndex')
    1334                 GeometryCalib=rmfield(GeometryCalib,'RefractionIndex');
    1335                 GeometryCalib=rmfield(GeometryCalib,'InterfaceCoord');
    1336             end
    1337 
    1338             % update the current xml file
    1339             errormsg=update_imadoc(GeometryCalib,XmlFile,'GeometryCalib');% introduce the calibration data in the xml file
    1340             if ~strcmp(errormsg,'')
    1341                 msgbox_uvmat('ERROR',errormsg);
    1342             else
    1343                 display([XmlFile ' updated with slice positions'])
    1344                 nbcalib=nbcalib+1;
    1345             end
    1346         end
    1347     end
    1348 end
    1349 set(hObject,'BackgroundColor',[1 0 0])
    1350 msgbox_uvmat('CONFIMATION',[SubDirBase ' calibrated with slice positions for ' num2str(nbcalib) ' experiments']);
    1351 
     1299if get(hObject,'Value') %open the GUI browse_data
     1300    % look for the GUI uvmat and check for an image as input
     1301    huvmat=findobj(allchild(0),'Name','uvmat');
     1302    hhuvmat=guidata(huvmat);%handles of elements in the GUI uvmat
     1303    RootPath=get(hhuvmat.RootPath,'String');
     1304    SubDir=get(hhuvmat.SubDir,'String');
     1305    browse_data(fullfile(RootPath,SubDir))
     1306else
     1307    hbrowse=findobj(allchild(0),'Tag','browse_data');
     1308    if ~isempty(hbrowse)
     1309        delete(hbrowse)
     1310    end
     1311end
     1312
     1313%
     1314% set(hObject,'BackgroundColor',[1 1 0])
     1315% drawnow
     1316%
     1317% %% read the GUI set_slice
     1318% SliceData=read_GUI(get(hObject,'parent'));
     1319%
     1320% %% get info on the GUI uvmat
     1321% huvmat=findobj(allchild(0),'Tag','uvmat');
     1322% hhuvmat=guidata(huvmat);
     1323% RootPath=read_file_boxes(hhuvmat);
     1324%
     1325% OutPutDir=uigetfile_uvmat('choose an image folder to document with slice position?',fileparts(RootPath),'uigetdir');
     1326% OutPut=browse_data(OutPutDir,'off','on');
     1327% nbcalib=0;
     1328% for ilist=1:numel(OutPut.Experiment)
     1329%     for idevice=1:numel(OutPut.DataSeries)
     1330%         SubDirBase=regexprep(OutPut.DataSeries{idevice},'\..+$','');
     1331%         XmlFile=fullfile(OutPut.Campaign,OutPut.Experiment{ilist},[SubDirBase '.xml']);
     1332%
     1333%         % read the current xml file
     1334%         if  exist(XmlFile,'file')
     1335%             [s,errormsg]=imadoc2struct(XmlFile,'GeometryCalib');
     1336%             if ~isempty(errormsg)
     1337%                 msgbox_uvmat('ERROR',['error in reading ' XmlFile ': ' errormsg])
     1338%                 return
     1339%             end
     1340%             GeometryCalib=s.GeometryCalib;
     1341%             GeometryCalib.NbSlice=SliceData.NbSlice;
     1342%             GeometryCalib.CheckVolumeScan=SliceData.CheckVolumeScan;
     1343%             Z_plane=linspace(SliceData.Z(1),SliceData.Z(2),SliceData.NbSlice);
     1344%             GeometryCalib.SliceCoord=Z_plane'*[0 0 1];
     1345%             GeometryCalib.SliceAngle=zeros(GeometryCalib.NbSlice,3);
     1346%             Angle_1=linspace(SliceData.SliceAngle_1(1),SliceData.SliceAngle_1(2),SliceData.NbSlice);
     1347%             Angle_2=linspace(SliceData.SliceAngle_2(1),SliceData.SliceAngle_2(2),SliceData.NbSlice);
     1348%             GeometryCalib.SliceAngle(:,1)=Angle_1';%rotation around x axis (to generalise)
     1349%             GeometryCalib.SliceAngle(:,2)=Angle_2';%rotation around y axis (to generalise)
     1350%             GeometryCalib.SliceAngle(:,3)=0;
     1351%             if SliceData.CheckRefraction
     1352%                 GeometryCalib.InterfaceCoord=[0 0 SliceData.H];
     1353%                 GeometryCalib.RefractionIndex=SliceData.RefractionIndex;
     1354%             elseif isfield(GeometryCalib,'RefractionIndex')
     1355%                 GeometryCalib=rmfield(GeometryCalib,'RefractionIndex');
     1356%                 GeometryCalib=rmfield(GeometryCalib,'InterfaceCoord');
     1357%             end
     1358%
     1359%             % update the current xml file
     1360%             errormsg=update_imadoc(GeometryCalib,XmlFile,'GeometryCalib');% introduce the calibration data in the xml file
     1361%             if ~strcmp(errormsg,'')
     1362%                 msgbox_uvmat('ERROR',errormsg);
     1363%             else
     1364%                 display([XmlFile ' updated with slice positions'])
     1365%                 nbcalib=nbcalib+1;
     1366%             end
     1367%         end
     1368%     end
     1369% end
     1370% set(hObject,'BackgroundColor',[1 0 0])
     1371% msgbox_uvmat('CONFIMATION',[SubDirBase ' calibrated with slice positions for ' num2str(nbcalib) ' experiments']);
     1372%
    13521373
    13531374%------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.