(* Hugo J. de Boer 22-7-2015

Supplementary Information with the manuscript

Optimal allocation of leaf epidermal area for gas exchange
H.J.de Boer,C.A.Price,F.Wagner-Cremer,S.C.Dekker,P.J.Franks,E.J.Veneklaas
*)

Clear["Global`*"]
Needs["PlotLegends`"]
Needs["ErrorBarPlots`"]

(* Calculation of the anatomical maximum stomatal conductance gsmax (Eq. 1)*)
gsmax =(((dh2o/wv) Ds amax)/(pd+(π/2)(Sqrt[(amax/π)])));

(* Calculation of fractional cover of the epidermis by stomata (Eq. 2) *)
fgc= Ds Agc ;

(* Allometric relation between stomatal size and density (Eq. 3)*)
Agc = bs * (Ds^S) ;

(*Marginal change in fractional stomatal cover (Eq. 12)*)
df = D[fgc,Ds]

(*Calculation of pore depth based in guard cell width*)
pd =Wgc;
Wgc = (Sqrt[Agc ratAgcWgc (2/π)]);

(* Allometric relation between pore size and stomatal size (Eq. 4)*)

amax = bp* (Agc^P);

(*Marginal change in maximal stomatal conductance (Eq. 10)*)
dg = FullSimplify[D[gsmax,Ds]]

(*Marginal ratio Lambda (Eq. 13)*)
dgdf = dg/df;

FullSimplify[dgdf]

T = 25+273.15; (*temperature*)
dco2 = (((T/273.15))^1.8)*1.33*(10^(-5)); (*Diffusion coefficient co2*)
dh2o=1.6*dco2; (*Diffusion coefficient h2o*)
d = dh2o;
wv=0.024466; (*molar volume of air, m^3/mol*)
v = wv;

ratAgcWgc = 0.36;
bs = 5.24;
bp = 0.048;
P = 0.9288;
S = -1.23;
Plot[gsmax,{Ds,1*10^6,2500*10^6}];
ParametricPlot[{gsmax,fs*100},{Ds,1*10^6,2500*10^6},AspectRatio->1];
Clear[P,S]

(*Plot the three region of the response in sign of Lambda with opaque areas indicating unrealistic values*)
Ds = 247*10^6; (*All species, average value*)
bs = 0.101;
bp = 0.048;
p1=RegionPlot[dgdf>0 ,{S,-2,-0.4},{P,0.75,1.5},PlotStyle->{Opacity[0.5],Red},MaxRecursion->5,PlotRange->{{-2,-0.4},{0.75,1.5}}];
p4=RegionPlot[df>0 ,{S,-2,-0.4},{P,0.75,1.5},PlotStyle->{Opacity[0.5],Green},MaxRecursion->5,PlotRange->{{-2,-0.4},{0.75,1.5}}];
p5=RegionPlot[Agc<amax ,{S,-2,-0.4},{P,0.75,1.5},PlotStyle->{Opacity[0.5],Black},MaxRecursion->5,PlotRange->{{-2,-0.4},{0.75,1.5}}];
p6=RegionPlot[fgc>1 ,{S,-2,-0.4},{P,0.75,1.5},PlotStyle->{Opacity[0.5],Black},MaxRecursion->5,PlotRange->{{-2,-0.4},{0.75,1.5}}];
Show[List[p1,p4,p5,p6]]

(*Show the relation between gsmax and fs in the three region with contasting sign in Lambda*)
(*Region 1*)
bs = 0.2;
S = -1.05;
bp = 0.05;
P = 1;
minDs = 1*10^6;
maxDs=50000*10^6;
p1=ParametricPlot[{gsmax,fgc*100},{Ds,minDs,maxDs},AspectRatio->1,PlotStyle->{Blue,Thick},PlotRange->{{0,4},{5,15}}];

(*Region 2*)
bs = 0.03;
S = -0.95;
bp = 0.05;
P = 1;
minDs = 1*10^6;
maxDs=50000*10^6;
p2=ParametricPlot[{gsmax,fgc*100},{Ds,minDs,maxDs},AspectRatio->1,PlotStyle->{Thick,Red},PlotRange->{{0,4},{0,20}}];

(*Region 3*)
bs = 10000;
S = -1.5;
bp = 1000;
P = 1.4;
minDs = 1000*10^6;
maxDs=10000000*10^6;
p3=ParametricPlot[{gsmax,fgc*100},{Ds,minDs,maxDs},AspectRatio->1,PlotStyle->{Thick,Yellow},PlotRange->{{0,4},{0,16}},AxesOrigin->{0,0}];
Show[List[p3,p2,p1]]