parse_int_array Subroutine

private subroutine parse_int_array(varnam, varval, isub1, n, description, icode, startindex)

Routine that obtains the values of an integer array from the input file author: P J Knight, CCFE, Culham Science Centre varnam : input string : name of the variable varval(n) : input/output integer array : value of the variable isub1 : input integer : array element pointer n : input integer : size of varval array icode : output integer : diagnostic flag description : input string : brief description of the variable This routine parses a line in one of the two following forms:

 name = v1[, v2, ...]
 name(element) = v
 

to read in and extract one or more values for an integer 1-D array.

N.B. No array bounds or value range checking is performed. None

Arguments

Type IntentOptional AttributesName
character(len=*), intent(in) :: varnam
integer, intent(inout), dimension(n):: varval
integer, intent(inout) :: isub1
integer, intent(in) :: n
character(len=*), intent(in) :: description
integer, intent(out) :: icode
integer, intent(in), optional :: startindex

Contents

Source Code


Source Code

  subroutine parse_int_array(varnam,varval,isub1,n,description,icode,startindex)

    !! Routine that obtains the values of an integer array
    !! from the input file
    !! author: P J Knight, CCFE, Culham Science Centre
    !! varnam : input string : name of the variable
    !! varval(n) : input/output integer array : value of the variable
    !! isub1 : input integer : array element pointer
    !! n : input integer : size of varval array
    !! icode : output integer : diagnostic flag
    !! description : input string : brief description of the variable
    !! This routine parses a line in one of the two following forms:
    !! <PRE>
    !! name = v1[, v2, ...]
    !! name(element) = v
    !! </PRE>
    !! to read in and extract one or more values for an integer 1-D array.
    !! <P>N.B. No array bounds or value range checking is performed.
    !! None
    !
    ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    implicit none

    !  Arguments
    character(len=*), intent(in) :: varnam, description
    integer, intent(inout) :: isub1
    integer, intent(in) :: n
    integer, intent(out) :: icode
    integer, dimension(n), intent(inout) :: varval
    integer, intent(in), optional :: startindex

    !  Local variables
    integer :: oldval, val
    ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    !  Check whether a subscript was found by the preceding call to GET_VARIABLE_NAME

    if (subscript_present) then

       oldval = varval(isub1)
       call get_value_int(val,icode)

       if (icode /= 0) then
          write(*,*) 'Error in IN.DAT found at line ',lineno
          write(*,*) 'Variable name, description:'
          write(*,*) varnam, ', ', description
          error = .True.
       end if

       varval(isub1) = val
       if ((report_changes == 1).and.(varval(isub1) /= oldval)) then
          write(outfile,10) trim(description),', ', &
               trim(varnam),'(',isub1,') = ',varval(isub1)
       end if

   else  ! subscript is not present

       isub1 = 1
       if(present(startindex))isub1 = startindex
       do
          call get_value_int(val,icode)

          !  icode == 1 denotes an error
          !  icode == -1 denotes end of line
          if (icode /= 0) then
              ! Make sure isub1 = the last array index
              isub1 = isub1 - 1
              return
          end if

          oldval = varval(isub1)
          varval(isub1) = val
          if ((report_changes == 1).and.(varval(isub1) /= oldval)) then
             write(outfile,10) trim(description),', ', &
                  trim(varnam),'(',isub1,') = ',varval(isub1)
          end if
          isub1 = isub1 + 1
       end do

    end if

10  format(a,a,a,a1,i3,a,i12)

  end subroutine parse_int_array