9 integer,
parameter :: dp = kind(0.0d0)
21 integer,
parameter :: table_max_rows = 1500
24 integer,
parameter :: interp_linear = 1
25 integer,
parameter :: interp_cubic_spline = 2
27 integer :: input_interpolation = -1
42 type(cfg_t),
intent(inout) :: cfg
43 character(len=20) :: method
45 call cfg_add_get(cfg,
"table_data%size",
table_size, &
46 "Size of the lookup table for reaction rates")
48 "Minimal field (in Td) for the rate coeff. lookup table")
50 "Maximal field (Td) for lookup tables, < 0 means automatic")
53 call cfg_add_get(cfg,
"table_data%input_interpolation", method, &
54 "Input interpolation method (linear, cubic_spline)")
57 input_interpolation = interp_linear
59 input_interpolation = interp_cubic_spline
61 error stop
"invalid input_interpolation method"
65 call cfg_add_get(cfg,
"table_data%xspacing", method, &
66 "x-spacing for lookup table (linear, quadratic)")
73 error stop
"invalid table_data%xspacing (linear, quadratic)"
77 print *,
"Spacing used for lookup tables: ", trim(method)
85 type(lt_t),
intent(inout) :: tbl
86 integer,
intent(in) :: i_col
87 real(dp),
intent(in) :: x(:)
88 real(dp),
intent(in) :: y(:)
89 real(dp),
intent(out),
optional :: max_err
90 real(dp),
allocatable :: y_table(:)
93 if (
size(x) /=
size(y)) error stop
"size(x) /= size(y)"
95 select case (input_interpolation)
97 call lt_set_col(tbl, i_col, x, y)
98 case (interp_cubic_spline)
103 if (minval(y) >= 0.0_dp)
then
106 y_table = max(0.0_dp, y_table)
109 call lt_set_col_data(tbl, i_col, y_table)
111 error stop
"invalid input_interpolation"
114 if (
present(max_err))
then
116 max_err = maxval(abs(y - lt_get_col(tbl, i_col, x)))/maxval(abs(y))
122 character(len=*),
intent(in) :: file_name, data_name
123 real(dp),
allocatable,
intent(out) :: x_data(:), y_data(:)
126 integer :: iostate, nl
129 character(LEN=40) :: line_fmt
130 character(LEN=string_len) :: line
131 real(dp) :: temp_table(2, table_max_rows)
138 line_fmt =
"(A" // trim(adjustl(line_fmt)) //
")"
141 open(newunit=my_unit, file = trim(file_name), action =
"read", &
142 err = 999, iostat = iostate, status=
"old")
159 read(my_unit, fmt = line_fmt, err = 999,
end = 888) line; nl = nl+1
160 if (line == data_name)
exit
168 read(my_unit, fmt = line_fmt, err = 999,
end = 777) line; nl = nl+1
170 if ( line(1:5) ==
"-----" )
then
172 else if (line(1:7) ==
"FACTOR:")
then
173 read(line(8:), *) factor
174 else if (line(1:8) ==
"COMMENT:")
then
177 print *,
"In file ", trim(file_name),
" at line", nl
179 error stop
"Unknown statement in input file"
186 read(my_unit, fmt = line_fmt, err = 999,
end = 777) line; nl = nl+1
188 if ( line(1:5) ==
"-----" )
then
190 else if (trim(line) ==
"" .or. line(1:1) ==
"#")
then
192 else if (n_rows < table_max_rows)
then
194 read(line, fmt = *, err = 999,
end = 777) temp_table(:, n_rows)
196 print *,
"CS_read_file error: too many rows in ", &
197 file_name,
" at line ", nl
202 if (
allocated(x_data))
deallocate(x_data)
203 if (
allocated(y_data))
deallocate(y_data)
204 allocate(x_data(n_rows))
205 allocate(y_data(n_rows))
207 x_data = temp_table(1, 1:n_rows)
208 y_data = factor * temp_table(2, 1:n_rows)
217 print *,
"table_from_file unexpectedly reached end of " // trim(file_name)
218 print *,
"searching '" // trim(data_name) //
"'"
219 call print_usage(file_name, data_name)
223 print *,
"table_from_file: no data in " // trim(file_name)
224 print *,
"searching '" // trim(data_name) //
"'"
225 call print_usage(file_name, data_name)
229 print *,
"table_from_file error at line", nl
230 print *,
"ioState = ", iostate,
" in ", trim(file_name)
231 print *,
"searching '" // trim(data_name) //
"'"
232 call print_usage(file_name, data_name)
237 subroutine print_usage(file_name, data_name)
238 character(len=*),
intent(in) :: file_name
239 character(len=*),
intent(in) :: data_name
242 print *,
"Expected a file '", trim(file_name), &
243 "' with the following structure:"
244 print *, trim(data_name)
245 print *,
"FACTOR: 1.0 [optional: multiply with this factor]"
246 print *,
"[other lines]"
247 print *,
"------------------ [at least 5 dashes]"
248 print *,
"xxx xxx [data in two column format]"
251 print *,
"------------------"
253 end subroutine print_usage
Module for cubic spline interpolation.
pure elemental real(dp) function, public spline_evaluate(u, spl)
subroutine, public spline_set_coeffs(x, y, n, spl)
Calculate coefficients for cubic spline interpolation.
Module with settings and routines for tabulated data.
subroutine, public table_data_initialize(cfg)
Initialize this module.
subroutine, public table_set_column(tbl, i_col, x, y, max_err)
Interpolate data and store in lookup table.
real(dp), public, protected table_max_townsend
Maximum field (Td) for lookup tables.
integer, public, protected table_xspacing
X-spacing for lookup table.
integer, public, protected table_size
How large lookup tables should be.
subroutine, public table_from_file(file_name, data_name, x_data, y_data)
Routine to read in tabulated data from a file.
real(dp), public, protected table_min_townsend
Minimum field (Td) for lookup tables.
integer, parameter string_len
Default length of strings.