class EnergyPlus::DDYFile

Public Class Methods

new(path) click to toggle source
# File lib/energyplus/DDYFile.rb, line 23
def initialize(path)
  @path = path
  @lines = []
  if File.exists?(@path)
    File.open(@path) do |f|
      while line = f.gets
        @lines << line.chomp
      end
    end
  end
end

Public Instance Methods

cooling(typestr) click to toggle source
# File lib/energyplus/DDYFile.rb, line 159
def cooling(typestr)
  search = "Annual Cooling " + typestr

  obj = findObjectByComment(search)

  puts "[DDYFile] #{File.basename(@path.to_s)} missing cooling #{typestr}" if obj.nil?

  ddyinfo = []
  ddyinfo << search.gsub("\\","")
  ddyinfo << search.gsub("\\","").gsub(" ","_").gsub(".","_").gsub("%","").gsub("=>","_").gsub("__","_")
  ddyinfo << obj

  return ddyinfo

end
findObjectByComment(comment) click to toggle source
# File lib/energyplus/DDYFile.rb, line 61
def findObjectByComment(comment)
  comment = Regexp.new(comment)
  objects().each do |object|
    if object.comment =~ comment
      return object
    end
  end

  return nil
end
get_data_source() click to toggle source

returns an array of “data source, year, and type

# File lib/energyplus/DDYFile.rb, line 73
def get_data_source
  #! Using Design Conditions from "Climate Design Data 2005 ASHRAE Handbook"
  #! Using Design Conditions from "Climate Design Data 2009 ASHRAE Handbook"
  src_s = ""
  @lines.each_index do |i|
    if @lines[i] =~ /Climate Design Data [0-9]{4} ASHRAE Handbook/
      src_s = @lines[i]
      break
    end
  end

  src = []
  src << src_s.match("Climate Design Data [0-9]{4} ASHRAE Handbook")[0]
  src << src_s.match("[0-9]{4}")[0]
  src << "ASHRAE Handbook"

  return src

end
get_indicating_type(ddyobj) click to toggle source

updated for ddy for EP 7.1 2012

# File lib/energyplus/DDYFile.rb, line 105
def get_indicating_type(ddyobj)
  val = ddyobj.fieldString(8).downcase
  if val == "dewpoint"
  res = []
  res << val
  res << ddyobj.fieldValue(9)
  res << "C"
  elsif val == "wetbulb"
  res = []
  res << val
  res << ddyobj.fieldValue(9)
    res << "C"
 elsif val == "enthalpy"
  res = []
  res << val
  res << ddyobj.fieldValue(12)
  res << "kJ/kg"
  end
  return res
end
heating(typestr) click to toggle source

untyped enumerations for heating, cooling, and humidification make this an array, the first column of the array is the ep object, the remaining items are the “attributes and tags”

# File lib/energyplus/DDYFile.rb, line 129
def heating(typestr)
  search = "Annual Heating " + typestr

  obj = findObjectByComment(search)

  puts "[DDYFile] #{File.basename(@path.to_s)} missing heating #{typestr}" if obj.nil?

  ddyinfo = []
  ddyinfo << search.gsub("\\","")
  ddyinfo << search.gsub("\\","").gsub(" ","_").gsub(".","_").gsub("%","").gsub("=>","_").gsub("__","_")
  ddyinfo << obj

  return ddyinfo
end
humidification(typestr) click to toggle source
# File lib/energyplus/DDYFile.rb, line 144
def humidification(typestr)
  search = "Annual Humidification " + typestr

  obj = findObjectByComment(search)

  puts "[DDYFile] #{File.basename(@path.to_s)} missing humidification #{typestr}" if obj.nil?

  ddyinfo = []
  ddyinfo << search.gsub("\\","")
  ddyinfo << search.gsub("\\","").gsub(" ","_").gsub(".","_").gsub("%","").gsub("=>","_").gsub("__","_")
  ddyinfo << obj

  return ddyinfo
end
objects() click to toggle source
# File lib/energyplus/DDYFile.rb, line 35
def objects
  objects = []
  object_fields = []
  object_type = ''
  inobject = false
  object_comment = nil
  @lines.each_index do |i|
    if not inobject and @lines[i] =~ /^\s*\w/
      object_fields = []
      inobject = true
      object_type = @lines[i]
      if @lines[i-1] =~ /^\s*!/
        object_comment = @lines[i-1]
      end
    elsif inobject and @lines[i] =~ /^[^!]*;/
      object_fields << @lines[i]
      inobject = false
      objects << IdfObject.new(object_type,object_fields,object_comment)
    elsif inobject
      object_fields << @lines[i]
    else
    end
  end
  return objects
end
write_idf_snippet(filename, ddyobj) click to toggle source
# File lib/energyplus/DDYFile.rb, line 93
def write_idf_snippet(filename, ddyobj)
  if not ddyobj.nil?
    File.delete(filename) if File.exists?(filename)
    File.open(filename, 'w') do |fl|
  #add version identifier to file
    fl << "\nVersion,\n  7.1;                                    ! Version Identifier \n\n"
      fl << ddyobj
    end
  end
end