Skip to content

Commit

Permalink
Merge pull request #1 from jacobwilliams/refactor
Browse files Browse the repository at this point in the history
Refactor
  • Loading branch information
jacobwilliams authored Feb 7, 2024
2 parents 3cf28aa + 445edb9 commit 358db8e
Show file tree
Hide file tree
Showing 30 changed files with 2,651 additions and 193 deletions.
86 changes: 86 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: CI
on: [push]
jobs:

Build:
runs-on: ${{ matrix.os }}
permissions:
contents: write
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@v3
with:
submodules: recursive

- name: Install Python
uses: actions/setup-python@v4 # 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@v5
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Install Python dependencies
if: contains( matrix.os, 'ubuntu')
run: |
python -m pip install --upgrade pip
pip install ford numpy matplotlib
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 add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install -y gcc-${{ matrix.gcc_v }} gfortran-${{ matrix.gcc_v }}
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

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

- name: Create coverage report
run: |
mkdir -p ${{ env.COV_DIR }}
mv ./build/gfortran_*/*/* ${{ env.COV_DIR }}
lcov --capture --initial --base-directory . --directory ${{ env.COV_DIR }} --output-file ${{ env.COV_DIR }}/coverage.base
lcov --capture --base-directory . --directory ${{ env.COV_DIR }} --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@v3
with:
files: build/coverage/coverage.info

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

- name: Deploy Documentation
if: github.ref == 'refs/heads/master'
uses: JamesIves/[email protected]
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 @@ -39,3 +39,4 @@
/doc
/lib
/bin
/archive
90 changes: 63 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,45 @@
National Space Science Data Center Data set PT-11B Mar 1996
Radbelt: Work in progress to refactor the AE-8/AP-8 Van Allen belt model.

### Status

[![Language](https://img.shields.io/badge/-Fortran-734f96?logo=fortran&logoColor=white)](https://github.com/topics/fortran)
[![GitHub release](https://img.shields.io/github/release/jacobwilliams/radbelt.svg)](https://github.com/jacobwilliams/radbelt/releases/latest)
[![CI Status](https://github.com/jacobwilliams/radbelt/actions/workflows/CI.yml/badge.svg)](https://github.com/jacobwilliams/radbelt/actions)
[![codecov](https://codecov.io/gh/jacobwilliams/radbelt/branch/master/graph/badge.svg)](https://codecov.io/gh/jacobwilliams/radbelt)
[![last-commit](https://img.shields.io/github/last-commit/jacobwilliams/radbelt)](https://github.com/jacobwilliams/radbelt/commits/master)

### Compiling

A [Fortran Package Manager](https://github.com/fortran-lang/fpm) manifest file is included, so that the library and test cases can be compiled with FPM. For example:

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

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

### Documentation

The latest API documentation can be found [here](https://jacobwilliams.github.io/radbelt/). This was generated from the source code using [FORD](https://github.com/Fortran-FOSS-Programmers/ford).

### See also

* [NASA ModelWebArchive](https://git.smce.nasa.gov/ccmc-share/modelwebarchive)
* [An Astropy-friendly wrapper for the AE-8/AP-8 Van Allen belt model](https://github.com/nasa/radbelt)
* [pyIGRF](https://github.com/rilma/pyIGRF)
* https://github.com/lanl/RAM-SCB/blob/master/srcExternal/igrf.f
* https://github.com/space-physics/igrf/blob/main/src/igrf/fortran/igrf13.f



# Original Readme

National Space Science Data Center Data set PT-11B Mar 1996
=========================================================================

```
Expand All @@ -12,7 +53,7 @@ SOURCE: Dieter Bilitza, GSFC/NSSDC code 633, Greenbelt,
[email protected]
CONTENT: 12 files *.* blocks
FORTRAN source code:
FORTRAN source code:
driver program with interface RADBELT.FOR 48
subroutines, functions TRMFUN.FOR 30
Expand All @@ -34,48 +75,43 @@ CONTENT: 12 files *.* blocks

These empirical models describe the differential or
integral, omnidirectional fluxes of electrons (AE-8) and protons
(AP-8) in the inner and outer radiation belts (electrons: L=1.1
to 11, protons: L=1.1 to 7) for two epochs representing solar
maximum (1970) and minimum (1964) conditions. The energy spectrum
ranges from 0.1 to 400 MeV for the protons and from 0.04 to 7 MeV
for the electrons. AE-8 and AP-8 are the most recent ones in a
series of models established by J. Vette and his colleges at NSSDC
starting in the early sixties. The models are based on almost all
(AP-8) in the inner and outer radiation belts (electrons: L=1.1
to 11, protons: L=1.1 to 7) for two epochs representing solar
maximum (1970) and minimum (1964) conditions. The energy spectrum
ranges from 0.1 to 400 MeV for the protons and from 0.04 to 7 MeV
for the electrons. AE-8 and AP-8 are the most recent ones in a
series of models established by J. Vette and his colleges at NSSDC
starting in the early sixties. The models are based on almost all
available satellite data. It is IMPORTANT that the models maps for
solar maximum are used with a magnetic field model for epoch=1970
and for solar minimum for epoch=1964.

For each epoch and particle the model consists of a three-
dimensional table of (logarithm of) particle fluxes in energy, L-value,
and B/B0 (magnetic field strength normalized to the equator). The program
MODEL finds the particle fluxes for given energy, L-value and B/B0 by
interpolating in energy (subroutine TRARA1) and in L * B/B0 space (TRARA2).
dimensional table of (logarithm of) particle fluxes in energy, L-value,
and B/B0 (magnetic field strength normalized to the equator). The program
MODEL finds the particle fluxes for given energy, L-value and B/B0 by
interpolating in energy (subroutine TRARA1) and in L * B/B0 space (TRARA2).
The program RADBELT produces tables of integral or differential fluxes
for different energies varying with L or B/B0.

The coefficient files are provided in VAX/VMS binary (*.bin) and
ASCII (*.asc) format. For all systems other than VMS the use of the ASCII
files is recommended. If using the ASCII coefficient one needs to slightly
files is recommended. If using the ASCII coefficient one needs to slightly
modify the RADBELT.FOR program as described in a comment statement in
RADBELT (this comments are found after the OPEN statement for the coefficient
RADBELT (this comments are found after the OPEN statement for the coefficient
file).

In March 1995 the earlier used compressed model maps AP8MIC and AP8MAC
were replaced with the full maps AP8MIN/MAX with the help of D. Heynderickx
(BIRA, Brussel, Belgium) and A. Beliaev (INP/MSU, Moscow, Russia). Heynderickx
and Beliaev (1995) had found and corrected a small error in the AP8MIN map;
were replaced with the full maps AP8MIN/MAX with the help of D. Heynderickx
(BIRA, Brussel, Belgium) and A. Beliaev (INP/MSU, Moscow, Russia). Heynderickx
and Beliaev (1995) had found and corrected a small error in the AP8MIN map;
two lines had been exchanged.

### AVAILABILITY:

(1) FORTRAN source code from this directory.
(2) Model parameters can be computed and plotted online at http://nssdc.gsfc.nasa.gov/space/model/ .


### See also

* [NASA ModelWebArchive](https://git.smce.nasa.gov/ccmc-share/modelwebarchive)

### REFERENCES:

G.W. Singley, and J.I. Vette, The AE-4 Model of the Outer Radiation
Expand All @@ -102,16 +138,16 @@ M.T. Teague, N.J. Schofield, K.W. Chan, and J.I. Vette, A Study of
Inner Zone Electron Data and their Comparison with Trapped
Radiation Models, NSSDC/WDC-A-R&S 79-06, 1979.

J.I. Vette, The AE-8 Trapped Electron Model Environment,
J.I. Vette, The AE-8 Trapped Electron Model Environment,
NSSDC/WDC-A-R&S 91-24, 1991.

J.I. Vette, The NASA/National Space Science Data Center Trapped
Radiation Environment Model Program (1964-1991), NSSDC/WDC-A-R&S
J.I. Vette, The NASA/National Space Science Data Center Trapped
Radiation Environment Model Program (1964-1991), NSSDC/WDC-A-R&S
91-29, 1991.

(most of these references are available from NSSDC)

D. Heynderickx and A. Beliaev, J. Spacecraft and Rockets 32, 190-192, 1995.

National Space Science Data Center Data set PT-11B Mar 1996
National Space Science Data Center Data set PT-11B Mar 1996
=========================================================================
65 changes: 33 additions & 32 deletions test/radbelt.f90 → app/radbelt.f90
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
!*==spag_program_1.f90 processed by SPAG 8.01MH 17:13 30 Jan 2024
!!SPAG Open source Personal, Educational or Academic User NON-COMMERCIAL USE - Not for use on proprietary or closed source code
PROGRAM spag_program_1

use radbelt_module

use trmfun_module
use radbelt_kinds_module

IMPLICIT NONE
!*** Start of declarations inserted by SPAG
REAL af , bb0 , bbeg , bend , blv , bstep , df , e , ebeg , eda , ediff , eend , ei , estep , fl , flux , vbeg , vend , vstep , &
& xl
REAL xmax , xmin , xx
INTEGER i , ib , ibl , ibltab , ie , iei , ihead , il , inde , itest , itt , iuaeap , iuout , j , jagnr , jpara , jtab , k , l ,&
& map

type(trm_type) :: trm
REAL(wp) af , bb0 , bbeg , bend , blv , bstep , df , e , ebeg , eda , &
ediff , eend , ei , estep , fl , flux , vbeg , vend , vstep , &
xl
REAL(wp) xmax , xmin , xx
INTEGER i , ib , ibl , ibltab , ie , iei , ihead , il , inde , itest , &
itt , iuaeap , iuout , j , jagnr , jpara , jtab , k , l ,&
map
INTEGER maxi , mini , monito , mtype , n , nb , ne , nl , nmap , nn
!*** End of declarations inserted by SPAG
! RADBELT.FOR SEPTEMBER 88
! RADBELT.FOR SEPTEMBER 88
!
!***********************************************************************
!* *
Expand All @@ -32,7 +33,7 @@ PROGRAM spag_program_1
!*** differential electron or proton fluxes for given energies, ***
!*** L-values, magnetic field strengths and map-type. ***
!*** The program will ask you for: ***
!*** NE number of energies you want displayed ***
!*** NE number of energies you want displayed ***
!*** E(1),... E(NE) energies or EBEGIN,EEND,ESTEP begin, ***
!*** end and stepsize of energy range ***
!*** NL number of L-values ***
Expand All @@ -41,7 +42,7 @@ PROGRAM spag_program_1
!*** B/B0(1),... B/B0(NL) B/B0-values or BBEGIN,BEND,BSTEP ***
!*** MTYPE map type: 1 AP8MAX 2 AP8MIN 3 AE4MAX 4 AE4MIN ***
!*** 5 AEI7HI 6 AEI7LO 7 AE8MAX 8 AE8MIN ***
!*** JTAB output options: integral or differential fluxes ***
!*** JTAB output options: integral or differential fluxes ***
!*** versus L or B/B0 ***
!*** The program interpolates the NSSDC model map in B/B0, L ***
!*** (function TRARA2), and energy (subroutine TRARA1). ***
Expand Down Expand Up @@ -78,12 +79,12 @@ PROGRAM spag_program_1
!*** (2) INCREMENTS PER DECADE OF LOGARITHMIC FLUX ***
!*** (3) EPOCH OF MODEL ***
!*** (4) SCALE FACTOR FOR ENERGY; E/MEV=E(MAP)/IHEAD(4) ***
!*** =6400 (AE-8), =100 (AP-8) ***
!*** =6400 (AE-8), =100 (AP-8) ***
!*** (5) SCALE FACTOR FOR L-VALUE =2100 (AE-8), =2048 (AP-8) ***
!*** (6) SCALE FACTOR FOR B/B0 =1024 (AE-8), =2048 (AP-8) ***
!*** (7) SCALE FACTOR FOR LOGARITHM OF FLUXES =1024 (AE,AP-8)***
!*** (8) NUMBER OF ELEMENTS IN MAP =13548 (AE8MAX), ***
!*** =13168 (AE8MIN), =6509 (AP8MAX), =6688 (AP8MIN) ***
!*** (8) NUMBER OF ELEMENTS IN MAP =13548 (AE8MAX), ***
!*** =13168 (AE8MIN), =6509 (AP8MAX), =6688 (AP8MIN) ***
!*** ***
!*** LAYOUT OF MAP: ***
!*** MAP CONSISTS OF SEVERAL VARIABLE-LENGTH SUB-MAPS, EACH ***
Expand Down Expand Up @@ -178,14 +179,14 @@ PROGRAM spag_program_1
ENDDO
ENDDO
!
! I/O UNIT NUMBERS
! I/O UNIT NUMBERS
!
egnr = 5 ! INPUT
monito = 6 ! MONITOR
iuaeap = 15 ! MODEL COEFFICIENTS INPUT
iuout = 16 ! OUTPUT (OUTPUT.AEP)
!
! INPUT OF PARAMETERS
! INPUT OF PARAMETERS
!
notbeg = .FALSE.
!-----------1. window: introduction--------------------------------
Expand Down Expand Up @@ -288,19 +289,19 @@ PROGRAM spag_program_1
! READ (iuaeap) ihead
! nmap = ihead(8)
! READ (iuaeap) (map(i),i=1,nmap)

! ASCIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
! When using the ASCII coefficient files instead of the binary
! coefficient files, one should replace the preceding 5 statements
! with the following 6 statements
!
99005 FORMAT(A6,'.ASC')
OPEN(IUAEAP,FILE=FNAME,STATUS='OLD',ERR=80,FORM='FORMATTED')
READ(IUAEAP,1301) IHEAD
NMAP=IHEAD(8)
READ(IUAEAP,1301) (MAP(I),I=1,NMAP)
1301 FORMAT(1X,12I6)
99005 FORMAT(A6,'.ASC')
OPEN(IUAEAP,FILE=FNAME,STATUS='OLD',ERR=80,FORM='FORMATTED')
READ(IUAEAP,1301) IHEAD
NMAP=IHEAD(8)
READ(IUAEAP,1301) (MAP(I),I=1,NMAP)
1301 FORMAT(1X,12I6)

CLOSE (iuaeap)
IF ( mtype<3 ) THEN
particle = 'PROTONS'
Expand Down Expand Up @@ -534,7 +535,7 @@ PROGRAM spag_program_1
!----------------THE B LOOP-------------------------------------
DO i = 1 , nb
bb0 = xl(2,i)
CALL trara1(ihead,map,fl,bb0,e,flux,ne)
CALL trm%trara1(ihead,map,fl,bb0,e,flux,ne)
!----------------THE ENERGY LOOP--------------------------------
DO k = 1 , ne
af(k,l,i) = 0.0
Expand All @@ -552,10 +553,10 @@ PROGRAM spag_program_1
itest = 0
ediff = ei - e(k)
!-----------------IS ENERGY INTERVALL LARGE ENOUGH ?-------------
! IF ((EI.GT.0.25).AND.(EDIFF.LT.0.1999)) ITEST=1
! IF ((EI.LE.0.10).AND.(EDIFF.LT.0.0499)) ITEST=1
! IF(((EI.LE.0.25).AND.(EDIFF.LT.0.0999)
! & .AND.(EI.GT.0.1))) ITEST=1
! IF ((EI.GT.0.25).AND.(EDIFF.LT.0.1999)) ITEST=1
! IF ((EI.LE.0.10).AND.(EDIFF.LT.0.0499)) ITEST=1
! IF(((EI.LE.0.25).AND.(EDIFF.LT.0.0999)
! & .AND.(EI.GT.0.1))) ITEST=1
iei = 1
IF ( ei>0.10 ) iei = 2
IF ( ei>0.25 ) iei = 3
Expand Down
File renamed without changes.
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: 10%
project:
default:
target: 10%
Loading

0 comments on commit 358db8e

Please sign in to comment.