Skip to content

Commit db2758a

Browse files
committed
explict cast
more compile checks
1 parent 9872b49 commit db2758a

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,11 @@ cmake_minimum_required(VERSION 3.14)
22

33
project(DonutFortran LANGUAGES Fortran)
44

5+
if(CMAKE_Fortran_COMPILER_ID STREQUAL GNU)
6+
add_compile_options(-Wall -Werror=array-bounds -fcheck=bounds
7+
"$<$<CONFIG:Debug,RelWithDebInfo>:-Wextra;-Wpedantic>"
8+
"$<$<CONFIG:Release>:-fno-backtrace>"
9+
)
10+
endif()
11+
512
add_executable(donut app/main.f90)

app/main.f90

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
program donut
22

3-
use, intrinsic :: iso_fortran_env, only : wp=>real64, stdout => output_unit
3+
use, intrinsic:: iso_fortran_env, only: stdout => output_unit
44

55
implicit none (type, external)
66

77
character, parameter :: ESC = achar(27)
88
character(3), parameter :: LF = ESC // "[d" !< line feed
9-
character(3), parameter :: TL = ESC // "[2J" !< erase screen and move to top left
9+
character(4), parameter :: TL = ESC // "[2J" !< erase screen and move to top left
1010
character, parameter :: TAB(0:11) = [".", ",", "-", "~", ":", ";", "=", "!", "*", "#", "$", "@"]
11-
real(wp), parameter :: PI = 4*atan(1.)
11+
real, parameter :: PI = 4*atan(1.)
1212

1313
integer :: cols, rows, L, k
1414

15-
real(wp) :: a=0, b=0, i, j
15+
real :: a=0, b=0, i, j
1616

17-
real(wp), allocatable :: z(:)
17+
real, allocatable :: z(:)
1818
character, allocatable :: screen(:)
1919

20-
real(wp) :: sini,cosj,sinA,sinj,cosA,cosj2, mess, cosi,cosB,t,sinB
20+
real :: sini,cosj,sinA,sinj,cosA,cosj2, mess, cosi,cosB,t,sinB
2121
integer :: x,y,o,N,ii, u, Nloop
2222
character(5) :: buf
2323

@@ -74,9 +74,9 @@ program donut
7474
cosi = cos(i)
7575
mess = 1 / (sini*cosj2*sinA+sinj*cosA+5)
7676
t = sini*cosj2*cosA - sinj*sinA
77-
x = 40 + 30*mess*(cosi*cosj2*cosB - t*sinB)
78-
y = 12 + 15*mess*(cosi*cosj2*sinB + t*cosB)
79-
o = min(L, x+cols*y) !< C program goes out of bounds
77+
x = int(40 + 30*mess*(cosi*cosj2*cosB - t*sinB))
78+
y = int(12 + 15*mess*(cosi*cosj2*sinB + t*cosB))
79+
o = min(L-1, x+cols*y) !< C program goes out of bounds
8080
N = int(8*((sinj*sinA - sini*cosj*cosA)*cosB - sini*cosj*sinA - sinj*cosA - cosi * cosj*sinB))
8181
if(rows>y .and. y>0 .and. x>0 .and. cols>x .and. mess>z(o)) then
8282
z(o) = mess

0 commit comments

Comments
 (0)