anchor.diff:           ! Now we need to figure out if the zero frequency was given in the file.  If so, we change NumWvFreq1 to
            ! NumWvFreq1+2.  If not, change to NumWvFreq1+4.  We will add on the inifinite frequency value and 
            ! zero out all values not in the input frequency range. The inifinite frequency value will be set to HUGE
  -         ! and we'll add/subtract epsilon to the non-zero frequencies entered so that we can achieve a step 
  +         ! and we'll add/subtract epsilon to the first non-zero frequency entered so that we can achieve a step 
            ! change for zeroing the values outside the input frequency range.
         IF (HaveZeroFreq1) THEN
            Data4D%NumWvFreq1 = Data4D%NumWvFreq1+2
  +         WvFreq1LoIdx   = 1
         ELSE
            Data4D%NumWvFreq1 = Data4D%NumWvFreq1+4
  -      ENDIF
  -      
  -         ! Do the same for NumWvFreq2 as we did for NumWvFreq1
  +         WvFreq1LoIdx   = 3
  +      ENDIF
  +
  +         ! Set the index for the highest frequency stored before the cutoff
  +      WvFreq1HiIdx   =  Data4D%NumWvFreq1-2
  +
  +
  +         ! Do the same for NumWvFreq2 as we did for NumWvFreq2
         IF (HaveZeroFreq2) THEN
            Data4D%NumWvFreq2 = Data4D%NumWvFreq2+2
  +         WvFreq2LoIdx   = 1
         ELSE
            Data4D%NumWvFreq2 = Data4D%NumWvFreq2+4
  -      ENDIF
  +         WvFreq2LoIdx   = 3
  +      ENDIF
  +
  +         ! Set the index for the highest frequency stored before the cutoff
  +      WvFreq2HiIdx   =  Data4D%NumWvFreq2-2
  +
   
            ! Now allocate the array for holding the WvFreq1
         ALLOCATE( Data4D%WvFreq1( Data4D%NumWvFreq1), STAT=ErrStatTmp)
  
positive.code:       ENDDO
  
           ! Now change the negative values to be 0.0
        DO I=1,NumDataLines
           IF ( RawData4D(I,1) < 0.0_ReKi ) THEN
              RawData4D(I,1) = 0.0_ReKi
              HaveZeroFreq1 = .TRUE.
  
negative.code:             CLOSE( UnitDataFile )
              IF (ALLOCATED(TmpRealArr))       DEALLOCATE(TmpRealArr,STAT=ErrStatTmp)
              IF (ALLOCATED(RawData3D))        DEALLOCATE(RawData3D,STAT=ErrStatTmp)
              IF (ALLOCATED(RawData3DTmp))     DEALLOCATE(RawData3DTmp,STAT=ErrStatTmp)
              IF (ALLOCATED(TmpDataRow))       DEALLOCATE(TmpDataRow,STAT=ErrStatTmp)
              IF (ALLOCATED(TmpWvFreq1))       DEALLOCATE(TmpWvFreq1,STAT=ErrStatTmp)
              CALL CleanUp
              RETURN
           ENDIF
           RawData3DTmp(I,:) = TmpDataRow
        ENDDO
  
        CLOSE( UnitDataFile )
  
  
           !> Before continuing, we need to figure out how many actual lines of data we will
           !! be keeping (lines where the force component index is positive).  The force component
           !! is in column 4 for 3D data read in.  First find out if there are negative force
           !! components, then count the number of data rows we are keeping.  Then copy data over.
        IF ( MINVAL(RawData3DTmp(:,4)) < 0_IntKi ) THEN             ! check the 4th element (force component)
           CALL SetErrStat( ErrID_Warn,' Negative load components found (moving reference frame). Ignoring', &
                 ErrStat,ErrMsg,'Read_DataFile3D')
  
              ! Count how many lines we are keeping.
           NumDataLinesKeep = 0_IntKi
           DO I=1,NumDataLines
              IF ( RawData3DTmp(I,4) > 0 ) THEN
                 NumDataLinesKeep = NumDataLinesKeep + 1
              ENDIF
           ENDDO
  
              ! Allocate an array to hold the data from the file that we are keeping
           CALL AllocAry( RawData3D, NumDataLinesKeep, NumDataColumns, ' Array for holding raw 3D data for 2nd order WAMIT files', ErrStatTmp, ErrMsgTmp )
           CALL SetErrStat( ErrStatTmp, ErrMsgTmp, ErrStat, ErrMsg, 'Read_DataFile3D')
           IF ( ErrStat >= AbortErrLev ) THEN
              CLOSE( UnitDataFile )
              IF (ALLOCATED(TmpRealArr))       DEALLOCATE(TmpRealArr,STAT=ErrStatTmp)
              IF (ALLOCATED(RawData3D))        DEALLOCATE(RawData3D,STAT=ErrStatTmp)
              IF (ALLOCATED(RawData3DTmp))     DEALLOCATE(RawData3DTmp,STAT=ErrStatTmp)
              IF (ALLOCATED(TmpDataRow))       DEALLOCATE(TmpDataRow,STAT=ErrStatTmp)
              IF (ALLOCATED(TmpWvFreq1))       DEALLOCATE(TmpWvFreq1,STAT=ErrStatTmp)
              CALL CleanUp
              RETURN
           ENDIF
  
              ! Now copy over the data that we are keeping. Ignore the rest
           NumDataLinesKeep = 0_IntKi
           DO I=1,NumDataLines
              IF ( RawData3DTmp(I,4) > 0 ) THEN
                 NumDataLinesKeep = NumDataLinesKeep + 1
                 RawData3D( NumDataLinesKeep, : ) = RawData3DTmp(I,:)
              ENDIF
           ENDDO
  
              ! We no longer need the raw data from the file.
           IF (ALLOCATED(RawData3DTmp))     DEALLOCATE(RawData3DTmp,STAT=ErrStatTmp)
  
           ! no negative force components, so just move the array.
        ELSE
           CALL MOVE_ALLOC( RawData3DTmp, RawData3D )
           NumDataLinesKeep = NumDataLines
        ENDIF
  
  
           !> Before proceeding further, we are going to change the wave period from measured
  