anchor.diff:     INTEGER                      :: K                                               ! Generic index
      INTEGER                      :: LastInd                                         ! Index into the arrays saved from the last call as a starting point for this call
      INTEGER                      :: nSeeds                                          ! number of seeds required to initialize the intrinsic random number generator
  -   INTEGER                      :: NWaveKin0Prime                                  ! Number of points along a vertical line passing through the platform reference point where the incident wave kinematics will be computed before applying stretching to the instantaneous free surface (-)
  +   INTEGER                      :: NWaveKin0Prime                                  ! Number of points where the incident wave kinematics will be computed before applying stretching to the instantaneous free surface (-)
      INTEGER,    ALLOCATABLE      :: TmpWaveSeeds   (:)                              ! A temporary array used for portability. IVF/CVF use a random number generator initialized with 2 seeds; other platforms can use different implementations (e.g. gfortran needs 8 or 12 seeds)
  -   INTEGER                      :: UnFA     = 31                                   ! I/O unit number for the file needed for the GH Bladed wave data by FAST.
  -   INTEGER                      :: UnKi     = 32                                   ! I/O unit number for the GH Bladed wave data file containing wave particle kinematics time history.
  -   INTEGER                      :: UnSu     = 33                                   ! I/O unit number for the GH Bladed wave data file containing surface elevation time history.
  -
  -   LOGICAL                      :: Reading                                        ! Flag to say whether or not we are still reading from the GH Bladed wave data files (files not exhausted).
  -
  +   COMPLEX(ReKi)                :: tmpComplex                                      ! A temporary varible to hold the complex value of the wave elevation before storing it into a REAL array
  +   COMPLEX(ReKi),ALLOCATABLE    ::tmpComplexArr(:)
      TYPE(FFT_DataType)           :: FFT_Data                                        ! the instance of the FFT module we're using
   
  -      ! Initialize data
  -      
  -   ErrStat  = 0
  -   LastInd  = 1 
  -   Reading  = .TRUE.
  -
  -
  -      ! Save these values for future use:
  -
  -   WaveDat%NWaveElev  = Waves_InitData%NWaveElev
  -   WaveDat%NWaveKin0  = Waves_InitData%NWaveKin0
  -
  -   ALLOCATE ( WaveDat%DZNodes   (WaveDat%NWaveKin0) , STAT=ErrStat )
  -   IF ( ErrStat /= 0 )  THEN
  -      CALL ProgAbort(' Error allocating memory for the DZNodes array.', TrapErrors = .TRUE.)
  -      RETURN
  -   ENDIF
  -
  -   ALLOCATE ( WaveDat%WaveKinzi0(WaveDat%NWaveKin0) , STAT=ErrStat )
  -   IF ( ErrStat /= 0 )  THEN
  -      CALL ProgAbort(' Error allocating memory for the WaveKinzi0 array.', TrapErrors = .TRUE.)
  -      RETURN
  -   ENDIF
  -
  -   ALLOCATE ( WaveDat%WaveElevxi(WaveDat%NWaveElev) , STAT=ErrStat )    ! not sure this is necessary due to the assignment operator below
  -   IF ( ErrStat /= 0 )  THEN
  -      CALL ProgAbort(' Error allocating memory for the WaveElevxi array.', TrapErrors = .TRUE.)
  -      RETURN
  -   ENDIF
  -
  -   ALLOCATE ( WaveDat%WaveElevyi(WaveDat%NWaveElev) , STAT=ErrStat )
  -   IF ( ErrStat /= 0 )  THEN
  -      CALL ProgAbort(' Error allocating memory for the WaveElevyi array.', TrapErrors = .TRUE.)
  -      RETURN
  -   ENDIF
  -   
  -   
  -   WaveDat%WaveElevxi = Waves_InitData%WaveElevxi     ! store the array for interpolation later
  -   WaveDat%WaveElevyi = Waves_InitData%WaveElevyi     ! store the array for interpolation later
  -
  -
  -   WaveDat%DZNodes   (:) = Waves_InitData%DZNodes (:)
  -   WaveDat%Gravity       = Waves_InitData%Gravity
  -   WaveDat%WaveDir       = Waves_InitData%WaveDir
  -   WaveDat%WaveKinzi0(:) = Waves_InitData%WaveKinzi0(:)
  -   WaveDat%WaveMod       = Waves_InitData%WaveMod
  -   WaveDat%WaveStMod     = Waves_InitData%WaveStMod
  -           WaveTMax      = Waves_InitData%WaveTMax
  -   WaveDat%WtrDens       = Waves_InitData%WtrDens
  -   WaveDat%WtrDpth       = Waves_InitData%WtrDpth
  -
  -   WaveDat%RhoXg         = WaveDat%WtrDens*WaveDat%Gravity
  -
  -
  -
  -
  -      ! Initialize the variables associated with the incident wave:
  -
  -   SELECT CASE ( WaveDat%WaveMod ) ! Which incident wave kinematics model are we using?
  -
  -   CASE ( 0 )              ! None=still water.
  -
  -
  -
  -      ! Initialize everything to zero:
  -
  -      WaveDat%NStepWave  = 2                ! We must have at least two elements in order to interpolate later on
  -      WaveDat%NStepWave2 = 1
  -
  -      ALLOCATE ( WaveDat%WaveTime      (0:WaveDat%NStepWave-1                    ) , STAT=ErrStat )
  -      IF ( ErrStat /= 0 )  THEN
  -         CALL ProgAbort(' Error allocating memory for the WaveTime array.', TrapErrors = .TRUE.)
  -         RETURN
  -      ENDIF
  -
  -      ALLOCATE ( WaveDat%WaveElevC0    (0:WaveDat%NStepWave2                     ) , STAT=ErrStat )
  -      IF ( ErrStat /= 0 )  THEN
  -         CALL ProgAbort(' Error allocating memory for the WaveElevC0 array.', TrapErrors = .TRUE.)
  -         RETURN
  -      ENDIF
  -
  -      ALLOCATE ( WaveDat%WaveElev0     (0:WaveDat%NStepWave-1                    ) , STAT=ErrStat )
  -      IF ( ErrStat /= 0 )  THEN
  -         CALL ProgAbort(' Error allocating memory for the WaveElev0 array.', TrapErrors = .TRUE.)
  -         RETURN
  -      ENDIF
  -
  -      ALLOCATE ( WaveDat%WaveElev      (0:WaveDat%NStepWave-1,WaveDat%NWaveElev  ) , STAT=ErrStat )
  -      IF ( ErrStat /= 0 )  THEN
  -         CALL ProgAbort(' Error allocating memory for the WaveElev array.', TrapErrors = .TRUE.)
  -         RETURN
  -      ENDIF
  -
  -      ALLOCATE ( WaveDat%WaveDynP0     (0:WaveDat%NStepWave-1,WaveDat%NWaveKin0  ) , STAT=ErrStat )
  -      IF ( ErrStat /= 0 )  THEN
  -         CALL ProgAbort(' Error allocating memory for the WaveDynP0 array.', TrapErrors = .TRUE.)
  -         RETURN
  -      ENDIF
  -
  -
  -      ALLOCATE ( WaveDat%WaveVel0      (0:WaveDat%NStepWave-1,WaveDat%NWaveKin0,3) , STAT=ErrStat )
  -      IF ( ErrStat /= 0 )  THEN
  -         CALL ProgAbort(' Error allocating memory for the WaveVel0 array.', TrapErrors = .TRUE.)
  -         RETURN
  -      ENDIF
  -
  -      ALLOCATE ( WaveDat%WaveAcc0      (0:WaveDat%NStepWave-1,WaveDat%NWaveKin0,3) , STAT=ErrStat )
  -      IF ( ErrStat /= 0 )  THEN
  -         CALL ProgAbort(' Error allocating memory for the WaveAcc0 array.', TrapErrors = .TRUE.)
  -         RETURN
  -      ENDIF
  -
  -      WaveDat%WaveDOmega = 0.0
  -      WaveDat%WaveTime   = (/ 0.0_DbKi, 1.0_DbKi /)   ! We must have at least two different time steps in the interpolation
  -      WaveDat%WaveElevC0 = (0.0,0.0)
  -      WaveDat%WaveElev0  = 0.0
  -      WaveDat%WaveElev   = 0.0
  -      WaveDat%WaveDynP0  = 0.0
  -      WaveDat%WaveVel0   = 0.0
  -      WaveDat%WaveAcc0   = 0.0
  -      
  -
  -      ! Add the current velocities to the wave velocities:
  -
  -      DO J = 1,WaveDat%NWaveKin0   ! Loop through all points along a vertical line passing through the platform reference point where the incident wave kinematics will be computed
  -
  -         CALL InitCurrent ( Current_Data, &
  -                            WaveDat%WaveKinzi0(J), WaveDat%WtrDpth  , Waves_InitData%DirRoot  , CurrVxi  , CurrVyi )
  -
  -         WaveDat%WaveVel0(:,J,1) = WaveDat%WaveVel0(:,J,1) + CurrVxi  ! xi-direction
  -         WaveDat%WaveVel0(:,J,2) = WaveDat%WaveVel0(:,J,2) + CurrVyi  ! yi-direction
  -
  -      ENDDO                ! J - All points along a vertical line passing through the platform reference point where the incident wave kinematics will be computed
  -
  -
  -
  -
  -   CASE ( 1, 2, 3, 10 )       ! Plane progressive (regular) wave, JONSWAP/Pierson-Moskowitz spectrum (irregular) wave, or user-defined spectrum (irregular) wave.
  -
  -
  -
  -      ! Tell our nice users what is about to happen that may take a while:
  +   
  +      ! Initialize ErrStat
  +         
  +   ErrStat = ErrID_None         
  +   ErrMsg  = "" 
  +   
  +   
  +   ! Plane progressive (regular) wave, JONSWAP/Pierson-Moskowitz spectrum (irregular) wave, or user-defined spectrum (irregular) wave.
  +
  +         ! Tell our nice users what is about to happen that may take a while:
   
         CALL WrScr ( ' Generating incident wave kinematics and current time history.' )
   
  
positive.code:       !   and including, -WtrDpth and 0.0; the WaveKinzi0Prime(:) array must also
        !   include 0.0 even if the WaveKinzi0(:) array does not.
  
        ! Determine J_Min and NWaveKin0Prime here:
  
           J_Min          = 0
           NWaveKin0Prime = 0
           DO J = 1,WaveDat%NWaveKin0   ! Loop through all points along a vertical line passing through the platform reference point where the incident wave kinematics will be computed
              IF (    WaveDat%WaveKinzi0(J) >= -WaveDat%WtrDpth )  THEN
                 IF ( J_Min         == 0        )  J_Min = J
                 NWaveKin0Prime = NWaveKin0Prime + 1
                 IF ( WaveDat%WaveKinzi0(J) >= 0.0              )  EXIT
              ENDIF
           ENDDO                ! J - All points along a vertical line passing through the platform reference point where the incident wave kinematics will be computed
  
  
        ! ALLOCATE the WaveKinzi0Prime(:) array and compute its elements here:
  
           ALLOCATE ( WaveKinzi0Prime(NWaveKin0Prime) , STAT=ErrStat )
           IF ( ErrStat /= 0 )  THEN
              CALL ProgAbort(' Error allocating memory for the WaveKinzi0Prime array.', TrapErrors = .TRUE.)
              RETURN
           ENDIF
  
           DO J = 1,NWaveKin0Prime ! Loop through all points along a vertical line passing through the platform reference point where the incident wave kinematics will be computed without stretching
              WaveKinzi0Prime(J) = MIN( WaveDat%WaveKinzi0(J+J_Min-1), 0.0 )   ! The uppermost point is always zero even if WaveKinzi0(NWaveKin0Prime+J_Min-1) > 0.0
           ENDDO                   ! J - All points along a vertical line passing through the platform reference point where the incident wave kinematics will be computed without stretching
  
  
  
        CASE ( 3 )                 ! Wheeler stretching.
  
negative.code: 
  !JASON: ADD OTHER STRETCHING METHODS HERE, SUCH AS: DELTA STRETCHING (SEE ISO 19901-1) OR CHAKRABARTI STRETCHING (SEE OWTES)???
  !JASON: APPLY STRETCHING TO THE DYNAMIC PRESSURE, IF YOU EVER COMPUTE THAT HERE!!!
  
        SELECT CASE ( InitInp%WaveStMod )  ! Which model are we using to extrapolate the incident wave kinematics to the instantaneous free surface?
  
        CASE ( 0 )                 ! None=no stretching.
  
  