Skip to content

Commit e9d2235

Browse files
committed
added FPM support
added VSCode config file. updates to CI. moved tests folder out of src
1 parent 497671b commit e9d2235

File tree

8 files changed

+94
-53
lines changed

8 files changed

+94
-53
lines changed

.github/workflows/CI.yml

+19-11
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,36 @@ jobs:
99
matrix:
1010
os: [ubuntu-latest]
1111
gcc_v: [9] # Version of GFortran we want to use.
12+
python-version: [3.7]
1213
env:
1314
FC: gfortran-${{ matrix.gcc_v }}
1415
GCC_V: ${{ matrix.gcc_v }}
1516

1617
steps:
1718
- name: Checkout code
18-
uses: actions/checkout@v1
19+
uses: actions/checkout@v2
20+
with:
21+
submodules: recursive
1922

2023
- name: Set up Python 3.x
2124
uses: actions/setup-python@v1 # Use pip to install latest CMake, & FORD/Jin2For, etc.
2225
with:
23-
python-version: 3.x
26+
python-version: ${{ matrix.python-version }}
27+
28+
- name: Setup Graphviz
29+
uses: ts-graphviz/setup-graphviz@v1
2430

25-
- name: Install other tools
31+
- name: Setup Fortran Package Manager
32+
uses: fortran-lang/setup-fpm@v3
33+
with:
34+
github-token: ${{ secrets.GITHUB_TOKEN }}
35+
36+
- name: Install Python dependencies
2637
if: contains( matrix.os, 'ubuntu')
2738
run: |
28-
sudo apt-get install graphviz
29-
sudo -H pip install numpy
30-
sudo -H pip install ford && ford --version
31-
sudo -H pip install matplotlib
39+
python -m pip install --upgrade pip
40+
pip install numpy matplotlib ford
41+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
3242
3343
- name: Install GFortran Linux
3444
if: contains( matrix.os, 'ubuntu')
@@ -41,9 +51,7 @@ jobs:
4151
--slave /usr/bingcov gcov /usr/bin/gcov-${GCC_V}
4252
4353
- name: Compile
44-
run: |
45-
mkdir bin
46-
gfortran -O2 ./src/pyplot_module.f90 ./src/tests/test.f90 -o ./bin/test
54+
run: fpm build --profile release
4755

4856
- name: Run test
4957
run: ./bin/test
@@ -52,7 +60,7 @@ jobs:
5260
run: ford ./pyplot-fortran.md
5361

5462
- name: Deploy Documentation
55-
if: github.ref == 'refs/heads/master'
63+
if: github.ref == 'refs/heads/master'
5664
uses: JamesIves/github-pages-deploy-action@4.1.0
5765
with:
5866
branch: gh-pages # The branch the action should deploy to.

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
bin/
22
lib/
33
doc/
4+
build/
45

56
# Compiled Object files
67
*.slo

README.md

+27-32
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
Pyplot-Fortran
2-
=============================
1+
### Pyplot-Fortran
2+
33

44
A simple module for generating plots from Fortran using Python's matplotlib.pyplot.
55

6-
Overview
7-
---------------
6+
### Overview
87

98
Currently, this module can be used to generate simple plots from Fortran. Eventually, it may be expanded to provide additional features and other types of plots.
109

1110
The way it works is simply to generate a Python script with the plotting code, which
1211
is then executed from the command line using the Fortran ```execute_command_line``` function.
1312

14-
The module requires a modern Fortran compiler (it uses various Fortran 2003/2008 features such as deferred-length strings). It should work fine with the latest gfortran or ifort compilers. A simple script ```build.sh``` is provided for building the library and test program (requires gfortran and [FoBiS](https://github.com/szaghi/FoBiS)). It will also build the HTML documentation if [FORD](https://github.com/cmacmackin/ford) is installed.
13+
The module requires a modern Fortran compiler (it uses various Fortran 2003/2008 features such as deferred-length strings). It should work fine with the latest gfortran or ifort compilers. A simple script ```build.sh``` is provided for building the library and test program (requires gfortran and [FoBiS](https://github.com/szaghi/FoBiS)). It will also build the HTML documentation if [FORD](https://github.com/Fortran-FOSS-Programmers/ford) is installed. A `fpm.toml` file is also provided for use with the [Fortran Package Manager](https://github.com/fortran-lang/fpm).
1514

16-
Supported plot types
17-
---------------
15+
### Supported plot types
1816

1917
* ```matplotlib.pyplot.plot``` -- 2D/3D plot of lines and/or markers
2018
* ```matplotlib.pyplot.bar``` -- bar plot
@@ -24,42 +22,39 @@ Supported plot types
2422
* ```matplotlib.pyplot.hist``` -- histogram plot
2523
* ```matplotlib.pyplot.errorbar``` -- errorbar plot
2624

27-
Example
28-
---------------
25+
### Example
2926

3027
The following example generates a plot of the sine function:
3128

3229
```Fortran
33-
program test
34-
35-
use,intrinsic :: iso_fortran_env, only: wp => real64
36-
use pyplot_module
30+
program test
3731
38-
implicit none
32+
use,intrinsic :: iso_fortran_env, only: wp => real64
33+
use pyplot_module
3934
40-
real(wp),dimension(100) :: x,sx
41-
type(pyplot) :: plt
42-
integer :: i
35+
implicit none
4336
44-
!generate some data:
45-
x = [(real(i,wp), i=0,size(x)-1)]/5.0_wp
46-
sx = sin(x)
37+
real(wp),dimension(100) :: x,sx
38+
type(pyplot) :: plt
39+
integer :: i
4740
48-
!plot it:
49-
call plt%initialize(grid=.true.,xlabel='angle (rad)',&
50-
title='Plot of $\sin(x)$',legend=.true.)
51-
call plt%add_plot(x,sx,label='$\sin(x)$',linestyle='b-o',markersize=5,linewidth=2)
52-
call plt%savefig('sinx.png', pyfile='sinx.py')
41+
!generate some data:
42+
x = [(real(i,wp), i=0,size(x)-1)]/5.0_wp
43+
sx = sin(x)
5344
54-
end program test
45+
!plot it:
46+
call plt%initialize(grid=.true.,xlabel='angle (rad)',&
47+
title='Plot of $\sin(x)$',legend=.true.)
48+
call plt%add_plot(x,sx,label='$\sin(x)$',linestyle='b-o',markersize=5,linewidth=2)
49+
call plt%savefig('sinx.png', pyfile='sinx.py')
5550
51+
end program test
5652
```
5753

58-
Documentation
59-
---------------
54+
### Documentation
55+
56+
* The API documentation for the current ```master``` branch can be found [here](https://jacobwilliams.github.io/pyplot-fortran/). This is generated by processing the source files with [FORD](https://github.com/Fortran-FOSS-Programmers/ford). Note that the build script will also generate these files automatically in the ```doc``` folder, assuming you have FORD installed.
6057

61-
* The API documentation for the current ```master``` branch can be found [here](http://jacobwilliams.github.io/pyplot-fortran/). This is generated by processing the source files with [FORD](https://github.com/cmacmackin/ford). Note that the build script will also generate these files automatically in the ```doc``` folder, assuming you have FORD installed.
58+
### See also
6259

63-
See also
64-
---------------
65-
* [Matplotlib](http://matplotlib.org)
60+
* [Matplotlib](https://matplotlib.org)

fpm.toml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name = "pyplot-fortran"
2+
version = "3.1.0"
3+
author = "Jacob Williams"
4+
maintainer = "Jacob Williams"
5+
copyright = "Copyright (c) 2015-2021, Jacob Williams"
6+
license = "BSD-3"
7+
description = "A simple module for generating plots from Fortran using Python's matplotlib.pyplot."
8+
homepage = "https://github.com/jacobwilliams/pyplot-fortran"
9+
10+
[library]
11+
source-dir = "src"
12+
13+
[install]
14+
library = true
15+
16+
[build]
17+
auto-executables = false
18+
auto-examples = false
19+
auto-tests = false
20+
21+
[[test]]
22+
name = "test"
23+
source-dir = "tests"
24+
main = "test.f90"

pyplot-fortran.code-workspace

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"folders": [
3+
{
4+
"path": "."
5+
}
6+
],
7+
"settings": {
8+
"files.trimTrailingWhitespace": true,
9+
"editor.insertSpaces": true,
10+
"editor.tabSize": 4,
11+
"editor.trimAutoWhitespace": true
12+
}
13+
}

pyplot.fobis

+8-8
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ cflags_heritage = True
2121
build_dir = ./lib/
2222
mod_dir = ./mod/
2323
obj_dir = ./obj/
24-
src = ./src/
24+
src = ./
2525
colors = True
2626
quiet = False
2727
log = False
@@ -38,7 +38,7 @@ cflags_heritage = True
3838
build_dir = ./lib/
3939
mod_dir = ./mod/
4040
obj_dir = ./obj/
41-
src = ./src/
41+
src = ./
4242
colors = True
4343
quiet = False
4444
log = False
@@ -55,7 +55,7 @@ cflags_heritage = True
5555
build_dir = ./lib/
5656
mod_dir = ./mod/
5757
obj_dir = ./obj/
58-
src = ./src/
58+
src = ./
5959
colors = True
6060
quiet = False
6161
log = False
@@ -72,7 +72,7 @@ cflags_heritage = True
7272
build_dir = ./lib/
7373
mod_dir = ./mod/
7474
obj_dir = ./obj/
75-
src = ./src/
75+
src = ./
7676
colors = True
7777
quiet = False
7878
log = False
@@ -90,7 +90,7 @@ cflags_heritage = True
9090
build_dir = ./bin/
9191
mod_dir = ./mod/
9292
obj_dir = ./obj/
93-
src = ./src/
93+
src = ./
9494
colors = True
9595
quiet = False
9696
log = False
@@ -104,7 +104,7 @@ cflags_heritage = True
104104
build_dir = ./bin/
105105
mod_dir = ./mod/
106106
obj_dir = ./obj/
107-
src = ./src/
107+
src = ./
108108
colors = True
109109
quiet = False
110110
log = False
@@ -118,7 +118,7 @@ cflags_heritage = True
118118
build_dir = ./bin/
119119
mod_dir = ./mod/
120120
obj_dir = ./obj/
121-
src = ./src/
121+
src = ./
122122
colors = True
123123
quiet = False
124124
log = False
@@ -132,7 +132,7 @@ cflags_heritage = True
132132
build_dir = ./bin/
133133
mod_dir = ./mod/
134134
obj_dir = ./obj/
135-
src = ./src/
135+
src = ./
136136
colors = True
137137
quiet = False
138138
log = False

src/pyplot_module.f90

+2-2
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ subroutine initialize(me, grid, xlabel, ylabel, zlabel, title, legend, use_numpy
243243
call me%add_str('matplotlib.rcParams["xtick.labelsize"] = '//trim(xtick_labelsize_str))
244244
call me%add_str('matplotlib.rcParams["ytick.labelsize"] = '//trim(ytick_labelsize_str))
245245
call me%add_str('matplotlib.rcParams["legend.fontsize"] = '//trim(legend_fontsize_str))
246-
if (me%usetex) call me%add_str('matplotlib.rcParams["text.usetex"] = True')
246+
if (me%usetex) call me%add_str('matplotlib.rcParams["text.usetex"] = True')
247247

248248
call me%add_str('')
249249

@@ -427,7 +427,7 @@ subroutine add_hist(me, x, label, xlim, ylim, xscale, yscale, bins, normed, cumu
427427
trim(xname)//','//&
428428
'label='//trim(me%raw_str_token)//'"'//trim(label)//'",'//&
429429
'bins='//trim(binsstr)//','//&
430-
'cumulative='//trim(cumulativestr)//')')
430+
'cumulative='//trim(cumulativestr)//')')
431431

432432
!axis limits:
433433
if (allocated(xlimstr)) call me%add_str('ax.set_xlim('//xlimstr//')')
File renamed without changes.

0 commit comments

Comments
 (0)