49 integer,
parameter :: SPEC_FILE_MAX_LIST_LINES = 1000
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,
' ')
238 if (i >= spec_line_max_var_len)
then
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
268 do while (.not. done)
269 if (len_trim(rest) == 0)
then
277 'internal processing error')
279 if (i >= spec_line_max_var_len)
then
282 //
' longer than: ' &
285 line%data(n_data) = rest(1:(i-1))
323 integer,
intent(in) :: max_lines
328 integer :: i, num_lines
329 type(spec_line_t) :: temp_line_list(spec_file_max_list_lines)
340 num_lines = num_lines + 1
341 if (num_lines > spec_file_max_list_lines)
then
343 'maximum number of lines exceeded')
345 if (max_lines > 0)
then
346 if (num_lines >= max_lines)
then
360 do i = 1,
size(line_list)
363 deallocate(line_list)
364 allocate(line_list(num_lines))
382 integer,
intent(in) :: max_lines
386 integer :: i, line_length
389 if (
size(line_array) > 0)
then
390 line_length =
size(line_array(1)%data)
391 do i = 2,
size(line_array)
392 if (
size(line_array(i)%data) /= line_length)
then
394 'lines have unequal numbers of entries for array')
411 character(len=*),
intent(in) :: name
413 if (line%name /= name)
then
415 'line must begin with: ' // trim(name) &
416 //
' not: ' // trim(line%name))
429 character(len=*),
intent(in) :: name
431 character(len=*),
intent(in) :: read_name
433 integer name_len, read_name_len
435 if (name /= read_name)
then
437 'line must begin with: ' // trim(name) &
438 //
' not: ' // trim(read_name))
453 integer,
intent(in) :: length
455 if (
size(line%data) /= length)
then
470 integer,
intent(in) :: ios
472 character(len=*),
intent(in) :: type
489 character(len=*),
intent(in) :: string
494 read(string,
'(i20)', iostat=ios) val
508 character(len=*),
intent(in) :: string
513 read(string,
'(f30.0)', iostat=ios) val
527 character(len=*),
intent(in) :: string
533 if ((trim(string) ==
'yes') &
534 .or. (trim(string) ==
'y') &
535 .or. (trim(string) ==
'true') &
536 .or. (trim(string) ==
't') &
537 .or. (trim(string) ==
'1'))
then
539 elseif ((trim(string) ==
'no') &
540 .or. (trim(string) ==
'n') &
541 .or. (trim(string) ==
'false') &
542 .or. (trim(string) ==
'f') &
543 .or. (trim(string) ==
'0'))
then
560 character(len=*),
intent(in) :: name
562 integer,
intent(out) :: var
584 character(len=*),
intent(in) :: name
586 real(kind=dp),
intent(out) :: var
607 character(len=*),
intent(in) :: name
609 logical,
intent(out) :: var
630 character(len=*),
intent(in) :: name
632 character(len=*),
intent(out) :: var
654 character(len=*),
intent(in) :: name
656 complex(kind=dc),
intent(out) :: var
679 integer,
intent(in) :: max_lines
681 character(len=SPEC_LINE_MAX_VAR_LEN),
pointer :: names(:)
683 real(kind=dp),
pointer :: vals(:,:)
686 integer :: num_lines, line_length, i, j
688 allocate(line_array(0))
690 num_lines =
size(line_array)
693 if (num_lines > 0)
then
694 line_length =
size(line_array(1)%data)
695 allocate(names(num_lines))
696 allocate(vals(num_lines, line_length))
698 names(i) = line_array(i)%name
710 deallocate(line_array)
722 character(len=*),
intent(in) :: name
724 real(kind=dp),
pointer :: times(:)
726 real(kind=dp),
pointer :: vals(:)
728 integer :: n_lines, n_times
729 character(len=SPEC_LINE_MAX_VAR_LEN),
pointer :: read_names(:)
730 real(kind=dp),
pointer :: read_data(:,:)
732 allocate(read_names(0))
733 allocate(read_data(0,0))
736 n_lines =
size(read_names)
737 if (n_lines /= 2)
then
738 call
die_msg(694159200,
'must have exactly two data lines in file ' &
741 n_times =
size(read_data,2)
742 if (n_times < 1)
then
743 call
die_msg(925956383,
'must have at least one data poin in file ' &
746 if (trim(read_names(1)) /=
"time")
then
747 call
die_msg(407039398,
'first data line in ' // trim(file%name) &
748 //
' must start with: time not: ' // trim(read_names(1)))
750 if (trim(read_names(2)) /= name)
then
751 call
die_msg(692842968,
'second data line in ' // trim(file%name) &
752 //
' must start with: ' // trim(name) &
753 //
' not: ' // trim(read_names(2)))
758 allocate(times(n_times))
759 allocate(vals(n_times))
760 times = read_data(1,:)
761 vals = read_data(2,:)
762 deallocate(read_names)
763 deallocate(read_data)
An input file with extra data for printing messages.
subroutine spec_line_strip_comment(string)
Strip the comments from a string. Comments are everything after the first # character.
subroutine spec_file_check_line_name(file, line, name)
Check that the name of the line data is as given.
subroutine die_msg(code, error_msg)
Error immediately.
subroutine spec_file_open(filename, file)
Open a spec file for reading.
subroutine spec_file_read_timed_real_array(file, name, times, vals)
Read an a time-indexed array of real data.
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_line_strip_leading_spaces(string)
Strip leading spaces from a string.
A single line of input data, split at whitespace.
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.
subroutine spec_file_check_line_length(file, line, length)
Check that the length of the line data is as given.
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_line_copy(from_spec_line, to_spec_line)
Copies a spec_line.
logical function spec_file_string_to_logical(file, string)
Convert a string to an logical.
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_name(file, name, read_name)
Checks that the read_name is the same as name.
Common utility subroutines.
subroutine spec_line_tabs_to_spaces(string)
Expand all tabs in a string into single spaces (one tab makes one space).
subroutine spec_file_read_string(file, name, var)
Read a string from a spec file that must have a given name.
integer function spec_file_string_to_integer(file, string)
Convert a string to an integer.
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_logical(file, name, var)
Read a logical from a spec file that must have a given name.
character(len=pmc_util_convert_string_len) function integer_to_string(val)
Convert an integer to a string format.
A single line of formatted test for input.
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...
Reading formatted text input.
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 spec_line_allocate_size(spec_line, n_data)
Allocates memory for a spec_line of the given size.
subroutine spec_line_allocate(spec_line)
Allocates memory for a spec_line.
real(kind=dp) function spec_file_string_to_real(file, string)
Convert a string to an real.
subroutine spec_file_read_line(file, line, eof)
Read a spec_line from the spec_file.
subroutine spec_file_die_msg(code, file, msg)
Exit with an error message containing filename and line number.
subroutine spec_line_deallocate(spec_line)
Frees all storage.
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_real(file, name, var)
Read a real number from a spec file that must have the given name.
subroutine free_unit(unit)
Frees a unit number returned by get_unit().
subroutine spec_file_read_line_raw(file, line, eof)
Read a single line from a spec file, signaling if we have hit EOF.