Public Class CRenewable

    Private Result As CResult
    Private DSET As DS
    Public Sub New(ByRef pds As DS, ByRef presult As CResult)
        DSET = pds
        Result = presult
        'ByVal dr존 As DS.tbl_zoneRow,
    End Sub
    ' Public Overridable Sub Calc_ThermalSolarSystem_EN(ByVal i_system_ts As Integer, ByVal i_count_ts As Integer, ByVal i_ts_month As Integer, ByVal i_ts_d_mth As Integer, ByVal Q_H_sol_us_m as decimal, ByVal Q_W_sol_us_m as decimal, ByRef Q_W_sol_out_m as decimal, ByRef Q_H_sol_out_m as decimal, ByRef W_sol_aux_m as decimal)

    Public Overridable Sub Calc_ThermalSolarSystem_EN(ByVal i_system_ts As Integer, ByVal DR_code As String, ByVal i_ts_month As Integer, ByVal i_ts_d_mth As Integer, ByVal Q_H_sol_us_m As Decimal, ByVal Q_W_sol_us_m As Decimal, _
                                                      ByRef Q_W_sol_out_m As Decimal, ByRef Q_H_sol_out_m As Decimal, ByRef W_sol_aux_m As Decimal)

        pLog.Add(String.Format(">>Calc_ThermalSolarSystem_EN 진입 : i_system_ts={0}, DR_code={1}, i_ts_month={2}, i_ts_d_mth={3}, Q_H_sol_us_m={4}, Q_W_sol_us_m={5}, Q_W_sol_out_m={6}, Q_H_sol_out_m={7}, W_sol_aux_m={8}", _
                               i_system_ts, DR_code, i_ts_month, i_ts_d_mth, Q_H_sol_us_m, Q_W_sol_us_m, Q_W_sol_out_m, Q_H_sol_out_m, W_sol_aux_m))


        Dim theta_ref As Decimal, theta_w As Decimal, theta_cw As Decimal, U_loop_p As Decimal, U_loop As Decimal, Delta_T As Decimal
        Dim A_ As Decimal, a As Decimal, b As Decimal, c As Decimal, d As Decimal, e As Decimal, f As Decimal, eta_loop As Decimal, IAM As Decimal, eta_0 As Decimal
        Dim a_1 As Decimal, a_2 As Decimal, P_H As Decimal, P_W As Decimal, V_ref As Decimal, V_sol As Decimal, t_m As Decimal, I_m As Decimal, P_aux_nom As Decimal
        'Dim i_ts_location As Integer, i_count_ts_location As Integer
        '     Dim i_count_month As Integer
        Dim i_direction As Integer
        Dim t_aux_m As Decimal, l_tot As Decimal, f_st As Decimal, U_st As Decimal
        Dim theta_setpoint As Decimal, theta_a_avg As Decimal, theta_e_avg As Decimal
        Dim Q_sol_ls_rbl_m As Decimal, Q_sol_aux_rbl_m As Decimal, Q_sol_st_ls_rbl_m As Decimal, Q_bu_dis_ls_rbl_m As Decimal, Q_bu_dis_ls_m As Decimal, Q_sol_ls_m As Decimal
        Dim Q_W_bu_dis_ls_m As Decimal, Q_H_bu_dis_ls_m As Decimal, Q_W_sol_st_ls_m As Decimal, Q_H_sol_st_ls_m As Decimal
        Dim A_H As Decimal, A_W As Decimal, X As Decimal, Y As Decimal
        Dim Q_W_sol_out_net As Decimal, Q_H_sol_out_net As Decimal, H_W_ratio As Decimal

        Q_W_sol_out_net = 0
        Q_H_sol_out_net = 0


        'Dim Dr기상데이터 As DS.tbl_weatherRow
        'For i_count_ts_location = 1 To DSET.tbl_weather.Rows.Count ' Range("건물위치").Columns.Count
        '    Dr기상데이터 = DSET.tbl_weather(i_count_ts_location - 1)
        '    If dr존.지역 = Dr기상데이터.건물위치 Then  '//이상하다 1버번쨰 존의 지역값만 계속쓴다 -_-;; 지역은 즉 존에할당된게아니고 1개만 존재하는듯하다
        '        i_ts_location = i_count_ts_location '//기상데이터에서 현재지정된 존.지역의 기상데이터의 지역의 열번호(엑셀에서만)를 기억한다 (나중에 이번호로 데이터 참조하려고)
        '        Exit For
        '    End If
        '    '//지역찾을떄그냥 DR지역을 사용하도록한다.
        '    'If Worksheets("입력존").Range("지역1").Offset(0, 0) = Worksheets("기상데이타").Range("건물위치1").Offset(0, i_count_ts_location - 1) Then
        '    '    i_ts_location = i_count_ts_location
        '    '    Exit For
        '    'End If
        'Next

        l_tot = 0

        Dim Dr신재생 As DS.tbl_newRow = CType(DSET.tbl_new.Select("code='" & DR_code & "' and code <> '0'", "code")(0), DS.tbl_newRow)    '//신재생의 태양열시스템

        Select Case Dr신재생.집열판방위.Trim ' Worksheets("신재생기기").Range("태양열시스템종류1").Offset(3, i_count_ts - 1)
            Case "동" '동"
                i_direction = 12

            Case "남동" '남동"
                i_direction = 10

            Case "남" '남"
                i_direction = 9

            Case "남서" '남서"
                i_direction = 11

            Case "서" '서"
                i_direction = 13

            Case "수평" '수평"  '//월별평균일사 수평면을 사용  나머지것들은 45도짜리를 사용한다. 45도짜리 코드값을 해당코드+1000이다. 해당코드+1000으로 미리 셋팅햇다(변경불가)
                i_direction = 0
            Case Else
                MsgBox("신재생에너지-태양열의 집열판 방위값이 올바르지않습니다", MsgBoxStyle.Critical, "확인")
        End Select

        '//집열판방위에따른 월별평균일사의 총합을 가져온다
        '//weather_ilsa 의 p코드에는 지역코드값이 들어가고 코드값은 집열판방위+1000 의값이 해당 각도의 방향에대한 데이터가된다.


        '///만약값이 서울   방향이 남  이엇을경우에는  해당 일사데이터를 찾는게 목적이에요. 여기서 서울의 코드값은 찾을수잇어요
        '//그담이 방향 남에 맞는 일사데이터를 찾아야하는데.. 일사데이터 코드로는 못찾으니깐. 이름으로 찾아요.
        '//이름 45도를 앞에 붙이기 200915


        Dim 일사이름 As String = "45도" & Dr신재생.집열판방위 & "향"  '//이렇게되면  남(45)  라는 최종이름이 되겟죠?
        If Dr신재생.집열판방위 = "수평" Then 일사이름 = "수평면"

        Dim Drow평균일사() As DS.weather_ilsaRow = CType(DSET.weather_ilsa.Select("pcode='" & Calc.Pub.기상데이터.code & _
                                                                              "' and 설명='" & 일사이름 & "'"), DS.weather_ilsaRow())
        '//그렇게해서 서울의 코드에 해당하는 pcode 와  이름이   남(45)로 되어잇는 일사데이터테이블에서 데이터를 검색하게되겟죠?
        '//즉 데이터가 나오면 해당 데이터가 맞는거에요 ..이건 데이터베이스 이름을 남(45) 식으로 모두 고쳐주세요

        If Drow평균일사.GetUpperBound(0) = -1 Then
            MsgBox("지역코드=" + Calc.Pub.기상데이터.code + vbCrLf + "집열판방위코드=" + Dr신재생.집열판방위 + _
            vbCrLf + "예상일사코드=" + 일사이름 + _
            vbCrLf + "에 해당하는 평균일사데이터가 없습니다. 1개의 행이 반환되어야 합니다", MsgBoxStyle.Critical, "계산실패")
            I_m = 0
            ' Return
        Else
            l_tot += TOSG(Drow평균일사(0).m01) + TOSG(Drow평균일사(0).m02) + TOSG(Drow평균일사(0).m03) + TOSG(Drow평균일사(0).m04) + _
            TOSG(Drow평균일사(0).m05) + TOSG(Drow평균일사(0).m06) + TOSG(Drow평균일사(0).m07) + TOSG(Drow평균일사(0).m08) + _
            TOSG(Drow평균일사(0).m09) + TOSG(Drow평균일사(0).m10) + TOSG(Drow평균일사(0).m11) + TOSG(Drow평균일사(0).m12)
            I_m = TOSG(Drow평균일사(0)("m" & i_ts_month.ToString("00")))   '//이줄로 위의 케이스문을 대체햇다 오류나면 케이스문으로 일단 사용할예정

        End If
        t_aux_m = I_m / l_tot * 2000

        '//월별외기평균온도(i_ts_month << 파라미터)
        theta_e_avg = TOSG(Calc.Pub.기상데이터("m" & i_ts_month.ToString("00")))
        'theta_e_avg =  Worksheets("기상데이타").Range("최소외기온도1").Offset(2 + i_ts_month, i_ts_location - 1) '//월별외기평균온도 tbl_weather에 존재

        Select Case Dr신재생.축열탱크설치장소.Trim ' Worksheets("신재생기기").Range("태양열축열탱크1").Offset(2, i_count_ts - 1)
            Case "난방공간" '난방공간"
                theta_a_avg = 20
            Case "비난방공간" '비난방공간"
                theta_a_avg = theta_e_avg + (20 - theta_e_avg) / 2
            Case "외부공간" '외부공간"
                theta_a_avg = theta_e_avg
        End Select

        theta_w = 40
        theta_cw = 15
        a_2 = 0
        eta_loop = 0.8
        eta_0 = 0.6
        t_m = i_ts_d_mth * 24
        a = 1.029
        b = -0.065
        c = -0.245
        d = 0.0018
        e = 0.0215
        f = 0


        Select Case Dr신재생.집열기유형.Trim 'Worksheets("신재생기기").Range("태양열시스템종류1").Offset(1, i_count_ts - 1)
            Case "평판형" '평판형"
                a_1 = 6
                IAM = 0.94
            Case "진공관형" '진공관형"
                a_1 = 3
                IAM = 1
        End Select

        If Dr신재생.태양열시스템의성능 = "성능치" Then ' Worksheets("신재생기기").Range("태양열시스템종류1").Offset(5, i_count_ts - 1) = "성능치" Then
            eta_0 = TOSG(Dr신재생.무손실효율계수) 'Worksheets("신재생기기").Range("태양열시스템종류1").Offset(6, i_count_ts - 1)
            a_1 = TOSG(Dr신재생.열손실계수1차) 'Worksheets("신재생기기").Range("태양열시스템종류1").Offset(7, i_count_ts - 1)
            a_2 = TOSG(Dr신재생.열손실계수2차) 'Worksheets("신재생기기").Range("태양열시스템종류1").Offset(8, i_count_ts - 1)
        End If

        Select Case Dr신재생.태양열종류.Trim ' Worksheets("신재생기기").Range("태양열시스템종류1").Offset(0, i_count_ts - 1)
            Case "급탕" '급탕"
                A_ = TOSG(Dr신재생.집열판면적) ' Worksheets("신재생기기").Range("태양열시스템종류1").Offset(2, i_count_ts - 1)
                U_loop_p = TOSG(5 + 0.5 * A_) '(B.3)
                U_loop = a_1 + a_2 * 40 + U_loop_p / A_ '(13)
                theta_ref = TOSG(11.6 + 1.18 * theta_w + 3.86 * theta_cw - 1.32 * theta_e_avg) '(B.8) 급탕시스템인 경우 theta_w는 40도, theta_cw 시수온도는15도 가정
                Delta_T = theta_ref - theta_e_avg '(14)
                V_ref = A_ * 75
                V_sol = TOSG(Dr신재생.축열탱크체적급탕) ' Worksheets("신재생기기").Range("태양열축열탱크1").Offset(0, i_count_ts - 1)
                f_st = TOSG((V_ref / V_sol) ^ 0.25) '(B.5)
                If Q_W_sol_us_m <> 0 Then
                    X = A_ * U_loop * eta_loop * Delta_T * f_st * t_m / (Q_W_sol_us_m * 1000) '(12)
                    Y = A_ * IAM * eta_0 * eta_loop * I_m * t_m / (Q_W_sol_us_m * 1000) '(15)
                    Q_W_sol_out_m = (a * Y + b * X + c * Y * Y + d * X * X + e * Y * Y * Y + f * X * X * X) * Q_W_sol_us_m '(11)
                Else
                    Q_W_sol_out_m = 0
                End If
                If Q_W_sol_out_m < 0 Then Q_W_sol_out_m = 0
                If Q_W_sol_out_m > Q_W_sol_us_m Then Q_W_sol_out_m = Q_W_sol_us_m

                '태양열시스템 열손실
                U_st = TOSG(0.16 * V_sol ^ 0.5) '(B.9)
                theta_setpoint = 60
                If Q_W_sol_us_m <> 0 Then
                    Q_W_sol_st_ls_m = U_st * (theta_setpoint - theta_a_avg) * (Q_W_sol_out_m / Q_W_sol_us_m) * t_m / 1000 '(17)
                    Q_bu_dis_ls_m = TOSG(0.02 * Q_W_sol_us_m * (Q_W_sol_out_m / Q_W_sol_us_m))
                Else
                    Q_W_sol_st_ls_m = 0
                    Q_bu_dis_ls_m = 0
                End If

                If i_system_ts = 1 Then '=====================================================2010.04.02 추가

                    '난방 부분
                    theta_ref = TOSG(11.6 + 1.18 * theta_w + 3.86 * theta_cw - 1.32 * theta_e_avg) '(B.8) 급탕시스템인 경우 theta_w는 40도, theta_cw 시수온도는15도 가정
                    Delta_T = theta_ref - theta_e_avg '(14)
                    V_ref = A_H * 75
                    V_sol = TOSG(Dr신재생.축열탱크체적난방) ' Worksheets("신재생기기").Range("태양열축열탱크1").Offset(1, i_count_ts - 1)
                    f_st = TOSG((V_ref / V_sol) ^ 0.25) '(B.5)
                    If Q_H_sol_us_m <> 0 Then
                        X = A_H * U_loop * eta_loop * Delta_T * f_st * t_m / (Q_H_sol_us_m * 1000) '(12)
                        Y = A_H * IAM * eta_0 * eta_loop * I_m * t_m / (Q_H_sol_us_m * 1000) '(15)
                        Q_H_sol_out_m = (a * Y + b * X + c * Y * Y + d * X * X + e * Y * Y * Y + f * X * X * X) * Q_H_sol_us_m '(11)
                    Else
                        Q_H_sol_out_m = 0
                    End If
                    If Q_H_sol_out_m < 0 Then Q_H_sol_out_m = 0
                    If Q_H_sol_out_m > Q_H_sol_us_m Then Q_H_sol_out_m = Q_H_sol_us_m

                    '태양열시스템 열손실
                    U_st = TOSG(0.16 * V_sol ^ 0.5) '(B.9)
                    theta_setpoint = 40
                    If Q_H_sol_us_m <> 0 Then
                        Q_H_sol_st_ls_m = U_st * (theta_setpoint - theta_a_avg) * (Q_H_sol_out_m / Q_H_sol_us_m) * t_m / 1000 '(17)
                        Q_H_bu_dis_ls_m = TOSG(0.02 * Q_H_sol_us_m * (Q_H_sol_out_m / Q_H_sol_us_m))
                    Else
                        Q_H_sol_st_ls_m = 0
                        Q_H_bu_dis_ls_m = 0
                    End If
                    Q_sol_ls_m = Q_H_sol_st_ls_m + Q_H_bu_dis_ls_m + Q_W_sol_st_ls_m + Q_W_bu_dis_ls_m

                End If '=====================================================2010.04.02 추가

                '  Q_sol_ls_m = Q_W_sol_st_ls_m + Q_bu_dis_ls_m

                ' 보조에너지
                P_aux_nom = TOSG(Dr신재생.솔라펌프의정격출력) ' Worksheets("신재생기기").Range("태양열시스템종류1").Offset(4, i_count_ts - 1)
                W_sol_aux_m = P_aux_nom * t_aux_m / 1000

                Q_sol_aux_rbl_m = TOSG(W_sol_aux_m * 0.5)

                Select Case Dr신재생.축열탱크설치장소.Trim 'Worksheets("신재생기기").Range("태양열축열탱크1").Offset(2, i_count_ts - 1)
                    Case "난방공간" '난방공간"
                        Q_sol_st_ls_rbl_m = Q_W_sol_st_ls_m
                        Q_bu_dis_ls_rbl_m = Q_bu_dis_ls_m
                    Case "비난방공간" '비난방공간"
                        Q_sol_st_ls_rbl_m = TOSG(Q_W_sol_st_ls_m * 0.5)
                        Q_bu_dis_ls_rbl_m = TOSG(Q_bu_dis_ls_m * 0.5)
                    Case "외부공간" '외부공간"
                        Q_sol_st_ls_rbl_m = 0
                        Q_bu_dis_ls_rbl_m = 0
                End Select

                Q_sol_ls_rbl_m = Q_sol_aux_rbl_m + Q_sol_st_ls_rbl_m + Q_bu_dis_ls_rbl_m '(20)



            Case "난방+급탕" '난방+급탕"
                P_H = Q_H_sol_us_m / (Q_H_sol_us_m + Q_W_sol_us_m) '(9)
                P_W = Q_W_sol_us_m / (Q_H_sol_us_m + Q_W_sol_us_m) '(10)
                A_ = TOSG(Dr신재생.집열판면적) ' Worksheets("신재생기기").Range("태양열시스템종류1").Offset(2, i_count_ts - 1)
                A_H = P_H * A_
                A_W = P_W * A_

                '급탕 부분
                U_loop_p = 5 + 0.5 * A_W '(B.3) '===========================2010.04.24 추가
                If A_W <> 0 Then
                    U_loop = a_1 + a_2 * 40 + U_loop_p / A_W '(13) '===============2010.04.24 추가
                    theta_ref = TOSG(11.6 + 1.18 * theta_w + 3.86 * theta_cw - 1.32 * theta_e_avg) '(B.8) 급탕시스템인 경우 theta_w는 40도, theta_cw 시수온도는15도 가정
                    Delta_T = theta_ref - theta_e_avg '(14)
                    V_ref = A_W * 75
                    V_sol = TOSG(Dr신재생.축열탱크체적급탕) ' Worksheets("신재생기기").Range("태양열축열탱크1").Offset(0, i_count_ts - 1)
                    f_st = TOSG((V_ref / V_sol) ^ 0.25) '(B.5)
                End If
                If Q_W_sol_us_m <> 0 Then
                    X = A_W * U_loop * eta_loop * Delta_T * f_st * t_m / (Q_W_sol_us_m * 1000) '(12)
                    Y = A_W * IAM * eta_0 * eta_loop * I_m * t_m / (Q_W_sol_us_m * 1000) '(15)
                    Q_W_sol_out_m = (a * Y + b * X + c * Y * Y + d * X * X + e * Y * Y * Y + f * X * X * X) * Q_W_sol_us_m '(11)
                Else
                    Q_W_sol_out_m = 0
                End If
                If Q_W_sol_out_m < 0 Then Q_W_sol_out_m = 0
                If Q_W_sol_out_m > Q_W_sol_us_m Then Q_W_sol_out_m = Q_W_sol_us_m

                '태양열시스템 열손실
                U_st = TOSG(0.16 * V_sol ^ 0.5) '(B.9)
                theta_setpoint = 60
                If Q_W_sol_us_m <> 0 Then
                    Q_W_sol_st_ls_m = U_st * (theta_setpoint - theta_a_avg) * (Q_W_sol_out_m / Q_W_sol_us_m) * t_m / 1000 '(17)
                    Q_W_bu_dis_ls_m = TOSG(0.02 * Q_W_sol_us_m * (Q_W_sol_out_m / Q_W_sol_us_m))
                Else
                    Q_W_sol_st_ls_m = 0
                    Q_W_bu_dis_ls_m = 0
                End If


                '난방 부분
                U_loop_p = 5 + 0.5 * A_H '(B.3) '===========================2010.04.24 추가
                U_loop = a_1 + a_2 * 40 + U_loop_p / A_H '(13) '===============2010.04.24 추가

                theta_ref = TOSG(11.6 + 1.18 * theta_w + 3.86 * theta_cw - 1.32 * theta_e_avg) '(B.8) 급탕시스템인 경우 theta_w는 40도, theta_cw 시수온도는15도 가정
                Delta_T = theta_ref - theta_e_avg '(14)
                V_ref = A_H * 75
                V_sol = TOSG(Dr신재생.축열탱크체적난방) ' Worksheets("신재생기기").Range("태양열축열탱크1").Offset(1, i_count_ts - 1)
                f_st = TOSG((V_ref / V_sol) ^ 0.25) '(B.5)
                If Q_H_sol_us_m <> 0 Then
                    X = A_H * U_loop * eta_loop * Delta_T * f_st * t_m / (Q_H_sol_us_m * 1000) '(12)
                    Y = A_H * IAM * eta_0 * eta_loop * I_m * t_m / (Q_H_sol_us_m * 1000) '(15)
                    Q_H_sol_out_m = (a * Y + b * X + c * Y * Y + d * X * X + e * Y * Y * Y + f * X * X * X) * Q_H_sol_us_m '(11)
                Else
                    Q_H_sol_out_m = 0
                End If
                If Q_H_sol_out_m < 0 Then Q_H_sol_out_m = 0
                If Q_H_sol_out_m > Q_H_sol_us_m Then Q_H_sol_out_m = Q_H_sol_us_m

                '태양열시스템 열손실
                U_st = TOSG(0.16 * V_sol ^ 0.5) '(B.9)
                theta_setpoint = 40
                If Q_H_sol_us_m <> 0 Then
                    Q_H_sol_st_ls_m = U_st * (theta_setpoint - theta_a_avg) * (Q_H_sol_out_m / Q_H_sol_us_m) * t_m / 1000 '(17)
                    Q_H_bu_dis_ls_m = TOSG(0.02 * Q_H_sol_us_m * (Q_H_sol_out_m / Q_H_sol_us_m))
                Else
                    Q_H_sol_st_ls_m = 0
                    Q_H_bu_dis_ls_m = 0
                End If
                Q_sol_ls_m = Q_H_sol_st_ls_m + Q_H_bu_dis_ls_m + Q_W_sol_st_ls_m + Q_W_bu_dis_ls_m



                ' 보조에너지
                P_aux_nom = TOSG(Dr신재생.솔라펌프의정격출력) ' Worksheets("신재생기기").Range("태양열시스템종류1").Offset(4, i_count_ts - 1)
                W_sol_aux_m = P_aux_nom * t_aux_m / 1000

                Q_sol_aux_rbl_m = TOSG(W_sol_aux_m * 0.5)

                Select Case Dr신재생.축열탱크설치장소.Trim ' Worksheets("신재생기기").Range("태양열축열탱크1").Offset(2, i_count_ts - 1)
                    Case "난방공간" '난방공간"
                        Q_sol_ls_rbl_m = Q_sol_aux_rbl_m + Q_sol_ls_m
                    Case "비난방공간" '비난방공간"
                        Q_sol_ls_rbl_m = TOSG(Q_sol_aux_rbl_m + Q_sol_ls_m * 0.5)
                    Case "외부공간" '외부공간"
                        Q_sol_ls_rbl_m = Q_sol_aux_rbl_m
                End Select

        End Select


        ''보조에너지
        ''f_sol_m = Q_sol_out_m / Q_sol_us_m '(21)
        ''W_bu_aux_m = W_bu_nom_m * (1 - f_sol_m) '(22)

        ''P_aux_nom = 50 + 5 * A_ '(B.4)


        '// 신재생에너지 자립률 추가(2017.01.20)
        If (Q_H_sol_out_m + Q_W_sol_out_m) = 0 Then
            H_W_ratio = 0 ' Q_H_sol_out_m / (Q_H_sol_out_m + Q_W_sol_out_m)

        Else
            H_W_ratio = Q_H_sol_out_m / (Q_H_sol_out_m + Q_W_sol_out_m)
        End If

        '   Q_H_sol_out_net = Q_H_sol_out_m + H_W_ratio * W_sol_aux_m * 2.75
        Q_W_sol_out_net = Q_W_sol_out_m + (1 - H_W_ratio) * W_sol_aux_m * 2.75



        '// 신재생에너지 자립률 추가







        '//열에너지생산량-태양열
        Result.생산E(i_ts_month).태양열생산량 += Q_W_sol_out_net + Q_H_sol_out_net '// 20170120 추가
        '//Result.생산E(i_ts_month).태양열생산량 += Q_W_sol_out_m + Q_H_sol_out_m '20170120 삭제
        'DSETR.TReqUse.Rows(CEnum.ResultRow.생산_열생산량_태양열)(CStr("M" & Format(i_ts_month, "00"))) = CSng(DSETR.TReqUse.Rows(CEnum.ResultRow.생산_열생산량_태양열)(CStr("M" & Format(i_ts_month, "00")))) + Q_W_sol_out_m + Q_H_sol_out_m 'Sheets("계산결과").Cells(97, 7 + i_ts_month) = Q_W_sol_out_m + Q_H_sol_out_m
        'Dim TDR As DSR.TReqUseRow = CType(DSETR.TReqUse.Rows(CEnum.ResultRow.생산_단위면적당생산량_태양열), DSR.TReqUseRow)
        Select Case i_system_ts '//이것도 프로시져 파라미터이다.
            Case 1  '//난방?급탕 혼합형태?
                If Q_W_sol_out_m <> 0 Then
                    Result.생산E(i_ts_month).면적당생산량태양열 += (Q_W_sol_out_net / Result.사용면적.W) '// 20170120 추가
                    'Result.생산E(i_ts_month).면적당생산량태양열 += (Q_W_sol_out_m / Result.사용면적.W)  삭제
                Else
                    Result.생산E(i_ts_month).면적당생산량태양열 += (Q_H_sol_out_net / Result.사용면적.H) '// 20170120 추가
                    'Result.생산E(i_ts_month).면적당생산량태양열 += (Q_H_sol_out_m / Result.사용면적.H)
                End If
            Case 2  '//냉방?
                Result.생산E(i_ts_month).면적당생산량태양열 += (Q_H_sol_out_net / Result.사용면적.C) '// 20170120 추가
                'Result.생산E(i_ts_month).면적당생산량태양열 += (Q_H_sol_out_m / Result.사용면적.C)
            Case 3  '//급탕
                Result.생산E(i_ts_month).면적당생산량태양열 += (Q_W_sol_out_net / Result.사용면적.W) '// 20170120 추가
                'Result.생산E(i_ts_month).면적당생산량태양열 += (Q_W_sol_out_m / Result.사용면적.W)
            Case Else
                MsgBox("단위면적당생산량 누적시 i_syste_ts 가 알수없음", MsgBoxStyle.Critical, "확인")
        End Select

        pLog.Add(String.Format(">>Calc_ThermalSolarSystem_EN 진입 : 태양열생산량={0}, 면적당생산량태양열={1}, Q_W_sol_out_m={2}, Q_H_sol_out_m={3}", _
                                       Result.생산E(i_ts_month).태양열생산량, Result.생산E(i_ts_month).면적당생산량태양열, Q_W_sol_out_net, Q_H_sol_out_net))   '// 20170120 수정
        'pLog.Add(String.Format(">>Calc_ThermalSolarSystem_EN 진입 : 태양열생산량={0}, 면적당생산량태양열={1}, Q_W_sol_out_m={2}, Q_H_sol_out_m={3}", _
        '                       Result.생산E(i_ts_month).태양열생산량, Result.생산E(i_ts_month).면적당생산량태양열, Q_W_sol_out_m, Q_H_sol_out_m))   

    End Sub

    Public Overridable Sub Calc_PhotovoltaicSystem_EN(ByVal i_count_pv_month As Integer, ByVal i_pv_d_mth As Integer)

        pLog.Add(String.Format(">>Calc_PhotovoltaicSystem_EN 진입 : i_count_pv_month={0}, i_pv_d_mth={1}", _
                          i_count_pv_month, i_pv_d_mth))

        Dim E_el_pv_out As Decimal, P_pk As Decimal, f_perf As Decimal, E_sol As Decimal
        Dim a As Decimal, K_pk As Decimal
        'Dim i_count_pv As Integer, i_count_pv_location As Integer, i_pv_location As Integer

        E_el_pv_out = 0

        'If DSET.tbl_new.Rows.Count > 0 Then ' Worksheets("신재생기기").Range("신재생생산기기1").Offset(0, 0) <> "" Then    '//신재생기기 처음칸에 뭐가 잇다? 즉 데이터가잇느냐
        For Each Dr신재생 As DS.tbl_newRow In DSET.tbl_new.Select("code <> '0'", "code")
            If Dr신재생.기기종류 = "태양광" Then

                a = TOSG(Dr신재생.태양광모듈면적) ' Worksheets("신재생기기").Range("태양광모듈1").Offset(0, i_count_pv - 1)

                Select Case Dr신재생.태양광모듈적용타입.Trim ' Worksheets("신재생기기").Range("태양광모듈1").Offset(4, i_count_pv - 1)
                    Case "밀착형" '밀착형"
                        f_perf = 0.7
                    Case "후면통풍형" '후면통풍형"
                        f_perf = 0.75
                    Case "기계환기형" '기계환기형"
                        f_perf = 0.8
                End Select


                'If a <> 0 Then  '//태양광모듈면적이있을경우에만 작동하도록한다.


                Dim Dr일사 As DS.weather_ilsaRow
                Select Case Dr신재생.태양광모듈기울기.Trim ' Worksheets("신재생기기").Range("태양광모듈1").Offset(1, i_count_pv - 1)
                    Case "수평" '수평"
                        '//수평면에해당하는 월별평균일사 값을 가져온다.수평면 0001은 고정값이된다.
                        Dr일사 = CType(DSET.weather_ilsa.Select("pcode='" & Calc.Pub.기상데이터.code & "' and code='0001'")(0), DS.weather_ilsaRow)
                        E_sol = TOSG(Dr일사("M" & Format(i_count_pv_month, "00"))) * i_pv_d_mth * 24 / 1000

                    Case "45도" '45도"
                        Select Case Dr신재생.태양광모듈방위.Trim ' Worksheets("신재생기기").Range("태양광모듈1").Offset(2, i_count_pv - 1)
                            Case "남" '"남"
                                '//45도 남에대한건 기본 수평면하고 +9를 하면 나온다 나머지도 순서이므로 +1을 게속해주면된다.
                                Dr일사 = CType(DSET.weather_ilsa.Select("pcode='" & Calc.Pub.기상데이터.code & "' and code='" & Format(1 + 9, "0000") & "'")(0), DS.weather_ilsaRow)
                                E_sol = TOSG(Dr일사("M" & Format(i_count_pv_month, "00"))) * i_pv_d_mth * 24 / 1000
                            Case "남동" '"남동"
                                Dr일사 = CType(DSET.weather_ilsa.Select("pcode='" & Calc.Pub.기상데이터.code & "' and code='" & Format(1 + 10, "0000") & "'")(0), DS.weather_ilsaRow)
                                E_sol = TOSG(Dr일사("M" & Format(i_count_pv_month, "00"))) * i_pv_d_mth * 24 / 1000
                            Case "남서" '"남서"
                                Dr일사 = CType(DSET.weather_ilsa.Select("pcode='" & Calc.Pub.기상데이터.code & "' and code='" & Format(1 + 11, "0000") & "'")(0), DS.weather_ilsaRow)
                                E_sol = TOSG(Dr일사("M" & Format(i_count_pv_month, "00"))) * i_pv_d_mth * 24 / 1000
                            Case "동" '"동"
                                Dr일사 = CType(DSET.weather_ilsa.Select("pcode='" & Calc.Pub.기상데이터.code & "' and code='" & Format(1 + 12, "0000") & "'")(0), DS.weather_ilsaRow)
                                E_sol = TOSG(Dr일사("M" & Format(i_count_pv_month, "00"))) * i_pv_d_mth * 24 / 1000
                            Case "서" '"서"
                                Dr일사 = CType(DSET.weather_ilsa.Select("pcode='" & Calc.Pub.기상데이터.code & "' and code='" & Format(1 + 13, "0000") & "'")(0), DS.weather_ilsaRow)
                                E_sol = TOSG(Dr일사("M" & Format(i_count_pv_month, "00"))) * i_pv_d_mth * 24 / 1000
                        End Select

                    Case "수직" '수직"
                        Select Case Dr신재생.태양광모듈방위.Trim 'Worksheets("신재생기기").Range("태양광모듈1").Offset(2, i_count_pv - 1)
                            Case "남" '"남"
                                Dr일사 = CType(DSET.weather_ilsa.Select("pcode='" & Calc.Pub.기상데이터.code & "' and code='" & Format(1 + 1, "0000") & "'")(0), DS.weather_ilsaRow)
                                E_sol = TOSG(Dr일사("M" & Format(i_count_pv_month, "00"))) * i_pv_d_mth * 24 / 1000
                            Case "남동" '"남동"
                                Dr일사 = CType(DSET.weather_ilsa.Select("pcode='" & Calc.Pub.기상데이터.code & "' and code='" & Format(1 + 2, "0000") & "'")(0), DS.weather_ilsaRow)
                                E_sol = TOSG(Dr일사("M" & Format(i_count_pv_month, "00"))) * i_pv_d_mth * 24 / 1000
                            Case "남서" '"남서"
                                Dr일사 = CType(DSET.weather_ilsa.Select("pcode='" & Calc.Pub.기상데이터.code & "' and code='" & Format(1 + 3, "0000") & "'")(0), DS.weather_ilsaRow)
                                E_sol = TOSG(Dr일사("M" & Format(i_count_pv_month, "00"))) * i_pv_d_mth * 24 / 1000
                            Case "동" '"동"
                                Dr일사 = CType(DSET.weather_ilsa.Select("pcode='" & Calc.Pub.기상데이터.code & "' and code='" & Format(1 + 4, "0000") & "'")(0), DS.weather_ilsaRow)
                                E_sol = TOSG(Dr일사("M" & Format(i_count_pv_month, "00"))) * i_pv_d_mth * 24 / 1000
                            Case "서" '"서"
                                Dr일사 = CType(DSET.weather_ilsa.Select("pcode='" & Calc.Pub.기상데이터.code & "' and code='" & Format(1 + 5, "0000") & "'")(0), DS.weather_ilsaRow)
                                E_sol = TOSG(Dr일사("M" & Format(i_count_pv_month, "00"))) * i_pv_d_mth * 24 / 1000
                        End Select
                End Select

                'E_sol = E_sol_hor * f_tlt 수평면일사에 계수를 곱하지 않고 직접 기상데이타 적용

                Select Case Dr신재생.태양광모듈종류.Trim ' Worksheets("신재생기기").Range("태양광모듈1").Offset(3, i_count_pv - 1)
                    Case "단결정" '단결정"
                        K_pk = 0.12
                    Case "다결정" '다결정"
                        K_pk = 0.1
                    Case "비정질박막형" '비정질박막형"
                        K_pk = 0.04
                    Case "기타박막형" '기타박막형"
                        K_pk = 0.035
                    Case "CIS박막형" 'CIS박막형"
                        K_pk = 0.105
                    Case "CdTe박막형" 'CdTe박막형"
                        K_pk = 0.095
                    Case "성능치 입력"
                        Try
                            K_pk = TOSG(Dr신재생.태양광모듈효율)
                        Catch ex As Exception
                            MsgBox("태양광모듈효율을 알 수 없습니다.", MsgBoxStyle.Critical, "값=" & Dr신재생.태양광모듈효율)
                            K_pk = 0
                        End Try

                    Case Else
                        MsgBox("알수없는 태양광모듈종류입니다.", MsgBoxStyle.Critical, "값=" & Dr신재생.태양광모듈종류)

                End Select

                P_pk = K_pk * a
                E_el_pv_out = E_el_pv_out + E_sol * P_pk * f_perf
                'End If
            End If
        Next


        'If Sheets("계산결과").Cells(104, 7 + i_count_pv_month) = "" Then
        '    Sheets("계산결과").Cells(104, 7 + i_count_pv_month) = E_el_pv_out
        'Else
        '    Sheets("계산결과").Cells(104, 7 + i_count_pv_month) = Sheets("계산결과").Cells(104, 7 + i_count_pv_month) + E_el_pv_out
        'End If

        Result.생산E(i_count_pv_month).태양광전력생산량 += E_el_pv_out

        pLog.Add(String.Format(">>Calc_PhotovoltaicSystem_EN 진입 : E_el_pv_out={0}, 태양광전력생산량={1}", _
                       E_el_pv_out, Result.생산E(i_count_pv_month).태양광전력생산량))



        'DSETR.TReqUse.Rows(CEnum.ResultRow.생산_전기_태양광)("M" & Format(i_count_pv_month, "00")) = CSng(DSETR.TReqUse.Rows(CEnum.ResultRow.생산_전기_태양광)("M" & Format(i_count_pv_month, "00"))) + E_el_pv_out  ' Sheets("계산결과").Cells(95, 7 + i_count_pv_month)
    End Sub

    Public Overridable Sub Calc_HeatpumpSystem(ByVal i_system_hp As Integer, ByVal i_HeatCool As Integer, ByVal Dr신재생 As DS.tbl_newRow, ByVal Q_hp_outg As Decimal, ByVal i_hp_month As Integer, _
                                               ByVal d_h_mth As Integer, ByVal t_hp As Integer, ByVal theta_VA As Decimal, ByVal theta_i As Decimal, ByRef Q_h_outg As Decimal, ByRef Q_h_f_hp As Decimal, ByRef Q_h_g_aux As Decimal)

        pLog.Add(String.Format(">>Calc_HeatpumpSystem 진입 : i_system_hp={0}, i_HeatCool={1},dr신재생={2},Q_hp_outg={3},i_hp_month={4},d_h_mth={5},t_hp={6},theta_VA={7},theta_i={8},Q_h_outg={9},Q_h_f_hp={10},Q_h_g_aux={11}", _
                          i_system_hp, i_HeatCool, Dr신재생.code, Q_hp_outg, i_hp_month, d_h_mth, t_hp, theta_VA, theta_i, Q_h_outg, Q_h_f_hp, Q_h_g_aux))


        Dim f_Verwindung As Decimal, V As Decimal, q_B_S As Decimal, Phi_g As Decimal
        Dim Q_h_g As Decimal, Q_h_g_s As Decimal, Q_h_g_WP As Decimal
        Dim P_rd_mot As Decimal
        'Dim Q_h_f_hp as decimal 'DIN 에서는 Q_h_f로 표기
        'Dim Delta_p_prim as decimal, Delta_p_sek as decimal
        Dim Phi_prim_aux As Decimal, Phi_sek_aux As Decimal, t_ON_aux As Decimal
        Dim theta_h_s As Decimal
        Dim COP As Decimal
        Dim Q_h_outg_net As Decimal


        Q_h_g_s = 0
        Q_h_g_WP = 0 '전기히트펌프인 경우 0  가스히트펌프는 ?
        P_rd_mot = 0
        Q_h_f_hp = 0
        Q_h_outg_net = 0


        'eta_aux = 0.3
        'Delta_p_prim = 40 'kPa 1차측
        'Delta_p_sek = 10 'kPa 2차측

        'MsgBox(i_count_hp)

        'i_count_hp = 0  '//신재생 줄번호는 무조건 0이된다. 20100127 '//연습용데이터 문제있음
        ' Dim Dr신재생 As DS.tbl_newRow = CType(DSET.tbl_new.Rows(0), DS.tbl_newRow)

        Phi_g = TOSG(Dr신재생.지열히트펌프용량) '  Worksheets("신재생기기").Range("지열히트펌프용량1").Offset(0, i_count_hp - 1)

        If Dr신재생.가동연료 <> "전기" And i_HeatCool = 1 And Dr신재생.열교환기설치여부 = "예" Then ' Worksheets("신재생기기").Range("지열히트펌프용량1").Offset(5, i_count_hp - 1) = "예" Then
            P_rd_mot = 0.4
        End If

        If Q_hp_outg < (Phi_g * t_hp) * (1 + P_rd_mot) Then
            Q_h_outg = Q_hp_outg
        Else
            Q_h_outg = Phi_g * t_hp * (1 + P_rd_mot)
        End If

        If i_HeatCool = 1 Or i_HeatCool = 3 Then '난방 1 , 냉방 2, 급탕 3
            '난방, 급탕
            If Dr신재생.팽창탱크설치여부 = "예" Then ' Worksheets("신재생기기").Range("지열히트펌프용량1").Offset(6, i_count_hp - 1) = "예" Then
                f_Verwindung = 1.2
                V = TOSG(Dr신재생.팽창탱크체적) ' Worksheets("신재생기기").Range("지열히트펌프용량1").Offset(7, i_count_hp - 1)
                q_B_S = TOSG(0.4 + 0.14 * V ^ 0.45) '(51)
                theta_h_s = theta_VA '급수온도로 적용
                Q_h_g_s = f_Verwindung * (theta_h_s - theta_i) / 45 * d_h_mth * q_B_S '(49) 외부완충(팽창탱크 유무)

            End If

            Q_h_g = Q_h_g_s + Q_h_g_WP
            COP = TOSG(Dr신재생.열성능비난방) ' Worksheets("신재생기기").Range("지열히트펌프용량1").Offset(1, i_count_hp - 1)

        Else
            '냉방

            COP = TOSG(Dr신재생.열성능비냉방) ' Worksheets("신재생기기").Range("지열히트펌프용량1").Offset(2, i_count_hp - 1)

        End If


        If Dr신재생.가동연료 = "전기" Then ' Worksheets("신재생기기").Range("신재생및열병합기기종류1").Offset(1, i_count_hp - 1) = "전기" Then
            Q_h_f_hp = (Q_h_outg + Q_h_g) / COP
            '    Q_h_in = Q_h_outg + Q_h_g - Q_h_f_hp '월간 전기히트펌프(재생에너지유입량)
        Else
            Q_h_f_hp = Q_h_outg / COP
            '    If i_HeatCool = 1 And Worksheets("신재생기기").Range("지열히트펌프용량1").Offset(5, i_count_hp - 1) = "예" Then
            '        P_rd_mot = 0.4
            '    End If
            '    Q_h_in = Q_h_outg + Q_h_g - Q_h_f_hp * (1 + P_rd_mot) '월간 가스히트펌프(재생에너지유입량)
        End If

        'Q_h_f = Q_h_outg + Q_h_g - k_rd_g * Q_h_g_aux - Q_h_in '월간(A.1) 전기히트펌프(난방요구량 충당)
        'Q_h_f = (Q_h_outg + Q_h_g - k_rd_g * Q_h_g_aux - Q_h_in) / (1 + P_rd_mot) '월간(A.2) 가스히트펌프(난방요구량 충당)


        '보조에너지


        'Phi_prim_aux = Delta_p_prim * V_dot / (eta_aux * 3600) '(89) 사용자 입력항목이므로 확인 요망
        'Phi_sek_aux = Delta_p_sek * V_dot / (eta_aux * 3600) '(89) 사용자 입력항목이므로 확인 요망

        t_ON_aux = Q_h_outg / (Phi_g) '(81)
        Phi_prim_aux = TOSG(Dr신재생.펌프용량1차) ' Worksheets("신재생기기").Range("지열히트펌프용량1").Offset(3, i_count_hp - 1)
        Phi_sek_aux = TOSG(Dr신재생.펌프용량2차) ' Worksheets("신재생기기").Range("지열히트펌프용량1").Offset(4, i_count_hp - 1)

        Q_h_g_aux = TOSG((Phi_prim_aux + Phi_sek_aux) * 0.001 * t_ON_aux) '(88)


        '// 신재생에너지 자립률 추가(2017.01.20)

        If Dr신재생.가동연료 = "전기" Then
            Q_h_outg_net = Q_h_outg - ((Q_h_f_hp + Q_h_g_aux) * 2.75)  '전기 1차에너지계수 적용
            If Q_h_outg_net < 0 Then Q_h_outg_net = 0

        Else
            Q_h_outg_net = Q_h_outg - (Q_h_f_hp * 1.1 + Q_h_g_aux * 2.75)  '가스 1차에너지계수 적용
            If Q_h_outg_net < 0 Then Q_h_outg_net = 0
        End If



        '// 신재생에너지 자립률 추가


        '//열에너지생산량 (지열)
        Result.생산E(i_hp_month).지열생산량 += Q_h_outg_net '//20170120 추가
        '// Result.생산E(i_hp_month).지열생산량 += Q_h_f_hp  '20170120 지열생산량을 수정
        'DSETR.TReqUse.Rows(79)("M" & Format(i_hp_month, "00")) = CSng(DSETR.TReqUse.Rows(79)("M" & Format(i_hp_month, "00"))) + Q_h_f_hp 'DrT생산.열생산량지열 += Q_h_f_hp

        pLog.Add(String.Format(">>Calc_HeatpumpSystem 결과0 Q_h_f_hp={0},t_ON_aux={1},Q_h_g_aux={2}", _
                      Q_h_f_hp, t_ON_aux, Q_h_g_aux))

        pLog.Add(String.Format(">>Calc_HeatpumpSystem 결과1 지열생산량={0}", _
                       Result.생산E(i_hp_month).지열생산량))

        '100 : Total >> DrT생산.단위면적당생산량지열
        Select Case i_system_hp
            Case 1
                Result.생산E(i_hp_month).면적당생산량지열 += (Q_h_outg_net / Result.사용면적.H)  '//20170120 추가
                '//Result.생산E(i_hp_month).면적당생산량지열 += (Q_h_f_hp / Result.사용면적.H) '20170120 지열생산량을 수정
                'DSETR.TReqUse.Rows(100)("M00") = CSng(DSETR.TReqUse.Rows(100)("M00")) + Q_h_f_hp / CSng(DSETR.TReqUse.Rows(10)("M00")) ' DrT요구량.난방사용면적 ' Sheets("계산결과").Cells(15, 7)
            Case 2
                Result.생산E(i_hp_month).면적당생산량지열 += (Q_h_outg_net / Result.사용면적.C)  '//20170120 추가
                '//Result.생산E(i_hp_month).면적당생산량지열 += (Q_h_f_hp / Result.사용면적.C) '20170120 지열생산량을 수정
                'DSETR.TReqUse.Rows(100)("M00") = CSng(DSETR.TReqUse.Rows(100)("M00")) + Q_h_f_hp / CSng(DSETR.TReqUse.Rows(15)("M00")) 'DrT요구량.냉방사용면적 '("계산결과").Cells(20, 7)
            Case 3
                Result.생산E(i_hp_month).면적당생산량지열 += (Q_h_outg_net / Result.사용면적.W)  '//20170120 추가
                '//Result.생산E(i_hp_month).면적당생산량지열 += (Q_h_f_hp / Result.사용면적.W) '20170120 지열생산량을 수정
        End Select

        pLog.Add(String.Format(">>Calc_HeatpumpSystem 결과2 면적당생산량지열={0}", _
                       Result.생산E(i_hp_month).면적당생산량지열))

    End Sub

    Public Overridable Sub Calc_CogenerationSystemEN(ByVal Dr신재생 As DS.tbl_newRow, i_system_chp As Integer, ByVal i_chp_month As Integer, ByVal Q_h_outg As Decimal, ByVal t_chp As Integer, _
                                                     ByRef Q_chp_gen_out As Decimal, ByRef E_chp_gen_in As Decimal)

        pLog.Add(String.Format(">>Calc_CogenerationSystemEN 진입 : Dr신재생={0}, i_system_chp={1},i_chp_month={2},Q_h_outg={3},t_chp={4},Q_chp_gen_out={5},E_chp_gen_in={6}", _
                          Dr신재생.code, i_system_chp, i_chp_month, Q_h_outg, t_chp, Q_chp_gen_out, E_chp_gen_in))

        'EN15316-4-4_2007 5.6.2에서 시작
        'Dim Wmsg As New System.Text.StringBuilder
        'Wmsg.AppendLine("Calc_CogenerationSystemEN 이 함수의경우")
        'Wmsg.AppendLine("i_count_chp 에따라서 열을 할당해야한다.... 지만..아직 이 파라미터값을 모르게삳")
        'Wmsg.AppendLine("사용하는곳의 참조확인을해서 저곳이 신재생기기 코드값이 바로오는건지 다른값인지 확인해봐야겠다")
        'MsgBox(Wmsg.ToString)

        Dim Q_dot_T_chp As Decimal
        Dim eta_T_chp_an As Decimal, eta_el_chp_an As Decimal
        Dim E_el_chp_out As Decimal
        Dim Q_chp_gen_out_net As Decimal, E_el_chp_out_net As Decimal, Q_E_ratio As Decimal, net_ratio As Decimal

        Q_chp_gen_out_net = 0
        E_el_chp_out_net = 0
        Q_E_ratio = 0
        net_ratio = 0



        ' Dim Dr신재생 As DS.tbl_newRow = CType(DSET.tbl_new.Rows(0), DS.tbl_newRow)

        Q_dot_T_chp = TOSG(Dr신재생.열생산능력) ' Worksheets("신재생기기").Range("열병합열생산능력1").Offset(0, i_count_chp - 1)
        eta_T_chp_an = TOSG(Dr신재생.열생산효율) ' Worksheets("신재생기기").Range("열병합열생산능력1").Offset(1, i_count_chp - 1)
        eta_el_chp_an = TOSG(Dr신재생.발전효율) ' Worksheets("신재생기기").Range("열병합열생산능력1").Offset(2, i_count_chp - 1)

        If Q_h_outg > (Q_dot_T_chp * t_chp) Then
            Q_chp_gen_out = Q_dot_T_chp * t_chp
        Else
            Q_chp_gen_out = Q_h_outg
        End If

        E_chp_gen_in = Q_chp_gen_out / (eta_T_chp_an / 100)
        E_el_chp_out = E_chp_gen_in * eta_el_chp_an / 100

        Result.생산E(i_chp_month).열병합전력생산량 += E_el_chp_out

        pLog.Add(String.Format("Calc_CogenerationSystemEN 결과0 E_chp_gen_in={0},E_el_chp_out={1}", E_chp_gen_in, E_el_chp_out))
        pLog.Add(String.Format("Calc_CogenerationSystemEN 결과1 열병합전력생산량={0}", Result.생산E(i_chp_month).열병합전력생산량))

        '//전기생산량 열병합
        If Dr신재생.열병합신재생여부 Then


            '// 신재생에너지 자립률 추가(2017.01.20)

            net_ratio = (Q_chp_gen_out + E_el_chp_out * 2.75) / (E_chp_gen_in * 1.1)
            Q_E_ratio = Q_chp_gen_out / (Q_chp_gen_out + E_el_chp_out * 2.75)
            Q_chp_gen_out_net = Q_chp_gen_out * (net_ratio - 1) * Q_E_ratio
            E_el_chp_out_net = (E_el_chp_out * 2.75 * (net_ratio - 1) * (1 - Q_E_ratio)) / 2.75
            If Q_chp_gen_out_net < 0 Then Q_chp_gen_out_net = 0
            If E_el_chp_out_net < 0 Then E_el_chp_out_net = 0



            '// 신재생에너지 자립률 추가


            '//전력
            Result.생산E(i_chp_month).신재생열병합전력생산량 += (E_el_chp_out_net) '//20170120 추가
            'Result.생산E(i_chp_month).신재생열병합전력생산량 += (E_el_chp_out)

            pLog.Add(String.Format("Calc_CogenerationSystemEN 결과2 신재생열병합전력생산량={0}", Result.생산E(i_chp_month).신재생열병합전력생산량))

            '//면적당열병합 (신재생면적당열생산량)
            Select Case i_system_chp
                Case 1
                    Result.생산E(i_chp_month).신재생면적당열생산량 += (Q_chp_gen_out_net / Result.사용면적.H) '// 20170120 추가
                    'Result.생산E(i_chp_month).신재생면적당열생산량 += (Q_chp_gen_out / Result.사용면적.H)
                Case 2
                    Result.생산E(i_chp_month).신재생면적당열생산량 += (Q_chp_gen_out_net / Result.사용면적.C) '// 20170120 추가
                    'Result.생산E(i_chp_month).신재생면적당열생산량 += (Q_chp_gen_out / Result.사용면적.C)
                Case 3
                    Result.생산E(i_chp_month).신재생면적당열생산량 += (Q_chp_gen_out_net / Result.사용면적.W) '// 20170120 추가
                    'Result.생산E(i_chp_month).신재생면적당열생산량 += (Q_chp_gen_out / Result.사용면적.W)

            End Select

            pLog.Add(String.Format("Calc_CogenerationSystemEN 결과3 신재생면적당열생산량={0}", Result.생산E(i_chp_month).신재생면적당열생산량))

        End If
        'DSETR.TReqUse.Rows(77)("M" & Format(i_chp_month, "00")) = CSng(DSETR.TReqUse.Rows(77)("M" & Format(i_chp_month, "00"))) + E_el_chp_out ' Sheets("계산결과").Cells(96, 7 + i_chp_month) = E_el_chp_out
    End Sub
End Class
