         runs (get plan :runs [0])
         cache (read-hyperspectral-cache hs-cache-filename)
         samples (get plan :samples [2500000])
-        embed (get plan :embed true)]
+        embed (get plan :embed true)
+        save-every (get plan :save-every)]
     (doseq [image-count samples
             run runs]
       (if verbose
         (println (format "Simulating %d retinas with %d samples from cache %s (run = %d)..."
                          (count my-retinas) image-count hs-cache-filename run)))
-      (let [corr-mtcs (if verbose
-                        (simulate-retinas
-                         my-retinas cache
-                         :image-count image-count
-                         :init-reduce (cons [0 nil] (repeat (dec (count my-retinas)) nil))
-                         :analysis (cons (fn [[iter dat] sig]
-                                           (if (= 0 (mod iter 1000))
-                                             (println "Iteration " iter "..."))
-                                           [(inc iter) (correlation-analysis dat sig)])
-                                         (repeat (dec (count my-retinas)) correlation-analysis))
-                         :finish (cons (fn [[iter dat]]
-                                         (println "Simulation complete after " iter " iterations.")
-                                         (correlation-analysis dat))
-                                       (repeat (dec (count my-retinas)) correlation-analysis)))
-                        (simulate-retinas my-retinas (val cache) :image-count image-count))
+      (let [[inits analfns finfns] (make-analysis save-every
+                                                  (when verbose print-every)
+                                                  my-retinas
+                                                  run
+                                                  embed)
+            corr-mtcs (simulate-retinas my-retinas cache
+                                        :image-count image-count
+                                        :init-reduce inits
+                                        :analysis analfns
+                                        :finish finfns)
             flnms (map #(str output-dir "/" (simulation-filename % image-count run)) my-retinas)]
         (doall
          (map #(write-simulation %1 %2 %3 :embed embed)

                 :sizes [20]
                 :S-cone-flags [:human]
                 :samples [2500000]
                 :runs [1 2]}
      :standard {:surrounds [[0.25 3.0] nil]
                 :L-to-Ms [[16 1] [8 1] [4 1] [2 1] [1 1] [1 2] [1 4] [1 8] [1 16]]
                 :M-lambda-maxs [530.3 535 540 545 550 555]

                 :else ""))
         "].bin")))

;; used when setting up retina simulations automatically by simulate-some-retinas
(defn- analysis-print-every [[analfn finfn every-k iter dat] sig]
  (if (= 0 (mod iter every-k))
    (println (format "Iteration %8d..." iter)))
  [analfn finfn every-k (inc iter) (analfn dat sig)])
(defn- finish-print-every [[analfn finfn every-k iter dat]]
  (println "Simulation finished after " iter " iterations.")
  (finfn dat))
(defn- analysis-save-every [[analfn finfn R run embed every-k iter dat] sig]
  (if (and (> iter 0) (= 0 (mod iter every-k)))
    (write-simulation (simulation-filename R iter run :embed embed) R (finfn dat)))
  [analfn finfn R run every-k (inc iter) (analfn dat sig)])
(defn- finish-save-every [[analfn finfn R run embed every-k iter dat]]
  (finfn dat))
(defn- init-print-every [analfn finfn every-k start-dat]
  [analfn finfn every-k 0 start-dat])
(defn- init-save-every [analfn finfn R run embed every-k start-dat]
  [analfn finfn R run every-k 0 start-dat])
(defn- make-analysis [save-every print-every Rs run embed]
  (let [n (count Rs)
        [init1 anal1 fin1]
        (if save-every
          [(map #(init-save-every correlation-analysis correlation-analysis
                                  %1 run embed save-every nil)
                Rs)
           (repeat n analysis-save-every)
           (repeat n finish-save-every)]
          [(repeat n nil) (repeat n correlation-analysis) (repeat n correlation-analysis)])]
    (if print-every
      [(cons (init-print-every (first anal1) (first fin1) print-every (first init1))
             (next init1))
       (cons analysis-print-every (next anal1))
       (cons finish-print-every (next fin1))]
      [init1 anal1 fin1])))

;; a function for simulating some of the retinas; given the total number of jobs and
;; a a job id, this will simulate and write out the results for the appropriate chunk
;; of simulations from the given set. The plan should be :basic or :standard.
(defn simulate-some-retinas [plan-id hs-cache-filename output-dir total-nodes node-id
                             &{:keys [verbose print-every] :or {print-every 10000}}]
  (let [plan (get simulation-plans plan-id)
        plan-retinas (retinas-from-plan plan)
        my-retinas (if (coll? node-id)
