forked from NRCan-IETS-CE-O-HBC/HTAP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart-substitute.rb
More file actions
251 lines (161 loc) · 5.13 KB
/
start-substitute.rb
File metadata and controls
251 lines (161 loc) · 5.13 KB
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
#!/usr/bin/env ruby
# Ruby implementation of 'start-substiture.pl'
require 'optparse'
require 'fileutils'
=begin rdoc
=========================================================================================
METHODS: Routines called in this file must be defined before use in Ruby
(can't put at bottom of listing).
=========================================================================================
=end
def fatalerror( err_msg )
# Display a fatal error and quit. -----------------------------------
if ($gTest_params["logfile"])
$fLOG.write("\nsubstitute-h2k.rb -> Fatal error: \n")
$fLOG.write("#{err_msg}\n")
end
print "\n=========================================================\n"
print "substitute-h2k.rb -> Fatal error: \n\n"
print " #{err_msg}\n"
print "\n\n"
print "substitute-h2k.rb -> Other Error or warning messages:\n\n"
print "#{$ErrorBuffer}\n"
exit() # Run stopped
end
$help_msg = "
start-substitute.rb:
This script searches through the supplied command line argument file
and creates one choice file per row in the supplied csv file.
use: ./start-substitute.rb param1
where: param1 = GenOpt-picked-these-choices.GO-tmp
"
$welcome_msg = "
start-substitute.rb:
"
if ARGV.empty? then
puts $help_msg
exit()
else
puts $welcome_msg
end
options = {}
optparse = OptionParser.new do |opts|
opts.banner = $help_msg
opts.on("-h", "--help", "Displays help") do
puts opts
exit
end
end.parse!
$GenOptChoices = ""
ARGV.each do |f|
$GenOptChoices = f
end
$MasterPath = Dir.getwd()
$LogFile = "#{$MasterPath}\\Start-SubstituteRb-log.txt"
$ChoiceFLDir = "."
# Log file
fLOG = File.new($LogFile,"w")
if fLOG == nil then
fatalerror (" Could not open #{$LogFile}.\n")
end
fLOG.write(" --- start-substitute.rb log start ---\n")
# Choice file - open...
fGenOptChoices = File.new( $GenOptChoices, "r" )
if fGenOptChoices == nil then
fatalerror (" Could not open #{$GenOptChoices} \n")
end
$linecount = 0
# ...and parse...
while !fGenOptChoices.eof? do
$linecount = $linecount + 1
$line = fGenOptChoices.readline
$line.strip!
$line.gsub!(/\!.*$/, '') # Removes comments
$line.gsub!(/\s*/, '') # Removes mid-line white space
if ( $linecount < 10 ) then
$lineSTR = " #{$linecount}"
else
$lineSTR = "#{$linecount}"
end
if ( $line !~ /^\s*$/ )
puts "|#{$lineSTR}|" << $line
lineTokenValue = $line.split(':')
$token = lineTokenValue[0]
$value = lineTokenValue[1]
if ($token =~ /Opt-ChoiceFileName/ )
$choiceFileName = $value
fLOG.write (" Choice file is #{$choiceFileName} \n");
end
if ($token =~ /Location/ )
$Location = $value
fLOG.write (" Location is #{$Location} \n");
end
if ($token =~ /HeatCool-Control/ )
$HC_ctl = $value
fLOG.write (" HC-ctl is #{$HC_ctl} \n");
end
if ($token =~ /HRV_ctl/ )
$hrvctl = $value
fLOG.write (" HRV-ctl is #{$hrvctl} \n");
end
if ($token =~ /ElecLoadScale/ )
$ElecLoad = $value
fLOG.write (" ElecLoad is #{$ElecLoad} \n");
end
if ($token =~ /DHWLoadScale/ )
$DHWLoad = $value
fLOG.write (" DHWLoad is #{$DHWLoad} \n");
end
if ($token =~ /OptionsFile/ )
$OptionsFile = $value
fLOG.write (" Options are #{$OptionsFile} \n");
end
if ($token =~ /Archetype/ )
$Archetype = $value
fLOG.write (" Archetype is #{$Archetype} \n");
end
end
end
fGenOptChoices.close
fLOG.write " The current directory is : #{$MasterPath} \n"
FileUtils.copy("#{$choiceFileName}",".\\")
fChoiceFileContent = File.new(".\\#{$choiceFileName}","r")
if fChoiceFileContent == nil then
fatalerror (" Could not open #{$choiceFileName} \n")
end
fLOG.write(" Reading from .\\#{$choiceFileName}\n")
$line_edits = ""
while !fChoiceFileContent.eof? do
$line = fChoiceFileContent.readline
$line = $line.gsub(/<LOCATION>/,$Location)
#puts "|| #{$line}\n"
$line_edits << $line
end
puts "===================== output will look like =============================="
puts $line_edits
puts "--------------------- end output -----------------------------------------"
fChoiceFileContent.close
fChoiceFileContentEdited = File.new(".\\#{$choiceFileName}-edit","w")
if fChoiceFileContentEdited == nil then
fatalerror (" Could not open #{$choiceFileName}-edit \n")
end
fChoiceFileContentEdited.write($line_edits)
fChoiceFileContentEdited.close
$cmd = "ruby C:\\HTAP\\substitute-h2k.rb -vv -c #{$choiceFileName}-edit -o #{$OptionsFile} "
fLOG.write("CMD: #{$cmd}\n")
pid = Process.spawn($cmd)
Process.wait pid, 0
status = $?.exitstatus
#
#
#my $command = $ARGV[1]." ../substitute.pl -e -c $choiceFileName -o ../options-generic-GHG.options -b ./GenericHome-GHG -vv";
#
#print LOG "The command is: ".$command."\n";
#
#system ( $command );
#
#close ( LOG );
fLOG.write(" ---start-substitute.rb log end -----\n\n")
puts "
start-substitute.rb done.
"