diff --git a/README.md b/README.md index cd03beb..acc7503 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,49 @@ Currently, this module can be used to generate simple plots from Fortran. Event The way it works is simply to generate a Python script with the plotting code, which is then executed from the command line using the Fortran ```execute_command_line``` function. -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). +### Compiling + +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 `fmp.toml` file is provided for compiling pyplot-fortran 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 `pyplot-fortran` within your fpm project, add the following to your `fpm.toml` file: +```toml +[dependencies] +pyplot-fortran = { git="https://github.com/jacobwilliams/pyplot-fortran.git" } +``` + +or, to use a specific version: +```toml +[dependencies] +pyplot-fortran = { git="https://github.com/jacobwilliams/pyplot-fortran.git", tag = "3.1.0" } +``` + +To generate the documentation using [ford](https://github.com/Fortran-FOSS-Programmers/ford), run: ```ford pyplot-fortran.md``` ### Supported plot types @@ -30,7 +72,7 @@ The module requires a modern Fortran compiler (it uses various Fortran 2003/2008 The following example generates a plot of the sine function: -```Fortran +```fortran program test use,intrinsic :: iso_fortran_env, only: wp => real64 @@ -57,7 +99,7 @@ The following example generates a plot of the sine function: ### Documentation - * 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. + * 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). ### See also diff --git a/build.sh b/build.sh deleted file mode 100755 index af51c97..0000000 --- a/build.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/bash - -# -# Simple build script for pyplot-fortran. -# - -PROJECTNAME='pyplot-fortran' # project name for robodoc -MODCODE='pyplot_module.f90' # module file name -FORDMD='pyplot-fortran.md' # FORD settings file -LIBOUT='libpyplot.a' # name of library -DOCDIR='./doc/' # build directory for documentation -SRCDIR='./src/' # library source directory -BINDIR='./bin/' # build directory for unit tests -LIBDIR='./lib/' # build directory for library - -#compiler flags: - -FCOMPILER='gnu' #Set default compiler to gfortran -FCOMPILERFLAGS='-c -O2 -fbacktrace -Wall -Wextra -Wno-maybe-uninitialized -Wno-unused-function -pedantic -std=f2008' - -#build the library and example using FoBiS: - -if hash FoBiS.py 2>/dev/null; then - FoBiS.py build -compiler ${FCOMPILER} -cflags "${FCOMPILERFLAGS}" -dbld ${LIBDIR} -s ${SRCDIR} -dmod ./ -dobj ./ -t ${MODCODE} -o ${LIBOUT} -mklib static -colors - FoBiS.py build -compiler ${FCOMPILER} -cflags "${FCOMPILERFLAGS}" -dbld ${BINDIR} -s ${SRCDIR} -dmod ./ -dobj ./ -colors -else - echo "FoBiS.py not found! Cannot build library. Install using: sudo pip install FoBiS.py" -fi - -# build the documentation using FORD: - -if hash ford 2>/dev/null; then - echo "Building documentation..." - ford ${FORDMD} -else - echo "FORD not found! Cannot build documentation. To install, run: sudo pip install ford" -fi \ No newline at end of file diff --git a/pyplot.fobis b/pyplot.fobis deleted file mode 100644 index efdbcee..0000000 --- a/pyplot.fobis +++ /dev/null @@ -1,144 +0,0 @@ -[modes] -modes = static-gnu static-gnu-debug - static-intel static-intel-debug - tests-gnu tests-gnu-debug - tests-intel tests-intel-debug - -[common-variables] -$CSTATIC_GNU = -c -fbacktrace -Wall -Wextra -Wno-maybe-uninitialized -Wno-unused-function -pedantic -std=f2008 -$CSTATIC_INT = -c -std08 -$DEBUG_GNU = -O0 -g3 -Warray-bounds -Wcharacter-truncation -Wline-truncation -Wimplicit-interface -Wimplicit-procedure -Wunderflow -fcheck=all -fmodule-private -ffree-line-length-132 -fimplicit-none -fbacktrace -fdump-core -finit-real=nan -std=f2008 -fall-intrinsics -$DEBUG_INT = -O0 -debug all -check all -warn all -extend-source 132 -traceback -gen-interfaces#-fpe-all=0 -fp-stack-check -fstack-protector-all -ftrapuv -no-ftz -std08 -$OPTIMIZE = -O2 - -# main modes -# library -[static-gnu] -description = Build library with GNU gfortran by optmized-static flags -compiler = gnu -cflags = $CSTATIC_GNU $OPTIMIZE -cflags_heritage = True -build_dir = ./lib/ -mod_dir = ./mod/ -obj_dir = ./obj/ -src = ./ -colors = True -quiet = False -log = False -jobs = 2 -mklib = static -target = pyplot_module.f90 -output = libpyplot.a - -[static-gnu-debug] -description = Build library with GNU gfortran by debug-static flags -compiler = gnu -cflags = $CSTATIC_GNU $DEBUG_GNU -cflags_heritage = True -build_dir = ./lib/ -mod_dir = ./mod/ -obj_dir = ./obj/ -src = ./ -colors = True -quiet = False -log = False -jobs = 2 -mklib = static -target = pyplot_module.f90 -output = libpyplot.a - -[static-intel] -description = Build library with Intel Fortran by optmized-static flags -compiler = intel -cflags = $CSTATIC_INT $OPTIMIZE -cflags_heritage = True -build_dir = ./lib/ -mod_dir = ./mod/ -obj_dir = ./obj/ -src = ./ -colors = True -quiet = False -log = False -jobs = 2 -mklib = static -target = pyplot_module.f90 -output = libpyplot.a - -[static-intel-debug] -description = Build library with Intel Fortran by debug-static flags -compiler = gnu -cflags = $CSTATIC_INT $DEBUG_INT -cflags_heritage = True -build_dir = ./lib/ -mod_dir = ./mod/ -obj_dir = ./obj/ -src = ./ -colors = True -quiet = False -log = False -jobs = 2 -mklib = static -target = pyplot_module.f90 -output = libpyplot.a - -# test programs -[tests-gnu] -description = Build all tests with GNU gfortran by optmized-static flags -compiler = gnu -cflags = $CSTATIC_GNU $OPTIMIZE -cflags_heritage = True -build_dir = ./bin/ -mod_dir = ./mod/ -obj_dir = ./obj/ -src = ./ -colors = True -quiet = False -log = False -jobs = 2 - -[tests-gnu-debug] -description = Build all tests with GNU gfortran by debug-static flags -compiler = gnu -cflags = $CSTATIC_GNU $DEBUG_GNU -cflags_heritage = True -build_dir = ./bin/ -mod_dir = ./mod/ -obj_dir = ./obj/ -src = ./ -colors = True -quiet = False -log = False -jobs = 2 - -[tests-intel] -description = Build all tests with Intel Fortran by optmized-static flags -compiler = intel -cflags = $CSTATIC_INT $OPTIMIZE -cflags_heritage = True -build_dir = ./bin/ -mod_dir = ./mod/ -obj_dir = ./obj/ -src = ./ -colors = True -quiet = False -log = False -jobs = 2 - -[tests-intel-debug] -description = Build all tests with Intel Fortran by debug-static flags -compiler = gnu -cflags = $CSTATIC_INT $DEBUG_INT -cflags_heritage = True -build_dir = ./bin/ -mod_dir = ./mod/ -obj_dir = ./obj/ -src = ./ -colors = True -quiet = False -log = False -jobs = 2 - -# auxiliary rules -[rule-makedoc] -help = Rule for building documentation from source files -rule_1 = ford pyplot-fortran.md diff --git a/src/pyplot_module.f90 b/src/pyplot_module.F90 similarity index 98% rename from src/pyplot_module.f90 rename to src/pyplot_module.F90 index 859c58c..82f8085 100644 --- a/src/pyplot_module.f90 +++ b/src/pyplot_module.F90 @@ -8,16 +8,39 @@ ! !# See also ! * Inspired by: [EasyPlot](https://pypi.python.org/pypi/EasyPlot) +! +!@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 pyplot_module - use, intrinsic :: iso_fortran_env, only : real64, error_unit + use, intrinsic :: iso_fortran_env implicit none private - integer, parameter, private :: wp = real64 !! Default real kind [8 bytes]. +#ifdef REAL32 + integer,parameter,public :: pyplot_wp = real32 !! real kind used by this module [4 bytes] +#elif REAL64 + integer,parameter,public :: pyplot_wp = real64 !! real kind used by this module [8 bytes] +#elif REAL128 + integer,parameter,public :: pyplot_wp = real128 !! real kind used by this module [16 bytes] +#else + integer,parameter,public :: pyplot_wp = real64 !! real kind used by this module [8 bytes] +#endif + + integer,parameter :: wp = pyplot_wp !! local copy of `pyplot_wp` with a shorter name character(len=*), parameter :: tmp_file = 'pyplot_module_temp_1234567890.py' !! Default name of the temporary file !! (this can also be user-specified). diff --git a/tests/test.f90 b/tests/test.f90 index 674df9f..e4449ea 100644 --- a/tests/test.f90 +++ b/tests/test.f90 @@ -7,8 +7,7 @@ program test - use, intrinsic :: iso_fortran_env, only : wp => real64 - use pyplot_module, only : pyplot + use pyplot_module, only : pyplot, wp => pyplot_wp implicit none