Skip to content

Commit

Permalink
Merge pull request #1 from jacobwilliams/develop
Browse files Browse the repository at this point in the history
adding CI
  • Loading branch information
jacobwilliams committed Apr 15, 2022
2 parents f7d00ff + c520beb commit 9e521f3
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 53 deletions.
80 changes: 80 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: CI
on: [push]
jobs:

Build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
gcc_v: [10] # Version of GFortran we want to use.
python-version: [3.9]
env:
FC: gfortran-${{ matrix.gcc_v }}
GCC_V: ${{ matrix.gcc_v }}

steps:
- name: Checkout code
uses: actions/checkout@v2
with:
submodules: recursive

- name: Set up Python 3.x
uses: actions/setup-python@v1 # Use pip to install latest CMake, & FORD/Jin2For, etc.
with:
python-version: ${{ matrix.python-version }}

- name: Setup Graphviz
uses: ts-graphviz/setup-graphviz@v1

- name: Setup Fortran Package Manager
uses: fortran-lang/setup-fpm@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Install Python dependencies
if: contains( matrix.os, 'ubuntu')
run: |
python -m pip install --upgrade pip
pip install matplotlib ford
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Install GFortran Linux
if: contains( matrix.os, 'ubuntu')
run: |
sudo apt-get install lcov
sudo update-alternatives \
--install /usr/bin/gcc gcc /usr/bin/gcc-${{ matrix.gcc_v }} 100 \
--slave /usr/bin/gfortran gfortran /usr/bin/gfortran-${{ matrix.gcc_v }} \
--slave /usr/bin/gcov gcov /usr/bin/gcov-${{ matrix.gcc_v }}
# - name: Compile
# run: fpm build --profile release --flag -fopenmp

- name: Run tests
run: fpm test --profile debug --flag -coverage --flag -fopenmp

- name: Create coverage report
run: |
mkdir -p ${{ env.COV_DIR }}
lcov --capture --initial --base-directory . --directory build/gfortran_*/ --output-file ${{ env.COV_DIR }}/coverage.base
lcov --capture --base-directory . --directory build/gfortran_*/ --output-file ${{ env.COV_DIR }}/coverage.capture
lcov --add-tracefile ${{ env.COV_DIR }}/coverage.base --add-tracefile ${{ env.COV_DIR }}/coverage.capture --output-file ${{ env.COV_DIR }}/coverage.info
env:
COV_DIR: build/coverage

- name: Upload coverage report
uses: codecov/codecov-action@v2
with:
files: build/coverage/coverage.info

- name: Build documentation
run: ford ./fgif.md

- name: Deploy Documentation
if: github.ref == 'refs/heads/master'
uses: JamesIves/github-pages-deploy-action@4.1.0
with:
branch: gh-pages # The branch the action should deploy to.
folder: doc # The folder the action should deploy.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@

.DS_Store

/*.gif
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2014-2021, Jacob Williams
Copyright (c) 2014-2022, Jacob Williams
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
![fgif](media/mandelbrot.gif)
============

[![GitHub release](https://img.shields.io/github/release/jacobwilliams/fgif.svg)](https://github.com/jacobwilliams/fgif/releases/latest)
[![Build Status](https://github.com/jacobwilliams/fgif/actions/workflows/CI.yml/badge.svg)](https://github.com/jacobwilliams/fgif/actions)
[![codecov](https://codecov.io/gh/jacobwilliams/fgif/branch/master/graph/badge.svg?token=43HK33CSMY)](https://codecov.io/gh/jacobwilliams/fgif)
[![last-commit](https://img.shields.io/github/last-commit/jacobwilliams/fgif)](https://github.com/jacobwilliams/fgif/commits/master)

FGIF: Create Animated GIFs with Fortran

### Description
Expand All @@ -13,17 +18,21 @@ Based on the public domain code at: http://fortranwiki.org/fortran/show/writegif
A `fmp.toml` file is provided for compiling `fgif` with the [Fortran Package Manager](https://github.com/fortran-lang/fpm). For example, to build:

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

And to run the unit tests:

```
fpm test --profile release
fpm test --profile release --flag "-fopenmp"
```

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

### Documentation

The latest API documentation can be found [here](http://jacobwilliams.github.io/fgif/). This was generated from the source code using [FORD](https://github.com/Fortran-FOSS-Programmers/ford).
13 changes: 13 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
comment:
layout: header, changes, diff, sunburst
coverage:
ignore:
- test
- doc
status:
patch:
default:
target: 70%
project:
default:
target: 60%
17 changes: 3 additions & 14 deletions fpm.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "fgif"
author = "Jacob Williams"
copyright = "Copyright (c) 2014-2021, Jacob Williams"
copyright = "Copyright (c) 2014-2022, Jacob Williams"
license = "BSD-3"
description = "Create Animated GIFs with Fortran"
homepage = "https://github.com/jacobwilliams/fgif"
Expand All @@ -9,21 +9,10 @@ keywords = ["gif"]
[build]
auto-executables = false
auto-examples = false
auto-tests = false
auto-tests = true

[library]
source-dir = "src"

[install]
library = true

[[test]]
name = "circle_illusion"
source-dir = "tests"
main = "circle_illusion.f90"

[[test]]
name = "mandelbrot"
source-dir = "tests"
main = "mandelbrot.f90"
link = ["gomp"]
library = true
File renamed without changes.
72 changes: 36 additions & 36 deletions tests/mandelbrot.f90 → test/mandelbrot.f90
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,41 @@
!# Using OpenMP
! * Compile with `-fopenmp`
! * Set number of threads from bash: `export OMP_NUM_THREADS=4`

program mandelbrot_example

use, intrinsic :: iso_fortran_env, only: wp=>real64
use gif_module

implicit none

integer :: i,ix,iy,n
integer,dimension(:,:,:),allocatable :: pixel !! pixel values
integer,dimension(:,:),allocatable :: colormap
integer,dimension(:,:),allocatable :: colormap
real(wp) :: xmin,xmax,ymin,ymax,xstep,ystep,x,y,tmp
integer :: width, height, iframe, maxiter
complex(wp) :: z, c
real(wp) :: tstart,tend

real(wp),external :: omp_get_wtime !OpenMP routine

integer, parameter :: nmax = 1000
integer, parameter :: nframes = 11

!build the colormap:
allocate(colormap(3,0:255))
do i=0,255
allocate(colormap(3,0:255))
do i=0,255
!colormap(:,i) = [255-i, 255-i, 255-i] !gray
colormap(:,i) = [255, 255-i, 255-i] !red
end do
colormap(:,255) = [0,0,0] !black

!full set:
! xmin = -2.0_wp
! xmax = 1.0_wp
! ymin = -1.3_wp
! ymax = 1.3_wp

!zoom test:
xmin = -0.55_wp
xmax = 0.25_wp
Expand All @@ -50,36 +50,36 @@ program mandelbrot_example

width = 250 !500 !1000
height = width * ((ymax-ymin)/(xmax-xmin))

xstep = (xmax-xmin)/width
ystep = (ymax-ymin)/height

allocate(pixel(nframes,width,height))
tstart = omp_get_wtime()

tstart = omp_get_wtime()

do iframe=1,nframes

!if (nframes==1) then
! maxiter = nmax
!else
! maxiter = 10 + (iframe-1)*(nmax/nframes)
!end if

maxiter = nmax

!$omp parallel shared (pixel) private (ix,iy,x,y,c,z,n)
!$omp do
!$omp do

do ix=1,width

x = xmin + (ix-1)*xstep

do iy=1,height
y = ymin + (iy-1)*ystep
c = cmplx(x, y)

y = ymin + (iy-1)*ystep
c = cmplx(x, y, kind=wp)

z = 0
n = 0
do while (abs(z)<2.0_wp .and. (n<=maxiter) )
Expand All @@ -91,15 +91,15 @@ program mandelbrot_example
else
!pixel(iframe,ix,height-iy+1) = mod(n,255) !not in set
pixel(iframe,ix,height-iy+1) = (nmax*n)/(255) !not in set

end if

end do !ix
end do !iy

!$omp end do
!$omp end parallel

!...zoom in test...
tmp = abs(xmax-xmin)
xmin = xmin + tmp/4
Expand All @@ -109,14 +109,14 @@ program mandelbrot_example
ymax = ymax - tmp/4
xstep = (xmax-xmin)/width
ystep = (ymax-ymin)/height
end do !iframe

end do !iframe

tend = omp_get_wtime()

write(*,*) 'run time:',tend-tstart,' sec'

call write_animated_gif('mandelbrot.gif',pixel,colormap,delay=10)

end program mandelbrot_example
!*****************************************************************************************

0 comments on commit 9e521f3

Please sign in to comment.