Skip to content

Commit

Permalink
Fix compilation errors with p22
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Oct 7, 2024
1 parent 9d5e597 commit b8d1906
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
2 changes: 2 additions & 0 deletions docs/src/fortran/lib/constants.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions docs/src/fortran/lib/utils.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions fortran/src/include/constants.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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

4 changes: 2 additions & 2 deletions fortran/src/include/utils.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions fortran/src/p0022.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ('"')
Expand Down

0 comments on commit b8d1906

Please sign in to comment.