#### APPENDIX B: *A*–*C*_{I} CURVE FITTING ROUTINE FOR USE WITH ‘R’

## This script is a method for fitting a photosynthesis model to response curves of the dependency of assimilation rates over CO_{2} concentrations at the mesophyll.

## The method considers discontinuous nonlinear functions and solves for parameters by minimization of least-squares differences between the data and the model.

## The output parameters (*V*_{cmax}, *J*_{max} (assuming saturating light), TPU, and *R*_{d}) are computed for temperatures measured during the response curve.

## The error term takes into account the number of observations

## Photo = Net photosynthetic carbon assimilation | (*µ*mol CO_{2} m^{−2} s^{−1}) | Dependent Variable |

## Ci = [CO_{2}] inside the leaf | (*µ*mol mol^{−1}) (same as ppm or *µ*bar) | Independent Variable |

## *V*_{cmax} = maximum carboxylation capacity | (*µ*mol CO_{2} m^{−2} s^{−1}) | Parameter |

## *J*_{max} = electron transport rate | (*µ*mol CO_{2} m^{−2} s^{−1}) | Parameter |

## TPU = triose phosphate utilization | (*µ*mol CO_{2} m^{−2} s^{−1}) | Parameter |

## *R*_{d} = respiration under light | (*µ*mol CO_{2} m^{−2} s^{−1}) | Parameter |

## Tleaf = leaf temperature | (°C) | Independent Variable |

## Start from a "clean" R environment

## Load relevant libraries

## Import data from a text file, skipping 12 initial information lines from a Licor 6400 standard output file. This value might change according to individual machine's setup.

response.curve <- read.table(filename <- choose.files(), skip = 12, header = TRUE)

# the following prints the names of the variables from the data set, useful to check if file was loaded correctly

## Photosynthesis model based on:

## Farquhar G.D., von Caemmerer S. & Berry J.A. (1980) A biochemical model of photosynthetic CO_{2} assimilation in leaves of C_{3} species. *Planta***149**, 78–90

## Sharkey T.D., Bernacchi C.J., Farquhar G.D. & Singsaas E.L. (2007) Fitting photosynthetic carbon dioxide response curves for C_{3} leaves. *Plant, Cell & Environment***30**, 1035–1040

O2 | <- 21 | # Estimated Oxygen concentration at mesophyll - (kPa) |

Kc | <- 40.49 | # Michaelis-Menten constant for CO_{2} (Pa) - von Caemmerer *et al.* (1994) |

delta_Kc | <- 59356 | # activation energy (kJ mol^{−1}) - Badger & Collatz (1977) |

# Kc adjusted to actual leaf temperature - (Pa)

Kc_Tleaf | <- Kc * exp((Tleaf+273.15-298.15)*delta_Kc/(298.15*8.314*(Tleaf+273.15))) |

Ko | <- 24.8 | # Michaelis-Menten constant for CO_{2} (kPa)- von Caemmerer *et al.* (1994) |

delta_Ko | <- 35948 | # activation energy (kJ mol^{−1}) - Badger & Collatz (1977) |

# Ko adjusted to actual leaf temperature - (kPa)

Ko_Tleaf | <- Ko * exp((Tleaf+273.15-298.15)*delta_Ko/(298.15*8.314*(Tleaf+273.15))) |

gstar | <- 3.69 | # CO_{2} compensation point (Pa)- von Caemmerer *et al.* (1994) |

delta_gstar | <- 29000 | # activation energy (kJ mol^{−1}) - Jordan & Ogren (1984) |

# gstar adjusted to actual leaf temperature - (Pa)

gstar_Tleaf | <- gstar * exp((Tleaf+273.15-298.15)*delta_gstar/(298.15*8.314*(Tleaf+273.15))) |

Km | <- Kc_Tleaf*(1+O2/Ko_Tleaf) |

# converts Ci from ppm to Pa

## Function that contains the model equations and the variables

*V*_{cmax} | <- x[1] | # variable 1 |

*J*_{max} | <- x[2] | # variable 2 |

TPU | <- x[3] | # variable 3 |

*R*_{d} | <- x[4] | # variable 4 |

# electron transport rate fitted to high C values

aj <- ifelse (C >= 45, *J*_{max}* (C - gstar_Tleaf) / (4*C + 8 * gstar_Tleaf)-*R*_{d}, 999)

# ignore intermediary C values (region of co-limitation)

aa <- ifelse ((C > 30 & C < 45), Photo,999)

# carboxylation rate fitted to low C values

av <- ifelse (C <= 30, *V*_{cmax}* (C - gstar_Tleaf) / (Km + C)- *R*_{d}, 999)

# triose phosphate utilization fitted to the last point of the curve

atpu <- ifelse (C == max(C),3 * TPU - *R*_{d}, Photo)

a <- pmin(av,aj,aa) | |

adiff <- sum((Photo - a)^2) | # least-square minimization |

bdiff <- sum((Photo - atpu)^2) | |

diffsum <- adiff + bdiff | # object to be minimized |

} | |

## curve fitting procedure, using the "optim" command. It will vary the variables to get the smallest "diffsum" possible

## initial values (first guess) for the starting point of "optim"

start.values1 <- c(100,130,10,3)

first <- optim(start.values1,ffitt,control = list (maxit =9000), method = "BFGS")

## calculating the error for the curve fitting

fit.error<-first$value[1]/(length(Photo)-sum(C>30 & C<45))

## creates a sequence of CO_{2} values for the figures

# creates values of av based on estimated parameters (*V*_{cmax} and *R*_{d})

av1 <- first$par[1]* (Cseq - mean(gstar_Tleaf))/(mean(Km) + Cseq ) - first$par[4]

# creates values of af based on estimated parameters (*J*_{max} and *R*_{d})

aj1 <- first$par[2]* (Cseq - mean(gstar_Tleaf))/(4*Cseq + 8*mean(gstar_Tleaf)) - first$par[4]

# creates values of atpu based on estimated parameters (TPU and *R*_{d})

atpu1 <- first$par[3]* 3 - first$par[4]+ (Cseq /10^10)

## creating a figure showing the relationship between Photo and [CO2] at the mesophyll

plot (C,Photo,col ="blue",pch=19,xlim=c(0,200), ylim=c(-5,60), ylab="A (*µ*mol CO_{2} m^{−2} s^{−1})", xlab="[CO_{2}] at mesophyll-Ci (Pa)")

title(main = c(filename),cex.main=0.8)

lines (Cseq, av1, col = "red", lwd = "2")

lines (Cseq, aj1, col = "orange", lwd = "2")

lines (Cseq, atpu1, col = "purple", lwd = "2")

text (50,60,"Vcmax =",pos=2,col = "red");text (45,60,round(first$par[1],digits=1),pos=4,col = "red")

text (50,55,"Jmax =",pos=2,col = "orange");text (45,55,round(first$par[2],digits=1),pos=4,col = "orange")

text (50,50,"TPU =",pos=2,col = "purple");text (45,50,round(first$par[3],digits=1),pos=4,col = "purple")

text (160,0,"Rd =",pos=2);text (170,0,round(first$par[4],digits=2),pos=4)

text (160,−5,"error =",pos=2);text (170,−5,round(fit.error,digits=2),pos=4)