Skip to content

Commit

Permalink
Merge pull request #127 from NOAA-EMC/ejh_f90_2
Browse files Browse the repository at this point in the history
converted tocgrib to F90
  • Loading branch information
edwardhartnett committed Jan 26, 2022
2 parents 79dfcc7 + 98e2455 commit cb892ed
Show file tree
Hide file tree
Showing 6 changed files with 370 additions and 403 deletions.
6 changes: 5 additions & 1 deletion src/tocgrib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#
# Mark Potts, Kyle Gerheiser

# Set compiler flags.
if(CMAKE_Fortran_COMPILER_ID MATCHES "^(Intel)$")
set(CMAKE_Fortran_FLAGS "-g -assume noold_ldout_format -axCORE-AVX2 ${CMAKE_Fortran_FLAGS}")
set(CMAKE_Fortran_FLAGS_RELEASE "-O2 ${CMAKE_Fortran_FLAGS}")
Expand All @@ -11,12 +12,15 @@ elseif(CMAKE_Fortran_COMPILER_ID MATCHES "^(GNU)$")
set(CMAKE_Fortran_FLAGS_RELEASE "-O2 ${CMAKE_Fortran_FLAGS}")
endif()

set(fortran_src makwmo.f mkfldsep.f tocgrib.f)
# This is the Fortran source code.
set(fortran_src makwmo.F90 mkfldsep.F90 tocgrib.F90)

# Build the executable.
set(exe_name tocgrib)
add_executable(${exe_name} ${fortran_src})
target_link_libraries(${exe_name} PRIVATE w3emc::w3emc_4 bacio::${bacio_name})

# Install the utility.
install(TARGETS ${exe_name} RUNTIME DESTINATION bin)

# If doxygen documentation is enabled, build it.
Expand Down
74 changes: 74 additions & 0 deletions src/tocgrib/makwmo.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
!> @file
!> @brief Format the wmo header.
!> @author Farley @date 84-07-06

!> Forms the wmo header for a given bulletin.
!>
!> ### Program History Log
!> Date | Programmer | Comments
!> -----|------------|---------
!> 84-07-06 | Farley | Original author
!> 94-10-10 | R. E. Jones | changes for cray
!> 95-10-18 | R. E. Jones | add parameter kwbx to call
!> 98-06-16 | Gilbert | Changed argument list to pass in day and hour instead of the old O.N. 84 date word.
!> 2003-03-28 | Gilbert | Removed equivalences.
!>
!> @param[in] bulhed ttaaii bulletin header ft10
!> @param[in] iday day of month
!> @param[in] ihour hour of day.
!> @param[in] kwbx 4 characters (kwbc to kwbq)
!> @param[out] header complete wmo header in ascii
!>
!> @author Farley @date 84-07-06
SUBROUTINE MAKWMO (BULHED,IDAY,IHOUR,KWBX,HEADER)
!
CHARACTER * 6 BULHED
CHARACTER * 1 HEADER (*)
CHARACTER * 1 WMOHDR (21)
CHARACTER * 4 KWBX
CHARACTER * 2 CTEMP
!$ 1. CREATE WMO HEADER.
!$ 1.1 CONVERT BULHED FROM EBCDIC TO ASCII.
! WRITE (6,FMT='('' MADE IT TO MAKWMO'')')
!
DO I = 1,6
WMOHDR(I) = BULHED(I:I)
END DO
WMOHDR(7)=char(32) ! ASCII BLANK
!
! MOVE KWBX INTO WMO HEADER
!
DO I = 1,4
WMOHDR(I+7) = KWBX(I:I)
END DO
WMOHDR(12)=char(32) ! ASCII BLANK
!
!$ 1.2 PICK OFF THE DAY OF MONTH (YY)
!$ AND CONVERT TO ASCII.
!
write(ctemp,fmt='(I2.2)') IDAY
WMOHDR(13)=ctemp(1:1)
WMOHDR(14)=ctemp(2:2)
!
!$ 1.3 PICK OFF THE HOUR(GG) AND CONVERT TO ASCII.
!
write(ctemp,fmt='(I2.2)') IHOUR
WMOHDR(15)=ctemp(1:1)
WMOHDR(16)=ctemp(2:2)
!
! 1.4 FIL IN REST OF HEADER
!
WMOHDR(17)=char(48) ! ASCII "0"
WMOHDR(18)=char(48) ! ASCII "0"
WMOHDR(19)=char(13) ! ASCII CR = '\r'
WMOHDR(20)=char(13) ! ASCII CR = '\r'
WMOHDR(21)=char(10) ! ASCII LF = '\n'
!
!$ 2. MOVE WMOHDR TO OUTPUT FIELD.
!
DO I = 1,21
HEADER(I) = WMOHDR(I)
end do
!
RETURN
END SUBROUTINE MAKWMO
74 changes: 0 additions & 74 deletions src/tocgrib/makwmo.f

This file was deleted.

82 changes: 41 additions & 41 deletions src/tocgrib/mkfldsep.f → src/tocgrib/mkfldsep.F90
Original file line number Diff line number Diff line change
Expand Up @@ -53,44 +53,44 @@
!> @param[out] lenout Integer length of the flag field separator block.
!>
!> @author Gilbert @date 2002-09-16
subroutine mkfldsep(csep,iopt,lenin,lenbull,lenout)
!
character*(*),intent(out) :: csep
integer,intent(in) :: iopt,lenin,lenbull
integer,intent(out) :: lenout
!
character(len=4),parameter :: cstar='****',clb='####'
!
if (iopt.eq.1) then
if ( lenin .le. 18 .and. lenbull .le. 999999 ) then
! Create OPTION 1 separator block
csep(1:4)=clb
csep(5:7)='018'
write(csep(8:13),fmt='(I6.6)') lenbull
csep(14:17)=clb
csep(18:18)=char(10)
lenout=18
else ! Create OPTION 1a separator block
nnn=lenin
if ( nnn.lt.23 ) nnn=23
csep(1:4)=clb
write(csep(5:7),fmt='(I3.3)') nnn
write(csep(8:18),fmt='(I11.11)') lenbull
csep(19:nnn-5)='0'
csep(nnn-4:nnn-1)=clb
csep(nnn:nnn)=char(10)
lenout=nnn
endif
elseif (iopt.eq.2) then ! Create OPTION 2 separator block
csep(1:4)=cstar
write(csep(5:14),fmt='(I10.10)') lenbull
csep(15:18)=cstar
csep(19:19)=char(10)
lenout=19
else
print *,"mkfldsep: Option ",iopt," not recognized."
csep(1:lenin)=' '
endif
!
return
end
subroutine mkfldsep(csep,iopt,lenin,lenbull,lenout)
!
character*(*),intent(out) :: csep
integer,intent(in) :: iopt,lenin,lenbull
integer,intent(out) :: lenout
!
character(len=4),parameter :: cstar='****',clb='####'
!
if (iopt.eq.1) then
if ( lenin .le. 18 .and. lenbull .le. 999999 ) then
! Create OPTION 1 separator block
csep(1:4)=clb
csep(5:7)='018'
write(csep(8:13),fmt='(I6.6)') lenbull
csep(14:17)=clb
csep(18:18)=char(10)
lenout=18
else ! Create OPTION 1a separator block
nnn=lenin
if ( nnn.lt.23 ) nnn=23
csep(1:4)=clb
write(csep(5:7),fmt='(I3.3)') nnn
write(csep(8:18),fmt='(I11.11)') lenbull
csep(19:nnn-5)='0'
csep(nnn-4:nnn-1)=clb
csep(nnn:nnn)=char(10)
lenout=nnn
endif
elseif (iopt.eq.2) then ! Create OPTION 2 separator block
csep(1:4)=cstar
write(csep(5:14),fmt='(I10.10)') lenbull
csep(15:18)=cstar
csep(19:19)=char(10)
lenout=19
else
print *,"mkfldsep: Option ",iopt," not recognized."
csep(1:lenin)=' '
endif
!
return
end subroutine mkfldsep
Loading

0 comments on commit cb892ed

Please sign in to comment.