-
Notifications
You must be signed in to change notification settings - Fork 8
/
substitute-h2k.rb
7301 lines (6204 loc) · 341 KB
/
substitute-h2k.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env ruby
# ******************************************************************************
# substitute-h2k.rb
# Developed by Jeff Blake, CanmetENERGY-Ottawa, Natural Resources Canada
# Created Nov 2015
# Master maintained in GitHub
#
# This is a Ruby version of the substitute-h2k.pl script originally written by
# Alex Ferguson. This version is customized for HOT2000 runs. This script can be
# used stand-alone, with GenOpt or HTAP-PRM.rb for parametric runs or optimizations
# of HOT2000 inputs.
# ******************************************************************************
require 'rexml/document'
require 'optparse'
require 'timeout'
require 'fileutils'
require 'digest'
require 'json'
require 'set'
require 'pp'
require_relative 'inc/msgs'
require_relative 'inc/H2KUtils'
require_relative 'inc/HTAPUtils'
require_relative 'inc/constants'
require_relative 'inc/rulesets'
require_relative 'inc/costing'
require_relative 'inc/legacy-code'
require_relative 'inc/hourly'
require_relative 'inc/application_modules'
include REXML
# This allows for no "REXML::" prefix to REXML methods
$program = "substitute-h2k.rb"
HTAPInit()
# Parameters controlling timeout and re-try limits for HOT2000
# maxRunTime in seconds (decimal value accepted) set to nil or 0 means no timeout checking!
# Typical H2K run < 10 seconds, but may much take longer in ERS mode
$maxRunTime = 60
# JTB 05-10-2016: Also setting maximum retries within timeout period
$maxTries = 3
$gJasonExport = false
$gJasonTest = false
ScriptName = "substitute.rb"
# HOT2000 output data sets depend on the run mode set in the HOT2000 inputs. In General mode
# just one run is done and one set of outputs is generated, In ERS mode, multiple (7) runs of the
# H2K core are initiated by the interface (either CLI or GUI). The output data sets contain the
# following sections ("houseCode is the XML attribute in each section):
# houseCode=nil: Runs without any imposed conditions on inputs (i.e., same as "General" mode)
# houseCode=SOC: ERS mode using "Standard Operating Conditions"
# houseCode=HOC: ERS mode using "Household Operating Conditions"
# houseCode=HCV: ERS mode "House with Continuous Scheduled Ventilation"
# houseCode=ROC: ERS mode "House with Reduced Operating Conditions"
# houseCode=Reference: ERS "Reference House"
# houseCode=UserHouse: ERS mode "General Mode"
#
# 01-Feb-2018 JTB: Note that this variable will be overridden by the choice file setting for
# Opt-ResultHouseCode. In the case where the user has set an ERS mode output
# data set but the input file is set to General mode, this variable will be
# changed to "General".
$outputHCode = "SOC"
# Global variable names (i.e., variables that maintain their content and use (scope)
# throughout this file).
# Note loose convention to start global variables with a 'g'.
# Ruby *requires* globals to start with '$'.
$gDebug = false
$gSkipSims = false
$gTest_params = Hash.new
# test parameters
$gChoiceFile = ""
$gOptionFile = ""
$PRMcall = false
$ExtraOutput1 = false
$TsvOutput = false
$keepH2KFolder = false
$autoCostOptions = false
$autoEstimateCosts = false
$houseUpgraded = false
$houseUpgradeList = ""
$hourlyCalcs = false
$gTotalCost = 0
$gIncBaseCosts = 12000
# Note: This is dependent on model!
$cost_type = 0
$gRotate = "S"
$gArchGOChoiceFile = 0
$gReadROutStrTxt = false
$ArchetypeData = Hash.new
$ArchetypeData["pre-substitution"]= Hash.new
$ArchetypeData["post-substitution"] = Hash.new
# Use lambda function to avoid the extra lines of creating each hash nesting
$blk = lambda { |h,k| h[k] = Hash.new(&$blk) }
$gOptions = Hash.new(&$blk)
$gOptions2 = Hash.new
$gOptionsOld = Hash.new
$gChoices = Hash.new(&$blk)
$gResults = Hash.new(&$blk)
$gElecRate = Hash.new(&$blk)
$gExtraDataSpecd = Hash.new
$ThisError = ""
$ErrorBuffer = ""
$SaveVPOutput = 0
$gEnergyPV = 0
$gEnergySDHW = 0
$gEnergyHeating = 0
$gEnergyCooling = 0
$gEnergyVentilation = 0
$gEnergyWaterHeating = 0
$gEnergyEquipment = 0
$gERSNum = 0
# ERS number
$gRegionalCostAdj = 0
$gRotationAngle = 0
$gEnergyElec = 0
$gEnergyGas = 0
$gEnergyOil = 0
$gEnergyProp = 0
$gEnergyWood = 0
$gEnergyPellet = 0
$gEnergyHardWood = 0
$gEnergyMixedWood = 0
$gEnergySoftWood = 0
$gEnergyTotalWood = 0
$LapsedTime = 0
$NumTries = 0
$gTotalBaseCost = 0
$gUtilityBaseCost = 0
$PVTarrifDollarsPerkWh = 0.10
# Default value if not set in Options file
$gPeakCoolingLoadW = 0
$gPeakHeatingLoadW = 0
$gPeakElecLoadW = 0
# Maybe needed for hourly model?
$gPeakCoolingW = 0
$gPeakHeatingW = 0
# Variables for saving part-load data from hourly-bins
$binDatHrs = Array.new
$binDatTmp = Array.new
$binDatTsfB = Array.new
$binDatHLR = Array.new
$binDatT2cap = Array.new
$binDatT2cap = Array.new
$binDatT2PLR = Array.new
$binDatT1PLR = Array.new
#Aliases for input/output short hand & long hand
$aliasShortInput = "i"
$aliasShortOutput = "o"
$aliasShortConfig = "c"
$aliasShortArch = "a"
$aliasLongInput = "input"
$aliasLongOutput = "output"
$aliasLongConfig = "configuration"
$aliasLongArch = "archetype"
$aliasLongStatus = "status"
$aliasLongCosts = "cost-estimates"
# Default to short
$aliasInput = $aliasLongInput
$aliasOutput = $aliasLongOutput
$aliasConfig = $aliasLongConfig
$aliasArch = $aliasLongArch
# Path where this script was started and considered master
# Not sure why, but substiture-h2k.rb fails without this converison.
$gMasterPath.gsub!(/\//, '\\')
#$unitCostFileName = "C:/HTAP/HTAPUnitCosts.json"
#$rulesetsFileName = "C:/HTAP/HTAP-rulesets.json"
#Variables that store the average utility costs, energy amounts.
$gAvgEnergy_Total = 0
$gAvgPVRevenue = 0
$gAvgElecCons_KWh = 0
$gAvgPVOutput_kWh = 0
$gAvgCost_Total = 0
$gAvgEnergyCoolingGJ = 0
$gAvgEnergyVentilationGJ = 0
$gAvgEnergyWaterHeatingGJ = 0
$gAvgEnergyEquipmentGJ = 0
$gAvgNGasCons_m3 = 0
$gAvgOilCons_l = 0
$gAvgPropCons_l = 0
$gAvgPelletCons_t = 0
$gDirection = ""
# Flag for reporting general information
$FlagHouseInfo = true
# Flag for reporting choices in inputs
$gReportChoices = true
$GenericWindowParams = Hash.new(&$blk)
$GenericWindowParamsDefined = 0
$gLookForArchetype = 1
$gAuxEnergyHeatingGJ = 0
# 29-Nov-2016 JTB: Added for use by RC
$gEnergyHeatingElec = 0
$gEnergyVentElec = 0
$gEnergyHeatingFossil = 0
$gEnergyWaterHeatingElec = 0
$gEnergyWaterHeatingFossil = 0
$gAvgEnergyHeatingElec = 0
$gAvgEnergyVentElec = 0
$gAvgEnergyHeatingFossil = 0
$gAvgEnergyWaterHeatingElec = 0
$gAvgEnergyWaterHeatingFossil = 0
$gAmtOil = 0
$Locale = ""
# Weather location for current run
$gWarn = false
$UnitCostFileSet = false
$RulesetFileSet = false
$gNoDebug = false
$PVInt = "NA"
$PVIntModel = false
$annPVPowerFromBrowseRpt = 0.0
# Flags for AC Performance Data from Browse.rpt file
$annACSensibleLoadFromBrowseRpt = 0.0
$annACLatentLoadFromBrowseRpt = 0.0
$TotalAirConditioningLoad = 0.0
$AvgACCOP = 0.0
$costEstimates = Hash.new
$ruleSetChoices = Hash.new
$ruleSetName = ""
$gRulesetSpecs = Hash.new
$HDDs = ""
$optionCost = 0.00
# Total cost of all options used in this run
##=begin rdoc
#=========================================================================================
#METHODS: Routines called in this file must be defined before use in Ruby
#(can't put at bottom of listing).
#=========================================================================================
#=end
# -----------------------------------------------------------------------------------------------------
def exportOptionsToJson()
log_out("Exporting legacy data to JSON format")
$gExportFormat = Hash.new
$gOptions.each do |attribute, defs|
# Ignore legacy tags that aren't supported anymore.
if ( $LegacyOptionsToIgnore.include? attribute )
stream_out " - skipping : #{attribute} (legacy variable no longer supported)\n"
next
else
stream_out " - exporting > #{attribute}\n"
end
# Are relationships 1->1 (flat) or 1->[1,2,3..] (tree)?
if ( attribute =~ /GOconfig_rotate/ ||
attribute =~ /Opt-DBFiles/ ||
attribute =~ /Opt-ResultHouseCode/ ||
attribute =~ /Opt-Archetype/ ||
attribute =~ /Ruleset/ ) then
treeStructure = false
structure = "flat"
else
treeStructure = true
structure = "tree"
end
# is cost data required?
if ( ! treeStructure ||
attribute =~ /GOconfig_rotate/ ||
attribute =~ /Opt-FuelCost/ ||
attribute =~ /Opt-Location/ ||
attribute =~ /Opt-FuelCost/ ||
attribute =~ /Opt-DBFiles/ ||
attribute =~ /Opt-ResultHouseCode/ ||
attribute =~ /Opt-FuelCost/ ) then
costingincluded = false
costtext = "not applicable"
else
costingincluded = true
costtext = "included"
end
# Create entry
$gExportFormat[attribute] = Hash.new
$gExportFormat[attribute] = {
"structure" => structure ,
"costed" => costingincluded ,
"options" => Hash.new ,
"default" => nil ,
"stop-on-error" => false
}
if ( treeStructure ) then
$gExportFormat[attribute]["h2kSchema"] = Array.new
end
stopOnError = $gOptions[attribute]["stop-on-error"]
if ( stopOnError == 1 ) then
$gExportFormat[attribute]["stop-on-error"] = true
end
if ($gOptions[attribute].has_key?("default"))then
$gExportFormat[attribute]["default"] = $gOptions[attribute]["default"]["value"]
end
if ( treeStructure ) then
$gOptions[attribute]["tags"].each do | index, tagname |
# Listing of all supported tags
$gExportFormat[attribute]["h2kSchema"].push(tagname)
end
end
$gOptions[attribute]["options"].each do | option, defs2 |
$gExportFormat[attribute]["options"][option] = Hash.new
if ( treeStructure ) then
$gExportFormat[attribute]["options"][option]["h2kMap"] = Hash.new
$gExportFormat[attribute]["options"][option]["h2kMap"]["base"] = Hash.new
# one day consider:
#$gExportFormat[attribute]["options"][option]["values"]["variant"]
$gExportFormat[attribute]["options"][option]["costs"] = Hash.new
if ( costingincluded )
$gExportFormat[attribute]["options"][option]["costs"]["components"] = Array.new
# This field doesn't exist in the HOT2000 file. Let's create an empty example
$gExportFormat[attribute]["options"][option]["costs"]["components"] = [ "Example Key-phrase: Layer1", "Example Key-phrase: Layer2", "Example Key-phrase: Layer3" ]
# This field doesn't exist in the HOT2000 file. Let's create an empty example
$gExportFormat[attribute]["options"][option]["costs"]["custom-costs"] = Hash.new
#$gExportFormat[attribute]["options"][option]["costs"]["custom-costs"] ={ "ExampleScenarioA" =>
# { "Units" => "sf floor area",
# "TotUnitCost" => 1.50,
# "Comment" => "eg: Alex's original estimate"
# },
# "ExampleScenarioB" => { "Units" => "sf floor area",
# "TotUnitCost" => 1.70,
# "Comment" => "eg: Real numbers from ACME builder."
# }
#}
end
# Code for testing purposes : Allows direct comparison between .json and .options generated data maps.
if ( $gDebug ) then
$gExportFormat[attribute]["options"][option]["costs"]["legacy"] = Hash.new
costType = $gOptions[attribute]["options"][option]["cost-type"]
costVal = $gOptions[attribute]["options"][option]["cost"]
$gExportFormat[attribute]["options"][option]["costs"]["legacy"] = { "cost-type" => costType, "cost" => costVal }
end
end
$gOptions[attribute]["options"][option]["values"].each do | valnum, val |
result = val["conditions"]["all"]
if ( treeStructure )
schematag = $gExportFormat[attribute]["h2kSchema"][valnum.to_i - 1]
$gExportFormat[attribute]["options"][option]["h2kMap"]["base"][schematag] = result
else
$gExportFormat[attribute]["options"][option] = result
end
end
end
end
stream_out ("Writing out options in json format (HTAP-options.json)...")
$JSONoutput = File.open("HTAP-options.json", 'w')
$JSONoutput.write(JSON.pretty_generate($gExportFormat))
$JSONoutput.close
stream_out("done.")
if ( $gDebug ) then
$JSONoutput = File.open("HTAPLegacyOptionsStructure.json", 'w')
$JSONoutput.write(JSON.pretty_generate($gOptions))
$JSONoutput.close
$gOptions2 = HTAPData.parse_json_options_file("HTAP-options.json")
$JSONoutput = File.open("HTAPJSONOptionsStructure.json", 'w')
$JSONoutput.write(JSON.pretty_generate($gOptions2))
$JSONoutput.close
debug_out ("Wrote old and new data formats to:\n")
debug_out (" - HTAPLegacyOptionsStructure.json \n")
debug_out (" - HTAPJSONOptionsStructure.json \n")
debug_out (" ( diff these files to compare data models ) \n")
end
end
# =========================================================================================
# Search through the HOT2000 working file (copy of input file specified on command line)
# and change values for settings defined in choice/options files.
# =========================================================================================
def processFile(h2kElements)
#debug_off
# Load all XML elements from HOT2000 code library file. This file is specified
# in option Opt-DBFiles
codeLibName = $gOptions["Opt-DBFiles"]["options"][ $gChoices["Opt-DBFiles"] ]["values"]["1"]["conditions"]["all"]
h2kCodeFile = $run_path + "\\StdLibs" + "\\" + codeLibName
if ( !File.exist?(h2kCodeFile) )
fatalerror("Code library file #{codeLibName} not found in #{$run_path + "\\StdLibs" + "\\"}!")
else
h2kCodeElements = H2KFile.get_elements_from_filename(h2kCodeFile)
end
begin
debug_out ("saving a copy of the pre-substitute version (file-presub.h2k)\n")
newXMLFile = File.open("file-presub.h2k", "w")
$XMLdoc.write(newXMLFile)
rescue
warn_out ("Couldn't create debugging file - filepresub.h2k")
ensure
newXMLFile.close
end
$ArchetypeData["pre-substitution"]["fuelHeating"] = H2KFile.getPrimaryHeatSys( h2kElements )
$ArchetypeData["pre-substitution"]["fuelDHW"] = H2KFile.getPrimaryDHWSys( h2kElements )
# Will contain XML elements for fuel cost file, if Opt-Location is processed!
# Initialized here outside of Opt-Locations check to make scope broader
h2kFuelElements = nil
# H2K version numbers can be used to determine availability of data in the H2K input file.
# Made global so available outide of this subroutine definition. Note that processed output
# file will have the version number of the H2K CLI version used in the run!
locationText = "HouseFile/Application/Version"
$versionMajor_H2K_input = h2kElements[locationText].attributes["major"]
$versionMinor_H2K_input = h2kElements[locationText].attributes["minor"]
$versionBuild_H2K_input = h2kElements[locationText].attributes["build"]
locationText = "HouseFile/House/Generation/PhotovoltaicSystems"
if ( h2kElements[locationText] != nil )
$PVIntModel = true
end
debug_out "Foundation config: #{$foundationConfiguration}\n"
# Legacy - set global foundaton type.
if ( $foundationConfiguration == "wholeFdn")
# Refer to tag value for OPT-H2K-ConfigType in choice Opt-H2KFoundation to determine which foundations to change (further down)!
config = $gOptions["Opt-H2KFoundation"]["options"][ $gChoices["Opt-H2KFoundation"] ]["values"]["1"]["conditions"]["all"]
(configType, configSubType, fndTypes) = config.split('_')
# Refer to tag value for OPT-H2K-ConfigType in choice Opt-H2KFoundationSlabCrawl to determine which foundations to change (further down)!
config2 = $gOptions["Opt-H2KFoundationSlabCrawl"]["options"][ $gChoices["Opt-H2KFoundationSlabCrawl"] ]["values"]["1"]["conditions"]["all"]
(configType2, configSubType2, fndTypes2) = config2.split('_')
end
optDHWTankSize = "1"
# DHW variable defined here so scope includes all DHW tags
sysType1 = [ "Baseboards", "Furnace", "Boiler", "ComboHeatDhw", "P9" ]
sysType2 = [ "AirHeatPump", "WaterHeatPump", "GroundHeatPump", "AirConditioning" ]
# 06-Feb-2017 JTB: Save the base house system heating capacity (Watts) before this XML section is deleted.
# For use when setting the P9 heating capacity and burner input when "Calculated" option specified
# in options file even though it's not available in H2K GUI!
baseHeatSysCap = getBaseSystemCapacity(h2kElements, sysType1)
# Open the unit cost file for reading below
if ( $autoCostOptions )
$unitCostFile = File.read($unitCostFileName)
unitCostDataHash = JSON.parse($unitCostFile)
end
baseOptionCost = 0
$gChoiceOrder.each do |choiceEntry|
#debug_on
next if ( $DoNotValidateOptions.include? choiceEntry )
debug_out drawRuler("By ChoiceOrder : #{choiceEntry}",". ")
debug_out("Processing: #{choiceEntry} | #{$gOptions[choiceEntry]["type"]} = #{$gChoices[choiceEntry]}\n")
if ( $gOptions[choiceEntry]["type"] == "internal" )
choiceVal = $gChoices[choiceEntry]
tagHash = $gOptions[choiceEntry]["tags"]
valHash = $gOptions[choiceEntry]["options"][choiceVal]["result"]
#debug_out "choice val = #{choiceVal}\n"
#debug_out "contents of tagHash:\n#{tagHash.pretty_inspect}\n"
#debug_out "contents of valHash:\n#{valHash.pretty_inspect}\n"
for tagIndex in tagHash.keys()
tag = tagHash[tagIndex]
#debug_on
debug_out "tagIndex: #{tagIndex}: #{tag}\n"
value = valHash[tagIndex.to_s]
if ( value == "" || value.nil? )
debug_out (">>ERR #{choiceEntry} / #{choiceVal} / #{tag} - empty value \n")
value = ""
end
# Replace existing values in H2K file ....................................
# Weather Location
#--------------------------------------------------------------------------
if ( choiceEntry =~ /Opt-Location/ )
$Locale = $gChoices["Opt-Location"]
$gRunLocale = $Locale
# debug_on
# changing the soil condition to permafrost if the location is within
# continuous permafrost zone
set_permafrost_by_location(h2kElements,$Locale)
if ( tag =~ /OPT-H2K-WTH-FILE/ && value != "NA" )
# Weather file to use for HOT2000 run
locationText = "HouseFile/ProgramInformation/Weather"
# Check on existence of H2K weather file
if ( !File.exist?($run_path + "\\Dat" + "\\" + value) )
fatalerror("Weather file #{value} not found in Dat folder !")
else
h2kElements[locationText].attributes["library"] = value
end
elsif ( tag =~ /OPT-H2K-Region/ && value != "NA" )
# Weather region to use for HOT2000 run
locationText = "HouseFile/ProgramInformation/Weather/Region"
h2kElements[locationText].attributes["code"] = value
# Match Client Information Region with this Region to avoid H2K PreCheck dialog!
locationText = "HouseFile/ProgramInformation/Client/StreetAddress/Province"
$gRunRegion = $ProvArr[value.to_i - 1]
h2kElements[locationText].text = $ProvArr[value.to_i - 1]
debug_out ("Run Region: #{$gRunRegion}\n")
elsif ( tag =~ /OPT-H2K-Location/ && value != "NA" )
# Weather location to use for HOT2000 run
locationText = "HouseFile/ProgramInformation/Weather/Location"
h2kElements[locationText].attributes["code"] = value
elsif ( tag =~ /OPT-WEATHER-FILE/ )
# Do nothing
elsif ( tag =~ /OPT-Latitude/ )
# Do nothing
elsif ( tag =~ /OPT-Longitude/ )
# Do nothing
else
if ( value == "NA" )
# Don't change anything
else
fatalerror("Missing H2K #{choiceEntry} tag:#{tag}")
end
end
debug_off
# Fuel Costs
#--------------------------------------------------------------------------
elsif ( choiceEntry =~ /Opt-FuelCost/ )
# HOT2000 Fuel costing data selections (library file and fuel rates).
#print "- TAG: #{tag} / #{value} \n"
if ( tag =~ /OPT-LibraryFile/ && value != "NA" )
# Fuel Cost file to use for HOT2000 run
locationText = "HouseFile/FuelCosts"
# Check on existence of H2K weather file
h2kFuelFile = $run_path + "\\StdLibs" + "\\" + value
if ( !File.exist?(h2kFuelFile) )
fatalerror("Fuel cost file #{value} not found in #{$run_path + "\\StdLibs" + "\\"}!")
else
h2kElements[locationText].attributes["library"] = value
# Open fuel file and read elements to use below. This assumes that this tag
# always comes before the remainder of the weather location tags below!!
h2kFuelElements = H2KFile.get_elements_from_filename(h2kFuelFile)
end
elsif ( tag =~ /OPT-ElecName/ && value != "NA" )
SetFuelCostRates( "Electricity", h2kElements, h2kFuelElements, value )
elsif ( tag =~ /OPT-GasName/ && value != "NA" )
SetFuelCostRates( "NaturalGas", h2kElements, h2kFuelElements, value )
elsif ( tag =~ /OPT-OilName/ && value != "NA" )
SetFuelCostRates( "Oil", h2kElements, h2kFuelElements, value )
elsif ( tag =~ /OPT-PropaneName/ && value != "NA" )
SetFuelCostRates( "Propane", h2kElements, h2kFuelElements, value )
elsif ( tag =~ /OPT-WoodName/ && value != "NA" )
SetFuelCostRates( "Wood", h2kElements, h2kFuelElements, value )
else
if ( value == "NA" )
# Don't change anything
else
fatalerror("Missing H2K #{choiceEntry} tag:#{tag}")
end
end
# Air Infiltration Rate
#--------------------------------------------------------------------------
elsif ( choiceEntry =~ /Opt-ACH/ )
if ( tag =~ /Opt-ACH/ && value != "NA" )
# Need to set the House/AirTightnessTest code attribute to "Blower door test values" (x)
locationText = "HouseFile/House/NaturalAirInfiltration/Specifications/House/AirTightnessTest"
h2kElements[locationText].attributes["code"] = "x"
# Must also remove "Air Leakage Test Data" section, if present, since it will over-ride user-specified ACH value
locationText = "HouseFile/House/NaturalAirInfiltration/AirLeakageTestData"
if ( h2kElements[locationText] != nil )
# Need to remove this section!
locationText = "HouseFile/House/NaturalAirInfiltration"
h2kElements[locationText].delete_element("AirLeakageTestData")
# Change CGSB attribute to true (was set to "As Operated" by AirLeakageTestData section
locationText = "HouseFile/House/NaturalAirInfiltration/Specifications/BlowerTest"
h2kElements[locationText].attributes["isCgsbTest"] = "true"
end
# Set the blower door test value in airChangeRate field
locationText = "HouseFile/House/NaturalAirInfiltration/Specifications/BlowerTest"
h2kElements[locationText].attributes["airChangeRate"] = value
# $ACHRate = h2kElements[locationText].attributes["airChangeRate"].to_f
h2kElements[locationText].attributes["isCgsbTest"] = "true"
h2kElements[locationText].attributes["isCalculated"] = "true"
elsif( tag =~ /Opt-BuildingSite/ && value != "NA" )
if(value.to_f < 1 || value.to_f > 8)
fatalerror("In #{choiceEntry}, invalid building site input #{value}")
end
locationText = "HouseFile/House/NaturalAirInfiltration/Specifications/BuildingSite/Terrain"
h2kElements[locationText].attributes["code"] = value
elsif( tag =~ /Opt-WallShield/ && value != "NA" )
if(value.to_f < 1 || value.to_f > 5)
fatalerror("In #{choiceEntry}, invalid wall shielding input #{value}")
end
locationText = "HouseFile/House/NaturalAirInfiltration/Specifications/LocalShielding/Walls"
h2kElements[locationText].attributes["code"] = value
elsif( tag =~ /Opt-FlueShield/ && value != "NA" )
if(value.to_f < 1 || value.to_f > 5)
fatalerror("In #{choiceEntry}, invalid wall shielding input #{value}")
end
locationText = "HouseFile/House/NaturalAirInfiltration/Specifications/LocalShielding/Flue"
h2kElements[locationText].attributes["code"] = value
#else
# if ( value == "NA" ) # Don't change anything
# else fatalerror("Missing H2K #{choiceEntry} tag:#{tag}") end
end
# Ceilings - All ceiling constructions
# Note: UsrSpec R-values will change all ceilings regardless of construction type but code library
# entries must match the code names that appear in code lib "Ceiling Codes" group or the
# "Flat or Cathedral Ceiling Codes" group.
#--------------------------------------------------------------------------
elsif ( choiceEntry =~ /Opt-Ceilings/ )
if ( tag =~ /Opt-Ceiling/ && value != "NA" )
# If this surface code name exists in the code library, use the code
# (either Favourite or UsrDef) for ceiling and ceiling_flat groupings.
# Code names in library are unique and split into two groups: "Ceiling Codes"
# and "Flat or Cathedral Ceiling Codes" so the code name specified CAN ONLY EXIST
# in one of these groups!
# Note: Not using "Standard", non-library codes (e.g., 2221292000)
foundCodeLibElement = nil
useThisCodeID = "Code 99"
foundCodeLibElement, useThisCodeID = findCeilingCodeInLibrary( h2kElements, h2kCodeElements, value )
if foundCodeLibElement != nil
# Change all existing surface references of this type to useThisCodeID
# NOTE: House ceiling components all under "Ceiling" tag - only <Codes>
# section distinguishes between "Ceiling" and "CeilingFlat"
locationText = "HouseFile/House/Components/Ceiling/Construction/CeilingType"
h2kElements.each(locationText) do |element|
# Check if each house entry has an "idref" attribute and add if it doesn't.
if element.attributes["idref"] != nil
element.attributes["idref"] = useThisCodeID
else
element.add_attribute("idref", useThisCodeID)
end
element.text = value
element.attributes["nominalInsulation"] = foundCodeLibElement.attributes["nominalRValue"]
end
else
# Code name not found in the code library!
# Code missing or a User Specified R-value in OPT-H2K-EffRValue
# or NA in OPT-H2K-EffRValue
debug_out(" INFO: Code name: #{value} NOT in code library for H2K #{choiceEntry} tag:#{tag}\n")
end
elsif ( tag =~ /OPT-H2K-EffRValue/ && value != "NA" )
# Change ALL existing ceiling codes to User Specified R-value
locationText = "HouseFile/House/Components/Ceiling/Construction/CeilingType"
h2kElements.each(locationText) do |element|
element.text = "User specified"
element.attributes["rValue"] = (value.to_f / R_PER_RSI).to_s
if element.attributes["idref"] != nil then
# Must delete attribute for User Specified!
element.delete_attribute("idref")
end
end
else
if ( value == "NA" )
# Don't change anything
else
fatalerror("Missing H2K #{choiceEntry} tag:#{tag}")
end
end
# Attic Ceilings - All Attic/gable, Attic/Hip or Scissor ceiling constructions
#-----------------------------------------------------------------------------
elsif ( choiceEntry =~ /Opt-AtticCeilings/ )
if ( tag =~ /Opt-Ceiling/ && value != "NA" )
# If this surface code name exists in the code library, use the code
# (either Favourite or UsrDef) for "Ceiling Codes" grouping.
# Code names in library are unique.
# Note: Not using "Standard", non-library codes (e.g., 2221292000)
foundCodeLibElement = nil
useThisCodeID = "Code 99"
foundCodeLibElement, useThisCodeID = findCeilingCodeInLibrary( h2kElements, h2kCodeElements, value )
if foundCodeLibElement != nil
# Change all existing surface references of this type to useThisCodeID
# NOTE: House ceiling components all under "Ceiling" tag - only <Codes>
# section distinguishes between "Ceiling" and "CeilingFlat"
locationText = "HouseFile/House/Components/Ceiling/Construction"
h2kElements.each(locationText) do |element|
# Check if construction type (element 1) is Attic/gable (2), Attic/hip (3) or Scissor (6)
if element[1].attributes["code"] == "2" || element[1].attributes["code"] == "3" || element[1].attributes["code"] == "6"
# Check if each house entry has an "idref" attribute for CeilingType (element 3) and add if it doesn't.
if element[3].attributes["idref"] != nil
element[3].attributes["idref"] = useThisCodeID
else
element[3].add_attribute("idref", useThisCodeID)
end
element[3].text = value
element[3].attributes["nominalInsulation"] = foundCodeLibElement.attributes["nominalRValue"]
end
end
else
# Code name not found in the code library!
# Code missing or a User Specified R-value in OPT-H2K-EffRValue
# or NA in OPT-H2K-EffRValue
debug_out(" INFO: Code name: #{value} NOT in code library for H2K #{choiceEntry} tag:#{tag}\n")
end
elsif ( tag =~ /OPT-H2K-EffRValue/ && value != "NA" )
locationText = "HouseFile/House/Components/Ceiling/Construction"
h2kElements.each(locationText) do |element|
# Check if construction type (element 1) is Attic/gable (2), Attic/hip (3) or Scissor (6)
if element[1].attributes["code"] == "2" || element[1].attributes["code"] == "3" || element[1].attributes["code"] == "6"
element[3].text = "User specified"
element[3].attributes["rValue"] = (value.to_f / R_PER_RSI).to_s
if element[3].attributes["idref"] != nil then
# Must delete attribute for User Specified!
element[3].delete_attribute("idref")
end
end
end
elsif (tag =~ /OPT-H2K-HeelHeight/ && value != "NA")
locationText = "HouseFile/House/Components/Ceiling/Measurements"
h2kElements[locationText].attributes["heelHeight"] = value
else
if ( value == "NA" )
# Don't change anything
else
fatalerror("Missing H2K #{choiceEntry} tag:#{tag}")
end
end
# Cathedral Ceilings - All Cathedral ceiling constructions
#--------------------------------------------------------------------------
elsif ( choiceEntry =~ /Opt-CathCeilings/ )
if ( tag =~ /Opt-Ceiling/ && value != "NA" )
# If this surface code name exists in the code library, use the code
# (either Favourite or UsrDef) for "Flat or Cathedral Ceiling Codes" grouping.
# Code names in library are unique.
# Note: Not using "Standard", non-library codes (e.g., 2221292000)
foundCodeLibElement = nil
useThisCodeID = "Code 99"
foundCodeLibElement, useThisCodeID = findCeilingCodeInLibrary( h2kElements, h2kCodeElements, value )
if foundCodeLibElement != nil
# Change all existing surface references of this type to useThisCodeID
# NOTE: House ceiling components all under "Ceiling" tag - only <Codes>
# section distinguishes between "Ceiling" and "CeilingFlat"
locationText = "HouseFile/House/Components/Ceiling/Construction"
h2kElements.each(locationText) do |element|
# Check if construction type (element 1) is Cathedral (4)
if element[1].attributes["code"] == "4"
# Check if each house entry has an "idref" attribute for CeilingType (element 3) and add if it doesn't.
if element[3].attributes["idref"] != nil
element[3].attributes["idref"] = useThisCodeID
else
element[3].add_attribute("idref", useThisCodeID)
end
element[3].text = value
element[3].attributes["nominalInsulation"] = foundCodeLibElement.attributes["nominalRValue"]
end
end
else
# Code name not found in the code library!
# Code missing or a User Specified R-value in OPT-H2K-EffRValue
# or NA in OPT-H2K-EffRValue
debug_out(" INFO: Code name: #{value} NOT in code library for H2K #{choiceEntry} tag:#{tag}\n")
end
elsif ( tag =~ /OPT-H2K-EffRValue/ && value != "NA" )
locationText = "HouseFile/House/Components/Ceiling/Construction"
h2kElements.each(locationText) do |element|
# Check if construction type (element 1) is Cathedral (4)
if element[1].attributes["code"] == "4"
element[3].text = "User specified"
element[3].attributes["rValue"] = (value.to_f / R_PER_RSI).to_s
if element[3].attributes["idref"] != nil then
# Must delete attribute for User Specified!
element[3].delete_attribute("idref")
end
end
end
else
if ( value == "NA" )
# Don't change anything
else
fatalerror("Missing H2K #{choiceEntry} tag:#{tag}")
end
end
# Flat Ceilings - All Flat ceiling constructions
#--------------------------------------------------------------------------
elsif ( choiceEntry =~ /Opt-FlatCeilings/ )
if ( tag =~ /Opt-Ceiling/ && value != "NA" )
# If this surface code name exists in the code library, use the code
# (either Favourite or UsrDef) from the "Flat or Cathedral Ceiling Codes" grouping.
# Code names in library are unique.
# Note: Not using "Standard", non-library codes (e.g., 2221292000)
foundCodeLibElement = nil
useThisCodeID = "Code 99"
foundCodeLibElement, useThisCodeID = findCeilingCodeInLibrary( h2kElements, h2kCodeElements, value )
if foundCodeLibElement != nil
# Change all existing surface references of this type to useThisCodeID
# NOTE: House ceiling components all under "Ceiling" tag - only <Codes>
# section distinguishes between "Ceiling" and "CeilingFlat"
locationText = "HouseFile/House/Components/Ceiling/Construction"
h2kElements.each(locationText) do |element|
# Check if construction type (element 1) is Flat (5)
if element[1].attributes["code"] == "5"
# Check if each house entry has an "idref" attribute for CeilingType (element 3) and add if it doesn't.
if element[3].attributes["idref"] != nil
element[3].attributes["idref"] = useThisCodeID
else
element[3].add_attribute("idref", useThisCodeID)
end
element[3].text = value
element[3].attributes["nominalInsulation"] = foundCodeLibElement.attributes["nominalRValue"]
end
end
else
# Code name not found in the code library!
# Code missing or a User Specified R-value in OPT-H2K-EffRValue
# or NA in OPT-H2K-EffRValue
debug_out(" INFO: Code name: #{value} NOT in code library for H2K #{choiceEntry} tag:#{tag}\n")
end
elsif ( tag =~ /OPT-H2K-EffRValue/ && value != "NA" )
locationText = "HouseFile/House/Components/Ceiling/Construction"
h2kElements.each(locationText) do |element|
# Check if construction type (element 1) is Flat (5)
if element[1].attributes["code"] == "5"
element[3].text = "User specified"
element[3].attributes["rValue"] = (value.to_f / R_PER_RSI).to_s
if element[3].attributes["idref"] != nil then
# Must delete attribute for User Specified!
element[3].delete_attribute("idref")
end
end
end
else
if ( value == "NA" )
# Don't change anything
else
fatalerror("Missing H2K #{choiceEntry} tag:#{tag}")
end
end
# Main Walls
#--------------------------------------------------------------------------
elsif ( choiceEntry =~ /Opt-MainWall/ )
if ( tag =~ /OPT-H2K-CodeName/ && value != "NA" )
# If this surface type code name exists in the code library, use the code
# (either Fav or UsrDef) for all surfaces. Code names in library are unique.
# Note: Not using "Standard", non-library codes (e.g., 2221292000)
# Look for this code name in code library (Favorite and UserDefined)
thisCodeInHouse = false
useThisCodeID = "Code 89"
foundFavLibCode = false
foundUsrDefLibCode = false
foundCodeLibElement = ""
locationCodeFavText = "Codes/Wall/Favorite/Code"
h2kCodeElements.each(locationCodeFavText) do |codeElement|
if ( codeElement.get_text("Label") == value )
foundFavLibCode = true
foundCodeLibElement = Marshal.load(Marshal.dump(codeElement))
break
end
end
# Code library names are also unique across Favorite and User Defined codes
if ( ! foundFavLibCode )
locationCodeUsrDefText = "Codes/Wall/UserDefined/Code"
h2kCodeElements.each(locationCodeUsrDefText) do |codeElement|
if ( codeElement.get_text("Label") == value )
foundUsrDefLibCode = true
foundCodeLibElement = Marshal.load(Marshal.dump(codeElement))