
%  TEINIT Subroutine injected into S-function 
%  Command lines for MATLAB:
%clear all
global YY YP XMV;
%  NN = 50;
%  TIME = 0;
%  YY = zeros(50,1);
%  YP = zeros(50,1);
%  TEINIT_3(NN,TIME,YY,YP)
%
%
%        Initialization
% 
%          Inputs:
% 
%            NN   = Number of differential equations
% 
%          Outputs:
% 
%            Time = Current time(hrs)
%            YY   = Current state values
%            YP   = Current derivative values
% 
%       DOUBLE PRECISION XMEAS,XMV

% global IDV 
%       DOUBLE PRECISION G
%global G
%       DOUBLE PRECISION
%      .UCLR,UCVR,UTLR,UTVR,
%      .XLR,XVR,ETR,ESR,
%      .TCR,TKR,DLR,
%      .VLR,VVR,VTR,
%      .PTR,PPR,
%      .CRXR,RR,RH,
%      .FWR,TWR,QUR,HWR,UAR,
%      .UCLS,UCVS,UTLS,UTVS,
%      .XLS,XVS,ETS,ESS,
%      .TCS,TKS,DLS,
%      .VLS,VVS,VTS,
%      .PTS,PPS,
%      .FWS,TWS,QUS,HWS,
%      .UCLC,UTLC,XLC,
%      .ETC,ESC,TCC,DLC,
%      .VLC,VTC,QUC,
%      .UCVV,UTVV,XVV,
%      .ETV,ESV,TCV,TKV,
%      .VTV,PTV,
%      .VCV,VRNG,VTAU,
%      .FTM,
%      .FCM,XST,XMWS,
%      .HST,TST,SFR,
%      .CPFLMX,CPPRMX,CPDH,
%      .TCWR,TCWS,
%      .HTR,AGSP,
%      .XDEL,XNS,
%      .TGAS,TPROD,VST
global UCLR UCVR UTLR UTVR XLR XVR ETR ESR...
      TCR TKR DLR VLR VVR VTR PTR PPR CRXR RR RH FWR TWR QUR HWR UAR...
      UCLS UCVS UTLS UTVS XLS XVS ETS ESS TCS TKS DLS...
      VLS VVS VTS PTS PPS FWS TWS QUS HWS UCLC UTLC XLC...
      ETC ESC TCC DLC VLC VTC QUC UCVV UTVV XVV ETV ESV TCV TKV...
      VTV PTV VCV VRNG VTAU FTM FCM XST XMWS...
      HST TST SFR CPFLMX CPPRMX CPDH TCWR TCWS HTR AGSP...
      XDEL XNS TGAS TPROD VST IVST 
	  
 TCR = 0; % put in by MWB, since it is not defined in the program, just initialized.
 TCS = 0; % put in by MWB, since it is not defined in the program, just initialized.
 TCC = 0; % put in by MWB, since it is not defined in the program, just initialized.
 DLR = 0; % put in by MWB, since it is not defined in the program, just initialized.
 DLS = 0; % put in by MWB, since it is not defined in the program, just initialized.
 DLC = 0; % put in by MWB, since it is not defined in the program, just initialized.
 TCV = 0; % put in by MWB, since it is not defined in the program, just initialized.
 HST = zeros(13,1); % put in by MWB, since it is not defined in the program, just initialized.

%       DOUBLE PRECISION
%      .ADIST,
%      .BDIST,
%      .CDIST,
%      .DDIST,
%      .TLAST,
%      .TNEXT,
%      .HSPAN,
%      .HZERO,
%      .SSPAN,
%      .SZERO,
%      .SPSPAN
global ADIST BDIST CDIST DDIST TLAST TNEXT HSPAN...
      HZERO SSPAN SZERO SPSPAN IDVWLK
% 	  DOUBLE PRECISION
%      .AVP,BVP,CVP,
%      .AH,BH,CH,
%      .AG,BG,CG,
%      .AV,
%      .AD,BD,CD,
%      .XMW
global AVP BVP CVP AH BH CH AG BG CG AV...
      AD BD CD XMW
global G
G=1431655765;
%       DOUBLE PRECISION YY(NN),
%      .YP(NN),
%      .TIME
      XMW(1,1) = 2.0;
      XMW(2,1) = 25.4;
      XMW(3,1) = 28.0;
      XMW(4,1) = 32.0;
      XMW(5,1) = 46.0;
      XMW(6,1) = 48.0;
      XMW(7,1) = 62.0;
      XMW(8,1) = 76.0;
      AVP(1,1) = 0.0;
      AVP(2,1) = 0.0;
      AVP(3,1) = 0.0;
      AVP(4,1) = 15.92;
      AVP(5,1) = 16.35;
      AVP(6,1) = 16.35;
      AVP(7,1) = 16.43;
      AVP(8,1) = 17.21;
      BVP(1,1) = 0.0;
      BVP(2,1) = 0.0;
      BVP(3,1) = 0.0;
      BVP(4,1) = -1444.0;
      BVP(5,1) = -2114.0;
      BVP(6,1) = -2114.0;
      BVP(7,1) = -2748.0;
      BVP(8,1) = -3318.0;
      CVP(1,1) = 0.0;
      CVP(2,1) = 0.0;
      CVP(3,1) = 0.0;
      CVP(4,1) = 259.0;
      CVP(5,1) = 265.5;
      CVP(6,1) = 265.5;
      CVP(7,1) = 232.9;
      CVP(8,1) = 249.6;
      AD(1,1) = 1.0;
      AD(2,1) = 1.0;
      AD(3,1) = 1.0;
      AD(4,1) = 23.3;
      AD(5,1) = 33.9;
      AD(6,1) = 32.8;
      AD(7,1) = 49.9; 
      AD(8,1) = 50.5;
      BD(1,1) = 0.0;
      BD(2,1) = 0.0;
      BD(3,1) = 0.0;
      BD(4,1) = -0.0700;
      BD(5,1) = -0.0957;
      BD(6,1) = -0.0995;
      BD(7,1) = -0.0191;
      BD(8,1) = -0.0541;
      CD(1,1) = 0.0;
      CD(2,1) = 0.0;
      CD(3,1) = 0.0;
      CD(4,1) = -0.0002;
      CD(5,1) = -0.000152;
      CD(6,1) = -0.000233;
      CD(7,1) = -0.000425;
      CD(8,1) = -0.000150;
      AH(1,1) = 1 * 10 ^ (-6);
      AH(2,1) = 1 * 10 ^ (-6);
      AH(3,1) = 1 * 10 ^ (-6);
      AH(4,1) = 0.960 * 10^(-6);
      AH(5,1) = 0.573 * 10^(-6);
      AH(6,1) = 0.652 * 10^(-6);
      AH(7,1) = 0.515 * 10^(-6);
      AH(8,1) = 0.471E-6;
      BH(1,1) = 0.0;
      BH(2,1) = 0.0;
      BH(3,1) = 0.0;
      BH(4,1) = 8.70E-9;
      BH(5,1) = 2.41E-9;
      BH(6,1) = 2.18E-9;
      BH(7,1) = 5.65E-10;
      BH(8,1) = 8.70E-10;
      CH(1,1) = 0.0;
      CH(2,1) = 0.0;
      CH(3,1) = 0.0;
      CH(4,1) = 4.81E-11;
      CH(5,1) = 1.82E-11;
      CH(6,1) = 1.94E-11;
      CH(7,1) = 3.82E-12;
      CH(8,1) = 2.62E-12;
      AV(1,1) = 1.0E-6;
      AV(2,1) = 1.0E-6;
      AV(3,1) = 1.0E-6;
      AV(4,1) = 86.7E-6;
      AV(5,1) = 160.E-6;
      AV(6,1) = 160.E-6;
      AV(7,1) = 225.E-6;
      AV(8,1) = 209.E-6;
      AG(1,1) = 3.411E-6;
      AG(2,1) = 0.3799E-6;
      AG(3,1) = 0.2491E-6;
      AG(4,1) = 0.3567E-6;
      AG(5,1) = 0.3463E-6;
      AG(6,1) = 0.3930E-6;
      AG(7,1) = 0.170E-6;
      AG(8,1) = 0.150E-6;
      BG(1,1) = 7.18E-10;
      BG(2,1) = 1.08E-9;
      BG(3,1) = 1.36E-11;
      BG(4,1) = 8.51E-10;
      BG(5,1) = 8.96E-10;
      BG(6,1) = 1.02E-9;
      BG(7,1) = 0;
      BG(8,1) = 0;
      CG(1,1) = 6.0E-13;
      CG(2,1) = -3.98E-13;
      CG(3,1) = -3.93E-14;
      CG(4,1) = -3.12E-13;
      CG(5,1) = -3.27E-13;
      CG(6,1) = -3.12E-13;
      CG(7,1) = 0;
      CG(8,1) = 0;
      YY(1,1) = 10.40491389;
      YY(2,1) = 4.363996017;
      YY(3,1) = 7.570059737;
      YY(4,1) = 0.4230042431;
      YY(5,1) = 24.15513437;
      YY(6,1) = 2.942597645;
      YY(7,1) = 154.3770655;
      YY(8,1) = 159.1865960;
      YY(9,1) = 2.808522723;
      YY(10,1) = 63.75581199;
      YY(11,1) = 26.74026066;
      YY(12,1) = 46.38532432;
      YY(13,1) = 0.2464521543;
      YY(14,1) = 15.20484404;
      YY(15,1) = 1.852266172;
      YY(16,1) = 52.44639459;
      YY(17,1) = 41.20394008;
      YY(18,1) = 0.5699317760;
      YY(19,1) = 0.4306056376;
      YY(20,1) = 7.9906200783E-03;
      YY(21,1) = 0.9056036089;
      YY(22,1) = 1.6054258216E-02;
      YY(23,1) = 0.7509759687;
      YY(24,1) = 8.8582855955E-02;
      YY(25,1) = 48.27726193;
      YY(26,1) = 39.38459028;
      YY(27,1) = 0.3755297257;
      YY(28,1) = 107.7562698;
      YY(29,1) = 29.77250546;
      YY(30,1) = 88.32481135;
      YY(31,1) = 23.03929507;
      YY(32,1) = 62.85848794;
      YY(33,1) = 5.546318688;
      YY(34,1) = 11.92244772;
      YY(35,1) = 5.555448243;
      YY(36,1) = 0.9218489762;
      YY(37,1) = 94.59927549;
      YY(38,1) = 77.29698353;
      YY(39,1) = 63.05263039;
      YY(40,1) = 53.97970677;
      YY(41,1) = 24.64355755;
      YY(42,1) = 61.30192144;
      YY(43,1) = 22.21000000;
      YY(44,1) = 40.06374673;
      YY(45,1) = 38.10034370;
      YY(46,1) = 46.53415582;
      YY(47,1) = 47.44573456;
      YY(48,1) = 41.10581288;
      YY(49,1) = 18.11349055;
      YY(50,1) = 50.00000000;
	  
for I = 1:12
      XMV(I,1) = YY(I + 38,1);
      VCV(I,1) = XMV(I,1);
      VST(I,1) = 2.0;
      IVST(I,1) = 0;
end
  
      VRNG(1,1) = 400.00;
      VRNG(2,1) = 400.00;
      VRNG(3,1) = 100.00;
      VRNG(4,1) = 1500.00;
      VRNG(7,1) = 1500.00;
      VRNG(8,1) = 1000.00;
      VRNG(9,1) = 0.03;
      VRNG(10,1) = 1000;
      VRNG(11,1) = 1200.0;
      VTR = 1300.0;
      VTS = 3500.0;
      VTC = 156.5;
      VTV = 5000.0;
      HTR(1,1) = 0.06899381054;
      HTR(2,1) = 0.05;
      HWR = 7060;
      HWS = 11138;
      SFR(1,1) = 0.99500;
      SFR(2,1) = 0.99100;
      SFR(3,1) = 0.99000;
      SFR(4,1) = 0.91600;
      SFR(5,1) = 0.93600;
      SFR(6,1) = 0.93800;
      SFR(7,1) = 5.80000E-02;
      SFR(8,1) = 3.01000E-02;
      XST(1,1) = 0.0;
      XST(2,1) = 0.0001;
      XST(3,1) = 0.0;
      XST(4,1) = 0.9999;
      XST(5,1) = 0.0;
      XST(6,1) = 0.0;
      XST(7,1) = 0.0;
      XST(8,1) = 0.0;
      TST(1,1) = 45;
      XST(1,2) = 0.0;
      XST(2,2) = 0.0;
      XST(3,2) = 0.0;
      XST(4,2) = 0.0;
      XST(5,2) = 0.9999;
      XST(6,2) = 0.0001;
      XST(7,2) = 0.0;
      XST(8,2) = 0.0;
      TST(2,1) = 45;
      XST(1,3) = 0.9999;
      XST(2,3) = 0.0001;
      XST(3,3) = 0.0;
      XST(4,3) = 0.0;
      XST(5,3) = 0.0;
      XST(6,3) = 0.0;
      XST(7,3) = 0.0;
      XST(8,3) = 0.0;
      TST(3,1) = 45;
      XST(1,4) = 0.4850;
      XST(2,4) = 0.0050;
      XST(3,4) = 0.5100;
      XST(4,4) = 0.0;
      XST(5,4) = 0.0;
      XST(6,4) = 0.0;
      XST(7,4) = 0.0;
      XST(8,4) = 0.0;
      TST(4,1) = 45;
      CPFLMX = 280275;
      CPPRMX = 1.3;
      VTAU(1,1) = 8;
      VTAU(2,1) = 8;
      VTAU(3,1) = 6;
      VTAU(4,1) = 9;
      VTAU(5,1) = 7;
      VTAU(6,1) = 5;
      VTAU(7,1) = 5;
      VTAU(8,1) = 5;
      VTAU(9,1) = 120;
      VTAU(10,1) = 5;
      VTAU(11,1) = 5;
      VTAU(12,1) = 5;
	  
for I=1:12
      VTAU(I,1) = VTAU(I,1) / 3600;
end
  
      G = 1431655765;
      XNS(1,1) = 0.0012;
      XNS(2,1) = 18.000;
      XNS(3,1) = 22.000;
      XNS(4,1) = 0.0500;
      XNS(5,1) = 0.2000;
      XNS(6,1) = 0.2100;
      XNS(7,1) = 0.3000;
      XNS(8,1) = 0.5000;
      XNS(9,1) = 0.0100;
      XNS(10,1) = 0.0017;
      XNS(11,1) = 0.0100;
      XNS(12,1) = 1.0000;
      XNS(13,1) = 0.3000;
      XNS(14,1) = 0.1250;
      XNS(15,1) = 1.0000;
      XNS(16,1) = 0.3000;
      XNS(17,1) = 0.1150;
      XNS(18,1) = 0.0100;
      XNS(19,1) = 1.1500;
      XNS(20,1) = 0.2000;
      XNS(21,1) = 0.0100;
      XNS(22,1) = 0.0100;
      XNS(23,1) = 0.250;
      XNS(24,1) = 0.100;
      XNS(25,1) = 0.250;
      XNS(26,1) = 0.100;
      XNS(27,1) = 0.250;
      XNS(28,1) = 0.025;
      XNS(29,1) = 0.250;
      XNS(30,1) = 0.100;
      XNS(31,1) = 0.250;
      XNS(32,1) = 0.100;
      XNS(33,1) = 0.250;
      XNS(34,1) = 0.025;
      XNS(35,1) = 0.050;
      XNS(36,1) = 0.050;
      XNS(37,1) = 0.010;
      XNS(38,1) = 0.010;
      XNS(39,1) = 0.010;
      XNS(40,1) = 0.500;
      XNS(41,1) = 0.500;
	        HSPAN(1,1) = 0.2;
      HZERO(1,1) = 0.5;
      SSPAN(1,1) = 0.03;
      SZERO(1,1) = 0.485;
      SPSPAN(1,1) = 0;
      HSPAN(2,1) = 0.7;
      HZERO(2,1) = 1.0;
      SSPAN(2,1) = 0.003;
      SZERO(2,1) = 0.005;
      SPSPAN(2,1) = 0;
      HSPAN(3,1) = 0.25;
      HZERO(3,1) = 0.5;
      SSPAN(3,1) = 10;
      SZERO(3,1) = 45;
      SPSPAN(3,1) = 0;
      HSPAN(4,1) = 0.7;
      HZERO(4,1) = 1.0;
      SSPAN(4,1) = 10;
      SZERO(4,1) = 45;
      SPSPAN(4,1) = 0;
      HSPAN(5,1) = 0.15;
      HZERO(5,1) = 0.25;
      SSPAN(5,1) = 10;
      SZERO(5,1) = 35;
      SPSPAN(5,1) = 0;
      HSPAN(6,1) = 0.15;
      HZERO(6,1) = 0.25;
      SSPAN(6,1) = 10;
      SZERO(6,1) = 40;
      SPSPAN(6,1) = 0;
      HSPAN(7,1) = 1;
      HZERO(7,1) = 2;
      SSPAN(7,1) = 0.25;
      SZERO(7,1) = 1.0;
      SPSPAN(7,1) = 0;
      HSPAN(8,1) = 1;
      HZERO(8,1) = 2;
      SSPAN(8,1) = 0.25;
      SZERO(8,1) = 1.0;
      SPSPAN(8,1) = 0;
      HSPAN(9,1) = 0.4;
      HZERO(9,1) = 0.5;
      SSPAN(9,1) = 0.25;
      SZERO(9,1) = 0.0;
      SPSPAN(9,1) = 0;
      HSPAN(10,1) = 1.5;
      HZERO(10,1) = 2.0;
      SSPAN(10,1) = 0.0;
      SZERO(10,1) = 0.0;
      SPSPAN(10,1) = 0;
      HSPAN(11,1) = 2.0;
      HZERO(11,1) = 3.0;
      SSPAN(11,1) = 0.0;
      SZERO(11,1) = 0.0;
      SPSPAN(11,1) = 0;
      HSPAN(12,1) = 1.5;
      HZERO(12,1) = 2.0;
      SSPAN(12,1) = 0.0;
      SZERO(12,1) = 0.0;
      SPSPAN(12,1) = 0;
	  
for I=1:12
      TLAST(I,1)=0;
      TNEXT(I,1)=0.1;
      ADIST(I,1)=SZERO(I,1);
      BDIST(I,1)=0;
      CDIST(I,1)=0;
      DDIST(I,1)=0;
end
