/******************************************
** Name     : beer.h
** Function : tools for beer utilities
** Author   : Domenick Venezia
**/
/* INCLUDE FILES **************************/

#ifndef BEER_H
#define BEER_H

/*
** This is for Jackie Rager's hopping functions
*/
#define RAGER_HIGH_SPECIFIC_GAVITY (1.050)
#define RAGER_HOP_UTIL_MAX_MINUTES (60.0)

/* Define the coefficients for a 3rd order polynomial for SG temp correction
*/

#define A0 (1.313454)
#define A1 (-0.132674)
#define A2 (2.057793e-3)
#define A3 (-2.627634e-6)

/*
** data for relative density of water
*/
#define BEER_NUM_DENS (111)


static float density_water[BEER_NUM_DENS] = {
   0.999868, /*   0 C */
   0.999927,
   0.999968,
   0.999992,
   1.000000,
   0.999992,
   0.999968,
   0.999930,
   0.999877,
   0.999809,
   0.999728, /*  10 C */
   0.999634,
   0.999526,
   0.999406,
   0.999273,
   0.999129,
   0.998972,
   0.998804,
   0.998625,
   0.998435,
   0.998234, /*  20 C */
   0.998022,
   0.997801,
   0.997569,
   0.997327,
   0.997075,
   0.996814,
   0.996544,
   0.996264,
   0.995976,
   0.995678, /*  30 C */
   0.995372,
   0.995057,
   0.994734,
   0.994403,
   0.994063,
   0.993716,
   0.993360,
   0.992997,
   0.992626,
   0.992247, /*  40 C */
   0.991861,
   0.991467,
   0.991067,
   0.990659,
   0.990244,
   0.989822,
   0.989393,
   0.988957,
   0.988515,
   0.988066, /*  50 C */
   0.987610,
   0.987148,
   0.986680,
   0.986205,
   0.985723,
   0.985236,
   0.984743,
   0.984243,
   0.983737,
   0.983226, /*  60 C */
   0.982708,
   0.982185,
   0.981655,
   0.981120,
   0.980580,
   0.980034,
   0.979482,
   0.978924,
   0.978361,
   0.977793, /*  70 C */
   0.977219,
   0.976640,
   0.976056,
   0.975466,
   0.974871,
   0.974271,
   0.973665,
   0.973055,
   0.972439,
   0.971819, /*  80 C */
   0.971193,
   0.970562,
   0.969926,
   0.969286,
   0.968640,
   0.967990,
   0.967335,
   0.966674,
   0.966009,
   0.965340, /*  90 C */
   0.964665,
   0.963986,
   0.963302,
   0.962613,
   0.961920,
   0.961222,
   0.960519,
   0.959812,
   0.959100,
   0.958384, /* 100 C */
   0.957662,
   0.956937,
   0.956207,
   0.955472,
   0.954733,
   0.953989,
   0.953240,
   0.952488,
   0.951730,
   0.950968 };

/* FUNCTIONS ******************************************/

float corrected_SG( float SG, float temp, char temptype );
float corrected_SG_at_15C( float SG, float temp, char temptype );
float SG_to_Plato( float SG );
float lbs_extract_per_gal_SG( float SG_raw, float temp, char temptype );
float SG_change_with_vol( float SG0, float vol0, float vol1 );
float vol_change_with_SG( float vol0, float SG0, float SG1 );
float temp_to_F_degrees( float temp, char temptype );
float temp_to_C_degrees( float temp, char temptype );
float C_to_F_degrees( float temp );
float F_to_C_degrees( float temp );
float lbs_to_kgs( float lbs );
float kgs_to_lbs( float kgs );
float gals_to_liters( float gals );
float liters_to_gals( float liters );
float qts_to_liters( float qts );
float liters_to_qts( float liters );
float alc_calories_per_12_oz( float OSG, float FSG );
float ext_calories_per_12_oz( float OSG, float FSG );
float CO2_pressure( float vol, float tempF );
float decoct( float vt, float tt, float t0, float td );
float beer_step_add_vol( float vm, float tm, float ta, float tf );
float beer_relative_density_of_water( float t0, float t1 );
float beer_relative_volume_of_water( float t0, float v0, float t1 );

/*
** Hopping calculations
*/

float tinseth_hop_gravity_adjustment( float SGB );
float tinseth_hop_boil_time_factor( float boil_time );
float tinseth_hop_utilization( float SGB, float boil_time );
float tinseth_hop_ibu_from_weight( float Util, float Acid, 
                       float Wt, float Vol, float GA, float WtFactor );
float tinseth_hop_weight_from_ibu( float Util, float Acid, 
                       float IBU, float Vol, float GA, float WtFactor );

float rager_hop_gravity_adjustment( float SGB );
float rager_hop_util( int boil_minutes );
float rager_hop_ibu_from_weight( float Util, float Acid, 
                       float Wt, float Vol, float GA, float WtFactor );
float rager_hop_weight_from_ibu( float Util, float Acid, 
                       float IBU, float Vol, float GA, float WtFactor );

float ballings_factor( float P );
float alcohol_by_weight_fix( float OSG, float FSG );
float alcohol_by_weight_AJ( float OSG, float FSG );
float abw_to_abv( float abw );

float brix_to_ri( float brix );
float brix_to_sg( float brix );
float brix_to_fg( float ob, float ab );
float brix_to_abw( float sg, float ab );
float brix_sg_to_abw( float ab, float sg );

/******************************************/

#endif
