Skip to content

Commit b04531d

Browse files
committed
template
1 parent 437a7c5 commit b04531d

File tree

14 files changed

+176
-205
lines changed

14 files changed

+176
-205
lines changed

.appveyor.yml

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,31 @@
11
image:
22
- Visual Studio 2017
3+
# - Ubuntu too old CMake 3.5
34

45
stack: python 3
56

67
environment:
78
MINGW_DIR: C:\mingw-w64\x86_64-7.2.0-posix-seh-rt_v5-rev1\mingw64\bin
8-
PY_DIR: C:\Python36-x64
9+
PY_DIR: C:\Python37-x64
910

1011
clone_depth: 3
1112

1213
before_build:
1314
- cmd: set PATH=%MINGW_DIR%;%PY_DIR%;%PY_DIR%\Scripts;%PATH%
14-
# fix CMake sh.exe issue, by removing Git path.
15-
- cmd: set PATH=%PATH:C:\Program Files\Git\usr\bin;=%
16-
- cmd: set FC=%MINGW_DIR%\gfortran
17-
- cmd: set CXX=%MINGW_DIR%\g++
18-
- cmd: set CC=%MINGW_DIR%\gcc
19-
- cmd: mklink bin\make.exe %MINGW_DIR%\mingw32-make.exe
2015

21-
- sh: sudo apt -yq update > /dev/null
22-
- sh: sudo apt install -yq --no-install-suggests --no-install-recommends gfortran cmake make > /dev/null
16+
- sh: sudo apt-get -yq update > /dev/null
17+
- sh: sudo apt-get install -yq --no-install-suggests --no-install-recommends gfortran cmake make > /dev/null
2318

2419
build_script:
2520
- pip install -e .[tests]
2621

2722
- cd bin
28-
- cmd: cmake -G "MinGW Makefiles" ..
23+
- cmd: cmake -G "MinGW Makefiles" -DCMAKE_SH="CMAKE_SH-NOTFOUND" ..
2924
- sh: cmake ..
30-
- make
25+
- cmake --build .
3126

3227
after_build:
33-
- make test
28+
- ctest -V
3429
- cd ..
35-
- pytest -v
30+
- pytest -xsv
3631

.travis.yml

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
language: python
2-
fast_finish: true
2+
sudo: required
3+
dist: xenial
4+
group: travis_latest
5+
6+
git:
7+
depth: 3
8+
quiet: true
39

4-
python:
10+
python:
511
- 3.5
612
- 3.6
7-
- "3.7-dev"
13+
- 3.7
814

915
os:
1016
- linux
1117

1218
env: FC=gfortran-6
1319

14-
group: travis_latest
15-
16-
git:
17-
depth: 3
18-
1920
addons:
2021
apt:
2122
sources:
@@ -27,32 +28,29 @@ addons:
2728
before_install:
2829
- if [[ $TRAVIS_OS_NAME == osx ]]; then
2930
brew update > /dev/null;
30-
brew install gcc || true > /dev/null;
31-
brew link --overwrite gcc > /dev/null;
31+
brew install gcc > /dev/null || brew link --overwrite gcc > /dev/null;
3232
export FC=gfortran;
3333
brew install opencoarrays > /dev/null;
3434
fi
3535

3636
install:
37-
- pip -q install -e .[tests]
38-
37+
- pip install -e .[tests]
38+
3939
- cd bin
4040
- cmake ..
41-
- make
42-
- make test
43-
- cd ..
41+
- cmake --build .
4442

45-
script:
43+
script:
44+
- ctest -V
45+
- cd ..
46+
4647
- pytest -sv
4748
- flake8
4849
- mypy . --ignore-missing-imports
4950

50-
after_success:
51+
after_success:
5152
- if [[ $TRAVIS_PYTHON_VERSION == 3.6* ]]; then
52-
coverage run tests/test_all.py;
53+
pytest --cov;
5354
coveralls;
5455
fi
55-
56-
after_failure:
57-
- ctest -V
5856

CMakeLists.txt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ else()
1010
endif()
1111

1212
if(${CMAKE_Fortran_COMPILER_ID} STREQUAL GNU)
13-
if(${CMAKE_Fortran_COMPILER_VERSION} VERSION_GREATER_EQUAL 8.1)
13+
if(${CMAKE_Fortran_COMPILER_VERSION} VERSION_GREATER_EQUAL 8)
1414
list(APPEND FFLAGS -std=f2018)
1515
endif()
1616

1717
list(APPEND FFLAGS -mtune=native -Wall -Wextra -Wpedantic -Werror=array-bounds -fbacktrace -fexceptions)
18-
if(NOT CYGWIN AND NOT WIN32)
18+
if(UNIX AND NOT (CYGWIN OR APPLE))
1919
list(APPEND FFLAGS -fstack-protector-all)
2020
endif()
2121
elseif(${CMAKE_Fortran_COMPILER_ID} STREQUAL PGI)
@@ -43,13 +43,17 @@ elseif(${CMAKE_Fortran_COMPILER_ID} STREQUAL GNU)
4343
endif()
4444
endif()
4545

46-
set(okcomp GNU Intel)
47-
if(CMAKE_Fortran_COMPILER_ID IN_LIST okcomp)
48-
add_library(assert assert.f90)
46+
47+
add_library(assert assert.f90)
48+
target_compile_options(assert PRIVATE ${FFLAGS})
49+
50+
set(f08 GNU Intel)
51+
if(CMAKE_Fortran_COMPILER_ID IN_LIST f08)
52+
target_sources(assert PRIVATE error2008.f90)
4953
else()
50-
add_library(assert assert_legacy.f90)
54+
target_sources(assert PRIVATE error2003.f90)
5155
endif()
52-
target_compile_options(assert PRIVATE ${FFLAGS})
56+
5357

5458
add_library(lineclip lineclipping.f90)
5559
target_compile_options(lineclip 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, only: wp, err, assert_isclose
5+
use assert, only: wp, errorstop, 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]))) call err('failed no intersection test')
69+
if (.not.all(ieee_is_nan([x1,y1,x2,y2]))) call errorstop() !'failed no intersection test'
7070

7171
print *, 'OK lineclip'
7272

DemoLineclip.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
#!/usr/bin/env python
22
import numpy as np
3-
from lineClipping import cohensutherland
3+
from pylineclip import cohensutherland
44

55
"""
66
make box with corners LL/UR (1,3) (4,5)
77
and line segment with ends (0,0) (4,6)
88
"""
9-
# %% LOWER to UPPER test
10-
x1, y1, x2, y2 = cohensutherland(1, 5, 4, 3,
11-
0, 0, 4, 6)
129

13-
np.testing.assert_array_almost_equal([x1, y1, x2, y2], [2, 3, 3.3333333333333, 5])
14-
# %% no intersection test
15-
x1, y1, x2, y2 = cohensutherland(1, 5, 4, 3,
16-
0, 0.1, 0, 0.1)
1710

18-
assert x1 is None and y1 is None and x2 is None and y2 is None
19-
# %% left to right test
20-
x1, y1, x2, y2 = cohensutherland(1, 5, 4, 3,
21-
0, 4, 5, 4)
22-
np.testing.assert_array_almost_equal([x1, y1, x2, y2], [1, 4, 4, 4])
11+
def main():
12+
# %% LOWER to UPPER test
13+
x1, y1, x2, y2 = cohensutherland(1, 5, 4, 3,
14+
0, 0, 4, 6)
15+
16+
np.testing.assert_array_almost_equal([x1, y1, x2, y2], [2, 3, 3.3333333333333, 5])
17+
# %% no intersection test
18+
x1, y1, x2, y2 = cohensutherland(1, 5, 4, 3,
19+
0, 0.1, 0, 0.1)
20+
21+
assert x1 is None and y1 is None and x2 is None and y2 is None
22+
# %% left to right test
23+
x1, y1, x2, y2 = cohensutherland(1, 5, 4, 3,
24+
0, 4, 5, 4)
25+
np.testing.assert_array_almost_equal([x1, y1, x2, y2], [1, 4, 4, 4])
26+
27+
28+
if __name__ == '__main__':
29+
main()

assert.f90

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
module assert
2+
! Gfortran >= 6 needed for ieee_arithmetic: ieee_is_nan
23

34
use, intrinsic:: iso_c_binding, only: sp=>c_float, dp=>c_double
45
use, intrinsic:: iso_fortran_env, only: stderr=>error_unit
5-
use, intrinsic:: ieee_arithmetic
6+
use, intrinsic:: ieee_arithmetic, only: ieee_is_finite, ieee_is_nan
7+
use error, only: errorstop
68
implicit none
79
private
8-
10+
911
integer,parameter :: wp = sp
1012

11-
public :: wp,isclose, assert_isclose, err
12-
13+
public :: wp,isclose, assert_isclose, errorstop
14+
1315
contains
1416

1517
elemental logical function isclose(actual, desired, rtol, atol, equal_nan)
@@ -29,7 +31,7 @@ elemental logical function isclose(actual, desired, rtol, atol, equal_nan)
2931
real(wp), intent(in) :: actual, desired
3032
real(wp), intent(in), optional :: rtol, atol
3133
logical, intent(in), optional :: equal_nan
32-
34+
3335
real(wp) :: r,a
3436
logical :: n
3537
! this is appropriate INSTEAD OF merge(), since non present values aren't defined.
@@ -41,12 +43,12 @@ elemental logical function isclose(actual, desired, rtol, atol, equal_nan)
4143
if (present(equal_nan)) n = equal_nan
4244

4345
!print*,r,a,n,actual,desired
44-
46+
4547
!--- sanity check
46-
if ((r < 0._wp).or.(a < 0._wp)) error stop 'tolerances must be non-negative'
47-
!--- simplest case
48-
isclose = (actual == desired)
49-
if (isclose) return
48+
if ((r < 0._wp).or.(a < 0._wp)) call errorstop
49+
!--- simplest case -- too unlikely, especially for arrays?
50+
!isclose = (actual == desired)
51+
!if (isclose) return
5052
!--- equal nan
5153
isclose = n.and.(ieee_is_nan(actual).and.ieee_is_nan(desired))
5254
if (isclose) return
@@ -59,6 +61,8 @@ end function isclose
5961

6062

6163
impure elemental subroutine assert_isclose(actual, desired, rtol, atol, equal_nan, err_msg)
64+
! NOTE: with Fortran 2018 this can be Pure
65+
!
6266
! inputs
6367
! ------
6468
! actual: value "measured"
@@ -77,15 +81,10 @@ impure elemental subroutine assert_isclose(actual, desired, rtol, atol, equal_na
7781

7882
if (.not.isclose(actual,desired,rtol,atol,equal_nan)) then
7983
write(stderr,*) merge(err_msg,'',present(err_msg)),': actual',actual,'desired',desired
80-
error stop
84+
call errorstop
8185
endif
8286

8387
end subroutine assert_isclose
8488

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

assert_legacy.f90

Lines changed: 0 additions & 92 deletions
This file was deleted.

error2003.f90

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module error
2+
3+
implicit none
4+
5+
contains
6+
7+
pure subroutine errorstop
8+
stop 1
9+
end subroutine errorstop
10+
11+
end module error
12+

0 commit comments

Comments
 (0)