tic;    
[VOI, STATES, ALGEBRAIC, CONSTANTS] = mainFunction();
toc;

function [VOI, STATES, ALGEBRAIC, CONSTANTS] = mainFunction()
    % This is the "main function".  In Matlab, things work best if you rename this function to match the filename.
   [VOI, STATES, ALGEBRAIC, CONSTANTS] = solveModel();
end

function [algebraicVariableCount] = getAlgebraicVariableCount()
    % Used later when setting a global variable with the number of algebraic variables.
    % Note: This is not the "main method".
    algebraicVariableCount =303;
end
% There are a total of 62 entries in each of the rate and state variable arrays.
% There are a total of 177 entries in the constant variable array.
%

function [VOI, STATES, ALGEBRAIC, CONSTANTS] = solveModel()
    [LEGEND_STATES, LEGEND_ALGEBRAIC, LEGEND_VOI, LEGEND_CONSTANTS] = createLegends();
    % Create ALGEBRAIC of correct size
    global algebraicVariableCount;  algebraicVariableCount = getAlgebraicVariableCount();
    % Initialise constants and state variables
    [INIT_STATES, CONSTANTS] = initConsts;

    % Set timespan to solve over
    tspan = [0, 2.6];

    % Set numerical accuracy options for ODE solver
    options = odeset('RelTol', 1e-05, 'AbsTol', 1e-16, 'MaxStep', 3e-4);

    % Solve model with ODE solver
    [VOI, STATES] = ode15s(@(VOI, STATES)computeRates(VOI, STATES, CONSTANTS), tspan, INIT_STATES, options);

    % Compute algebraic variables
    [RATES, ALGEBRAIC] = computeRates(VOI, STATES, CONSTANTS);
    ALGEBRAIC = computeAlgebraic(ALGEBRAIC, CONSTANTS, STATES, VOI);

    vlabels = {'I_stim in component environment (fA)',...
        'V_m in component environment (volt)',...
        'q_Ca_i in component environment (fmol)',...
        'q_Ca_o in component environment (fmol)',...
        'q_Ca_D in component environment (fmol)',...
        'q_Ca_SR in component environment (fmol)',...
        'q_TRPN in component environment (fmol)',...
        'q_Ca_TRPN in component environment (fmol)',...
        'q_PLBp in component environment (fmol)',...
        'pHi in component environment (dimensionless)',...
        'SL in component crossbridge_TRPN (metre)',...
        'T_active in component crossbridge_TRPN (kPa)',...
        'T_passive in component crossbridge_TRPN (kPa)'}; %I_pulse in component environment (fA)',...
    [~, i_st, i_alg] = find_indices(vlabels, cellstr(LEGEND_CONSTANTS), cellstr(LEGEND_STATES), cellstr(LEGEND_ALGEBRAIC));
    if i_st
        plot_selected(i_st,VOI,STATES,'s',LEGEND_STATES,'STATES',ceil(sqrt(length(i_st))))
    end
    plot_selected(i_alg,VOI,ALGEBRAIC,'s',LEGEND_ALGEBRAIC,'ALGEBRAIC',ceil(sqrt(length(i_alg))))

    % fluxes
    flabs = {'v_leak in component Ca_leak (fmol_per_sec)',...
        'v_R_TRPNCa in component crossbridge_TRPN (fmol_per_sec)',...
        'v_R_UW in component crossbridge_TRPN (fmol_per_sec)',...
        'v_R_WS in component crossbridge_TRPN (fmol_per_sec)',...
        'v_diadDf in component diadCaDiffusion (fmol_per_sec)',...
        'v_Ca_o_LCC in component LCC (fmol_per_sec)',...
        'v_Ca_i_NCX in component NCX (fmol_per_sec)',...
        'v_pCa_R1 in component pCa (fmol_per_sec)',...
        'v_pCa_R2 in component pCa (fmol_per_sec)',...
        'v_PLBph1 in component PLB (fmol_per_sec)',...
        'v_PLBph2 in component PLB (fmol_per_sec)',...
        'v_RyR in component RyR (fmol_per_sec)',...
        'v_Ca_i_SERCA in component SERCA (fmol_per_sec)'};
    [~, ~, i_alg] = find_indices(flabs, cellstr(LEGEND_CONSTANTS), cellstr(LEGEND_STATES), cellstr(LEGEND_ALGEBRAIC));
    plot_selected(i_alg,VOI,ALGEBRAIC,'s',LEGEND_ALGEBRAIC,'FLUXES',ceil(sqrt(length(i_alg))))

    if false
        % Ca conservation 
        Ca_labels = {'q_Ca_i in component environment (fmol)',...
            'q_Ca_o in component environment (fmol)',...
            'q_Ca_D in component environment (fmol)',...
            'q_Ca_SR in component environment (fmol)',...
            'q_Ca_TRPN in component environment (fmol)'};
        serca_ca = {};
        [~, i_st, ~] = find_indices(Ca_labels, cellstr(LEGEND_CONSTANTS), cellstr(LEGEND_STATES), cellstr(LEGEND_ALGEBRAIC));
        assert(length(Ca_labels)==length(i_st))
        figure,
        plot(VOI, sum(STATES(:,i_st),2));
        title('sum Ca fmol')
    end
end            


function [i_con, i_st, i_alg] = find_indices(labels, LEGEND_CONSTANTS, LEGEND_STATES, LEGEND_ALGEBRAIC)
% return the indices for the selected labels
    all_legends = [LEGEND_CONSTANTS; LEGEND_STATES; LEGEND_ALGEBRAIC];
    
    i_con = [];
    for i = 1:length(labels)
        i_con = [i_con; find(strcmp(labels{i},LEGEND_CONSTANTS))];
    end
    i_st = [];
    for i = 1:length(labels)
        i_st = [i_st; find(strcmp(labels{i},LEGEND_STATES))];
    end
    i_alg = [];
    for i = 1:length(labels)
        i_alg = [i_alg; find(strcmp(labels{i},LEGEND_ALGEBRAIC))];
    end
    
    if length(i_con) + length(i_st) + length(i_alg) < length(labels)
        error('missing index');
    end
end


function [] = plot_selected(ids,x,y,legend_x,legend_y,titlestr,ns)
    istart = 1;
    figure();
%     plot stimuli
    for i = 1:length(ids)
        subplot(ns,ns,i)
        plotting_x = x(istart:end);
        plotting_y = y(istart:end,ids(i));
        if isempty(plotting_y) % probably a constant scalar
            plotting_y = repmat(y(ids(i)),2);
            plotting_x = [x(istart), x(end)];
        end
        plot(plotting_x, plotting_y);
        xlabel('time (s)');
        str = split(legend_y(ids(i),:), ' ');
        str = legend_y(ids(i),:);
        l = legend(str);
        set(l,'interpreter','none');
    end
    if verLessThan('matlab','9.5')
        suptitle(titlestr)    
    else
        sgtitle(titlestr)    
    end
end

function [LEGEND_STATES, LEGEND_ALGEBRAIC, LEGEND_VOI, LEGEND_CONSTANTS] = createLegends()
    LEGEND_STATES = ''; LEGEND_ALGEBRAIC = ''; LEGEND_VOI = ''; LEGEND_CONSTANTS = '';
    LEGEND_CONSTANTS(:,1) = strpad('kappa_leak in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,2) = strpad('kappa_R_TRPNCa in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,3) = strpad('kappa_R_BU in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,4) = strpad('kappa_R_UW in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,5) = strpad('kappa_R_WS in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,6) = strpad('kappa_R_SU in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,7) = strpad('kappa_diadDf in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,8) = strpad('kappa_LCC_Ca1 in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,9) = strpad('kappa_LCC_Ca2 in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,10) = strpad('kappa_d000 in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,11) = strpad('kappa_d010 in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,12) = strpad('kappa_d020 in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,13) = strpad('kappa_d001 in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,14) = strpad('kappa_d011 in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,15) = strpad('kappa_d021 in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,16) = strpad('kappa_f1_000 in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,17) = strpad('kappa_f1_100 in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,18) = strpad('kappa_f1_001 in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,19) = strpad('kappa_f1_101 in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,20) = strpad('kappa_f2_000 in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,21) = strpad('kappa_f2_100 in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,22) = strpad('kappa_f2_001 in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,23) = strpad('kappa_f2_101 in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,24) = strpad('kappa_f3_010 in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,25) = strpad('kappa_f3_110 in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,26) = strpad('kappa_f3_011 in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,27) = strpad('kappa_f3_111 in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,28) = strpad('kappa_fCa000 in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,29) = strpad('kappa_fCa100 in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,30) = strpad('kappa_fCa010 in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,31) = strpad('kappa_fCa110 in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,32) = strpad('kappa_fCa020 in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,33) = strpad('kappa_fCa120 in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,34) = strpad('kappa_1_NCX in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,35) = strpad('kappa_2_NCX in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,36) = strpad('kappa_3_NCX in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,37) = strpad('kappa_4_NCX in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,38) = strpad('kappa_5_NCX in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,39) = strpad('kappa_6_NCX in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,40) = strpad('kappa_pCa_R1 in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,41) = strpad('kappa_pCa_R2 in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,42) = strpad('kappa_PLBph1 in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,43) = strpad('kappa_PLBph2 in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,44) = strpad('kappa_PLBd1 in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,45) = strpad('kappa_PLBd2 in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,46) = strpad('kappa_Inh in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,47) = strpad('kappa_RyR in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,48) = strpad('kappa_OC in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,49) = strpad('kappa_CCI in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,50) = strpad('kappa_CII in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,51) = strpad('kappa_IO in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,52) = strpad('kappa_SERCA_R1_2 in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,53) = strpad('kappa_SERCA_R2_4 in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,54) = strpad('kappa_SERCA_R2_2a in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,55) = strpad('kappa_SERCA_R4_5 in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,56) = strpad('kappa_SERCA_R5_6 in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,57) = strpad('kappa_SERCA_R6_8 in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,58) = strpad('kappa_SERCA_R8_9 in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,59) = strpad('kappa_SERCA_R9_10 in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,60) = strpad('kappa_SERCA_R10_1 in component BG_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,61) = strpad('K_Ca_SR in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,62) = strpad('K_Ca_i in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,63) = strpad('K_TRPN in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,64) = strpad('K_Ca_TRPN in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,65) = strpad('K_B_XB in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,66) = strpad('K_U_XB in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,67) = strpad('K_W_XB in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,68) = strpad('K_S_XB in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,69) = strpad('K_Ca_D in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,70) = strpad('K_Ca_o in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,71) = strpad('K_000_LCC in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,72) = strpad('K_010_LCC in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,73) = strpad('K_020_LCC in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,74) = strpad('K_100_LCC in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,75) = strpad('K_110_LCC in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,76) = strpad('K_120_LCC in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,77) = strpad('K_001_LCC in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,78) = strpad('K_011_LCC in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,79) = strpad('K_021_LCC in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,80) = strpad('K_101_LCC in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,81) = strpad('K_111_LCC in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,82) = strpad('K_121_LCC in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,83) = strpad('K_1_NCX in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,84) = strpad('K_2_NCX in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,85) = strpad('K_3_NCX in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,86) = strpad('K_4_NCX in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,87) = strpad('K_5_NCX in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,88) = strpad('K_6_NCX in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,89) = strpad('K_Na_i in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,90) = strpad('K_Na_o in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,91) = strpad('K_pCa in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,92) = strpad('K_pCa_Ca in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,93) = strpad('K_PLB in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,94) = strpad('K_PKACI in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,95) = strpad('K_PLB_PKACI in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,96) = strpad('K_PP1 in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,97) = strpad('K_PLBp_PP1 in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,98) = strpad('K_PLBp in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,99) = strpad('K_Ip in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,100) = strpad('K_Ip_PP1 in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,101) = strpad('K_C_RyR in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,102) = strpad('K_CI_RyR in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,103) = strpad('K_I_RyR in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,104) = strpad('K_O_RyR in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,105) = strpad('K_P1_SERCA in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,106) = strpad('K_P2_SERCA in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,107) = strpad('K_P2a_SERCA in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,108) = strpad('K_P4_SERCA in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,109) = strpad('K_P5_SERCA in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,110) = strpad('K_P6_SERCA in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,111) = strpad('K_P8_SERCA in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,112) = strpad('K_P9_SERCA in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,113) = strpad('K_P10_SERCA in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,114) = strpad('K_H in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,115) = strpad('K_MgATP in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,116) = strpad('K_MgADP in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,117) = strpad('K_Pi in component BG_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,118) = strpad('z_rCa in component BG_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,119) = strpad('z_fd in component BG_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,120) = strpad('z_ff1 in component BG_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,121) = strpad('z_ff2 in component BG_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,122) = strpad('z_ff3 in component BG_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,123) = strpad('z_rd in component BG_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,124) = strpad('z_rf1 in component BG_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,125) = strpad('z_rf2 in component BG_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,126) = strpad('z_rf3 in component BG_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,127) = strpad('nNa_o_NCX in component BG_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,128) = strpad('nNa_i_NCX in component BG_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,129) = strpad('zf_NCX in component BG_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,130) = strpad('zr_NCX in component BG_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,131) = strpad('n_Tm in component BG_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,132) = strpad('n_CaTRPN in component BG_parameters (dimensionless)');
    LEGEND_VOI = strpad('time in component environment (second)');
    LEGEND_CONSTANTS(:,133) = strpad('vol_myo in component environment (pL)');
    LEGEND_CONSTANTS(:,134) = strpad('C_m in component environment (fF)');
    LEGEND_STATES(:,1) = strpad('q_membrane in component environment (fC)');
    LEGEND_STATES(:,2) = strpad('q_Ca_D in component environment (fmol)');
    LEGEND_STATES(:,3) = strpad('q_TRPN in component environment (fmol)');
    LEGEND_STATES(:,4) = strpad('q_Ca_TRPN in component environment (fmol)');
    LEGEND_STATES(:,5) = strpad('q_Ca_i in component environment (fmol)');
    LEGEND_STATES(:,6) = strpad('q_Na_i in component environment (fmol)');
    LEGEND_STATES(:,7) = strpad('q_Na_o in component environment (fmol)');
    LEGEND_STATES(:,8) = strpad('q_B_XB in component environment (fmol)');
    LEGEND_STATES(:,9) = strpad('q_U_XB in component environment (fmol)');
    LEGEND_STATES(:,10) = strpad('q_W_XB in component environment (fmol)');
    LEGEND_STATES(:,11) = strpad('q_S_XB in component environment (fmol)');
    LEGEND_STATES(:,12) = strpad('q_Ca_o in component environment (fmol)');
    LEGEND_STATES(:,13) = strpad('q_PLB in component environment (fmol)');
    LEGEND_STATES(:,14) = strpad('q_PKACI in component environment (fmol)');
    LEGEND_STATES(:,15) = strpad('q_PLB_PKACI in component environment (fmol)');
    LEGEND_STATES(:,16) = strpad('q_PP1 in component environment (fmol)');
    LEGEND_STATES(:,17) = strpad('q_PLBp_PP1 in component environment (fmol)');
    LEGEND_STATES(:,18) = strpad('q_PLBp in component environment (fmol)');
    LEGEND_CONSTANTS(:,135) = strpad('q_PLBp_baseline in component environment (fmol)');
    LEGEND_STATES(:,19) = strpad('q_Ip in component environment (fmol)');
    LEGEND_STATES(:,20) = strpad('q_Ip_PP1 in component environment (fmol)');
    LEGEND_STATES(:,21) = strpad('q_Ca_SR in component environment (fmol)');
    LEGEND_STATES(:,22) = strpad('q_pCa in component environment (fmol)');
    LEGEND_STATES(:,23) = strpad('q_pCa_Ca in component environment (fmol)');
    LEGEND_STATES(:,24) = strpad('q_H in component environment (fmol)');
    LEGEND_STATES(:,25) = strpad('q_Pi in component environment (fmol)');
    LEGEND_STATES(:,26) = strpad('q_MgADP in component environment (fmol)');
    LEGEND_STATES(:,27) = strpad('q_MgATP in component environment (fmol)');
    LEGEND_STATES(:,28) = strpad('q_000_LCC in component environment (fmol)');
    LEGEND_STATES(:,29) = strpad('q_010_LCC in component environment (fmol)');
    LEGEND_STATES(:,30) = strpad('q_020_LCC in component environment (fmol)');
    LEGEND_STATES(:,31) = strpad('q_100_LCC in component environment (fmol)');
    LEGEND_STATES(:,32) = strpad('q_110_LCC in component environment (fmol)');
    LEGEND_STATES(:,33) = strpad('q_120_LCC in component environment (fmol)');
    LEGEND_STATES(:,34) = strpad('q_001_LCC in component environment (fmol)');
    LEGEND_STATES(:,35) = strpad('q_011_LCC in component environment (fmol)');
    LEGEND_STATES(:,36) = strpad('q_021_LCC in component environment (fmol)');
    LEGEND_STATES(:,37) = strpad('q_101_LCC in component environment (fmol)');
    LEGEND_STATES(:,38) = strpad('q_111_LCC in component environment (fmol)');
    LEGEND_STATES(:,39) = strpad('q_121_LCC in component environment (fmol)');
    LEGEND_STATES(:,40) = strpad('q_P1_NCX in component environment (fmol)');
    LEGEND_STATES(:,41) = strpad('q_P2_NCX in component environment (fmol)');
    LEGEND_STATES(:,42) = strpad('q_P3_NCX in component environment (fmol)');
    LEGEND_STATES(:,43) = strpad('q_P4_NCX in component environment (fmol)');
    LEGEND_STATES(:,44) = strpad('q_P5_NCX in component environment (fmol)');
    LEGEND_STATES(:,45) = strpad('q_P6_NCX in component environment (fmol)');
    LEGEND_STATES(:,46) = strpad('q_C_RyR in component environment (fmol)');
    LEGEND_STATES(:,47) = strpad('q_CI_RyR in component environment (fmol)');
    LEGEND_STATES(:,48) = strpad('q_I_RyR in component environment (fmol)');
    LEGEND_STATES(:,49) = strpad('q_O_RyR in component environment (fmol)');
    LEGEND_STATES(:,50) = strpad('q_P1_SERCA in component environment (fmol)');
    LEGEND_STATES(:,51) = strpad('q_P2_SERCA in component environment (fmol)');
    LEGEND_STATES(:,52) = strpad('q_P2a_SERCA in component environment (fmol)');
    LEGEND_STATES(:,53) = strpad('q_P4_SERCA in component environment (fmol)');
    LEGEND_STATES(:,54) = strpad('q_P5_SERCA in component environment (fmol)');
    LEGEND_STATES(:,55) = strpad('q_P6_SERCA in component environment (fmol)');
    LEGEND_STATES(:,56) = strpad('q_P8_SERCA in component environment (fmol)');
    LEGEND_STATES(:,57) = strpad('q_P9_SERCA in component environment (fmol)');
    LEGEND_STATES(:,58) = strpad('q_P10_SERCA in component environment (fmol)');
    LEGEND_ALGEBRAIC(:,55) = strpad('v_leak in component Ca_leak (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,67) = strpad('v_R_TRPNCa in component crossbridge_TRPN (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,74) = strpad('v_R_BU in component crossbridge_TRPN (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,76) = strpad('v_R_UW in component crossbridge_TRPN (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,78) = strpad('v_R_WS in component crossbridge_TRPN (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,80) = strpad('v_R_SU in component crossbridge_TRPN (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,60) = strpad('T_total in component crossbridge_TRPN (kPa)');
    LEGEND_STATES(:,59) = strpad('SL in component crossbridge_TRPN (metre)');
    LEGEND_ALGEBRAIC(:,73) = strpad('v_diadDf in component diadCaDiffusion (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,183) = strpad('v_Ca_D_LCC in component LCC (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,182) = strpad('v_Ca_o_LCC in component LCC (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,181) = strpad('I_mem_LCC in component LCC (fA)');
    LEGEND_ALGEBRAIC(:,222) = strpad('v_Ca_o_NCX in component NCX (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,223) = strpad('v_Ca_i_NCX in component NCX (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,215) = strpad('v_Na_o_NCX in component NCX (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,203) = strpad('v_Na_i_NCX in component NCX (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,221) = strpad('I_mem_NCX in component NCX (fA)');
    LEGEND_ALGEBRAIC(:,228) = strpad('v_pCa_R1 in component pCa (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,229) = strpad('v_pCa_R2 in component pCa (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,231) = strpad('I_mem_pCa in component pCa (fA)');
    LEGEND_ALGEBRAIC(:,56) = strpad('v_PLBph1 in component PLB (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,61) = strpad('v_PLBph2 in component PLB (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,63) = strpad('v_PLBd1 in component PLB (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,66) = strpad('v_PLBd2 in component PLB (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,57) = strpad('v_Inh in component PLB (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,238) = strpad('v_RyR in component RyR (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,247) = strpad('v_RyRgate_Ca_D in component RyR (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,290) = strpad('v_Ca_i_SERCA in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,296) = strpad('v_Ca_SR_SERCA in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,301) = strpad('v_H_SERCA in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,287) = strpad('v_MgADP_SERCA in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,284) = strpad('v_MgATP_SERCA in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,282) = strpad('v_Pi_SERCA in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,2) = strpad('V_m in component environment (volt)');
    LEGEND_ALGEBRAIC(:,29) = strpad('I_stim in component environment (fA)');
    LEGEND_CONSTANTS(:,136) = strpad('stimPeriod in component environment (second)');
    LEGEND_CONSTANTS(:,137) = strpad('stimDuration in component environment (second)');
    LEGEND_ALGEBRAIC(:,12) = strpad('tPeriod in component environment (second)');
    LEGEND_ALGEBRAIC(:,34) = strpad('v_Ca_stim in component environment (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,233) = strpad('sum_I in component environment (fA)');
    LEGEND_ALGEBRAIC(:,3) = strpad('dSL in component environment (m_per_s)');
    LEGEND_CONSTANTS(:,138) = strpad('V_max in component environment (m_per_s)');
    LEGEND_CONSTANTS(:,139) = strpad('vol_cell in component environment (pL)');
    LEGEND_CONSTANTS(:,171) = strpad('vol_SR in component environment (pL)');
    LEGEND_CONSTANTS(:,140) = strpad('vol_o in component environment (pL)');
    LEGEND_CONSTANTS(:,141) = strpad('vol_D in component environment (pL)');
    LEGEND_ALGEBRAIC(:,4) = strpad('cCai in component environment (mM)');
    LEGEND_ALGEBRAIC(:,5) = strpad('cCao in component environment (mM)');
    LEGEND_ALGEBRAIC(:,6) = strpad('cCaSR in component environment (mM)');
    LEGEND_ALGEBRAIC(:,7) = strpad('cCaD in component environment (mM)');
    LEGEND_ALGEBRAIC(:,8) = strpad('cNai in component environment (mM)');
    LEGEND_ALGEBRAIC(:,9) = strpad('pHi in component environment (dimensionless)');
    LEGEND_ALGEBRAIC(:,10) = strpad('Ca_tot in component environment (fmol)');
    LEGEND_CONSTANTS(:,142) = strpad('R in component constants (J_per_K_per_mol)');
    LEGEND_CONSTANTS(:,143) = strpad('T in component constants (kelvin)');
    LEGEND_CONSTANTS(:,144) = strpad('F in component constants (C_per_mol)');
    LEGEND_CONSTANTS(:,145) = strpad('zNa in component ion_valences (dimensionless)');
    LEGEND_CONSTANTS(:,146) = strpad('zCl in component ion_valences (dimensionless)');
    LEGEND_CONSTANTS(:,147) = strpad('zK in component ion_valences (dimensionless)');
    LEGEND_CONSTANTS(:,148) = strpad('zCa in component ion_valences (dimensionless)');
    LEGEND_ALGEBRAIC(:,39) = strpad('mu_Ca_SR in component Ca_leak (J_per_mol)');
    LEGEND_ALGEBRAIC(:,49) = strpad('mu_Ca_i in component Ca_leak (J_per_mol)');
    LEGEND_ALGEBRAIC(:,59) = strpad('mu_TRPN in component crossbridge_TRPN (J_per_mol)');
    LEGEND_ALGEBRAIC(:,62) = strpad('mu_Ca_i in component crossbridge_TRPN (J_per_mol)');
    LEGEND_ALGEBRAIC(:,64) = strpad('mu_Ca_TRPN in component crossbridge_TRPN (J_per_mol)');
    LEGEND_ALGEBRAIC(:,65) = strpad('mu_B_XB in component crossbridge_TRPN (J_per_mol)');
    LEGEND_ALGEBRAIC(:,68) = strpad('mu_U_XB in component crossbridge_TRPN (J_per_mol)');
    LEGEND_ALGEBRAIC(:,70) = strpad('mu_W_XB in component crossbridge_TRPN (J_per_mol)');
    LEGEND_ALGEBRAIC(:,72) = strpad('mu_S_XB in component crossbridge_TRPN (J_per_mol)');
    LEGEND_CONSTANTS(:,149) = strpad('SL_0 in component crossbridge_TRPN (metre)');
    LEGEND_CONSTANTS(:,150) = strpad('q_MS in component crossbridge_TRPN (fmol)');
    LEGEND_CONSTANTS(:,151) = strpad('r_s in component crossbridge_TRPN (dimensionless)');
    LEGEND_CONSTANTS(:,152) = strpad('r_w in component crossbridge_TRPN (dimensionless)');
    LEGEND_CONSTANTS(:,153) = strpad('A_eff in component crossbridge_TRPN (dimensionless)');
    LEGEND_CONSTANTS(:,154) = strpad('phi in component crossbridge_TRPN (dimensionless)');
    LEGEND_CONSTANTS(:,155) = strpad('k_uw in component crossbridge_TRPN (per_sec)');
    LEGEND_CONSTANTS(:,156) = strpad('k_ws in component crossbridge_TRPN (per_sec)');
    LEGEND_STATES(:,60) = strpad('G_w in component crossbridge_TRPN (metre)');
    LEGEND_STATES(:,61) = strpad('G_s in component crossbridge_TRPN (metre)');
    LEGEND_CONSTANTS(:,172) = strpad('c_w in component crossbridge_TRPN (per_sec)');
    LEGEND_CONSTANTS(:,173) = strpad('c_s in component crossbridge_TRPN (per_sec)');
    LEGEND_CONSTANTS(:,170) = strpad('A_w in component crossbridge_TRPN (dimensionless)');
    LEGEND_CONSTANTS(:,176) = strpad('A_s in component crossbridge_TRPN (dimensionless)');
    LEGEND_ALGEBRAIC(:,42) = strpad('nu_1 in component crossbridge_TRPN (m_per_s)');
    LEGEND_ALGEBRAIC(:,31) = strpad('nu_2 in component crossbridge_TRPN (m_per_s)');
    LEGEND_ALGEBRAIC(:,36) = strpad('nu_3 in component crossbridge_TRPN (m_per_s)');
    LEGEND_ALGEBRAIC(:,43) = strpad('nu_4 in component crossbridge_TRPN (m_per_s)');
    LEGEND_ALGEBRAIC(:,32) = strpad('nu_5 in component crossbridge_TRPN (m_per_s)');
    LEGEND_ALGEBRAIC(:,37) = strpad('nu_6 in component crossbridge_TRPN (m_per_s)');
    LEGEND_ALGEBRAIC(:,52) = strpad('v_1 in component crossbridge_TRPN (m_per_s)');
    LEGEND_ALGEBRAIC(:,27) = strpad('v_2 in component crossbridge_TRPN (m_per_s)');
    LEGEND_ALGEBRAIC(:,53) = strpad('v_4 in component crossbridge_TRPN (m_per_s)');
    LEGEND_CONSTANTS(:,157) = strpad('v_to_mu in component crossbridge_TRPN (Js_per_m2)');
    LEGEND_ALGEBRAIC(:,33) = strpad('T_active in component crossbridge_TRPN (kPa)');
    LEGEND_CONSTANTS(:,158) = strpad('T_ref in component crossbridge_TRPN (kPa)');
    LEGEND_ALGEBRAIC(:,11) = strpad('F_T_S in component crossbridge_TRPN (kPa)');
    LEGEND_ALGEBRAIC(:,28) = strpad('F_T_W in component crossbridge_TRPN (kPa)');
    LEGEND_STATES(:,62) = strpad('Cdd in component crossbridge_TRPN (metre)');
    LEGEND_ALGEBRAIC(:,44) = strpad('eta in component crossbridge_TRPN (second)');
    LEGEND_CONSTANTS(:,159) = strpad('eta_l in component crossbridge_TRPN (second)');
    LEGEND_CONSTANTS(:,160) = strpad('eta_s in component crossbridge_TRPN (second)');
    LEGEND_CONSTANTS(:,161) = strpad('k in component crossbridge_TRPN (dimensionless)');
    LEGEND_CONSTANTS(:,162) = strpad('alpha in component crossbridge_TRPN (kPa)');
    LEGEND_ALGEBRAIC(:,45) = strpad('v_Cdd in component crossbridge_TRPN (m_per_s)');
    LEGEND_ALGEBRAIC(:,46) = strpad('nu_d in component crossbridge_TRPN (m_per_s)');
    LEGEND_ALGEBRAIC(:,47) = strpad('nu_k in component crossbridge_TRPN (m_per_s)');
    LEGEND_ALGEBRAIC(:,48) = strpad('nu_f in component crossbridge_TRPN (m_per_s)');
    LEGEND_ALGEBRAIC(:,54) = strpad('F_d in component crossbridge_TRPN (kPa)');
    LEGEND_ALGEBRAIC(:,38) = strpad('F_1 in component crossbridge_TRPN (kPa)');
    LEGEND_ALGEBRAIC(:,58) = strpad('T_passive in component crossbridge_TRPN (kPa)');
    LEGEND_CONSTANTS(:,163) = strpad('b in component crossbridge_TRPN (dimensionless)');
    LEGEND_ALGEBRAIC(:,69) = strpad('mu_Ca_D in component diadCaDiffusion (J_per_mol)');
    LEGEND_ALGEBRAIC(:,71) = strpad('mu_Ca_i in component diadCaDiffusion (J_per_mol)');
    LEGEND_ALGEBRAIC(:,77) = strpad('mu_Ca_o in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,79) = strpad('mu_Ca_D in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,75) = strpad('V_mem in component LCC (volt)');
    LEGEND_ALGEBRAIC(:,89) = strpad('Af_LCC_Ca1 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,117) = strpad('Ar_LCC_Ca1 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,115) = strpad('Am_LCC_Ca1 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,176) = strpad('v_LCC_Ca1 in component LCC (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,90) = strpad('Af_LCC_Ca2 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,118) = strpad('Ar_LCC_Ca2 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,116) = strpad('Am_LCC_Ca2 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,178) = strpad('v_LCC_Ca2 in component LCC (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,109) = strpad('Af_fCa00 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,155) = strpad('Ar_fCa00 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,156) = strpad('v_fCa00 in component LCC (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,110) = strpad('Af_fCa01 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,157) = strpad('Ar_fCa01 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,160) = strpad('v_fCa01 in component LCC (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,111) = strpad('Af_fCa02 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,161) = strpad('Ar_fCa02 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,164) = strpad('v_fCa02 in component LCC (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,112) = strpad('Af_fCa10 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,165) = strpad('Ar_fCa10 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,168) = strpad('v_fCa10 in component LCC (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,113) = strpad('Af_fCa11 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,169) = strpad('Ar_fCa11 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,172) = strpad('v_fCa11 in component LCC (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,114) = strpad('Af_fCa12 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,173) = strpad('Ar_fCa12 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,175) = strpad('v_fCa12 in component LCC (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,81) = strpad('mu_S000_LCC in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,158) = strpad('v_S000_LCC in component LCC (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,82) = strpad('mu_S010_LCC in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,162) = strpad('v_S010_LCC in component LCC (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,83) = strpad('mu_S020_LCC in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,166) = strpad('v_S020_LCC in component LCC (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,84) = strpad('mu_S100_LCC in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,170) = strpad('v_S100_LCC in component LCC (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,85) = strpad('mu_S110_LCC in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,174) = strpad('v_S110_LCC in component LCC (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,87) = strpad('mu_S120_LCC in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,177) = strpad('v_S120_LCC in component LCC (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,13) = strpad('mu_S001_LCC in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,159) = strpad('v_S001_LCC in component LCC (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,14) = strpad('mu_S011_LCC in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,163) = strpad('v_S011_LCC in component LCC (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,15) = strpad('mu_S021_LCC in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,167) = strpad('v_S021_LCC in component LCC (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,16) = strpad('mu_S101_LCC in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,171) = strpad('v_S101_LCC in component LCC (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,86) = strpad('mu_S111_LCC in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,179) = strpad('v_S111_LCC in component LCC (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,88) = strpad('mu_S121_LCC in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,180) = strpad('v_S121_LCC in component LCC (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,91) = strpad('Af_d000 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,119) = strpad('Ar_d000 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,120) = strpad('v_d000 in component LCC (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,93) = strpad('Af_d010 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,123) = strpad('Ar_d010 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,124) = strpad('v_d010 in component LCC (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,95) = strpad('Af_d020 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,127) = strpad('Ar_d020 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,128) = strpad('v_d020 in component LCC (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,97) = strpad('Af_f1_000 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,131) = strpad('Ar_f1_000 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,132) = strpad('v_f1_000 in component LCC (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,101) = strpad('Af_f2_000 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,139) = strpad('Ar_f2_000 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,140) = strpad('v_f2_000 in component LCC (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,105) = strpad('Af_f3_010 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,147) = strpad('Ar_f3_010 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,148) = strpad('v_f3_010 in component LCC (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,99) = strpad('Af_f1_100 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,135) = strpad('Ar_f1_100 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,136) = strpad('v_f1_100 in component LCC (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,103) = strpad('Af_f2_100 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,143) = strpad('Ar_f2_100 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,144) = strpad('v_f2_100 in component LCC (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,107) = strpad('Af_f3_110 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,151) = strpad('Ar_f3_110 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,152) = strpad('v_f3_110 in component LCC (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,92) = strpad('Af_d001 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,121) = strpad('Ar_d001 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,122) = strpad('v_d001 in component LCC (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,94) = strpad('Af_d011 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,125) = strpad('Ar_d011 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,126) = strpad('v_d011 in component LCC (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,96) = strpad('Af_d021 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,129) = strpad('Ar_d021 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,130) = strpad('v_d021 in component LCC (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,98) = strpad('Af_f1_001 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,133) = strpad('Ar_f1_001 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,134) = strpad('v_f1_001 in component LCC (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,102) = strpad('Af_f2_001 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,141) = strpad('Ar_f2_001 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,142) = strpad('v_f2_001 in component LCC (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,106) = strpad('Af_f3_011 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,149) = strpad('Ar_f3_011 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,150) = strpad('v_f3_011 in component LCC (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,100) = strpad('Af_f1_101 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,137) = strpad('Ar_f1_101 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,138) = strpad('v_f1_101 in component LCC (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,104) = strpad('Af_f2_101 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,145) = strpad('Ar_f2_101 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,146) = strpad('v_f2_101 in component LCC (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,108) = strpad('Af_f3_111 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,153) = strpad('Ar_f3_111 in component LCC (J_per_mol)');
    LEGEND_ALGEBRAIC(:,154) = strpad('v_f3_111 in component LCC (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,17) = strpad('Ca_tot in component LCC (fmol)');
    LEGEND_ALGEBRAIC(:,185) = strpad('mu_Ca_o in component NCX (J_per_mol)');
    LEGEND_ALGEBRAIC(:,186) = strpad('mu_Ca_i in component NCX (J_per_mol)');
    LEGEND_ALGEBRAIC(:,187) = strpad('mu_Na_o in component NCX (J_per_mol)');
    LEGEND_ALGEBRAIC(:,188) = strpad('mu_Na_i in component NCX (J_per_mol)');
    LEGEND_ALGEBRAIC(:,189) = strpad('mu_P1_NCX in component NCX (J_per_mol)');
    LEGEND_ALGEBRAIC(:,190) = strpad('mu_P2_NCX in component NCX (J_per_mol)');
    LEGEND_ALGEBRAIC(:,191) = strpad('mu_P3_NCX in component NCX (J_per_mol)');
    LEGEND_ALGEBRAIC(:,192) = strpad('mu_P4_NCX in component NCX (J_per_mol)');
    LEGEND_ALGEBRAIC(:,193) = strpad('mu_P5_NCX in component NCX (J_per_mol)');
    LEGEND_ALGEBRAIC(:,194) = strpad('mu_P6_NCX in component NCX (J_per_mol)');
    LEGEND_ALGEBRAIC(:,219) = strpad('v_P1_NCX in component NCX (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,207) = strpad('v_P2_NCX in component NCX (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,210) = strpad('v_P3_NCX in component NCX (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,213) = strpad('v_P4_NCX in component NCX (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,216) = strpad('v_P5_NCX in component NCX (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,220) = strpad('v_P6_NCX in component NCX (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,195) = strpad('Af_r1 in component NCX (J_per_mol)');
    LEGEND_ALGEBRAIC(:,201) = strpad('Ar_r1 in component NCX (J_per_mol)');
    LEGEND_ALGEBRAIC(:,202) = strpad('v_r1 in component NCX (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,196) = strpad('Af_r2 in component NCX (J_per_mol)');
    LEGEND_ALGEBRAIC(:,204) = strpad('Ar_r2 in component NCX (J_per_mol)');
    LEGEND_ALGEBRAIC(:,205) = strpad('v_r2 in component NCX (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,197) = strpad('Af_r3 in component NCX (J_per_mol)');
    LEGEND_ALGEBRAIC(:,206) = strpad('Ar_r3 in component NCX (J_per_mol)');
    LEGEND_ALGEBRAIC(:,208) = strpad('v_r3 in component NCX (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,198) = strpad('Af_r4 in component NCX (J_per_mol)');
    LEGEND_ALGEBRAIC(:,209) = strpad('Ar_r4 in component NCX (J_per_mol)');
    LEGEND_ALGEBRAIC(:,211) = strpad('v_r4 in component NCX (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,199) = strpad('Af_r5 in component NCX (J_per_mol)');
    LEGEND_ALGEBRAIC(:,212) = strpad('Ar_r5 in component NCX (J_per_mol)');
    LEGEND_ALGEBRAIC(:,214) = strpad('v_r5 in component NCX (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,200) = strpad('Af_r6 in component NCX (J_per_mol)');
    LEGEND_ALGEBRAIC(:,217) = strpad('Ar_r6 in component NCX (J_per_mol)');
    LEGEND_ALGEBRAIC(:,218) = strpad('v_r6 in component NCX (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,184) = strpad('V_mem in component NCX (volt)');
    LEGEND_ALGEBRAIC(:,224) = strpad('mu_Ca_i in component pCa (J_per_mol)');
    LEGEND_ALGEBRAIC(:,225) = strpad('mu_Ca_o in component pCa (J_per_mol)');
    LEGEND_ALGEBRAIC(:,226) = strpad('mu_pCa in component pCa (J_per_mol)');
    LEGEND_ALGEBRAIC(:,227) = strpad('mu_pCa_Ca in component pCa (J_per_mol)');
    LEGEND_ALGEBRAIC(:,1) = strpad('mu_PLB in component PLB (J_per_mol)');
    LEGEND_ALGEBRAIC(:,26) = strpad('mu_PKACI in component PLB (J_per_mol)');
    LEGEND_ALGEBRAIC(:,30) = strpad('mu_PLB_PKACI in component PLB (J_per_mol)');
    LEGEND_ALGEBRAIC(:,35) = strpad('mu_PP1 in component PLB (J_per_mol)');
    LEGEND_ALGEBRAIC(:,40) = strpad('mu_PLBp_PP1 in component PLB (J_per_mol)');
    LEGEND_ALGEBRAIC(:,50) = strpad('mu_PLBp in component PLB (J_per_mol)');
    LEGEND_ALGEBRAIC(:,41) = strpad('mu_Ip in component PLB (J_per_mol)');
    LEGEND_ALGEBRAIC(:,51) = strpad('mu_Ip_PP1 in component PLB (J_per_mol)');
    LEGEND_CONSTANTS(:,164) = strpad('nCa_1 in component RyR (dimensionless)');
    LEGEND_CONSTANTS(:,165) = strpad('nCa_2 in component RyR (dimensionless)');
    LEGEND_ALGEBRAIC(:,230) = strpad('mu_Ca_SR in component RyR (J_per_mol)');
    LEGEND_ALGEBRAIC(:,232) = strpad('mu_Ca_D in component RyR (J_per_mol)');
    LEGEND_ALGEBRAIC(:,18) = strpad('q_Ca_gate_complexes in component RyR (fmol)');
    LEGEND_ALGEBRAIC(:,234) = strpad('mu_C_RyR in component RyR (J_per_mol)');
    LEGEND_ALGEBRAIC(:,235) = strpad('mu_CI_RyR in component RyR (J_per_mol)');
    LEGEND_ALGEBRAIC(:,236) = strpad('mu_I_RyR in component RyR (J_per_mol)');
    LEGEND_ALGEBRAIC(:,237) = strpad('mu_O_RyR in component RyR (J_per_mol)');
    LEGEND_ALGEBRAIC(:,239) = strpad('v_OC in component RyR (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,241) = strpad('v_CCI in component RyR (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,243) = strpad('v_CII in component RyR (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,245) = strpad('v_IO in component RyR (fmol_per_sec)');
    LEGEND_CONSTANTS(:,166) = strpad('n_Ca_i in component SERCA (dimensionless)');
    LEGEND_CONSTANTS(:,167) = strpad('n_Ca_SR in component SERCA (dimensionless)');
    LEGEND_CONSTANTS(:,168) = strpad('n_H in component SERCA (dimensionless)');
    LEGEND_ALGEBRAIC(:,19) = strpad('q_SERCA_Ca_complexes in component SERCA (fmol)');
    LEGEND_ALGEBRAIC(:,20) = strpad('c_Ca_i in component SERCA (mM)');
    LEGEND_ALGEBRAIC(:,21) = strpad('c_Ca_SR in component SERCA (mM)');
    LEGEND_ALGEBRAIC(:,22) = strpad('c_H in component SERCA (mM)');
    LEGEND_ALGEBRAIC(:,23) = strpad('c_MgADP in component SERCA (mM)');
    LEGEND_ALGEBRAIC(:,24) = strpad('c_MgATP in component SERCA (mM)');
    LEGEND_ALGEBRAIC(:,25) = strpad('c_Pi in component SERCA (mM)');
    LEGEND_CONSTANTS(:,169) = strpad('vol_i in component SERCA (pL)');
    LEGEND_CONSTANTS(:,175) = strpad('vol_sr in component SERCA (pL)');
    LEGEND_CONSTANTS(:,177) = strpad('vol_isr in component SERCA (pL)');
    LEGEND_ALGEBRAIC(:,240) = strpad('mu_Ca_i in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,242) = strpad('mu_Ca_SR in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,244) = strpad('mu_H in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,246) = strpad('mu_MgADP in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,248) = strpad('mu_MgATP in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,250) = strpad('mu_P1 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,285) = strpad('v_P1 in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,249) = strpad('mu_Pi in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,251) = strpad('mu_P2 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,292) = strpad('v_P2 in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,252) = strpad('mu_P2a in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,289) = strpad('v_P2a in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,253) = strpad('mu_P4 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,294) = strpad('v_P4 in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,254) = strpad('mu_P5 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,295) = strpad('v_P5 in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,256) = strpad('mu_P6 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,298) = strpad('v_P6 in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,258) = strpad('mu_P8 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,300) = strpad('v_P8 in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,259) = strpad('mu_P9 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,302) = strpad('v_P9 in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,255) = strpad('mu_P10 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,303) = strpad('v_P10 in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,260) = strpad('mu_PLBp_baseline in component SERCA (J_per_mol)');
    LEGEND_CONSTANTS(:,174) = strpad('mu_PLBp in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,261) = strpad('mu_PLBp_eff in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,264) = strpad('Af_R1_2 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,265) = strpad('Ar_R1_2 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,281) = strpad('v_SERCA_R1_2 in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,266) = strpad('Af_R5_6 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,267) = strpad('Ar_R5_6 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,283) = strpad('v_SERCA_R5_6 in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,268) = strpad('Af_R2_2a in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,269) = strpad('Ar_R2_2a in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,286) = strpad('v_SERCA_R2_2a in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,270) = strpad('Af_R2_4 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,271) = strpad('Ar_R2_4 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,288) = strpad('v_SERCA_R2_4 in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,272) = strpad('Af_R4_5 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,273) = strpad('Ar_R4_5 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,291) = strpad('v_SERCA_R4_5 in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,274) = strpad('Af_R6_8 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,275) = strpad('Ar_R6_8 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,293) = strpad('v_SERCA_R6_8 in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,276) = strpad('Af_R8_9 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,277) = strpad('Ar_R8_9 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,297) = strpad('v_SERCA_R8_9 in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,278) = strpad('Af_R9_10 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,279) = strpad('Ar_R9_10 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,299) = strpad('v_SERCA_R9_10 in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,262) = strpad('Af_R10_1 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,263) = strpad('Ar_R10_1 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,280) = strpad('v_SERCA_R10_1 in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,257) = strpad('v_SERCA_R10_1_noPLBp in component SERCA (fmol_per_sec)');
    LEGEND_RATES(:,21) = strpad('d/dt q_Ca_SR in component environment (fmol)');
    LEGEND_RATES(:,5) = strpad('d/dt q_Ca_i in component environment (fmol)');
    LEGEND_RATES(:,3) = strpad('d/dt q_TRPN in component environment (fmol)');
    LEGEND_RATES(:,4) = strpad('d/dt q_Ca_TRPN in component environment (fmol)');
    LEGEND_RATES(:,8) = strpad('d/dt q_B_XB in component environment (fmol)');
    LEGEND_RATES(:,9) = strpad('d/dt q_U_XB in component environment (fmol)');
    LEGEND_RATES(:,10) = strpad('d/dt q_W_XB in component environment (fmol)');
    LEGEND_RATES(:,11) = strpad('d/dt q_S_XB in component environment (fmol)');
    LEGEND_RATES(:,2) = strpad('d/dt q_Ca_D in component environment (fmol)');
    LEGEND_RATES(:,12) = strpad('d/dt q_Ca_o in component environment (fmol)');
    LEGEND_RATES(:,6) = strpad('d/dt q_Na_i in component environment (fmol)');
    LEGEND_RATES(:,7) = strpad('d/dt q_Na_o in component environment (fmol)');
    LEGEND_RATES(:,22) = strpad('d/dt q_pCa in component environment (fmol)');
    LEGEND_RATES(:,23) = strpad('d/dt q_pCa_Ca in component environment (fmol)');
    LEGEND_RATES(:,13) = strpad('d/dt q_PLB in component environment (fmol)');
    LEGEND_RATES(:,14) = strpad('d/dt q_PKACI in component environment (fmol)');
    LEGEND_RATES(:,15) = strpad('d/dt q_PLB_PKACI in component environment (fmol)');
    LEGEND_RATES(:,16) = strpad('d/dt q_PP1 in component environment (fmol)');
    LEGEND_RATES(:,17) = strpad('d/dt q_PLBp_PP1 in component environment (fmol)');
    LEGEND_RATES(:,18) = strpad('d/dt q_PLBp in component environment (fmol)');
    LEGEND_RATES(:,19) = strpad('d/dt q_Ip in component environment (fmol)');
    LEGEND_RATES(:,20) = strpad('d/dt q_Ip_PP1 in component environment (fmol)');
    LEGEND_RATES(:,24) = strpad('d/dt q_H in component environment (fmol)');
    LEGEND_RATES(:,26) = strpad('d/dt q_MgADP in component environment (fmol)');
    LEGEND_RATES(:,27) = strpad('d/dt q_MgATP in component environment (fmol)');
    LEGEND_RATES(:,25) = strpad('d/dt q_Pi in component environment (fmol)');
    LEGEND_RATES(:,1) = strpad('d/dt q_membrane in component environment (fC)');
    LEGEND_RATES(:,60) = strpad('d/dt G_w in component crossbridge_TRPN (metre)');
    LEGEND_RATES(:,59) = strpad('d/dt SL in component crossbridge_TRPN (metre)');
    LEGEND_RATES(:,61) = strpad('d/dt G_s in component crossbridge_TRPN (metre)');
    LEGEND_RATES(:,62) = strpad('d/dt Cdd in component crossbridge_TRPN (metre)');
    LEGEND_RATES(:,28) = strpad('d/dt q_000_LCC in component environment (fmol)');
    LEGEND_RATES(:,29) = strpad('d/dt q_010_LCC in component environment (fmol)');
    LEGEND_RATES(:,30) = strpad('d/dt q_020_LCC in component environment (fmol)');
    LEGEND_RATES(:,31) = strpad('d/dt q_100_LCC in component environment (fmol)');
    LEGEND_RATES(:,32) = strpad('d/dt q_110_LCC in component environment (fmol)');
    LEGEND_RATES(:,33) = strpad('d/dt q_120_LCC in component environment (fmol)');
    LEGEND_RATES(:,34) = strpad('d/dt q_001_LCC in component environment (fmol)');
    LEGEND_RATES(:,35) = strpad('d/dt q_011_LCC in component environment (fmol)');
    LEGEND_RATES(:,36) = strpad('d/dt q_021_LCC in component environment (fmol)');
    LEGEND_RATES(:,37) = strpad('d/dt q_101_LCC in component environment (fmol)');
    LEGEND_RATES(:,38) = strpad('d/dt q_111_LCC in component environment (fmol)');
    LEGEND_RATES(:,39) = strpad('d/dt q_121_LCC in component environment (fmol)');
    LEGEND_RATES(:,40) = strpad('d/dt q_P1_NCX in component environment (fmol)');
    LEGEND_RATES(:,41) = strpad('d/dt q_P2_NCX in component environment (fmol)');
    LEGEND_RATES(:,42) = strpad('d/dt q_P3_NCX in component environment (fmol)');
    LEGEND_RATES(:,43) = strpad('d/dt q_P4_NCX in component environment (fmol)');
    LEGEND_RATES(:,44) = strpad('d/dt q_P5_NCX in component environment (fmol)');
    LEGEND_RATES(:,45) = strpad('d/dt q_P6_NCX in component environment (fmol)');
    LEGEND_RATES(:,49) = strpad('d/dt q_O_RyR in component environment (fmol)');
    LEGEND_RATES(:,46) = strpad('d/dt q_C_RyR in component environment (fmol)');
    LEGEND_RATES(:,47) = strpad('d/dt q_CI_RyR in component environment (fmol)');
    LEGEND_RATES(:,48) = strpad('d/dt q_I_RyR in component environment (fmol)');
    LEGEND_RATES(:,50) = strpad('d/dt q_P1_SERCA in component environment (fmol)');
    LEGEND_RATES(:,51) = strpad('d/dt q_P2_SERCA in component environment (fmol)');
    LEGEND_RATES(:,52) = strpad('d/dt q_P2a_SERCA in component environment (fmol)');
    LEGEND_RATES(:,53) = strpad('d/dt q_P4_SERCA in component environment (fmol)');
    LEGEND_RATES(:,54) = strpad('d/dt q_P5_SERCA in component environment (fmol)');
    LEGEND_RATES(:,58) = strpad('d/dt q_P10_SERCA in component environment (fmol)');
    LEGEND_RATES(:,55) = strpad('d/dt q_P6_SERCA in component environment (fmol)');
    LEGEND_RATES(:,56) = strpad('d/dt q_P8_SERCA in component environment (fmol)');
    LEGEND_RATES(:,57) = strpad('d/dt q_P9_SERCA in component environment (fmol)');
    LEGEND_STATES  = LEGEND_STATES';
    LEGEND_ALGEBRAIC = LEGEND_ALGEBRAIC';
    LEGEND_RATES = LEGEND_RATES';
    LEGEND_CONSTANTS = LEGEND_CONSTANTS';
end

function [STATES, CONSTANTS] = initConsts()
    VOI = 0; CONSTANTS = []; STATES = []; ALGEBRAIC = [];
    CONSTANTS(:,1) = 1.15709e-07;
    CONSTANTS(:,2) = 61.0541;
    CONSTANTS(:,3) = 6.60969;
    CONSTANTS(:,4) = 0.295711;
    CONSTANTS(:,5) = 0.00695792;
    CONSTANTS(:,6) = 125243;
    CONSTANTS(:,7) = 0.0310391;
    CONSTANTS(:,8) = 1.38255;
    CONSTANTS(:,9) = 1.82032;
    CONSTANTS(:,10) = 318.525;
    CONSTANTS(:,11) = 16.0854;
    CONSTANTS(:,12) = 21.1788;
    CONSTANTS(:,13) = 0.0976302;
    CONSTANTS(:,14) = 0.00493031;
    CONSTANTS(:,15) = 0.00649145;
    CONSTANTS(:,16) = 30.6817;
    CONSTANTS(:,17) = 152.358;
    CONSTANTS(:,18) = 0.00940418;
    CONSTANTS(:,19) = 0.0466988;
    CONSTANTS(:,20) = 1.9942;
    CONSTANTS(:,21) = 9.9027;
    CONSTANTS(:,22) = 0.000611238;
    CONSTANTS(:,23) = 0.00303525;
    CONSTANTS(:,24) = 4350.95;
    CONSTANTS(:,25) = 21605.7;
    CONSTANTS(:,26) = 1.3336;
    CONSTANTS(:,27) = 6.62232;
    CONSTANTS(:,28) = 33428.5;
    CONSTANTS(:,29) = 165997;
    CONSTANTS(:,30) = 1688.13;
    CONSTANTS(:,31) = 8382.84;
    CONSTANTS(:,32) = 2222.67;
    CONSTANTS(:,33) = 11037.2;
    CONSTANTS(:,34) = 137056;
    CONSTANTS(:,35) = 4.86896e+07;
    CONSTANTS(:,36) = 18031.2;
    CONSTANTS(:,37) = 4.86896e+07;
    CONSTANTS(:,38) = 137056;
    CONSTANTS(:,39) = 2.58491;
    CONSTANTS(:,40) = 10645.2;
    CONSTANTS(:,41) = 1.39676e-05;
    CONSTANTS(:,42) = 12.9403;
    CONSTANTS(:,43) = 1.86433;
    CONSTANTS(:,44) = 0.0641048;
    CONSTANTS(:,45) = 0.201046;
    CONSTANTS(:,46) = 1268.2;
    CONSTANTS(:,47) = 1.09771e+06;
    CONSTANTS(:,48) = 8.4695;
    CONSTANTS(:,49) = 0.169284;
    CONSTANTS(:,50) = 605.345;
    CONSTANTS(:,51) = 50.4454;
    CONSTANTS(:,52) = 3.7044e-07;
    CONSTANTS(:,53) = 6.52609;
    CONSTANTS(:,54) = 32453.6;
    CONSTANTS(:,55) = 6.52609;
    CONSTANTS(:,56) = 0.410048;
    CONSTANTS(:,57) = 306.914;
    CONSTANTS(:,58) = 6705.42;
    CONSTANTS(:,59) = 6705.42;
    CONSTANTS(:,60) = 5.16941e-06;
    CONSTANTS(:,61) = 4.84473;
    CONSTANTS(:,62) = 1.14841;
    CONSTANTS(:,63) = 11.5169;
    CONSTANTS(:,64) = 0.0633859;
    CONSTANTS(:,65) = 9.07364;
    CONSTANTS(:,66) = 3.40261;
    CONSTANTS(:,67) = 22.2479;
    CONSTANTS(:,68) = 5.56196e-06;
    CONSTANTS(:,69) = 68.3097;
    CONSTANTS(:,70) = 0.0273186;
    CONSTANTS(:,71) = 1.52818;
    CONSTANTS(:,72) = 30.261;
    CONSTANTS(:,73) = 22.9835;
    CONSTANTS(:,74) = 0.307744;
    CONSTANTS(:,75) = 6.09395;
    CONSTANTS(:,76) = 4.6284;
    CONSTANTS(:,77) = 4985.77;
    CONSTANTS(:,78) = 98728.5;
    CONSTANTS(:,79) = 74985.1;
    CONSTANTS(:,80) = 1004.03;
    CONSTANTS(:,81) = 19881.9;
    CONSTANTS(:,82) = 15100.5;
    CONSTANTS(:,83) = 5.29552e+08;
    CONSTANTS(:,84) = 30.5889;
    CONSTANTS(:,85) = 26491.3;
    CONSTANTS(:,86) = 48390.4;
    CONSTANTS(:,87) = 7.29508e+08;
    CONSTANTS(:,88) = 137.015;
    CONSTANTS(:,89) = 0.0516362;
    CONSTANTS(:,90) = 0.0433449;
    CONSTANTS(:,91) = 0.0123956;
    CONSTANTS(:,92) = 0.0179648;
    CONSTANTS(:,93) = 0.48081;
    CONSTANTS(:,94) = 0.0120814;
    CONSTANTS(:,95) = 2.99063;
    CONSTANTS(:,96) = 0.0189733;
    CONSTANTS(:,97) = 1.63618;
    CONSTANTS(:,98) = 66.4927;
    CONSTANTS(:,99) = 62.242;
    CONSTANTS(:,100) = 0.0305154;
    CONSTANTS(:,101) = 2111.06;
    CONSTANTS(:,102) = 29.5362;
    CONSTANTS(:,103) = 0.0991171;
    CONSTANTS(:,104) = 7.08424;
    CONSTANTS(:,105) = 61.3791;
    CONSTANTS(:,106) = 1.84355;
    CONSTANTS(:,107) = 0.270336;
    CONSTANTS(:,108) = 1344.35;
    CONSTANTS(:,109) = 0.00209829;
    CONSTANTS(:,110) = 143.432;
    CONSTANTS(:,111) = 0.688505;
    CONSTANTS(:,112) = 1.3084;
    CONSTANTS(:,113) = 1.34332;
    CONSTANTS(:,114) = 495.145;
    CONSTANTS(:,115) = 14.9326;
    CONSTANTS(:,116) = 1.49783e-05;
    CONSTANTS(:,117) = 0.00615601;
    CONSTANTS(:,118) = 2;
    CONSTANTS(:,119) = 2.1404;
    CONSTANTS(:,120) = -1.1495;
    CONSTANTS(:,121) = 0.72162;
    CONSTANTS(:,122) = 4.2933;
    CONSTANTS(:,123) = -2.1404;
    CONSTANTS(:,124) = 1.8993;
    CONSTANTS(:,125) = -0.52288;
    CONSTANTS(:,126) = 0;
    CONSTANTS(:,127) = 3;
    CONSTANTS(:,128) = 3;
    CONSTANTS(:,129) = -0.55679;
    CONSTANTS(:,130) = 0.44321;
    CONSTANTS(:,131) = 1.1;
    CONSTANTS(:,132) = 2;
    CONSTANTS(:,133) = 25.84;
    CONSTANTS(:,134) = 153400;
    STATES(:,1) = -13039;
    STATES(:,2) = 3.68876E-07;
    STATES(:,3) = 2.57;
    STATES(:,4) = 1e-18;
    STATES(:,5) = 0.005663912;
    STATES(:,6) = 481.46;
    STATES(:,7) = 725.48;
    STATES(:,8) = 1;
    STATES(:,9) = 0;
    STATES(:,10) = 0;
    STATES(:,11) = 0;
    STATES(:,12) = 6.84;
    STATES(:,13) = 4.028E+00;
    STATES(:,14) = 2.234E-03;
    STATES(:,15) = 1e-18;
    STATES(:,16) = 3.382E-02;
    STATES(:,17) = 1e-18;
    STATES(:,18) = 1e-18;
    CONSTANTS(:,135) = 1e-18;
    STATES(:,19) = 1.999E-03;
    STATES(:,20) = 1e-18;
    STATES(:,21) = 0.641;
    STATES(:,22) = 0.0032;
    STATES(:,23) = 1e-9;
    STATES(:,24) = 2.584e-6;
    STATES(:,25) = 570;
    STATES(:,26) = 1.3794;
    STATES(:,27) = 3.8;
    STATES(:,28) = 1.3798e-05;
    STATES(:,29) = 1.3798e-05;
    STATES(:,30) = 1.3798e-05;
    STATES(:,31) = 1.3798e-05;
    STATES(:,32) = 1.3798e-05;
    STATES(:,33) = 1.3798e-05;
    STATES(:,34) = 1.3798e-05;
    STATES(:,35) = 1.3798e-05;
    STATES(:,36) = 1.3798e-05;
    STATES(:,37) = 1.3798e-05;
    STATES(:,38) = 1.3798e-05;
    STATES(:,39) = 1.3798e-05;
    STATES(:,40) = 4.24554e-07;
    STATES(:,41) = 4.24554e-07;
    STATES(:,42) = 4.24554e-07;
    STATES(:,43) = 4.24554e-07;
    STATES(:,44) = 4.24554e-07;
    STATES(:,45) = 4.24554e-07;
    STATES(:,46) = 4.13941e-05;
    STATES(:,47) = 4.13941e-05;
    STATES(:,48) = 4.13941e-05;
    STATES(:,49) = 4.13941e-05;
    STATES(:,50) = 2.83036e-08;
    STATES(:,51) = 2.83036e-08;
    STATES(:,52) = 2.83036e-08;
    STATES(:,53) = 2.83036e-08;
    STATES(:,54) = 2.83036e-08;
    STATES(:,55) = 2.83036e-08;
    STATES(:,56) = 2.83036e-08;
    STATES(:,57) = 2.83036e-08;
    STATES(:,58) = 2.83036e-08;
    STATES(:,59) = 2e-6;
    CONSTANTS(:,136) = 1;
    CONSTANTS(:,137) = 0.001;
    CONSTANTS(:,138) = 19e-6;
    CONSTANTS(:,139) = 38;
    CONSTANTS(:,140) = 5.182;
    CONSTANTS(:,141) = 0.0025375;
    CONSTANTS(:,142) = 8.31;
    CONSTANTS(:,143) = 310;
    CONSTANTS(:,144) = 96485;
    CONSTANTS(:,145) = 1;
    CONSTANTS(:,146) = -1;
    CONSTANTS(:,147) = 1;
    CONSTANTS(:,148) = 2;
    CONSTANTS(:,149) = 2e-6;
    CONSTANTS(:,150) = 1e-6;
    CONSTANTS(:,151) = 0.25;
    CONSTANTS(:,152) = 0.5;
    CONSTANTS(:,153) = 25;
    CONSTANTS(:,154) = 2.23;
    CONSTANTS(:,155) = 26;
    CONSTANTS(:,156) = 4;
    STATES(:,60) = 1e-6;
    STATES(:,61) = 1e-6;
    CONSTANTS(:,157) = 1;
    CONSTANTS(:,158) = 40.5;
    STATES(:,62) = 0;
    CONSTANTS(:,159) = 200e3;
    CONSTANTS(:,160) = 20e3;
    CONSTANTS(:,161) = 7;
    CONSTANTS(:,162) = 2.1;
    CONSTANTS(:,163) = 9.1;
    CONSTANTS(:,164) = 1;
    CONSTANTS(:,165) = 2;
    CONSTANTS(:,166) = 2;
    CONSTANTS(:,167) = 2;
    CONSTANTS(:,168) = 2;
    CONSTANTS(:,169) = 34.0;
    CONSTANTS(:,170) = ( CONSTANTS(:,153).*CONSTANTS(:,151))./( (1.00000 - CONSTANTS(:,151)).*CONSTANTS(:,152)+CONSTANTS(:,151));
    CONSTANTS(:,171) =  CONSTANTS(:,139).*0.0350000;
    CONSTANTS(:,172) = ( CONSTANTS(:,154).*CONSTANTS(:,155).*(1.00000 - CONSTANTS(:,152)))./CONSTANTS(:,152);
    CONSTANTS(:,173) = ( CONSTANTS(:,154).*CONSTANTS(:,156).*(1.00000 - CONSTANTS(:,151)).*CONSTANTS(:,152))./CONSTANTS(:,151);
    CONSTANTS(:,174) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,98).*CONSTANTS(:,135));
    CONSTANTS(:,175) =  CONSTANTS(:,169).*0.0350000;
    CONSTANTS(:,176) = CONSTANTS(:,170);
    CONSTANTS(:,177) = CONSTANTS(:,169)+CONSTANTS(:,175);
    if (isempty(STATES)), warning('Initial values for states not set');, end
end

function [RATES, ALGEBRAIC] = computeRates(VOI, STATES, CONSTANTS)
	disp(VOI)
    global algebraicVariableCount;
    statesSize = size(STATES);
    statesColumnCount = statesSize(2);
    if ( statesColumnCount == 1)
        STATES = STATES';
        ALGEBRAIC = zeros(1, algebraicVariableCount);
        utilOnes = 1;
    else
        statesRowCount = statesSize(1);
        ALGEBRAIC = zeros(statesRowCount, algebraicVariableCount);
        RATES = zeros(statesRowCount, statesColumnCount);
        utilOnes = ones(statesRowCount, 1);
    end
    ALGEBRAIC(:,3) = piecewise({VOI<0.0600000,  1.00000.*CONSTANTS(:,138) , VOI>0.500000&VOI<1.10000,   - 0.100000.*CONSTANTS(:,138) },  0.00000.*CONSTANTS(:,138));
    ALGEBRAIC(:,27) = ALGEBRAIC(:,3);
    RATES(:,59) = ALGEBRAIC(:,27);
    [CONSTANTS, STATES, ALGEBRAIC] = rootfind_0(VOI, CONSTANTS, STATES, ALGEBRAIC);
    RATES(:,62) = ALGEBRAIC(:,45);
    ALGEBRAIC(:,31) =   - CONSTANTS(:,170).*ALGEBRAIC(:,27);
    ALGEBRAIC(:,36) =  CONSTANTS(:,172).*STATES(:,60);
    ALGEBRAIC(:,42) =  - ALGEBRAIC(:,31) - ALGEBRAIC(:,36);
    ALGEBRAIC(:,52) = ALGEBRAIC(:,42);
    RATES(:,60) = ALGEBRAIC(:,52);
    ALGEBRAIC(:,32) =   - CONSTANTS(:,176).*ALGEBRAIC(:,27);
    ALGEBRAIC(:,37) =  CONSTANTS(:,173).*STATES(:,61);
    ALGEBRAIC(:,43) =  - ALGEBRAIC(:,32) - ALGEBRAIC(:,37);
    ALGEBRAIC(:,53) = ALGEBRAIC(:,43);
    RATES(:,61) = ALGEBRAIC(:,53);
    ALGEBRAIC(:,35) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,96).*STATES(:,16));
    ALGEBRAIC(:,41) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,99).*STATES(:,19));
    ALGEBRAIC(:,51) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,100).*STATES(:,20));
    ALGEBRAIC(:,57) =  CONSTANTS(:,46).*(exp((ALGEBRAIC(:,35)+ALGEBRAIC(:,41))./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,51)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    RATES(:,19) =  - ALGEBRAIC(:,57);
    RATES(:,20) = ALGEBRAIC(:,57);
    ALGEBRAIC(:,1) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,93).*STATES(:,13));
    ALGEBRAIC(:,26) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,94).*STATES(:,14));
    ALGEBRAIC(:,30) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,95).*STATES(:,15));
    ALGEBRAIC(:,56) =  CONSTANTS(:,42).*(exp((ALGEBRAIC(:,1)+ALGEBRAIC(:,26))./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,30)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,50) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,98).*STATES(:,18));
    ALGEBRAIC(:,61) =  CONSTANTS(:,43).*(exp(ALGEBRAIC(:,30)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp((ALGEBRAIC(:,50)+ALGEBRAIC(:,26))./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    RATES(:,14) = ALGEBRAIC(:,61) - ALGEBRAIC(:,56);
    RATES(:,15) = ALGEBRAIC(:,56) - ALGEBRAIC(:,61);
    RATES(:,16) = ALGEBRAIC(:,56) - ALGEBRAIC(:,61);
    ALGEBRAIC(:,40) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,97).*STATES(:,17));
    ALGEBRAIC(:,63) =  CONSTANTS(:,44).*(exp((ALGEBRAIC(:,50)+ALGEBRAIC(:,35))./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,40)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    RATES(:,18) = ALGEBRAIC(:,61) - ALGEBRAIC(:,63);
    ALGEBRAIC(:,59) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,63).*STATES(:,3));
    ALGEBRAIC(:,62) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,62).*STATES(:,5));
    ALGEBRAIC(:,64) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,64).*STATES(:,4));
    ALGEBRAIC(:,67) =  CONSTANTS(:,2).*(exp(( CONSTANTS(:,132).*ALGEBRAIC(:,62)+ALGEBRAIC(:,59))./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,64)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    RATES(:,3) =  - ALGEBRAIC(:,67);
    RATES(:,4) = ALGEBRAIC(:,67);
    ALGEBRAIC(:,66) =  CONSTANTS(:,45).*(exp(ALGEBRAIC(:,40)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp((ALGEBRAIC(:,1)+ALGEBRAIC(:,35))./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    RATES(:,13) = ALGEBRAIC(:,66) - ALGEBRAIC(:,56);
    RATES(:,17) = ALGEBRAIC(:,63) - ALGEBRAIC(:,66);
    ALGEBRAIC(:,65) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,65).*STATES(:,8));
    ALGEBRAIC(:,68) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,66).*STATES(:,9));
    ALGEBRAIC(:,74) =  CONSTANTS(:,3).*(exp((ALGEBRAIC(:,65)+ CONSTANTS(:,131).*ALGEBRAIC(:,64))./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp((ALGEBRAIC(:,68)+ CONSTANTS(:,131).*ALGEBRAIC(:,64))./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    RATES(:,8) =  - ALGEBRAIC(:,74);
    ALGEBRAIC(:,70) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,67).*STATES(:,10));
    ALGEBRAIC(:,76) =  CONSTANTS(:,4).*(exp(ALGEBRAIC(:,68)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,70)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,72) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,68).*STATES(:,11));
    ALGEBRAIC(:,78) =  CONSTANTS(:,5).*(exp(ALGEBRAIC(:,70)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,72)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    RATES(:,10) = ALGEBRAIC(:,76) - ALGEBRAIC(:,78);
    ALGEBRAIC(:,80) =  CONSTANTS(:,6).*(exp(ALGEBRAIC(:,72)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,68)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    RATES(:,9) = (ALGEBRAIC(:,74) - ALGEBRAIC(:,76))+ALGEBRAIC(:,80);
    RATES(:,11) = ALGEBRAIC(:,78) - ALGEBRAIC(:,80);
    ALGEBRAIC(:,81) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,71).*STATES(:,28));
    ALGEBRAIC(:,109) = ALGEBRAIC(:,81);
    ALGEBRAIC(:,79) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,69).*STATES(:,2));
    ALGEBRAIC(:,155) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,77).*STATES(:,34))+ CONSTANTS(:,118).*ALGEBRAIC(:,79);
    ALGEBRAIC(:,156) =  CONSTANTS(:,28).*(exp(ALGEBRAIC(:,109)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,155)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,75) = STATES(:,1)./CONSTANTS(:,134);
    ALGEBRAIC(:,91) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,71).*STATES(:,28))+ CONSTANTS(:,119).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,119) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,74).*STATES(:,31))+ CONSTANTS(:,123).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,120) =  CONSTANTS(:,10).*(exp(ALGEBRAIC(:,91)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,119)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,97) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,71).*STATES(:,28))+ CONSTANTS(:,120).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,131) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,72).*STATES(:,29))+ CONSTANTS(:,124).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,132) =  CONSTANTS(:,16).*(exp(ALGEBRAIC(:,97)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,131)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,101) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,71).*STATES(:,28))+ CONSTANTS(:,121).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,139) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,73).*STATES(:,30))+ CONSTANTS(:,125).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,140) =  CONSTANTS(:,20).*(exp(ALGEBRAIC(:,101)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,139)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,158) = (( - ALGEBRAIC(:,120) - ALGEBRAIC(:,132)) - ALGEBRAIC(:,140)) - ALGEBRAIC(:,156);
    RATES(:,28) = ALGEBRAIC(:,158);
    ALGEBRAIC(:,92) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,77).*STATES(:,34))+ CONSTANTS(:,119).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,121) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,80).*STATES(:,37))+ CONSTANTS(:,123).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,122) =  CONSTANTS(:,13).*(exp(ALGEBRAIC(:,92)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,121)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,98) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,77).*STATES(:,34))+ CONSTANTS(:,120).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,133) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,78).*STATES(:,35))+ CONSTANTS(:,124).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,134) =  CONSTANTS(:,18).*(exp(ALGEBRAIC(:,98)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,133)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,102) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,77).*STATES(:,34))+ CONSTANTS(:,121).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,141) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,79).*STATES(:,36))+ CONSTANTS(:,125).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,142) =  CONSTANTS(:,22).*(exp(ALGEBRAIC(:,102)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,141)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,159) = (( - ALGEBRAIC(:,122) - ALGEBRAIC(:,134)) - ALGEBRAIC(:,142)) -  - ALGEBRAIC(:,156);
    RATES(:,34) = ALGEBRAIC(:,159);
    ALGEBRAIC(:,82) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,72).*STATES(:,29));
    ALGEBRAIC(:,110) = ALGEBRAIC(:,82);
    ALGEBRAIC(:,157) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,78).*STATES(:,35))+ CONSTANTS(:,118).*ALGEBRAIC(:,79);
    ALGEBRAIC(:,160) =  CONSTANTS(:,30).*(exp(ALGEBRAIC(:,110)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,157)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,93) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,72).*STATES(:,29))+ CONSTANTS(:,119).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,123) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,75).*STATES(:,32))+ CONSTANTS(:,123).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,124) =  CONSTANTS(:,11).*(exp(ALGEBRAIC(:,93)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,123)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,105) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,72).*STATES(:,29))+ CONSTANTS(:,122).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,147) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,73).*STATES(:,30))+ CONSTANTS(:,126).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,148) =  CONSTANTS(:,24).*(exp(ALGEBRAIC(:,105)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,147)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,162) = (( - ALGEBRAIC(:,124)+ALGEBRAIC(:,132)) - ALGEBRAIC(:,160)) - ALGEBRAIC(:,148);
    RATES(:,29) = ALGEBRAIC(:,162);
    ALGEBRAIC(:,94) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,78).*STATES(:,35))+ CONSTANTS(:,119).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,125) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,81).*STATES(:,38))+ CONSTANTS(:,123).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,126) =  CONSTANTS(:,14).*(exp(ALGEBRAIC(:,94)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,125)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,106) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,78).*STATES(:,35))+ CONSTANTS(:,122).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,149) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,79).*STATES(:,36))+ CONSTANTS(:,126).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,150) =  CONSTANTS(:,26).*(exp(ALGEBRAIC(:,106)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,149)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,163) = (( - ALGEBRAIC(:,126)+ALGEBRAIC(:,134)) -  - ALGEBRAIC(:,160)) - ALGEBRAIC(:,150);
    RATES(:,35) = ALGEBRAIC(:,163);
    ALGEBRAIC(:,83) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,73).*STATES(:,30));
    ALGEBRAIC(:,111) = ALGEBRAIC(:,83);
    ALGEBRAIC(:,161) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,79).*STATES(:,36))+ CONSTANTS(:,118).*ALGEBRAIC(:,79);
    ALGEBRAIC(:,164) =  CONSTANTS(:,32).*(exp(ALGEBRAIC(:,111)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,161)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,95) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,73).*STATES(:,30))+ CONSTANTS(:,119).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,127) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,76).*STATES(:,33))+ CONSTANTS(:,123).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,128) =  CONSTANTS(:,12).*(exp(ALGEBRAIC(:,95)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,127)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,166) = (( - ALGEBRAIC(:,128)+ALGEBRAIC(:,140)) - ALGEBRAIC(:,164))+ALGEBRAIC(:,148);
    RATES(:,30) = ALGEBRAIC(:,166);
    ALGEBRAIC(:,96) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,79).*STATES(:,36))+ CONSTANTS(:,119).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,129) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,82).*STATES(:,39))+ CONSTANTS(:,123).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,130) =  CONSTANTS(:,15).*(exp(ALGEBRAIC(:,96)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,129)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,167) = (( - ALGEBRAIC(:,130)+ALGEBRAIC(:,142)) -  - ALGEBRAIC(:,164))+ALGEBRAIC(:,150);
    RATES(:,36) = ALGEBRAIC(:,167);
    ALGEBRAIC(:,84) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,74).*STATES(:,31));
    ALGEBRAIC(:,112) = ALGEBRAIC(:,84);
    ALGEBRAIC(:,165) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,80).*STATES(:,37))+ CONSTANTS(:,118).*ALGEBRAIC(:,79);
    ALGEBRAIC(:,168) =  CONSTANTS(:,29).*(exp(ALGEBRAIC(:,112)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,165)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,99) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,74).*STATES(:,31))+ CONSTANTS(:,120).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,135) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,75).*STATES(:,32))+ CONSTANTS(:,124).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,136) =  CONSTANTS(:,17).*(exp(ALGEBRAIC(:,99)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,135)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,103) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,74).*STATES(:,31))+ CONSTANTS(:,121).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,143) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,76).*STATES(:,33))+ CONSTANTS(:,125).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,144) =  CONSTANTS(:,21).*(exp(ALGEBRAIC(:,103)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,143)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,170) = (( - ALGEBRAIC(:,144)+ALGEBRAIC(:,120)) - ALGEBRAIC(:,136)) - ALGEBRAIC(:,168);
    RATES(:,31) = ALGEBRAIC(:,170);
    ALGEBRAIC(:,100) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,80).*STATES(:,37))+ CONSTANTS(:,120).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,137) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,81).*STATES(:,38))+ CONSTANTS(:,124).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,138) =  CONSTANTS(:,19).*(exp(ALGEBRAIC(:,100)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,137)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,104) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,80).*STATES(:,37))+ CONSTANTS(:,121).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,145) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,82).*STATES(:,39))+ CONSTANTS(:,125).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,146) =  CONSTANTS(:,23).*(exp(ALGEBRAIC(:,104)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,145)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,171) = (( - ALGEBRAIC(:,146)+ALGEBRAIC(:,122)) - ALGEBRAIC(:,138)) -  - ALGEBRAIC(:,168);
    RATES(:,37) = ALGEBRAIC(:,171);
    ALGEBRAIC(:,85) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,75).*STATES(:,32));
    ALGEBRAIC(:,113) = ALGEBRAIC(:,85);
    ALGEBRAIC(:,169) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,81).*STATES(:,38))+ CONSTANTS(:,118).*ALGEBRAIC(:,79);
    ALGEBRAIC(:,172) =  CONSTANTS(:,31).*(exp(ALGEBRAIC(:,113)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,169)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,107) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,75).*STATES(:,32))+ CONSTANTS(:,122).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,151) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,76).*STATES(:,33))+ CONSTANTS(:,126).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,152) =  CONSTANTS(:,25).*(exp(ALGEBRAIC(:,107)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,151)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,174) = ((ALGEBRAIC(:,136)+ALGEBRAIC(:,124)) - ALGEBRAIC(:,172)) - ALGEBRAIC(:,152);
    RATES(:,32) = ALGEBRAIC(:,174);
    ALGEBRAIC(:,87) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,76).*STATES(:,33));
    ALGEBRAIC(:,114) = ALGEBRAIC(:,87);
    ALGEBRAIC(:,173) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,82).*STATES(:,39))+ CONSTANTS(:,118).*ALGEBRAIC(:,79);
    ALGEBRAIC(:,175) =  CONSTANTS(:,33).*(exp(ALGEBRAIC(:,114)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,173)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,177) = ((ALGEBRAIC(:,144)+ALGEBRAIC(:,128)) - ALGEBRAIC(:,175))+ALGEBRAIC(:,152);
    RATES(:,33) = ALGEBRAIC(:,177);
    ALGEBRAIC(:,86) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,81).*STATES(:,38));
    ALGEBRAIC(:,89) = ALGEBRAIC(:,79)+ CONSTANTS(:,148).*CONSTANTS(:,144).*ALGEBRAIC(:,75)+ALGEBRAIC(:,86);
    ALGEBRAIC(:,77) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,70).*STATES(:,12));
    ALGEBRAIC(:,117) = ALGEBRAIC(:,77)+ALGEBRAIC(:,86);
    ALGEBRAIC(:,115) =  CONSTANTS(:,148).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,176) = piecewise({ALGEBRAIC(:,115)==0.00000,  CONSTANTS(:,8).*(exp(ALGEBRAIC(:,89)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,117)./( CONSTANTS(:,142).*CONSTANTS(:,143)))) },  ((( CONSTANTS(:,8).*ALGEBRAIC(:,115))./( CONSTANTS(:,142).*CONSTANTS(:,143)))./(exp(ALGEBRAIC(:,115)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - 1.00000)).*(exp(ALGEBRAIC(:,89)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,117)./( CONSTANTS(:,142).*CONSTANTS(:,143)))));
    ALGEBRAIC(:,108) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,81).*STATES(:,38))+ CONSTANTS(:,122).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,153) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,82).*STATES(:,39))+ CONSTANTS(:,126).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,154) =  CONSTANTS(:,27).*(exp(ALGEBRAIC(:,108)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,153)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,179) = ((ALGEBRAIC(:,138)+ALGEBRAIC(:,126)) - (( - ALGEBRAIC(:,172)+ALGEBRAIC(:,176)) - ALGEBRAIC(:,176))) - ALGEBRAIC(:,154);
    RATES(:,38) = ALGEBRAIC(:,179);
    ALGEBRAIC(:,88) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,82).*STATES(:,39));
    ALGEBRAIC(:,90) = ALGEBRAIC(:,79)+ CONSTANTS(:,148).*CONSTANTS(:,144).*ALGEBRAIC(:,75)+ALGEBRAIC(:,88);
    ALGEBRAIC(:,118) = ALGEBRAIC(:,77)+ALGEBRAIC(:,88);
    ALGEBRAIC(:,116) =  CONSTANTS(:,148).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,178) = piecewise({ALGEBRAIC(:,116)==0.00000,  CONSTANTS(:,9).*(exp(ALGEBRAIC(:,90)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,118)./( CONSTANTS(:,142).*CONSTANTS(:,143)))) },  ((( CONSTANTS(:,9).*ALGEBRAIC(:,116))./( CONSTANTS(:,142).*CONSTANTS(:,143)))./(exp(ALGEBRAIC(:,116)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - 1.00000)).*(exp(ALGEBRAIC(:,90)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,118)./( CONSTANTS(:,142).*CONSTANTS(:,143)))));
    ALGEBRAIC(:,180) = ((ALGEBRAIC(:,146)+ALGEBRAIC(:,130)) - (( - ALGEBRAIC(:,175)+ALGEBRAIC(:,178)) - ALGEBRAIC(:,178)))+ALGEBRAIC(:,154);
    RATES(:,39) = ALGEBRAIC(:,180);
    ALGEBRAIC(:,189) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,83).*STATES(:,40));
    ALGEBRAIC(:,195) = ALGEBRAIC(:,189);
    ALGEBRAIC(:,188) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,89).*STATES(:,6));
    ALGEBRAIC(:,190) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,84).*STATES(:,41));
    ALGEBRAIC(:,201) =  CONSTANTS(:,128).*ALGEBRAIC(:,188)+ALGEBRAIC(:,190);
    ALGEBRAIC(:,202) =  CONSTANTS(:,34).*(exp(ALGEBRAIC(:,195)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,201)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,203) =  CONSTANTS(:,128).*ALGEBRAIC(:,202);
    RATES(:,6) = ALGEBRAIC(:,203);
    ALGEBRAIC(:,186) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,62).*STATES(:,5));
    ALGEBRAIC(:,196) = ALGEBRAIC(:,190)+ALGEBRAIC(:,186);
    ALGEBRAIC(:,191) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,85).*STATES(:,42));
    ALGEBRAIC(:,204) = ALGEBRAIC(:,191);
    ALGEBRAIC(:,205) =  CONSTANTS(:,35).*(exp(ALGEBRAIC(:,196)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,204)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,207) = ALGEBRAIC(:,202) - ALGEBRAIC(:,205);
    RATES(:,41) = ALGEBRAIC(:,207);
    ALGEBRAIC(:,197) = ALGEBRAIC(:,191);
    ALGEBRAIC(:,192) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,86).*STATES(:,43));
    ALGEBRAIC(:,206) = ALGEBRAIC(:,192);
    ALGEBRAIC(:,208) =  CONSTANTS(:,36).*(exp(ALGEBRAIC(:,197)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,206)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,210) = ALGEBRAIC(:,205) - ALGEBRAIC(:,208);
    RATES(:,42) = ALGEBRAIC(:,210);
    ALGEBRAIC(:,198) = ALGEBRAIC(:,192);
    ALGEBRAIC(:,185) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,70).*STATES(:,12));
    ALGEBRAIC(:,193) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,87).*STATES(:,44));
    ALGEBRAIC(:,209) = ALGEBRAIC(:,193)+ALGEBRAIC(:,185);
    ALGEBRAIC(:,211) =  CONSTANTS(:,37).*(exp(ALGEBRAIC(:,198)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,209)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,213) =  - ALGEBRAIC(:,211)+ALGEBRAIC(:,208);
    RATES(:,43) = ALGEBRAIC(:,213);
    ALGEBRAIC(:,187) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,90).*STATES(:,7));
    ALGEBRAIC(:,199) = ALGEBRAIC(:,193)+ CONSTANTS(:,127).*ALGEBRAIC(:,187);
    ALGEBRAIC(:,194) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,88).*STATES(:,45));
    ALGEBRAIC(:,212) = ALGEBRAIC(:,194);
    ALGEBRAIC(:,214) =  CONSTANTS(:,38).*(exp(ALGEBRAIC(:,199)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,212)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,215) =   - CONSTANTS(:,127).*ALGEBRAIC(:,214);
    RATES(:,7) = ALGEBRAIC(:,215);
    ALGEBRAIC(:,216) =  - ALGEBRAIC(:,214)+ALGEBRAIC(:,211);
    RATES(:,44) = ALGEBRAIC(:,216);
    ALGEBRAIC(:,184) = STATES(:,1)./CONSTANTS(:,134);
    ALGEBRAIC(:,200) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,88).*STATES(:,45))+ CONSTANTS(:,129).*CONSTANTS(:,144).*ALGEBRAIC(:,184);
    ALGEBRAIC(:,217) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,83).*STATES(:,40))+ CONSTANTS(:,130).*CONSTANTS(:,144).*ALGEBRAIC(:,184);
    ALGEBRAIC(:,218) =  CONSTANTS(:,39).*(exp(ALGEBRAIC(:,200)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,217)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,219) = ALGEBRAIC(:,218) - ALGEBRAIC(:,202);
    RATES(:,40) = ALGEBRAIC(:,219);
    ALGEBRAIC(:,220) =  - ALGEBRAIC(:,218)+ALGEBRAIC(:,214);
    RATES(:,45) = ALGEBRAIC(:,220);
    ALGEBRAIC(:,182) = ALGEBRAIC(:,178)+ALGEBRAIC(:,176);
    ALGEBRAIC(:,222) = ALGEBRAIC(:,211);
    ALGEBRAIC(:,224) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,62).*STATES(:,5));
    ALGEBRAIC(:,226) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,91).*STATES(:,22));
    ALGEBRAIC(:,227) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,92).*STATES(:,23));
    ALGEBRAIC(:,228) =  CONSTANTS(:,40).*(exp((ALGEBRAIC(:,224)+ALGEBRAIC(:,226))./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,227)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    RATES(:,12) = ALGEBRAIC(:,182)+ALGEBRAIC(:,222)+ALGEBRAIC(:,228);
    ALGEBRAIC(:,225) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,70).*STATES(:,12));
    ALGEBRAIC(:,229) =  CONSTANTS(:,41).*(exp(ALGEBRAIC(:,227)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp((ALGEBRAIC(:,225)+ALGEBRAIC(:,226))./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    RATES(:,22) =  - ALGEBRAIC(:,228)+ALGEBRAIC(:,229);
    RATES(:,23) = ALGEBRAIC(:,228) - ALGEBRAIC(:,229);
    ALGEBRAIC(:,181) =  CONSTANTS(:,144).*((((((((((((((((((( CONSTANTS(:,125).*ALGEBRAIC(:,142) -  CONSTANTS(:,121).*ALGEBRAIC(:,142))+ CONSTANTS(:,126).*ALGEBRAIC(:,150) -  CONSTANTS(:,122).*ALGEBRAIC(:,150))+ CONSTANTS(:,124).*ALGEBRAIC(:,138) -  CONSTANTS(:,120).*ALGEBRAIC(:,138))+ CONSTANTS(:,125).*ALGEBRAIC(:,146) -  CONSTANTS(:,121).*ALGEBRAIC(:,146))+ CONSTANTS(:,126).*ALGEBRAIC(:,154) -  CONSTANTS(:,122).*ALGEBRAIC(:,154))+ CONSTANTS(:,124).*ALGEBRAIC(:,134) -  CONSTANTS(:,120).*ALGEBRAIC(:,134))+ CONSTANTS(:,123).*ALGEBRAIC(:,130) -  CONSTANTS(:,119).*ALGEBRAIC(:,130))+ CONSTANTS(:,123).*ALGEBRAIC(:,126) -  CONSTANTS(:,119).*ALGEBRAIC(:,126))+ CONSTANTS(:,123).*ALGEBRAIC(:,122) -  CONSTANTS(:,119).*ALGEBRAIC(:,122))+ CONSTANTS(:,126).*ALGEBRAIC(:,152) -  CONSTANTS(:,122).*ALGEBRAIC(:,152))+ CONSTANTS(:,125).*ALGEBRAIC(:,144) -  CONSTANTS(:,121).*ALGEBRAIC(:,144))+ CONSTANTS(:,124).*ALGEBRAIC(:,136) -  CONSTANTS(:,120).*ALGEBRAIC(:,136))+ CONSTANTS(:,126).*ALGEBRAIC(:,148) -  CONSTANTS(:,122).*ALGEBRAIC(:,148))+ CONSTANTS(:,125).*ALGEBRAIC(:,140) -  CONSTANTS(:,121).*ALGEBRAIC(:,140))+ CONSTANTS(:,124).*ALGEBRAIC(:,132) -  CONSTANTS(:,120).*ALGEBRAIC(:,132))+ CONSTANTS(:,123).*ALGEBRAIC(:,128) -  CONSTANTS(:,119).*ALGEBRAIC(:,128))+ CONSTANTS(:,123).*ALGEBRAIC(:,124) -  CONSTANTS(:,119).*ALGEBRAIC(:,124))+ CONSTANTS(:,123).*ALGEBRAIC(:,120) -  CONSTANTS(:,119).*ALGEBRAIC(:,120)) - ( CONSTANTS(:,148).*ALGEBRAIC(:,176)+ CONSTANTS(:,148).*ALGEBRAIC(:,178)));
    ALGEBRAIC(:,221) =  CONSTANTS(:,144).*(  - CONSTANTS(:,129).*ALGEBRAIC(:,218)+ CONSTANTS(:,130).*ALGEBRAIC(:,218));
    ALGEBRAIC(:,231) =   - CONSTANTS(:,148).*CONSTANTS(:,144).*ALGEBRAIC(:,229);
    ALGEBRAIC(:,12) = VOI -  floor(VOI./CONSTANTS(:,136)).*CONSTANTS(:,136);
    ALGEBRAIC(:,29) = piecewise({ALGEBRAIC(:,12)>=0.300000&ALGEBRAIC(:,12)<=0.300000+CONSTANTS(:,137), ( 0.00000.*0.0300000.*CONSTANTS(:,134))./CONSTANTS(:,137) }, 0.00000);
    ALGEBRAIC(:,233) = ALGEBRAIC(:,181)+ALGEBRAIC(:,221)+ALGEBRAIC(:,231)+ALGEBRAIC(:,29);
    RATES(:,1) = ALGEBRAIC(:,233);
    ALGEBRAIC(:,232) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,69).*STATES(:,2));
    ALGEBRAIC(:,234) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,101).*STATES(:,46));
    ALGEBRAIC(:,237) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,104).*STATES(:,49));
    ALGEBRAIC(:,239) =  CONSTANTS(:,48).*(exp(ALGEBRAIC(:,237)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp((ALGEBRAIC(:,234)+ CONSTANTS(:,165).*ALGEBRAIC(:,232))./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,235) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,102).*STATES(:,47));
    ALGEBRAIC(:,241) =  CONSTANTS(:,49).*(exp((ALGEBRAIC(:,234)+ CONSTANTS(:,164).*ALGEBRAIC(:,232))./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,235)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    RATES(:,46) = ALGEBRAIC(:,239) - ALGEBRAIC(:,241);
    ALGEBRAIC(:,236) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,103).*STATES(:,48));
    ALGEBRAIC(:,243) =  CONSTANTS(:,50).*(exp((ALGEBRAIC(:,235)+ CONSTANTS(:,165).*ALGEBRAIC(:,232))./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,236)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    RATES(:,47) = ALGEBRAIC(:,241) - ALGEBRAIC(:,243);
    ALGEBRAIC(:,245) =  CONSTANTS(:,51).*(exp(ALGEBRAIC(:,236)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp((ALGEBRAIC(:,237)+ CONSTANTS(:,164).*ALGEBRAIC(:,232))./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    RATES(:,49) = ALGEBRAIC(:,245) - ALGEBRAIC(:,239);
    RATES(:,48) = ALGEBRAIC(:,243) - ALGEBRAIC(:,245);
    ALGEBRAIC(:,69) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,69).*STATES(:,2));
    ALGEBRAIC(:,71) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,62).*STATES(:,5));
    ALGEBRAIC(:,73) =  CONSTANTS(:,7).*(exp(ALGEBRAIC(:,69)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,71)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,183) = (( (CONSTANTS(:,118)).*ALGEBRAIC(:,168)+ CONSTANTS(:,118).*ALGEBRAIC(:,172)+ CONSTANTS(:,118).*ALGEBRAIC(:,164)+ CONSTANTS(:,118).*ALGEBRAIC(:,160)+ CONSTANTS(:,118).*ALGEBRAIC(:,156)+ CONSTANTS(:,118).*ALGEBRAIC(:,175)) - ALGEBRAIC(:,176)) - ALGEBRAIC(:,178);
    ALGEBRAIC(:,230) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,61).*STATES(:,21));
    ALGEBRAIC(:,238) =  CONSTANTS(:,47).*exp(ALGEBRAIC(:,237)./( CONSTANTS(:,142).*CONSTANTS(:,143))).*(exp(ALGEBRAIC(:,230)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,232)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,247) = (( CONSTANTS(:,165).*ALGEBRAIC(:,239) -  CONSTANTS(:,164).*ALGEBRAIC(:,241)) -  CONSTANTS(:,165).*ALGEBRAIC(:,243))+ CONSTANTS(:,164).*ALGEBRAIC(:,245);
    RATES(:,2) =  - ALGEBRAIC(:,73)+ALGEBRAIC(:,183)+ALGEBRAIC(:,238)+ALGEBRAIC(:,247);
    ALGEBRAIC(:,255) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,113).*STATES(:,58));
    ALGEBRAIC(:,260) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,98).*STATES(:,18));
    ALGEBRAIC(:,261) = ALGEBRAIC(:,260) - CONSTANTS(:,174);
    ALGEBRAIC(:,262) = ALGEBRAIC(:,255)+ALGEBRAIC(:,261);
    ALGEBRAIC(:,250) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,105).*STATES(:,50));
    ALGEBRAIC(:,249) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,117).*STATES(:,25));
    ALGEBRAIC(:,263) = ALGEBRAIC(:,250)+ALGEBRAIC(:,249)+ALGEBRAIC(:,261);
    ALGEBRAIC(:,280) =  CONSTANTS(:,60).*(exp(ALGEBRAIC(:,262)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,263)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,282) = ALGEBRAIC(:,280);
    RATES(:,25) = ALGEBRAIC(:,282);
    ALGEBRAIC(:,248) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,115).*STATES(:,27));
    ALGEBRAIC(:,264) = ALGEBRAIC(:,250)+ALGEBRAIC(:,248)+ALGEBRAIC(:,261);
    ALGEBRAIC(:,251) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,106).*STATES(:,51));
    ALGEBRAIC(:,265) = ALGEBRAIC(:,251)+ALGEBRAIC(:,261);
    ALGEBRAIC(:,281) =  CONSTANTS(:,52).*(exp(ALGEBRAIC(:,264)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,265)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,284) =  - ALGEBRAIC(:,281);
    RATES(:,27) = ALGEBRAIC(:,284);
    ALGEBRAIC(:,285) = ALGEBRAIC(:,280) - ALGEBRAIC(:,281);
    RATES(:,50) = ALGEBRAIC(:,285);
    ALGEBRAIC(:,254) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,109).*STATES(:,54));
    ALGEBRAIC(:,266) = ALGEBRAIC(:,254)+ALGEBRAIC(:,261);
    ALGEBRAIC(:,246) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,116).*STATES(:,26));
    ALGEBRAIC(:,256) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,110).*STATES(:,55));
    ALGEBRAIC(:,267) = ALGEBRAIC(:,246)+ALGEBRAIC(:,256)+ALGEBRAIC(:,261);
    ALGEBRAIC(:,283) =  CONSTANTS(:,56).*(exp(ALGEBRAIC(:,266)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,267)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,287) = ALGEBRAIC(:,283);
    RATES(:,26) = ALGEBRAIC(:,287);
    ALGEBRAIC(:,244) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,114).*STATES(:,24));
    ALGEBRAIC(:,268) = ALGEBRAIC(:,251)+ALGEBRAIC(:,244)+ALGEBRAIC(:,261);
    ALGEBRAIC(:,252) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,107).*STATES(:,52));
    ALGEBRAIC(:,269) = ALGEBRAIC(:,252)+ALGEBRAIC(:,261);
    ALGEBRAIC(:,286) =  CONSTANTS(:,54).*(exp(ALGEBRAIC(:,268)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,269)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,289) = ALGEBRAIC(:,286);
    RATES(:,52) = ALGEBRAIC(:,289);
    ALGEBRAIC(:,39) =  ( CONSTANTS(:,142).*CONSTANTS(:,143)).*log( CONSTANTS(:,61).*STATES(:,21));
    ALGEBRAIC(:,49) =  ( CONSTANTS(:,142).*CONSTANTS(:,143)).*log( CONSTANTS(:,62).*STATES(:,5));
    ALGEBRAIC(:,55) =  CONSTANTS(:,1).*(exp(ALGEBRAIC(:,39)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,49)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,223) =  - ALGEBRAIC(:,205);
    ALGEBRAIC(:,240) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,62).*STATES(:,5));
    ALGEBRAIC(:,270) = ALGEBRAIC(:,251)+ CONSTANTS(:,166).*ALGEBRAIC(:,240)+ALGEBRAIC(:,261);
    ALGEBRAIC(:,253) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,108).*STATES(:,53));
    ALGEBRAIC(:,271) = ALGEBRAIC(:,253)+ALGEBRAIC(:,261);
    ALGEBRAIC(:,288) =  CONSTANTS(:,53).*(exp(ALGEBRAIC(:,270)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,271)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,290) =   - CONSTANTS(:,166).*ALGEBRAIC(:,288);
    ALGEBRAIC(:,34) = piecewise({ALGEBRAIC(:,12)>=0.300000&ALGEBRAIC(:,12)<=0.300000+CONSTANTS(:,137),  0.00000.*8000.00 }, 0.00000);
    RATES(:,5) = ((  - ALGEBRAIC(:,67).*CONSTANTS(:,132)+ALGEBRAIC(:,290)+ALGEBRAIC(:,55)+ALGEBRAIC(:,73)+ALGEBRAIC(:,223)) - ALGEBRAIC(:,228))+ALGEBRAIC(:,34);
    ALGEBRAIC(:,292) = ALGEBRAIC(:,281) - ALGEBRAIC(:,288);
    RATES(:,51) = ALGEBRAIC(:,292);
    ALGEBRAIC(:,272) = ALGEBRAIC(:,253)+ALGEBRAIC(:,261);
    ALGEBRAIC(:,273) = ALGEBRAIC(:,254)+ CONSTANTS(:,168).*ALGEBRAIC(:,244)+ALGEBRAIC(:,261);
    ALGEBRAIC(:,291) =  CONSTANTS(:,55).*(exp(ALGEBRAIC(:,272)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,273)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,294) = ALGEBRAIC(:,288) - ALGEBRAIC(:,291);
    RATES(:,53) = ALGEBRAIC(:,294);
    ALGEBRAIC(:,295) = ALGEBRAIC(:,291) - ALGEBRAIC(:,283);
    RATES(:,54) = ALGEBRAIC(:,295);
    ALGEBRAIC(:,274) = ALGEBRAIC(:,256)+ALGEBRAIC(:,261);
    ALGEBRAIC(:,242) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,61).*STATES(:,21));
    ALGEBRAIC(:,258) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,111).*STATES(:,56));
    ALGEBRAIC(:,275) = ALGEBRAIC(:,258)+ CONSTANTS(:,167).*ALGEBRAIC(:,242)+ALGEBRAIC(:,261);
    ALGEBRAIC(:,293) =  CONSTANTS(:,57).*(exp(ALGEBRAIC(:,274)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,275)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,296) =  CONSTANTS(:,167).*ALGEBRAIC(:,293);
    RATES(:,21) = ( - ALGEBRAIC(:,55) - ALGEBRAIC(:,238))+ALGEBRAIC(:,296);
    ALGEBRAIC(:,298) = ALGEBRAIC(:,283) - ALGEBRAIC(:,293);
    RATES(:,55) = ALGEBRAIC(:,298);
    ALGEBRAIC(:,276) = ALGEBRAIC(:,258)+ CONSTANTS(:,168).*ALGEBRAIC(:,244)+ALGEBRAIC(:,261);
    ALGEBRAIC(:,259) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,112).*STATES(:,57));
    ALGEBRAIC(:,277) = ALGEBRAIC(:,259)+ALGEBRAIC(:,261);
    ALGEBRAIC(:,297) =  CONSTANTS(:,58).*(exp(ALGEBRAIC(:,276)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,277)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,300) = ALGEBRAIC(:,293) - ALGEBRAIC(:,297);
    RATES(:,56) = ALGEBRAIC(:,300);
    ALGEBRAIC(:,278) = ALGEBRAIC(:,259)+ALGEBRAIC(:,261);
    ALGEBRAIC(:,279) = ALGEBRAIC(:,244)+ALGEBRAIC(:,255)+ALGEBRAIC(:,261);
    ALGEBRAIC(:,299) =  CONSTANTS(:,59).*(exp(ALGEBRAIC(:,278)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,279)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,301) = (( CONSTANTS(:,168).*ALGEBRAIC(:,291) - ALGEBRAIC(:,286)) -  CONSTANTS(:,168).*ALGEBRAIC(:,297))+ALGEBRAIC(:,299);
    RATES(:,24) = ALGEBRAIC(:,301);
    ALGEBRAIC(:,303) = ALGEBRAIC(:,299) - ALGEBRAIC(:,280);
    RATES(:,58) = ALGEBRAIC(:,303);
    ALGEBRAIC(:,302) = ALGEBRAIC(:,297) - ALGEBRAIC(:,299);
    RATES(:,57) = ALGEBRAIC(:,302);
   RATES = RATES';
end

% Calculate algebraic variables
function ALGEBRAIC = computeAlgebraic(ALGEBRAIC, CONSTANTS, STATES, VOI)
    statesSize = size(STATES);
    statesColumnCount = statesSize(2);
    if ( statesColumnCount == 1)
        STATES = STATES';
        utilOnes = 1;
    else
        statesRowCount = statesSize(1);
        utilOnes = ones(statesRowCount, 1);
    end
    ALGEBRAIC(:,3) = piecewise({VOI<0.0600000,  1.00000.*CONSTANTS(:,138) , VOI>0.500000&VOI<1.10000,   - 0.100000.*CONSTANTS(:,138) },  0.00000.*CONSTANTS(:,138));
    ALGEBRAIC(:,27) = ALGEBRAIC(:,3);
    ALGEBRAIC(:,31) =   - CONSTANTS(:,170).*ALGEBRAIC(:,27);
    ALGEBRAIC(:,36) =  CONSTANTS(:,172).*STATES(:,60);
    ALGEBRAIC(:,42) =  - ALGEBRAIC(:,31) - ALGEBRAIC(:,36);
    ALGEBRAIC(:,52) = ALGEBRAIC(:,42);
    ALGEBRAIC(:,32) =   - CONSTANTS(:,176).*ALGEBRAIC(:,27);
    ALGEBRAIC(:,37) =  CONSTANTS(:,173).*STATES(:,61);
    ALGEBRAIC(:,43) =  - ALGEBRAIC(:,32) - ALGEBRAIC(:,37);
    ALGEBRAIC(:,53) = ALGEBRAIC(:,43);
    ALGEBRAIC(:,35) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,96).*STATES(:,16));
    ALGEBRAIC(:,41) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,99).*STATES(:,19));
    ALGEBRAIC(:,51) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,100).*STATES(:,20));
    ALGEBRAIC(:,57) =  CONSTANTS(:,46).*(exp((ALGEBRAIC(:,35)+ALGEBRAIC(:,41))./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,51)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,1) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,93).*STATES(:,13));
    ALGEBRAIC(:,26) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,94).*STATES(:,14));
    ALGEBRAIC(:,30) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,95).*STATES(:,15));
    ALGEBRAIC(:,56) =  CONSTANTS(:,42).*(exp((ALGEBRAIC(:,1)+ALGEBRAIC(:,26))./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,30)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,50) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,98).*STATES(:,18));
    ALGEBRAIC(:,61) =  CONSTANTS(:,43).*(exp(ALGEBRAIC(:,30)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp((ALGEBRAIC(:,50)+ALGEBRAIC(:,26))./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,40) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,97).*STATES(:,17));
    ALGEBRAIC(:,63) =  CONSTANTS(:,44).*(exp((ALGEBRAIC(:,50)+ALGEBRAIC(:,35))./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,40)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,59) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,63).*STATES(:,3));
    ALGEBRAIC(:,62) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,62).*STATES(:,5));
    ALGEBRAIC(:,64) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,64).*STATES(:,4));
    ALGEBRAIC(:,67) =  CONSTANTS(:,2).*(exp(( CONSTANTS(:,132).*ALGEBRAIC(:,62)+ALGEBRAIC(:,59))./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,64)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,66) =  CONSTANTS(:,45).*(exp(ALGEBRAIC(:,40)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp((ALGEBRAIC(:,1)+ALGEBRAIC(:,35))./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,65) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,65).*STATES(:,8));
    ALGEBRAIC(:,68) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,66).*STATES(:,9));
    ALGEBRAIC(:,74) =  CONSTANTS(:,3).*(exp((ALGEBRAIC(:,65)+ CONSTANTS(:,131).*ALGEBRAIC(:,64))./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp((ALGEBRAIC(:,68)+ CONSTANTS(:,131).*ALGEBRAIC(:,64))./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,70) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,67).*STATES(:,10));
    ALGEBRAIC(:,76) =  CONSTANTS(:,4).*(exp(ALGEBRAIC(:,68)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,70)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,72) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,68).*STATES(:,11));
    ALGEBRAIC(:,78) =  CONSTANTS(:,5).*(exp(ALGEBRAIC(:,70)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,72)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,80) =  CONSTANTS(:,6).*(exp(ALGEBRAIC(:,72)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,68)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,81) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,71).*STATES(:,28));
    ALGEBRAIC(:,109) = ALGEBRAIC(:,81);
    ALGEBRAIC(:,79) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,69).*STATES(:,2));
    ALGEBRAIC(:,155) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,77).*STATES(:,34))+ CONSTANTS(:,118).*ALGEBRAIC(:,79);
    ALGEBRAIC(:,156) =  CONSTANTS(:,28).*(exp(ALGEBRAIC(:,109)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,155)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,75) = STATES(:,1)./CONSTANTS(:,134);
    ALGEBRAIC(:,91) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,71).*STATES(:,28))+ CONSTANTS(:,119).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,119) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,74).*STATES(:,31))+ CONSTANTS(:,123).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,120) =  CONSTANTS(:,10).*(exp(ALGEBRAIC(:,91)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,119)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,97) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,71).*STATES(:,28))+ CONSTANTS(:,120).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,131) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,72).*STATES(:,29))+ CONSTANTS(:,124).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,132) =  CONSTANTS(:,16).*(exp(ALGEBRAIC(:,97)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,131)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,101) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,71).*STATES(:,28))+ CONSTANTS(:,121).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,139) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,73).*STATES(:,30))+ CONSTANTS(:,125).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,140) =  CONSTANTS(:,20).*(exp(ALGEBRAIC(:,101)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,139)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,158) = (( - ALGEBRAIC(:,120) - ALGEBRAIC(:,132)) - ALGEBRAIC(:,140)) - ALGEBRAIC(:,156);
    ALGEBRAIC(:,92) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,77).*STATES(:,34))+ CONSTANTS(:,119).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,121) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,80).*STATES(:,37))+ CONSTANTS(:,123).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,122) =  CONSTANTS(:,13).*(exp(ALGEBRAIC(:,92)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,121)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,98) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,77).*STATES(:,34))+ CONSTANTS(:,120).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,133) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,78).*STATES(:,35))+ CONSTANTS(:,124).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,134) =  CONSTANTS(:,18).*(exp(ALGEBRAIC(:,98)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,133)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,102) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,77).*STATES(:,34))+ CONSTANTS(:,121).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,141) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,79).*STATES(:,36))+ CONSTANTS(:,125).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,142) =  CONSTANTS(:,22).*(exp(ALGEBRAIC(:,102)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,141)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,159) = (( - ALGEBRAIC(:,122) - ALGEBRAIC(:,134)) - ALGEBRAIC(:,142)) -  - ALGEBRAIC(:,156);
    ALGEBRAIC(:,82) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,72).*STATES(:,29));
    ALGEBRAIC(:,110) = ALGEBRAIC(:,82);
    ALGEBRAIC(:,157) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,78).*STATES(:,35))+ CONSTANTS(:,118).*ALGEBRAIC(:,79);
    ALGEBRAIC(:,160) =  CONSTANTS(:,30).*(exp(ALGEBRAIC(:,110)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,157)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,93) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,72).*STATES(:,29))+ CONSTANTS(:,119).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,123) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,75).*STATES(:,32))+ CONSTANTS(:,123).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,124) =  CONSTANTS(:,11).*(exp(ALGEBRAIC(:,93)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,123)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,105) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,72).*STATES(:,29))+ CONSTANTS(:,122).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,147) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,73).*STATES(:,30))+ CONSTANTS(:,126).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,148) =  CONSTANTS(:,24).*(exp(ALGEBRAIC(:,105)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,147)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,162) = (( - ALGEBRAIC(:,124)+ALGEBRAIC(:,132)) - ALGEBRAIC(:,160)) - ALGEBRAIC(:,148);
    ALGEBRAIC(:,94) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,78).*STATES(:,35))+ CONSTANTS(:,119).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,125) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,81).*STATES(:,38))+ CONSTANTS(:,123).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,126) =  CONSTANTS(:,14).*(exp(ALGEBRAIC(:,94)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,125)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,106) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,78).*STATES(:,35))+ CONSTANTS(:,122).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,149) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,79).*STATES(:,36))+ CONSTANTS(:,126).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,150) =  CONSTANTS(:,26).*(exp(ALGEBRAIC(:,106)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,149)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,163) = (( - ALGEBRAIC(:,126)+ALGEBRAIC(:,134)) -  - ALGEBRAIC(:,160)) - ALGEBRAIC(:,150);
    ALGEBRAIC(:,83) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,73).*STATES(:,30));
    ALGEBRAIC(:,111) = ALGEBRAIC(:,83);
    ALGEBRAIC(:,161) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,79).*STATES(:,36))+ CONSTANTS(:,118).*ALGEBRAIC(:,79);
    ALGEBRAIC(:,164) =  CONSTANTS(:,32).*(exp(ALGEBRAIC(:,111)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,161)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,95) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,73).*STATES(:,30))+ CONSTANTS(:,119).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,127) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,76).*STATES(:,33))+ CONSTANTS(:,123).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,128) =  CONSTANTS(:,12).*(exp(ALGEBRAIC(:,95)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,127)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,166) = (( - ALGEBRAIC(:,128)+ALGEBRAIC(:,140)) - ALGEBRAIC(:,164))+ALGEBRAIC(:,148);
    ALGEBRAIC(:,96) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,79).*STATES(:,36))+ CONSTANTS(:,119).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,129) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,82).*STATES(:,39))+ CONSTANTS(:,123).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,130) =  CONSTANTS(:,15).*(exp(ALGEBRAIC(:,96)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,129)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,167) = (( - ALGEBRAIC(:,130)+ALGEBRAIC(:,142)) -  - ALGEBRAIC(:,164))+ALGEBRAIC(:,150);
    ALGEBRAIC(:,84) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,74).*STATES(:,31));
    ALGEBRAIC(:,112) = ALGEBRAIC(:,84);
    ALGEBRAIC(:,165) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,80).*STATES(:,37))+ CONSTANTS(:,118).*ALGEBRAIC(:,79);
    ALGEBRAIC(:,168) =  CONSTANTS(:,29).*(exp(ALGEBRAIC(:,112)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,165)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,99) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,74).*STATES(:,31))+ CONSTANTS(:,120).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,135) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,75).*STATES(:,32))+ CONSTANTS(:,124).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,136) =  CONSTANTS(:,17).*(exp(ALGEBRAIC(:,99)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,135)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,103) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,74).*STATES(:,31))+ CONSTANTS(:,121).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,143) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,76).*STATES(:,33))+ CONSTANTS(:,125).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,144) =  CONSTANTS(:,21).*(exp(ALGEBRAIC(:,103)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,143)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,170) = (( - ALGEBRAIC(:,144)+ALGEBRAIC(:,120)) - ALGEBRAIC(:,136)) - ALGEBRAIC(:,168);
    ALGEBRAIC(:,100) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,80).*STATES(:,37))+ CONSTANTS(:,120).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,137) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,81).*STATES(:,38))+ CONSTANTS(:,124).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,138) =  CONSTANTS(:,19).*(exp(ALGEBRAIC(:,100)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,137)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,104) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,80).*STATES(:,37))+ CONSTANTS(:,121).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,145) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,82).*STATES(:,39))+ CONSTANTS(:,125).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,146) =  CONSTANTS(:,23).*(exp(ALGEBRAIC(:,104)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,145)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,171) = (( - ALGEBRAIC(:,146)+ALGEBRAIC(:,122)) - ALGEBRAIC(:,138)) -  - ALGEBRAIC(:,168);
    ALGEBRAIC(:,85) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,75).*STATES(:,32));
    ALGEBRAIC(:,113) = ALGEBRAIC(:,85);
    ALGEBRAIC(:,169) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,81).*STATES(:,38))+ CONSTANTS(:,118).*ALGEBRAIC(:,79);
    ALGEBRAIC(:,172) =  CONSTANTS(:,31).*(exp(ALGEBRAIC(:,113)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,169)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,107) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,75).*STATES(:,32))+ CONSTANTS(:,122).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,151) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,76).*STATES(:,33))+ CONSTANTS(:,126).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,152) =  CONSTANTS(:,25).*(exp(ALGEBRAIC(:,107)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,151)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,174) = ((ALGEBRAIC(:,136)+ALGEBRAIC(:,124)) - ALGEBRAIC(:,172)) - ALGEBRAIC(:,152);
    ALGEBRAIC(:,87) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,76).*STATES(:,33));
    ALGEBRAIC(:,114) = ALGEBRAIC(:,87);
    ALGEBRAIC(:,173) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,82).*STATES(:,39))+ CONSTANTS(:,118).*ALGEBRAIC(:,79);
    ALGEBRAIC(:,175) =  CONSTANTS(:,33).*(exp(ALGEBRAIC(:,114)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,173)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,177) = ((ALGEBRAIC(:,144)+ALGEBRAIC(:,128)) - ALGEBRAIC(:,175))+ALGEBRAIC(:,152);
    ALGEBRAIC(:,86) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,81).*STATES(:,38));
    ALGEBRAIC(:,89) = ALGEBRAIC(:,79)+ CONSTANTS(:,148).*CONSTANTS(:,144).*ALGEBRAIC(:,75)+ALGEBRAIC(:,86);
    ALGEBRAIC(:,77) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,70).*STATES(:,12));
    ALGEBRAIC(:,117) = ALGEBRAIC(:,77)+ALGEBRAIC(:,86);
    ALGEBRAIC(:,115) =  CONSTANTS(:,148).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,176) = piecewise({ALGEBRAIC(:,115)==0.00000,  CONSTANTS(:,8).*(exp(ALGEBRAIC(:,89)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,117)./( CONSTANTS(:,142).*CONSTANTS(:,143)))) },  ((( CONSTANTS(:,8).*ALGEBRAIC(:,115))./( CONSTANTS(:,142).*CONSTANTS(:,143)))./(exp(ALGEBRAIC(:,115)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - 1.00000)).*(exp(ALGEBRAIC(:,89)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,117)./( CONSTANTS(:,142).*CONSTANTS(:,143)))));
    ALGEBRAIC(:,108) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,81).*STATES(:,38))+ CONSTANTS(:,122).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,153) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,82).*STATES(:,39))+ CONSTANTS(:,126).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,154) =  CONSTANTS(:,27).*(exp(ALGEBRAIC(:,108)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,153)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,179) = ((ALGEBRAIC(:,138)+ALGEBRAIC(:,126)) - (( - ALGEBRAIC(:,172)+ALGEBRAIC(:,176)) - ALGEBRAIC(:,176))) - ALGEBRAIC(:,154);
    ALGEBRAIC(:,88) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,82).*STATES(:,39));
    ALGEBRAIC(:,90) = ALGEBRAIC(:,79)+ CONSTANTS(:,148).*CONSTANTS(:,144).*ALGEBRAIC(:,75)+ALGEBRAIC(:,88);
    ALGEBRAIC(:,118) = ALGEBRAIC(:,77)+ALGEBRAIC(:,88);
    ALGEBRAIC(:,116) =  CONSTANTS(:,148).*CONSTANTS(:,144).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,178) = piecewise({ALGEBRAIC(:,116)==0.00000,  CONSTANTS(:,9).*(exp(ALGEBRAIC(:,90)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,118)./( CONSTANTS(:,142).*CONSTANTS(:,143)))) },  ((( CONSTANTS(:,9).*ALGEBRAIC(:,116))./( CONSTANTS(:,142).*CONSTANTS(:,143)))./(exp(ALGEBRAIC(:,116)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - 1.00000)).*(exp(ALGEBRAIC(:,90)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,118)./( CONSTANTS(:,142).*CONSTANTS(:,143)))));
    ALGEBRAIC(:,180) = ((ALGEBRAIC(:,146)+ALGEBRAIC(:,130)) - (( - ALGEBRAIC(:,175)+ALGEBRAIC(:,178)) - ALGEBRAIC(:,178)))+ALGEBRAIC(:,154);
    ALGEBRAIC(:,189) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,83).*STATES(:,40));
    ALGEBRAIC(:,195) = ALGEBRAIC(:,189);
    ALGEBRAIC(:,188) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,89).*STATES(:,6));
    ALGEBRAIC(:,190) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,84).*STATES(:,41));
    ALGEBRAIC(:,201) =  CONSTANTS(:,128).*ALGEBRAIC(:,188)+ALGEBRAIC(:,190);
    ALGEBRAIC(:,202) =  CONSTANTS(:,34).*(exp(ALGEBRAIC(:,195)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,201)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,203) =  CONSTANTS(:,128).*ALGEBRAIC(:,202);
    ALGEBRAIC(:,186) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,62).*STATES(:,5));
    ALGEBRAIC(:,196) = ALGEBRAIC(:,190)+ALGEBRAIC(:,186);
    ALGEBRAIC(:,191) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,85).*STATES(:,42));
    ALGEBRAIC(:,204) = ALGEBRAIC(:,191);
    ALGEBRAIC(:,205) =  CONSTANTS(:,35).*(exp(ALGEBRAIC(:,196)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,204)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,207) = ALGEBRAIC(:,202) - ALGEBRAIC(:,205);
    ALGEBRAIC(:,197) = ALGEBRAIC(:,191);
    ALGEBRAIC(:,192) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,86).*STATES(:,43));
    ALGEBRAIC(:,206) = ALGEBRAIC(:,192);
    ALGEBRAIC(:,208) =  CONSTANTS(:,36).*(exp(ALGEBRAIC(:,197)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,206)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,210) = ALGEBRAIC(:,205) - ALGEBRAIC(:,208);
    ALGEBRAIC(:,198) = ALGEBRAIC(:,192);
    ALGEBRAIC(:,185) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,70).*STATES(:,12));
    ALGEBRAIC(:,193) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,87).*STATES(:,44));
    ALGEBRAIC(:,209) = ALGEBRAIC(:,193)+ALGEBRAIC(:,185);
    ALGEBRAIC(:,211) =  CONSTANTS(:,37).*(exp(ALGEBRAIC(:,198)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,209)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,213) =  - ALGEBRAIC(:,211)+ALGEBRAIC(:,208);
    ALGEBRAIC(:,187) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,90).*STATES(:,7));
    ALGEBRAIC(:,199) = ALGEBRAIC(:,193)+ CONSTANTS(:,127).*ALGEBRAIC(:,187);
    ALGEBRAIC(:,194) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,88).*STATES(:,45));
    ALGEBRAIC(:,212) = ALGEBRAIC(:,194);
    ALGEBRAIC(:,214) =  CONSTANTS(:,38).*(exp(ALGEBRAIC(:,199)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,212)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,215) =   - CONSTANTS(:,127).*ALGEBRAIC(:,214);
    ALGEBRAIC(:,216) =  - ALGEBRAIC(:,214)+ALGEBRAIC(:,211);
    ALGEBRAIC(:,184) = STATES(:,1)./CONSTANTS(:,134);
    ALGEBRAIC(:,200) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,88).*STATES(:,45))+ CONSTANTS(:,129).*CONSTANTS(:,144).*ALGEBRAIC(:,184);
    ALGEBRAIC(:,217) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,83).*STATES(:,40))+ CONSTANTS(:,130).*CONSTANTS(:,144).*ALGEBRAIC(:,184);
    ALGEBRAIC(:,218) =  CONSTANTS(:,39).*(exp(ALGEBRAIC(:,200)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,217)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,219) = ALGEBRAIC(:,218) - ALGEBRAIC(:,202);
    ALGEBRAIC(:,220) =  - ALGEBRAIC(:,218)+ALGEBRAIC(:,214);
    ALGEBRAIC(:,182) = ALGEBRAIC(:,178)+ALGEBRAIC(:,176);
    ALGEBRAIC(:,222) = ALGEBRAIC(:,211);
    ALGEBRAIC(:,224) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,62).*STATES(:,5));
    ALGEBRAIC(:,226) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,91).*STATES(:,22));
    ALGEBRAIC(:,227) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,92).*STATES(:,23));
    ALGEBRAIC(:,228) =  CONSTANTS(:,40).*(exp((ALGEBRAIC(:,224)+ALGEBRAIC(:,226))./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,227)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,225) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,70).*STATES(:,12));
    ALGEBRAIC(:,229) =  CONSTANTS(:,41).*(exp(ALGEBRAIC(:,227)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp((ALGEBRAIC(:,225)+ALGEBRAIC(:,226))./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,181) =  CONSTANTS(:,144).*((((((((((((((((((( CONSTANTS(:,125).*ALGEBRAIC(:,142) -  CONSTANTS(:,121).*ALGEBRAIC(:,142))+ CONSTANTS(:,126).*ALGEBRAIC(:,150) -  CONSTANTS(:,122).*ALGEBRAIC(:,150))+ CONSTANTS(:,124).*ALGEBRAIC(:,138) -  CONSTANTS(:,120).*ALGEBRAIC(:,138))+ CONSTANTS(:,125).*ALGEBRAIC(:,146) -  CONSTANTS(:,121).*ALGEBRAIC(:,146))+ CONSTANTS(:,126).*ALGEBRAIC(:,154) -  CONSTANTS(:,122).*ALGEBRAIC(:,154))+ CONSTANTS(:,124).*ALGEBRAIC(:,134) -  CONSTANTS(:,120).*ALGEBRAIC(:,134))+ CONSTANTS(:,123).*ALGEBRAIC(:,130) -  CONSTANTS(:,119).*ALGEBRAIC(:,130))+ CONSTANTS(:,123).*ALGEBRAIC(:,126) -  CONSTANTS(:,119).*ALGEBRAIC(:,126))+ CONSTANTS(:,123).*ALGEBRAIC(:,122) -  CONSTANTS(:,119).*ALGEBRAIC(:,122))+ CONSTANTS(:,126).*ALGEBRAIC(:,152) -  CONSTANTS(:,122).*ALGEBRAIC(:,152))+ CONSTANTS(:,125).*ALGEBRAIC(:,144) -  CONSTANTS(:,121).*ALGEBRAIC(:,144))+ CONSTANTS(:,124).*ALGEBRAIC(:,136) -  CONSTANTS(:,120).*ALGEBRAIC(:,136))+ CONSTANTS(:,126).*ALGEBRAIC(:,148) -  CONSTANTS(:,122).*ALGEBRAIC(:,148))+ CONSTANTS(:,125).*ALGEBRAIC(:,140) -  CONSTANTS(:,121).*ALGEBRAIC(:,140))+ CONSTANTS(:,124).*ALGEBRAIC(:,132) -  CONSTANTS(:,120).*ALGEBRAIC(:,132))+ CONSTANTS(:,123).*ALGEBRAIC(:,128) -  CONSTANTS(:,119).*ALGEBRAIC(:,128))+ CONSTANTS(:,123).*ALGEBRAIC(:,124) -  CONSTANTS(:,119).*ALGEBRAIC(:,124))+ CONSTANTS(:,123).*ALGEBRAIC(:,120) -  CONSTANTS(:,119).*ALGEBRAIC(:,120)) - ( CONSTANTS(:,148).*ALGEBRAIC(:,176)+ CONSTANTS(:,148).*ALGEBRAIC(:,178)));
    ALGEBRAIC(:,221) =  CONSTANTS(:,144).*(  - CONSTANTS(:,129).*ALGEBRAIC(:,218)+ CONSTANTS(:,130).*ALGEBRAIC(:,218));
    ALGEBRAIC(:,231) =   - CONSTANTS(:,148).*CONSTANTS(:,144).*ALGEBRAIC(:,229);
    ALGEBRAIC(:,12) = VOI -  floor(VOI./CONSTANTS(:,136)).*CONSTANTS(:,136);
    ALGEBRAIC(:,29) = piecewise({ALGEBRAIC(:,12)>=0.300000&ALGEBRAIC(:,12)<=0.300000+CONSTANTS(:,137), ( 0.00000.*0.0300000.*CONSTANTS(:,134))./CONSTANTS(:,137) }, 0.00000);
    ALGEBRAIC(:,233) = ALGEBRAIC(:,181)+ALGEBRAIC(:,221)+ALGEBRAIC(:,231)+ALGEBRAIC(:,29);
    ALGEBRAIC(:,232) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,69).*STATES(:,2));
    ALGEBRAIC(:,234) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,101).*STATES(:,46));
    ALGEBRAIC(:,237) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,104).*STATES(:,49));
    ALGEBRAIC(:,239) =  CONSTANTS(:,48).*(exp(ALGEBRAIC(:,237)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp((ALGEBRAIC(:,234)+ CONSTANTS(:,165).*ALGEBRAIC(:,232))./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,235) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,102).*STATES(:,47));
    ALGEBRAIC(:,241) =  CONSTANTS(:,49).*(exp((ALGEBRAIC(:,234)+ CONSTANTS(:,164).*ALGEBRAIC(:,232))./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,235)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,236) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,103).*STATES(:,48));
    ALGEBRAIC(:,243) =  CONSTANTS(:,50).*(exp((ALGEBRAIC(:,235)+ CONSTANTS(:,165).*ALGEBRAIC(:,232))./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,236)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,245) =  CONSTANTS(:,51).*(exp(ALGEBRAIC(:,236)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp((ALGEBRAIC(:,237)+ CONSTANTS(:,164).*ALGEBRAIC(:,232))./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,69) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,69).*STATES(:,2));
    ALGEBRAIC(:,71) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,62).*STATES(:,5));
    ALGEBRAIC(:,73) =  CONSTANTS(:,7).*(exp(ALGEBRAIC(:,69)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,71)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,183) = (( (CONSTANTS(:,118)).*ALGEBRAIC(:,168)+ CONSTANTS(:,118).*ALGEBRAIC(:,172)+ CONSTANTS(:,118).*ALGEBRAIC(:,164)+ CONSTANTS(:,118).*ALGEBRAIC(:,160)+ CONSTANTS(:,118).*ALGEBRAIC(:,156)+ CONSTANTS(:,118).*ALGEBRAIC(:,175)) - ALGEBRAIC(:,176)) - ALGEBRAIC(:,178);
    ALGEBRAIC(:,230) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,61).*STATES(:,21));
    ALGEBRAIC(:,238) =  CONSTANTS(:,47).*exp(ALGEBRAIC(:,237)./( CONSTANTS(:,142).*CONSTANTS(:,143))).*(exp(ALGEBRAIC(:,230)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,232)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,247) = (( CONSTANTS(:,165).*ALGEBRAIC(:,239) -  CONSTANTS(:,164).*ALGEBRAIC(:,241)) -  CONSTANTS(:,165).*ALGEBRAIC(:,243))+ CONSTANTS(:,164).*ALGEBRAIC(:,245);
    ALGEBRAIC(:,255) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,113).*STATES(:,58));
    ALGEBRAIC(:,260) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,98).*STATES(:,18));
    ALGEBRAIC(:,261) = ALGEBRAIC(:,260) - CONSTANTS(:,174);
    ALGEBRAIC(:,262) = ALGEBRAIC(:,255)+ALGEBRAIC(:,261);
    ALGEBRAIC(:,250) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,105).*STATES(:,50));
    ALGEBRAIC(:,249) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,117).*STATES(:,25));
    ALGEBRAIC(:,263) = ALGEBRAIC(:,250)+ALGEBRAIC(:,249)+ALGEBRAIC(:,261);
    ALGEBRAIC(:,280) =  CONSTANTS(:,60).*(exp(ALGEBRAIC(:,262)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,263)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,282) = ALGEBRAIC(:,280);
    ALGEBRAIC(:,248) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,115).*STATES(:,27));
    ALGEBRAIC(:,264) = ALGEBRAIC(:,250)+ALGEBRAIC(:,248)+ALGEBRAIC(:,261);
    ALGEBRAIC(:,251) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,106).*STATES(:,51));
    ALGEBRAIC(:,265) = ALGEBRAIC(:,251)+ALGEBRAIC(:,261);
    ALGEBRAIC(:,281) =  CONSTANTS(:,52).*(exp(ALGEBRAIC(:,264)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,265)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,284) =  - ALGEBRAIC(:,281);
    ALGEBRAIC(:,285) = ALGEBRAIC(:,280) - ALGEBRAIC(:,281);
    ALGEBRAIC(:,254) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,109).*STATES(:,54));
    ALGEBRAIC(:,266) = ALGEBRAIC(:,254)+ALGEBRAIC(:,261);
    ALGEBRAIC(:,246) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,116).*STATES(:,26));
    ALGEBRAIC(:,256) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,110).*STATES(:,55));
    ALGEBRAIC(:,267) = ALGEBRAIC(:,246)+ALGEBRAIC(:,256)+ALGEBRAIC(:,261);
    ALGEBRAIC(:,283) =  CONSTANTS(:,56).*(exp(ALGEBRAIC(:,266)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,267)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,287) = ALGEBRAIC(:,283);
    ALGEBRAIC(:,244) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,114).*STATES(:,24));
    ALGEBRAIC(:,268) = ALGEBRAIC(:,251)+ALGEBRAIC(:,244)+ALGEBRAIC(:,261);
    ALGEBRAIC(:,252) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,107).*STATES(:,52));
    ALGEBRAIC(:,269) = ALGEBRAIC(:,252)+ALGEBRAIC(:,261);
    ALGEBRAIC(:,286) =  CONSTANTS(:,54).*(exp(ALGEBRAIC(:,268)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,269)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,289) = ALGEBRAIC(:,286);
    ALGEBRAIC(:,39) =  ( CONSTANTS(:,142).*CONSTANTS(:,143)).*log( CONSTANTS(:,61).*STATES(:,21));
    ALGEBRAIC(:,49) =  ( CONSTANTS(:,142).*CONSTANTS(:,143)).*log( CONSTANTS(:,62).*STATES(:,5));
    ALGEBRAIC(:,55) =  CONSTANTS(:,1).*(exp(ALGEBRAIC(:,39)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,49)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,223) =  - ALGEBRAIC(:,205);
    ALGEBRAIC(:,240) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,62).*STATES(:,5));
    ALGEBRAIC(:,270) = ALGEBRAIC(:,251)+ CONSTANTS(:,166).*ALGEBRAIC(:,240)+ALGEBRAIC(:,261);
    ALGEBRAIC(:,253) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,108).*STATES(:,53));
    ALGEBRAIC(:,271) = ALGEBRAIC(:,253)+ALGEBRAIC(:,261);
    ALGEBRAIC(:,288) =  CONSTANTS(:,53).*(exp(ALGEBRAIC(:,270)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,271)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,290) =   - CONSTANTS(:,166).*ALGEBRAIC(:,288);
    ALGEBRAIC(:,34) = piecewise({ALGEBRAIC(:,12)>=0.300000&ALGEBRAIC(:,12)<=0.300000+CONSTANTS(:,137),  0.00000.*8000.00 }, 0.00000);
    ALGEBRAIC(:,292) = ALGEBRAIC(:,281) - ALGEBRAIC(:,288);
    ALGEBRAIC(:,272) = ALGEBRAIC(:,253)+ALGEBRAIC(:,261);
    ALGEBRAIC(:,273) = ALGEBRAIC(:,254)+ CONSTANTS(:,168).*ALGEBRAIC(:,244)+ALGEBRAIC(:,261);
    ALGEBRAIC(:,291) =  CONSTANTS(:,55).*(exp(ALGEBRAIC(:,272)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,273)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,294) = ALGEBRAIC(:,288) - ALGEBRAIC(:,291);
    ALGEBRAIC(:,295) = ALGEBRAIC(:,291) - ALGEBRAIC(:,283);
    ALGEBRAIC(:,274) = ALGEBRAIC(:,256)+ALGEBRAIC(:,261);
    ALGEBRAIC(:,242) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,61).*STATES(:,21));
    ALGEBRAIC(:,258) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,111).*STATES(:,56));
    ALGEBRAIC(:,275) = ALGEBRAIC(:,258)+ CONSTANTS(:,167).*ALGEBRAIC(:,242)+ALGEBRAIC(:,261);
    ALGEBRAIC(:,293) =  CONSTANTS(:,57).*(exp(ALGEBRAIC(:,274)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,275)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,296) =  CONSTANTS(:,167).*ALGEBRAIC(:,293);
    ALGEBRAIC(:,298) = ALGEBRAIC(:,283) - ALGEBRAIC(:,293);
    ALGEBRAIC(:,276) = ALGEBRAIC(:,258)+ CONSTANTS(:,168).*ALGEBRAIC(:,244)+ALGEBRAIC(:,261);
    ALGEBRAIC(:,259) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,112).*STATES(:,57));
    ALGEBRAIC(:,277) = ALGEBRAIC(:,259)+ALGEBRAIC(:,261);
    ALGEBRAIC(:,297) =  CONSTANTS(:,58).*(exp(ALGEBRAIC(:,276)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,277)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,300) = ALGEBRAIC(:,293) - ALGEBRAIC(:,297);
    ALGEBRAIC(:,278) = ALGEBRAIC(:,259)+ALGEBRAIC(:,261);
    ALGEBRAIC(:,279) = ALGEBRAIC(:,244)+ALGEBRAIC(:,255)+ALGEBRAIC(:,261);
    ALGEBRAIC(:,299) =  CONSTANTS(:,59).*(exp(ALGEBRAIC(:,278)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp(ALGEBRAIC(:,279)./( CONSTANTS(:,142).*CONSTANTS(:,143))));
    ALGEBRAIC(:,301) = (( CONSTANTS(:,168).*ALGEBRAIC(:,291) - ALGEBRAIC(:,286)) -  CONSTANTS(:,168).*ALGEBRAIC(:,297))+ALGEBRAIC(:,299);
    ALGEBRAIC(:,303) = ALGEBRAIC(:,299) - ALGEBRAIC(:,280);
    ALGEBRAIC(:,302) = ALGEBRAIC(:,297) - ALGEBRAIC(:,299);
    ALGEBRAIC(:,2) = STATES(:,1)./CONSTANTS(:,134);
    ALGEBRAIC(:,4) = STATES(:,5)./CONSTANTS(:,133);
    ALGEBRAIC(:,5) = STATES(:,12)./CONSTANTS(:,140);
    ALGEBRAIC(:,6) = STATES(:,21)./CONSTANTS(:,171);
    ALGEBRAIC(:,7) = STATES(:,2)./CONSTANTS(:,141);
    ALGEBRAIC(:,8) = STATES(:,6)./CONSTANTS(:,133);
    ALGEBRAIC(:,9) =  - arbitrary_log(STATES(:,24)./CONSTANTS(:,133), 10);
    ALGEBRAIC(:,10) = STATES(:,5)+STATES(:,12)+STATES(:,4)+STATES(:,21)+STATES(:,2)+STATES(:,23)+ 2.00000.*(STATES(:,53)+STATES(:,54)+STATES(:,55))+STATES(:,42)+STATES(:,43);
    ALGEBRAIC(:,11) =  (CONSTANTS(:,158)./( CONSTANTS(:,149).*CONSTANTS(:,150).*CONSTANTS(:,151))).*STATES(:,11).*(STATES(:,61)+CONSTANTS(:,149));
    ALGEBRAIC(:,13) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,77).*STATES(:,34));
    ALGEBRAIC(:,14) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,78).*STATES(:,35));
    ALGEBRAIC(:,15) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,79).*STATES(:,36));
    ALGEBRAIC(:,16) =  CONSTANTS(:,142).*CONSTANTS(:,143).*log( CONSTANTS(:,80).*STATES(:,37));
    ALGEBRAIC(:,17) = STATES(:,12)+STATES(:,2)+STATES(:,34)+STATES(:,35)+STATES(:,36)+STATES(:,37)+STATES(:,38)+STATES(:,39);
    ALGEBRAIC(:,18) =  CONSTANTS(:,165).*STATES(:,49)+ CONSTANTS(:,164).*STATES(:,47)+ (CONSTANTS(:,164)+CONSTANTS(:,165)).*STATES(:,48);
    ALGEBRAIC(:,19) =  CONSTANTS(:,166).*STATES(:,53)+ CONSTANTS(:,166).*STATES(:,54)+ CONSTANTS(:,167).*STATES(:,55);
    ALGEBRAIC(:,20) = STATES(:,5)./CONSTANTS(:,169);
    ALGEBRAIC(:,21) = STATES(:,21)./CONSTANTS(:,175);
    ALGEBRAIC(:,22) = STATES(:,24)./CONSTANTS(:,177);
    ALGEBRAIC(:,23) = STATES(:,26)./CONSTANTS(:,169);
    ALGEBRAIC(:,24) = STATES(:,27)./CONSTANTS(:,169);
    ALGEBRAIC(:,25) = STATES(:,25)./CONSTANTS(:,169);
    ALGEBRAIC(:,28) =  (CONSTANTS(:,158)./( CONSTANTS(:,149).*CONSTANTS(:,150).*CONSTANTS(:,151))).*STATES(:,10).*STATES(:,60);
    ALGEBRAIC(:,33) = ALGEBRAIC(:,11)+ALGEBRAIC(:,28);
    ALGEBRAIC(:,38) =  CONSTANTS(:,162).*(exp(( CONSTANTS(:,163).*STATES(:,59))./CONSTANTS(:,149)) - 1.00000);
    ALGEBRAIC(:,54) =  (( CONSTANTS(:,162).*ALGEBRAIC(:,44))./CONSTANTS(:,149)).*ALGEBRAIC(:,45);
    ALGEBRAIC(:,58) = ALGEBRAIC(:,38)+ALGEBRAIC(:,54);
    ALGEBRAIC(:,60) = ALGEBRAIC(:,33)+ALGEBRAIC(:,58);
    ALGEBRAIC(:,257) =  CONSTANTS(:,60).*(exp(ALGEBRAIC(:,255)./( CONSTANTS(:,142).*CONSTANTS(:,143))) - exp((ALGEBRAIC(:,250)+ALGEBRAIC(:,249))./( CONSTANTS(:,142).*CONSTANTS(:,143))));
end

% Functions required for solving differential algebraic equation
function [CONSTANTS, STATES, ALGEBRAIC] = rootfind_0(VOI, CONSTANTS_IN, STATES_IN, ALGEBRAIC_IN)
    ALGEBRAIC = ALGEBRAIC_IN;
    CONSTANTS = CONSTANTS_IN;
    STATES = STATES_IN;
    global initialGuess_0;
    if (length(initialGuess_0) ~= 5), initialGuess_0 = [0.1,0.1,0.1,0.1,0.1];, end
    options = optimset('Display', 'off', 'TolX', 1E-6);
    if length(VOI) == 1
        residualfn = @(algebraicCandidate)residualSN_0(algebraicCandidate, ALGEBRAIC, VOI, CONSTANTS, STATES);
        soln = fsolve(residualfn, initialGuess_0, options);
        initialGuess_0 = soln;
        ALGEBRAIC(:,44) = soln(1);
        ALGEBRAIC(:,45) = soln(2);
        ALGEBRAIC(:,46) = soln(3);
        ALGEBRAIC(:,47) = soln(4);
        ALGEBRAIC(:,48) = soln(5);
    else
        SET_ALGEBRAIC(:,44) = logical(1);
        SET_ALGEBRAIC(:,45) = logical(1);
        SET_ALGEBRAIC(:,46) = logical(1);
        SET_ALGEBRAIC(:,47) = logical(1);
        SET_ALGEBRAIC(:,48) = logical(1);
        for i=1:length(VOI)
            residualfn = @(algebraicCandidate)residualSN_0(algebraicCandidate, ALGEBRAIC(i,:), VOI(i), CONSTANTS, STATES(i,:));
            soln = fsolve(residualfn, initialGuess_0, options);
            initialGuess_0 = soln;
            TEMP_ALGEBRAIC(:,44) = soln(1);
            TEMP_ALGEBRAIC(:,45) = soln(2);
            TEMP_ALGEBRAIC(:,46) = soln(3);
            TEMP_ALGEBRAIC(:,47) = soln(4);
            TEMP_ALGEBRAIC(:,48) = soln(5);
            ALGEBRAIC(i,SET_ALGEBRAIC) = TEMP_ALGEBRAIC(SET_ALGEBRAIC);
        end
    end
end

function resid = residualSN_0(algebraicCandidate, ALGEBRAIC, VOI, CONSTANTS, STATES)
    ALGEBRAIC(:,44) = algebraicCandidate(1);
    ALGEBRAIC(:,45) = algebraicCandidate(2);
    ALGEBRAIC(:,46) = algebraicCandidate(3);
    ALGEBRAIC(:,47) = algebraicCandidate(4);
    ALGEBRAIC(:,48) = algebraicCandidate(5);
    resid(1) = ALGEBRAIC(:,44) - piecewise({ALGEBRAIC(:,45)>0.00000, CONSTANTS(:,159) }, CONSTANTS(:,160));
    resid(2) = ALGEBRAIC(:,45) - ALGEBRAIC(:,46);
    resid(3) = ALGEBRAIC(:,47) -  (CONSTANTS(:,161)./ALGEBRAIC(:,44)).*STATES(:,62);
    resid(4) = ALGEBRAIC(:,48) -  (CONSTANTS(:,161)./ALGEBRAIC(:,44)).*(STATES(:,59) - CONSTANTS(:,149));
    resid(5) = ALGEBRAIC(:,46) - ( - ALGEBRAIC(:,47)+ALGEBRAIC(:,48));
end

% Compute result of a piecewise function
function x = piecewise(cases, default)
    set = [0];
    for i = 1:2:length(cases)
        if (length(cases{i+1}) == 1)
            x(cases{i} & ~set,:) = cases{i+1};
        else
            x(cases{i} & ~set,:) = cases{i+1}(cases{i} & ~set);
        end
        set = set | cases{i};
        if(set), break, end
    end
    if (length(default) == 1)
        x(~set,:) = default;
    else
        x(~set,:) = default(~set);
    end
end

% Compute a logarithm to any base" +
function x = arbitrary_log(a, base)
    x = log(a) ./ log(base);
end

% Pad out or shorten strings to a set length
function strout = strpad(strin)
    req_length = 160;
    insize = size(strin,2);
    if insize > req_length
        strout = strin(1:req_length);
    else
        strout = [strin, blanks(req_length - insize)];
    end
end

