Skip to content

Commit

Permalink
Merge pull request #6 from jacobwilliams/develop
Browse files Browse the repository at this point in the history
develop
  • Loading branch information
jacobwilliams committed Feb 27, 2022
2 parents 3424bec + 235181a commit c2dd1ba
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 16 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
finterp: Modern Fortran Multidimensional Linear Interpolation
https://github.com/jacobwilliams/finterp

Copyright (c) 2016-2021, Jacob Williams
Copyright (c) 2016-2022, Jacob Williams
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
Expand Down
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ FINTERP: Multidimensional Linear Interpolation with Modern Fortran

## Status

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

## Description

Expand Down Expand Up @@ -65,6 +67,48 @@ call s6%destroy()

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.

## Compiling

A `fmp.toml` file is provided for compiling finterp with the [Fortran Package Manager](https://github.com/fortran-lang/fpm). For example, to build:

```
fpm build --profile release
```

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:

Preprocessor flag | Kind | Number of bytes
----------------- | ----- | ---------------
`REAL32` | `real(kind=real32)` | 4
`REAL64` | `real(kind=real64)` | 8
`REAL128` | `real(kind=real128)` | 16

For example, to build a single precision version of the library, use:

```
fpm build --profile release --flag "-DREAL32"
```

To run the unit tests:

```
fpm test
```

To use `finterp` within your fpm project, add the following to your `fpm.toml` file:
```toml
[dependencies]
finterp = { git="https://github.com/jacobwilliams/finterp.git" }
```

or, to use a specific version:
```toml
[dependencies]
finterp = { git="https://github.com/jacobwilliams/finterp.git", tag = "1.3.0" }
```

To generate the documentation using [ford](https://github.com/Fortran-FOSS-Programmers/ford), run: ```ford finterp.md```

## Documentation

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).
Expand Down
2 changes: 1 addition & 1 deletion finterp.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ display: public
protected
source: true
graph: true
exclude_dir: ./tests
exclude_dir: ./test
extra_mods: iso_fortran_env:https://gcc.gnu.org/onlinedocs/gfortran/ISO_005fFORTRAN_005fENV.html

{!README.md!}
2 changes: 1 addition & 1 deletion fpm.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = "finterp"
version = "1.2.3"
version = "1.3.0"
author = "Jacob Williams"
maintainer = "Jacob Williams"
copyright = "Copyright (c) 2016-2021, Jacob Williams"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,40 @@
! which have been tabulated at the nodes of an n-dimensional rectangular grid.
! If any coordinate \( (x_i, y_i, ...) \) lies outside the range of the corresponding
! variable, then extrapolation is performed using the two nearest points.
!
!@note The default real kind (`wp`) can be
! changed using optional preprocessor flags.
! This library was built with real kind:
#ifdef REAL32
! `real(kind=real32)` [4 bytes]
#elif REAL64
! `real(kind=real64)` [8 bytes]
#elif REAL128
! `real(kind=real128)` [16 bytes]
#else
! `real(kind=real64)` [8 bytes]
#endif

module linear_interpolation_module

use iso_fortran_env, only: wp => real64 ! working precision
use iso_fortran_env

implicit none

private

#ifdef REAL32
integer,parameter,public :: finterp_rk = real32 !! real kind used by this module [4 bytes]
#elif REAL64
integer,parameter,public :: finterp_rk = real64 !! real kind used by this module [8 bytes]
#elif REAL128
integer,parameter,public :: finterp_rk = real128 !! real kind used by this module [16 bytes]
#else
integer,parameter,public :: finterp_rk = real64 !! real kind used by this module [8 bytes]
#endif

integer,parameter :: wp = finterp_rk !! local copy of `finterp_rk` with a shorter name

real(wp),parameter,private :: zero = 0.0_wp !! numeric constant
real(wp),parameter,private :: one = 1.0_wp !! numeric constant

Expand Down
24 changes: 15 additions & 9 deletions test/test.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

program linear_interpolation_test

use linear_interpolation_module
use,intrinsic :: iso_fortran_env, only: wp => real64
use linear_interpolation_module, wp => finterp_rk

implicit none

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

real(wp) :: x(nx),y(ny),z(nz),q(nq),r(nr),s(ns)
real(wp) :: fcn_1d(nx)
real(wp) :: fcn_2d(nx,ny)
real(wp) :: fcn_3d(nx,ny,nz)
real(wp) :: fcn_4d(nx,ny,nz,nq)
real(wp) :: fcn_5d(nx,ny,nz,nq,nr)
real(wp) :: fcn_6d(nx,ny,nz,nq,nr,ns)
real(wp),dimension(:),allocatable :: fcn_1d
real(wp),dimension(:,:),allocatable :: fcn_2d
real(wp),dimension(:,:,:),allocatable :: fcn_3d
real(wp),dimension(:,:,:,:),allocatable :: fcn_4d
real(wp),dimension(:,:,:,:,:),allocatable :: fcn_5d
real(wp),dimension(:,:,:,:,:,:),allocatable :: fcn_6d

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

allocate(fcn_1d(nx))
allocate(fcn_2d(nx,ny))
allocate(fcn_3d(nx,ny,nz))
allocate(fcn_4d(nx,ny,nz,nq))
allocate(fcn_5d(nx,ny,nz,nq,nr))
allocate(fcn_6d(nx,ny,nz,nq,nr,ns))

fail = .false.
tol = 1.0e-14_wp
do i=1,nx
Expand Down
5 changes: 2 additions & 3 deletions test/test_nearest.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

program nearest_neighbor_test

use linear_interpolation_module
use,intrinsic :: iso_fortran_env, only: wp => real64
use linear_interpolation_module, wp => finterp_rk

implicit none

Expand All @@ -17,7 +16,7 @@ program nearest_neighbor_test

type(nearest_interp_1d) :: s1
real(wp) :: val,tru,err,errmax
integer :: i,idx,iflag
integer :: i,iflag

! initialize
call s1%initialize(x,fcn_1d,iflag)
Expand Down

0 comments on commit c2dd1ba

Please sign in to comment.