Skip to content

WWMIII: IBOUNDFORMAT=1 reads from unopened FILEWAVE unit and falls back to fort.50005 #228

Description

@jc-suen

Hi SCHISM group,

When running SCHISM with WWMIII using the WWM parametric wave boundary format:

FILEBOUND    = 'wwmbnd.gr3'
FILEWAVE     = 'wave_param_boundary.dat'
IBOUNDFORMAT = 1
LBCWA        = T
LBCSE        = T
LINHOM       = T
LBCSP        = F

the file wave_param_boundary.dat exists and contains time-varying, spatially non-uniform parametric wave boundary data. Each time block contains one header line followed by one row for each active wave boundary node:

header line
Hs Period Direction Spread Shape SpreadMode GaussWidth Gamma
Hs Period Direction Spread Shape SpreadMode GaussWidth Gamma
...

However, the model does not read the file specified by FILEWAVE. Instead, it attempts to read the Fortran default file name fort.50005.

The model may fail with an error similar to:

forrtl: No such file or directory
unit 50005
file fort.50005

or the WWM wave boundary file is not read correctly.

In WWMIII, FILEWAVE is assigned to WAV%FNAME, while WAV%FHNDL is a Fortran unit number, for example:

WAV%FHNDL = 50005
WAV%FNAME = FILEWAVE

However, in the READWAVEPARWWM subroutine in src/WWMIII/wwm_initio.F90, the IBOUNDFORMAT=1 path directly reads from the unit:

READ(WAV%FHNDL,*)
READ(WAV%FHNDL, *) SPPARM(:,IPP)

If the unit has not previously been explicitly opened with:

OPEN(WAV%FHNDL, FILE=TRIM(WAV%FNAME), STATUS='OLD')

Fortran treats the unopened unit 50005 as the default file fort.50005. As a result, the model does not read:

FILEWAVE = 'wave_param_boundary.dat'

and instead tries to read:

fort.50005

In READWAVEPARWWM, before the first READ(WAV%FHNDL,*), check whether the unit is already opened. If it is not opened, explicitly open the file specified by WAV%FNAME.

Add a local variable:

LOGICAL :: LOPEN2

Then add the following before reading from WAV%FHNDL:

INQUIRE(WAV%FHNDL, OPENED=LOPEN2)
IF (.NOT. LOPEN2) THEN
  CALL TEST_FILE_EXIST_DIE('Missing wave file : ', TRIM(WAV%FNAME))
  OPEN(WAV%FHNDL, FILE=TRIM(WAV%FNAME), STATUS='OLD')
END IF

If the statement is split across multiple lines, Fortran free-form continuation should be used, for example:

CALL TEST_FILE_EXIST_DIE('Missing wave file : ', &
&  TRIM(WAV%FNAME))

After adding the explicit INQUIRE and OPEN logic, IBOUNDFORMAT=1 correctly reads the file specified by FILEWAVE, such as wave_param_boundary.dat, and the model can continue running normally.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions