% Author: Elsa W. Birch, ewbirch@stanford.edu, Covert Lab - Stanford Bioengineering
% Date: 4/24/2011
% Version: associated with production of the figures for Birch et al. 2012 
%
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
%
% Summary: Allocate media resources to organisms based on their proportion biomass total
% 
% Inputs: simulation sructure
%
% Outputs: vector of media effectively percived by each organism
%
%
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
%
% Notes: > This function is entirely unnescary for only one organism (host level) in media
%
%
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function [ allocatedMedia ] = FBA_EB_mediaAllocateSimpleProportion(simulation)

biomassEachOrg = zeros(1,simulation.nOrganism);

% test if simulation has run or if need to reference initial state (occurs durring
% intalizeation)
if simulation.iSim > 1
    
    % there is a previous timestep to reference biomass at
    for iOrgBiomass = 1 : simulation.nOrganism

        biomassEachOrg(iOrgBiomass) = ...
            simulation.(simulation.organismList{iOrgBiomass}).simulation.biomass(simulation.iSim - 1);

    end % for iOrgBiomass
    
else
    
    % reference biomass at initial
    for iOrgBiomass = 1 : simulation.nOrganism

        biomassEachOrg(iOrgBiomass) = ...
            simulation.(simulation.organismList{iOrgBiomass}).simulation.initialBiomass;

    end % for iOrgBiomass
    
end % if simulation.iSim > 1

mediaAvalible = simulation.media(:,simulation.iSim - 1);
totalBiomass = sum(biomassEachOrg);
% 
allocatedMedia = mediaAvalible * biomassEachOrg / totalBiomass;