annotate fft/fftw/fftw-3.3.4/doc/FAQ/bfnnconv.pl @ 40:223f770b5341 kissfft-double tip

Try a double-precision kissfft
author Chris Cannam
date Wed, 07 Sep 2016 10:40:32 +0100
parents 26056e866c29
children
rev   line source
Chris@19 1 #!/usr/bin/perl --
Chris@19 2 # Copyright (C) 1993-1995 Ian Jackson.
Chris@19 3
Chris@19 4 # This file is free software; you can redistribute it and/or modify
Chris@19 5 # it under the terms of the GNU General Public License as published by
Chris@19 6 # the Free Software Foundation; either version 2, or (at your option)
Chris@19 7 # any later version.
Chris@19 8
Chris@19 9 # It is distributed in the hope that it will be useful,
Chris@19 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@19 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@19 12 # GNU General Public License for more details.
Chris@19 13
Chris@19 14 # You should have received a copy of the GNU General Public License
Chris@19 15 # along with GNU Emacs; see the file COPYING. If not, write to
Chris@19 16 # the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Chris@19 17 # Boston, MA 02111-1307, USA.
Chris@19 18
Chris@19 19 # (Note: I do not consider works produced using these BFNN processing
Chris@19 20 # tools to be derivative works of the tools, so they are NOT covered
Chris@19 21 # by the GPL. However, I would appreciate it if you credited me if
Chris@19 22 # appropriate in any documents you format using BFNN.)
Chris@19 23
Chris@19 24 @outputs=('ascii','info','html');
Chris@19 25
Chris@19 26 while ($ARGV[0] =~ m/^\-/) {
Chris@19 27 $_= shift(@ARGV);
Chris@19 28 if (m/^-only/) {
Chris@19 29 @outputs= (shift(@ARGV));
Chris@19 30 } else {
Chris@19 31 warn "unknown option `$_' ignored";
Chris@19 32 }
Chris@19 33 }
Chris@19 34
Chris@19 35 $prefix= $ARGV[0];
Chris@19 36 $prefix= 'stdin' unless length($prefix);
Chris@19 37 $prefix =~ s/\.bfnn$//;
Chris@19 38
Chris@19 39 if (open(O,"$prefix.xrefdb")) {
Chris@19 40 @xrefdb= <O>;
Chris@19 41 close(O);
Chris@19 42 } else {
Chris@19 43 warn "no $prefix.xrefdb ($!)";
Chris@19 44 }
Chris@19 45
Chris@19 46 $section= -1;
Chris@19 47 for $thisxr (@xrefdb) {
Chris@19 48 $_= $thisxr;
Chris@19 49 chop;
Chris@19 50 if (m/^Q (\w+) ((\d+)\.(\d+)) (.*)$/) {
Chris@19 51 $qrefn{$1}= $2;
Chris@19 52 $qreft{$1}= $5;
Chris@19 53 $qn2ref{$3,$4}= $1;
Chris@19 54 $maxsection= $3;
Chris@19 55 $maxquestion[$3]= $4;
Chris@19 56 } elsif (m/^S (\d+) /) {
Chris@19 57 $maxsection= $1;
Chris@19 58 $sn2title{$1}=$';
Chris@19 59 }
Chris@19 60 }
Chris@19 61
Chris@19 62 open(U,">$prefix.xrefdb-new");
Chris@19 63
Chris@19 64 for $x (@outputs) { require("m-$x.pl"); }
Chris@19 65
Chris@19 66 &call('init');
Chris@19 67
Chris@19 68 while (<>) {
Chris@19 69 chop;
Chris@19 70 next if m/^\\comment\b/;
Chris@19 71 if (!m/\S/) {
Chris@19 72 &call('endpara');
Chris@19 73 next;
Chris@19 74 }
Chris@19 75 if (s/^\\section +//) {
Chris@19 76 $line= $_;
Chris@19 77 $section++; $question=0;
Chris@19 78 print U "S $section $line\n";
Chris@19 79 $|=1; print "S$section",' 'x10,"\r"; $|=0;
Chris@19 80 &call('endpara');
Chris@19 81 &call('startmajorheading',"$section",
Chris@19 82 "Section $section",
Chris@19 83 $section<$maxsection ? "Section ".($section+1) : '',
Chris@19 84 $section>1 ? 'Section '.($section-1) : 'Top');
Chris@19 85 &text($line);
Chris@19 86 &call('endmajorheading');
Chris@19 87 if ($section) {
Chris@19 88 &call('endpara');
Chris@19 89 &call('startindex');
Chris@19 90 for $thisxr (@xrefdb) {
Chris@19 91 $_= $thisxr;
Chris@19 92 chop;
Chris@19 93 if (m/^Q (\w+) (\d+)\.(\d+) (.*)$/) {
Chris@19 94 $ref= $1; $num1= $2; $num2= $3; $text= $4;
Chris@19 95 next unless $num1 == $section;
Chris@19 96 &call('startindexitem',$ref,"Q$num1.$num2","Question $num1.$num2");
Chris@19 97 &text($text);
Chris@19 98 &call('endindexitem');
Chris@19 99 }
Chris@19 100 }
Chris@19 101 &call('endindex');
Chris@19 102 }
Chris@19 103 } elsif (s/^\\question \d{2}[a-z]{3}((:\w+)?) +//) {
Chris@19 104 $line= $_;
Chris@19 105 $question++;
Chris@19 106 $qrefstring= $1;
Chris@19 107 $qrefstring= "q_${section}_$question" unless $qrefstring =~ s/^://;
Chris@19 108 print U "Q $qrefstring $section.$question $line\n";
Chris@19 109 $|=1; print "Q$section.$question",' 'x10,"\r"; $|=0;
Chris@19 110 &call('endpara');
Chris@19 111 &call('startminorheading',$qrefstring,
Chris@19 112 "Question $section.$question",
Chris@19 113 $question < $maxquestion[$section] ? "Question $section.".($question+1) :
Chris@19 114 $section < $maxsection ? "Question ".($section+1).".1" : '',
Chris@19 115 $question > 1 ? "Question $section.".($question-1) :
Chris@19 116 $section > 1 ? "Question ".($section-1).'.'.($maxquestion[$section-1]) :
Chris@19 117 'Top',
Chris@19 118 "Section $section");
Chris@19 119 &text("Question $section.$question. $line");
Chris@19 120 &call('endminorheading');
Chris@19 121 } elsif (s/^\\only +//) {
Chris@19 122 @saveoutputs= @outputs;
Chris@19 123 @outputs=();
Chris@19 124 for $x (split(/\s+/,$_)) {
Chris@19 125 push(@outputs,$x) if grep($x eq $_, @saveoutputs);
Chris@19 126 }
Chris@19 127 } elsif (s/^\\endonly$//) {
Chris@19 128 @outputs= @saveoutputs;
Chris@19 129 } elsif (s/^\\copyto +//) {
Chris@19 130 $fh= $';
Chris@19 131 while(<>) {
Chris@19 132 last if m/^\\endcopy$/;
Chris@19 133 while (s/^([^\`]*)\`//) {
Chris@19 134 print $fh $1;
Chris@19 135 m/([^\\])\`/ || warn "`$_'";
Chris@19 136 $_= $';
Chris@19 137 $cmd= $`.$1;
Chris@19 138 $it= `$cmd`; chop $it;
Chris@19 139 print $fh $it;
Chris@19 140 }
Chris@19 141 print $fh $_;
Chris@19 142 }
Chris@19 143 } elsif (m/\\index$/) {
Chris@19 144 &call('startindex');
Chris@19 145 for $thisxr (@xrefdb) {
Chris@19 146 $_= $thisxr;
Chris@19 147 chop;
Chris@19 148 if (m/^Q (\w+) (\d+\.\d+) (.*)$/) {
Chris@19 149 $ref= $1; $num= $2; $text= $3;
Chris@19 150 &call('startindexitem',$ref,"Q$num","Question $num");
Chris@19 151 &text($text);
Chris@19 152 &call('endindexitem');
Chris@19 153 } elsif (m/^S (\d+) (.*)$/) {
Chris@19 154 $num= $1; $text= $2;
Chris@19 155 next unless $num;
Chris@19 156 &call('startindexmainitem',"s_$num",
Chris@19 157 "Section $num.","Section $num");
Chris@19 158 &text($text);
Chris@19 159 &call('endindexitem');
Chris@19 160 } else {
Chris@19 161 warn $_;
Chris@19 162 }
Chris@19 163 }
Chris@19 164 &call('endindex');
Chris@19 165 } elsif (m/^\\call-(\w+) +(\w+)\s*(.*)$/) {
Chris@19 166 $fn= $1.'_'.$2;
Chris@19 167 eval { &$fn($3); };
Chris@19 168 warn $@ if length($@);
Chris@19 169 } elsif (m/^\\call +(\w+)\s*(.*)$/) {
Chris@19 170 eval { &call($1,$2); };
Chris@19 171 warn $@ if length($@);
Chris@19 172 } elsif (s/^\\set +(\w+)\s*//) {
Chris@19 173 $svalue= $'; $svari= $1;
Chris@19 174 eval("\$user_$svari=\$svalue"); $@ && warn "setting $svalue failed: $@\n";
Chris@19 175 } elsif (m/^\\verbatim$/) {
Chris@19 176 &call('startverbatim');
Chris@19 177 while (<>) {
Chris@19 178 chop;
Chris@19 179 last if m/^\\endverbatim$/;
Chris@19 180 &call('verbatim',$_);
Chris@19 181 }
Chris@19 182 &call('endverbatim');
Chris@19 183 } else {
Chris@19 184 s/\.$/\. /;
Chris@19 185 &text($_." ");
Chris@19 186 }
Chris@19 187 }
Chris@19 188
Chris@19 189 print ' 'x25,"\r";
Chris@19 190 &call('finish');
Chris@19 191 rename("$prefix.xrefdb-new","$prefix.xrefdb") || warn "rename xrefdb: $!";
Chris@19 192 exit 0;
Chris@19 193
Chris@19 194
Chris@19 195 sub text {
Chris@19 196 local($in,$rhs,$word,$refn,$reft,$fn,$style);
Chris@19 197 $in= "$holdover$_[0]";
Chris@19 198 $holdover= '';
Chris@19 199 while ($in =~ m/\\/) {
Chris@19 200 #print STDERR ">$`##$'\n";
Chris@19 201 $rhs=$';
Chris@19 202 &call('text',$`);
Chris@19 203 $_= $rhs;
Chris@19 204 if (m/^\w+ $/) {
Chris@19 205 $holdover= "\\$&";
Chris@19 206 $in= '';
Chris@19 207 } elsif (s/^fn\s+([^\s\\]*\w)//) {
Chris@19 208 $in= $_;
Chris@19 209 $word= $1;
Chris@19 210 &call('courier');
Chris@19 211 &call('text',$word);
Chris@19 212 &call('endcourier');
Chris@19 213 } elsif (s/^tab\s+(\d+)\s+//) {
Chris@19 214 $in= $_; &call('tab',$1);
Chris@19 215 } elsif (s/^nl\s+//) {
Chris@19 216 $in= $_; &call('newline');
Chris@19 217 } elsif (s/^qref\s+(\w+)//) {
Chris@19 218 $refn= $qrefn{$1};
Chris@19 219 $reft= $qreft{$1};
Chris@19 220 if (!length($refn)) {
Chris@19 221 warn "unknown question `$1'";
Chris@19 222 }
Chris@19 223 $in= "$`\\pageref:$1:$refn:$reft\\endpageref.$_";
Chris@19 224 } elsif (s/^pageref:(\w+):([^:\n]+)://) {
Chris@19 225 $in= $_;
Chris@19 226 &call('pageref',$1,$2);
Chris@19 227 } elsif (s/^endpageref\.//) {
Chris@19 228 $in= $_; &call('endpageref');
Chris@19 229 } elsif (s/^(\w+)\{//) {
Chris@19 230 $in= $_; $fn= $1;
Chris@19 231 eval { &call("$fn"); };
Chris@19 232 if (length($@)) { warn $@; $fn= 'x'; }
Chris@19 233 push(@styles,$fn);
Chris@19 234 } elsif (s/^\}//) {
Chris@19 235 $in= $_;
Chris@19 236 $fn= pop(@styles);
Chris@19 237 if ($fn ne 'x') { &call("end$fn"); }
Chris@19 238 } elsif (s/^\\//) {
Chris@19 239 $in= $_;
Chris@19 240 &call('text',"\\");
Chris@19 241 } elsif (s,^(\w+)\s+([-A-Za-z0-9.\@:/]*\w),,) {
Chris@19 242 #print STDERR "**$&**$_\n";
Chris@19 243 $in= $_;
Chris@19 244 $style=$1; $word= $2;
Chris@19 245 &call($style);
Chris@19 246 &call('text',$word);
Chris@19 247 &call("end$style");
Chris@19 248 } else {
Chris@19 249 warn "unknown control `\\$_'";
Chris@19 250 $in= $_;
Chris@19 251 }
Chris@19 252 }
Chris@19 253 &call('text',$in);
Chris@19 254 }
Chris@19 255
Chris@19 256
Chris@19 257 sub call {
Chris@19 258 local ($fnbase, @callargs) = @_;
Chris@19 259 local ($coutput);
Chris@19 260 for $coutput (@outputs) {
Chris@19 261 if ($fnbase eq 'text' && eval("\@${coutput}_cmds")) {
Chris@19 262 #print STDERR "special handling text (@callargs) for $coutput\n";
Chris@19 263 $evstrg= "\$${coutput}_args[\$#${coutput}_args].=\"\@callargs\"";
Chris@19 264 eval($evstrg);
Chris@19 265 length($@) && warn "call adding for $coutput (($evstrg)): $@";
Chris@19 266 } else {
Chris@19 267 $fntc= $coutput.'_'.$fnbase;
Chris@19 268 &$fntc(@callargs);
Chris@19 269 }
Chris@19 270 }
Chris@19 271 }
Chris@19 272
Chris@19 273
Chris@19 274 sub recurse {
Chris@19 275 local (@outputs) = $coutput;
Chris@19 276 local ($holdover);
Chris@19 277 &text($_[0]);
Chris@19 278 }
Chris@19 279
Chris@19 280
Chris@19 281 sub arg {
Chris@19 282 #print STDERR "arg($_[0]) from $coutput\n";
Chris@19 283 $cmd= $_[0];
Chris@19 284 eval("push(\@${coutput}_cmds,\$cmd); push(\@${coutput}_args,'')");
Chris@19 285 length($@) && warn "arg setting up for $coutput: $@";
Chris@19 286 }
Chris@19 287
Chris@19 288 sub endarg {
Chris@19 289 #print STDERR "endarg($_[0]) from $coutput\n";
Chris@19 290 $evstrg= "\$${coutput}_cmd= \$cmd= pop(\@${coutput}_cmds); ".
Chris@19 291 "\$${coutput}_arg= \$arg= pop(\@${coutput}_args); ";
Chris@19 292 eval($evstrg);
Chris@19 293 length($@) && warn "endarg extracting for $coutput (($evstrg)): $@";
Chris@19 294 #print STDERR ">call $coutput $cmd $arg< (($evstrg))\n";
Chris@19 295 $evstrg= "&${coutput}_do_${cmd}(\$arg)";
Chris@19 296 eval($evstrg);
Chris@19 297 length($@) && warn "endarg running ${coutput}_do_${cmd} (($evstrg)): $@";
Chris@19 298 }