PROC define_ica (
  physical_data_array : array of string = $optional
  host_network        : string = $optional
  network_ids         : array of string = $optional
  system_ids          : array of string = $optional
  relays              : array of string = $optional
  ica_index1          : array of integer = $optional
  ica_index2          : array of integer = $optional
  physical_entries    : integer = $optional
  lcu_entries         : var of integer = $optional
  status              : var of status = $optional
  )

" Make local copies of the procedure parameters.

  physical_data = $value(physical_data_array)
  host_network_id = $value(host_network)
  network_id_array = $value(network_ids)
  system_id_array = $value(system_ids)
  rr_array = $value(relays)
  ica_element1_index = $value(ica_index1)
  ica_element2_index = $value(ica_index2)
  number_physical_entries = $value(physical_entries)
  number_lcu_entries = $value(lcu_entries)

  create_variable (choice cr_requested) k=string
  create_variable choice_to_lcu_map k=integer d=9 v=0
  create_variable (i j max_choice number_used) k=integer
  create_variable conversion_status k=status
  create_variable ica2_in_use k=boolean
  create_variable lcu_index k=integer
  create_variable network_access_count k=integer
  create_variable successful k=boolean

check_if_ica_available: ..
  BLOCK
    FOR i = 1 TO number_physical_entries DO
      IF ($substr(physical_data(i), 5, 4) = 'ICA2') THEN
        ica2_in_use = FALSE
        FOR j = 1 TO number_lcu_entries DO
          IF ((ica_element1_index(j) = i) OR (ica_element2_index(j) = i)) AND ..
             ((network_id_array(j) <> ' ') AND (system_id_array(j) <> ' ')) THEN
            ica2_in_use = TRUE
          IFEND
        FOREND
        IF NOT ica2_in_use THEN
          EXIT check_if_ica_available
        IFEND
      ELSE
        EXIT check_if_ica_available
      IFEND
    FOREND
    put_line ( '0No ICA''s available for network access definition.' ..
               ' All ICA-II''s have been defined in OSI mode.')
    accept_line cr_requested input p='Press NEXT: '
    EXIT_PROC
  BLOCKEND check_if_ica_available

main_loop: ..
  LOOP

    network_access_count = 0
    FOR i = 1 to number_lcu_entries DO
      IF (network_id_array(i) <> ' ') AND (system_id_array(i) = ' ') THEN
        network_access_count = network_access_count + 1
      IFEND
    FOREND
    IF network_access_count = 0 THEN

      lcu_index = number_lcu_entries + 1
      prompt_for_network_access physical_data host_network_id number_physical_entries ica_element1_index ..
            ica_element2_index network_id_array(lcu_index) rr_array(lcu_index) ica_element1_index(lcu_index) ..
            ica_element2_index(lcu_index) number_lcu_entries
      IF ica_element1_index(lcu_index) = 0 THEN
        EXIT main_loop
      IFEND

    ELSE

      put_line (..
            '1Define Network Accesses'..
            '0   Network          Relays                                   Channel Serial ' ..
            '    Identifier     Restricted Element Name                     Number Number '..
            '  ')
      number_used = 0
      max_choice = 0
      FOR i = 1 TO number_lcu_entries DO
        number_used = number_used + 1
        IF system_id_array(i) = ' ' THEN
          max_choice = max_choice + 1
          choice_to_lcu_map(max_choice) = i
          put_line ' '//$strrep(max_choice)//'. '//$substr(network_id_array(i), 1, 15, ' ')//$substr(' ', 1, ..
                6-$strlen(rr_array(i)))//rr_array(i)//'    '//$substr(..
                physical_data(ica_element1_index(i)), 9, 50)
          IF ica_element2_index(i) <> 0 THEN
            number_used = number_used + 1
            put_line $substr(' ', 1, 29)//$substr(physical_data(ica_element2_index(i)), 9, 50)
          IFEND
        IFEND
      FOREND
      IF (number_used < number_physical_entries) THEN
        max_choice = max_choice + 1
        choice_to_lcu_map(max_choice) = number_lcu_entries + 1
        put_line (' '//$strrep(max_choice)//'. Define another network access.')
      IFEND
      put_line '0Enter a menu selection, QUIT, GO, or ?: '
      choice = ''
      accept_line choice input p=''
      IF (choice = '?') OR ($translate(lower_to_upper, choice) = 'HELP') THEN

        put_line (..
          '0This menu prompts you to define the network configuration of your '..
          ' mainframe.  The network configuration defines how the mainframe '..
          ' accesses one or more ethernet networks, ie. which 2629_1 or $2629_2 '..
          ' Integrated Communications Adapters (ICA) connect to which ethernets. '..
          ' The menu selections above show the current network accesses defined. '..
          ' If more than one ICA connects to the same ethernet, the secondary '..
          ' one is displayed on a separate line. '..
          '0Enter a menu selection to modify the parameters for a network access '..
          '   or define an additional network access (if that option is displayed).'..
          ' Enter GO or press NEXT to install the network configuration you have'..
          '   defined.'..
          ' Enter QUIT to return to the main menu without installing the '..
          '   configuration.  Any network configuration parameters you have set'..
          '   will be lost. '..
          '  ')
        accept_line cr_requested input p='Press NEXT: '

      ELSEIF ($translate(lower_to_upper, choice) = 'QUIT') OR ($translate(lower_to_upper, choice) = 'QUI') ..
            THEN

        EXIT main_loop

      ELSEIF (choice = ' ') OR ($translate(lower_to_upper, choice) = 'GO') THEN

        install_network_config_file FALSE host_network_id network_id_array system_id_array rr_array ..
            physical_data number_physical_entries number_lcu_entries ica_element1_index ..
            ica_element2_index successful
        IF successful THEN
          $value(network_ids) = network_id_array
          $value(relays) = rr_array
          $value(ica_index1) = ica_element1_index
          $value(ica_index2) = ica_element2_index
          $value(lcu_entries) = number_lcu_entries
          EXIT main_loop
        IFEND

      ELSE

        include_line 'i = $integer(choice)' status=conversion_status
        IF conversion_status.normal THEN
          IF (i >= 1) AND (i <= max_choice) THEN
            prompt_for_network_access physical_data host_network_id number_physical_entries ica_element1_index ..
                  ica_element2_index network_id_array(choice_to_lcu_map(i)) rr_array(choice_to_lcu_map(i)) ..
                  ica_element1_index(choice_to_lcu_map(i)) ica_element2_index(choice_to_lcu_map(i)) ..
                  number_lcu_entries
            CYCLE main_loop
          IFEND
        IFEND
        put_line '  '
        accept_line cr_requested input p='Invalid selection, press NEXT: '

      IFEND

    IFEND

  LOOPEND main_loop

PROCEND define_ica
