                        (dotimes [_ num-images]
                          (write-buf channel (.take filled-buffer-queue))))))))
 
+
+(defn write-test [num-images]
+  (let [filename (str "D:/AcquisitionData/deleteMe" (rand-int 100000) ".dat")
+        buf (image-to-byte-buffer (core getImage) (byte-buffer (* 2 n)))]
+    (println "\nparallel:" filename)
+    (with-open [file (RandomAccessFile. filename "rw")]
+               (time (let [channel (.getChannel file)]
+                       (dotimes [_ num-images]
+                         (write-buf channel buf)))))))
+
 (defn acquire-and-write-parallel [num-images]
-  (let [filename (str "E:/acquisition/deleteMe" (rand-int 100000) ".dat")]
-    (println filename)
-    ;(run-sequence-acquisition num-images false)
+  (let [filename (str "D:/AcquisitionData/deleteMe" (rand-int 100000) ".dat")]
+    (println "\nparallel:" filename)
     (with-open [file (RandomAccessFile. filename "rw")]
                (time (let [channel (.getChannel file)
+                           n (count (core getImage))
                            image-queue (queuify num-images 5 #(core getImage))
-                           empty-buffer-queue (queuify num-images 5 #(byte-buffer (* 2 n)))
+                           empty-buffer-queue (queuify 10 10 #(byte-buffer (* 2 n)))
                            filled-buffer-queue (queuify num-images 5 #(image-to-byte-buffer
                                                                         (.take image-queue)
                                                                         (.take empty-buffer-queue)))
                            ]
                        ;(println image-queue empty-buffer-queue filled-buffer-queue)
                        (dotimes [_ num-images]
-                         (write-buf channel (.take filled-buffer-queue))))))))
+                         (let [buf (.take filled-buffer-queue)]
+                           (write-buf channel buf)
+                           (.offer empty-buffer-queue buf))))))))
         
   
 
 ;; other tests
-
-(defn test-write [num-images]
-  (let [buffer (byte-buffer (* 2560 2160 2))
-        filename (str "D:/AcquisitionData/test" (rand-int 100000) ".dat")
-        file (RandomAccessFile. filename "rw")
-        channel (.getChannel file)]
-    (println filename)
-    (try
-      (dotimes [i num-images]; 100
-                     (.rewind buffer)
-        (.write channel buffer))
-      (catch Exception e (println e))
-      (finally
-        (.close file)))))  
 
 (defn monitor-circular-buffer []
   (while (not (core isSequenceRunning))
     (Thread/sleep 100))
   (while (core isSequenceRunning)
     (println (core getRemainingImageCount))
-    (Thread/sleep 250)))
+    (Thread/sleep 1000)))
 
 (defn drain-queue [blocking-queue]
   (future (loop [i 0]

(def corePop-memo (memoize #(core popNextImage)))

(defn acquire-and-write-to-disk [num-images]
  (let [filename (str "E:/acquisition/deleteMe" (rand-int 100000) ".dat")]
    (println filename)
    ;(run-sequence-acquisition num-images false)
    (with-open [file (RandomAccessFile. filename "rw")]
               (time (let [channel (.getChannel file)
                           image-queue (queuify num-images 5 #(core getImage))

           (java.nio.channels FileChannel$MapMode))
  (:require [org.micromanager.mm :as mm])
  (:use [org.micromanager.mm :only (core)]))

(defn queuify
  "Runs zero-arg function n times on another thread. Returns
