Public Class CHeating

    Dim Q_w_ce As Decimal, Q_w_b As Decimal, theta_NA_Grenz As Decimal, theta_WA_Grenz As Decimal, Q_w_d_i As Decimal, t_h As Decimal
    Dim L_G As Decimal, B_G As Decimal, n_G As Decimal, h_G As Decimal, V_s As Decimal, f_verbindung As Decimal, q_B_S As Decimal, Q_dot_N As Decimal, theta_g_m As Decimal
    Dim theta_i As Integer, t_Nutz_d As Integer, d_Nutz_a As Integer
    Dim eta_k_100 As Decimal, Q_w_g_100 As Decimal, Q_w_outg_i As Decimal, q_B_theta As Decimal, Q_B_w As Decimal, Q_w_g As Decimal, d_h_rB As Decimal
    Dim theta_e_min As Decimal, f_L_WA As Decimal
    Dim Q_w_ce_aux As Decimal, Q_w_d_aux As Decimal, Q_w_g_aux As Decimal, P_Pump_w As Decimal, c_p1 As Decimal, c_p2 As Decimal, t_P As Decimal, P_aux_100 As Decimal
    Dim Q_w_s_aux As Decimal, d_Nutz_mth As Integer, Q_w_s As Decimal, Q_w_d As Decimal, L_i As Decimal, Q_w_outg As Decimal
    Dim f_Hs_Hi As Decimal, t_w_100 As Decimal, q_B_70 As Decimal, Q_w_f As Decimal, Q_w_aux As Decimal, Q_w_g_i As Decimal
    Dim use_Oil As Decimal, use_LNG As Decimal, use_LPG As Decimal, use_Elec As Decimal, use_DH As Decimal
    'Dim i_count_renewable As Integer
    Dim Q_h_outg_i As Decimal
    Dim Q_W_sol_out_m As Decimal, Q_H_sol_out_m As Decimal, W_sol_aux_m As Decimal, W_sol_aux As Decimal
    Dim system_type As Integer

    Dim Q_dot_HP_waterheating As Decimal, COP_HP_7 As Decimal, COP_HP_10 As Decimal, L_HP_waterheating As Decimal
    Dim COP_HP_total As Decimal

    Dim D_DS As Decimal, B_DS As Decimal, theta_prim_DS As Decimal, theta_DS As Decimal, Psi_DS As Decimal, H_DS As Decimal


    '==================================2010.2.21 수정
    Dim d_op_mth As Integer
    Dim d_op_max_mth As Integer

    '==================================2010.2.21 수정

    Dim Q_w_CHP As Decimal, Q_w_f_CHP As Decimal '==============2011.07.19 추가
    Dim Q_wp_outg As Decimal, Q_w_f_hp As Decimal, Q_w_g_hp_aux As Decimal '==================================2013.01.13 추가

    '==================================2013.08.18 추가
    Dim system_count As Decimal

    Dim a_Q_w_b As Decimal = 0
    Dim a_d_op_max_mth As Decimal = 0
    Dim a_t_h As Decimal = 0

    Public Overridable Sub Calc_WaterheatingSystem(ByVal i_count_month As Integer, ByVal d_mth As Integer, ByVal theta_e As Decimal)

        pLog.Add("================================")
        pLog.Add(String.Format(" Enter >> Calc_WaterheatingSystem Mon={0},d_mth={1},theta_e={2}", i_count_month, d_mth, theta_e))
        pLog.Add("================================")
        d_op_max_mth = 0

        Q_w_ce = 0 '급탕에서는 공급손실이 없음
        theta_NA_Grenz = 10
        theta_WA_Grenz = 10
        theta_e_min = -11.3
        f_verbindung = 1.2 '동일공간의 경우임, 타공간의 경우 (3.2.7-36) 참조
        theta_i = 22 '2011.04.01 수정 기존 13에서 주변온도를 22도로 수정(급탕에 대한 설정조건 완화)
        t_Nutz_d = 11 '2011.04.01 수정 기존 24에서 운영시간를 11로 수정(급탕에 대한 설정조건 완화)
        Q_w_g_100 = 0
        d_Nutz_a = 365
        Q_w_g = 0
        Q_w_g_aux = 0
        Q_w_d_aux = 0
        Q_w_s_aux = 0
        Q_w_ce_aux = 0
        use_Oil = 0
        use_LNG = 0
        use_LPG = 0
        use_Elec = 0
        use_DH = 0
        Q_w_outg = 0
        Q_h_outg_i = 0
        W_sol_aux = 0
        system_type = 3
        '====================================2011.07.21 추가
        Q_w_CHP = 0
        Q_w_f_CHP = 0
        '====================================2011.07.21 추가

        '======================2013.01.13 추가
        system_count = 1
        '======================2013.01.13 추가

        '======================2013.08.18 추가
        Q_w_f_hp = 0
        Q_wp_outg = 0
        Q_w_g_hp_aux = 0
        '======================2013.08.18 추가

        '//각달별로데이터를 초기화해야함(131020-arin)
        Q_w_f = 0
        Q_w_aux = 0
        use_Oil = 0
        use_LNG = 0
        use_LPG = 0
        use_DH = 0
        use_Elec = 0

        a_Q_w_b = 0
        a_d_op_max_mth = 0
        a_t_h = 0

        '====================================2010.2.21 수정
        'd_Nutz_mth = d_mth ' 연중가동으로 계산 추후 검토
        '====================================2010.2.21 수정

        Dim Mon As String = "M" & Format(i_count_month, "00")

        '태양광 시스템
        Dim Calc_태양 As New CRenewable(DSET, Result) : Calc_태양.Calc_PhotovoltaicSystem_EN(i_count_month, d_mth)


        Dim 급탕용량합 As Decimal = 0
        For Each Dr난방 As DS.tbl_nanbangkikiRow In DSET.tbl_nanbangkiki.Select("code<>'0' and 헤더적용=true", "code")

            pLog.Add(String.Format("Loop 난방기기 code={0},급탕용량합={1}", Dr난방.code, 급탕용량합))

            If DSET.tbl_zone.Select("열생산급탕생산기기='" & Dr난방.code & "' and code <> '0'").GetUpperBound(0) <> -1 Then '//급탕생산기기로 지정되어있는가            '//존에서 이 난방기기가 사용되었는가?             ' Worksheets("난방기기").Range("난방생산기기1").Offset(5, i_count_boiler - 1) = "예" Then  
                pLog.Add(String.Format("급탕기기로 사용됨 기기방식={0}", Dr난방.열생산기기방식))
                Select Case Dr난방.열생산기기방식.Trim.ToUpper
                    Case "보일러"
                        급탕용량합 += TOSG(Dr난방.보일러정격출력)
                    Case "지역난방"
                        급탕용량합 += TOSG(Dr난방.열교환기정격출력)
                    Case "히트펌프"
                        급탕용량합 += TOSG(Dr난방.히트난방용량)
                    Case "전기보일러"
                        급탕용량합 += TOSG(Dr난방.보일러정격출력)
                End Select
                pLog.Add(String.Format("급탕용량합 값={0}", 급탕용량합))
            End If

            For Each Dr존 As DS.tbl_zoneRow In DSET.tbl_zone.Select("열생산급탕생산기기='" & Dr난방.code & "' and code <> '0'", "code")

                pLog.Add(String.Format("Process Zone = {0},난방기기={1}", Dr존.code, Dr난방.code))

                Dim Drow결과() As DSR.월별에너지분석Row = CType(DSETR.월별에너지분석.Select("월='" & Mon & "' and 존='" & Dr존.code & "'"), DSR.월별에너지분석Row())
                Dim Drow최대() As DSR.최대냉난방부하Row = CType(DSETR.최대냉난방부하.Select("Zone='" & Dr존.code & "'"), DSR.최대냉난방부하Row())
                a_Q_w_b += (TOSG(Drow결과(0).급탕요구량) / system_count) ' Sheets("" & i_count_month & "").Cells(15, 7 + i_count_zone) '//급탕에너지요구량

                '===================================================================================2010.2.21 수정
                Dim a_d_op_mth As Decimal = 0
                Dim Dr프로필() As DS.tbl_profileRow = CType(DSET.tbl_profile.Select("code='" & Dr존.프로필 & "' and code <> '0'", "code"), DS.tbl_profileRow())
                If Dr프로필.GetUpperBound(0) = -1 Then
                    LogSB.AppendLine(Dr존.설명 & "존의 프로필코드(" & Dr존.프로필 & ") 가 존재하지않습니다")
                    'MsgBox(Dr존.설명 & "존의 프로필코드(" & Dr존.프로필 & ") 가 존재하지않습니다")
                Else
                    a_d_op_mth = CInt(TOSG(Dr프로필(0)("day" & Format(i_count_month, "00")))) ' Worksheets("설정조건").Range("월간사용일수1").Offset(i_count_month, i_count_profile)
                End If

                If a_t_h < Result.최대부하.Item(Dr존.code).일일난방최대가동시간 * d_op_mth Then
                    a_t_h = Result.최대부하.Item(Dr존.code).일일난방최대가동시간 * d_op_mth
                End If

                If a_d_op_max_mth < a_d_op_mth Then a_d_op_max_mth = a_d_op_mth

                pLog.Add(String.Format("a_Q_w_b={0},a_d_op_mth={1},a_t_h={2},a_d_op_max_mth={3}", a_Q_w_b, a_d_op_mth, a_t_h, a_d_op_max_mth))
            Next
        Next

        For Each Dr난방 As DS.tbl_nanbangkikiRow In DSET.tbl_nanbangkiki.Select("code<>'0'", "code")

            pLog.Add(String.Format("Process 난방기기 Code={0}", Dr난방.code))

            '=====================2010.2.21 수정
            d_op_max_mth = 0
            '=====================2010.2.21 수정

            Dim 비율 As Decimal
            If 급탕용량합 = 0 Then
                비율 = 1
            Else

                '===================================================================================2014.02.24 추가
                Select Case Dr난방.열생산기기방식.Trim.ToUpper
                    Case "보일러"
                        비율 = Dr난방.보일러정격출력 / 급탕용량합
                    Case "지역난방"
                        비율 = Dr난방.열교환기정격출력 / 급탕용량합
                    Case "히트펌프"
                        비율 = Dr난방.히트난방용량 / 급탕용량합
                    Case "전기보일러"
                        비율 = Dr난방.보일러정격출력 / 급탕용량합
                End Select

                '===================================================================================2014.02.24 추가

            End If

            pLog.Add(String.Format("비율 = {0}", 비율))

            If Dr난방.개별기기적용 = "1" Then
                pLog.Add("개별기기적용로직 실행")
                Calc_급탕_개별기기적용시(Dr난방, Mon, 비율, i_count_month, theta_e, d_mth)
            Else
                pLog.Add("개별기기(미)적용로직 실행")
                Calc_급탕_개별기기미적용시(Dr난방, Mon, 비율, i_count_month, theta_e, d_mth)
            End If
        Next


        Q_w_f = Q_w_f + Q_w_outg + Q_w_g ' - Q_w_reg '(3.2.9-5) 급탕에너지소요량
        'Q_w_aux = Q_w_ce_aux + Q_w_d_aux + Q_w_s_aux + Q_w_g_aux + W_sol_aux '급탕보조에너지소요량 (3.2.9-7)

        Result.E소요량(i_count_month).급탕 = Q_w_f
        Result.E소요량(i_count_month).급탕보조 = Q_w_aux

        '//열원별에너지소요량 - 급탕에너지소요량
        Result.일차E소요량(i_count_month).급탕등유 = use_Oil

        Result.일차E소요량(i_count_month).급탕LNG = use_LNG
        Result.일차E소요량(i_count_month).급탕LPG = use_LPG
        Result.일차E소요량(i_count_month).급탕지역 = use_DH
        Result.일차E소요량(i_count_month).급탕전력 = use_Elec

        pLog.Add(String.Format("급탕={0},급탕보조={1},급탕등유={2},급탕LNG={3},급탕LPG={4},급탕지역={5},급탕전력={6}", Q_w_f, Q_w_aux, use_Oil, use_LNG, use_LPG, use_DH, use_Elec))
    End Sub

    Private Sub Calc_급탕_개별기기미적용시(dr난방 As DS.tbl_nanbangkikiRow, Mon As String, 비율 As Decimal, i_count_month As Integer, theta_e As Decimal, d_mth As Integer)

        pLog.Add(String.Format(">> Calc_급탕_개별기기미적용시(난방기기={0},Mon={1},비율={2},i_count_month={3},theta_e={4},d_mth={5}", _
                               dr난방.code, Mon, 비율, i_count_month, theta_e, d_mth))

        Dim 적용기기목록() As DS.tbl_zoneRow = DSET.tbl_zone.Select("열생산급탕생산기기='" & dr난방.code & "' and code <> '0'", "code")
        pLog.Add(String.Format("급탕기기로적용된 갯수={0}", 적용기기목록.Length))

        If 적용기기목록.Length > 0 Then '//급탕생산기기로 지정되어있는가            '//존에서 이 난방기기가 사용되었는가?             ' Worksheets("난방기기").Range("난방생산기기1").Offset(5, i_count_boiler - 1) = "예" Then  

            pLog.Add(">> ")

            Q_w_b = 0
            Q_w_s = 0
            Q_w_d = 0
            Q_w_outg_i = 0
            Q_w_g_i = 0
            W_sol_aux_m = 0
            t_h = 0
            d_op_max_mth = 0
            Q_w_ce_aux = 0
            Q_w_d_aux = 0
            Q_w_s_aux = 0
            Q_w_g_aux = 0
            'W_sol_aux_m = 0
            system_count = 1 '//160315

            If dr난방.열생산기기방식.Trim = "전기보일러" Then
                pLog.Add("전기보일러는 q_w_b 값을 0으로 처리합니다")
                Q_w_b = 0
            End If

            ' Dim Dr존 As DS.tbl_zoneRow  '//여기존 할당부분은엑셀하고 다시 비교해야할듯 하다 이존은 아래쪽에 프로시져 넘길떄 사용한다.

            '//현재난방기기를  급탕생산기기로 사용하는 존을 가져와서 누적시킴
            For Each Dr존 As DS.tbl_zoneRow In 적용기기목록
                'MsgBox(Mon & "/" & Dr존.code)

                system_count = 1 'IIf(dr난방.개별기기적용 = "0", 1, TOSG(Dr존.입력존의수))   '//20130818

                pLog.Add(String.Format("Process Zone:{0}", Dr존.code))

                'If dr난방.헤더적용 Then
                '    Q_w_b = a_Q_w_b
                '    Q_w_b *= 비율

                '    d_op_max_mth = a_d_op_max_mth
                '    t_h = a_t_h
                'Else
                Dim Drow결과() As DSR.월별에너지분석Row = CType(DSETR.월별에너지분석.Select("월='" & Mon & "' and 존='" & Dr존.code & "'"), DSR.월별에너지분석Row())
                Dim Drow최대() As DSR.최대냉난방부하Row = CType(DSETR.최대냉난방부하.Select("Zone='" & Dr존.code & "'"), DSR.최대냉난방부하Row())
                Q_w_b = Q_w_b + TOSG(Drow결과(0).급탕요구량) / system_count ' Sheets("" & i_count_month & "").Cells(15, 7 + i_count_zone) '//급탕에너지요구량

                '===================================================================================2010.2.21 수정
                Dim Dr프로필() As DS.tbl_profileRow = CType(DSET.tbl_profile.Select("code='" & Dr존.프로필 & "' and code <> '0'", "code"), DS.tbl_profileRow())
                If Dr프로필.GetUpperBound(0) = -1 Then
                    LogSB.AppendLine(Dr존.설명 & "존의 프로필코드(" & Dr존.프로필 & ") 가 존재하지않습니다")
                    'MsgBox(Dr존.설명 & "존의 프로필코드(" & Dr존.프로필 & ") 가 존재하지않습니다")
                Else
                    d_op_mth = CInt(TOSG(Dr프로필(0)("day" & Format(i_count_month, "00")))) ' Worksheets("설정조건").Range("월간사용일수1").Offset(i_count_month, i_count_profile)
                End If

                If t_h < Result.최대부하.Item(Dr존.code).일일난방최대가동시간 * d_op_mth Then
                    t_h = Result.최대부하.Item(Dr존.code).일일난방최대가동시간 * d_op_mth
                End If
                If d_op_max_mth < d_op_mth Then
                    d_op_max_mth = d_op_mth
                End If
                '===================================================================================2010.2.21 수정
                'End If

                pLog.Add(String.Format("q_w_b={0},d_op_mth={1},t_h={2},d_op_max_mth={3}", Q_w_b, d_op_mth, t_h, d_op_max_mth))

            Next
            '===================================================================================2014.2.25 수정
            If dr난방.헤더적용 Then
                Q_w_b = a_Q_w_b
                Q_w_b *= 비율
                pLog.Add(String.Format("헤더적용으로인해 q_w_b 값이 수정됩니다 q_w_b=", Q_w_b))
            End If

            '===================================================================================2014.2.25 수정

            '====================================2010.2.21 수정
            d_Nutz_mth = d_op_max_mth
            '====================================2010.2.21 수정

            If dr난방.분배시스템방식 = "중앙식" Then ' Dr난방.분배시스템방식 = "중앙식" Then

                If dr난방.배관길이 <> "" AndAlso dr난방.배관길이 <> "0" Then '//입력치
                    L_i = TOSG(dr난방.배관길이) * 0.255
                Else
                    L_G = TOSG(dr난방.건물길이) ' Dr난방.건물길이
                    B_G = TOSG(dr난방.건물넓이) 'Dr난방.건물넓이
                    n_G = TOSG(dr난방.열공급층수) 'Dr난방.열공급층수
                    h_G = TOSG(dr난방.층고) 'Worksheets("난방기기").Range("급탕분배건물길이1").Offset(3, i_count_boiler - 1)
                    L_i = TOSG((2 * L_G + 0.0325 * L_G * B_G + 6) * 0.2 + (0.025 * L_G * B_G * h_G * n_G + 2 * (L_G + B_G) * n_G) * 0.255 + (0.1 * L_G * B_G * n_G) * 0.255) '단일배관난방적용
                End If


                '=================================================2010. 02. 11 수정
                For Each Dr난방분배 As DS.tbl_nbunbaeRow In DSET.tbl_nbunbae.Select("배관망유형='급탕' and 생산기기구분='" & dr난방.code & "'", "code")
                    L_i += TOSG(Dr난방분배.배관구간길이) * TOSG(Dr난방분배.열관류율)
                Next
                'For i_count_pipe = 1 To Range("배관구간").Columns.Count
                '    If Worksheets("난방분배시스템").Range("분배생산기기1").Offset(2, i_count_pipe - 1) = "급탕" Then
                '        If Worksheets("난방기기").Range("난방생산기기1").Offset(0, i_count_boiler - 1) = Worksheets("난방분배시스템").Range("분배생산기기1").Offset(0, i_count_pipe - 1) Then
                '            L_i = L_i + Worksheets("난방분배시스템").Range("배관구간방식1").Offset(1, i_count_pipe - 1) * Worksheets("난방분배시스템").Range("배관구간방식1").Offset(2, i_count_pipe - 1)
                '        End If
                '    End If
                'Next
                '=================================================2010. 02. 11 수정

                If dr난방.순환유무 = "무" Then ' Worksheets("난방기기").Range("급탕분배방식1").Offset(1, i_count_boiler - 1) = "무" Then
                    ':중앙비순환시스템
                    Q_w_d_i = TOSG(1 / 1000 * L_i * ((23 * 0.2 ^ (-0.2) - theta_i) * d_Nutz_mth * 24)) '(3.2.9-11) 중앙비순환시스템 L_i 에 U_i 포함 theta_w_m_비순환 는 23*0.2^(-0.2)
                    theta_g_m = 40
                Else
                    ':중앙순환시스템
                    Q_w_d_i = TOSG(1 / 1000 * L_i * d_Nutz_mth * ((50 - theta_i) * t_Nutz_d + 0.5 * (23 * 0.2 ^ (-0.2) - theta_i) * (24 - t_Nutz_d))) '(3.2.9-11) 중앙순환시스템 L_i 에 U_i 포함 theta_w_m_순환 는 50도
                    theta_g_m = 50
                End If

                Q_w_d = Q_w_d + Q_w_d_i '(3.2.9-12)

            Else

                theta_g_m = 40 '2013.01.12 추가 개별식의 경우 비순환시스템으로 적용

            End If


            Select Case dr난방.축열탱크방식.Trim ' Worksheets("난방기기").Range("난방기기축열탱크1").Offset(0, i_count_boiler - 1)
                Case "전기가열식" '전기가열식"

                    ':저탕조용량(모를경우)
                    'f_N = 1 / (t_Nutz_d * 1) '(3.2.9-24)  t_Nutz_T 는 t_Nutz_d 로 적용, eta_Sp는 1로 적용 추후 검토
                    ':심야전기가열
                    'V_s = 1.42 * Q_w_b_d * f_N * 860 / ((theta_w_m - theta_k) * eta_s) '(3.2.9-33) : 심야전기가열
                    ':주간전기가열
                    'V_s = 0.67 * Q_w_b_d * f_N * 860 / ((Q_w_m - Q_k) * eta_s) '(3.2.9-34) : 주간전기가열
                    V_s = TOSG(dr난방.축열제척) ' Worksheets("난방기기").Range("난방기기축열체적1").Offset(0, i_count_boiler - 1)
                    q_B_S = TOSG(0.29 + 0.019 * V_s ^ 0.8) '(3.2.9-30) :1994 이후
                    Q_w_s = TOSG((55 - theta_i) / 45 * d_Nutz_mth * q_B_S) '(3.2.9-29) : 전기가열식 저탕조


                Case "가스가열식" '가스가열식"

                    ':가스가열식 저탕조
                    V_s = TOSG(dr난방.축열제척) 'Worksheets("난방기기").Range("난방기기축열체적1").Offset(0, i_count_boiler - 1)
                    ':1994 이후
                    q_B_S = TOSG(2 + 0.033 * V_s ^ 1.1) '(3.2.9-38)
                    Q_w_s = TOSG((55 - theta_i) / 50 * d_Nutz_mth * q_B_S) '(3.2.9-37) : 가스가열식 저탕조

                Case "간접가열식" '간접가열식"
                    ':간접 가열식 저탕조
                    ':태양열 복합 저탕조(UA_sb_s_a를 모를 경우)
                    'q_B_S = (0.4 + 0.2 * (V_s_aux + V_s_sol) ^ 0.4) * V_s_aux / (V_s_aux + V_s_sol) '(3.2.9-26)
                    'f_N = 1 / (t_Nutz_T * n_Sp) '(3.2.9-24)
                    ':저탕조용량(모를 경우)
                    'V_s = (Q_w_b_d * f_N * 860) / ((theta_w_m - theta_k) * eta_s) '(3.2.9-23)
                    V_s = TOSG(dr난방.축열제척) 'Worksheets("난방기기").Range("난방기기축열체적1").Offset(0, i_count_boiler - 1)
                    If V_s < 1000 Then
                        ':1000이하
                        ' q_B_S = 'CSng(0.8 + 2 * V_s ^ 0.77) '(3.2.9-18) 여기맞아요? 예 0.
                        q_B_S = 0.8 + 0.02 * V_s ^ 0.77 '(3.2.9-18) '===================================2010.04.24 수정
                    Else
                        ':1000이상
                        q_B_S = TOSG(0.39 * V_s ^ 0.35 + 0.5) '(3.2.9-19)
                    End If
                    Q_w_s = f_verbindung * (50 - theta_i) / 45 * d_Nutz_mth * q_B_S '(3.2.9-16)

            End Select

            Q_w_outg_i = Q_w_b + Q_w_ce + Q_w_d + Q_w_s '(3.2.9-4)


            Q_w_outg = Q_w_outg + Q_w_outg_i * system_count


            pLog.Add(String.Format("Q_w_outg_i={0},Q_w_outg={1}", Q_w_outg_i, Q_w_outg))


            ' 신재생에너지 시스템
            '----------------------------------------------------------------------------------------------------------------------------------
            '----------------------------------------------------------------------------------------------------------------------------------

            '태양열(급탕) 시스템
            Dim CRenew As New CRenewable(DSET, Result)
            If dr난방.신재생연결여부 = "시스템연결" AndAlso dr난방.연결된시스템 <> "0" Then 'Worksheets("난방기기").Range("신재생난방연결1").Offset(0, i_count_boiler - 1) = "시스템연결" Then
                Dim dr신재생 As DS.tbl_newRow = CType(DSET.tbl_new.Select("code <> '0' and code='" & dr난방.연결된시스템 & "'")(0), DS.tbl_newRow)
                '  If dr신재생.기기종류.Trim.IndexOf("태") <> -1 Then
                Select Case dr신재생.기기종류.Trim
                    Case "태양열" '//태양열
                        If dr신재생.태양열종류 = "급탕" Then
                            Calc.Renewable.Calc_ThermalSolarSystem_EN(system_type, dr신재생.code, i_count_month, d_mth, Q_h_outg_i, Q_w_outg_i, Q_W_sol_out_m, Q_H_sol_out_m, W_sol_aux_m)
                            Q_w_outg = Q_w_outg - Q_W_sol_out_m
                            Q_w_outg_i = Q_w_outg_i - Q_W_sol_out_m
                            W_sol_aux = W_sol_aux + W_sol_aux_m
                        End If
                        '=======================================================================2011.007.19 추가
                    Case "열병합" '//열병합
                        Select Case dr신재생.가동연료.Trim
                            Case "난방유" '난방유"
                                CRenew.Calc_CogenerationSystemEN(dr신재생, 3, i_count_month, Q_w_outg_i, t_h, Q_w_CHP, Q_w_f_CHP)
                                Q_w_outg = Q_w_outg - Q_w_CHP
                                Q_w_outg_i = Q_w_outg_i - Q_w_CHP
                                use_Oil = use_Oil + Q_w_f_CHP * system_count '===========2013.08.18 수정
                                Q_w_f = Q_w_f + Q_w_f_CHP * system_count '============================2013.01.13 수정, 2013.08.18 수정
                            Case "천연가스" '천연가스"
                                CRenew.Calc_CogenerationSystemEN(dr신재생, 3, i_count_month, Q_w_outg_i, t_h, Q_w_CHP, Q_w_f_CHP)
                                Q_w_outg = Q_w_outg - Q_w_CHP
                                Q_w_outg_i = Q_w_outg_i - Q_w_CHP
                                use_LNG = use_LNG + Q_w_f_CHP * system_count '===========2013.08.18 수정
                                Q_w_f = Q_w_f + Q_w_f_CHP * system_count '============================2013.01.13 수정, 2013.08.18 수정
                            Case "액화가스" '액화가스"
                                CRenew.Calc_CogenerationSystemEN(dr신재생, 3, i_count_month, Q_w_outg_i, t_h, Q_w_CHP, Q_w_f_CHP)
                                Q_w_outg = Q_w_outg - Q_w_CHP
                                Q_w_outg_i = Q_w_outg_i - Q_w_CHP
                                use_LPG = use_LPG + Q_w_f_CHP * system_count '===========2013.08.18 수정
                                Q_w_f = Q_w_f + Q_w_f_CHP * system_count '============================2013.01.13 수정, 2013.08.18 수정
                            Case Else
                                MsgBox("신재생에너지의 가동연료를 확인할 수 없습니다", MsgBoxStyle.Critical, dr신재생.가동연료)
                        End Select
                        '=======================================================================2011.007.19 추가

                    Case "지열" '//지열
                        Select Case dr신재생.가동연료.Trim
                            Case "전기" '전기"
                                CRenew.Calc_HeatpumpSystem(system_type, 3, dr신재생, Q_w_outg_i, i_count_month, d_op_max_mth, t_h, theta_g_m, theta_i, Q_wp_outg, Q_w_f_hp, Q_w_g_hp_aux) '=============2010.04.01 수정 Q_h_outg 를 Q_h_outg_i 로 수정
                                Q_w_outg = Q_w_outg - Q_wp_outg
                                Q_w_outg_i = Q_w_outg_i - Q_wp_outg
                                use_Elec = use_Elec + (Q_w_f_hp + Q_w_g_hp_aux) * system_count '===========2013.08.18 수정
                                Q_w_f = Q_w_f + (Q_w_f_hp + Q_w_g_hp_aux) * system_count '============================2010.04.17 추가, 2013.08.18 수정
                            Case "천연가스" '천연가스"
                                CRenew.Calc_HeatpumpSystem(system_type, 3, dr신재생, Q_w_outg_i, i_count_month, d_op_max_mth, t_h, theta_g_m, theta_i, Q_wp_outg, Q_w_f_hp, Q_w_g_hp_aux) '=============2010.04.01 수정 Q_h_outg 를 Q_h_outg_i 로 수정
                                Q_w_outg = Q_w_outg - Q_wp_outg
                                Q_w_outg_i = Q_w_outg_i - Q_wp_outg
                                use_LNG = use_LNG + Q_w_f_hp * system_count '===========2013.08.18 수정
                                use_Elec = use_Elec + Q_w_g_hp_aux * system_count '===========2013.08.18 수정
                                Q_w_f = Q_w_f + (Q_w_f_hp + Q_w_g_hp_aux) * system_count '============================2010.04.17 추가, 2013.08.18 수정
                                '//요기맞죠 ^^?
                            Case "액화가스" '액화가스"
                                CRenew.Calc_HeatpumpSystem(system_type, 3, dr신재생, Q_w_outg_i, i_count_month, d_op_max_mth, t_h, theta_g_m, theta_i, Q_wp_outg, Q_w_f_hp, Q_w_g_hp_aux) '=============2010.04.01 수정 Q_h_outg 를 Q_h_outg_i 로 수정
                                Q_w_outg = Q_w_outg - Q_wp_outg
                                Q_w_outg_i = Q_w_outg_i - Q_wp_outg
                                use_LPG = use_LPG + Q_w_f_hp * system_count '===========2013.08.18 수정
                                use_Elec = use_Elec + Q_w_g_hp_aux * system_count '===========2013.08.18 수정
                                Q_w_f = Q_w_f + (Q_w_f_hp + Q_w_g_hp_aux) * system_count '============================2010.04.17 추가, 2013.08.18 수정
                        End Select
                    Case Else
                        '//160428
                        If MsgBox("알수없는 기기종류" + vbCrLf + dr신재생.기기종류 + vbCrLf + _
                                  "계산을 중단하시겠습니까?", MsgBoxStyle.Question Or MsgBoxStyle.YesNo, "확인") = MsgBoxResult.Yes Then
                            Return
                        End If
                End Select
                'End If
            End If

            pLog.Add(String.Format("신재생 : 태양열급탕 결과 Q_w_outg={0},Q_w_outg_i={1},use_LPG={2},use_LNG={5},use_Elec={3},Q_w_f={4}", Q_w_outg, Q_w_outg_i, use_LPG, use_Elec, Q_w_f, use_LNG))

            '----------------------------------------------------------------------------------------------------------------------------------
            '----------------------------------------------------------------------------------------------------------------------------------

            '=========================================================================================================================2013.01.13 히트펌프 위치 수정

            If dr난방.열생산기기방식 = "히트펌프" Then

                pLog.Add("히트펌프조건 진입")

                Q_dot_HP_waterheating = TOSG(dr난방.히트난방용량) ' Worksheets("난방기기").Range("히트펌프사용연료1").Offset(1, i_count_boiler - 1)
                COP_HP_7 = TOSG(dr난방.히트난방정격7) ' Worksheets("난방기기").Range("히트펌프사용연료1").Offset(2, i_count_boiler - 1)
                COP_HP_10 = TOSG(dr난방.히트난방정격10) ' Worksheets("난방기기").Range("히트펌프사용연료1").Offset(3, i_count_boiler - 1) ' 새로운 버전에서 15도로 입력값 수정
                L_HP_waterheating = TOSG(dr난방.히트배관길이) ' Worksheets("난방기기").Range("히트펌프사용연료1").Offset(4, i_count_boiler - 1)
                If theta_e > 15 Then
                    COP_HP_total = (COP_HP_7 - COP_HP_10) / 22 * 15 + COP_HP_7 - 7 * (COP_HP_7 - COP_HP_10) / 22
                Else
                    COP_HP_total = (COP_HP_7 - COP_HP_10) / 22 * theta_e + COP_HP_7 - 7 * (COP_HP_7 - COP_HP_10) / 22
                End If

                If theta_e < 7 Then

                    If theta_e >= 0 Then
                        COP_HP_total = TOSG(COP_HP_total * ((1 - 0.86) / 7 * theta_e + 0.86))
                    Else
                        COP_HP_total = TOSG(COP_HP_total * ((0.98 - 0.86) / 7 * (-theta_e) + 0.86))
                    End If

                End If

                If Q_dot_HP_waterheating <= 20 Then
                    COP_HP_total = TOSG(COP_HP_total * (1 - L_HP_waterheating * 0.002))
                Else
                    If Q_dot_HP_waterheating <= 100 Then
                        COP_HP_total = TOSG(COP_HP_total * (1 - L_HP_waterheating * 0.0009))
                    Else
                        COP_HP_total = TOSG(COP_HP_total * (1 - L_HP_waterheating * 0.0014))
                    End If
                End If

                Q_w_outg = Q_w_outg - Q_w_outg_i '===================================================2013.01.16 추가

                If Q_dot_HP_waterheating = 0 Or t_h = 0 Then '=============================================================2014.03.07 추가
                    Q_w_outg_i = 0
                Else
                    If Q_w_outg_i / (Q_dot_HP_waterheating * t_h) > 1 Or dr난방.히트펌프시스템종류 = "실내외분리시스템" Then
                        Q_w_outg_i = Q_w_outg_i / COP_HP_total
                    Else
                        Q_w_outg_i = Q_w_outg_i / (COP_HP_total * (Q_w_outg_i / (Q_dot_HP_waterheating * t_h) * 0.5 + 0.5))
                    End If

                End If                                       '=============================================================2014.03.07 추가

                Q_w_outg = Q_w_outg + Q_w_outg_i '===================================================2013.01.16 추가

                pLog.Add(String.Format("히트펌프조건 완료 Q_w_outg={0}", Q_w_outg))
            End If

            '=========================================================================================================================2013.01.13 히트펌프 위치 수정


            Q_dot_N = TOSG(IIf(dr난방.보일러정격출력 = "", 0, dr난방.보일러정격출력)) 'Worksheets("난방기기").Range("난방기기정격출력1").Offset(0, i_count_boiler - 1)
            eta_k_100 = TOSG(IIf(dr난방.정격보일러효율 = "", 0, TOSG(dr난방.정격보일러효율))) / 100 ' Worksheets("난방기기").Range("난방기기정격효율1").Offset(0, i_count_boiler - 1) / 100

            'Select Case Worksheets("난방기기").Range("난방기기사용연료1").Offset(0, i_count_boiler - 1)
            'Case "난방유"
            'f_Hs_Hi = 1.06
            'Case "천연가스"
            'f_Hs_Hi = 1.11
            'Case "액화가스"
            'f_Hs_Hi = 1.09
            'Case "석탄"
            'f_Hs_Hi = 1.04
            'Case "갈탄"
            'f_Hs_Hi = 1.07
            'Case "나무"
            'f_Hs_Hi = 1.08
            'End Select
            f_Hs_Hi = 1 ' 국내는 총발열량을 기준으로 입력함으로 우선 1로 설정, 추후 검토

            If dr난방.열생산기기방식 = "보일러" Then ' Worksheets("난방기기").Range("열생산기기방식1").Offset(0, i_count_boiler - 1) = "보일러" Then

                pLog.Add("열생산기기방식 - 보일러진입")

                If d_Nutz_mth = 0 Or eta_k_100 = 0 Then '//201.11.20 추가(학교프로파일 적용시 문제점 해결) '====2014.03.07 추가
                    Q_w_g_100 = 0
                Else
                    Q_w_g_100 = (f_Hs_Hi - eta_k_100) / eta_k_100 * Q_w_outg_i / d_Nutz_mth '(3.2.9-58)
                End If

                If d_Nutz_mth = 0 Or Q_dot_N = 0 Then '//201.11.20 추가(학교프로파일 적용시 문제점 해결)'====2014.03.07 추가
                    t_w_100 = 0
                Else
                    t_w_100 = Q_w_outg_i / (Q_dot_N * d_Nutz_mth) '(3.2.9-61)
                End If

                Select Case dr난방.보일러방식.Trim ' Worksheets("난방기기").Range("보일러방식1").Offset(0, i_count_boiler - 1)
                    Case "가스보일러" '가스보일러"
                        q_B_70 = TOSG((8.5 * Q_dot_N ^ (-0.4)) / 100)

                    Case "기름보일러" '기름보일러"
                        q_B_70 = TOSG((8.5 * Q_dot_N ^ (-0.4)) / 100)

                    Case "저온가스보일러" '저온가스보일러"
                        q_B_70 = TOSG((4.5 * Q_dot_N ^ (-0.4)) / 100)

                    Case "저온기름보일러" '저온기름보일러"
                        q_B_70 = TOSG((4.25 * Q_dot_N ^ (-0.4)) / 100)

                    Case "콘덴싱보일러" '콘덴싱보일러"
                        q_B_70 = TOSG((4 * Q_dot_N ^ (-0.4)) / 100)
                    Case Else
                        MsgBox("난방.보일러방식을 알수없습니다", MsgBoxStyle.Critical, "값=" & dr난방.보일러방식)
                End Select

                q_B_theta = q_B_70 * (theta_g_m - theta_i) / (70 - 20) '(3.2.9-60)
                If eta_k_100 = 0 Then '===========================================2014.03.07 추가
                    Q_B_w = 0
                Else
                    Q_B_w = q_B_theta * Q_dot_N / eta_k_100 * (t_Nutz_d - t_w_100) * f_Hs_Hi '(3.2.9-59)
                End If                '===========================================2014.03.07 추가


                If theta_WA_Grenz - theta_e_min = 0 Then '====================================================2014.03.07 추가
                    f_L_WA = 1
                Else
                    f_L_WA = 1 - (theta_WA_Grenz - theta_e) / (theta_WA_Grenz - theta_e_min) '(3.2.7-22)
                End If                                   '====================================================2014.03.07 추가

                If d_mth = 0 Then
                    d_h_rB = 0
                Else
                    d_h_rB = d_mth * ((365 - f_L_WA * (365 - d_Nutz_a)) / 365) * (t_h / (d_mth * 24)) '(3.2.7-21)
                End If


                ':d_h_rB > d_Nutz_mth 일 경우
                If d_h_rB > d_Nutz_mth Then
                    d_Nutz_mth = CInt(d_h_rB)
                End If

                Q_w_g = Q_w_g + (Q_w_g_100 * d_Nutz_mth + Q_B_w * (d_Nutz_mth - d_h_rB)) * system_count '=====2013.08.13 수정 '(3.2.9-57)
                Q_w_g_i = Q_w_g_100 * d_Nutz_mth + Q_B_w * (d_Nutz_mth - d_h_rB)

                pLog.Add(String.Format("열생산기기방식 - 보일러완료 : Q_w_g={0},Q_w_g_i={1}", Q_w_g, Q_w_g_i))

            Else

                If dr난방.열생산기기방식 = "지역난방" Then ' Worksheets("난방기기").Range("열생산기기방식1").Offset(0, i_count_boiler - 1) = "지역난방" Then

                    pLog.Add("열생산기기방식 - 지역난방")

                    If dr난방.지역난방방식 = "중온수" Then ' Worksheets("난방기기").Range("지역난방온수방식1").Offset(0, i_count_boiler - 1) = "중온수" Then
                        D_DS = 0.6
                        theta_prim_DS = 105
                        'MsgBox("난방기기 단열등급에  등급2/3 등급3/4 등급 4/5 추가해야함")
                        Select Case dr난방.단열등급.Trim '  Dr난방.단열등급
                            Case "기본단열" '기본단열" '원래는 등급1/2 이지만 국내에서는 법적단열로 사용
                                B_DS = 4.9
                            Case "등급2/3" '등급2/3"
                                B_DS = 4.4
                            Case "등급3/4" '등급3/4"
                                B_DS = 4
                            Case "등급4/5" '등급4/5"
                                B_DS = 3.5
                        End Select
                    End If
                    'MsgBox("난방기기 지역난방방식에 고온수 0002 추가해야함") --추가는 했으나 엑셀에서는 중온수고정이다 그래서 하위 루틴은 실행되면안된다
                    If dr난방.지역난방방식 = "고온수" Then 'Worksheets("난방기기").Range("지역난방온수방식1").Offset(0, i_count_boiler - 1) = "고온수" Then
                        ' MsgBox("난방기기의 지역난방방식은 중온수 고정입니다.", MsgBoxStyle.Information, "확인")
                        D_DS = 0.4
                        theta_prim_DS = 150
                        Select Case dr난방.단열등급.Trim
                            Case "기본단열" '기본단열" '원래는 등급1/2 이지만 국내에서는 법적단열로 사용
                                B_DS = 4.3
                            Case "등급2/3" '등급2/3"
                                B_DS = 3.9
                            Case "등급3/4" '등급3/4"
                                B_DS = 3.5
                            Case "등급4/5" '등급4/5"
                                B_DS = 3.1
                        End Select
                    End If



                    theta_DS = D_DS * theta_prim_DS + (1 - D_DS) * 55 ' theta_sek_DS는 55도로 설정 (3.2.7-112)
                    Psi_DS = TOSG(dr난방.열교환기정격출력) ' .Worksheets("난방기기").Range("난방기기정격출력1").Offset(1, i_count_boiler - 1)
                    H_DS = TOSG(B_DS * Psi_DS ^ (1 / 3))
                    Q_w_g = Q_w_g + (H_DS * (theta_DS - theta_i)) * system_count '=====2013.08.13 수정
                    use_DH = use_DH + (H_DS * (theta_DS - theta_i)) * system_count '========2013.08.18 수정

                    pLog.Add(String.Format("열생산기기방식 - 지역난방완료 : Q_w_g={0},use_DH={1}", Q_w_g, use_DH))

                End If

            End If

            ': 급탕 전기 보조에너지 시작

            Q_w_ce_aux = 0
            Q_w_g_aux = 0 '// 2014.01.08 추가

            P_Pump_w = TOSG(dr난방.펌프동력급탕) ' Worksheets("난방기기").Range("급탕펌프제어유형1").Offset(1, i_count_boiler - 1)
            Select Case dr난방.펌프제어.Trim 'Worksheets("난방기기").Range("급탕펌프제어유형1").Offset(0, i_count_boiler - 1)
                Case "비제어" '비제어"
                    c_p1 = 0.25
                    c_p2 = 0.94
                Case "제어" '제어"
                    c_p1 = 0.5
                    c_p2 = 0.63
                Case "(없음)"
                    c_p1 = 0
                    c_p2 = 0
                Case Else
                    '//160428 중단기능추가
                    Dim msg As String = String.Format("[난방기기:{0}] 알수없는 펌프제어 값={1}", dr난방.code, dr난방.펌프제어)
                    If MsgBox(msg + vbCrLf + "계산을 중단하시겠습니까?", MsgBoxStyle.Question Or MsgBoxStyle.YesNo, "확인") = MsgBoxResult.Yes Then
                        Return
                    End If
            End Select

            Q_w_d_aux = Q_w_d_aux + P_Pump_w / 1000 * d_Nutz_mth * t_Nutz_d * (c_p1 + c_p2) '(3.2.9-15)

            Select Case dr난방.축열탱크방식.Trim ' Worksheets("난방기기").Range("난방기기축열탱크1").Offset(0, i_count_boiler - 1)
                Case "전기가열식" '전기가열식"
                    'Q_w_s_aux = Q_w_s_aux + 0

                Case "가스가열식" '가스가열식"
                    'Q_w_s_aux = Q_w_s_aux + 0

                Case "간접가열식" '간접가열식"

                    '=================================================================================2010.10.19 추가
                    Select Case dr난방.열생산기기방식.Trim 'Worksheets("난방기기").Range("열생산기기방식1").Offset(0, i_count_boiler - 1)
                        Case "보일러"
                            t_P = TOSG(Q_w_outg_i * 1.1 / Q_dot_N) '(3.2.9-28)
                        Case "지역난방"
                            t_P = TOSG(Q_w_outg_i * 1.1 / TOSG(dr난방.열교환기정격출력))
                        Case "전기보일러"
                            t_P = 1
                        Case "히트펌프"
                            t_P = 1
                    End Select
                    '=================================================================================2010.10.19 추가
                    Q_w_s_aux = TOSG(Q_w_s_aux + 0.001 * P_Pump_w * t_P) '(3.2.9-27)

            End Select
            If dr난방.열생산기기방식 = "보일러" Then 'Worksheets("난방기기").Range("열생산기기방식1").Offset(0, i_count_boiler - 1) = "보일러" Then
                Select Case dr난방.보일러방식.Trim 'Worksheets("난방기기").Range("보일러방식1").Offset(0, i_count_boiler - 1)
                    Case "가스보일러" '가스보일러"
                        P_aux_100 = TOSG((0.148 * Q_dot_N + 40) / 1000) '(3.2.9-77)

                    Case "기름보일러" '기름보일러"
                        P_aux_100 = TOSG(0.045 * Q_dot_N ^ 0.48) '(3.2.9-78)

                    Case "저온가스보일러" '저온가스보일러"
                        P_aux_100 = TOSG((0.148 * Q_dot_N + 40) / 1000) '(3.2.9-79)

                    Case "저온기름보일러" '저온기름보일러"
                        P_aux_100 = TOSG(0.045 * Q_dot_N ^ 0.48) '(3.2.9-80)

                    Case "콘덴싱보일러" '콘덴싱보일러"
                        P_aux_100 = TOSG(0.045 * Q_dot_N ^ 0.48) '(3.2.9-81)

                End Select

                If d_Nutz_mth = 0 Or Q_dot_N = 0 Then '//201.11.20 추가(학교프로파일 적용시 문제점 해결) '===2014.03.07 추가
                    t_w_100 = 0
                Else
                    t_w_100 = Q_w_outg_i / (Q_dot_N * d_Nutz_mth) '(3.2.9-61)
                End If

                Q_w_g_aux = Q_w_g_aux + P_aux_100 * t_w_100 * d_Nutz_mth '+ P_aux_SB * (24 - t_w_100) * (d_Nutz_mth - d_h_rB) '(3.2.9-7)

            End If



            If dr난방.열생산기기방식 = "보일러" Then ' Then 'Worksheets("난방기기").Range("열생산기기방식1").Offset(0, i_count_boiler - 1) = "보일러" Then
                Select Case dr난방.사용연료.Trim '  Worksheets("난방기기").Range("난방기기사용연료1").Offset(0, i_count_boiler - 1)
                    Case "난방유" '난방유"
                        use_Oil = use_Oil + (Q_w_outg_i + Q_w_g_i) * system_count '========2013.08.18 수정

                    Case "천연가스" '천연가스"
                        use_LNG = use_LNG + (Q_w_outg_i + Q_w_g_i) * system_count '========2013.08.18 수정

                    Case "액화가스" '액화가스"
                        use_LPG = use_LPG + (Q_w_outg_i + Q_w_g_i) * system_count '========2013.08.18 수정

                End Select
            Else
                Select Case dr난방.열생산기기방식.Trim 'Worksheets("난방기기").Range("열생산기기방식1").Offset(0, i_count_boiler - 1)
                    Case "지역난방" '지역난방"
                        use_DH = use_DH + Q_w_outg_i * system_count '========2013.08.18 수정

                    Case "전기보일러" '전기보일러"
                        use_Elec = use_Elec + (Q_w_outg_i + (Q_w_outg_i * 0.09)) * system_count '========2013.08.18 수정 '2011.03.08 개별전기보일러 생산손실을 내부 생산식저장으로 설정
                        Q_w_outg = Q_w_outg + (Q_w_outg_i * 0.09) * system_count '========2013.11.6 수정

                        '====================================================================================2010.03.14 추가
                    Case "히트펌프"

                        Select Case dr난방.히트연료 ' Worksheets("난방기기").Range("히트펌프사용연료1").Offset(0, i_count_boiler - 1)
                            Case "전기"
                                use_Elec = use_Elec + (Q_w_outg_i + Q_w_g_i) * system_count '========2013.08.18 수정
                            Case "천연가스"
                                use_LNG = use_LNG + (Q_w_outg_i + Q_w_g_i) * system_count '========2013.08.18 수정
                            Case "액화가스"
                                use_LPG = use_LPG + (Q_w_outg_i + Q_w_g_i) * system_count '========2013.08.18 수정
                        End Select
                        '====================================================================================2010.03.14 추가

                End Select

            End If

            use_Elec = use_Elec + (Q_w_ce_aux + Q_w_d_aux + Q_w_s_aux + Q_w_g_aux + W_sol_aux) * system_count '========2013.08.18 수정
            Q_w_aux = Q_w_aux + (Q_w_ce_aux + Q_w_d_aux + Q_w_s_aux + Q_w_g_aux + W_sol_aux) * system_count '========2013.08.18 수정 '급탕보조에너지소요량 (3.2.9-7) 2011.03.23 추가

            pLog.Add(String.Format("급탕_개별기기미적용시 완료 use_Elec={0},Q_w_aux={1}", use_Elec, Q_w_aux))
        End If
    End Sub

    Private Sub Calc_급탕_개별기기적용시(dr난방 As DS.tbl_nanbangkikiRow, Mon As String, 비율 As Decimal, i_count_month As Integer, theta_e As Decimal, d_mth As Integer)

        pLog.Add(String.Format(">> Enter Process : Calc_급탕_개별기기적용시 : mon={0},비율={1},i_count_month={2},theta_e={3},d_mth={4}", Mon, 비율, i_count_month, theta_e, d_mth))

        Dim dr존데이터() As DS.tbl_zoneRow = DSET.tbl_zone.Select("열생산급탕생산기기='" & dr난방.code & "' and code <> '0'", "code")
        If dr존데이터.Length > 0 Then '//급탕생산기기로 지정되어있는가            '//존에서 이 난방기기가 사용되었는가?             ' Worksheets("난방기기").Range("난방생산기기1").Offset(5, i_count_boiler - 1) = "예" Then  

            pLog.Add("급탕생산기기로 적용된 건수가 있으므로 값들을 초기화한다")

            Q_w_b = 0
            Q_w_s = 0
            Q_w_d = 0
            Q_w_outg_i = 0
            Q_w_g_i = 0
            W_sol_aux_m = 0
            t_h = 0
            d_op_max_mth = 0
            Q_w_ce_aux = 0
            Q_w_d_aux = 0
            Q_w_s_aux = 0
            Q_w_g_aux = 0
            'W_sol_aux_m = 0
            system_count = 1
        End If

        pLog.Add(String.Format("system_count={0}", system_count))

        If dr난방.열생산기기방식.Trim = "전기보일러" Then Q_w_b = 0

        pLog.Add(String.Format("Q_w_b={0}", Q_w_b))

        ' Dim Dr존 As DS.tbl_zoneRow  '//여기존 할당부분은엑셀하고 다시 비교해야할듯 하다 이존은 아래쪽에 프로시져 넘길떄 사용한다.

        '//현재난방기기를  급탕생산기기로 사용하는 존을 가져와서 누적시킴
        For Each Dr존 As DS.tbl_zoneRow In dr존데이터
            system_count = TOSG(Dr존.입력존의수)  '//20130818
            If system_count = 0 Then system_count = 1

            pLog.Add(String.Format("ZoneCode={0},System_Count={1}", Dr존.code, system_count))


            'If dr난방.헤더적용 Then
            '    Q_w_b = a_Q_w_b
            '    Q_w_b *= 비율

            '    d_op_max_mth = a_d_op_max_mth
            '    t_h = a_t_h
            'Else
            Dim Drow결과() As DSR.월별에너지분석Row = CType(DSETR.월별에너지분석.Select("월='" & Mon & "' and 존='" & Dr존.code & "'"), DSR.월별에너지분석Row())
            Dim Drow최대() As DSR.최대냉난방부하Row = CType(DSETR.최대냉난방부하.Select("Zone='" & Dr존.code & "'"), DSR.최대냉난방부하Row())
            Q_w_b = TOSG(Drow결과(0).급탕요구량) / system_count ' Sheets("" & i_count_month & "").Cells(15, 7 + i_count_zone) '//급탕에너지요구량

            '===================================================================================2010.2.21 수정
            Dim Dr프로필() As DS.tbl_profileRow = CType(DSET.tbl_profile.Select("code='" & Dr존.프로필 & "' and code <> '0'", "code"), DS.tbl_profileRow())
            If Dr프로필.GetUpperBound(0) = -1 Then
                LogSB.AppendLine(Dr존.설명 & "존의 프로필코드(" & Dr존.프로필 & ") 가 존재하지않습니다")
                'MsgBox(Dr존.설명 & "존의 프로필코드(" & Dr존.프로필 & ") 가 존재하지않습니다")
            Else
                d_op_mth = CInt(TOSG(Dr프로필(0)("day" & Format(i_count_month, "00")))) ' Worksheets("설정조건").Range("월간사용일수1").Offset(i_count_month, i_count_profile)
            End If

            If t_h < Result.최대부하.Item(Dr존.code).일일난방최대가동시간 * d_op_mth Then
                t_h = Result.최대부하.Item(Dr존.code).일일난방최대가동시간 * d_op_mth
            End If
            If d_op_max_mth < d_op_mth Then
                d_op_max_mth = d_op_mth
            End If
            '===================================================================================2010.2.21 수정
            'End If


            '====================================2010.2.21 수정
            d_Nutz_mth = d_op_max_mth
            '====================================2010.2.21 수정

            pLog.Add(String.Format("q_w_b={0},d_op_mth={1},t_h={2},d_op_max_mth={3},d_nutz_mth={4}", Q_w_b, d_op_mth, t_h, d_op_max_mth, d_Nutz_mth))

            If dr난방.분배시스템방식 = "중앙식" Then ' Dr난방.분배시스템방식 = "중앙식" Then

                If dr난방.배관길이 <> "" AndAlso dr난방.배관길이 <> "0" Then '//입력치
                    L_i = TOSG(dr난방.배관길이) * 0.255
                Else
                    L_G = TOSG(dr난방.건물길이) ' Dr난방.건물길이
                    B_G = TOSG(dr난방.건물넓이) 'Dr난방.건물넓이
                    n_G = TOSG(dr난방.열공급층수) 'Dr난방.열공급층수
                    h_G = TOSG(dr난방.층고) 'Worksheets("난방기기").Range("급탕분배건물길이1").Offset(3, i_count_boiler - 1)
                    L_i = TOSG((2 * L_G + 0.0325 * L_G * B_G + 6) * 0.2 + (0.025 * L_G * B_G * h_G * n_G + 2 * (L_G + B_G) * n_G) * 0.255 + (0.1 * L_G * B_G * n_G) * 0.255) '단일배관난방적용
                End If


                '=================================================2010. 02. 11 수정
                For Each Dr난방분배 As DS.tbl_nbunbaeRow In DSET.tbl_nbunbae.Select("배관망유형='급탕' and 생산기기구분='" & dr난방.code & "'", "code")
                    L_i += TOSG(Dr난방분배.배관구간길이) * TOSG(Dr난방분배.열관류율)
                Next
                'For i_count_pipe = 1 To Range("배관구간").Columns.Count
                '    If Worksheets("난방분배시스템").Range("분배생산기기1").Offset(2, i_count_pipe - 1) = "급탕" Then
                '        If Worksheets("난방기기").Range("난방생산기기1").Offset(0, i_count_boiler - 1) = Worksheets("난방분배시스템").Range("분배생산기기1").Offset(0, i_count_pipe - 1) Then
                '            L_i = L_i + Worksheets("난방분배시스템").Range("배관구간방식1").Offset(1, i_count_pipe - 1) * Worksheets("난방분배시스템").Range("배관구간방식1").Offset(2, i_count_pipe - 1)
                '        End If
                '    End If
                'Next
                '=================================================2010. 02. 11 수정

                If dr난방.순환유무 = "무" Then ' Worksheets("난방기기").Range("급탕분배방식1").Offset(1, i_count_boiler - 1) = "무" Then
                    ':중앙비순환시스템
                    Q_w_d_i = TOSG(1 / 1000 * L_i * ((23 * 0.2 ^ (-0.2) - theta_i) * d_Nutz_mth * 24)) '(3.2.9-11) 중앙비순환시스템 L_i 에 U_i 포함 theta_w_m_비순환 는 23*0.2^(-0.2)
                    theta_g_m = 40
                Else
                    ':중앙순환시스템
                    Q_w_d_i = TOSG(1 / 1000 * L_i * d_Nutz_mth * ((50 - theta_i) * t_Nutz_d + 0.5 * (23 * 0.2 ^ (-0.2) - theta_i) * (24 - t_Nutz_d))) '(3.2.9-11) 중앙순환시스템 L_i 에 U_i 포함 theta_w_m_순환 는 50도
                    theta_g_m = 50
                End If

                Q_w_d = Q_w_d + Q_w_d_i '(3.2.9-12)

            Else

                theta_g_m = 40 '2013.01.12 추가 개별식의 경우 비순환시스템으로 적용

            End If

            pLog.Add(String.Format("theta_g_m={0}", theta_g_m))


            Select Case dr난방.축열탱크방식.Trim ' Worksheets("난방기기").Range("난방기기축열탱크1").Offset(0, i_count_boiler - 1)
                Case "전기가열식" '전기가열식"

                    ':저탕조용량(모를경우)
                    'f_N = 1 / (t_Nutz_d * 1) '(3.2.9-24)  t_Nutz_T 는 t_Nutz_d 로 적용, eta_Sp는 1로 적용 추후 검토
                    ':심야전기가열
                    'V_s = 1.42 * Q_w_b_d * f_N * 860 / ((theta_w_m - theta_k) * eta_s) '(3.2.9-33) : 심야전기가열
                    ':주간전기가열
                    'V_s = 0.67 * Q_w_b_d * f_N * 860 / ((Q_w_m - Q_k) * eta_s) '(3.2.9-34) : 주간전기가열
                    V_s = TOSG(dr난방.축열제척) ' Worksheets("난방기기").Range("난방기기축열체적1").Offset(0, i_count_boiler - 1)
                    q_B_S = TOSG(0.29 + 0.019 * V_s ^ 0.8) '(3.2.9-30) :1994 이후
                    Q_w_s = TOSG((55 - theta_i) / 45 * d_Nutz_mth * q_B_S) '(3.2.9-29) : 전기가열식 저탕조


                Case "가스가열식" '가스가열식"

                    ':가스가열식 저탕조
                    V_s = TOSG(dr난방.축열제척) 'Worksheets("난방기기").Range("난방기기축열체적1").Offset(0, i_count_boiler - 1)
                    ':1994 이후
                    q_B_S = TOSG(2 + 0.033 * V_s ^ 1.1) '(3.2.9-38)
                    Q_w_s = TOSG((55 - theta_i) / 50 * d_Nutz_mth * q_B_S) '(3.2.9-37) : 가스가열식 저탕조

                Case "간접가열식" '간접가열식"
                    ':간접 가열식 저탕조
                    ':태양열 복합 저탕조(UA_sb_s_a를 모를 경우)
                    'q_B_S = (0.4 + 0.2 * (V_s_aux + V_s_sol) ^ 0.4) * V_s_aux / (V_s_aux + V_s_sol) '(3.2.9-26)
                    'f_N = 1 / (t_Nutz_T * n_Sp) '(3.2.9-24)
                    ':저탕조용량(모를 경우)
                    'V_s = (Q_w_b_d * f_N * 860) / ((theta_w_m - theta_k) * eta_s) '(3.2.9-23)
                    V_s = TOSG(dr난방.축열제척) 'Worksheets("난방기기").Range("난방기기축열체적1").Offset(0, i_count_boiler - 1)
                    If V_s < 1000 Then
                        ':1000이하
                        ' q_B_S = 'CSng(0.8 + 2 * V_s ^ 0.77) '(3.2.9-18) 여기맞아요? 예 0.
                        q_B_S = 0.8 + 0.02 * V_s ^ 0.77 '(3.2.9-18) '===================================2010.04.24 수정
                    Else
                        ':1000이상
                        q_B_S = TOSG(0.39 * V_s ^ 0.35 + 0.5) '(3.2.9-19)
                    End If
                    Q_w_s = f_verbindung * (50 - theta_i) / 45 * d_Nutz_mth * q_B_S '(3.2.9-16)

            End Select

            Q_w_outg_i = Q_w_b + Q_w_ce + Q_w_d + Q_w_s '(3.2.9-4)


            Q_w_outg = Q_w_outg + Q_w_outg_i * system_count

            pLog.Add(String.Format("q_w_outg_i={0},Q_w_outg={1}", Q_w_outg_i, Q_w_outg))

            ' 신재생에너지 시스템
            '----------------------------------------------------------------------------------------------------------------------------------
            '----------------------------------------------------------------------------------------------------------------------------------

            '태양열(급탕) 시스템
            'If Dr난방.설명.ToUpper.IndexOf("B-1") <> -1 Then
            '    MsgBox(Dr난방.code)
            'End If
            Dim CRenew As New CRenewable(DSET, Result)
            If dr난방.신재생연결여부 = "시스템연결" AndAlso dr난방.연결된시스템 <> "0" Then 'Worksheets("난방기기").Range("신재생난방연결1").Offset(0, i_count_boiler - 1) = "시스템연결" Then
                Dim dr신재생 As DS.tbl_newRow = CType(DSET.tbl_new.Select("code <> '0' and code='" & dr난방.연결된시스템 & "'")(0), DS.tbl_newRow)
                '  If dr신재생.기기종류.Trim.IndexOf("태") <> -1 Then
                Select Case dr신재생.기기종류.Trim
                    Case "태양열" '//태양열
                        If dr신재생.태양열종류 = "급탕" Then
                            Calc.Renewable.Calc_ThermalSolarSystem_EN(system_type, dr신재생.code, i_count_month, d_mth, Q_h_outg_i, Q_w_outg_i, Q_W_sol_out_m, Q_H_sol_out_m, W_sol_aux_m)
                            Q_w_outg = Q_w_outg - Q_W_sol_out_m
                            Q_w_outg_i = Q_w_outg_i - Q_W_sol_out_m
                            W_sol_aux = W_sol_aux + W_sol_aux_m
                        End If
                        '=======================================================================2011.007.19 추가
                    Case "열병합" '//열병합
                        Select Case dr신재생.가동연료.Trim
                            Case "난방유" '난방유"
                                CRenew.Calc_CogenerationSystemEN(dr신재생, 3, i_count_month, Q_w_outg_i, t_h, Q_w_CHP, Q_w_f_CHP)
                                Q_w_outg = Q_w_outg - Q_w_CHP
                                Q_w_outg_i = Q_w_outg_i - Q_w_CHP
                                use_Oil = use_Oil + Q_w_f_CHP * system_count '===========2013.08.18 수정
                                Q_w_f = Q_w_f + Q_w_f_CHP * system_count '============================2013.01.13 수정, 2013.08.18 수정
                            Case "천연가스" '천연가스"
                                CRenew.Calc_CogenerationSystemEN(dr신재생, 3, i_count_month, Q_w_outg_i, t_h, Q_w_CHP, Q_w_f_CHP)
                                Q_w_outg = Q_w_outg - Q_w_CHP
                                Q_w_outg_i = Q_w_outg_i - Q_w_CHP
                                use_LNG = use_LNG + Q_w_f_CHP * system_count '===========2013.08.18 수정
                                Q_w_f = Q_w_f + Q_w_f_CHP * system_count '============================2013.01.13 수정, 2013.08.18 수정
                            Case "액화가스" '액화가스"
                                CRenew.Calc_CogenerationSystemEN(dr신재생, 3, i_count_month, Q_w_outg_i, t_h, Q_w_CHP, Q_w_f_CHP)
                                Q_w_outg = Q_w_outg - Q_w_CHP
                                Q_w_outg_i = Q_w_outg_i - Q_w_CHP
                                use_LPG = use_LPG + Q_w_f_CHP * system_count '===========2013.08.18 수정
                                Q_w_f = Q_w_f + Q_w_f_CHP * system_count '============================2013.01.13 수정, 2013.08.18 수정
                            Case Else
                                MsgBox("신재생에너지의 가동연료를 확인할 수 없습니다", MsgBoxStyle.Critical, dr신재생.가동연료)
                        End Select
                        '=======================================================================2011.007.19 추가

                    Case "지열" '//지열
                        Select Case dr신재생.가동연료.Trim
                            Case "전기" '전기"
                                CRenew.Calc_HeatpumpSystem(system_type, 3, dr신재생, Q_w_outg_i, i_count_month, d_op_max_mth, t_h, theta_g_m, theta_i, Q_wp_outg, Q_w_f_hp, Q_w_g_hp_aux) '=============2010.04.01 수정 Q_h_outg 를 Q_h_outg_i 로 수정
                                Q_w_outg = Q_w_outg - Q_wp_outg
                                Q_w_outg_i = Q_w_outg_i - Q_wp_outg
                                use_Elec = use_Elec + (Q_w_f_hp + Q_w_g_hp_aux) * system_count '===========2013.08.18 수정
                                Q_w_f = Q_w_f + (Q_w_f_hp + Q_w_g_hp_aux) * system_count '============================2010.04.17 추가, 2013.08.18 수정
                            Case "천연가스" '천연가스"
                                CRenew.Calc_HeatpumpSystem(system_type, 3, dr신재생, Q_w_outg_i, i_count_month, d_op_max_mth, t_h, theta_g_m, theta_i, Q_wp_outg, Q_w_f_hp, Q_w_g_hp_aux) '=============2010.04.01 수정 Q_h_outg 를 Q_h_outg_i 로 수정
                                Q_w_outg = Q_w_outg - Q_wp_outg
                                Q_w_outg_i = Q_w_outg_i - Q_wp_outg
                                use_LNG = use_LNG + Q_w_f_hp * system_count '===========2013.08.18 수정
                                use_Elec = use_Elec + Q_w_g_hp_aux * system_count '===========2013.08.18 수정
                                Q_w_f = Q_w_f + (Q_w_f_hp + Q_w_g_hp_aux) * system_count '============================2010.04.17 추가, 2013.08.18 수정
                                '//요기맞죠 ^^?
                            Case "액화가스" '액화가스"
                                CRenew.Calc_HeatpumpSystem(system_type, 3, dr신재생, Q_w_outg_i, i_count_month, d_op_max_mth, t_h, theta_g_m, theta_i, Q_wp_outg, Q_w_f_hp, Q_w_g_hp_aux) '=============2010.04.01 수정 Q_h_outg 를 Q_h_outg_i 로 수정
                                Q_w_outg = Q_w_outg - Q_wp_outg
                                Q_w_outg_i = Q_w_outg_i - Q_wp_outg
                                use_LPG = use_LPG + Q_w_f_hp * system_count '===========2013.08.18 수정
                                use_Elec = use_Elec + Q_w_g_hp_aux * system_count '===========2013.08.18 수정
                                Q_w_f = Q_w_f + (Q_w_f_hp + Q_w_g_hp_aux) * system_count '============================2010.04.17 추가, 2013.08.18 수정
                        End Select



                End Select
                'End If
            End If

            '----------------------------------------------------------------------------------------------------------------------------------
            '----------------------------------------------------------------------------------------------------------------------------------
            '=========================================================================================================================2013.01.13 히트펌프 위치 수정

            If dr난방.열생산기기방식 = "히트펌프" Then

                pLog.Add("열생산기기방식-히트펌프진입")
                Q_dot_HP_waterheating = TOSG(dr난방.히트난방용량) ' Worksheets("난방기기").Range("히트펌프사용연료1").Offset(1, i_count_boiler - 1)
                COP_HP_7 = TOSG(dr난방.히트난방정격7) ' Worksheets("난방기기").Range("히트펌프사용연료1").Offset(2, i_count_boiler - 1)
                COP_HP_10 = TOSG(dr난방.히트난방정격10) ' Worksheets("난방기기").Range("히트펌프사용연료1").Offset(3, i_count_boiler - 1) ' 새로운 버전에서 15도로 입력값 수정
                L_HP_waterheating = TOSG(dr난방.히트배관길이) ' Worksheets("난방기기").Range("히트펌프사용연료1").Offset(4, i_count_boiler - 1)
                If theta_e > 15 Then
                    COP_HP_total = (COP_HP_7 - COP_HP_10) / 22 * 15 + COP_HP_7 - 7 * (COP_HP_7 - COP_HP_10) / 22
                Else
                    COP_HP_total = (COP_HP_7 - COP_HP_10) / 22 * theta_e + COP_HP_7 - 7 * (COP_HP_7 - COP_HP_10) / 22
                End If

                If theta_e < 7 Then

                    If theta_e >= 0 Then
                        COP_HP_total = TOSG(COP_HP_total * ((1 - 0.86) / 7 * theta_e + 0.86))
                    Else
                        COP_HP_total = TOSG(COP_HP_total * ((0.98 - 0.86) / 7 * (-theta_e) + 0.86))
                    End If

                End If

                If Q_dot_HP_waterheating <= 20 Then
                    COP_HP_total = TOSG(COP_HP_total * (1 - L_HP_waterheating * 0.002))
                Else
                    If Q_dot_HP_waterheating <= 100 Then
                        COP_HP_total = TOSG(COP_HP_total * (1 - L_HP_waterheating * 0.0009))
                    Else
                        COP_HP_total = TOSG(COP_HP_total * (1 - L_HP_waterheating * 0.0014))
                    End If
                End If

                Q_w_outg = Q_w_outg - Q_w_outg_i '===================================================2013.01.16 추가


                If Q_dot_HP_waterheating = 0 Or t_h = 0 Then '=============================================================2014.03.07 추가
                    Q_w_outg_i = 0
                Else
                    If Q_w_outg_i / (Q_dot_HP_waterheating * t_h) > 1 Or dr난방.히트펌프시스템종류 = "실내외분리시스템" Then
                        Q_w_outg_i = Q_w_outg_i / COP_HP_total
                    Else
                        Q_w_outg_i = Q_w_outg_i / (COP_HP_total * (Q_w_outg_i / (Q_dot_HP_waterheating * t_h) * 0.5 + 0.5))
                    End If

                End If                                       '=============================================================2014.03.07 추가

                Q_w_outg = Q_w_outg + Q_w_outg_i '===================================================2013.01.16 추가

                pLog.Add(String.Format("열생산기기방식-히트펌프완료 Q_w_outg={0}", Q_w_outg))

            End If

            '=========================================================================================================================2013.01.13 히트펌프 위치 수정

            Q_dot_N = TOSG(IIf(dr난방.보일러정격출력 = "", 0, dr난방.보일러정격출력)) 'Worksheets("난방기기").Range("난방기기정격출력1").Offset(0, i_count_boiler - 1)
            eta_k_100 = TOSG(IIf(dr난방.정격보일러효율 = "", 0, TOSG(dr난방.정격보일러효율))) / 100 ' Worksheets("난방기기").Range("난방기기정격효율1").Offset(0, i_count_boiler - 1) / 100

            'Select Case Worksheets("난방기기").Range("난방기기사용연료1").Offset(0, i_count_boiler - 1)
            'Case "난방유"
            'f_Hs_Hi = 1.06
            'Case "천연가스"
            'f_Hs_Hi = 1.11
            'Case "액화가스"
            'f_Hs_Hi = 1.09
            'Case "석탄"
            'f_Hs_Hi = 1.04
            'Case "갈탄"
            'f_Hs_Hi = 1.07
            'Case "나무"
            'f_Hs_Hi = 1.08
            'End Select
            f_Hs_Hi = 1 ' 국내는 총발열량을 기준으로 입력함으로 우선 1로 설정, 추후 검토

            If dr난방.열생산기기방식 = "보일러" Then ' Worksheets("난방기기").Range("열생산기기방식1").Offset(0, i_count_boiler - 1) = "보일러" Then

                pLog.Add("열생산기기방식-보일러진입")

                If d_Nutz_mth = 0 Or eta_k_100 = 0 Then '//201.11.20 추가(학교프로파일 적용시 문제점 해결) '==============2014.03.07 추가
                    Q_w_g_100 = 0
                Else
                    Q_w_g_100 = (f_Hs_Hi - eta_k_100) / eta_k_100 * Q_w_outg_i / d_Nutz_mth '(3.2.9-58)
                End If

                If d_Nutz_mth = 0 Or Q_dot_N = 0 Then '//201.11.20 추가(학교프로파일 적용시 문제점 해결) '=================2014.03.07 추가
                    t_w_100 = 0
                Else
                    t_w_100 = Q_w_outg_i / (Q_dot_N * d_Nutz_mth) '(3.2.9-61)
                End If

                Select Case dr난방.보일러방식.Trim ' Worksheets("난방기기").Range("보일러방식1").Offset(0, i_count_boiler - 1)
                    Case "가스보일러" '가스보일러"
                        q_B_70 = TOSG((8.5 * Q_dot_N ^ (-0.4)) / 100)

                    Case "기름보일러" '기름보일러"
                        q_B_70 = TOSG((8.5 * Q_dot_N ^ (-0.4)) / 100)

                    Case "저온가스보일러" '저온가스보일러"
                        q_B_70 = TOSG((4.5 * Q_dot_N ^ (-0.4)) / 100)

                    Case "저온기름보일러" '저온기름보일러"
                        q_B_70 = TOSG((4.25 * Q_dot_N ^ (-0.4)) / 100)

                    Case "콘덴싱보일러" '콘덴싱보일러"
                        q_B_70 = TOSG((4 * Q_dot_N ^ (-0.4)) / 100)
                    Case Else
                        MsgBox("난방.보일러방식을 알수없습니다", MsgBoxStyle.Critical, "값=" & dr난방.보일러방식)
                End Select

                q_B_theta = q_B_70 * (theta_g_m - theta_i) / (70 - 20) '(3.2.9-60)
                If eta_k_100 = 0 Then '===========================================2014.03.07 추가
                    Q_B_w = 0
                Else
                    Q_B_w = q_B_theta * Q_dot_N / eta_k_100 * (t_Nutz_d - t_w_100) * f_Hs_Hi '(3.2.9-59)
                End If                '===========================================2014.03.07 추가

                If theta_WA_Grenz - theta_e_min = 0 Then '====================================================2014.03.07 추가
                    f_L_WA = 1
                Else
                    f_L_WA = 1 - (theta_WA_Grenz - theta_e) / (theta_WA_Grenz - theta_e_min) '(3.2.7-22)
                End If                                   '====================================================2014.03.07 추가

                If d_mth = 0 Then
                    d_h_rB = 0
                Else
                    d_h_rB = d_mth * ((365 - f_L_WA * (365 - d_Nutz_a)) / 365) * (t_h / (d_mth * 24)) '(3.2.7-21)
                End If


                ':d_h_rB > d_Nutz_mth 일 경우
                If d_h_rB > d_Nutz_mth Then
                    d_Nutz_mth = CInt(d_h_rB)
                End If

                Q_w_g = Q_w_g + (Q_w_g_100 * d_Nutz_mth + Q_B_w * (d_Nutz_mth - d_h_rB)) * system_count '=====2013.08.13 수정 '(3.2.9-57)
                Q_w_g_i = Q_w_g_100 * d_Nutz_mth + Q_B_w * (d_Nutz_mth - d_h_rB)

                pLog.Add(String.Format("열생산기기방식-보일러완료 Q_w_g={0},Q_w_g_i={1}", Q_w_g, Q_w_g_i))     '===2017.02.26 당초 Q_w_g_i={1]" 을 Q_w_g_i={1}" 으로 오류 수정

            Else

                If dr난방.열생산기기방식 = "지역난방" Then ' Worksheets("난방기기").Range("열생산기기방식1").Offset(0, i_count_boiler - 1) = "지역난방" Then

                    pLog.Add("열생산기기방식-지역난방진입")

                    If dr난방.지역난방방식 = "중온수" Then ' Worksheets("난방기기").Range("지역난방온수방식1").Offset(0, i_count_boiler - 1) = "중온수" Then
                        D_DS = 0.6
                        theta_prim_DS = 105
                        'MsgBox("난방기기 단열등급에  등급2/3 등급3/4 등급 4/5 추가해야함")
                        Select Case dr난방.단열등급.Trim '  Dr난방.단열등급
                            Case "기본단열" '기본단열" '원래는 등급1/2 이지만 국내에서는 법적단열로 사용
                                B_DS = 4.9
                            Case "등급2/3" '등급2/3"
                                B_DS = 4.4
                            Case "등급3/4" '등급3/4"
                                B_DS = 4
                            Case "등급4/5" '등급4/5"
                                B_DS = 3.5
                        End Select
                    End If
                    'MsgBox("난방기기 지역난방방식에 고온수 0002 추가해야함") --추가는 했으나 엑셀에서는 중온수고정이다 그래서 하위 루틴은 실행되면안된다
                    If dr난방.지역난방방식 = "고온수" Then 'Worksheets("난방기기").Range("지역난방온수방식1").Offset(0, i_count_boiler - 1) = "고온수" Then
                        ' MsgBox("난방기기의 지역난방방식은 중온수 고정입니다.", MsgBoxStyle.Information, "확인")
                        D_DS = 0.4
                        theta_prim_DS = 150
                        Select Case dr난방.단열등급.Trim
                            Case "기본단열" '기본단열" '원래는 등급1/2 이지만 국내에서는 법적단열로 사용
                                B_DS = 4.3
                            Case "등급2/3" '등급2/3"
                                B_DS = 3.9
                            Case "등급3/4" '등급3/4"
                                B_DS = 3.5
                            Case "등급4/5" '등급4/5"
                                B_DS = 3.1
                        End Select
                    End If



                    theta_DS = D_DS * theta_prim_DS + (1 - D_DS) * 55 ' theta_sek_DS는 55도로 설정 (3.2.7-112)
                    Psi_DS = TOSG(dr난방.열교환기정격출력) ' .Worksheets("난방기기").Range("난방기기정격출력1").Offset(1, i_count_boiler - 1)
                    H_DS = TOSG(B_DS * Psi_DS ^ (1 / 3))
                    Q_w_g = Q_w_g + (H_DS * (theta_DS - theta_i)) * system_count '=====2013.08.13 수정
                    use_DH = use_DH + (H_DS * (theta_DS - theta_i)) * system_count '========2013.08.18 수정


                    pLog.Add(String.Format("열생산기기방식-지역난방완료 {0},{1}", Q_w_g, use_DH))
                End If

            End If

            ': 급탕 전기 보조에너지 시작

            Q_w_ce_aux = 0
            Q_w_g_aux = 0 '// 2014.01.08 추가

            P_Pump_w = TOSG(dr난방.펌프동력급탕) ' Worksheets("난방기기").Range("급탕펌프제어유형1").Offset(1, i_count_boiler - 1)
            Select Case dr난방.펌프제어.Trim 'Worksheets("난방기기").Range("급탕펌프제어유형1").Offset(0, i_count_boiler - 1)
                Case "비제어" '비제어"
                    c_p1 = 0.25
                    c_p2 = 0.94
                Case "제어" '제어"
                    c_p1 = 0.5
                    c_p2 = 0.63
                Case "(없음)"
                    c_p1 = 0
                    c_p2 = 0
                Case Else
                    MsgBox("[난방기가: " & dr난방.code & "] 알수없는 펌프제어방식(" & dr난방.펌프제어.Trim & ")", MsgBoxStyle.Critical, dr난방.펌프제어)


            End Select

            Q_w_d_aux = Q_w_d_aux + P_Pump_w / 1000 * d_Nutz_mth * t_Nutz_d * (c_p1 + c_p2) '(3.2.9-15)

            Select Case dr난방.축열탱크방식.Trim ' Worksheets("난방기기").Range("난방기기축열탱크1").Offset(0, i_count_boiler - 1)
                Case "전기가열식" '전기가열식"
                    'Q_w_s_aux = Q_w_s_aux + 0

                Case "가스가열식" '가스가열식"
                    'Q_w_s_aux = Q_w_s_aux + 0

                Case "간접가열식" '간접가열식"

                    '=================================================================================2010.10.19 추가
                    Select Case dr난방.열생산기기방식.Trim 'Worksheets("난방기기").Range("열생산기기방식1").Offset(0, i_count_boiler - 1)
                        Case "보일러"
                            t_P = TOSG(Q_w_outg_i * 1.1 / Q_dot_N) '(3.2.9-28)
                        Case "지역난방"
                            t_P = TOSG(Q_w_outg_i * 1.1 / TOSG(dr난방.열교환기정격출력))
                        Case "전기보일러"
                            t_P = 1
                        Case "히트펌프"
                            t_P = 1
                    End Select
                    '=================================================================================2010.10.19 추가
                    Q_w_s_aux = TOSG(Q_w_s_aux + 0.001 * P_Pump_w * t_P) '(3.2.9-27)

            End Select
            If dr난방.열생산기기방식 = "보일러" Then 'Worksheets("난방기기").Range("열생산기기방식1").Offset(0, i_count_boiler - 1) = "보일러" Then
                Select Case dr난방.보일러방식.Trim 'Worksheets("난방기기").Range("보일러방식1").Offset(0, i_count_boiler - 1)
                    Case "가스보일러" '가스보일러"
                        P_aux_100 = TOSG((0.148 * Q_dot_N + 40) / 1000) '(3.2.9-77)

                    Case "기름보일러" '기름보일러"
                        P_aux_100 = TOSG(0.045 * Q_dot_N ^ 0.48) '(3.2.9-78)

                    Case "저온가스보일러" '저온가스보일러"
                        P_aux_100 = TOSG((0.148 * Q_dot_N + 40) / 1000) '(3.2.9-79)

                    Case "저온기름보일러" '저온기름보일러"
                        P_aux_100 = TOSG(0.045 * Q_dot_N ^ 0.48) '(3.2.9-80)

                    Case "콘덴싱보일러" '콘덴싱보일러"
                        P_aux_100 = TOSG(0.045 * Q_dot_N ^ 0.48) '(3.2.9-81)

                End Select

                If d_Nutz_mth = 0 Or Q_dot_N = 0 Then '//201.11.20 추가(학교프로파일 적용시 문제점 해결) '================2014.03.07 추가
                    t_w_100 = 0
                Else
                    t_w_100 = Q_w_outg_i / (Q_dot_N * d_Nutz_mth) '(3.2.9-61)
                End If

                Q_w_g_aux = Q_w_g_aux + P_aux_100 * t_w_100 * d_Nutz_mth '+ P_aux_SB * (24 - t_w_100) * (d_Nutz_mth - d_h_rB) '(3.2.9-7)

            End If



            If dr난방.열생산기기방식 = "보일러" Then ' Then 'Worksheets("난방기기").Range("열생산기기방식1").Offset(0, i_count_boiler - 1) = "보일러" Then
                Select Case dr난방.사용연료.Trim '  Worksheets("난방기기").Range("난방기기사용연료1").Offset(0, i_count_boiler - 1)
                    Case "난방유" '난방유"
                        use_Oil = use_Oil + (Q_w_outg_i + Q_w_g_i) * system_count '========2013.08.18 수정

                    Case "천연가스" '천연가스"
                        use_LNG = use_LNG + (Q_w_outg_i + Q_w_g_i) * system_count '========2013.08.18 수정

                    Case "액화가스" '액화가스"
                        use_LPG = use_LPG + (Q_w_outg_i + Q_w_g_i) * system_count '========2013.08.18 수정

                End Select
            Else
                Select Case dr난방.열생산기기방식.Trim 'Worksheets("난방기기").Range("열생산기기방식1").Offset(0, i_count_boiler - 1)
                    Case "지역난방" '지역난방"
                        use_DH = use_DH + Q_w_outg_i * system_count '========2013.08.18 수정

                    Case "전기보일러" '전기보일러"
                        use_Elec = use_Elec + (Q_w_outg_i + (Q_w_outg_i * 0.09)) * system_count '========2013.08.18 수정 '2011.03.08 개별전기보일러 생산손실을 내부 생산식저장으로 설정
                        Q_w_outg = Q_w_outg + (Q_w_outg_i * 0.09) * system_count '========2013.11.6 수정

                        '====================================================================================2010.03.14 추가
                    Case "히트펌프"

                        Select Case dr난방.히트연료 ' Worksheets("난방기기").Range("히트펌프사용연료1").Offset(0, i_count_boiler - 1)
                            Case "전기"
                                use_Elec = use_Elec + (Q_w_outg_i + Q_w_g_i) * system_count '========2013.08.18 수정
                            Case "천연가스"
                                use_LNG = use_LNG + (Q_w_outg_i + Q_w_g_i) * system_count '========2013.08.18 수정
                            Case "액화가스"
                                use_LPG = use_LPG + (Q_w_outg_i + Q_w_g_i) * system_count '========2013.08.18 수정
                        End Select
                        '====================================================================================2010.03.14 추가

                End Select

            End If

            use_Elec = use_Elec + (Q_w_ce_aux + Q_w_d_aux + Q_w_s_aux + Q_w_g_aux + W_sol_aux) * system_count '========2013.08.18 수정
            Q_w_aux = Q_w_aux + (Q_w_ce_aux + Q_w_d_aux + Q_w_s_aux + Q_w_g_aux + W_sol_aux) * system_count '========2013.08.18 수정 '급탕보조에너지소요량 (3.2.9-7) 2011.03.23 추가

            pLog.Add(String.Format("급탕개별기기적용시 완료 : use_ele={0},q_w_aux={1}", use_Elec, Q_w_aux))
        Next '//for zonerow

    End Sub


    '//i_ce As Integer 제거함 사용안됨
    Dim i_count_beta As Integer
    Dim Q_h_f As Decimal, Q_h_outg As Decimal, Q_h_g As Decimal
    Dim Q_h_b As Decimal, Q_h_b_i As Decimal, Q_h_ce As Decimal, Q_h_ce_i As Decimal, Q_dot_h_max As Decimal, Q_h_d As Decimal, Q_h_s As Decimal
    Dim f_hydr As Decimal, f_int As Decimal, f_Radiant As Decimal
    Dim beta_k_pl As Decimal, beta_k_100 As Decimal, n As Decimal, t_h_op_d As Integer, n_beta As Integer
    Dim theta_i_h_soll As Decimal, theta_VA As Decimal, theta_RA As Decimal
    Dim e As Decimal, f As Decimal, Q_V_g_100 As Decimal, Q_V_g_pl As Decimal, Q_h_g_v_i As Decimal
    Dim Q_h_ce_aux As Decimal, Q_h_d_aux As Decimal, Q_h_d_aux_i As Decimal, beta_h_s As Decimal, Q_h_s_aux As Decimal, Q_h_g_aux As Decimal, P_h_g_aux As Decimal, P_aux_pl As Decimal, P_aux_SB As Decimal
    Dim eta_L As Decimal, eta_B As Decimal, eta_C As Decimal, eta_h_ce As Decimal, beta_h_d As Decimal, beta_h As Decimal
    Dim theta_VL_m_beta_h_d As Decimal, theta_RL_m_beta_h_d As Decimal, theta_HK_m_beta_h_d As Decimal, eta_k_pl As Decimal
    Dim f_L_NA As Decimal, t_h_rL_T As Decimal, t_h_rL As Decimal
    Dim Q_dot_d_in As Decimal, Q_dot_B_h As Decimal, Q_h_g_i As Decimal
    Dim P_Pump As Decimal, f_P_A As Decimal
    Dim P_C As Decimal, P_V As Decimal, P_P As Decimal, n_V As Decimal, n_P As Decimal, Q_V_P As Decimal, Q_c As Decimal, Q_h_aux As Decimal
    Dim t_h_max As Integer
    Dim Q_h_CHP As Decimal, Q_h_f_CHP As Decimal
    Dim i_HeatCool As Integer, Q_hp_outg As Decimal, Q_h_f_hp As Decimal, Q_h_g_hp_aux As Decimal
    Dim Q_dot_HP_heating As Decimal, L_HP_heating As Decimal  '=======================2010.03.14 추가
    Dim U_i As Decimal

    Dim a_Q_h_b_i As Decimal = 0
    Dim a_Q_dot_h_max As Decimal = 0
    Dim a_t_h_max As Decimal = 0
    Dim a_t_h_op_d As Decimal = 0
    Dim a_d_op_mth As Decimal = 0
    Dim priod_value As Single = 0
    Dim age As Decimal = 1 '//준공연도에 의한 경년변화값
    Dim age_heating As Decimal = 1

    Public Overridable Sub Calc_HeatingSystem(ByVal i_count_month As Integer, ByVal theta_e As Decimal)

        pLog.Add(String.Format("Enter >> Calc_HeatingSystem i_count_month={0},theta_e={1}", i_count_month, theta_e))
       
        d_op_max_mth = 0
        '==================================2010.2.21 수정

     
        'For Each DRpriod As DS.tbl_DescRow In DSET.tbl_Desc.Select("cname<>'0'", "cname")
        '    priod_value = CSng(DRpriod.priod)
        'Next
        'If priod_value > 20 Then priod_value = 20
        'age = (1 - 0.01) ^ priod_value
        'age_heating = (1 - 0.005) ^ priod_value

        '==================================2013.08.18 추가

        'Dim system_count_check As Integer '체크여부 리턴값 확인 필요
        'Dim header_check As Integer '체크여부 리턴값 확인 필요

        U_i = 0D
        theta_NA_Grenz = 10
        theta_WA_Grenz = 10
        beta_k_pl = 0.3
        beta_k_100 = 1
        f_verbindung = 1.2 '동일공간의 경우임, 타공간의 경우 (3.2.7-36) 참조
        f_hydr = 1 '리버스리턴 계수로 지금은 1로 적용, 추후 검토
        f_int = 1 ' 간헐(0.97-0.98), 지속 1 우선 1로 적용, 추후 검토
        f_verbindung = 1.2
        theta_i_h_soll = 20
        theta_i = 13 ' 비난방공간으로 가정
        n = 1.33 '라디에이터 1.33, 바닥난방 1.1, 우선 라디에이터 적용
        theta_e_min = -11.3
        d_Nutz_a = 365 '연간이용일수 우선 연중가동으로 적용
        Q_h_outg = 0
        'd_Nutz_mth = d_mth ' 연중가동으로 계산 추후 검토  '================2010.2.21 수정
        Q_h_g = 0
        Q_h_ce_aux = 0
        Q_h_d_aux = 0
        Q_h_s_aux = 0
        Q_h_g_aux = 0
        use_Oil = 0
        use_LNG = 0
        use_LPG = 0
        use_Elec = 0
        use_DH = 0
        Q_h_outg = 0
        Q_w_outg = 0
        Q_h_CHP = 0
        Q_h_f_CHP = 0
        i_HeatCool = 1
        Q_hp_outg = 0
        Q_h_f_hp = 0
        Q_h_g_hp_aux = 0
        W_sol_aux = 0
        system_type = 1
        Q_h_f = 0 '===============================2010.04.17 추가
        t_Nutz_d = 24 '==========================2010.04.24 추가

        '======================2013.01.13 추가
        system_count = 1
        '======================2013.01.13 추가

        '//각달별로데이터를 초기화(131020-arin)
        Q_h_aux = 0
        use_Elec = 0
        use_Oil = 0
        use_LNG = 0
        use_LPG = 0
        use_DH = 0
        use_Elec = 0

        a_Q_h_b_i = 0
        a_Q_dot_h_max = 0
        a_t_h_max = 0
        a_t_h_op_d = 0
        a_d_op_mth = 0
        priod_value = 0
        age = 1 '//준공연도에 의한 경년변화값
        age_heating = 1



        Dim Mon As String = "M" & Format(i_count_month, "00")

        '//130822
        Dim 보일러정격출력합 As Decimal = 0    '//acc
        
        For Each Dr난방 As DS.tbl_nanbangkikiRow In DSET.tbl_nanbangkiki.Select("code<>'0' and 헤더적용=true", "code")

            '=======================================================================================================2014.02.24 수정
            Select Case Dr난방.열생산기기방식.Trim.ToUpper
                Case "보일러"
                    보일러정격출력합 += TOSG(Dr난방.보일러정격출력)
                Case "지역난방"
                    보일러정격출력합 += TOSG(Dr난방.열교환기정격출력)
                Case "히트펌프"
                    보일러정격출력합 += TOSG(Dr난방.히트난방용량)
                Case "전기보일러"
                    보일러정격출력합 += TOSG(Dr난방.보일러정격출력)
            End Select
            '=======================================================================================================2014.02.24 수정


            For Each DR존 As DS.tbl_zoneRow In DSET.tbl_zone.Select("(공조난방생산기기 = '" & Dr난방.code & "' and 냉난방공조 <> '기능없음' and (외기부하처리여부 = '예' or 냉난방공조 = '냉난방' or 냉난방공조 = '난방') ) or (열생산난방생산기기='" & Dr난방.code & "'  and 냉난방방식 <> '냉방' and 냉난방방식 <> '기능없음') and code <> '0'") ' For i_count_zone = 1 To DSET.tbl_zone.Rows.Count
                Dim 판단1 As Boolean = False
                Dim 판단2 As Boolean = False
                If DR존.열생산난방생산기기 = Dr난방.code Then 판단1 = True
                If DR존.공조난방생산기기 = Dr난방.code Then 판단2 = True

                If 판단1 And (DR존.냉난방방식 = "냉난방" OrElse DR존.냉난방방식 = "난방") Then
                    Dim Dr월에너지 As DSR.월별에너지분석Row = CType(DSETR.월별에너지분석.Select("월='" & Mon & "' and 존='" & DR존.code & "'")(0), DSR.월별에너지분석Row)
                    Dim Drow최대() As DSR.최대냉난방부하Row = CType(DSETR.최대냉난방부하.Select("Zone='" & DR존.code & "'"), DSR.최대냉난방부하Row())

                    system_count = IIf(Dr난방.개별기기적용 = "0", 1, TOSG(DR존.입력존의수)) '===========2013.08.18 추가
                    If system_count = 0 Then system_count = 1


                    If (DR존.냉난방공조 = "환기" OrElse DR존.냉난방공조 = "냉방") And DR존.외기부하처리여부 = "예" Then
                        a_Q_h_b_i += TOSG(Dr월에너지.난방요구량열) / system_count '===========2012.08.18 수정
                    Else
                        a_Q_h_b_i += TOSG(Dr월에너지.난방요구량열 + Dr월에너지.난방요구량공조) / system_count '===========2012.08.18 수정 ' Sheets("" & i_count_month & "").Cells(7, 7 + i_count_zone)
                    End If
                    '=========================================================================================================================================================2010.2.21 수정
                    a_Q_dot_h_max += TOSG(Drow최대(0).최대난방기기부하) ' Worksheets("0").Range("최대난방부하1").Offset(0, i_count_zone - 1)

                    '===================================================================================2010.2.21 수정
                    Dim DR프로필 As DS.tbl_profileRow = CType(DSET.tbl_profile.Select("code='" & DR존.프로필 & "' and code <> '0'")(0), DS.tbl_profileRow)
                    If i_count_month = 0 Then
                        d_op_mth = 0
                    Else
                        d_op_mth = CInt(TOSG(DR프로필("day" & Format(i_count_month, "00"))))
                    End If
                    If t_h < TOSG(Drow최대(0).난방최대가동시간) * d_op_mth Then
                        t_h = CInt(TOSG(Drow최대(0).난방최대가동시간) * d_op_mth)
                    End If
                    If d_op_max_mth < d_op_mth Then d_op_max_mth = d_op_mth
                    '===================================================================================2010.2.21 수정
                    If t_h > t_h_max Then t_h_max = t_h
                    If t_h_op_d < TOSG(Drow최대(0).난방최대가동시간) Then t_h_op_d = CInt(TOSG(Drow최대(0).난방최대가동시간)) ' Sheets("0").Range("최대난방부하1").Offset(2, i_count_zone - 1)

                    '//acc
                    If d_op_max_mth > a_d_op_max_mth Then a_d_op_max_mth = d_op_max_mth
                    If t_h > a_t_h Then a_t_h = t_h
                    If t_h_max > a_t_h_max Then a_t_h_max = t_h_max
                    If t_h_op_d > a_t_h_op_d Then a_t_h_op_d = t_h_op_d
                End If  '//판단1

                If DR존.냉난방공조 = "냉난방" OrElse DR존.냉난방공조 = "난방" OrElse ((DR존.냉난방공조 = "환기" OrElse DR존.냉난방공조 = "냉방") And DR존.외기부하처리여부 = "예") Then ' 공조기 사용에 따른 난방에너지
                    '=========================================================================================================================================================2010.2.21 수정
                    system_count = IIf(Dr난방.개별기기적용 = "0", 1, TOSG(DR존.입력존의수))   '//20130818
                    If system_count = 0 Then system_count = 1

                    If 판단2 Then

                        Dim 월에너지분석 As DSR.월별에너지분석Row = CType(DSETR.월별에너지분석.Select("월='" & Mon & "' and 존='" & DR존.code & "'")(0), DSR.월별에너지분석Row)
                        If (DR존.냉난방공조 = "환기" OrElse DR존.냉난방공조 = "냉방") And DR존.외기부하처리여부 = "예" Then '// 2010.11.19 추가
                            a_Q_h_b_i += TOSG(월에너지분석.난방요구량공조) / system_count '=========2013.08.18 수정
                        Else
                            a_Q_h_b_i += TOSG(월에너지분석.공조요구량난방) / system_count '=========2013.08.18 수정 ' Sheets("" & i_count_month & "").Cells(19, 7 + i_count_zone)
                        End If

                        '//
                        Dim Drow최대() As DSR.최대냉난방부하Row = CType(DSETR.최대냉난방부하.Select("zone='" & DR존.code & "'"), DSR.최대냉난방부하Row())
                        Dim Dr프로필 As DS.tbl_profileRow = CType(DSET.tbl_profile.Select("code='" & DR존.프로필 & "' and code <> '0'")(0), DS.tbl_profileRow)
                        Q_dot_h_max = TOSG(Q_dot_h_max + TOSG(Drow최대(0).최대난방기기부하)) / system_count '=====2013.08.18 수정 ' Worksheets("0").Range("최대난방부하1").Offset(0, i_count_zone - 1)

                        If i_count_month = 0 Then
                            d_op_mth = 0
                        Else
                            d_op_mth = CInt(TOSG(Dr프로필("day" & Format(i_count_month, "00"))))
                        End If
                        If t_h < TOSG(Drow최대(0).난방최대가동시간) * d_op_mth Then
                            t_h = CInt(TOSG(Drow최대(0).난방최대가동시간) * d_op_mth)
                        End If
                        If d_op_max_mth < d_op_mth Then
                            d_op_max_mth = d_op_mth
                        End If
                        If t_h > t_h_max Then
                            t_h_max = t_h
                        End If
                        If t_h_op_d < TOSG(Drow최대(0).난방최대가동시간) Then
                            t_h_op_d = CInt(TOSG(Drow최대(0).난방최대가동시간)) ' Sheets("0").Range("최대난방부하1").Offset(2, i_count_zone - 1)
                        End If

                        '//acc
                        If Q_dot_h_max > a_Q_dot_h_max Then a_Q_dot_h_max = Q_dot_h_max
                        If d_op_mth > a_d_op_mth Then a_d_op_mth = d_op_mth
                        If t_h > a_t_h Then a_t_h = t_h
                        If d_op_max_mth > a_d_op_max_mth Then a_d_op_max_mth = d_op_max_mth
                        If t_h_max > a_t_h_max Then a_t_h_max = t_h_max
                        If t_h_op_d > a_t_h_op_d Then a_t_h_op_d = t_h_op_d
                    End If
                End If
            Next
        Next


        For Each Dr난방 As DS.tbl_nanbangkikiRow In DSET.tbl_nanbangkiki.Select("code<>'0'", "code")

            Dim 비율 As Decimal
            If 보일러정격출력합 = 0 Then
                비율 = 1
            Else

                '=======================================================================================================2014.02.24 수정
                Select Case Dr난방.열생산기기방식.Trim.ToUpper
                    Case "보일러"
                        비율 = Dr난방.보일러정격출력 / 보일러정격출력합
                    Case "지역난방"
                        비율 = Dr난방.열교환기정격출력 / 보일러정격출력합
                    Case "히트펌프"
                        비율 = Dr난방.히트난방용량 / 보일러정격출력합
                    Case "전기보일러"
                        비율 = Dr난방.보일러정격출력 / 보일러정격출력합
                End Select
                '=======================================================================================================2014.02.24 수정

            End If

            If Dr난방.개별기기적용 = "1" Then
                Calc_난방_개별기기적용시(Dr난방, Mon, 비율, i_count_month, theta_e)
            Else
                Calc_난방_개별기기미적용시(Dr난방, Mon, 비율, i_count_month, theta_e)
            End If

        Next

        '//에너지소요량 - 에너지소요량분석 - 난방에너지소요량
        Q_h_f = Q_h_f + Q_h_outg + Q_h_g '- Q_h_reg '(3.2.7-4)신재생에너지는 추후 추가 '===================2010.04.17 수정

        'DSETR.TReqUse.Rows(CEnum.ResultRow.난방에너지소요량)(Mon) = Q_h_f        'Sheets("계산결과").Cells(39, 7 + i_count_month) = Q_h_f
        Result.E소요량(i_count_month).난방 = Q_h_f

        ': 난방 전기 보조에너지 연결
        For Each dr존 As DS.tbl_zoneRow In DSET.tbl_zone.Select("냉난방열공급시스템<>'0' and code<>'0'", "code")
            'If dr존.열생산난방생산기기 <> "0" Or dr존.냉난방열공급시스템 <> "0" Then 'dr존.냉난방열공급시스템 <> "" Then

            system_count = TOSG(dr존.입력존의수) '===========2013.08.18 추가

            Dim Dr프로필 As DS.tbl_profileRow = CType(DSET.tbl_profile.Select("code='" & dr존.프로필 & "' and code <> '0'")(0), DS.tbl_profileRow)
            If i_count_month = 0 Then
                d_op_mth = 0
            Else
                d_op_mth = CInt(Dr프로필("day" & Format(i_count_month, "00")))
            End If

            For Each Dr공급 As DS.tbl_kongkubRow In DSET.tbl_kongkub.Select("code='" & dr존.냉난방열공급시스템 & "' and code <> '0'", "code")
                '===================================================================================2010.2.21 수정
                t_h = CInt(TOSG(Result.최대부하.Item(dr존.code).일일난방최대가동시간) * d_op_mth)
                If theta_WA_Grenz - theta_e_min = 0 Then '=============================================2014.03.07 추가
                    f_L_WA = 1
                Else
                    f_L_WA = 1 - (theta_WA_Grenz - theta_e) / (theta_WA_Grenz - theta_e_min) '(3.2.7-22)
                End If                                   '=============================================2014.03.07 추가


                If d_op_mth = 0 Then '//201.11.20 추가(학교프로파일 적용시 문제점 해결)
                    d_h_rB = 0
                Else
                    d_h_rB = TOSG(d_op_mth * ((365 - f_L_WA * (365 - d_Nutz_a)) / 365) * (t_h / (d_op_mth * 24))) '(3.2.7-21)
                End If
                t_h_op_d = CInt(TOSG(Result.최대부하.Item(dr존.code).일일난방최대가동시간))

                If theta_NA_Grenz - theta_e_min = 0 Then '=============================================2014.03.07 추가
                    f_L_NA = 1
                Else
                    f_L_NA = 1 - (theta_NA_Grenz - theta_e) / (theta_NA_Grenz - theta_e_min) '(3.2.7-20)
                End If                                   '=============================================2014.03.07 추가



                t_h_rL_T = 24 - f_L_NA * (24 - t_h_op_d) '(3.2.7-19)
                t_h_rL = t_h_rL_T * d_h_rB '(3.2.7-23)

                P_C = TOSG(Dr공급.제어기의정격전력) ' Worksheets("난방공급시스템").Range("난방공급제어전력1").Offset(0, i_count_ce - 1)
                P_V = TOSG(Dr공급.팬송풍기정격전력) 'Worksheets("난방공급시스템").Range("난방공급제어전력1").Offset(1, i_count_ce - 1)
                P_P = TOSG(Dr공급.펌프정격전력) 'Worksheets("난방공급시스템").Range("난방공급제어전력1").Offset(2, i_count_ce - 1)
                n_V = TOSG(Dr공급.팬송풍기수) ' Worksheets("난방공급시스템").Range("난방공급팬1").Offset(0, i_count_ce - 1)
                n_P = TOSG(Dr공급.추가펌프수) 'Worksheets("난방공급시스템").Range("난방공급팬1").Offset(1, i_count_ce - 1)
                Q_V_P = ((P_V * n_V + P_P * n_P) * t_h_rL) / 1000 '(3.2.7-34)
                Q_c = P_C * d_op_mth * 24 / 1000 '(3.2.7-33)
                Q_h_ce_aux = Q_h_ce_aux + (Q_c + Q_V_P) * TOSG(dr존.냉난방열공급시스템수) * system_count ' Worksheets("입력존").Range("입력난방공급기기1").Offset(1, i_count_zone - 1) '(3.2.7-32) '////2012.07.08 입력존의 수 추가
            Next

            'End If
        Next


        Q_h_aux = Q_h_ce_aux + Q_h_d_aux + Q_h_s_aux + Q_h_g_aux + W_sol_aux '(3.2.7-5) 난방보조에너지소요량
        'DSETR.TReqUse.Rows(CEnum.ResultRow.난방보조에너지소요량)(Mon) = Q_h_aux 'Sheets("계산결과").Cells(41, 7 + i_count_month) = Q_h_aux
        Result.E소요량(i_count_month).난방보조 = Q_h_aux
        use_Elec = use_Elec + Q_h_ce_aux + Q_h_d_aux + Q_h_s_aux + Q_h_g_aux + W_sol_aux

        '//연간 Co2 배출량 - 난방에너지소요량
        Result.일차E소요량(i_count_month).난방등유 = use_Oil
        Result.일차E소요량(i_count_month).난방LNG = use_LNG
        Result.일차E소요량(i_count_month).난방LPG = use_LPG
        Result.일차E소요량(i_count_month).난방지역 = use_DH
        Result.일차E소요량(i_count_month).난방전력 = use_Elec

        pLog.Add(String.Format("q_h_aux={0},난방등유={1},LNG={2},LPG={3},지역={4},전력={5}", Q_h_aux, use_Oil, use_LNG, use_LPG, use_DH, use_Elec))

    End Sub

    Private Sub Calc_난방_개별기기미적용시(dr난방 As DS.tbl_nanbangkikiRow, mon As String, 비율 As Decimal, i_count_month As Integer, theta_e As Decimal)

        pLog.Add(" >> Enter : Calc_난방_개별기기미적용시")

        '//이 난방기기가 존전체내역에서 사용이되엇나?
        If DSET.tbl_zone.Select("(공조난방생산기기 = '" & dr난방.code & "' and 냉난방공조 <> '기능없음' and (외기부하처리여부 = '예' or 냉난방공조 = '냉난방' or 냉난방공조 = '난방') ) or (열생산난방생산기기='" & dr난방.code & "'  and 냉난방방식 <> '냉방' and 냉난방방식 <> '기능없음') ").GetUpperBound(0) <> -1 Then 'If Worksheets("난방기기").Range("난방생산기기1").Offset(4, i_count_boiler - 1) = "예" Then
            '"(공조난방생산기기 = '" & Dr난방.code & "' and 냉난방공조 <> '기능없음' and (외기부하처리여부 = '예' or 냉난방공조 = '냉난방' or 냉난방공조 = '난방') ) or (열생산난방생산기기='" & Dr난방.code & "'  and 냉난방방식 <> '냉방' and 냉난방방식 <> '기능없음') "
            Q_h_b = 0
            Q_h_ce = 0
            Q_dot_h_max = 0
            t_h_max = 0
            t_h = 0   '원래 식은 t_h = t_h_op + t_h_we 월간 난방 시간
            t_h_op_d = 0
            Q_h_d = 0
            Q_h_s = 0
            n_beta = 0 ' 순차가동시 full 부하 대수
            Q_h_g_v_i = 0
            '==================================2010.2.21 수정
            d_op_max_mth = 0
            d_Nutz_mth = 0
            '==================================2010.2.21 수정

            For Each DR존 As DS.tbl_zoneRow In DSET.tbl_zone.Select("(공조난방생산기기 = '" & dr난방.code & "' and 냉난방공조 <> '기능없음' and (외기부하처리여부 = '예' or 냉난방공조 = '냉난방' or 냉난방공조 = '난방') ) or (열생산난방생산기기='" & dr난방.code & "'  and 냉난방방식 <> '냉방' and 냉난방방식 <> '기능없음') and code <> '0'") ' For i_count_zone = 1 To DSET.tbl_zone.Rows.Count

                '//지금 사용하는 존이 공조에의한것인지 아닌지를 판단
                Dim 판단1 As Boolean = False
                Dim 판단2 As Boolean = False
                If DR존.열생산난방생산기기 = dr난방.code Then 판단1 = True
                If DR존.공조난방생산기기 = dr난방.code Then 판단2 = True

                '//다시 생각을...

                'If Worksheets("입력존").Range("입력난방생산기기1").Offset(0, i_count_zone - 1) <> "" And Worksheets("입력존").Range("입력난방생산기기1").Offset(0, i_count_zone - 1) = Worksheets("난방기기").Range("난방생산기기1").Offset(0, i_count_boiler - 1) Then
                '  If DR존.열생산난방생산기기 = Dr난방.code Then ' Worksheets("난방기기").Range("난방생산기기1").Offset(0, i_count_boiler - 1) Then
                '=========================================================================================================================================================2010.2.21 수정
                '1105 소스백업 If DR존.냉난방방식 = "냉난방" OrElse DR존.냉난방방식 = "난방" Then ' Worksheets("입력존").Range("공조존2").Offset(0, i_count_zone - 1) <> "냉난방" Then
                If 판단1 And (DR존.냉난방방식 = "냉난방" OrElse DR존.냉난방방식 = "난방") Then
                    Dim Dr월에너지 As DSR.월별에너지분석Row = CType(DSETR.월별에너지분석.Select("월='" & mon & "' and 존='" & DR존.code & "'")(0), DSR.월별에너지분석Row)
                    Dim Drow최대() As DSR.최대냉난방부하Row = CType(DSETR.최대냉난방부하.Select("Zone='" & DR존.code & "'"), DSR.최대냉난방부하Row())

                    system_count = 1 'IIf(dr난방.개별기기적용 = "0", 1, TOSG(DR존.입력존의수)) '===========2013.08.18 추가

                    'If dr난방.헤더적용 Then
                    '    'Q_h_b_i = a_Q_h_b_i
                    '    'Q_h_b_i *= 비율 '//130818
                    '    'Q_h_b = Q_h_b_i
                    '    'Q_dot_h_max = a_Q_dot_h_max
                    'Else
                    If (DR존.냉난방공조 = "환기" OrElse DR존.냉난방공조 = "냉방") And DR존.외기부하처리여부 = "예" Then
                        Q_h_b_i = TOSG(Dr월에너지.난방요구량열) / system_count '===========2012.08.18 수정
                    Else
                        Q_h_b_i = TOSG(Dr월에너지.난방요구량열 + Dr월에너지.난방요구량공조) / system_count '===========2012.08.18 수정 ' Sheets("" & i_count_month & "").Cells(7, 7 + i_count_zone)
                    End If
                    Q_h_b = Q_h_b + Q_h_b_i
                    '=========================================================================================================================================================2010.2.21 수정
                    Q_dot_h_max = TOSG(Q_dot_h_max + TOSG(Drow최대(0).최대난방기기부하)) ' Worksheets("0").Range("최대난방부하1").Offset(0, i_count_zone - 1)
                    'End If



                    '===================================================================================2010.2.21 수정
                    'If dr난방.헤더적용 Then
                    '    d_op_mth = a_d_op_mth
                    '    t_h = a_t_h
                    '    d_op_max_mth = a_d_op_max_mth
                    '    t_h_max = a_t_h_max
                    '    t_h_op_d = a_t_h_op_d
                    'Else
                    Dim DR프로필 As DS.tbl_profileRow = CType(DSET.tbl_profile.Select("code='" & DR존.프로필 & "' and code <> '0'")(0), DS.tbl_profileRow)
                    If i_count_month = 0 Then
                        d_op_mth = 0
                    Else
                        d_op_mth = CInt(TOSG(DR프로필("day" & Format(i_count_month, "00"))))
                    End If

                    If t_h < TOSG(Drow최대(0).난방최대가동시간) * d_op_mth Then
                        t_h = CInt(TOSG(Drow최대(0).난방최대가동시간) * d_op_mth)
                    End If
                    If d_op_max_mth < d_op_mth Then
                        d_op_max_mth = d_op_mth
                    End If
                    '===================================================================================2010.2.21 수정
                    If t_h > t_h_max Then t_h_max = t_h
                    If t_h_op_d < TOSG(Drow최대(0).난방최대가동시간) Then t_h_op_d = CInt(TOSG(Drow최대(0).난방최대가동시간)) ' Sheets("0").Range("최대난방부하1").Offset(2, i_count_zone - 1)
                    'i_ce = 0
                    'End If

                    '//아래 if 문이 모두 공급기기 데이터를 가지고 게산을 하고잇네요 이 부분을 전부 실행못하게 해야합니다.
                    If DR존.냉난방열공급시스템 = "0" Then
                        '//0일떄 특정 변수를 초기화(=0) 하려면 이곳에 입력하세요.
                    Else

                        Dim Dr공급 As DS.tbl_kongkubRow = CType(DSET.tbl_kongkub.Select("code='" & DR존.냉난방열공급시스템 & "' and code <> '0'")(0), DS.tbl_kongkubRow)

                        If (DR존.천장고 = "" OrElse TOSG(DR존.천장고) < 4) Then ' Worksheets("입력존").Range("천장고1").Offset(0, i_count_zone - 1) < 4 Then

                            Select Case Dr공급.열공급시스템.Trim '  Dr공급.열공급시스템
                                Case "노출형방열기(열)" '노출형방열기(열)"
                                    eta_L = (0.93 + 0.95) / 2
                                    eta_B = 1
                                    Select Case Dr공급.노출형제어.Trim 'Dr공급.노출형제어
                                        Case "비제어" '비제어"
                                            eta_C = 0.8
                                        Case "on/off제어"
                                            eta_C = 0.88
                                        Case "PI제어" 'PI제어"
                                            eta_C = 0.97
                                    End Select
                                Case "바닥난방(열)" '바닥난방(열)"
                                    eta_L = 1
                                    Select Case Dr공급.바닥난방열제어.Trim ' Dr공급.바닥난방열제어
                                        Case "비제어" '비제어"
                                            eta_C = 0.78
                                        Case "on/off제어"
                                            eta_C = 0.88
                                        Case "PI제어" 'PI제어"
                                            eta_C = 0.95
                                    End Select
                                    Select Case Dr공급.바닥난방열건축부위.Trim ' Worksheets("난방공급시스템").Range("바닥열시스템1").Offset(0, i_ce - 1)
                                        Case "습식" '습식"
                                            eta_B = (0.93 + 0.95) / 2
                                        Case "반건식" '반건식"
                                            eta_B = (0.95 + 0.95) / 2
                                        Case "건식" '건식"
                                            eta_B = (0.98 + 0.95) / 2
                                    End Select
                                Case "바닥난방(전기)" '바닥난방(전기)"
                                    eta_L = 1
                                    Select Case Dr공급.바닥난방전기제어.Trim ' Dr공급.바닥난방전기제어
                                        Case "비제어" '비제어"
                                            eta_C = 0.91
                                        Case "on/off제어"
                                            eta_C = 0.93 '2011.05.03  추가, 우선 on/off 제어와 PI제어를 같게 적용, 추후검토
                                        Case "PI제어" 'PI제어"
                                            eta_C = 0.93
                                    End Select
                                    Select Case Dr공급.바닥난방전기건축부위.Trim ' Worksheets("난방공급시스템").Range("바닥전기시스템1").Offset(0, i_ce - 1)
                                        Case "습식" '습식"
                                            eta_B = (0.93 + 0.95) / 2
                                        Case "반건식" '반건식"
                                            eta_B = (0.95 + 0.95) / 2
                                        Case "건식" '건식"
                                            eta_B = (0.98 + 0.95) / 2
                                    End Select
                                Case "전기난방" '전기난방"
                                    eta_L = 2 ' eta_h_ce 값을 맞추기 위해서 임의로 설정한 값(전기난방은 eta_h_ce 값이 바로 정해지기때문)
                                    eta_B = 2 ' eta_h_ce 값을 맞추기 위해서 임의로 설정한 값(전기난방은 eta_h_ce 값이 바로 정해지기때문)
                                    Select Case Dr공급.전기난방제어.Trim ' Dr공급.바닥난방전기제어
                                        Case "비제어"
                                            eta_C = -1.1235955 '2011.05.03 추가, 우선 on/off 제어와 비제어를 같게 적용, 추후검토
                                        Case "on/off제어"
                                            eta_C = -1.1235955 ' eta_h_ce 0.89 값을 맞추기 위해서 임의로 설정한 값(전기난방은 eta_h_ce 값이 바로 정해지기때문)
                                        Case "PI제어" 'PI제어"
                                            eta_C = -1.07527 ' eta_h_ce 0.93 값을 맞추기 위해서 임의로 설정한 값(전기난방은 eta_h_ce 값이 바로 정해지기때문)
                                    End Select
                            End Select
                            f_Radiant = 1
                        Else
                            If TOSG(DR존.천장고) >= 4 And TOSG(DR존.천장고) < 10 Then

                                Select Case Dr공급.열공급시스템.Trim '  Dr공급.열공급시스템
                                    Case "노출형방열기(열)" '노출형방열기(열)"
                                        f_Radiant = 1
                                        eta_L = 0.9
                                        eta_B = 1
                                        Select Case Dr공급.노출형제어.Trim 'Dr공급.노출형제어
                                            Case "비제어" '비제어"
                                                eta_C = 0.8
                                            Case "on/off제어"
                                                eta_C = 0.93
                                            Case "PI제어" 'PI제어"
                                                eta_C = 0.97
                                        End Select
                                    Case "바닥난방(열)" '바닥난방(열)"
                                        f_Radiant = 0.85
                                        eta_L = 0.98
                                        Select Case Dr공급.바닥난방열제어.Trim ' Dr공급.바닥난방열제어
                                            Case "비제어" '비제어"
                                                eta_C = 0.8
                                            Case "on/off제어"
                                                eta_C = 0.93
                                            Case "PI제어" 'PI제어"
                                                eta_C = 0.97
                                        End Select
                                        eta_B = 0.95
                                    Case "바닥난방(전기)" '바닥난방(전기)"
                                        f_Radiant = 0.85
                                        eta_L = 0.98
                                        Select Case Dr공급.바닥난방전기제어.Trim ' Dr공급.바닥난방전기제어
                                            Case "비제어" '비제어"
                                                eta_C = 0.8
                                            Case "on/off제어"
                                                eta_C = 0.93
                                            Case "PI제어" 'PI제어"
                                                eta_C = 0.97
                                        End Select
                                        eta_B = 0.95
                                    Case "전기난방" '전기난방"
                                        f_Radiant = 1
                                        eta_L = 0.935
                                        eta_B = 1
                                        Select Case Dr공급.바닥난방전기제어.Trim ' Dr공급.바닥난방전기제어
                                            Case "비제어" '비제어"
                                                eta_C = 0.8
                                            Case "on/off제어"
                                                eta_C = 0.93
                                            Case "PI제어" 'PI제어"
                                                eta_C = 0.97
                                        End Select
                                End Select
                            Else


                                Select Case Dr공급.열공급시스템.Trim
                                    Case "노출형방열기(열)" '노출형방열기(열)"
                                        f_Radiant = 1
                                        eta_L = 0.72 ' 우선 15m 기준 설정
                                        eta_B = 1
                                        Select Case Dr공급.노출형제어.Trim
                                            Case "비제어"
                                                eta_C = 0.8
                                            Case "on/off제어"
                                                eta_C = 0.93
                                            Case "PI제어"
                                                eta_C = 0.97
                                        End Select
                                    Case "바닥난방(열)" '바닥난방(열)"
                                        f_Radiant = 0.85
                                        eta_L = 0.92
                                        Select Case Dr공급.바닥난방열제어.Trim
                                            Case "비제어"
                                                eta_C = 0.8
                                            Case "on/off제어"
                                                eta_C = 0.93
                                            Case "PI제어"
                                                eta_C = 0.97
                                        End Select
                                        eta_B = 0.95
                                    Case "바닥난방(전기)" '바닥난방(전기)"
                                        f_Radiant = 0.85
                                        eta_L = 0.92
                                        Select Case Dr공급.바닥난방전기제어.Trim
                                            Case "비제어"
                                                eta_C = 0.8
                                            Case "on/off제어"
                                                eta_C = 0.93
                                            Case "PI제어"
                                                eta_C = 0.97
                                        End Select
                                        eta_B = 0.95
                                    Case "전기난방" '전기난방"
                                        f_Radiant = 1
                                        eta_L = 0.78
                                        eta_B = 1
                                        Select Case Dr공급.바닥난방전기제어.Trim
                                            Case "비제어"
                                                eta_C = 0.8
                                            Case "on/off제어"
                                                eta_C = 0.93
                                            Case "PI제어"
                                                eta_C = 0.97
                                        End Select
                                End Select

                            End If

                        End If

                        eta_h_ce = 1 / (4 - (eta_L + eta_C + eta_B)) '(3.27-28)

                        Q_h_ce_i = (f_Radiant * f_int * f_hydr / eta_h_ce - 1) * Q_h_b_i '(3.2.7-27)
                        Q_h_ce = Q_h_ce + Q_h_ce_i

                    End If
                End If '//판단1 //난방생산기기 완료

                If DR존.냉난방공조 = "냉난방" OrElse DR존.냉난방공조 = "난방" OrElse ((DR존.냉난방공조 = "환기" OrElse DR존.냉난방공조 = "냉방") And DR존.외기부하처리여부 = "예") Then ' 공조기 사용에 따른 난방에너지
                    '=========================================================================================================================================================2010.2.21 수정
                    system_count = 1 'IIf(dr난방.개별기기적용 = "0", 1, TOSG(DR존.입력존의수))   '//20130818
                    If 판단2 Then

                        'If dr난방.헤더적용 Then
                        '    Q_h_b_i = a_Q_h_b_i
                        '    Q_h_b_i *= 비율 '//130818
                        '    Q_h_b = Q_h_b_i '//Q_c_b + Q_c_b_i

                        'Else
                        Dim 월에너지분석 As DSR.월별에너지분석Row = CType(DSETR.월별에너지분석.Select("월='" & mon & "' and 존='" & DR존.code & "'")(0), DSR.월별에너지분석Row)
                        If (DR존.냉난방공조 = "환기" OrElse DR존.냉난방공조 = "냉방") And DR존.외기부하처리여부 = "예" Then '// 2010.11.19 추가
                            Q_h_b_i = TOSG(월에너지분석.난방요구량공조) / system_count '=========2013.08.18 수정
                        Else
                            Q_h_b_i = TOSG(월에너지분석.공조요구량난방) / system_count '=========2013.08.18 수정 ' Sheets("" & i_count_month & "").Cells(19, 7 + i_count_zone)
                        End If
                        Q_h_b = Q_h_b + Q_h_b_i
                        'End If
                        'Q_h_ce_i = 0 '공조기는 0으로 설정 '==============================================================2010.03.20 수정 공조기는 0으로 설정한 것을 수정
                        If (DR존.냉난방공조 = "환기" OrElse DR존.냉난방공조 = "냉방") And DR존.외기부하처리여부 = "예" Then '// 2010.11.19 추가

                        Else
                            If TOSG(DR존.천장고p) >= 4 Then
                                If TOSG(DR존.천장고p) >= 20 Then
                                    Q_h_ce_i = TOSG((1 / (1 / (4 - (0.71 + 0.97 + 1))) - 1) * Q_h_b_i)
                                Else
                                    If TOSG(DR존.천장고p) >= 15 Then
                                        Q_h_ce_i = TOSG((1 / (1 / (4 - (0.78 + 0.97 + 1))) - 1) * Q_h_b_i)
                                    Else
                                        If TOSG(DR존.천장고p) >= 12 Then
                                            Q_h_ce_i = TOSG((1 / (1 / (4 - (0.84 + 0.97 + 1))) - 1) * Q_h_b_i)
                                        Else
                                            If TOSG(DR존.천장고p) >= 10 Then
                                                Q_h_ce_i = TOSG((1 / (1 / (4 - (0.87 + 0.97 + 1))) - 1) * Q_h_b_i)
                                            Else
                                                If TOSG(DR존.천장고p) >= 8 Then
                                                    Q_h_ce_i = TOSG((1 / (1 / (4 - (0.91 + 0.97 + 1))) - 1) * Q_h_b_i)
                                                Else
                                                    If TOSG(DR존.천장고p) >= 6 Then
                                                        Q_h_ce_i = TOSG((1 / (1 / (4 - (0.96 + 0.97 + 1))) - 1) * Q_h_b_i)
                                                    Else
                                                        Q_h_ce_i = TOSG((1 / (1 / (4 - (0.99 + 0.97 + 1))) - 1) * Q_h_b_i)
                                                    End If
                                                End If
                                            End If
                                        End If
                                    End If
                                End If
                            End If

                            '===============================================================================================2010.03.20 수정

                            Q_h_ce = Q_h_ce + Q_h_ce_i
                        End If

                        'If dr난방.헤더적용 Then
                        '    Q_dot_h_max = a_Q_dot_h_max
                        '    d_op_mth = a_d_op_mth
                        '    t_h = a_t_h
                        '    d_op_max_mth = a_d_op_max_mth
                        '    t_h_max = a_t_h_max
                        '    t_h_op_d = a_t_h_op_d
                        'Else
                        '//프로필
                        Dim Drow최대() As DSR.최대냉난방부하Row = CType(DSETR.최대냉난방부하.Select("zone='" & DR존.code & "'"), DSR.최대냉난방부하Row())
                        Dim Dr프로필 As DS.tbl_profileRow = CType(DSET.tbl_profile.Select("code='" & DR존.프로필 & "' and code <> '0'")(0), DS.tbl_profileRow)
                        Q_dot_h_max = TOSG(Q_dot_h_max + TOSG(Drow최대(0).최대난방기기부하)) / system_count '=====2013.08.18 수정 ' Worksheets("0").Range("최대난방부하1").Offset(0, i_count_zone - 1)

                        If i_count_month = 0 Then
                            d_op_mth = 0
                        Else
                            d_op_mth = CInt(TOSG(Dr프로필("day" & Format(i_count_month, "00"))))
                        End If
                        If t_h < TOSG(Drow최대(0).난방최대가동시간) * d_op_mth Then t_h = CInt(TOSG(Drow최대(0).난방최대가동시간) * d_op_mth)
                        If d_op_max_mth < d_op_mth Then d_op_max_mth = d_op_mth
                        If t_h > t_h_max Then t_h_max = t_h
                        If t_h_op_d < TOSG(Drow최대(0).난방최대가동시간) Then t_h_op_d = CInt(TOSG(Drow최대(0).난방최대가동시간)) ' Sheets("0").Range("최대난방부하1").Offset(2, i_count_zone - 1)

                        'End If





                    End If
                    '=========================================================================================================================================================2010.2.21 수정


                End If
                '//공조 난방기기 완료 ㅋㅋ 끝
                ' End If

            Next

            If dr난방.헤더적용 Then
                Q_h_b = a_Q_h_b_i * 비율
            End If





            '==================================2010.2.21 수정
            d_Nutz_mth = d_op_max_mth
            '==================================2010.2.21 수정
            'beta_h_d = (Q_h_b + Q_h_ce) / (Q_dot_h_max * t_h_max)  ' t_h 가 t_h_max 일 것으로 추정 추후 검토

            'theta_VA = TOSG(Dr난방.급수온도) ' Worksheets("난방기기").Range("난방기기급수온도1").Offset(0, i_count_boiler - 1)
            'theta_RA = TOSG(Dr난방.환수온도) ' Worksheets("난방기기").Range("난방기기환수온도1").Offset(0, i_count_boiler - 1)

            'theta_VL_m_beta_h_d = TOSG((theta_VA - theta_i_h_soll) * beta_h_d ^ (1 / n) + theta_i_h_soll) '(3.2.7.13)
            'theta_RL_m_beta_h_d = TOSG((theta_RA - theta_i_h_soll) * beta_h_d ^ (1 / n) + theta_i_h_soll) '(3.2.7.14)


            'theta_HK_m_beta_h_d = TOSG(0.5 * (theta_VL_m_beta_h_d + theta_RL_m_beta_h_d))


            'f_L_WA = 1 - (theta_WA_Grenz - theta_e) / (theta_WA_Grenz - theta_e_min) '(3.2.7-22)
            'd_h_rB = TOSG(d_op_max_mth * ((365 - f_L_WA * (365 - d_Nutz_a)) / 365) * (t_h / (d_op_max_mth * 24))) '(3.2.7-21) '================== d_op_max_mth 2010.2.21 수정'CSng(d_mth * ((365 - f_L_WA * (365 - d_Nutz_a)) / 365) * (t_h / (d_mth * 24))) '(3.2.7-21)

            'f_L_NA = 1 - (theta_NA_Grenz - theta_e) / (theta_NA_Grenz - theta_e_min) '(3.2.7-20)
            't_h_rL_T = 24 - f_L_NA * (24 - t_h_op_d) '(3.2.7-19)
            't_h_rL = t_h_rL_T * d_h_rB '(3.2.7-23)


            '===================================================================2010.11.04 위치수정 및 추가 '2011.03.16 다시 수정
            If dr난방.열생산기기방식 = "히트펌프" Then
                If dr난방.운전방식.Trim = "동시가동" Then
                    Q_dot_h_max = TOSG(dr난방.히트난방용량) * TOSG(dr난방.보일러대수)
                Else
                    Q_dot_h_max = TOSG(dr난방.히트난방용량) ' Worksheets("난방기기").Range("히트펌프사용연료1").Offset(1, i_count_boiler - 1)
                End If

            End If

            If t_h_max = 0 Or Q_dot_h_max = 0 Then '======================================================================2014.043.07 추가
                beta_h_d = 0
            Else
                beta_h_d = (Q_h_b + Q_h_ce) / (Q_dot_h_max * t_h_max)  ' t_h 가 t_h_max 일 것으로 추정 추후 검토
            End If                                '======================================================================2014.043.07 추가


            If beta_h_d > 1 Then beta_h_d = 1

            theta_VA = TOSG(dr난방.급수온도) ' Worksheets("난방기기").Range("난방기기급수온도1").Offset(0, i_count_boiler - 1)
            theta_RA = TOSG(dr난방.환수온도) ' Worksheets("난방기기").Range("난방기기환수온도1").Offset(0, i_count_boiler - 1)

            theta_VL_m_beta_h_d = TOSG((theta_VA - theta_i_h_soll) * beta_h_d ^ (1 / n) + theta_i_h_soll) '(3.2.7.13)
            theta_RL_m_beta_h_d = TOSG((theta_RA - theta_i_h_soll) * beta_h_d ^ (1 / n) + theta_i_h_soll) '(3.2.7.14)


            theta_HK_m_beta_h_d = TOSG(0.5 * (theta_VL_m_beta_h_d + theta_RL_m_beta_h_d))


            If theta_WA_Grenz - theta_e_min = 0 Then '==================================================================2014.03.07 추가
                f_L_WA = 1
            Else
                f_L_WA = 1 - (theta_WA_Grenz - theta_e) / (theta_WA_Grenz - theta_e_min) '(3.2.7-22)
            End If '==================================================================2014.03.07 추가

            If d_op_max_mth = 0 Then '==================================================================2014.03.07 추가
                d_h_rB = 0
            Else
                d_h_rB = TOSG(d_op_max_mth * ((365 - f_L_WA * (365 - d_Nutz_a)) / 365) * (t_h / (d_op_max_mth * 24))) '(3.2.7-21) '================== d_op_max_mth 2010.2.21 수정'CSng(d_mth * ((365 - f_L_WA * (365 - d_Nutz_a)) / 365) * (t_h / (d_mth * 24))) '(3.2.7-21)
            End If '==================================================================2014.03.07 추가


            If theta_NA_Grenz - theta_e_min = 0 Then
                f_L_NA = 1
            Else
                f_L_NA = 1 - (theta_NA_Grenz - theta_e) / (theta_NA_Grenz - theta_e_min) '(3.2.7-20)
            End If



            t_h_rL_T = 24 - f_L_NA * (24 - t_h_op_d) '(3.2.7-19)
            t_h_rL = t_h_rL_T * d_h_rB '(3.2.7-23)
            '===================================================================2010.11.04 위치수정 및 추가  '2011.03.16 다시 수정



            '=================================================2010. 02. 11 수정
            For Each Dr난방분배 As DS.tbl_nbunbaeRow In DSET.tbl_nbunbae.Select("생산기기구분='" & dr난방.code & "' and code <> '0'", "code")
                'If Dr난방.code = Dr난방분배.생산기기구분 Then '  Worksheets("난방분배시스템").Range("분배생산기기1").Offset(0, i_count_pipe - 1) Then

                Select Case Dr난방분배.표준치적용.Trim ' Worksheets("난방분배시스템").Range("분배생산기기1").Offset(1, i_count_pipe - 1)
                    Case "상세입력" '상세입력"
                        L_i = TOSG(Dr난방분배.배관구간길이) '= Worksheets("난방분배시스템").Range("배관구간방식1").Offset(1, i_count_pipe - 1)
                        U_i = TOSG(Dr난방분배.열관류율) ' Worksheets("난방분배시스템").Range("배관구간방식1").Offset(2, i_count_pipe - 1)
                        Select Case Dr난방분배.배관설치장소.Trim ' Worksheets("난방분배시스템").Range("배관구간방식1").Offset(3, i_count_pipe - 1)
                            Case "표준난방존" '표준난방존"
                                Q_h_d = (Q_h_d + U_i * (theta_HK_m_beta_h_d - theta_i_h_soll) * L_i * t_h_rL) / 1000
                            Case "표준비난방존" '표준비난방존"
                                Q_h_d = (Q_h_d + U_i * (theta_HK_m_beta_h_d - 13) * L_i * t_h_rL) / 1000
                            Case "외부" '외부"
                                Q_h_d = (Q_h_d + U_i * (theta_HK_m_beta_h_d - theta_e) * L_i * t_h_rL) / 1000
                        End Select
                    Case "표준치조건" '표준치조건"
                        L_G = TOSG(Dr난방분배.건물길이x) ' Worksheets("난방분배시스템").Range("난방분배건물길이1").Offset(0, i_count_pipe - 1)
                        B_G = TOSG(Dr난방분배.건물길이y) ' Worksheets("난방분배시스템").Range("난방분배건물길이1").Offset(1, i_count_pipe - 1)
                        n_G = TOSG(Dr난방분배.층수) 'Worksheets("난방분배시스템").Range("난방분배건물길이1").Offset(2, i_count_pipe - 1)
                        h_G = TOSG(Dr난방분배.층고) ' Worksheets("난방분배시스템").Range("난방분배건물길이1").Offset(3, i_count_pipe - 1)
                        If dr난방.배관망유형 = "이중배관" Then ' then Worksheets("난방기기").Range("난방기기배관망1").Offset(0, i_count_boiler - 1) = "이중배관" Then
                            If Dr난방분배.지관장소 = "외부" Then ' then외부" Then
                                L_i = TOSG((2 * L_G + 0.01625 * L_G * B_G * B_G) * 0.2 + (0.025 * L_G * B_G * h_G * n_G) * 0.255 + (0.55 * L_G * B_G * n_G) * 0.255) '외부배관난방적용
                            Else
                                L_i = TOSG((2 * L_G + 0.0325 * L_G * B_G + 6) * 0.2 + (0.025 * L_G * B_G * h_G * n_G) * 0.255 + (0.55 * L_G * B_G * n_G) * 0.255) '내부배관난방적용
                            End If
                        Else
                            L_i = TOSG((2 * L_G + 0.0325 * L_G * B_G + 6) * 0.2 + (0.025 * L_G * B_G * h_G * n_G + 2 * (L_G + B_G) * n_G) * 0.255 + (0.1 * L_G * B_G * n_G) * 0.255) '단일배관난방적용
                        End If
                        Q_h_d = (Q_h_d + (theta_HK_m_beta_h_d - theta_i_h_soll) * L_i * t_h_rL) / 1000 '(3.2.7-36) 'theta_i를 theta_i_h_soll 로 수정 추후 검토 ' U_i는 L_i에 포함
                    Case Else
                        MsgBox("표준치적용을 알수없습니다", MsgBoxStyle.Critical, Dr난방분배.표준치적용)
                End Select
                'End If
            Next

            '=================================================2010. 02. 11 수정
            If dr난방.축열탱크방식 <> "축열탱크없음" Then ' Worksheets("난방기기").Range("난방기기축열탱크1").Offset(0, i_count_boiler - 1) <> "축열탱크없음" Then
                V_s = TOSG(dr난방.축열제척) ' Worksheets("난방기기").Range("난방기기축열체적1").Offset(0, i_count_boiler - 1)
                q_B_S = TOSG(0.4 + 0.14 * V_s ^ 0.45) '(3.2.7-43)
                Q_h_s = f_verbindung * (theta_VA - theta_i) / 45 * d_op_max_mth * q_B_S '(3.2.7-41) theta_h_s 는 theta_VA 로 설정'================== d_op_max_mth 2010.2.21 수정
            End If

            '===================================================================================================================2010.2.21 수정
            Q_h_outg_i = Q_h_b + Q_h_ce + Q_h_d + Q_h_s '(3.2.7-1)

            If dr난방.열생산기기방식 = "전기보일러" Then
                Q_h_outg_i = Q_h_outg_i / (TOSG(dr난방.정격보일러효율) * age_heating / 100)
            End If




            Q_h_outg = Q_h_outg + Q_h_outg_i * system_count '=====2013.08.13 수정  '(3.2.7-1)
            '===================================================================================================================2010.2.21 수정

            If dr난방.열생산기기방식 = "보일러" Then ' Worksheets("난방기기").Range("열생산기기방식1").Offset(0, i_count_boiler - 1) = "보일러" Then
                '//아래는 급탕생산기기로 지정되어잇는가?
                If DSET.tbl_zone.Select("열생산급탕생산기기='" & dr난방.code & "'").GetUpperBound(0) <> -1 Then 'If Worksheets("난방기기").Range("난방생산기기1").Offset(5, i_count_boiler - 1) = "예" Then
                    Q_w_b = 0
                    For Each Dr입력존 As DS.tbl_zoneRow In DSET.tbl_zone.Select("code <> '0' and 열생산급탕생산기기='" & dr난방.code & "'", "code")
                        Dim Drow최대() As DSR.최대냉난방부하Row = CType(DSETR.최대냉난방부하.Select("zone='" & Dr입력존.code & "'"), DSR.최대냉난방부하Row())
                        Dim Dr월에너지분석 As DSR.월별에너지분석Row = CType(DSETR.월별에너지분석.Select("월='" & mon & "' and 존='" & Dr입력존.code & "'")(0), DSR.월별에너지분석Row)

                        system_count = IIf(dr난방.개별기기적용 = "0", 1, TOSG(Dr입력존.입력존의수))   '//20130818
                        If system_count = 0 Then system_count = 1

                        Q_w_b = TOSG(Q_w_b + TOSG(Dr월에너지분석.급탕요구량)) / system_count 'Sheets("" & i_count_month & "").Cells(15, 7 + i_count_zone)
                        '===================================================================================2010.2.21 수정
                        Dim Dr프로필 As DS.tbl_profileRow = CType(DSET.tbl_profile.Select("code='" & Dr입력존.프로필 & "'")(0), DS.tbl_profileRow)

                        If i_count_month = 0 Then
                            d_op_mth = 0
                        Else
                            d_op_mth = CInt(TOSG(Dr프로필("day" & Format(i_count_month, "00"))))
                        End If

                        If t_h < TOSG(Drow최대(0).난방최대가동시간) * d_op_mth Then
                            t_h = CInt(TOSG(Drow최대(0).난방최대가동시간) * d_op_mth)
                        End If
                        If d_op_max_mth < d_op_mth Then
                            d_op_max_mth = d_op_mth
                        End If
                        '===================================================================================2010.2.21 수정                          
                    Next
                End If
            End If


            ' 여기에 신재생에너지를 산출하고 Q_h_outg 와 Q_h_outg_i 에서 신재생에너지를 차감해야
            '----------------------------------------------------------------------------------------------------------------------------------
            '----------------------------------------------------------------------------------------------------------------------------------

            '신재생 및 열병합 시스템
            Dim CRenew As New CRenewable(DSET, Result)
            ' Dim Dr신재생 As DS.tbl_newRow = CType(DSET.tbl_new.Rows(0), DS.tbl_newRow)
            If dr난방.신재생연결여부 = "시스템연결" AndAlso dr난방.연결된시스템.Trim <> "" AndAlso dr난방.연결된시스템 <> "0" Then '  Worksheets("난방기기").Range("신재생난방연결1").Offset(0, i_count_boiler - 1) = "시스템연결" Then
                Dim Dr신재생 As DS.tbl_newRow = CType(DSET.tbl_new.Select("code='" & dr난방.연결된시스템 & "' and code <> '0'")(0), DS.tbl_newRow)
                '//식은 맞는듯한게 값이 이상하게 들었네요... 뭘해도 되도록 수정해버리죠 ㅋㅋ


                Select Case Dr신재생.기기종류.Trim ' Dr난방.연결된시스템.Trim
                    Case "지열" '//지열
                        Select Case Dr신재생.가동연료.Trim
                            Case "전기" '전기"
                                CRenew.Calc_HeatpumpSystem(system_type, i_HeatCool, Dr신재생, Q_h_outg_i, i_count_month, d_op_max_mth, t_h, theta_VA, theta_i, Q_hp_outg, Q_h_f_hp, Q_h_g_hp_aux) '=============2010.04.01 수정 Q_h_outg 를 Q_h_outg_i 로 수정
                                Q_h_outg = Q_h_outg - Q_hp_outg
                                Q_h_outg_i = Q_h_outg_i - Q_hp_outg
                                use_Elec = use_Elec + (Q_h_f_hp + Q_h_g_hp_aux) * system_count '=============2013.08.18 수정
                                Q_h_f = Q_h_f + (Q_h_f_hp + Q_h_g_hp_aux) * system_count '=============2013.08.18 수정  '============================2010.04.17 추가
                            Case "천연가스" '천연가스"
                                CRenew.Calc_HeatpumpSystem(system_type, i_HeatCool, Dr신재생, Q_h_outg_i, i_count_month, d_op_max_mth, t_h, theta_VA, theta_i, Q_hp_outg, Q_h_f_hp, Q_h_g_hp_aux) '=============2010.04.01 수정 Q_h_outg 를 Q_h_outg_i 로 수정
                                Q_h_outg = Q_h_outg - Q_hp_outg
                                Q_h_outg_i = Q_h_outg_i - Q_hp_outg
                                use_LNG = use_LNG + Q_h_f_hp * system_count '=============2013.08.18 수정
                                use_Elec = use_Elec + Q_h_g_hp_aux * system_count '=============2013.08.18 수정
                                Q_h_f = Q_h_f + (Q_h_f_hp + Q_h_g_hp_aux) * system_count '=============2013.08.18 수정 '============================2010.04.17 추가
                                '//요기맞죠 ^^?
                            Case "액화가스" '액화가스"
                                CRenew.Calc_HeatpumpSystem(system_type, i_HeatCool, Dr신재생, Q_h_outg_i, i_count_month, d_op_max_mth, t_h, theta_VA, theta_i, Q_hp_outg, Q_h_f_hp, Q_h_g_hp_aux) '=============2010.04.01 수정 Q_h_outg 를 Q_h_outg_i 로 수정
                                Q_h_outg = Q_h_outg - Q_hp_outg
                                Q_h_outg_i = Q_h_outg_i - Q_hp_outg
                                use_LPG = use_LPG + Q_h_f_hp * system_count '=============2013.08.18 수정
                                use_Elec = use_Elec + Q_h_g_hp_aux * system_count '=============2013.08.18 수정
                                Q_h_f = Q_h_f + (Q_h_f_hp + Q_h_g_hp_aux) * system_count '=============2013.08.18 수정 '============================2010.04.17 추가
                        End Select
                    Case "열병합" '//열병합
                        Select Case Dr신재생.가동연료.Trim
                            Case "난방유" '난방유"
                                CRenew.Calc_CogenerationSystemEN(Dr신재생, 1, i_count_month, Q_h_outg_i, t_h, Q_h_CHP, Q_h_f_CHP)
                                Q_h_outg = Q_h_outg - Q_h_CHP
                                Q_h_outg_i = Q_h_outg_i - Q_h_CHP
                                use_Oil = use_Oil + Q_h_f_CHP * system_count '=============2013.08.18 수정
                                Q_h_f = Q_h_f + Q_h_f_CHP * system_count '=============2013.08.18 수정 '============================2010.04.17
                            Case "천연가스" '천연가스"
                                CRenew.Calc_CogenerationSystemEN(Dr신재생, 1, i_count_month, Q_h_outg_i, t_h, Q_h_CHP, Q_h_f_CHP)
                                Q_h_outg = Q_h_outg - Q_h_CHP
                                Q_h_outg_i = Q_h_outg_i - Q_h_CHP
                                use_LNG = use_LNG + Q_h_f_CHP * system_count '=============2013.08.18 수정
                                Q_h_f = Q_h_f + Q_h_f_CHP * system_count '=============2013.08.18 수정 '============================2010.04.17
                            Case "액화가스" '액화가스"
                                CRenew.Calc_CogenerationSystemEN(Dr신재생, 1, i_count_month, Q_h_outg_i, t_h, Q_h_CHP, Q_h_f_CHP)
                                Q_h_outg = Q_h_outg - Q_h_CHP
                                Q_h_outg_i = Q_h_outg_i - Q_h_CHP
                                use_LPG = use_LPG + Q_h_f_CHP * system_count '=============2013.08.18 수정
                                Q_h_f = Q_h_f + Q_h_f_CHP * system_count '=============2013.08.18 수정 '============================2010.04.17
                            Case Else
                                MsgBox("신재생에너지의 가동연료를 확인할 수 없습니다", MsgBoxStyle.Critical, Dr신재생.가동연료)
                        End Select
                End Select
            End If


            '----------------------------------------------------------------------------------------------------------------------------------
            '----------------------------------------------------------------------------------------------------------------------------------

            '===========================================================================================2013.01.13 이동
            If dr난방.열생산기기방식 = "히트펌프" Then

                Q_dot_HP_heating = TOSG(dr난방.히트난방용량) ' Worksheets("난방기기").Range("히트펌프사용연료1").Offset(1, i_count_boiler - 1)
                COP_HP_7 = TOSG(dr난방.히트난방정격7) * age ' Worksheets("난방기기").Range("히트펌프사용연료1").Offset(2, i_count_boiler - 1)
                COP_HP_10 = TOSG(dr난방.히트난방정격10) * age ' Worksheets("난방기기").Range("히트펌프사용연료1").Offset(3, i_count_boiler - 1)
                L_HP_heating = TOSG(dr난방.히트배관길이) ' Worksheets("난방기기").Range("히트펌프사용연료1").Offset(4, i_count_boiler - 1)
                If theta_e > 15 Then
                    COP_HP_total = (COP_HP_7 - COP_HP_10) / 22 * 15 + COP_HP_7 - 7 * (COP_HP_7 - COP_HP_10) / 22
                Else
                    COP_HP_total = (COP_HP_7 - COP_HP_10) / 22 * theta_e + COP_HP_7 - 7 * (COP_HP_7 - COP_HP_10) / 22
                End If

                If theta_e < 7 Then

                    If theta_e >= 0 Then
                        COP_HP_total = TOSG(COP_HP_total * ((1 - 0.86) / 7 * theta_e + 0.86))
                    Else
                        COP_HP_total = TOSG(COP_HP_total * ((0.98 - 0.86) / 7 * (-theta_e) + 0.86))
                    End If

                End If

                If Q_dot_HP_heating <= 20 Then
                    COP_HP_total = TOSG(COP_HP_total * (1 - L_HP_heating * 0.002))
                Else
                    If Q_dot_HP_heating <= 100 Then
                        COP_HP_total = TOSG(COP_HP_total * (1 - L_HP_heating * 0.0009))
                    Else
                        COP_HP_total = TOSG(COP_HP_total * (1 - L_HP_heating * 0.0014))
                    End If
                End If



                Q_h_outg = Q_h_outg - Q_h_outg_i '===================================================2013.01.16 추가
                '======================================================================================================================================================2010.04.23 추가


                '======================================================================================================================================================2012.07.08 추가

                If dr난방.운전방식.Trim = "동시가동" Or dr난방.운전방식.Trim = "순차가동" Then
                    Q_dot_HP_heating = Q_dot_HP_heating * TOSG(dr난방.보일러대수)
                End If


                If t_h_max = 0 Or Q_dot_HP_heating = 0 Then '=================================================================================2014.03.07 추가
                    Q_h_outg_i = 0
                Else
                    If Q_h_outg_i / (Q_dot_HP_heating * t_h_max) >= 1 Or dr난방.히트펌프시스템종류 = "실내외분리시스템" Then '====2010.04.26 수정
                        Q_h_outg_i = Q_h_outg_i / COP_HP_total
                    Else
                        If dr난방.운전방식.Trim = "순차가동" Then
                            For i_count_beta = 1 To CInt(TOSG(dr난방.보일러대수))
                                If Q_h_outg_i <= (Q_dot_HP_heating * t_h_max / TOSG(dr난방.보일러대수) * i_count_beta) Then
                                    Q_h_outg_i = ((Q_h_outg_i / COP_HP_total) * (i_count_beta - 1) + (Q_h_outg_i / (COP_HP_total * (Q_h_outg_i / (Q_dot_HP_heating * t_h_max / TOSG(dr난방.보일러대수)) * 0.5 + 0.5)))) / i_count_beta
                                    Exit For
                                End If
                            Next

                        Else
                            Q_h_outg_i = Q_h_outg_i / (COP_HP_total * (Q_h_outg_i / (Q_dot_HP_heating * t_h_max) * 0.5 + 0.5)) '====2010.04.26 수정
                        End If

                    End If

                End If '=================================================================================2014.03.07 추가

                '======================================================================================================================================================2010.04.23 추가
                Q_h_outg = Q_h_outg + Q_h_outg_i * system_count '=====2013.08.13 수정 '===================================================2013.01.16 추가


            End If

            '===========================================================================================2013.01.13 이동



            If dr난방.열생산기기방식 = "보일러" Then 'Worksheets("난방기기").Range("열생산기기방식1").Offset(0, i_count_boiler - 1) = "보일러" Then

                If DSET.tbl_zone.Select("열생산급탕생산기기='" & dr난방.code & "' and code <> '0'").GetUpperBound(0) <> -1 Then ' If Worksheets("난방기기").Range("난방생산기기1").Offset(5, i_count_boiler - 1) = "예" Then

                    If dr난방.분배시스템방식 = "중앙식" Then ' Dr난방.분배시스템방식 = "중앙식" Then

                        L_G = TOSG(dr난방.건물길이) ' Dr난방.건물길이
                        B_G = TOSG(dr난방.건물넓이) ' Dr난방.건물넓이
                        n_G = TOSG(dr난방.열공급층수) 'Dr난방.열공급층수
                        h_G = TOSG(dr난방.층고) ' Dr난방.층고
                        L_i = TOSG((2 * L_G + 0.0325 * L_G * B_G + 6) * 0.2 + (0.025 * L_G * B_G * h_G * n_G + 2 * (L_G + B_G) * n_G) * 0.255 + (0.1 * L_G * B_G * n_G) * 0.255) '단일배관난방적용

                        If dr난방.순환유무 = "무" Then '  Worksheets("난방기기").Range("급탕분배방식1").Offset(1, i_count_boiler - 1) = "무" Then
                            ':중앙비순환시스템
                            Q_w_d_i = TOSG(1 / 1000 * L_i * ((23 * 0.2 ^ (-0.2) - theta_i) * d_Nutz_mth * 24)) '(3.2.9-11) 중앙비순환시스템 L_i 에 U_i 포함 theta_w_m_비순환 는 23*0.2^(-0.2)
                            theta_g_m = 40
                        Else
                            ':중앙순환시스템
                            Q_w_d_i = TOSG(1 / 1000 * L_i * d_Nutz_mth * ((50 - theta_i) * t_Nutz_d + 0.5 * (23 * 0.2 ^ (-0.2) - theta_i) * (24 - t_Nutz_d))) '(3.2.9-11) 중앙순환시스템 L_i 에 U_i 포함 theta_w_m_순환 는 50도
                            theta_g_m = 50
                        End If

                        Q_w_d = Q_w_d + Q_w_d_i '(3.2.9-12)
                    End If


                    Select Case dr난방.축열탱크방식.Trim 'Worksheets("난방기기").Range("난방기기축열탱크1").Offset(0, i_count_boiler - 1)
                        Case "전기가열식" '전기가열식"

                            ':저탕조용량(모를경우)
                            'f_N = 1 / (t_Nutz_d * 1) '(3.2.9-24)  t_Nutz_T 는 t_Nutz_d 로 적용, eta_Sp는 1로 적용 추후 검토
                            ':심야전기가열
                            'V_s = 1.42 * Q_w_b_d * f_N * 860 / ((theta_w_m - theta_k) * eta_s) '(3.2.9-33) : 심야전기가열
                            ':주간전기가열
                            'V_s = 0.67 * Q_w_b_d * f_N * 860 / ((Q_w_m - Q_k) * eta_s) '(3.2.9-34) : 주간전기가열
                            V_s = TOSG(dr난방.축열제척) ' Worksheets("난방기기").Range("난방기기축열체적1").Offset(0, i_count_boiler - 1)
                            q_B_S = TOSG(0.29 + 0.019 * V_s ^ 0.8) '(3.2.9-30) :1994 이후
                            Q_w_s = (55 - theta_i) / 45 * d_Nutz_mth * q_B_S '(3.2.9-29) : 전기가열식 저탕조

                        Case "가스가열식" '가스가열식"

                            ':가스가열식 저탕조
                            V_s = TOSG(dr난방.축열제척) ' Worksheets("난방기기").Range("난방기기축열체적1").Offset(0, i_count_boiler - 1)
                            ':1994 이후
                            q_B_S = TOSG(2 + 0.033 * V_s ^ 1.1) '(3.2.9-38)
                            Q_w_s = (55 - theta_i) / 50 * d_Nutz_mth * q_B_S '(3.2.9-37) : 가스가열식 저탕조

                        Case "간접가열식" '간접가열식"
                            ':간접 가열식 저탕조
                            ':태양열 복합 저탕조(UA_sb_s_a를 모를 경우)
                            'q_B_S = (0.4 + 0.2 * (V_s_aux + V_s_sol) ^ 0.4) * V_s_aux / (V_s_aux + V_s_sol) '(3.2.9-26)
                            'f_N = 1 / (t_Nutz_T * n_Sp) '(3.2.9-24)
                            ':저탕조용량(모를 경우)
                            'V_s = (Q_w_b_d * f_N * 860) / ((theta_w_m - theta_k) * eta_s) '(3.2.9-23)
                            V_s = TOSG(dr난방.축열제척) ' Worksheets("난방기기").Range("난방기기축열체적1").Offset(0, i_count_boiler - 1)
                            If V_s < 1000 Then
                                ':1000이하
                                q_B_S = 0.8 + 0.02 * V_s ^ 0.77 '(3.2.9-18) '============================2010.04.24 수정
                            Else
                                ':1000이상
                                q_B_S = TOSG(0.39 * V_s ^ 0.35 + 0.5) '(3.2.9-19)
                            End If
                            Q_w_s = f_verbindung * (50 - theta_i) / 45 * d_Nutz_mth * q_B_S '(3.2.9-16)

                    End Select

                    Q_w_outg_i = Q_w_b + Q_w_ce + Q_w_d + Q_w_s '(3.2.9-4)
                    Q_w_outg = Q_w_outg + Q_w_outg_i * system_count '=====2013.08.13 수정

                Else
                    Q_w_outg_i = 0
                End If


                ' 신재생에너지 시스템
                '----------------------------------------------------------------------------------------------------------------------------------
                '----------------------------------------------------------------------------------------------------------------------------------

                '태양열(난방+급탕) 시스템
                If dr난방.신재생연결여부 = "시스템연결" AndAlso dr난방.연결된시스템 <> "0" Then ' Worksheets("난방기기").Range("신재생난방연결1").Offset(0, i_count_boiler - 1) = "시스템연결" Then
                    Dim Dr신재생 As DS.tbl_newRow = CType(DSET.tbl_new.Select("code='" & dr난방.연결된시스템 & "' and code <> '0'")(0), DS.tbl_newRow)

                    Select Case Dr신재생.기기종류.Trim
                        Case "태양열" '//태양열일때
                            If Dr신재생.태양열종류 = "난방+급탕" Then '난방+급탕" Then

                                'Dim Dr존 As DS.tbl_zoneRow = CType(DSET.tbl_zone.Select("code<>'0'", "code")(i_count_zone - 1), DS.tbl_zoneRow)
                                Calc.Renewable.Calc_ThermalSolarSystem_EN(system_type, Dr신재생.code, i_count_month, d_op_max_mth, Q_h_outg_i, Q_w_outg_i, Q_W_sol_out_m, Q_H_sol_out_m, W_sol_aux_m)
                                Q_h_outg = Q_h_outg - Q_H_sol_out_m
                                Q_h_outg_i = Q_h_outg_i - Q_H_sol_out_m
                                Q_w_outg = Q_w_outg - Q_W_sol_out_m
                                Q_w_outg_i = Q_w_outg_i - Q_W_sol_out_m
                                W_sol_aux = W_sol_aux + W_sol_aux_m * system_count '=======2013.08.18 수정
                            End If
                    End Select
                End If

                '----------------------------------------------------------------------------------------------------------------------------------
                '----------------------------------------------------------------------------------------------------------------------------------

                Q_dot_N = TOSG(dr난방.보일러정격출력) ' Worksheets("난방기기").Range("난방기기정격출력1").Offset(0, i_count_boiler - 1)
                If d_Nutz_mth = 0 Or Q_dot_N = 0 Or d_h_rB = 0 Then '//201.11.20 추가(학교프로파일 적용시 문제점 해결) '=====================2014.03.07 추가
                    t_w_100 = 0
                    Q_dot_d_in = 0
                Else
                    t_w_100 = Q_w_outg_i / (Q_dot_N * d_Nutz_mth) '(3.2.9-61)
                    Q_dot_d_in = Q_h_outg_i / (d_h_rB * (t_h_rL_T - t_w_100)) '(3.2.7-69) 난방 또는 난방 및 급탕
                    ' 우선 미적용 Q_dot_d_in = sigma_Q_h_outg / (t_Betrieb_K - t_W_100) * d_Nutz_mth '(3.2.7-70) 난방, 급탕 및 공조
                End If


                Select Case dr난방.운전방식.Trim ' Worksheets("난방기기").Range("난방기기운전방식1").Offset(0, i_count_boiler - 1)
                    Case "단독가동" '단독가동"
                        beta_h = Q_dot_d_in / Q_dot_N '(3.2.7-64) : 단일보일러 시설
                    Case "동시가동" ' 동시가동"
                        beta_h = TOSG(Q_dot_d_in / (Q_dot_N * TOSG(dr난방.보일러대수))) '(3.2.7-64) : 다수보일러 동시가동
                    Case "순차가동" '순차가동"
                        For i_count_beta = 1 To CInt(TOSG(dr난방.보일러대수))
                            If Q_dot_d_in <= (Q_dot_N * i_count_beta) Then
                                beta_h = (Q_dot_d_in - Q_dot_N * (i_count_beta - 1)) / Q_dot_N * i_count_beta '다수보일러 대수제어
                                n_beta = i_count_beta - 1
                                Exit For
                            End If
                        Next
                End Select


                '------------------------------------------------------------------------------------
                ' 보일러 가동 손실의 경우 국내 데이타 미비로 정격효율을 부분부하효율로 적용 추후 검토 필요

                'eta_k_100 = (a + b * Ln(Q_dot_N)) / 100 '(3.2.7-83) 일반보일러
                'eta_k_pl = (c + d * Ln(Q_dot_N)) / 100 '(3.2.7-84) 일반보일러
                'eta_k_100 = (a + b * Ln(Q_dot_N)) / 100 '(3.2.7-85) 콘덴싱보일러
                'eta_k_pl = (c + d * Ln(Q_dot_N)) / 105 '(3.2.7-86) 콘덴싱보일러


                'q_B_70 = (E * (Q_dot_N ^ F)) / 100 '(3.2.7-64)
                'q_B_theta = q_B_70 * (theta_HK_m_beta_h_g - theta_i) / (70 - 20) '(3.2.7-72)
                'Q_dot_B_h = q_B_theta * (Q_dot_N / eta_k_100) * f_Hs_Hi '(3.2.7-71) 정지 대기모드



                'beta_h_g = (Q_h_b + Q_h_ce + Q_h_d + Q_h_s) / (Q_dot_h_max * t_h) '(3.2.7-10)
                'theta_VL_m_beta_h_g = (theta_VA - theta_i_h_soll) * beta_h_g ^ (1 / n) + theta_i_h_soll '(3.2.7.13)
                'theta_RL_m_beta_h_g = (theta_RA - theta_i_h_soll) * beta_h_g ^ (1 / n) + theta_i_h_soll '(3.2.7.-14)

                'eta_k_pl_Betrieb = eta_k_pl + H * (theta_g_test_pl - theta_HK_m_beta_h_g) '(3.2.7-76)
                'eta_k_100_Betrieb = eta_k_100 + G * (theta_g_test100 - theta_HK_m_beta_h_g) '(3.2.7-75)
                'Q_V_g_100 = (f_Hs_Hi - eta_k_100_Betrieb) / eta_k_100_Betrieb * Q_dot_N '(3.2.7-74)
                'Q_V_g_pl = (f_Hs_Hi - eta_k_pl_Betrieb) / eta_k_pl_Betrieb * beta_k_pl * Q_dot_N '(3.2.7-73)

                '--          -------             -----             ---             ---             ---     --

                eta_k_100 = TOSG(TOSG(dr난방.정격보일러효율) * age_heating / 100) ' Worksheets("난방기기").Range("난방기기정격효율1").Offset(0, i_count_boiler - 1) / 100
                eta_k_pl = eta_k_100
                f = -0.4

                If dr난방.열생산기기방식 = "보일러" Then ' Worksheets("난방기기").Range("열생산기기방식1").Offset(0, i_count_boiler - 1) = "보일러" Then
                    Select Case dr난방.보일러방식.Trim ' Worksheets("난방기기").Range("보일러방식1").Offset(0, i_count_boiler - 1)
                        Case "가스보일러" '가스보일러"
                            e = 8.5
                            f = -0.4
                        Case "기름보일러" '기름보일러"
                            e = 8.5
                            f = -0.4
                        Case "저온가스보일러" '저온가스보일러"
                            e = 4.5
                            f = -0.4
                        Case "저온기름보일러" '저온기름보일러"
                            e = 4.25
                        Case "콘덴싱보일러" '콘덴싱보일러"
                            e = 4
                    End Select

                    q_B_70 = TOSG((e * (Q_dot_N ^ f)) / 100)

                Else
                    q_B_70 = 1
                End If

                q_B_theta = q_B_70 '원래는 =q_B_70 * (theta_HK_m_beta_h_g - theta_i) / (70 - 20) 이지만 q_B_theta 와 q_B_70 이 같은 것으로 적용 추후검토



                'Select Case Worksheets("난방기기").Range("난방기기사용연료1").Offset(0, i_count_boiler - 1)
                'Case "난방유"
                'f_Hs_Hi = 1.06
                'Case "천연가스"
                'f_Hs_Hi = 1.11
                'Case "액화가스"
                'f_Hs_Hi = 1.09
                'Case "석탄"
                'f_Hs_Hi = 1.04
                'Case "갈탄"
                'f_Hs_Hi = 1.07
                'Case "나무"
                'f_Hs_Hi = 1.08
                'End Select

                f_Hs_Hi = 1 ' 국내는 총발열량을 기준으로 입력함으로 우선 1로 설정, 추후 검토

                Q_dot_B_h = q_B_theta * (Q_dot_N / eta_k_100) * f_Hs_Hi '(3.2.7-71)

                Q_V_g_100 = (f_Hs_Hi - eta_k_100) / eta_k_100 * Q_dot_N
                Q_V_g_pl = (f_Hs_Hi - eta_k_pl) / eta_k_pl * beta_k_pl * Q_dot_N

                '------------------------------------------------------------------------------------------------------





                If beta_h > beta_k_pl Then
                    Q_h_g_v_i = ((beta_h - beta_k_pl) / (1 - beta_k_pl) * (Q_V_g_100 - Q_V_g_pl) + Q_V_g_pl) * (t_h_rL_T - t_w_100)
                    Q_h_g_v_i = Q_h_g_v_i + ((Q_V_g_100 - Q_V_g_pl) + Q_V_g_pl) * (t_h_rL_T - t_w_100) * n_beta
                Else
                    '======================================================================================== 2010.2.21 수정
                    If beta_h = 0 Then
                        Q_h_g_v_i = 0
                    Else
                        Q_h_g_v_i = ((beta_h / beta_k_pl) * (Q_V_g_pl - Q_dot_B_h) + Q_dot_B_h) * (t_h_rL_T - t_w_100)
                    End If
                    '======================================================================================== 2010.2.21 수정
                End If

                Q_h_g = Q_h_g + (Q_h_g_v_i * d_h_rB) * system_count '=====2013.08.13 수정 '(3.2.7-66)
                Q_h_g_i = Q_h_g_v_i * d_h_rB

            Else

                If dr난방.열생산기기방식 = "지역난방" Then ' Worksheets("난방기기").Range("열생산기기방식1").Offset(0, i_count_boiler - 1) = "지역난방" Then
                    If dr난방.지역난방방식 = "중온수" Then ' Worksheets("난방기기").Range("지역난방온수방식1").Offset(0, i_count_boiler - 1) = "중온수" Then
                        D_DS = 0.6
                        theta_prim_DS = 105
                        'MsgBox("난방기기 단열등급에  등급2/3 등급3/4 등급 4/5 추가해야함")
                        Select Case dr난방.단열등급.Trim '  Dr난방.단열등급
                            Case "기본단열" '기본단열" '원래는 등급1/2 이지만 국내에서는 법적단열로 사용
                                B_DS = 4.9
                            Case "등급2/3" '등급2/3"
                                B_DS = 4.4
                            Case "등급3/4" '등급3/4"
                                B_DS = 4
                            Case "등급4/5" '등급4/5"
                                B_DS = 3.5
                        End Select
                    End If
                    'MsgBox("난방기기 지역난방방식에 고온수 0002 추가해야함") --추가는 했으나 엑셀에서는 중온수고정이다 그래서 하위 루틴은 실행되면안된다
                    If dr난방.지역난방방식 = "고온수" Then 'Worksheets("난방기기").Range("지역난방온수방식1").Offset(0, i_count_boiler - 1) = "고온수" Then
                        ' MsgBox("난방기기의 지역난방방식은 중온수 고정입니다.", MsgBoxStyle.Information, "확인")
                        D_DS = 0.4
                        theta_prim_DS = 150
                        Select Case dr난방.단열등급.Trim
                            Case "기본단열" '기본단열" '원래는 등급1/2 이지만 국내에서는 법적단열로 사용
                                B_DS = 4.3
                            Case "등급2/3" '등급2/3"
                                B_DS = 3.9
                            Case "등급3/4" '등급3/4"
                                B_DS = 3.5
                            Case "등급4/5" '등급4/5"
                                B_DS = 3.1
                        End Select
                    End If

                    theta_DS = D_DS * theta_prim_DS + (1 - D_DS) * 55 ' theta_sek_DS는 55도로 설정 (3.2.7-112)
                    Psi_DS = TOSG(dr난방.열교환기정격출력) ' .Worksheets("난방기기").Range("난방기기정격출력1").Offset(1, i_count_boiler - 1)
                    H_DS = TOSG(B_DS * Psi_DS ^ (1 / 3))
                    Q_h_g = Q_h_g + (H_DS * (theta_DS - theta_i)) * system_count '=====2013.08.13 수정
                    use_DH = use_DH + (H_DS * (theta_DS - theta_i)) * system_count '========2013.08.18 수정

                End If


            End If


            ' 전기보조에너지 Q_h_d_aux 산출 관련

            P_Pump = TOSG(dr난방.펌프동력) ' Worksheets("난방기기").Range("난방펌프제어유형1").Offset(1, i_count_boiler - 1)
            Select Case dr난방.펌프제어유형.Trim ' Worksheets("난방기기").Range("난방펌프제어유형1").Offset(0, i_count_boiler - 1)
                Case "비제어" '비제어"
                    c_p1 = 0.25
                    c_p2 = 0.75
                Case "정압" '정압"
                    c_p1 = 0.75
                    c_p2 = 0.25
                Case "변압" '변압"
                    c_p1 = 0.9
                    c_p2 = 0.1
            End Select

            If beta_h_d = 0 Then
                Q_h_d_aux_i = 0
            Else
                Q_h_d_aux_i = P_Pump / 1000 * beta_h_d * t_h * (c_p1 + c_p2 / beta_h_d) '(3.2.7-39)
            End If
            Select Case dr난방.펌프교정계수.Trim ' Worksheets("난방기기").Range("난방펌프교정계수1").Offset(0, i_count_boiler - 1)
                Case "정상가동" '정상가동"
                    f_P_A = 1
                Case "감소가동" '감소가동"
                    f_P_A = 0.6
                Case "가동정지" '"
                    f_P_A = 0
            End Select

            If t_h = 0 Or Q_h_d_aux_i = 0 Then '=========================================================================2014.03.07 추가

            Else
                Q_h_d_aux = TOSG(Q_h_d_aux + (Q_h_d_aux_i * (1.03 * t_h_rL + f_P_A * (t_h - t_h_rL)) / t_h) * system_count) '(3.2.7-40)
            End If                           '=========================================================================2014.03.07 추가





            If dr난방.축열탱크방식 = "축열탱크없음" Then
                P_Pump = 0 ' Dr난방.Worksheets("난방기기").Range("축열펌프정격전력1").Offset(0, i_count_boiler - 1)
            Else
                P_Pump = TOSG(dr난방.펌프정격전력) ' Dr난방.Worksheets("난방기기").Range("축열펌프정격전력1").Offset(0, i_count_boiler - 1)
                '=================================================================2010.11.04 위치 수정
                If dr난방.열생산기기방식 = "히트펌프" Then
                    If dr난방.운전방식.Trim = "동시가동" Then
                        Q_dot_h_max = TOSG(dr난방.히트난방용량) * TOSG(dr난방.보일러대수)
                    Else
                        Q_dot_h_max = TOSG(dr난방.히트난방용량) ' Worksheets("난방기기").Range("히트펌프사용연료1").Offset(1, i_count_boiler - 1)
                    End If

                End If

                If Q_dot_h_max = 0 Or t_h = 0 Then '============================================================2014.03.07 추가
                    beta_h_s = 0
                Else
                    beta_h_s = (Q_h_b + Q_h_ce + Q_h_d) / (Q_dot_h_max * t_h) '(3.2.7-9)
                End If                               '============================================================2014.03.07 추가


                If beta_h_s > 1 Then beta_h_s = 1
                t_P = beta_h_s * 24 * d_op_max_mth '(3.2.7-44)
                Q_h_s_aux = Q_h_s_aux + (P_Pump * t_P / 1000) * system_count '===2013.08.18 수정 '(3.2.7-44)
                '=================================================================2010.11.04 위치 수정

            End If
            If dr난방.열생산기기방식 = "보일러" Then 'Worksheets("난방기기").Range("열생산기기방식1").Offset(0, i_count_boiler - 1) = "보일러" Then

                P_aux_SB = 0.02

                Select Case dr난방.보일러방식.Trim ' Worksheets("난방기기").Range("보일러방식1").Offset(0, i_count_boiler - 1)
                    Case "가스보일러" '가스보일러"
                        P_aux_100 = TOSG((0.148 * Q_dot_N + 40) / 1000)
                        P_aux_pl = TOSG((0.148 * Q_dot_N + 40) / 1000)
                    Case "기름보일러" '기름보일러"
                        P_aux_100 = TOSG(0.045 * Q_dot_N ^ 0.48)
                        P_aux_pl = TOSG(0.015 * Q_dot_N ^ 0.48)
                    Case "저온가스보일러" '저온가스보일러"
                        P_aux_100 = TOSG((0.148 * Q_dot_N + 40) / 1000)
                        P_aux_pl = TOSG((0.148 * Q_dot_N + 40) / 1000)
                    Case "저온기름보일러" '저온기름보일러"
                        P_aux_100 = TOSG(0.045 * Q_dot_N ^ 0.48)
                        P_aux_pl = TOSG(0.015 * Q_dot_N ^ 0.48)
                    Case "콘덴싱보일러" '콘덴싱보일러"
                        P_aux_100 = TOSG(0.045 * Q_dot_N ^ 0.48)
                        P_aux_pl = TOSG(0.015 * Q_dot_N ^ 0.48)

                End Select

                If beta_h > beta_k_pl Then
                    P_h_g_aux = (beta_h - beta_k_pl) / (1 - beta_k_pl) * (P_aux_100 - P_aux_pl) + P_aux_pl '(3.2.7-82)
                Else
                    P_h_g_aux = (beta_h / beta_k_pl) * (P_aux_pl - P_aux_SB) + P_aux_SB '(3.2.7-81)
                End If

                If d_Nutz_mth = 0 Then '//201.11.20 추가(학교프로파일 적용시 문제점 해결)
                    t_w_100 = 0
                Else
                    t_w_100 = Q_w_outg / (Q_dot_N * d_Nutz_mth)
                End If

                Q_h_g_aux = Q_h_g_aux + (P_h_g_aux * (t_h_rL - t_w_100 * d_op_max_mth * d_Nutz_a / 365) + P_aux_SB * (24 * d_op_max_mth - t_h_rL)) * system_count '=====2013.08.18 수정 '(3.2.7-80)


            End If


            If dr난방.열생산기기방식 = "보일러" Then 'Worksheets("난방기기").Range("열생산기기방식1").Offset(0, i_count_boiler - 1) = "보일러" Then
                Select Case dr난방.사용연료.Trim ' Worksheets("난방기기").Range("난방기기사용연료1").Offset(0, i_count_boiler - 1)
                    Case "난방유" '난방유"
                        use_Oil = use_Oil + (Q_h_outg_i + Q_h_g_i) * system_count '========2013.08.18 수정

                    Case "천연가스" '천연가스"
                        use_LNG = use_LNG + (Q_h_outg_i + Q_h_g_i) * system_count '========2013.08.18 수정

                    Case "액화가스" '액화가스"
                        use_LPG = use_LPG + (Q_h_outg_i + Q_h_g_i) * system_count '========2013.08.18 수정

                End Select
            Else
                Select Case dr난방.열생산기기방식.Trim 'Worksheets("난방기기").Range("열생산기기방식1").Offset(0, i_count_boiler - 1)
                    '====================================================================2010.2.21 수정
                    Case "지역난방" '지역난방"
                        use_DH = use_DH + Q_h_outg_i * system_count '========2013.08.18 수정

                    Case "전기보일러" '전기보일러"
                        use_Elec = use_Elec + (Q_h_outg_i + (Q_h_outg_i * 0.09)) * system_count '========2013.08.18 수정 '2011.03.08 전기보일러 생산손실을 내부 생산식 저장으로 설정
                        '====================================================================2010.2.21 수정
                        '====================================================================2010.03.14 추가
                    Case "히트펌프"
                        Select Case dr난방.히트연료 ' Worksheets("난방기기").Range("히트펌프사용연료1").Offset(0, i_count_boiler - 1)
                            Case "전기"
                                use_Elec = use_Elec + Q_h_outg_i * system_count '========2013.08.18 수정

                            Case "천연가스"
                                use_LNG = use_LNG + Q_h_outg_i * system_count '========2013.08.18 수정

                            Case "액화가스"
                                use_LPG = use_LPG + Q_h_outg_i * system_count '========2013.08.18 수정

                        End Select
                        '====================================================================2010.03.14 추가
                End Select

            End If

        End If
    End Sub

    Private Sub Calc_난방_개별기기적용시(dr난방 As DS.tbl_nanbangkikiRow, mon As String, 비율 As Decimal, i_count_month As Integer, theta_e As Decimal)

        pLog.Add(" >> Enter : Calc_난방_개별기기적용시")
        '//이 난방기기가 존전체내역에서 사용이되엇나?

        Dim dr존데이터() As DS.tbl_zoneRow = DSET.tbl_zone.Select("(공조난방생산기기 = '" & dr난방.code & "' and 냉난방공조 <> '기능없음' and (외기부하처리여부 = '예' or 냉난방공조 = '냉난방' or 냉난방공조 = '난방') ) or (열생산난방생산기기='" & dr난방.code & "'  and 냉난방방식 <> '냉방' and 냉난방방식 <> '기능없음') ")
        If dr존데이터.Length > 0 Then
            '"(공조난방생산기기 = '" & Dr난방.code & "' and 냉난방공조 <> '기능없음' and (외기부하처리여부 = '예' or 냉난방공조 = '냉난방' or 냉난방공조 = '난방') ) or (열생산난방생산기기='" & Dr난방.code & "'  and 냉난방방식 <> '냉방' and 냉난방방식 <> '기능없음') "
            Q_h_b = 0
            Q_h_ce = 0
            Q_dot_h_max = 0
            t_h_max = 0
            t_h = 0   '원래 식은 t_h = t_h_op + t_h_we 월간 난방 시간
            t_h_op_d = 0
            Q_h_d = 0
            Q_h_s = 0
            n_beta = 0 ' 순차가동시 full 부하 대수
            Q_h_g_v_i = 0
            '==================================2010.2.21 수정
            d_op_max_mth = 0
            d_Nutz_mth = 0
            '==================================2010.2.21 수정
            Q_w_outg = 0 '=================================2013.12.18 추가
        End If

        'If DSET.tbl_zone.Select("(공조난방생산기기 = '" & dr난방.code & "' and 냉난방공조 <> '기능없음' and (외기부하처리여부 = '예' or 냉난방공조 = '냉난방' or 냉난방공조 = '난방') ) or (열생산난방생산기기='" & dr난방.code & "'  and 냉난방방식 <> '냉방' and 냉난방방식 <> '기능없음') ").GetUpperBound(0) <> -1 Then 'If Worksheets("난방기기").Range("난방생산기기1").Offset(4, i_count_boiler - 1) = "예" Then


        For Each DR존 As DS.tbl_zoneRow In dr존데이터

            '//지금 사용하는 존이 공조에의한것인지 아닌지를 판단
            Dim 판단1 As Boolean = False
            Dim 판단2 As Boolean = False
            If DR존.열생산난방생산기기 = dr난방.code Then 판단1 = True
            If DR존.공조난방생산기기 = dr난방.code Then 판단2 = True

            '//다시 생각을...

            'If Worksheets("입력존").Range("입력난방생산기기1").Offset(0, i_count_zone - 1) <> "" And Worksheets("입력존").Range("입력난방생산기기1").Offset(0, i_count_zone - 1) = Worksheets("난방기기").Range("난방생산기기1").Offset(0, i_count_boiler - 1) Then
            '  If DR존.열생산난방생산기기 = Dr난방.code Then ' Worksheets("난방기기").Range("난방생산기기1").Offset(0, i_count_boiler - 1) Then
            '=========================================================================================================================================================2010.2.21 수정
            '1105 소스백업 If DR존.냉난방방식 = "냉난방" OrElse DR존.냉난방방식 = "난방" Then ' Worksheets("입력존").Range("공조존2").Offset(0, i_count_zone - 1) <> "냉난방" Then
            If 판단1 And (DR존.냉난방방식 = "냉난방" OrElse DR존.냉난방방식 = "난방") Then
                Dim Dr월에너지 As DSR.월별에너지분석Row = CType(DSETR.월별에너지분석.Select("월='" & mon & "' and 존='" & DR존.code & "'")(0), DSR.월별에너지분석Row)
                Dim Drow최대() As DSR.최대냉난방부하Row = CType(DSETR.최대냉난방부하.Select("Zone='" & DR존.code & "'"), DSR.최대냉난방부하Row())

                system_count = IIf(dr난방.개별기기적용 = "0", 1, TOSG(DR존.입력존의수)) '===========2013.08.18 추가

                'If dr난방.헤더적용 Then
                '    Q_h_b_i = a_Q_h_b_i
                '    Q_h_b_i *= 비율 '//130818
                '    Q_h_b = Q_h_b_i
                '    Q_dot_h_max = a_Q_dot_h_max
                'Else
                If (DR존.냉난방공조 = "환기" OrElse DR존.냉난방공조 = "냉방") And DR존.외기부하처리여부 = "예" Then
                    Q_h_b_i = TOSG(Dr월에너지.난방요구량열) / system_count '===========2012.08.18 수정
                Else
                    Q_h_b_i = TOSG(Dr월에너지.난방요구량열 + Dr월에너지.난방요구량공조) / system_count '===========2012.08.18 수정 ' Sheets("" & i_count_month & "").Cells(7, 7 + i_count_zone)
                End If
                Q_h_b = Q_h_b_i
                '=========================================================================================================================================================2010.2.21 수정
                Q_dot_h_max = TOSG(Q_dot_h_max + TOSG(Drow최대(0).최대난방기기부하)) ' Worksheets("0").Range("최대난방부하1").Offset(0, i_count_zone - 1)
                'End If

                '===================================================================================2010.2.21 수정
                'If dr난방.헤더적용 Then
                '    d_op_mth = a_d_op_mth
                '    t_h = a_t_h
                '    d_op_max_mth = a_d_op_max_mth
                '    t_h_max = a_t_h_max
                '    t_h_op_d = a_t_h_op_d
                'Else
                Dim DR프로필 As DS.tbl_profileRow = CType(DSET.tbl_profile.Select("code='" & DR존.프로필 & "' and code <> '0'")(0), DS.tbl_profileRow)
                If i_count_month = 0 Then
                    d_op_mth = 0
                Else
                    d_op_mth = CInt(TOSG(DR프로필("day" & Format(i_count_month, "00"))))
                End If

                If t_h < TOSG(Drow최대(0).난방최대가동시간) * d_op_mth Then
                    t_h = CInt(TOSG(Drow최대(0).난방최대가동시간) * d_op_mth)
                End If
                If d_op_max_mth < d_op_mth Then
                    d_op_max_mth = d_op_mth
                End If
                '===================================================================================2010.2.21 수정
                If t_h > t_h_max Then t_h_max = t_h
                If t_h_op_d < TOSG(Drow최대(0).난방최대가동시간) Then t_h_op_d = CInt(TOSG(Drow최대(0).난방최대가동시간)) ' Sheets("0").Range("최대난방부하1").Offset(2, i_count_zone - 1)
                'i_ce = 0
                'End If

                '//아래 if 문이 모두 공급기기 데이터를 가지고 게산을 하고잇네요 이 부분을 전부 실행못하게 해야합니다.
                If DR존.냉난방열공급시스템 = "0" Then
                    '//0일떄 특정 변수를 초기화(=0) 하려면 이곳에 입력하세요.
                Else

                    Dim Dr공급 As DS.tbl_kongkubRow = CType(DSET.tbl_kongkub.Select("code='" & DR존.냉난방열공급시스템 & "' and code <> '0'")(0), DS.tbl_kongkubRow)

                    If (DR존.천장고 = "" OrElse TOSG(DR존.천장고) < 4) Then ' Worksheets("입력존").Range("천장고1").Offset(0, i_count_zone - 1) < 4 Then

                        Select Case Dr공급.열공급시스템.Trim '  Dr공급.열공급시스템
                            Case "노출형방열기(열)" '노출형방열기(열)"
                                eta_L = (0.93 + 0.95) / 2
                                eta_B = 1
                                Select Case Dr공급.노출형제어.Trim 'Dr공급.노출형제어
                                    Case "비제어" '비제어"
                                        eta_C = 0.8
                                    Case "on/off제어"
                                        eta_C = 0.88
                                    Case "PI제어" 'PI제어"
                                        eta_C = 0.97
                                End Select
                            Case "바닥난방(열)" '바닥난방(열)"
                                eta_L = 1
                                Select Case Dr공급.바닥난방열제어.Trim ' Dr공급.바닥난방열제어
                                    Case "비제어" '비제어"
                                        eta_C = 0.78
                                    Case "on/off제어"
                                        eta_C = 0.88
                                    Case "PI제어" 'PI제어"
                                        eta_C = 0.95
                                End Select
                                Select Case Dr공급.바닥난방열건축부위.Trim ' Worksheets("난방공급시스템").Range("바닥열시스템1").Offset(0, i_ce - 1)
                                    Case "습식" '습식"
                                        eta_B = (0.93 + 0.95) / 2
                                    Case "반건식" '반건식"
                                        eta_B = (0.95 + 0.95) / 2
                                    Case "건식" '건식"
                                        eta_B = (0.98 + 0.95) / 2
                                End Select
                            Case "바닥난방(전기)" '바닥난방(전기)"
                                eta_L = 1
                                Select Case Dr공급.바닥난방전기제어.Trim ' Dr공급.바닥난방전기제어
                                    Case "비제어" '비제어"
                                        eta_C = 0.91
                                    Case "on/off제어"
                                        eta_C = 0.93 '2011.05.03  추가, 우선 on/off 제어와 PI제어를 같게 적용, 추후검토
                                    Case "PI제어" 'PI제어"
                                        eta_C = 0.93
                                End Select
                                Select Case Dr공급.바닥난방전기건축부위.Trim ' Worksheets("난방공급시스템").Range("바닥전기시스템1").Offset(0, i_ce - 1)
                                    Case "습식" '습식"
                                        eta_B = (0.93 + 0.95) / 2
                                    Case "반건식" '반건식"
                                        eta_B = (0.95 + 0.95) / 2
                                    Case "건식" '건식"
                                        eta_B = (0.98 + 0.95) / 2
                                End Select
                            Case "전기난방" '전기난방"
                                eta_L = 2 ' eta_h_ce 값을 맞추기 위해서 임의로 설정한 값(전기난방은 eta_h_ce 값이 바로 정해지기때문)
                                eta_B = 2 ' eta_h_ce 값을 맞추기 위해서 임의로 설정한 값(전기난방은 eta_h_ce 값이 바로 정해지기때문)
                                Select Case Dr공급.전기난방제어.Trim ' Dr공급.바닥난방전기제어
                                    Case "비제어"
                                        eta_C = -1.1235955 '2011.05.03 추가, 우선 on/off 제어와 비제어를 같게 적용, 추후검토
                                    Case "on/off제어"
                                        eta_C = -1.1235955 ' eta_h_ce 0.89 값을 맞추기 위해서 임의로 설정한 값(전기난방은 eta_h_ce 값이 바로 정해지기때문)
                                    Case "PI제어" 'PI제어"
                                        eta_C = -1.07527 ' eta_h_ce 0.93 값을 맞추기 위해서 임의로 설정한 값(전기난방은 eta_h_ce 값이 바로 정해지기때문)
                                End Select
                        End Select
                        f_Radiant = 1
                    Else
                        If TOSG(DR존.천장고) >= 4 And TOSG(DR존.천장고) < 10 Then

                            Select Case Dr공급.열공급시스템.Trim '  Dr공급.열공급시스템
                                Case "노출형방열기(열)" '노출형방열기(열)"
                                    f_Radiant = 1
                                    eta_L = 0.9
                                    eta_B = 1
                                    Select Case Dr공급.노출형제어.Trim 'Dr공급.노출형제어
                                        Case "비제어" '비제어"
                                            eta_C = 0.8
                                        Case "on/off제어"
                                            eta_C = 0.93
                                        Case "PI제어" 'PI제어"
                                            eta_C = 0.97
                                    End Select
                                Case "바닥난방(열)" '바닥난방(열)"
                                    f_Radiant = 0.85
                                    eta_L = 0.98
                                    Select Case Dr공급.바닥난방열제어.Trim ' Dr공급.바닥난방열제어
                                        Case "비제어" '비제어"
                                            eta_C = 0.8
                                        Case "on/off제어"
                                            eta_C = 0.93
                                        Case "PI제어" 'PI제어"
                                            eta_C = 0.97
                                    End Select
                                    eta_B = 0.95
                                Case "바닥난방(전기)" '바닥난방(전기)"
                                    f_Radiant = 0.85
                                    eta_L = 0.98
                                    Select Case Dr공급.바닥난방전기제어.Trim ' Dr공급.바닥난방전기제어
                                        Case "비제어" '비제어"
                                            eta_C = 0.8
                                        Case "on/off제어"
                                            eta_C = 0.93
                                        Case "PI제어" 'PI제어"
                                            eta_C = 0.97
                                    End Select
                                    eta_B = 0.95
                                Case "전기난방" '전기난방"
                                    f_Radiant = 1
                                    eta_L = 0.935
                                    eta_B = 1
                                    Select Case Dr공급.바닥난방전기제어.Trim ' Dr공급.바닥난방전기제어
                                        Case "비제어" '비제어"
                                            eta_C = 0.8
                                        Case "on/off제어"
                                            eta_C = 0.93
                                        Case "PI제어" 'PI제어"
                                            eta_C = 0.97
                                    End Select
                            End Select
                        Else


                            Select Case Dr공급.열공급시스템.Trim
                                Case "노출형방열기(열)" '노출형방열기(열)"
                                    f_Radiant = 1
                                    eta_L = 0.72 ' 우선 15m 기준 설정
                                    eta_B = 1
                                    Select Case Dr공급.노출형제어.Trim
                                        Case "비제어"
                                            eta_C = 0.8
                                        Case "on/off제어"
                                            eta_C = 0.93
                                        Case "PI제어"
                                            eta_C = 0.97
                                    End Select
                                Case "바닥난방(열)" '바닥난방(열)"
                                    f_Radiant = 0.85
                                    eta_L = 0.92
                                    Select Case Dr공급.바닥난방열제어.Trim
                                        Case "비제어"
                                            eta_C = 0.8
                                        Case "on/off제어"
                                            eta_C = 0.93
                                        Case "PI제어"
                                            eta_C = 0.97
                                    End Select
                                    eta_B = 0.95
                                Case "바닥난방(전기)" '바닥난방(전기)"
                                    f_Radiant = 0.85
                                    eta_L = 0.92
                                    Select Case Dr공급.바닥난방전기제어.Trim
                                        Case "비제어"
                                            eta_C = 0.8
                                        Case "on/off제어"
                                            eta_C = 0.93
                                        Case "PI제어"
                                            eta_C = 0.97
                                    End Select
                                    eta_B = 0.95
                                Case "전기난방" '전기난방"
                                    f_Radiant = 1
                                    eta_L = 0.78
                                    eta_B = 1
                                    Select Case Dr공급.바닥난방전기제어.Trim
                                        Case "비제어"
                                            eta_C = 0.8
                                        Case "on/off제어"
                                            eta_C = 0.93
                                        Case "PI제어"
                                            eta_C = 0.97
                                    End Select
                            End Select

                        End If

                    End If

                    eta_h_ce = 1 / (4 - (eta_L + eta_C + eta_B)) '(3.27-28)

                    Q_h_ce_i = (f_Radiant * f_int * f_hydr / eta_h_ce - 1) * Q_h_b_i '(3.2.7-27)
                    Q_h_ce = Q_h_ce_i

                End If
            End If '//판단1 //난방생산기기 완료

            If DR존.냉난방공조 = "냉난방" OrElse DR존.냉난방공조 = "난방" OrElse ((DR존.냉난방공조 = "환기" OrElse DR존.냉난방공조 = "냉방") And DR존.외기부하처리여부 = "예") Then ' 공조기 사용에 따른 난방에너지
                '=========================================================================================================================================================2010.2.21 수정
                system_count = IIf(dr난방.개별기기적용 = "0", 1, TOSG(DR존.입력존의수))   '//20130818
                If system_count = 0 Then system_count = 1

                If 판단2 Then

                    'If dr난방.헤더적용 Then
                    '    Q_h_b_i = a_Q_h_b_i
                    '    Q_h_b_i *= 비율 '//130818
                    '    Q_h_b = Q_h_b_i '//Q_c_b + Q_c_b_i

                    'Else
                    Dim 월에너지분석 As DSR.월별에너지분석Row = CType(DSETR.월별에너지분석.Select("월='" & mon & "' and 존='" & DR존.code & "'")(0), DSR.월별에너지분석Row)
                    If (DR존.냉난방공조 = "환기" OrElse DR존.냉난방공조 = "냉방") And DR존.외기부하처리여부 = "예" Then '// 2010.11.19 추가
                        Q_h_b_i = TOSG(월에너지분석.난방요구량공조) / system_count '=========2013.08.18 수정
                    Else
                        Q_h_b_i = TOSG(월에너지분석.공조요구량난방) / system_count '=========2013.08.18 수정 ' Sheets("" & i_count_month & "").Cells(19, 7 + i_count_zone)
                    End If
                    Q_h_b = Q_h_b_i
                    'End If
                    'Q_h_ce_i = 0 '공조기는 0으로 설정 '==============================================================2010.03.20 수정 공조기는 0으로 설정한 것을 수정
                    If (DR존.냉난방공조 = "환기" OrElse DR존.냉난방공조 = "냉방") And DR존.외기부하처리여부 = "예" Then '// 2010.11.19 추가

                    Else
                        If TOSG(DR존.천장고p) >= 4 Then
                            If TOSG(DR존.천장고p) >= 20 Then
                                Q_h_ce_i = TOSG((1 / (1 / (4 - (0.71 + 0.97 + 1))) - 1) * Q_h_b_i)
                            Else
                                If TOSG(DR존.천장고p) >= 15 Then
                                    Q_h_ce_i = TOSG((1 / (1 / (4 - (0.78 + 0.97 + 1))) - 1) * Q_h_b_i)
                                Else
                                    If TOSG(DR존.천장고p) >= 12 Then
                                        Q_h_ce_i = TOSG((1 / (1 / (4 - (0.84 + 0.97 + 1))) - 1) * Q_h_b_i)
                                    Else
                                        If TOSG(DR존.천장고p) >= 10 Then
                                            Q_h_ce_i = TOSG((1 / (1 / (4 - (0.87 + 0.97 + 1))) - 1) * Q_h_b_i)
                                        Else
                                            If TOSG(DR존.천장고p) >= 8 Then
                                                Q_h_ce_i = TOSG((1 / (1 / (4 - (0.91 + 0.97 + 1))) - 1) * Q_h_b_i)
                                            Else
                                                If TOSG(DR존.천장고p) >= 6 Then
                                                    Q_h_ce_i = TOSG((1 / (1 / (4 - (0.96 + 0.97 + 1))) - 1) * Q_h_b_i)
                                                Else
                                                    Q_h_ce_i = TOSG((1 / (1 / (4 - (0.99 + 0.97 + 1))) - 1) * Q_h_b_i)
                                                End If
                                            End If
                                        End If
                                    End If
                                End If
                            End If
                        End If

                        '===============================================================================================2010.03.20 수정

                        Q_h_ce = Q_h_ce_i
                    End If

                    'If dr난방.헤더적용 Then
                    '    Q_dot_h_max = a_Q_dot_h_max
                    '    d_op_mth = a_d_op_mth
                    '    t_h = a_t_h
                    '    d_op_max_mth = a_d_op_max_mth
                    '    t_h_max = a_t_h_max
                    '    t_h_op_d = a_t_h_op_d
                    'Else
                    '//프로필
                    Dim Drow최대() As DSR.최대냉난방부하Row = CType(DSETR.최대냉난방부하.Select("zone='" & DR존.code & "'"), DSR.최대냉난방부하Row())
                    Dim Dr프로필 As DS.tbl_profileRow = CType(DSET.tbl_profile.Select("code='" & DR존.프로필 & "' and code <> '0'")(0), DS.tbl_profileRow)
                    Q_dot_h_max = TOSG(Q_dot_h_max + TOSG(Drow최대(0).최대난방기기부하)) / system_count '=====2013.08.18 수정 ' Worksheets("0").Range("최대난방부하1").Offset(0, i_count_zone - 1)

                    If i_count_month = 0 Then
                        d_op_mth = 0
                    Else
                        d_op_mth = CInt(TOSG(Dr프로필("day" & Format(i_count_month, "00"))))
                    End If
                    If t_h < TOSG(Drow최대(0).난방최대가동시간) * d_op_mth Then t_h = CInt(TOSG(Drow최대(0).난방최대가동시간) * d_op_mth)
                    If d_op_max_mth < d_op_mth Then d_op_max_mth = d_op_mth
                    If t_h > t_h_max Then t_h_max = t_h
                    If t_h_op_d < TOSG(Drow최대(0).난방최대가동시간) Then t_h_op_d = CInt(TOSG(Drow최대(0).난방최대가동시간)) ' Sheets("0").Range("최대난방부하1").Offset(2, i_count_zone - 1)

                    'End If
                End If
                '=========================================================================================================================================================2010.2.21 수정
            End If
            '//공조 난방기기 완료 ㅋㅋ 끝
            ' End If

            '==================================2010.2.21 수정
            d_Nutz_mth = d_op_max_mth
            '==================================2010.2.21 수정
            'beta_h_d = (Q_h_b + Q_h_ce) / (Q_dot_h_max * t_h_max)  ' t_h 가 t_h_max 일 것으로 추정 추후 검토

            'theta_VA = TOSG(Dr난방.급수온도) ' Worksheets("난방기기").Range("난방기기급수온도1").Offset(0, i_count_boiler - 1)
            'theta_RA = TOSG(Dr난방.환수온도) ' Worksheets("난방기기").Range("난방기기환수온도1").Offset(0, i_count_boiler - 1)

            'theta_VL_m_beta_h_d = TOSG((theta_VA - theta_i_h_soll) * beta_h_d ^ (1 / n) + theta_i_h_soll) '(3.2.7.13)
            'theta_RL_m_beta_h_d = TOSG((theta_RA - theta_i_h_soll) * beta_h_d ^ (1 / n) + theta_i_h_soll) '(3.2.7.14)


            'theta_HK_m_beta_h_d = TOSG(0.5 * (theta_VL_m_beta_h_d + theta_RL_m_beta_h_d))


            'f_L_WA = 1 - (theta_WA_Grenz - theta_e) / (theta_WA_Grenz - theta_e_min) '(3.2.7-22)
            'd_h_rB = TOSG(d_op_max_mth * ((365 - f_L_WA * (365 - d_Nutz_a)) / 365) * (t_h / (d_op_max_mth * 24))) '(3.2.7-21) '================== d_op_max_mth 2010.2.21 수정'CSng(d_mth * ((365 - f_L_WA * (365 - d_Nutz_a)) / 365) * (t_h / (d_mth * 24))) '(3.2.7-21)

            'f_L_NA = 1 - (theta_NA_Grenz - theta_e) / (theta_NA_Grenz - theta_e_min) '(3.2.7-20)
            't_h_rL_T = 24 - f_L_NA * (24 - t_h_op_d) '(3.2.7-19)
            't_h_rL = t_h_rL_T * d_h_rB '(3.2.7-23)


            '===================================================================2010.11.04 위치수정 및 추가 '2011.03.16 다시 수정
            If dr난방.열생산기기방식 = "히트펌프" Then
                If dr난방.운전방식.Trim = "동시가동" Then
                    Q_dot_h_max = TOSG(dr난방.히트난방용량) * TOSG(dr난방.보일러대수)
                Else
                    Q_dot_h_max = TOSG(dr난방.히트난방용량) ' Worksheets("난방기기").Range("히트펌프사용연료1").Offset(1, i_count_boiler - 1)
                End If

            End If

            If Q_dot_h_max = 0 Or t_h_max = 0 Then '==========================================================2014.03.07 추가
                beta_h_d = 0
            Else
                beta_h_d = (Q_h_b + Q_h_ce) / (Q_dot_h_max * t_h_max)
            End If                                 '==========================================================2014.03.07 추가


            ' t_h 가 t_h_max 일 것으로 추정 추후 검토

            If beta_h_d > 1 Then beta_h_d = 1

            theta_VA = TOSG(dr난방.급수온도) ' Worksheets("난방기기").Range("난방기기급수온도1").Offset(0, i_count_boiler - 1)
            theta_RA = TOSG(dr난방.환수온도) ' Worksheets("난방기기").Range("난방기기환수온도1").Offset(0, i_count_boiler - 1)

            theta_VL_m_beta_h_d = TOSG((theta_VA - theta_i_h_soll) * beta_h_d ^ (1 / n) + theta_i_h_soll) '(3.2.7.13)
            theta_RL_m_beta_h_d = TOSG((theta_RA - theta_i_h_soll) * beta_h_d ^ (1 / n) + theta_i_h_soll) '(3.2.7.14)


            theta_HK_m_beta_h_d = TOSG(0.5 * (theta_VL_m_beta_h_d + theta_RL_m_beta_h_d))

            If theta_WA_Grenz - theta_e_min = 0 Then '==================================================2014.03.07 추가
                f_L_WA = 1
            Else
                f_L_WA = 1 - (theta_WA_Grenz - theta_e) / (theta_WA_Grenz - theta_e_min) '(3.2.7-22)
            End If '==================================================2014.03.07 추가

            If d_op_max_mth = 0 Then
                d_h_rB = 0
            Else
                d_h_rB = TOSG(d_op_max_mth * ((365 - f_L_WA * (365 - d_Nutz_a)) / 365) * (t_h / (d_op_max_mth * 24))) '(3.2.7-21) '================== d_op_max_mth 2010.2.21 수정'CSng(d_mth * ((365 - f_L_WA * (365 - d_Nutz_a)) / 365) * (t_h / (d_mth * 24))) '(3.2.7-21)
            End If

            If theta_NA_Grenz - theta_e_min = 0 Then '==================================================2014.03.07 추가
                f_L_NA = 1
            Else
                f_L_NA = 1 - (theta_NA_Grenz - theta_e) / (theta_NA_Grenz - theta_e_min) '(3.2.7-20)
            End If '==================================================2014.03.07 추가


            t_h_rL_T = 24 - f_L_NA * (24 - t_h_op_d) '(3.2.7-19)
            t_h_rL = t_h_rL_T * d_h_rB '(3.2.7-23)
            '===================================================================2010.11.04 위치수정 및 추가  '2011.03.16 다시 수정



            '=================================================2010. 02. 11 수정
            For Each Dr난방분배 As DS.tbl_nbunbaeRow In DSET.tbl_nbunbae.Select("생산기기구분='" & dr난방.code & "' and code <> '0'", "code")
                'If Dr난방.code = Dr난방분배.생산기기구분 Then '  Worksheets("난방분배시스템").Range("분배생산기기1").Offset(0, i_count_pipe - 1) Then

                Select Case Dr난방분배.표준치적용.Trim ' Worksheets("난방분배시스템").Range("분배생산기기1").Offset(1, i_count_pipe - 1)
                    Case "상세입력" '상세입력"
                        L_i = TOSG(Dr난방분배.배관구간길이) '= Worksheets("난방분배시스템").Range("배관구간방식1").Offset(1, i_count_pipe - 1)
                        U_i = TOSG(Dr난방분배.열관류율) ' Worksheets("난방분배시스템").Range("배관구간방식1").Offset(2, i_count_pipe - 1)
                        Select Case Dr난방분배.배관설치장소.Trim ' Worksheets("난방분배시스템").Range("배관구간방식1").Offset(3, i_count_pipe - 1)
                            Case "표준난방존" '표준난방존"
                                Q_h_d = (Q_h_d + U_i * (theta_HK_m_beta_h_d - theta_i_h_soll) * L_i * t_h_rL) / 1000
                            Case "표준비난방존" '표준비난방존"
                                Q_h_d = (Q_h_d + U_i * (theta_HK_m_beta_h_d - 13) * L_i * t_h_rL) / 1000
                            Case "외부" '외부"
                                Q_h_d = (Q_h_d + U_i * (theta_HK_m_beta_h_d - theta_e) * L_i * t_h_rL) / 1000
                        End Select
                    Case "표준치조건" '표준치조건"
                        L_G = TOSG(Dr난방분배.건물길이x) ' Worksheets("난방분배시스템").Range("난방분배건물길이1").Offset(0, i_count_pipe - 1)
                        B_G = TOSG(Dr난방분배.건물길이y) ' Worksheets("난방분배시스템").Range("난방분배건물길이1").Offset(1, i_count_pipe - 1)
                        n_G = TOSG(Dr난방분배.층수) 'Worksheets("난방분배시스템").Range("난방분배건물길이1").Offset(2, i_count_pipe - 1)
                        h_G = TOSG(Dr난방분배.층고) ' Worksheets("난방분배시스템").Range("난방분배건물길이1").Offset(3, i_count_pipe - 1)
                        If dr난방.배관망유형 = "이중배관" Then ' then Worksheets("난방기기").Range("난방기기배관망1").Offset(0, i_count_boiler - 1) = "이중배관" Then
                            If Dr난방분배.지관장소 = "외부" Then ' then외부" Then
                                L_i = TOSG((2 * L_G + 0.01625 * L_G * B_G * B_G) * 0.2 + (0.025 * L_G * B_G * h_G * n_G) * 0.255 + (0.55 * L_G * B_G * n_G) * 0.255) '외부배관난방적용
                            Else
                                L_i = TOSG((2 * L_G + 0.0325 * L_G * B_G + 6) * 0.2 + (0.025 * L_G * B_G * h_G * n_G) * 0.255 + (0.55 * L_G * B_G * n_G) * 0.255) '내부배관난방적용
                            End If
                        Else
                            L_i = TOSG((2 * L_G + 0.0325 * L_G * B_G + 6) * 0.2 + (0.025 * L_G * B_G * h_G * n_G + 2 * (L_G + B_G) * n_G) * 0.255 + (0.1 * L_G * B_G * n_G) * 0.255) '단일배관난방적용
                        End If
                        Q_h_d = (Q_h_d + (theta_HK_m_beta_h_d - theta_i_h_soll) * L_i * t_h_rL) / 1000 '(3.2.7-36) 'theta_i를 theta_i_h_soll 로 수정 추후 검토 ' U_i는 L_i에 포함
                    Case Else
                        MsgBox("표준치적용을 알수없습니다", MsgBoxStyle.Critical, Dr난방분배.표준치적용)
                End Select
                'End If
            Next

            '=================================================2010. 02. 11 수정
            If dr난방.축열탱크방식 <> "축열탱크없음" Then ' Worksheets("난방기기").Range("난방기기축열탱크1").Offset(0, i_count_boiler - 1) <> "축열탱크없음" Then
                V_s = TOSG(dr난방.축열제척) ' Worksheets("난방기기").Range("난방기기축열체적1").Offset(0, i_count_boiler - 1)
                q_B_S = TOSG(0.4 + 0.14 * V_s ^ 0.45) '(3.2.7-43)
                Q_h_s = f_verbindung * (theta_VA - theta_i) / 45 * d_op_max_mth * q_B_S '(3.2.7-41) theta_h_s 는 theta_VA 로 설정'================== d_op_max_mth 2010.2.21 수정
            End If

            '===================================================================================================================2010.2.21 수정
            Q_h_outg_i = Q_h_b + Q_h_ce + Q_h_d + Q_h_s '(3.2.7-1)

            If dr난방.열생산기기방식 = "전기보일러" Then
                Q_h_outg_i = Q_h_outg_i / (TOSG(dr난방.정격보일러효율) * age_heating / 100)
            End If




            Q_h_outg = Q_h_outg + Q_h_outg_i * system_count '=====2013.08.13 수정  '(3.2.7-1)
            '===================================================================================================================2010.2.21 수정

            If dr난방.열생산기기방식 = "보일러" Then ' Worksheets("난방기기").Range("열생산기기방식1").Offset(0, i_count_boiler - 1) = "보일러" Then
                '//아래는 급탕생산기기로 지정되어잇는가?
                If DSET.tbl_zone.Select("열생산급탕생산기기='" & dr난방.code & "'").GetUpperBound(0) <> -1 Then 'If Worksheets("난방기기").Range("난방생산기기1").Offset(5, i_count_boiler - 1) = "예" Then
                    Q_w_b = 0
                    For Each Dr입력존 As DS.tbl_zoneRow In DSET.tbl_zone.Select("code <> '0' and 열생산급탕생산기기='" & dr난방.code & "'", "code")
                        Dim Drow최대() As DSR.최대냉난방부하Row = CType(DSETR.최대냉난방부하.Select("zone='" & Dr입력존.code & "'"), DSR.최대냉난방부하Row())
                        Dim Dr월에너지분석 As DSR.월별에너지분석Row = CType(DSETR.월별에너지분석.Select("월='" & mon & "' and 존='" & Dr입력존.code & "'")(0), DSR.월별에너지분석Row)

                        Dim system_count_2 As Decimal = IIf(dr난방.개별기기적용 = "0", 1, TOSG(Dr입력존.입력존의수))   '//20130818  '=====2013.12.18 system_count_2 추가

                        'Q_w_b = TOSG(Q_w_b + (TOSG(Dr월에너지분석.급탕요구량) / system_count_2)) 'Sheets("" & i_count_month & "").Cells(15, 7 + i_count_zone)  '=====2013.12.18 system_count_2 추가
                        Q_w_b = TOSG(Dr월에너지분석.급탕요구량) / system_count_2 'Sheets("" & i_count_month & "").Cells(15, 7 + i_count_zone)  '=====2013.12.18 system_count_2 추가 '=============2014.05.29 누적오류 수정
                        '===================================================================================2010.2.21 수정
                        Dim Dr프로필 As DS.tbl_profileRow = CType(DSET.tbl_profile.Select("code='" & Dr입력존.프로필 & "'")(0), DS.tbl_profileRow)

                        If i_count_month = 0 Then
                            d_op_mth = 0
                        Else
                            d_op_mth = CInt(TOSG(Dr프로필("day" & Format(i_count_month, "00"))))
                        End If

                        If t_h < TOSG(Drow최대(0).난방최대가동시간) * d_op_mth Then
                            t_h = CInt(TOSG(Drow최대(0).난방최대가동시간) * d_op_mth)
                        End If
                        If d_op_max_mth < d_op_mth Then
                            d_op_max_mth = d_op_mth
                        End If
                        '===================================================================================2010.2.21 수정                          
                    Next
                End If
            End If


            ' 여기에 신재생에너지를 산출하고 Q_h_outg 와 Q_h_outg_i 에서 신재생에너지를 차감해야
            '----------------------------------------------------------------------------------------------------------------------------------
            '----------------------------------------------------------------------------------------------------------------------------------

            '신재생 및 열병합 시스템
            Dim CRenew As New CRenewable(DSET, Result)
            ' Dim Dr신재생 As DS.tbl_newRow = CType(DSET.tbl_new.Rows(0), DS.tbl_newRow)
            If dr난방.신재생연결여부 = "시스템연결" AndAlso dr난방.연결된시스템.Trim <> "" AndAlso dr난방.연결된시스템 <> "0" Then '  Worksheets("난방기기").Range("신재생난방연결1").Offset(0, i_count_boiler - 1) = "시스템연결" Then
                Dim Dr신재생 As DS.tbl_newRow = CType(DSET.tbl_new.Select("code='" & dr난방.연결된시스템 & "' and code <> '0'")(0), DS.tbl_newRow)
                '//식은 맞는듯한게 값이 이상하게 들었네요... 뭘해도 되도록 수정해버리죠 ㅋㅋ


                Select Case Dr신재생.기기종류.Trim ' Dr난방.연결된시스템.Trim
                    Case "지열" '//지열
                        Select Case Dr신재생.가동연료.Trim
                            Case "전기" '전기"
                                CRenew.Calc_HeatpumpSystem(system_type, i_HeatCool, Dr신재생, Q_h_outg_i, i_count_month, d_op_max_mth, t_h, theta_VA, theta_i, Q_hp_outg, Q_h_f_hp, Q_h_g_hp_aux) '=============2010.04.01 수정 Q_h_outg 를 Q_h_outg_i 로 수정
                                Q_h_outg = Q_h_outg - Q_hp_outg
                                Q_h_outg_i = Q_h_outg_i - Q_hp_outg
                                use_Elec = use_Elec + (Q_h_f_hp + Q_h_g_hp_aux) * system_count '=============2013.08.18 수정
                                Q_h_f = Q_h_f + (Q_h_f_hp + Q_h_g_hp_aux) * system_count '=============2013.08.18 수정  '============================2010.04.17 추가
                            Case "천연가스" '천연가스"
                                CRenew.Calc_HeatpumpSystem(system_type, i_HeatCool, Dr신재생, Q_h_outg_i, i_count_month, d_op_max_mth, t_h, theta_VA, theta_i, Q_hp_outg, Q_h_f_hp, Q_h_g_hp_aux) '=============2010.04.01 수정 Q_h_outg 를 Q_h_outg_i 로 수정
                                Q_h_outg = Q_h_outg - Q_hp_outg
                                Q_h_outg_i = Q_h_outg_i - Q_hp_outg
                                use_LNG = use_LNG + Q_h_f_hp * system_count '=============2013.08.18 수정
                                use_Elec = use_Elec + Q_h_g_hp_aux * system_count '=============2013.08.18 수정
                                Q_h_f = Q_h_f + (Q_h_f_hp + Q_h_g_hp_aux) * system_count '=============2013.08.18 수정 '============================2010.04.17 추가
                                '//요기맞죠 ^^?
                            Case "액화가스" '액화가스"
                                CRenew.Calc_HeatpumpSystem(system_type, i_HeatCool, Dr신재생, Q_h_outg_i, i_count_month, d_op_max_mth, t_h, theta_VA, theta_i, Q_hp_outg, Q_h_f_hp, Q_h_g_hp_aux) '=============2010.04.01 수정 Q_h_outg 를 Q_h_outg_i 로 수정
                                Q_h_outg = Q_h_outg - Q_hp_outg
                                Q_h_outg_i = Q_h_outg_i - Q_hp_outg
                                use_LPG = use_LPG + Q_h_f_hp * system_count '=============2013.08.18 수정
                                use_Elec = use_Elec + Q_h_g_hp_aux * system_count '=============2013.08.18 수정
                                Q_h_f = Q_h_f + (Q_h_f_hp + Q_h_g_hp_aux) * system_count '=============2013.08.18 수정 '============================2010.04.17 추가
                        End Select
                    Case "열병합" '//열병합
                        Select Case Dr신재생.가동연료.Trim
                            Case "난방유" '난방유"
                                CRenew.Calc_CogenerationSystemEN(Dr신재생, 1, i_count_month, Q_h_outg_i, t_h, Q_h_CHP, Q_h_f_CHP)
                                Q_h_outg = Q_h_outg - Q_h_CHP
                                Q_h_outg_i = Q_h_outg_i - Q_h_CHP
                                use_Oil = use_Oil + Q_h_f_CHP * system_count '=============2013.08.18 수정
                                Q_h_f = Q_h_f + Q_h_f_CHP * system_count '=============2013.08.18 수정 '============================2010.04.17
                            Case "천연가스" '천연가스"
                                CRenew.Calc_CogenerationSystemEN(Dr신재생, 1, i_count_month, Q_h_outg_i, t_h, Q_h_CHP, Q_h_f_CHP)
                                Q_h_outg = Q_h_outg - Q_h_CHP
                                Q_h_outg_i = Q_h_outg_i - Q_h_CHP
                                use_LNG = use_LNG + Q_h_f_CHP * system_count '=============2013.08.18 수정
                                Q_h_f = Q_h_f + Q_h_f_CHP * system_count '=============2013.08.18 수정 '============================2010.04.17
                            Case "액화가스" '액화가스"
                                CRenew.Calc_CogenerationSystemEN(Dr신재생, 1, i_count_month, Q_h_outg_i, t_h, Q_h_CHP, Q_h_f_CHP)
                                Q_h_outg = Q_h_outg - Q_h_CHP
                                Q_h_outg_i = Q_h_outg_i - Q_h_CHP
                                use_LPG = use_LPG + Q_h_f_CHP * system_count '=============2013.08.18 수정
                                Q_h_f = Q_h_f + Q_h_f_CHP * system_count '=============2013.08.18 수정 '============================2010.04.17
                            Case Else
                                MsgBox("신재생에너지의 가동연료를 확인할 수 없습니다", MsgBoxStyle.Critical, Dr신재생.가동연료)
                        End Select
                End Select
            End If


            '----------------------------------------------------------------------------------------------------------------------------------
            '----------------------------------------------------------------------------------------------------------------------------------

            '===========================================================================================2013.01.13 이동
            If dr난방.열생산기기방식 = "히트펌프" Then

                Q_dot_HP_heating = TOSG(dr난방.히트난방용량) ' Worksheets("난방기기").Range("히트펌프사용연료1").Offset(1, i_count_boiler - 1)
                COP_HP_7 = TOSG(dr난방.히트난방정격7) * age ' Worksheets("난방기기").Range("히트펌프사용연료1").Offset(2, i_count_boiler - 1)
                COP_HP_10 = TOSG(dr난방.히트난방정격10) * age ' Worksheets("난방기기").Range("히트펌프사용연료1").Offset(3, i_count_boiler - 1)
                L_HP_heating = TOSG(dr난방.히트배관길이) ' Worksheets("난방기기").Range("히트펌프사용연료1").Offset(4, i_count_boiler - 1)
                If theta_e > 15 Then
                    COP_HP_total = (COP_HP_7 - COP_HP_10) / 22 * 15 + COP_HP_7 - 7 * (COP_HP_7 - COP_HP_10) / 22
                Else
                    COP_HP_total = (COP_HP_7 - COP_HP_10) / 22 * theta_e + COP_HP_7 - 7 * (COP_HP_7 - COP_HP_10) / 22
                End If

                If theta_e < 7 Then

                    If theta_e >= 0 Then
                        COP_HP_total = TOSG(COP_HP_total * ((1 - 0.86) / 7 * theta_e + 0.86))
                    Else
                        COP_HP_total = TOSG(COP_HP_total * ((0.98 - 0.86) / 7 * (-theta_e) + 0.86))
                    End If

                End If

                If Q_dot_HP_heating <= 20 Then
                    COP_HP_total = TOSG(COP_HP_total * (1 - L_HP_heating * 0.002))
                Else
                    If Q_dot_HP_heating <= 100 Then
                        COP_HP_total = TOSG(COP_HP_total * (1 - L_HP_heating * 0.0009))
                    Else
                        COP_HP_total = TOSG(COP_HP_total * (1 - L_HP_heating * 0.0014))
                    End If
                End If



                Q_h_outg = Q_h_outg - Q_h_outg_i '===================================================2013.01.16 추가
                '======================================================================================================================================================2010.04.23 추가


                '======================================================================================================================================================2012.07.08 추가

                If dr난방.운전방식.Trim = "동시가동" Or dr난방.운전방식.Trim = "순차가동" Then
                    Q_dot_HP_heating = Q_dot_HP_heating * TOSG(dr난방.보일러대수)
                End If



                If Q_dot_HP_heating = 0 Or t_h_max = 0 Then '===========================================================2014.03.07 추가
                    Q_h_outg_i = 0
                Else
                    If Q_h_outg_i / (Q_dot_HP_heating * t_h_max) >= 1 Or dr난방.히트펌프시스템종류 = "실내외분리시스템" Then '====2010.04.26 수정
                        Q_h_outg_i = Q_h_outg_i / COP_HP_total
                    Else
                        If dr난방.운전방식.Trim = "순차가동" Then
                            For i_count_beta = 1 To CInt(TOSG(dr난방.보일러대수))
                                If Q_h_outg_i <= (Q_dot_HP_heating * t_h_max / TOSG(dr난방.보일러대수) * i_count_beta) Then
                                    Q_h_outg_i = ((Q_h_outg_i / COP_HP_total) * (i_count_beta - 1) + (Q_h_outg_i / (COP_HP_total * (Q_h_outg_i / (Q_dot_HP_heating * t_h_max / TOSG(dr난방.보일러대수)) * 0.5 + 0.5)))) / i_count_beta
                                    Exit For
                                End If
                            Next

                        Else
                            Q_h_outg_i = Q_h_outg_i / (COP_HP_total * (Q_h_outg_i / (Q_dot_HP_heating * t_h_max) * 0.5 + 0.5)) '====2010.04.26 수정
                        End If

                    End If
                End If '===========================================================2014.03.07 추가


                
                '======================================================================================================================================================2010.04.23 추가
                Q_h_outg = Q_h_outg + Q_h_outg_i * system_count '=====2013.08.13 수정 '===================================================2013.01.16 추가


            End If

            '===========================================================================================2013.01.13 이동



            If dr난방.열생산기기방식 = "보일러" Then 'Worksheets("난방기기").Range("열생산기기방식1").Offset(0, i_count_boiler - 1) = "보일러" Then

                If DSET.tbl_zone.Select("열생산급탕생산기기='" & dr난방.code & "' and code <> '0'").GetUpperBound(0) <> -1 Then ' If Worksheets("난방기기").Range("난방생산기기1").Offset(5, i_count_boiler - 1) = "예" Then

                    If dr난방.분배시스템방식 = "중앙식" Then ' Dr난방.분배시스템방식 = "중앙식" Then

                        L_G = TOSG(dr난방.건물길이) ' Dr난방.건물길이
                        B_G = TOSG(dr난방.건물넓이) ' Dr난방.건물넓이
                        n_G = TOSG(dr난방.열공급층수) 'Dr난방.열공급층수
                        h_G = TOSG(dr난방.층고) ' Dr난방.층고
                        L_i = TOSG((2 * L_G + 0.0325 * L_G * B_G + 6) * 0.2 + (0.025 * L_G * B_G * h_G * n_G + 2 * (L_G + B_G) * n_G) * 0.255 + (0.1 * L_G * B_G * n_G) * 0.255) '단일배관난방적용

                        If dr난방.순환유무 = "무" Then '  Worksheets("난방기기").Range("급탕분배방식1").Offset(1, i_count_boiler - 1) = "무" Then
                            ':중앙비순환시스템
                            Q_w_d_i = TOSG(1 / 1000 * L_i * ((23 * 0.2 ^ (-0.2) - theta_i) * d_Nutz_mth * 24)) '(3.2.9-11) 중앙비순환시스템 L_i 에 U_i 포함 theta_w_m_비순환 는 23*0.2^(-0.2)
                            theta_g_m = 40
                        Else
                            ':중앙순환시스템
                            Q_w_d_i = TOSG(1 / 1000 * L_i * d_Nutz_mth * ((50 - theta_i) * t_Nutz_d + 0.5 * (23 * 0.2 ^ (-0.2) - theta_i) * (24 - t_Nutz_d))) '(3.2.9-11) 중앙순환시스템 L_i 에 U_i 포함 theta_w_m_순환 는 50도
                            theta_g_m = 50
                        End If

                        Q_w_d = Q_w_d + Q_w_d_i '(3.2.9-12)
                    End If


                    Select Case dr난방.축열탱크방식.Trim 'Worksheets("난방기기").Range("난방기기축열탱크1").Offset(0, i_count_boiler - 1)
                        Case "전기가열식" '전기가열식"

                            ':저탕조용량(모를경우)
                            'f_N = 1 / (t_Nutz_d * 1) '(3.2.9-24)  t_Nutz_T 는 t_Nutz_d 로 적용, eta_Sp는 1로 적용 추후 검토
                            ':심야전기가열
                            'V_s = 1.42 * Q_w_b_d * f_N * 860 / ((theta_w_m - theta_k) * eta_s) '(3.2.9-33) : 심야전기가열
                            ':주간전기가열
                            'V_s = 0.67 * Q_w_b_d * f_N * 860 / ((Q_w_m - Q_k) * eta_s) '(3.2.9-34) : 주간전기가열
                            V_s = TOSG(dr난방.축열제척) ' Worksheets("난방기기").Range("난방기기축열체적1").Offset(0, i_count_boiler - 1)
                            q_B_S = TOSG(0.29 + 0.019 * V_s ^ 0.8) '(3.2.9-30) :1994 이후
                            Q_w_s = (55 - theta_i) / 45 * d_Nutz_mth * q_B_S '(3.2.9-29) : 전기가열식 저탕조

                        Case "가스가열식" '가스가열식"

                            ':가스가열식 저탕조
                            V_s = TOSG(dr난방.축열제척) ' Worksheets("난방기기").Range("난방기기축열체적1").Offset(0, i_count_boiler - 1)
                            ':1994 이후
                            q_B_S = TOSG(2 + 0.033 * V_s ^ 1.1) '(3.2.9-38)
                            Q_w_s = (55 - theta_i) / 50 * d_Nutz_mth * q_B_S '(3.2.9-37) : 가스가열식 저탕조

                        Case "간접가열식" '간접가열식"
                            ':간접 가열식 저탕조
                            ':태양열 복합 저탕조(UA_sb_s_a를 모를 경우)
                            'q_B_S = (0.4 + 0.2 * (V_s_aux + V_s_sol) ^ 0.4) * V_s_aux / (V_s_aux + V_s_sol) '(3.2.9-26)
                            'f_N = 1 / (t_Nutz_T * n_Sp) '(3.2.9-24)
                            ':저탕조용량(모를 경우)
                            'V_s = (Q_w_b_d * f_N * 860) / ((theta_w_m - theta_k) * eta_s) '(3.2.9-23)
                            V_s = TOSG(dr난방.축열제척) ' Worksheets("난방기기").Range("난방기기축열체적1").Offset(0, i_count_boiler - 1)
                            If V_s < 1000 Then
                                ':1000이하
                                q_B_S = 0.8 + 0.02 * V_s ^ 0.77 '(3.2.9-18) '============================2010.04.24 수정
                            Else
                                ':1000이상
                                q_B_S = TOSG(0.39 * V_s ^ 0.35 + 0.5) '(3.2.9-19)
                            End If
                            Q_w_s = f_verbindung * (50 - theta_i) / 45 * d_Nutz_mth * q_B_S '(3.2.9-16)

                    End Select

                    Q_w_outg_i = Q_w_b + Q_w_ce + Q_w_d + Q_w_s '(3.2.9-4)
                    Q_w_outg = Q_w_outg + Q_w_outg_i * system_count '=====2013.08.13 수정

                Else
                    Q_w_outg_i = 0
                End If


                ' 신재생에너지 시스템
                '----------------------------------------------------------------------------------------------------------------------------------
                '----------------------------------------------------------------------------------------------------------------------------------

                '태양열(난방+급탕) 시스템
                If dr난방.신재생연결여부 = "시스템연결" AndAlso dr난방.연결된시스템 <> "0" Then ' Worksheets("난방기기").Range("신재생난방연결1").Offset(0, i_count_boiler - 1) = "시스템연결" Then
                    Dim Dr신재생 As DS.tbl_newRow = CType(DSET.tbl_new.Select("code='" & dr난방.연결된시스템 & "' and code <> '0'")(0), DS.tbl_newRow)

                    Select Case Dr신재생.기기종류.Trim
                        Case "태양열" '//태양열일때
                            If Dr신재생.태양열종류 = "난방+급탕" Then '난방+급탕" Then

                                'Dim Dr존 As DS.tbl_zoneRow = CType(DSET.tbl_zone.Select("code<>'0'", "code")(i_count_zone - 1), DS.tbl_zoneRow)
                                Calc.Renewable.Calc_ThermalSolarSystem_EN(system_type, Dr신재생.code, i_count_month, d_op_max_mth, Q_h_outg_i, Q_w_outg_i, Q_W_sol_out_m, Q_H_sol_out_m, W_sol_aux_m)
                                Q_h_outg = Q_h_outg - Q_H_sol_out_m
                                Q_h_outg_i = Q_h_outg_i - Q_H_sol_out_m
                                Q_w_outg = Q_w_outg - Q_W_sol_out_m
                                Q_w_outg_i = Q_w_outg_i - Q_W_sol_out_m
                                W_sol_aux = W_sol_aux + W_sol_aux_m * system_count '=======2013.08.18 수정
                            End If
                    End Select
                End If

                '----------------------------------------------------------------------------------------------------------------------------------
                '----------------------------------------------------------------------------------------------------------------------------------

                Q_dot_N = TOSG(dr난방.보일러정격출력) ' Worksheets("난방기기").Range("난방기기정격출력1").Offset(0, i_count_boiler - 1)
                If d_Nutz_mth = 0 Then '//201.11.20 추가(학교프로파일 적용시 문제점 해결)
                    t_w_100 = 0
                Else
                    t_w_100 = Q_w_outg_i / (Q_dot_N * d_Nutz_mth) '(3.2.9-61)
                    Q_dot_d_in = Q_h_outg_i / (d_h_rB * (t_h_rL_T - t_w_100)) '(3.2.7-69) 난방 또는 난방 및 급탕
                    ' 우선 미적용 Q_dot_d_in = sigma_Q_h_outg / (t_Betrieb_K - t_W_100) * d_Nutz_mth '(3.2.7-70) 난방, 급탕 및 공조
                End If


                Select Case dr난방.운전방식.Trim ' Worksheets("난방기기").Range("난방기기운전방식1").Offset(0, i_count_boiler - 1)
                    Case "단독가동" '단독가동"
                        beta_h = Q_dot_d_in / Q_dot_N '(3.2.7-64) : 단일보일러 시설
                    Case "동시가동" ' 동시가동"
                        beta_h = TOSG(Q_dot_d_in / (Q_dot_N * TOSG(dr난방.보일러대수))) '(3.2.7-64) : 다수보일러 동시가동
                    Case "순차가동" '순차가동"
                        For i_count_beta = 1 To CInt(TOSG(dr난방.보일러대수))
                            If Q_dot_d_in <= (Q_dot_N * i_count_beta) Then
                                beta_h = (Q_dot_d_in - Q_dot_N * (i_count_beta - 1)) / Q_dot_N * i_count_beta '다수보일러 대수제어
                                n_beta = i_count_beta - 1
                                Exit For
                            End If
                        Next
                End Select


                '------------------------------------------------------------------------------------
                ' 보일러 가동 손실의 경우 국내 데이타 미비로 정격효율을 부분부하효율로 적용 추후 검토 필요

                'eta_k_100 = (a + b * Ln(Q_dot_N)) / 100 '(3.2.7-83) 일반보일러
                'eta_k_pl = (c + d * Ln(Q_dot_N)) / 100 '(3.2.7-84) 일반보일러
                'eta_k_100 = (a + b * Ln(Q_dot_N)) / 100 '(3.2.7-85) 콘덴싱보일러
                'eta_k_pl = (c + d * Ln(Q_dot_N)) / 105 '(3.2.7-86) 콘덴싱보일러


                'q_B_70 = (E * (Q_dot_N ^ F)) / 100 '(3.2.7-64)
                'q_B_theta = q_B_70 * (theta_HK_m_beta_h_g - theta_i) / (70 - 20) '(3.2.7-72)
                'Q_dot_B_h = q_B_theta * (Q_dot_N / eta_k_100) * f_Hs_Hi '(3.2.7-71) 정지 대기모드



                'beta_h_g = (Q_h_b + Q_h_ce + Q_h_d + Q_h_s) / (Q_dot_h_max * t_h) '(3.2.7-10)
                'theta_VL_m_beta_h_g = (theta_VA - theta_i_h_soll) * beta_h_g ^ (1 / n) + theta_i_h_soll '(3.2.7.13)
                'theta_RL_m_beta_h_g = (theta_RA - theta_i_h_soll) * beta_h_g ^ (1 / n) + theta_i_h_soll '(3.2.7.-14)

                'eta_k_pl_Betrieb = eta_k_pl + H * (theta_g_test_pl - theta_HK_m_beta_h_g) '(3.2.7-76)
                'eta_k_100_Betrieb = eta_k_100 + G * (theta_g_test100 - theta_HK_m_beta_h_g) '(3.2.7-75)
                'Q_V_g_100 = (f_Hs_Hi - eta_k_100_Betrieb) / eta_k_100_Betrieb * Q_dot_N '(3.2.7-74)
                'Q_V_g_pl = (f_Hs_Hi - eta_k_pl_Betrieb) / eta_k_pl_Betrieb * beta_k_pl * Q_dot_N '(3.2.7-73)

                '--          -------             -----             ---             ---             ---     --

                eta_k_100 = TOSG(TOSG(dr난방.정격보일러효율) * age_heating / 100) ' Worksheets("난방기기").Range("난방기기정격효율1").Offset(0, i_count_boiler - 1) / 100
                eta_k_pl = eta_k_100
                f = -0.4

                If dr난방.열생산기기방식 = "보일러" Then ' Worksheets("난방기기").Range("열생산기기방식1").Offset(0, i_count_boiler - 1) = "보일러" Then
                    Select Case dr난방.보일러방식.Trim ' Worksheets("난방기기").Range("보일러방식1").Offset(0, i_count_boiler - 1)
                        Case "가스보일러" '가스보일러"
                            e = 8.5
                            f = -0.4
                        Case "기름보일러" '기름보일러"
                            e = 8.5
                            f = -0.4
                        Case "저온가스보일러" '저온가스보일러"
                            e = 4.5
                            f = -0.4
                        Case "저온기름보일러" '저온기름보일러"
                            e = 4.25
                        Case "콘덴싱보일러" '콘덴싱보일러"
                            e = 4
                    End Select

                    q_B_70 = TOSG((e * (Q_dot_N ^ f)) / 100)

                Else
                    q_B_70 = 1
                End If

                q_B_theta = q_B_70 '원래는 =q_B_70 * (theta_HK_m_beta_h_g - theta_i) / (70 - 20) 이지만 q_B_theta 와 q_B_70 이 같은 것으로 적용 추후검토



                'Select Case Worksheets("난방기기").Range("난방기기사용연료1").Offset(0, i_count_boiler - 1)
                'Case "난방유"
                'f_Hs_Hi = 1.06
                'Case "천연가스"
                'f_Hs_Hi = 1.11
                'Case "액화가스"
                'f_Hs_Hi = 1.09
                'Case "석탄"
                'f_Hs_Hi = 1.04
                'Case "갈탄"
                'f_Hs_Hi = 1.07
                'Case "나무"
                'f_Hs_Hi = 1.08
                'End Select

                f_Hs_Hi = 1 ' 국내는 총발열량을 기준으로 입력함으로 우선 1로 설정, 추후 검토

                Q_dot_B_h = q_B_theta * (Q_dot_N / eta_k_100) * f_Hs_Hi '(3.2.7-71)

                Q_V_g_100 = (f_Hs_Hi - eta_k_100) / eta_k_100 * Q_dot_N
                Q_V_g_pl = (f_Hs_Hi - eta_k_pl) / eta_k_pl * beta_k_pl * Q_dot_N

                '------------------------------------------------------------------------------------------------------





                If beta_h > beta_k_pl Then
                    Q_h_g_v_i = ((beta_h - beta_k_pl) / (1 - beta_k_pl) * (Q_V_g_100 - Q_V_g_pl) + Q_V_g_pl) * (t_h_rL_T - t_w_100)
                    Q_h_g_v_i = Q_h_g_v_i + ((Q_V_g_100 - Q_V_g_pl) + Q_V_g_pl) * (t_h_rL_T - t_w_100) * n_beta
                Else
                    '======================================================================================== 2010.2.21 수정
                    If beta_h = 0 Then
                        Q_h_g_v_i = 0
                    Else
                        Q_h_g_v_i = ((beta_h / beta_k_pl) * (Q_V_g_pl - Q_dot_B_h) + Q_dot_B_h) * (t_h_rL_T - t_w_100)
                    End If
                    '======================================================================================== 2010.2.21 수정
                End If

                Q_h_g = Q_h_g + (Q_h_g_v_i * d_h_rB) * system_count '=====2013.08.13 수정 '(3.2.7-66)
                Q_h_g_i = Q_h_g_v_i * d_h_rB

            Else

                If dr난방.열생산기기방식 = "지역난방" Then ' Worksheets("난방기기").Range("열생산기기방식1").Offset(0, i_count_boiler - 1) = "지역난방" Then
                    If dr난방.지역난방방식 = "중온수" Then ' Worksheets("난방기기").Range("지역난방온수방식1").Offset(0, i_count_boiler - 1) = "중온수" Then
                        D_DS = 0.6
                        theta_prim_DS = 105
                        'MsgBox("난방기기 단열등급에  등급2/3 등급3/4 등급 4/5 추가해야함")
                        Select Case dr난방.단열등급.Trim '  Dr난방.단열등급
                            Case "기본단열" '기본단열" '원래는 등급1/2 이지만 국내에서는 법적단열로 사용
                                B_DS = 4.9
                            Case "등급2/3" '등급2/3"
                                B_DS = 4.4
                            Case "등급3/4" '등급3/4"
                                B_DS = 4
                            Case "등급4/5" '등급4/5"
                                B_DS = 3.5
                        End Select
                    End If
                    'MsgBox("난방기기 지역난방방식에 고온수 0002 추가해야함") --추가는 했으나 엑셀에서는 중온수고정이다 그래서 하위 루틴은 실행되면안된다
                    If dr난방.지역난방방식 = "고온수" Then 'Worksheets("난방기기").Range("지역난방온수방식1").Offset(0, i_count_boiler - 1) = "고온수" Then
                        ' MsgBox("난방기기의 지역난방방식은 중온수 고정입니다.", MsgBoxStyle.Information, "확인")
                        D_DS = 0.4
                        theta_prim_DS = 150
                        Select Case dr난방.단열등급.Trim
                            Case "기본단열" '기본단열" '원래는 등급1/2 이지만 국내에서는 법적단열로 사용
                                B_DS = 4.3
                            Case "등급2/3" '등급2/3"
                                B_DS = 3.9
                            Case "등급3/4" '등급3/4"
                                B_DS = 3.5
                            Case "등급4/5" '등급4/5"
                                B_DS = 3.1
                        End Select
                    End If

                    theta_DS = D_DS * theta_prim_DS + (1 - D_DS) * 55 ' theta_sek_DS는 55도로 설정 (3.2.7-112)
                    Psi_DS = TOSG(dr난방.열교환기정격출력) ' .Worksheets("난방기기").Range("난방기기정격출력1").Offset(1, i_count_boiler - 1)
                    H_DS = TOSG(B_DS * Psi_DS ^ (1 / 3))
                    Q_h_g = Q_h_g + (H_DS * (theta_DS - theta_i)) * system_count '=====2013.08.13 수정
                    use_DH = use_DH + (H_DS * (theta_DS - theta_i)) * system_count '========2013.08.18 수정

                End If


            End If


            ' 전기보조에너지 Q_h_d_aux 산출 관련

            P_Pump = TOSG(dr난방.펌프동력) ' Worksheets("난방기기").Range("난방펌프제어유형1").Offset(1, i_count_boiler - 1)
            Select Case dr난방.펌프제어유형.Trim ' Worksheets("난방기기").Range("난방펌프제어유형1").Offset(0, i_count_boiler - 1)
                Case "비제어" '비제어"
                    c_p1 = 0.25
                    c_p2 = 0.75
                Case "정압" '정압"
                    c_p1 = 0.75
                    c_p2 = 0.25
                Case "변압" '변압"
                    c_p1 = 0.9
                    c_p2 = 0.1
            End Select

            If beta_h_d = 0 Then
                Q_h_d_aux_i = 0
            Else
                Q_h_d_aux_i = P_Pump / 1000 * beta_h_d * t_h * (c_p1 + c_p2 / beta_h_d) '(3.2.7-39)
            End If
            Select Case dr난방.펌프교정계수.Trim ' Worksheets("난방기기").Range("난방펌프교정계수1").Offset(0, i_count_boiler - 1)
                Case "정상가동" '정상가동"
                    f_P_A = 1
                Case "감소가동" '감소가동"
                    f_P_A = 0.6
                Case "가동정지" '"
                    f_P_A = 0
            End Select

            If t_h = 0 Then '====================================================================2014.03.07 추가
                Q_h_d_aux = 0
            Else
                Q_h_d_aux = TOSG(Q_h_d_aux + (Q_h_d_aux_i * (1.03 * t_h_rL + f_P_A * (t_h - t_h_rL)) / t_h) * system_count) '(3.2.7-40)
            End If             '====================================================================2014.03.07 추가





            If dr난방.축열탱크방식 = "축열탱크없음" Then
                P_Pump = 0 ' Dr난방.Worksheets("난방기기").Range("축열펌프정격전력1").Offset(0, i_count_boiler - 1)
            Else
                P_Pump = TOSG(dr난방.펌프정격전력) ' Dr난방.Worksheets("난방기기").Range("축열펌프정격전력1").Offset(0, i_count_boiler - 1)
                '=================================================================2010.11.04 위치 수정
                If dr난방.열생산기기방식 = "히트펌프" Then
                    If dr난방.운전방식.Trim = "동시가동" Then
                        Q_dot_h_max = TOSG(dr난방.히트난방용량) * TOSG(dr난방.보일러대수)
                    Else
                        Q_dot_h_max = TOSG(dr난방.히트난방용량) ' Worksheets("난방기기").Range("히트펌프사용연료1").Offset(1, i_count_boiler - 1)
                    End If

                End If

                If Q_dot_h_max = 0 Or t_h = 0 Then '========================================================2014.03.07 추가
                    beta_h_s = 0
                Else
                    beta_h_s = (Q_h_b + Q_h_ce + Q_h_d) / (Q_dot_h_max * t_h) '(3.2.7-9)
                End If                             '========================================================2014.03.07 추가


                If beta_h_s > 1 Then beta_h_s = 1
                t_P = beta_h_s * 24 * d_op_max_mth '(3.2.7-44)
                Q_h_s_aux = Q_h_s_aux + (P_Pump * t_P / 1000) * system_count '===2013.08.18 수정 '(3.2.7-44)
                '=================================================================2010.11.04 위치 수정

            End If
            If dr난방.열생산기기방식 = "보일러" Then 'Worksheets("난방기기").Range("열생산기기방식1").Offset(0, i_count_boiler - 1) = "보일러" Then

                P_aux_SB = 0.02

                Select Case dr난방.보일러방식.Trim ' Worksheets("난방기기").Range("보일러방식1").Offset(0, i_count_boiler - 1)
                    Case "가스보일러" '가스보일러"
                        P_aux_100 = TOSG((0.148 * Q_dot_N + 40) / 1000)
                        P_aux_pl = TOSG((0.148 * Q_dot_N + 40) / 1000)
                    Case "기름보일러" '기름보일러"
                        P_aux_100 = TOSG(0.045 * Q_dot_N ^ 0.48)
                        P_aux_pl = TOSG(0.015 * Q_dot_N ^ 0.48)
                    Case "저온가스보일러" '저온가스보일러"
                        P_aux_100 = TOSG((0.148 * Q_dot_N + 40) / 1000)
                        P_aux_pl = TOSG((0.148 * Q_dot_N + 40) / 1000)
                    Case "저온기름보일러" '저온기름보일러"
                        P_aux_100 = TOSG(0.045 * Q_dot_N ^ 0.48)
                        P_aux_pl = TOSG(0.015 * Q_dot_N ^ 0.48)
                    Case "콘덴싱보일러" '콘덴싱보일러"
                        P_aux_100 = TOSG(0.045 * Q_dot_N ^ 0.48)
                        P_aux_pl = TOSG(0.015 * Q_dot_N ^ 0.48)

                End Select

                If beta_h > beta_k_pl Then
                    P_h_g_aux = (beta_h - beta_k_pl) / (1 - beta_k_pl) * (P_aux_100 - P_aux_pl) + P_aux_pl '(3.2.7-82)
                Else
                    P_h_g_aux = (beta_h / beta_k_pl) * (P_aux_pl - P_aux_SB) + P_aux_SB '(3.2.7-81)
                End If

                If d_Nutz_mth = 0 Then '//201.11.20 추가(학교프로파일 적용시 문제점 해결)
                    t_w_100 = 0
                Else
                    If system_count = 0 Then
                        t_w_100 = Q_w_outg_i / (Q_dot_N * d_Nutz_mth)
                    Else
                        t_w_100 = (Q_w_outg_i) / (Q_dot_N * d_Nutz_mth)   '//2011.12.04 수정
                    End If

                End If

                Q_h_g_aux = Q_h_g_aux + (P_h_g_aux * (t_h_rL - t_w_100 * d_op_max_mth * d_Nutz_a / 365) + P_aux_SB * (24 * d_op_max_mth - t_h_rL)) * system_count '=====2013.08.18 수정 '(3.2.7-80)


            End If


            If dr난방.열생산기기방식 = "보일러" Then 'Worksheets("난방기기").Range("열생산기기방식1").Offset(0, i_count_boiler - 1) = "보일러" Then
                Select Case dr난방.사용연료.Trim ' Worksheets("난방기기").Range("난방기기사용연료1").Offset(0, i_count_boiler - 1)
                    Case "난방유" '난방유"
                        use_Oil = use_Oil + (Q_h_outg_i + Q_h_g_i) * system_count '========2013.08.18 수정

                    Case "천연가스" '천연가스"
                        use_LNG = use_LNG + (Q_h_outg_i + Q_h_g_i) * system_count '========2013.08.18 수정

                    Case "액화가스" '액화가스"
                        use_LPG = use_LPG + (Q_h_outg_i + Q_h_g_i) * system_count '========2013.08.18 수정

                End Select
            Else
                Select Case dr난방.열생산기기방식.Trim 'Worksheets("난방기기").Range("열생산기기방식1").Offset(0, i_count_boiler - 1)
                    '====================================================================2010.2.21 수정
                    Case "지역난방" '지역난방"
                        use_DH = use_DH + Q_h_outg_i * system_count '========2013.08.18 수정

                    Case "전기보일러" '전기보일러"
                        use_Elec = use_Elec + (Q_h_outg_i + (Q_h_outg_i * 0.09)) * system_count '========2013.08.18 수정 '2011.03.08 전기보일러 생산손실을 내부 생산식 저장으로 설정
                        '====================================================================2010.2.21 수정
                        '====================================================================2010.03.14 추가
                    Case "히트펌프"
                        Select Case dr난방.히트연료 ' Worksheets("난방기기").Range("히트펌프사용연료1").Offset(0, i_count_boiler - 1)
                            Case "전기"
                                use_Elec = use_Elec + Q_h_outg_i * system_count '========2013.08.18 수정

                            Case "천연가스"
                                use_LNG = use_LNG + Q_h_outg_i * system_count '========2013.08.18 수정

                            Case "액화가스"
                                use_LPG = use_LPG + Q_h_outg_i * system_count '========2013.08.18 수정

                        End Select
                        '====================================================================2010.03.14 추가
                End Select

            End If

        Next

        pLog.Add("Calc_난방_개별기기적용시 : 완료")

    End Sub

    Private DSET As DS
    Private DSETR As DSR
    Dim Result As CResult
    Public Sub New(ByRef pds As DS, ByRef pdsetr As DSR, ByRef presult As CResult)
        DSET = pds
        DSETR = pdsetr
        Result = presult
    End Sub
End Class


