Skip to content

Commit 5194029

Browse files
committed
better CI and Fortran standard adherence
1 parent 364d7e0 commit 5194029

File tree

6 files changed

+69
-55
lines changed

6 files changed

+69
-55
lines changed

.travis.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ fast_finish: true
44
python:
55
- 2.7
66
- 3.6
7+
- "3.7-dev"
78

89
os:
910
- linux
@@ -25,11 +26,11 @@ addons:
2526

2627
before_install:
2728
- if [[ $TRAVIS_OS_NAME == osx ]]; then
28-
brew update;
29-
brew install gcc || true;
30-
brew link --overwrite gcc;
29+
brew update > /dev/null;
30+
brew install gcc || true > /dev/null;
31+
brew link --overwrite gcc > /dev/null;
3132
export FC=gfortran;
32-
brew install opencoarrays;
33+
brew install opencoarrays > /dev/null;
3334
fi
3435

3536
install:
@@ -38,6 +39,7 @@ install:
3839
- cd bin
3940
- cmake ..
4041
- make
42+
- make test
4143
- cd ..
4244

4345
script:

CMakeLists.txt

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ cmake_minimum_required(VERSION 3.7)
22
project(lineclip Fortran)
33
enable_testing()
44

5-
add_compile_options(-O3 -g)
5+
6+
if(CMAKE_BUILD_TYPE STREQUAL Debug)
7+
add_compile_options(-g -O0)
8+
else()
9+
add_compile_options(-O3)
10+
endif()
611

712
if(${CMAKE_Fortran_COMPILER_ID} STREQUAL GNU)
813
if(${CMAKE_Fortran_COMPILER_VERSION} VERSION_GREATER_EQUAL 8.1)
@@ -15,14 +20,17 @@ if(${CMAKE_Fortran_COMPILER_ID} STREQUAL GNU)
1520
if(NOT CYGWIN AND NOT WIN32)
1621
list(APPEND FFLAGS -fstack-protector-all)
1722
endif()
23+
elseif(${CMAKE_Fortran_COMPILER_ID} STREQUAL PGI)
24+
list(APPEND FFLAGS -Mallocatable=03)
1825
elseif(${CMAKE_Fortran_COMPILER_ID} STREQUAL Flang)
26+
list(APPEND FFLAGS -Mallocatable=03)
1927
link_libraries(-static-flang-libs)
2028
endif()
2129

22-
# TODO should be able to run coarrays demo even in single case, may be algorithmic error in my Coarray demo code?
30+
2331
set(DEMO_COARRAYS FALSE)
2432
if(${CMAKE_Fortran_COMPILER_ID} STREQUAL Intel)
25-
add_compile_options(-coarray=shared)# -check all)
33+
add_compile_options(-coarray=shared)
2634
link_libraries(-coarray=shared)
2735
set(DEMO_COARRAYS TRUE)
2836
elseif(${CMAKE_Fortran_COMPILER_ID} STREQUAL GNU)
@@ -39,7 +47,12 @@ endif()
3947

4048
add_library(lineclip lineclipping.f90)
4149

42-
add_library(assert assert.f90)
50+
set(okcomp GNU Intel)
51+
if(CMAKE_Fortran_COMPILER_ID IN_LIST okcomp)
52+
add_library(assert assert.f90)
53+
else()
54+
add_library(assert assert_legacy.f90)
55+
endif()
4356

4457
add_executable(RunLineclip DemoLineclip.f90)
4558
target_compile_options(RunLineclip PRIVATE ${FFLAGS})

DemoLineclip.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ program test
22

33
use, intrinsic:: ieee_arithmetic
44
use lineclip,only: Ccohensutherland, cohensutherland
5-
use assert
5+
use assert, only: wp, err, assert_isclose
66

77
implicit none
88

@@ -66,7 +66,7 @@ subroutine test_lineclip()
6666
x1=0.;y1=0.1;x2=0.;y2=0.1
6767

6868
call cohensutherland(xmin,ymax,xmax,ymin,x1,y1,x2,y2)
69-
if (.not.all(ieee_is_nan([x1,y1,x2,y2]))) error stop 'failed no intersection test'
69+
if (.not.all(ieee_is_nan([x1,y1,x2,y2]))) call err('failed no intersection test')
7070

7171
print *, 'OK lineclip'
7272

assert.f90

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
module assert
22

3-
use, intrinsic:: iso_fortran_env, only: sp=>real32, dp=>real64, qp=>real128, stderr=>error_unit
3+
use, intrinsic:: iso_c_binding, only: sp=>c_float, dp=>c_double
4+
use, intrinsic:: iso_fortran_env, only: stderr=>error_unit
45
use, intrinsic:: ieee_arithmetic
56
implicit none
67
private
78

8-
integer,parameter :: wp = dp
9+
integer,parameter :: wp = sp
910

10-
public :: wp,isclose, assert_isclose
11+
public :: wp,isclose, assert_isclose, err
1112

1213
contains
1314

@@ -31,10 +32,13 @@ elemental logical function isclose(actual, desired, rtol, atol, equal_nan)
3132

3233
real(wp) :: r,a
3334
logical :: n
34-
35-
r = merge(rtol, 1e-5_wp, present(rtol))
36-
a = merge(atol, 0._wp, present(atol))
37-
n = merge(equal_nan, .false., present(equal_nan))
35+
! this is appropriate INSTEAD OF merge(), since non present values aren't defined.
36+
r = 1e-5_wp
37+
a = 0._wp
38+
n = .false.
39+
if (present(rtol)) r = rtol
40+
if (present(atol)) a = atol
41+
if (present(equal_nan)) n = equal_nan
3842

3943
!print*,r,a,n,actual,desired
4044

@@ -69,13 +73,19 @@ impure elemental subroutine assert_isclose(actual, desired, rtol, atol, equal_na
6973
real(wp), intent(in) :: actual, desired
7074
real(wp), intent(in), optional :: rtol, atol
7175
logical, intent(in), optional :: equal_nan
72-
character(*), intent(in), optional :: err_msg
73-
76+
character(*), intent(in), optional :: err_msg
77+
7478
if (.not.isclose(actual,desired,rtol,atol,equal_nan)) then
7579
write(stderr,*) merge(err_msg,'',present(err_msg)),': actual',actual,'desired',desired
7680
error stop
7781
endif
7882

7983
end subroutine assert_isclose
8084

85+
86+
pure subroutine err(msg)
87+
character, intent(in) :: msg
88+
error stop msg
89+
end subroutine err
90+
8191
end module assert

lineclipping.f90

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
module lineclip
22

3-
use, intrinsic:: iso_c_binding, only: sp=>C_FLOAT, dp=>C_DOUBLE, c_int
3+
use, intrinsic:: iso_c_binding, only: c_int
44
use, intrinsic:: iso_fortran_env, only : stderr=>error_unit
55
use, intrinsic:: ieee_arithmetic, only: ieee_value, ieee_quiet_nan, ieee_is_nan
6+
use assert, only: err,wp
67

78
implicit none
89

9-
integer, parameter :: wp=dp
1010
integer,parameter :: inside=0,left=1,right=2,lower=4,upper=8
1111
private
1212
public:: wp,cohensutherland,Ccohensutherland
@@ -58,8 +58,6 @@ elemental subroutine cohensutherland(xmin,ymax,xmax,ymin, &
5858
nan = ieee_value(1.,ieee_quiet_nan)
5959

6060

61-
62-
6361
! check for trivially outside lines
6462
k1 = getclip(x1,y1,xmin,xmax,ymin,ymax)
6563
k2 = getclip(x2,y2,xmin,xmax,ymin,ymax)
@@ -87,13 +85,13 @@ elemental subroutine cohensutherland(xmin,ymax,xmax,ymin, &
8785
y = y1 + (y2 - y1) * (xmin - x1) / (x2 - x1)
8886
x = xmin
8987
else
90-
error stop 'undefined clipping state'
88+
call err('undefined clipping state')
9189
endif
9290

93-
if (opt == k1) then
91+
if (opt == k1) then ! not case select
9492
x1 = x; y1 = y
9593
k1 = getclip(x1,y1,xmin,xmax,ymin,ymax)
96-
else if (opt == k2) then
94+
elseif (opt == k2) then
9795
x2 = x; y2 = y
9896
k2 = getclip(x2,y2,xmin,xmax,ymin,ymax)
9997
endif

tests/test_all.py

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,29 @@
11
#!/usr/bin/env python
2-
import logging
3-
import unittest
4-
from numpy.testing import assert_array_almost_equal
5-
import subprocess
6-
from pathlib import Path
2+
from numpy.testing import assert_array_almost_equal,run_module_suite
73
#
8-
from pylineclip import cohensutherland
4+
import pylineclip as plc
95

10-
path=Path(__file__).parents[1]
116

12-
class BasicTests(unittest.TestCase):
13-
def test_lineclip(self):
14-
"""
15-
make box with corners LL/UR (1,3) (4,5)
16-
and line segment with ends (0,0) (4,6)
17-
"""
18-
#%% LOWER to UPPER test
19-
x1, y1, x2, y2 = cohensutherland(1, 5, 4, 3,
20-
0, 0, 4, 6)
7+
def test_lineclip():
8+
"""
9+
make box with corners LL/UR (1,3) (4,5)
10+
and line segment with ends (0,0) (4,6)
11+
"""
12+
#%% LOWER to UPPER test
13+
x1, y1, x2, y2 = plc.cohensutherland(1, 5, 4, 3,
14+
0, 0, 4, 6)
2115

22-
assert_array_almost_equal([x1,y1,x2,y2],[2, 3, 3.3333333333333,5])
23-
#%% no intersection test
24-
x1,y1,x2,y2 = cohensutherland(1,5, 4,3,
25-
0,0.1,0,0.1)
26-
assert x1==y1==x2==y2==None
27-
#%% left to right test
28-
x1,y1,x2,y2 = cohensutherland(1,5,4,3,
29-
0,4,5,4)
30-
assert_array_almost_equal([x1,y1,x2,y2],[1, 4, 4, 4])
16+
assert_array_almost_equal([x1,y1,x2,y2],[2, 3, 3.3333333333333,5])
17+
#%% no intersection test
18+
x1,y1,x2,y2 = plc.cohensutherland(1,5, 4,3,
19+
0,0.1,0,0.1)
20+
assert x1==y1==x2==y2==None
21+
#%% left to right test
22+
x1,y1,x2,y2 = plc.cohensutherland(1,5,4,3,
23+
0,4,5,4)
24+
assert_array_almost_equal([x1,y1,x2,y2],[1, 4, 4, 4])
3125

32-
def test_fortran_lineclip(self):
33-
34-
subprocess.check_call([str(path / 'bin/RunLineclip')])
3526

3627

3728
if __name__ == '__main__':
38-
unittest.main()
29+
run_module_suite()

0 commit comments

Comments
 (0)