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

//cross-sectional area is A and thickness is ?x
//The time rate of heat flow, ?Q/?t, for small ?T and small ?x, is proportional to A(?T/?x).
//H = -kA(dT/dx)

/*
380.82 W/(m K)
401

140mm
25.4mm

[K] = [°C] + 273.15

W/(m K)
W/(m C)

385 = W/(m*(C+273.15))


Heat conduction Q/ Time = (Thermal conductivity) x (Area) x (Thot - Tcold)/Thickness 

Q = Tc * A * (Th - Tc) / Thickness
Q*Thickness = Tc * A * (Th - Tc)



A = Q*Thickness / (Tc*Thot - Tc*Tcold)


q / A = k dT / s

where

q / A = heat transfer per unit area (W/m2)

k = thermal conductivity  (W/mK)

dT = temperature difference (oC)

s = wall thickness (m)

A = qs/kt

A = 100*0.14/385*35


100 = 385*X*X*35/0.14
100 = 13475*X*X/0.14
14 = 13475*X*X

*/

void Usage(void){
	printf("./thermal thermal_conductivity watts length_cm\n");

}

int main(int argc, char **argv){
	double Thermal_Conductivity = 385;
	double Thickness = 0.14;
	double Width = 0.0254;
	double Length = 0.0254;
	double Thot = 60; //333.15;
	double Tcold = 40; //298.15;
	double Heat_Conduction = 100;
	double Area = 0;
	double tmp1, tmp2, tmp3, tmp4;


	if(argc != 4){
		Usage();
		exit(1);
	}
	Thermal_Conductivity = atof(argv[1]);
	Heat_Conduction = atof(argv[2]);
	Thickness = atof(argv[3])/100;

	tmp3 = Thermal_Conductivity*Thot;
	tmp4 = Thermal_Conductivity*Tcold;
	tmp1 = Heat_Conduction*Thickness;
	tmp2 = tmp3 - tmp4;

	Area = tmp1 / tmp2;

	printf("Area: %lfcm Width: %lfcm\n", Area*10, sqrt(Area*10));


	return 0;
}
