anchor.diff:               CALL Catenary ( XF           , ZF          , Line%UnstrLen, LineProp%EA  , &
                                WetWeight    , SeabedCD,    TenTol,     (N+1)     , &
                                LSNodes, LNodesX, LNodesZ , ErrStat2, ErrMsg2)
  -
   
         IF (ErrStat2 == ErrID_None) THEN ! if it worked, use it
             ! Transform the positions of each node on the current line from the local
  
positive.code:       TYPE(MD_InputType)    :: uArray(1)    ! a size-one array for u to make call to TimeStep happy
        REAL(DbKi)            :: utimes(1)    ! a size-one array saying time is 0 to make call to TimeStep happy  
  
  
  
  
        ErrStat = ErrID_None
  
negative.code:          ZF     = REAL( ZF_In    , DbKi )
  
  
           
        !  HF and VF cannot be initialized to zero when a  portion of the line rests on the seabed and the anchor tension is nonzero
           
        ! Generate the initial guess values for the horizontal and vertical tensions
        !   at the fairlead in the Newton-Raphson iteration for the catenary mooring
        !   line solution.  Use starting values documented in: Peyrot, Alain H. and
        !   Goulois, A. M., "Analysis Of Cable Structures," Computers & Structures,
        !   Vol. 10, 1979, pp. 805-813:
           XF2     = XF*XF
           ZF2     = ZF*ZF
  
           IF     ( XF           == 0.0_DbKi    )  THEN ! .TRUE. if the current mooring line is exactly vertical
              Lamda0 = 1.0D+06
           ELSEIF ( L <= SQRT( XF2 + ZF2 ) )  THEN ! .TRUE. if the current mooring line is taut
              Lamda0 = 0.2_DbKi
           ELSE                                    ! The current mooring line must be slack and not vertical
              Lamda0 = SQRT( 3.0_DbKi*( ( L**2 - ZF2 )/XF2 - 1.0_DbKi ) )
           ENDIF
  
           HF = ABS( 0.5_DbKi*W*  XF/     Lamda0      )
           VF =      0.5_DbKi*W*( ZF/TANH(Lamda0) + L )         
                                      
  
              ! Abort when there is no solution or when the only possible solution is
              !   illogical:
  
           IF (    Tol <= EPSILON(TOL) )  THEN   ! .TRUE. when the convergence tolerance is specified incorrectly
             ErrStat = ErrID_Warn
             ErrMsg = ' Convergence tolerance must be greater than zero in routine Catenary().'
             return
           ELSEIF ( XF <  0.0_DbKi )  THEN   ! .TRUE. only when the local coordinate system is not computed correctly
             ErrStat = ErrID_Warn
             ErrMsg =  ' The horizontal distance between an anchor and its'// &
                           ' fairlead must not be less than zero in routine Catenary().'
             return
  
           ELSEIF ( ZF <  0.0_DbKi )  THEN   ! .TRUE. if the fairlead has passed below its anchor
             ErrStat = ErrID_Warn
             ErrMsg =  ' A fairlead has passed below its anchor.'
             return
  
           ELSEIF ( L  <= 0.0_DbKi )  THEN   ! .TRUE. when the unstretched line length is specified incorrectly
             ErrStat = ErrID_Warn
             ErrMsg =  ' Unstretched length of line must be greater than zero in routine Catenary().'
             return
  
           ELSEIF ( EA <= 0.0_DbKi )  THEN   ! .TRUE. when the unstretched line length is specified incorrectly
             ErrStat = ErrID_Warn
             ErrMsg =  ' Extensional stiffness of line must be greater than zero in routine Catenary().'
             return
  
           ELSEIF ( W  == 0.0_DbKi )  THEN   ! .TRUE. when the weight of the line in fluid is zero so that catenary solution is ill-conditioned
             ErrStat = ErrID_Warn
             ErrMsg = ' The weight of the line in fluid must not be zero. '// &
                           ' Routine Catenary() cannot solve quasi-static mooring line solution.'
             return
  
  
           ELSEIF ( W  >  0.0_DbKi )  THEN   ! .TRUE. when the line will sink in fluid
  
              LMax      = XF - EA/W + SQRT( (EA/W)*(EA/W) + 2.0_DbKi*ZF*EA/W )  ! Compute the maximum stretched length of the line with seabed interaction beyond which the line would have to double-back on itself; here the line forms an "L" between the anchor and fairlead (i.e. it is horizontal along the seabed from the anchor, then vertical to the fairlead)
  
              IF ( ( L  >=  LMax   ) .AND. ( CB >= 0.0_DbKi ) )  then  ! .TRUE. if the line is as long or longer than its maximum possible value with seabed interaction
                 ErrStat = ErrID_Warn
                 ErrMsg =  ' Unstretched mooring line length too large. '// &
                              ' Routine Catenary() cannot solve quasi-static mooring line solution.'
                 return
              END IF
  
           ENDIF
  
  