Go to the documentation of this file.
61 character(len=SPEC_LINE_MAX_VAR_LEN) :: name
76 integer,
intent(in) :: code
80 character(len=*),
intent(in) :: msg
93 integer,
intent(in) :: code
97 logical,
intent(in) :: condition_ok
99 character(len=*),
intent(in) :: msg
101 if (.not. condition_ok)
then
102 call die_msg(code,
"file " // trim(file%name) //
" line " &
114 character(len=*),
intent(in) :: filename
120 file%name = trim(filename)
122 open(unit=file%unit, status=
'old', file=file%name, iostat=ios)
124 call die_msg(173932734,
"unable to open file " // trim(file%name) &
152 character(len=*),
intent(out) :: line
154 logical,
intent(out) :: eof
156 integer :: ios, n_read
158 file%line_num = file%line_num + 1
161 read(unit=file%unit, fmt=
'(a)', advance=
'no',
end=100, eor=110, &
188 character(len=*),
intent(out) :: line
190 logical,
intent(out) :: eof
195 do while (.not. done)
200 call spec_line_strip_comment(line)
201 call spec_line_tabs_to_spaces(line)
202 call spec_line_strip_leading_spaces(line)
203 if (len_trim(line) > 0)
then
219 type(spec_line_t),
intent(inout) :: line
221 logical,
intent(out) :: eof
223 character(len=SPEC_LINE_MAX_LEN) :: line_string, rest
231 i = index(line_string,
' ')
238 if (i >= spec_line_max_var_len)
then
242 line%name = line_string(1:(i-1))
243 line_string = line_string(i:)
244 call spec_line_strip_leading_spaces(line_string)
250 do while (.not. done)
251 if (len_trim(rest) == 0)
then
258 call spec_line_strip_leading_spaces(rest)
263 call spec_line_set_size(line, n_data)
267 do while (.not. done)
268 if (len_trim(rest) == 0)
then
276 'internal processing error')
278 if (i >= spec_line_max_var_len)
then
281 //
' longer than: ' &
284 line%data(n_data) = rest(1:(i-1))
286 call spec_line_strip_leading_spaces(rest)
302 type(spec_line_t),
intent(inout) :: line
322 integer,
intent(in) :: max_lines
324 type(spec_line_t),
allocatable :: line_list(:)
327 integer :: i, num_lines
328 type(spec_line_t),
allocatable :: temp_line_list(:)
336 num_lines = num_lines + 1
339 'maximum number of lines exceeded')
341 if (max_lines > 0)
then
342 if (num_lines >= max_lines)
then
353 allocate(line_list(num_lines))
354 line_list = temp_line_list(1:num_lines)
367 integer,
intent(in) :: max_lines
369 type(spec_line_t),
allocatable :: line_array(:)
371 integer :: i, line_length
374 if (
size(line_array) > 0)
then
375 line_length =
size(line_array(1)%data)
376 do i = 2,
size(line_array)
377 if (
size(line_array(i)%data) /= line_length)
then
379 'lines have unequal numbers of entries for array')
394 type(spec_line_t),
intent(in) :: line
396 character(len=*),
intent(in) :: name
398 if (line%name /= name)
then
400 'line must begin with: ' // trim(name) &
401 //
' not: ' // trim(line%name))
414 character(len=*),
intent(in) :: name
416 character(len=*),
intent(in) :: read_name
418 integer name_len, read_name_len
420 if (name /= read_name)
then
422 'line must begin with: ' // trim(name) &
423 //
' not: ' // trim(read_name))
436 type(spec_line_t),
intent(in) :: line
438 integer,
intent(in) :: length
440 if (
size(line%data) /= length)
then
455 integer,
intent(in) :: ios
457 character(len=*),
intent(in) :: type
474 character(len=*),
intent(in) :: string
479 read(string,
'(i20)', iostat=ios) val
493 character(len=*),
intent(in) :: string
498 read(string,
'(f30.0)', iostat=ios) val
512 character(len=*),
intent(in) :: string
518 if ((trim(string) ==
'yes') &
519 .or. (trim(string) ==
'y') &
520 .or. (trim(string) ==
'true') &
521 .or. (trim(string) ==
't') &
522 .or. (trim(string) ==
'1'))
then
524 elseif ((trim(string) ==
'no') &
525 .or. (trim(string) ==
'n') &
526 .or. (trim(string) ==
'false') &
527 .or. (trim(string) ==
'f') &
528 .or. (trim(string) ==
'0'))
then
545 character(len=*),
intent(in) :: name
547 integer,
intent(out) :: var
549 type(spec_line_t) :: line
567 character(len=*),
intent(in) :: name
569 real(kind=
dp),
intent(out) :: var
571 type(spec_line_t) :: line
588 character(len=*),
intent(in) :: name
590 logical,
intent(out) :: var
592 type(spec_line_t) :: line
609 character(len=*),
intent(in) :: name
611 character(len=*),
intent(out) :: var
613 type(spec_line_t) :: line
631 character(len=*),
intent(in) :: name
633 complex(kind=dc),
intent(out) :: var
635 type(spec_line_t) :: line
654 integer,
intent(in) :: max_lines
656 character(len=SPEC_LINE_MAX_VAR_LEN),
allocatable :: names(:)
658 real(kind=
dp),
allocatable :: vals(:,:)
660 type(spec_line_t),
allocatable :: line_array(:)
661 integer :: num_lines, line_length, i, j
664 num_lines =
size(line_array)
665 if (
allocated(names))
deallocate(names)
666 if (
allocated(vals))
deallocate(vals)
667 if (num_lines > 0)
then
668 line_length =
size(line_array(1)%data)
669 allocate(names(num_lines))
670 allocate(vals(num_lines, line_length))
672 names(i) = line_array(i)%name
692 character(len=*),
intent(in) :: name
694 real(kind=
dp),
allocatable :: times(:)
696 real(kind=
dp),
allocatable :: vals(:)
698 integer :: n_lines, n_times
699 character(len=SPEC_LINE_MAX_VAR_LEN),
allocatable :: read_names(:)
700 real(kind=
dp),
allocatable :: read_data(:,:)
704 n_lines =
size(read_names)
705 if (n_lines /= 2)
then
706 call die_msg(694159200,
'must have exactly two data lines in file ' &
709 n_times =
size(read_data,2)
710 if (n_times < 1)
then
711 call die_msg(925956383,
'must have at least one data poin in file ' &
714 if (trim(read_names(1)) /=
"time")
then
715 call die_msg(407039398,
'first data line in ' // trim(file%name) &
716 //
' must start with: time not: ' // trim(read_names(1)))
718 if (trim(read_names(2)) /= name)
then
719 call die_msg(692842968,
'second data line in ' // trim(file%name) &
720 //
' must start with: ' // trim(name) &
721 //
' not: ' // trim(read_names(2)))
724 times = read_data(1,:)
725 vals = read_data(2,:)
subroutine spec_file_read_line_raw(file, line, eof)
Read a single line from a spec file, signaling if we have hit EOF.
subroutine spec_file_read_complex(file, name, var)
Read a complex number from a spec file that must have the given name.
subroutine spec_file_read_integer(file, name, var)
Read an integer from a spec file that must have the given name.
integer function spec_file_string_to_integer(file, string)
Convert a string to an integer.
subroutine spec_file_close(file)
Close a spec file.
integer function get_unit()
Returns an available unit number. This should be freed by free_unit().
subroutine die_msg(code, error_msg)
Error immediately.
integer, parameter dp
Kind of a double precision real number.
Reading formatted text input.
subroutine spec_file_read_logical(file, name, var)
Read a logical from a spec file that must have a given name.
integer, parameter spec_file_max_list_lines
Maximum number of lines in an array.
An input file with extra data for printing messages.
subroutine spec_file_read_real(file, name, var)
Read a real number from a spec file that must have the given name.
character(len=pmc_util_convert_string_len) function integer_to_string(val)
Convert an integer to a string format.
subroutine spec_file_check_name(file, name, read_name)
Checks that the read_name is the same as name.
subroutine spec_file_check_line_length(file, line, length)
Check that the length of the line data is as given.
logical function spec_file_string_to_logical(file, string)
Convert a string to an logical.
subroutine spec_file_check_read_iostat(file, ios, type)
Check the IOSTAT and error if it is bad.
subroutine spec_file_read_line_list(file, max_lines, line_list)
Read a list of spec_lines from a file, stopping at max_lines or EOF, whichever comes first.
subroutine spec_file_open(filename, file)
Open a spec file for reading.
subroutine spec_file_read_line_array(file, max_lines, line_array)
Read an array of spec_lines from a file, stopping at max_lines or EOF. All lines must have the same n...
subroutine spec_file_read_timed_real_array(file, name, times, vals)
Read an a time-indexed array of real data.
subroutine spec_file_read_line_no_eof(file, line)
Read a spec_line from the spec_file. This will always succeed or error out, so should only be called ...
real(kind=dp) function spec_file_string_to_real(file, string)
Convert a string to an real.
subroutine spec_file_read_real_named_array(file, max_lines, names, vals)
Read an array of named lines with real data. All lines must have the same number of data elements.
subroutine spec_file_read_line(file, line, eof)
Read a spec_line from the spec_file.
subroutine spec_file_read_next_data_line(file, line, eof)
Read the next line from the spec file that contains useful data (stripping comments and blank lines).
Common utility subroutines.
subroutine spec_file_die_msg(code, file, msg)
Exit with an error message containing filename and line number.
subroutine spec_file_read_string(file, name, var)
Read a string from a spec file that must have a given name.
integer, parameter dc
Kind of a double precision complex number.
subroutine free_unit(unit)
Frees a unit number returned by get_unit().
subroutine spec_file_check_line_name(file, line, name)
Check that the name of the line data is as given.
A single line of formatted test for input.
subroutine spec_file_assert_msg(code, file, condition_ok, msg)
Exit with an error message containing filename and line number if condition_ok is ....