Public Class CAirHandlingOD

    Dim T As String = "공조기기"

    ''' <summary>
    ''' 최대냉/난반후하 계산식인거 같다.
    ''' </summary>
    ''' <param name="i_HeatCool"></param>
    ''' <remarks></remarks>
    Public Overridable Sub Calc_Max_Power(ByVal i_HeatCool As Integer)
        'Dim i_count_zone As Integer, i_count_AHU As Integer, i_count_profile As Integer
        Dim c_p_L As Decimal, rho_L As Decimal
        Dim theta_i_c As Decimal, theta_ABL_wi As Decimal, theta_ABL_so As Decimal, theta_AUL_wi As Decimal, theta_AUL_so As Decimal, theta_ZUL_wi As Decimal, theta_ZUL_so As Decimal
        Dim x_ABL_wi As Decimal, x_ABL_so As Decimal, x_AUL_wi As Decimal, x_AUL_so As Decimal, x_ZUL_so As Decimal
        Dim h_ABL_wi As Decimal, h_ABL_so As Decimal, h_AUL_wi As Decimal, h_AUL_so As Decimal, h_ZUL_wi As Decimal, h_ZUL_so As Decimal
        Dim Delta_h_WRG As Decimal, V_dot_mech_m As Decimal, V_dot_star As Decimal, theta_c_mech_min As Decimal, ps_theta_ZUL_so As Decimal
        Dim Q_dot_h_star As Decimal, Q_dot_c_star As Decimal, Q_dot_st_star As Decimal
        Dim Q_dot_h_max As Decimal, Q_dot_c_max As Decimal
        Dim theta_e_min As Decimal, theta_e_max As Decimal, V_A As Decimal, theta_i_h As Decimal, theta_i_c_soll As Decimal
        Dim A_B As Decimal, c_p_Lrho_L As Decimal


        theta_i_c = 24
        theta_i_c_soll = 26
        theta_i_h = 20
        c_p_L = 1.006 'kJ/kg K
        rho_L = 1.204 'kg/m3 (20도 1기압상태)
        c_p_Lrho_L = 0.34 'Wh/m3 K
        theta_ABL_wi = 22
        x_ABL_wi = 0.008 '편차가 없는 습도요구 적용
        h_ABL_wi = 42.6 '편차가 없는 습도요구 적용
        theta_ABL_so = 26
        x_ABL_so = 0.008 '편차가 없는 습도요구 적용
        h_ABL_so = 46.7 '편차가 없는 습도요구 적용
        theta_AUL_wi = -12
        x_AUL_wi = 0.001
        h_AUL_wi = -9.6
        theta_AUL_so = 32
        x_AUL_so = 0.012
        h_AUL_so = 63
        theta_e_min = -11.3
        theta_e_max = 31.5


        'Dim dr공조처리 As DS.tbl_kongjoRow

        For Each Dr존 As DS.tbl_zoneRow In DSET1.tbl_zone.Select("code<>'0'", "code")

            Dim dr최대냉난방부하 As DSR.최대냉난방부하Row = CType(DSETR1.최대냉난방부하.Select("zone='" & Dr존.code & "'")(0), DSR.최대냉난방부하Row)
            If Dr존.냉난방공조 = "냉방" Or Dr존.냉난방공조 = "냉난방" Then
                A_B = TOSG(T, Dr존.면적) ' Worksheets("입력존").Range("전용면적1").Offset(0, i_count_zone - 1)
                Dim dr프로필 As DS.tbl_profile_odRow = CType(DSET1.tbl_profile_od.Select("code='0'")(0), DS.tbl_profile_odRow)
                V_A = TOSG(T, dr프로필.최소도입외기량) * A_B ' Worksheets("설정조건").Range("최소도입외기량1").Offset(0, i_count_profile) * A_B

                For Each dr공조처리 As DS.tbl_kongjoRow In DSET1.tbl_kongjo.Select("code <>'0'", "code")
                    '//아래두코드는 상단코드로 변경
                    'If Dr존.냉난방공조처리시스템 <> "" Then ' Worksheets("입력존").Range("입력난방공급기기1").Offset(2, i_count_zone - 1) <> "" Then
                    'If Dr존.냉난방공조처리시스템 = dr공조처리.code Then ' Worksheets("입력존").Range("입력난방공급기기1").Offset(2, i_count_zone - 1) = Worksheets("공조처리시스템").Range("공조기기1").Offset(0, i_count_AHU - 1) Then

                    ' 공조기 최대 가열성능
                    If i_HeatCool = 1 Then
                        If Dr존.냉난방공조 = "냉난방" Then ' Worksheets("입력존").Range("공조존2").Offset(0, i_count_zone - 1) = "냉난방" Then
                            Delta_h_WRG = 0 '(3.2.5-54) 열 회수기 없음


                            theta_ZUL_wi = TOSG(T, dr공조처리.설정치난방) ' Worksheets("공조처리시스템").Range("공조방식1").Offset(1, i_count_AHU - 1) 'theta_h_mech_min '(도표 3-3)

                            'h_ZUL_wi = 1.01 * theta_ZUL_wi + 0.001 * (2501 + 1.86 * theta_ZUL_wi) '(3.2.5-38) 습도요구 없음
                            'h_ZUL_wi = 1.01 * theta_ZUL_wi + 0.006 * (2501 + 1.86 * theta_ZUL_wi) '(3.2.5-42) 편차가 있는 습도요구
                            h_ZUL_wi = TOSG(T, 1.01 * theta_ZUL_wi + 0.008 * (2501 + 1.86 * theta_ZUL_wi)) '(3.2.5-48) 편차가 없는 습도요구만 우선 적용
                            Q_dot_h_max = TOSG(T, dr최대냉난방부하.최대난방기기부하) ' Worksheets("0").Range("최대난방부하1").Offset(0, i_count_zone - 1)

                            '--------------------------------------------------------------------------------------------------2010.02.22 수정
                            If (TOSG(T, dr공조처리.설정치난방) - theta_i_h) > 0 Then
                                V_dot_mech_m = 1000 * Q_dot_h_max / (c_p_Lrho_L * (TOSG(T, dr공조처리.설정치난방) - theta_i_h))
                                'Console.WriteLine(String.Format("%%%%%% V_dot_mech_m = {0},Q_dot_h_max={1},c_p_Lrho_L={2},theta_i_h={3},dr공조처리.설정치난방={4}",                                                                 V_dot_mech_m, Q_dot_h_max, c_p_Lrho_L, theta_i_h, dr공조처리.설정치난방))
                            Else
                                V_dot_mech_m = 0
                            End If
                            '--------------------------------------------------------------------------------------------------2010.02.22 수정

                            V_dot_star = V_dot_mech_m
                            Q_dot_h_star = V_dot_star * rho_L * (c_p_L * (theta_ZUL_wi - theta_AUL_wi) - Delta_h_WRG) / 3600 '(3.2.5-58) 증기가습 없음 - 열교환방식으로 수정 추후 검토

                            dr최대냉난방부하.최대가열성능 = Q_dot_h_star
                            'Worksheets("0").Range("최대난방부하1").Offset(3, i_count_zone - 1) = Q_dot_h_star
                            If Q_dot_h_max > (c_p_Lrho_L * (theta_i_h - theta_e_min) * V_A) / 1000 Then
                                dr최대냉난방부하.최대난방실내부하 = (Q_dot_h_max - (c_p_Lrho_L * (theta_i_h - theta_e_min) * V_A) / 1000)
                                'Worksheets("0").Range("최대난방부하1").Offset(1, i_count_zone - 1) = Q_dot_h_max - (c_p_Lrho_L * (theta_i_h - theta_e_min) * V_A) / 1000
                            Else
                                dr최대냉난방부하.최대난방실내부하 = 0
                                'Worksheets("0").Range("최대난방부하1").Offset(1, i_count_zone - 1) = 0
                            End If
                        End If

                        '공조기 최대 가습성능

                        'h_ZUL_wi = 1.01 * theta_ZUL_wi + 0.001 * (2501 + 1.86 * theta_ZUL_wi) '(3.2.5-38) 습도요구 없음
                        'h_ZUL_wi = 1.01 * theta_ZUL_wi + 0.006 * (2501 + 1.86 * theta_ZUL_wi) '(3.2.5-42) 편차가 있는 습도요구
                        h_ZUL_wi = TOSG(T, 1.01 * theta_ZUL_wi + 0.008 * (2501 + 1.86 * theta_ZUL_wi)) '(3.2.5-48) 편차가 없는 습도 요구

                        Delta_h_WRG = 0 '(3.2.5-63) 열 회수기 없음

                        Q_dot_st_star = V_dot_star * rho_L * (h_ZUL_wi - h_AUL_wi - Delta_h_WRG) / 3600 '(3.2.5-65)
                        dr최대냉난방부하.최대가습성능 = Q_dot_st_star
                        dr최대냉난방부하.공조풍량 = V_dot_star
                        'Worksheets("0").Range("최대가습성능1").Offset(0, i_count_zone - 1) = Q_dot_st_star
                        'Worksheets("0").Range("최대가습성능1").Offset(1, i_count_zone - 1) = V_dot_star '공조풍량

                    Else

                        ' 공조기 최대 냉각성능

                        theta_c_mech_min = TOSG(T, dr공조처리.설정치냉방) ' Worksheets("공조처리시스템").Range("공조방식1").Offset(2, i_count_AHU - 1)
                        theta_ZUL_so = theta_c_mech_min '(도표 3.3)
                        ps_theta_ZUL_so = TOSG(T, Math.Exp(23.621 - 4065 / (theta_ZUL_so + 236.2506))) '(3.2.5-37) 0.01C<=theta<=80C
                        x_ZUL_so = TOSG(T, 0.5911 / (100000 / ps_theta_ZUL_so - 0.95)) '(3.2.5-41)

                        'h_ZUL_so = 1.01 * theta_ZUL_so + 0.012 * (2501 + 1.86 * theta_ZUL_so) '(3.2.5-39) 습도요구 없음 ps_theta_ZUL_so>1892Pa
                        'h_ZUL_so = 1.01 * theta_ZUL_so + x_ZUL_so * (2501 + 1.86 * theta_ZUL_so) '(3.2.5-40) 습도요구 없음 ps_theta_ZUL_so<=1892Pa
                        'h_ZUL_so = 1.01 * theta_ZUL_so + 0.011 * (2501 + 1.86 * theta_ZUL_so) '(3.2.5-43) 편차가 있는 습도요구 ps_theta_ZUL_so>1737Pa
                        'h_ZUL_so = 1.01 * theta_ZUL_so + x_ZUL_so * (2501 + 1.86 * theta_ZUL_so) '(3.2.5-44) 편차가 있는 습도요구 ps_theta_ZUL_so<=1737Pa

                        If ps_theta_ZUL_so > 1269 Then
                            h_ZUL_so = TOSG(T, 1.01 * theta_ZUL_so + 0.008 * (2501 + 1.86 * theta_ZUL_so)) '(3.2.5-43) 편차가 없는 습도요구 ps_theta_ZUL_so>1269Pa
                        Else
                            h_ZUL_so = TOSG(T, 1.01 * theta_ZUL_so + x_ZUL_so * (2501 + 1.86 * theta_ZUL_so)) '(3.2.5-44) 편차가 없는 습도요구 ps_theta_ZUL_so<=1269Pa
                        End If

                        Delta_h_WRG = 0 '(3.2.5-59) 열 회수기 없음

                        Q_dot_c_max = TOSG(T, dr최대냉난방부하.최대냉방기기부하) ' Worksheets("0").Range("최대냉방부하1").Offset(0, i_count_zone - 1)
                        '--------------------------------------------------------------------------------------------------2010.02.22 수정
                        If (theta_i_c - TOSG(T, dr공조처리.설정치냉방)) > 0 Then
                            V_dot_star = 1000 * Q_dot_c_max / (c_p_Lrho_L * (theta_i_c - TOSG(T, dr공조처리.설정치냉방)))
                        Else
                            V_dot_star = 0
                        End If
                        '--------------------------------------------------------------------------------------------------2010.02.22 수정
                        Q_dot_c_star = V_dot_star * rho_L * (h_AUL_so - h_ZUL_so - Delta_h_WRG) / 3600 '(3.2.5-62)

                        dr최대냉난방부하.최대냉각성능 = Q_dot_c_star
                        dr최대냉난방부하.최대냉방실내부하 = Q_dot_c_max - (c_p_Lrho_L * (theta_e_max - theta_i_c_soll) * V_A) / 1000

                        'Worksheets("0").Range("최대냉방부하1").Offset(3, i_count_zone - 1) = Q_dot_c_star
                        'Worksheets("0").Range("최대냉방부하1").Offset(1, i_count_zone - 1) = Q_dot_c_max - (c_p_Lrho_L * (theta_e_max - theta_i_c_soll) * V_A) / 1000
                    End If

                    'End If
                    'End If

                Next
            Else

                dr최대냉난방부하.최대난방실내부하 = 0
                dr최대냉난방부하.최대냉방실내부하 = 0
                dr최대냉난방부하.최대가열성능 = 0
                dr최대냉난방부하.최대냉각성능 = 0
                dr최대냉난방부하.최대가습성능 = 0
                dr최대냉난방부하.공조풍량 = 0
            End If

        Next

    End Sub

    Public Overridable Sub Calc_AirHandling(ByVal i_count_month As Integer, ByVal theta_e As Decimal) ' ByVal d_mth As Integer,
        Dim A_B As Decimal
        Dim x_ABL_wi As Decimal, h_ABL_wi As Decimal, x_ABL_so As Decimal, h_ABL_so As Decimal, x_AUL_wi As Decimal, h_AUL_wi As Decimal, x_AUL_so As Decimal, h_AUL_so As Decimal
        Dim c_p_L As Decimal, rho_L As Decimal, f_p As Decimal, rho_cl As Decimal
        Dim q_st_18_12h_m As Decimal, q_st_12h_m As Decimal, q_h_12h_m As Decimal, q_c_12h_m As Decimal, q_h_m As Decimal, q_c_m As Decimal, q_st_m As Decimal
        Dim eta_ZUL As Decimal, eta_ABL As Decimal, f_h_H As Decimal, f_h_C As Decimal, f_h_st As Decimal
        Dim Delta_p_star_ZUL As Decimal, Delta_p_star_ABL As Decimal, Delta_h_WRG As Decimal
        Dim Q_V_E_ZUL_m As Decimal, Q_V_E_ABL_m As Decimal, Q_c_b As Decimal, Q_h_b As Decimal, Q_vh_b As Decimal, Q_vc_b As Decimal, Q_vm_b As Decimal
        Dim t_V_mech_m As Decimal, theta_V_mech_m As Decimal, theta_hc_m As Decimal
        Dim V_dot_mech_m As Decimal, V_dot_mech_max As Decimal, V_dot_A As Decimal, V_dot_z As Decimal, P_V_ZUL_m As Decimal, P_V_ABL_m As Decimal
        Dim Sigma_V_dot As Decimal, Sigma_V_dot_3 As Decimal
        Dim theta_h_mech_m As Decimal, theta_c_mech_m As Decimal

        ' Dim i_count_zone As Integer, i_count_profile As Integer, i_count_AHU As Integer
        Dim theta_i_c_soll As Integer, theta_i_c As Integer, theta_i_h_soll As Integer, d_V_mech_m As Integer, theta_ABL_wi As Integer, theta_ABL_so As Integer
        Dim V_dot_mech_h_max As Decimal, V_dot_mech_c_max As Decimal, V_dot_mech_c_m As Decimal, V_dot_mech_h_m As Decimal
        Dim theta_e_min As Decimal, theta_e_max As Decimal
        Dim x_ZUL_wi As Decimal, theta_ZUL_wi As Decimal, theta_AUL As Decimal, h_AUL As Decimal, x_AUL As Decimal, theta_AUL_j As Decimal, x_AUL_j As Decimal, psi_AUL_j As Decimal
        Dim h_B As Decimal, r_0 As Decimal, m_dot_1_L As Decimal, u As Decimal, Phi_h As Decimal, Phi_c As Decimal '===============================2010.04.14 수정
        Dim Q_VE_B As Decimal, Q_VE_ZU As Decimal, Q_VE_D As Decimal
        Dim c_p_Lrho_L As Decimal, theta_ZUL_so As Decimal, p_S_theta_ZUL_so As Decimal, p_95_theta_ZUL_so As Decimal, x_95_ZUL_so As Decimal
        Dim h_95_ZUL_so As Decimal, i_count_air As Integer, i_count_start_time As Integer, i_count_end_time As Integer ', i_profile As Integer
        Dim P_D_j_theta_AUL_j As Decimal


        If i_count_month = 3 Then
            'Console.WriteLine("sdf")
        End If

        ' 공조처리

        theta_i_c_soll = 26
        theta_i_c = 24 'theta_i_c_soll - 2 '(2-36)
        theta_i_h_soll = 20
        c_p_L = 1.006 'kJ/kg K
        rho_L = 1.204 'kg/m3 (20도 1기압상태)
        c_p_Lrho_L = 0.34 'Wh/m3 K
        f_p = 0.4 '= Delta_p_konst / Delta_p_star = 0.4 '(3.2.5-13, 7-1)
        '================================================2010.2.21 수정
        'd_V_mech_m = d_mth
        '================================================2010.2.21 수정
        theta_ABL_wi = 20
        x_ABL_wi = 0.008 '편차가 없는 습도요구 적용
        h_ABL_wi = 42.6 '편차가 없는 습도요구 적용
        theta_ABL_so = 26
        x_ABL_so = 0.008 'kg/kg 편차가 없는 습도요구 적용
        h_ABL_so = 46.7 'kJ/kg 편차가 없는 습도요구 적용
        x_AUL_wi = 0.001
        h_AUL_wi = -9.6
        x_AUL_so = 0.012
        h_AUL_so = 63
        q_st_18_12h_m = 0 '우선 0으로 적용 추후 검토
        theta_e_min = -11.3
        theta_e_max = 31.5
        r_0 = 2500 'kJ/kg
        x_ZUL_wi = 0.00699


        'Dim Dr프로필 As DS.tbl_profileRow   '//아래에서 할당되도록되어있다.
        '//location 은 거의 서울(0번줄)이된다.
        Dim Drow평균온도 As DS.weather_temp_odRow = CType(DSET1.weather_temp_od.Select("pcode='" & CalcO.Pub.기상데이터.code & "' and code='" & Format(i_count_month, "0000") & "'")(0), DS.weather_temp_odRow)
        Dim Drow평균습도 As DS.weather_supdo_odRow = CType(DSET1.weather_supdo_od.Select("pcode='" & CalcO.Pub.기상데이터.code & "' and code='" & Format(i_count_month, "0000") & "'")(0), DS.weather_supdo_odRow)
        Dim Mon As String = "M" & Format(i_count_month, "00")

        Dim sum_kongjo As Decimal = 0
        Dim sum_baeki As Decimal = 0
        Dim ea_kongjo As Decimal = 0
        Dim ea_baeki As Decimal = 0
        For Each Dr공조 As DS.tbl_kongjoRow In DSET1.tbl_kongjo.Select("code <> '0'", "code")
            If Dr공조.급기풍량 <> "" AndAlso Dr공조.급기풍량 <> "0" Then
                sum_kongjo += TOSG(T, Dr공조.급기풍량) * TOSG(T, Dr공조.대수)
            End If
            If Dr공조.배기풍량 <> "" AndAlso Dr공조.배기풍량 <> "0" Then
                sum_baeki += TOSG(T, Dr공조.배기풍량) * TOSG(T, Dr공조.대수)
            End If
        Next



        For Each Dr존 As DS.tbl_zoneRow In DSET1.tbl_zone.Select("code<>'0'", "code")
            Dim Drow분석() As DSR.월별에너지분석Row = CType(DSETR1.월별에너지분석.Select("월='" & Mon & "' and 존='" & Dr존.code & "'"), DSR.월별에너지분석Row())
            'If Worksheets("입력존").Range("공조존2").Offset(0, i_count_zone - 1) = "냉방" Or Worksheets("입력존").Range("공조존2").Offset(0, i_count_zone - 1) = "냉난방" Then
            If Dr존.냉난방공조 = "냉난방" Or Dr존.냉난방공조 = "환기" Then

                '//존의 프로필과 일치하는 프로필검색후 적용
                Dim Dr프로필 As DS.tbl_profile_odRow = CType(DSET1.tbl_profile_od.Select("code='0'")(0), DS.tbl_profile_odRow)
                t_V_mech_m = TOSG(T, Dr프로필.운전시간난방) ' Worksheets("설정조건").Range("사용시작시간1").Offset(5, i_count_profile)
                V_dot_A = TOSG(T, Dr프로필.최소도입외기량) ' Worksheets("설정조건").Range("최소도입외기량1").Offset(0, i_count_profile)
                'i_profile = i_count_profile '//아래 루프종료문은 없어서 추가했다.
                '===================================================================================2010.2.21 추가
                If i_count_month = 0 Then
                    d_V_mech_m = 0
                Else
                    d_V_mech_m = CInt(Dr프로필("day" & Format(i_count_month, "00")))
                End If
                '===================================================================================2010.2.21 추가
                Q_V_E_ZUL_m = 0
                Q_V_E_ABL_m = 0

                For Each Dr공조 As DS.tbl_kongjoRow In DSET1.tbl_kongjo.Select("code <> '0'", "code")
                    'If Dr존.냉난방공조처리시스템 <> "" Then ' Worksheets("입력존").Range("입력난방공급기기1").Offset(2, i_count_zone - 1) <> "" Then
                    'If Worksheets("입력존").Range("입력난방공급기기1").Offset(2, i_count_zone - 1) = Worksheets("공조처리시스템").Range("공조기기1").Offset(0, i_count_AHU - 1) Then
                    'If Dr존.냉난방공조처리시스템 = Dr공조.code Then ' Worksheets("공조처리시스템").Range("공조기기1").Offset(0, i_count_AHU - 1) Then

                    'If i_count_month > 4 Then
                    '    'Console.WriteLine(String.Format("공조 {0}월 존이름={1},급기풍량={2},배기풍량={3}", i_count_month, Dr공조.code, Dr공조.급기풍량, Dr공조.배기풍량))
                    'End If

                    If sum_kongjo = 0 Then
                        ea_kongjo = 0
                    Else
                        ea_kongjo = TOSG(T, Dr공조.급기풍량) * TOSG(T, Dr공조.대수) / sum_kongjo

                    End If
                    If sum_baeki = 0 Then
                        ea_baeki = 0
                    Else
                        ea_baeki = TOSG(T, Dr공조.배기풍량) * TOSG(T, Dr공조.대수) / sum_baeki

                    End If
                    Q_vh_b = 0
                    Q_vc_b = 0
                    Q_vm_b = 0


                    If Dr공조.급기팬동력 <> "" AndAlso Dr공조.급기팬동력 <> "0" AndAlso Dr공조.급기팬동력 <> "0." Then
                        Try
                            eta_ZUL = Math.Round(TOSG(T, Dr공조.급기풍량) * TOSG(T, Dr공조.대수) * (TOSG(T, Dr공조.총압력손실급기팬) / 9.8) / (TOSG(T, Dr공조.급기팬동력) * TOSG(T, Dr공조.대수) * 102 * 3600), 3)

                        Catch ex As Exception
                            eta_ZUL = 0
                        End Try
                    End If


                    If Dr공조.배기팬동력 <> "" AndAlso Dr공조.배기팬동력 <> "0" AndAlso Dr공조.배기팬동력 <> "0." Then
                        Try
                            Dim a As Double = TOSG(T, Dr공조.배기풍량) * TOSG(T, Dr공조.대수) * (TOSG(T, Dr공조.총압력손실배기팬) / 9.8)
                            Dim b As Double = (TOSG(T, Dr공조.배기팬동력) * TOSG(T, Dr공조.대수) * 102 * 3600)


                            eta_ABL = Math.Round(a / b, 3)

                        Catch ex As Exception
                            eta_ABL = 0
                        End Try
                    End If

                    Delta_p_star_ZUL = TOSG(T, Dr공조.총압력손실급기팬) ' Worksheets("공조처리시스템").Range("총압력상승1").Offset(0, i_count_AHU - 1)
                    Delta_p_star_ABL = TOSG(T, Dr공조.총압력손실배기팬) ' Worksheets("공조처리시스템").Range("총압력상승1").Offset(1, i_count_AHU - 1)
                    theta_V_mech_m = TOSG(T, Dr공조.설정치냉방) ' Worksheets("공조처리시스템").Range("공조방식1").Offset(2, i_count_AHU - 1)
                    theta_h_mech_m = TOSG(T, Dr공조.설정치난방) 'Worksheets("공조처리시스템").Range("공조방식1").Offset(1, i_count_AHU - 1)
                    theta_c_mech_m = TOSG(T, Dr공조.설정치냉방) ' Worksheets("공조처리시스템").Range("공조방식1").Offset(2, i_count_AHU - 1)

                    A_B = TOSG(T, Dr존.면적) ' Worksheets("입력존").Range("전용면적1").Offset(0, i_count_zone - 1)

                    theta_AUL = 0
                    x_AUL = 0
                    i_count_start_time = CInt(Dr프로필.운전시작시간.Substring(0, Dr프로필.운전시작시간.IndexOf(":")))  ' Worksheets("설정조건").Range("사용시작시간1").Offset(3, i_profile)
                    i_count_end_time = CInt(Dr프로필.운전종료시간.Substring(0, Dr프로필.운전종료시간.IndexOf(":"))) ' Worksheets("설정조건").Range("사용시작시간1").Offset(4, i_profile)
                    If i_count_start_time - i_count_end_time < 0 Then
                        For i_count_air = 0 To CInt(t_V_mech_m - 1) '자정 전까지 운전 조건
                            '//Dr기상데이터의 2번째 인덱스부터 시간이다.
                            theta_AUL_j = TOSG(T, Drow평균온도("t" & Format(i_count_start_time + i_count_air + 1, "00"))) ' Worksheets("기상데이타").Range("시간별평균온도1").Offset((i_count_month - 1) * 25 + i_count_start_time + i_count_air, location - 1)
                            psi_AUL_j = TOSG(T, Drow평균습도("t" & Format(i_count_start_time + i_count_air + 1, "00"))) / 100 '  Worksheets("기상데이타").Range("시간별평균습도1").Offset((i_count_month - 1) * 25 + i_count_start_time + i_count_air, location - 1) / 100
                            P_D_j_theta_AUL_j = TOSG(T, psi_AUL_j * Math.Exp(23.621 - 4065 / (theta_AUL_j + 236.2506)))
                            x_AUL_j = TOSG(T, 0.5911 / (100000 / P_D_j_theta_AUL_j - 0.95))
                            theta_AUL = theta_AUL + theta_AUL_j
                            x_AUL = x_AUL + x_AUL_j
                        Next
                    Else
                        For i_count_air = 0 To 23 - i_count_start_time  '자정 넘어까지 운전 조건
                            theta_AUL_j = TOSG(T, Drow평균온도("t" & Format(i_count_start_time + i_count_air + 1, "00"))) 'Worksheets("기상데이타").Range("시간별평균온도1").Offset((i_count_month - 1) * 25 + i_count_start_time + i_count_air, location - 1)
                            psi_AUL_j = TOSG(T, Drow평균습도("t" & Format(i_count_start_time + i_count_air + 1, "00"))) / 100 'Worksheets("기상데이타").Range("시간별평균습도1").Offset((i_count_month - 1) * 25 + i_count_start_time + i_count_air, location - 1) / 100
                            P_D_j_theta_AUL_j = TOSG(T, psi_AUL_j * Math.Exp(23.621 - 4065 / (theta_AUL_j + 236.2506)))
                            x_AUL_j = TOSG(T, 0.5911 / (100000 / P_D_j_theta_AUL_j - 0.95))
                            theta_AUL = theta_AUL + theta_AUL_j
                            x_AUL = x_AUL + x_AUL_j
                        Next
                        For i_count_air = 0 To i_count_end_time - 1 '자정 넘어까지 운전 조건
                            theta_AUL_j = TOSG(T, Drow평균온도("t" & Format(i_count_air + 1, "00"))) 'Worksheets("기상데이타").Range("시간별평균온도1").Offset((i_count_month - 1) * 25 + i_count_air, location - 1)
                            psi_AUL_j = TOSG(T, Drow평균습도("t" & Format(i_count_air + 1, "00"))) / 100 'Worksheets("기상데이타").Range("시간별평균습도1").Offset((i_count_month - 1) * 25 + i_count_air, location - 1) / 100
                            P_D_j_theta_AUL_j = TOSG(T, psi_AUL_j * Math.Exp(23.621 - 4065 / (theta_AUL_j + 236.2506)))
                            x_AUL_j = TOSG(T, 0.5911 / (100000 / P_D_j_theta_AUL_j - 0.95))
                            theta_AUL = theta_AUL + theta_AUL_j
                            x_AUL = x_AUL + x_AUL_j
                        Next

                    End If

                    If (t_V_mech_m = 0) Then
                        theta_AUL = 0
                        x_AUL = 0
                    Else
                        theta_AUL = theta_AUL / t_V_mech_m
                        x_AUL = x_AUL / t_V_mech_m
                    End If


                    h_AUL = c_p_L * theta_AUL + x_AUL * (r_0 + c_p_L * theta_AUL)

                    ''V_dot_mech_h_max = Worksheets("0").Range("최대난방부하1").Offset(1, i_count_zone - 1) * 1000 / (c_p_Lrho_L * (theta_h_mech_m - theta_i_h_soll)) '(3.2.4-86)

                    '//현재존과일치하는 데이터수집
                    If (theta_i_c_soll - theta_c_mech_m) <> 0 Then
                        V_dot_mech_max = TOSG(T, Result1o.최대부하.Item(Dr존.code).최대냉방실내부하) * 1000 * ea_kongjo / (c_p_Lrho_L * (theta_i_c_soll - theta_c_mech_m)) '(3.2.4-86)
                    Else
                        V_dot_mech_max = 0
                    End If

                    ' Worksheets("0").Range("최대냉방부하1").Offset(1, i_count_zone - 1)

                    ''If V_dot_mech_h_max < V_dot_mech_c_max Then
                    ''    V_dot_mech_max = V_dot_mech_c_max
                    ''Else
                    ''    V_dot_mech_max = V_dot_mech_h_max
                    ''End If

                    If V_dot_mech_max < V_dot_A * A_B * ea_kongjo Then V_dot_mech_max = V_dot_A * A_B * ea_kongjo



                    Select Case Dr공조.공조방식.Trim ' Worksheets("공조처리시스템").Range("공조방식1").Offset(0, i_count_AHU - 1)
                        Case "정풍량" '정풍량"
                            V_dot_mech_m = TOSG(T, Dr공조.급기풍량) '/////////20191010 V_dot_mech_max 를 공조급기풍량으로 수정

                        Case "변풍량" '변풍량"
                            '//계산결과가들엉잇는 12개월용시트(1~12)에ㅓ 해당값을 찾는 엑셀루틴이다. 이건좀 교환하기가 그러네;;ㅠ
                            '//해당12개시트의 데이터는 DSR월별에너지분석에 존재한다 이곳에는 월/존두개의 기본키가존재하며 해당rOW를 가져와야한다.

                            If Drow분석.GetUpperBound(0) = -1 Then
                                MsgBox("월별에너지분석에 " & i_count_month & "데이터가 없습니다", MsgBoxStyle.Critical, "계산실패")
                                Return
                            End If

                            'Q_c_b = Sheets("" & i_count_month & "").Cells(11, 7 + i_count_zone) - (t_V_mech_m * d_V_mech_m * c_p_Lrho_L * (theta_AUL - theta_c_mech_m) * V_dot_A * A_B) / 1000
                            Q_c_b = TOSG(T, Drow분석(0).냉방요구량공조) * ea_kongjo - (t_V_mech_m * d_V_mech_m * c_p_Lrho_L * (theta_AUL - theta_c_mech_m) * V_dot_A * A_B) * ea_kongjo / 1000

                            If Q_c_b < 0 Then Q_c_b = 0

                            V_dot_mech_m = (t_V_mech_m * d_V_mech_m * c_p_Lrho_L * (theta_AUL - theta_c_mech_m) * V_dot_A * A_B * ea_kongjo) / 1000 + Q_c_b / (t_V_mech_m * d_V_mech_m * c_p_Lrho_L * (theta_i_c - theta_c_mech_m) / 1000) '(3.2.5-4) 공조풍량(변풍량)

                            If i_count_month = 3 Then
                                '//no err
                                ''Console.WriteLine(String.Format("#### t_V_mech_m={0},d_V_mech_m={1},c_p_Lrho_L={2},theta_AUL={3},theta_c_mech_m={4},V_dot_A={5},A_B={6},ea_kongjo={7},Q_c_b={8},t_V_mech_m={9},d_V_mech_m={10},c_p_Lrho_L={11},theta_i_c={12},theta_c_mech_m={13}", _
                                't_V_mech_m, d_V_mech_m, c_p_Lrho_L, theta_AUL, theta_c_mech_m, V_dot_A, A_B, ea_kongjo, Q_c_b, t_V_mech_m, d_V_mech_m, c_p_Lrho_L, theta_i_c, theta_c_mech_m))
                            End If
                            'If V_dot_mech_m < 0 Then
                            'V_dot_mech_m = 0
                            'End If

                            If V_dot_mech_m < V_dot_A * A_B * ea_kongjo Then V_dot_mech_m = V_dot_A * A_B * ea_kongjo

                            If i_count_month = 3 Then
                                'no
                                ''Console.WriteLine(String.Format("#### V_dot_mech_m={0},V_dot_A={1},A_B={2}", _
                                'V_dot_mech_m, V_dot_A, A_B))
                            End If


                    End Select

                    'If V_dot_mech_m = 0 Then
                    '    theta_hc_m = theta_V_mech_m
                    'Else
                    '    theta_hc_m = theta_V_mech_m - Q_V_E_ZUL_m * 1000 / (t_V_mech_m * d_V_mech_m * c_p_Lrho_L * V_dot_mech_m) + 1.4 '(3.2.5-22) Q_V_E_ZUL_m에 1000 을 곱해야하는지 확인요망
                    'End If




                    '==========================================================================================================================================
                    '월별 풍량당 공조에너지 요구량은 추후 적용


                    'If theta_hc_m <= 22 And theta_hc_m > 18 Then
                    'q_h_12h_m = q_h_18_12h_m + g_h_o_m * (theta_hc_m - 18) '(3.2.5-23) 18C<theta_hc_m<=22C
                    'q_c_12h_m = q_c_18_12h_m - g_c_o_m * (theta_hc_m - 18) '(3.2.5-25) 18C<theta_hc_m<=22C
                    'End If
                    'If theta_hc_m <= 18 And theta_hc_m > 14 Then
                    'q_h_12h_m = q_h_18_12h_m + g_h_u_m * (theta_hc_m - 18) '(3.2.5-24) 14C<theta_hc_m<=18C
                    'q_c_12h_m = q_c_18_12h_m - g_c_u_m * (theta_hc_m - 18) '(3.2.5-26) 14C<theta_hc_m<=18C
                    'End If
                    'q_st_12h_m = q_st_18_12h_m '(3.2.5-27)



                    '==========================================================================================================================================
                    '==========================================================================================================================================

                    If V_dot_mech_m = 0 Then
                        u = 1  '//??
                    Else
                        u = (V_dot_mech_m - V_dot_A * A_B * ea_kongjo) / V_dot_mech_m
                    End If


                    If Dr공조.열교환기유형 = "현열교환" OrElse Dr공조.열교환기유형 = "전열교환" Then ' Worksheets("공조처리시스템").Range("열교환기1").Offset(0, i_count_AHU - 1) = "현열교환" Or Worksheets("공조처리시스템").Range("열교환기1").Offset(0, i_count_AHU - 1) = "전열교환" Then
                        Phi_h = TOSG(Dr공조.열회수율) / 100 'Worksheets("공조처리시스템").Range("열교환기1").Offset(1, i_count_AHU - 1) '=====================2010.04.14 수정
                        Phi_c = TOSG(Dr공조.열회수율_냉방) / 100 'Worksheets("공조처리시스템").Range("열교환기1").Offset(2, i_count_AHU - 1) '=====================2010.04.14 수정
                    Else
                        Phi_h = 0 '==============================2010.04.14 수정
                        Phi_c = 0 '==============================2010.04.14 수정
                    End If




                    If TOSG(T, Drow분석(0).난방요구량공조) > 0 AndAlso ea_kongjo > 0 Then 'Sheets("" & i_count_month & "").Cells(8, 7 + i_count_zone) > 0 Then


                        'Q_h_b = Sheets("" & i_count_month & "").Cells(8, 7 + i_count_zone) - (theta_i_h_soll - theta_AUL) * c_p_L * rho_L * d_V_mech_m * t_V_mech_m * V_dot_A * A_B / 3600
                        Q_h_b = TOSG(T, Drow분석(0).난방요구량공조) * ea_kongjo - (theta_i_h_soll - theta_AUL) * c_p_L * rho_L * d_V_mech_m * t_V_mech_m * V_dot_A * A_B * ea_kongjo / 3600
                        Select Case Dr공조.공조방식.Trim ' Worksheets("공조처리시스템").Range("공조방식1").Offset(0, i_count_AHU - 1)
                            Case "정풍량"
                                theta_ZUL_wi = 1000 * Q_h_b / (V_dot_mech_m * c_p_Lrho_L * t_V_mech_m * d_V_mech_m) + theta_i_h_soll 'd_Nutz=d_V_mech_m 으로 적용

                            Case "변풍량"
                                If V_dot_mech_m > V_dot_A * A_B * ea_kongjo Then
                                    theta_ZUL_wi = theta_h_mech_m
                                Else
                                    If V_dot_mech_m = 0 Then
                                        theta_ZUL_wi = theta_i_h_soll
                                    Else
                                        theta_ZUL_wi = 1000 * Q_h_b / (V_dot_mech_m * c_p_Lrho_L * t_V_mech_m * d_V_mech_m) + theta_i_h_soll
                                    End If

                                End If
                        End Select

                        m_dot_1_L = V_dot_mech_m * rho_L

                        '외기모드 경우와 에너지
                        'theta_ZUL_wi<theta_ABL_wi+(1-u)*(1-Phi)*(theta_AUL-theta_ABL_wi)
                        'Q_VE_B = 0
                        'Q_VE_D = 0

                        '//h_B = c_p_L * theta_ZUL_wi + x_ZUL_wi * (r_0 + c_p_L * theta_ZUL_wi)

                        '//가습기유형은 = 가습불가로 한다 170827
                        Select Case Dr공조.열교환기유형.Trim ' Worksheets("공조처리시스템").Range("열교환기1").Offset(0, i_count_AHU - 1)
                            Case "현열교환" '현열교환"
                                Q_VE_ZU = d_V_mech_m * (m_dot_1_L * t_V_mech_m * c_p_L * (theta_ZUL_wi - u * theta_ABL_wi - (1 - u) * (theta_AUL + Phi_h * (theta_ABL_wi - theta_AUL))) / 3600) '==============2010.04.14 수정
                            Case "전열교환" '전열교환"
                                Q_VE_ZU = d_V_mech_m * (m_dot_1_L * t_V_mech_m * c_p_L * (theta_ZUL_wi - u * theta_ABL_wi - (1 - u) * (theta_AUL + Phi_h * (h_ABL_wi - h_AUL) / c_p_L)) / 3600) '==============2010.04.14 수정
                            Case Else
                                '"열회수불가" '열회수불가"
                                Q_VE_ZU = d_V_mech_m * (m_dot_1_L * t_V_mech_m * c_p_L * (theta_ZUL_wi - u * theta_ABL_wi - (1 - u) * theta_AUL) / 3600)
                        End Select
                        Q_vh_b = Q_VE_ZU
                        Q_vm_b = 0


                        '//Q_VE_B = d_V_mech_m * (m_dot_1_L * t_V_mech_m * (h_B - u * h_ABL_wi - (1 - u) * h_AUL) / 3600)
                        'Q_vh_b = Q_VE_B


                    Else
                        Q_vh_b = 0
                        Q_vm_b = 0

                    End If


                    If i_count_month = 3 Then
                        'Console.WriteLine(String.Format("----------- Drow분석(0).냉방요구량공조={0},ea_kongjo={1}",                         Drow분석(0).냉방요구량공조, ea_kongjo))
                    End If

                    '------------------------------------------------------------------------------------------------------------------------------------------
                    If TOSG(T, Drow분석(0).냉방요구량공조) > 0 AndAlso ea_kongjo > 0 Then ' Sheets("" & i_count_month & "").Cells(11, 7 + i_count_zone) > 0 Then

                        Q_c_b = TOSG(T, Drow분석(0).냉방요구량공조) 'Sheets("" & i_count_month & "").Cells(11, 7 + i_count_zone)
                        Select Case Dr공조.공조방식.Trim 'Worksheets("공조처리시스템").Range("공조방식1").Offset(0, i_count_AHU - 1)
                            Case "정풍량" '정풍량"
                                If theta_AUL - theta_i_c_soll > 0 Then
                                    Q_c_b = Q_c_b - (theta_AUL - theta_i_c_soll) * c_p_L * rho_L * d_V_mech_m * t_V_mech_m * V_dot_A * A_B / 3600
                                    Q_c_b = Q_c_b * ea_kongjo
                                Else
                                    Q_c_b = Q_c_b - (theta_i_c_soll - theta_AUL) * c_p_L * rho_L * d_V_mech_m * t_V_mech_m * V_dot_A * A_B / 3600
                                    Q_c_b = Q_c_b * ea_kongjo
                                End If
                                If Q_c_b < 0 Then Q_c_b = 0
                                If (V_dot_mech_m * c_p_Lrho_L * t_V_mech_m * d_V_mech_m) = 0 Then
                                    theta_ZUL_so = 0
                                Else
                                    theta_ZUL_so = theta_i_c - 1000 * Q_c_b * ea_kongjo / (V_dot_mech_m * c_p_Lrho_L * t_V_mech_m * d_V_mech_m) 'd_Nutz=d_V_mech_m 으로 적용
                                End If


                            Case "변풍량" '변풍량"
                                If V_dot_mech_m > V_dot_A * A_B * ea_kongjo OrElse V_dot_mech_m = 0 Then
                                    theta_ZUL_so = theta_c_mech_m
                                Else
                                    theta_ZUL_so = theta_i_c - 1000 * Q_c_b * ea_kongjo / (V_dot_mech_m * c_p_Lrho_L * t_V_mech_m * d_V_mech_m)
                                End If
                                Q_c_b = Q_c_b * ea_kongjo
                        End Select

                        p_S_theta_ZUL_so = TOSG(T, Math.Exp(23.621 - 4065 / (theta_ZUL_so + 236.2506)))
                        p_95_theta_ZUL_so = TOSG(T, 0.95 * p_S_theta_ZUL_so)
                        x_95_ZUL_so = TOSG(T, 0.5911 / (100000 / p_95_theta_ZUL_so - 0.95))
                        m_dot_1_L = V_dot_mech_m * rho_L
                        h_95_ZUL_so = c_p_L * theta_ZUL_so + x_95_ZUL_so * (r_0 + c_p_L * theta_ZUL_so)


                        'If theta_ZUL_so > theta_AUL Then

                        '냉방의 경우 가열에너지
                        'Select Case Worksheets("공조처리시스템").Range("열교환기1").Offset(0, i_count_AHU - 1)
                        'Case "열회수불가"
                        'If theta_ZUL_so > theta_ABL_so + (1 - u) * (theta_AUL - theta_ABL_so) Then
                        'Q_VE_ZU = d_V_mech_m * (m_dot_1_L * t_V_mech_m * c_p_L * (theta_ZUL_so - u * theta_ABL_so - (1 - u) * theta_AUL) / 3600)
                        'Q_vh_b = Q_vh_b + Q_VE_ZU
                        'Else
                        'If Worksheets("공조처리시스템").Range("공조방식1").Offset(6, i_count_AHU - 1) = "무" Then
                        'i_count_air = 1
                        'End If
                        'End If
                        'Case "현열교환"
                        'If theta_ZUL_so > theta_ABL_so + (1 - u) * (1 - Phi) * (theta_AUL - theta_ABL_so) Then
                        'Q_VE_ZU = d_V_mech_m * (m_dot_1_L * t_V_mech_m * c_p_L * (theta_ZUL_so - u * theta_ABL_so - (1 - u) * (theta_AUL + Phi * (theta_ABL_so - theta_AUL))) / 3600)
                        'Q_vh_b = Q_vh_b + Q_VE_ZU
                        'Else
                        'If Worksheets("공조처리시스템").Range("공조방식1").Offset(6, i_count_AHU - 1) = "무" Then
                        'i_count_air = 1
                        'End If
                        'End If
                        'Case "전열교환"
                        'If theta_ZUL_so > theta_ABL_so + (1 - u) * (1 - Phi) * (h_AUL - h_ABL_so) / c_p_L Then
                        'Q_VE_ZU = d_V_mech_m * (m_dot_1_L * t_V_mech_m * c_p_L * (theta_ZUL_so - u * theta_ABL_so - (1 - u) * (theta_AUL + Phi * (h_ABL_so - h_AUL) / c_p_L)) / 3600)
                        'Q_vh_b = Q_vh_b + Q_VE_ZU
                        'Else
                        'If Worksheets("공조처리시스템").Range("공조방식1").Offset(6, i_count_AHU - 1) = "무" Then
                        'i_count_air = 1
                        'End If
                        'End If
                        'End Select
                        'End If

                        If i_count_month = 3 Then
                            'Console.WriteLine(String.Format("***** theta_ZUL_so={0},theta_AUL={1}",                             theta_ZUL_so, theta_AUL))
                        End If

                        If theta_ZUL_so > theta_AUL Then ' Worksheets("공조처리시스템").Range("공조방식1").Offset(6, i_count_AHU - 1) = "유" Then
                            Q_vc_b = 0
                            V_dot_mech_m = (t_V_mech_m * d_V_mech_m * c_p_Lrho_L * (theta_c_mech_m - theta_AUL) * V_dot_A * A_B) / 1000 + Q_c_b / (t_V_mech_m * d_V_mech_m * c_p_Lrho_L * (theta_i_c - theta_AUL) / 1000)
                            If V_dot_mech_m < V_dot_A * A_B * ea_kongjo Then V_dot_mech_m = V_dot_A * A_B * ea_kongjo '===================2011.07.11 추가 ea_kongjo를 추가함


                            If i_count_month = 3 Then
                                'Console.WriteLine(String.Format("#### V_dot_mech_m={0},d_V_mech_m={1},c_p_Lrho_L={2}",                                 V_dot_mech_m, d_V_mech_m, c_p_Lrho_L))
                            End If



                        Else
                            If 0.5911 / (100000 / p_95_theta_ZUL_so - 0.95) > (1 - u) * x_AUL + u * x_ABL_so Then
                                Q_vc_b = -m_dot_1_L * d_V_mech_m * t_V_mech_m * c_p_L * (theta_ZUL_so - u * theta_ABL_so - (1 - u) * theta_AUL) / 3600
                            Else
                                Q_vc_b = -m_dot_1_L * d_V_mech_m * t_V_mech_m * (h_95_ZUL_so - u * h_ABL_so - (1 - u) * h_AUL) / 3600
                            End If

                        End If
                    Else
                        Q_vc_b = 0

                    End If
                    '==========================================================================================================================================
                    '==========================================================================================================================================

                    Select Case Dr공조.공조방식.Trim ' Worksheets("공조처리시스템").Range("공조방식1").Offset(0, i_count_AHU - 1)
                        Case "정풍량" '정풍량"
                            If eta_ZUL <> 0 Then
                                P_V_ZUL_m = V_dot_mech_m * Delta_p_star_ZUL / eta_ZUL / 3600000  ' V_dot_ZUL = V_dot_mech_m (3.2.5-7) 정풍량 (3600은 Pa을 W환산하면서 h를 s로 환산)
                            Else
                                P_V_ZUL_m = 0
                            End If

                            If eta_ABL <> 0 Then
                                P_V_ABL_m = TOSG(T, Dr공조.배기풍량) * Delta_p_star_ABL / eta_ABL / 3600000  ''/////////20191010 V_dot_mech_max 를 공조배기풍량으로 수정
                            Else
                                P_V_ABL_m = 0
                            End If

                            Q_V_E_ZUL_m += P_V_ZUL_m * t_V_mech_m * d_V_mech_m '(3.2.5-10) 정풍량
                            Q_V_E_ABL_m += P_V_ABL_m * t_V_mech_m * d_V_mech_m '(3.2.5-10) 정풍량

                            If i_count_month = 3 Then
                                'Console.WriteLine(String.Format("[{0}] #2 Q_V_E_ZUL_m={1},Q_V_E_ABL_m={2}", i_count_month, Q_V_E_ZUL_m, Q_V_E_ABL_m))
                            End If

                        Case "변풍량" '변풍량"

                            Sigma_V_dot = t_V_mech_m * d_V_mech_m * V_dot_mech_m + 1000 * Q_c_b / (c_p_Lrho_L * (theta_i_c - theta_V_mech_m)) '(3.2.5-5) 월간 공조풍량 합(변풍량)
                            ' 수식 변경 Sigma_V_dot_3 = t_V_mech_m * d_V_mech_m * (V_dot_mech_m ^ 3) + Q_c_b / (c_p_L * rho_L * (theta_i_c - theta_V_mech_m))
                            Sigma_V_dot_3 = TOSG(T, Sigma_V_dot * (0.8 * V_dot_mech_m + 0.2 * V_dot_mech_max) ^ 2)

                            If V_dot_mech_m = 0 Then
                                P_V_ZUL_m = 0 'CSng(V_dot_mech_m * Delta_p_star_ZUL * f_p / eta_ZUL / 3600 + (V_dot_mech_m ^ 3 * Delta_p_star_ZUL * (1 - f_p)) / (eta_ZUL * V_dot_mech_m ^ 2) / 3600) '(3.2.5-11)  변풍량 시간, 용도로 추후검토
                                P_V_ABL_m = 0 'CSng(V_dot_mech_m * Delta_p_star_ABL * f_p / eta_ABL / 3600 + (V_dot_mech_m ^ 3 * Delta_p_star_ABL * (1 - f_p)) / (eta_ABL * V_dot_mech_m ^ 2) / 3600) '(3.2.5-11)  변풍량 시간, 용도로 추후검
                                Q_V_E_ZUL_m = 0 'P_V_ZUL_m * t_V_mech_m * d_V_mech_m / 1000 'kWh (3.2.5-10) 변풍량 냉방부하
                                Q_V_E_ABL_m = 0 'P_V_ABL_m * t_V_mech_m * d_V_mech_m / 1000 'kWh (3.2.5-10) 변풍량 냉방부하
                            Else

                                '==========================변풍량에서도 효율이 없을 경우 동력이 0인 것으로 평가 2010.10.10
                                If eta_ZUL <> 0 Then
                                    P_V_ZUL_m = TOSG(T, V_dot_mech_m * Delta_p_star_ZUL * f_p / eta_ZUL / 3600 + (V_dot_mech_m ^ 3 * Delta_p_star_ZUL * (1 - f_p)) / (eta_ZUL * V_dot_mech_max ^ 2) / 3600) '(3.2.5-11)  변풍량 시간, 용도로 추후검토
                                Else
                                    P_V_ZUL_m = 0
                                End If
                                If eta_ABL <> 0 Then
                                    P_V_ABL_m = TOSG(T, V_dot_mech_m * Delta_p_star_ABL * f_p / eta_ABL / 3600 + (V_dot_mech_m ^ 3 * Delta_p_star_ABL * (1 - f_p)) / (eta_ABL * V_dot_mech_max ^ 2) / 3600) '(3.2.5-11)  변풍량 시간, 용도로 추후검
                                Else
                                    P_V_ABL_m = 0
                                End If
                                '============================================================2010.10.10

                                Q_V_E_ZUL_m += P_V_ZUL_m * t_V_mech_m * d_V_mech_m / 1000 'kWh (3.2.5-10) 변풍량 냉방부하
                                Q_V_E_ABL_m += P_V_ABL_m * t_V_mech_m * d_V_mech_m / 1000 'kWh (3.2.5-10) 변풍량 냉방부하

                                If i_count_month = 3 Then
                                    'Console.WriteLine(String.Format("[{0}] Q_V_E_ZUL_m={1},Q_V_E_ABL_m={2}", i_count_month, Q_V_E_ZUL_m, Q_V_E_ABL_m))

                                    'Console.WriteLine(String.Format(">>> P_V_ZUL_m={0},t_V_mech_m={1},d_V_mech_m={2}", P_V_ZUL_m, t_V_mech_m, d_V_mech_m))
                                    'Console.WriteLine(String.Format(">>> V_dot_mech_m={0},Delta_p_star_ZUL={1},f_p={2},eta_ZUL={3},V_dot_mech_m={4},Delta_p_star_ZUL={5},eta_ZUL={6},V_dot_mech_max={7}",                                                                     V_dot_mech_m, Delta_p_star_ZUL, f_p, eta_ZUL, V_dot_mech_m, Delta_p_star_ZUL, eta_ZUL, V_dot_mech_max))

                                End If

                            End If

                        Case "환기용"
                            If eta_ZUL <> 0 Then
                                P_V_ZUL_m = V_dot_A * A_B * ea_kongjo * Delta_p_star_ZUL / eta_ZUL / 3600000  ' V_dot_ZUL = V_dot_mech_m (3.2.5-7) 정풍량 (3600은 Pa을 W환산하면서 h를 s로 환산)
                            Else
                                P_V_ZUL_m = 0
                            End If

                            If eta_ABL <> 0 Then
                                P_V_ABL_m = V_dot_A * A_B * ea_baeki * Delta_p_star_ABL / eta_ABL / 3600000
                            Else
                                P_V_ABL_m = 0
                            End If

                            Q_V_E_ZUL_m += P_V_ZUL_m * t_V_mech_m * d_V_mech_m '(3.2.5-10) 정풍량
                            Q_V_E_ABL_m += P_V_ABL_m * t_V_mech_m * d_V_mech_m '(3.2.5-10) 정풍량
                            If i_count_month = 3 Then
                                'Console.WriteLine(String.Format("[{0}] #3 Q_V_E_ZUL_m={1},Q_V_E_ABL_m={2}", i_count_month, Q_V_E_ZUL_m, Q_V_E_ABL_m))
                            End If



                    End Select





                    '------------------------------------------------------------------------------------------------------------------------------------------
                    ' 우선 외기온도에 대한 공조에너지 요구량 산정 필요 ????

                    'q_st_12h_m = q_st_18_12h_m '(3.2.5-27)

                    'If theta_e < theta_hc_m Then
                    'Select Case Worksheets("공조처리시스템").Range("열교환기1").Offset(0, i_count_AHU - 1)
                    'Case "열회수불가"
                    'Delta_h_WRG = 0 '(3.2.5-54) 열 회수기 없음
                    'Case "현열교환"
                    'Delta_h_WRG = Worksheets("공조처리시스템").Range("열교환기1").Offset(1, i_count_AHU - 1) / 100 * c_p_L * (theta_ABL_wi - theta_e) '(3.2.5-55) 순수 현열 회수기
                    'Case "전열교환"
                    'Delta_h_WRG = Worksheets("공조처리시스템").Range("열교환기1").Offset(1, i_count_AHU - 1) / 100 * c_p_L * (theta_ABL_wi - theta_e) '(3.2.5-56) 현열 및 습기 회수기 우선 현열만 고려
                    'End Select
                    'q_h_12h_m = rho_L * (c_p_L * (theta_hc_m - theta_e) - Delta_h_WRG) * 12 * d_mth * V_dot_A * A_B + rho_L * c_p_L * (theta_h_mech_m - theta_i_h_soll) * 12 * d_mth * (V_dot_mech_m - V_dot_A * A_B) 'theta_h_mech_m 과 theta_hc_m 중 선택 검토

                    'End If

                    'If theta_e > theta_hc_m Then
                    'Select Case Worksheets("공조처리시스템").Range("열교환기1").Offset(0, i_count_AHU - 1)
                    'Case "열회수불가"
                    'Delta_h_WRG = 0 '(3.2.5-54) 열 회수기 없음
                    'Case "현열교환"
                    'If theta_e > theta_ABL_so Then
                    'Delta_h_WRG = Worksheets("공조처리시스템").Range("열교환기1").Offset(1, i_count_AHU - 1) / 100 * c_p_L * (theta_e - theta_ABL_so) '(3.2.5-55) 순수 현열 회수기
                    'Else
                    'Delta_h_WRG = Worksheets("공조처리시스템").Range("열교환기1").Offset(1, i_count_AHU - 1) / 100 * c_p_L * (theta_ABL_so - theta_e) '(3.2.5-55) 순수 현열 회수기
                    'End If
                    'Case "전열교환"
                    'If theta_e > theta_ABL_so Then
                    'Delta_h_WRG = Worksheets("공조처리시스템").Range("열교환기1").Offset(1, i_count_AHU - 1) / 100 * c_p_L * (theta_e - theta_ABL_so) '(3.2.5-55) 순수 현열 회수기 우선 현열만 고려
                    'Else
                    'Delta_h_WRG = Worksheets("공조처리시스템").Range("열교환기1").Offset(1, i_count_AHU - 1) / 100 * c_p_L * (theta_ABL_so - theta_e) '(3.2.5-55) 순수 현열 회수기 우선 현열만 고려
                    'End If

                    'End Select

                    'q_c_12h_m = rho_L * (c_p_L * (theta_e - theta_hc_m) - Delta_h_WRG) * 12 * d_mth * V_dot_A * A_B + rho_L * c_p_L * (theta_i_c_soll - theta_c_mech_m) * 12 * d_mth * (V_dot_mech_m - V_dot_A * A_B) 'theta_c_mech_m 과 theta_hc_m 중 선택 검토

                    'End If


                    'f_h_H = 1 + 6.333 * 10 ^ (-3) * (t_V_mech_m - 12) - 2.689 * 10 ^ (-4) * (t_V_mech_m - 12) ^ 2 + 6.94 * 10 ^ (-6) * (t_V_mech_m - 12) ^ 3 '(3.2.5-31)
                    'f_h_C = 1 - 5.583 * 10 ^ (-3) * (t_V_mech_m - 12) + 2.153 * 10 ^ (-4) * (t_V_mech_m - 12) ^ 2 - 6.597 * 10 ^ (-6) * (t_V_mech_m - 12) ^ 3 '(3.2.5-32) 편차가 없는 습도요구
                    'f_h_C = 1 - 1.552 * 10 ^ (-3) * (t_V_mech - 12) - 8.073 * 10 ^ (-4) * (t_V_mech_m - 12) ^ 2 - 1.302 * 10 ^ (-6) * (t_V_mech_m - 12) ^ 3 '(3.2.5-32) 편차가 있는 습도요구 추후 검토
                    'f_h_st = 1

                    'q_h_m = q_h_12h_m * t_V_mech_m / 12 * f_h_H * d_V_mech_m / d_mth '(3-28)
                    'q_c_m = q_c_12h_m * t_V_mech_m / 12 * f_h_C * d_V_mech_m / d_mth '(3-29)
                    'q_st_m = q_st_12h_m * t_V_mech_m / 12 * f_h_st * d_V_mech_m / d_mth '(3-30)

                    'Q_vh_b = q_h_m * V_dot_mech_m '(3-36) =Q_vi_b (7-2,7-8,7-14)
                    'Q_vc_b = q_c_m * V_dot_mech_m '(3-36) =Q_vi_b (7-2,7-8,7-14)
                    'Q_vm_b = q_st_m * V_dot_mech_m '(3-36) =Q_vi_b (7-2,7-8,7-14)

                    'Q_vh_b = q_h_m / 1000 ' 우선 공조풍량을 미리 포함시킴 추후 검토
                    'Q_vc_b = q_c_m / 1000 ' 우선 공조풍량을 미리 포함시킴 추후 검토
                    'Q_vm_b = q_st_m * V_dot_mech_m / 1000 '(3-36) =Q_vi_b (7-2,7-8,7-14)

                    '==========================================================================================================================================
                    Drow분석(0).공조풍량 = V_dot_mech_m
                    'Sheets("" & i_count_month & "").Cells(17, 7 + i_count_zone) = V_dot_mech_m
                    If Q_vh_b < 0 Then
                        Q_vh_b = 0 '음수 여부 추후 검토
                    End If
                    Drow분석(0).공조요구량난방 = Q_vh_b
                    'Sheets("" & i_count_month & "").Cells(19, 7 + i_count_zone) = Q_vh_b

                    If Q_vc_b < 0 Then
                        Q_vc_b = 0 '냉방공조에너지요구량이 -인 것은 난방에서 처리되는 것으로 설정
                    End If
                    Drow분석(0).공조요구량냉방 = Q_vc_b
                    'Sheets("" & i_count_month & "").Cells(21, 7 + i_count_zone) = Q_vc_b

                    If Q_vm_b < 0 Then
                        Q_vm_b = 0 '음수 여부 추후 검토
                    End If
                    Drow분석(0).공조요구량가습 = Q_vm_b '  Sheets("" & i_count_month & "").Cells(23, 7 + i_count_zone) = Q_vm_b
                    Drow분석(0).환기요구량 = Q_V_E_ZUL_m + Q_V_E_ABL_m ' Sheets("" & i_count_month & "").Cells(25, 7 + i_count_zone) = Q_V_E_ZUL_m + Q_V_E_ABL_m

                    If i_count_month = 3 Then
                        ''Console.WriteLine(String.Format("문제의 {0}월", i_count_month))
                        'Console.WriteLine(String.Format("환기요구량 {0}, {1}, {2}", i_count_month, Q_V_E_ZUL_m, Q_V_E_ABL_m))
                    End If
                    '==========================================================================================================================================
                    'End If
                    'End If
                Next

            Else
                Drow분석(0).공조풍량 = 0 '  Sheets("" & i_count_month & "").Cells(17, 7 + i_count_zone) = 0
                Drow분석(0).공조요구량난방 = 0 '     Sheets("" & i_count_month & "").Cells(19, 7 + i_count_zone) = 0
                Drow분석(0).공조요구량냉방 = 0 'Sheets("" & i_count_month & "").Cells(21, 7 + i_count_zone) = 0
                Drow분석(0).공조요구량가습 = 0 ' Sheets("" & i_count_month & "").Cells(23, 7 + i_count_zone) = 0
                Drow분석(0).환기요구량 = 0 'Sheets("" & i_count_month & "").Cells(25, 7 + i_count_zone) = 0



                ''===========================================================2017.12.25 공조부분 추가

                '==========================================================================2010.02.04 추가부분 시작
                If Dr존.냉난방공조 = "환기" OrElse (Dr존.냉난방공조 = "난방" AndAlso Dr존.외기부하처리여부 = "예") Then   '//환기
                    Dim DR프로필() As DS.tbl_profile_odRow = CType(DSET1.tbl_profile_od.Select("code='0'"), DS.tbl_profile_odRow())
                    If DR프로필.GetUpperBound(0) = 0 Then
                        t_V_mech_m = TOSG(DR프로필(0).운전시간난방) ' Worksheets("설정조건").Range("사용시작시간1").Offset(5, i_count_profile)
                        V_dot_A = TOSG(DR프로필(0).최소도입외기량) 'Worksheets("설정조건").Range("최소도입외기량1").Offset(0, i_count_profile)
                        A_B = TOSG(Dr존.면적) * TOSG(Dr존.입력존의수) ' Worksheets("입력존").Range("전용면적1").Offset(0, i_count_zone - 1)
                        '===================================================================================2010.2.25 추가
                        'd_V_mech_m = Worksheets("설정조건").Range("월간사용일수1").Offset(i_count_month, i_count_profile)
                        Select Case i_count_month
                            Case 0 : d_V_mech_m = 0
                            Case 1 : d_V_mech_m = DR프로필(0).day01
                            Case 2 : d_V_mech_m = DR프로필(0).day02
                            Case 3 : d_V_mech_m = DR프로필(0).day03
                            Case 4 : d_V_mech_m = DR프로필(0).day04
                            Case 5 : d_V_mech_m = DR프로필(0).day05
                            Case 6 : d_V_mech_m = DR프로필(0).day06
                            Case 7 : d_V_mech_m = DR프로필(0).day07
                            Case 8 : d_V_mech_m = DR프로필(0).day08
                            Case 9 : d_V_mech_m = DR프로필(0).day09
                            Case 10 : d_V_mech_m = DR프로필(0).day10
                            Case 11 : d_V_mech_m = DR프로필(0).day11
                            Case 12 : d_V_mech_m = DR프로필(0).day12
                        End Select
                        '===================================================================================2010.2.25 추가

                    End If

                    Dim DR공조() As DS.tbl_kongjoRow = CType(DSET1.tbl_kongjo.Select("code='" & Dr존.냉난방공조처리시스템 & "' and code <> '0'"), DS.tbl_kongjoRow())
                    If DR공조.GetUpperBound(0) = 0 Then

                        '------------------------------------------------------------------------------------------------------------------------------------------------------------------------------2010.05.26 추가
                        If DR공조(0).열교환기유형.Trim = "현열교환" OrElse DR공조(0).열교환기유형.Trim = "전열교환" Then
                            Phi_h = TOSG(DR공조(0).열회수율) / 100 'Worksheets("공조처리시스템").Range("열교환기1").Offset(1, i_count_AHU - 1)
                            Phi_c = TOSG(DR공조(0).열회수율_냉방) / 100 'Worksheets("공조처리시스템").Range("열교환기1").Offset(2, i_count_AHU - 1)
                        Else
                            Phi_h = 0
                            Phi_c = 0
                        End If
                        '// 여기 i_count_month 에 0 이 오지는 않나요? 예.. 1 부터 시작해요
                        '// If CSng(Drow분석(0).난방요구량공조) > 0 Then 'Sheets("" & i_count_month & "").Cells(8, 7 + i_count_zone) > 0 Then

                        If TOSG(Drow분석(0).난방요구량공조) > 0 Then
                            Drow분석(0).난방요구량공조 = (1 - Phi_h) * TOSG(Drow분석(0).난방요구량공조)
                        End If

                        If TOSG(Drow분석(0).냉방요구량공조) > 0 Then
                            Drow분석(0).냉방요구량공조 = (1 - Phi_c) * TOSG(Drow분석(0).냉방요구량공조)
                        End If

                        'If Sheets("" & i_count_month & "").Cells(8, 7 + i_count_zone) > 0 Then
                        '    Sheets("" & i_count_month & "").Cells(8, 7 + i_count_zone) = (1 - Phi_h) * Sheets("" & i_count_month & "").Cells(8, 7 + i_count_zone)
                        'End If

                        'If Sheets("" & i_count_month & "").Cells(11, 7 + i_count_zone) > 0 Then
                        '    Sheets("" & i_count_month & "").Cells(11, 7 + i_count_zone) = (1 - Phi_c) * Sheets("" & i_count_month & "").Cells(11, 7 + i_count_zone)
                        'End If

                        '------------------------------------------------------------------------------------------------------------------------------------------------------------------------------2010.05.26 추가

                        eta_ZUL = TOSG(DR공조(0).총효율급기팬) ' Worksheets("공조처리시스템").Range("총압력상승1").Offset(2, i_count_AHU - 1)
                        eta_ABL = TOSG(DR공조(0).총효율배기팬) ' Worksheets("공조처리시스템").Range("총압력상승1").Offset(3, i_count_AHU - 1)
                        Delta_p_star_ZUL = TOSG(DR공조(0).총압력손실급기팬) ' Worksheets("공조처리시스템").Range("총압력상승1").Offset(0, i_count_AHU - 1)
                        Delta_p_star_ABL = TOSG(DR공조(0).총압력손실배기팬) ' Worksheets("공조처리시스템").Range("총압력상승1").Offset(1, i_count_AHU - 1)

                        If eta_ZUL <> 0 Then
                            P_V_ZUL_m = V_dot_A * A_B * Delta_p_star_ZUL / eta_ZUL / 3600000
                        Else
                            P_V_ZUL_m = 0
                        End If

                        If eta_ABL <> 0 Then
                            P_V_ABL_m = V_dot_A * A_B * Delta_p_star_ABL / eta_ABL / 3600000
                        Else
                            P_V_ABL_m = 0
                        End If
                        Q_V_E_ZUL_m = P_V_ZUL_m * t_V_mech_m * d_V_mech_m
                        Q_V_E_ABL_m = P_V_ABL_m * t_V_mech_m * d_V_mech_m


                        Result1o.E분석(i_count_month).환기에너지요구량(Dr존.code) = Q_V_E_ZUL_m + Q_V_E_ABL_m
                        ''Console.WriteLine(String.Format("환기요구량2={0}", Q_V_E_ZUL_m + Q_V_E_ABL_m))
                        'Sheets("" & i_count_month & "").Cells(25, 7 + i_count_zone) = Q_V_E_ZUL_m + Q_V_E_ABL_m
                    End If
                Else
                    Result1o.E분석(i_count_month).환기에너지요구량(Dr존.code) = 0
                End If
                '==========================================================================2010.02.04 추가부분 끝





                ''=======================================2017.12.25 공조부분 추가 끝








            End If

        Next


    End Sub
End Class
