#!/usr/bin/ruby
require 'date'

unless (ARGV.length == 1)
  puts("A single filename argument is required")
  exit(1)
end

imgfile  = ARGV[0]
unless (File.file?(imgfile))
  puts("#{imgfile} not found")
  exit(1)
end

result = 1
min = "Unknown"    # emit nothing if no collection time is present

basefile = File.basename(imgfile, ".tiff")
# Look for "_NNmin_" in file name
item = basefile.scan(/_\d+min_/)

# If match found extract and emit the result
if (item.length == 1)
    min = item[0].scan(/\d+/)
    result = 0
end

# emit the results
puts(min)
exit(result)
