Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimized ww3_outp for the netcdf point output #1365

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions model/inp/ww3_outp.inp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ $ -------------------------------------------------------------------- $
$ WAVEWATCH III Point output post-processing $
$--------------------------------------------------------------------- $
$ First output time (yyyymmdd hhmmss), increment of output (s),
$ and number of output times.
$ and number of output times, optional per-time-step (1) or single (0)
$ point output
$
19680606 060000 3600. 7
19680606 060000 3600. 7 1
$
$ Points requested --------------------------------------------------- $
$ Define points for which output is to be generated.
Expand Down
22 changes: 10 additions & 12 deletions model/src/w3bullmd.F90
Original file line number Diff line number Diff line change
Expand Up @@ -269,18 +269,16 @@ SUBROUTINE W3BULL &
CSVBLINE = BLANK2
!
IPG1 = 0
IF (IOUT .EQ. 1) THEN
DO IP=1, NPTAB
HST(IP,1) = -99.9
TPT(IP,1) = -99.9
DMT(IP,1) = -99.9
ENDDO
DO IP=1, NPMAX
IYY(IP) = .FALSE.
IPI(IP)=1
ILEN(IP)=0
ENDDO
ENDIF
DO IP=1, NPTAB
HST(IP,1) = -99.9
TPT(IP,1) = -99.9
DMT(IP,1) = -99.9
ENDDO
DO IP=1, NPMAX
IYY(IP) = .FALSE.
IPI(IP)=1
ILEN(IP)=0
ENDDO
!
! 3. Get overall wave height ---------------------------------------- *
!
Expand Down
93 changes: 56 additions & 37 deletions model/src/w3iopomd.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,7 @@ end function nf90_err_check
!>
!> @author Edward Hartnett @date 1-Nov-2023
!>
SUBROUTINE W3IOPON_READ(IOTST, IMOD_IN, filename, ncerr)
SUBROUTINE W3IOPON_READ(IOTST, IMOD_IN, filename, ncerr, TOUT )
USE NetCDF
USE W3ODATMD, ONLY: W3DMO2
USE W3WDATMD, ONLY: TIME
Expand All @@ -1337,10 +1337,13 @@ SUBROUTINE W3IOPON_READ(IOTST, IMOD_IN, filename, ncerr)

INTEGER, INTENT(OUT) :: IOTST
INTEGER, INTENT(IN), OPTIONAL :: IMOD_IN
character(*), intent(in) :: filename
character(*), intent(out) :: filename
integer, intent(inout) :: ncerr
INTEGER, INTENT(IN), OPTIONAL :: TOUT(2)
CHARACTER(LEN=15) :: TIMETAG
LOGICAL :: per_time_step
INTEGER :: IGRD,MK,MTH
integer :: fh
integer :: fh, itime
integer :: d_nopts, d_nspec, d_vsize, d_namelen, d_grdidlen, d_time, d_ww3time
integer :: d_nopts_len, d_nspec_len, d_vsize_len, d_namelen_len, d_grdidlen_len, d_time_len, d_ww3time_len
integer :: v_idtst, v_vertst, v_nk, v_nth, v_ptloc, v_ptnme, v_time, v_ww3time
Expand All @@ -1365,6 +1368,15 @@ SUBROUTINE W3IOPON_READ(IOTST, IMOD_IN, filename, ncerr)
IGRD = 1
END IF

! Determine if we are reading a per-time-step file
per_time_step = PRESENT(TOUT)
IF (per_time_step) THEN
WRITE(TIMETAG, '(I8.8, ".", I6.6)') TOUT(1), TOUT(2)
filename = TRIM(FNMPRE) // TRIM(TIMETAG) // '.out_pnt.' // TRIM(FILEXT) // '.nc'
ELSE
filename = FNMPRE(:LEN_TRIM(FNMPRE))//'out_pnt.'//FILEXT(:LEN_TRIM(FILEXT))//'.nc'
END IF

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AliS-Noaa - Particularly because the code will fail without a very informative error, before trying to open the file, adding in a check to see if the file exists and if it does not, providing an informative error statement before existing would be helpful. Please let me know if you need any assistance adding this.

! Open the netCDF file.
ncerr = nf90_open(filename, NF90_NOWRITE, fh)
if (nf90_err(ncerr) .ne. 0) return
Expand Down Expand Up @@ -1424,11 +1436,16 @@ SUBROUTINE W3IOPON_READ(IOTST, IMOD_IN, filename, ncerr)
if (nf90_err(ncerr) .ne. 0) return
ncerr = nf90_inquire_dimension(fh, d_time, len = d_time_len)
if (nf90_err(ncerr) .ne. 0) return

!Determine the start for the time dimension
IF ( per_time_step ) THEN
itime=1
ELSE
itime=IPASS
END IF

IF ( IPASS .LE. d_time_len ) THEN

IF ( IPASS.EQ.1 ) THEN

IF ( itime .LE. d_time_len ) THEN
IF ( itime.EQ.1 ) THEN
! Read scalar variables.
ncerr = nf90_inq_varid(fh, VNAME_NK, v_nk)
if (nf90_err(ncerr) .ne. 0) return
Expand All @@ -1440,33 +1457,32 @@ SUBROUTINE W3IOPON_READ(IOTST, IMOD_IN, filename, ncerr)
if (nf90_err(ncerr) .ne. 0) return

!read in written variables NK, NTH as MK and MTH
!and ensure they match
!and ensure they match
IF (NK.NE.MK .OR. NTH.NE.MTH) THEN
WRITE (NDSE,904) MK, MTH, NK, NTH
CALL EXTCDE ( 12 )
END IF

! Allocate variables:
! Allocate variables:
IF ( .NOT. O2INIT ) &
CALL W3DMO2 ( IGRD, NDSE, NDST, NOPTS )
CALL W3DMO2 ( IGRD, NDSE, NDST, NOPTS )

! Read vars with nopts as a dimension.
ncerr = nf90_inq_varid(fh, VNAME_PTLOC, v_ptloc)
if (nf90_err(ncerr) .ne. 0) return
ncerr = nf90_get_var(fh, v_ptloc, PTLOC, start = (/ 1, 1/), &
count = (/ d_vsize_len, d_nopts_len /))
count = (/ d_vsize_len, d_nopts_len /))
if (nf90_err(ncerr) .ne. 0) return
ncerr = nf90_inq_varid(fh, VNAME_PTNME, v_ptnme)
if (nf90_err(ncerr) .ne. 0) return
ncerr = nf90_get_var(fh, v_ptnme, PTNME)
if (nf90_err(ncerr) .ne. 0) return
END IF

!Variables read based on time (IPASS):

END IF

!Variables read based on time (IPASS):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!Variables read based on time (IPASS):
->
!Variables read based on time (itime):

ncerr = nf90_inq_varid(fh, VNAME_WW3TIME, v_ww3time)
if (nf90_err(ncerr) .ne. 0) return
ncerr = nf90_get_var(fh, v_ww3time, TIME, start = (/ 1, IPASS/), &
ncerr = nf90_get_var(fh, v_ww3time, TIME, start = (/ 1, itime/), &
count = (/ d_vsize_len, 1 /))
if (nf90_err(ncerr) .ne. 0) return

Expand All @@ -1479,90 +1495,89 @@ SUBROUTINE W3IOPON_READ(IOTST, IMOD_IN, filename, ncerr)

ncerr = nf90_inq_varid(fh, VNAME_DPO, v_dpo)
if (nf90_err(ncerr) .ne. 0) return
ncerr = nf90_get_var(fh, v_dpo, DPO, start = (/ 1, IPASS/), &
ncerr = nf90_get_var(fh, v_dpo, DPO, start = (/ 1, itime/), &
count = (/ NOPTS, 1 /))
if (nf90_err(ncerr) .ne. 0) return
ncerr = nf90_inq_varid(fh, VNAME_WAO, v_wao)
if (nf90_err(ncerr) .ne. 0) return
ncerr = nf90_get_var(fh, v_wao, WAO, start = (/ 1, IPASS/), &
ncerr = nf90_get_var(fh, v_wao, WAO, start = (/ 1, itime/), &
count = (/ NOPTS, 1 /))
if (nf90_err(ncerr) .ne. 0) return
ncerr = nf90_inq_varid(fh, VNAME_WDO, v_wdo)
if (nf90_err(ncerr) .ne. 0) return
ncerr = nf90_get_var(fh, v_wdo, WDO, start = (/ 1, IPASS/), &
ncerr = nf90_get_var(fh, v_wdo, WDO, start = (/ 1, itime/), &
count = (/ NOPTS, 1 /))
if (nf90_err(ncerr) .ne. 0) return
#ifdef W3_FLX5
ncerr = nf90_inq_varid(fh, VNAME_TAUAO, v_tauao)
if (nf90_err(ncerr) .ne. 0) return
ncerr = nf90_get_var(fh, v_tauao, TAUAO, start = (/ 1, IPASS/), &
ncerr = nf90_get_var(fh, v_tauao, TAUAO, start = (/ 1, itime/), &
count = (/ NOPTS, 1 /))
if (nf90_err(ncerr) .ne. 0) return
ncerr = nf90_inq_varid(fh, VNAME_TAUDO, v_taudo)
if (nf90_err(ncerr) .ne. 0) return
ncerr = nf90_get_var(fh, v_taudo, TAUDO, start = (/ 1, IPASS/), &
ncerr = nf90_get_var(fh, v_taudo, TAUDO, start = (/ 1, itime/), &
count = (/ NOPTS, 1 /))
if (nf90_err(ncerr) .ne. 0) return
ncerr = nf90_inq_varid(fh, VNAME_DAIRO, v_dairo)
if (nf90_err(ncerr) .ne. 0) return
ncerr = nf90_get_var(fh, v_dairo, DAIRO, start = (/ 1, IPASS/), &
ncerr = nf90_get_var(fh, v_dairo, DAIRO, start = (/ 1, itime/), &
count = (/ NOPTS, 1 /))
if (nf90_err(ncerr) .ne. 0) return
#endif
#ifdef W3_SETUP
ncerr = nf90_inq_varid(fh, ZET_SETO, v_zet_seto)
if (nf90_err(ncerr) .ne. 0) return
ncerr = nf90_get_var(fh, v_zet_seto, ZET_SETO, start = (/ 1, IPASS/), &
ncerr = nf90_get_var(fh, v_zet_seto, ZET_SETO, start = (/ 1, itime/), &
count = (/ NOPTS, 1 /))
if (nf90_err(ncerr) .ne. 0) return
#endif
ncerr = nf90_inq_varid(fh, VNAME_ASO, v_aso)
if (nf90_err(ncerr) .ne. 0) return
ncerr = nf90_get_var(fh, v_aso, ASO, start = (/ 1, IPASS/), &
ncerr = nf90_get_var(fh, v_aso, ASO, start = (/ 1, itime/), &
count = (/ NOPTS, 1 /))
if (nf90_err(ncerr) .ne. 0) return
ncerr = nf90_inq_varid(fh, VNAME_CAO, v_cao)
if (nf90_err(ncerr) .ne. 0) return
ncerr = nf90_get_var(fh, v_cao, CAO, start = (/ 1, IPASS/), &
ncerr = nf90_get_var(fh, v_cao, CAO, start = (/ 1, itime/), &
count = (/ NOPTS, 1 /))
if (nf90_err(ncerr) .ne. 0) return
ncerr = nf90_inq_varid(fh, VNAME_CDO, v_cdo)
if (nf90_err(ncerr) .ne. 0) return
ncerr = nf90_get_var(fh, v_cdo, CDO, start = (/ 1, IPASS/), &
ncerr = nf90_get_var(fh, v_cdo, CDO, start = (/ 1, itime/), &
count = (/ NOPTS, 1 /))
if (nf90_err(ncerr) .ne. 0) return
ncerr = nf90_inq_varid(fh, VNAME_ICEO, v_iceo)
if (nf90_err(ncerr) .ne. 0) return
ncerr = nf90_get_var(fh, v_iceo, ICEO, start = (/ 1, IPASS/), &
ncerr = nf90_get_var(fh, v_iceo, ICEO, start = (/ 1, itime/), &
count = (/ NOPTS, 1 /))
if (nf90_err(ncerr) .ne. 0) return
ncerr = nf90_inq_varid(fh, VNAME_ICEHO, v_iceho)
if (nf90_err(ncerr) .ne. 0) return
ncerr = nf90_get_var(fh, v_iceho, ICEHO, start = (/ 1, IPASS/), &
ncerr = nf90_get_var(fh, v_iceho, ICEHO, start = (/ 1, itime/), &
count = (/ NOPTS, 1 /))
if (nf90_err(ncerr) .ne. 0) return
ncerr = nf90_inq_varid(fh, VNAME_ICEFO, v_icefo)
if (nf90_err(ncerr) .ne. 0) return
ncerr = nf90_get_var(fh, v_icefo, ICEFO, start = (/ 1, IPASS/), &
ncerr = nf90_get_var(fh, v_icefo, ICEFO, start = (/ 1, itime/), &
count = (/ NOPTS, 1 /))
if (nf90_err(ncerr) .ne. 0) return
ncerr = nf90_inq_varid(fh, VNAME_GRDID, v_grdid)
if (nf90_err(ncerr) .ne. 0) return
ncerr = nf90_get_var(fh, v_grdid, GRDID, start = (/ 1, 1, IPASS/), &
ncerr = nf90_get_var(fh, v_grdid, GRDID, start = (/ 1, 1, itime/), &
count = (/ 13, nopts, 1 /))
if (nf90_err(ncerr) .ne. 0) return
ncerr = nf90_inq_varid(fh, VNAME_SPCO, v_spco)
if (nf90_err(ncerr) .ne. 0) return
ncerr = nf90_get_var(fh, v_spco, SPCO, start = (/ 1, 1, IPASS/), &
ncerr = nf90_get_var(fh, v_spco, SPCO, start = (/ 1, 1, itime/), &
count = (/nspec, nopts, 1 /))
if (nf90_err(ncerr) .ne. 0) return

ELSE
! Set flag to indicate IPASS > d_time_len
! and are at the end of the
IOTST = -1
END IF

END IF
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove extra space here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JessicaMeixner-NOAA This is done and its ready for review.

! Close the file.
ncerr = nf90_close(fh)
if (nf90_err(ncerr) .ne. 0) return
Expand Down Expand Up @@ -1912,7 +1927,7 @@ END SUBROUTINE W3IOPON_WRITE
!> @param[in] IMOD Model number for W3GDAT etc.
!>
!> @author Edward Hartnett @date 1-Nov-2023
SUBROUTINE W3IOPON ( INXOUT, NDSOP, IOTST, IMOD)
SUBROUTINE W3IOPON ( INXOUT, NDSOP, IOTST, IMOD, TOUT )
USE W3GDATMD, ONLY: W3SETG
USE W3WDATMD, ONLY: W3SETW
USE W3ODATMD, ONLY: W3SETO
Expand All @@ -1930,8 +1945,8 @@ SUBROUTINE W3IOPON ( INXOUT, NDSOP, IOTST, IMOD)
CHARACTER, INTENT(IN) :: INXOUT*(*)
INTEGER, INTENT(IN) :: NDSOP
INTEGER, INTENT(OUT) :: IOTST
INTEGER, INTENT(IN), OPTIONAL :: TOUT(2)
INTEGER, INTENT(IN), OPTIONAL :: IMOD

CHARACTER(LEN=15) :: TIMETAG
INTEGER :: IGRD
character(len = 124) :: filename
Expand Down Expand Up @@ -1975,7 +1990,11 @@ SUBROUTINE W3IOPON ( INXOUT, NDSOP, IOTST, IMOD)

! Do a read or a write of the point file.
IF (INXOUT .EQ. 'READ') THEN
CALL W3IOPON_READ(IOTST, IMOD, filename, ncerr)
IF (PRESENT(TOUT)) THEN
CALL W3IOPON_READ(IOTST, IMOD, filename, ncerr, TOUT)
ELSE
CALL W3IOPON_READ(IOTST, IMOD, filename, ncerr)
END IF
ELSE
CALL W3IOPON_WRITE(OFILES(2), filename, ncerr)
ENDIF
Expand Down
Loading
Loading