Skip to content

Commit

Permalink
more test development
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardhartnett committed Nov 5, 2023
1 parent 188b21e commit 979c46d
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 15 deletions.
15 changes: 11 additions & 4 deletions model/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,21 @@ function(copy_test_data_2 srcname destname)
file(RENAME "${CMAKE_CURRENT_BINARY_DIR}/${srcname}" "${CMAKE_CURRENT_BINARY_DIR}/${destname}")
endfunction()

# Function to build and run a test.
function(unit_test name)
add_executable(${name} ${name}.F90)
target_link_libraries(${name} PRIVATE ww3_lib)
add_test(NAME ${name} COMMAND ${name})
endfunction()

# Copy test data files that are in the repo to the build directory.
copy_test_data(out_pnt.ww3)
copy_test_data_2(io_mod_def.ww3 mod_def.ww3)
copy_test_data(switch.io)
copy_test_data(ww3_outp.inp)

# Build and run the test.
add_executable(test_io test_io.F90)
target_link_libraries(test_io PRIVATE ww3_lib)
add_test(NAME test_io COMMAND test_io)
# Build and run the tests.
unit_test(test_io_points_bin)
unit_test(test_io)


33 changes: 22 additions & 11 deletions model/tests/test_io.F90
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,24 @@ program test_io
implicit none

integer, target :: i, j, k, l
integer :: ndsop, iotest, imod, ndstst, ierr, ndsbul, ndsi, ndsm
integer :: ndsop, iotest, imod, ndstst, ierr, ndsbul, ndsm
integer :: ndstrc, ntrace
real :: m2km
character*7 expected_ptnme
character*6 my_fmt
real :: expected_loc_1

print *, 'Testing WW3 IO...'
print *, 'Testing WW3 binary point file code.'

! These are mysterious but have to be called or else the IPASS
! variable does not exist and w3iopo() crashes.
call w3nmod(1, 6, 6)
call w3setg(1, 6, 6)
call w3ndat(6, 6)
call w3setw(1, 6, 6)
call w3nout(6, 6)
call w3seto(1, 6, 6)

ndsi = 10
ndsm = 20
ndsop = 20
ndsbul = 0
Expand All @@ -38,21 +39,22 @@ program test_io
900 FORMAT (/15X,' *** WAVEWATCH III Point output post.*** '/ &
15X,'==============================================='/)

open(ndsi, file = 'ww3_outp.inp', status='old', iostat = ierr)
if (ierr .ne. 0) stop 10
! Open the file with the output settings for WW3. It is not needed actually.
! open(ndsi, file = 'ww3_outp.inp', status='old', iostat = ierr)
! if (ierr .ne. 0) stop 10

! 2. Read model definition file.
CALL W3IOGR('READ', NDSM)
WRITE (NDSO,920) GNAME
920 FORMAT (' Grid name : ',A/)

IF (FLAGLL) THEN
M2KM = 1.
ELSE
M2KM = 1.E-3
END IF
! IF (FLAGLL) THEN
! M2KM = 1.
! ELSE
! M2KM = 1.E-3
! END IF

! Read the file out_pnt.ww3 from the model/tests/data directory.n
! Read the file out_pnt.ww3 from the model/tests/data directory.
call w3iopo('READ', ndsop, iotest)
if (iotest .ne. 0) stop 10
close(ndsop)
Expand All @@ -75,6 +77,15 @@ program test_io
expected_loc_1 = expected_loc_1 + 5000.0
if (ptloc(2, i) .ne. 0) stop 22
end do

print *, 'OK!'
print *, 'testing WW3 binary point file write...'

! This is not working yet.
call w3iopo('WRITE', ndsop, iotest)
print *, iotest
! if (iotest .ne. 0) stop 100
print *, 'OK!'
print *, 'SUCCESS!'
end program test_io

85 changes: 85 additions & 0 deletions model/tests/test_io_points_bin.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
! This is a test for model IO for WW3. This tests the legacy (binary)
! output of points data, done by function W3IOPO().
!
! Ed Hartnett 10/14/23
program test_io_points_bin
use w3iopomd
use w3gdatmd
use w3wdatmd
use w3odatmd
use w3iogrmd
use w3adatmd
implicit none

integer, target :: i, j, k, l
integer :: ndsop, iotest, imod, ndstst, ierr, ndsbul, ndsm
integer :: ndstrc, ntrace
real :: m2km
character*7 expected_ptnme
character*6 my_fmt
real :: expected_loc_1

print *, 'Testing WW3 binary point file code.'

! These are mysterious but have to be called or else the IPASS
! variable does not exist and w3iopo() crashes.
call w3nmod(1, 6, 6)
call w3setg(1, 6, 6)
call w3ndat(6, 6)
call w3setw(1, 6, 6)
call w3nout(6, 6)
call w3seto(1, 6, 6)

ndsm = 20
ndsop = 20
ndsbul = 0
ndstrc = 6
ntrace = 10

write (ndso,900)
900 FORMAT (/15X,' *** WAVEWATCH III Point output post.*** '/ &
15X,'==============================================='/)

! Open the file with the output settings for WW3. It is not needed actually.
! open(ndsi, file = 'ww3_outp.inp', status='old', iostat = ierr)
! if (ierr .ne. 0) stop 10

! 2. Read model definition file.
CALL W3IOGR('READ', NDSM)
WRITE (NDSO,920) GNAME
920 FORMAT (' Grid name : ',A/)

! IF (FLAGLL) THEN
! M2KM = 1.
! ELSE
! M2KM = 1.E-3
! END IF

! Read the file out_pnt.ww3 from the model/tests/data directory.
call w3iopo('READ', ndsop, iotest)
if (iotest .ne. 0) stop 10
close(ndsop)

! Make sure we got the values we expected.
if (nopts .ne. 11) stop 11
expected_loc_1 = 0.0
do i = 1, nopts
! Check ptnme and ptloc arrays.
print *, ptnme(i), ptloc(1, i), ptloc(2, i)
if (i .lt. 10) then
my_fmt = '(a,i1)'
else
my_fmt = '(a,i2)'
endif
write(fmt = my_fmt, unit=expected_ptnme) 'Point', i
if (ptnme(i) .ne. expected_ptnme) stop 20
print *, expected_loc_1
if (ptloc(1, i) .ne. expected_loc_1) stop 21
expected_loc_1 = expected_loc_1 + 5000.0
if (ptloc(2, i) .ne. 0) stop 22
end do

print *, 'OK!'
print *, 'SUCCESS!'
end program test_io_points_bin

0 comments on commit 979c46d

Please sign in to comment.