1!$Id:$
2      subroutine filargs(nargs)
3
4!      * * F E A P * * A Finite Element Analysis Program
5
6!....  Copyright (c) 1984-2017: Regents of the University of California
7!                               All rights reserved
8
9!-----[--.----+----.----+----.-----------------------------------------]
10!     Modification log                                Date (dd/mm/year)
11!       Original version                                    22/07/2017
12!-----[--.----+----.----+----.-----------------------------------------]
13!      Purpose: Get command line arguments
14
15!      Inputs:
16
17!      Outputs:
18!         nargs  - Number of command line arguments found
19!         File names returned in common /comfil/
20!-----[--.----+----.----+----.-----------------------------------------]
21      implicit  none
22
23      include  'comfil.h'
24
25      integer   (kind=4)  :: nargs
26      character (len=128) :: inp, otp, res, sav
27      character (len=130) :: argv
28      integer   (kind=4)  :: i, nchars
29
30      save
31
32!     Set files to blank
33
34      inp = ' '
35      otp = ' '
36      res = ' '
37      sav = ' '
38
39!     Check arguments set on command line
40
41      nargs = command_argument_count()
42
43      if(nargs.gt.0) then
44        do i = 1, nargs
45
46          call get_command_argument(i,argv)
47          nchars = len_trim(argv)
48
49          if (argv(1:1) .eq. '-') then
50
51!           Input file specification
52
53            if      (argv(2:2).eq.'i') then
54              inp = argv(3:nchars)
55
56!           Output file specification
57
58            else if (argv(2:2).eq.'o') then
59              otp = argv(3:nchars)
60
61!           Restart read file specification
62
63            else if (argv(2:2).eq.'r') then
64              res = argv(3:nchars)
65
66!           Restart save file specification
67
68            else if (argv(2:2).eq.'s') then
69              sav = argv(3:nchars)
70
71!           Error on command line
72
73            else
74              write( *, 2000) argv(2:nchars)
75              call plstop(.true.)
76            endif
77
78!         Error on first character
79
80          else
81            write( *, 2001)  argv(1:nchars)
82            call plstop(.true.)
83          endif
84        end do ! i
85
86!       Check that files are correct if nargs > 0
87
88        if(inp.ne.' ') then
89
90          if(otp.eq.' ') then
91            otp      = inp
92            otp(1:1) = 'O'
93          endif
94          if(res.eq.' ') then
95            res      = inp
96            res(1:1) = 'R'
97          endif
98          if(sav.eq.' ') then
99            sav      = inp
100            sav(1:1) = 'R'
101          endif
102
103!       One of the command arguments must be for input file
104
105        else
106          write( *, 2002)
107          call plstop(.true.)
108        endif
109
110      endif ! nargs > 0
111
112!     Formats
113
1142000  format(' *ERROR* Unknown command line option   -> ',a/
115     &       '         First character must be: -')
1162001  format(' *ERROR* Unknown command line argument -> ',a/
117     &       '         Must be: i, o, r, or s')
1182002  format(' *ERROR* Command line arguments must include an'/
119     &       '         INPUT filename with form: -iI....')
120
121      end
122