 
 (defmain BucketForma [source-path results-path & codes]
   (bucket-forma source-path results-path codes))
+
+(defmapop [find-first [re]]
+  [s]
+  (re-find re s))
+
+(defmain BucketCountry
+  [source-path dest-path]
+  (let [src (hfs-textline source-path)]
+    (?<- (hfs-textline dest-path
+                       :sinkmode :replace
+                       :sink-template "%s/"
+                       :templatefields ["?datestring"]
+                       :outfields ["?text"]
+                       :sinkparts 3)
+         [?datestring ?text]
+         (src ?text)
+         (find-first [#"[^\s]+"] ?text :> ?datestring))))
 
 ;; ## Rain Processing, for Dan
 ;;

                                             ["ecoid"] ["gadm"]
                                             ["border"]])]
    (?<- (hfs-textline out-path
                       :sinkparts 3
                       :sink-template "%s/")
         [?country ?lat ?lon ?mod-h ?mod-v ?sample ?line ?hansen ?ecoid ?vcf ?gadm ?border]

         (>= ?vcf 25))))

;; ## Forma
(def forma-run-parameters
  {"1000-32" {:est-start "2005-12-01"
              :est-end "2011-07-01"
