anchor.diff:          AA     = AMINA + ARA0 * (AMAXA - AMINA)
   
           SPLP(I)=AA+K1-3.+10.*LOG10(DSTRP*M**5.*DBARH*L/R**2.)+DELK1
  -
  -
           STS = p%FreqList(I) * DSTRS / U
   
  -      IF (.NOT. SWITCH) THEN
  -        A      = LOG10( STS / ST1PRIM )
  -        CALL AMIN(A,AMINA)
  -        CALL AMAX(A,AMAXA)
  -        AA = AMINA + ARA0 * (AMAXA - AMINA)
  -
  -        SPLS(I) = AA+K1-3.+10.*LOG10(DSTRS*M**5.*DBARH* &
  -                 L/R**2.)
  -
  -!      'B' CURVE COMPUTATION
  -!       --------------------
  -
  -!        B = ABS(LOG10(STS / ST2))
  -        B = LOG10(STS / ST2) ! abs not needed absolute taken in the AMAX,AMIN
  -        CALL BMIN(B,BMINB)
  -        CALL BMAX(B,BMAXB)
  -        BB = BMINB + BRB0 * (BMAXB-BMINB)
  -        SPLALPH(I)=BB+K2+10.*LOG10(DSTRS*M**5.*DBARH*L/R**2.)
  -
  -      ELSE
  -
  -!       THE 'A' COMPUTATION IS DROPPED IF 'SWITCH' IS TRUE
  -!       --------------------------------------------------
  -
  -
  -        SPLS(I) = 10.*LOG10(DSTRS*M**5.*DBARL*L/R**2.)
  -!    SPLP(I) = 0.0 + 10.*LOG10(DSTRS*M**5.*DBARL*L/R**2.) ! changed the line below because the SPLP should be calculatd with DSTRP not with DSTRS
  -        SPLP(I) = 10.*LOG10(DSTRP*M**5.*DBARL*L/R**2.) ! this is correct
  -!        B = ABS(LOG10(STS / ST2))
  -        B = LOG10(STS / ST2) ! abs not needed absolute taken in the AMAX,AMIN
  -        CALL AMIN(B,AMINB)
  -        CALL AMAX(B,AMAXB)
  -        BB = AMINB + ARA02 * (AMAXB-AMINB)
  -        SPLALPH(I)=BB+K2+10.*LOG10(DSTRS*M**5.*DBARL*L/R**2.)
  -      ENDIF
  -
  -
  -!      SUM ALL CONTRIBUTIONS FROM 'A' AND 'B' ON BOTH
  -!      PRESSURE AND SUCTION SIDE ON A MEAN-SQUARE PRESSURE
  -!      BASIS
  -!      ---------------------------------------------------
  -
  -      IF (SPLP(I)    .LT. -100.) SPLP(I)    = -100.
  -      IF (SPLS(I)    .LT. -100.) SPLS(I)    = -100.
  -      IF (SPLALPH(I) .LT. -100.) SPLALPH(I) = -100.
  -
  -      P1  = 10.**(SPLP(I) / 10.)
  -      P2  = 10.**(SPLS(I) / 10.)
  -      P4  = 10.**(SPLALPH(I) / 10.)
  -
  -      SPLTBL(I) = 10. * LOG10(P1 + P2 + P4)
  -!   print*,p%FreqList(I),SPLP(I),SPLS(I),SPLalph(I),SWITCH,ALPSTAR
  +        IF (.NOT. SWITCH) THEN
  +            A      = LOG10( STS / ST1PRIM )
  +            CALL AMIN(A,AMINA)
  +            CALL AMAX(A,AMAXA)
  +            AA = AMINA + ARA0 * (AMAXA - AMINA)
  +            SPLS(I) = AA+K1-3.+10.*LOG10(DSTRS*M**5.*DBARH* L/R**2.)
  +            !  'B' CURVE COMPUTATION
  +            !        B = ABS(LOG10(STS / ST2))
  +            B = LOG10(STS / ST2) ! abs not needed absolute taken in the AMAX,AMIN
  +            CALL BMIN(B,BMINB)
  +            CALL BMAX(B,BMAXB)
  +            BB = BMINB + BRB0 * (BMAXB-BMINB)
  +            SPLALPH(I)=BB+K2+10.*LOG10(DSTRS*M**5.*DBARH*L/R**2.)
  +        ELSE
  +            ! The 'a' computation is dropped if 'switch' is true
  +            SPLS(I) = 10.*LOG10(DSTRS*M**5.*DBARL*L/R**2.)
  +            !    SPLP(I) = 0.0 + 10.*LOG10(DSTRS*M**5.*DBARL*L/R**2.) ! changed the line below because the SPLP should be calculatd with DSTRP not with DSTRS
  +            SPLP(I) = 10.*LOG10(DSTRP*M**5.*DBARL*L/R**2.) ! this is correct
  +            !        B = ABS(LOG10(STS / ST2))
  +            B = LOG10(STS / ST2) ! abs not needed absolute taken in the AMAX,AMIN
  +            CALL AMIN(B,AMINB)
  +            CALL AMAX(B,AMAXB)
  +            BB = AMINB + ARA02 * (AMAXB-AMINB)
  +            SPLALPH(I)=BB+K2+10.*LOG10(DSTRS*M**5.*DBARL*L/R**2.)
  +        ENDIF
  +        ! Sum all contributions from 'a' and 'b' on both pressure and suction side on a mean-square pressure basis
  +        IF (SPLP(I)    .LT. -100.) SPLP(I)    = -100.
  +        IF (SPLS(I)    .LT. -100.) SPLS(I)    = -100.
  +        IF (SPLALPH(I) .LT. -100.) SPLALPH(I) = -100.
  +
  +        P1  = 10.**(SPLP(I) / 10.)
  +        P2  = 10.**(SPLS(I) / 10.)
  +        P4  = 10.**(SPLALPH(I) / 10.)
  +        SPLTBL(I) = 10. * LOG10(P1 + P2 + P4)
       ENDDO
  - !   print*, '--------------------------------------------------------'
  -      RETURN
  -      END SUBROUTINE TBLTE
  +END SUBROUTINE TBLTE
   !==================================================================================================================================!
  -!==================================================================================================================================!
  -	SUBROUTINE TIPNOIS(ALPHTIP,ALPRAT2,C,U ,THETA,PHI, R,p,SPLTIP, errStat, errMsg)
  -
  -  REAL(ReKi),           	                  INTENT(IN   )  :: ALPHTIP        ! AOA
  -  REAL(ReKi),           	                  INTENT(IN   )  :: ALPRAT2        ! TIP LIFT CURVE SLOPE                 ---
  -  REAL(ReKi),           	                  INTENT(IN   )  :: C              ! Chord Length
  -  REAL(ReKi),           	                  INTENT(IN   )  :: U              ! FREESTREAM VELOCITY               METERS/SEC
  -  REAL(ReKi),           	                  INTENT(IN   )  :: THETA          ! DIRECTIVITY ANGLE                  DEGREES 
  -  REAL(ReKi),           	                  INTENT(IN   )  :: PHI            ! DIRECTIVITY ANGLE                  DEGREES
  -  REAL(ReKi),           	                  INTENT(IN   )  :: R              ! SOURCE TO OBSERVER DISTANCE        METERS
  -  TYPE(AA_ParameterType),                         INTENT(IN   )  :: p              ! Parameters
  -
  -  REAL(ReKi),DIMENSION(size(p%FreqList)),	  INTENT(  OUT)  :: SPLTIP         !
  -  INTEGER(IntKi),                   		  INTENT(  OUT)  :: errStat        ! Error status of the operation
  -  character(*),                                   INTENT(  OUT)  :: errMsg         ! Error message if ErrStat /= ErrID_None
  -  integer(intKi)                                             :: ErrStat2       ! temporary Error status
  -  character(ErrMsgLen)                                       :: ErrMsg2        ! temporary Error message
  -  character(*), parameter                                    :: RoutineName = 'tipnoise'
  -
  -! local variables
  -   REAL(ReKi)        :: M        ! MACH NUMBER                         ---
  -   REAL(ReKi)        :: MM       ! MAXIMUM MACH NUMBER                 ---
  -   REAL(ReKi)        :: ALPTIPP  ! CORRECTED TIP ANGLE OF ATTACK      DEGREES
  -   REAL(ReKi)        :: DBARH    ! DIRECTIVITY                         ---
  -   REAL(ReKi)        :: SCALE    ! SCALING TERM                        ---
  -   REAL(ReKi)        :: STPP     ! STROUHAL NUMBER                     ---
  -   REAL(ReKi)        :: UM       ! MAXIMUM VELOCITY                  METERS/SEC
  -   REAL(ReKi)        :: L        ! CHARACTERISTIC LENGTH FOR TIP      METERS
  -   REAL(ReKi)        :: TERM     ! SCALING TERM                        ---
  -   integer(intKi)    :: I        !I A generic index for DO loops.	
  -
  -	
  -   ErrStat = ErrID_None
  -   ErrMsg  = ""
  -
  -   
  -      IF (alphtip.eq.0.) THEN
  -         SPLTIP= 0
  -         RETURN
  -      ELSEIF (alphtip.lt.0.) THEN
  -!         alphtip = ABS (alphtip) !  (EB_DTU) NOT possible to change inten(in) variable, INSTEAD 
  -				  !  ALPTIPP is equal to abs(alphtip) - see next equation 
  -      ENDIF
  -!! used to be  ALPTIPP = ALPHTIP * ALPRAT2
  -               ALPTIPP = ABS(ALPHTIP) * ALPRAT2
  -
  -!!!      COMPUTE ´ MACH NUMBER
  -!!!      ---------------------------------------
  -        M          = U  / p%SpdSound
  -!!!      COMPUTE DIRECTIVITY FUNCTION
  -!!!      ----------------------------
  -	  CALL DIRECTH(M,THETA,PHI,DBARH,errStat2,errMsg2)
  -		 CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName ) 
  -
  -      IF (p%ROUND) THEN
  +SUBROUTINE TIPNOIS(ALPHTIP,ALPRAT2,C,U ,THETA,PHI, R,p,SPLTIP, errStat, errMsg)
  +    REAL(ReKi),                               INTENT(IN   )  :: ALPHTIP        !< AOA
  +    REAL(ReKi),                               INTENT(IN   )  :: ALPRAT2        !< TIP LIFT CURVE SLOPE                 ---
  +    REAL(ReKi),                               INTENT(IN   )  :: C              !< Chord Length
  +    REAL(ReKi),                               INTENT(IN   )  :: U              !< FREESTREAM VELOCITY               METERS/SEC
  +    REAL(ReKi),                               INTENT(IN   )  :: THETA          !< DIRECTIVITY ANGLE                  DEGREES 
  +    REAL(ReKi),                               INTENT(IN   )  :: PHI            !< DIRECTIVITY ANGLE                  DEGREES
  +    REAL(ReKi),                               INTENT(IN   )  :: R              !< SOURCE TO OBSERVER DISTANCE        METERS
  +    TYPE(AA_ParameterType) ,                  INTENT(IN   )  :: p              !< Parameters
  +    REAL(ReKi),DIMENSION(size(p%FreqList)),   INTENT(  OUT)  :: SPLTIP         !<
  +    INTEGER(IntKi),                           INTENT(  OUT)  :: errStat        !< Error status of the operation
  +    character(*),                             INTENT(  OUT)  :: errMsg         !< Error message if ErrStat /= ErrID_None
  +    ! local variables
  +    integer(intKi)                                             :: ErrStat2       ! temporary Error status
  +    character(ErrMsgLen)                                       :: ErrMsg2        ! temporary Error message
  +    character(*), parameter                                    :: RoutineName = 'tipnoise'
  +    REAL(ReKi)        :: M        ! MACH NUMBER                         ---
  +    REAL(ReKi)        :: MM       ! MAXIMUM MACH NUMBER                 ---
  +    REAL(ReKi)        :: ALPTIPP  ! CORRECTED TIP ANGLE OF ATTACK      DEGREES
  +    REAL(ReKi)        :: DBARH    ! DIRECTIVITY                         ---
  +    REAL(ReKi)        :: SCALE    ! SCALING TERM                        ---
  +    REAL(ReKi)        :: STPP     ! STROUHAL NUMBER                     ---
  +    REAL(ReKi)        :: UM       ! MAXIMUM VELOCITY                  METERS/SEC
  +    REAL(ReKi)        :: L        ! CHARACTERISTIC LENGTH FOR TIP      METERS
  +    REAL(ReKi)        :: TERM     ! SCALING TERM                        ---
  +    integer(intKi)    :: I        !I A generic index for DO loops.	
  +    ErrStat = ErrID_None
  +    ErrMsg  = ""
  +    IF (alphtip.eq.0.) THEN
  +        SPLTIP= 0
  +        RETURN
  +    ELSEIF (alphtip.lt.0.) THEN
  +        !         alphtip = ABS (alphtip) !  (EB_DTU) NOT possible to change inten(in) variable, INSTEAD 
  +        !  ALPTIPP is equal to abs(alphtip) - see next equation 
  +    ENDIF
  +    !! used to be  ALPTIPP = ALPHTIP * ALPRAT2
  +    ALPTIPP = ABS(ALPHTIP) * ALPRAT2
  +    M          = U  / p%SpdSound ! MACH NUMBER
  +    ! Compute directivity function
  +    CALL DIRECTH(M,THETA,PHI,DBARH,errStat2,errMsg2)
  +    CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName ) 
  +    IF (p%ROUND) THEN
           L = .008 * ALPTIPP * C
  -      ELSE
  +    ELSE
           IF (ABS(ALPTIPP) .LE. 2.) THEN
  -          L = (.023 + .0169*ALPTIPP) * C
  +            L = (.023 + .0169*ALPTIPP) * C
           ELSE
  -          L = (.0378 + .0095*ALPTIPP) * C
  +            L = (.0378 + .0095*ALPTIPP) * C
           ENDIF
  -      ENDIF
  -
  -
  -      MM     = (1. + .036*ALPTIPP) * M
  -
  -      UM     = MM * p%SpdSound
  -
  -      TERM  = M*M*MM**3.*L**2.*DBARH/R**2.
  -      IF (TERM .NE. 0.0) THEN
  +    ENDIF
  +    MM    = (1. + .036*ALPTIPP) * M
  +    UM    = MM * p%SpdSound
  +    TERM  = M*M*MM**3.*L**2.*DBARH/R**2.
  +    IF (TERM .NE. 0.0) THEN
           SCALE = 10.*LOG10(TERM)
  -      ELSE
  +    ELSE
           SCALE = 0.0
  -      ENDIF
  -
  -      DO I=1,size(p%FreqList)
  +    ENDIF
  +    DO I=1,size(p%FreqList)
           STPP      = p%FreqList(I) * L / UM
           SPLTIP(I) = 126.-30.5*(LOG10(STPP)+.3)**2. + SCALE
  -	  ENDDO
  -
  -
  -      RETURN
  -      END SUBROUTINE TipNois
  -!==================================================================================================================================!
  +    ENDDO
  +END SUBROUTINE TipNois
   !==================================================================================================================================!
   SUBROUTINE InflowNoise(AlphaNoise,Chord,U,THETA,PHI,d,RObs,MeanVNoise,TINoise,LE_Location,dissip,ufluct,p,SPLti,errStat,errMsg)
  -
  -	IMPLICIT NONE
  -  REAL(ReKi),           	                  INTENT(IN   )  :: AlphaNoise        ! AOA
  -  REAL(ReKi),           	                  INTENT(IN   )  :: Chord          ! Chord Length
  -  REAL(ReKi),           	                  INTENT(IN   )  :: U              !
  -  REAL(ReKi),           	                  INTENT(IN   )  :: d              ! element span
  -  REAL(ReKi),           	                  INTENT(IN   )  :: RObs           ! distance to observer
  -  REAL(ReKi),           	                  INTENT(IN   )  :: THETA          ! 
  -  REAL(ReKi),           	                  INTENT(IN   )  :: PHI            ! Spanwise directivity angle 
  -  REAL(ReKi),           	                  INTENT(IN   )  :: MeanVNoise     ! 
  -  REAL(ReKi),           	                  INTENT(IN   )  :: TINoise        !
  -  REAL(ReKi),           	                  INTENT(IN   )  :: LE_Location    ! 
  -  REAL(ReKi),           	                  INTENT(IN   )  :: dissip         ! 
  -  REAL(ReKi),           	                  INTENT(IN   )  :: ufluct         ! 
  -  TYPE(AA_ParameterType),                         INTENT(IN   )  :: p              ! Parameters
  -
  -  REAL(ReKi),DIMENSION(size(p%FreqList)),	  INTENT(  OUT)  :: SPLti         !
  -  INTEGER(IntKi),                   		  INTENT(  OUT)  :: errStat        ! Error status of the operation
  -  character(*),                                   INTENT(  OUT)  :: errMsg         ! Error message if ErrStat /= ErrID_None
  -  integer(intKi)                                                 :: ErrStat2       ! temporary Error status
  -  character(ErrMsgLen)                                           :: ErrMsg2        ! temporary Error message
  -  character(*), parameter                                        :: RoutineName = 'InflowNoise'
  -
  +  REAL(ReKi),                                 INTENT(IN   ) :: AlphaNoise        ! AOA
  +  REAL(ReKi),                                 INTENT(IN   ) :: Chord          ! Chord Length
  +  REAL(ReKi),                                 INTENT(IN   ) :: U              !
  +  REAL(ReKi),                                 INTENT(IN   ) :: d              ! element span
  +  REAL(ReKi),                                 INTENT(IN   ) :: RObs           ! distance to observer
  +  REAL(ReKi),                                 INTENT(IN   ) :: THETA          !
  +  REAL(ReKi),                                 INTENT(IN   ) :: PHI            ! Spanwise directivity angle
  +  REAL(ReKi),                                 INTENT(IN   ) :: MeanVNoise     !
  +  REAL(ReKi),                                 INTENT(IN   ) :: TINoise        !
  +  REAL(ReKi),                                 INTENT(IN   ) :: LE_Location    !
  +  REAL(ReKi),                                 INTENT(IN   ) :: dissip         !
  +  REAL(ReKi),                                 INTENT(IN   ) :: ufluct         !
  +  TYPE(AA_ParameterType),                     INTENT(IN   ) :: p              ! Parameters
  +  REAL(ReKi),DIMENSION(size(p%FreqList)),     INTENT(  OUT) :: SPLti         !
  +  INTEGER(IntKi),                             INTENT(  OUT) :: errStat        ! Error status of the operation
  +  character(*),                               INTENT(  OUT) :: errMsg         ! Error message if ErrStat /= ErrID_None
  +  integer(intKi)                                            :: ErrStat2       ! temporary Error status
  +  character(ErrMsgLen)                                      :: ErrMsg2        ! temporary Error message
  +  character(*), parameter                                   :: RoutineName = 'InflowNoise'
   ! local variables
     REAL(ReKi)                   :: Beta2                                           ! Prandtl-Glauert correction factor
     REAL(ReKi)                   :: DBARH                                           ! High-frequency directivity correction factor
  
positive.code: !          SPLti(i) = 10*log10(DBARH*Lturb*0.5*d*Mach**5*tinooisess**2*Kh**3*(1+Kh**2)**(-7/3)/RObs**2) +&
  !              10*log10(10**18.13) + 10*log10(DBARH*LFC/(1+LFC));   
  	ENDDO
  !
  
   
  !!Buck&Oerlamans&Palo - !Experimental validation of a wind turbine turbulent inflow noise prediction code 2016 paper
  	!DO I=1,size(p%FreqList)
          ! IF (p%FreqList(I) <= Frequency_cutoff) THEN
  
negative.code:   REAL(ReKi)                   :: SPLhigh                                         ! predicted high frequency sound pressure level
    REAL(ReKi)                   :: Ums                                             ! mean square turbulence level
    REAL(ReKi)                   :: WaveNumber                                      ! wave number - non-dimensional frequency
    REAL(ReKi)                   :: Kbar                                      ! nafnoise 
    REAL(ReKi)                   :: khat,Kh                                   ! nafnoise 
    REAL(ReKi)                   :: ke                                        ! nafnoise 
    REAL(ReKi)                   :: alpstar                                   ! nafnoise 
    REAL(ReKi)                   :: mu                                        ! nafnoise 
    REAL(ReKi)                   :: tinooisess                                ! nafnoise 
    REAL(ReKi)                   :: L_Gammas                                  ! nafnoise 
  
    INTEGER(intKi)    	       :: I        !I A generic index for DO loops.	
     ErrStat = ErrID_None
     ErrMsg  = ""
     !!!--- NAF NOISE IDENTICAL
     	Mach = U/p%SpdSound
  ! This part is recently added for height and surface roughness dependent estimation of turbulence intensity and turbulence scales
  	!%Lturb=300*(Z/300)^(0.46+0.074*log(p%z0_aa));      	        !% Gives larger  length scale
  	Lturb=25.d0*LE_Location**(0.35)*p%z0_aa**(-0.063)               !% Gives smaller length scale
  	L_Gammas=0.24+0.096*log10(p%z0_aa)+0.016*(log10(p%z0_aa))**2;   !% Can be computed or just give it a value.
  