# open the class to add methods to return sizing values
class OpenStudio::Model::CoilHeatingGasMultiStage

  def setStandardEfficiencyAndCurves(template, standards)
    
    successfully_set_all_properties = true
    
    # Get the coil capacity
    capacity_w = nil
    htg_stages = self.stages
    if htg_stages.last.nominalCapacity.is_initialized
      capacity_w = htg_stages.last.nominalCapacity.get
    elsif self.autosizedStage4NominalCapacity.is_initialized
      capacity_w = self.autosizedStage4NominalCapacity.get
    else
      OpenStudio::logFree(OpenStudio::Warn, 'openstudio.standards.CoilCoolingDXMultiSpeed', "For #{self.name} capacity is not available, cannot apply efficiency standard.")
      successfully_set_all_properties = false
      return successfully_set_all_properties
    end   

    # Set number of stages for NECB 2011
    if(template == 'NECB 2011')
      num_stages = (capacity_w/(66.0*1000.0)+0.5).round
      num_stages = [num_stages,4].min
      stage_cap = []
      if(num_stages == 1)
        stage_cap[0] = capacity_w/2.0
        stage_cap[1] = 2.0*stage_cap[0]
        stage_cap[2] = stage_cap[1]+0.1
        stage_cap[3] = stage_cap[2]+0.1
      else
        stage_cap[0] = 66.0*1000.0
        stage_cap[1] = 2.0*stage_cap[0]
        if(num_stages == 2)
          stage_cap[2] = stage_cap[1]+0.1
          stage_cap[3] = stage_cap[2]+0.1         
        elsif(num_stages == 3)
          stage_cap[2] = 3.0*stage_cap[0]
          stage_cap[3] = stage_cap[2]+0.1
        elsif(num_stages == 4)
          stage_cap[2] = 3.0*stage_cap[0]
          stage_cap[3] = 4.0*stage_cap[0]
        end
      end
      # set capacities, flow rates, and sensible heat ratio for stages
      for istage in 0..3
        htg_stages[istage].setNominalCapacity(stage_cap[istage])
      end
      # PLF vs PLR curve
      furnace_plffplr_curve_name = 'FURNACE-EFFPLR-NECB2011'
    end

    # plf vs plr curve for furnace
    furnace_plffplr_curve = self.model.add_curve(furnace_plffplr_curve_name, standards)
    if furnace_plffplr_curve
      self.setPartLoadFractionCorrelationCurve(furnace_plffplr_curve)
    else
      OpenStudio::logFree(OpenStudio::Warn, 'openstudio.standards.CoilHeatingGasMultiStage', "For #{self.name}, cannot find plffplr curve, will not be set.")
      successfully_set_all_properties = false
    end
    
  end

end