 
 (defn- get-avg-gran-size
   "Gets SizeEstimation value for AverageSizeOfGranulesSampled and parses it to a number."
-  [vars]
-  (let [value (get-in (first vars) [:umm :SizeEstimation :AverageSizeOfGranulesSampled])]
-    (if (string? value)
-      (read-string value)
-      value)))
-
-(defn- get-avg-compression-rate
+  [variable]
+  (-> variable
+      (get-in [:umm :SizeEstimation :AverageSizeOfGranulesSampled])
+      read-number))
+
+(defn- get-avg-compression-rate-ascii
   "Gets SizeEstimation value for AvgCompressionRateASCII and parses it to a number."
-  [vars]
-  (let [value (get-in (first vars) [:umm :SizeEstimation :AvgCompressionRateASCII])]
-    (if (string? value)
-      (read-string value)
-      value)))
+  [variable]
+  (-> variable
+      (get-in [:umm :SizeEstimation :AvgCompressionRateASCII])
+      read-number))
+
+(defn- get-avg-compression-rate-netcdf4
+  "Gets SizeEstimation value for AvgCompressionRateNetCDF4 and parses it to a number."
+  [variable]
+  (-> variable
+      (get-in [:umm :SizeEstimation :AvgCompressionRateNetCDF4])
+      read-number))
 
 (defn estimate-dods-size
+  "Calculates the estimated size for DODS format."
   [granule-count variables]
   (let [compression 1
         metadata 0 ; included here for symmetry

    (+ (* granule-count compression measurements) metadata)))

(defn- estimate-netcdf3-size
  [granule-count variables metadata]
  (let [compression 1
        measurements (reduce + (map get-measurement variables))]
    (+ (* granule-count compression measurements) metadata)))

(defn- estimate-ascii-size
  "Calculates the estimated size for ASCII format."
  [granule-count variables params]
  (let [metadata 0
        avg-gran-size (get-avg-gran-size variables)
        edsc-size-estimate (read-string (:edsc-size-estimate params))
        avg-compression-rate (get-avg-compression-rate variables)
        measurements (reduce + (map get-measurement variables))]
    (* edsc-size-estimate (+ (* (/ (/ edsc-size-estimate granule-count) avg-gran-size) avg-compression-rate) metadata))))

(defn- -estimate-size
  [fmt granule-count vars granule-metadata-size params]
  (case (keyword (string/lower-case fmt))
    :dods (estimate-dods-size granule-count vars)
    :nc (estimate-netcdf3-size granule-count vars granule-metadata-size)
    :ascii (estimate-ascii-size granule-count vars params)
    (do
      (log/errorf "Cannot estimate size for %s (not implemented)." fmt)
      {:errors ["not-implemented"]})))

;;; Note that all internal operations for estimating size are performed
;;; assuming bytes as the units.

(defn- read-number
  "If value is string, read-string.  Otherwise ignore."
  [value]
  (if (string? value)
    (read-string value)
    value))

(defn- get-measurement
  [variable]
  (let [dims (get-in variable [:umm :Dimensions])
