Done. The wetting and drying algorithm was redesigned so it is more robust. A new routine wetdry.F was introduced to compute the wet/dry mask (rmask_wet, umask_wet, and vmask_wet), time-averaged mask over all barotropic steps (rmask_wet_avg), and full land/sea and wet/dry masks (rmask_full, umask_full, vmask_full). The full mask are only used for output purposes.
The barotropic velocities masking due to wetting and drying is somewhat tricky. For example, we now have:
# ifdef WET_DRY
cff5=ABS(ABS(umask_wet(i,j))-1.0_r8)
cff6=0.5_r8+DSIGN(0.5_r8,ubar(i,j,knew))*umask_wet(i,j)
cff7=0.5_r8*umask_wet(i,j)*cff5+cff6*(1.0_r8-cff5)
ubar(i,j,knew)=ubar(i,j,knew)*cff7
fac1=cff2/cff
rhs_ubar(i,j)=(ubar(i,j,knew)*(Dnew(i,j)+Dnew(i-1,j))- &
& ubar(i,j,kstp)*(Dstp(i,j)+Dstp(i-1,j)))* &
& fac1
# endif
The computation of the depths and level thicknesses are moved from step2d to main3d. This is done for clarity and to facilitate nesting in the future. A new internal cpp option is introduced (MOVE_SET_DEPTH) to avoid doing this in the adjoint-based algorithm. This is temporary and it will removed when the testing in several adjoint-based applications is completed. I tied few adjoint-based computations and I got identical sanity checks.
Many thanks to John Warner for his help in rewriting the wetting and drying option. We hope that this algorithm is more robust and eliminated the problem reported at the open boundaries.