diff --git a/docs/src/fortran/lib/constants.rst b/docs/src/fortran/lib/constants.rst index 6e60df86..0217910d 100644 --- a/docs/src/fortran/lib/constants.rst +++ b/docs/src/fortran/lib/constants.rst @@ -39,6 +39,8 @@ View source code :source:`fortran/include/constants.f90` Denotes the exit codes of different failure modes, counting up from 1 +.. f:variable:: DATA_MAX_NAME_SIZE + :type: integer .. f:variable:: ANSWERT_STR_SIZE :type: integer diff --git a/docs/src/fortran/lib/utils.rst b/docs/src/fortran/lib/utils.rst index 1fca3786..fa9ceb66 100644 --- a/docs/src/fortran/lib/utils.rst +++ b/docs/src/fortran/lib/utils.rst @@ -5,6 +5,14 @@ View source code :source:`fortran/include/utils.f90` .. f:module:: utils +.. f:function:: open_data_file(name) + + Return the unit number for a newly-opened file in ``/_data/``, where ``/`` is the repository root. + + :p character(len=DATA_MAX_NAME_SIZE) id: + :returns unit: + :rtype unit: integer + .. f:function:: get_answer(id) Return the answer to a given problem, as represented in ``/_data/answers.tsv``, where ``/`` is the repository root. diff --git a/fortran/src/include/constants.f90 b/fortran/src/include/constants.f90 index 6a5ec563..4e73d8fa 100644 --- a/fortran/src/include/constants.f90 +++ b/fortran/src/include/constants.f90 @@ -20,6 +20,7 @@ module constants integer, parameter :: ERROR_UTILS_ALLOCATE_FAILED = 5 ! file/string sizes + integer, parameter :: DATA_MAX_NAME_SIZE = 32 integer, parameter :: ANSWERT_STR_SIZE = 16 end module constants diff --git a/fortran/src/include/utils.f90 b/fortran/src/include/utils.f90 index 7192c1b0..8bb44066 100644 --- a/fortran/src/include/utils.f90 +++ b/fortran/src/include/utils.f90 @@ -13,7 +13,7 @@ module utils type(AnswerT), private, dimension(1024) :: cached_answers contains integer function open_data_file(name) result(unit) - character(len=32), intent(in) :: name + character(len=DATA_MAX_NAME_SIZE), intent(in) :: name integer :: ios unit = prev_unit + 1 @@ -42,7 +42,7 @@ type(AnswerT) function get_answer(id) result(answer) end function subroutine init_answer_cache() - character(len=32), parameter ::file_name = "answers.tsv" + character(len=DATA_MAX_NAME_SIZE), parameter ::file_name = "answers.tsv" character(len=64) :: line character(len=32) :: val character(len=4) :: id_, type_, length diff --git a/fortran/src/p0022.f90 b/fortran/src/p0022.f90 index dfd72742..17a6630c 100644 --- a/fortran/src/p0022.f90 +++ b/fortran/src/p0022.f90 @@ -22,6 +22,7 @@ module Problem0022 integer, parameter :: longest_name = 11 contains integer(i18t) function p0022() result(answer) + character(len=DATA_MAX_NAME_SIZE), parameter :: file_name = "p0022_names.txt" character(len=longest_name), dimension(name_count) :: names character(len=1) current_char integer(i18t) score @@ -30,14 +31,14 @@ integer(i18t) function p0022() result(answer) i = 1 answer = 0 names = '' - unit = open_data_file("p0022_names.txt") + unit = open_data_file(file_name) do read(unit, '(A1)', IOSTAT=ios) current_char if (ios /= 0) then exit end if - select case current_char + select case (current_char) case (',') i = i + 1 case ('"')