      Subroutine Engset(hbonde, hbond, energy, donres, accres, bndct)   ENGS001
c                                                                       ENGS002
c     find a place to put this h-bond. discard third bonds if necessary ENGS003
c                                                                       ENGS004
      Include 'sstruc.par'                                              ENGS005
      real    hbonde(maxbnd,maxres), energy                             ENGS006
      integer hbond(maxbnd,maxres), donres, accres, bndct               ENGS007
                                                                        ENGS008
      integer acpl, donpl, rejptr                                       ENGS009
      integer engpl                                                     ENGS010
                                                                        ENGS011
      donpl = engpl(energy,hbonde(nst,donres))                          ENGS012
      acpl = engpl(energy,hbonde(cst,accres))                           ENGS013
      If (acpl .eq. 0 .or. donpl .eq. 0) then                           ENGS014
         write(errfi,400) donres, accres, energy                        ENGS015
  400    format('third (+) Hbond (N-C) ',I4,2x,i4,                      ENGS016
     &                          ' energy ',f6.2,' abandoned')           ENGS017
      else                                                              ENGS018
         if (hbond(nst+1,donres) .ne. 0) then                           ENGS019
            write(errfi,400) donres, hbond(nst+1,donres),               ENGS020
     &                    hbonde(nst+1,donres)                          ENGS021
            rejptr = hbond(nst+1,donres)                                ENGS022
            call rejbnd(donres,hbond(cst,rejptr),hbonde(cst,rejptr))    ENGS023
            bndct = bndct - 1                                           ENGS024
         end if                                                         ENGS025
         if (hbond(cst+1,accres) .ne. 0) then                           ENGS026
            write(errfi,400) hbond(cst+1,accres), accres,               ENGS027
     &                    hbonde(cst+1,accres)                          ENGS028
            rejptr = hbond(cst+1,accres)                                ENGS029
            call rejbnd(accres,hbond(nst,rejptr),hbonde(nst,rejptr))    ENGS030
            bndct = bndct - 1                                           ENGS031
         end if                                                         ENGS032
         If (acpl .eq. 1) then                                          ENGS033
            hbond(cst+1,accres) = hbond(cst,accres)                     ENGS034
            hbonde(cst+1,accres) = hbonde(cst,accres)                   ENGS035
         end if                                                         ENGS036
         If (donpl .eq. 1) then                                         ENGS037
            hbond(nst+1,donres) = hbond(nst,donres)                     ENGS038
            hbonde(nst+1,donres) = hbonde(nst,donres)                   ENGS039
         end if                                                         ENGS040
         hbond(cst+acpl-1,accres) = donres                              ENGS041
         hbonde(cst+acpl-1,accres) = energy                             ENGS042
         hbond(nst+donpl-1,donres) = accres                             ENGS043
         hbonde(nst+donpl-1,donres) = energy                            ENGS044
         bndct = bndct + 1                                              ENGS045
      end if                                                            ENGS046
      END                                                               ENGS047
