Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
uvahotspot
GitHub Repository: uvahotspot/HotSpot
Path: blob/master/scripts/hsconvert-flp.pl
612 views
1
#!/usr/bin/perl
2
3
# program to sanitize a floorplan with high aspect ratio blocks
4
# by chopping up of those blocks
5
6
# use warnings;
7
8
#params
9
$threshold = 1.0;
10
11
sub usage {
12
print("usage: hsconvert-flp.pl [-a <aspect ratio>] <file>\n");
13
print("sub-divides the high-aspect-ratio blocks and prints the resultant floorplan to stdout\n");
14
print("[-a <aspect ratio>] -- approx aspect ratio threshold above which to sub-divide blocks (default 1.0)\n");
15
print("<file> -- input floorplan file (eg: ev6.flp.orig)\n");
16
exit(1);
17
}
18
19
usage() if (@ARGV > 3 || !@ARGV % 2 || ! -f $ARGV[@ARGV-1]);
20
21
for($i=0; $i < @ARGV-1; $i+=2) {
22
if ($ARGV[$i] eq "-a") {
23
$threshold=$ARGV[$i+1];
24
($threshold >= 1) || die("error: aspect ratio should be >= 1\n");
25
next;
26
}
27
28
usage();
29
}
30
31
open (FILE, "<$ARGV[@ARGV-1]") || die("error: file $ARGV[@ARGV-1] could not be opened for reading\n");
32
while (<FILE>) {
33
# skip comments and empty lines
34
if (/^\s*#|^\s*$/) {
35
print;
36
next;
37
}
38
39
chomp;
40
@strs = split(/\s+/);
41
die ("error: wrong floorplan input format\n") if (@strs != 3 && @strs != 5);
42
43
# block dimensions
44
if (@strs == 5) {
45
($name, $width, $height, $leftx, $bottomy) = @strs;
46
$aspect = $height / $width;
47
$vertical = 1;
48
if ($aspect < 1) {
49
$aspect = 1.0 / $aspect;
50
$vertical = 0;
51
}
52
53
# block sub-division
54
if ($aspect > $threshold) {
55
$factor = int($aspect/$threshold + 0.5);
56
# only one block after sub-division
57
if ($factor <= 1) {
58
print join("\t", @strs)."\n";
59
next;
60
}
61
$chopcount{$name} = $factor;
62
if ($vertical) {
63
$height /= $factor;
64
} else {
65
$width /= $factor;
66
}
67
for($i=0; $i < $factor; $i++) {
68
printf($name."_".$i."\t%.6f\t%.6f\t%.6f\t%.6f\n", $width, $height, $leftx, $bottomy);
69
if($vertical) {
70
$bottomy += $height;
71
} else {
72
$leftx += $width;
73
}
74
}
75
# no need to sub-divide, print as-is
76
} else {
77
print join("\t", @strs)."\n";
78
}
79
# connectivity information
80
} elsif(@strs == 3) {
81
($name1, $name2, $density) = @strs;
82
$count1 = $chopcount{$name1};
83
$count2 = $chopcount{$name2};
84
# update connectivity for sub-divided blocks
85
if ($count1 && $count2) {
86
for($i=0; $i < $count1; $i++) {
87
for($j=0; $j < $count2; $j++) {
88
printf($name1."_".$i."\t".$name2."_".$j."\t%.3f\n", $density);
89
}
90
}
91
} elsif($count1) {
92
for($i=0; $i < $count1; $i++) {
93
printf($name1."_".$i."\t".$name2."\t%.3f\n", $density);
94
}
95
} elsif ($count2) {
96
for($i=0; $i < $count2; $i++) {
97
printf($name1."\t".$name2."_".$i."\t%.3f\n", $density);
98
}
99
# print as-is
100
} else {
101
print join("\t", @strs)."\n";
102
}
103
}
104
}
105
close(FILE);
106
107
108