Skip to content

Commit

Permalink
Merge pull request #127 from AlexanderRichert-NOAA/add_testing_Oct2023
Browse files Browse the repository at this point in the history
Extend testing (splat, sptrung, sptrungv, sppad, splaplac)
  • Loading branch information
AlexanderRichert-NOAA authored Oct 30, 2023
2 parents 2d9519a + c4b8e4d commit 8c8be66
Show file tree
Hide file tree
Showing 15 changed files with 245 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
cd sp
mkdir build
cd build
cmake -DOPENMP=${{ matrix.openmp }} -DBUILD_SHARED_LIBS=${{ matrix.sharedlibs }} ${{ matrix.options }} -DCMAKE_INSTALL_PREFIX="~/install" ..
cmake -DOPENMP=${{ matrix.openmp }} -DBUILD_SHARED_LIBS=${{ matrix.sharedlibs }} ${{ matrix.options }} -DTEST_TIME_LIMIT=ON -DCMAKE_INSTALL_PREFIX="~/install" ..
make -j2 VERBOSE=1
make install
ls -l ~/install
Expand Down
22 changes: 11 additions & 11 deletions .github/workflows/Spack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ jobs:
matrix:
os: ["ubuntu-latest"]
openmp: ["+openmp", "~openmp"]
sharedlibs: ["+shared", "~shared"]
pic: ["+pic", "~pic"]
precision: ["d", "4", "8"]
variants: ["+shared +pic precision=4", "~shared ~pic precision=d", "~shared +pic precision=8"]
runs-on: ${{ matrix.os }}

steps:
Expand All @@ -43,29 +41,31 @@ jobs:
spack env activate sp-env
cp $GITHUB_WORKSPACE/sp/spack/package.py $SPACK_ROOT/var/spack/repos/builtin/packages/sp/package.py
spack develop --no-clone --path $GITHUB_WORKSPACE/sp sp@develop
spack add sp@develop%gcc@11 ${{ matrix.openmp }} ${{ matrix.sharedlibs }} ${{ matrix.pic }} precision=${{ matrix.precision }},4
spack add ip@develop ${{ matrix.sharedlibs }} precision=${{ matrix.precision }} target=x86_64
if [ ${{ matrix.precision }} == "d" ]; then spack add grib-util@develop ; fi
spack add sp@develop%gcc@11 ${{ matrix.openmp }} ${{ matrix.variants }}
spack add ip@develop ${{ matrix.variants }} target=x86_64
precision=$(echo ${{ matrix.variants }} | grep -oP " precision=\K[4d8]")
if [ "$precision" == "d" ]; then spack add grib-util@develop ; fi
spack external find cmake gmake
spack concretize
# Run installation and run CTest suite
spack install --verbose --fail-fast --test root
# Print test results
cat $(spack location -i sp)/.spack/install-time-test-log.txt
cat $(spack location -i ip)/.spack/install-time-test-log.txt
if [ ${{ matrix.precision }} == "d" ]; then
if [ "$precision" == "d" ]; then
cat $(spack location -i grib-util)/.spack/install-time-test-log.txt
fi
# Run 'spack load' and check that key build options were respected
spack load sp
if [ ${{ matrix.sharedlibs }} == "+shared" ]; then suffix="so" ; else suffix="a"; fi
ls ${SP_LIB${{ matrix.precision }}} | grep -cE '/libsp_${{ matrix.precision }}\.'$suffix'$'
if [[ "${{ matrix.variants }}" =~ "+shared" ]]; then suffix="so" ; else suffix="a"; fi
libvar=SP_LIB${precision}
ls ${!libvar} | grep -cE "/libsp_${precision}\."$suffix'$'
- name: Upload test results
uses: actions/upload-artifact@v3
if: ${{ failure() }}
with:
name: spackci-ctest-output-${{ matrix.os }}-${{ matrix.openmp }}-${{ matrix.sharedlibs }}-${{ matrix.pic }}-${{ matrix.precision }}
name: spackci-ctest-output-${{ matrix.os }}-${{ matrix.openmp }}-${{ matrix.variants }}
path: ${{ github.workspace }}/*/spack-build-*/Testing/Temporary/LastTest.log

# This job validates the Spack recipe by making sure each cmake build option is represented
Expand All @@ -82,7 +82,7 @@ jobs:
- name: recipe-check
run: |
echo "If this jobs fails, look at the most recently output CMake option below and make sure that option appears in spack/package.py"
for opt in $(grep -ioP '^option\(\K(?!(ENABLE_DOCS))[^ ]+' $GITHUB_WORKSPACE/sp/CMakeLists.txt) ; do
for opt in $(grep -ioP '^option\(\K(?!(ENABLE_DOCS|TEST_TIME_LIMIT))[^ ]+' $GITHUB_WORKSPACE/sp/CMakeLists.txt) ; do
echo "Checking for presence of '$opt' CMake option in package.py"
grep -cP "define.+\b${opt}\b" $GITHUB_WORKSPACE/sp/spack/package.py
done
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ option(BUILD_4 "Build the 4-byte real version of the library, libsp_4.a" ON)
option(BUILD_D "Build the 8-byte real version of the library, libsp_d.a" ON)
option(BUILD_8 "Build the 8-byte integer version of the library, libsp_8.a" OFF)
option(BUILD_DEPRECATED "Build deprecated functions" OFF)
option(TEST_TIME_LIMIT "Set timeout for tests" OFF)

# Figure whether user wants a _4, a _d, or both libraries.
if(BUILD_4)
Expand Down
5 changes: 5 additions & 0 deletions docs/user_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ should always be zero, as should the global mean of any divergence and
vorticity fields. The stride between the start of successive wave
fields is general, defaulting to the computed length of each field.

It should be noted that some routines may behave poorly or unpredictably when
using 4-byte reals (libsp_4). In some routines, small numerical differences can
be amplified into noticeable differences in output field values. Some
applications may therefore benefit from the use of 8-byte reals (libsp_d).

This documentation is divided into 3 chapters. Chapter I is this
introduction. Chapter II is a list of all entry points. Chapter III
is a set of examples.
Expand Down
26 changes: 19 additions & 7 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# This is the CMake build file for the test directory of NCEPLIBS-sp.

# Kyle Gerheiser, Ed Hartnett
# Kyle Gerheiser, Ed Hartnett, Alex Richert

execute_process(COMMAND cmake -E create_symlink
"${CMAKE_CURRENT_SOURCE_DIR}/data"
"${CMAKE_CURRENT_BINARY_DIR}/data"
)

# This function builds, links, and runs a test program.
function(create_test name kind)
function(create_test name kind timeout)
add_executable(${name}_${kind} ${name}.F90)

# Include openMP if desired.
Expand All @@ -13,15 +18,22 @@ function(create_test name kind)
target_link_libraries(${name}_${kind} PRIVATE sp::sp_${kind})
set_target_properties(${name}_${kind} PROPERTIES COMPILE_FLAGS "${fortran_${kind}_flags}")
add_test(NAME ${name}_${kind} COMMAND ${name}_${kind})
target_compile_definitions(${name}_${kind} PUBLIC -DKIND_${kind})
target_compile_definitions(${name}_${kind} PUBLIC -DKIND_${kind})
if(TEST_TIME_LIMIT)
set_tests_properties(${name}_${kind} PROPERTIES TIMEOUT ${timeout})
endif()
endfunction()

# At the moment, only _d is tested.
# Build a _4 and _d version of each test and link them to the _4 and
# _d builds of the library, for 4-byte real, and 8-byte real.
foreach(kind ${kinds})
create_test(test_ncpus ${kind})
create_test(test_splat ${kind})
create_test(test_sptezv ${kind})
create_test(test_fft ${kind})
create_test(test_ncpus ${kind} 0.3)
create_test(test_splaplac ${kind} 0.3)
create_test(test_splat ${kind} 0.3)
create_test(test_sppad ${kind} 0.3)
create_test(test_sptezv ${kind} 0.3)
create_test(test_fft ${kind} 0.3)
create_test(test_sptrung ${kind} 0.3)
create_test(test_sptrungv ${kind} 2)
endforeach()
3 changes: 3 additions & 0 deletions tests/data/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sptrungv* files were generated from ip's './test_vector_grib1_4 "205" "4"' test case and modifying spectral_interp_mod.F90 to write out UI, VI, RLAT, and RLON immediately before the SPTRUNGV call, and UO and VO immediately after.

sptrung* files were generated from ip's 'test_scalar_grib2_4 "-1" "4"' test case and modifying spectral_interp_mod.F90 to write out GI.
Binary file added tests/data/sptrung.gi.in
Binary file not shown.
Binary file added tests/data/sptrungv.ll.in
Binary file not shown.
Binary file added tests/data/sptrungv.uv.in
Binary file not shown.
Binary file added tests/data/sptrungv.uv.out
Binary file not shown.
47 changes: 47 additions & 0 deletions tests/test_splaplac.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
! This is a test from the NCEPLIBS-sp project.
!
! This test tests the splaplac() subrroutine.
!
! Alex Richert, Oct 2023
PROGRAM TEST_SPLAPLAC
IMPLICIT NONE

INTEGER I, M, J, QSIZE, QD2SIZE
REAL, ALLOCATABLE :: ENN1(:), Q(:), QD2(:), QREF(:), REF(:), QD2REF(:)
REAL :: TOL=1E-7

M=2

DO I=0,1
QSIZE=(M+1)*((I+1)*M+2)
QD2SIZE=(M+1)*((I+1)*M+2)
ALLOCATE(QD2REF(QD2SIZE))
IF (I.EQ.0) THEN
QD2REF=(/0.0,0.0,-0.25,-0.333,-0.417,-0.5,-0.583,-0.667, &
-0.75,-0.833,-0.917,-1.0/)
ELSEIF (I.EQ.1) THEN
QD2REF=(/0.0,0.0,-0.167,-0.222,-0.278,-0.333,-0.389,-0.444, &
-0.5,-0.556,-0.611,-0.667,-0.722,-0.778,-0.833,-0.889,-0.944,-1.0/)
ENDIF
ALLOCATE(ENN1((M+1)*((I+1)*M+2)/2))
ENN1=1.0
ALLOCATE(Q(QSIZE))
ALLOCATE(QREF(QSIZE))
ALLOCATE(QD2(QD2SIZE))
DO J=1,QSIZE
Q(J) = REAL(J)/REAL(QSIZE)
ENDDO
QREF=Q
CALL SPLAPLAC(I,M,ENN1,Q,QD2,1)
IF (.NOT.ALL(ABS(QD2-QD2REF).LT.1E-2)) STOP 1
Q=-999.9
CALL SPLAPLAC(I,M,ENN1,Q,QD2,-1)
IF (.NOT.ALL(ABS(Q(3:)-QREF(3:)).LT.TOL)) STOP 2
DEALLOCATE(QD2REF)
DEALLOCATE(ENN1)
DEALLOCATE(Q)
DEALLOCATE(QREF)
DEALLOCATE(QD2)
ENDDO !DO I

END PROGRAM TEST_SPLAPLAC
15 changes: 11 additions & 4 deletions tests/test_splat.F90
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ program test_splat
use iso_fortran_env, only: real64
implicit none

integer :: j, jmax
real :: slat(584), wlat(584)
integer :: j, jj, jmax, ref_j(5)
real :: slat(584), wlat(584), ref_slat(5), ref_wlat(5)
real :: tini=1e-5

jmax = 584 ! t382 grid

Expand Down Expand Up @@ -36,8 +37,14 @@ program test_splat
endif
end do

do j = 1, jmax
print*,'J/SLAT/WLAT ',j, slat(j), wlat(j)
call splat(256, jmax, slat, wlat)
ref_j = (/1, 20, 100, 292, 584/)
ref_slat = (/0.999996364, 0.994503140, 0.860138953, 2.68967217E-03, -0.999996364/)
ref_wlat = (/1.25922097E-05, 5.63323090E-04, 2.74388562E-03, 5.37929870E-03, 1.25922097E-05/)

do jj = 1, 5
if (abs(ref_slat(jj)-slat(ref_j(jj))) .gt. tini) error stop "slat mismatch for IDRT=256"
if (abs(ref_wlat(jj)-wlat(ref_j(jj))) .gt. tini) error stop "wlat mismatch for IDRT=256"
enddo

end program test_splat
47 changes: 47 additions & 0 deletions tests/test_sppad.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
! This is a test from the NCEPLIBS-sp project.
!
! This test tests the sppad() subrroutine.
!
! Alex Richert, Oct 2023
PROGRAM TEST_SPPAD
IMPLICIT NONE

INTEGER WHICH, I, IMAX1, IMAX2
INTEGER, DIMENSION(6) :: I1=(/0,1,0,0,1,1/), I2=(/0,1,0,1,0,1/)
INTEGER, DIMENSION(6) :: M1=(/384,384,1,1,1,1/), M2=(/384,384,2,2,2,2/)
REAL, ALLOCATABLE :: Q1(:), Q2(:)
REAL :: TINI=TINY(1.0)
REAL, DIMENSION(18) :: W4REF, W6REF

W4REF=(/1.0/6.0,1.0/3.0,0.5,2.0/3.0,0.0,0.0, &
5.0/6.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0/)
W6REF=(/0.1250,0.25,0.375,0.5,0.0,0.0,0.625,0.75,0.875,1.0, &
0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0/)

DO WHICH=1,6
IMAX1=(M1(WHICH)+1)*((I1(WHICH)+1)*M1(WHICH)+2)
IMAX2=(M2(WHICH)+1)*((I2(WHICH)+1)*M2(WHICH)+2)
IF ((WHICH.LE.2) .AND. (IMAX1.NE.IMAX2)) STOP 1
ALLOCATE(Q1(1:IMAX1))
ALLOCATE(Q2(1:IMAX2))
! Make all test values positive to distinguish from padding zeros
DO I=1,IMAX1
Q1(I)=REAL(I)/REAL(IMAX1)
ENDDO
CALL SPPAD(I1(WHICH),M1(WHICH),Q1,I2(WHICH),M2(WHICH),Q2)
! When I1==I2, the arrays should be unchanged
IF ((WHICH.EQ.1).AND.(.NOT.ALL(ABS(Q1-Q2).LT.TINI))) STOP 2
IF ((WHICH.EQ.2).AND.(.NOT.ALL(ABS(Q1-Q2).LT.TINI))) STOP 3
! Non-pad values (i.e., non-zeros) should be unchanged
IF (.NOT. ALL(ABS(Q1-PACK(Q2,Q2>TINI)).LT.TINI)) STOP 4
IF (WHICH.EQ.4) THEN
IF (.NOT.ALL(ABS(Q2-W4REF).LT.TINI)) STOP 5
ENDIF
IF (WHICH.EQ.6) THEN
IF (.NOT.ALL(ABS(Q2-W6REF).LT.TINI)) STOP 6
ENDIF
DEALLOCATE(Q1)
DEALLOCATE(Q2)
ENDDO ! WHICH=1,6

END PROGRAM TEST_SPPAD
42 changes: 42 additions & 0 deletions tests/test_sptrung.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
! This is a test from the NCEPLIBS-sp project.
!
! This test tests the sptrung() subrroutine.
!
! Alex Richert, Oct 2023
program test_sptrung
implicit none

INTEGER :: I
INTEGER :: IROMB=0, MAXWV=89
INTEGER :: IDRTI=256, IMAXI=360, JMAXI=180
INTEGER,parameter :: KM=1
INTEGER :: NO=4, IPRIME=181, ISKIPI=1, JSKIPI=360
INTEGER,parameter :: MI=64800, MO=4
REAL :: RLAT(MO),RLON(MO)
REAL :: GI(MI,KM)
REAL :: GO(MO,KM)
REAL :: GOREF(MO,KM)
REAL*4 :: RDGI(MI,KM)
REAL :: X=0.0
REAL :: TINI=4e-3


OPEN (12, file="data/sptrung.gi.in", form='unformatted', recl=MI*KM*4, convert='little_endian')
READ (12) RDGI
CLOSE (12)

GI = REAL(RDGI)

GOREF(:,1) = (/77.3174667,70.4562683,72.8935242,51.0591698/)
RLAT = (/45.0,35.0,40.0,35.0/)
RLON = (/-100.0,-100.0,-90.0,-120.0/)

CALL SPTRUNG(IROMB,MAXWV,IDRTI,IMAXI,JMAXI,KM,NO, &
IPRIME,ISKIPI,JSKIPI,MI,MO,0,0,0,RLAT,RLON, &
GI,GO)

DO I=1,MO
IF (ABS(GO(I,KM)-GOREF(I,KM)) .GT. TINI) STOP 1
ENDDO

end program test_sptrung
58 changes: 58 additions & 0 deletions tests/test_sptrungv.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
! This is a test from the NCEPLIBS-sp project.
!
! This test tests the sptrungv() subrroutine.
!
! Alex Richert, Oct 2023
program test_sptrungv
implicit none

!
!
INTEGER :: I
INTEGER :: IROMB=0, MAXWV=89
INTEGER :: IDRTI=0, IMAXI=360, JMAXI=181
INTEGER,parameter :: KM=1
INTEGER :: NO=26553, IPRIME=1, ISKIPI=1, JSKIPI=-360
INTEGER,parameter :: MI=65160, MO=26553
REAL :: RLAT(MO),RLON(MO)
REAL :: UI(MI,KM),VI(MI,KM)
REAL :: UO(MO,KM),VO(MO,KM)
REAL :: UOREF(MO,KM),VOREF(MO,KM)
REAL*4 :: RDRLAT(MO),RDRLON(MO)
REAL*4 :: RDUI(MI,KM),RDVI(MI,KM)
REAL*4 :: RDUOREF(MO,KM),RDVOREF(MO,KM)
REAL :: X=0.0
REAL :: TOL=1e-2

OPEN (12, file="data/sptrungv.uv.in", access='direct', recl=MI*KM*4, convert='little_endian')
READ (12, rec=1) RDUI
READ (12, rec=2) RDVI
CLOSE (12)

OPEN (13, file="data/sptrungv.ll.in", access="direct", recl=MO*4, convert='little_endian')
READ (13, rec=1) RDRLAT
READ (13, rec=2) RDRLON
CLOSE (13)

OPEN (14, file="data/sptrungv.uv.out", access="direct", recl=MO*KM*4, convert='little_endian')
READ (14, rec=1) RDUOREF
READ (14, rec=2) RDVOREF
CLOSE (14)

UI = REAL(RDUI)
VI = REAL(RDVI)
RLAT = REAL(RDRLAT)
RLON = REAL(RDRLON)
UOREF = REAL(RDUOREF)
VOREF = REAL(RDVOREF)

CALL SPTRUNGV(IROMB,MAXWV,IDRTI,IMAXI,JMAXI,KM,NO, &
IPRIME,ISKIPI,JSKIPI,MI,MO,0,0,0,RLAT,RLON, &
UI,VI,.TRUE.,UO,VO,.FALSE.,X,X,.FALSE.,X,X)

DO I=1, MO
IF (ABS(UO(I,KM)-RDUOREF(I,KM)) .GT. TOL) STOP 1
IF (ABS(VO(I,KM)-RDVOREF(I,KM)) .GT. TOL) STOP 2
ENDDO

end program test_sptrungv

0 comments on commit 8c8be66

Please sign in to comment.