# *********************************************************************
# *  Copyright (c) 2008-2015, Natural Resources Canada
# *  All rights reserved.
# *
# *  This library is free software; you can redistribute it and/or
# *  modify it under the terms of the GNU Lesser General Public
# *  License as published by the Free Software Foundation; either
# *  version 2.1 of the License, or (at your option) any later version.
# *
# *  This library is distributed in the hope that it will be useful,
# *  but WITHOUT ANY WARRANTY; without even the implied warranty of
# *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# *  Lesser General Public License for more details.
# *
# *  You should have received a copy of the GNU Lesser General Public
# *  License along with this library; if not, write to the Free Software
# *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
# **********************************************************************/


require "#{File.dirname(__FILE__)}/btap"


module BTAP
  #Contains data and methods for compliance and archetype work.
  module Compliance
    # Contains NECB relelvant methods and data.
    module NECB2011
      # NECB data tables / arrays.
      module Data
        #Envelope Conductance values for each climat zone / HDD limits.
        module Conductances
          #array of conductances(metric) per climate zone.
          Wall        = [0.315,0.278,0.247,0.210,0.210,0.183]
          Roof        = [0.227,0.183,0.183,0.162,0.162,0.142]
          Floor       = [0.227,0.183,0.183,0.162,0.162,0.142]
          Window      = [2.400,2.200,2.200,2.200,2.200,1.600]
          Door        = [2.400,2.200,2.200,2.200,2.200,1.600]
          GroundWall  = [0.568,0.379,0.284,0.284,0.284,0.210]
          GroundRoof  = [0.568,0.379,0.284,0.284,0.284,0.210]
          GroundFloor = [0.757,0.757,0.757,0.757,0.757,0.379]
        end


        #NECB Weekday, Sat,Sun Schedules.
        Schedules = [
          ["NECB","A","Occ","Wkd","FRACTION",0,0,0,0,0,0,0,0.1,0.7,0.9,0.9,0.9,0.5,0.5,0.9,0.9,0.9,0.7,0.3,0.1,0.1,0.1,0.1,0],
          ["NECB","A","Occ","Sat","FRACTION",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
          ["NECB","A","Occ","SunHol","FRACTION",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
          ["NECB","A","Ltg","Wkd","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.3,0.8,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.8,0.5,0.3,0.3,0.1,0.1,0.05],
          ["NECB","A","Ltg","Sat","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05],
          ["NECB","A","Ltg","SunHol","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05],
          ["NECB","A","Equ","Wkd","FRACTION",0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.3,0.8,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.5,0.3,0.3,0.2,0.2,0.2],
          ["NECB","A","Equ","Sat","FRACTION",0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2],
          ["NECB","A","Equ","SunHol","FRACTION",0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2],
          ["NECB","A","Fan","Wkd","ON_OFF",0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0],
          ["NECB","A","Fan","Sat","ON_OFF",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
          ["NECB","A","Fan","SunHol","ON_OFF",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
          ["NECB","A","Proc","Wkd","FRACTION",0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.3,0.8,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.5,0.3,0.3,0.2,0.2,0.2],
          ["NECB","A","Proc","Sat","FRACTION",0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2],
          ["NECB","A","Proc","SunHol","FRACTION",0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2],
          ["NECB","A","Clg","Wkd","TEMPERATURE",35,35,35,35,35,35,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,35,35,35],
          ["NECB","A","Clg","Sat","TEMPERATURE",35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35],
          ["NECB","A","Clg","SunHol","TEMPERATURE",35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35],
          ["NECB","A","Htg","Wkd","TEMPERATURE",18,18,18,18,18,18,20,22,22,22,22,22,22,22,22,22,22,22,22,22,22,18,18,18],
          ["NECB","A","Htg","Sat","TEMPERATURE",18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18],
          ["NECB","A","Htg","SunHol","TEMPERATURE",18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18],
          ["NECB","A","HW","Wkd","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.1,0.5,0.5,0.9,0.9,0.9,0.9,0.9,0.9,0.7,0.5,0.3,0.2,0.2,0.2,0.05,0.05],
          ["NECB","A","HW","Sat","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05],
          ["NECB","A","HW","SunHol","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05],
          ["NECB","B","Occ","Wkd","FRACTION",0.3,0.1,0,0,0,0,0,0,0,0.1,0.2,0.5,0.9,0.8,0.5,0.2,0.2,0.3,0.6,0.9,0.9,0.9,0.6,0.4],
          ["NECB","B","Occ","Sat","FRACTION",0.5,0.3,0,0,0,0,0,0,0,0.1,0.2,0.5,0.9,0.8,0.5,0.2,0.2,0.3,0.6,0.9,0.9,0.9,0.6,0.6],
          ["NECB","B","Occ","SunHol","FRACTION",0.1,0.3,0,0,0,0,0,0,0,0,0.1,0.4,0.5,0.5,0.4,0.2,0.2,0.2,0.5,0.7,0.7,0.5,0.3,0.1],
          ["NECB","B","Ltg","Wkd","FRACTION",0.9,0.5,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.5,0.7,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9],
          ["NECB","B","Ltg","Sat","FRACTION",0.9,0.5,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.5,0.7,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9],
          ["NECB","B","Ltg","SunHol","FRACTION",0.5,0.5,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.5,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.5],
          ["NECB","B","Equ","Wkd","FRACTION",0.9,0.5,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.5,0.7,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9],
          ["NECB","B","Equ","Sat","FRACTION",0.9,0.5,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.5,0.7,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9],
          ["NECB","B","Equ","SunHol","FRACTION",0.5,0.5,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.5,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.5],
          ["NECB","B","Fan","Wkd","ON_OFF",1,1,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
          ["NECB","B","Fan","Sat","ON_OFF",1,1,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
          ["NECB","B","Fan","SunHol","ON_OFF",0,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0],
          ["NECB","B","Proc","Wkd","FRACTION",0.9,0.5,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.5,0.7,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9],
          ["NECB","B","Proc","Sat","FRACTION",0.9,0.5,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.5,0.7,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9],
          ["NECB","B","Proc","SunHol","FRACTION",0.5,0.5,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.5,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.5],
          ["NECB","B","Clg","Wkd","TEMPERATURE",24,35,35,35,35,35,35,35,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24],
          ["NECB","B","Clg","Sat","TEMPERATURE",24,35,35,35,35,35,35,35,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24],
          ["NECB","B","Clg","SunHol","TEMPERATURE",35,35,35,35,35,35,35,35,35,24,24,24,24,24,24,24,24,24,24,24,24,24,24,35],
          ["NECB","B","Htg","Wkd","TEMPERATURE",22,22,18,18,18,18,18,18,20,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22],
          ["NECB","B","Htg","Sat","TEMPERATURE",22,22,18,18,18,18,18,18,20,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22],
          ["NECB","B","Htg","SunHol","TEMPERATURE",18,22,18,18,18,18,18,18,18,20,22,22,22,22,22,22,22,22,22,22,22,22,22,18],
          ["NECB","B","HW","Wkd","FRACTION",0.6,0.5,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.7,0.7,0.4,0.5,0.6,0.6,0.4,0.3,0.3,0.4,0.5,0.8,0.8,0.9,0.9],
          ["NECB","B","HW","Sat","FRACTION",0.7,0.6,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.7,0.7,0.4,0.5,0.6,0.6,0.4,0.3,0.3,0.4,0.5,0.8,0.8,0.9,0.9],
          ["NECB","B","HW","SunHol","FRACTION",0.5,0.6,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.7,0.7,0.4,0.5,0.6,0.6,0.4,0.3,0.3,0.4,0.5,0.8,0.8,0.5,0.5],
          ["NECB","C","Occ","Wkd","FRACTION",0,0,0,0,0,0,0,0,0.1,0.2,0.5,0.5,0.7,0.7,0.7,0.7,0.8,0.7,0.5,0.3,0.3,0,0,0],
          ["NECB","C","Occ","Sat","FRACTION",0,0,0,0,0,0,0,0,0.1,0.2,0.5,0.6,0.8,0.9,0.9,0.9,0.8,0.7,0.5,0.2,0.2,0,0,0],
          ["NECB","C","Occ","SunHol","FRACTION",0,0,0,0,0,0,0,0,0,0,0.1,0.2,0.2,0.4,0.4,0.4,0.4,0.4,0.2,0,0,0,0,0],
          ["NECB","C","Ltg","Wkd","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.5,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.6,0.5,0.05,0.05,0.05],
          ["NECB","C","Ltg","Sat","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.5,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.6,0.5,0.05,0.05,0.05],
          ["NECB","C","Ltg","SunHol","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.5,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.6,0.05,0.05,0.05,0.05,0.05],
          ["NECB","C","Equ","Wkd","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.5,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.6,0.5,0.05,0.05,0.05],
          ["NECB","C","Equ","Sat","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.5,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.6,0.5,0.05,0.05,0.05],
          ["NECB","C","Equ","SunHol","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.5,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.6,0.05,0.05,0.05,0.05,0.05],
          ["NECB","C","Fan","Wkd","ON_OFF",0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0],
          ["NECB","C","Fan","Sat","ON_OFF",0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0],
          ["NECB","C","Fan","SunHol","ON_OFF",0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0],
          ["NECB","C","Proc","Wkd","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.5,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.6,0.5,0.05,0.05,0.05],
          ["NECB","C","Proc","Sat","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.5,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.6,0.5,0.05,0.05,0.05],
          ["NECB","C","Proc","SunHol","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.5,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.6,0.05,0.05,0.05,0.05,0.05],
          ["NECB","C","Clg","Wkd","TEMPERATURE",35,35,35,35,35,35,35,24,24,24,24,24,24,24,24,24,24,24,24,24,24,35,35,35],
          ["NECB","C","Clg","Sat","TEMPERATURE",35,35,35,35,35,35,35,24,24,24,24,24,24,24,24,24,24,24,24,24,24,35,35,35],
          ["NECB","C","Clg","SunHol","TEMPERATURE",35,35,35,35,35,35,35,35,35,24,24,24,24,24,24,24,24,24,24,35,35,35,35,35],
          ["NECB","C","Htg","Wkd","TEMPERATURE",18,18,18,18,18,18,18,20,22,22,22,22,22,22,22,22,22,22,22,22,22,18,18,18],
          ["NECB","C","Htg","Sat","TEMPERATURE",18,18,18,18,18,18,18,20,22,22,22,22,22,22,22,22,22,22,22,22,22,18,18,18],
          ["NECB","C","Htg","SunHol","TEMPERATURE",18,18,18,18,18,18,18,18,18,20,22,22,22,22,22,22,22,22,22,18,18,18,18,18],
          ["NECB","C","HW","Wkd","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.1,0.2,0.3,0.4,0.8,0.8,0.8,0.8,0.6,0.4,0.3,0.2,0.2,0.05,0.05,0.05],
          ["NECB","C","HW","Sat","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.1,0.2,0.3,0.5,0.9,0.9,0.9,0.9,0.7,0.5,0.3,0.2,0.2,0.05,0.05,0.05],
          ["NECB","C","HW","SunHol","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.1,0.2,0.4,0.8,0.8,0.6,0.4,0.3,0.2,0.05,0.05,0.05,0.05,0.05],
          ["NECB","D","Occ","Wkd","FRACTION",0,0,0,0,0,0,0,0,0.1,0.9,0.9,0.9,0.8,0.8,0.8,0.8,0.5,0.2,0.1,0.3,0.3,0.3,0.1,0],
          ["NECB","D","Occ","Sat","FRACTION",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
          ["NECB","D","Occ","SunHol","FRACTION",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
          ["NECB","D","Ltg","Wkd","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.3,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.7,0.5,0.5,0.7,0.7,0.7,0.3,0.05],
          ["NECB","D","Ltg","Sat","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05],
          ["NECB","D","Ltg","SunHol","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05],
          ["NECB","D","Equ","Wkd","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.3,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.7,0.5,0.5,0.7,0.7,0.7,0.3,0.05],
          ["NECB","D","Equ","Sat","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05],
          ["NECB","D","Equ","SunHol","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05],
          ["NECB","D","Fan","Wkd","ON_OFF",0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0],
          ["NECB","D","Fan","Sat","ON_OFF",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
          ["NECB","D","Fan","SunHol","ON_OFF",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
          ["NECB","D","Proc","Wkd","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.3,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.7,0.5,0.5,0.7,0.7,0.7,0.3,0.05],
          ["NECB","D","Proc","Sat","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05],
          ["NECB","D","Proc","SunHol","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05],
          ["NECB","D","Clg","Wkd","TEMPERATURE",35,35,35,35,35,35,35,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,35],
          ["NECB","D","Clg","Sat","TEMPERATURE",35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35],
          ["NECB","D","Clg","SunHol","TEMPERATURE",35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35],
          ["NECB","D","Htg","Wkd","TEMPERATURE",18,18,18,18,18,18,18,20,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,18],
          ["NECB","D","Htg","Sat","TEMPERATURE",18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18],
          ["NECB","D","Htg","SunHol","TEMPERATURE",18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18],
          ["NECB","D","HW","Wkd","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.5,0.5,0.9,0.9,0.9,0.9,0.9,0.9,0.7,0.3,0.5,0.5,0.5,0.3,0.05,0.05],
          ["NECB","D","HW","Sat","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05],
          ["NECB","D","HW","SunHol","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05],
          ["NECB","E","Occ","Wkd","FRACTION",0,0,0,0,0,0,0,0,0.2,0.7,0.9,0.9,0.9,0.9,0.5,0.9,0.8,0.8,0.2,0,0,0,0,0],
          ["NECB","E","Occ","Sat","FRACTION",0,0,0,0,0,0,0,0,0,0.2,0.2,0.2,0.2,0.1,0.1,0.1,0.1,0,0,0,0,0,0,0],
          ["NECB","E","Occ","SunHol","FRACTION",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
          ["NECB","E","Ltg","Wkd","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.4,0.7,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.4,0.05,0.05,0.05,0.05,0.05],
          ["NECB","E","Ltg","Sat","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.5,0.9,0.9,0.9,0.9,0.9,0.7,0.5,0.05,0.05,0.05,0.05,0.05,0.05,0.05],
          ["NECB","E","Ltg","SunHol","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05],
          ["NECB","E","Equ","Wkd","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.4,0.7,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.4,0.05,0.05,0.05,0.05,0.05],
          ["NECB","E","Equ","Sat","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.5,0.9,0.9,0.9,0.9,0.9,0.7,0.5,0.05,0.05,0.05,0.05,0.05,0.05,0.05],
          ["NECB","E","Equ","SunHol","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05],
          ["NECB","E","Fan","Wkd","ON_OFF",0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0],
          ["NECB","E","Fan","Sat","ON_OFF",0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0],
          ["NECB","E","Fan","SunHol","ON_OFF",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
          ["NECB","E","Proc","Wkd","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.4,0.7,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.4,0.05,0.05,0.05,0.05,0.05],
          ["NECB","E","Proc","Sat","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.5,0.9,0.9,0.9,0.9,0.9,0.7,0.5,0.05,0.05,0.05,0.05,0.05,0.05,0.05],
          ["NECB","E","Proc","SunHol","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05],
          ["NECB","E","Clg","Wkd","TEMPERATURE",35,35,35,35,35,35,35,24,24,24,24,24,24,24,24,24,24,24,24,35,35,35,35,35],
          ["NECB","E","Clg","Sat","TEMPERATURE",35,35,35,35,35,35,35,35,24,24,24,24,24,24,24,24,24,35,35,35,35,35,35,35],
          ["NECB","E","Clg","SunHol","TEMPERATURE",35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35],
          ["NECB","E","Htg","Wkd","TEMPERATURE",18,18,18,18,18,18,18,20,22,22,22,22,22,22,22,22,22,22,22,18,18,18,18,18],
          ["NECB","E","Htg","Sat","TEMPERATURE",18,18,18,18,18,18,18,18,20,22,22,22,22,22,22,22,22,18,18,18,18,18,18,18],
          ["NECB","E","Htg","SunHol","TEMPERATURE",18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18],
          ["NECB","E","HW","Wkd","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.1,0.4,0.5,0.5,0.7,0.9,0.8,0.7,0.8,0.3,0.05,0.05,0.05,0.05,0.05,0.05],
          ["NECB","E","HW","Sat","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.2,0.2,0.4,0.2,0.2,0.2,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05],
          ["NECB","E","HW","SunHol","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05],
          ["NECB","F","Occ","Wkd","FRACTION",0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.7,0.4,0.4,0.2,0.2,0.2,0.2,0.2,0.2,0.3,0.5,0.5,0.5,0.7,0.7,0.8,0.9],
          ["NECB","F","Occ","Sat","FRACTION",0.7,0.9,0.9,0.9,0.9,0.9,0.9,0.7,0.5,0.5,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.5,0.6,0.6,0.6,0.7,0.7],
          ["NECB","F","Occ","SunHol","FRACTION",0.8,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.5,0.5,0.5,0.3,0.3,0.2,0.2,0.2,0.3,0.4,0.4,0.6,0.6,0.8,0.8],
          ["NECB","F","Ltg","Wkd","FRACTION",0.3,0.2,0.2,0.1,0.1,0.1,0.2,0.4,0.5,0.4,0.4,0.3,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.6,0.8,0.9,0.8,0.6],
          ["NECB","F","Ltg","Sat","FRACTION",0.3,0.2,0.2,0.1,0.1,0.1,0.1,0.3,0.3,0.4,0.4,0.3,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.6,0.7,0.7,0.7,0.6],
          ["NECB","F","Ltg","SunHol","FRACTION",0.3,0.3,0.3,0.2,0.2,0.2,0.2,0.3,0.4,0.4,0.3,0.3,0.3,0.3,0.2,0.2,0.2,0.2,0.2,0.5,0.7,0.8,0.6,0.5],
          ["NECB","F","Equ","Wkd","FRACTION",0.3,0.2,0.2,0.1,0.1,0.1,0.2,0.4,0.5,0.4,0.4,0.3,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.6,0.8,0.9,0.8,0.6],
          ["NECB","F","Equ","Sat","FRACTION",0.3,0.2,0.2,0.1,0.1,0.1,0.1,0.3,0.3,0.4,0.4,0.3,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.6,0.7,0.7,0.7,0.6],
          ["NECB","F","Equ","SunHol","FRACTION",0.3,0.3,0.3,0.2,0.2,0.2,0.2,0.3,0.4,0.4,0.3,0.3,0.3,0.3,0.2,0.2,0.2,0.2,0.2,0.5,0.7,0.8,0.6,0.5],
          ["NECB","F","Fan","Wkd","ON_OFF",1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
          ["NECB","F","Fan","Sat","ON_OFF",1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
          ["NECB","F","Fan","SunHol","ON_OFF",1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
          ["NECB","F","Proc","Wkd","FRACTION",0.3,0.2,0.2,0.1,0.1,0.1,0.2,0.4,0.5,0.4,0.4,0.3,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.6,0.8,0.9,0.8,0.6],
          ["NECB","F","Proc","Sat","FRACTION",0.3,0.2,0.2,0.1,0.1,0.1,0.1,0.3,0.3,0.4,0.4,0.3,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.6,0.7,0.7,0.7,0.6],
          ["NECB","F","Proc","SunHol","FRACTION",0.3,0.3,0.3,0.2,0.2,0.2,0.2,0.3,0.4,0.4,0.3,0.3,0.3,0.3,0.2,0.2,0.2,0.2,0.2,0.5,0.7,0.8,0.6,0.5],
          ["NECB","F","Clg","Wkd","TEMPERATURE",24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24],
          ["NECB","F","Clg","Sat","TEMPERATURE",24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24],
          ["NECB","F","Clg","SunHol","TEMPERATURE",24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24],
          ["NECB","F","Htg","Wkd","TEMPERATURE",22,18,18,18,18,18,18,20,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22],
          ["NECB","F","Htg","Sat","TEMPERATURE",22,18,18,18,18,18,18,20,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22],
          ["NECB","F","Htg","SunHol","TEMPERATURE",22,18,18,18,18,18,18,20,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22],
          ["NECB","F","HW","Wkd","FRACTION",0.5,0.3,0.2,0.1,0.1,0.2,0.4,0.6,0.9,0.7,0.5,0.5,0.4,0.5,0.4,0.3,0.3,0.3,0.3,0.5,0.7,0.7,0.7,0.7],
          ["NECB","F","HW","Sat","FRACTION",0.5,0.3,0.2,0.1,0.1,0.2,0.4,0.5,0.8,0.6,0.5,0.5,0.5,0.5,0.5,0.4,0.3,0.3,0.3,0.5,0.7,0.7,0.7,0.7],
          ["NECB","F","HW","SunHol","FRACTION",0.5,0.3,0.2,0.1,0.1,0.2,0.4,0.4,0.6,0.9,0.7,0.5,0.5,0.5,0.4,0.3,0.3,0.3,0.3,0.4,0.6,0.6,0.6,0.6],
          ["NECB","G","Occ","Wkd","FRACTION",0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.7,0.4,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.5,0.9,0.9,0.9,0.9,0.9,0.9],
          ["NECB","G","Occ","Sat","FRACTION",0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.7,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.7,0.9,0.9,0.9,0.9,0.9,0.9],
          ["NECB","G","Occ","SunHol","FRACTION",0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.7,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.7,0.9,0.9,0.9,0.9,0.9,0.9],
          ["NECB","G","Ltg","Wkd","FRACTION",0.3,0,0,0,0,0,0.2,0.5,0.5,0,0,0,0,0,0,0,0,0,0,0.9,0.9,0.9,0.8,0.6],
          ["NECB","G","Ltg","Sat","FRACTION",0.3,0,0,0,0,0,0.2,0.5,0.5,0,0,0,0,0,0,0,0,0,0,0.9,0.9,0.9,0.8,0.6],
          ["NECB","G","Ltg","SunHol","FRACTION",0.3,0,0,0,0,0,0.2,0.5,0.5,0,0,0,0,0,0,0,0,0,0,0.9,0.9,0.9,0.8,0.6],
          ["NECB","G","Equ","Wkd","FRACTION",0.3,0.2,0.2,0.2,0.2,0.2,0.2,0.8,0.8,0.4,0.4,0.4,0.4,0.4,0.4,0.4,0.5,0.2,0.9,0.9,0.7,0.5,0.5,0.5],
          ["NECB","G","Equ","Sat","FRACTION",0.3,0.2,0.2,0.2,0.2,0.2,0.2,0.8,0.8,0.4,0.4,0.4,0.4,0.4,0.4,0.4,0.5,0.2,0.9,0.9,0.7,0.5,0.5,0.5],
          ["NECB","G","Equ","SunHol","FRACTION",0.3,0.2,0.2,0.2,0.2,0.2,0.2,0.8,0.8,0.4,0.4,0.4,0.4,0.4,0.4,0.4,0.5,0.2,0.9,0.9,0.7,0.5,0.5,0.5],
          ["NECB","G","Fan","Wkd","ON_OFF",1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
          ["NECB","G","Fan","Sat","ON_OFF",1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
          ["NECB","G","Fan","SunHol","ON_OFF",1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
          ["NECB","G","Proc","Wkd","FRACTION",0.3,0.2,0.2,0.2,0.2,0.2,0.2,0.8,0.8,0.4,0.4,0.4,0.4,0.4,0.4,0.4,0.5,0.2,0.9,0.9,0.7,0.5,0.5,0.5],
          ["NECB","G","Proc","Sat","FRACTION",0.3,0.2,0.2,0.2,0.2,0.2,0.2,0.8,0.8,0.4,0.4,0.4,0.4,0.4,0.4,0.4,0.5,0.2,0.9,0.9,0.7,0.5,0.5,0.5],
          ["NECB","G","Proc","SunHol","FRACTION",0.3,0.2,0.2,0.2,0.2,0.2,0.2,0.8,0.8,0.4,0.4,0.4,0.4,0.4,0.4,0.4,0.5,0.2,0.9,0.9,0.7,0.5,0.5,0.5],
          ["NECB","G","Clg","Wkd","TEMPERATURE",24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24],
          ["NECB","G","Clg","Sat","TEMPERATURE",24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24],
          ["NECB","G","Clg","SunHol","TEMPERATURE",24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24],
          ["NECB","G","Htg","Wkd","TEMPERATURE",22,18,18,18,18,18,18,20,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22],
          ["NECB","G","Htg","Sat","TEMPERATURE",22,18,18,18,18,18,18,20,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22],
          ["NECB","G","Htg","SunHol","TEMPERATURE",22,18,18,18,18,18,18,20,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22],
          ["NECB","G","HW","Wkd","FRACTION",0.1,0.05,0.05,0.05,0.05,0.05,0.2,0.8,0.7,0.5,0.4,0.2,0.2,0.2,0.3,0.5,0.5,0.7,0.7,0.4,0.4,0.2,0.2,0.1],
          ["NECB","G","HW","Sat","FRACTION",0.1,0.05,0.05,0.05,0.05,0.05,0.05,0.2,0.5,0.5,0.5,0.3,0.3,0.3,0.3,0.7,0.9,0.7,0.7,0.6,0.5,0.4,0.3,0.2],
          ["NECB","G","HW","SunHol","FRACTION",0.1,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.2,0.3,0.3,0.2,0.2,0.3,0.4,0.5,0.6,0.7,0.4,0.3,0.2,0.2,0.2,0.2],
          ["NECB","H","Occ","Wkd","FRACTION",0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9],
          ["NECB","H","Occ","Sat","FRACTION",0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9],
          ["NECB","H","Occ","SunHol","FRACTION",0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9],
          ["NECB","H","Ltg","Wkd","FRACTION",0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9],
          ["NECB","H","Ltg","Sat","FRACTION",0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9],
          ["NECB","H","Ltg","SunHol","FRACTION",0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9],
          ["NECB","H","Equ","Wkd","FRACTION",0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9],
          ["NECB","H","Equ","Sat","FRACTION",0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9],
          ["NECB","H","Equ","SunHol","FRACTION",0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9],
          ["NECB","H","Fan","Wkd","ON_OFF",1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
          ["NECB","H","Fan","Sat","ON_OFF",1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
          ["NECB","H","Fan","SunHol","ON_OFF",1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
          ["NECB","H","Proc","Wkd","FRACTION",0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9],
          ["NECB","H","Proc","Sat","FRACTION",0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9],
          ["NECB","H","Proc","SunHol","FRACTION",0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9],
          ["NECB","H","Clg","Wkd","TEMPERATURE",24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24],
          ["NECB","H","Clg","Sat","TEMPERATURE",24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24],
          ["NECB","H","Clg","SunHol","TEMPERATURE",24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24],
          ["NECB","H","Htg","Wkd","TEMPERATURE",22,18,18,18,18,18,18,20,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22],
          ["NECB","H","Htg","Sat","TEMPERATURE",22,18,18,18,18,18,18,20,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22],
          ["NECB","H","Htg","SunHol","TEMPERATURE",22,18,18,18,18,18,18,20,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22],
          ["NECB","H","HW","Wkd","FRACTION",0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9],
          ["NECB","H","HW","Sat","FRACTION",0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9],
          ["NECB","H","HW","SunHol","FRACTION",0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9],
          ["NECB","I","Occ","Wkd","FRACTION",0.1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.1,0.1,0.1,0.4,0.8,0.8,0.8,0.6,0.4],
          ["NECB","I","Occ","Sat","FRACTION",0.1,0,0,0,0,0,0,0,0,0,0.1,0.1,0.1,0.4,0.6,0.8,0.6,0.4,0.2,0.4,0.8,0.8,0.6,0.4],
          ["NECB","I","Occ","SunHol","FRACTION",0,0,0,0,0,0,0,0,0.2,0.4,0.8,0.8,0.4,0.2,0,0,0,0,0,0,0,0,0,0],
          ["NECB","I","Ltg","Wkd","FRACTION",0.5,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.5,0.5,0.5,0.8,0.9,0.9,0.9,0.9,0.9],
          ["NECB","I","Ltg","Sat","FRACTION",0.5,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.5,0.5,0.5,0.8,0.9,0.9,0.9,0.8,0.6,0.8,0.9,0.9,0.9,0.9],
          ["NECB","I","Ltg","SunHol","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.5,0.9,0.9,0.9,0.9,0.5,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05],
          ["NECB","I","Equ","Wkd","FRACTION",0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.2,0.2,0.2,0.8,0.8,0.8,0.8,0.8,0.8],
          ["NECB","I","Equ","Sat","FRACTION",0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.2,0.2,0.2,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8],
          ["NECB","I","Equ","SunHol","FRACTION",0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.8,0.8,0.8,0.8,0.8,0.2,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1],
          ["NECB","I","Fan","Wkd","ON_OFF",1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1],
          ["NECB","I","Fan","Sat","ON_OFF",1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
          ["NECB","I","Fan","SunHol","ON_OFF",0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0],
          ["NECB","I","Proc","Wkd","FRACTION",0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.2,0.2,0.2,0.8,0.8,0.8,0.8,0.8,0.8],
          ["NECB","I","Proc","Sat","FRACTION",0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.2,0.2,0.2,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8],
          ["NECB","I","Proc","SunHol","FRACTION",0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.8,0.8,0.8,0.8,0.8,0.2,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1],
          ["NECB","I","Clg","Wkd","TEMPERATURE",35,35,35,35,35,35,35,35,35,35,35,35,35,35,24,24,24,24,24,24,24,24,24,24],
          ["NECB","I","Clg","Sat","TEMPERATURE",35,35,35,35,35,35,35,35,35,35,24,24,24,24,24,24,24,24,24,24,24,24,24,24],
          ["NECB","I","Clg","SunHol","TEMPERATURE",35,35,35,35,35,35,35,24,24,24,24,24,24,24,35,35,35,35,35,35,35,35,35,35],
          ["NECB","I","Htg","Wkd","TEMPERATURE",18,18,18,18,18,18,18,18,18,18,18,18,18,18,20,22,22,22,22,22,22,22,22,22],
          ["NECB","I","Htg","Sat","TEMPERATURE",18,18,18,18,18,18,18,18,18,18,20,22,22,22,22,22,22,22,22,22,22,22,22,22],
          ["NECB","I","Htg","SunHol","TEMPERATURE",18,18,18,18,18,18,18,20,22,22,22,22,22,22,18,18,18,18,18,18,18,18,18,18],
          ["NECB","I","HW","Wkd","FRACTION",0.2,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.2,0.2,0.2,0.4,0.9,0.9,0.9,0.8,0.6],
          ["NECB","I","HW","Sat","FRACTION",0.2,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.2,0.2,0.2,0.4,0.8,0.9,0.8,0.6,0.4,0.4,0.9,0.9,0.8,0.6],
          ["NECB","I","HW","SunHol","FRACTION",0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.1,0.2,0.4,0.4,0.2,0.1,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05]
        ]

        #NECB Building Type Data
        #Name,IsSpaceType?,NECBScheduleType,OccupantDensity(m2/p),Plug Loads(w/m2),DHW(W/m2),LightingPowerDensity(W/m2),AirChanges(Ac/h),Diveristy Factor (not used) ,4.2.2.2.(2,infiltration_rate m3/s/m2, SystemSpaceType ]
        BuildingTypeData = [
          ["Automotive facility",0,"E",20,5,90,8.8,0.001151044,0,0,0.00025, 1],      
          ["Convention centre",0,"C",8,2.5,30,11.6,0.000747686,0,0,0.00025, 1],      
          ["Courthouse",0,"A",15,5,60,11.3,0.000462385,0,0,0.00025, 1],              
          ["Dining - bar/lounge",0,"B",10,1,115,10.7,0.001269099,0,0,0.00025, 11],
          ["Dining - cafeteria",0,"B",10,1,115,9.7,0.001269099,0,0,0.00025,11],
          ["Dining - family",0,"B",10,1,115,9.6,0.001269099,0,0,0.00025,11],
          ["Dormitory",0,"G",30,2.5,500,6.6,0.000383681,0,0,0.00025, 10],
          ["Exercise centre",0,"B",10,1,90,9.5,0.001249422,0,0,0.00025, 4],
          ["Fire station",0,"F",25,2.5,400,7.6,0.000751622,0,0,0.00025,2],
          ["Gymnasium",0,"B",10,1,90,10.8,0.001249422,0,0,0.00025, 4],
          ["Health-care clinic",0,"A",20,7.5,90,9.4,0.002287331,0,0,0.00025,4],
          ["Hospital",0,"H",20,7.5,90,13,0.002287331,0,0,0.00025,6],
          ["Hotel",0,"F",25,2.5,500,10.8,0.000399422,0,0,0.00025,9],
          ["Library",0,"C",20,2.5,90,12.7,0.00072801,0,0,0.00025,5],
          ["Manufacturing facility",0,"A",30,10,90,11.9,0.00107234,0,0,0.00025,8],
          ["Motel",0,"F",25,2.5,500,9.5,0.000399422,0,0,0.00025,9],
          ["Motion picture theatre",0,"C",8,1,30,8.9,0.000600116,0,0,0.00025,1],
          ["Multi-unit residential",0,"G",60,5,500,6.5,0.000344329,0,0,0.00025,9],
          ["Museum",0,"C",20,2.5,60,11.4,0.000482061,0,0,0.00025,5],
          ["Office",0,"A",25,7.5,90,9.7,0.000399422,0,0,0.00025,4],
          ["Parking garage",0,"H",1000,0,0,2.7,0.0003097,0,0,0.00025,2],
          ["Penitentiary",0,"H",30,2.5,400,10.4,0.000383681,0,0,0.00025,10],
          ["Performing arts theatre",0,"C",8,1,30,15,0.000600116,0,0,0.00025,1],
          ["Police station",0,"H",25,7.5,90,10.3,0.000399422,0,0,0.00025,1], # What is the systemspacetype?
          ["Post office",0,"A",25,7.5,90,9.4,0.000751622,0,0,0.00025, 4], # What is the systemspacetype?
          ["Religious",0,"I",5,1,15,11.3,0.0007772,0,0,0.00025, 1],
          ["Retail",0,"C",30,2.5,40,15.1,0.000423033,0,0,0.00025,4],
          ["School/university",0,"D",8,5,60,10.7,0.000747686,0,0,0.00025,1],
          ["Sports arena",0,"B",10,1,90,8.4,0.000659144,0,0,0.00025,4],
          ["Town hall",0,"D",25,7.5,90,9.9,0.000399422,0,0,0.00025,1],
          ["Transportation",0,"H",15,1,65,8.3,0.000541089,0,0,0.00025,4],
          ["Warehouse",0,"A",1500,1,300,7.1,0.000308126,0,0,0.00025,12],
          ["Workshop",0,"A",30,10,90,12.9,0.00107234,0,0,0.00025,8]
        ]

        #NECB Space Type Data
        #Name,IsSpaceType?,NECBScheduleType,OccupantDensity(p/m2),Plug Loads(w/m2),DHW(W/m2),LightingPowerDensity(W/m2),AirChanges(Ac/h),Diveristy Factor (not used) ,4.2.2.2.(2,infiltration_rate m3/s/m2, SystemSpaceType]
        SpaceTypeData = [
          ["- undefined -",1,"*",0,0,0,0,0,0,0,0.00025 , 0],
          ["Dwelling Unit(s)",1,"G",60,5,500,5,0.000344329,0,1,0.00025, 9],
          ["Atrium - H < 13m",1,"C",10,2.5,0,0,0.000304977,0,1,0.00025, 4],
          ["Atrium - H > 13m",1,"C",10,2.5,0,0,0.000304977,0,1,0.00025, 4],
          ["Audience - auditorium",1,"C",5,2.5,30,8.5,0.004117196,0.3,0.9,0.00025, 1],
          ["Audience - performance arts",1,"C",7.5,2.5,30,26.2,0.004117196,0,1,0.00025, 1],
          ["Audience - motion picture",1,"C",5,2.5,30,12.3,0.004117196,0,1,0.00025, 1],
          ["Classroom/lecture/training",1,"D",7.5,5,65,13.3,0.002782919,0.5,0.9,0.00025, 1],
          ["Conf./meet./multi-purpose",1,"C",5,1,45,13.2,0.001575717,0.5,0.9,0.00025, 1],
          ["Corr. >= 2.4m wide",1,"*",100,0,0,7.1,0.000304977,0,1,0.00025, 0],
          ["Corr. < 2.4m wide",1,"*",100,0,0,8.4,0.000304977,0,1,0.00025, 0],
          ["Dining - bar lounge/leisure",1,"B",10,1,90,14.1,0.003583485,0,1,0.00025,11],
          ["Dining - family space",1,"B",10,1,120,9.6,0.003583485,0,1,0.00025,11],
          ["Dining - other",1,"B",10,1,120,7,0.003583485,0,1,0.00025,11],
          ["Dress./fitt. - performance arts",1,"C",30,2.5,40,4.3,0.001181788,0.4,0.9,0.00025,1],
          ["Electrical/Mechanical",1,"*",200,1,0,13.3,0.000304977,0.9,1,0.00025,0],
          ["Food preparation",1,"B",20,10,120,10.7,0.001372399,0,1,0.00025,11], # SystemSpaceType issue.
          ["Lab - classrooms",1,"D",20,10,180,17.2,0.002185672,0.4,1,0.00025,6],
          ["Lab - research",1,"A",20,10,180,23.6,0.002185672,0,1,0.00025,6],
          ["Lobby - elevator",1,"C",10,1,0,6.9,0.004117196,0,1,0.00025,1],
          ["Lobby - performance arts",1,"C",10,1,0,21.5,0.004117196,0,1,0.00025,1],
          ["Lobby - motion picture",1,"C",10,1,0,5.6,0.004117196,0,1,0.00025,1],
          ["Lobby - other",1,"C",10,1,0,9.7,0.004117196,0,1,0.00025,1],
          ["Locker room",1,"*",10,2.5,0,9.8,0.000940347,0.5,0.9,0.00025,4],
          ["Lounge/recreation",1,"B",10,1,60,9.4,0.000940347,0,1,0.00025,11],
          ["Office - enclosed",1,"A",20,7.5,90,11.9,0.000432051,0.3,0.9,0.00025,4],
          ["Office - open plan",1,"A",20,7.5,90,11,0.000432051,0.2,0.9,0.00025,4],
          ["Sales area",1,"C",30,2.5,40,18.1,0.001181788,0,1,0.00025,4],
          ["Stairway",1,"*",200,0,0,7.4,0.000304977,0,1,0.00025,0],
          ["Storage area",1,"E",100,1,300,6.8,0.000355807,0.6,0.9,0.00025,12],
          ["Washroom",1,"*",30,1,0,10.5,0.000304977,0.5,0.9,0.00025,0],
          ["Workshop space",1,"A",30,10,90,17.1,0.001931524,0,1,0.00025,8],
          ["Automotive - repair",1,"E",20,5,90,7.2,0.001270739,0,1,0.00025,2],
          ["Bank - banking and offices",1,"A",25,5,60,14.9,0.00087681,0,1,0.00025,4],
          ["Convention centre - audience",1,"C",5,2.5,30,8.8,0.004117196,0.2,0.9,0.00025,1],
          ["Convention centre - exhibit",1,"C",5,2.5,30,15.6,0.000864103,0,1,0.00025,1],
          ["Courthouse - courtroom",1,"A",5,2.5,30,18.5,0.002084013,0.2,1,0.00025,1],
          ["Courthouse - cell",1,"H",25,2.5,325,14.7,0.001245325,0,1,0.00025,10],
          ["Courthouse - chambers",1,"A",20,7.5,90,12.6,0.000432051,0.3,0.9,0.00025,1],
          ["Penitentiary - audience",1,"C",5,2.5,30,4.6,0.002084013,0,1,0.00025,1],
          ["Penitentiary - classroom",1,"D",7.5,5,65,14.4,0.002782919,0.5,0.9,0.00025,1],
          ["Penitentiary - dining",1,"B",10,1,120,11.5,0.003583485,0,1,0.00025,11],
          ["Dormitory - living quarters",1,"G",25,2.5,500,4.1,0.000559125,0,1,0.00025,10],
          ["Fire station - engine room",1,"H",25,2.5,325,6,0.001270739,0.5,1,0.00025,2],
          ["Fire station - quarters",1,"G",25,2.5,500,3.4,0.000813273,0,1,0.00025,9],
          ["Gym - fitness",1,"B",5,1,90,9.8,0.004371344,0,1,0.00025,4],
          ["Gym - audience",1,"B",5,0,30,4.6,0.004117196,0,1,0.00025,4],
          ["Gym - play",1,"B",5,1.5,90,12.9,0.001524887,0,1,0.00025,4],
          ["Hospital corr. >= 2.4m",1,"*",100,0,0,9.6,0.000762444,0,1,0.00025,0],
          ["Hospital corr. < 2.4m",1,"*",100,0,0,11.7,0.000762444,0,1,0.00025,0],
          ["Hospital - emergency",1,"H",20,10,180,24.3,0.003049775,0,1,0.00025,6],
          ["Hospital - exam",1,"C",20,10,90,17.9,0.001524887,0.3,1,0.00025,6],
          ["Hospital - laundry/washing",1,"C",20,20,60,8,0.002287331,0,1,0.00025,6],
          ["Hospital - lounge/recreation",1,"B",10,1,60,11.5,0.001270739,0,1,0.00025,11],
          ["Hospital - medical supply",1,"H",20,1,0,13.7,0.001524887,0.5,0.9,0.00025,6],
          ["Hospital - nursery",1,"H",20,10,90,9.5,0.001524887,0,1,0.00025,6],
          ["Hospital - nurses' station",1,"H",20,2.5,45,9.4,0.001524887,0,1,0.00025,6],
          ["Hospital - operating room",1,"H",20,10,300,20.3,0.004574662,0.1,1,0.00025,6],
          ["Hospital - patient room",1,"H",20,10,90,6.7,0.001524887,0.1,1,0.00025,6],
          ["Hospital - pharmacy",1,"C",20,2.5,45,12.3,0.002287331,0,1,0.00025,6],
          ["Hospital - physical therapy",1,"C",20,10,45,9.8,0.002287331,0.2,1,0.00025,6],
          ["Hospital - radiology/imaging",1,"H",20,10,90,14.2,0.002287331,0,1,0.00025,6],
          ["Hospital - recovery",1,"H",20,10,180,12.4,0.004574662,0,1,0.00025,6],
          ["Hotel/Motel - dining",1,"B",10,1,115,8.8,0.003583485,0,1,0.00025,11],
          ["Hotel/Motel - rooms",1,"F",25,2.5,600,11.9,0.000559125,0,1,0.00025,9],
          ["Hotel/Motel - lobby",1,"H",10,2.5,30,11.4,0.001448643,0,1,0.00025,1],
          ["Hway lodging - dining",1,"B",10,1,115,9.5,0.003583485,0,1,0.00025,11],
          ["Hway lodging - rooms",1,"F",25,2.5,600,8.1,0.000559125,0,1,0.00025,9],
          ["Library - cataloging",1,"C",20,2.5,90,7.8,0.000864103,0,1,0.00025,4],
          ["Library - reading",1,"C",20,1,90,10,0.000864103,0,1,0.00025,4],
          ["Library - stacks",1,"C",20,0,90,22.9,0.000864103,0,1,0.00025,4],
          ["Mfg - corr. >= 2.4m",1,"*",100,0,0,4.4,0.001270739,0,1,0.00025,0],
          ["Mfg - corr. < 2.4m",1,"*",100,0,0,5.5,0.001270739,0,1,0.00025,0],
          ["Mfg - detailed",1,"A",30,0,90,13.9,0.001270739,0,1,0.00025,8],
          ["Mfg - equipment",1,"A",30,10,90,13.3,0.001270739,0.2,1,0.00025,8],
          ["Mfg - bay H > 15m",1,"A",30,10,90,11.3,0.001270739,0,1,0.00025,8],
          ["Mfg - 7.5 <= bay H <= 15m",1,"A",30,10,90,13.2,0.001270739,0,1,0.00025,8],
          ["Mfg - bay H < 7.5m",1,"A",30,10,90,12.8,0.001270739,0,1,0.00025,8],
          ["Museum - exhibition",1,"C",5,2.5,60,11.3,0.001829865,0.2,1,0.00025,5],
          ["Museum - restoration",1,"A",20,5,50,11,0.000864103,0.3,1,0.00025,5],
          ["Parking garage space",1,"H",1000,0,0,2,0.002541479,0.4,1,0.00025,2],
          ["Post office sorting",1,"A",20,7.5,90,10.1,0.00087681,0,1,0.00025,4],
          ["Religious - audience",1,"I",5,1,15,18.2,0.003354752,0.3,1,0.00025,1],
          ["Religious - fellowship hall",1,"C",5,1,45,6.9,0.003354752,0.3,1,0.00025,1],
          ["Religious - pulpit/choir",1,"I",5,1,15,18.2,0.003354752,0.1,1,0.00025,1],
          ["Retail - dressing/fitting",1,"C",30,2.5,40,9.4,0.001181788,0.4,0.9,0.00025,4],
          ["Retail - mall concourse",1,"C",20,1,30,11.8,0.001829865,0,1,0.00025,4],
          ["Retail - sales",1,"C",30,2.5,40,18.1,0.001181788,0,1,0.00025,4],
          ["Sports arena - audience",1,"B",5,0,30,4.6,0.006023305,0,1,0.00025,4],
          ["Sports arena - court c4",1,"B",5,1.5,90,7.8,0.001524887,0,1,0.00025,4],
          ["Sports arena - court c3",1,"B",5,1.5,90,12.9,0.001524887,0,1,0.00025,4],
          ["Sports arena - court c2",1,"B",5,1.5,90,20.7,0.001524887,0,1,0.00025,4],
          ["Sports arena - court c1",1,"B",5,1.5,90,32.4,0.001524887,0,1,0.00025,4],
          ["Sports arena - ring",1,"B",5,1.5,90,28.8,0.001524887,0,1,0.00025,4],
          ["Transp. baggage",1,"H",20,2.5,65,8.2,0.00087681,0,1,0.00025,4],
          ["Transp. seating",1,"H",10,0,65,5.8,0.004117196,0,1,0.00025,4],
          ["Transp. concourse",1,"H",20,0,65,3.9,0.004117196,0,1,0.00025,4],
          ["Transp. counter",1,"H",10,2.5,65,11.6,0.00087681,0,1,0.00025,4],
          ["Warehouse - fine",1,"A",50,1,65,10.2,0.000304977,0.5,0.9,0.00025,12],
          ["Warehouse - med/blk",1,"A",100,1,65,6.4,0.000304977,0.5,0.9,0.00025,12],
          ["Warehouse - med/blk2",1,"A",100,1,65,10.2,0.000304977,0.5,0.9,0.00025,12]
        ]
      end
      #this defines the system space types, from Table 8.4.4.8.A
      SystemSpaceTypes = [
        "None",
        #If greater than 4 stories
        "Assembly Area",[3,6],
        "Automotive Area",[4],
        #If colling cap > 20kW
        "Data Processing Area",[1,2],
        #if greater than 2 stories
        "General Area",[3,6],

        "Historical Collections Area",[2],
        "Hospital Area",[3],
        "Indoor Arena",[7],
        "Industrial Area",[3],
        #if heated and cooled use proposed.
        "Residential/Accomodation Area",[1],
        "Sleeping Area",[3],
        #food prep with a vented hood (add a new space type?)
        "Supermarket/Food Services Area",[3,4],
        #non_refridgerated spaces, refrigerated spaces.(New space types?)
        "Warehouse Area",[4,5]
      ]

      #This method ???.
      #@author phylroy.lopez@nrcan.gc.ca
      #@param hdd [Float]
      #@return [Double] a constant float
      def self.max_fwdr(hdd)
        #NECB 3.2.1.4

        if hdd < 4000
          return 0.40
        elsif hdd >= 4000 and hdd <=7000
          return  (2000-0.2 * hdd)/3000
        elsif hdd >7000
          return 0.20
        end
      end


      # This method will set the the envelope (wall, roof, glazings) to  values to
      # the default NECB 2011 values based on the heating degree day value (hdd) surface by surface.
      #@author phylroy.lopez@nrcan.gc.ca
      #@param model [OpenStudio::model::Model] A model object
      #@param hdd [Float]
      def self.set_necb_envelope( model, runner=nil)

        BTAP::runner_register("Info","set_envelope_surfaces_to_necb!", runner) 
        if model.weatherFile.empty? or model.weatherFile.get.path.empty? or not File.exists?(model.weatherFile.get.path.get.to_s)
          
          BTAP::runner_register("Error","Weather file is not defined. Please ensure the weather file is defined and exists.", runner) 
          return false
        end
        hdd = BTAP::Environment::WeatherFile.new(model.weatherFile.get.path.get).hdd18
        
        #interate Through all surfaces
        model.getSurfaces.each do |surface|
          #set fenestration to wall ratio.
          BTAP::Compliance::NECB2011::set_necb_external_surface_conductance(surface,hdd,false,1.0)

          #dig into the subsurface and change them as well.
          model.getSubSurfaces.each do |subsurface|
            BTAP::Compliance::NECB2011::set_necb_external_subsurface_conductance(subsurface,hdd)
          end
        end
      end

      # this will create a copy and convert all construction sets to NECB reference conductances.
      #@author phylroy.lopez@nrcan.gc.ca
      #@param model [OpenStudio::model::Model] A model object
      #@param default_surface_construction_set [String]
      #@return [Boolean] returns true if sucessful, false if not
      def self.set_construction_set_to_necb!(model,default_surface_construction_set,
          runner = nil,
          scale_wall = 1.0,
          scale_floor = 1.0 ,
          scale_roof = 1.0,
          scale_ground_wall = 1.0,
          scale_ground_floor = 1.0,
          scale_ground_roof = 1.0,
          scale_door = 1.0,
          scale_window = 1.0
        )
        BTAP::runner_register("Info","set_construction_set_to_necb!", runner) 
        if model.weatherFile.empty? or model.weatherFile.get.path.empty? or not File.exists?(model.weatherFile.get.path.get.to_s)
          
          BTAP::runner_register("Error","Weather file is not defined. Please ensure the weather file is defined and exists.", runner) 
          return false
        end
        hdd = BTAP::Environment::WeatherFile.new(model.weatherFile.get.path.get).hdd18
        
        old_name = ""
        unless default_surface_construction_set.getAttribute("name").empty? 
          old_name =  default_surface_construction_set.getAttribute("name").get.valueAsString
        end
        
   
        climate_zone_index = get_climate_zone_index(hdd)
        new_name = "#{old_name} at climate #{get_climate_zone_name(hdd)}"

        #convert conductance values to rsi values. (Note: we should really be only using conductances in)
        wall_rsi = 1.0 / ( scale_wall * BTAP::Compliance::NECB2011::Data::Conductances::Wall[climate_zone_index] )
        floor_rsi = 1.0 / ( scale_floor * BTAP::Compliance::NECB2011::Data::Conductances::Floor[climate_zone_index] )
        roof_rsi = 1.0 / ( scale_roof * BTAP::Compliance::NECB2011::Data::Conductances::Roof[climate_zone_index] )
        ground_wall_rsi = 1.0 / ( scale_ground_wall * BTAP::Compliance::NECB2011::Data::Conductances::GroundWall[climate_zone_index] )
        ground_floor_rsi = 1.0 / ( scale_ground_floor * BTAP::Compliance::NECB2011::Data::Conductances::GroundFloor[climate_zone_index] )
        ground_roof_rsi = 1.0 / ( scale_ground_roof * BTAP::Compliance::NECB2011::Data::Conductances::GroundRoof[climate_zone_index] )
        door_rsi = 1.0 / ( scale_door * BTAP::Compliance::NECB2011::Data::Conductances::Door[climate_zone_index] )
        window_rsi = 1.0 / ( scale_window * BTAP::Compliance::NECB2011::Data::Conductances::Window[climate_zone_index] )
        BTAP::Resources::Envelope::ConstructionSets::customize_default_surface_construction_set_rsi!(model,new_name,default_surface_construction_set,
          wall_rsi, floor_rsi, roof_rsi,
          ground_wall_rsi, ground_floor_rsi, ground_roof_rsi,
          window_rsi,  nil ,  nil,
          window_rsi, nil , nil,
          door_rsi,
          door_rsi, nil ,nil,
          door_rsi,
          window_rsi,  nil , nil,
          window_rsi,   nil , nil,
          window_rsi, nil , nil
        )
        BTAP::runner_register("Info","set_construction_set_to_necb! was sucessful.", runner)
        return true
      end

      # This method will convert in place(over write) a construction set to necb conductances.
      #@author phylroy.lopez@nrcan.gc.ca
      #@param model [OpenStudio::model::Model] A model object
      #@param scale_wall [Float]
      #@param scale_floor [Float]
      #@param scale_roof [Float]
      #@param scale_ground_wall [Float]
      #@param scale_ground_floor [Float]
      #@param scale_ground_roof [Float]
      #@param scale_door [Float]
      #@param scale_window [Float]
      def self.set_all_construction_sets_to_necb!(model,
          runner = nil, 
          scale_wall = 1.0,
          scale_floor = 1.0 ,
          scale_roof = 1.0,
          scale_ground_wall = 1.0,
          scale_ground_floor = 1.0,
          scale_ground_roof = 1.0,
          scale_door = 1.0,
          scale_window = 1.0)

        model.getDefaultConstructionSets.each do |set|
          self.set_construction_set_to_necb!(model,
            set,
            runner,
            scale_wall,
            scale_floor ,
            scale_roof,
            scale_ground_wall,
            scale_ground_floor,
            scale_ground_roof,
            scale_door,
            scale_window)
        end
      end


      #This method will set the fwdr for a building. It will remove all glazings
      # and hard set the FDWR.
      #@author phylroy.lopez@nrcan.gc.ca
      #@param model [OpenStudio::model::Model] A model object
      #@param runner [Object]
      #@param [Boolean] use_max
      def self.set_necb_fwdr(model,use_max = false, runner = nil)
        BTAP::runner_register("Info","set_necb_fwdr", runner)         
        if model.weatherFile.empty? or model.weatherFile.get.path.empty? or not File.exists?(model.weatherFile.get.path.get.to_s)
          BTAP::runner_register("Error","Weather file is not defined. Please ensure the weather file is defined and exists.", runner) 
          return false
        end
        hdd = BTAP::Environment::WeatherFile.new(model.weatherFile.get.path.get).hdd18
        
        old_fwdr = BTAP::Geometry::get_fwdr(model)
        BTAP::runner_register("Info","old FWDR is #{old_fwdr}", runner) 
        outdoor_surfaces = BTAP::Geometry::Surfaces::filter_by_boundary_condition(model.getSurfaces(), "Outdoors")
        outdoor_subsurfaces = BTAP::Geometry::Surfaces::get_subsurfaces_from_surfaces(outdoor_surfaces)
        outdoor_walls = BTAP::Geometry::Surfaces::filter_by_surface_types(outdoor_surfaces, "Wall")
        
        #Remove all windows
        BTAP::Geometry::Surfaces::filter_subsurfaces_by_types(outdoor_subsurfaces, ["FixedWindow" , "OperableWindow" ]).each {|door| door.remove}
        #Remove all doors
        BTAP::Geometry::Surfaces::filter_subsurfaces_by_types(outdoor_subsurfaces, ["Door" , "GlassDoor" ]).each {|door| door.remove}
        
        if use_max == true or old_fwdr > self.max_fwdr(hdd)
          ratio = self.max_fwdr(hdd)
        else
          ratio = old_fwdr
        end
        outdoor_walls.each {|wall| wall.setWindowToWallRatio(ratio) }
        
        BTAP::runner_register("Info","New FWDR is #{BTAP::Geometry::get_fwdr(model)} based on HDD of #{hdd}.", runner) 
        return model
      end

      #This method will set the fwdr for a building. It will remove all glazings
      # and hard set the FDWR.
      #@author phylroy.lopez@nrcan.gc.ca
      #@param model [OpenStudio::model::Model] A model object
      #@param runner [OpenStudio::Ruleset::OSRunner]
      def self.set_necb_srr(model, runner = nil)
        BTAP::runner_register("Info","Setting NECB Skylight to Roof Ration to 0.05", runner) 
        ratio = 0.05
        old_srr = BTAP::Geometry::get_srr(model)
        BTAP::runner_register("InitialCondition","old Skylight to Roof Ratio is #{old_srr}", runner) 
        outdoor_surfaces = BTAP::Geometry::Surfaces::filter_by_boundary_condition(model.getSurfaces(), "Outdoors")
        outdoor_subsurfaces = BTAP::Geometry::Surfaces::get_subsurfaces_from_surfaces(outdoor_surfaces)
        outdoor_roofs = BTAP::Geometry::Surfaces::filter_by_surface_types(outdoor_surfaces, "RoofCeiling")
        skylights = BTAP::Geometry::Surfaces::filter_subsurfaces_by_types(outdoor_subsurfaces, ["Skylight", "TubularDaylightDiffuser","TubularDaylightDome" ])
        overhead_doors = BTAP::Geometry::Surfaces::filter_subsurfaces_by_types(outdoor_subsurfaces, ["OverheadDoor" ])
        skylights.each {|skylight| skylight.remove}
        overhead_doors.each {|overhead_door| overhead_door.remove}
        outdoor_roofs.each {|roof| roof.setWindowToWallRatio(ratio) }
        BTAP::runner_register("FinalCondition","old Skylight to Roof Ratio is #{BTAP::Geometry::get_srr(model)}", runner) 
      end




      #This model gets the climate zone column index from tables 3.2.2.x
      #@author phylroy.lopez@nrcan.gc.ca
      #@param hdd [Float]
      #@return [Fixnum] climate zone 4-8
      def self.get_climate_zone_index(hdd)
        #check for climate zone index from NECB 3.2.2.X
        case hdd
        when 0..2999        then return 0    #climate zone 4
        when 3000..3999     then return 1    #climate zone 5
        when 4000..4999     then return 2    #climate zone 6
        when 5000..5999     then return 3    #climate zone 7a
        when 6000..6999     then return 4    #climate zone 7b
        when 7000..1000000  then return 5    #climate zone 8
        end
      end
    
      #This model gets the climate zone name and returns the climate zone string.
      #@author phylroy.lopez@nrcan.gc.ca
      #@param hdd [Float]
      #@return [Fixnum] climate zone 4-8
      def self.get_climate_zone_name(hdd)
        case self.get_climate_zone_index(hdd)
        when 0    then return "4"
        when 1    then return "5"    #climate zone 5
        when 2    then return "6"    #climate zone 6
        when 3    then return "7a"    #climate zone 7a
        when 4    then return "7b"    #climate zone 7b
        when 5    then return "8"    #climate zone 8
        end
      end
    
    

      #Set all external surface conductances to NECB values.
      #@author phylroy.lopez@nrcan.gc.ca
      #@param surface [String]
      #@param hdd [Float]
      #@param is_radiant [Boolian]
      #@param scaling_factor [Float]
      #@return [String] surface as RSI
      def self.set_necb_external_surface_conductance(surface,hdd,is_radiant = false,scaling_factor = 1.0)
        conductance_value = 0
        climate_zone_index = self.get_climate_zone_index(hdd)
       
        if surface.outsideBoundaryCondition.downcase == "outdoors"

          case surface.surfaceType.downcase
          when "wall"
            conductance_value =  BTAP::Compliance::NECB2011::Data::Conductances::Wall[climate_zone_index] * scaling_factor
          when "floor"
            conductance_value = BTAP::Compliance::NECB2011::Data::Conductances::Floor[climate_zone_index]  * scaling_factor
          when "roofceiling"
            conductance_value = BTAP::Compliance::NECB2011::Data::Conductances::Roof[climate_zone_index] 
          end
          if (is_radiant)
            conductance_value = conductance_value * 0.80
          end
          return BTAP::Geometry::Surfaces::set_surfaces_construction_conductance( [surface], conductance_value )
        end


        if surface.outsideBoundaryCondition.downcase.match(/ground/)
          case surface.surfaceType.downcase
          when "wall"
            conductance_value =  BTAP::Compliance::NECB2011::Data::Conductances::GroundWall[BTAP::Compliance::NECB2011::get_climate_zone_index(@hdd)]
          when "floor"
            conductance_value =  BTAP::Compliance::NECB2011::Data::Conductances::GroundFloor[BTAP::Compliance::NECB2011::get_climate_zone_index(@hdd)]
          when "roofceiling"
            conductance_value =  BTAP::Compliance::NECB2011::Data::Conductances::GroundRoof[BTAP::Compliance::NECB2011::get_climate_zone_index(@hdd)]
          end
          if (is_radiant)
            conductance_value = conductance_value * 0.80
          end
          return BTAP::Geometry::Surfaces::set_surfaces_construction_conductance( [surface], conductance_value )

        end
      end

      #Set all external subsurfaces (doors, windows, skylights) to NECB values.
      #@author phylroy.lopez@nrcan.gc.ca
      #@param subsurface [String]
      #@param hdd [Float]
      def self.set_necb_external_subsurface_conductance(subsurface,hdd)
        conductance_value = 0
        climate_zone_index = get_climate_zone_index(hdd)
        if subsurface.outsideBoundaryCondition.downcase.match("outdoors")
          case subsurface.subSurfaceType.downcase
          when /window/
            conductance_value =  BTAP::Compliance::NECB2011::Data::Conductances::Window[climate_zone_index]
          when /door/
            conductance_value = BTAP::Compliance::NECB2011::Data::Conductance::Door[climate_zone_index]
          end
          subsurface.setRSI(1/conductance_value)
        end
      end
      
      #Set all zones to NECB space types as provided by the space type map file 
      #(doors, windows, skylights) to NECB values. This model will be bare and 
      #only have ideal hvac installed. All previous space librairies will be removed 
      #and only NECB libraries will remain. Constructions will remain, even if flawed.   
      #@author phylroy.lopez@nrcan.gc.ca
      #@param idf_filename [String] a idf file
      #@param runner [Object]
      #@return [OpenStudio::model::Model] A model object
      def self.convert_idf_to_osm_and_map_doe_zones_to_necb_space_types(idf_filename, runner = nil)
                
        
        #spacetype map file should be in IDF folder.
        space_type_csv_file = File.dirname(idf_filename) + "/SpaceTypeConversions.csv"
        BTAP::runner_register("ERROR","Spacemap file #{space_type_csv_file} could not be found", runner) unless File.exist?(space_type_csv_file)
        
        #Load IDF file
        model = BTAP::FileIO.load_idf(idf_filename)
        

        #Set building name to match archetype name.
        BTAP::FileIO::set_name(model,"#{File.basename(idf_filename,'.idf')}")
          

        
        #Set Building Stories
        BTAP::Geometry::BuildingStoreys::auto_assign_spaces_to_stories( model )

        #Add NECB Libraries
        BTAP::runner_register("INFO", "Adding NECB default spacetype libs to model... (this may take a while)....", runner)
        BTAP::Compliance::NECB2011::add_necb_schedules( model )
        BTAP::Compliance::NECB2011::add_necb_space_types( model )
        BTAP::Compliance::NECB2011::add_necb_building_types( model )
        BTAP::runner_register("INFO", "Done!.", runner)
        
        
        #iterate thourgh all spaces.
        BTAP::runner_register("INFO", "Mapping NECB space types.",runner)
        #Open CSV Map file.. this contains the map from DOE spacenames to NECB space types.
        found_idf_file_in_space_type_csv = false  
        idf_base_filename = Pathname.new(idf_filename).basename.to_s
        BTAP::runner_register("INFO", "Loaded CSV DOE Space name to NECB SpaceType map file #{space_type_csv_file}.",runner)
        CSV.foreach( space_type_csv_file, :headers => true, :converters => :all ) do |row|
          #puts "Checking #{row['idf_file']} for map."
          if row['idf_file'] == idf_base_filename
            #puts "Found #{row['idf_file']} for map."
            #flag that the idf file was found in the csv file. 
            found_idf_file_in_space_type_csv = true  
            #check if the spacetype is a valid NECB space type. 
            if is_proper_spacetype(row['necb_space_type']) != false
              #get space as named in csv file.
              space_name  = row['zone_name'].gsub(/\bThermal Zone\b/, '').strip
              #get space by space name
              if model.getSpaceTypeByName("NECB-#{row['necb_space_type']}").empty?
                BTAP::runner_register("ERROR","Missing spacetype: #{row['necb_space_type']}", runner) 
              end
              space = model.getSpaceByName(space_name).get
          
              #Get NECB spacetype
              if model.getSpaceTypeByName("NECB-#{row['necb_space_type']}").empty?
                BTAP::runner_register("ERROR","Space name #{space_name} not found in model.", runner)
                return false
              end
              necb_spacetype = model.getSpaceTypeByName("NECB-#{row['necb_space_type']}").get
              #set space type
              space.setSpaceType(necb_spacetype)
              puts "**space #{space.name} has been set to spacetype #{necb_spacetype.name}"
            else
              BTAP::runner_register("ERROR","#{row['necb_space_type']} is not a proper NECB space type",runner)
            end
          else
            if found_idf_file_in_space_type_csv == true
              break
            else
              next
            end
          end
        end
        unless found_idf_file_in_space_type_csv == true
          BTAP::runner_register("ERROR","#{Pathname.new(idf_filename).basename.to_s} not found in spacetype csv mapping in #{space_type_csv_file}.") 
        end
        return model
      end
      


      #Get Wildcard SpaceTypes
      #@author phylroy.lopez@nrcan.gc.ca
      #@param type [String]
      #@return [String] wildcard_space_types
      def self.get_spacetype_names_by_necb_schedule_type(type)
        wildcard_space_types = Array.new()
        BTAP::Compliance::NECB2011::Data::SpaceTypeData.each do |spacetype_data|
          if spacetype_data[2] == type
            wildcard_space_types << ("NECB-" + spacetype_data[0]).to_s
          end
        end
        return wildcard_space_types
      end

      #This will create space types from the type_array.
      #@author phylroy.lopez@nrcan.gc.ca
      #@param model [OpenStudio::model::Model] A model object
      #@param type_array[array<String>]

      def self.add_usage_types(model, type_array )
        
        people = nil 
        lighting = nil 
        electric = nil 
        hotwater = nil 
        oa_load = nil 
        infiltration = nil   
        
        type_array.each do |array|
          #  ["Name","IsSpaceType?","ScheduleType",OccupantDensity,Plug Loads,DHW,LightingPowerDensity,AirChanges,Absence of,4.2.2.2.(2).a,infiltration_rate m3/s/m2]
          name, is_space_type, schedule_type,occupancy_density,plug_loads,dhw,lpd,oa_rate,absence,other,infiltration_rate  = array
          space_type_name = "NECB-" + name.strip
          if schedule_type != "*"
            default_schedule_set = OpenStudio::Model::getDefaultScheduleSetByName(model,"NECB-" + schedule_type).get

            #create loads
            people_name = "NECB-" + name + "-sched-"  + schedule_type + "-people"
            occupancy_density == 0.0 ? people = nil : people = BTAP::Resources::SpaceLoads::create_people_load(model,people_name,occupancy_density)
              
            light_name = "NECB-" + name + "-sched-"  + schedule_type + "-lights" 
            lpd == 0.0 ? lighting = nil : lighting = BTAP::Resources::SpaceLoads::create_lighting_load(model,light_name,lpd)

            elec_name = "NECB-" + name + "-sched-"  + schedule_type + "-elec"
            plug_loads == 0.0 ? electric = nil : electric = BTAP::Resources::SpaceLoads::create_electric_load(model,elec_name,plug_loads)
               
            hotwater_name = "NECB-" + name + "-sched-"  + schedule_type + "-dhw"
            dhw == 0.0 ? hotwater = nil : hotwater = BTAP::Resources::SpaceLoads::create_hotwater_load(model,hotwater_name,dhw)
             
            oa_name = "NECB-" + name + "-sched-"  + schedule_type + "-oa"
            oa_rate == 0.0 ? oa_load = nil : oa_load = BTAP::Resources::SpaceLoads::create_oa_load(model,oa_name,occupancy_density * oa_rate,0,0,0,"Maximum", BTAP::Resources::Schedules::StandardSchedules::Fraction::always_on(model) )
            
            infiltration_name = "NECB-" + name + "-sched-"  + schedule_type + "-inf"
            infiltration_rate == 0.0 ? infiltration = nil : infiltration = BTAP::Resources::SpaceLoads::create_infiltration_load(model, infiltration_name, infiltration_rate, "Flow/ExteriorArea", BTAP::Resources::Schedules::StandardSchedules::Fraction::always_on(model))
              
            BTAP::Resources::SpaceTypes::create_space_type(model,space_type_name,default_schedule_set,people,lighting,electric,hotwater,oa_load,infiltration)
          else
            ["*","A","B","C","D","E","F","G","H","I"].each do |schedule_type|

              default_schedule_set = OpenStudio::Model::getDefaultScheduleSetByName(model,"NECB-" + schedule_type).get unless schedule_type == "*"
              new_space_type_name = space_type_name
              new_space_type_name = space_type_name + "-" + schedule_type unless schedule_type == "*"
              #create loads
              people_name = "NECB-" + name + "-sched-"  + schedule_type + "-people"
              occupancy_density == 0.0 ? people = nil : people = BTAP::Resources::SpaceLoads::create_people_load(model,people_name,occupancy_density)
              
              light_name = "NECB-" + name + "-sched-"  + schedule_type + "-lights" 
              lpd == 0.0 ? lighting = nil : lighting = BTAP::Resources::SpaceLoads::create_lighting_load(model,light_name,lpd)

              elec_name = "NECB-" + name + "-sched-"  + schedule_type + "-elec"
              plug_loads == 0.0 ? electric = nil : electric = BTAP::Resources::SpaceLoads::create_electric_load(model,elec_name,plug_loads)
               
              hotwater_name = "NECB-" + name + "-sched-"  + schedule_type + "-dhw"
              dhw == 0.0 ? hotwater = nil : hotwater = BTAP::Resources::SpaceLoads::create_hotwater_load(model,hotwater_name,dhw)
             
              oa_name = "NECB-" + name + "-sched-"  + schedule_type + "-oa"
              oa_rate == 0.0 ? oa_load = nil : oa_load = BTAP::Resources::SpaceLoads::create_oa_load(model,oa_name,occupancy_density * oa_rate,0,0,0,"Maximum", BTAP::Resources::Schedules::StandardSchedules::Fraction::always_on(model) )
            
              infiltration_name = "NECB-" + name + "-sched-"  + schedule_type + "-inf"
              infiltration_rate == 0.0 ? infiltration = nil : infiltration = BTAP::Resources::SpaceLoads::create_infiltration_load(model, infiltration_name, infiltration_rate, "Flow/ExteriorArea", BTAP::Resources::Schedules::StandardSchedules::Fraction::always_on(model))
              
              BTAP::Resources::SpaceTypes::create_space_type(model,new_space_type_name,default_schedule_set,people,lighting,electric,hotwater,oa_load,infiltration)
            end
          end
        end
      end


      # This method adds all the NECB 2011 schedules to the model. This was used to
      # generate the NECB.osm file.
      #@author phylroy.lopez@nrcan.gc.ca
      #@param model [OpenStudio::model::Model] A model object
      #@return [OpenStudio::model::Model] A model object
      def self.add_necb_schedules(model)

        #model.add_schedule_type_limits()
        counter = 0
        schedulesetname = ""
        schedule_set = ""
        cooling_sched = ""
        #why am I doing it in this primitive way? Ruby 1.8.6 does not support "step" method iterator.. :(
        while (NECB2011::Data::Schedules[counter] != nil)
          #Get Data from row.
          schedule_letter = BTAP::Compliance::NECB2011::Data::Schedules[counter][1]
          load_type = BTAP::Compliance::NECB2011::Data::Schedules[counter][2]
          schedule_type = BTAP::Compliance::NECB2011::Data::Schedules[counter][4]
          weekdayhourly = BTAP::Compliance::NECB2011::Data::Schedules[counter][5..28]
          sathourly = BTAP::Compliance::NECB2011::Data::Schedules[counter+1][5..28]
          sunhourly = BTAP::Compliance::NECB2011::Data::Schedules[counter+2][5..28]

          if schedulesetname != ("NECB-" + schedule_letter )
            schedulesetname =   ("NECB-" + schedule_letter )
            schedule_set = OpenStudio::Model::DefaultScheduleSet.new(model)
            schedule_set.setName(schedulesetname)
            schedule_set.setInfiltrationSchedule(Resources::Schedules::StandardSchedules::Fraction::always_on(model))
          end
          rulesetname = "NECB-" + schedule_letter + "-" + load_type

          #Add hourly schedule
          ruleset = BTAP::Resources::Schedules::create_annual_ruleset_schedule(model,rulesetname,schedule_type,[weekdayhourly,sathourly,sunhourly])


          #assign the ruleset to the correct type.
          case load_type
          when "Occ"
            schedule_set.setNumberofPeopleSchedule(ruleset)
          when "Ltg"
            schedule_set.setLightingSchedule(ruleset)
          when "Equ"
            schedule_set.setElectricEquipmentSchedule(ruleset)
          when "Fan"

            schedule_set.setHoursofOperationSchedule(ruleset)
          when "Proc"
            schedule_set.setOtherEquipmentSchedule(ruleset)
          when "Clg"
            cooling_sched = ruleset
          when "Htg"
            BTAP::Resources::Schedules::create_annual_thermostat_setpoint_dual_setpoint(model,schedulesetname,ruleset,cooling_sched)
          when "HW"

            schedule_set.setHotWaterEquipmentSchedule(ruleset)
          end
          counter = counter + 3
        end
        return model
      end

      #This method will add all the NECB building types to a model
      #@author phylroy.lopez@nrcan.gc.ca
      #@param model [OpenStudio::model::Model] A model object
      #@return [OpenStudio::model::Model] A model object
      def self.add_necb_building_types( model )
        self.add_usage_types(model, BTAP::Compliance::NECB2011::Data::BuildingTypeData )
        return model
      end

      #this method will add all the NECB space types to the model.
      #@author phylroy.lopez@nrcan.gc.ca
      #@param model [OpenStudio::model::Model] A model object
      #@return [OpenStudio::model::Model] A model object
      def self.add_necb_space_types( model )
        self.add_usage_types(model, BTAP::Compliance::NECB2011::Data::SpaceTypeData )
        return model
      end

      #This method will add the schedules, building types and space types to the
      # model.
      #@author phylroy.lopez@nrcan.gc.ca
      #@param model [OpenStudio::model::Model] A model object
      def self.add_necb_libraries_to_model(model)
        self.add_necb_schedules(model)
        self.add_necb_building_types( model )
        self.add_necb_space_types( model )
      end

      #This method will write all the NECB libraries to the NECB model.
      #@author phylroy.lopez@nrcan.gc.ca
      def self.create_necb_libraries()

        puts "Creating necb_libraries in #{BTAP::TESTING_FOLDER} "
        necb_schedules = OpenStudio::Model::Model.new()
        self.add_necb_schedules(necb_schedules)
        FileUtils.rm_rf(BTAP::TESTING_FOLDER + "/necb_schedules.osm")
        necb_schedules.save(OpenStudio::Path.new(BTAP::TESTING_FOLDER + "/necb_schedules.osm"))

        necb_space_types = OpenStudio::Model::Model.new()
        self.add_necb_space_types(self.add_necb_schedules(necb_space_types))
        FileUtils.rm_rf(BTAP::TESTING_FOLDER + "/necb_space_types.osm")
        necb_space_types.save(OpenStudio::Path.new(BTAP::TESTING_FOLDER + "/necb_space_types.osm"))

        necb_building_types = OpenStudio::Model::Model.new()
        self.add_necb_building_types(self.add_necb_schedules(necb_building_types))
        FileUtils.rm_rf(BTAP::TESTING_FOLDER + "/necb_building_types.osm")
        necb_building_types.save(OpenStudio::Path.new(BTAP::TESTING_FOLDER + "/necb_building_types.osm"))

        necb_full = OpenStudio::Model::Model.new()
        self.add_necb_building_types( self.add_necb_space_types( self.add_necb_schedules(necb_full) ) )
        FileUtils.rm_rf(BTAP::TESTING_FOLDER + "/necb_full.osm")
        necb_full.save(OpenStudio::Path.new(BTAP::TESTING_FOLDER + "/necb_full.osm"))
      end


      # This model converts all DOE to NECB reference building.
      #@author phylroy.lopez@nrcan.gc.ca
      #@param idf_folder [String]
      #@return [OpenStudio::model::Model] model_array
      def self.convert_all_doe_to_necb_reference_building(idf_folder, output_folder = 'C:/test/', construction_library_file = nil , construction_set_name = nil , weather_file = nil , set_necb_fdwr = true)
        #iterate through all idf file in Original folder.
        filenames = Array.new()
        idf_filenames = BTAP::FileIO::get_find_files_from_folder_by_extension(idf_folder, "idf")
        puts idf_folder
        puts "filenames: #{idf_filenames}"
        BTAP::FileIO::get_find_files_from_folder_by_extension(idf_folder, ".idf").each do |idf_filename|
          puts idf_filename
          #Convert doe E+ file to NECB space types and create osm model.
          model = BTAP::Compliance::NECB2011::convert_doe_to_necb_reference_building(idf_filename, construction_library_file , construction_set_name , weather_file, set_necb_fdwr )
          #determine climate zone. 
          #set default to nil. 
          weather = nil
          #set weather file        
          unless weather_file == nil
            #Set weather file.
            weather = BTAP::Environment::WeatherFile.new(weather_file)
            weather.set_weather_file(model)
          end
          new_filename = "#{output_folder}#{File.basename(idf_filename,'.idf')}_#{weather.state_province_region}_#{weather.city}_CZ-#{ BTAP::Compliance::NECB2011::get_climate_zone_name(weather.hdd18)}.osm"
          BTAP::FileIO::save_osm(model, new_filename)
          filenames << new_filename
        end
        return filenames
      end


      def self.set_wildcard_schedules_to_dominant_building_schedule(model, runner = nil)
        
        new_sched_ruleset = OpenStudio::Model::DefaultScheduleSet.new(model)  #initialize
        BTAP::runner_register("Info", "set_wildcard_schedules_to_dominant_building_schedule", runner)
        #Set wildcard schedules based on dominant schedule type in building.
        dominant_sched_type = BTAP::Compliance::NECB2011::determine_dominant_necb_schedule_type(model)
        #puts "dominant_sched_type = #{dominant_sched_type}"
        # find schedule set that corresponds to dominant schedule type
        model.getDefaultScheduleSets.each do |sched_ruleset| 
          # just check people schedule
          # TO DO: should make this smarter: check all schedules
          people_sched = sched_ruleset.numberofPeopleSchedule
          people_sched_name = people_sched.get.name.to_s unless people_sched.empty?
                  
          search_string = "NECB-#{dominant_sched_type}"
         
          if people_sched.empty? == false         
            if people_sched_name.include? search_string              
              new_sched_ruleset = sched_ruleset          
            end
          end
        end
        
        # replace the default schedule set for the space type with * to schedule ruleset with dominant schedule type
        
        model.getSpaces.each do |space|
          #check to see if space space type has a "*" wildcard schedule.
          spacetype_name = space.spaceType.get.name.to_s unless space.spaceType.empty?
          if determine_necb_schedule_type( space ).to_s == "*".to_s 
            new_sched = (spacetype_name).to_s                                  
            optional_spacetype = model.getSpaceTypeByName(new_sched)   
            if optional_spacetype.empty?
              BTAP::runner_register("Error", "Cannot find NECB spacetype #{new_sched}" , runner )
            else
              BTAP::runner_register("Info","Setting wildcard spacetype #{spacetype_name} default schedule set to #{new_sched_ruleset.name}",runner)
              optional_spacetype.get.setDefaultScheduleSet(new_sched_ruleset)    #this works!                            
            end
          end
        end    # end of do |space|
               
        return true
      end
      
      def self.set_zones_thermostat_schedule_based_on_space_type_schedules(model,runner = nil)
        puts "in set_zones_thermostat_schedule_based_on_space_type_schedules"
        BTAP::runner_register("DEBUG","Start-set_zones_thermostat_schedule_based_on_space_type_schedules" , runner)
        model.getThermalZones.each do |zone|
          BTAP::runner_register("DEBUG","\tThermalZone:#{zone.name}" , runner)
          array = []
          zone.spaces.each do |space|
            schedule_type = BTAP::Compliance::NECB2011::determine_necb_schedule_type( space ).to_s
            BTAP::runner_register("DEBUG","space name/type:#{space.name}/#{schedule_type}" , runner)
            
            # if wildcard space type, need to get dominant schedule type
            if schedule_type = "*".to_s 
              dominant_sched_type = BTAP::Compliance::NECB2011::determine_dominant_necb_schedule_type(model)
              schedule_type = dominant_sched_type
            end
            
            array << schedule_type
          end
          array.uniq!
          if array.size > 1
            BTAP::runner_register("Error", "#{zone.name} has spaces with different schedule types. Please ensure that all the spaces are of the same schedule type A to I.",runner)  
            return false
          end

          
          htg_search_string = "NECB-#{array[0]}-Thermostat Setpoint-Heating"
          clg_search_string = "NECB-#{array[0]}-Thermostat Setpoint-Cooling"
          
          if model.getScheduleRulesetByName(htg_search_string).empty? == false
            htg_sched = model.getScheduleRulesetByName(htg_search_string).get     
          else
            BTAP::runner_register("ERROR","heating_thermostat_setpoint_schedule NECB-#{array[0]} does not exist" , runner)
            return false
          end
          
          if model.getScheduleRulesetByName(clg_search_string).empty? == false
            clg_sched = model.getScheduleRulesetByName(clg_search_string).get
          else
            BTAP::runner_register("ERROR","cooling_thermostat_setpoint_schedule NECB-#{array[0]} does not exist" , runner)
            return false
          end
          
          name = "NECB-#{array[0]}-Thermostat Dual Setpoint Schedule"
          
          # If dual setpoint already exists, use that one, else create one       
          if model.getThermostatSetpointDualSetpointByName(name).empty? == false 
            ds = model.getThermostatSetpointDualSetpointByName(name).get 
          else
            ds = BTAP::Resources::Schedules::create_annual_thermostat_setpoint_dual_setpoint(model, name, htg_sched, clg_sched)
          end
          
          thermostatClone = ds.clone.to_ThermostatSetpointDualSetpoint.get
          zone.setThermostatSetpointDualSetpoint(thermostatClone)
          BTAP::runner_register("Info","ThermalZone #{zone.name} set to DualSetpoint Schedule NECB-#{array[0]}",runner)
                         
        end
        
        BTAP::runner_register("DEBUG","END-set_zones_thermostat_schedule_based_on_space_type_schedules" , runner)
        return true
      end
      
      # This model converts all DOE to NECB reference building.
      #@author phylroy.lopez@nrcan.gc.ca
      #@param idf_filename [String]
      #@param model [OpenStudio::Model::Model]
      #@param runner [Object]
      #@return  [OpenStudio::model::Model] model
      def self.convert_idf_to_osm_with_necb_space_types(idf_filename,model = nil,runner = nil)
        
        #Load up idf as OSM file and convert spacetypes based on map contained in File.dirname(idf_filename) + "/SpaceTypeConversions.csv"
        model = BTAP::Compliance::NECB2011::convert_idf_to_osm_and_map_doe_zones_to_necb_space_types(idf_filename,runner)
        
        #Taking care of wildcard spacetypes. 
        BTAP::Compliance::NECB2011::set_wildcard_schedules_to_dominant_building_schedule(model, runner)
        
        #set weather file        
        BTAP::Environment::WeatherFile.new(weather_file).set_weather_file(model,runner)
        
        #set Construction set.
        BTAP::Resources::Envelope::ConstructionSets::set_construction_set_by_file(model, construction_library_file, construction_set_name, runner)

        #set NECB u-values to construction. 
        BTAP::Compliance::NECB2011::set_all_construction_sets_to_necb!( model, runner ) 
        
        #Set FWDR
        BTAP::Compliance::NECB2011::set_necb_fwdr( model, true, runner)
        
        # Set Surface if they are out of wack.
        BTAP::Geometry::match_surfaces( model )
        
        #*** HVAC ***
        BTAP::Compliance::NECB2011::necb_autozoner(model)
        
        BTAP::Compliance::NECB2011::set_zones_thermostat_schedule_based_on_space_type_schedules(model,runner)



       

        #*** HVAC ***
        BTAP::Compliance::NECB2011::necb_autozoner(model)
        
  
        #Set output for Raymond 
        #create array of output variables strings from E+
        output_variable_array =
          [
          "Facility Total Electric Demand Power",
          "Water Heater Gas Rate",
          "Plant Supply Side Heating Demand Rate",
          "Heating Coil Gas Rate",
          "Cooling Coil Electric Power",
          "Boiler Gas Rate",
          "Heating Coil Air Heating Rate",
          "Heating Coil Electric Power",
          "Cooling Coil Total Cooling Rate",
          "Water Heater Heating Rate",
          #          "Facility Total HVAC Electric Demand Power",
          #          "Facility Total Electric Demand Power",
          "Zone Air Temperature",
          "Water Heater Electric Power"
          #          "Baseboard Air Inlet Temperature",
          #          "Baseboard Air Outlet Temperature",
          #          "Baseboard Water Inlet Temperature",
          #          "Baseboard Water Outlet Temperature",
          #          "Boiler Inlet Temperature",
          #          "Boiler Outlet Temperature",
          #          "Plant Supply Side Inlet Temperature",
          #          "Plant Supply Side Outlet Temperature",
          #          "People Radiant Heating Rate",
          #          "People Sensible Heating Rate",
          #          "People Latent Gain Rate",
          #          "People Total Heating Rate",
          #          "Lights Total Heating Rate",
          #          "Electric Equipment Total Heating Rate",
          #          "Other Equipment Total Heating Rate",
          #          "District Heating Hot Water Rate",
          #          "District Heating Rate",
          #          "Air System Outdoor Air Flow Fraction",
          #          "Air System Outdoor Air Minimum Flow Fraction",
          #          "Air System Fan Electric Energy"
        ]
        BTAP::Reports::set_output_variables(model,"Hourly", output_variable_array)
        puts  "added output variables ..." << output_variable_array.to_s << "\n"
        
        #Purge unused objects and return osm model object. 
        model.purgeUnusedResourceObjects
        return model
      end

      # This method confirms if the type is the proper space type
      #@author phylroy.lopez@nrcan.gc.ca
      #@param type [String]
      #@return  [String] item
      def self.is_proper_spacetype(type)
        BTAP::Compliance::NECB2011::Data::SpaceTypeData.each do |item|
          if item[0] == type
            return item
          end
        end
        return false
      end
      
      # This method determines if all the spacetype names match the NECB spacetypes. This is a prerequisite for NECB zoning and system assignment
      #@author phylroy.lopez@nrcan.gc.ca
      #@param model [OpenStudio::Model::Model]
      #@param runner [Object]
      #@return [String] item
      def self.check_all_spacetypes_are_valid_necb_names(model,runner = nil)
        #collect space type and building type names. 
        spacetypenames = []
        found = false
        BTAP::Compliance::NECB2011::Data::SpaceTypeData.each    {  |item| spacetypenames << item[0]}
        BTAP::Compliance::NECB2011::Data::BuildingTypeData.each {  |item| spacetypenames << item[0]}
        non_necb_spacetype_names = []
        model.getSpaceTypes.each do |model_spacetype|
          found = false
          spacetypenames.each do |valid_spacetype_name|
            # The optional suffix allows for for defined "wildcard" spacetypes to pass through. 
            if model_spacetype.name =~ /NECB-#{valid_spacetype_name}(\-[ABCDEFGHI])?/
              found = true
            end
          end
          non_necb_spacetype_names << model_spacetype.name unless found == true
        end
        if non_necb_spacetype_names.size > 0
          BTAP::runner_register("ERROR","The following spacetypes are not NECB space types.", runner)
          non_necb_spacetype_names.each {|item| BTAP::runner_register("ERROR","-#{item}", runner) }
          BTAP::runner_register("ERROR","Please edit model and assign valid space types.", runner)
          return false
        end
        BTAP::runner_register("INFO","All spacetypes conform to NECB naming.", runner)
        return true
      end
      
      
      
      # This model gets the building space type info from lookup table. 
      #@author phylroy.lopez@nrcan.gc.ca
      #@param type [String]
      #@return  [String] item
      def self.lookup_spacetype_info(type)
        BTAP::Compliance::NECB2011::Data::SpaceTypeData.each do |item|
          # The optional suffix allows for for defined "wildcard" spacetypes to pass through. 
          # space type names have changed - original commented out below (until i know it works)
          # if type.strip =~ /NECB 2011 - Space Function - #{item[0]}(\-[ABCDEFGHI])?/         
          if type.strip =~ /Space Function #{item[0]}(\-[ABCDEFGHI])?/
            return item
          end
          
        end
        BTAP::Compliance::NECB2011::Data::BuildingTypeData.each do |item|
          # space type names have changed - original commented out below (until i know it works)
          # if type.strip =~ /NECB 2011 - Space Function - #{item[0]}(\-[ABCDEFGHI])?/
          if type.strip =~ /Space Function #{item[0]}(\-[ABCDEFGHI])?/
            return item
          end
        end
        raise ("#{type} is not a NECB space type, Cannot use NECB system definitions!!")
      end

      #This model determines the dominant NECB schedule type
      #@param model [OpenStudio::model::Model] A model object
      #return s.each [String]
      def self.determine_dominant_necb_schedule_type( model )
        # Here is a hash to keep track of the m2 running total of spacetypes for each
        # sched type.
        s = Hash[
          "A",0,
          "B",0,
          "C",0,
          "D",0,
          "E",0,
          "F",0,
          "G",0,
          "H",0,
          "I",0
        ]
        #iterate through spaces in building.
        model.getSpaces.each do |space|
          raise ("Space #{space.name} does not have a spacetype defined!") if space.spaceType.empty?
          
          spacetype_name = space.spaceType.get.name
          
          
          #iterate through the NECB spacetypes
          found_space_type = false
          BTAP::Compliance::NECB2011::Data::SpaceTypeData.each do |spacetype|            
            
             # puts "compare #{spacetype_name.to_s}  == #{("Space Function " + spacetype[0]).to_s}"
             
            # i think spacetype names have changed, remove NECB 2011 - 
            #if (spacetype_name.to_s  == ("NECB 2011 - Space Function - " + spacetype[0]).to_s ) 
            #  s[ spacetype[2] ] = s[ spacetype[2] ] + space.floorArea() if "*" != spacetype[2]
              
            if (spacetype_name.to_s  == ("Space Function " + spacetype[0]).to_s ) 
              s[ spacetype[2] ] = s[ spacetype[2] ] + space.floorArea() if "*" != spacetype[2]
              
              #puts "Found #{space.spaceType.get.name} schedule #{spacetype[2]} match with floor area of #{space.floorArea()}"
              found_space_type = true
            elsif spacetype_name.to_s =~ /NECB-#{spacetype[0].to_s}(\-[ABCDEFGHI])?/
              #found wildcard..will not count to total. 
              found_space_type = true
            end
      
          end
          raise ("Did not find #{space.spaceType.get.name} in NECB space types.") if found_space_type == false
        end
        #finds max value and returns NECB schedule letter.
        puts s
        raise("default necb schedule could not be determined for . ") if 0.0 == s.values.max
        return s.each { |k, v| return k.to_s if v == s.values.max }
      end
      
      #This method determines the spacetype schedule type. This will re
      #@author phylroy.lopez@nrcan.gc.ca
      #@param space [String]
      #@return [String]:["A","B","C","D","E","F","G","H","I"] spacetype
      def self.determine_necb_schedule_type(space)
        BTAP::Compliance::NECB2011::Data::SpaceTypeData.each do |spacetype|
          spacetype_name = space.spaceType.get.name  unless space.spaceType.empty?
          #If it is a regular space type.
          
          # space type names have changed - original commented out below
          # if spacetype_name.to_s  == ("NECB 2011 - Space Function - " + spacetype[0]).to_s          
          if spacetype_name.to_s  == ("Space Function " + spacetype[0]).to_s
            return spacetype[2]
          end
          #if it is a wildcard space type the schedule is in the name ensure that 
          # space type names have changed - original commented out below
          #  if spacetype_name.to_s =~ /#{"NECB 2011 - Space Function - " + spacetype[0]}-(\S)$/i        
          if spacetype_name.to_s =~ /#{"Space Function " + spacetype[0]}-(\S)$/i
            return $1
          end
        end
        raise ("Could not find space type #{space.spaceType.get.name  unless space.spaceType.empty?} as a valid NECB spacetype")
      end
      
      
      #Create a data struct for the space to system to placement information. 
      SpacezoningData = Struct.new( 
        :space,                   # the space object 
        :system_number,           # the necb system type
        :story,                   # the floor
        :horizontal_placement,    # the horizontal placement (norht, south, east, west, core) 
        :vertical_placment,       # the vertical placement ( ground, top, both, middle )
        :people_obj )             # Spacetype people object
      
      # This method will take a model that uses NECB 2011 spacetypes , and..
      # 1. Create a building story schema. 
      # 2. Remove all existing Thermal Zone defintions. 
      # 3. Create new thermal zones based on the following definitions. 
      # Rule1 all zones must contain only the same schedule / occupancy schedule. 
      # Rule2 zones must cater to similar solar gains (N,E,S,W) 
      # Rule3 zones must not pass from floor to floor. They must be contained to a single floor or level. 
      # Rule4 Wildcard spaces will be associated with the nearest zone of similar schedule type in which is shared most of it's internal surface with.  
      # Rule5 For NECB zones must contain spaces of similar system type only. 
      #@author phylroy.lopez@nrcan.gc.ca
      #@param model [OpenStudio::model::Model] A model object
      #@return [String] system_zone_array
      def self.necb_autozone_and_autosystem(
          model,
          runner,
          use_ideal_air_loads = false,
          boiler_fueltype = "NaturalGas",
          mau_type = true,
          mau_heating_coil_type = "Hot Water",
          baseboard_type = "Hot Water",
          chiller_type = "Scroll",
          mua_cooling_type = "DX",
          heating_coil_types_sys3 = "Gas",
          heating_coil_types_sys4 = "Gas",
          heating_coil_types_sys6 = "Hot Water",
          fan_type = "AF_or_BI_rdg_fancurve" )
        
        #system assignment. 
        unless  ["NaturalGas","Electricity","PropaneGas","FuelOil#1","FuelOil#2","Coal","Diesel","Gasoline","OtherFuel1"].include?(boiler_fueltype)
          BTAP::runner_register("ERROR","boiler_fueltype = #{boiler_fueltype}",runner)
          return
        end
          
        unless [true, false].include?(mau_type) 
          BTAP::runner_register("ERROR","mau_type = #{mau_type}",runner)
          return 
        end
            
        unless ["Hot Water", "Electric"].include?(mau_heating_coil_type)
          BTAP::runner_register("ERROR","mau_heating_coil_type = #{mau_heating_coil_type}",runner)
          return false
        end
        
        unless ["Hot Water" , "Electric"].include?(baseboard_type)
          BTAP::runner_register("ERROR","baseboard_type = #{baseboard_type}",runner)
          return false
        end
        
        
        unless ["Scroll","Centrifugal","Rotary Screw","Reciprocating"].include?(chiller_type)
          BTAP::runner_register("ERROR","chiller_type = #{chiller_type}",runner)
          return false
        end
        unless ["DX","Hydronic"].include?(mua_cooling_type)
          BTAP::runner_register("ERROR","mua_cooling_type = #{mua_cooling_type}",runner)
          return false
        end
        
        unless ["Electric", "Gas", "DX"].include?(heating_coil_types_sys3)
          BTAP::runner_register("ERROR","heating_coil_types_sys3 = #{heating_coil_types_sys3}",runner)
          return false
        end
        
        unless ["Electric", "Gas", "DX"].include?(heating_coil_types_sys4)
          BTAP::runner_register("ERROR","heating_coil_types_sys4 = #{heating_coil_types_sys4}",runner)
          return false
        end
        
        unless ["Hot Water", "Electric"].include?(heating_coil_types_sys6)
          BTAP::runner_register("ERROR","heating_coil_types_sys6 = #{heating_coil_types_sys6}",runner)
          return false
        end
        
        unless ["AF_or_BI_rdg_fancurve","AF_or_BI_inletvanes","fc_inletvanes","var_speed_drive"].include?(fan_type)
          BTAP::runner_register("ERROR","fan_type = #{fan_type}",runner)
          return false
        end
      
        unless ["Electric", "Hot Water"].include?(heating_coil_types_sys6)
          BTAP::runner_register("ERROR","heating_coil_types_sys6 = #{heating_coil_types_sys6}",runner)
          return false
        end
        
        unless ["Electric", "Gas"].include?(heating_coil_types_sys4)
          BTAP::runner_register("ERROR","heating_coil_types_sys4 = #{heating_coil_types_sys4}",runner)
          return false
        end

        #some defaults until we figure out how to handle them. (TODO) 
        vented = true
        heated_only = true
        refrigerated = false
        cooling_capacity = 19.0 #only after sizing run is completed. 
        # Reassign / set floors if required. 
        BTAP::Geometry::BuildingStoreys::auto_assign_stories(model)
        
        
        #Array to store schedule objects
        schedule_type_array = []
        
        
        #This remove all ThermalZones in model just in case
        model.getThermalZones.each do |zone|
          zone.remove
        end
        
        #this method replaces all the "*" space types with concrete "A-I" schedule based shedules. 
        BTAP::Compliance::NECB2011::set_wildcard_schedules_to_dominant_building_schedule(model, runner)
        
        #find the number of stories in the model. 
        number_of_stories = model.getBuildingStorys.size
        
        #set up system array containers. These will contain the spaces associated with the system types. 
        space_zoning_data_array = []
        
        #First pass of spaces to collect information into the space_zoning_data_array . 
        model.getSpaces.each do |space|
          #initialize building story variable. 
          building_story = nil
          #check to see if the space is already set to a story. 
          if not space.buildingStory.empty?
            building_story = space.buildingStory.get
          end
            
          #this will get the spacetype system index 8.4.4.8A  from the SpaceTypeData and BuildingTypeData in  (1-12)
          space_system_index = nil
          if space.spaceType.empty?
            space_system_index = nil
          else
            space_system_index = self.lookup_spacetype_info(space.spaceType.get.name.get)[11]
          end
          
          #identify space-system_index and assign the right NECB system type 1-7. 
          system = nil
          case space_system_index
          when nil
          when 0
            #These are spaces are undefined...so they are unconditioned and have no loads other than infiltration and no systems
            system = 0
          when 1 #Assembly Area.
            if number_of_stories <= 4
              system = 3
            else
              system = 6
            end
            
          when 2 #"Automotive Area",[4]
            system = 4
            
          when 3 #"Data Processing Area",[1,2]
            if cooling_capacity > 20 #KW...need a sizing run. 
              system = 2
            else
              system = 1
            end

          when 4 #"General Area",[3,6]
            if number_of_stories <= 2 
              system = 3
            else
              system = 6
            end
            
          when 5 #"Historical Collections Area",[2],
            system = 2
            
          when 6 # "Hospital Area",[3],
            system = 6
            
          when 7 # "Indoor Arena",[7],
            system = 7
            
          when 8 # "Industrial Area [3] this need some thought. 
            system = 3
            
          when 9 # "Residential/Accomodation Area",[1], this needs some thought. 
            if heated_only
              system = 1
            else 
              system = 1
            end
            
          when 10 #"Sleeping Area",[3],
            system = 3
            
          when 11 #"Supermarket/Food Services Area",[3,4],
            if vented
              system = 3
            else
              system = 4
            end
            
          when 12 # Warehouse
            if refrigerated
              system = 3
            else
              system = 3
            end
          end 
          #get placement on floor, core or perimeter and if a top, bottom, middle or single story. 
          horizontal_placement, vertical_placement =  BTAP::Geometry::Spaces::get_space_placement( space )
          #dump all info into an array for debugging and iteration. 
          unless space.spaceType.empty? or space.spaceType.get.name.to_s.include?("undefined")
            space_zoning_data_array << SpacezoningData.new( space,system,building_story, horizontal_placement,vertical_placement,space.spaceType.get.people )
            schedule_type_array <<  BTAP::Compliance::NECB2011::determine_necb_schedule_type( space ).to_s
          end
        end
        #remove duplicates
        schedule_type_array.uniq!
        
        #now lets apply the rules. 
        # Rule1 all zones must contain only the same schedule / occupancy schedule. 
        # Rule2 zones must cater to similar solar gains (N,E,S,W) 
        # Rule3 zones must not pass from floor to floor. They must be contained to a single floor or level. 
        # Rule4 Wildcard spaces will be associated with the nearest zone of similar schedule type in which is shared most of it's internal surface with.  
        # Rule5 NECB zones must contain spaces of similar system type only. 

        #Thermal zone hash

        system_zone_array = []
        #Lets iterate by system
        (0..7).each do |system_number|
          system_zone_array[system_number] = []
          #iterate by story
          story_counter = 0
          model.getBuildingStorys.each do |story|
            #puts "Story:#{story}"
            story_counter = story_counter + 1
            #iterate by operation schedule type. 
            schedule_type_array.each do |schedule_type|
              #iterate by horizontal location
              ["north","east","west","south","core"].each do |horizontal_placement|
                #puts "horizontal_placement:#{horizontal_placement}"
                space_array = Array.new
                space_zoning_data_array.each do |space_info|
                  #puts "Spacename: #{space_info.space.name}:#{space_info.space.spaceType.get.name}"
                  if space_info.system_number == system_number and 
                      space_info.space.spaceType.get.name.get.include?("- undefined -") == false and
                      space_info.story == story and
                      BTAP::Compliance::NECB2011::determine_necb_schedule_type(space_info.space).to_s == schedule_type and
                      space_info.horizontal_placement == horizontal_placement

                    space_array << space_info.space
                  end
                end
                #create Thermal Zone if space_array is not empty.
                if space_array.size > 0
                  #create new zone and add the spaces to it. 
                  name = "Sys-#{system_number.to_s} Flr-#{story_counter.to_s} Sch-#{schedule_type.to_s} HPlcmt-#{horizontal_placement}"
                  thermal_zone = BTAP::Geometry::Zones::create_thermal_zone(model, space_array)
                  thermal_zone.setAttribute("name",name)
                  BTAP::runner_register("INFO", "ThermalZone:#{name} Created with the following spaces:", runner)
                  space_array.each do |space|
                    BTAP::runner_register("DEBUG","space name/type:#{space.name}:#{space.spaceType.get.name}" , runner)
                  end
                  
                  #default it to ideal air system. 
                  #thermal_zone_ideal_loads = OpenStudio::Model::ZoneHVACIdealLoadsAirSystem.new(model)
                  #thermal_zone_ideal_loads.addToThermalZone(thermal_zone)
                  
                  # thermal_zone.setUseIdealAirLoads(true) - this uses HVACTemplateObject
                  
                  #store zone in 
                  system_zone_array[system_number] << thermal_zone

                end
              end
            end
          end
        end #system iteration
        
        BTAP::Compliance::NECB2011::set_zones_thermostat_schedule_based_on_space_type_schedules(model,runner)

        unless use_ideal_air_loads == true
          

          puts "boiler_fueltype = #{boiler_fueltype}"                     
           
          system_zone_array.each_with_index do |zones,system_index|
            #skip if no thermal zones for this system.
            next if zones.size == 0
            puts "Zone Names for System #{system_index}"
            puts "system_index = #{system_index}"
            case system_index
            when 0 
              zones.each do |thermal_zone|
              thermal_zone_ideal_loads = OpenStudio::Model::ZoneHVACIdealLoadsAirSystem.new(model)
              thermal_zone_ideal_loads.addToThermalZone(thermal_zone)
              end
            when 1
              BTAP::Resources::HVAC::HVACTemplates::NECB2011::assign_zones_sys1(model, zones, boiler_fueltype, mau_type, mau_heating_coil_type, baseboard_type)            
            when 2
              BTAP::Resources::HVAC::HVACTemplates::NECB2011::assign_zones_sys2(model, zones, boiler_fueltype, chiller_type, mua_cooling_type)
            when 3
              BTAP::Resources::HVAC::HVACTemplates::NECB2011::assign_zones_sys3(model, zones, boiler_fueltype, heating_coil_types_sys3, baseboard_type)
            when 4
              BTAP::Resources::HVAC::HVACTemplates::NECB2011::assign_zones_sys4(model, zones, boiler_fueltype, heating_coil_types_sys4, baseboard_type)
            when 5
              BTAP::Resources::HVAC::HVACTemplates::NECB2011::assign_zones_sys5(model, zones, boiler_fueltype, chiller_type, mua_cooling_type)
            when 6
              BTAP::Resources::HVAC::HVACTemplates::NECB2011::assign_zones_sys6(model, zones, boiler_fueltype, heating_coil_types_sys6, baseboard_type, chiller_type, fan_type)              
            when 7
              BTAP::Resources::HVAC::HVACTemplates::NECB2011::assign_zones_sys2(model, zones, boiler_fueltype, chiller_type, mua_cooling_type)
            end
          end
        end               
      end
    end
  end #Compliance
end