30 #define GDRS_CFGREADERROR 255 31 #define GDRS_CFGCLOSEERROR 256 32 #define GDRS_FREADERROR 258 33 #define GDRS_FCLOSEERROR 259 34 #define GDRS_NOMEM 260 35 #define GDRS_DIDNOTRUN 261 36 #define GDRS_TOO_MANY_TAX_ENTRIES 262 38 #define GDRS_ID_TABLE "id='gdrstable'" 39 #define GDRS_ROW_ID "calcrow" 40 #define GDRS_CLASS_REGION "class='gdrsregion'" 41 #define GDRS_ID_WORLD "class='gdrsregion' id='gdrsworld'" 42 #define GDRS_TEXT_COL "class='gdrstextcol'" 44 #define GDRS_SQLITE_OFFSET 1024 45 #define GDRS_SQLITE_CANTDELETEDB 1023 46 #define GDRS_SQLITE_BUFSIZE 2048 47 #define GDRS_SQLITE_HALFBUFSIZE 1024 48 #define GDRS_NUM_PARAMS 12 49 #define GDRS_NUM_TAX_PARAMS 6 51 #define EPS_NEWTON 1.0e-9 55 #define PER_BEFORE_EP 0 56 #define PER_SEQUENCE 1 64 #define TAX_MAX_ENTRIES 100 65 #define TAX_TYPE_VALUE 0 66 #define TAX_TYPE_NATL_QUINTILE 1 67 #define TAX_TYPE_GLOBAL_QUINTILE 2 69 #define GAP_COMBINE_NONE 0 70 #define GAP_COMBINE_ADD 1 71 #define GAP_COMBINE_MAX 2 72 #define GAP_COMBINE_MIN 3 179 double M(
double a,
double zc,
double ybar,
double sigma);
182 double a_gamma(
double gamma,
double y,
double a,
double b);
183 double b_gamma(
double gamma,
double y,
double b);
184 double A_gamma(
double gamma,
double za,
double zb,
double yl,
double yu,
double ybar,
double sigma);
185 double B_gamma(
double gamma,
double za,
double zb,
double yu,
double ybar,
double sigma);
186 double capbetween(
double za,
double zb,
double zl,
double zu,
double yl,
double yu_ppp,
double ybar,
double sigma,
double pi,
double luxmult);
187 double respbetween(
double gamma,
double za,
double zb,
double zl,
double zu,
double yl,
double yu_ppp,
double ybar,
double sigma,
double A);
188 double rhat(
double E,
double gamma,
double sigma,
double ybar);
189 double c_indiv(
double y,
double yl,
double yu,
int do_interp);
190 double r_indiv(
double gamma,
double y,
double yl,
double yu,
double A,
int do_interp);
For the application, basic dimensions: number of countries and bounding years.
float emisselast
Emissions elasticity.
int a1refyear
The year compared to which A1 reduces emissions (e.g., 1990 or 2005)
int emergstart
Start year of "emergency progam".
int dump2sql3(const char *fname, struct gdrs_struct gdrs)
After the calculation, write all results to the SQLite3 database.
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 use_lulucf
Flag whether to include land-use change emissions.
struct datablock zu
Luxury threshold converted to "z" variable .
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.
void combine_gap(struct fixedfactor *gap, int i, double newgap, int combine)
Calculate and store luxury emissions.
void calcybar(struct gdrs_struct *gdrs)
Calculate mean income from GDP and population.
float capfrac
Income counted toward capacity between thresholds.
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...
struct datablock pop
Population in people.
struct datablock lux_emiss_applied
Luxury emissions actually used in adjusted baseline (calculated)
double b_gamma(double gamma, double y, double b)
Calculate the function.
struct datablock gdp
GDP in MER.
struct timeseries emergpath
The emergency pathway in GtC.
void nextrci(int year, struct gdrs_struct *gdrs)
Calculate the GDRs Responsibility-Capacity Indicator for a particular year.
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)
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.
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...
void cleargdrs(struct gdrs_struct gdrs)
Clear out the GDRs data structure.
int sequenceyear
End of the first committment period with sequencing: only A1 up to here.
A one-dimensional array that contains global information that is the same for all countries...
float dt_high
Luxury threshold – in MER.
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 A_gamma(double gamma, double za, double zb, double yl, double yu, double ybar, double sigma)
Calculate the function.
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.
void handle_sql3error(sqlite3 *db, sqlite3_stmt *stmt)
Function that wraps repetitive code for SQLite3 errors.
struct datablock ybar_ppp
Mean income in PPP.
struct sqlite3_stmt sqlite3_stmt
float billpercgwp
Bill as percent of GWP.
struct fixedfactor annex2
Filter for Annex 2 countries.
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) ...
struct fixedfactor rci_lagged
Averaged RCI for mitigation smoothing.
struct datablock bl_nonco2
Baseline non-CO2 gases.
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.
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.
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)
struct datablock kab_gap
Gap between Kyoto-adjusted baseline and standard baseline.
double luxcap(int year, struct gdrs_struct *gdrs)
If calculating luxury-capped baselines adjust the luxury threshold if needed to stay above emergency ...
struct datablock gini
Gini coefficient.
struct datablock bl_lulucf
Baseline land use, land-use change, and forestry.
struct datablock baseline
Baseline emissions, the sum of all selected baseline components.
void calcallocs(struct gdrs_struct *gdrs)
Calculate allocations for all years.
struct fixedfactor frozen
Emissions that are "frozen" following the first sequencing period.
double c_indiv(double y, double yl, double yu, int do_interp)
Calculate individual per capita capacity at a specified income level.
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.
struct datablock alloc_gdrs
Emissions allocation (calculated)
int use_kab
Flag whether to use Kyoto-adjusted baselines (KABs)
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 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.
struct datablock tax_pop_below[TAX_MAX_ENTRIES]
Table to hold population below the tax line.
struct datablock bl_fossil
Baseline fossil emissions.
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)
The tax table has a dynamically allocated array of entries of this form.
struct datablock volrdxn
Voluntary reductions.
float dt_low
Development threshold – in PPP.
struct appdata ad
Basic information about dimensions: number of countries, start year, end year.
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.
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...
double M(double a, double zc, double ybar, double sigma)
Calculate a function that is repeatedly used in calculations.
double B_gamma(double gamma, double za, double zb, double yu, double ybar, double sigma)
Calculate the function.
double rhat(double E, double gamma, double sigma, double ybar)
Calculate the factor for a country.
struct datablock c
Capacity (calculated)
int interp_between_thresholds
If true, interpolate capacity and responsibility between thresholds.
struct fixedfactor annex1
Filter for Annex 1 countries.
int loadgdrs(struct gdrs_struct *gdrs, const char *fname)
Function to translate from SQLite3 database to internal data structures.
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.
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 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...
struct datablock rci
Responsibility-Capacity Indicator (calculated)
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 a_gamma(double gamma, double y, double a, double b)
Calculate the function.
struct datablock tax_pop_dens[TAX_MAX_ENTRIES]
Table to hold pop & prob dens at different tax levels.
int emerg_path_id
Integer ID indicating which emergency path to use.
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. ...
void calc_luxemiss(struct fixedfactor *gap, double *totgap, int year, int period, int combine, struct gdrs_struct *gdrs)
Calculate and store luxury emissions.
int kab_only_ratified
Flag whether to only include countries that ratified the Kyoto agreement.