%% Create Matlab Variables from Server Variables
% Written by: Henrik Hjelseth Hansen, 27.01.2012

function [OLGA,var]=OLGA_variables_setup(da)
% Define Matlab parameters from the OLGA server

%% Add data group to Server Connection
OLGA = addgroup(da, 'OLGA'); %Make Group for data items on server

%% Time and Speed Variables in OLGA
var.ex_time=additem(OLGA,'Sim.SimDemo.ExternalClock'); %OLGA TIME
var.sim_time=additem(OLGA,'Sim.SimDemo.SIMTIME');      %OLGA TIME
var.init_time=additem(OLGA,'Sim.SimDemo.INITTIME');    %OLGA TIME
var.time=additem(OLGA,'Sim.SimDemo.TIME');             %OLGA TIME
var.time_step=additem(OLGA,'Sim.SimDemo.HT');          %OLGA TIME
var.speed=additem(OLGA,'Sim.SimDemo.SPEED');           %Simulator Speed
var.stop=additem(OLGA,'Sim.SimDemo.Stop');             %Stop OLGA Parameter
var.pause=additem(OLGA,'Sim.SimDemo.PAUSE');           %Pause OLGA server
var.set_time=additem(OLGA,'Sim.SimDemo.SetTime');
var.set_time_time=additem(OLGA,'Sim.SimDemo.SetTime.Time');


%% Snap parameters (for loading files, i.e., restart files)
var.snap_file=additem(OLGA,'Sim.SimDemo.SaveSnap.File');      % The Snap File
var.snap_save=additem(OLGA,'Sim.SimDemo.SaveSnap');           % The Snap File
var.load_snap_file=additem(OLGA,'Sim.SimDemo.LoadSnap.File'); % Load Snap OLGA
var.load_snap=additem(OLGA,'Sim.SimDemo.LoadSnap');           % Boolean load snap
var.delete_snap_file=additem(OLGA,'Sim.SimDemo.DeleteSnap.File');
var.delete_snap=additem(OLGA,'Sim.SimDemo.DeleteSnap');

%% Pressures in OLGA Model
var.p_bh =additem(OLGA,'Sim.SimDemo.BRAN-1_PIPE_1_2.PT');        % Pressure in bottom hole
var.p_tt =additem(OLGA,'Sim.SimDemo.BRAN-3_PIPE_1_2.PT');        % Pressure in top of tubing        
var.p_at =additem(OLGA,'Sim.SimDemo.BRAN-2_PIPE_2_1.PT');        % Pressure top of annulus
var.p_ab =additem(OLGA,'Sim.SimDemo.BRAN-2_PIPE_1B_3.PT');        % Pressure in annulus at injection point (annulus bottom)

%% Disturbances
%var.pressure=additem(OLGA,'Sim.SimDemo.Annulus_PIPE-1_2.PT');    % Pressure in reservoair
%var.pressure=additem(OLGA,'Sim.SimDemo.Annulus_PIPE-1_2.PT');    % Pressure in lift gas source

%% Flows and Liquid Volume Fraction
var.w_Ga_in=additem(OLGA,'Sim.SimDemo.BRAN-2_PIPE_2_10.GG');        % Gas Flow Into Annulus
var.wmix_r_out=additem(OLGA,'Sim.SimDemo.PRODCHOKE_1.GVALVE');     % Production Flow
var.alpha_lt=additem(OLGA,'Sim.SimDemo.BRAN-3_PIPE_1_2.HOL');       % Liquid volume fraction top
%var.mix_t=additem(OLGA,'Sim.SimDemo.');       % Mixture Density in top of tubing

%% Valves in OLGA Model
var.prod_choke = additem(OLGA, 'Sim.SimDemo.PRODCHOKE_1.OPENING');  %Production Valve Opening
%var.gas_choke = additem(OLGA,'Sim.SimDemo.');     %Gas Choke Valve

%% Mixture Density in top of tubing
var.rho_M_t = additem(OLGA,'Sim.SimDemo.BRAN-3_PIPE_1_2.EVRRHOMIX');

%% States in OLGA Model
var.x1 = additem(OLGA,'Sim.SimDemo.BRAN-2.GASMASS'); % Gas Mass Annulus
var.x2 = additem(OLGA,'Sim.SimDemo.BRAN-3.GASMASS'); % Gas Mass Tubing
var.x3 = additem(OLGA,'Sim.SimDemo.BRAN-3.LIQMASS'); % Liquid Mass Tubing
var.x3_2 = additem(OLGA,'Sim.SimDemo.BRAN-1.LIQMASS'); % Liquid Mass Tubing

pause(3)

end








