Logo

Programming-Idioms

History of Idiom 162 > diff from v11 to v12

Edit summary for version 12 by tkoenig:
New Fortran implementation by user [tkoenig]

Version 11

2019-09-28, 09:20:51

Version 12

2019-09-28, 10:07:04

Idiom #162 Execute procedures depending on options

execute bat if b is a program option and fox if f is a program option.

Idiom #162 Execute procedures depending on options

execute bat if b is a program option and fox if f is a program option.

Code
  do i=1, command_argument_count ()
     call get_command_argument (i, length=length)
     if (length > len(opt)) then
        deallocate (opt)
        allocate (character(length) :: opt)
     end if
     call get_command_argument (i, opt)
     if (opt(1:1) /= '-') exit
     do j=2, length
        select case (opt(j:j))
        case ('b')
           print *,"bat"
        case ('f')
           print *,"fox"
        end select
     end do
  end do
Comments bubble
This implements standard Unix conventions, so -bf is equivalent to -b -f. i, j and length are integers, opt is a character(len=:), allocatable .