def write_elements(options={})
      # Check if we are able to create given file:
      open_file(options[:file_name])
      # Go ahead and write if the file was opened successfully:
      if @file
        # Initiate necessary variables:
        @transfer_syntax = options[:syntax]
        # Until a DICOM write has completed successfully the status is 'unsuccessful':
        @write_success = false
        # Default explicitness of start of DICOM file:
        @explicit = true
        # Default endianness of start of DICOM files (little endian):
        @str_endian = false
        # When the file switch from group 0002 to a later group we will update encoding values, and this switch will keep track of that:
        @switched = false
        # Items contained under the Pixel Data element needs some special attention to write correctly:
        @enc_image = false
        # Create a Stream instance to handle the encoding of content to a binary string:
        @stream = Stream.new(nil, @str_endian)
        # Tell the Stream instance which file to write to:
        @stream.set_file(@file)
        # Write the DICOM signature:
        write_signature if options[:signature]
        write_data_elements(children)
        # As file has been written successfully, it can be closed.
        @file.close
        # Mark this write session as successful:
        @write_success = true
      end
    end
def write_elements(options={})
      # Check if we are able to create given file:
      open_file(options[:file_name])
      # Go ahead and write if the file was opened successfully:
      if @file
        # Initiate necessary variables:
        @transfer_syntax = options[:syntax]
        # Until a DICOM write has completed successfully the status is 'unsuccessful':
        @write_success = false
        # Default explicitness of start of DICOM file:
        @explicit = true
        # Default endianness of start of DICOM files (little endian):
        @str_endian = false
        # When the file switch from group 0002 to a later group we will update encoding values, and this switch will keep track of that:
        @switched = false
        # Items contained under the Pixel Data element needs some special attention to write correctly:
        @enc_image = false
        # Create a Stream instance to handle the encoding of content to a binary string:
        @stream = Stream.new(nil, @str_endian)
        # Tell the Stream instance which file to write to:
        @stream.set_file(@file)
        # Write the DICOM signature:
        write_signature if options[:signature]
        write_data_elements(children)
        # As file has been written successfully, it can be closed.
        @file.close
        # Mark this write session as successful:
        @write_success = true
      end
    end
Handles the encoding of DICOM information to string as well as writing it to file.

 @param [Hash] options the options to use for encoding the DICOM string
 @option options [String] :file_name the path & name of the DICOM file which is to be written to disk
 @option options [Boolean] :signature if true, the 128 byte preamble and 'DICM' signature is prepended to the encoded string
 @option options [String] :syntax the transfer syntax used for the encoding settings of the post-meta part of the DICOM string