   (let [path (.toString hdf-file)]
     (metadata (gdal/Open path) "SUBDATASETS")))
 
+(defn raster-array
+  "Unpacks the data inside of a MODIS band into a 1xN integer array."
+  [^Dataset data]
+  (let [band (.GetRasterBand data 1)
+        type (gdalconstConstants/GDT_UInt16)
+        width (.GetXSize band)
+        height (.GetYSize band)
+        ret (int-array (* width height))]
+    (do (.ReadRaster band 0 0 width height type ret)
+        ret)))
+
 ;; ##Cascalog Custom Functions
 ;; These guys actually get called by the queries inside of core.
 
 (defmapop
-  #^{:doc "Generates metadata values for a given unpacked MODIS Dataset and a seq of keys."}
+  #^{:doc "Generates metadata values for a given unpacked MODIS
+Dataset and a seq of keys."}
   [meta-values [meta-keys]] [modis]
   (let [metadata (metadata modis "")]
     (map #(.get metadata %) meta-keys)))
 
 (defmapcatop
-  #^{:doc "Stateful approach to unpacking HDF files. Registers all gdal formats,
-Creates a temp directory, then saves the byte array to disk. This byte
-array is processed with gdal, and then the temp directory is destroyed.
-Function returns the decompressed MODIS file as a 1-tuple."}
+  #^{:doc "Stateful approach to unpacking HDF files. Registers all
+gdal formats, Creates a temp directory, then saves the byte array to
+disk. This byte array is processed with gdal, and then the temp
+directory is destroyed. Function returns the decompressed MODIS file
+as a 1-tuple."}
   unpack {:stateful true}
   ([]
      (do

  #^{:doc "Default set of data for FORMA processing."}
  *forma-subsets*
  #{:ndvi :evi :qual :reli})

;; ##Helper Functions
;; These are organized fairly well... more docs later.


(defn subdataset-filter
  "Generates a predicate function that compares Hashtable entries to a supplied
   set of acceptable keys. These keys should exist in *modis-subsets*."
  [good-keys]
  (let [kept-substrings (map *modis-subsets* good-keys)]
    (fn [entry]
      (let [val (.getValue entry)
            key (.getKey entry)]
        (and (s/substring? "_NAME" key)
             (some #(s/substring? % val) kept-substrings))))))

(def forma-dataset? (subdataset-filter *forma-subsets*))

