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

filter: Statementstmt 0.0% 0 / 137 Branchbran 0.0% 0 / 76 Conditioncond 0.0% 0 / 29 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 14 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 264 CC 39 SCAR 42.2
CC
39
Cov
0%
findfifo
156.0
iis
110.0
iiscirc
30.0
CRAP 68.0
1  
2 #
3 # GENERATED WITH PDL::PP! Don't modify!
4 #
5 package PDL::Graphics::IIS;
6  
7 @EXPORT_OK = qw( iis iiscur iiscirc $stdimage $iisframe saoimage ximtool PDL::PP _iis PDL::PP _iiscirc );
8 %EXPORT_TAGS = (Func=>[@EXPORT_OK]);
9  
10 use PDL::Core;
11 use PDL::Exporter;
12 use DynaLoader;
13  
14  
15  
16
17 @ISA = ( 'PDL::Exporter','DynaLoader' );
18 push @PDL::Core::PP, __PACKAGE__;
19 bootstrap PDL::Graphics::IIS ;
20  
21  
22  
23  
24  
25 =head1 NAME
26  
27 PDL::Graphics::IIS - Display PDL images on IIS devices (saoimage/ximtool)
28  
29 =head1 SYNOPSIS
30  
31 use PDL::Graphics::IIS;
32 saoimage ( -geometry => '800x800' );
33 iis rvals(100,100);
34  
35 =head1 DESCRIPTION
36  
37 This module provides an interface to any image display 'device' which support the
38 'IIS protocol' - viz the SAOimage and Ximtool X-windows programs, the
39 old SunView imtool program and presumably even the original IIS CRT itself
40 if they aren't all in museums!
41  
42 These programs should be familiar to astronomer's - they are used by
43 the common IRAF system. The programs and their HTML documentation
44 can be obtained from the following URLs:
45  
46 SAOimage: http://tdc-www.harvard.edu/software/saoimage.html
47 Ximtool: http://iraf.noao.edu/iraf/web/projects/x11iraf/x11iraf.html
48  
49 Non-astronomer's may find they quite nifty for displaying 2D data.
50  
51 The Perl variable C<$stdimage> is exported from the module and controls
52 the frame buffer configuration currently in use. The default value
53 is C<imt1024> which specifies a C<1024x1024> frame buffer. Other
54 values supported by the module are:
55
56 imt512, imt800, imt1024, imt1600, imt2048, and imt4096.
57  
58 If you have a F<$HOME/.imtoolrc> you can use it to specify other frame
59 buffer names and configurations in exactly the same way you can in
60 IRAF. Here is a sample file:
61  
62 -------------------snip-------------------------
63 # Format: configno nframes width height
64 1 2 512 512 # imt1|imt512
65 2 2 800 800 # imt2|imt800
66 3 2 1024 1024 # imt3|imt1024
67 4 1 1600 1600 # imt4|imt1600
68 5 1 2048 2048 # imt5|imt2048
69 6 1 4096 4096 # imt6|imt4096
70 7 1 8192 8192 # imt7|imt8192
71 8 1 1024 4096 # imt8|imt1x4
72 9 2 1144 880 # imt9|imtfs full screen (1152x900 minus frame)
73 10 2 1144 764 # imt10|imtfs35 full screen at 35mm film aspect ratio
74 -------------------snip-------------------------
75  
76 (Note: some versions of SAOimage may not even work if this file is not
77 present. If you get funny error messages about 'imtoolrc' try copying
78 the above to F<$HOME/.imtoolrc> or F</usr/local/lib/imtoolrc>)
79  
80 The Perl variable C<$iisframe> is also exported from the module and controls
81 which display frame number to use in programs such as Ximtool which supports
82 multiple frames. This allows you to do useful things such as blink between
83 images.
84  
85 The module communicates with the IIS device down FIFO pipes (special UNIX
86 files) - unlike IRAF this module does a pretty decent job of intelligently
87 guessing which file names to use for the pipes and will prompt for their
88 creating if absent. Also if SAOimage or Ximtool are started from within Perl
89 using the module this will guarantee correct file names!
90  
91 =head1 FUNCTIONS
92  
93 =cut
94  
95  
96  
97  
98  
99  
100  
101  
102  
103 use PDL::Core '';
104 use PDL::Basic '';
105 use Carp;
106  
107 $iisframe = 1; # Starting defaults
108 $stdimage = "imt1024";
109 $last_stdimage = "";
110 $HOME = $ENV{'HOME'}; # Used a lot so shorten
111  
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 threading 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 = new PDL::Options( { 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 specied points and colours. Because
226 this module uses
227 L<PDL::PP|PDL::PP> threading 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  
331 ################ Private routines #################
332  
333 # Change the frame buffer configuration
334  
335 sub fbconfig {
336 my $name = shift;
337 parseimtoolrc() unless $parsed++;
338 findfifo() unless $foundfifo++;
339 barf 'No frame buffer configuration "'.$name.'" found'."\n"
340 unless defined $imtoolrc{$name};
341 ($fbconfig, $fb_x, $fb_y ) = @{ $imtoolrc{$name} };
342 print "Using $stdimage - fbconfig=$fbconfig (${fb_x}x$fb_y)\n" if $PDL::verbose;;
343 $last_stdimage = $stdimage;
344 1;}
345  
346 # Try and find user/system imtoolrc definitions
347  
348 sub parseimtoolrc {
349 # assoc array holds imtool configuations - init with some standard
350 # ones in case imtoolrc goes missing
351  
352 %imtoolrc = (
353 'imt512' => [1,512,512], 'imt800' => [2,800,800],
354 'imt1024' => [3,1024,1024], 'imt1600' => [4,1600,1600],
355 'imt2048' => [5,2048,2048], 'imt4096' => [6,4096,4096],
356 );
357  
358 # Look for imtoolrc file
359  
360 $imtoolrc = "/usr/local/lib/imtoolrc";
361 $imtoolrc = "$HOME/.imtoolrc" if -e "$HOME/.imtoolrc";
362 if (!-e $imtoolrc) {
363 warn "WARNING: unable to find an imtoolrc file in $HOME/.imtoolrc\n".
364 "or /usr/local/lib/imtoolrc. Will try \$stdimage = imt1024.\n";
365 return 1;
366 }
367  
368 # Load frame buffer configuartions from imtoolrc file and
369 # store in assoc array
370  
371 open(IMTOOLRC, $imtoolrc) || die "File $imtoolrc not found";
372 while(<IMTOOLRC>) {
373 if ( /^\s*(\d+)\s+\d+\s+(\d+)\s+(\d+)\s+\#\s*(\S+)\s/ ) {
374 foreach $name (split(/\|/,$4)) {
375 $imtoolrc{$name} = [$1,$2,$3];
376 }
377 }
378 }close(IMTOOLRC);
379 1;}
380  
381 # Try a few obvious places for the FIFO pipe and create if necessary
382  
383 sub findfifo {
384 $fifi = ""; $fifo = "";
385 if (-e "/dev/imt1i" && -e "/dev/imt1o") {
386 $fifi = "/dev/imt1i"; $fifo = "/dev/imt1o";
387 }
388 if (-e "$HOME/dev/imt1i" && -e "$HOME/dev/imt1o") {
389 $fifi = "$HOME/dev/imt1i"; $fifo = "$HOME/dev/imt1o";
390 }
391 if (-e "$HOME/iraf/dev/imt1i" && -e "$HOME/iraf/dev/imt1o") {
392 $fifi = "$HOME/iraf/dev/imt1i"; $fifo = "$HOME/iraf/dev/imt1o";
393 }
394 if (defined $ENV{'IMTDEV'} && $ENV{'IMTDEV'} =~ /^fifo:(.*):(.*)$/) {
395 $fifi = $1; $fifo = $2;
396 }
397 if ($fifi eq "" && $fifo eq "") { # Still not found use this default
398 warn "WARNING: cannot locate FIFO pipes in /dev/, $HOME/dev, ".
399 "$HOME/iraf/dev or environment variable \$IMTDEV\n";
400 $fifi = "$HOME/dev/imt1i"; $fifo = "$HOME/dev/imt1o";
401 }
402 print "Using FIFO devices in: $fifi\n".
403 " out: $fifo\n" if $PDL::verbose;
404 for $pipe ($fifi, $fifo) {
405 if (!-p $pipe) {
406 print "FIFO $pipe does not exist - try and create now? "; my $ans = <STDIN>;
407 system "/usr/etc/mknod $pipe p" if $ans =~ /^y/i;
408  
409 if ($ans =~ /^y/i) {
410 unlink $pipe if -e $pipe;
411 my $path = $ENV{PATH};
412 $ENV{PATH} .= ":/etc:/usr/etc";
413  
414 # Note system return value is backwards - hence 'and'
415  
416 if ( system('mknod', $pipe, 'p') and system('mkfifo',$pipe) ) {
417 die "Failed to create named pipe $pipe\n";
418 }
419 $ENV{PATH} = $path;
420 }
421 }
422 }
423 1;}
424  
425  
426  
427  
428  
429  
430 *_iis = \&PDL::Graphics::IIS::_iis;
431  
432  
433  
434  
435  
436 *_iiscirc = \&PDL::Graphics::IIS::_iiscirc;
437  
438  
439  
440 ;
441  
442  
443 =head1 BUGS
444  
445 None known
446  
447 =head1 AUTHOR
448  
449 Copyright (C) Karl Glazebrook 1997.
450 All rights reserved. There is no warranty. You are allowed
451 to redistribute this software / documentation under certain
452 conditions. For details, see the file COPYING in the PDL
453 distribution. If this file is separated from the PDL distribution,
454 the copyright notice should be included in the file.
455  
456 =cut
457  
458  
459  
460  
461  
462  
463 # Exit with OK status
464  
465 1;
466  
467