Weird errors that dont make sense to me

program Pyramid
    ! modules
    use :: Help
    use :: CompilerSettings
    
    ! variables
    implicit none
    integer                  :: argc
    integer                  :: i ! iterator
    character (len = 64)     :: arg
    type(CompilerSettings_t) :: settings

    ! code
    argc = command_argument_count()
    if (argc == 0) then
        call ShowHelp()
        stop 0
    end if

    do i = 0, argc
        call get_command_argument(i, arg)

        if (arg(0) == '-') then
            select case (arg(1))
                case ('h')
                    call ShowHelp()
                case default
                    print *, "Unknown argument " // arg
            end select
        else
            settings%input = arg
        end if
    end do
end program Pyramid
gfortran  -c src/main.f90 -Wall -Wextra -Werror -pedantic -std=f2003 -g -o bin/main.o
src/main.f90:28:55:

   28 |                     print *, "Unknown argument " // arg
      |                                                       1
Error: Function ‘arg’ requires an argument list at (1)
src/main.f90:31:32:

   31 |             settings%input = arg
      |                                1
Error: Function ‘arg’ requires an argument list at (1)
src/main.f90:21:37:

   21 |         call get_command_argument(i, arg)
      |                                     1
Error: In call to ‘get_command_argument’ at (1), type mismatch in argument ‘value’; pass ‘PROCEDURE’ to ‘CHARACTER(*)’

Shouldn’t arg in get_command_argument be an array of stings instead of a single string?

If not more is needed this array may contain a single element that is then used afterwards.

no, see GET_COMMAND_ARGUMENT (The GNU Fortran Compiler)

Without seeing the module definitions, it is difficult to comment.

" if (arg(0) == ‘-’) then " looks suspicious !

It looks that “arg” should be / is a character string, not an array of characters, so the processing of arg needs to be changed. The following may be more appropriate ?

    settings%input = ' '
    do i = 0, argc
        call get_command_argument(i, arg)

        if (arg(1:1) == '-') then
            select case (arg(2:2))
                case ('h')
                    call ShowHelp()
                case default
                    print *, "Unknown argument " // arg
            end select
        else
            settings%input = trim(settings%input) // ' ' // trim(arg)    ! should arg be appended
        end if
    end do

oh thanks

As defined here, arg is a function of type character(len=64). This is because it is referenced as arg(0). To get the first character of a variable arg you need arg(1:1).

John

@yeti0904 ,

So as you may have noticed, if you have a scalar object, say, of CHARACTER type of some length greater than the index / indices you plan to reference, then s(1:1) is a reference to the first character in that object; s(1:3) to a substring which is the first 3 characters; and s(m:n) for the substring referring to the mth thru’ nth characters.

If you have an array object (rank \geq 1) of CHARACTER type, say s_arr, then the same analogy holds except that you refer to the array element first e.g., s_arr(i)(1:3) for the first 3 characters of the array element i.