// MonteScatter.java // This class is an applet that uses monte carlo methods to determine scattering // path lengths in a number of cloud structures. import java.awt.*; import java.applet.*; public class MonteScatter extends Applet implements Runnable { public void init() { Panel tmp_panel; int i; thread=null; cloud=new Slab1D(10.0); sm=new RandomScatter(); dir=new RTVector(1); dir.Set(0,-1.0); this.setLayout(new BorderLayout()); main_panel=new Panel(); main_panel.setLayout(new GridLayout(3,3)); cloud_choice=new Choice(); cloud_choice.addItem("1D Slab"); cloud_choice.addItem("2D Slab"); cloud_choice.addItem("2D Sphere"); cloud_choice.addItem("2D Fractal"); cloud_choice.addItem("3D Slab"); cloud_choice.addItem("3D Sphere"); cloud_choice.addItem("3D Fractal"); main_panel.add(cloud_choice); scatter_choice=new Choice(); scatter_choice.addItem("Isotropic"); scatter_choice.addItem("Rayleigh"); scatter_choice.addItem("Henye-Greenstein"); main_panel.add(scatter_choice); aoi_choice=new Choice(); aoi_choice.addItem("0 degrees"); aoi_choice.addItem("15 degrees"); aoi_choice.addItem("30 degrees"); aoi_choice.addItem("45 degrees"); aoi_choice.addItem("60 degrees"); aoi_choice.addItem("85 degrees"); main_panel.add(aoi_choice); ss_button=new Button("Start"); main_panel.add(ss_button); tmp_panel=new Panel(); tmp_panel.add(new Label("Optical Depth:")); tau_label=new Label("10.0"); tmp_panel.add(tau_label); main_panel.add(tmp_panel); iteration_count=0; tmp_panel=new Panel(); tmp_panel.add(new Label("Num. Iteration:")); iteration_label=new Label("000000"); tmp_panel.add(iteration_label); main_panel.add(tmp_panel); tmp_panel=new Panel(); tmp_panel.add(new Label("Trans. Path Length:")); aplt_label=new Label("0.0"); tmp_panel.add(aplt_label); main_panel.add(tmp_panel); aplt_sum=0.0; tmp_panel=new Panel(); tmp_panel.add(new Label("Reflected Path Length:")); aplr_label=new Label("0.0"); tmp_panel.add(aplr_label); main_panel.add(tmp_panel); aplr_sum=0.0; tmp_panel=new Panel(); tmp_panel.add(new Label("% Reflected:")); albedo_label=new Label("0.0"); tmp_panel.add(albedo_label); main_panel.add(tmp_panel); num_reflected=0; this.add("South",main_panel); tmp_panel=new Panel(); tmp_panel.setLayout(new GridLayout(1,3)); data_plot=new AdjustablePlot2D(); data_plot.AddDataSet(cloud.GetData()); data_plot.x_label="Optical Depth Density"; data_plot.y_label="Altitude"; tmp_panel.add("West",data_plot); cloud_panel=new Panel(); tmp_panel.add("Center",cloud_panel); distrib_plot=new Plot2D(); trans_distrib_data=new DataSet2D(20,10); trans_distrib_data.SetSortOrder(DataSet2D.SORT_Y); for(i=19; i>=0; i--) { trans_distrib_data.AddElement(new Point2D(1.0*i,0.0)); } trans_distrib_data.plot_color=Color.red; trans_distrib_data.description="Transmitted"; distrib_plot.AddDataSet(trans_distrib_data); ref_distrib_data=new DataSet2D(20,10); ref_distrib_data.SetSortOrder(DataSet2D.SORT_Y); for(i=19; i>=0; i--) { ref_distrib_data.AddElement(new Point2D(1.0*i,0.0)); } ref_distrib_data.plot_color=Color.blue; ref_distrib_data.description="Reflected"; distrib_plot.AddDataSet(ref_distrib_data); distrib_plot.x_label="Path Length"; distrib_plot.y_label="Count"; tmp_panel.add(distrib_plot); this.add("Center",tmp_panel); cloud.DrawCloud(cloud_panel); } public void run() { boolean flag=true; int i; try { while(true) { pp=new PhotonPath(cloud,sm,dir); if(pp.Follow(10000)) { iteration_count++; iteration_label.setText(Integer.toString(iteration_count)); if(pp.WasTransmitted()) { aplt_sum+=pp.GetPathLength(); aplt_label.setText(Double.toString(aplt_sum/(iteration_count-num_reflected))); tau_label.setText(Double.toString(cloud.OpticalDepth())); try { flag=true; for(i=1; (i<20) && flag; i++) { if(pp.GetPathLength()