import java.util.Random;
import javax.swing.JFrame;

public class Main {
    public static void main(String[] args) {
        // Get these from user input later
        final int gridWidth = 100;
        final int gridHeight = 100;
        final double tempFinal = 1e-3;
        final double tempInit = 10.0;
        final double tau = 1e4;
        final int frameSkip = 0;

        Random random = new Random();

        int t = 0;
        double temp = tempInit;

        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //frame.setSize(width * 10 + 50, height * 10 + 50);
        frame.setSize(GridPanel.PANEL_WIDTH, GridPanel.PANEL_HEIGHT);
        frame.setVisible(true);

        GridPanel gridPanel = new GridPanel(gridWidth, gridHeight);
        frame.add(gridPanel);

        while (temp > tempFinal) {
            t++;
            temp = cooling(t, tau, tempInit);

            // Do the Markov chain
            Coordinate[] sites = gridPanel.pickSites();
            if (gridPanel.hasSingleDimer(sites)) {
                if (random.nextDouble() < Math.exp(-1 / temp))
                        gridPanel.removeDimer(sites);
            }
            else if (gridPanel.getCells().get(sites[0]).dimer == null
                     && gridPanel.getCells().get(sites[1]).dimer == null)
                gridPanel.placeDimer(sites);
            
            if (t % (frameSkip + 1) == 0) {
                System.out.format("%d %f %d\n", t, temp, gridPanel.getNDimers());
                gridPanel.repaint();
            }
        }

    }

    /**
     * The cooling schedule for determining the probability of state changes
     * in the Markov chain.
     *
     * @param t the current time
     * @param tau the time constant
     * @param tempInit the initial "temperature" of the system
     * @return the new temperature of the system
     */
    private static double cooling(double t, double tau, double tempInit) {
        return tempInit * Math.exp(-t / tau);
    }
}

@@ -9,156 +9,511 @@
 ava.
-util.Random;%0Aimport javax.swing.JFrame;%0A%0Apublic class Main %7B%0A    public static void main(String%5B%5D args) %7B%0A        // Get these from user
+io.File;%0Aimport java.io.FileNotFoundException;%0Aimport java.util.Random;%0Aimport java.util.Scanner;%0Aimport javax.swing.JFrame;%0A%0Apublic class Main %7B%0A    public static void main(String%5B%5D args) throws FileNotFoundException %7B%0A        if (args.length == 0) %7B%0A            System.err.println(%22Input file not given%22);%0A            return;%0A        %7D%0A%0A        if (args.length %3E 1) %7B%0A            System.err.println(%22Too many arguments given%22);%0A            return;%0A        %7D%0A%0A        // Read parameters from
  input 
-later
+file
 %0A   
@@ -521,33 +521,140 @@
     
-final int gridWidth = 100
+File infile = new File(args%5B0%5D);%0A        Scanner scanner = new Scanner(new File(args%5B0%5D));%0A        int gridWidth = scanner.nextInt()
 ;%0A  
@@ -655,30 +655,24 @@
 ();%0A        
-final 
 int gridHeig
@@ -680,11 +680,25 @@
 t = 
-100
+scanner.nextInt()
 ;%0A  
@@ -695,38 +695,32 @@
 tInt();%0A        
-final 
 double tempFinal
@@ -718,20 +718,35 @@
 temp
-Final = 1e-3
+Init = scanner.nextDouble()
 ;%0A  
@@ -743,38 +743,32 @@
 uble();%0A        
-final 
 double tempInit 
@@ -766,19 +766,36 @@
 temp
-Init = 10.0
+Final = scanner.nextDouble()
 ;%0A  
@@ -800,22 +800,16 @@
         
-final 
 double t
@@ -817,11 +817,28 @@
 u = 
-1e4
+scanner.nextDouble()
 ;%0A  
@@ -847,14 +847,8 @@
     
-final 
 int 
@@ -863,78 +863,103 @@
 p = 
-0;%0A%0A        Random random = new Random();%0A%0A        int t = 0
+scanner.nextInt();%0A        boolean verbose = (scanner.nextInt() == 0) ? false : true
 ;%0A
+%0A
         
 doub
@@ -958,30 +958,36 @@
     
-double temp = tempInit
+Random random = new Random()
 ;%0A%0A 
@@ -1088,68 +1088,8 @@
 E);%0A
-        //frame.setSize(width * 10 + 50, height * 10 + 50);%0A
     
@@ -1282,24 +1282,148 @@
 ridPanel);%0A%0A
+        int t = 0;%0A        double temp = tempInit;%0A%0A        if (!verbose)%0A            System.out.println(%22Simulating...%22);%0A%0A
         whil
@@ -2020,32 +2020,65 @@
 ip + 1) == 0) %7B%0A
+                if (verbose)%0A    
                 
@@ -2200,24 +2200,169 @@
 %7D%0A        %7D%0A
+        // Print the final state%0A        if (!verbose)%0A            System.out.format(%22Final state: %25d %25f %25d%5Cn%22, t, temp, gridPanel.getNDimers());
 %0A    %7D%0A%0A    

Read parameters from input file