#!/usr/bin/ruby
#
# Make an image file list in the format
# required by MB-System
#
# Assumes that this script is run from the
# 'usual' perls/bin directory.
#
# Defaults to the survey directory linked to
# by perls/bin/latest. Otherwise, uses the first
# argument as the survey directory.
#

##
# Go to the image directory and ensure that subdirectories exist
#
if (ARGV.length > 0)
  wd = ARGV[0]
else
  wd = "latest"  # Default directory
end
wd += "/images"

begin
  Dir.chdir(wd)
  raise "No \'left\' directory" unless (File.directory?("./left"))
  raise "No \'right\' directory" unless (File.directory?("./right"))
rescue Exception => e
  puts("Cannot find image directories at #{wd}: #{e}")
  exit
end
pwd = Dir.getwd
puts("Generating img_list.txt in #{pwd} ...")

##
# Open the image list file
#
list_file = File.new("imagelist.mb-2", "w")

##
# Populate the image list file
#
right = Dir["right/*.tif"]
left  = Dir["left/*.tif"]
