def open_file(file)
      # Check if file already exists:
      if File.exist?(file)
        # Is (the existing file) writable?
        unless File.writable?(file)
          raise "The program does not have permission or resources to create this file: #{file}"
        end
      else
        # File does not exist.
        # Check if this file's path contains a folder that does not exist, and therefore needs to be created:
        folders = file.split(File::SEPARATOR)
        if folders.length > 1
          # Remove last element (which should be the file string):
          folders.pop
          path = folders.join(File::SEPARATOR)
          # Check if this path exists:
          unless File.directory?(path)
            # We need to create (parts of) this path:
            require 'fileutils'
            FileUtils.mkdir_p(path)
          end
        end
      end
      # It has been verified that the file can be created:
      return File.new(file, 'wb:ISO8859-1')
    end
def open_file(file)
      # Check if file already exists:
      if File.exist?(file)
        # Is (the existing file) writable?
        unless File.writable?(file)
          raise "The program does not have permission or resources to create this file: #{file}"
        end
      else
        # File does not exist.
        # Check if this file's path contains a folder that does not exist, and therefore needs to be created:
        folders = file.split(File::SEPARATOR)
        if folders.length > 1
          # Remove last element (which should be the file string):
          folders.pop
          path = folders.join(File::SEPARATOR)
          # Check if this path exists:
          unless File.directory?(path)
            # We need to create (parts of) this path:
            require 'fileutils'
            FileUtils.mkdir_p(path)
          end
        end
      end
      # It has been verified that the file can be created:
      return File.new(file, 'wb:ISO8859-1')
    end
Tests if the path/file is writable, creates any folders if necessary, and opens the file for writing.

 @param [String] file a path/file string
 @raise if the given file cannot be created