PartMC  2.6.1
spec_line.F90
Go to the documentation of this file.
1 ! Copyright (C) 2007-2010, 2012 Nicole Riemer and Matthew West
2 ! Licensed under the GNU General Public License version 2 or (at your
3 ! option) any later version. See the file COPYING for details.
4 
5 !> \file
6 !> The pmc_spec_line module.
7 
8 !> A single line of formatted test for input.
10 
11  use pmc_util
12 
13  !> Maximum size of a single line.
14  integer, parameter :: spec_line_max_len = 10000
15  !> Maximum size of a variable.
16  integer, parameter :: spec_line_max_var_len = 300
17 
18  !> A single line of input data, split at whitespace.
19  !!
20  !! Input lines are assumed to be in the format
21  !! <pre>
22  !! # stand-alone comment
23  !! &lt;name&gt; &lt;whitespace&gt; &lt;data1&gt; &lt;whitespace&gt; &lt;data2&gt; ... # optional comment
24  !! </pre>
25  !! An spec_line_t structure stores the name and data split at
26  !! whitespace.
28  !> Variable name.
29  character(len=SPEC_LINE_MAX_VAR_LEN) :: name
30  !> Array of data as strings.
31  character(len=SPEC_LINE_MAX_VAR_LEN), allocatable :: data(:)
32  end type spec_line_t
33 
34 contains
35 
36 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
37 
38  !> Sets the number of data elements in the line.
39  subroutine spec_line_set_size(spec_line, n_data)
40 
41  !> Struct to alloc.
42  type(spec_line_t), intent(inout) :: spec_line
43  !> Number of data items.
44  integer, intent(in) :: n_data
45 
46  if (allocated(spec_line%data)) deallocate(spec_line%data)
47  allocate(spec_line%data(n_data))
48  spec_line%data = ""
49 
50  end subroutine spec_line_set_size
51 
52 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
53 
54  !> Strip the comments from a string. Comments are everything after
55  !> the first # character.
56  subroutine spec_line_strip_comment(string)
57 
58  !> Complete input string.
59  character(len=*), intent(inout) :: string
60 
61  integer :: hash_index
62 
63  hash_index = index(string, '#')
64  if (hash_index > 0) then
65  string = string(1:(hash_index - 1))
66  end if
67 
68  end subroutine spec_line_strip_comment
69 
70 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
71 
72  !> Expand all tabs in a string into single spaces (one tab makes one
73  !> space).
74  subroutine spec_line_tabs_to_spaces(string)
75 
76  !> Complete input string.
77  character(len=*), intent(inout) :: string
78 
79  integer :: i
80 
81  do i = 1,len(string)
82  if (ichar(string(i:i)) == 9) then
83  string(i:i) = ' '
84  end if
85  end do
86 
87  end subroutine spec_line_tabs_to_spaces
88 
89 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
90 
91  !> Strip leading spaces from a string.
92  subroutine spec_line_strip_leading_spaces(string)
93 
94  !> Complete input string.
95  character(len=*), intent(inout) :: string
96 
97  integer :: i
98 
99  if (len_trim(string) > 0) then
100  i = verify(string, ' ') ! first character not a space
101  string = string(i:)
102  end if
103 
104  end subroutine spec_line_strip_leading_spaces
105 
106 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
107 
108 end module pmc_spec_line
pmc_spec_line::spec_line_set_size
subroutine spec_line_set_size(spec_line, n_data)
Sets the number of data elements in the line.
Definition: spec_line.F90:40
pmc_spec_line::spec_line_t
A single line of input data, split at whitespace.
Definition: spec_line.F90:27
pmc_spec_line::spec_line_max_var_len
integer, parameter spec_line_max_var_len
Maximum size of a variable.
Definition: spec_line.F90:16
pmc_spec_line::spec_line_max_len
integer, parameter spec_line_max_len
Maximum size of a single line.
Definition: spec_line.F90:14
pmc_spec_line::spec_line_tabs_to_spaces
subroutine spec_line_tabs_to_spaces(string)
Expand all tabs in a string into single spaces (one tab makes one space).
Definition: spec_line.F90:75
pmc_util
Common utility subroutines.
Definition: util.F90:9
pmc_spec_line::spec_line_strip_comment
subroutine spec_line_strip_comment(string)
Strip the comments from a string. Comments are everything after the first # character.
Definition: spec_line.F90:57
pmc_spec_line::spec_line_strip_leading_spaces
subroutine spec_line_strip_leading_spaces(string)
Strip leading spaces from a string.
Definition: spec_line.F90:93
pmc_spec_line
A single line of formatted test for input.
Definition: spec_line.F90:9