BioCro  0.92
 All Data Structures Files Functions Variables Typedefs Macros
c3photo.c File Reference
#include <R.h>
#include <math.h>
#include <Rmath.h>
#include <Rinternals.h>
#include "c3photo.h"
+ Include dependency graph for c3photo.c:

Go to the source code of this file.

Functions

SEXP c3photo (SEXP Qp1, SEXP Tl1, SEXP RH1, SEXP VCMAX, SEXP JMAX, SEXP RD, SEXP CA, SEXP B0, SEXP B1, SEXP OX2, SEXP THETA, SEXP STOMWS, SEXP WS)
 
double solc (double LeafT)
 
double solo (double LeafT)
 
struct c3_str c3photoC (double Qp, double Tleaf, double RH, double Vcmax0, double Jmax, double Rd0, double bb0, double bb1, double Ca, double O2, double thet, double StomWS, int ws)
 

Function Documentation

SEXP c3photo ( SEXP  Qp1,
SEXP  Tl1,
SEXP  RH1,
SEXP  VCMAX,
SEXP  JMAX,
SEXP  RD,
SEXP  CA,
SEXP  B0,
SEXP  B1,
SEXP  OX2,
SEXP  THETA,
SEXP  STOMWS,
SEXP  WS 
)
14 {
15  struct c3_str tmp = {0,0,0,0};
16 
17  double Qp, Tl, RH, Catm;
18  double Bet0,Bet1;
19 
20  double vcmax, jmax, Rd, Ca, O2, theta,StomWS;
21 
22  vcmax = REAL(VCMAX)[0];
23  jmax = REAL(JMAX)[0];
24  Bet0 = REAL(B0)[0];
25  Bet1 = REAL(B1)[0];
26  Rd = REAL(RD)[0];
27  O2 = REAL(OX2)[0];
28  theta = REAL(THETA)[0];
29  StomWS = REAL(STOMWS)[0];
30  int nq , nt, nr, i;
31  int ws = INTEGER(WS)[0];
32  SEXP lists, names;
33  SEXP GsV;
34  SEXP ASSV;
35  SEXP CiV;
36 
37  nq = length(Qp1);nt = length(Tl1);nr = length(RH1);
38 
39  PROTECT(lists = allocVector(VECSXP,3));
40  PROTECT(names = allocVector(STRSXP,3));
41 
42  PROTECT(GsV = allocVector(REALSXP,nq));
43  PROTECT(ASSV = allocVector(REALSXP,nq));
44  PROTECT(CiV = allocVector(REALSXP,nq));
45 
46  Ca = REAL(CA)[0]; /* partial pressure of CO2 at the leaf surface */
47 
48  /* Start of the loop */
49  for(i = 0; i < nq ; i++)
50  {
51  /*pick the right element*/
52  Qp = REAL(Qp1)[i];
53  Tl = REAL(Tl1)[i];
54  RH = REAL(RH1)[i];
55  Catm = REAL(CA)[i];
56 
57  tmp = c3photoC(Qp, Tl, RH, vcmax, jmax, Rd, Bet0, Bet1, Catm, O2, theta,StomWS,ws);
58 
59  REAL(GsV)[i] = tmp.Gs;
60  REAL(ASSV)[i] = tmp.Assim;
61  REAL(CiV)[i] = tmp.Ci;
62  }
63 
64  SET_VECTOR_ELT(lists,0,GsV);
65  SET_VECTOR_ELT(lists,1,ASSV);
66  SET_VECTOR_ELT(lists,2,CiV);
67  SET_STRING_ELT(names,0,mkChar("Gs"));
68  SET_STRING_ELT(names,1,mkChar("Assim"));
69  SET_STRING_ELT(names,2,mkChar("Ci"));
70  setAttrib(lists,R_NamesSymbol,names);
71  UNPROTECT(5);
72  return(lists);
73 }
struct c3_str c3photoC(double Qp, double Tleaf, double RH, double Vcmax0, double Jmax, double Rd0, double bb0, double bb1, double Ca, double O2, double thet, double StomWS, int ws)
Definition: c3photo.c:119
double Assim
Definition: c3photo.h:10
double Gs
Definition: c3photo.h:11
Definition: c3photo.h:8
double Ci
Definition: c3photo.h:12
struct c3_str c3photoC ( double  Qp,
double  Tleaf,
double  RH,
double  Vcmax0,
double  Jmax,
double  Rd0,
double  bb0,
double  bb1,
double  Ca,
double  O2,
double  thet,
double  StomWS,
int  ws 
)
double solc ( double  LeafT)
90  {
91 
92  double tmp;
93 
94  if(LeafT > 24 && LeafT < 26){
95  tmp = 1;
96  }else{
97  tmp = (1.673998 - 0.0612936 * LeafT + 0.00116875 * pow(LeafT,2) - 8.874081e-06 * pow(LeafT,3)) / 0.735465;
98  }
99 
100  return(tmp);
101 }
double solo ( double  LeafT)
103  {
104 
105  double tmp;
106 
107  if(LeafT > 24 && LeafT < 26){
108  tmp = 1;
109  }else{
110  tmp = (0.047 - 0.0013087 * LeafT + 2.5603e-05 * pow(LeafT,2) - 2.1441e-07 * pow(LeafT,3)) / 0.026934;
111  }
112 
113  return(tmp);
114 }