#include <stdlib.h>
#include <stdio.h>
#include <math.h>

#define PI 3.14159265359
#define VE 0.95
#define BORE 3.66
#define STROKE 3.57
#define COMP_R 9.7
#define TARGET_RPM 1800
#define SOUND_SPEED 13503.9
#define EXT_VALVE_OPEN 149
#define EXT_VALVE_CLOSE 8

int main(int argc, char **argv){

	const double swept_volume = PI * BORE/2 * BORE/2 * STROKE;
	const double cross_sect_area = swept_volume*TARGET_RPM/88200;
	const double inside_diameter = sqrt(cross_sect_area*1.273);
	//Inside Diameter = √cross-section area x 1.273
	//Cross-Section Area = (cylinder volume x RPM) ÷ 88,200
	//Swept Volume = Pi x (bore ÷ 2) x (bore ÷ 2) x stroke
	//Swept Volume = bore x bore x stroke x .7854
	//swept_volume = PI * BORE/2 * BORE/2 * STROKE;
	const double ext_duration = 360-EXT_VALVE_OPEN+EXT_VALVE_CLOSE;
	double max_runner_length = 0;
	double min_runner_length = 0;
	double open_to_open = ext_duration + 240-ext_duration;
	double open_close = 240+ext_duration;
	double revs_per_sec = TARGET_RPM/60;
	double sec_per_rev = 1/revs_per_sec;

	double tmp1 = 0;
	double tmp2 = 0;

	tmp1 = open_to_open/360 * sec_per_rev;
	tmp2 = open_close/360 * sec_per_rev;

	min_runner_length = SOUND_SPEED*tmp1/2;
	max_runner_length = SOUND_SPEED*tmp2/2;

	printf("swept volume: %lf\n", swept_volume);
	printf("cross sectional area: %lf\n", cross_sect_area);
	printf("inside diameter: %lf\n", inside_diameter);
	printf("min length: %lf\n", min_runner_length);
	printf("max length: %lf\n", max_runner_length);

	return 0;
}
