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)
203 if (len_trim(line) > 0)
then 221 logical,
intent(out) :: eof
223 character(len=SPEC_LINE_MAX_LEN) :: line_string, rest
231 i = index(line_string,
' ')
242 line%name = line_string(1:(i-1))
243 line_string = line_string(i:)
250 do while (.not. done)
251 if (len_trim(rest) == 0)
then 267 do while (.not. done)
268 if (len_trim(rest) == 0)
then 276 'internal processing error')
281 //
' longer than: ' &
284 line%data(n_data) = rest(1:(i-1))
322 integer,
intent(in) :: max_lines
327 integer :: i, num_lines
335 num_lines = num_lines + 1
338 'maximum number of lines exceeded')
340 if (max_lines > 0)
then 341 if (num_lines >= max_lines)
then 352 allocate(line_list(num_lines))
353 line_list = temp_line_list(1:num_lines)
366 integer,
intent(in) :: max_lines
370 integer :: i, line_length
373 if (
size(line_array) > 0)
then 374 line_length =
size(line_array(1)%data)
375 do i = 2,
size(line_array)
376 if (
size(line_array(i)%data) /= line_length)
then 378 'lines have unequal numbers of entries for array')
395 character(len=*),
intent(in) :: name
397 if (line%name /= name)
then 399 'line must begin with: ' // trim(name) &
400 //
' not: ' // trim(line%name))
413 character(len=*),
intent(in) :: name
415 character(len=*),
intent(in) :: read_name
417 integer name_len, read_name_len
419 if (name /= read_name)
then 421 'line must begin with: ' // trim(name) &
422 //
' not: ' // trim(read_name))
437 integer,
intent(in) :: length
439 if (
size(line%data) /= length)
then 454 integer,
intent(in) :: ios
456 character(len=*),
intent(in) :: type
473 character(len=*),
intent(in) :: string
478 read(string,
'(i20)', iostat=ios) val
492 character(len=*),
intent(in) :: string
497 read(string,
'(f30.0)', iostat=ios) val
511 character(len=*),
intent(in) :: string
517 if ((trim(string) ==
'yes') &
518 .or. (trim(string) ==
'y') &
519 .or. (trim(string) ==
'true') &
520 .or. (trim(string) ==
't') &
521 .or. (trim(string) ==
'1'))
then 523 elseif ((trim(string) ==
'no') &
524 .or. (trim(string) ==
'n') &
525 .or. (trim(string) ==
'false') &
526 .or. (trim(string) ==
'f') &
527 .or. (trim(string) ==
'0'))
then 544 character(len=*),
intent(in) :: name
546 integer,
intent(out) :: var
566 character(len=*),
intent(in) :: name
568 real(kind=dp),
intent(out) :: var
587 character(len=*),
intent(in) :: name
589 logical,
intent(out) :: var
608 character(len=*),
intent(in) :: name
610 character(len=*),
intent(out) :: var
630 character(len=*),
intent(in) :: name
632 complex(kind=dc),
intent(out) :: var
653 integer,
intent(in) :: max_lines
655 character(len=SPEC_LINE_MAX_VAR_LEN),
allocatable :: names(:)
657 real(kind=dp),
allocatable :: vals(:,:)
660 integer :: num_lines, line_length, i, j
663 num_lines =
size(line_array)
664 if (
allocated(names))
deallocate(names)
665 if (
allocated(vals))
deallocate(vals)
666 if (num_lines > 0)
then 667 line_length =
size(line_array(1)%data)
668 allocate(names(num_lines))
669 allocate(vals(num_lines, line_length))
671 names(i) = line_array(i)%name
691 character(len=*),
intent(in) :: name
693 real(kind=dp),
allocatable :: times(:)
695 real(kind=dp),
allocatable :: vals(:)
697 integer :: n_lines, n_times
698 character(len=SPEC_LINE_MAX_VAR_LEN),
allocatable :: read_names(:)
699 real(kind=dp),
allocatable :: read_data(:,:)
703 n_lines =
size(read_names)
704 if (n_lines /= 2)
then 705 call die_msg(694159200,
'must have exactly two data lines in file ' &
708 n_times =
size(read_data,2)
709 if (n_times < 1)
then 710 call die_msg(925956383,
'must have at least one data poin in file ' &
713 if (trim(read_names(1)) /=
"time")
then 714 call die_msg(407039398,
'first data line in ' // trim(file%name) &
715 //
' must start with: time not: ' // trim(read_names(1)))
717 if (trim(read_names(2)) /= name)
then 718 call die_msg(692842968,
'second data line in ' // trim(file%name) &
719 //
' must start with: ' // trim(name) &
720 //
' not: ' // trim(read_names(2)))
723 times = read_data(1,:)
724 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.
An input file with extra data for printing messages.
integer function spec_file_string_to_integer(file, string)
Convert a string to an integer.
subroutine spec_file_close(file)
Close a spec file.
subroutine spec_line_strip_comment(string)
Strip the comments from a string. Comments are everything after the first # character.
subroutine spec_file_check_read_iostat(file, ios, type)
Check the IOSTAT and error if it is bad.
subroutine spec_line_strip_leading_spaces(string)
Strip leading spaces from a string.
A single line of input data, split at whitespace.
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_check_line_length(file, line, length)
Check that the length of the line data is as given.
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)...
subroutine spec_file_read_real(file, name, var)
Read a real number from a spec file that must have the given name.
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_integer(file, name, var)
Read an integer from a spec file that must have the given name.
subroutine die_msg(code, error_msg)
Error immediately.
integer function get_unit()
Returns an available unit number. This should be freed by free_unit().
subroutine spec_line_set_size(spec_line, n_data)
Sets the number of data elements in the line.
logical function spec_file_string_to_logical(file, string)
Convert a string to an logical.
real(kind=dp) function spec_file_string_to_real(file, string)
Convert a string to an real.
subroutine spec_file_read_logical(file, name, var)
Read a logical from a spec file that must have a given name.
subroutine spec_file_die_msg(code, file, msg)
Exit with an error message containing filename and line number.
subroutine spec_file_read_line(file, line, eof)
Read a spec_line from the spec_file.
Reading formatted text input.
subroutine spec_file_check_name(file, name, read_name)
Checks that the read_name is the same as name.
integer, parameter spec_file_max_list_lines
Maximum number of lines in an array.
subroutine spec_file_open(filename, file)
Open a spec file for reading.
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_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 ...
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 ...
subroutine spec_file_read_string(file, name, var)
Read a string from a spec file that must have a given name.
subroutine spec_line_tabs_to_spaces(string)
Expand all tabs in a string into single spaces (one tab makes one space).
character(len=pmc_util_convert_string_len) function integer_to_string(val)
Convert an integer to a string format.
Common utility subroutines.
integer, parameter dc
Kind of a double precision complex number.
subroutine free_unit(unit)
Frees a unit number returned by get_unit().
integer, parameter spec_line_max_var_len
Maximum size of a variable.