55 int retcode, sql3ret, i, emergpath_idx;
62 char querybuff[1024], subquery[255], param_name[255];
65 if (!access(fname, F_OK)) {
79 timep = localtime(&now);
80 gdrs->
thisyear = timep->tm_year + 1900;
83 sprintf(querybuff,
"SELECT COUNT(iso3) FROM country;");;
94 sprintf(querybuff,
"SELECT MIN(year) AS min_year, MAX(year) AS max_year FROM core;");
105 sprintf(querybuff,
"SELECT iso3 FROM country ORDER BY iso3;");
117 sprintf(querybuff,
"SELECT param_id, int_val FROM params WHERE int_val IS NOT NULL ORDER BY param_id;");
124 if (!strcmp(param_name,
"a1_ref_year")) {
126 }
else if (!strcmp(param_name,
"assign_mit_gap_to")) {
128 }
else if (!strcmp(param_name,
"cumsince")) {
130 }
else if (!strcmp(param_name,
"do_luxcap")) {
132 }
else if (!strcmp(param_name,
"emerg_path_id")) {
134 }
else if (!strcmp(param_name,
"emergstart")) {
136 }
else if (!strcmp(param_name,
"interp_between_thresholds")) {
138 }
else if (!strcmp(param_name,
"kab_only_ratified")) {
140 }
else if (!strcmp(param_name,
"use_lag")) {
142 }
else if (!strcmp(param_name,
"sequenceyear")) {
144 }
else if (!strcmp(param_name,
"use_kab")) {
146 }
else if (!strcmp(param_name,
"use_lulucf")) {
148 }
else if (!strcmp(param_name,
"use_netexports")) {
150 }
else if (!strcmp(param_name,
"use_nonco2")) {
152 }
else if (!strcmp(param_name,
"usesequence")) {
160 sprintf(querybuff,
"SELECT param_id, real_val FROM params WHERE real_val IS NOT NULL ORDER BY param_id;");
169 if (!strcmp(param_name,
"a1_perc_rdxn")) {
171 }
else if (!strcmp(param_name,
"a1_shape_param")) {
173 }
else if (!strcmp(param_name,
"billpercgwp_adapt")) {
175 }
else if (!strcmp(param_name,
"billpercgwp_mit")) {
177 }
else if (!strcmp(param_name,
"dev_thresh")) {
179 }
else if (!strcmp(param_name,
"emisselast")) {
181 }
else if (!strcmp(param_name,
"lux_thresh")) {
183 }
else if (!strcmp(param_name,
"lux_thresh_mult")) {
185 }
else if (!strcmp(param_name,
"respweight")) {
196 sprintf(querybuff,
"SELECT MIN(year) AS min_year, MAX(year) AS max_year FROM pathways WHERE emergpath_GtC IS NOT NULL;");
207 switch (emergpath_idx) {
209 sprintf(subquery,
"source = 'fossil'");
213 sprintf(subquery,
"source = 'fossil' OR source ='lulucf'");
217 sprintf(subquery,
"source = 'fossil' OR source ='nonco2'");
221 sprintf(subquery,
"source = 'fossil' OR source ='lulucf' OR source ='nonco2'");
225 "SELECT year, 1000 * SUM(emergpath_GtC) as emergpath_MtC FROM pathways, pathway_names WHERE pathway_names.pathway_id = %d AND pathway_names.name_short = pathways.pathway AND (%s) GROUP BY year ORDER BY year;",
247 sprintf(querybuff,
"SELECT iso3, value FROM flags WHERE flag=\"annex_1\" ORDER BY iso3;");
259 sprintf(querybuff,
"SELECT iso3, value FROM flags WHERE flag=\"annex_2\" ORDER BY iso3;");
272 sprintf(querybuff,
"SELECT country.iso3, commitment_percent FROM country LEFT OUTER JOIN kyoto_info ON country.iso3 = kyoto_info.iso3 ORDER BY country.iso3;");
284 sprintf(querybuff,
"SELECT country.iso3, ratified FROM country LEFT OUTER JOIN kyoto_info ON country.iso3 = kyoto_info.iso3 ORDER BY country.iso3;");
301 if ((retcode =
readtable(db,
"pop_person", &gdrs->
pop, gdrs->
ad))) {
314 if ((retcode =
readtable(db,
"gdp_blnUSDMER", &gdrs->
gdp, gdrs->
ad))) {
446 sprintf(querybuff,
"SELECT seq_no, ppp, value, quintile, global FROM tax_levels;");
522 if ((retcode =
allocdata(&gdrs->
r, gdrs->
ad)))
return retcode;
523 if ((retcode =
allocdata(&gdrs->
c, gdrs->
ad)))
return retcode;
578 int i, year, sql3ret, err;
580 char querybuff[1024];
583 sprintf(querybuff,
"SELECT MIN(year) AS min_year, MAX(year) AS max_year FROM core WHERE %s IS NOT NULL;", column);
599 sprintf(querybuff,
"SELECT iso3, year, %s FROM core WHERE %s IS NOT NULL ORDER BY iso3, year;", column, column);
604 for (i = 0; i < ad.
numrecs; i++) {
605 for (year = table->
y_start; year <= table->y_end; year++) {
608 setval(*table, val, i, year, ad);
689 double ybar, P, sigma,
z;
690 double cum, deriv, cumP;
696 }
else if (isinf(y) == 1) {
707 if (ppp_or_mer ==
XR_MER) {
714 deriv += P *
dnorm(
z)/(sigma * y);
722 if (dist_deriv) *dist_deriv = deriv;
740 double y, qcalc, qderiv;
745 for (niter = 0; niter <
MAXITER; niter++) {
746 qcalc =
globaldist(y, year, gdrs, ppp_or_mer, &qderiv);
749 y += (q - qcalc)/qderiv;
770 return ybar * exp(sigma * (
qnorm(q) - 0.5 * sigma));
785 gap->
data[i] = newgap;
788 gap->
data[i] += newgap;
791 if (newgap > gap->
data[i]) gap->
data[i] = newgap;
794 if (newgap < gap->data[i]) gap->
data[i] = newgap;
814 double bau_at_start_ep, bau_now, tot_bau, ep;
815 double kyoto_startep_frac,
filter;
816 double totgap_temp, newgap, ep_gap;
851 newgap =
filter * bau_at_start_ep * (1.0 - kyoto_startep_frac);
852 if (newgap < 0.0) newgap = 0.0;
853 newgaps.
data[i] = newgap;
854 totgap_temp += newgap;
859 ep_gap = tot_bau > ep ? tot_bau - ep : 0.0;
861 if (totgap_temp > ep_gap) {
862 newgap = fabs(totgap_temp) >
EPSILON ? newgaps.
data[i] * ep_gap/totgap_temp : 0.0;
864 newgap = newgaps.
data[i];
894 double lux_emiss, ybar, yu, yu_adj, yu_ppp, f1;
895 double blval, gamma, sigma, zu,
filter, newgap;
915 f1 = pow(yu_ppp/ybar, gamma) * exp(-0.5 * gamma * (gamma - 1) * sigma * sigma);
916 lux_emiss = blval * (1 -
pnorm(zu - gamma * sigma) - f1 * (1 -
pnorm(zu)));
924 f1 *= pow(yu_adj/yu, gamma);
931 newgap =
filter * blval * (1 -
pnorm(zu - gamma * sigma) - f1 * (1 -
pnorm(zu)));
936 *totgap += gap->
data[i];
950 double bltot, globalrdxn, alloc, rci;
951 int lag_start, lag_ndx;
957 double a1, a2, a1rci, a2rci, a1natlrdxn;
958 double tfrac, a1rdxn;
959 double blref, blval, f;
984 for (year = gdrs->
ad.
minyear; year <= gdrs->ad.maxyear; year++) {
988 if (gdrs->
use_lag && year > lag_start) {
989 lag_ndx = year - lag_start;
996 if (gdrs->
use_lag && lag_ndx > 0) {
1004 if (year < gdrs->emergstart) {
1007 if (gdrs->
usesequence && year <= gdrs->sequenceyear) {
1015 a1rci = a2rci = a1rdxn = 0.0;
1019 for (i = 0; i < gdrs->
ad.
numrecs; i++) {
1046 for (i = 0; i < gdrs->
ad.
numrecs; i++) {
1053 for (i = 0; i < gdrs->
ad.
numrecs; i++) {
1067 a1natlrdxn = (rci/a1rci) * a1rdxn;
1068 alloc = blval - gap.
data[i] - a1natlrdxn;
1071 alloc -= (rci/a1rci) * (globalrdxn - a1rdxn);
1073 alloc -= a2 * (rci/a2rci) * (globalrdxn - a1rdxn);
1085 alloc = blval - gap.
data[i] - globalrdxn * rci;
1108 int i, j, yprev, do_interp, ppp_or_mer;
1109 double sigma, gamma, popdens, z_tax, zl, zu, yl, yu, yu_ppp, ybar, E, P, A;
1110 double c, r, rci, rci_indiv, ppp2mer, pi, tax_mer;
1111 double csum, rsum, rprev;
1112 double gwp, tot_tax, ytax, ytax_ppp;
1131 csum = rsum = gwp = 0.0;
1132 for (i = 0; i < gdrs->
ad.
numrecs; i++) {
1140 gwp += P * pi * ybar;
1150 if (year <= gdrs->cumsince) {
1155 A =
rhat(E, gamma, sigma, ybar);
1159 r_ann.
data[i] =
respbetween(gamma, -INFINITY, INFINITY, zl, zl, yl, yl, ybar, sigma, A);
1162 r_ann.
data[i] =
respbetween(gamma, -INFINITY, INFINITY, zl, zu, yl, yu_ppp, ybar, sigma, A);
1165 if (year <= gdrs->cumsince) {
1168 rprev =
getval(gdrs->
r, i, yprev, gdrs->
ad);
1170 r = r_ann.
data[i] + rprev;
1197 for (i = 0; i < gdrs->
ad.
numrecs; i++) {
1209 if (year <= gdrs->cumsince) {
1214 A =
rhat(E, gamma, sigma, ybar);
1224 ytax = pi * ytax_ppp;
1229 rci_indiv = (1 - gdrs->
respweight) * P *
c_indiv(ytax, pi * yl, yu, do_interp)/csum;
1230 rci_indiv += gdrs->
respweight * (r/rsum) *
r_indiv(gamma, ytax_ppp, yl, yu/pi, A, do_interp)/r_ann.
data[i];
1232 if (isnan(rci_indiv)) {
1242 z_tax =
ztransf(ytax_ppp, ybar, sigma);
1243 popdens = P *
dnorm(z_tax)/(sigma * ytax_ppp);
1244 tax_mer = rci_indiv * tot_tax * popdens;
1270 double M(
double a,
double zc,
double ybar,
double sigma) {
1271 double fact1, fact2, fact3;
1273 fact1 = pow(ybar, a);
1274 fact2 = exp(0.5 * sigma * sigma * a * (a - 1));
1276 fact3 = 1 -
pnorm(zc - a * sigma);
1277 }
else if (zc > 0) {
1283 return fact1 * fact2 * fact3;
1299 double a_gamma(
double gamma,
double y,
double a,
double b) {
1306 r = gamma/(1 + gamma);
1307 t1 = r * (pow(y,gamma + 1) - pow(a, gamma+1));
1308 t2 = a * (pow(y, gamma) - pow(a, gamma));
1310 return (t1 - t2)/(b - a);
1325 double b_gamma(
double gamma,
double y,
double b) {
1326 return pow(y, gamma) - pow(b, gamma);
1347 double A_gamma(
double gamma,
double za,
double zb,
double yl,
double yu,
double ybar,
double sigma) {
1348 double r, t1, t2, t3,
z;
1350 if (fabs(yu - yl) <
EPSILON) {
1355 t1 = -gamma * r * (
M(gamma + 1, zb, ybar, sigma) -
M(gamma + 1, za, ybar, sigma));
1356 t2 = yl * (
M(gamma, zb, ybar, sigma) -
M(gamma, za, ybar, sigma));
1357 t3 = -pow(yl, gamma + 1) * r * (
M(0, zb, ybar, sigma) -
M(0, za, ybar, sigma));
1359 return (t1 + t2 + t3)/(yu - yl);
1379 double B_gamma(
double gamma,
double za,
double zb,
double yu,
double ybar,
double sigma) {
1382 t1 = -(
M(gamma, zb, ybar, sigma) -
M(gamma, za, ybar, sigma));
1383 t2 = -pow(yu, gamma) * (
M(0, zb, ybar, sigma) -
M(0, za, ybar, sigma));
1408 double capbetween(
double za,
double zb,
double zl,
double zu,
double yl,
double yu_ppp,
double ybar,
double sigma,
double pi,
double luxmult) {
1414 }
else if (zb < zl) {
1416 }
else if (za < zl) {
1418 retval =
A_gamma(gamma, zl, zb, yl, yu_ppp, ybar, sigma);
1420 retval =
A_gamma(gamma, zl, zu, yl, yu_ppp, ybar, sigma) +
1422 luxmult *
B_gamma(gamma, zu, zb, yu_ppp, ybar, sigma);
1424 }
else if (za < zu) {
1426 retval =
A_gamma(gamma, za, zb, yl, yu_ppp, ybar, sigma);
1428 retval =
A_gamma(gamma, za, zu, yl, yu_ppp, ybar, sigma) +
1430 luxmult *
B_gamma(gamma, zu, zb, yu_ppp, ybar, sigma);
1433 retval = luxmult *
B_gamma(gamma, za, zb, yu_ppp, ybar, sigma) +
1459 double respbetween(
double gamma,
double za,
double zb,
double zl,
double zu,
double yl,
double yu_ppp,
double ybar,
double sigma,
double A) {
1464 }
else if (zb < zl) {
1466 }
else if (za < zl) {
1468 retval =
A_gamma(gamma, zl, zb, yl, yu_ppp, ybar, sigma);
1470 retval =
A_gamma(gamma, zl, zu, yl, yu_ppp, ybar, sigma) +
1472 B_gamma(gamma, zu, zb, yu_ppp, ybar, sigma);
1474 }
else if (za < zu) {
1476 retval =
A_gamma(gamma, za, zb, yl, yu_ppp, ybar, sigma);
1478 retval =
A_gamma(gamma, za, zu, yl, yu_ppp, ybar, sigma) +
1480 B_gamma(gamma, zu, zb, yu_ppp, ybar, sigma);
1483 retval =
B_gamma(gamma, za, zb, yu_ppp, ybar, sigma) +
1503 double rhat(
double E,
double gamma,
double sigma,
double ybar) {
1504 return E * exp(-0.5 * gamma * (gamma-1) * sigma * sigma)/pow(ybar, gamma);
1519 double c_indiv(
double y,
double yl,
double yu,
int do_interp) {
1522 }
else if (do_interp) {
1546 double r_indiv(
double gamma,
double y,
double yl,
double yu,
double A,
int do_interp) {
1551 }
else if (do_interp) {
1553 retval =
a_gamma(gamma, y, yl, yu);
1558 retval = pow(y,gamma) - pow(yl,gamma);
1573 double sigma, gamma, zu, zushift, yu, ybar, E;
1574 double Ebau, Egap, Eep, Eabove, Fderiv;
1575 double f1, f2, f3, f4, f5, frozen_tot;
1576 int niter, i, recalc;
1594 if (year < gdrs->emergstart) {
1597 if (gdrs->
usesequence && year <= gdrs->sequenceyear) {
1610 for (i = 0; i < gdrs->
ad.
numrecs; i++) {
1631 f1 = pow(yu/ybar, gamma) * exp(-0.5 * gamma * (gamma - 1) * sigma * sigma);
1632 Eabove += E * (1 -
pnorm(zu - gamma * sigma) - f1 * (1 -
pnorm(zu)));
1638 Egap = Ebau + frozen_tot < Eep ? 0 : Ebau + frozen_tot - Eep;
1641 if (Eabove > Egap) {
1644 for (niter = 0; niter <
MAXITER; niter++) {
1647 for (i = 0; i < gdrs->
ad.
numrecs; i++) {
1656 zu = (1/sigma) * log(yu/ybar) + 0.5 * sigma;
1659 f1 = pow(yu/ybar, gamma) * exp(-0.5 * gamma * (gamma - 1) * sigma * sigma);
1660 zushift = zu - gamma * sigma;
1661 Eabove += E * (1 -
pnorm(zushift) - f1 * (1 -
pnorm(zu)));
1662 f2 = E/(sigma * yu);
1663 f3 =
dnorm(zushift);
1664 f4 = gamma * sigma * (1 -
pnorm(zu));
1666 Fderiv += f2 * (f3 + f1 * (f4 - f5));
1673 yu = yu - (Egap - Eabove)/Fderiv;
1683 for (i = 0; i < gdrs->
ad.
numrecs; i++) {
1693 zu = (1/sigma) * log(yu/ybar) + 0.5 * sigma;
1722 for (i = 1; i < 3; i++) {
1729 for (i = 1; i < 3; i++) {
1735 for (i = 0; i < gdrs->
ad.
numrecs; i++) {
1736 for (year = gdrs->
ybar_ppp.
y_start; year <= gdrs->ybar_ppp.y_end; year++) {
1756 double ybar, sigma,
z;
1764 if (isinf(y) == 1) {
1776 for (i = 0; i < gdrs->ad.numrecs; i++) {
1777 for (year = result.
y_start; year <= result.
y_end; year++) {
1779 ybar =
getval(gdrs->ybar_ppp, i, year, gdrs->ad);
1780 if (ppp_or_mer ==
XR_MER) {
1781 ybar /=
getval(gdrs->ppp2mer, i, year, gdrs->ad);
1783 sigma =
getval(gdrs->sdlog, i, year, gdrs->ad);
1784 z = (1/sigma) * log(y/ybar) + 0.5 * sigma;
1786 setval(result,
z, i, year, gdrs->ad);
1801 int sql3ret, i, j, k, year, numvals;
1816 sqlite3_exec(db,
"PRAGMA journal_mode = MEMORY", NULL, NULL, &errmsg);
1818 if ((sql3ret =
sqlite3_exec(db,
"DROP TABLE IF EXISTS gdrs;", NULL, NULL, &errmsg))) {
1819 fprintf(stderr,
"Error: %s\n", errmsg);
1825 strcpy(sqlbuff,
"CREATE TABLE gdrs (");
1826 strcat(sqlbuff,
"iso3 TEXT NOT NULL");
1827 strcat(sqlbuff,
", year INT NOT NULL");
1828 strcat(sqlbuff,
", allocation_MtC REAL");
1829 strcat(sqlbuff,
", a1_dom_rdxn_MtC REAL");
1830 strcat(sqlbuff,
", r_MtC REAL");
1831 strcat(sqlbuff,
", c_blnUSDMER REAL");
1832 strcat(sqlbuff,
", rci REAL");
1833 strcat(sqlbuff,
", pop_above_dl REAL");
1834 strcat(sqlbuff,
", pop_above_lux REAL");
1835 strcat(sqlbuff,
", lux_emiss_MtC REAL");
1836 strcat(sqlbuff,
", lux_emiss_applied_MtC REAL");
1837 strcat(sqlbuff,
", kyoto_gap_MtC REAL");
1840 sprintf(valbuff,
", tax_pop_below_%d REAL, tax_income_mer_dens_%d REAL, tax_income_ppp_dens_%d REAL, tax_revenue_mer_dens_%d REAL, tax_revenue_ppp_dens_%d REAL, tax_pop_dens_%d REAL",
1842 strcat(sqlbuff, valbuff);
1844 strcat(sqlbuff,
");");
1846 if ((sql3ret =
sqlite3_exec(db, sqlbuff, NULL, NULL, &errmsg))) {
1847 fprintf(stderr,
"Error: %s\n", errmsg);
1855 sprintf(sqlbuff,
"INSERT INTO gdrs VALUES(");
1856 for (i = 0; i < numvals; i++) {
1858 strcat(sqlbuff,
"?");
1860 strcat(sqlbuff,
",?");
1863 strcat(sqlbuff,
")");
1897 fprintf(stderr,
"Error: %s\n\tSQL: %s\n", errmsg, sqlbuff);
1908 if ((sql3ret =
sqlite3_exec(db,
"CREATE UNIQUE INDEX idx_gdrs ON gdrs(iso3 ASC, year ASC);", NULL, NULL, &errmsg))) {
1909 fprintf(stderr,
"Error: %s\n", errmsg);
1917 "INSERT OR IGNORE INTO schemes VALUES (\"Greenhouse Development Rights\", \"gdrs\");",
1918 NULL, NULL, &errmsg))) {
1919 fprintf(stderr,
"Error: %s\n", errmsg);
For the application, basic dimensions: number of countries and bounding years.
float emisselast
Emissions elasticity.
int loadgdrs(struct gdrs_struct *gdrs, const char *fname)
Function to translate from SQLite3 database to internal data structures.
int a1refyear
The year compared to which A1 reduces emissions (e.g., 1990 or 2005)
int emergstart
Start year of "emergency progam".
#define TAX_TYPE_GLOBAL_QUINTILE
double c_indiv(double y, double yl, double yu, int do_interp)
Calculate individual per capita capacity at a specified income level.
int use_lulucf
Flag whether to include land-use change emissions.
int y_start
The start year.
double B_gamma(double gamma, double za, double zb, double yu, double ybar, double sigma)
Calculate the function.
int dump2sql3(const char *fname, struct gdrs_struct gdrs)
After the calculation, write all results to the SQLite3 database.
struct datablock zu
Luxury threshold converted to "z" variable .
struct datablock binop(struct datablock a, struct datablock b, char op, struct appdata ad)
Carry out a binary operation (+, -, *, /) on two datablock structures.
double qnorm(double p)
The inverse cumulative standardized normal distribution.
int maxyear
Final year for the dataset.
#define GDRS_SQLITE_OFFSET
int cumsince
Calculate responsibility from this year.
float a1_shape_param
If sequencing, exponent on tfrac^a1_shape_param that affects how rapidly A1 countries approach target...
#define GDRS_TOO_MANY_TAX_ENTRIES
struct datablock pop
Population in people.
struct datablock lux_emiss_applied
Luxury emissions actually used in adjusted baseline (calculated)
struct datablock gdp
GDP in MER.
struct timeseries emergpath
The emergency pathway in GtC.
double r_indiv(double gamma, double y, double yl, double yu, double A, int do_interp)
Calculate individual per capita annual responsibility at a specified income level.
float lux_thresh_mult
Tax multiplier for incomes above luxury threshold.
A one-dimensional array that contains information on countries that is the same for all years...
char ** iso3
The ISO 3-letter code for the country.
struct datablock r
Responsibility (calculated)
void combine_gap(struct fixedfactor *gap, int i, double newgap, int combine)
Calculate and store luxury emissions.
#define GDRS_SQLITE_BUFSIZE
int numrecs
Number of records (i.e., number of countries)
This is the main struct that contains data from the sqlite3 database and calculated values...
struct datablock ppp2mer
Ratio of GDP in PPP to GDP in MER.
int use_nonco2
Flag whether to include non-CO2 gases.
float respweight
Responsibility weight.
int readtable(sqlite3 *db, const char *column, struct datablock *table, struct appdata ad)
Helper function to read a column from the "core" table into a datablock.
void cleargdrs(struct gdrs_struct gdrs)
Clear out the GDRs data structure.
double nationalquintile(double q, double ybar, double sigma)
Calculate the income at a given quintile for a country.
struct datablock tax_revenue_ppp_dens[TAX_MAX_ENTRIES]
Table to hold contribution to tax in different countries & years for the different tax levels (multip...
#define GDRS_SQLITE_HALFBUFSIZE
int sequenceyear
End of the first committment period with sequencing: only A1 up to here.
double getffval(struct fixedfactor ff, int row, struct appdata ad)
Get a value for a specified row (country) from a fixedfactor.
#define sqlite3_column_int
void clearts(struct timeseries ts)
Free the memory taken up by a timeseries.
float dt_high
Luxury threshold – in MER.
#define sqlite3_column_text
struct fixedfactor kyoto_startep_frac
For Annex I countries, Kyoto committments at the start of the emergency program as a fraction of BaU...
struct fixedfactor kyoto_ratified
A filter equal to 1.0 if ratified and 0.0 if not.
int num_tax_levels
Number of entries in the tax level table in the database.
double b_gamma(double gamma, double y, double b)
Calculate the function.
struct datablock ybar_ppp
Mean income in PPP.
struct datablock scalmult(double scalar, struct datablock dbin, struct appdata ad)
Multiply a datablock by a scaling factor.
void nextrci(int year, struct gdrs_struct *gdrs)
Calculate the GDRs Responsibility-Capacity Indicator for a particular year.
double rhat(double E, double gamma, double sigma, double ybar)
Calculate the factor for a country.
struct sqlite3_stmt sqlite3_stmt
double capbetween(double za, double zb, double zl, double zu, double yl, double yu_ppp, double ybar, double sigma, double pi, double luxmult)
Calculate capacity per capita between two income limits.
int minyear
Earliest year for the dataset.
double gettsval(struct timeseries ts, int year, struct appdata ad)
Get the value for a particular year from a timeseries.
float billpercgwp
Bill as percent of GWP.
void setffval(struct fixedfactor ff, double val, int row, struct appdata ad)
Set a value for a specified row (country) for a fixedfactor.
struct fixedfactor annex2
Filter for Annex 2 countries.
double luxcap(int year, struct gdrs_struct *gdrs)
If calculating luxury-capped baselines adjust the luxury threshold if needed to stay above emergency ...
int allocdata(struct datablock *dblock, struct appdata ad)
Create a datablock in memory, using application-specific dimensions.
void calcallocs(struct gdrs_struct *gdrs)
Calculate allocations for all years.
#define sqlite3_bind_double
struct datablock pop_above_lux
Population above luxury threshold (calculated)
struct datablock tax_income_mer_dens[TAX_MAX_ENTRIES]
Table to hold tax income in MER terms (multiplied by pop & prob density–summable over countries) ...
void settsval(struct timeseries ts, double val, int year, struct appdata ad)
Set the value for a particular year in a timeseries.
double gini2sdlog(double gini)
The standard deviation of the log of income corresponding to a given Gini, assuming lognormal...
struct fixedfactor rci_lagged
Averaged RCI for mitigation smoothing.
struct datablock bl_nonco2
Baseline non-CO2 gases.
double ztransf(double y, double ybar, double sigma)
The transformed value .
void cleardata(struct datablock dblock)
Free the memory taken up by a datablock.
int do_luxcap
Flag whether to use luxury-capped baselines.
struct datablock tax_income_ppp_dens[TAX_MAX_ENTRIES]
Table to hold tax income in PPP terms (multiplied by pop & prob density–summable over countries) ...
int thisyear
Store the current year.
struct datablock zl
Development threshold converted to "z" variable .
struct datablock zu_adj
Adjusted luxury threshold as "z" variable .
struct datablock scalpop
Scaled population, in billions (calculated as 1.0e-9 * population)
double getval(struct datablock db, int row, int year, struct appdata ad)
Get the data value from the datablock for specified row & year.
struct datablock kab_gap
Gap between Kyoto-adjusted baseline and standard baseline.
double globalquintile(double q, int year, struct gdrs_struct *gdrs, int ppp_or_mer)
Calculate the income at a given quintile for the world as a whole.
void clearff(struct fixedfactor ff)
Free the memory taken up by a fixedfactor.
struct datablock gini
Gini coefficient.
void calc_kab(struct fixedfactor *gap, double *totgap, int year, int period, int combine, struct gdrs_struct *gdrs)
Calculate and store "Kyoto gap" for Kyoto-adjusted baselines.
int allocff(struct fixedfactor *ff, struct appdata ad)
Create a fixedfactor in memory, of length = number of countries.
#define sqlite3_column_type
double * data
The array, length = ad.numrecs when created.
struct datablock bl_lulucf
Baseline land use, land-use change, and forestry.
struct datablock baseline
Baseline emissions, the sum of all selected baseline components.
#define sqlite3_column_double
double dnorm(double x)
The standard normal probability density.
struct fixedfactor frozen
Emissions that are "frozen" following the first sequencing period.
double A_gamma(double gamma, double za, double zb, double yl, double yu, double ybar, double sigma)
Calculate the function.
struct datablock alloc_gdrs
Emissions allocation (calculated)
int use_kab
Flag whether to use Kyoto-adjusted baselines (KABs)
void handle_sql3error(sqlite3 *db, sqlite3_stmt *stmt)
Function that wraps repetitive code for SQLite3 errors.
struct datablock lux_emiss
Emissions over the luxury threshold (calculated)
struct tax_entry tax_levels[TAX_MAX_ENTRIES]
Table of tax levels with associated information.
int allocts(struct timeseries *ts, struct appdata ad)
Create a timeseries in memory, of length = y_start - y_end + 1.
struct datablock z(double y, struct gdrs_struct *gdrs, int ppp_or_mer)
Calculate the "z" transformed version of an income level for all countries and years.
#define sqlite3_prepare_v2
double M(double a, double zc, double ybar, double sigma)
Calculate a function that is repeatedly used in calculations.
struct datablock tax_pop_below[TAX_MAX_ENTRIES]
Table to hold population below the tax line.
struct datablock bl_fossil
Baseline fossil emissions.
double a_gamma(double gamma, double y, double a, double b)
Calculate the function.
int usesequence
Boolean: true if Annex 1 countries act first (sequencing)
struct datablock a1domrdxn
Annex 1 domestic reductions (if sequencing)
struct datablock pop_above_dl
Population above development threshold (calculated)
double * data
The data, length = y_start - y_end + 1 when created.
double respbetween(double gamma, double za, double zb, double zl, double zu, double yl, double yu_ppp, double ybar, double sigma, double A)
Calculate responsibility between two income limits.
struct datablock volrdxn
Voluntary reductions.
double pnorm(double x)
The cumulative standardized normal distribution.
float dt_low
Development threshold – in PPP.
struct appdata ad
Basic information about dimensions: number of countries, start year, end year.
#define GDRS_NUM_TAX_PARAMS
int assign_mitgap_to
If sequencing: either 1 (Annex 1) or 2 (Annex 2) for who bears responsibility for mitigation gap...
struct datablock tax_revenue_mer_dens[TAX_MAX_ENTRIES]
Table to hold contribution to tax in different countries & years for the different tax levels (multip...
struct datablock c
Capacity (calculated)
void calc_luxemiss(struct fixedfactor *gap, double *totgap, int year, int period, int combine, struct gdrs_struct *gdrs)
Calculate and store luxury emissions.
int interp_between_thresholds
If true, interpolate capacity and responsibility between thresholds.
struct fixedfactor annex1
Filter for Annex 1 countries.
int y_start
The start year.
#define sqlite3_bind_text
float a1_perc_rdxn
If sequencing, % below ref year that A1 must reduce it's emissions by sequence year.
A two-dimensional array that contains information for country/year combinations.
struct timeseries filter(struct datablock data, struct fixedfactor filter, struct appdata ad)
Aggregate data in a datablock using a fixedfactor "filter" to produce a timeseries.
struct datablock sdlog
Standard deviation of log income, estimated from Gini assuming lognormal distribution.
struct timeseries yu_adj
Adjusted luxury threshold to ensure that adjusted baseline is not below emergency pathway...
void setval(struct datablock db, double val, int row, int year, struct appdata ad)
Set a specific value in a datablock, specified by row and year.
struct datablock rci
Responsibility-Capacity Indicator (calculated)
struct datablock transform(struct datablock dbin, double(*f)(double), struct appdata ad)
Apply a function to a datablock.
struct datablock bl_netexports
Baseline net exports, for embodied carbon.
struct fixedfactor kyoto_startep_frac_1990
For Annex I countries, Kyoto committments at the start of the emergency program as a fraction of 1990...
double globaldist(double y, int year, struct gdrs_struct *gdrs, int ppp_or_mer, double *dist_deriv)
Calculate the fraction of global population below a specified income level in the given year...
struct datablock tax_pop_dens[TAX_MAX_ENTRIES]
Table to hold pop & prob dens at different tax levels.
#define TAX_TYPE_NATL_QUINTILE
int emerg_path_id
Integer ID indicating which emergency path to use.
void calcybar(struct gdrs_struct *gdrs)
Calculate mean income from GDP and population.
int use_netexports
Flag whether to include emissions embodied in traded goods.
int use_lag
Apply a (varying) time lag between mitigation investment and realized reductions. ...
int kab_only_ratified
Flag whether to only include countries that ratified the Kyoto agreement.