Skip to content

Commit

Permalink
improved test of mkfldsep() (#228)
Browse files Browse the repository at this point in the history
* improved test of mkfldsep()

* improved docs

* improved docs

* improved docs

---------

Co-authored-by: Alex Richert <[email protected]>
  • Loading branch information
edwardhartnett and AlexanderRichert-NOAA authored Jun 7, 2024
1 parent a432bfb commit 52e7701
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 58 deletions.
13 changes: 8 additions & 5 deletions src/mkfldsep.f
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
C> @brief Makes TOC Flag Field Separator Block
C> @author Stephen Gilbert @date 2002-09-16

C> Generates a TOC Flag Field Separator Block used to separate
C> WMO Bulletins within a transmission file to be ingested in TOC's
C> FTP Input Service, which can be used to disseminate WMO buletins.
C> (see http://weather.gov/tg/ftpingest.html)
C> Generates a TOC Flag Field Separator Block used to separate WMO
C> Bulletins within a transmission file to be ingested in TOC's FTP Input
C> Service, which can be used to disseminate WMO buletins. See [File
C> Transfer Input Service Guide - Input examples and how to FTP files to
C> the Gateway] (https://www.weather.gov/tg/ftpingest).
C>
C> This routine can generate different flag field separator blocks
C> depending on the value of variable iopt.
C> depending on the value of variable iopt. For details see [GATEWAY File
C> Standards & Content Structures] (https://www.weather.gov/tg/fstandrd).
C>
C> Bulletin "Flag Field Separator" block - OPTION 1 (old)
C> - bytes:
Expand Down Expand Up @@ -73,6 +75,7 @@ subroutine mkfldsep(csep,iopt,lenin,lenbull,lenout)
csep(1:4)=clb
write(csep(5:7),fmt='(I3.3)') nnn
write(csep(8:18),fmt='(I11.11)') lenbull
! In docs, these bytes are "reserved for future use".
csep(19:nnn-5)='0'
csep(nnn-4:nnn-1)=clb
csep(nnn:nnn)=char(10)
Expand Down
95 changes: 42 additions & 53 deletions tests/test_mkfldsep.F90
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ program test_mkflsep

character * 1 csep(80), lenbull_cin(4)
integer :: iopt, lenin, lenbull, lenbull_in
integer :: lenout, itot, i
integer :: lenin_values(3) = (/ 21, 23, 25 /)
integer :: lenout, itot, i, j, nnn
integer, parameter :: lenhead = 21
character(len=4),parameter :: cstar='****', clb='####'

Expand All @@ -25,60 +26,48 @@ program test_mkflsep
end do
print *, 'OK!'

print *, 'testing with iopt 1, lenin = 18...'
iopt = 1
lenin = 18
itot = 5000
lenbull = itot + lenhead
call mkfldsep(csep, iopt, lenin, lenbull, lenout)
if (lenout .ne. 18) stop 199
! do i = 1, lenin
! print *, i, ichar(csep(i))
! end do
! Test iopt 1 with 3 different values for lenin.
do j = 1, 3
iopt = 1
lenin = lenin_values(j)
nnn = lenin
print *, 'testing with iopt 1, lenin = ', lenin
if (nnn .lt. 23) nnn = 23
itot = 5000
lenbull = itot + lenhead
call mkfldsep(csep, iopt, lenin, lenbull, lenout)
if (lenout .ne. nnn) stop 299
! do i = 1, lenout
! print '(i3, a1, z2.2, a1, i2, a1, a)', i, ' ', csep(i), ' ', ichar(csep(i)), ' ', csep(i)
! end do

! Check every byte of result.
do i = 1, 4
if (csep(i) .ne. '#') stop 200
end do
if (csep(5) .ne. '0' .or. csep(6) .ne. '1' .or. csep(7) .ne. '8') stop 201
! This is the length of message plus header as an i6.6.
if (csep(8) .ne. '0' .or. csep(9) .ne. '0' .or. csep(10) .ne. '5') stop 202
if (csep(11) .ne. '0' .or. csep(12) .ne. '2' .or. csep(13) .ne. '1') stop 203
do i = 14, 17
if (csep(i) .ne. '#') stop 205
! Check every byte of result.
do i = 1, 4
if (csep(i) .ne. '#') stop 100
end do
if (csep(5) .ne. '0' .or. csep(6) .ne. '2') stop 101
if (j .le. 2) then
if (csep(7) .ne. '3') stop 102
else
if (csep(7) .ne. '5') stop 102
endif
! This is the length of message plus header as an i6.6.
if (csep(8) .ne. '0' .or. csep(9) .ne. '0' .or. csep(10) .ne. '0') stop 105
if (csep(11) .ne. '0' .or. csep(12) .ne. '0' .or. csep(13) .ne. '0') stop 113
if (csep(14) .ne. '0' .or. csep(15) .ne. '5' .or. csep(16) .ne. '0') stop 114
if (csep(17) .ne. '2' .or. csep(18) .ne. '1') stop 115
! I think this was intended by the original programmer to be a
! range of 19:nnn-5. But in the standard these bytes are
! "reserved for future use" so it does not matter. So only
if (nnn > 23) then
if (csep(19) .ne. '0') stop 130
endif
do i = nnn - 4, nnn - 1
if (csep(i) .ne. '#') stop 135
end do
if (csep(nnn) .ne. char(10)) stop 140
print *, 'OK!'
end do
if (csep(18) .ne. char(10)) stop 207
print *, 'OK!'

print *, 'testing with iopt 1, lenin = 23...'
iopt = 1
lenin = 23
itot = 5000
lenbull = itot + lenhead
call mkfldsep(csep, iopt, lenin, lenbull, lenout)
if (lenout .ne. 23) stop 299
! do i = 1, lenin
! print *, i, ichar(csep(i))
! end do

! Check every byte of result.
do i = 1, 4
if (csep(i) .ne. '#') stop 100
end do
if (csep(5) .ne. '0' .or. csep(6) .ne. '2' .or. csep(7) .ne. '3') stop 101
! This is the length of message plus header as an i6.6.
if (csep(8) .ne. '0' .or. csep(9) .ne. '0' .or. csep(10) .ne. '0') stop 102
if (csep(11) .ne. '0' .or. csep(12) .ne. '0' .or. csep(13) .ne. '0') stop 103
if (csep(14) .ne. '0' .or. csep(15) .ne. '5' .or. csep(16) .ne. '0') stop 104
if (csep(17) .ne. '2' .or. csep(18) .ne. '1') stop 105
do i = 19, lenin - 5 ! not used in this case
if (csep(i) .ne. '0') stop 110
end do
do i = lenin - 4, lenin - 1
if (csep(i) .ne. '#') stop 115
end do
if (csep(lenin) .ne. char(10)) stop 120
print *, 'OK!'

print *, 'testing with iopt 2...'
iopt = 2
Expand Down

0 comments on commit 52e7701

Please sign in to comment.