Silverfrost Forums

Welcome to our forums

get_command_argument

14 Feb 2022 1:36 #28774

integer, external :: get_arg_num (n), as a function,

I started trying to quickly write a simple integer function in Plato to return the value of the n'th argument, but got an ICE when compiling using FTN95 8.80.0.

I can't see what I have done wrong ? Is an internal read in a function a problem ? I have made a few changes, but the ICE remains.

  integer function get_arg_num (n)
    integer :: n, i, iostat
    character(16) :: arg

    call get_command_argument (n, arg)

    read (arg,fmt='(bn,i16)', iostat=iostat) i
    if ( iostat /= 0 ) then
      write (*,12) n,arg
 12   format ('Unable to obtain number from arg ',i0,' :',a)
      i = 0
    end if
    get_arg_num = i
  end function get_arg_num

  subroutine get_arg_val (n, i)
    integer :: n, i, iostat, L
    character(16) :: arg

    call get_command_argument (n, arg, L)

!    read (arg,fmt='(bn,i16)', iostat=iostat) i
    read (arg,11, iostat=iostat) i
 11 format (bn,i16)
    if ( iostat /= 0 ) then
      write (*,12) n,arg
 12   format ('Unable to obtain number from arg ',i0,' :',a)
      i = 0
    end if
!    get_arg_num = i
  end subroutine get_arg_val

My ftn95.cfg is /ERROR_NUMBERS /ECHO_OPTIONS /IMPLICIT_NONE /INTL /LOGL

The following also fails ? subroutine get_arg_string (n, arg) integer :: n character*16 :: arg, string

    call get_command_argument (n, string)
    arg = string

  end subroutine get_arg_string
14 Feb 2022 1:55 #28775

It looks to work ok with FTN95 Ver 8.62.0

14 Feb 2022 7:40 #28776

It is interesting that it compiles with extra declared integers, as subroutine get_arg_string (n, arg) integer :: n, l, stat character*16 :: arg, string

    call get_command_argument (n, string)
    arg = string

  end subroutine get_arg_string

but ICE with the in-line comment or multiple routines subroutine get_arg_string (n, arg) integer :: n, l, stat character*16 :: arg, string

    call get_command_argument (n, string)
    arg = string

  end subroutine get_arg_string

  subroutine get_arg_str (n, arg)
    integer :: n, l, stat   ! inline comment
    character*16 :: arg, string

    call get_command_argument (n, string)
    arg = string

  end subroutine get_arg_str

and fails if 2 routines are together, even without the in-line comment

14 Feb 2022 10:21 #28778

John

Thanks for the feedback. I have logged this for investigation.

15 Feb 2022 8:18 #28785

A regression at about 8.72 has the effect that the first argument of get_command_argument must not itself be an argument.

So a temporary work-around is to copy n to i (say) before the call...

    i = n
    call get_command_argument (i, arg)
15 Feb 2022 9:19 #28786

This regression has now been fixed for the next release of FTN95.

15 Feb 2022 12:36 #28789

Paul,

Thanks for the quick clarification. I can use that work-around.

John

Please login to reply.