diff --git a/docs/src/fortran/lib/constants.rst b/docs/src/fortran/lib/constants.rst new file mode 100644 index 00000000..dcd1631c --- /dev/null +++ b/docs/src/fortran/lib/constants.rst @@ -0,0 +1,31 @@ +constants.f90 +============= + +View source code :source:`fortran/include/constants.f90` + +.. f:module:: constants + +.. f:variable:: i1t + :type: integer +.. f:variable:: i4t + :type: integer +.. f:variable:: i19t + :type: integer + + A set of digit type constraints that denote how many decimal digits a number can support. + They are given as ``it`` or ``r_t`` + +.. f:variable:: errort + :type: integer(i1t) +.. f:variable:: int64t + :type: integer(i1t) +.. f:variable:: stringt + :type: integer(i1t) + + Denotes the type of an :f:type:`AnswerT` + +.. literalinclude:: ../../../../fortran/src/include/constants.f90 + :language: Fortran + :linenos: + +.. tags:: constants diff --git a/docs/src/fortran/lib/utils.rst b/docs/src/fortran/lib/utils.rst index 83b23f77..23a279b5 100644 --- a/docs/src/fortran/lib/utils.rst +++ b/docs/src/fortran/lib/utils.rst @@ -19,7 +19,7 @@ View source code :source:`fortran/include/utils.f90` Return the answer to a given problem, as represented in ``/_data/answers.tsv`` - :p integer(kind=4) id: + :p integer(i4d) id: :returns answer: :rtype answer: AnswerT @@ -27,21 +27,12 @@ View source code :source:`fortran/include/utils.f90` This stores the answer to a generic problem, storing multiple potential types. If the type field contains :f:var:`errort`, there was an error in generating the answer. If it is :f:var:`int64t`, it holds data of - type ``integer(kind=8)``. If it is :f:var:`stringt`, it holds an allocatable character array. + type ``integer(i19t)``. If it is :f:var:`stringt`, it holds an allocatable character array. - :f integer(kind=8) int_value: + :f integer(i19t) int_value: :f character(len=:) string_value: :fattrs string_value: allocatable - :f integer(kind=1) type: - -.. f:variable:: errort - :type: integer(kind=1) -.. f:variable:: int64t - :type: integer(kind=1) -.. f:variable:: stringt - :type: integer(kind=1) - - Denotes the type of an :f:type:`AnswerT` + :f integer(i1d) type: .. literalinclude:: ../../../../fortran/src/include/utils.f90 :language: Fortran diff --git a/fortran/Makefile b/fortran/Makefile index d8b4e242..a123b101 100644 --- a/fortran/Makefile +++ b/fortran/Makefile @@ -39,9 +39,12 @@ help: @echo " $(BLUE)test_auto$(NC) Run through all Fortran tests (parallel execution not implemented)." @echo " $(BLUE)clean$(NC) Clean up any stray files." -$(BUILD_DIR)/%.o: $(SRC_DIR)/%.f90 +$(BUILD_DIR)/include/constants.o: $(SRC_DIR)/include/constants.f90 @mkdir -p $(BUILD_DIR)/include - $(FC) $(opt_args) $(cov_args) -c $< -o $@ + $(FC) $(opt_args) $(cov_args) -c $(SRC_DIR)/include/constants.f90 -o $(BUILD_DIR)/include/constants.o + +$(BUILD_DIR)/%.o: $(SRC_DIR)/%.f90 $(BUILD_DIR)/include/constants.o + $(FC) $(opt_args) $(cov_args) $(BUILD_DIR)/include/constants.o -c $< -o $@ test_runner: ../LICENSE @$(MAKE) $(OBJ_FILES) $(MFLAGS) -j --no-print-directory diff --git a/fortran/src/include/constants.f90 b/fortran/src/include/constants.f90 new file mode 100644 index 00000000..c8944904 --- /dev/null +++ b/fortran/src/include/constants.f90 @@ -0,0 +1,14 @@ +module constants + implicit none + + integer, parameter :: i1t = selected_int_kind(1) + integer, parameter :: i4t = selected_int_kind(4) + integer, parameter :: i19t = selected_int_kind(19) + + integer(i1t), parameter :: errort = 0 + integer(i1t), parameter :: int64t = 1 + integer(i1t), parameter :: stringt = 2 + +contains +end module constants + diff --git a/fortran/src/include/utils.f90 b/fortran/src/include/utils.f90 index 5fcc801a..90bb1c0a 100644 --- a/fortran/src/include/utils.f90 +++ b/fortran/src/include/utils.f90 @@ -1,17 +1,15 @@ module utils - implicit none + use constants - integer(kind=1), parameter :: errort = 0 - integer(kind=1), parameter :: int64t = 1 - integer(kind=1), parameter :: stringt = 2 + implicit none type :: AnswerT - integer(kind=8) :: int_value + integer(i19t) :: int_value character(len=:), allocatable :: string_value - integer(kind=1) :: type + integer(i1t) :: type end type AnswerT - logical(kind=1) :: cache_inited = .false. + logical :: cache_inited = .false. type(AnswerT), dimension(1024) :: cached_answers contains @@ -52,9 +50,9 @@ end function get_data_file function get_answer(id) result(answer) type(AnswerT) :: answer - integer(kind=4), intent(in) :: id - integer(kind=4) :: ios, row_start, row_end, line_length - integer(kind=8) :: i, j + integer(i4t), intent(in) :: id + integer(i19t) :: i, j + integer :: ios, row_start, row_end, line_length character(len=:), allocatable :: text character(len=32) :: val character(len=4) :: id_, type_, length diff --git a/fortran/test.f90 b/fortran/test.f90 index 61390005..aa3e57fe 100644 --- a/fortran/test.f90 +++ b/fortran/test.f90 @@ -1,4 +1,5 @@ program test + use constants use utils use Problem0001 use Problem0002 @@ -10,8 +11,8 @@ program test use Problem0836 implicit none - integer(kind=4), dimension(:), allocatable :: problem_ids - logical(kind=1), dimension(:), allocatable :: long_runtime + integer(i4t), dimension(:), allocatable :: problem_ids + logical, dimension(:), allocatable :: long_runtime integer :: num_problems num_problems = 8 @@ -48,11 +49,10 @@ program test contains subroutine process_problems(problem_ids, long_runtime) - integer(kind=4), dimension(:), intent(in) :: problem_ids - logical(kind=1), dimension(:), intent(in) :: long_runtime + integer(i4t), dimension(:), intent(in) :: problem_ids + logical, dimension(:), intent(in) :: long_runtime type(AnswerT) :: expected, answer - integer(kind=4) :: i - integer :: first_count, second_count, count_rate, count_max, tmp + integer :: i, first_count, second_count, count_rate, count_max, tmp real :: time_elapsed ! Loop through each problem @@ -119,7 +119,7 @@ subroutine process_problems(problem_ids, long_runtime) end subroutine process_problems type(AnswerT) function select_function(problem_id) result(answer) - integer(kind=4), intent(in) :: problem_id + integer(i4t), intent(in) :: problem_id answer%type = int64t select case (problem_id)