Skip to content

Commit

Permalink
Merge pull request #331 from NOAA-EMC/jba_inout
Browse files Browse the repository at this point in the history
convert remaining IN and OUT test codes to F90
  • Loading branch information
jbathegit authored Mar 3, 2023
2 parents 9040896 + bbd4b28 commit 061c75d
Show file tree
Hide file tree
Showing 38 changed files with 1,609 additions and 1,843 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Intel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
uses: actions/cache@v2
with:
path: ~/data
key: data-1
key: data-3

- name: build
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
uses: actions/cache@v2
with:
path: ~/data
key: data-1
key: data-3

- name: build
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/MacOS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
uses: actions/cache@v2
with:
path: ~/data
key: data-2
key: data-3

- name: build-bufr
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/developer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
uses: actions/cache@v2
with:
path: ~/data
key: data-1
key: data-3

- name: build
run: |
Expand Down
2 changes: 1 addition & 1 deletion src/makestab.f
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ SUBROUTINE MAKESTAB
C Reset any existing inventory pointers.

IF(IOMSG(LUN).NE.0) THEN
IF(LUS(LUN).EQ.0) THEN
IF(LUS(LUN).LE.0) THEN
INC = (NTAB+1)-MTAB(1,LUN)
ELSE
INC = MTAB(1,LUS(LUN))-MTAB(1,LUN)
Expand Down
114 changes: 19 additions & 95 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@
#
# Rahul Mahajan, Jeff Ator, Ed Hartnett

# This function builds, links, and runs a test program.
function(create_test name kind)
add_executable(${name}_${kind} ${name}.F90)
set_target_properties(${name}_${kind} PROPERTIES COMPILE_FLAGS "${fortran_${kind}_flags}")
target_compile_definitions(${name}_${kind} PUBLIC -DKIND_${kind})
target_link_libraries(${name}_${kind} PRIVATE bufr_4)
add_dependencies(${name}_${kind} bufr_4)
add_test(NAME ${name}_${kind} COMMAND ${name}_${kind})
endfunction()

# Fetch test data from: https://ftp.emc.ncep.noaa.gov/static_files/public/bufr.tar
set(BUFR_URL "https://ftp.emc.ncep.noaa.gov/static_files/public")
if(${PROJECT_VERSION} VERSION_GREATER_EQUAL 11.6.0)
Expand Down Expand Up @@ -65,25 +55,20 @@ add_custom_command(

file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/testrun)

list(APPEND test_IN_srcs
test_IN_5.F
test_IN_6.F
test_IN_7.F
test_IN_8.F90
)

list(APPEND test_OUT_2_srcs
test_OUT_2.F
)

list(APPEND test_OUT_other_srcs
test_OUT_1.F
test_OUT_3.F
test_OUT_4.F
test_OUT_5.F
test_OUT_6.F
test_OUT_7.F90
)
# This function builds, links, and runs an intest or outtest program.
function(create_test name kind num)
set(testID "${name}${num}_${kind}")
add_executable(${testID} ${name}${num}.F90)
set_target_properties(${testID} PROPERTIES COMPILE_FLAGS "${fortran_${kind}_flags}")
target_compile_definitions(${testID} PUBLIC -DKIND_${kind})
target_link_libraries(${testID} PRIVATE bufr_4)
add_dependencies(${testID} bufr_4)
if(${name} MATCHES "^intest")
add_test(NAME ${testID} COMMAND ${testID})
else()
add_test(NAME ${testID} COMMAND ${CMAKE_BINARY_DIR}/bin/test_outtest.sh ${testID} ${num})
endif()
endfunction()

list(APPEND test_c_interface_srcs
test_c_interface.c
Expand All @@ -92,8 +77,7 @@ list(APPEND test_c_interface_srcs

# Install testing scripts
list(APPEND test_scripts
test_wrapper_IN.sh
test_wrapper_OUT.sh
test_outtest.sh
test_gettab.sh
test_binv.sh
test_sinv.sh
Expand All @@ -111,73 +95,14 @@ foreach(test_script ${test_scripts})
${CMAKE_BINARY_DIR}/bin/${test_script} )
endforeach()

function(bufr_add_test TESTNAME EXENAME)
add_test(NAME ${TESTNAME}
COMMAND ${CMAKE_BINARY_DIR}/bin/test_wrapper_OUT.sh ${EXENAME})
endfunction()

function(bufr_add_test_preAPX TESTNAME EXENAME)
add_test(NAME ${TESTNAME}
COMMAND ${CMAKE_BINARY_DIR}/bin/test_wrapper_OUT.sh ${EXENAME} "Y")
endfunction()

list(APPEND test_kinds 4 8 d)

set(fortran_8_defs INTSIZE_8)

# Add tests which don't require output log processing.
foreach(kind ${test_kinds})
create_test(intest1 ${kind})
create_test(intest2 ${kind})
create_test(intest3 ${kind})
create_test(intest4 ${kind})
endforeach()

# IN tests
foreach(test_src ${test_IN_srcs})
string(REGEX REPLACE "(.F90|.F)" "" testPref ${test_src})
foreach(kind ${test_kinds})
set(test ${testPref}_${kind})
set(test_exe ${test}.x)
add_executable(${test_exe} ${test_src})
set_target_properties(${test_exe} PROPERTIES COMPILE_FLAGS
"${fortran_${kind}_flags}")
target_compile_definitions(${test_exe} PRIVATE "${fortran_${kind}_defs}")
add_dependencies(${test_exe} bufr_4)
target_link_libraries(${test_exe} PUBLIC bufr::bufr_4)
add_test(NAME ${test} COMMAND ${CMAKE_BINARY_DIR}/bin/test_wrapper_IN.sh ${test_exe})
foreach(innum RANGE 1 9)
create_test(intest ${kind} ${innum})
endforeach()
endforeach()

# OUT_2 tests; these use the bufr_add_test_preAPX function
foreach(test_src ${test_OUT_2_srcs})
string(REPLACE ".F" "" testPref ${test_src})
foreach(kind ${test_kinds})
set(test ${testPref}_${kind})
set(test_exe ${test}.x)
add_executable(${test_exe} ${test_src})
set_target_properties(${test_exe} PROPERTIES COMPILE_FLAGS
"${fortran_${kind}_flags}")
target_compile_definitions(${test_exe} PRIVATE "${fortran_${kind}_defs}")
add_dependencies(${test_exe} bufr_4)
target_link_libraries(${test_exe} PRIVATE bufr::bufr_4)
bufr_add_test_preAPX(${test} ${test_exe})
endforeach()
endforeach()

# all other OUT tests
foreach(test_src ${test_OUT_other_srcs})
string(REGEX REPLACE "(.F90|.F)" "" testPref ${test_src})
foreach(kind ${test_kinds})
set(test ${testPref}_${kind})
set(test_exe ${test}.x)
add_executable(${test_exe} ${test_src})
set_target_properties(${test_exe} PROPERTIES COMPILE_FLAGS
"${fortran_${kind}_flags}")
target_compile_definitions(${test_exe} PRIVATE "${fortran_${kind}_defs}")
add_dependencies(${test_exe} bufr_4)
target_link_libraries(${test_exe} PRIVATE bufr::bufr_4)
bufr_add_test(${test} ${test_exe})
foreach(outnum RANGE 1 9)
create_test(outtest ${kind} ${outnum})
endforeach()
endforeach()

Expand Down Expand Up @@ -246,4 +171,3 @@ foreach(xb_num RANGE 1 2)
"${CMAKE_BINARY_DIR}/utils/xbfmg ${xb_flags_${xb_num}}" "testfiles/data"
"testfiles/testoutput/xbfmg" "${xb_case}")
endforeach()

60 changes: 31 additions & 29 deletions test/intest1.F90
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
! Reads test file 'testfiles/IN_1' using CRBMG with
! OPENBF IO = 'SEC3'.
!
! Ed Hartnett, J. Ator, 2/3/23
! Ed Hartnett, J. Ator, 2/3/2023
program intest1
implicit none
integer mxbfd4, mxds3, nds3, ierme, imgdt
Expand All @@ -18,7 +18,7 @@ program intest1
real*8 r8arr(mxr8pm, mxr8lv)
integer ibfmg(mxbfd4)
character smidstg*9, softvstg*12, cmgtag*8, &
bfmg(mxbf), cds3(mxds3)*6, tagpr*8, celem(2)*60, cunit(2)*22
bfmg(mxbf), cds3(mxds3)*6, tagpr*8, celem*60, cunit*22
character*20 filnam / 'testfiles/IN_1' /
character filost / 'r' /
equivalence (bfmg(1), ibfmg(1))
Expand All @@ -32,10 +32,10 @@ program intest1
! Open the test file.
call cobfl(filnam, filost)

! Specify format of section 1 date/time when reading.
! Specify format of Section 1 date/time when reading.
call datelen(10)

! Specify the use of section 3 decoding.
! Specify the use of Section 3 decoding.
open (unit = 11, file = '/dev/null')
call openbf(11, 'SEC3', 11)

Expand All @@ -44,59 +44,61 @@ program intest1

! Read a BUFR message from the test file into a memory array.
call crbmg(bfmg, mxbf, nbyt, ierr)
if (ierr .ne. 0) stop 2
if (ierr .ne. 0) stop 1

! Read and check some values from Section 1.
if ((iupbs01(ibfmg, 'MTYP') .ne. 2) .or. &
(iupbs01(ibfmg, 'MTV') .ne. 14) .or. (iupbs01(ibfmg, 'LENM') .ne. 4169)) stop 3
if (iupbs01(ibfmg, 'MTYP') .ne. 2) stop 2
if (iupbs01(ibfmg, 'MTV') .ne. 14) stop 3
if (iupbs01(ibfmg, 'LENM') .ne. 4169) stop 4

! Read and check some values from Section 3.
if ((iupbs3(ibfmg, 'NSUB') .ne. 1) .or. &
(iupbs3(ibfmg, 'ICMP') .ne. 0)) stop 4
if (iupbs3(ibfmg, 'NSUB') .ne. 1) stop 5
if (iupbs3(ibfmg, 'ICMP') .ne. 0) stop 6

! Read and check some data descriptors from Section 3.
call upds3(ibfmg, mxds3, cds3, nds3)
IF (nds3 .ne. 8 .or. cds3(1) .ne. '309052' .or. cds3(5) .ne. '002095') stop 5
IF (nds3 .ne. 8 .or. cds3(1) .ne. '309052' .or. cds3(5) .ne. '002095') stop 7

! Pass the BUFR message from the memory array into the library.
call readerme(ibfmg, 11, cmgtag, imgdt, ierme)
if (ierme .ne. 0 .or. cmgtag .ne. 'MSTTB001') stop 6
if (ierme .ne. 0 .or. cmgtag .ne. 'MSTTB001') stop 8

! Get and check the element names and units associated with some
! Table B mnemonics.
call nemdefs(11, 'VSIGX', celem(1), cunit(1), ierndv)
call nemdefs(11, 'SMID', celem(2), cunit(2), iernds)
if (ierndv .ne. 0 .or. iernds .ne. 0 .or. celem(1)(1:40) .ne. &
'Extended vertical sounding significance ' .or. celem(2)(1:39) .ne. &
'Ship or mobile land station identifier ' .or. cunit(1)(1:12) .ne. &
'FLAG TABLE ' .or. cunit(2)(1:10) .ne. 'CCITT IA5 ') stop 7
call nemdefs(11, 'VSIGX', celem, cunit, ierndv)
if (ierndv .ne. 0 .or. celem(1:40) .ne. 'Extended vertical sounding significance ' .or. &
cunit(1:12) .ne. 'FLAG TABLE ') stop 9
call nemdefs(11, 'SMID', celem, cunit, iernds)
if (iernds .ne. 0 .or. celem(1:39) .ne. 'Ship or mobile land station identifier ' .or. &
cunit(1:10) .ne. 'CCITT IA5 ') stop 10

! Read and check the Section 1 date-time.
if (imgdt .ne. 2012093012) stop 8
if (imgdt .ne. 2012093012) stop 11

! Read a data subset from the BUFR message.
if (ireadsb(11) .ne. 0 ) stop 9
if (ireadsb(11) .ne. 0 ) stop 12

! Get and check the parent of a Table B mnemonic.
call gettagpr(11, 'PRLC', 192, tagpr, iertgp)
if (iertgp .ne. 0 .or. tagpr .ne. 'WSPLRAOB') stop 10
if (iertgp .ne. 0 .or. tagpr .ne. 'WSPLRAOB') stop 13

! Read and check some data values.
call ufbint(11, r8arr, MXR8PM, MXR8LV, nr8lv, 'CLONH A4ME HSMSL QCEVR')
IF (nr8lv .ne. 1 .or. NINT(r8arr(1,1)*100000) .ne. 10388797 .or. &
NINT(r8arr(2,1)) .ne. 7 .or. NINT(r8arr(3,1)) .ne. 14 .or. &
ibfms(r8arr(4,1)) .ne. 1) stop 11
call ufbint(11, r8arr, mxr8pm, mxr8lv, nr8lv, 'CLONH A4ME HSMSL QCEVR')
IF (nr8lv .ne. 1 .or. nint(r8arr(1,1)*100000) .ne. 10388797 .or. &
nint(r8arr(2,1)) .ne. 7 .or. nint(r8arr(3,1)) .ne. 14 .or. &
ibfms(r8arr(4,1)) .ne. 1) stop 14

! Read and check a sequence of data values.
call ufbseq(11, r8arr, MXR8PM, MXR8LV, nr8lv, 'TDWPRAOB')
IF (nr8lv .ne. 191 .or. NINT(r8arr(8,3)*100) .ne. 29416 .or. &
NINT(r8arr(10,11)*10) .ne. 55 .or. NINT(r8arr(2,12)) .ne. 2048 .or. &
NINT(r8arr(5,67)*100000) .ne. -1167 .or. NINT(r8arr(1,186)) .ne. 2523) stop 12
call ufbseq(11, r8arr, mxr8pm, mxr8lv, nr8lv, 'TDWPRAOB')
IF (nr8lv .ne. 191 .or. nint(r8arr(8,3)*100) .ne. 29416 .or. &
nint(r8arr(10,11)*10) .ne. 55 .or. nint(r8arr(2,12)) .ne. 2048 .or. &
nint(r8arr(5,67)*100000) .ne. -1167 .or. nint(r8arr(1,186)) .ne. 2523) stop 15

! Read and check some long character strings.
call readlc(11, smidstg, 'SMID')
IF (smidstg(7:9) .ne. 'UAO') stop 16
call readlc(11, softvstg, 'SOFTV')
IF (smidstg(7:9) .ne. 'UAO' .or. softvstg(5:12) .ne. '5.8.5.10') stop 13
IF (softvstg(5:12) .ne. '5.8.5.10') stop 17

! Close the test file.
call ccbfl()
Expand Down
2 changes: 1 addition & 1 deletion test/intest2.F90
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
! Reads test file 'testfiles/IN_2' with OPENBF IO = IN and LUNIN !=
! LUNDX.
!
! Ed Hartnett, J. Ator, 2/15/23
! Ed Hartnett, J. Ator, 2/15/2023
program intest2
implicit none
integer*4 ireadmg, iupvs01, nmsub, ibfms
Expand Down
25 changes: 13 additions & 12 deletions test/intest3.F90
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
! Reads test file 'testfiles/IN_3' using nested delayed
! replication, OPENBF IO = IN, and LUNIN = LUNDX.
!
! Ed Hartnett, J. Ator, 2/22/23
! Ed Hartnett, J. Ator, 2/22/2023
program intest3
implicit none

Expand All @@ -14,13 +14,12 @@ program intest3
parameter (mxr8lv = 50)

integer isct, imgdt, ityr, itmo, itdy, ithr, itmi, ier, &
nr8lv, nr8rr, nr8rf, nr8rhr, nr8rh, nr8rdr, nr8rd, &
ierndh, iernds, ierndd
nr8lv, nr8rr, nr8rf, nr8rhr, nr8rh, nr8rdr, nr8rd

real*8 r8arr(mxr8pm, mxr8lv), r8arf(mxr8pm, mxr8lv), r8arhr(1, mxr8lv), &
r8arh(mxr8pm, mxr8lv), r8ardr(1, mxr8lv), r8ard (mxr8pm, mxr8lv)

character cmgtag*8, celem(3)*40, cunit(3)*20
character cmgtag*8, celem*40, cunit*20

print *, 'Testing reading IN_3, using nested delayed replication, OPENBF IO = IN, and LUNIN = LUNDX'

Expand Down Expand Up @@ -131,16 +130,18 @@ program intest3
enddo

! Verify that all available subsets were successfully read.
if ( isct .ne. 10 ) stop 102
if ( isct .ne. 10 ) stop 112

! Check some mnemonic definitions.
call nemdefs ( 11, 'HSMSL', celem(1), cunit(1), ierndh )
call nemdefs ( 11, 'SHRV', celem(2), cunit(2), iernds )
call nemdefs ( 11, 'DCHG', celem(3), cunit(3), ierndd )
if ( ( ierndh .ne. 0 ) .or. ( iernds .ne. 0 ) .or. ( ierndd .ne. 0 ) .or. ( celem(1)(1:36) .ne. &
'HEIGHT OF STATION GROUND ABOVE MSL ' ) .or. ( cunit(1)(1:9) .ne. 'METERS ' ) .or. &
( celem(2)(1:24) .ne. 'SHEF DATA REVISION FLAG ' ) .or. ( cunit(2)(1:12) .ne. 'CODE TABLE ' ) .or. &
( celem(3)(1:15) .ne. 'DISCHARGE ' ) .or. ( cunit(3)(1:20) .ne. 'METERS**3/SECOND ' ) ) stop 103
call nemdefs ( 11, 'HSMSL', celem, cunit, ier )
if ( ( ier .ne. 0 ) .or. ( celem(1:36) .ne. 'HEIGHT OF STATION GROUND ABOVE MSL ' ) .or. &
( cunit(1:9) .ne. 'METERS ' ) ) stop 113
call nemdefs ( 11, 'SHRV', celem, cunit, ier )
if ( ( ier .ne. 0 ) .or. ( celem(1:24) .ne. 'SHEF DATA REVISION FLAG ' ) .or. &
( cunit(1:12) .ne. 'CODE TABLE ' ) ) stop 114
call nemdefs ( 11, 'DCHG', celem, cunit, ier )
if ( ( ier .ne. 0 ) .or. ( celem(1:15) .ne. 'DISCHARGE ' ) .or. &
( cunit(1:20) .ne. 'METERS**3/SECOND ' ) ) stop 115

print *, 'SUCCESS!'
end program intest3
Loading

0 comments on commit 061c75d

Please sign in to comment.