function []= OLGA_simulate(var,t,simTime,Ts)
%% *************** Description ****************************************
% This function Updates the External Clock on the OLGA server.
% When the OLGA simulator is set in 'External' mode, the simulation
% will run until the SimTime catches up with the External Clock 
% ex_time   = the external clock on OLGA Server
% sim_time  = the simulation time on OLGA server
% init_time = the initial simulation time on OLGA server 
% Written by: Henrik Hjelseth Hansen, 27.01.2012
% *********************************************************************    

%% Read External Clock On OLGA Server
ex_time_read=read(var.ex_time);
ex_time_output=ex_time_read.Value;

%% Read Sim Time on OLGA Server
sim_time_read=read(var.sim_time);
sim_time_output=sim_time_read.Value;

%% Read Initial Time On OLGA Server
init_time_read=read(var.init_time);
init_time_output=sim_time_read.Value;

%% Read OLGA Simulation Speed from Server
speed_read=read(var.speed);
speed_output=speed_read.Value;

%% Simulate OLGA One Second By Updating the External Clock
%Ts=60;                       % Sampling Time
sec=1e-05;                  % 1 second in OLGA
step=ex_time_output+sec*Ts;    % Step time for 1 sec
write(var.ex_time,step);    % Update time to simulate one second
if(speed_output ~=0)
    pause(3*Ts*1/speed_output);  % Pause to let simulation time catch up with External Clock
else
    pause(1);               % Initial Value for speed ==0
end
OLGA_percent_finished(t,simTime,Ts); 
end
