The method for the wind correction has been implemented into a FORTRAN subroutine.
!-------------------------------------------------------------------
! Inputs:
! VB: The vessel's speed. (m/s)
! AB0: The angle of the vessel velocity using the compass coordinate
! system (CCS) in degrees.
! VW: The wind speed, that is relative to the ferry. (m/s)
! AW0: The angle of the wind velocity in CCS relative to the boat
! and using the NWS convention (i.e. direction wind is coming from).
! Outputs:
! VWC: The corrected wind speed relative to the ground. (m/s)
! AWC3: The angle for the corrected wind velocity in the CCS in
! degrees, along with using the NWS convention.
! UPWIND: This returns a zero if the starboard or bow is upwind.
! This returns a one if the port or stern is upwind.
!-------------------------------------------------------------------
SUBROUTINE Windcorrect (VB, VW, AB0, AW0, VWC, AWC3, UPWIND)
REAL, INTENT(IN) :: VB, VW, AB0, AW0
REAL, INTENT(OUT) :: VWC, AWC3
REAL :: VBX, VBY, VWX, VWY, VX0, VY0, VX, VY, AW2, VWX0, VWY0
REAL :: AB1, AW1, PI, AWC, AWC1, AB, AW, AT, AWC2
INTEGER, INTENT(OUT) :: UPWIND
INTEGER :: A, B
! These modulus functions convert the angle of the velocities from
! the compass coordinates system (CCS) into the polar coordinate
! system (PCS), in degrees.
AB1 = MOD(((360.0 - AB0) + 90.0), 360.0)
AW1 = MOD(((360.0 - AW0) + 90.0), 360.0)
! The following is the conversion from degrees to radians for the
! angle of the boat.
PI = 3.1415926536
AB = AB1 * PI / 180
! Before the angle of the wind with respect to the vessel gets
! converted from degrees to radians, the angle needs to be changed
! so that the angle of the wind represents the direction the wind is
! moving to rather than coming from.
AW2 = MOD((AW1 + 180.0), 360.0)
AW = AW2 * PI / 180
! These are the components for the vessel's velocity relative to the
! ground.
VBX = ABS(VB) * COS(AB)
VBY = ABS(VB) * SIN(AB)
! This provides the components for the wind velocity with respect to
! the boat in PCS.
VWX0 = ABS(VW) * COS(AW)
VWY0 = ABS(VW) * SIN(AW)
! In order to get the x-y components of the wind velocity, as
! measured on the boat, in terms of the coordinate system of the
! ground, an angle rotation is required.
AT = (PI/2) - AB
! This rotation takes the following form:
VWX = (COS(AT) * VWX0) + (SIN(AT) * VWY0)
VWY = (-SIN(AT) * VWX0) + (COS(AT) * VWY0)
! Vector addition is used to account for the motion of the vessel
! and calculate the wind relative to the ground.
VX0 = VWX + VBX
VY0 = VWY + VBY
! To facilitate the calculations, the values for VX and VY are
! rounded to the nearest one-thousandth. This was done so that
! any values that are equal to zero will become zero. For
! example, in some of the calculations, when VX0 and VY0 should have
! equalled zero were actually retrieving values in the range of
! 10E-07. This was a problem because of the IF statement below
! which deals with tangent was computed incorrect values for the
! angles of the corrected wind in PCS.
VX = VX0 * 1000
A = INT(VX)
VX = REAL(A) / 1000
VY = VY0 * 1000
B = INT(VY)
VY = REAL(B) / 1000
! The following formula calculates the speed of the corrected wind.
VWC = SQRT((VX * VX) + (VY * VY))
! The following gives the direction of the corrected wind in PCS.
IF (VX .EQ. 0) THEN
! The wind direction is retrieved in degrees if this is true.
IF (VY .GT. 0) THEN
AWC1 = 90.0
ELSE IF (VY .LT. 0) THEN
AWC1 = 270.0
ELSE
AWC1 = 0.0
END IF
ELSE
! The wind direction is retrieved in radians if this is true.
AWC = ATAN2(VY, VX)
! The corrected angle is converted from radians back into
! degrees.
IF (AWC .LT. 0) THEN
AWC1 = (AWC * 180 / PI) + 360
ELSE
AWC1 = AWC * 180 / PI
END IF
END IF
! The wind direction is changed from the PCS back into the CCS.
IF (VX .EQ. 0) THEN
IF (VY .GT. 0) THEN
AWC2 = 0.0
AWC3 = 180.0
ELSE
AWC2 = 180.0
AWC3 = 0.0
END IF
ELSE
AWC2 = MOD(((360.0 - AWC1) + 90.0), 360.0)
END IF
! The angle of the corrected wind is converted from CCS into
! the NWS convention.
IF (AWC2 .GE. 0 .AND. AWC2 .LT. 180) THEN
AWC3 = AWC2 + 180.0
ELSE
AWC3 = AWC2 - 180.0
END IF
IF (AW0 .GE. 0 .AND. AW0 .LT. 180) THEN
! The following provides whether the starboard or the bow
! is upwind.
UPWIND = 0
ELSE
! The following provides whether the port or the stern
! is upwind.
UPWIND = 1
END IF
END SUBROUTINE Windcorrect