      subroutine args(argdim,argmx,argt,argtl)

c     Copyright 2012 Leon van Dommelen.  This software is made available
c     under the GNU Public License version 3.

c     Get the arguments from the command line.

c     Trailing whitespace is eliminated, except that empty arguments
c     return as the first whitespace character.

c     This version for g77.

      implicit none

c input:

c     declared number of arguments
      integer argdim

c output:

c     number of arguments
      integer argmx

c     arguments
      character*256 argt(argdim)
      integer argtl(argdim)

c local:

c     argument index
      integer arg

c     character index
      integer i

c     returns command line parameters
      integer iargc
      external iargc,getarg

c executable:

c     get number of command arguments
      argmx=iargc()

c     get the arguments
      do 100 arg=1,min(argmx,argdim)
         argt(arg)=' '
         call getarg(arg,argt(arg))
         if(argt(arg)(253:256).ne.'    ')then
            if(arg.le.9)
     &       call fatal('Argument '//char(arg+48)//' too long')
            if(arg.gt.9)
     &       call fatal('Arguments too long')
         endif
         do 10 i=256,1,-1
            argtl(arg)=i
            if(argt(arg)(i:i).gt.' ')goto 100
   10    continue
  100 continue

      return
      end
