Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
uvahotspot
GitHub Repository: uvahotspot/HotSpot
Path: blob/master/scripts/grid_thermal_map.pl
612 views
1
#!/usr/bin/perl -w
2
#This script helps to generate an SVG figure.
3
#(More informaiton about SVG can be found at http://www.w3.org/TR/SVG/).
4
#SVG figures can be zoomed without losing resolutions.
5
#
6
#USAGE: grid_thermal_map.pl <flp_file> <grid_temp_file> > <filename>.svg
7
#
8
#Use IE or SVG Viewer to open "<filename>.svg". May need to enable XML
9
#in your IE. Also, in Linux, ImageMagick 'convert' could be used to convert
10
#it to other file formats
11
#(eg `convert -font Helvetica <filename>.svg <filename>.pdf`).
12
#
13
#Inputs:
14
# (1) A floorplan file with the same format as the other HotSpot .flp files.
15
# (2) A list of grid temperatures, with the format of each line:
16
# <grid_number> <grid_temperature>
17
# Example floorplan file (example.flp) and the corresponding grid
18
# temperature file (example.t) are inlcuded in this release. The resulting
19
# SVG figure (example.svg) is also included.
20
#
21
#Acknowledgement: The HotSpot developers would like to thank Joshua Rosenbluh
22
#at Grinnell College, Iowa, for his information and help on the SVG figures.
23
24
use strict;
25
26
sub usage () {
27
print("usage: grid_thermal_map.pl <flp_file> <grid_steady_file> > <filename>.svg (or)\n");
28
print(" grid_thermal_map.pl <flp_file> <grid_steady_file> <rows> <cols> > <filename>.svg\n");
29
print(" grid_thermal_map.pl <flp_file> <grid_steady_file> <rows> <cols> <min> <max> > <filename>.svg\n");
30
print("prints an 'SVG' format visual thermal map to stdout\n");
31
print("<flp_file> -- path to the file containing the floorplan (eg: ev6.flp)\n");
32
print("<grid_steady_file> -- path to the grid temperatures file (eg: sample.grid.steady)\n");
33
print("<rows> -- no. of rows in the grid (default 64)\n");
34
print("<cols> -- no. of columns in the grid (default 64)\n");
35
print("<min> -- min. temperature of the scale (defaults to min. from <grid_temp_file>)\n");
36
print("<max> -- max. temperature of the scale (defaults to max. from <grid_temp_file>)\n");
37
exit(1);
38
}
39
40
&usage() if (@ARGV != 2 && @ARGV != 4 && @ARGV != 6 || ! -f $ARGV[0] || ! -f $ARGV[1]);
41
42
#constants used throughout the program
43
my $num_levels=21; #number of colors used
44
my $max_rotate=200; #maximum hue rotation
45
my $floor_map_path=$ARGV[0];#path to the file containing floorplan
46
my $temp_map_path=$ARGV[1]; #path to the grid temperature file
47
my $stroke_coeff=10**-7; #used to tune the stroke-width
48
my $stroke_opacity=0; #used to control the opacity of the floor plan
49
my $smallest_shown=10000; #fraction of the entire chip necessary to see macro
50
my $zoom=10**6;
51
my $in_minx=0; my $in_miny=0; my $in_maxx=0; my $in_maxy=0;
52
my $txt_offset=100;
53
my $x_bound;
54
55
56
#variables used throughout the program
57
my $fp ;#the SVG to draw the floorplan
58
my $tm ;#the SVG to draw the thermal map
59
my $defs;#definitions
60
61
my $min_x=10**10;my $max_x=0;
62
my $min_y=10**10;my $max_y=0;
63
my $tot_x;my $tot_y;
64
65
#Specify grid row and column here
66
my $row=64; my $col=64;
67
if (@ARGV >= 4) {
68
$row = $ARGV[2];
69
$col = $ARGV[3];
70
}
71
72
# define my palette with 21 RGB colors, from red to green to blue
73
my @palette;
74
75
$palette[0]='255,0,0';
76
$palette[1]='255,51,0';
77
$palette[2]='255,102,0';
78
$palette[3]='255,153,0';
79
$palette[4]='255,204,0';
80
$palette[5]='255,255,0';
81
$palette[6]='204,255,0';
82
$palette[7]='153,255,0';
83
$palette[8]='102,255,0';
84
$palette[9]='51,255,0';
85
$palette[10]='0,255,0';
86
$palette[11]='0,255,51';
87
$palette[12]='0,255,102';
88
$palette[13]='0,255,153';
89
$palette[14]='0,255,204';
90
$palette[15]='0,255,255';
91
$palette[16]='0,204,255';
92
$palette[17]='0,153,255';
93
$palette[18]='0,102,255';
94
$palette[19]='0,51,255';
95
$palette[20]='0,0,255';
96
97
{#generate the SVG for the floorplan
98
99
#declare variables to be used locally
100
my @AoA_flp;#Array of arrays
101
my @AoA_grid;
102
my $min_t=1000;
103
my $max_t=0;
104
105
my $unit_cnt=0;
106
107
#this section reads the floor map file
108
{my $num='\s+([\d.]+)';my $dumb_num='\s+[\d.]+';
109
open(FP, "< $floor_map_path") or die "Couldn't open $floor_map_path for reading: $!\n";
110
#input file order: instance name, width, height, minx, miny
111
112
while (<FP>) {
113
if (/^(\S+)$num$num$num$num/)
114
{
115
$in_minx=$4*$zoom; $in_miny=$5*$zoom; $in_maxx=($4+$2)*$zoom; $in_maxy=($5+$3)*$zoom;
116
$min_x=$in_minx if $in_minx<$min_x;$max_x=$in_maxx if $in_maxx>$max_x;
117
$min_y=$in_miny if $in_miny<$min_y;$max_y=$in_maxy if $in_maxy>$max_y;
118
# $min_t=$6 if $6<$min_t;$max_t=$6 if $6>$max_t;
119
push @AoA_flp, [ ($1,$in_minx,$in_miny,$in_maxx,$in_maxy,$6) ] ;
120
}
121
}
122
123
close(FP);
124
}
125
$tot_x=$max_x-$min_x;
126
$tot_y=$max_y-$min_y;
127
$x_bound=$max_x*1.2;
128
129
my $grid_h=$tot_y/$row;
130
my $grid_w=$tot_x/$col;
131
my ($grid_minx,$grid_miny,$grid_maxx,$grid_maxy);
132
133
#this section reads the temperature map file
134
{my $num1='\s+([\d.]+)';my $dumb_num1='\s+[\d.]+';
135
open(TM, "< $temp_map_path") or die "Couldn't open $temp_map_path for reading: $!\n";
136
#input file order: grid#, temperature
137
138
while (<TM>) {
139
if (/^(\S+)$num1/)
140
{
141
$grid_minx=($1%$col)*$grid_w;
142
$grid_maxx=($1%$col+1)*$grid_w;
143
$grid_miny=(int($1/$col))*$grid_h;
144
$grid_maxy=(int($1/$col)+1)*$grid_h;
145
$min_t=$2 if $2<$min_t;$max_t=$2 if $2>$max_t;
146
push @AoA_grid, [ ($1,$grid_minx,$grid_miny,$grid_maxx,$grid_maxy,$2) ] ;
147
}
148
}
149
close(TM);
150
}
151
152
# if upper and lower limits need to be specified, do it here
153
if (@ARGV == 6) {
154
$min_t=$ARGV[4];
155
$max_t=$ARGV[5];
156
}
157
158
#draw the grid temperatures
159
$tm='<g id="floorplan" style="stroke: none; fill: red;">'."\n";
160
{
161
my ($w1,$h1, $level);
162
foreach (@AoA_grid){
163
$w1=(@{$_}[3])-(@{$_}[1]);
164
$h1=(@{$_}[4])-(@{$_}[2]);
165
if ($w1>$tot_x/$smallest_shown && $h1>$tot_y/$smallest_shown){
166
if ($max_t > $min_t) {
167
$level=int(($max_t-(@{$_}[5]))/($max_t-$min_t)*($num_levels-1));
168
} else {
169
$level = 0;
170
}
171
$tm.="\t".'<rect x="'.@{$_}[1] .'" y="'. @{$_}[2] .
172
'" width="'.$w1 .'" height="'.$h1 .
173
'" style="fill:rgb(' .$palette[$level].')" />'."\n";
174
}
175
}
176
}
177
178
#draw the floorplan
179
{
180
my ($w,$h, $start_y, $end_y, $txt_start_x, $txt_start_y);
181
foreach (@AoA_flp){
182
$unit_cnt += 1;
183
$w=(@{$_}[3])-(@{$_}[1]);
184
$h=(@{$_}[4])-(@{$_}[2]);
185
$start_y=$tot_y-@{$_}[2]-$h;
186
$end_y=$tot_y-@{$_}[2];
187
$txt_start_x=@{$_}[1]+$txt_offset;
188
$txt_start_y=$start_y+2*$txt_offset;
189
if ($w>$tot_x/$smallest_shown && $h>$tot_y/$smallest_shown){
190
$fp.="\t".'<line x1="'.@{$_}[1] .'" y1="'. $start_y .
191
'" x2="'. @{$_}[3] .'" y2="'. $start_y .
192
'" style="stroke:black;stroke-width:30" />'."\n";
193
194
$fp.="\t".'<line x1="'.@{$_}[1] .'" y1="'. $start_y .
195
'" x2="'. @{$_}[1] .'" y2="'. $end_y .
196
'" style="stroke:black;stroke-width:30" />'."\n";
197
198
$fp.="\t".'<line x1="'.@{$_}[3] .'" y1="'. $start_y .
199
'" x2="'. @{$_}[3] .'" y2="'. $end_y .
200
'" style="stroke:black;stroke-width:30" />'."\n";
201
202
$fp.="\t".'<line x1="'.@{$_}[1] .'" y1="'. $end_y .
203
'" x2="'. @{$_}[3] .'" y2="'. $end_y .
204
'" style="stroke:black;stroke-width:30" />'."\n";
205
206
$fp.="\t".'<text x="'.$txt_start_x .'" y="'. $txt_start_y .
207
'" fill="black" text_anchor="start" style="font-size:180" > '. @{$_}[0] .' </text>'."\n";
208
}
209
}
210
}
211
212
# draw the color scale bar
213
{
214
my $i;
215
my $txt_ymin;
216
my $w2=$max_x*0.05;
217
my $h2=$max_y*0.025;
218
my $clr_xmin=$max_x*1.1;
219
my $clr_ymin=$max_y*0.05;
220
my $scale_xmin=$max_x*1.05;
221
my $scale_value;
222
my $final_scale_value=$min_t+(1/$num_levels)*($max_t-$min_t);
223
$final_scale_value=~s/^(\d+)\.(\d)(\d)(\d)\d+/$1\.$2$3$4/;
224
225
for ($i=0; $i<$num_levels; $i++) {
226
if ($w2>$tot_x/$smallest_shown && $h2>$tot_y/$smallest_shown){
227
# $level=int(($max_t-(@{$_}[5]))/($max_t-$min_t)*($num_levels-1));
228
$fp.="\t".'<rect x="'.$clr_xmin .'" y="'. $clr_ymin .
229
'" width="'.$w2 .'" height="'.$h2 .
230
'" style="fill:rgb(' .$palette[$i].'); stroke:none" />'."\n";
231
if ($i%3==0) {
232
$txt_ymin=$clr_ymin+$h2*0.5;
233
$scale_value=($max_t-$min_t)*(1-$i/($num_levels-1))+$min_t;
234
$scale_value=~s/^(\d+)\.(\d)(\d)\d+/$1\.$2$3/;
235
$fp.="\t".'<text x="'.$scale_xmin .'" y="'. $txt_ymin.
236
'" fill="black" text_anchor="start" style="font-size:250" > '. $scale_value .' </text>'."\n";
237
}
238
}
239
$clr_ymin+=$h2;
240
}
241
$min_t=~s/^(\d+)\.(\d)(\d)\d+/$1\.$2$3/;
242
$fp.="\t".'<text x="'.$scale_xmin .'" y="'. $clr_ymin .
243
'" fill="black" text_anchor="start" style="font-size:250" > '. $min_t .' </text>'."\n";
244
}
245
246
$fp.="</g>\n";
247
}
248
#svg header and footer
249
my $svgheader= <<"SVG_HEADER";
250
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
251
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
252
<svg width="900px" height="500px"
253
viewBox="$min_x $min_y $x_bound $max_y">
254
<title>Sample Temperature Map For HotSpot Grid Model</title>
255
SVG_HEADER
256
257
my $svgfooter= <<"SVG_FOOTER";
258
</svg>
259
SVG_FOOTER
260
261
print $svgheader.$tm.$fp.$svgfooter;
262
#writes out the header, definitions, thermal map, floor plan and footer
263
264