function plotCTGViewerLite(timestamp, fhr, uc, sFileCTGViewerLitePy)
% PLOTCTGVIEWERLITE plot data using CTGViewerLite written in python
%
% Synopsis:
%  plotCTGViewerLite(timestamp, fhr, uc, [sFileCTGViewerLitePy])
%
% Description: 
%  Plot fetal heart rate and uterine contraction using CTGViewerLite application
%  written in python. First the fhr and uc are saved into a temporary
%  matlab file and then the CTGViewerLite.py is called with path mat-file
%  given as an argument.
%
% Input:
%  timestamp - [nx1][int] timestamp in samples, gaps in fhr are treated as missing
%                         stamps. For examples: timestamp = [1,2,3,4,7,8,9,10,20,21,22]
%  fhr  - [nx1][double] fetal heart rate
%  uc   - [nx1][double] uterine contractions
%  sFileCTGViewerLitePy - [string][optional] - path to file CTGViewerLite.py. 
%                         This must be specified if used outside BioDat group
%
% Output:
%
% Example:
%  [aFhr, aToco, cParams] = loadCTU_UHB_db_physionet(timestamp, fhr, uc,'~/CTGViewerLite/src/CTGViewerLite.py);
%
% See also:
%
% About:
%  Jiri Spilka
%  http://bio.felk.cvut.cz/~spilkaj
%  2013, CTU in Prague, FEE, Dept. of Cybernetics 
%
% Modifications:
% 

bDEBUG = true;

if ~exist('sFileCTGViewerLitePy','var')
    cSettings = settings(); 
    sFileCTGViewerLitePy = cSettings.sFileCTGViewerLitePy;
end

timestamp = makeColumnVector(timestamp);
fhr = makeColumnVector(fhr);
uc = makeColumnVector(uc);

% save to matlab file, the names of fields are strict

file = strcat(tempname,'.mat');
save(file,'timestamp','fhr','uc') % the variables must be named: fhr,uc

% run python
% the parameter & starts seperate process
[result,status] = python(sFileCTGViewerLitePy,'&','-m',file);
%pause(1); % this pause must be here, otherwise the might be deleted (below) before it is loaded in python

if bDEBUG
    fprintf('status: %s \n', status);
    fprintf('resutls: %s \n', result);
end

% try % try to delete
%      delete(file);
% catch
%     return
% end

function x = makeColumnVector(x)

[m,n] = size(x);

if m < n
    x = x';
end