The Elk Code
 
Loading...
Searching...
No Matches
numlist.f90
Go to the documentation of this file.
1
2! Copyright (C) 2015 Manh Duc Le, 2017-18 Arsenii Gerasimov, Yaroslav Kvashnin,
3! Lars Nordstrom and J. K. Dewhurst. This file is distributed under the terms of
4! the GNU General Public License. See the file COPYING for license details.
5
6!BOP
7! !ROUTINE: numlist
8! !INTERFACE:
9subroutine numlist(str,n,list)
10! !INPUT/OUTPUT PARAMETERS:
11! str : string to be converted to list of numbers (in,character(*))
12! n : on entry, the maximum allowed number of elements; on exit, the number
13! of elements in the list (inout,integer)
14! list : list of elements (out,integer(n))
15! !DESCRIPTION:
16! Converts a space- or comma-separated string of integers, including ranges,
17! to a list. For example, the string `{\tt 1,2,10-13 5 6}' would be converted
18! to the list {\tt 1,2,10,11,12,13,5,6}.
19!
20! !REVISION HISTORY:
21! Created May 2015 (Manh Duc Le)
22!EOP
23!BOC
24implicit none
25! arguments
26character(*), intent(in) :: str
27integer, intent(inout) :: n
28integer, intent(out) :: list(n)
29! local variables
30integer i0,i1,i,j,m,ios
31! automatic arrays
32integer l(n)
33i=0
34i0=1
35do
36 m=index(str(i0:),'-')
37 if (m == 0) then
38 i1=256
39 else
40 i1=i0+m-2
41 end if
42 l(:)=0
43 read(str(i0:i1),*,iostat=ios) l
44 if (i > 0) then
45 do j=list(i)+1,l(1)-1
46 if (i == n) return
47 i=i+1
48 list(i)=j
49 end do
50 end if
51 do j=1,n
52 if (l(j) == 0) exit
53 if (i == n) return
54 i=i+1
55 list(i)=l(j)
56 end do
57 if (m == 0) then
58 n=i
59 return
60 end if
61 i0=i0+m
62end do
63end subroutine
64!EOC
65
subroutine numlist(str, n, list)
Definition numlist.f90:10