/**           PlankRadiation: Simple program to calculate
 *            the planks radiation spectrum for a specified
 *            wavelength and temperature
 */
import uk.ac.ed.ph.sciprog.*;

public class PlankRadiation {
    public static void main(String args[]) {

	//        Declare fixed constants

	final double PLANK = 6.67e-34;           // Plank's constant
	final double BOLTZMAN = 1.38e-23;        // Boltzmans constant.
	final double C = 2.9985e8;               // Speed of light

	//       Set up the iopanel to read two doubles.

	Display panel = new Display("Plank Distribution");
	Input tempInput = new Input("Temperature is kelvin", 5800.0);
	panel.addInput(tempInput);
	Input wavelengthInput = new Input("Wavelength in nm",500.0);
	panel.addInput(wavelengthInput);

	while(true) {

	    panel.waitForButtonPress();
	    
	    //               get temperature and wavelength

	    double temp = tempInput.getDouble();
	    double lambda = wavelengthInput.getDouble();
	    lambda /= 1.0e9;             // Change to SI units (meters)

	    //                calcuate plank distribution 
	    //                Note that plank and PLANK and different!!!!

	    double plank = 8.0*Math.PI*PLANK*C/Math.pow(lambda,5.0)*
	    	(1.0 / (Math.exp(C*PLANK/(BOLTZMAN*lambda*temp)) - 1.0));
	    
	    //                format the output.

	    panel.printf("Energy distribution for T = %.5g K\n at %.6g m is %.6e\n",
			 temp,lambda,plank);

	}
    }
}
			 
