Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
uvahotspot
GitHub Repository: uvahotspot/HotSpot
Path: blob/master/scripts/3Dfig.pl
612 views
1
#!/usr/bin/perl
2
3
# program to convert the floorplan file and FIG-like output
4
# of HotSpot into a FIG file
5
6
#use warnings;
7
8
#params
9
#$maxx = 12600;
10
#$maxy = 9600;
11
$maxx = 9600;
12
$maxy = 12600;
13
$res = 1200;
14
#aspect ratio of blocks to give vertical labels
15
$skinny = 3;
16
17
sub usage () {
18
print("usage: 3Dfig.pl [-a <area ratio>] [-f <fontsize>] [-s <nskip>] <file>\n");
19
print("Reads in a layer configuration file and creates a .FIG file for each floorplan listed.\n");
20
print("Requires that all referenced files are in the same directory as 3Dfig.pl.\n");
21
print("[-a <area ratio>] -- approx page occupancy by figure (default 0.95)\n");
22
print("[-f <fontsize>] -- font size to be used (default 10)\n");
23
print("[-s <nskip>] -- no. of entries to be skipped in input (default 0)\n");
24
print("<file> -- input .lcf file (eg: example.lcf)\n");
25
exit(1);
26
}
27
28
&usage() if (@ARGV > 7 || !@ARGV % 2 || ! -f $ARGV[@ARGV-1]);
29
30
$occupancy = 0.95;
31
$fontsize = 10;
32
$nskip = 0;
33
34
for($i=0; $i < @ARGV-1; $i+=2) {
35
if ($ARGV[$i] eq "-a") {
36
$occupancy=$ARGV[$i+1];
37
next;
38
}
39
40
if ($ARGV[$i] eq "-f") {
41
$fontsize=$ARGV[$i+1];
42
next;
43
}
44
45
if ($ARGV[$i] eq "-s") {
46
$nskip=$ARGV[$i+1];
47
next;
48
}
49
50
&usage();
51
exit(1);
52
}
53
54
open (LCFFILE, "<$ARGV[@ARGV-1]") || die("error: file $ARGV[@ARGV-1] could not be opened\n");
55
while(<LCFFILE>){
56
next if (/^\s*#|^\s*$/);
57
my($line) = $_;
58
chomp($line);
59
# Remove ^m DOS ending #
60
$str =~ s/\r//g;
61
next unless ($line =~ m/\.flp$/);
62
push(@infile,$line);
63
}
64
close(LCFFILE);
65
$numfiles = @infile;
66
67
68
for($i = 0;$i<$numfiles;$i++){
69
$fileout = substr($infile[$i],0,-3);
70
$fileout = "$fileout"."fig";
71
push(@outfiles,$fileout);
72
# print "$fileout\n";
73
}
74
75
76
for($k=0;$k<$numfiles;$k++){
77
print $outfiles[$k] . "\n";
78
# print $infile[$k] . "\n";
79
# print $numfiles . "\n";
80
81
open (OUTFILE,">$outfiles[$k]")|| die("error: file $outfiles[$k] could not be opened\n");
82
open (FILE, "<$infile[$k]") || die("error: file $infile[$k] could not be opened\n");
83
#open (OUTFILE,">$fileout");
84
#open (FILE, "<$ARGV[@ARGV-1]") || die("error: file $ARGV[@ARGV-1] could not be opened\n");
85
$maxfig = -inf;
86
$minfig = inf;
87
$figinput = 0;
88
while (<FILE>) {
89
if (/FIG starts/) {
90
$figinput = 1;
91
last;
92
}
93
}
94
95
# This is a HotSpot floorplan file and not an output of print_flp_fig.
96
# So let us generate the print_flp_fig output ourselves and save it in a
97
# temporary file.
98
if (!$figinput) {
99
seek(FILE, 0, 0);
100
$timestamp = time();
101
$file = "$infile[$i].$timestamp";
102
open(NEWFILE, ">$file") || die("error: file $file could not be created\n");
103
print(NEWFILE "FIG starts\n");
104
while (<FILE>) {
105
# skip comments and empty lines
106
next if (/^\s*#|^\s*$/);
107
chomp;
108
@strs = split(/\s+/);
109
$size = @strs;
110
if (@strs != 3 && @strs != 5 && @strs !=7) {
111
unlink($file);
112
die ("error: wrong floorplan input format\n");
113
}
114
# skip connectivity information
115
next if (@strs == 3);
116
($name, $width, $height, $leftx, $bottomy, $sheat, $resist) = @strs;
117
$rightx = $leftx + $width;
118
$topy = $bottomy + $height;
119
$size = @strs;
120
if($size==7){
121
printf(NEWFILE "%.16f %.16f %.16f %.16f %.16f %.16f %.16f %.16f %.16f %.16f %.16f %.16f\n",
122
$leftx, $bottomy, $leftx, $topy, $rightx, $topy, $rightx, $bottomy,
123
$leftx, $bottomy, $sheat, $resist);
124
} else {
125
printf(NEWFILE "%.16f %.16f %.16f %.16f %.16f %.16f %.16f %.16f %.16f %.16f\n",
126
$leftx, $bottomy, $leftx, $topy, $rightx, $topy, $rightx, $bottomy,
127
$leftx, $bottomy);
128
}
129
130
printf(NEWFILE "%s\n", $name);
131
}
132
print(NEWFILE "FIG ends\n");
133
close(NEWFILE);
134
close(FILE);
135
open(FILE, "<$file") || die("error: file $file could not be opened\n");
136
while (<FILE>) {
137
last if (/FIG starts/);
138
}
139
}
140
141
$pos=tell(FILE);
142
$j=0;
143
while (<FILE>) {
144
last if (/FIG ends/);
145
next if (/[a-zA-Z_]|^\s*$/);
146
if ($j < $nskip) {
147
$j++;
148
next;
149
}
150
chomp;
151
@nums = split(/\s+/);
152
$numsize = @nums;
153
# print "@nums Size:$numsize\n";
154
if($numsize==12){
155
$tempResist = pop(@nums);
156
$tempSheat = pop(@nums);
157
}
158
159
for ($i=0; $i < @nums; $i++) {
160
$maxfig = $nums[$i] if ($nums[$i] > $maxfig);
161
$minfig = $nums[$i] if ($nums[$i] < $minfig);
162
}
163
if($numsize==12){
164
push(@nums,$tempSheat);
165
push(@nums,$tempResist);
166
}
167
168
}
169
170
$maxfig-=$minfig;
171
$scale = (($maxx < $maxy)?$maxx:$maxy) / $maxfig * sqrt($occupancy);
172
$xorig = ($maxx-$maxfig*$scale)/2;
173
$yorig = ($maxy-$maxfig*$scale)/2;
174
175
print OUTFILE "#FIG 3.1\nPortrait\nCenter\nInches\n$res 2\n";
176
seek(FILE, $pos, 0);
177
178
$j=0;
179
while (<FILE>) {
180
last if (/FIG ends/);
181
if ($j < $nskip * 2) {
182
$j++;
183
next;
184
}
185
chomp;
186
@coords = split(/\s+/);
187
$size = @coords;
188
if($size==12){
189
$resist = pop(@coords);
190
$sheat=pop(@coords);
191
}
192
next if ($#coords == -1);
193
@coords = map($_-$minfig, @coords);
194
@coords = map($_*$scale, @coords);
195
$leftx = $rightx = $coords[0];
196
$bottomy = $topy = $coords[1];
197
for($i=2; $i < @coords; $i++) {
198
if ($i % 2) {
199
$bottomy = $coords[$i] if ($coords[$i] < $bottomy);
200
$topy = $coords[$i] if ($coords[$i] > $topy);
201
} else {
202
$leftx = $coords[$i] if ($coords[$i] < $leftx);
203
$rightx = $coords[$i] if ($coords[$i] > $rightx);
204
}
205
}
206
for ($i=0; $i < @coords; $i++) {
207
if ($i % 2) {
208
$coords[$i] = int($maxy - $coords[$i] - $yorig);
209
}
210
else {
211
$coords[$i] = int($coords[$i] + $xorig);
212
}
213
}
214
printf OUTFILE ("2 2 0 1 -1 7 0 0 -1 0.000 0 0 0 0 0 %d\n", int (@coords)/2);
215
print OUTFILE "\t@coords\n";
216
$xpos = int($xorig + ($leftx + $rightx) / 2.0);
217
$ypos = int($maxy - ($bottomy + $topy) / 2.0 - $yorig);
218
$angle = 0;
219
$angle = 1.5708 if (($topy - $bottomy) > $skinny * ($rightx - $leftx));
220
$name = <FILE>;
221
chomp($name);
222
print OUTFILE "4 1 -1 0 0 0 $fontsize $angle 4 -1 -1 $xpos $ypos $name\\001\n";
223
if($resist!=0 && $sheat!=0){
224
$ypos = $ypos + $fontsize + 100;
225
print OUTFILE "4 1 -1 0 0 0 $fontsize $angle 4 -1 -1 $xpos $ypos ";
226
printf OUTFILE ("Resistivity:%.3f\\001\n",$resist);
227
$ypos = $ypos + 2*$fontsize + 100;
228
print OUTFILE "4 1 -1 0 0 0 $fontsize $angle 4 -1 -1 $xpos $ypos ";
229
printf OUTFILE ("Specific Heat:%.3f\\001\n",$sheat);
230
}
231
$resist = 0;
232
$sheat = 0;
233
}
234
close(FILE);
235
close(OUTFILE);
236
237
238
# delete the temporary file created
239
unlink ($file) if (!$figinput);
240
}
241
242