% Connection of OLGA and Matlab
% Gisle Otto Eikrem
% 20.05.2005
% Brukt og forandret av Henrik Tuvnes 13.09.2008

%Oppstart av server
%close all; clear all;

%location = 'rotvoll'
location = 'hjemme'

%% [errmsg] = OLGADisconnect;
home=pwd;   % home directory, current

if strcmp(location,'rotvoll')

%Path
olga_input_dir = 'C:\workspace\SlugControl\Simulations\source\';
olga_server_dir = 'C:\Program Files\SPT Group\OLGA 5.3\OlgaExecutables_5_3\';
olga_input_fil = 'multiple_source_0.inp';
olga_restart_file = '';
matlab_reload_file = 'restart.mat';

cd (olga_server_dir);
dos('start /low olga-5.3 -server olga_1 &');	  
disp('Waiting for server connection');
pause(5);
clc;
cd(home);
[errmsg] = OLGAConnect('localhost olga_1');
                       
elseif strcmp(location,'hjemme')

%Path
olga_input_dir = 'D:\Workspace\SlugControl\Simulations\source\';
olga_server_dir = 'C:\Programfiler\SPT Group\OLGA 5.3\OlgaExecutables_5_3\';
olga_input_fil = 'multiple_source_0.inp';
olga_restart_file = '';
%matlab_reload_file = 'restart.mat';

cd (olga_server_dir);
dos('start /low olga-5.3 -server olga_1 &');	  
disp('Waiting for server connection');
pause(5);
clc;
cd(home);
[errmsg] = OLGAConnect('localhost olga_1');
    
end


[errmsg] = OLGAStart([olga_input_dir olga_input_fil])

[errmsg] = OLGATestOn; % Information to DOS-windo
%

% [errmsg]=OLGASetTrendVar('$INLET PT GT GORST');
% [errmsg]=OLGASetTrendVar('$INLET2 PT GT GORST');
% [errmsg]=OLGASetTrendVar('$INLET3 PT GT GORST');
% [errmsg]=OLGASetTrendVar('$INLET4 PT GT GORST');
% 
[errmsg]=OLGASetTrendVar('$INLET PT GT GORST $INLET2 PT GT GORST $INLET3 PT GT GORST $INLET4 PT GT GORST')

%[errmsg] = OLGASetProfileVar('$Q-2H PT HOL');
% % 
% % 
%  [errmsg] = OLGASetInputVar('$SOUR-1 SOURCE', 5);
%   [errmsg] = OLGASetInputVar('$SOUR-2 SOURCE', 5);
%    [errmsg] = OLGASetInputVar('$SOUR-3 SOURCE', 5);
%     [errmsg] = OLGASetInputVar('$SOUR-4 SOURCE', 5);
% % 

input_var.def = '$SOUR-1 SOURCE $SOUR-2 SOURCE $SOUR-3 SOURCE $SOUR-4 SOURCE';
input_var.dim = [5;5;5;5];

[errmsg] = OLGASetInputVar(input_var.def,input_var.dim);


% % initial values
% SourceGasFraction = -1;
% SourceMassFlowrate = 4;
% SourcePres=220E5;  % Pa
% SourceTemp=144;     %C
% SourceWaterFrac=0;
%
%InpData = [SourceGasFraction SourceMassFlowrate SourcePres SourceTemp SourceWaterFrac SourceGasFraction SourceMassFlowrate SourcePres SourceTemp SourceWaterFrac SourceGasFraction SourceMassFlowrate SourcePres SourceTemp SourceWaterFrac SourceGasFraction SourceMassFlowrate SourcePres SourceTemp SourceWaterFrac];

%[errmsg] = OLGASetInputData( InpData );

% input_var.def = '$SOUR-1 SOURCE';% $SUBSEACHOKE VALVE';
% input_var.dim = [5;1];
% 
% % input_var.pos_u_PC_1 = 1;
% % input_var.pos_u_PC_2 = 2;
% % 
% aaa
%[errmsg] = OLGASetInputVar(input_var.def,input_var.dim);
%[errmsg]=OLGASetInputVar('$SUBSEA VALVE $SOUR-1 SOURCE', [1 5]);

% % 
% %--------------------------------------------
% 
%[errmsg] =  OLGALoadSnap(olga_restart_file);
% 
% %load('restart270202.mat');
% 
t_current1 = OLGAGetTime;


