Root/
Source at commit e62da4e created 10 years 4 months ago. By Werner Almesberger, cae-tools/cameo/fped2stl.pl (flush): substitute coordinates only once | |
---|---|
1 | #!/usr/bin/perl |
2 | # |
3 | # fped2stl.pl - Convert fped 2D stacks to STL meshes |
4 | # |
5 | # Written 2013 by Werner Almesberger |
6 | # Copyright 2013 Werner Almesberger |
7 | # |
8 | # This program is free software; you can redistribute it and/or modify |
9 | # it under the terms of the GNU General Public License as published by |
10 | # the Free Software Foundation; either version 2 of the License, or |
11 | # (at your option) any later version. |
12 | # |
13 | |
14 | |
15 | use POSIX; |
16 | |
17 | sub usage |
18 | { |
19 | print STDERR "usage: $0 prefix [file ...]\n\n"; |
20 | exit(1); |
21 | } |
22 | |
23 | |
24 | sub flush |
25 | { |
26 | local ($z1) = sprintf("%e", $_[0]); |
27 | |
28 | $z = sprintf("%e", $z); |
29 | return unless defined $s; |
30 | print STDERR "$name $z ...\n"; |
31 | $^F = 20; |
32 | pipe SR, SW; |
33 | pipe RR, RW; |
34 | $pid = fork(); |
35 | if (!$pid) { |
36 | close SW; |
37 | close RR; |
38 | $sn = fileno SR; |
39 | $rn = fileno RW; |
40 | open(PIPE, "|cameo >/dev/fd/$rn") || die "cameo: $!"; |
41 | print PIPE "gnuplot 0mm /dev/fd/$sn\n"; |
42 | print PIPE "stl\n"; |
43 | close PIPE; |
44 | exit; |
45 | } |
46 | close SR; |
47 | close RW; |
48 | |
49 | print SW $s; |
50 | close SW; |
51 | |
52 | while (<RR>) { |
53 | s/cameo/$name/; |
54 | s/(vertex.*)0\.0*e\+00$/$1$z/ || s/(vertex.*)1\.0*e\+00$/$1$z1/; |
55 | print; |
56 | } |
57 | close RR; |
58 | } |
59 | |
60 | |
61 | &usage if $ARGV[0] =~ /^-[^0-9]/; |
62 | |
63 | $pfx = shift @ARGV; |
64 | &usage unless defined $pfx; |
65 | |
66 | $skip = 1; |
67 | while (<>) { |
68 | if (/^# $pfx(.*?)-(\d+(\.\d*)?)\s*$/) { |
69 | &flush($2); |
70 | $name = $1; |
71 | $z = $2; |
72 | undef $s; |
73 | $skip = 0; |
74 | } elsif (/^# /) { |
75 | $skip = 1; |
76 | } |
77 | next if $skip; |
78 | next if /^#/; |
79 | $s .= $_; |
80 | } |
81 | &flush(0); |
82 |
Branches:
master