blib/lib/PDL/Graphics/IIS.pm untested

filter: Statementstmt 0.0% 0 / 143 Branchbran 0.0% 0 / 76 Conditioncond 0.0% 0 / 29 MC/DCmcdc 0.0% 0 / 19 Subroutinesub 0.0% 0 / 16 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 291 CC 39 SCAR 41.8
CC
39
Cov
0%
findfifo
156.0
iis
110.0
iiscirc
30.0
CRAP 65.6
1 #
2 # GENERATED WITH PDL::PP from iis.pd! Don't modify!
3 #
4 package PDL::Graphics::IIS;
5  
6 our @EXPORT_OK = qw(iis iiscur iiscirc $stdimage $iisframe saoimage ximtool _iis _iiscirc );
7 our %EXPORT_TAGS = (Func=>\@EXPORT_OK);
8  
9 use PDL::Core;
10 use PDL::Exporter;
11 use DynaLoader;
12  
13  
14
15 our @ISA = ( 'PDL::Exporter','DynaLoader' );
16 push @PDL::Core::PP, __PACKAGE__;
17 bootstrap PDL::Graphics::IIS ;
18  
19  
20  
21  
22  
23  
24  
25  
26 #line 4 "iis.pd"
27  
28 =head1 NAME
29  
30 PDL::Graphics::IIS - Display PDL images on IIS devices (saoimage/ximtool)
31  
32 =head1 SYNOPSIS
33  
34 use PDL::Graphics::IIS;
35 saoimage ( -geometry => '800x800' );
36 iis rvals(100,100);
37  
38 =head1 DESCRIPTION
39  
40 This module provides an interface to any image display 'device' which support the
41 'IIS protocol' - viz the SAOimage and Ximtool X-windows programs, the
42 old SunView imtool program and presumably even the original IIS CRT itself
43 if they aren't all in museums!
44  
45 These programs should be familiar to astronomers - they are used by
46 the common IRAF system. The programs and their HTML documentation
47 can be obtained from the following URLs:
48  
49 SAOimage: http://tdc-www.harvard.edu/software/saoimage.html
50 Ximtool: http://iraf.noao.edu/iraf/web/projects/x11iraf/x11iraf.html
51  
52 Non-astronomers may find they quite nifty for displaying 2D data.
53  
54 The Perl variable C<$stdimage> is exported from the module and controls
55 the frame buffer configuration currently in use. The default value
56 is C<imt1024> which specifies a C<1024x1024> frame buffer. Other
57 values supported by the module are:
58
59 imt512, imt800, imt1024, imt1600, imt2048, and imt4096.
60  
61 If you have a F<$HOME/.imtoolrc> you can use it to specify other frame
62 buffer names and configurations in exactly the same way you can in
63 IRAF. Here is a sample file:
64  
65 -------------------snip-------------------------
66 # Format: configno nframes width height
67 1 2 512 512 # imt1|imt512
68 2 2 800 800 # imt2|imt800
69 3 2 1024 1024 # imt3|imt1024
70 4 1 1600 1600 # imt4|imt1600
71 5 1 2048 2048 # imt5|imt2048
72 6 1 4096 4096 # imt6|imt4096
73 7 1 8192 8192 # imt7|imt8192
74 8 1 1024 4096 # imt8|imt1x4
75 9 2 1144 880 # imt9|imtfs full screen (1152x900 minus frame)
76 10 2 1144 764 # imt10|imtfs35 full screen at 35mm film aspect ratio
77 -------------------snip-------------------------
78  
79 (Note: some versions of SAOimage may not even work if this file is not
80 present. If you get funny error messages about 'imtoolrc' try copying
81 the above to F<$HOME/.imtoolrc> or F</usr/local/lib/imtoolrc>)
82  
83 The Perl variable C<$iisframe> is also exported from the module and controls
84 which display frame number to use in programs such as Ximtool which supports
85 multiple frames. This allows you to do useful things such as blink between
86 images.
87  
88 The module communicates with the IIS device down FIFO pipes (special UNIX
89 files) - unlike IRAF this module does a pretty decent job of intelligently
90 guessing which file names to use for the pipes and will prompt for their
91 creating if absent. Also if SAOimage or Ximtool are started from within Perl
92 using the module this will guarantee correct file names!
93  
94 =head1 FUNCTIONS
95  
96 =cut
97  
98 use strict;
99 use warnings;
100  
101 our $VERSION = '0.001';
102  
103 #line 85 "iis.pd"
104 use PDL::Core '';
105 use PDL::Basic '';
106 use Carp;
107  
108 $iisframe = 1; # Starting defaults
109 $stdimage = "imt1024";
110 $last_stdimage = "";
111 $HOME = $ENV{'HOME'}; # Used a lot so shorten
112  
113 ################ Public routines #################
114  
115 # Display
116  
117 =head2 iis
118  
119 =for ref
120  
121 Displays an image on a IIS device (e.g. SAOimage/Ximtool)
122  
123 =for usage
124  
125 iis $image, [ { MIN => $min, MAX => $max,
126 TITLE => 'pretty picture',
127 FRAME => 2 } ]
128 iis $image, [$min,$max]
129  
130 =for sig
131  
132 (image(m,n),[\%options]) or (image(m,n),[min(),max()])
133  
134 Displays image on a IIS device. If C<min()> or C<max()> are omitted they
135 are autoscaled. A good demonstration of PDL broadcasting can be had
136 by giving C<iis()> a data *cube* - C<iis()> will be repeatedly called
137 for each plane of the cube resulting in a poor man's movie!
138  
139 If supplied, C<TITLE> is used to label the frame, if no title is
140 supplied, either the C<OBJECT> value stored in the image header or a
141 default string is used (the title is restricted to a maximum
142 length of 32 characters).
143  
144 To specify which frame to draw to, either use
145 the package variable C<$iisframe>, or the C<FRAME> option.
146  
147 =cut
148  
149 sub iis {
150 my $usage = 'Usage: iis ( $image, [\%hash | $min, $max] )';
151 barf $usage if $#_<0 || $#_>2;
152  
153 my $image = shift;
154 my ( $min, $max );
155  
156 my $title = 'perlDL rules !';
157 my $header = $image->gethdr();
158 if ( defined $header and defined $$header{OBJECT} ) {
159 $title = $$header{OBJECT};
160 $title =~ s/^'(.*)'$/$1/;
161 }
162  
163 my $frame = $iisframe;
164 if ( $#_ == 1 ) { $min = $_[0]; $max = $_[1]; }
165 elsif ( $#_ == 0 ) {
166 barf $usage unless ref($_[0]) eq "HASH";
167  
168 my $opt = PDL::Options->new( { MIN => undef, MAX => undef, TITLE => $title, FRAME => $frame } );
169 $opt->options( shift );
170 my $options = $opt->current;
171  
172 $min = $$options{MIN};
173 $max = $$options{MAX};
174 $title = $$options{TITLE};
175 $iisframe = $$options{FRAME};
176 }
177  
178 my($nx,$ny) = dims($image);
179 fbconfig($stdimage) if $stdimage ne $last_stdimage;
180 $min = $image->min unless defined $min;
181 $max = $image->max unless defined $max;
182 print "Displaying $nx x $ny image in frame $iisframe from $min to $max ...\n" if $PDL::verbose;
183 PDL::_iis($image,$min,$max,$title);
184 $iisframe = $frame; # restore value
185 1;
186 }
187  
188 =head2 iiscur
189  
190 =for ref
191  
192 Return cursor position from an IIS device (e.g. SAOimage/Ximtool)
193  
194 =for usage
195  
196 ($x,$y) = iiscur($ch)
197  
198 This function puts up an interactive cursor on the IIS device and returns
199 the C<($x,$y)> position and the character typed (C<$ch>)
200 by the user.
201  
202 =cut
203  
204 sub iiscur {
205 barf 'Usage: ($x,$y) = iiscur($ch)' if $#_>=1;
206 my ($x,$y,$ch) = _iiscur_int();
207 $_[0] = $ch; # Pass this back in args
208 return ($x,$y);
209 }
210  
211 =head2 iiscirc
212  
213 =for ref
214  
215 Draws a circle on a IIS device (e.g. SAOimage/Ximtool)
216  
217 =for sig
218  
219 (x(),y(),radius(),colour())
220  
221 =for usage
222  
223 iiscirc $x, $y, [$radius, $colour]
224  
225 Draws circles on the IIS device with specified points and colours. Because
226 this module uses
227 L<PDL::PP> broadcasting you can supply lists of points via
228 1D arrays, etc.
229  
230 An amusing PDL idiom is:
231  
232 pdl> iiscirc iiscur
233  
234 Note the colours are the same as IRAF, viz:
235  
236 201 = cursor color (white)
237 202 = black
238 203 = white
239 204 = red
240 205 = green
241 206 = blue
242 207 = yellow
243 208 = cyan
244 209 = magenta
245 210 = coral
246 211 = maroon
247 212 = orange
248 213 = khaki
249 214 = orchid
250 215 = turquoise
251 216 = violet
252 217 = wheat
253  
254 =cut
255  
256 sub iiscirc {
257 barf 'Usage: iiscirc( $x, $y, [$radius, $colour] )' if $#_<1 || $#_>3;
258 my($x, $y, $radius, $colour)=@_;
259 fbconfig($stdimage) if $stdimage ne $last_stdimage;
260 $radius = 10 unless defined $radius;
261 $colour = 204 unless defined $colour;
262 PDL::_iiscirc($x, $y, $radius, $colour);
263 1;
264 }
265  
266 =head2 saoimage
267  
268 =for ref
269  
270 Starts the SAOimage external program
271  
272 =for usage
273  
274 saoimage[(command line options)]
275  
276 Starts up the SAOimage external program. Default FIFO devices are chosen
277 so as to be compatible with other IIS module functions. If no suitable
278 FIFOs are found it will offer to create them.
279  
280 e.g.:
281  
282 =for example
283  
284 pdl> saoimage
285 pdl> saoimage( -geometry => '800x800' )
286  
287 =cut
288  
289 sub saoimage { # Start SAOimage
290 fbconfig($stdimage) if $stdimage ne $last_stdimage;
291 if( !($pid = fork)) { # error or child
292 exec("saoimage", -idev => $fifo, -odev => $fifi, @_) if defined $pid;
293 die "Can't start saoimage: $!\n";
294 }
295 return $pid;
296 }
297  
298 =head2 ximtool
299  
300 =for ref
301  
302 Starts the Ximtool external program
303  
304 =for usage
305  
306 ximtool[(command line options)]
307  
308 Starts up the Ximtool external program. Default FIFO devices are chosen
309 so as to be compatible with other IIS module functions. If no suitable
310 FIFOs are found it will offer to create them.
311  
312 e.g.
313  
314 =for example
315  
316 pdl> ximtool
317 pdl> ximtool (-maxColors => 64)
318  
319 =cut
320  
321 sub ximtool { # Start Ximtool
322 fbconfig($stdimage) if $stdimage ne $last_stdimage;
323 if( !($pid = fork)) { # error or child
324 exec("ximtool", -xrm => "ximtool*input_fifo: $fifi", -xrm => "ximtool*output_fifo: $fifo", @_) if defined $pid;
325 die "Can't start ximtool: $!\n";
326 }
327 return $pid;
328 }
329  
330 ################ Private routines #################
331  
332 # Change the frame buffer configuration
333  
334 sub fbconfig {
335 my $name = shift;
336 parseimtoolrc() unless $parsed++;
337 findfifo() unless $foundfifo++;
338 barf 'No frame buffer configuration "'.$name.'" found'."\n"
339 unless defined $imtoolrc{$name};
340 ($fbconfig, $fb_x, $fb_y ) = @{ $imtoolrc{$name} };
341 print "Using $stdimage - fbconfig=$fbconfig (${fb_x}x$fb_y)\n" if $PDL::verbose;;
342 $last_stdimage = $stdimage;
343 1;}
344  
345 # Try and find user/system imtoolrc definitions
346  
347 sub parseimtoolrc {
348 # assoc array holds imtool configuations - init with some standard
349 # ones in case imtoolrc goes missing
350  
351 %imtoolrc = (
352 'imt512' => [1,512,512], 'imt800' => [2,800,800],
353 'imt1024' => [3,1024,1024], 'imt1600' => [4,1600,1600],
354 'imt2048' => [5,2048,2048], 'imt4096' => [6,4096,4096],
355 );
356  
357 # Look for imtoolrc file
358  
359 $imtoolrc = "/usr/local/lib/imtoolrc";
360 $imtoolrc = "$HOME/.imtoolrc" if -e "$HOME/.imtoolrc";
361 if (!-e $imtoolrc) {
362 warn "WARNING: unable to find an imtoolrc file in $HOME/.imtoolrc\n".
363 "or /usr/local/lib/imtoolrc. Will try \$stdimage = imt1024.\n";
364 return 1;
365 }
366  
367 # Load frame buffer configuartions from imtoolrc file and
368 # store in assoc array
369  
370 open(IMTOOLRC, $imtoolrc) || die "File $imtoolrc not found";
371 while(<IMTOOLRC>) {
372 if ( /^\s*(\d+)\s+\d+\s+(\d+)\s+(\d+)\s+\#\s*(\S+)\s/ ) {
373 foreach $name (split(/\|/,$4)) {
374 $imtoolrc{$name} = [$1,$2,$3];
375 }
376 }
377 }close(IMTOOLRC);
378 1;}
379  
380 # Try a few obvious places for the FIFO pipe and create if necessary
381  
382 sub findfifo {
383 $fifi = ""; $fifo = "";
384 if (-e "/dev/imt1i" && -e "/dev/imt1o") {
385 $fifi = "/dev/imt1i"; $fifo = "/dev/imt1o";
386 }
387 if (-e "$HOME/dev/imt1i" && -e "$HOME/dev/imt1o") {
388 $fifi = "$HOME/dev/imt1i"; $fifo = "$HOME/dev/imt1o";
389 }
390 if (-e "$HOME/iraf/dev/imt1i" && -e "$HOME/iraf/dev/imt1o") {
391 $fifi = "$HOME/iraf/dev/imt1i"; $fifo = "$HOME/iraf/dev/imt1o";
392 }
393 if (defined $ENV{'IMTDEV'} && $ENV{'IMTDEV'} =~ /^fifo:(.*):(.*)$/) {
394 $fifi = $1; $fifo = $2;
395 }
396 if ($fifi eq "" && $fifo eq "") { # Still not found use this default
397 warn "WARNING: cannot locate FIFO pipes in /dev/, $HOME/dev, ".
398 "$HOME/iraf/dev or environment variable \$IMTDEV\n";
399 $fifi = "$HOME/dev/imt1i"; $fifo = "$HOME/dev/imt1o";
400 }
401 print "Using FIFO devices in: $fifi\n".
402 " out: $fifo\n" if $PDL::verbose;
403 for $pipe ($fifi, $fifo) {
404 if (!-p $pipe) {
405 print "FIFO $pipe does not exist - try and create now? "; my $ans = <STDIN>;
406 system "/usr/etc/mknod $pipe p" if $ans =~ /^y/i;
407  
408 if ($ans =~ /^y/i) {
409 unlink $pipe if -e $pipe;
410 my $path = $ENV{PATH};
411 $ENV{PATH} .= ":/etc:/usr/etc";
412  
413 # Note system return value is backwards - hence 'and'
414  
415 if ( system('mknod', $pipe, 'p') and system('mkfifo',$pipe) ) {
416 die "Failed to create named pipe $pipe\n";
417 }
418 $ENV{PATH} = $path;
419 }
420 }
421 }
422 1;}
423 #line 424 "IIS.pm"
424  
425 *_iis = \&PDL::Graphics::IIS::_iis;
426  
427  
428  
429  
430 *_iiscirc = \&PDL::Graphics::IIS::_iiscirc;
431  
432  
433  
434  
435  
436  
437  
438 #line 620 "iis.pd"
439  
440 =head1 BUGS
441  
442 None known
443  
444 =head1 AUTHOR
445  
446 Copyright (C) Karl Glazebrook 1997.
447 All rights reserved. There is no warranty. You are allowed
448 to redistribute this software / documentation under certain
449 conditions. For details, see the file COPYING in the PDL
450 distribution. If this file is separated from the PDL distribution,
451 the copyright notice should be included in the file.
452  
453 =cut
454 #line 455 "IIS.pm"
455  
456 # Exit with OK status
457  
458 1;