QUICKSTART(1p) | User Contributed Perl Documentation | QUICKSTART(1p) |

pdl> help help $ pdldocHTML copies of the documentation should also be available. To find their location, try the following:

pdl> foreach ( map{"$_/PDL/HtmlDocs"}@INC ) { p "$_\n" if -d $_ }

use PDL; # in Perl scripts: use the standard perlDL modulesThere are also a lot of extension modules, e.g. PDL::Graphics::TriD. Most of these (but not all as sometimes it is not appropriate) follow a standard convention. If you say:

use PDL::Graphics::TriD;You import everything in a standard list from the module. Sometimes you might want to import nothing (e.g. if you want to use OO syntax all the time and save the import tax). For these you say:

use PDL::Graphics::TriD qw();And the empty "qw()" quotes are recognised as meaning 'nothing'. You can also specify a list of functions to import in the normal Perl way. There is also an interactive shell, "perldl" or "pdl2", see

$a = pdl [1..10]; # 1D array $a = pdl (1,2,3,4); # Ditto $a = pdl '[1 2 3 4]'; # Ditto $b = pdl [[1,2,3],[4,5,6]]; # 2D 3x2 array $b = pdl '[1 2 3; 4 5 6]'; # Ditto $b = pdl q[1,2,3; 4,5,6]; # Ditto $b = pdl <<NEWPDL # Ditto [1 2 3] [4 5 6] NEWPDL $c = pdl q[1 -2]; # 2-element piddle containing 1 and -2 $c = pdl q[1 - 2]; # 2-element piddle containing 1 and -2 $b = pdl 42 # 0-dimensional scalar $c = pdl $a; # Make a new copy $d = byte [1..10]; # See "Type conversion" $e = zeroes(3,2,4); # 3x2x4 zero-filled array $c = rfits $file; # Read FITS file @x = ( pdl(42), zeroes(3,2,4), rfits($file) ); # Is a LIST of PDL variables!The

$a = $b + 2; $a++; $a = $b / $c; # Etc. $c=sqrt($a); $d = log10($b+100); # Etc $e = $a>42; # Vector conditional $e = 42*($a>42) + $a*($a<=42); # Cap top $b = $a->log10 unless any ($a <= 0); # avoid floating point error $a = $a / ( max($a) - min($a) ); $f = where($a, $a > 10); # where returns a piddle of elements for # which the condition is true print $a; # $a in string context prints it in a N-dimensional format(and other Perl operators/functions) When using piddles in conditional expressions (i.e. "if", "unless" and "while" constructs) only piddles with exactly one element are allowed, e.g.

$a = pdl (1,0,0,1); print "is set" if $a->index(2);Note that the boolean operators return in general multi-element piddles. Therefore, the following will raise an error

print "is ok" if $a > 3;since "$a > 3" is a piddle with 4 elements. Rather use all or any to test if all or any of the elements fulfill the condition:

print "some are > 3" if any $a>3; print "can't take logarithm" unless all $a>0;There are also many predefined functions, which are described on other man pages. Check PDL::Index.

$a = [ $b = [ [ 1 2 3 0] [1 1] [ 1 -1 2 7] [0 2] [ 1 0 0 1] [0 2] ] [1 1] ] gives $c = [ [ 1 11] [ 8 10] [ 2 2] ]Note:

sub dotproduct { my ($a,$b) = @_; return sum($a*$b) ; } 1;If put in file dotproduct.pdl would be autoloaded if you are using PDL::AutoLoader (see below). Of course, this function is already available as the inner function, see PDL::Primitive.

$a = float($b); $c = long($d); # "long" is generally a 4 byte int $d = byte($a);Also

NOTE: The indx() routine is a special integer type that is the correct size for a PDL index value (dimension size, index, or offest) which can be either a 32bit (long) or 64bit (longlong) quantity depending on whether the perl is built with 32bit or 64bit support.These routines also automatically convert Perl lists to allow the convenient shorthand:

$a = byte [[1..10],[1..10]]; # Create 2D byte array $a = float [1..1000]; # Create 1D float arrayetc.

print $a; $b = "Answer is = $a ";

$b = $a->($x1:$x2,$y1:$y2,($z1)); # Take subsectionHere, $a is a 3-dimensional variable, and $b gets a planar cutout that is defined by the limits $x1, $x2, $y1, $y2, at the location $z1. The parenthesis around $z1 cause the trivial index to be omitted -- otherwise $b would be three-dimensional with a third dimension of order 1. You can put PDL slices on either side of the element-wise assignment operator ".=", like so:

# Set part of $bigimage to values from $smallimage $bigimage->($xa:$xb,$ya:$yb) .= $smallimage;Some other miscellany:

$c = nelem($a); # Number of pixels $val = at($object, $x,$y,$z...) # Pixel value at position, as a Perl scalar $val = $object->at($x,$y,$z...) # equivalent (method syntax OK) $b = xvals($a); # Fill array with X-coord values (also yvals(), zvals(), # axisvals($x,$axis) and rvals() for radial distance # from centre).

- PDL::IO::Misc
- Ascii, FITS and FIGARO/NDF IO routines.

- PDL::IO::FastRaw
- Using the raw data types of your machine, an unportable but blindingly fast IO format. Also supports memory mapping to conserve memory as well as get more speed.

- PDL::IO::FlexRaw
- General raw data formats. Like FastRaw, only better.

- PDL::IO::Browser
- A Curses browser for arrays.

- PDL::IO::Pnm
- Portaple bitmap and pixmap support.

- PDL::IO::Pic
- Using the previous module and netpbm, makes it possible to easily write GIF, jpeg and whatever with simple commands.

- PDL::Graphics::PGPLOT
- PGPLOT provides a simple library for line graphics and
image display.

- PDL::Graphics::PLplot
- PLplot provides a simple library for creating graphics with
multiple output drivers, including a direct-to-piddle driver.

- PDL::Graphics::IIS
- Many astronomers like to use SAOimage and Ximtool (or there
derivations/clones). These are useful free widgets for inspection and
visualisation of images. (They are not provided with perlDL but can easily
be obtained from their official sites off the Net.)

- PDL::Graphics::TriD
- See PDL::Graphics::TriD, this is a collection of 3D routines for OpenGL and (soon) VRML and other 3D formats which allow 3D point, line, and surface plots from PDL.

% perldl perlDL shell v1.354 PDL comes with ABSOLUTELY NO WARRANTY. For details, see the file 'COPYING' in the PDL distribution. This is free software and you are welcome to redistribute it under certain conditions, see the same file for details. ReadLines, NiceSlice, MultiLines enabled Reading PDL/default.perldlrc... Found docs database /home/pdl/dev/lib/perl5/site_perl/PDL/pdldoc.db Type 'help' for online help Type 'demo' for online demos Loaded PDL v2.4.9_003 (supports bad values) pdl> $x = rfits 'm51.fits' Reading IMAGE data... BITPIX = 32 size = 147456 pixels Reading 589824 bytes BSCALE = && BZERO = pdl> use PDL::Graphics::PGPLOT; pdl> imag $x Displaying 384 x 384 image from 40 to 761, using 84 colors (16-99)...You can also run it from the Perl debugger ("perl -MPDL -d -e 1") if you want. Miscellaneous shell features:

- p
- The shell aliases "p" to be a convenient short
form of "print", e.g.
pdl> p ones 5,3 [ [1 1 1 1 1] [1 1 1 1 1] [1 1 1 1 1] ]

- Initialization
- The files "~/.perldlrc" and "local.perldlrc" (in the current directory) are sourced if found. This allows the user to have global and local PDL code for startup.

- Help
- Type 'help'! One can search the PDL documentation, and look up documentation on any function.

- Escape
- Any line starting with the "#" character is treated as a shell escape. This character is configurable by setting the Perl variable $PERLDL_ESCAPE. This could, for example, be set in "~/.perldlrc".

+ - * / > < >= <= << >> & | ^ == != <=> ** % ! ~ sin log abs atan2 sqrt cos exp[All the unary functions (sin etc.) may be used with

- Simple arithmetic
- If $a is a big image (e.g. occupying 10MB) then the command
$a = $a + 1;

*permanent*memory waste. But on a small machine, the growth in the memory footprint can be considerable. It is obviously done this way so "$c=$a+1" works as expected.$b = $a; # $b and $a now point to same data $a = $a + 1;

$a++;

$b = pdl $a; # Real copy

$b = $a->copy;

- Functions
- Most functions, e.g. "log()", return a result
which is a transformation of their argument. This makes for good
programming practice. However many operations can be done
"in-place" and this may be required when large arrays are in use
and memory is at a premium. For these circumstances the operator
*inplace()*is provided which prevents the extra copy and allows the argument to be modified. e.g.:$x = log($array); # $array unaffected log( inplace($bigarray) ); # $bigarray changed in situ

- 1.
- The usual caveats about duplicate references apply.

- 2.
- Obviously when used with some functions which can not be applied in situ (e.g. "convolve()") unexpected effects may occur! We try to indicate "inplace()"-safe functions in the documentation.

- 3.
- Type conversions, such as"float()", may cause hidden copying.

sub myfiddle { my $pdl = topdl(shift); $pdl->fiddle_foo(...); ... }"topdl()" does NOT perform a copy if a pdl variable is passed - it just falls through - which is obviously the desired behaviour. The routine is not of course necessary in normal user defined functions which do not care about internals.

2017-08-10 | perl v5.26.0 |