PROCEDURE (ram$duplv) duplicate_labeled_volume, duplv (
  input_volume, iv: record
      recorded_vsn: any of
        name 1..6
        string 1..6
      anyend
      external_vsn: any of
        name 1..6
        string 1..6
      anyend = $optional
    recend = $required
  output_volume, ov: record
      recorded_vsn: any of
        name 1..6
        string 1..6
      anyend
      external_vsn: any of
        name 1..6
        string 1..6
      anyend = $optional
    recend = $required
  expiration_date, ed: (BY_NAME) any of
    key
      $unspecified
      (expired, e)
    keyend
    date
    time_increment
  anyend = $optional
  file_accessibility, fa: (BY_NAME, SECURE) any of
      key
        none
      keyend
      name 1..1
      string 1
    anyend = $optional
  file_set_identifier, fsi: (BY_NAME) any of
      name 1..6
      string 1..6
    anyend = $optional
  input_density, id: (BY_NAME) key
      mt9$800, mt9$1600, mt9$6250, mt18$38000
    keyend = osd$reqmt_default_density, mt9$1600
  output_density, od: (BY_NAME) key
      mt9$800, mt9$1600, mt9$6250, mt18$38000
    keyend = $optional
  owner_identifier, oi: (BY_NAME, SECURE) any of
      key
        none
      keyend
      name 1..14
      string 1..14
    anyend = $optional
  removable_media_group, rmg: (BY_NAME, SECURE) any of
      name 1..13
    anyend = $optional
  volume_accessibility, va: (BY_NAME, SECURE) any of
      key
        none
      keyend
      name 1..1
      string 1
    anyend = $optional
  status)

  TYPE
    vol_descriptor = record
    recorded_vsn: any of
    name 1..6
    string 1..6
    anyend
    external_vsn: any of
    name 1..6
    string 1..6
    anyend
    recend
  TYPEND

  VAR
    ignore_status: status
    input: file = $unique($local)
    in_vol: vol_descriptor
    local_status: status
    output: file = $unique($local)
    out_vol: vol_descriptor
    parameter_names: list of key mt9$800, mt9$1600, mt9$6250, mt18$38000 keyend=
    (mt9$800, mt9$1600, mt9$6250, mt18$38000)
    parameter_values: list of integer 0..2147483647 = (0 0 0 0)
    temp: file = $unique($local)
  VAREND

  WHEN any_fault exit terminate DO
    delete_file input status= ignore_status
    delete_file output status= ignore_status
    delete_file temp status= ignore_status
    release_resource mt9$800=all mt9$1600=all mt9$6250=all mt18$38000=all ..
          status=ignore_status
    EXIT duplicate_labeled_volume WITH osv$status
  WHENEND

  in_vol.recorded_vsn = input_volume.recorded_vsn
  IF $field(input_volume external_vsn specified) THEN
    in_vol.external_vsn = input_volume.external_vsn
  ELSE
    in_vol.external_vsn = in_vol.recorded_vsn
  IFEND

  out_vol.recorded_vsn = output_volume.recorded_vsn
  IF $field(output_volume external_vsn specified) THEN
    out_vol.external_vsn = output_volume.external_vsn
  ELSE
    out_vol.external_vsn = out_vol.recorded_vsn
  IFEND

  request_magnetic_tape input density=input_density ..
        recorded_vsn=in_vol.recorded_vsn external_vsn=in_vol.external_vsn ..
        ring=no

  IF $specified(output_density) THEN
    request_magnetic_tape output density=output_density ..
          recorded_vsn=out_vol.recorded_vsn ..
          external_vsn=out_vol.external_vsn ring=yes
    local_output_density = output_density
  ELSE
    request_magnetic_tape output density=input_density ..
          recorded_vsn=out_vol.recorded_vsn ..
          external_vsn=out_vol.external_vsn ring=yes
    local_output_density = input_density
  IFEND

  FOR i = 1 TO $size(parameter_names) DO
    IF input_density = parameter_names(i) THEN
      parameter_values(i) = parameter_values(i) + 1
    IFEND
    IF local_output_density = parameter_names(i) THEN
      parameter_values(i) = parameter_values(i) + 1
    IFEND
  FOREND

  reserve_resource mt9$800=parameter_values(1) mt9$1600=parameter_values(2) ..
        mt9$6250=parameter_values(3) mt18$38000=parameter_values(4)

  change_tape_label_attributes input file_set_position=next_file ..
        file_accessibility= file_accessibility ..
        owner_identifier= owner_identifier ..
        volume_accessibility= volume_accessibility rewrite_labels= false

  change_tape_label_attributes output file_set_position=next_file ..
        expiration_date=expiration_date ..
        file_accessibility=file_accessibility ..
        file_set_identifier=file_set_identifier ..
        owner_identifier=owner_identifier ..
        removable_media_group=removable_media_group ..
        volume_accessibility=volume_accessibility rewrite_labels=true

  FOR i = 1 TO 9999 DO
    copy_file input temp status=local_status
    IF local_status.normal THEN
      input_attrib = $tape_label_attributes(input last_accessed block_type, ..
            character_conversion, character_set, creation_date, ..
            expiration_date, file_identifier, file_set_identifier, ..
            generation_number, generation_version_number, ..
            maximum_block_length, maximum_record_length, padding_character, ..
            record_type)

      change_tape_label_attributes output ..
            block_type=input_attrib.block_type ..
            character_conversion= input_attrib.character_conversion ..
            character_set= input_attrib.character_set ..
            creation_date= input_attrib.creation_date ..
            file_identifier= input_attrib.file_identifier ..
            generation_number= input_attrib.generation_number ..
            generation_version_number= input_attrib.generation_version_number ..
            maximum_block_length= input_attrib.maximum_block_length ..
            maximum_record_length= input_attrib.maximum_record_length ..
            padding_character= input_attrib.padding_character ..
            record_type= input_attrib.record_type

      IF NOT $specified(file_set_identifier) THEN
        change_tape_label_attributes output ..
              file_set_identifier= input_attrib.file_set_identifier
      IFEND

      IF NOT $specified(expiration_date) THEN
        change_tape_label_attributes output ..
              expiration_date= input_attrib.expiration_date
      IFEND

      copy_file temp output
      delete_file temp
      delete_variable input_attrib
    ELSE
      IF i > 1 THEN
        EXIT_PROC
      ELSE
        EXIT_PROC WITH local_status
      IFEND
    IFEND
  FOREND

PROCEND duplicate_labeled_volume
