Skip to content

Commit c2dd1ba

Browse files
Merge pull request #6 from jacobwilliams/develop
develop
2 parents 3424bec + 235181a commit c2dd1ba

File tree

7 files changed

+90
-16
lines changed

7 files changed

+90
-16
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
finterp: Modern Fortran Multidimensional Linear Interpolation
22
https://github.com/jacobwilliams/finterp
33

4-
Copyright (c) 2016-2021, Jacob Williams
4+
Copyright (c) 2016-2022, Jacob Williams
55
All rights reserved.
66

77
Redistribution and use in source and binary forms, with or without modification,

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ FINTERP: Multidimensional Linear Interpolation with Modern Fortran
55

66
## Status
77

8+
[![GitHub release](https://img.shields.io/github/release/jacobwilliams/finterp.svg?style=plastic)](https://github.com/jacobwilliams/finterp/releases/latest)
89
![Build Status](https://github.com/jacobwilliams/finterp/actions/workflows/CI.yml/badge.svg?branch=master)
10+
[![codecov](https://codecov.io/gh/jacobwilliams/finterp/branch/master/graph/badge.svg?token=BHtd51oUTE)](https://codecov.io/gh/jacobwilliams/finterp)
911

1012
## Description
1113

@@ -65,6 +67,48 @@ call s6%destroy()
6567

6668
The library also includes classes for nearest neighbor interpolation (`nearest_interp_1d`, `nearest_interp_2d`, ...). The interfaces are the same as for the linear classes.
6769

70+
## Compiling
71+
72+
A `fmp.toml` file is provided for compiling finterp with the [Fortran Package Manager](https://github.com/fortran-lang/fpm). For example, to build:
73+
74+
```
75+
fpm build --profile release
76+
```
77+
78+
By default, the library is built with double precision (`real64`) real values. Explicitly specifying the real kind can be done using the following processor flags:
79+
80+
Preprocessor flag | Kind | Number of bytes
81+
----------------- | ----- | ---------------
82+
`REAL32` | `real(kind=real32)` | 4
83+
`REAL64` | `real(kind=real64)` | 8
84+
`REAL128` | `real(kind=real128)` | 16
85+
86+
For example, to build a single precision version of the library, use:
87+
88+
```
89+
fpm build --profile release --flag "-DREAL32"
90+
```
91+
92+
To run the unit tests:
93+
94+
```
95+
fpm test
96+
```
97+
98+
To use `finterp` within your fpm project, add the following to your `fpm.toml` file:
99+
```toml
100+
[dependencies]
101+
finterp = { git="https://github.com/jacobwilliams/finterp.git" }
102+
```
103+
104+
or, to use a specific version:
105+
```toml
106+
[dependencies]
107+
finterp = { git="https://github.com/jacobwilliams/finterp.git", tag = "1.3.0" }
108+
```
109+
110+
To generate the documentation using [ford](https://github.com/Fortran-FOSS-Programmers/ford), run: ```ford finterp.md```
111+
68112
## Documentation
69113

70114
The latest API documentation can be found [here](https://jacobwilliams.github.io/finterp/). This was generated from the source code using [FORD](https://github.com/Fortran-FOSS-Programmers/ford) (note that the included `build.sh` script will also generate these files).

finterp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ display: public
1515
protected
1616
source: true
1717
graph: true
18-
exclude_dir: ./tests
18+
exclude_dir: ./test
1919
extra_mods: iso_fortran_env:https://gcc.gnu.org/onlinedocs/gfortran/ISO_005fFORTRAN_005fENV.html
2020

2121
{!README.md!}

fpm.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name = "finterp"
2-
version = "1.2.3"
2+
version = "1.3.0"
33
author = "Jacob Williams"
44
maintainer = "Jacob Williams"
55
copyright = "Copyright (c) 2016-2021, Jacob Williams"
Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,40 @@
99
! which have been tabulated at the nodes of an n-dimensional rectangular grid.
1010
! If any coordinate \( (x_i, y_i, ...) \) lies outside the range of the corresponding
1111
! variable, then extrapolation is performed using the two nearest points.
12+
!
13+
!@note The default real kind (`wp`) can be
14+
! changed using optional preprocessor flags.
15+
! This library was built with real kind:
16+
#ifdef REAL32
17+
! `real(kind=real32)` [4 bytes]
18+
#elif REAL64
19+
! `real(kind=real64)` [8 bytes]
20+
#elif REAL128
21+
! `real(kind=real128)` [16 bytes]
22+
#else
23+
! `real(kind=real64)` [8 bytes]
24+
#endif
1225

1326
module linear_interpolation_module
1427

15-
use iso_fortran_env, only: wp => real64 ! working precision
28+
use iso_fortran_env
1629

1730
implicit none
1831

1932
private
2033

34+
#ifdef REAL32
35+
integer,parameter,public :: finterp_rk = real32 !! real kind used by this module [4 bytes]
36+
#elif REAL64
37+
integer,parameter,public :: finterp_rk = real64 !! real kind used by this module [8 bytes]
38+
#elif REAL128
39+
integer,parameter,public :: finterp_rk = real128 !! real kind used by this module [16 bytes]
40+
#else
41+
integer,parameter,public :: finterp_rk = real64 !! real kind used by this module [8 bytes]
42+
#endif
43+
44+
integer,parameter :: wp = finterp_rk !! local copy of `finterp_rk` with a shorter name
45+
2146
real(wp),parameter,private :: zero = 0.0_wp !! numeric constant
2247
real(wp),parameter,private :: one = 1.0_wp !! numeric constant
2348

test/test.f90

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
program linear_interpolation_test
66

7-
use linear_interpolation_module
8-
use,intrinsic :: iso_fortran_env, only: wp => real64
7+
use linear_interpolation_module, wp => finterp_rk
98

109
implicit none
1110

@@ -17,12 +16,12 @@ program linear_interpolation_test
1716
integer,parameter :: ns = 6 !! number of points in s
1817

1918
real(wp) :: x(nx),y(ny),z(nz),q(nq),r(nr),s(ns)
20-
real(wp) :: fcn_1d(nx)
21-
real(wp) :: fcn_2d(nx,ny)
22-
real(wp) :: fcn_3d(nx,ny,nz)
23-
real(wp) :: fcn_4d(nx,ny,nz,nq)
24-
real(wp) :: fcn_5d(nx,ny,nz,nq,nr)
25-
real(wp) :: fcn_6d(nx,ny,nz,nq,nr,ns)
19+
real(wp),dimension(:),allocatable :: fcn_1d
20+
real(wp),dimension(:,:),allocatable :: fcn_2d
21+
real(wp),dimension(:,:,:),allocatable :: fcn_3d
22+
real(wp),dimension(:,:,:,:),allocatable :: fcn_4d
23+
real(wp),dimension(:,:,:,:,:),allocatable :: fcn_5d
24+
real(wp),dimension(:,:,:,:,:,:),allocatable :: fcn_6d
2625

2726
type(linear_interp_1d) :: s1
2827
type(linear_interp_2d) :: s2
@@ -34,9 +33,16 @@ program linear_interpolation_test
3433
real(wp) :: tol,rnd
3534
real(wp),dimension(6) :: val,tru,err,errmax
3635
logical :: fail
37-
integer :: i,j,k,l,m,n,idx,idy,idz,idq,idr,ids
36+
integer :: i,j,k,l,m,n
3837
integer,dimension(6) :: iflag
3938

39+
allocate(fcn_1d(nx))
40+
allocate(fcn_2d(nx,ny))
41+
allocate(fcn_3d(nx,ny,nz))
42+
allocate(fcn_4d(nx,ny,nz,nq))
43+
allocate(fcn_5d(nx,ny,nz,nq,nr))
44+
allocate(fcn_6d(nx,ny,nz,nq,nr,ns))
45+
4046
fail = .false.
4147
tol = 1.0e-14_wp
4248
do i=1,nx

test/test_nearest.f90

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
program nearest_neighbor_test
66

7-
use linear_interpolation_module
8-
use,intrinsic :: iso_fortran_env, only: wp => real64
7+
use linear_interpolation_module, wp => finterp_rk
98

109
implicit none
1110

@@ -17,7 +16,7 @@ program nearest_neighbor_test
1716

1817
type(nearest_interp_1d) :: s1
1918
real(wp) :: val,tru,err,errmax
20-
integer :: i,idx,iflag
19+
integer :: i,iflag
2120

2221
! initialize
2322
call s1%initialize(x,fcn_1d,iflag)

0 commit comments

Comments
 (0)