 (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)
+  (let [filename (str "D:/AcquisitionData/deleteMe" (rand-int 100000) ".dat")]
+    (println "\nto disk:" filename)
     (with-open [file (RandomAccessFile. filename "rw")]
                (time (let [channel (.getChannel file)
                            image-queue (queuify num-images 5 #(core getImage))

                       (dotimes [_ num-images]
                         (write-buf channel (.take filled-buffer-queue))))))))

(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)
    (with-open [file (RandomAccessFile. filename "rw")]
               (time (let [channel (.getChannel file)
                           image-queue (queuify num-images 5 #(core getImage))
                           empty-buffer-queue (queuify num-images 5 #(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))))))))
        
  

;; 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)))

(defn drain-queue [blocking-queue]
  (future (loop [i 0]

  (.. ByteBuffer (allocateDirect size-bytes)
      (order (ByteOrder/nativeOrder))))

(def byte-buffer-memo (memoize byte-buffer))

(defn image-to-byte-buffer
  "Store 16-bit image pixel array data in a
   pre-existing byte buffer instance."
