<commit_before>!>  This module uses full-field binary wind files to determine the wind inflow.
!!  This module assumes that the origin, (0,0,0), is located at the tower centerline at ground level,
!!  and that all units are specified in the metric system (using meters and seconds).
!!  Data is assumed periodic in the X direction (and thus not shifted like FFWind files are).
MODULE IfW_HAWCWind
!!
!!  Created 25-June-2010 by <NAME>, National Renewable Energy Laboratory
!!     using subroutines and modules from AeroDyn v12.58
!!
!!----------------------------------------------------------------------------------------------------
!! Updated 8-Aug-2015 for InflowWind v3.0 in the FAST v8 Framework
!
!**********************************************************************************************************************************
! LICENSING
! Copyright (C) 2015-2016  National Renewable Energy Laboratory
!
!    This file is part of InflowWind.
!
! Licensed under the Apache License, Version 2.0 (the "License");
! you may not use this file except in compliance with the License.
! You may obtain a copy of the License at
!
!     http://www.apache.org/licenses/LICENSE-2.0
!
! Unless required by applicable law or agreed to in writing, software
! distributed under the License is distributed on an "AS IS" BASIS,
! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
! See the License for the specific language governing permissions and
! limitations under the License.
!
!**********************************************************************************************************************************
   USE                                          NWTC_Library
   USE                                          IfW_HAWCWind_Types

   IMPLICIT                                     NONE
   PRIVATE

   TYPE(ProgDesc),   PARAMETER               :: IfW_HAWCWind_Ver = ProgDesc( 'IfW_HAWCWind', '', '' )

   PUBLIC                                    :: IfW_HAWCWind_Init
   PUBLIC                                    :: IfW_HAWCWind_End
   PUBLIC                                    :: IfW_HAWCWind_CalcOutput

   INTEGER(IntKi), PARAMETER  :: nc = 3                           !< number of wind components
   INTEGER(IntKi), PARAMETER  :: WindProfileType_Constant = 0     !< constant wind
   INTEGER(IntKi), PARAMETER  :: WindProfileType_Log      = 1     !< logarithmic
   INTEGER(IntKi), PARAMETER  :: WindProfileType_PL       = 2     !< power law

   INTEGER(IntKi), PARAMETER  :: ScaleMethod_None         = 0     !< no scaling
   INTEGER(IntKi), PARAMETER  :: ScaleMethod_Direct       = 1     !< direct scaling factors
   INTEGER(IntKi), PARAMETER  :: ScaleMethod_StdDev       = 2     !< requested standard deviation
   
CONTAINS
!====================================================================================================
!>  This routine is used to initialize the parameters for using HAWC wind format files.
SUBROUTINE IfW_HAWCWind_Init(InitInp, p, MiscVars, Interval, InitOut, ErrStat, ErrMsg)

      ! Passed Variables
   TYPE(IfW_HAWCWind_InitInputType),         INTENT(IN   )  :: InitInp           !< Initialization data passed to the module
   TYPE(IfW_HAWCWind_ParameterType),         INTENT(  OUT)  :: p                 !< Parameters
   TYPE(IfW_HAWCWind_MiscVarType),           INTENT(  OUT)  :: MiscVars          !< Misc variables for optimization (not copied in glue code)
   TYPE(IfW_HAWCWind_InitOutputType),        INTENT(  OUT)  :: InitOut           !< Initialization output

   REAL(DbKi),                               INTENT(IN   )  :: Interval          !< Time Interval to use (passed through here)


      ! Error Handling
   INTEGER(IntKi),                           INTENT(  OUT)  :: ErrStat           !< determines if an error has been encountered
   CHARACTER(*),                             INTENT(  OUT)  :: ErrMsg            !< Message about errors


      ! Temporary variables for error handling
   INTEGER(IntKi)                                           :: TmpErrStat        ! temporary error status
   CHARACTER(ErrMsgLen)                                     :: TmpErrMsg         ! temporary error message
   CHARACTER(*),                             PARAMETER      :: RoutineName = 'IfW_HAWCWind_Init'

      ! Local Variables:



   ErrStat = ErrID_None
   ErrMsg  = ""

   ! validate init input data:
   call ValidateInput(InitInp, TmpErrStat, TmpErrMsg)
      CALL SetErrStat(TmpErrStat, TmpErrMsg, ErrStat, ErrMsg, RoutineName) 
      IF (ErrStat >= AbortErrLev) RETURN
  
      
   !-------------------------------------------------------------------------------------------------
   ! Set some internal module parameters based on input file values
   !-------------------------------------------------------------------------------------------------
   p%nx           = InitInp%nx   
   p%ny           = InitInp%ny   
   p%nz           = InitInp%nz   
   p%RefHt        = InitInp%RefHt
   p%URef         = InitInp%URef
   p%InitPosition = 0.0_ReKi  ! bjj: someday we may want to let the users give an offset time/position

   p%deltaXInv   = 1.0 / InitInp%dx
   p%deltaYInv   = 1.0 / InitInp%dy
   p%deltaZInv   = 1.0 / InitInp%dz
     
   
   p%LengthX     = InitInp%dx * p%nx !(nx-1)   !because the turbulence box is periodic in the X direction, we need to consider the length between point 1 and the next point 1 (instead of between points 1 and nx)
   p%LengthYHalf = 0.5*InitInp%dy * (p%ny-1)
   p%GridBase    = p%RefHt - 0.5*(p%nz-1)*InitInp%dz

   IF ( p%GridBase < 0.0_ReKi ) THEN
      call SetErrStat( ErrID_Fatal, 'The bottom of the grid is located at a height of '//&
                      TRIM( Num2LStr(p%GridBase) )//' meters, which is below the ground.', ErrStat,ErrMsg, RoutineName)
      RETURN
   END IF
   

   !-------------------------------------------------------------------------------------------------
   ! Read data files:<commit_msg>Shifted HAWC wind boxes by delta x for consistency<commit_after>!>  This module uses full-field binary wind files to determine the wind inflow.
!!  This module assumes that the origin, (0,0,0), is located at the tower centerline at ground level,
!!  and that all units are specified in the metric system (using meters and seconds).
!!  Data is assumed periodic in the X direction (and thus not shifted like FFWind files are).
MODULE IfW_HAWCWind
!!
!!  Created 25-June-2010 by <NAME>, National Renewable Energy Laboratory
!!     using subroutines and modules from AeroDyn v12.58
!!
!!----------------------------------------------------------------------------------------------------
!! Updated 8-Aug-2015 for InflowWind v3.0 in the FAST v8 Framework
!
!**********************************************************************************************************************************
! LICENSING
! Copyright (C) 2015-2016  National Renewable Energy Laboratory
!
!    This file is part of InflowWind.
!
! Licensed under the Apache License, Version 2.0 (the "License");
! you may not use this file except in compliance with the License.
! You may obtain a copy of the License at
!
!     http://www.apache.org/licenses/LICENSE-2.0
!
! Unless required by applicable law or agreed to in writing, software
! distributed under the License is distributed on an "AS IS" BASIS,
! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
! See the License for the specific language governing permissions and
! limitations under the License.
!
!**********************************************************************************************************************************
   USE                                          NWTC_Library
   USE                                          IfW_HAWCWind_Types

   IMPLICIT                                     NONE
   PRIVATE

   TYPE(ProgDesc),   PARAMETER               :: IfW_HAWCWind_Ver = ProgDesc( 'IfW_HAWCWind', '', '' )

   PUBLIC                                    :: IfW_HAWCWind_Init
   PUBLIC                                    :: IfW_HAWCWind_End
   PUBLIC                                    :: IfW_HAWCWind_CalcOutput

   INTEGER(IntKi), PARAMETER  :: nc = 3                           !< number of wind components
   INTEGER(IntKi), PARAMETER  :: WindProfileType_Constant = 0     !< constant wind
   INTEGER(IntKi), PARAMETER  :: WindProfileType_Log      = 1     !< logarithmic
   INTEGER(IntKi), PARAMETER  :: WindProfileType_PL       = 2     !< power law

   INTEGER(IntKi), PARAMETER  :: ScaleMethod_None         = 0     !< no scaling
   INTEGER(IntKi), PARAMETER  :: ScaleMethod_Direct       = 1     !< direct scaling factors
   INTEGER(IntKi), PARAMETER  :: ScaleMethod_StdDev       = 2     !< requested standard deviation
   
CONTAINS
!====================================================================================================
!>  This routine is used to initialize the parameters for using HAWC wind format files.
SUBROUTINE IfW_HAWCWind_Init(InitInp, p, MiscVars, Interval, InitOut, ErrStat, ErrMsg)

      ! Passed Variables
   TYPE(IfW_HAWCWind_InitInputType),         INTENT(IN   )  :: InitInp           !< Initialization data passed to the module
   TYPE(IfW_HAWCWind_ParameterType),         INTENT(  OUT)  :: p                 !< Parameters
   TYPE(IfW_HAWCWind_MiscVarType),           INTENT(  OUT)  :: MiscVars          !< Misc variables for optimization (not copied in glue code)
   TYPE(IfW_HAWCWind_InitOutputType),        INTENT(  OUT)  :: InitOut           !< Initialization output

   REAL(DbKi),                               INTENT(IN   )  :: Interval          !< Time Interval to use (passed through here)


      ! Error Handling
   INTEGER(IntKi),                           INTENT(  OUT)  :: ErrStat           !< determines if an error has been encountered
   CHARACTER(*),                             INTENT(  OUT)  :: ErrMsg            !< Message about errors


      ! Temporary variables for error handling
   INTEGER(IntKi)                                           :: TmpErrStat        ! temporary error status
   CHARACTER(ErrMsgLen)                                     :: TmpErrMsg         ! temporary error message
   CHARACTER(*),                             PARAMETER      :: RoutineName = 'IfW_HAWCWind_Init'

      ! Local Variables:



   ErrStat = ErrID_None
   ErrMsg  = ""

   ! validate init input data:
   call ValidateInput(InitInp, TmpErrStat, TmpErrMsg)
      CALL SetErrStat(TmpErrStat, TmpErrMsg, ErrStat, ErrMsg, RoutineName) 
      IF (ErrStat >= AbortErrLev) RETURN
  
      
   !-------------------------------------------------------------------------------------------------
   ! Set some internal module parameters based on input file values
   !-------------------------------------------------------------------------------------------------
   p%nx           = InitInp%nx   
   p%ny           = InitInp%ny   
   p%nz           = InitInp%nz   
   p%RefHt        = InitInp%RefHt
   p%URef         = InitInp%URef
   p%InitPosition = 0.0_ReKi  ! bjj: someday we may want to let the users give an offset time/position
   p%InitPosition(1) = InitInp%dx

   p%deltaXInv   = 1.0 / InitInp%dx
   p%deltaYInv   = 1.0 / InitInp%dy
   p%deltaZInv   = 1.0 / InitInp%dz
     
   
   p%LengthX     = InitInp%dx * p%nx !(nx-1)   !because the turbulence box is periodic in the X direction, we need to consider the length between point 1 and the next point 1 (instead of between points 1 and nx)
   p%LengthYHalf = 0.5*InitInp%dy * (p%ny-1)
   p%GridBase    = p%RefHt - 0.5*(p%nz-1)*InitInp%dz

   IF ( p%GridBase < 0.0_ReKi ) THEN
      call SetErrStat( ErrID_Fatal, 'The bottom of the grid is located at a height of '//&
                      TRIM( Num2LStr(p%GridBase) )//' meters, which is below the ground.', ErrStat,ErrMsg, RoutineName)
      RETURN
   END IF
   

   !-------------------------------------------------------------------------------------------------
   ! Read data files:
{'fraction_non_alphanumeric': 0.19323792786007196, 'fraction_numerical': 0.010293748430831032, 'mean_word_length': 1.8941632356502784, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2003084', 'n_tokens_mistral': 3350, 'n_tokens_neox': 3081, 'n_words': 989}